mtk: Move Rectangle.intersect from Meta

Also replaces it usage everywhere & remove the Clutter helper. Note the
tests were not moved yet to mtk.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3128>
This commit is contained in:
Bilal Elmoussaoui 2023-07-19 17:40:37 +02:00
parent 6f66dd9944
commit 565acaed9c
20 changed files with 107 additions and 142 deletions

View File

@ -214,10 +214,6 @@ void _clutter_util_rectangle_offset (const MtkRectangle *src,
int y,
MtkRectangle *dest);
gboolean _clutter_util_rectangle_intersection (const MtkRectangle *src1,
const MtkRectangle *src2,
MtkRectangle *dest);
CLUTTER_EXPORT
PangoDirection _clutter_pango_unichar_direction (gunichar ch);

View File

@ -602,7 +602,7 @@ find_damaged_tiles (ClutterStageView *view,
CAIRO_REGION_OVERLAP_OUT)
continue;
_clutter_util_rectangle_intersection (&tile, &fb_rect, &tile);
mtk_rectangle_intersect (&tile, &fb_rect, &tile);
if (is_tile_dirty (&tile, current_data, prev_data, bpp, stride))
cairo_region_union_rectangle (tile_damage_region, &tile);

View File

@ -263,8 +263,8 @@ clutter_stage_add_redraw_clip (ClutterStage *stage,
MtkRectangle intersection;
clutter_stage_view_get_layout (view, &view_layout);
if (_clutter_util_rectangle_intersection (&view_layout, clip,
&intersection))
if (mtk_rectangle_intersect (&view_layout, clip,
&intersection))
clutter_stage_view_add_redraw_clip (view, &intersection);
}
}

View File

