From 1abef24154dae56e8301620b98ae78de8f0b852d Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Tue, 8 Aug 2023 13:07:54 +0200 Subject: [PATCH] mtk: Move Rectangle.from_graphene_rect from Meta And drop the clutter helper Part-of: --- clutter/clutter/clutter-private.h | 6 -- clutter/clutter/clutter-util.c | 16 ------ mtk/mtk/mtk-rectangle.c | 50 +++++++++++++++++ mtk/mtk/mtk-rectangle.h | 13 +++++ src/backends/meta-monitor.c | 6 +- src/backends/meta-stage-impl.c | 7 ++- src/backends/native/meta-renderer-native.c | 6 +- .../x11/nested/meta-renderer-x11-nested.c | 6 +- src/compositor/meta-shaped-texture.c | 2 +- src/compositor/region-utils.c | 6 +- src/core/boxes-private.h | 19 ++----- src/core/boxes.c | 55 ++----------------- 12 files changed, 91 insertions(+), 101 deletions(-) diff --git a/clutter/clutter/clutter-private.h b/clutter/clutter/clutter-private.h index f73d73596..9d5e68c8c 100644 --- a/clutter/clutter/clutter-private.h +++ b/clutter/clutter/clutter-private.h @@ -37,7 +37,6 @@ #include "clutter/clutter-settings.h" #include "clutter/clutter-stage-manager.h" #include "clutter/clutter-stage.h" -#include "mtk/mtk.h" G_BEGIN_DECLS @@ -201,11 +200,6 @@ void _clutter_util_fully_transform_vertices (const graphene_matrix_t *modelvie graphene_point3d_t *vertices_out, int n_vertices); - -CLUTTER_EXPORT -void _clutter_util_rectangle_int_extents (const graphene_rect_t *src, - MtkRectangle *dest); - CLUTTER_EXPORT PangoDirection _clutter_pango_unichar_direction (gunichar ch); diff --git a/clutter/clutter/clutter-util.c b/clutter/clutter/clutter-util.c index 0abe6c6c7..50f98f60b 100644 --- a/clutter/clutter/clutter-util.c +++ b/clutter/clutter/clutter-util.c @@ -119,22 +119,6 @@ _clutter_util_fully_transform_vertices (const graphene_matrix_t *modelview, } } -void -_clutter_util_rectangle_int_extents (const graphene_rect_t *src, - MtkRectangle *dest) -{ - graphene_rect_t tmp = *src; - - graphene_rect_round_extents (&tmp, &tmp); - - *dest = (MtkRectangle) { - .x = tmp.origin.x, - .y = tmp.origin.y, - .width = tmp.size.width, - .height = tmp.size.height, - }; -} - typedef struct { GType value_type; diff --git a/mtk/mtk/mtk-rectangle.c b/mtk/mtk/mtk-rectangle.c index f8a51e245..35b194348 100644 --- a/mtk/mtk/mtk-rectangle.c +++ b/mtk/mtk/mtk-rectangle.c @@ -297,3 +297,53 @@ mtk_rectangle_to_graphene_rect (MtkRectangle *rect) } }; } + +/** + * mtk_rectangle_from_graphene_rect: + * @rect: A rectangle + * @rounding_strategy: The rounding strategy + * @dest: (out caller-allocates): an empty #MtkRectangle, to be filled + * with the coordinates of `rect`. + */ +void +mtk_rectangle_from_graphene_rect (const graphene_rect_t *rect, + MtkRoundingStrategy rounding_strategy, + MtkRectangle *dest) +{ + switch (rounding_strategy) + { + case MTK_ROUNDING_STRATEGY_SHRINK: + { + *dest = (MtkRectangle) { + .x = ceilf (rect->origin.x), + .y = ceilf (rect->origin.y), + .width = floorf (rect->size.width), + .height = floorf (rect->size.height), + }; + } + break; + case MTK_ROUNDING_STRATEGY_GROW: + { + graphene_rect_t clamped = *rect; + + graphene_rect_round_extents (&clamped, &clamped); + + *dest = (MtkRectangle) { + .x = clamped.origin.x, + .y = clamped.origin.y, + .width = clamped.size.width, + .height = clamped.size.height, + }; + } + break; + case MTK_ROUNDING_STRATEGY_ROUND: + { + *dest = (MtkRectangle) { + .x = roundf (rect->origin.x), + .y = roundf (rect->origin.y), + .width = roundf (rect->size.width), + .height = roundf (rect->size.height), + }; + } + } +} diff --git a/mtk/mtk/mtk-rectangle.h b/mtk/mtk/mtk-rectangle.h index d6b248d92..420ad73a0 100644 --- a/mtk/mtk/mtk-rectangle.h +++ b/mtk/mtk/mtk-rectangle.h @@ -29,6 +29,14 @@ #define MTK_TYPE_RECTANGLE (mtk_rectangle_get_type ()) +typedef enum _MtkRoundingStrategy +{ + MTK_ROUNDING_STRATEGY_SHRINK, + MTK_ROUNDING_STRATEGY_GROW, + MTK_ROUNDING_STRATEGY_ROUND, +} MtkRoundingStrategy; + + /** * MtkRectangle: * @x: X coordinate of the top-left corner @@ -122,3 +130,8 @@ gboolean mtk_rectangle_contains_rect (const MtkRectangle *outer_rect, MTK_EXPORT graphene_rect_t mtk_rectangle_to_graphene_rect (MtkRectangle *rect); +MTK_EXPORT +void mtk_rectangle_from_graphene_rect (const graphene_rect_t *rect, + MtkRoundingStrategy rounding_strategy, + MtkRectangle *dest); + diff --git a/src/backends/meta-monitor.c b/src/backends/meta-monitor.c index 1062926d7..16eddf686 100644 --- a/src/backends/meta-monitor.c +++ b/src/backends/meta-monitor.c @@ -856,9 +856,9 @@ meta_monitor_normal_derive_layout (MetaMonitor *monitor, g_return_if_fail (crtc_config); - meta_rectangle_from_graphene_rect (&crtc_config->layout, - META_ROUNDING_STRATEGY_ROUND, - layout); + mtk_rectangle_from_graphene_rect (&crtc_config->layout, + MTK_ROUNDING_STRATEGY_ROUND, + layout); } static gboolean diff --git a/src/backends/meta-stage-impl.c b/src/backends/meta-stage-impl.c index da0366f89..c35cb36e3 100644 --- a/src/backends/meta-stage-impl.c +++ b/src/backends/meta-stage-impl.c @@ -369,7 +369,8 @@ offset_scale_and_clamp_region (const cairo_region_t *region, tmp = mtk_rectangle_to_graphene_rect (rect); graphene_rect_offset (&tmp, offset_x, offset_y); graphene_rect_scale (&tmp, scale, scale, &tmp); - _clutter_util_rectangle_int_extents (&tmp, rect); + mtk_rectangle_from_graphene_rect (&tmp, MTK_ROUNDING_STRATEGY_GROW, + rect); } return cairo_region_create_rectangles (rects, n_rects); @@ -405,7 +406,9 @@ scale_offset_and_clamp_region (const cairo_region_t *region, tmp = mtk_rectangle_to_graphene_rect (rect); graphene_rect_scale (&tmp, scale, scale, &tmp); graphene_rect_offset (&tmp, offset_x, offset_y); - _clutter_util_rectangle_int_extents (&tmp, rect); + mtk_rectangle_from_graphene_rect (&tmp, + MTK_ROUNDING_STRATEGY_GROW, + rect); } return cairo_region_create_rectangles (rects, n_rects); diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c index 9103c04b2..e1c384958 100644 --- a/src/backends/native/meta-renderer-native.c +++ b/src/backends/native/meta-renderer-native.c @@ -1431,9 +1431,9 @@ meta_renderer_native_create_view (MetaRenderer *renderer, else scale = 1.0; - meta_rectangle_from_graphene_rect (&crtc_config->layout, - META_ROUNDING_STRATEGY_ROUND, - &view_layout); + mtk_rectangle_from_graphene_rect (&crtc_config->layout, + MTK_ROUNDING_STRATEGY_ROUND, + &view_layout); view_native = g_object_new (META_TYPE_RENDERER_VIEW_NATIVE, "name", meta_output_get_name (output), "stage", meta_backend_get_stage (backend), diff --git a/src/backends/x11/nested/meta-renderer-x11-nested.c b/src/backends/x11/nested/meta-renderer-x11-nested.c index ca5ff061a..d89ca1e8c 100644 --- a/src/backends/x11/nested/meta-renderer-x11-nested.c +++ b/src/backends/x11/nested/meta-renderer-x11-nested.c @@ -127,9 +127,9 @@ meta_renderer_x11_nested_create_view (MetaRenderer *renderer, else offscreen = NULL; - meta_rectangle_from_graphene_rect (&crtc_config->layout, - META_ROUNDING_STRATEGY_ROUND, - &view_layout); + mtk_rectangle_from_graphene_rect (&crtc_config->layout, + MTK_ROUNDING_STRATEGY_ROUND, + &view_layout); mode_info = meta_crtc_mode_get_info (crtc_config->mode); diff --git a/src/compositor/meta-shaped-texture.c b/src/compositor/meta-shaped-texture.c index 6f57cd0d0..24bce7161 100644 --- a/src/compositor/meta-shaped-texture.c +++ b/src/compositor/meta-shaped-texture.c @@ -1040,7 +1040,7 @@ meta_shaped_texture_update_area (MetaShapedTexture *stex, meta_rectangle_scale_double (clip, 1.0 / stex->buffer_scale, - META_ROUNDING_STRATEGY_GROW, + MTK_ROUNDING_STRATEGY_GROW, clip); if (meta_monitor_transform_is_rotated (stex->transform)) diff --git a/src/compositor/region-utils.c b/src/compositor/region-utils.c index 29686e026..2d7d138ed 100644 --- a/src/compositor/region-utils.c +++ b/src/compositor/region-utils.c @@ -467,9 +467,9 @@ meta_region_apply_matrix_transform_expand (const cairo_region_t *region, graphene_matrix_transform_bounds (transform, &rect, &transformed_rect); - meta_rectangle_from_graphene_rect (&transformed_rect, - META_ROUNDING_STRATEGY_GROW, - &rects[i]); + mtk_rectangle_from_graphene_rect (&transformed_rect, + MTK_ROUNDING_STRATEGY_GROW, + &rects[i]); } transformed_region = cairo_region_create_rectangles (rects, n_rects); diff --git a/src/core/boxes-private.h b/src/core/boxes-private.h index cdcd4e530..4a9f9d093 100644 --- a/src/core/boxes-private.h +++ b/src/core/boxes-private.h @@ -40,13 +40,6 @@ typedef enum FIXED_DIRECTION_Y = 1 << 1, } FixedDirections; -typedef enum _MetaRoundingStrategy -{ - META_ROUNDING_STRATEGY_SHRINK, - META_ROUNDING_STRATEGY_GROW, - META_ROUNDING_STRATEGY_ROUND, -} MetaRoundingStrategy; - /* Output functions -- note that the output buffer had better be big enough: * rect_to_string: RECT_LENGTH * region_to_string: (RECT_LENGTH+strlen(separator_string)) * @@ -249,10 +242,10 @@ gboolean meta_rectangle_is_adjacent_to (MtkRectangle *rect, MtkRectangle *other); META_EXPORT_TEST -void meta_rectangle_scale_double (const MtkRectangle *rect, - double scale, - MetaRoundingStrategy rounding_strategy, - MtkRectangle *dest); +void meta_rectangle_scale_double (const MtkRectangle *rect, + double scale, + MtkRoundingStrategy rounding_strategy, + MtkRectangle *dest); META_EXPORT_TEST void meta_rectangle_transform (const MtkRectangle *rect, @@ -261,10 +254,6 @@ void meta_rectangle_transform (const MtkRectangle *rect, int height, MtkRectangle *dest); -void meta_rectangle_from_graphene_rect (const graphene_rect_t *rect, - MetaRoundingStrategy rounding_strategy, - MtkRectangle *dest); - void meta_rectangle_crop_and_scale (const MtkRectangle *rect, graphene_rect_t *src_rect, int dst_width, diff --git a/src/core/boxes.c b/src/core/boxes.c index c82af6fb8..915ef9fb2 100644 --- a/src/core/boxes.c +++ b/src/core/boxes.c @@ -1850,16 +1850,16 @@ meta_rectangle_is_adjacent_to (MtkRectangle *rect, } void -meta_rectangle_scale_double (const MtkRectangle *rect, - double scale, - MetaRoundingStrategy rounding_strategy, - MtkRectangle *dest) +meta_rectangle_scale_double (const MtkRectangle *rect, + double scale, + MtkRoundingStrategy rounding_strategy, + MtkRectangle *dest) { graphene_rect_t tmp = GRAPHENE_RECT_INIT (rect->x, rect->y, rect->width, rect->height); graphene_rect_scale (&tmp, scale, scale, &tmp); - meta_rectangle_from_graphene_rect (&tmp, rounding_strategy, dest); + mtk_rectangle_from_graphene_rect (&tmp, rounding_strategy, dest); } /** @@ -1946,49 +1946,6 @@ meta_rectangle_transform (const MtkRectangle *rect, } } -void -meta_rectangle_from_graphene_rect (const graphene_rect_t *rect, - MetaRoundingStrategy rounding_strategy, - MtkRectangle *dest) -{ - switch (rounding_strategy) - { - case META_ROUNDING_STRATEGY_SHRINK: - { - *dest = (MtkRectangle) { - .x = ceilf (rect->origin.x), - .y = ceilf (rect->origin.y), - .width = floorf (rect->size.width), - .height = floorf (rect->size.height), - }; - } - break; - case META_ROUNDING_STRATEGY_GROW: - { - graphene_rect_t clamped = *rect; - - graphene_rect_round_extents (&clamped, &clamped); - - *dest = (MtkRectangle) { - .x = clamped.origin.x, - .y = clamped.origin.y, - .width = clamped.size.width, - .height = clamped.size.height, - }; - } - break; - case META_ROUNDING_STRATEGY_ROUND: - { - *dest = (MtkRectangle) { - .x = roundf (rect->origin.x), - .y = roundf (rect->origin.y), - .width = roundf (rect->size.width), - .height = roundf (rect->size.height), - }; - } - } -} - void meta_rectangle_crop_and_scale (const MtkRectangle *rect, graphene_rect_t *src_rect, @@ -2005,5 +1962,5 @@ meta_rectangle_crop_and_scale (const MtkRectangle *rect, &tmp); graphene_rect_offset (&tmp, src_rect->origin.x, src_rect->origin.y); - meta_rectangle_from_graphene_rect (&tmp, META_ROUNDING_STRATEGY_GROW, dest); + mtk_rectangle_from_graphene_rect (&tmp, MTK_ROUNDING_STRATEGY_GROW, dest); }