[cogl/cogl-1.16] tests: stop using cogl-auto-texture apis



commit 937337993d78fcde0d74a6e28da4e396d32bf038
Author: Robert Bragg <robert linux intel com>
Date:   Sun Jun 9 01:09:04 2013 +0100

    tests: stop using cogl-auto-texture apis
    
    The plan is to remove the cogl-auto-texture apis since they hide a bit
    too much from developers but currently the conformance tests depend on
    these apis in numerous places.
    
    For the conformance tests it makes some sense to continue using high
    level texture apis similar to the auto-texture apis since we may want
    to make broad variations to how textures are allocated as part of the
    testing running if that might help exercise more code paths.
    
    This patch copies much of the auto-texture functionality into some
    slightly more special purpose utilities in test-utils.c/h. Minor changes
    include being constrained to the public Cogl api and they also don't
    let you catch CoglErrors and just assume they should abort on error.
    
    Reviewed-by: Neil Roberts <neil linux intel com>
    
    (cherry picked from commit 911df79776ce6f695351c15e9872b4f1479d30bf)
    
    Conflicts:
        tests/conform/test-atlas-migration.c
        tests/conform/test-backface-culling.c
        tests/conform/test-blend-strings.c
        tests/conform/test-color-mask.c
        tests/conform/test-just-vertex-shader.c
        tests/conform/test-npot-texture.c
        tests/conform/test-primitive.c
        tests/conform/test-snippets.c
        tests/conform/test-texture-get-set-data.c
        tests/conform/test-texture-mipmap-get-set.c
        tests/conform/test-texture-no-allocate.c
        tests/conform/test-wrap-modes.c

 test-fixtures/test-utils.c                |  182 +++++++++++++++++++++++++++++
 test-fixtures/test-utils.h                |  115 ++++++++++++++++++
 tests/conform/test-atlas-migration.c      |   21 ++--
 tests/conform/test-backface-culling.c     |   23 ++--
 tests/conform/test-blend-strings.c        |   15 ++-
 tests/conform/test-color-mask.c           |    4 +-
 tests/conform/test-just-vertex-shader.c   |   13 +-
 tests/conform/test-materials.c            |    4 +-
 tests/conform/test-multitexture.c         |    4 +-
 tests/conform/test-npot-texture.c         |   15 ++-
 tests/conform/test-primitive.c            |   13 +-
 tests/conform/test-readpixels.c           |    4 +-
 tests/conform/test-snippets.c             |   13 +-
 tests/conform/test-texture-get-set-data.c |   21 ++--
 tests/conform/test-texture-mipmaps.c      |    2 +-
 tests/conform/test-texture-no-allocate.c  |   37 ++++---
 tests/conform/test-texture-rectangle.c    |    4 +-
 tests/conform/test-viewport.c             |    4 +-
 tests/conform/test-wrap-modes.c           |   21 ++--
 19 files changed, 415 insertions(+), 100 deletions(-)
---
diff --git a/test-fixtures/test-utils.c b/test-fixtures/test-utils.c
index 8c67219..e085beb 100644
--- a/test-fixtures/test-utils.c
+++ b/test-fixtures/test-utils.c
@@ -348,3 +348,185 @@ cogl_test_verbose (void)
 {
   return cogl_test_is_verbose;
 }
