mirror of
https://github.com/brl/mutter.git
synced 2024-11-26 01:50:42 -05:00
af7398788a
Texture allocation is now consistently handled lazily such that the internal format can now be controlled using cogl_texture_set_components() and cogl_texture_set_premultiplied() before allocating the texture with cogl_texture_allocate(). This means that the internal_format arguments to texture constructors are now redundant and since most of the texture constructors now can't ever fail the error arguments are also redundant. This now means we no longer use CoglPixelFormat in the public api for describing the internal format of textures which had been bad solution originally due to how specific CoglPixelFormat is which is missleading when we don't support such explicit control over the internal format. Reviewed-by: Neil Roberts <neil@linux.intel.com> (cherry picked from commit 99a53c82e9ab0a1e5ee35941bf83dc334b1fbe87) Note: there are numerous API changes for functions currently marked as 'unstable' which we don't think are in use by anyone depending on a stable 1.x api. Compared to the original patch though this avoids changing the cogl_texture_rectangle_new_with_size() api which we know is used by Mutter.
121 lines
3.5 KiB
C
121 lines
3.5 KiB
C
#include <cogl/cogl.h>
|
|
#include <string.h>
|
|
|
|
#include "test-utils.h"
|
|
|
|
/* Keep track of the number of textures that we've created and are
|
|
* still alive */
|
|
static int alive_texture_mask = 0;
|
|
|
|
#define N_LAYERS 3
|
|
#define N_PIPELINES 4
|
|
|
|
#define PIPELINE_LAYER_MASK(pipeline_num) \
|
|
(((1 << N_LAYERS) - 1) << (N_LAYERS * (pipeline_num) + 1))
|
|
#define LAST_PIPELINE_MASK PIPELINE_LAYER_MASK (N_PIPELINES - 1)
|
|
#define FIRST_PIPELINE_MASK PIPELINE_LAYER_MASK (0)
|
|
|
|
static void
|
|
free_texture_cb (void *user_data)
|
|
{
|
|
int texture_num = GPOINTER_TO_INT (user_data);
|
|
|
|
alive_texture_mask &= ~(1 << texture_num);
|
|
}
|
|
|
|
static CoglTexture *
|
|
create_texture (void)
|
|
{
|
|
static const guint8 data[] =
|
|
{ 0xff, 0xff, 0xff, 0xff };
|
|
static CoglUserDataKey texture_data_key;
|
|
CoglTexture2D *tex_2d;
|
|
static int texture_num = 1;
|
|
|
|
alive_texture_mask |= (1 << texture_num);
|
|
|
|
tex_2d = cogl_texture_2d_new_from_data (test_ctx,
|
|
1, 1, /* width / height */
|
|
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
|
|
4, /* rowstride */
|
|
data,
|
|
NULL);
|
|
|
|
/* Set some user data on the texture so we can track when it has
|
|
* been destroyed */
|
|
cogl_object_set_user_data (COGL_OBJECT (tex_2d),
|
|
&texture_data_key,
|
|
GINT_TO_POINTER (texture_num),
|
|
free_texture_cb);
|
|
|
|
texture_num++;
|
|
|
|
return tex_2d;
|
|
}
|
|
|
|
void
|
|
test_copy_replace_texture (void)
|
|
{
|
|
CoglPipeline *pipelines[N_PIPELINES];
|
|
int pipeline_num;
|
|
|
|
/* Create a set of pipeline copies each with three of their own
|
|
* replacement textures */
|
|
for (pipeline_num = 0; pipeline_num < N_PIPELINES; pipeline_num++)
|
|
{
|
|
int layer_num;
|
|
|
|
if (pipeline_num == 0)
|
|
pipelines[pipeline_num] = cogl_pipeline_new (test_ctx);
|
|
else
|
|
pipelines[pipeline_num] =
|
|
cogl_pipeline_copy (pipelines[pipeline_num - 1]);
|
|
|
|
for (layer_num = 0; layer_num < N_LAYERS; layer_num++)
|
|
{
|
|
CoglTexture *tex = create_texture ();
|
|
cogl_pipeline_set_layer_texture (pipelines[pipeline_num],
|
|
layer_num,
|
|
tex);
|
|
cogl_object_unref (tex);
|
|
}
|
|
}
|
|
|
|
/* Unref everything but the last pipeline */
|
|
for (pipeline_num = 0; pipeline_num < N_PIPELINES - 1; pipeline_num++)
|
|
cogl_object_unref (pipelines[pipeline_num]);
|
|
|
|
if (alive_texture_mask && cogl_test_verbose ())
|
|
{
|
|
int i;
|
|
|
|
g_print ("Alive textures:");
|
|
|
|
for (i = 0; i < N_PIPELINES * N_LAYERS; i++)
|
|
if ((alive_texture_mask & (1 << (i + 1))))
|
|
g_print (" %i", i);
|
|
|
|
g_print ("\n");
|
|
}
|
|
|
|
/* Ideally there should only be the textures from the last pipeline
|
|
* left alive. We also let Cogl keep the textures from the first
|
|
* texture alive because currently the child of the third layer in
|
|
* the first pipeline will retain its authority on the unit index
|
|
* state so that it can set it to 2. If there are more textures then
|
|
* it means the pipeline isn't correctly pruning redundant
|
|
* ancestors */
|
|
g_assert_cmpint (alive_texture_mask & ~FIRST_PIPELINE_MASK,
|
|
==,
|
|
LAST_PIPELINE_MASK);
|
|
|
|
/* Clean up the last pipeline */
|
|
cogl_object_unref (pipelines[N_PIPELINES - 1]);
|
|
|
|
/* That should get rid of the last of the textures */
|
|
g_assert_cmpint (alive_texture_mask, ==, 0);
|
|
|
|
if (cogl_test_verbose ())
|
|
g_print ("OK\n");
|
|
}
|