[cogl] bitmap: Store a pointer to the context



commit e7df2dbf79b7c5d40fb75452f8377a90d12eb910
Author: Neil Roberts <neil linux intel com>
Date:   Wed Apr 4 13:57:42 2012 +0100

    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>

 cogl/cogl-atlas-texture.c      |    2 --
 cogl/cogl-bitmap-private.h     |    3 +++
 cogl/cogl-bitmap.c             |   22 ++++++++++++++++------
 cogl/cogl-context.c            |    3 +--
 cogl/cogl-texture-2d-sliced.c  |    5 +++--
 cogl/cogl-texture-2d.c         |    5 +++--
 cogl/cogl-texture-3d-private.h |    3 +--
 cogl/cogl-texture-3d.c         |    9 +++++----
 cogl/cogl-texture-rectangle.c  |    5 +++--
 9 files changed, 35 insertions(+), 22 deletions(-)
---
diff --git a/cogl/cogl-atlas-texture.c b/cogl/cogl-atlas-texture.c
index 2701b87..d0be83d 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 fc93406..b46ba73 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 b0c6ec7..b81c681 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 8ed3103..937ea13 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 90c9a9e..275088f 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 a3f0426..b14c615 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 b1cc7d8..7b3f9cd 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 83ef3ad..4e9621e 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 e4db54d..a4d3dd9 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);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]