summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@chris-wilson.co.uk>2012-05-30 11:10:34 +0100
committerChris Wilson <chris@chris-wilson.co.uk>2012-05-30 11:10:34 +0100
commitf3a1ee5edd1a46e3c316d8555262bce556bc1480 (patch)
tree6ae7ae8792d6877fdffb0b914ebc99222f6fe928
parent9340fcd965dedf714f658c6ad441787d75c05e59 (diff)
gl: Do no access ctx after release during map-to-image
Based on a patch by Yuanhan Liu. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
-rw-r--r--src/cairo-gl-surface.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/cairo-gl-surface.c b/src/cairo-gl-surface.c
index a6093b4b..6b9bc670 100644
--- a/src/cairo-gl-surface.c
+++ b/src/cairo-gl-surface.c
@@ -995,7 +995,7 @@ _cairo_gl_surface_map_to_image (void *abstract_surface,
GLenum format, type;
pixman_format_code_t pixman_format;
unsigned int cpp;
- cairo_bool_t invert;
+ cairo_bool_t flipped, mesa_invert;
cairo_status_t status;
int y;
@@ -1070,23 +1070,23 @@ _cairo_gl_surface_map_to_image (void *abstract_surface,
_cairo_gl_composite_flush (ctx);
_cairo_gl_context_set_destination (ctx, surface, FALSE);
- invert = ! _cairo_gl_surface_is_texture (surface) &&
- ctx->has_mesa_pack_invert;
+ flipped = ! _cairo_gl_surface_is_texture (surface);
+ mesa_invert = flipped && ctx->has_mesa_pack_invert;
glPixelStorei (GL_PACK_ALIGNMENT, 4);
if (ctx->gl_flavor == CAIRO_GL_FLAVOR_DESKTOP)
glPixelStorei (GL_PACK_ROW_LENGTH, image->stride / cpp);
- if (invert)
+ if (mesa_invert)
glPixelStorei (GL_PACK_INVERT_MESA, 1);
y = extents->y;
- if (! _cairo_gl_surface_is_texture (surface))
+ if (flipped)
y = surface->height - extents->y - extents->height;
glReadPixels (extents->x, y,
extents->width, extents->height,
format, type, image->data);
- if (invert)
+ if (mesa_invert)
glPixelStorei (GL_PACK_INVERT_MESA, 0);
status = _cairo_gl_context_release (ctx, status);
@@ -1096,12 +1096,12 @@ _cairo_gl_surface_map_to_image (void *abstract_surface,
}
/* We must invert the image manualy if we lack GL_MESA_pack_invert */
- if (! ctx->has_mesa_pack_invert && ! _cairo_gl_surface_is_texture (surface)) {
+ if (flipped && ! mesa_invert) {
uint8_t stack[1024], *row = stack;
uint8_t *top = image->data;
uint8_t *bot = image->data + (image->height-1)*image->stride;
- if (image->stride > sizeof(stack)) {
+ if (image->stride > (int)sizeof(stack)) {
row = malloc (image->stride);
if (unlikely (row == NULL)) {
cairo_surface_destroy (&image->base);