+
+static void
+set_auto_mipmap_cb (CoglTexture *sub_texture,
+                    const float *sub_texture_coords,
+                    const float *meta_coords,
+                    void *user_data)
+{
+  cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (sub_texture),
+                                          FALSE);
+}
+
+CoglTexture *
+test_utils_texture_new_with_size (CoglContext *ctx,
+                                  int width,
+                                  int height,
+                                  TestUtilsTextureFlags flags,
+                                  CoglPixelFormat internal_format)
+{
+  CoglTexture *tex;
+  CoglError *skip_error = NULL;
+
+  if ((test_utils_is_pot (width) && test_utils_is_pot (height)) ||
+      (cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_BASIC) &&
+       cogl_has_feature (ctx, COGL_FEATURE_ID_TEXTURE_NPOT_MIPMAP)))
+    {
+      /* First try creating a fast-path non-sliced texture */
+      tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx,
+                                                         width, height,
+                                                         internal_format));
+
+      if (!cogl_texture_allocate (tex, &skip_error))
+        {
+          cogl_error_free (skip_error);
+          cogl_object_unref (tex);
+          tex = NULL;
+        }
+    }
+  else
+    tex = NULL;
+
+  if (!tex)
+    {
+      /* If it fails resort to sliced textures */
+      int max_waste = flags & TEST_UTILS_TEXTURE_NO_SLICING ?
+        -1 : COGL_TEXTURE_MAX_WASTE;
+      CoglTexture2DSliced *tex_2ds =
+        cogl_texture_2d_sliced_new_with_size (ctx,
+                                              width,
+                                              height,
+                                              max_waste,
+                                              internal_format);
+      tex = COGL_TEXTURE (tex_2ds);
+    }
+
+  if (flags & TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP)
+    {
+      /* To be able to iterate the slices of a #CoglTexture2DSliced we
+       * need to ensure the texture is allocated... */
+      cogl_texture_allocate (tex, NULL); /* don't catch exceptions */
+
+      cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (tex),
+                                           0, 0, 1, 1,
+                                           COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
+                                           COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
+                                           set_auto_mipmap_cb,
+                                           NULL); /* don't catch exceptions */
+    }
+
+  cogl_texture_allocate (tex, NULL);
+
+  return tex;
+}
+
+CoglTexture *
+test_utils_texture_new_from_bitmap (CoglBitmap *bitmap,
+                                    TestUtilsTextureFlags flags,
+                                    CoglPixelFormat internal_format)
+{
+  CoglAtlasTexture *atlas_tex;
+  CoglTexture *tex;
+  CoglError *internal_error = NULL;
+
+  if (!flags)
+    {
+      /* First try putting the texture in the atlas */
+      if ((atlas_tex = cogl_atlas_texture_new_from_bitmap (bitmap,
+                                                           internal_format,
+                                                           &internal_error)) &&
+           cogl_texture_allocate (COGL_TEXTURE (atlas_tex), &internal_error))
+        {
+          return COGL_TEXTURE (atlas_tex);
+        }
+
+      cogl_error_free (internal_error);
+      internal_error = NULL;
+    }
+
+  /* If that doesn't work try a fast path 2D texture */
+  if ((test_utils_is_pot (cogl_bitmap_get_width (bitmap)) &&
+       test_utils_is_pot (cogl_bitmap_get_height (bitmap))) ||
+      (cogl_has_feature (test_ctx, COGL_FEATURE_ID_TEXTURE_NPOT_BASIC) &&
+       cogl_has_feature (test_ctx, COGL_FEATURE_ID_TEXTURE_NPOT_MIPMAP)))
+    {
+      tex = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (bitmap,
+                                                           internal_format,
+                                                           &internal_error));
+
+      if (cogl_error_matches (internal_error,
+                              COGL_SYSTEM_ERROR,
+                              COGL_SYSTEM_ERROR_NO_MEMORY))
+        {
+          g_assert_not_reached ();
+          return NULL;
+        }
+
+      if (!tex)
+        {
+          cogl_error_free (internal_error);
+          internal_error = NULL;
+        }
+    }
+  else
+    tex = NULL;
+
+  if (!tex)
+    {
+      /* Otherwise create a sliced texture */
+      int max_waste = flags & TEST_UTILS_TEXTURE_NO_SLICING ?
+        -1 : COGL_TEXTURE_MAX_WASTE;
+      CoglTexture2DSliced *tex_2ds =
+        cogl_texture_2d_sliced_new_from_bitmap (bitmap,
+                                                max_waste,
+                                                internal_format,
+                                                NULL); /* don't catch
+                                                          exceptions */
+      tex = COGL_TEXTURE (tex_2ds);
+    }
+
+  if (flags & TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP)
+    {
+      cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (tex),
+                                           0, 0, 1, 1,
+                                           COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
+                                           COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
+                                           set_auto_mipmap_cb,
+                                           NULL); /* don't catch exceptions */
+    }
+
+  cogl_texture_allocate (tex, NULL);
+
+  return tex;
+}
+
+CoglTexture *
+test_utils_texture_new_from_data (CoglContext *ctx,
+                                  int width,
+                                  int height,
+                                  TestUtilsTextureFlags flags,
+                                  CoglPixelFormat format,
+                                  CoglPixelFormat internal_format,
+                                  int rowstride,
+                                  const uint8_t *data)
+{
+  CoglBitmap *bmp;
+  CoglTexture *tex;
+
+  g_assert_cmpint (format, !=, COGL_PIXEL_FORMAT_ANY);
+  g_assert (data != NULL);
+
+  /* Wrap the data into a bitmap */
+  bmp = cogl_bitmap_new_for_data (ctx,
+                                  width, height,
+                                  format,
+                                  rowstride,
+                                  (uint8_t *) data);
+
+  tex = test_utils_texture_new_from_bitmap (bmp, flags, internal_format);
+
+  cogl_object_unref (bmp);
+
+  return tex;
+}
diff --git a/test-fixtures/test-utils.h b/test-fixtures/test-utils.h
index 0c58820..8449df2 100644
--- a/test-fixtures/test-utils.h
+++ b/test-fixtures/test-utils.h
@@ -5,6 +5,10 @@
 #include <cogl/cogl-onscreen.h>
 #include <cogl/cogl-offscreen.h>
 #include <cogl/cogl-texture-2d.h>
