mtk: Move Rectangle.from_graphene_rect from Meta

And drop the clutter helper

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3128>
This commit is contained in:
Bilal Elmoussaoui 2023-08-08 13:07:54 +02:00
parent 152fdc89fc
commit 1abef24154
12 changed files with 91 additions and 101 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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),
};
}
}
}

View File

@ -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);

View File

@ -856,8 +856,8 @@ 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,
mtk_rectangle_from_graphene_rect (&crtc_config->layout,
MTK_ROUNDING_STRATEGY_ROUND,
layout);
}

View File

@ -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);

View File

@ -1431,8 +1431,8 @@ meta_renderer_native_create_view (MetaRenderer *renderer,
else
scale = 1.0;
meta_rectangle_from_graphene_rect (&crtc_config->layout,
META_ROUNDING_STRATEGY_ROUND,
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),

View File

@ -127,8 +127,8 @@ meta_renderer_x11_nested_create_view (MetaRenderer *renderer,
else
offscreen = NULL;
meta_rectangle_from_graphene_rect (&crtc_config->layout,
META_ROUNDING_STRATEGY_ROUND,
mtk_rectangle_from_graphene_rect (&crtc_config->layout,
MTK_ROUNDING_STRATEGY_ROUND,
&view_layout);
mode_info = meta_crtc_mode_get_info (crtc_config->mode);

View File

@ -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))

View File

@ -467,8 +467,8 @@ 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,
mtk_rectangle_from_graphene_rect (&transformed_rect,
MTK_ROUNDING_STRATEGY_GROW,
&rects[i]);
}

View File

@ -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)) *
@ -251,7 +244,7 @@ gboolean meta_rectangle_is_adjacent_to (MtkRectangle *rect,
META_EXPORT_TEST
void meta_rectangle_scale_double (const MtkRectangle *rect,
double scale,
MetaRoundingStrategy rounding_strategy,
MtkRoundingStrategy rounding_strategy,
MtkRectangle *dest);
META_EXPORT_TEST
@ -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,

View File

@ -1852,14 +1852,14 @@ meta_rectangle_is_adjacent_to (MtkRectangle *rect,
void
meta_rectangle_scale_double (const MtkRectangle *rect,
double scale,
MetaRoundingStrategy rounding_strategy,
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);
}