stage: don't call glGetIntegerv in clutter_stage_read_pixels
authorRobert Bragg <robert@linux.intel.com>
Tue, 1 Feb 2011 18:15:50 +0000 (18:15 +0000)
committerRobert Bragg <robert@linux.intel.com>
Mon, 7 Mar 2011 13:26:19 +0000 (13:26 +0000)
Firstly Clutter shouldn't be using OpenGL directly so this needed
changing but also conceptually it doesn't make sense for
clutter_stage_read_pixels to validate the requested area to read against
the viewport it would make more sense to compare against the window
size. Finally checking that the width of the area is less than the
viewport or window width without considering the x isn't enough to know
if the area extends outside the windows bounds. (same for the height)

This patch removes the validation of the read area from
clutter_stage_read_pixels and instead we now simply rely on the
semantics of cogl_read_pixels for reading areas outside the window
bounds.

clutter/clutter-stage.c

index f81d319..f52631b 100644 (file)
@@ -2186,35 +2186,24 @@ clutter_stage_read_pixels (ClutterStage *stage,
                            gint          width,
                            gint          height)
 {
+  ClutterGeometry geom;
   guchar *pixels;
-  GLint   viewport[4];
-  gint    rowstride;
-  gint    stage_width, stage_height;
 
   g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);
 
-  /* according to glReadPixels documentation pixels outside the viewport are
-   * undefined, but no error should be provoked, thus this is probably unnneed.
-   */
-  g_return_val_if_fail (x >= 0 && y >= 0, NULL);
-
   /* Force a redraw of the stage before reading back pixels */
   clutter_stage_ensure_current (stage);
   clutter_actor_paint (CLUTTER_ACTOR (stage));
 
-  glGetIntegerv (GL_VIEWPORT, viewport);
-  stage_width  = viewport[2];
-  stage_height = viewport[3];
-
-  if (width < 0 || width > stage_width)
-    width = stage_width;
+  clutter_actor_get_allocation_geometry (CLUTTER_ACTOR (stage), &geom);
 
-  if (height < 0 || height > stage_height)
-    height = stage_height;
+  if (width < 0)
+    width = geom.width;
 
-  rowstride = width * 4;
+  if (height < 0)
+    height = geom.height;
 
-  pixels  = g_malloc (height * rowstride);
+  pixels = g_malloc (height * width * 4);
 
   cogl_read_pixels (x, y, width, height,
                     COGL_READ_PIXELS_COLOR_BUFFER,