+#include <cogl/cogl-primitive-texture.h>
+#include <cogl/cogl-texture-2d-sliced.h>
+#include <cogl/cogl-meta-texture.h>
+#include <cogl/cogl-atlas-texture.h>
 #include <glib.h>
 
 /* We don't really care about functions that are defined without a
@@ -29,6 +33,27 @@ typedef enum _TestFlags
   TEST_REQUIREMENT_PER_VERTEX_POINT_SIZE = 1<<11
 } TestFlags;
 
+ /**
+ * TestUtilsTextureFlags:
+ * @TEST_UTILS_TEXTURE_NONE: No flags specified
+ * @TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP: Disables the automatic generation of
+ *   the mipmap pyramid from the base level image whenever it is
+ *   updated. The mipmaps are only generated when the texture is
+ *   rendered with a mipmap filter so it should be free to leave out
+ *   this flag when using other filtering modes
+ * @TEST_UTILS_TEXTURE_NO_SLICING: Disables the slicing of the texture
+ * @TEST_UTILS_TEXTURE_NO_ATLAS: Disables the insertion of the texture inside
+ *   the texture atlas used by Cogl
+ *
+ * Flags to pass to the test_utils_texture_new_* family of functions.
+ */
+typedef enum {
+  TEST_UTILS_TEXTURE_NONE           = 0,
+  TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP = 1 << 0,
+  TEST_UTILS_TEXTURE_NO_SLICING     = 1 << 1,
+  TEST_UTILS_TEXTURE_NO_ATLAS       = 1 << 2
+} TestUtilsTextureFlags;
+
 extern CoglContext *test_ctx;
 extern CoglFramebuffer *test_fb;
 
@@ -40,6 +65,84 @@ void
 test_utils_fini (void);
 
 /*
+ * test_utils_texture_new_with_size:
+ * @context: A #CoglContext
+ * @width: width of texture in pixels.
+ * @height: height of texture in pixels.
+ * @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE
+ * @internal_format: the #CoglPixelFormat to use for the GPU storage of the
+ *    texture.
+ *
+ * Creates a new #CoglTexture with the specified dimensions and pixel format.
+ *
+ * The storage for the texture is not necesarily created before this
+ * function returns. The storage can be explicitly allocated using
+ * cogl_texture_allocate() or preferably you can let Cogl
+ * automatically allocate the storage lazily when uploading data when
+ * Cogl may know more about how the texture will be used and can
+ * optimize how it is allocated.
+ *
+ * Return value: A newly created #CoglTexture
+ */
+CoglTexture *
+test_utils_texture_new_with_size (CoglContext *ctx,
+                                  int width,
+                                  int height,
+                                  TestUtilsTextureFlags flags,
+                                  CoglPixelFormat internal_format);
+
+/*
+ * test_utils_texture_new_from_data:
+ * @context: A #CoglContext
+ * @width: width of texture in pixels
+ * @height: height of texture in pixels
+ * @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE
+ * @format: the #CoglPixelFormat the buffer is stored in in RAM
+ * @internal_format: the #CoglPixelFormat that will be used for storing
+ *    the buffer on the GPU. If COGL_PIXEL_FORMAT_ANY is given then a
+ *    premultiplied format similar to the format of the source data will
+ *    be used. The default blending equations of Cogl expect premultiplied
+ *    color data; the main use of passing a non-premultiplied format here
+ *    is if you have non-premultiplied source data and are going to adjust
+ *    the blend mode (see cogl_material_set_blend()) or use the data for
+ *    something other than straight blending.
+ * @rowstride: the memory offset in bytes between the starts of
+ *    scanlines in @data
+ * @data: pointer the memory region where the source buffer resides
+ * @error: A #CoglError to catch exceptional errors or %NULL
+ *
+ * Creates a new #CoglTexture based on data residing in memory.
+ *
+ * Return value: A newly created #CoglTexture or %NULL on failure
+ */
+CoglTexture *
+test_utils_texture_new_from_data (CoglContext *ctx,
+                                  int width,
+                                  int height,
+                                  TestUtilsTextureFlags flags,
+                                  CoglPixelFormat format,
+                                  CoglPixelFormat internal_format,
+                                  int rowstride,
+                                  const uint8_t *data);
+
+/*
+ * test_utils_texture_new_from_bitmap:
+ * @bitmap: A #CoglBitmap pointer
+ * @flags: Optional flags for the texture, or %TEST_UTILS_TEXTURE_NONE
+ * @internal_format: the #CoglPixelFormat to use for the GPU storage of the
+ * texture
+ * @error: A #CoglError to catch exceptional errors or %NULL
+ *
+ * Creates a #CoglTexture from a #CoglBitmap.
+ *
+ * Return value: A newly created #CoglTexture or %NULL on failure
+ */
+CoglTexture *
+test_utils_texture_new_from_bitmap (CoglBitmap *bitmap,
+                                    TestUtilsTextureFlags flags,
+                                    CoglPixelFormat internal_format);
+
+/*
  * test_utils_check_pixel:
  * @framebuffer: The #CoglFramebuffer to read from
  * @x: x co-ordinate of the pixel to test
@@ -157,4 +260,16 @@ test_utils_create_color_texture (CoglContext *context,
 CoglBool
 cogl_test_verbose (void);
 
+/* test_util_is_pot:
+ * @number: A number to test
+ *
+ * Returns whether the given integer is a power of two
+ */
+static inline CoglBool
+test_utils_is_pot (unsigned int number)
+{
+  /* Make sure there is only one bit set */
+  return (number & (number - 1)) == 0;
+}
+
 #endif /* _TEST_UTILS_H_ */