@ -163,39 +163,6 @@ _clutter_util_rectangle_offset (const MtkRectangle *src,
dest->y += y;
}
gboolean
_clutter_util_rectangle_intersection (const MtkRectangle *src1,
const MtkRectangle *src2,
MtkRectangle *dest)
{
int x1, y1, x2, y2;
x1 = MAX (src1->x, src2->x);
y1 = MAX (src1->y, src2->y);
x2 = MIN (src1->x + (int) src1->width, src2->x + (int) src2->width);
y2 = MIN (src1->y + (int) src1->height, src2->y + (int) src2->height);
if (x1 >= x2 || y1 >= y2)
{
dest->x = 0;
dest->y = 0;
dest->width = 0;
dest->height = 0;
return FALSE;
}
else
{
dest->x = x1;
dest->y = y1;
dest->width = x2 - x1;
dest->height = y2 - y1;
return TRUE;
}
}
typedef struct
{
GType value_type;

View File

@ -98,3 +98,52 @@ mtk_rectangle_union (const MtkRectangle *rect1,
dest->width = dest_w;
dest->height = dest_h;
}
/**
* mtk_rectangle_intersect:
* @src1: a #MtkRectangle
* @src2: another #MtkRectangle
* @dest: (out caller-allocates): an empty #MtkRectangle, to be filled
* with the coordinates of the intersection.
*
* Find the intersection between the two rectangles
*
* Returns: TRUE is some intersection exists and is not degenerate, FALSE
* otherwise.
*/
gboolean
mtk_rectangle_intersect (const MtkRectangle *src1,
const MtkRectangle *src2,
MtkRectangle *dest)
{
int dest_x, dest_y;
int dest_w, dest_h;
int return_val;
g_return_val_if_fail (src1 != NULL, FALSE);
g_return_val_if_fail (src2 != NULL, FALSE);
g_return_val_if_fail (dest != NULL, FALSE);
return_val = FALSE;
dest_x = MAX (src1->x, src2->x);
dest_y = MAX (src1->y, src2->y);
dest_w = MIN (src1->x + src1->width, src2->x + src2->width) - dest_x;
dest_h = MIN (src1->y + src1->height, src2->y + src2->height) - dest_y;
if (dest_w > 0 && dest_h > 0)
{
dest->x = dest_x;
dest->y = dest_y;
dest->width = dest_w;
dest->height = dest_h;
return_val = TRUE;
}
else
{
dest->width = 0;
dest->height = 0;
}
return return_val;
}

View File

@ -74,3 +74,8 @@ void mtk_rectangle_union (const MtkRectangle *rect1,
const MtkRectangle *rect2,
MtkRectangle *dest);
MTK_EXPORT
gboolean mtk_rectangle_intersect (const MtkRectangle *src1,
const MtkRectangle *src2,
MtkRectangle *dest);

View File

@ -3369,9 +3369,9 @@ meta_monitor_manager_get_logical_monitor_from_rect (MetaMonitorManager *manager,
if (META_POINT_IN_RECT (center_x, center_y, logical_monitor->rect))
return logical_monitor;
if (!meta_rectangle_intersect (&logical_monitor->rect,
rect,
&intersection))
if (!mtk_rectangle_intersect (&logical_monitor->rect,
rect,
&intersection))
continue;
intersection_area = meta_rectangle_area (&intersection);
@ -3413,9 +3413,9 @@ meta_monitor_manager_get_highest_scale_monitor_from_rect (MetaMonitorManager *ma
MetaRectangle intersection;
float scale;
if (!meta_rectangle_intersect (&logical_monitor->rect,
rect,
&intersection))
if (!mtk_rectangle_intersect (&logical_monitor->rect,
rect,
&intersection))
continue;
scale = meta_logical_monitor_get_scale (logical_monitor);

View File

@ -323,7 +323,7 @@ meta_screen_cast_window_stream_src_get_videocrop (MetaScreenCastStreamSrc *src,
stream_rect.width = get_stream_width (window_src);
stream_rect.height = get_stream_height (window_src);
meta_rectangle_intersect (crop_rect, &stream_rect, crop_rect);
mtk_rectangle_intersect (crop_rect, &stream_rect, crop_rect);
return TRUE;
}

View File

@ -398,7 +398,7 @@ queue_redraw_clutter_rect (MetaStage *stage,
clutter_stage_view_get_layout (view, &view_layout);
if (meta_rectangle_intersect (&clip, &view_layout, &view_clip))
if (mtk_rectangle_intersect (&clip, &view_layout, &view_clip))
{
clutter_stage_view_add_redraw_clip (view, &view_clip);
clutter_stage_view_schedule_update (view);

View File

@ -966,9 +966,9 @@ compute_resistance_and_snapping_edges (MetaWindowDrag *window_drag)
* is offscreen (we also don't care about parts of edges covered
* by other windows or DOCKS, but that's handled below).
*/
meta_rectangle_intersect (&cur_rect,
&display_rect,
&reduced);
mtk_rectangle_intersect (&cur_rect,
&display_rect,
&reduced);
new_edges = NULL;

View File

@ -847,7 +847,7 @@ do_paint_content (MetaShapedTexture *stex,
MtkRectangle rect;
cairo_region_get_rectangle (blended_tex_region, i, &rect);
if (!meta_rectangle_intersect (&content_rect, &rect, &rect))
if (!mtk_rectangle_intersect (&content_rect, &rect, &rect))
continue;
paint_clipped_rectangle_node (stex, root_node,
@ -1036,7 +1036,7 @@ meta_shaped_texture_update_area (MetaShapedTexture *stex,
.height = stex->tex_height,
};
meta_rectangle_intersect (&buffer_rect, clip, clip);
mtk_rectangle_intersect (&buffer_rect, clip, clip);
meta_rectangle_scale_double (clip,
1.0 / stex->buffer_scale,
@ -1448,8 +1448,8 @@ meta_shaped_texture_get_image (MetaShapedTexture *stex,
.height = stex->dst_height,
};
if (!meta_rectangle_intersect (&dst_rect, clip,
image_clip))
if (!mtk_rectangle_intersect (&dst_rect, clip,
image_clip))
return NULL;
*image_clip = (MetaRectangle) {

View File

@ -1697,9 +1697,9 @@ meta_window_actor_get_image (MetaWindowActor *self,
tmp_clip = *clip;
tmp_clip.x += floorf (x);
tmp_clip.y += floorf (y);
if (!meta_rectangle_intersect (&framebuffer_clip,
&tmp_clip,
&intersected_clip))
if (!mtk_rectangle_intersect (&framebuffer_clip,
&tmp_clip,
&intersected_clip))
goto out;
framebuffer_clip = intersected_clip;
@ -1779,7 +1779,7 @@ meta_window_actor_paint_to_content (MetaWindowActor *self,
{
MetaRectangle tmp_clip;
if (!meta_rectangle_intersect (&framebuffer_clip, clip, &tmp_clip))
if (!mtk_rectangle_intersect (&framebuffer_clip, clip, &tmp_clip))
goto out;
framebuffer_clip = tmp_clip;

View File

@ -2,7 +2,7 @@
/*
* Copyright (C) 2005, 2006 Elijah Newren
* [meta_rectangle_intersect() is copyright the GTK+ Team according to Havoc,
* [mtk_rectangle_intersect() is copyright the GTK+ Team according to Havoc,
* see gdkrectangle.c. As far as Havoc knows, he probably wrote
* mtk_rectangle_equal(), and I'm guessing it's (C) Red Hat. So...]
* Copyright (C) 1995-2000 GTK+ Team
@ -153,53 +153,6 @@ meta_rectangle_area (const MetaRectangle *rect)
return rect->width * rect->height;
}
/**
* meta_rectangle_intersect:
* @src1: a #MetaRectangle
* @src2: another #MetaRectangle
* @dest: (out caller-allocates): an empty #MetaRectangle, to be filled
* with the coordinates of the intersection.
*
* Returns: TRUE is some intersection exists and is not degenerate, FALSE
* otherwise.
*/
gboolean
meta_rectangle_intersect (const MetaRectangle *src1,
const MetaRectangle *src2,
MetaRectangle *dest)
{
int dest_x, dest_y;
int dest_w, dest_h;
int return_val;
g_return_val_if_fail (src1 != NULL, FALSE);
g_return_val_if_fail (src2 != NULL, FALSE);
g_return_val_if_fail (dest != NULL, FALSE);
return_val = FALSE;
dest_x = MAX (src1->x, src2->x);
dest_y = MAX (src1->y, src2->y);
dest_w = MIN (src1->x + src1->width, src2->x + src2->width) - dest_x;
dest_h = MIN (src1->y + src1->height, src2->y + src2->height) - dest_y;
if (dest_w > 0 && dest_h > 0)
{
dest->x = dest_x;
dest->y = dest_y;
dest->width = dest_w;
dest->height = dest_h;
return_val = TRUE;
}
else
{
dest->width = 0;
dest->height = 0;
}
return return_val;
}
gboolean
meta_rectangle_overlap (const MetaRectangle *rect1,
const MetaRectangle *rect2)
@ -948,7 +901,7 @@ meta_rectangle_clip_to_region (const GList *spanning_rects,
continue;
/* Determine maximal overlap amount */
meta_rectangle_intersect (rect, compare_rect, &overlap);
mtk_rectangle_intersect (rect, compare_rect, &overlap);
maximal_overlap_amount_for_compare = meta_rectangle_area (&overlap);
/* See if this is the best rect so far */
@ -1282,7 +1235,7 @@ get_disjoint_strut_rect_list_in_region (const GSList *old_struts,
MetaRectangle *cur = &((MetaStrut*)old_struts->data)->rect;
MetaRectangle *copy = g_new (MetaRectangle, 1);
*copy = *cur;
if (meta_rectangle_intersect (copy, region, copy))
if (mtk_rectangle_intersect (copy, region, copy))
strut_rects = g_list_prepend (strut_rects, copy);
else
g_free (copy);
@ -1306,7 +1259,7 @@ get_disjoint_strut_rect_list_in_region (const GSList *old_struts,
MetaRectangle *comp = compare->data;
MetaRectangle overlap;
if (meta_rectangle_intersect (cur, comp, &overlap))
if (mtk_rectangle_intersect (cur, comp, &overlap))
{
/* Get a list of rectangles for each strut that don't overlap
* the intersection region.

View File

@ -838,8 +838,8 @@ try_flip_window_position (MetaWindow *window,
&flipped_rel_x, &flipped_rel_y);
flipped_rect.x = parent_x + flipped_rel_x;
flipped_rect.y = parent_y + flipped_rel_y;
meta_rectangle_intersect (&flipped_rect, &info->work_area_monitor,
&flipped_intersection);
mtk_rectangle_intersect (&flipped_rect, &info->work_area_monitor,
&flipped_intersection);
if ((constraint_adjustment == META_PLACEMENT_CONSTRAINT_ADJUSTMENT_FLIP_X &&
flipped_intersection.width == flipped_rect.width) ||
@ -966,8 +966,8 @@ constrain_custom_rule (MetaWindow *window,
adjusted_rel_y = window->placement.current.rel_y;
}
meta_rectangle_intersect (&adjusted_unconstrained, &info->work_area_monitor,
&intersection);
mtk_rectangle_intersect (&adjusted_unconstrained, &info->work_area_monitor,
&intersection);
constraint_satisfied = (mtk_rectangle_equal (&info->current,
&adjusted_unconstrained) &&
@ -1034,8 +1034,8 @@ constrain_custom_rule (MetaWindow *window,
&intersection);
}
meta_rectangle_intersect (&info->current, &info->work_area_monitor,
&intersection);
mtk_rectangle_intersect (&info->current, &info->work_area_monitor,
&intersection);
constraint_satisfied = is_custom_rule_satisfied (&info->current,
placement_rule,
&intersection);
@ -1100,8 +1100,8 @@ constrain_custom_rule (MetaWindow *window,
info->current.y = new_y;
}
meta_rectangle_intersect (&info->current, &info->work_area_monitor,
&intersection);
mtk_rectangle_intersect (&info->current, &info->work_area_monitor,
&intersection);
constraint_satisfied = is_custom_rule_satisfied (&info->current,
placement_rule,
&intersection);

View File

@ -2934,7 +2934,7 @@ handle_raise_or_lower (MetaDisplay *display,
meta_window_get_frame_rect (above, &above_rect);
/* Check if obscured */
if (meta_rectangle_intersect (&win_rect, &above_rect, &tmp))
if (mtk_rectangle_intersect (&win_rect, &above_rect, &tmp))
{
meta_window_raise (window);
return;

View File

@ -365,9 +365,9 @@ window_overlaps_focus_window (MetaWindow *window)
meta_window_get_frame_rect (window, &window_frame);
meta_window_get_frame_rect (focus_window, &focus_frame);
return meta_rectangle_intersect (&window_frame,
&focus_frame,
&overlap);
return mtk_rectangle_intersect (&window_frame,
&focus_frame,
&overlap);
}
static gboolean
@ -458,7 +458,7 @@ rectangle_overlaps_some_window (MetaRectangle *rect,
case META_WINDOW_MENU:
meta_window_get_frame_rect (other, &other_rect);
if (meta_rectangle_intersect (rect, &other_rect, &dest))
if (mtk_rectangle_intersect (rect, &other_rect, &dest))
return TRUE;
break;
}

View File

@ -5800,7 +5800,7 @@ meta_window_titlebar_is_onscreen (MetaWindow *window)
MetaRectangle *spanning_rect = onscreen_region->data;
MetaRectangle overlap;
meta_rectangle_intersect (&titlebar_rect, spanning_rect, &overlap);
mtk_rectangle_intersect (&titlebar_rect, spanning_rect, &overlap);
if (overlap.height > MIN (titlebar_rect.height, min_height_needed) &&
overlap.width > MIN (titlebar_rect.width * min_width_percent,
min_width_absolute))
@ -5834,9 +5834,9 @@ meta_window_get_work_area_for_logical_monitor (MetaWindow *window,
meta_workspace_get_work_area_for_logical_monitor (tmp->data,
logical_monitor,
&workspace_work_area);
meta_rectangle_intersect (area,
&workspace_work_area,
area);
mtk_rectangle_intersect (area,
&workspace_work_area,
area);
tmp = tmp->next;
}
@ -5916,9 +5916,9 @@ meta_window_get_work_area_all_monitors (MetaWindow *window,
MetaRectangle workspace_work_area;
meta_workspace_get_work_area_all_monitors (tmp->data,
&workspace_work_area);
meta_rectangle_intersect (area,
&workspace_work_area,
area);
mtk_rectangle_intersect (area,
&workspace_work_area,
area);
tmp = tmp->next;
}

View File

@ -117,11 +117,6 @@ MetaRectangle meta_rect (int x, int y, int width, int height);
META_EXPORT
int meta_rectangle_area (const MetaRectangle *rect);
META_EXPORT
gboolean meta_rectangle_intersect (const MetaRectangle *src1,
const MetaRectangle *src2,
MetaRectangle *dest);
/* overlap is similar to intersect but doesn't provide location of
* intersection information.
*/

View File

@ -141,18 +141,18 @@ test_intersect (void)
MetaRectangle temp;
MetaRectangle temp2;
meta_rectangle_intersect (&a, &b, &temp);
mtk_rectangle_intersect (&a, &b, &temp);
temp2 = meta_rect (100, 200, 10, 2);
g_assert (mtk_rectangle_equal (&temp, &temp2));
g_assert (meta_rectangle_area (&temp) == 20);
meta_rectangle_intersect (&a, &c, &temp);
mtk_rectangle_intersect (&a, &c, &temp);
g_assert (meta_rectangle_area (&temp) == 0);
meta_rectangle_intersect (&a, &d, &temp);
mtk_rectangle_intersect (&a, &d, &temp);
g_assert (meta_rectangle_area (&temp) == 0);
meta_rectangle_intersect (&b, &d, &b);
mtk_rectangle_intersect (&b, &d, &b);
g_assert (mtk_rectangle_equal (&b, &b_intersect_d));
}

View File

@ -83,8 +83,8 @@ meta_wayland_shell_surface_determine_geometry (MetaWaylandShellSurface *shell_su
meta_wayland_shell_surface_calculate_geometry (shell_surface,
&bounding_geometry);
meta_rectangle_intersect (set_geometry, &bounding_geometry,
&intersected_geometry);
mtk_rectangle_intersect (set_geometry, &bounding_geometry,
&intersected_geometry);
*out_geometry = intersected_geometry;
}