[cogl/cogl-1.18] texture-rectangle: update _new_with_size in line with master



commit a77dc1319c7e0179205cd9d082060f36cf878b66
Author: Robert Bragg <robert linux intel com>
Date:   Mon Jan 13 17:16:09 2014 +0000

    texture-rectangle: update _new_with_size in line with master
    
    This updates the cogl_texture_rectangle_new_with_size() api in line with
    master to be consistent with other texture constructors. This removes
    the internal_format and error arguments and allows the texture to be
    allocated lazily which means the texture can be configured with apis
    like cogl_texture_set_components() and cogl_texture_set_premultiplied()
    before it is allocated.
    
    Reviewed-by: Neil Roberts <neil linux intel com>

 cogl/cogl-texture-rectangle.c            |   40 +++--------------------------
 cogl/cogl-texture-rectangle.h            |   30 +++++++++------------
 cogl/winsys/cogl-winsys-glx.c            |    6 +---
 tests/conform/test-texture-no-allocate.c |    4 +--
 4 files changed, 21 insertions(+), 59 deletions(-)
---
diff --git a/cogl/cogl-texture-rectangle.c b/cogl/cogl-texture-rectangle.c
index c7f49b6..02bdb5f 100644
--- a/cogl/cogl-texture-rectangle.c
+++ b/cogl/cogl-texture-rectangle.c
@@ -193,46 +193,16 @@ _cogl_texture_rectangle_create_base (CoglContext *ctx,
 CoglTextureRectangle *
 cogl_texture_rectangle_new_with_size (CoglContext *ctx,
                                       int width,
-                                      int height,
-                                      CoglPixelFormat internal_format,
-                                      CoglError **error)
+                                      int height)
 {
-  CoglTextureLoader *loader;
-  CoglTextureRectangle *tex_rect;
-
-  /* Since no data, we need some internal format */
-  if (internal_format == COGL_PIXEL_FORMAT_ANY)
-    internal_format = COGL_PIXEL_FORMAT_RGBA_8888_PRE;
-
-  loader = _cogl_texture_create_loader ();
+  CoglTextureLoader *loader = _cogl_texture_create_loader ();
   loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZED;
   loader->src.sized.width = width;
   loader->src.sized.height = height;
 
-  tex_rect = _cogl_texture_rectangle_create_base (ctx, width, height,
-                                                  internal_format, loader);
-
-  /* XXX: This api has been changed for Cogl 2.0 on the master branch
-   * to not take a CoglError to allow the storage to be allocated
-   * lazily but since Mutter uses this api we are currently
-   * maintaining the semantics of immediately allocating the storage
-   */
-
-  /* By default tex->premultiplied is set to TRUE and tex->components
-   * get initialized according to a given source-format in
-   * _cogl_texture_init(). Since this api has an internal-format
-   * argument for compatibility we need to make sure the
-   * ->premultiplied and ->components state are initialized according
-   * to the users given @internal_format. */
-  _cogl_texture_set_internal_format (COGL_TEXTURE (tex_rect), internal_format);
-
-  if (!cogl_texture_allocate (COGL_TEXTURE (tex_rect), error))
-    {
-      cogl_object_unref (tex_rect);
-      return NULL;
-    }
-
-  return tex_rect;
+  return _cogl_texture_rectangle_create_base (ctx, width, height,
+                                              COGL_PIXEL_FORMAT_RGBA_8888_PRE,
+                                              loader);
 }
 
 static CoglBool
diff --git a/cogl/cogl-texture-rectangle.h b/cogl/cogl-texture-rectangle.h
index df3cbeb..421e331 100644
--- a/cogl/cogl-texture-rectangle.h
+++ b/cogl/cogl-texture-rectangle.h
@@ -81,13 +81,11 @@ cogl_is_texture_rectangle (void *object);
  * @ctx: A #CoglContext pointer
  * @width: The texture width to allocate
  * @height: The texture height to allocate
- * @internal_format: The desired internal texture format
- * @error: An optional CoglError pointer for reporting exceptions
  *
- * Allocates a new #CoglTextureRectangle texture with a given @width,
- * @height and @internal_format. This texture is a low-level texture
- * that the GPU can sample from directly unlike high-level textures
- * such as #CoglTexture2DSliced and #CoglAtlasTexture.
+ * Creates a new #CoglTextureRectangle texture with a given @width,
+ * and @height. This texture is a low-level texture that the GPU can
+ * sample from directly unlike high-level textures such as
+ * #CoglTexture2DSliced and #CoglAtlasTexture.
  *
  * <note>Unlike for #CoglTexture2D textures, coordinates for
  * #CoglTextureRectangle textures should not be normalized. So instead
@@ -102,15 +100,15 @@ cogl_is_texture_rectangle (void *object);
  * first check for the %COGL_FEATURE_ID_TEXTURE_RECTANGLE feature
  * using cogl_has_feature().</note>
  *
- * <note>For compatibility, unlike other texture constructors, this
- * api allocates texture storage synchronously and returns %NULL on
- * failure so it is not possible to configure rectangle textures
- * created with this api before allocation.</note>
+ * The storage for the texture is not allocated before this function
+ * returns. You can call cogl_texture_allocate() to explicitly
+ * allocate the underlying storage or preferably let Cogl
+ * automatically allocate storage lazily when it may know more about
+ * how the texture is going to be used and can optimize how it is
+ * allocated.
  *
- * Return value: (transfer full): A pointer to a newly allocated
- *          #CoglTextureRectangle texture or if the size was too large
- *          or there wasn't enough memory %NULL is returned and @error
- *          set.
+ * Returns value: (transfer full): A pointer to a new #CoglTextureRectangle
+ *          object with no storage allocated yet.
  *
  * Since: 1.10
  * Stability: unstable
@@ -118,9 +116,7 @@ cogl_is_texture_rectangle (void *object);
 CoglTextureRectangle *
 cogl_texture_rectangle_new_with_size (CoglContext *ctx,
                                       int width,
-                                      int height,
-                                      CoglPixelFormat internal_format,
-                                      CoglError **error);
+                                      int height);
 
 /**
  * cogl_texture_rectangle_new_from_bitmap:
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index 74ba46f..9b8677f 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -2504,13 +2504,11 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
           glx_tex_pixmap->glx_tex = COGL_TEXTURE (
             cogl_texture_rectangle_new_with_size (ctx,
                                                   tex->width,
-                                                  tex->height,
-                                                  texture_format,
-                                                  &error));
+                                                  tex->height));
 
           _cogl_texture_set_internal_format (tex, texture_format);
 
-          if (glx_tex_pixmap->glx_tex)
+          if (cogl_texture_allocate (glx_tex_pixmap->glx_tex, &error))
             COGL_NOTE (TEXTURE_PIXMAP, "Created a texture rectangle for %p",
                        tex_pixmap);
           else
diff --git a/tests/conform/test-texture-no-allocate.c b/tests/conform/test-texture-no-allocate.c
index 02c28d5..b0199a9 100644
--- a/tests/conform/test-texture-no-allocate.c
+++ b/tests/conform/test-texture-no-allocate.c
@@ -74,9 +74,7 @@ test_texture_no_allocate (void)
     {
       CoglTextureRectangle *texture_rect =
         cogl_texture_rectangle_new_with_size (test_ctx,
-                                              64, 64,
-                                              COGL_PIXEL_FORMAT_RGBA_8888_PRE,
-                                              NULL /* error */);
+                                              64, 64);
       cogl_object_unref (texture_rect);
     }
 }


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