diff --git a/tests/conform/test-atlas-migration.c b/tests/conform/test-atlas-migration.c
index 55660a8..f8435bc 100644
--- a/tests/conform/test-atlas-migration.c
+++ b/tests/conform/test-atlas-migration.c
@@ -53,16 +53,17 @@ create_texture (int size)
         }
     }
 
-  texture = cogl_texture_new_from_data (size, /* width */
-                                        size, /* height */
-                                        COGL_TEXTURE_NONE, /* flags */
-                                        /* format */
-                                        COGL_PIXEL_FORMAT_RGBA_8888,
-                                        /* internal format */
-                                        COGL_PIXEL_FORMAT_RGBA_8888,
-                                        /* rowstride */
-                                        size * 4,
-                                        data);
+  texture = test_utils_texture_new_from_data (test_ctx,
+                                              size, /* width */
+                                              size, /* height */
+                                              TEST_UTILS_TEXTURE_NONE, /* flags */
+                                              /* format */
+                                              COGL_PIXEL_FORMAT_RGBA_8888,
+                                              /* internal format */
+                                              COGL_PIXEL_FORMAT_RGBA_8888,
+                                              /* rowstride */
+                                              size * 4,
+                                              data);
 
   g_free (data);
 
diff --git a/tests/conform/test-backface-culling.c b/tests/conform/test-backface-culling.c
index ada65ce..8dc3e57 100644
--- a/tests/conform/test-backface-culling.c
+++ b/tests/conform/test-backface-culling.c
@@ -266,13 +266,14 @@ make_texture (void)
       *(--p) = 255;
     }
 
-  tex = cogl_texture_new_from_data (TEXTURE_SIZE,
-                                    TEXTURE_SIZE,
-                                    COGL_TEXTURE_NO_ATLAS,
-                                    COGL_PIXEL_FORMAT_RGBA_8888,
-                                    COGL_PIXEL_FORMAT_ANY,
-                                    TEXTURE_SIZE * 4,
-                                    tex_data);
+  tex = test_utils_texture_new_from_data (test_ctx,
+                                          TEXTURE_SIZE,
+                                          TEXTURE_SIZE,
+                                          TEST_UTILS_TEXTURE_NO_ATLAS,
+                                          COGL_PIXEL_FORMAT_RGBA_8888,
+                                          COGL_PIXEL_FORMAT_ANY,
+                                          TEXTURE_SIZE * 4,
+                                          tex_data);
 
   g_free (tex_data);
 
@@ -292,9 +293,11 @@ test_backface_culling (void)
 
   state.texture = make_texture ();
 
-  tex = cogl_texture_new_with_size (state.width, state.height,
-                                    COGL_TEXTURE_NO_SLICING,
-                                    COGL_PIXEL_FORMAT_ANY); /* internal fmt */
+  tex = test_utils_texture_new_with_size (test_ctx,
+                                          state.width, state.height,
+                                          TEST_UTILS_TEXTURE_NO_SLICING,
+                                          COGL_PIXEL_FORMAT_ANY); /* internal
+                                                                     format */
   state.offscreen = COGL_FRAMEBUFFER (cogl_offscreen_new_to_texture (tex));
   state.offscreen_tex = tex;
 
diff --git a/tests/conform/test-blend-strings.c b/tests/conform/test-blend-strings.c
index 57a77f0..eb5acfe 100644
--- a/tests/conform/test-blend-strings.c
+++ b/tests/conform/test-blend-strings.c
@@ -196,13 +196,14 @@ make_texture (uint32_t color)
 
   /* Note: we don't use COGL_PIXEL_FORMAT_ANY for the internal format here
    * since we don't want to allow Cogl to premultiply our data. */
-  tex = cogl_texture_new_from_data (QUAD_WIDTH,
-                                    QUAD_WIDTH,
-                                    COGL_TEXTURE_NONE,
-                                    COGL_PIXEL_FORMAT_RGBA_8888,
-                                    COGL_PIXEL_FORMAT_RGBA_8888,
-                                    QUAD_WIDTH * 4,
-                                    tex_data);
+  tex = test_utils_texture_new_from_data (test_ctx,
+                                          QUAD_WIDTH,
+                                          QUAD_WIDTH,
+                                          TEST_UTILS_TEXTURE_NONE,
+                                          COGL_PIXEL_FORMAT_RGBA_8888,
+                                          COGL_PIXEL_FORMAT_RGBA_8888,
+                                          QUAD_WIDTH * 4,
+                                          tex_data);
 
   g_free (tex_data);
 
