[mutter] clutter: Fix capture_into on non-origin view



commit ba194bd19e2f9bb045bf0a14b94429745fb27a66
Author: Jonas Ådahl <jadahl gmail com>
Date:   Fri Sep 15 16:25:19 2017 +0800

    clutter: Fix capture_into on non-origin view
    
    The capture_into() function wrote out of bounds when capturing from a
    non-origin view (not positioned at (0,0)). At the time of
    implementation, this API was used to capture pixels across views into a
    single data buffer, but the way it's used, and the way views may work
    now, makes this impossible to do properly.
    
    So remove the ability to capture into a pre-allocated buffer from
    multiple views, and complain if the passed rectantgle overlapps with
    multiple views. This removes the broken offset calculation all
    together, fixing the bug motivating this change.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=787715

 clutter/clutter/clutter-stage.c |   31 +++++++++++++++++++++----------
 1 files changed, 21 insertions(+), 10 deletions(-)
---
diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c
index 2940611..02ab07b 100644
--- a/clutter/clutter/clutter-stage.c
+++ b/clutter/clutter/clutter-stage.c
@@ -4856,11 +4856,9 @@ capture_view_into (ClutterStage          *stage,
   cogl_object_unref (bitmap);
 }
 
-void
-clutter_stage_capture_into (ClutterStage          *stage,
-                            gboolean               paint,
-                            cairo_rectangle_int_t *rect,
-                            uint8_t               *data)
+static ClutterStageView *
+get_view_at_rect (ClutterStage          *stage,
+                  cairo_rectangle_int_t *rect)
 {
   ClutterStagePrivate *priv = stage->priv;
   GList *views = _clutter_stage_window_get_views (priv->impl);
@@ -4872,8 +4870,6 @@ clutter_stage_capture_into (ClutterStage          *stage,
       cairo_rectangle_int_t view_layout;
       cairo_region_t *region;
       cairo_rectangle_int_t view_capture_rect;
-      int offset;
-      const int bpp = 4;
 
       clutter_stage_view_get_layout (view, &view_layout);
       region = cairo_region_create_rectangle (&view_layout);
@@ -4884,8 +4880,23 @@ clutter_stage_capture_into (ClutterStage          *stage,
       if (view_capture_rect.width == 0 || view_capture_rect.height == 0)
         continue;
 
-      offset = bpp * (view_capture_rect.y * rect->width + view_capture_rect.x);
-      capture_view_into (stage, paint, view, &view_capture_rect,
-                         data + offset, rect->width * bpp);
+      g_assert (view_capture_rect.width == rect->width &&
+                view_capture_rect.height == rect->height);
+      return view;
     }
+
+  return NULL;
+}
+
+void
+clutter_stage_capture_into (ClutterStage          *stage,
+                            gboolean               paint,
+                            cairo_rectangle_int_t *rect,
+                            uint8_t               *data)
+{
+  ClutterStageView *view;
+  int bpp = 4;
+
+  view = get_view_at_rect (stage, rect);
+  capture_view_into (stage, paint, view, rect, data, rect->width * bpp);
 }


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