diff --git a/cogl/cogl-atlas-texture.c b/cogl/cogl-atlas-texture.c index 2701b8774..d0be83dac 100644 --- a/cogl/cogl-atlas-texture.c +++ b/cogl/cogl-atlas-texture.c @@ -735,8 +735,6 @@ _cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp, int bmp_height; CoglPixelFormat bmp_format; - _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE); - _COGL_RETURN_VAL_IF_FAIL (cogl_is_bitmap (bmp), COGL_INVALID_HANDLE); bmp_width = cogl_bitmap_get_width (bmp); diff --git a/cogl/cogl-bitmap-private.h b/cogl/cogl-bitmap-private.h index fc9340652..b46ba7346 100644 --- a/cogl/cogl-bitmap-private.h +++ b/cogl/cogl-bitmap-private.h @@ -142,4 +142,7 @@ _cogl_bitmap_bind (CoglBitmap *bitmap, void _cogl_bitmap_unbind (CoglBitmap *bitmap); +CoglContext * +_cogl_bitmap_get_context (CoglBitmap *bitmap); + #endif /* __COGL_BITMAP_H */ diff --git a/cogl/cogl-bitmap.c b/cogl/cogl-bitmap.c index b0c6ec76e..b81c6811a 100644 --- a/cogl/cogl-bitmap.c +++ b/cogl/cogl-bitmap.c @@ -38,6 +38,10 @@ struct _CoglBitmap { CoglHandleObject _parent; + + /* Pointer back to the context that this bitmap was created with */ + CoglContext *context; + CoglPixelFormat format; int width; int height; @@ -73,6 +77,9 @@ _cogl_bitmap_free (CoglBitmap *bmp) if (bmp->buffer) cogl_object_unref (bmp->buffer); + if (bmp->context) + cogl_object_unref (bmp->context); + g_slice_free (CoglBitmap, bmp); } @@ -104,10 +111,8 @@ _cogl_bitmap_copy (CoglBitmap *src_bmp) int width = cogl_bitmap_get_width (src_bmp); int height = cogl_bitmap_get_height (src_bmp); - _COGL_GET_CONTEXT (ctx, NULL); - dst_bmp = - _cogl_bitmap_new_with_malloc_buffer (ctx, + _cogl_bitmap_new_with_malloc_buffer (src_bmp->context, width, height, src_format); @@ -188,6 +193,7 @@ cogl_bitmap_new_for_data (CoglContext *context, g_return_val_if_fail (cogl_is_context (context), NULL); bmp = g_slice_new (CoglBitmap); + bmp->context = cogl_object_ref (context); bmp->format = format; bmp->width = width; bmp->height = height; @@ -235,9 +241,7 @@ _cogl_bitmap_new_shared (CoglBitmap *shared_bmp, { CoglBitmap *bmp; - _COGL_GET_CONTEXT (ctx, NULL); - - bmp = cogl_bitmap_new_for_data (ctx, + bmp = cogl_bitmap_new_for_data (shared_bmp->context, width, height, format, rowstride, @@ -474,3 +478,9 @@ _cogl_bitmap_unbind (CoglBitmap *bitmap) else _cogl_bitmap_unmap (bitmap); } + +CoglContext * +_cogl_bitmap_get_context (CoglBitmap *bitmap) +{ + return bitmap->context; +} diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c index 8ed310399..937ea1326 100644 --- a/cogl/cogl-context.c +++ b/cogl/cogl-context.c @@ -405,8 +405,7 @@ cogl_context_new (CoglDisplay *display, /* If 3D or rectangle textures aren't supported then these should just silently return NULL */ context->default_gl_texture_3d_tex = - _cogl_texture_3d_new_from_bitmap (context, - default_texture_bitmap, + _cogl_texture_3d_new_from_bitmap (default_texture_bitmap, 1, /* height */ 1, /* depth */ COGL_PIXEL_FORMAT_RGBA_8888_PRE, diff --git a/cogl/cogl-texture-2d-sliced.c b/cogl/cogl-texture-2d-sliced.c index 90c9a9e22..275088f55 100644 --- a/cogl/cogl-texture-2d-sliced.c +++ b/cogl/cogl-texture-2d-sliced.c @@ -880,11 +880,12 @@ _cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp, GLenum gl_format; GLenum gl_type; int width, height; - - _COGL_GET_CONTEXT (ctx, NULL); + CoglContext *ctx; _COGL_RETURN_VAL_IF_FAIL (cogl_is_bitmap (bmp), NULL); + ctx = _cogl_bitmap_get_context (bmp); + width = cogl_bitmap_get_width (bmp); height = cogl_bitmap_get_height (bmp); diff --git a/cogl/cogl-texture-2d.c b/cogl/cogl-texture-2d.c index a3f042635..b14c61547 100644 --- a/cogl/cogl-texture-2d.c +++ b/cogl/cogl-texture-2d.c @@ -225,11 +225,12 @@ _cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp, GLenum gl_format; GLenum gl_type; guint8 *data; - - _COGL_GET_CONTEXT (ctx, COGL_INVALID_HANDLE); + CoglContext *ctx; _COGL_RETURN_VAL_IF_FAIL (bmp != NULL, COGL_INVALID_HANDLE); + ctx = _cogl_bitmap_get_context (bmp); + internal_format = _cogl_texture_determine_internal_format (cogl_bitmap_get_format (bmp), internal_format); diff --git a/cogl/cogl-texture-3d-private.h b/cogl/cogl-texture-3d-private.h index b1cc7d882..7b3f9cd8d 100644 --- a/cogl/cogl-texture-3d-private.h +++ b/cogl/cogl-texture-3d-private.h @@ -81,8 +81,7 @@ struct _CoglTexture3D * there was an error. */ CoglTexture3D * -_cogl_texture_3d_new_from_bitmap (CoglContext *context, - CoglBitmap *bmp, +_cogl_texture_3d_new_from_bitmap (CoglBitmap *bmp, unsigned int height, unsigned int depth, CoglPixelFormat internal_format, diff --git a/cogl/cogl-texture-3d.c b/cogl/cogl-texture-3d.c index 83ef3ad6a..4e9621e68 100644 --- a/cogl/cogl-texture-3d.c +++ b/cogl/cogl-texture-3d.c @@ -236,8 +236,7 @@ cogl_texture_3d_new_with_size (CoglContext *ctx, } CoglTexture3D * -_cogl_texture_3d_new_from_bitmap (CoglContext *ctx, - CoglBitmap *bmp, +_cogl_texture_3d_new_from_bitmap (CoglBitmap *bmp, unsigned int height, unsigned int depth, CoglPixelFormat internal_format, @@ -251,6 +250,9 @@ _cogl_texture_3d_new_from_bitmap (CoglContext *ctx, GLenum gl_format; GLenum gl_type; guint8 *data; + CoglContext *ctx; + + ctx = _cogl_bitmap_get_context (bmp); bmp_width = cogl_bitmap_get_width (bmp); bmp_format = cogl_bitmap_get_format (bmp); @@ -396,8 +398,7 @@ cogl_texture_3d_new_from_data (CoglContext *context, rowstride, (guint8 *) data); - ret = _cogl_texture_3d_new_from_bitmap (context, - bitmap, + ret = _cogl_texture_3d_new_from_bitmap (bitmap, height, depth, internal_format, diff --git a/cogl/cogl-texture-rectangle.c b/cogl/cogl-texture-rectangle.c index e4db54d5e..a4d3dd99a 100644 --- a/cogl/cogl-texture-rectangle.c +++ b/cogl/cogl-texture-rectangle.c @@ -230,11 +230,12 @@ _cogl_texture_rectangle_new_from_bitmap (CoglBitmap *bmp, GLenum gl_intformat; GLenum gl_format; GLenum gl_type; - - _COGL_GET_CONTEXT (ctx, NULL); + CoglContext *ctx; _COGL_RETURN_VAL_IF_FAIL (cogl_is_bitmap (bmp), NULL); + ctx = _cogl_bitmap_get_context (bmp); + internal_format = _cogl_texture_determine_internal_format (cogl_bitmap_get_format (bmp), internal_format);