1
0
Fork 0

mtk: Move meta_rectangle_transform to Mtk

Both MtkMonitorTransform and MtkRectangle are Mtk types, so we can push
this into Mtk and start using it in Clutter as well.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3930>
This commit is contained in:
Sebastian Wick 2024-08-07 22:46:36 +02:00 committed by Marge Bot
parent 89af55d8aa
commit dcaa57c2c8
7 changed files with 114 additions and 113 deletions

View file

@ -23,7 +23,6 @@
#include "mtk/mtk-rectangle.h" #include "mtk/mtk-rectangle.h"
MtkRectangle * MtkRectangle *
mtk_rectangle_copy (const MtkRectangle *rect) mtk_rectangle_copy (const MtkRectangle *rect)
{ {
@ -445,3 +444,87 @@ mtk_rectangle_is_adjacent_to (const MtkRectangle *rect,
else else
return FALSE; return FALSE;
} }
/**
* mtk_rectangle_transform:
* @rect: the #MtkRectangle to be transformed
* @transform: the #MtkMonitorTransform
* @width: the width of the target space
* @height: the height of the target space
* @dest: the transformed #MtkRectangle
*
* This function transforms the values in @rect in order to compensate for
* @transform applied to a #MetaMonitor, making them match the viewport. Note
* that compensating implies that for a clockwise rotation of the #MetaMonitor
* an anti-clockwise rotation has to be applied to @rect.
*/
void
mtk_rectangle_transform (const MtkRectangle *rect,
MtkMonitorTransform transform,
int width,
int height,
MtkRectangle *dest)
{
switch (transform)
{
case MTK_MONITOR_TRANSFORM_NORMAL:
*dest = *rect;
break;
case MTK_MONITOR_TRANSFORM_90:
*dest = (MtkRectangle) {
.x = rect->y,
.y = height - (rect->x + rect->width),
.width = rect->height,
.height = rect->width,
};
break;
case MTK_MONITOR_TRANSFORM_180:
*dest = (MtkRectangle) {
.x = width - (rect->x + rect->width),
.y = height - (rect->y + rect->height),
.width = rect->width,
.height = rect->height,
};
break;
case MTK_MONITOR_TRANSFORM_270:
*dest = (MtkRectangle) {
.x = width - (rect->y + rect->height),
.y = rect->x,
.width = rect->height,
.height = rect->width,
};
break;
case MTK_MONITOR_TRANSFORM_FLIPPED:
*dest = (MtkRectangle) {
.x = width - (rect->x + rect->width),
.y = rect->y,
.width = rect->width,
.height = rect->height,
};
break;
case MTK_MONITOR_TRANSFORM_FLIPPED_90:
*dest = (MtkRectangle) {
.x = rect->y,
.y = rect->x,
.width = rect->height,
.height = rect->width,
};
break;
case MTK_MONITOR_TRANSFORM_FLIPPED_180:
*dest = (MtkRectangle) {
.x = rect->x,
.y = height - (rect->y + rect->height),
.width = rect->width,
.height = rect->height,
};
break;
case MTK_MONITOR_TRANSFORM_FLIPPED_270:
*dest = (MtkRectangle) {
.x = width - (rect->y + rect->height),
.y = height - (rect->x + rect->width),
.width = rect->height,
.height = rect->width,
};
break;
}
}

View file

@ -25,6 +25,7 @@
#include <graphene.h> #include <graphene.h>
#include "mtk/mtk-macros.h" #include "mtk/mtk-macros.h"
#include "mtk/mtk-monitor-transform.h"
#define MTK_TYPE_RECTANGLE (mtk_rectangle_get_type ()) #define MTK_TYPE_RECTANGLE (mtk_rectangle_get_type ())
@ -161,4 +162,13 @@ MTK_EXPORT
gboolean mtk_rectangle_is_adjacent_to (const MtkRectangle *rect, gboolean mtk_rectangle_is_adjacent_to (const MtkRectangle *rect,
const MtkRectangle *other); const MtkRectangle *other);
MTK_EXPORT
void mtk_rectangle_transform (const MtkRectangle *rect,
MtkMonitorTransform transform,
int width,
int height,
MtkRectangle *dest);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MtkRectangle, mtk_rectangle_free) G_DEFINE_AUTOPTR_CLEANUP_FUNC (MtkRectangle, mtk_rectangle_free)

View file

@ -111,11 +111,11 @@ meta_renderer_view_transform_rect_to_onscreen (ClutterStageView *view,
MetaRendererViewPrivate *priv = MetaRendererViewPrivate *priv =
meta_renderer_view_get_instance_private (renderer_view); meta_renderer_view_get_instance_private (renderer_view);
meta_rectangle_transform (src_rect, mtk_rectangle_transform (src_rect,
priv->transform, priv->transform,
dst_width, dst_width,
dst_height, dst_height,
dst_rect); dst_rect);
} }
static void static void

View file