diff --git a/tests/conform/test-color-mask.c b/tests/conform/test-color-mask.c
index 331e29d..e4ae4bd 100644
--- a/tests/conform/test-color-mask.c
+++ b/tests/conform/test-color-mask.c
@@ -81,8 +81,8 @@ test_color_mask (void)
 
   for (i = 0; i < NUM_FBOS; i++)
     {
-      state.tex[i] = cogl_texture_new_with_size (128, 128,
-                                                 COGL_TEXTURE_NO_ATLAS,
+      state.tex[i] = test_utils_texture_new_with_size (test_ctx, 128, 128,
+                                                 TEST_UTILS_TEXTURE_NO_ATLAS,
                                                  COGL_PIXEL_FORMAT_RGB_888);
 
 
diff --git a/tests/conform/test-just-vertex-shader.c b/tests/conform/test-just-vertex-shader.c
index a4514ae..9113046 100644
--- a/tests/conform/test-just-vertex-shader.c
+++ b/tests/conform/test-just-vertex-shader.c
@@ -18,12 +18,13 @@ create_dummy_texture (void)
      vertex shader */
   static const uint8_t data[4] = { 0x00, 0xff, 0x00, 0xff };
 
-  return cogl_texture_new_from_data (1, 1, /* size */
-                                     COGL_TEXTURE_NONE,
-                                     COGL_PIXEL_FORMAT_RGB_888,
-                                     COGL_PIXEL_FORMAT_ANY,
-                                     4, /* rowstride */
-                                     data);
+  return test_utils_texture_new_from_data (test_ctx,
+                                           1, 1, /* size */
+                                           TEST_UTILS_TEXTURE_NONE,
+                                           COGL_PIXEL_FORMAT_RGB_888,
+                                           COGL_PIXEL_FORMAT_ANY,
+                                           4, /* rowstride */
+                                           data);
 }
 
 static void
diff --git a/tests/conform/test-materials.c b/tests/conform/test-materials.c
index 7c1da2f..69c9c74 100644
--- a/tests/conform/test-materials.c
+++ b/tests/conform/test-materials.c
@@ -111,11 +111,11 @@ test_using_all_layers (TestState *state, int x, int y)
      will use a red texture. The layers will all be modulated together
      so the final fragment should be red. */
 
-  white_texture = cogl_texture_new_from_data (1, 1, COGL_TEXTURE_NONE,
+  white_texture = test_utils_texture_new_from_data (1, 1, TEST_UTILS_TEXTURE_NONE,
                                               COGL_PIXEL_FORMAT_RGBA_8888_PRE,
                                               COGL_PIXEL_FORMAT_ANY,
                                               4, white_pixel);
-  red_texture = cogl_texture_new_from_data (1, 1, COGL_TEXTURE_NONE,
+  red_texture = test_utils_texture_new_from_data (1, 1, TEST_UTILS_TEXTURE_NONE,
                                             COGL_PIXEL_FORMAT_RGBA_8888_PRE,
                                             COGL_PIXEL_FORMAT_ANY,
                                             4, red_pixel);
diff --git a/tests/conform/test-multitexture.c b/tests/conform/test-multitexture.c
index 6eab806..da38766 100644
--- a/tests/conform/test-multitexture.c
+++ b/tests/conform/test-multitexture.c
@@ -85,9 +85,9 @@ make_texture (guchar ref)
 
   /* Note: we don't use COGL_PIXEL_FORMAT_ANY for the internal format here
    * since we don't want to allow Cogl to premultiply our data. */
-  tex = cogl_texture_new_from_data (QUAD_WIDTH * 2,
+  tex = test_utils_texture_new_from_data (QUAD_WIDTH * 2,
                                     QUAD_WIDTH * 2,
-                                    COGL_TEXTURE_NONE,
+                                    TEST_UTILS_TEXTURE_NONE,
                                     COGL_PIXEL_FORMAT_RGBA_8888,
                                     COGL_PIXEL_FORMAT_RGBA_8888,
                                     QUAD_WIDTH * 8,
diff --git a/tests/conform/test-npot-texture.c b/tests/conform/test-npot-texture.c
index a2bbd9f..3460fed 100644
--- a/tests/conform/test-npot-texture.c
+++ b/tests/conform/test-npot-texture.c
@@ -87,13 +87,14 @@ make_texture (void)
         }
     }
 
-  tex = cogl_texture_new_from_data (TEXTURE_SIZE,
-                                    TEXTURE_SIZE,
-                                    COGL_TEXTURE_NO_ATLAS,
-                                    COGL_PIXEL_FORMAT_RGBA_8888_PRE,
-                                    COGL_PIXEL_FORMAT_ANY,
-                                    TEXTURE_SIZE * 4,
-                                    tex_data);
+  tex = test_utils_texture_new_from_data (test_ctx,
+                                          TEXTURE_SIZE,
+                                          TEXTURE_SIZE,
+                                          TEST_UTILS_TEXTURE_NO_ATLAS,
+                                          COGL_PIXEL_FORMAT_RGBA_8888_PRE,
+                                          COGL_PIXEL_FORMAT_ANY,
+                                          TEXTURE_SIZE * 4,
+                                          tex_data);
 
   g_free (tex_data);
 
diff --git a/tests/conform/test-primitive.c b/tests/conform/test-primitive.c
index 66e6263..0d4d353 100644
--- a/tests/conform/test-primitive.c
+++ b/tests/conform/test-primitive.c
@@ -170,12 +170,13 @@ test_paint (TestState *state)
   tex_data[3] = (TEX_COLOR >> 24) & 0xff;
   tex_data[4] = (TEX_COLOR >> 16) & 0xff;
   tex_data[5] = (TEX_COLOR >> 8) & 0xff;
-  tex = cogl_texture_new_from_data (2, 1, /* size */
-                                    COGL_TEXTURE_NO_ATLAS,
-                                    COGL_PIXEL_FORMAT_RGB_888,
-                                    COGL_PIXEL_FORMAT_ANY,
-                                    6, /* rowstride */
-                                    tex_data);
+  tex = test_utils_texture_new_from_data (test_ctx,
+                                          2, 1, /* size */
+                                          TEST_UTILS_TEXTURE_NO_ATLAS,
+                                          COGL_PIXEL_FORMAT_RGB_888,
+                                          COGL_PIXEL_FORMAT_ANY,
+                                          6, /* rowstride */
+                                          tex_data);
   pipeline = cogl_pipeline_new (test_ctx);
   cogl_pipeline_set_color4ub (pipeline,
                               (PRIM_COLOR >> 24) & 0xff,
diff --git a/tests/conform/test-readpixels.c b/tests/conform/test-readpixels.c
index 83a1712..f543fb0 100644
--- a/tests/conform/test-readpixels.c
+++ b/tests/conform/test-readpixels.c
@@ -44,8 +44,8 @@ on_paint (ClutterActor *actor, void *state)
    */
 
   data = g_malloc (FRAMEBUFFER_WIDTH * 4 * FRAMEBUFFER_HEIGHT);
-  tex = cogl_texture_new_from_data (FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT,
-                                    COGL_TEXTURE_NO_SLICING,
+  tex = test_utils_texture_new_from_data (FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT,
+                                    TEST_UTILS_TEXTURE_NO_SLICING,
                                     COGL_PIXEL_FORMAT_RGBA_8888, /* data fmt */
                                     COGL_PIXEL_FORMAT_ANY, /* internal fmt */
                                     FRAMEBUFFER_WIDTH * 4, /* rowstride */
diff --git a/tests/conform/test-snippets.c b/tests/conform/test-snippets.c
index f27af80..82da75b 100644
--- a/tests/conform/test-snippets.c
+++ b/tests/conform/test-snippets.c
@@ -22,12 +22,13 @@ create_texture_pipeline (TestState *state)
       0x00, 0x00, 0xff, 0xff, /* blue */ 0xff, 0xff, 0x00, 0xff, /* yellow */
     };
 
-  tex = cogl_texture_new_from_data (2, 2, /* width/height */
-                                    COGL_TEXTURE_NO_ATLAS,
-                                    COGL_PIXEL_FORMAT_RGBA_8888_PRE,
-                                    COGL_PIXEL_FORMAT_ANY,
-                                    8, /* rowstride */
-                                    tex_data);
+  tex = test_utils_texture_new_from_data (test_ctx,
+                                          2, 2, /* width/height */
+                                          TEST_UTILS_TEXTURE_NO_ATLAS,
+                                          COGL_PIXEL_FORMAT_RGBA_8888_PRE,
+                                          COGL_PIXEL_FORMAT_ANY,
+                                          8, /* rowstride */
+                                          tex_data);
 
   pipeline = cogl_pipeline_new (test_ctx);
 
diff --git a/tests/conform/test-texture-get-set-data.c b/tests/conform/test-texture-get-set-data.c
index 8c635a9..003276a 100644
--- a/tests/conform/test-texture-get-set-data.c
+++ b/tests/conform/test-texture-get-set-data.c
@@ -5,7 +5,7 @@
 #include "test-utils.h"
 
 static void
-check_texture (int width, int height, CoglTextureFlags flags)
+check_texture (int width, int height, TestUtilsTextureFlags flags)
 {
   CoglTexture *tex;
   uint8_t *data, *p;
@@ -22,12 +22,13 @@ check_texture (int width, int height, CoglTextureFlags flags)
         *(p++) = (x ^ y);
       }
 
-  tex = cogl_texture_new_from_data (width, height,
-                                    flags,
-                                    COGL_PIXEL_FORMAT_RGBA_8888,
-                                    COGL_PIXEL_FORMAT_RGBA_8888,
-                                    width * 4,
-                                    data);
+  tex = test_utils_texture_new_from_data (test_ctx,
+                                          width, height,
+                                          flags,
+                                          COGL_PIXEL_FORMAT_RGBA_8888,
+                                          COGL_PIXEL_FORMAT_RGBA_8888,
+                                          width * 4,
+                                          data);
 
   /* Replace the bottom right quarter of the data with negated data to
      test set_region */
@@ -129,13 +130,13 @@ void
 test_texture_get_set_data (void)
 {
   /* First try without atlasing */
-  check_texture (256, 256, COGL_TEXTURE_NO_ATLAS);
+  check_texture (256, 256, TEST_UTILS_TEXTURE_NO_ATLAS);
   /* Try again with atlasing. This should end up testing the atlas
      backend and the sub texture backend */
   check_texture (256, 256, 0);
   /* Try with a really big texture in the hope that it will end up
      sliced. */
-  check_texture (4, 5128, COGL_TEXTURE_NO_ATLAS);
+  check_texture (4, 5128, TEST_UTILS_TEXTURE_NO_ATLAS);
   /* And in the other direction. */
-  check_texture (5128, 4, COGL_TEXTURE_NO_ATLAS);
+  check_texture (5128, 4, TEST_UTILS_TEXTURE_NO_ATLAS);
 }
diff --git a/tests/conform/test-texture-mipmaps.c b/tests/conform/test-texture-mipmaps.c
index b6cd421..3118ba8 100644
--- a/tests/conform/test-texture-mipmaps.c
+++ b/tests/conform/test-texture-mipmaps.c
@@ -33,7 +33,7 @@ make_texture (void)
         p += 3;
       }
 
-  tex = cogl_texture_new_from_data (TEX_SIZE, TEX_SIZE, COGL_TEXTURE_NONE,
+  tex = test_utils_texture_new_from_data (TEX_SIZE, TEX_SIZE, TEST_UTILS_TEXTURE_NONE,
                                     COGL_PIXEL_FORMAT_RGB_888,
                                     COGL_PIXEL_FORMAT_ANY,
                                     TEX_SIZE * 3,
diff --git a/tests/conform/test-texture-no-allocate.c b/tests/conform/test-texture-no-allocate.c
index fccb742..ad30e77 100644
--- a/tests/conform/test-texture-no-allocate.c
+++ b/tests/conform/test-texture-no-allocate.c
@@ -16,6 +16,7 @@ test_texture_no_allocate (void)
   uint8_t *tex_data;
   CoglTexture *texture;
   CoglTexture2D *texture_2d;
+  GError *error = NULL;
 
   tex_data = g_malloc (BIG_TEX_WIDTH * BIG_TEX_HEIGHT * 4);
 
@@ -25,30 +26,36 @@ test_texture_no_allocate (void)
 
   /* Try to create an atlas texture that is too big so it will
    * internally be freed without allocating */
-  texture = cogl_texture_new_from_data (BIG_TEX_WIDTH,
-                                        BIG_TEX_HEIGHT,
-                                        COGL_TEXTURE_NONE, /* flags */
-                                        /* format */
-                                        COGL_PIXEL_FORMAT_RGBA_8888_PRE,
-                                        /* internal format */
-                                        COGL_PIXEL_FORMAT_ANY,
-                                        /* rowstride */
-                                        BIG_TEX_WIDTH * 4,
-                                        tex_data);
+  texture = COGL_TEXTURE (
+    cogl_atlas_texture_new_from_data (test_ctx,
+                                      BIG_TEX_WIDTH,
+                                      BIG_TEX_HEIGHT,
+                                      /* format */
+                                      COGL_PIXEL_FORMAT_RGBA_8888_PRE,
+                                      /* internal format */
+                                      COGL_PIXEL_FORMAT_ANY,
+                                      /* rowstride */
+                                      BIG_TEX_WIDTH * 4,
+                                      tex_data,
+                                      &error));
 
   g_free (tex_data);
 
   /* It's ok if this causes an error, we just don't want it to
    * crash */
 
-  if (texture)
+  if (texture == NULL)
+    cogl_error_free (error);
+  else
     cogl_object_unref (texture);
 
   /* Try to create a sliced texture without allocating it */
-  texture = cogl_texture_new_with_size (BIG_TEX_WIDTH,
-                                        BIG_TEX_HEIGHT,
-                                        COGL_TEXTURE_NO_ATLAS,
-                                        COGL_PIXEL_FORMAT_RGBA_8888_PRE);
+  texture = COGL_TEXTURE (
+    cogl_texture_2d_sliced_new_with_size (test_ctx,
+                                          BIG_TEX_WIDTH,
+                                          BIG_TEX_HEIGHT,
+                                          COGL_TEXTURE_MAX_WASTE,
+                                          COGL_PIXEL_FORMAT_RGBA_8888_PRE));
   cogl_object_unref (texture);
 
   /* 2D texture */
diff --git a/tests/conform/test-texture-rectangle.c b/tests/conform/test-texture-rectangle.c
index 7766297..3784cdc 100644
--- a/tests/conform/test-texture-rectangle.c
+++ b/tests/conform/test-texture-rectangle.c
@@ -69,7 +69,7 @@ create_source_rect (void)
 
   g_free (data);
 
-  tex = cogl_texture_new_from_foreign (gl_tex,
+  tex = test_utils_texture_new_from_foreign (gl_tex,
                                        GL_TEXTURE_RECTANGLE_ARB,
                                        256, 256, 0, 0,
                                        COGL_PIXEL_FORMAT_RGBA_8888);
@@ -99,7 +99,7 @@ create_source_2d (void)
         *(p++) = 255;
       }
 
-  tex = cogl_texture_new_from_data (256, 256, COGL_TEXTURE_NONE,
+  tex = test_utils_texture_new_from_data (256, 256, TEST_UTILS_TEXTURE_NONE,
                                     COGL_PIXEL_FORMAT_RGBA_8888_PRE,
                                     COGL_PIXEL_FORMAT_ANY,
                                     256 * 4,
diff --git a/tests/conform/test-viewport.c b/tests/conform/test-viewport.c
index 3e610e8..c437ec7 100644
--- a/tests/conform/test-viewport.c
+++ b/tests/conform/test-viewport.c
@@ -210,8 +210,8 @@ on_paint (ClutterActor *actor, void *state)
    * Next test offscreen drawing...
    */
   data = g_malloc (FRAMEBUFFER_WIDTH * 4 * FRAMEBUFFER_HEIGHT);
-  tex = cogl_texture_new_from_data (FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT,
-                                    COGL_TEXTURE_NO_SLICING,
+  tex = test_utils_texture_new_from_data (FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT,
+                                    TEST_UTILS_TEXTURE_NO_SLICING,
                                     COGL_PIXEL_FORMAT_RGBA_8888, /* data fmt */
                                     COGL_PIXEL_FORMAT_ANY, /* internal fmt */
                                     FRAMEBUFFER_WIDTH * 4, /* rowstride */
diff --git a/tests/conform/test-wrap-modes.c b/tests/conform/test-wrap-modes.c
index db28898..4c31f89 100644
--- a/tests/conform/test-wrap-modes.c
+++ b/tests/conform/test-wrap-modes.c
@@ -15,7 +15,7 @@ typedef struct _TestState
 } TestState;
 
 static CoglTexture *
-create_texture (CoglTextureFlags flags)
+create_texture (TestUtilsTextureFlags flags)
 {
   uint8_t *data = g_malloc (TEX_SIZE * TEX_SIZE * 4), *p = data;
   CoglTexture *tex;
@@ -30,11 +30,12 @@ create_texture (CoglTextureFlags flags)
         *(p++) = 255;
       }
 
-  tex = cogl_texture_new_from_data (TEX_SIZE, TEX_SIZE, flags,
-                                    COGL_PIXEL_FORMAT_RGBA_8888_PRE,
-                                    COGL_PIXEL_FORMAT_ANY,
-                                    TEX_SIZE * 4,
-                                    data);
+  tex = test_utils_texture_new_from_data (test_ctx,
+                                          TEX_SIZE, TEX_SIZE, flags,
+                                          COGL_PIXEL_FORMAT_RGBA_8888_PRE,
+                                          COGL_PIXEL_FORMAT_ANY,
+                                          TEX_SIZE * 4,
+                                          data);
   g_free (data);
 
   return tex;
@@ -238,15 +239,15 @@ static void
 paint (TestState *state)
 {
   /* Draw the tests first with a non atlased texture */
-  state->texture = create_texture (COGL_TEXTURE_NO_ATLAS);
+  state->texture = create_texture (TEST_UTILS_TEXTURE_NO_ATLAS);
   draw_tests (state);
   cogl_object_unref (state->texture);
 
   /* Draw the tests again with a possible atlased texture. This should
      end up testing software repeats */
-  state->texture = create_texture (COGL_TEXTURE_NONE);
-  cogl_push_matrix ();
-  cogl_translate (0.0f, TEX_SIZE * 2.0f, 0.0f);
+  state->texture = create_texture (TEST_UTILS_TEXTURE_NONE);
+  cogl_framebuffer_push_matrix (test_fb);
+  cogl_framebuffer_translate (test_fb, 0.0f, TEX_SIZE * 2.0f, 0.0f);
   draw_tests (state);
   cogl_pop_matrix ();
   cogl_object_unref (state->texture);


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