[mutter] boxes: Add helper to scale rectangles by a double
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] boxes: Add helper to scale rectangles by a double
- Date: Thu, 3 Jan 2019 11:20:06 +0000 (UTC)
commit 36b46af92f77a28053ce330f1173cf2143870514
Author: Jonas Ã…dahl <jadahl gmail com>
Date: Thu Dec 20 16:58:03 2018 +0100
boxes: Add helper to scale rectangles by a double
And change the similar region scaling helper to use this one.
https://gitlab.gnome.org/GNOME/mutter/merge_requests/362
src/compositor/region-utils.c | 17 ++---------------
src/compositor/region-utils.h | 7 +------
src/core/boxes-private.h | 11 +++++++++++
src/core/boxes.c | 27 +++++++++++++++++++++++++++
4 files changed, 41 insertions(+), 21 deletions(-)
---
diff --git a/src/compositor/region-utils.c b/src/compositor/region-utils.c
index 1c1bd2664..4d2ae1df0 100644
--- a/src/compositor/region-utils.c
+++ b/src/compositor/region-utils.c
@@ -195,21 +195,8 @@ meta_region_scale_double (cairo_region_t *region,
{
cairo_region_get_rectangle (region, i, &rects[i]);
- switch (rounding_strategy)
- {
- case META_ROUNDING_STRATEGY_SHRINK:
- rects[i].x = (int) ceil (rects[i].x * scale);
- rects[i].y = (int) ceil (rects[i].y * scale);
- rects[i].width = (int) floor (rects[i].width * scale);
- rects[i].height = (int) floor (rects[i].height * scale);
- break;
- case META_ROUNDING_STRATEGY_GROW:
- rects[i].x = (int) floor (rects[i].x * scale);
- rects[i].y = (int) floor (rects[i].y * scale);
- rects[i].width = (int) ceil (rects[i].width * scale);
- rects[i].height = (int) ceil (rects[i].height * scale);
- break;
- }
+ meta_rectangle_scale_double (&rects[i], scale, rounding_strategy,
+ &rects[i]);
}
scaled_region = cairo_region_create_rectangles (rects, n_rects);
diff --git a/src/compositor/region-utils.h b/src/compositor/region-utils.h
index 4a9dd8170..473022b7e 100644
--- a/src/compositor/region-utils.h
+++ b/src/compositor/region-utils.h
@@ -26,12 +26,7 @@
#include "backends/meta-backend-types.h"
#include "clutter/clutter.h"
-
-typedef enum _MetaRoundingStrategy
-{
- META_ROUNDING_STRATEGY_SHRINK,
- META_ROUNDING_STRATEGY_GROW,
-} MetaRoundingStrategy;
+#include "core/boxes-private.h"
/**
* MetaRegionIterator:
diff --git a/src/core/boxes-private.h b/src/core/boxes-private.h
index 0fbed2059..4c6fd08ab 100644
--- a/src/core/boxes-private.h
+++ b/src/core/boxes-private.h
@@ -39,6 +39,12 @@ typedef enum
FIXED_DIRECTION_Y = 1 << 1,
} FixedDirections;
+typedef enum _MetaRoundingStrategy
+{
+ META_ROUNDING_STRATEGY_SHRINK,
+ META_ROUNDING_STRATEGY_GROW,
+} 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)) *
@@ -219,6 +225,11 @@ GList* meta_rectangle_find_nonintersected_monitor_edges (
gboolean meta_rectangle_is_adjecent_to (MetaRectangle *rect,
MetaRectangle *other);
+void meta_rectangle_scale_double (const MetaRectangle *rect,
+ double scale,
+ MetaRoundingStrategy rounding_strategy,
+ MetaRectangle *dest);
+
static inline ClutterRect
meta_rectangle_to_clutter_rect (MetaRectangle *rect)
{
diff --git a/src/core/boxes.c b/src/core/boxes.c
index 2725dfcbe..98a8d3586 100644
--- a/src/core/boxes.c
+++ b/src/core/boxes.c
@@ -2044,3 +2044,30 @@ meta_rectangle_is_adjecent_to (MetaRectangle *rect,
else
return FALSE;
}
+
+void
+meta_rectangle_scale_double (const MetaRectangle *rect,
+ double scale,
+ MetaRoundingStrategy rounding_strategy,
+ MetaRectangle *dest)
+{
+ switch (rounding_strategy)
+ {
+ case META_ROUNDING_STRATEGY_SHRINK:
+ *dest = (MetaRectangle) {
+ .x = (int) ceil (rect->x * scale),
+ .y = (int) ceil (rect->y * scale),
+ .width = (int) floor (rect->width * scale),
+ .height = (int) floor (rect->height * scale),
+ };
+ break;
+ case META_ROUNDING_STRATEGY_GROW:
+ *dest = (MetaRectangle) {
+ .x = (int) floor (rect->x * scale),
+ .y = (int) floor (rect->y * scale),
+ .width = (int) ceil (rect->width * scale),
+ .height = (int) ceil (rect->height * scale),
+ };
+ break;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]