bitmap: don't mark bitmap bound on _gl_bind error

This makes some changes to _cogl_bitmap_gl_bind to be more paranoid
about bad access arguments and make sure we don't mark a bitmap as bound
if there was an error in _cogl_buffer_gl_bind.

We now validate the access argument upfront to check that one of _READ
or _WRITE access has been requested. In the case that cogl is built
without debug support then we will still detect a bad access argument
later and now explicitly return before marking the bitmap as bound, just
in case the g_assert_not_reach has been somehow disabled. Finally we
defer setting bitmap->bound = TRUE until after we have check for any
error with _cogl_bitmap_gl_bind.

https://bugzilla.gnome.org/show_bug.cgi?id=686770

Reviewed-by: Neil Roberts <neil@linux.intel.com>

(cherry picked from commit 1720d5cf32449a189fd9d400cf5e6696cd50a9fa)
This commit is contained in:
Robert Bragg 2013-02-28 17:48:34 +00:00
parent bfea34b897
commit b62b9a68bb

View File

@ -447,6 +447,10 @@ _cogl_bitmap_gl_bind (CoglBitmap *bitmap,
uint8_t *ptr; uint8_t *ptr;
CoglError *internal_error = NULL; CoglError *internal_error = NULL;
g_return_val_if_fail (access & (COGL_BUFFER_ACCESS_READ |
COGL_BUFFER_ACCESS_WRITE),
NULL);
/* Divert to another bitmap if this data is shared */ /* Divert to another bitmap if this data is shared */
if (bitmap->shared_bmp) if (bitmap->shared_bmp)
return _cogl_bitmap_gl_bind (bitmap->shared_bmp, access, hints, error); return _cogl_bitmap_gl_bind (bitmap->shared_bmp, access, hints, error);
@ -463,8 +467,6 @@ _cogl_bitmap_gl_bind (CoglBitmap *bitmap,
return data; return data;
} }
bitmap->bound = TRUE;
if (access == COGL_BUFFER_ACCESS_READ) if (access == COGL_BUFFER_ACCESS_READ)
ptr = _cogl_buffer_gl_bind (bitmap->buffer, ptr = _cogl_buffer_gl_bind (bitmap->buffer,
COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK, COGL_BUFFER_BIND_TARGET_PIXEL_UNPACK,
@ -477,6 +479,7 @@ _cogl_bitmap_gl_bind (CoglBitmap *bitmap,
{ {
ptr = NULL; ptr = NULL;
g_assert_not_reached (); g_assert_not_reached ();
return NULL;
} }
/* NB: _cogl_buffer_gl_bind() may return NULL in non-error /* NB: _cogl_buffer_gl_bind() may return NULL in non-error
@ -488,6 +491,8 @@ _cogl_bitmap_gl_bind (CoglBitmap *bitmap,
return NULL; return NULL;
} }
bitmap->bound = TRUE;
/* The data pointer actually stores the offset */ /* The data pointer actually stores the offset */
return ptr + GPOINTER_TO_INT (bitmap->data); return ptr + GPOINTER_TO_INT (bitmap->data);
} }