stage: don't call glGetIntegerv in clutter_stage_read_pixels

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.
This commit is contained in:
Robert Bragg 2011-02-01 18:15:50 +00:00
parent 013b2433f0
commit 1431b77747

View 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];
clutter_actor_get_allocation_geometry (CLUTTER_ACTOR (stage), &geom);
if (width < 0 || width > stage_width)
width = stage_width;
if (width < 0)
width = geom.width;
if (height < 0 || height > stage_height)
height = stage_height;
if (height < 0)
height = geom.height;
rowstride = width * 4;
pixels = g_malloc (height * rowstride);
pixels = g_malloc (height * width * 4);
cogl_read_pixels (x, y, width, height,
COGL_READ_PIXELS_COLOR_BUFFER,