@ -1252,11 +1252,11 @@ meta_shaped_texture_update_area (MetaShapedTexture *stex,
scaled_and_transformed_height = stex->tex_height / stex->buffer_scale; scaled_and_transformed_height = stex->tex_height / stex->buffer_scale;
} }
inverted_transform = mtk_monitor_transform_invert (stex->transform); inverted_transform = mtk_monitor_transform_invert (stex->transform);
meta_rectangle_transform (clip, mtk_rectangle_transform (clip,
inverted_transform, inverted_transform,
scaled_and_transformed_width, scaled_and_transformed_width,
scaled_and_transformed_height, scaled_and_transformed_height,
clip); clip);
if (stex->has_viewport_src_rect || stex->has_viewport_dst_size) if (stex->has_viewport_src_rect || stex->has_viewport_dst_size)
{ {

View file

@ -237,10 +237,3 @@ META_EXPORT_TEST
GList* meta_rectangle_find_nonintersected_monitor_edges ( GList* meta_rectangle_find_nonintersected_monitor_edges (
const GList *monitor_rects, const GList *monitor_rects,
const GSList *all_struts); const GSList *all_struts);
META_EXPORT_TEST
void meta_rectangle_transform (const MtkRectangle *rect,
MtkMonitorTransform transform,
int width,
int height,
MtkRectangle *dest);

View file

@ -1825,88 +1825,3 @@ meta_rectangle_find_nonintersected_monitor_edges (
return ret; return ret;
} }
/**
* meta_rectangle_transform:
* @rect: the #MtkRectangle to be transformed
* @transform: the #MtkMonitorTransform
* @width: the width of the target space
* @height: the height of the target space
* @dest: the transformed #MtkRectangle
*
* This function transforms the values in @rect in order to compensate for
* @transform applied to a #MetaMonitor, making them match the viewport. Note
* that compensating implies that for a clockwise rotation of the #MetaMonitor
* an anti-clockwise rotation has to be applied to @rect.
*/
void
meta_rectangle_transform (const MtkRectangle *rect,
MtkMonitorTransform transform,
int width,
int height,
MtkRectangle *dest)
{
switch (transform)
{
case MTK_MONITOR_TRANSFORM_NORMAL:
*dest = *rect;
break;
case MTK_MONITOR_TRANSFORM_90:
*dest = (MtkRectangle) {
.x = rect->y,
.y = height - (rect->x + rect->width),
.width = rect->height,
.height = rect->width,
};
break;
case MTK_MONITOR_TRANSFORM_180:
*dest = (MtkRectangle) {
.x = width - (rect->x + rect->width),
.y = height - (rect->y + rect->height),
.width = rect->width,
.height = rect->height,
};
break;
case MTK_MONITOR_TRANSFORM_270:
*dest = (MtkRectangle) {
.x = width - (rect->y + rect->height),
.y = rect->x,
.width = rect->height,
.height = rect->width,
};
break;
case MTK_MONITOR_TRANSFORM_FLIPPED:
*dest = (MtkRectangle) {
.x = width - (rect->x + rect->width),
.y = rect->y,
.width = rect->width,
.height = rect->height,
};
break;
case MTK_MONITOR_TRANSFORM_FLIPPED_90:
*dest = (MtkRectangle) {
.x = rect->y,
.y = rect->x,
.width = rect->height,
.height = rect->width,
};
break;
case MTK_MONITOR_TRANSFORM_FLIPPED_180:
*dest = (MtkRectangle) {
.x = rect->x,
.y = height - (rect->y + rect->height),
.width = rect->width,
.height = rect->height,
};
break;
case MTK_MONITOR_TRANSFORM_FLIPPED_270:
*dest = (MtkRectangle) {
.x = width - (rect->y + rect->height),
.y = height - (rect->x + rect->width),
.width = rect->height,
.height = rect->width,
};
break;
}
}

View file

@ -278,11 +278,11 @@ region_transform (const MtkRegion *region,
{ {
rects[i] = mtk_region_get_rectangle (region, i); rects[i] = mtk_region_get_rectangle (region, i);
meta_rectangle_transform (&rects[i], mtk_rectangle_transform (&rects[i],
transform, transform,
width, width,
height, height,
&rects[i]); &rects[i]);
} }
transformed_region = mtk_region_create_rectangles (rects, n_rects); transformed_region = mtk_region_create_rectangles (rects, n_rects);
@ -2364,11 +2364,11 @@ meta_wayland_surface_try_acquire_scanout (MetaWaylandSurface *surface,
untransformed_view_height = view_rect.height; untransformed_view_height = view_rect.height;
} }
meta_rectangle_transform (&dst_rect, mtk_rectangle_transform (&dst_rect,
view_transform, view_transform,
untransformed_view_width, untransformed_view_width,
untransformed_view_height, untransformed_view_height,
&dst_rect); &dst_rect);
/* Use an implicit destination rect when possible */ /* Use an implicit destination rect when possible */
if (surface->viewport.has_dst_size || if (surface->viewport.has_dst_size ||