boxes: Add API to transform a MetaRectangle

To be used if not a whole region needs to get transformed.
It also has an argument for reverse-transforms.

https://gitlab.gnome.org/GNOME/mutter/merge_requests/366
This commit is contained in:
Robert Mader 2018-12-21 17:12:49 +01:00
parent b7a9c7e7d3
commit 686b7f8baa
3 changed files with 90 additions and 43 deletions

View File

@ -22,6 +22,7 @@
#include "backends/meta-monitor-transform.h"
#include "compositor/region-utils.h"
#include "core/boxes-private.h"
#include <math.h>
@ -392,51 +393,13 @@ meta_region_transform (cairo_region_t *region,
rects = g_new0 (cairo_rectangle_int_t, n_rects);
for (i = 0; i < n_rects; i++)
{
cairo_rectangle_int_t rect;
cairo_region_get_rectangle (region, i, &rects[i]);
rect = rects[i];
switch (transform)
{
case META_MONITOR_TRANSFORM_90:
rects[i].x = width - (rect.y + rect.height);
rects[i].y = rect.x;
rects[i].width = rect.height;
rects[i].height = rect.width;
break;
case META_MONITOR_TRANSFORM_180:
rects[i].x = width - (rect.x + rect.width);
rects[i].y = height - (rect.y + rect.height);
break;
case META_MONITOR_TRANSFORM_270:
rects[i].x = rect.y;
rects[i].y = height - (rect.x + rect.width);
rects[i].width = rect.height;
rects[i].height = rect.width;
break;
case META_MONITOR_TRANSFORM_FLIPPED:
rects[i].x = width - (rect.x + rect.width);
break;
case META_MONITOR_TRANSFORM_FLIPPED_90:
rects[i].x = width - (rect.y + rect.height);
rects[i].y = height - (rect.x + rect.width);
rects[i].width = rect.height;
rects[i].height = rect.width;
break;
case META_MONITOR_TRANSFORM_FLIPPED_180:
rects[i].y = height - (rect.y + rect.height);
break;
case META_MONITOR_TRANSFORM_FLIPPED_270:
rects[i].x = rect.y;
rects[i].y = rect.x;
rects[i].width = rect.height;
rects[i].height = rect.width;
break;
case META_MONITOR_TRANSFORM_NORMAL:
g_assert_not_reached ();
}
meta_rectangle_transform (&rects[i],
transform,
width,
height,
&rects[i]);
}
transformed_region = cairo_region_create_rectangles (rects, n_rects);

View File

@ -24,6 +24,7 @@
#include <glib-object.h>
#include "backends/meta-backend-types.h"
#include "meta/boxes.h"
#include "meta/common.h"
@ -245,4 +246,10 @@ meta_rectangle_to_clutter_rect (MetaRectangle *rect)
};
}
void meta_rectangle_transform (const MetaRectangle *rect,
MetaMonitorTransform transform,
int width,
int height,
MetaRectangle *dest);
#endif /* META_BOXES_PRIVATE_H */

View File

@ -30,6 +30,7 @@
#include "config.h"
#include "backends/meta-monitor-transform.h"
#include "core/boxes-private.h"
#include <X11/Xutil.h>
@ -2071,3 +2072,79 @@ meta_rectangle_scale_double (const MetaRectangle *rect,
break;
}
}
void
meta_rectangle_transform (const MetaRectangle *rect,
MetaMonitorTransform transform,
int width,
int height,
MetaRectangle *dest)
{
switch (transform)
{
case META_MONITOR_TRANSFORM_NORMAL:
*dest = (MetaRectangle) {
.x = rect->x,
.y = rect->y,
.width = rect->width,
.height = rect->height,
};
break;
case META_MONITOR_TRANSFORM_90:
*dest = (MetaRectangle) {
.x = width - (rect->y + rect->height),
.y = rect->x,
.width = rect->height,
.height = rect->width,
};
break;
case META_MONITOR_TRANSFORM_180:
*dest = (MetaRectangle) {
.x = width - (rect->x + rect->width),
.y = height - (rect->y + rect->height),
.width = rect->width,
.height = rect->height,
};
break;
case META_MONITOR_TRANSFORM_270:
*dest = (MetaRectangle) {
.x = rect->y,
.y = height - (rect->x + rect->width),
.width = rect->height,
.height = rect->width,
};
break;
case META_MONITOR_TRANSFORM_FLIPPED:
*dest = (MetaRectangle) {
.x = width - (rect->x + rect->width),
.y = rect->y,
.width = rect->width,
.height = rect->height,
};
break;
case META_MONITOR_TRANSFORM_FLIPPED_90:
*dest = (MetaRectangle) {
.x = width - (rect->y + rect->height),
.y = height - (rect->x + rect->width),
.width = rect->height,
.height = rect->width,
};
break;
case META_MONITOR_TRANSFORM_FLIPPED_180:
*dest = (MetaRectangle) {
.x = rect->x,
.y = height - (rect->y + rect->height),
.width = rect->width,
.height = rect->height,
};
break;
case META_MONITOR_TRANSFORM_FLIPPED_270:
*dest = (MetaRectangle) {
.x = rect->y,
.y = rect->x,
.width = rect->height,
.height = rect->width,
};
break;
}
}