summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Roberts <neil@linux.intel.com>2012-04-04 13:57:42 +0100
committerNeil Roberts <neil@linux.intel.com>2012-04-04 14:24:01 +0100
commite7df2dbf79b7c5d40fb75452f8377a90d12eb910 (patch)
treea0a782eb2a7f2b05558f54fb9fa5c5f353d3f132
parentbe9d5b34c66ac81656e37779eb64891a062f90af (diff)
downloadcogl-e7df2dbf79b7c5d40fb75452f8377a90d12eb910.tar.gz
bitmap: Store a pointer to the context
This adds a context member to CoglBitmap which stores the context it was created with. That way it can be used in texture constructors which use a bitmap. There is also an internal private function to get the context out of the bitmap which all of the texture constructors now use. _cogl_texture_3d_new_from_bitmap has had its context parameter removed so that it more closely matches the other bitmap constructors. Reviewed-by: Robert Bragg <robert@linux.intel.com>
-rw-r--r--cogl/cogl-atlas-texture.c2
-rw-r--r--cogl/cogl-bitmap-private.h3
-rw-r--r--cogl/cogl-bitmap.c22
-rw-r--r--cogl/cogl-context.c3
-rw-r--r--cogl/cogl-texture-2d-sliced.c5
-rw-r--r--cogl/cogl-texture-2d.c5
-rw-r--r--cogl/cogl-texture-3d-private.h3
-rw-r--r--cogl/cogl-texture-3d.c9
-rw-r--r--cogl/cogl-texture-rectangle.c5
9 files changed, 35 insertions, 22 deletions
diff --git a/cogl/cogl-atlas-texture.c b/cogl/cogl-atlas-texture.c
index 2701b877..d0be83da 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 fc934065..b46ba734 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 b0c6ec76..b81c6811 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 8ed31039..937ea132 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 90c9a9e2..275088f5 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 a3f04263..b14c6154 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 b1cc7d88..7b3f9cd8 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 83ef3ad6..4e9621e6 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 e4db54d5..a4d3dd99 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);