[mutter] region-utils: Add API to crop and scale an integer region



commit 07e65a6ef27aff594a748d235a1594300578c474
Author: Robert Mader <robert mader posteo de>
Date:   Sat Jan 5 16:41:35 2019 +0100

    region-utils: Add API to crop and scale an integer region
    
    https://gitlab.gnome.org/GNOME/mutter/merge_requests/323

 src/compositor/region-utils.c | 48 +++++++++++++++++++++++++++++++++++++++++++
 src/compositor/region-utils.h |  5 +++++
 2 files changed, 53 insertions(+)
---
diff --git a/src/compositor/region-utils.c b/src/compositor/region-utils.c
index 3a5839695..752af85c5 100644
--- a/src/compositor/region-utils.c
+++ b/src/compositor/region-utils.c
@@ -408,3 +408,51 @@ meta_region_transform (cairo_region_t       *region,
 
   return transformed_region;
 }
+
+cairo_region_t *
+meta_region_crop_and_scale (cairo_region_t *region,
+                            ClutterRect    *src_rect,
+                            int             dst_width,
+                            int             dst_height)
+{
+  int n_rects, i;
+  cairo_rectangle_int_t *rects;
+  cairo_region_t *viewport_region;
+
+  if (src_rect->size.width == dst_width &&
+      src_rect->size.height == dst_height &&
+      roundf (src_rect->origin.x) == src_rect->origin.x &&
+      roundf (src_rect->origin.y) == src_rect->origin.y)
+    {
+      viewport_region = cairo_region_copy (region);
+
+      if (src_rect->origin.x != 0 || src_rect->origin.y != 0)
+        {
+          cairo_region_translate (viewport_region,
+                                  (int) src_rect->origin.x,
+                                  (int) src_rect->origin.y);
+        }
+
+      return viewport_region;
+    }
+
+  n_rects = cairo_region_num_rectangles (region);
+
+  rects = g_new0 (cairo_rectangle_int_t, n_rects);
+  for (i = 0; i < n_rects; i++)
+    {
+      cairo_region_get_rectangle (region, i, &rects[i]);
+
+      meta_rectangle_crop_and_scale (&rects[i],
+                                     src_rect,
+                                     dst_width,
+                                     dst_height,
+                                     &rects[i]);
+    }
+
+  viewport_region = cairo_region_create_rectangles (rects, n_rects);
+
+  g_free (rects);
+
+  return viewport_region;
+}
diff --git a/src/compositor/region-utils.h b/src/compositor/region-utils.h
index 473022b7e..84e4d83bc 100644
--- a/src/compositor/region-utils.h
+++ b/src/compositor/region-utils.h
@@ -111,4 +111,9 @@ cairo_region_t * meta_region_transform (cairo_region_t       *region,
                                         int                   width,
                                         int                   height);
 
+cairo_region_t * meta_region_crop_and_scale (cairo_region_t *region,
+                                             ClutterRect    *src_rect,
+                                             int             dst_width,
+                                             int             dst_height);
+
 #endif /* __META_REGION_UTILS_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]