cogl: Port Texture* away from CoglObject

- Make Texture a parent GObject class and move the vtable funcs as vfuncs
instead of an interface as we would like to have dispose free the TextureLoader.
- Make the various texture sub-types inherit from it.
- Make all the sub-types constructors return a CoglTexture instead of their respective
specific type. As most of the times, the used functions accept a CoglTexture,
like all the GTK widgets constructors returning GtkWidget.
- Fix up the basics of gi-docgen for all these types.
- Remove CoglPrimitiveTexture as it is useless: It is just a texture underhood.
- Remove CoglMetaTexture: for the exact same reason as above.
- Switch various memory management functions to use g_ variant instead of the cogl_ one

Note we would still want to get rid of the _cogl_texture_init which is something
for the next commit

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3193>
This commit is contained in:
Bilal Elmoussaoui 2023-09-18 16:58:36 +02:00 committed by Marge Bot
parent 586c43d5a9
commit 863163cc6e
115 changed files with 2278 additions and 2449 deletions

View File

@ -230,7 +230,7 @@ create_fbo (ClutterBlur *blur,
float height; float height;
float width; float width;
cogl_clear_object (&pass->texture); g_clear_object (&pass->texture);
g_clear_object (&pass->framebuffer); g_clear_object (&pass->framebuffer);
width = cogl_texture_get_width (blur->source_texture); width = cogl_texture_get_width (blur->source_texture);
@ -238,9 +238,9 @@ create_fbo (ClutterBlur *blur,
scaled_width = floorf (width / blur->downscale_factor); scaled_width = floorf (width / blur->downscale_factor);
scaled_height = floorf (height / blur->downscale_factor); scaled_height = floorf (height / blur->downscale_factor);
pass->texture = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, pass->texture = cogl_texture_2d_new_with_size (ctx,
scaled_width, scaled_width,
scaled_height)); scaled_height);
if (!pass->texture) if (!pass->texture)
return FALSE; return FALSE;
@ -327,7 +327,7 @@ static void
clear_blur_pass (BlurPass *pass) clear_blur_pass (BlurPass *pass)
{ {
cogl_clear_object (&pass->pipeline); cogl_clear_object (&pass->pipeline);
cogl_clear_object (&pass->texture); g_clear_object (&pass->texture);
g_clear_object (&pass->framebuffer); g_clear_object (&pass->framebuffer);
} }
@ -358,7 +358,7 @@ clutter_blur_new (CoglTexture *texture,
blur = g_new0 (ClutterBlur, 1); blur = g_new0 (ClutterBlur, 1);
blur->sigma = sigma; blur->sigma = sigma;
blur->source_texture = cogl_object_ref (texture); blur->source_texture = g_object_ref (texture);
blur->downscale_factor = calculate_downscale_factor (width, height, sigma); blur->downscale_factor = calculate_downscale_factor (width, height, sigma);
if (G_APPROX_VALUE (sigma, 0.0, FLT_EPSILON)) if (G_APPROX_VALUE (sigma, 0.0, FLT_EPSILON))
@ -426,6 +426,6 @@ clutter_blur_free (ClutterBlur *blur)
clear_blur_pass (&blur->pass[VERTICAL]); clear_blur_pass (&blur->pass[VERTICAL]);
clear_blur_pass (&blur->pass[HORIZONTAL]); clear_blur_pass (&blur->pass[HORIZONTAL]);
cogl_clear_object (&blur->source_texture); g_clear_object (&blur->source_texture);
g_free (blur); g_free (blur);
} }

View File

@ -128,7 +128,7 @@ clutter_canvas_finalize (GObject *gobject)
ClutterCanvasPrivate *priv = CLUTTER_CANVAS (gobject)->priv; ClutterCanvasPrivate *priv = CLUTTER_CANVAS (gobject)->priv;
g_clear_object (&priv->buffer); g_clear_object (&priv->buffer);
cogl_clear_object (&priv->texture); g_clear_object (&priv->texture);
G_OBJECT_CLASS (clutter_canvas_parent_class)->finalize (gobject); G_OBJECT_CLASS (clutter_canvas_parent_class)->finalize (gobject);
} }
@ -317,10 +317,10 @@ clutter_canvas_paint_content (ClutterContent *content,
return; return;
if (priv->dirty) if (priv->dirty)
cogl_clear_object (&priv->texture); g_clear_object (&priv->texture);
if (priv->texture == NULL) if (priv->texture == NULL)
priv->texture = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (priv->buffer)); priv->texture = cogl_texture_2d_new_from_bitmap (priv->buffer);
if (priv->texture == NULL) if (priv->texture == NULL)
return; return;

View File

@ -70,7 +70,7 @@ create_texture_from_data (unsigned int width,
{ {
CoglContext *ctx = CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_get_default_backend ()); clutter_backend_get_cogl_context (clutter_get_default_backend ());
CoglTexture2D *texture_2d; CoglTexture *texture_2d;
texture_2d = cogl_texture_2d_new_from_data (ctx, texture_2d = cogl_texture_2d_new_from_data (ctx,
width, width,
@ -80,7 +80,7 @@ create_texture_from_data (unsigned int width,
data, data,
error); error);
return texture_2d ? COGL_TEXTURE (texture_2d) : NULL; return texture_2d;
} }
static void static void
@ -111,7 +111,7 @@ clutter_image_finalize (GObject *gobject)
ClutterImage *image = CLUTTER_IMAGE (gobject); ClutterImage *image = CLUTTER_IMAGE (gobject);
ClutterImagePrivate *priv = clutter_image_get_instance_private (image); ClutterImagePrivate *priv = clutter_image_get_instance_private (image);
cogl_clear_object (&priv->texture); g_clear_object (&priv->texture);
G_OBJECT_CLASS (clutter_image_parent_class)->finalize (gobject); G_OBJECT_CLASS (clutter_image_parent_class)->finalize (gobject);
} }
@ -248,7 +248,7 @@ clutter_image_set_data (ClutterImage *image,
priv = clutter_image_get_instance_private (image); priv = clutter_image_get_instance_private (image);
if (priv->texture != NULL) if (priv->texture != NULL)
cogl_object_unref (priv->texture); g_object_unref (priv->texture);
priv->texture = create_texture_from_data (width, priv->texture = create_texture_from_data (width,
height, height,
@ -306,7 +306,7 @@ clutter_image_set_bytes (ClutterImage *image,
priv = clutter_image_get_instance_private (image); priv = clutter_image_get_instance_private (image);
if (priv->texture != NULL) if (priv->texture != NULL)
cogl_object_unref (priv->texture); g_object_unref (priv->texture);
priv->texture = create_texture_from_data (width, priv->texture = create_texture_from_data (width,
height, height,
@ -391,7 +391,7 @@ clutter_image_set_area (ClutterImage *image,
if (!res) if (!res)
{ {
cogl_clear_object (&priv->texture); g_clear_object (&priv->texture);
} }
} }

View File

@ -155,7 +155,7 @@ clutter_offscreen_effect_real_create_texture (ClutterOffscreenEffect *effect,
CoglContext *ctx = CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_get_default_backend ()); clutter_backend_get_cogl_context (clutter_get_default_backend ());
return COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, MAX (width, 1), MAX (height, 1))); return cogl_texture_2d_new_with_size (ctx, MAX (width, 1), MAX (height, 1));
} }
static void static void
@ -256,7 +256,7 @@ update_fbo (ClutterEffect *effect,
return TRUE; return TRUE;
} }
g_clear_pointer (&priv->texture, cogl_object_unref); g_clear_object (&priv->texture);
g_clear_object (&priv->offscreen); g_clear_object (&priv->offscreen);
priv->texture = priv->texture =
@ -576,7 +576,7 @@ clutter_offscreen_effect_finalize (GObject *gobject)
ClutterOffscreenEffectPrivate *priv = self->priv; ClutterOffscreenEffectPrivate *priv = self->priv;
g_clear_object (&priv->offscreen); g_clear_object (&priv->offscreen);
g_clear_pointer (&priv->texture, cogl_object_unref); g_clear_object (&priv->texture);
g_clear_pointer (&priv->pipeline, cogl_object_unref); g_clear_pointer (&priv->pipeline, cogl_object_unref);
G_OBJECT_CLASS (clutter_offscreen_effect_parent_class)->finalize (gobject); G_OBJECT_CLASS (clutter_offscreen_effect_parent_class)->finalize (gobject);

View File

@ -710,7 +710,7 @@ clutter_scaling_filter_to_cogl_pipeline_filter (ClutterScalingFilter filter)
* Creates a new #ClutterPaintNode that will paint the passed @texture. * Creates a new #ClutterPaintNode that will paint the passed @texture.
* *
* This function will take a reference on @texture, so it is safe to * This function will take a reference on @texture, so it is safe to
* call cogl_object_unref() on @texture when it returns. * call g_object_unref() on @texture when it returns.
* *
* The @color must not be pre-multiplied with its #ClutterColor.alpha * The @color must not be pre-multiplied with its #ClutterColor.alpha
* channel value; if @color is %NULL, a fully opaque white color will * channel value; if @color is %NULL, a fully opaque white color will
@ -729,7 +729,7 @@ clutter_texture_node_new (CoglTexture *texture,
CoglColor cogl_color; CoglColor cogl_color;
CoglPipelineFilter min_f, mag_f; CoglPipelineFilter min_f, mag_f;
g_return_val_if_fail (cogl_is_texture (texture), NULL); g_return_val_if_fail (COGL_IS_TEXTURE (texture), NULL);
tnode = _clutter_paint_node_create (CLUTTER_TYPE_TEXTURE_NODE); tnode = _clutter_paint_node_create (CLUTTER_TYPE_TEXTURE_NODE);
@ -1782,7 +1782,6 @@ clutter_blur_node_new (unsigned int width,
g_autoptr (GError) error = NULL; g_autoptr (GError) error = NULL;
ClutterLayerNode *layer_node; ClutterLayerNode *layer_node;
ClutterBlurNode *blur_node; ClutterBlurNode *blur_node;
CoglTexture2D *tex_2d;
CoglContext *context; CoglContext *context;
CoglTexture *texture; CoglTexture *texture;
ClutterBlur *blur; ClutterBlur *blur;
@ -1792,13 +1791,12 @@ clutter_blur_node_new (unsigned int width,
blur_node = _clutter_paint_node_create (CLUTTER_TYPE_BLUR_NODE); blur_node = _clutter_paint_node_create (CLUTTER_TYPE_BLUR_NODE);
blur_node->sigma = sigma; blur_node->sigma = sigma;
context = clutter_backend_get_cogl_context (clutter_get_default_backend ()); context = clutter_backend_get_cogl_context (clutter_get_default_backend ());
tex_2d = cogl_texture_2d_new_with_size (context, width, height); texture = cogl_texture_2d_new_with_size (context, width, height);
texture = COGL_TEXTURE (tex_2d);
cogl_texture_set_premultiplied (texture, TRUE); cogl_texture_set_premultiplied (texture, TRUE);
offscreen = cogl_offscreen_new_with_texture (texture); offscreen = cogl_offscreen_new_with_texture (texture);
cogl_object_unref (tex_2d); g_object_unref (texture);
if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen), &error)) if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen), &error))
{ {
g_warning ("Unable to allocate paint node offscreen: %s", g_warning ("Unable to allocate paint node offscreen: %s",

View File

@ -381,20 +381,19 @@ create_offscreen_framebuffer (CoglContext *context,
GError **error) GError **error)
{ {
CoglOffscreen *framebuffer; CoglOffscreen *framebuffer;
CoglTexture2D *texture; CoglTexture *texture;
texture = cogl_texture_2d_new_with_size (context, width, height); texture = cogl_texture_2d_new_with_size (context, width, height);
cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (texture), cogl_primitive_texture_set_auto_mipmap (texture, FALSE);
FALSE);
if (!cogl_texture_allocate (COGL_TEXTURE (texture), error)) if (!cogl_texture_allocate (texture, error))
{ {
cogl_object_unref (texture); g_object_unref (texture);
return FALSE; return FALSE;
} }
framebuffer = cogl_offscreen_new_with_texture (COGL_TEXTURE (texture)); framebuffer = cogl_offscreen_new_with_texture (texture);
cogl_object_unref (texture); g_object_unref (texture);
if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (framebuffer), error)) if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (framebuffer), error))
{ {
g_object_unref (framebuffer); g_object_unref (framebuffer);

View File

@ -2784,7 +2784,7 @@ clutter_stage_paint_to_buffer (ClutterStage *stage,
CoglContext *cogl_context = CoglContext *cogl_context =
clutter_backend_get_cogl_context (clutter_backend); clutter_backend_get_cogl_context (clutter_backend);
int texture_width, texture_height; int texture_width, texture_height;
CoglTexture2D *texture; CoglTexture *texture;
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
CoglFramebuffer *framebuffer; CoglFramebuffer *framebuffer;
CoglBitmap *bitmap; CoglBitmap *bitmap;
@ -2802,10 +2802,10 @@ clutter_stage_paint_to_buffer (ClutterStage *stage,
return FALSE; return FALSE;
} }
offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (texture)); offscreen = cogl_offscreen_new_with_texture (texture);
framebuffer = COGL_FRAMEBUFFER (offscreen); framebuffer = COGL_FRAMEBUFFER (offscreen);
cogl_object_unref (texture); g_object_unref (texture);
if (!cogl_framebuffer_allocate (framebuffer, error)) if (!cogl_framebuffer_allocate (framebuffer, error))
return FALSE; return FALSE;
@ -2853,7 +2853,7 @@ clutter_stage_paint_to_content (ClutterStage *stage,
CoglContext *cogl_context = CoglContext *cogl_context =
clutter_backend_get_cogl_context (clutter_backend); clutter_backend_get_cogl_context (clutter_backend);
int texture_width, texture_height; int texture_width, texture_height;
CoglTexture2D *texture; CoglTexture *texture;
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
g_autoptr (CoglFramebuffer) framebuffer = NULL; g_autoptr (CoglFramebuffer) framebuffer = NULL;
@ -2870,10 +2870,10 @@ clutter_stage_paint_to_content (ClutterStage *stage,
return NULL; return NULL;
} }
offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (texture)); offscreen = cogl_offscreen_new_with_texture (texture);
framebuffer = COGL_FRAMEBUFFER (offscreen); framebuffer = COGL_FRAMEBUFFER (offscreen);
cogl_object_unref (texture); g_object_unref (texture);
if (!cogl_framebuffer_allocate (framebuffer, error)) if (!cogl_framebuffer_allocate (framebuffer, error))
return NULL; return NULL;

View File

@ -51,7 +51,7 @@ clutter_texture_content_finalize (GObject *gobject)
{ {
ClutterTextureContent *texture_content = CLUTTER_TEXTURE_CONTENT (gobject); ClutterTextureContent *texture_content = CLUTTER_TEXTURE_CONTENT (gobject);
g_clear_pointer (&texture_content->texture, cogl_object_unref); g_clear_object (&texture_content->texture);
G_OBJECT_CLASS (clutter_texture_content_parent_class)->finalize (gobject); G_OBJECT_CLASS (clutter_texture_content_parent_class)->finalize (gobject);
} }
@ -114,7 +114,7 @@ clutter_content_iface_init (ClutterContentInterface *iface)
* Creates a new [class@TextureContent] instance for @texture, taking an * Creates a new [class@TextureContent] instance for @texture, taking an
* internal reference to @texture. * internal reference to @texture.
* *
* If you change the contents of the [iface@Cogl.Texture] you will need * If you change the contents of the [class@Cogl.Texture] you will need
* to manually invalidate the @texture_content with [method@Content.invalidate] * to manually invalidate the @texture_content with [method@Content.invalidate]
* in order to update the actors using @texture_content as their content. * in order to update the actors using @texture_content as their content.
* *
@ -135,17 +135,16 @@ clutter_texture_content_new_from_texture (CoglTexture *texture,
if (clip) if (clip)
{ {
texture_content->texture = texture_content->texture = cogl_sub_texture_new (cogl_context,
COGL_TEXTURE (cogl_sub_texture_new (cogl_context,
texture, texture,
clip->x, clip->x,
clip->y, clip->y,
clip->width, clip->width,
clip->height)); clip->height);
} }
else else
{ {
texture_content->texture = cogl_object_ref (texture); texture_content->texture = g_object_ref (texture);
} }
return CLUTTER_CONTENT (texture_content); return CLUTTER_CONTENT (texture_content);
@ -155,13 +154,13 @@ clutter_texture_content_new_from_texture (CoglTexture *texture,
* clutter_texture_content_get_texture: * clutter_texture_content_get_texture:
* @texture_content: a #ClutterTextureContent * @texture_content: a #ClutterTextureContent
* *
* Retrieves a pointer to the [iface@Cogl.Texture] used by @texture_content. * Retrieves a pointer to the [class@Cogl.Texture] used by @texture_content.
* *
* If you change the contents of the returned [iface@Cogl.Texture] you will need * If you change the contents of the returned [class@Cogl.Texture] you will need
* to manually invalidate the @texture_content with [method@Content.invalidate] * to manually invalidate the @texture_content with [method@Content.invalidate]
* in order to update the actors using @texture_content as their content. * in order to update the actors using @texture_content as their content.
* *
* Return value: (transfer none): a pointer to the [iface@Cogl.Texture] * Return value: (transfer none): a pointer to the [class@Cogl.Texture]
*/ */
CoglTexture * CoglTexture *
clutter_texture_content_get_texture (ClutterTextureContent *texture_content) clutter_texture_content_get_texture (ClutterTextureContent *texture_content)

View File

@ -167,7 +167,7 @@ _cogl_pango_display_list_add_texture (CoglPangoDisplayList *dl,
node->color_override = dl->color_override; node->color_override = dl->color_override;
node->color = dl->color; node->color = dl->color;
node->pipeline = NULL; node->pipeline = NULL;
node->d.texture.texture = cogl_object_ref (texture); node->d.texture.texture = g_object_ref (texture);
node->d.texture.rectangles node->d.texture.rectangles
= g_array_new (FALSE, FALSE, sizeof (CoglPangoDisplayListRectangle)); = g_array_new (FALSE, FALSE, sizeof (CoglPangoDisplayListRectangle));
node->d.texture.primitive = NULL; node->d.texture.primitive = NULL;
@ -461,7 +461,7 @@ _cogl_pango_display_list_node_free (CoglPangoDisplayListNode *node)
{ {
g_array_free (node->d.texture.rectangles, TRUE); g_array_free (node->d.texture.rectangles, TRUE);
if (node->d.texture.texture != NULL) if (node->d.texture.texture != NULL)
cogl_object_unref (node->d.texture.texture); g_object_unref (node->d.texture.texture);
if (node->d.texture.primitive != NULL) if (node->d.texture.primitive != NULL)
cogl_object_unref (node->d.texture.primitive); cogl_object_unref (node->d.texture.primitive);
} }

View File

@ -76,7 +76,7 @@ static void
cogl_pango_glyph_cache_value_free (CoglPangoGlyphCacheValue *value) cogl_pango_glyph_cache_value_free (CoglPangoGlyphCacheValue *value)
{ {
if (value->texture) if (value->texture)
cogl_object_unref (value->texture); g_object_unref (value->texture);
g_free (value); g_free (value);
} }
@ -192,8 +192,8 @@ cogl_pango_glyph_cache_update_position_cb (void *user_data,
float tex_width, tex_height; float tex_width, tex_height;
if (value->texture) if (value->texture)
cogl_object_unref (value->texture); g_object_unref (value->texture);
value->texture = cogl_object_ref (new_texture); value->texture = g_object_ref (new_texture);
tex_width = cogl_texture_get_width (new_texture); tex_width = cogl_texture_get_width (new_texture);
tex_height = cogl_texture_get_height (new_texture); tex_height = cogl_texture_get_height (new_texture);
@ -216,7 +216,7 @@ cogl_pango_glyph_cache_add_to_global_atlas (CoglPangoGlyphCache *cache,
PangoGlyph glyph, PangoGlyph glyph,
CoglPangoGlyphCacheValue *value) CoglPangoGlyphCacheValue *value)
{ {
CoglAtlasTexture *texture; CoglTexture *texture;
GError *ignore_error = NULL; GError *ignore_error = NULL;
if (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_SHARED_ATLAS)) if (COGL_DEBUG_ENABLED (COGL_DEBUG_DISABLE_SHARED_ATLAS))
@ -230,13 +230,13 @@ cogl_pango_glyph_cache_add_to_global_atlas (CoglPangoGlyphCache *cache,
texture = cogl_atlas_texture_new_with_size (cache->ctx, texture = cogl_atlas_texture_new_with_size (cache->ctx,
value->draw_width, value->draw_width,
value->draw_height); value->draw_height);
if (!cogl_texture_allocate (COGL_TEXTURE (texture), &ignore_error)) if (!cogl_texture_allocate (texture, &ignore_error))
{ {
g_error_free (ignore_error); g_error_free (ignore_error);
return FALSE; return FALSE;
} }
value->texture = COGL_TEXTURE (texture); value->texture = texture;
value->tx1 = 0; value->tx1 = 0;
value->ty1 = 0; value->ty1 = 0;
value->tx2 = 1; value->tx2 = 1;

View File

@ -64,7 +64,7 @@ _cogl_pango_pipeline_cache_value_destroy (void *data)
CoglPangoPipelineCacheEntry *cache_entry = data; CoglPangoPipelineCacheEntry *cache_entry = data;
if (cache_entry->texture) if (cache_entry->texture)
cogl_object_unref (cache_entry->texture); g_object_unref (cache_entry->texture);
/* We don't need to unref the pipeline because it only takes a weak /* We don't need to unref the pipeline because it only takes a weak
reference */ reference */
@ -188,7 +188,7 @@ _cogl_pango_pipeline_cache_get (CoglPangoPipelineCache *cache,
{ {
CoglPipeline *base; CoglPipeline *base;
entry->texture = cogl_object_ref (texture); entry->texture = g_object_ref (texture);
if (_cogl_texture_get_format (entry->texture) == COGL_PIXEL_FORMAT_A_8) if (_cogl_texture_get_format (entry->texture) == COGL_PIXEL_FORMAT_A_8)
base = get_base_texture_alpha_pipeline (cache); base = get_base_texture_alpha_pipeline (cache);
@ -216,7 +216,7 @@ _cogl_pango_pipeline_cache_get (CoglPangoPipelineCache *cache,
pipeline_destroy_notify_cb); pipeline_destroy_notify_cb);
g_hash_table_insert (cache->hash_table, g_hash_table_insert (cache->hash_table,
texture ? cogl_object_ref (texture) : NULL, texture ? g_object_ref (texture) : NULL,
entry); entry);
/* This doesn't take a reference on the pipeline so that it will use /* This doesn't take a reference on the pipeline so that it will use

View File

@ -175,7 +175,7 @@ cogl_pango_renderer_draw_glyph (CoglPangoRenderer *priv,
the neighbouring glyphs are coming from the same atlas and bundle the neighbouring glyphs are coming from the same atlas and bundle
them together into a single VBO */ them together into a single VBO */
cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (cache_value->texture), cogl_meta_texture_foreach_in_region (cache_value->texture,
cache_value->tx1, cache_value->tx1,
cache_value->ty1, cache_value->ty1,
cache_value->tx2, cache_value->tx2,

View File

@ -30,7 +30,6 @@
#pragma once #pragma once
#include "cogl/cogl-object-private.h"
#include "cogl/cogl-texture-private.h" #include "cogl/cogl-texture-private.h"
#include "cogl/cogl-rectangle-map.h" #include "cogl/cogl-rectangle-map.h"
#include "cogl/cogl-atlas.h" #include "cogl/cogl-atlas.h"
@ -38,7 +37,7 @@
struct _CoglAtlasTexture struct _CoglAtlasTexture
{ {
CoglTexture _parent; CoglTexture parent_instance;
/* The format that the texture is in. This isn't necessarily the /* The format that the texture is in. This isn't necessarily the
same format as the atlas texture because we can store same format as the atlas texture because we can store
@ -60,6 +59,11 @@ struct _CoglAtlasTexture
CoglTexture *sub_texture; CoglTexture *sub_texture;
}; };
struct _CoglAtlasTextureClass
{
CoglTextureClass parent_class;
};
COGL_EXPORT void COGL_EXPORT void
_cogl_atlas_texture_add_reorganize_callback (CoglContext *ctx, _cogl_atlas_texture_add_reorganize_callback (CoglContext *ctx,
GHookFunc callback, GHookFunc callback,
@ -69,6 +73,3 @@ COGL_EXPORT void
_cogl_atlas_texture_remove_reorganize_callback (CoglContext *ctx, _cogl_atlas_texture_remove_reorganize_callback (CoglContext *ctx,
GHookFunc callback, GHookFunc callback,
void *user_data); void *user_data);
gboolean
_cogl_is_atlas_texture (void *object);

View File

@ -40,31 +40,50 @@
#include "cogl/cogl-texture-2d-private.h" #include "cogl/cogl-texture-2d-private.h"
#include "cogl/cogl-sub-texture-private.h" #include "cogl/cogl-sub-texture-private.h"
#include "cogl/cogl-context-private.h" #include "cogl/cogl-context-private.h"
#include "cogl/cogl-object-private.h"
#include "cogl/cogl-texture-driver.h" #include "cogl/cogl-texture-driver.h"
#include "cogl/cogl-rectangle-map.h" #include "cogl/cogl-rectangle-map.h"
#include "cogl/cogl-journal-private.h" #include "cogl/cogl-journal-private.h"
#include "cogl/cogl-atlas.h" #include "cogl/cogl-atlas.h"
#include "cogl/cogl1-context.h" #include "cogl/cogl1-context.h"
#include "cogl/cogl-sub-texture.h" #include "cogl/cogl-sub-texture.h"
#include "cogl/cogl-gtype-private.h"
#include "cogl/driver/gl/cogl-texture-gl-private.h" #include "cogl/driver/gl/cogl-texture-gl-private.h"
#include <stdlib.h> #include <stdlib.h>
static void _cogl_atlas_texture_free (CoglAtlasTexture *sub_tex);
static GQuark atlas_private_key = 0; static GQuark atlas_private_key = 0;
COGL_TEXTURE_DEFINE (AtlasTexture, atlas_texture); G_DEFINE_FINAL_TYPE (CoglAtlasTexture, cogl_atlas_texture, COGL_TYPE_TEXTURE)
COGL_GTYPE_DEFINE_CLASS (AtlasTexture, atlas_texture);
static const CoglTextureVtable cogl_atlas_texture_vtable; static void
_cogl_atlas_texture_remove_from_atlas (CoglAtlasTexture *atlas_tex)
{
if (atlas_tex->atlas)
{
_cogl_atlas_remove (atlas_tex->atlas,
&atlas_tex->rectangle);
static CoglSubTexture * g_object_unref (atlas_tex->atlas);
atlas_tex->atlas = NULL;
}
}
static void
cogl_atlas_texture_dispose (GObject *object)
{
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (object);
_cogl_atlas_texture_remove_from_atlas (atlas_tex);
if (atlas_tex->sub_texture)
g_object_unref (atlas_tex->sub_texture);
G_OBJECT_CLASS (cogl_atlas_texture_parent_class)->dispose (object);
}
static CoglTexture *
_cogl_atlas_texture_create_sub_texture (CoglTexture *full_texture, _cogl_atlas_texture_create_sub_texture (CoglTexture *full_texture,
const CoglRectangleMapEntry *rectangle) const CoglRectangleMapEntry *rectangle)
{ {
CoglContext *ctx = full_texture->context; CoglContext *ctx = cogl_texture_get_context (full_texture);
/* Create a subtexture for the given rectangle not including the /* Create a subtexture for the given rectangle not including the
1-pixel border */ 1-pixel border */
return cogl_sub_texture_new (ctx, return cogl_sub_texture_new (ctx,
@ -84,9 +103,9 @@ _cogl_atlas_texture_update_position_cb (void *user_data,
/* Update the sub texture */ /* Update the sub texture */
if (atlas_tex->sub_texture) if (atlas_tex->sub_texture)
cogl_object_unref (atlas_tex->sub_texture); g_object_unref (atlas_tex->sub_texture);
atlas_tex->sub_texture = COGL_TEXTURE ( atlas_tex->sub_texture =
_cogl_atlas_texture_create_sub_texture (new_texture, rectangle)); _cogl_atlas_texture_create_sub_texture (new_texture, rectangle);
/* Update the position */ /* Update the position */
atlas_tex->rectangle = *rectangle; atlas_tex->rectangle = *rectangle;
@ -102,7 +121,7 @@ _cogl_atlas_texture_pre_reorganize_foreach_cb
/* Keep a reference to the texture because we don't want it to be /* Keep a reference to the texture because we don't want it to be
destroyed during the reorganization */ destroyed during the reorganization */
cogl_object_ref (atlas_tex); g_object_ref (atlas_tex);
/* Notify cogl-pipeline.c that the texture's underlying GL texture /* Notify cogl-pipeline.c that the texture's underlying GL texture
* storage is changing so it knows it may need to bind a new texture * storage is changing so it knows it may need to bind a new texture
@ -178,7 +197,7 @@ _cogl_atlas_texture_post_reorganize_cb (void *user_data)
the structure for the texture so that it can get stored the structure for the texture so that it can get stored
in the atlas but it isn't a valid object yet */ in the atlas but it isn't a valid object yet */
if (data.textures[i]->atlas) if (data.textures[i]->atlas)
cogl_object_unref (data.textures[i]); g_object_unref (data.textures[i]);
} }
g_free (data.textures); g_free (data.textures);
@ -237,10 +256,9 @@ _cogl_atlas_texture_foreach_sub_texture_in_region (
void *user_data) void *user_data)
{ {
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex); CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
CoglMetaTexture *meta_texture = COGL_META_TEXTURE (atlas_tex->sub_texture);
/* Forward on to the sub texture */ /* Forward on to the sub texture */
cogl_meta_texture_foreach_in_region (meta_texture, cogl_meta_texture_foreach_in_region (atlas_tex->sub_texture,
virtual_tx_1, virtual_tx_1,
virtual_ty_1, virtual_ty_1,
virtual_tx_2, virtual_tx_2,
@ -264,31 +282,6 @@ _cogl_atlas_texture_gl_flush_legacy_texobj_wrap_modes (CoglTexture *tex,
wrap_mode_t); wrap_mode_t);
} }
static void
_cogl_atlas_texture_remove_from_atlas (CoglAtlasTexture *atlas_tex)
{
if (atlas_tex->atlas)
{
_cogl_atlas_remove (atlas_tex->atlas,
&atlas_tex->rectangle);
g_object_unref (atlas_tex->atlas);
atlas_tex->atlas = NULL;
}
}
static void
_cogl_atlas_texture_free (CoglAtlasTexture *atlas_tex)
{
_cogl_atlas_texture_remove_from_atlas (atlas_tex);
if (atlas_tex->sub_texture)
cogl_object_unref (atlas_tex->sub_texture);
/* Chain up */
_cogl_texture_free (COGL_TEXTURE (atlas_tex));
}
static int static int
_cogl_atlas_texture_get_max_waste (CoglTexture *tex) _cogl_atlas_texture_get_max_waste (CoglTexture *tex)
{ {
@ -410,7 +403,7 @@ _cogl_atlas_texture_migrate_out_of_atlas (CoglAtlasTexture *atlas_tex)
the copy can involve rendering which might cause the texture the copy can involve rendering which might cause the texture
to be used if it is used from a layer that is left in a to be used if it is used from a layer that is left in a
texture unit */ texture unit */
cogl_object_unref (atlas_tex->sub_texture); g_object_unref (atlas_tex->sub_texture);
atlas_tex->sub_texture = standalone_tex; atlas_tex->sub_texture = standalone_tex;
_cogl_atlas_texture_remove_from_atlas (atlas_tex); _cogl_atlas_texture_remove_from_atlas (atlas_tex);
@ -648,60 +641,6 @@ _cogl_atlas_texture_can_use_format (CoglPixelFormat format)
format == COGL_PIXEL_FORMAT_RGBA_8888); format == COGL_PIXEL_FORMAT_RGBA_8888);
} }
static CoglAtlasTexture *
_cogl_atlas_texture_create_base (CoglContext *ctx,
int width,
int height,
CoglPixelFormat internal_format,
CoglTextureLoader *loader)
{
CoglAtlasTexture *atlas_tex;
COGL_NOTE (ATLAS, "Adding texture of size %ix%i", width, height);
/* We need to allocate the texture now because we need the pointer
to set as the data for the rectangle in the atlas */
atlas_tex = g_new0 (CoglAtlasTexture, 1);
/* Mark it as having no atlas so we don't try to unref it in
_cogl_atlas_texture_post_reorganize_cb */
atlas_tex->atlas = NULL;
_cogl_texture_init (COGL_TEXTURE (atlas_tex),
ctx,
width, height,
internal_format,
loader,
&cogl_atlas_texture_vtable);
atlas_tex->sub_texture = NULL;
atlas_tex->atlas = NULL;
return _cogl_atlas_texture_object_new (atlas_tex);
}
CoglAtlasTexture *
cogl_atlas_texture_new_with_size (CoglContext *ctx,
int width,
int height)
{
CoglTextureLoader *loader;
/* We can't atlas zero-sized textures because it breaks the atlas
* data structure */
g_return_val_if_fail (width > 0 && height > 0, NULL);
loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZE;
loader->src.sized.width = width;
loader->src.sized.height = height;
loader->src.sized.format = COGL_PIXEL_FORMAT_ANY;
return _cogl_atlas_texture_create_base (ctx, width, height,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
loader);
}
static gboolean static gboolean
allocate_space (CoglAtlasTexture *atlas_tex, allocate_space (CoglAtlasTexture *atlas_tex,
int width, int width,
@ -710,7 +649,7 @@ allocate_space (CoglAtlasTexture *atlas_tex,
GError **error) GError **error)
{ {
CoglTexture *tex = COGL_TEXTURE (atlas_tex); CoglTexture *tex = COGL_TEXTURE (atlas_tex);
CoglContext *ctx = tex->context; CoglContext *ctx = cogl_texture_get_context (tex);
CoglAtlas *atlas; CoglAtlas *atlas;
GSList *l; GSList *l;
@ -795,7 +734,7 @@ allocate_with_size (CoglAtlasTexture *atlas_tex,
internal_format, internal_format,
error)) error))
{ {
_cogl_texture_set_allocated (COGL_TEXTURE (atlas_tex), _cogl_texture_set_allocated (tex,
internal_format, internal_format,
loader->src.sized.width, loader->src.sized.width,
loader->src.sized.height); loader->src.sized.height);
@ -869,7 +808,7 @@ _cogl_atlas_texture_allocate (CoglTexture *tex,
GError **error) GError **error)
{ {
CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex); CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex);
CoglTextureLoader *loader = tex->loader; CoglTextureLoader *loader = cogl_texture_get_loader (tex);
g_return_val_if_fail (loader, FALSE); g_return_val_if_fail (loader, FALSE);
@ -886,7 +825,95 @@ _cogl_atlas_texture_allocate (CoglTexture *tex,
g_return_val_if_reached (FALSE); g_return_val_if_reached (FALSE);
} }
CoglAtlasTexture * static void
cogl_atlas_texture_class_init (CoglAtlasTextureClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
CoglTextureClass *texture_class = COGL_TEXTURE_CLASS (klass);
object_class->dispose = cogl_atlas_texture_dispose;
texture_class->allocate = _cogl_atlas_texture_allocate;
texture_class->set_region = _cogl_atlas_texture_set_region;
texture_class->foreach_sub_texture_in_region = _cogl_atlas_texture_foreach_sub_texture_in_region;
texture_class->get_max_waste = _cogl_atlas_texture_get_max_waste;
texture_class->is_sliced = _cogl_atlas_texture_is_sliced;
texture_class->can_hardware_repeat = _cogl_atlas_texture_can_hardware_repeat;
texture_class->transform_coords_to_gl = _cogl_atlas_texture_transform_coords_to_gl;
texture_class->transform_quad_coords_to_gl = _cogl_atlas_texture_transform_quad_coords_to_gl;
texture_class->get_gl_texture = _cogl_atlas_texture_get_gl_texture;
texture_class->gl_flush_legacy_texobj_filters = _cogl_atlas_texture_gl_flush_legacy_texobj_filters;
texture_class->pre_paint = _cogl_atlas_texture_pre_paint;
texture_class->ensure_non_quad_rendering = _cogl_atlas_texture_ensure_non_quad_rendering;
texture_class->gl_flush_legacy_texobj_wrap_modes = _cogl_atlas_texture_gl_flush_legacy_texobj_wrap_modes;
texture_class->get_format = _cogl_atlas_texture_get_format;
texture_class->get_gl_format = _cogl_atlas_texture_get_gl_format;
}
static void
cogl_atlas_texture_init (CoglAtlasTexture *self)
{
CoglTexture *texture = COGL_TEXTURE (self);
texture->is_primitive = FALSE;
}
static CoglTexture *
_cogl_atlas_texture_create_base (CoglContext *ctx,
int width,
int height,
CoglPixelFormat internal_format,
CoglTextureLoader *loader)
{
CoglAtlasTexture *atlas_tex;
CoglTexture *tex;
COGL_NOTE (ATLAS, "Adding texture of size %ix%i", width, height);
/* We need to allocate the texture now because we need the pointer
to set as the data for the rectangle in the atlas */
atlas_tex = g_object_new (COGL_TYPE_ATLAS_TEXTURE, NULL);
/* Mark it as having no atlas so we don't try to unref it in
_cogl_atlas_texture_post_reorganize_cb */
atlas_tex->atlas = NULL;
tex = COGL_TEXTURE (atlas_tex);
_cogl_texture_init (tex,
ctx,
width, height,
internal_format,
loader);
atlas_tex->sub_texture = NULL;
atlas_tex->atlas = NULL;
return tex;
}
CoglTexture *
cogl_atlas_texture_new_with_size (CoglContext *ctx,
int width,
int height)
{
CoglTextureLoader *loader;
/* We can't atlas zero-sized textures because it breaks the atlas
* data structure */
g_return_val_if_fail (width > 0 && height > 0, NULL);
loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZE;
loader->src.sized.width = width;
loader->src.sized.height = height;
loader->src.sized.format = COGL_PIXEL_FORMAT_ANY;
return _cogl_atlas_texture_create_base (ctx, width, height,
COGL_PIXEL_FORMAT_RGBA_8888_PRE,
loader);
}
CoglTexture *
cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp) cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp)
{ {
CoglTextureLoader *loader; CoglTextureLoader *loader;
@ -904,7 +931,7 @@ cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp)
loader); loader);
} }
CoglAtlasTexture * CoglTexture *
cogl_atlas_texture_new_from_data (CoglContext *ctx, cogl_atlas_texture_new_from_data (CoglContext *ctx,
int width, int width,
int height, int height,
@ -914,7 +941,7 @@ cogl_atlas_texture_new_from_data (CoglContext *ctx,
GError **error) GError **error)
{ {
CoglBitmap *bmp; CoglBitmap *bmp;
CoglAtlasTexture *atlas_tex; CoglTexture *atlas_tex;
g_return_val_if_fail (format != COGL_PIXEL_FORMAT_ANY, NULL); g_return_val_if_fail (format != COGL_PIXEL_FORMAT_ANY, NULL);
g_return_val_if_fail (cogl_pixel_format_get_n_planes (format) == 1, NULL); g_return_val_if_fail (cogl_pixel_format_get_n_planes (format) == 1, NULL);
@ -938,7 +965,7 @@ cogl_atlas_texture_new_from_data (CoglContext *ctx,
if (atlas_tex && if (atlas_tex &&
!cogl_texture_allocate (COGL_TEXTURE (atlas_tex), error)) !cogl_texture_allocate (COGL_TEXTURE (atlas_tex), error))
{ {
cogl_object_unref (atlas_tex); g_object_unref (atlas_tex);
return NULL; return NULL;
} }
@ -969,27 +996,3 @@ _cogl_atlas_texture_remove_reorganize_callback (CoglContext *ctx,
if (hook) if (hook)
g_hook_destroy_link (&ctx->atlas_reorganize_callbacks, hook); g_hook_destroy_link (&ctx->atlas_reorganize_callbacks, hook);
} }
static const CoglTextureVtable
cogl_atlas_texture_vtable =
{
FALSE, /* not primitive */
_cogl_atlas_texture_allocate,
_cogl_atlas_texture_set_region,
NULL, /* is_get_data_supported */
NULL, /* get_data */
_cogl_atlas_texture_foreach_sub_texture_in_region,
_cogl_atlas_texture_get_max_waste,
_cogl_atlas_texture_is_sliced,
_cogl_atlas_texture_can_hardware_repeat,
_cogl_atlas_texture_transform_coords_to_gl,
_cogl_atlas_texture_transform_quad_coords_to_gl,
_cogl_atlas_texture_get_gl_texture,
_cogl_atlas_texture_gl_flush_legacy_texobj_filters,
_cogl_atlas_texture_pre_paint,
_cogl_atlas_texture_ensure_non_quad_rendering,
_cogl_atlas_texture_gl_flush_legacy_texobj_wrap_modes,
_cogl_atlas_texture_get_format,
_cogl_atlas_texture_get_gl_format,
NULL /* set_auto_mipmap */
};

View File

@ -41,8 +41,9 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/** /**
* SECTION:cogl-atlas-texture * CoglAtlasTexture:
* @short_description: Functions for managing textures in Cogl's global *
* Functions for managing textures in Cogl's global
* set of texture atlases * set of texture atlases
* *
* A texture atlas is a texture that contains many smaller images that * A texture atlas is a texture that contains many smaller images that
@ -63,18 +64,21 @@ G_BEGIN_DECLS
* some limitations to be aware of. Please see the documentation for * some limitations to be aware of. Please see the documentation for
* #CoglMetaTexture for more details.</note> * #CoglMetaTexture for more details.</note>
*/ */
#define COGL_TYPE_ATLAS_TEXTURE (cogl_atlas_texture_get_type ())
#define COGL_ATLAS_TEXTURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COGL_TYPE_ATLAS_TEXTURE, CoglAtlasTexture))
#define COGL_ATLAS_TEXTURE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COGL_TYPE_ATLAS_TEXTURE, CoglAtlasTexture const))
#define COGL_ATLAS_TEXTURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COGL_TYPE_ATLAS_TEXTURE, CoglAtlasTextureClass))
#define COGL_IS_ATLAS_TEXTURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COGL_TYPE_ATLAS_TEXTURE))
#define COGL_IS_ATLAS_TEXTURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COGL_TYPE_ATLAS_TEXTURE))
#define COGL_ATLAS_TEXTURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), COGL_TYPE_ATLAS_TEXTURE, CoglAtlasTextureClass))
typedef struct _CoglAtlasTextureClass CoglAtlasTextureClass;
typedef struct _CoglAtlasTexture CoglAtlasTexture; typedef struct _CoglAtlasTexture CoglAtlasTexture;
#define COGL_ATLAS_TEXTURE(tex) ((CoglAtlasTexture *) tex)
/** G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglAtlasTexture, g_object_unref)
* cogl_atlas_texture_get_gtype:
*
* Returns: a #GType that can be used with the GLib type system.
*/
COGL_EXPORT COGL_EXPORT
GType cogl_atlas_texture_get_gtype (void); GType cogl_atlas_texture_get_type (void) G_GNUC_CONST;
/** /**
* cogl_atlas_texture_new_with_size: * cogl_atlas_texture_new_with_size:
@ -106,7 +110,7 @@ GType cogl_atlas_texture_get_gtype (void);
* *
* Returns: (transfer full): A new #CoglAtlasTexture object. * Returns: (transfer full): A new #CoglAtlasTexture object.
*/ */
COGL_EXPORT CoglAtlasTexture * COGL_EXPORT CoglTexture *
cogl_atlas_texture_new_with_size (CoglContext *ctx, cogl_atlas_texture_new_with_size (CoglContext *ctx,
int width, int width,
int height); int height);
@ -149,7 +153,7 @@ cogl_atlas_texture_new_with_size (CoglContext *ctx,
* Return value: (transfer full): A new #CoglAtlasTexture object or * Return value: (transfer full): A new #CoglAtlasTexture object or
* %NULL on failure and @error will be updated. * %NULL on failure and @error will be updated.
*/ */
COGL_EXPORT CoglAtlasTexture * COGL_EXPORT CoglTexture *
cogl_atlas_texture_new_from_data (CoglContext *ctx, cogl_atlas_texture_new_from_data (CoglContext *ctx,
int width, int width,
int height, int height,
@ -187,19 +191,7 @@ cogl_atlas_texture_new_from_data (CoglContext *ctx,
* *
* Returns: (transfer full): A new #CoglAtlasTexture object. * Returns: (transfer full): A new #CoglAtlasTexture object.
*/ */
COGL_EXPORT CoglAtlasTexture * COGL_EXPORT CoglTexture *
cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp); cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp);
/**
* cogl_is_atlas_texture:
* @object: a #CoglObject
*
* Checks whether the given object references a #CoglAtlasTexture
*
* Return value: %TRUE if the passed object represents an atlas
* texture and %FALSE otherwise
*/
COGL_EXPORT gboolean
cogl_is_atlas_texture (void *object);
G_END_DECLS G_END_DECLS

View File

@ -55,7 +55,7 @@ cogl_atlas_dispose (GObject *object)
COGL_NOTE (ATLAS, "%p: Atlas destroyed", atlas); COGL_NOTE (ATLAS, "%p: Atlas destroyed", atlas);
if (atlas->texture) if (atlas->texture)
cogl_object_unref (atlas->texture); g_object_unref (atlas->texture);
if (atlas->map) if (atlas->map)
_cogl_rectangle_map_free (atlas->map); _cogl_rectangle_map_free (atlas->map);
@ -291,12 +291,12 @@ _cogl_atlas_create_map (CoglPixelFormat format,
return NULL; return NULL;
} }
static CoglTexture2D * static CoglTexture *
_cogl_atlas_create_texture (CoglAtlas *atlas, _cogl_atlas_create_texture (CoglAtlas *atlas,
int width, int width,
int height) int height)
{ {
CoglTexture2D *tex; CoglTexture *tex;
GError *ignore_error = NULL; GError *ignore_error = NULL;
_COGL_GET_CONTEXT (ctx, NULL); _COGL_GET_CONTEXT (ctx, NULL);
@ -323,13 +323,13 @@ _cogl_atlas_create_texture (CoglAtlas *atlas,
tex = cogl_texture_2d_new_from_bitmap (clear_bmp); tex = cogl_texture_2d_new_from_bitmap (clear_bmp);
_cogl_texture_set_internal_format (COGL_TEXTURE (tex), _cogl_texture_set_internal_format (tex,
atlas->texture_format); atlas->texture_format);
if (!cogl_texture_allocate (COGL_TEXTURE (tex), &ignore_error)) if (!cogl_texture_allocate (tex, &ignore_error))
{ {
g_error_free (ignore_error); g_error_free (ignore_error);
cogl_object_unref (tex); g_object_unref (tex);
tex = NULL; tex = NULL;
} }
@ -341,13 +341,13 @@ _cogl_atlas_create_texture (CoglAtlas *atlas,
{ {
tex = cogl_texture_2d_new_with_size (ctx, width, height); tex = cogl_texture_2d_new_with_size (ctx, width, height);
_cogl_texture_set_internal_format (COGL_TEXTURE (tex), _cogl_texture_set_internal_format (tex,
atlas->texture_format); atlas->texture_format);
if (!cogl_texture_allocate (COGL_TEXTURE (tex), &ignore_error)) if (!cogl_texture_allocate (tex, &ignore_error))
{ {
g_error_free (ignore_error); g_error_free (ignore_error);
cogl_object_unref (tex); g_object_unref (tex);
tex = NULL; tex = NULL;
} }
} }
@ -389,7 +389,7 @@ _cogl_atlas_reserve_space (CoglAtlas *atlas,
{ {
CoglAtlasGetRectanglesData data; CoglAtlasGetRectanglesData data;
CoglRectangleMap *new_map; CoglRectangleMap *new_map;
CoglTexture2D *new_tex; CoglTexture *new_tex;
unsigned int map_width = 0, map_height = 0; unsigned int map_width = 0, map_height = 0;
gboolean ret; gboolean ret;
CoglRectangleMapEntry new_position; CoglRectangleMapEntry new_position;
@ -516,20 +516,20 @@ _cogl_atlas_reserve_space (CoglAtlas *atlas,
data.n_textures, data.n_textures,
data.textures, data.textures,
atlas->texture, atlas->texture,
COGL_TEXTURE (new_tex), new_tex,
user_data); user_data);
_cogl_rectangle_map_free (atlas->map); _cogl_rectangle_map_free (atlas->map);
cogl_object_unref (atlas->texture); g_object_unref (atlas->texture);
} }
else else
/* We know there's only one texture so we can just directly /* We know there's only one texture so we can just directly
update the rectangle from its new position */ update the rectangle from its new position */
atlas->update_position_cb (data.textures[0].user_data, atlas->update_position_cb (data.textures[0].user_data,
COGL_TEXTURE (new_tex), new_tex,
&data.textures[0].new_position); &data.textures[0].new_position);
atlas->map = new_map; atlas->map = new_map;
atlas->texture = COGL_TEXTURE (new_tex); atlas->texture = new_tex;
waste = (_cogl_rectangle_map_get_remaining_space (atlas->map) * waste = (_cogl_rectangle_map_get_remaining_space (atlas->map) *
100 / (_cogl_rectangle_map_get_width (atlas->map) * 100 / (_cogl_rectangle_map_get_width (atlas->map) *
@ -582,7 +582,7 @@ create_migration_texture (CoglContext *ctx,
GError *skip_error = NULL; GError *skip_error = NULL;
/* First try creating a fast-path non-sliced texture */ /* First try creating a fast-path non-sliced texture */
tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, width, height)); tex = cogl_texture_2d_new_with_size (ctx, width, height);
_cogl_texture_set_internal_format (tex, internal_format); _cogl_texture_set_internal_format (tex, internal_format);
@ -593,22 +593,19 @@ create_migration_texture (CoglContext *ctx,
if (!cogl_texture_allocate (tex, &skip_error)) if (!cogl_texture_allocate (tex, &skip_error))
{ {
g_error_free (skip_error); g_error_free (skip_error);
cogl_object_unref (tex); g_object_unref (tex);
tex = NULL; tex = NULL;
} }
if (!tex) if (!tex)
{ {
CoglTexture2DSliced *tex_2ds = tex = cogl_texture_2d_sliced_new_with_size (ctx,
cogl_texture_2d_sliced_new_with_size (ctx,
width, width,
height, height,
COGL_TEXTURE_MAX_WASTE); COGL_TEXTURE_MAX_WASTE);
_cogl_texture_set_internal_format (COGL_TEXTURE (tex_2ds), _cogl_texture_set_internal_format (tex,
internal_format); internal_format);
tex = COGL_TEXTURE (tex_2ds);
} }
return tex; return tex;
@ -633,7 +630,7 @@ _cogl_atlas_copy_rectangle (CoglAtlas *atlas,
if (!cogl_texture_allocate (tex, &ignore_error)) if (!cogl_texture_allocate (tex, &ignore_error))
{ {
g_error_free (ignore_error); g_error_free (ignore_error);
cogl_object_unref (tex); g_object_unref (tex);
return NULL; return NULL;
} }

View File

@ -48,7 +48,7 @@ static const CoglBlitMode *_cogl_blit_default_mode = NULL;
static gboolean static gboolean
_cogl_blit_texture_render_begin (CoglBlitData *data) _cogl_blit_texture_render_begin (CoglBlitData *data)
{ {
CoglContext *ctx = data->src_tex->context; CoglContext *ctx = cogl_texture_get_context (data->src_tex);
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
CoglFramebuffer *fb; CoglFramebuffer *fb;
CoglPipeline *pipeline; CoglPipeline *pipeline;
@ -129,7 +129,7 @@ _cogl_blit_texture_render_blit (CoglBlitData *data,
static void static void
_cogl_blit_texture_render_end (CoglBlitData *data) _cogl_blit_texture_render_end (CoglBlitData *data)
{ {
CoglContext *ctx = data->src_tex->context; CoglContext *ctx = cogl_texture_get_context (data->src_tex);
/* Attach the target texture to the texture render pipeline so that /* Attach the target texture to the texture render pipeline so that
we don't keep a reference to the source texture forever. This is we don't keep a reference to the source texture forever. This is
@ -148,7 +148,7 @@ _cogl_blit_texture_render_end (CoglBlitData *data)
static gboolean static gboolean
_cogl_blit_framebuffer_begin (CoglBlitData *data) _cogl_blit_framebuffer_begin (CoglBlitData *data)
{ {
CoglContext *ctx = data->src_tex->context; CoglContext *ctx = cogl_texture_get_context (data->src_tex);
CoglOffscreen *dst_offscreen = NULL, *src_offscreen = NULL; CoglOffscreen *dst_offscreen = NULL, *src_offscreen = NULL;
CoglFramebuffer *dst_fb, *src_fb; CoglFramebuffer *dst_fb, *src_fb;
GError *ignore_error = NULL; GError *ignore_error = NULL;
@ -228,7 +228,7 @@ _cogl_blit_copy_tex_sub_image_begin (CoglBlitData *data)
GError *ignore_error = NULL; GError *ignore_error = NULL;
/* This will only work if the target texture is a CoglTexture2D */ /* This will only work if the target texture is a CoglTexture2D */
if (!cogl_is_texture_2d (data->dst_tex)) if (!COGL_IS_TEXTURE_2D (data->dst_tex))
return FALSE; return FALSE;
offscreen = _cogl_offscreen_new_with_texture_full offscreen = _cogl_offscreen_new_with_texture_full

View File

@ -134,7 +134,7 @@ struct _CoglContext
CoglPipelineCache *pipeline_cache; CoglPipelineCache *pipeline_cache;
/* Textures */ /* Textures */
CoglTexture2D *default_gl_texture_2d_tex; CoglTexture *default_gl_texture_2d_tex;
/* Central list of all framebuffers so all journals can be flushed /* Central list of all framebuffers so all journals can be flushed
* at any time. */ * at any time. */

View File

@ -78,7 +78,7 @@ cogl_context_dispose (GObject *object)
winsys->context_deinit (context); winsys->context_deinit (context);
if (context->default_gl_texture_2d_tex) if (context->default_gl_texture_2d_tex)
cogl_object_unref (context->default_gl_texture_2d_tex); g_object_unref (context->default_gl_texture_2d_tex);
if (context->opaque_color_pipeline) if (context->opaque_color_pipeline)
cogl_object_unref (context->opaque_color_pipeline); cogl_object_unref (context->opaque_color_pipeline);

View File

@ -59,15 +59,6 @@ struct _CoglGtypeClass
/**/ /**/
#define COGL_GTYPE_IMPLEMENT_INTERFACE(name) { \
const GInterfaceInfo g_implement_interface_info = { \
(GInterfaceInitFunc) _cogl_gtype_dummy_iface_init, NULL, NULL \
}; \
g_type_add_interface_static (fundamental_type_id, \
cogl_##name##_get_gtype(), \
&g_implement_interface_info); \
}
#define _COGL_GTYPE_DEFINE_BASE_CLASS_BEGIN(Name,name) \ #define _COGL_GTYPE_DEFINE_BASE_CLASS_BEGIN(Name,name) \
GType \ GType \
cogl_##name##_get_gtype (void) \ cogl_##name##_get_gtype (void) \
@ -121,52 +112,6 @@ cogl_##name##_get_gtype (void) \
{__VA_ARGS__;} \ {__VA_ARGS__;} \
_COGL_GTYPE_DEFINE_BASE_CLASS_END() _COGL_GTYPE_DEFINE_BASE_CLASS_END()
#define _COGL_GTYPE_DEFINE_INTERFACE_EXTENDED_BEGIN(Name,name) \
\
static void name##_default_init (Name##Interface *klass); \
GType \
name##_get_gtype (void) \
{ \
static size_t g_type_id = 0; \
if (g_once_init_enter (&g_type_id)) \
{ \
GType fundamental_type_id = \
g_type_register_static_simple (G_TYPE_INTERFACE, \
g_intern_static_string (#Name), \
sizeof (Name##Interface), \
(GClassInitFunc)name##_default_init, \
0, \
(GInstanceInitFunc)NULL, \
(GTypeFlags) 0); \
g_type_interface_add_prerequisite (fundamental_type_id, \
cogl_object_get_gtype()); \
{ /* custom code follows */
#define _COGL_GTYPE_DEFINE_INTERFACE_EXTENDED_END() \
/* following custom code */ \
} \
g_once_init_leave (&g_type_id, \
fundamental_type_id); \
} \
return g_type_id; \
} /* closes name##_get_type() */
#define COGL_GTYPE_DEFINE_INTERFACE(Name,name) \
typedef struct _Cogl##Name##Iface Cogl##Name##Iface; \
typedef Cogl##Name##Iface Cogl##Name##Interface; \
struct _Cogl##Name##Iface \
{ \
/*< private >*/ \
GTypeInterface g_iface; \
}; \
_COGL_GTYPE_DEFINE_INTERFACE_EXTENDED_BEGIN (Cogl##Name, cogl_##name) \
_COGL_GTYPE_DEFINE_INTERFACE_EXTENDED_END () \
static void \
cogl_##name##_default_init (Cogl##Name##Interface *iface) \
{ \
}
#define _COGL_GTYPE_DEFINE_TYPE_EXTENDED_BEGIN(Name,name,parent,flags) \ #define _COGL_GTYPE_DEFINE_TYPE_EXTENDED_BEGIN(Name,name,parent,flags) \
\ \
static void name##_init (Name *self); \ static void name##_init (Name *self); \

View File

@ -36,6 +36,7 @@
#include "cogl/cogl-spans.h" #include "cogl/cogl-spans.h"
#include "cogl/cogl-meta-texture.h" #include "cogl/cogl-meta-texture.h"
#include "cogl/cogl-texture-private.h" #include "cogl/cogl-texture-private.h"
#include "cogl/cogl-pipeline-layer-state.h"
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
@ -277,7 +278,7 @@ clamp_t_cb (CoglTexture *sub_texture,
} }
static gboolean static gboolean
foreach_clamped_region (CoglMetaTexture *meta_texture, foreach_clamped_region (CoglTexture *texture,
float *tx_1, float *tx_1,
float *ty_1, float *ty_1,
float *tx_2, float *tx_2,
@ -287,7 +288,7 @@ foreach_clamped_region (CoglMetaTexture *meta_texture,
CoglMetaTextureCallback callback, CoglMetaTextureCallback callback,
void *user_data) void *user_data)
{ {
float width = cogl_texture_get_width (COGL_TEXTURE (meta_texture)); float width = cogl_texture_get_width (texture);
ClampData clamp_data; ClampData clamp_data;
/* Consider that *tx_1 may be > *tx_2 and to simplify things /* Consider that *tx_1 may be > *tx_2 and to simplify things
@ -325,7 +326,7 @@ foreach_clamped_region (CoglMetaTexture *meta_texture,
{ {
clamp_data.start = *tx_1; clamp_data.start = *tx_1;
clamp_data.end = MIN (0, *tx_2); clamp_data.end = MIN (0, *tx_2);
cogl_meta_texture_foreach_in_region (meta_texture, cogl_meta_texture_foreach_in_region (texture,
half_texel_width, *ty_1, half_texel_width, *ty_1,
half_texel_width, *ty_2, half_texel_width, *ty_2,
COGL_PIPELINE_WRAP_MODE_REPEAT, COGL_PIPELINE_WRAP_MODE_REPEAT,
@ -345,7 +346,7 @@ foreach_clamped_region (CoglMetaTexture *meta_texture,
{ {
clamp_data.start = MAX (max_s_coord, *tx_1); clamp_data.start = MAX (max_s_coord, *tx_1);
clamp_data.end = *tx_2; clamp_data.end = *tx_2;
cogl_meta_texture_foreach_in_region (meta_texture, cogl_meta_texture_foreach_in_region (texture,
max_s_coord - half_texel_width, max_s_coord - half_texel_width,
*ty_1, *ty_1,
max_s_coord - half_texel_width, max_s_coord - half_texel_width,
@ -366,7 +367,7 @@ foreach_clamped_region (CoglMetaTexture *meta_texture,
if (wrap_t == COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE) if (wrap_t == COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE)
{ {
float height = cogl_texture_get_height (COGL_TEXTURE (meta_texture)); float height = cogl_texture_get_height (texture);
float max_t_coord = 1.0; float max_t_coord = 1.0;
float half_texel_height; float half_texel_height;
@ -377,7 +378,7 @@ foreach_clamped_region (CoglMetaTexture *meta_texture,
{ {
clamp_data.start = *ty_1; clamp_data.start = *ty_1;
clamp_data.end = MIN (0, *ty_2); clamp_data.end = MIN (0, *ty_2);
cogl_meta_texture_foreach_in_region (meta_texture, cogl_meta_texture_foreach_in_region (texture,
*tx_1, half_texel_height, *tx_1, half_texel_height,
*tx_2, half_texel_height, *tx_2, half_texel_height,
wrap_s, wrap_s,
@ -397,7 +398,7 @@ foreach_clamped_region (CoglMetaTexture *meta_texture,
{ {
clamp_data.start = MAX (max_t_coord, *ty_1); clamp_data.start = MAX (max_t_coord, *ty_1);
clamp_data.end = *ty_2; clamp_data.end = *ty_2;
cogl_meta_texture_foreach_in_region (meta_texture, cogl_meta_texture_foreach_in_region (texture,
*tx_1, *tx_1,
max_t_coord - half_texel_height, max_t_coord - half_texel_height,
*tx_2, *tx_2,
@ -452,7 +453,7 @@ normalize_meta_coords_cb (CoglTexture *slice_texture,
} }
void void
cogl_meta_texture_foreach_in_region (CoglMetaTexture *meta_texture, cogl_meta_texture_foreach_in_region (CoglTexture *texture,
float tx_1, float tx_1,
float ty_1, float ty_1,
float tx_2, float tx_2,
@ -462,7 +463,6 @@ cogl_meta_texture_foreach_in_region (CoglMetaTexture *meta_texture,
CoglMetaTextureCallback callback, CoglMetaTextureCallback callback,
void *user_data) void *user_data)
{ {
CoglTexture *texture = COGL_TEXTURE (meta_texture);
float width = cogl_texture_get_width (texture); float width = cogl_texture_get_width (texture);
float height = cogl_texture_get_height (texture); float height = cogl_texture_get_height (texture);
NormalizeData normalize_data; NormalizeData normalize_data;
@ -475,7 +475,7 @@ cogl_meta_texture_foreach_in_region (CoglMetaTexture *meta_texture,
if (wrap_s == COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE || if (wrap_s == COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE ||
wrap_t == COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE) wrap_t == COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE)
{ {
gboolean finished = foreach_clamped_region (meta_texture, gboolean finished = foreach_clamped_region (texture,
&tx_1, &ty_1, &tx_2, &ty_2, &tx_1, &ty_1, &tx_2, &ty_2,
wrap_s, wrap_t, wrap_s, wrap_t,
callback, callback,
@ -512,7 +512,7 @@ cogl_meta_texture_foreach_in_region (CoglMetaTexture *meta_texture,
* vtable, instead there will be a separate CoglMetaTexture * vtable, instead there will be a separate CoglMetaTexture
* interface vtable. */ * interface vtable. */
if (texture->vtable->foreach_sub_texture_in_region) if (COGL_TEXTURE_GET_CLASS (texture)->foreach_sub_texture_in_region)
{ {
ForeachData data; ForeachData data;
@ -554,7 +554,7 @@ cogl_meta_texture_foreach_in_region (CoglMetaTexture *meta_texture,
* that we can batch geometry. * that we can batch geometry.
*/ */
texture->vtable->foreach_sub_texture_in_region (texture, COGL_TEXTURE_GET_CLASS (texture)->foreach_sub_texture_in_region (texture,
0, 0, 1, 1, 0, 0, 1, 1,
create_grid_and_repeat_cb, create_grid_and_repeat_cb,
&data); &data);

View File

@ -89,17 +89,6 @@ G_BEGIN_DECLS
* meta-textures.</note> * meta-textures.</note>
*/ */
#if defined(__COGL_H_INSIDE__) && !defined(COGL_ENABLE_MUTTER_API) && \
!defined(COGL_GIR_SCANNING)
/* For the public C api we typedef interface types as void to avoid needing
* lots of casting in code and instead we will rely on runtime type checking
* for these objects. */
typedef void CoglMetaTexture;
#else
typedef struct _CoglMetaTexture CoglMetaTexture;
#define COGL_META_TEXTURE(X) ((CoglMetaTexture *)X)
#endif
/** /**
* CoglMetaTextureCallback: * CoglMetaTextureCallback:
* @sub_texture: A low-level #CoglTexture making up part of a * @sub_texture: A low-level #CoglTexture making up part of a
@ -171,7 +160,7 @@ typedef void (*CoglMetaTextureCallback) (CoglTexture *sub_texture,
* low-level texture maps to the original region. * low-level texture maps to the original region.
*/ */
COGL_EXPORT void COGL_EXPORT void
cogl_meta_texture_foreach_in_region (CoglMetaTexture *meta_texture, cogl_meta_texture_foreach_in_region (CoglTexture *texture,
float tx_1, float tx_1,
float ty_1, float ty_1,
float tx_2, float tx_2,

View File

@ -48,12 +48,12 @@ _cogl_offscreen_new_with_texture_full (CoglTexture *texture,
CoglOffscreenFlags flags, CoglOffscreenFlags flags,
int level) int level)
{ {
CoglContext *ctx = texture->context; CoglContext *ctx = cogl_texture_get_context (texture);
CoglFramebufferDriverConfig driver_config; CoglFramebufferDriverConfig driver_config;
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
CoglFramebuffer *fb; CoglFramebuffer *fb;
g_return_val_if_fail (cogl_is_texture (texture), NULL); g_return_val_if_fail (COGL_IS_TEXTURE (texture), NULL);
driver_config = (CoglFramebufferDriverConfig) { driver_config = (CoglFramebufferDriverConfig) {
.type = COGL_FRAMEBUFFER_DRIVER_TYPE_FBO, .type = COGL_FRAMEBUFFER_DRIVER_TYPE_FBO,
@ -64,7 +64,7 @@ _cogl_offscreen_new_with_texture_full (CoglTexture *texture,
"context", ctx, "context", ctx,
"driver-config", &driver_config, "driver-config", &driver_config,
NULL); NULL);
offscreen->texture = cogl_object_ref (texture); offscreen->texture = g_object_ref (texture);
offscreen->texture_level = level; offscreen->texture_level = level;
fb = COGL_FRAMEBUFFER (offscreen); fb = COGL_FRAMEBUFFER (offscreen);
@ -141,7 +141,7 @@ cogl_offscreen_dispose (GObject *object)
G_OBJECT_CLASS (cogl_offscreen_parent_class)->dispose (object); G_OBJECT_CLASS (cogl_offscreen_parent_class)->dispose (object);
cogl_clear_object (&offscreen->texture); g_clear_object (&offscreen->texture);
} }
static void static void

View File

@ -180,7 +180,7 @@ _cogl_pipeline_set_layer_texture_data (CoglPipeline *pipeline,
layer->differences &= ~change; layer->differences &= ~change;
if (layer->texture != NULL) if (layer->texture != NULL)
cogl_object_unref (layer->texture); g_object_unref (layer->texture);
g_assert (layer->owner == pipeline); g_assert (layer->owner == pipeline);
if (layer->differences == 0) if (layer->differences == 0)
@ -192,10 +192,10 @@ _cogl_pipeline_set_layer_texture_data (CoglPipeline *pipeline,
} }
if (texture != NULL) if (texture != NULL)
cogl_object_ref (texture); g_object_ref (texture);
if (layer == authority && if (layer == authority &&
layer->texture != NULL) layer->texture != NULL)
cogl_object_unref (layer->texture); g_object_unref (layer->texture);
layer->texture = texture; layer->texture = texture;
/* If we weren't previously the authority on this state then we need /* If we weren't previously the authority on this state then we need

View File

@ -189,7 +189,7 @@ _cogl_pipeline_layer_copy_differences (CoglPipelineLayer *dest,
case COGL_PIPELINE_LAYER_STATE_TEXTURE_DATA_INDEX: case COGL_PIPELINE_LAYER_STATE_TEXTURE_DATA_INDEX:
dest->texture = src->texture; dest->texture = src->texture;
if (dest->texture) if (dest->texture)
cogl_object_ref (dest->texture); g_object_ref (dest->texture);
break; break;
case COGL_PIPELINE_LAYER_STATE_SAMPLER_INDEX: case COGL_PIPELINE_LAYER_STATE_SAMPLER_INDEX:
@ -703,7 +703,7 @@ _cogl_pipeline_layer_free (CoglPipelineLayer *layer)
if (layer->differences & COGL_PIPELINE_LAYER_STATE_TEXTURE_DATA && if (layer->differences & COGL_PIPELINE_LAYER_STATE_TEXTURE_DATA &&
layer->texture != NULL) layer->texture != NULL)
cogl_object_unref (layer->texture); g_object_unref (layer->texture);
if (layer->differences & COGL_PIPELINE_LAYER_STATE_VERTEX_SNIPPETS) if (layer->differences & COGL_PIPELINE_LAYER_STATE_VERTEX_SNIPPETS)
_cogl_pipeline_snippet_list_free (&layer->big_state->vertex_snippets); _cogl_pipeline_snippet_list_free (&layer->big_state->vertex_snippets);

View File

@ -1752,7 +1752,7 @@ fallback_layer_cb (CoglPipelineLayer *layer, void *user_data)
COGL_COUNTER_INC (_cogl_uprof_context, layer_fallback_counter); COGL_COUNTER_INC (_cogl_uprof_context, layer_fallback_counter);
texture = COGL_TEXTURE (ctx->default_gl_texture_2d_tex); texture = ctx->default_gl_texture_2d_tex;
if (texture == NULL) if (texture == NULL)
{ {
@ -1760,7 +1760,7 @@ fallback_layer_cb (CoglPipelineLayer *layer, void *user_data)
"in for an invalid pipeline layer, since it was " "in for an invalid pipeline layer, since it was "
"using an unsupported texture target "); "using an unsupported texture target ");
/* might get away with this... */ /* might get away with this... */
texture = COGL_TEXTURE (ctx->default_gl_texture_2d_tex); texture = ctx->default_gl_texture_2d_tex;
} }
cogl_pipeline_set_layer_texture (pipeline, layer->index, texture); cogl_pipeline_set_layer_texture (pipeline, layer->index, texture);

View File

@ -35,24 +35,15 @@
#include "cogl/cogl-primitive-texture.h" #include "cogl/cogl-primitive-texture.h"
#include "cogl/cogl-texture-private.h" #include "cogl/cogl-texture-private.h"
gboolean
cogl_is_primitive_texture (void *object)
{
return (cogl_is_texture (object) &&
COGL_TEXTURE (object)->vtable->is_primitive);
}
void void
cogl_primitive_texture_set_auto_mipmap (CoglPrimitiveTexture *primitive_texture, cogl_primitive_texture_set_auto_mipmap (CoglTexture *texture,
gboolean value) gboolean value)
{ {
CoglTexture *texture; g_return_if_fail (COGL_IS_TEXTURE (texture) &&
texture->is_primitive);
g_return_if_fail (cogl_is_primitive_texture (primitive_texture)); g_assert (COGL_TEXTURE_GET_CLASS (texture)->set_auto_mipmap != NULL);
texture = COGL_TEXTURE (primitive_texture); COGL_TEXTURE_GET_CLASS (texture)->set_auto_mipmap (texture, value);
g_assert (texture->vtable->set_auto_mipmap != NULL);
texture->vtable->set_auto_mipmap (texture, value);
} }

View File

@ -34,56 +34,10 @@
#error "Only <cogl/cogl.h> can be included directly." #error "Only <cogl/cogl.h> can be included directly."
#endif #endif
#include "cogl/cogl-types.h" #include "cogl/cogl-texture.h"
G_BEGIN_DECLS G_BEGIN_DECLS
/**
* SECTION:cogl-primitive-texture
* @short_description: Interface for low-level textures like
* #CoglTexture2D.
*
* A #CoglPrimitiveTexture is a texture that is directly represented
* by a single texture on the GPU. For example this could be a
* #CoglTexture2D. This is opposed to high level meta textures which
* may be composed of multiple primitive textures or a sub-region of
* another texture such as #CoglAtlasTexture and #CoglTexture2DSliced.
*
* A texture that implements this interface can be directly used with
* the low level cogl_primitive_draw() API. Other types of textures
* need to be first resolved to primitive textures using the
* #CoglMetaTexture interface.
*
* <note>Most developers won't need to use this interface directly but
* still it is worth understanding the distinction between high-level
* and primitive textures because you may find other references in the
* documentation that detail limitations of using
* primitive textures.</note>
*/
#if defined(__COGL_H_INSIDE__) && !defined(COGL_ENABLE_MUTTER_API) && \
!defined(COGL_GIR_SCANNING)
/* For the public C api we typedef interface types as void to avoid needing
* lots of casting in code and instead we will rely on runtime type checking
* for these objects. */
typedef void CoglPrimitiveTexture;
#else
typedef struct _CoglPrimitiveTexture CoglPrimitiveTexture;
#define COGL_PRIMITIVE_TEXTURE(X) ((CoglPrimitiveTexture *)X)
#endif
/**
* cogl_is_primitive_texture:
* @object: A #CoglObject pointer
*
* Gets whether the given object references a primitive texture object.
*
* Return value: %TRUE if the pointer references a primitive texture, and
* %FALSE otherwise
*/
gboolean
cogl_is_primitive_texture (void *object);
/** /**
* cogl_primitive_texture_set_auto_mipmap: * cogl_primitive_texture_set_auto_mipmap:
* @primitive_texture: A #CoglPrimitiveTexture * @primitive_texture: A #CoglPrimitiveTexture
@ -97,7 +51,7 @@ cogl_is_primitive_texture (void *object);
* levels. By default auto mipmapping is enabled. * levels. By default auto mipmapping is enabled.
*/ */
COGL_EXPORT void COGL_EXPORT void
cogl_primitive_texture_set_auto_mipmap (CoglPrimitiveTexture *primitive_texture, cogl_primitive_texture_set_auto_mipmap (CoglTexture *primitive_texture,
gboolean value); gboolean value);
G_END_DECLS G_END_DECLS

View File

@ -272,7 +272,7 @@ _cogl_texture_quad_multiple_primitives (CoglFramebuffer *framebuffer,
if (wrap_t == COGL_PIPELINE_WRAP_MODE_AUTOMATIC) if (wrap_t == COGL_PIPELINE_WRAP_MODE_AUTOMATIC)
wrap_t = COGL_PIPELINE_WRAP_MODE_REPEAT; wrap_t = COGL_PIPELINE_WRAP_MODE_REPEAT;
cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (texture), cogl_meta_texture_foreach_in_region (texture,
tx_1, ty_1, tx_2, ty_2, tx_1, ty_1, tx_2, ty_2,
wrap_s, wrap_s,
wrap_t, wrap_t,
@ -580,7 +580,7 @@ _cogl_rectangles_validate_layer_cb (CoglPipeline *pipeline,
else else
{ {
static gboolean warning_seen = FALSE; static gboolean warning_seen = FALSE;
CoglTexture2D *tex_2d; CoglTexture *tex_2d;
if (!warning_seen) if (!warning_seen)
g_warning ("Skipping layer %d of your pipeline consisting of " g_warning ("Skipping layer %d of your pipeline consisting of "
@ -590,8 +590,7 @@ _cogl_rectangles_validate_layer_cb (CoglPipeline *pipeline,
/* Note: currently only 2D textures can be sliced. */ /* Note: currently only 2D textures can be sliced. */
tex_2d = state->ctx->default_gl_texture_2d_tex; tex_2d = state->ctx->default_gl_texture_2d_tex;
cogl_pipeline_set_layer_texture (pipeline, layer_index, cogl_pipeline_set_layer_texture (pipeline, layer_index, tex_2d);
COGL_TEXTURE (tex_2d));
return TRUE; return TRUE;
} }
} }

View File

@ -36,7 +36,7 @@
struct _CoglSubTexture struct _CoglSubTexture
{ {
CoglTexture _parent; CoglTexture parent_instance;
/* This is the texture that was passed in to /* This is the texture that was passed in to
_cogl_sub_texture_new. If this is also a sub texture then we will _cogl_sub_texture_new. If this is also a sub texture then we will
@ -57,3 +57,8 @@ struct _CoglSubTexture
int sub_x; int sub_x;
int sub_y; int sub_y;
}; };
struct _CoglSubTextureClass
{
CoglTextureClass parent_class;
};

View File

@ -38,21 +38,26 @@
#include "cogl/cogl-sub-texture-private.h" #include "cogl/cogl-sub-texture-private.h"
#include "cogl/cogl-sub-texture.h" #include "cogl/cogl-sub-texture.h"
#include "cogl/cogl-context-private.h" #include "cogl/cogl-context-private.h"
#include "cogl/cogl-object.h"
#include "cogl/cogl-texture-driver.h" #include "cogl/cogl-texture-driver.h"
#include "cogl/cogl-texture-2d.h" #include "cogl/cogl-texture-2d.h"
#include "cogl/cogl-gtype-private.h"
#include "cogl/driver/gl/cogl-texture-gl-private.h" #include "cogl/driver/gl/cogl-texture-gl-private.h"
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
static void _cogl_sub_texture_free (CoglSubTexture *sub_tex);
COGL_TEXTURE_DEFINE (SubTexture, sub_texture); G_DEFINE_FINAL_TYPE (CoglSubTexture, cogl_sub_texture, COGL_TYPE_TEXTURE)
COGL_GTYPE_DEFINE_CLASS (SubTexture, sub_texture);
static const CoglTextureVtable cogl_sub_texture_vtable; static void
cogl_sub_texture_dispose (GObject *object)
{
CoglSubTexture *sub_tex = COGL_SUB_TEXTURE (object);
g_object_unref (sub_tex->next_texture);
g_object_unref (sub_tex->full_texture);
G_OBJECT_CLASS (cogl_sub_texture_parent_class)->dispose (object);
}
static void static void
_cogl_sub_texture_unmap_quad (CoglSubTexture *sub_tex, _cogl_sub_texture_unmap_quad (CoglSubTexture *sub_tex,
@ -62,10 +67,10 @@ _cogl_sub_texture_unmap_quad (CoglSubTexture *sub_tex,
float width = cogl_texture_get_width (sub_tex->full_texture); float width = cogl_texture_get_width (sub_tex->full_texture);
float height = cogl_texture_get_height (sub_tex->full_texture); float height = cogl_texture_get_height (sub_tex->full_texture);
coords[0] = (coords[0] * width - sub_tex->sub_x) / tex->width; coords[0] = (coords[0] * width - sub_tex->sub_x) / cogl_texture_get_width (tex);
coords[1] = (coords[1] * height - sub_tex->sub_y) / tex->height; coords[1] = (coords[1] * height - sub_tex->sub_y) / cogl_texture_get_height (tex);
coords[2] = (coords[2] * width - sub_tex->sub_x) / tex->width; coords[2] = (coords[2] * width - sub_tex->sub_x) / cogl_texture_get_width (tex);
coords[3] = (coords[3] * height - sub_tex->sub_y) / tex->height; coords[3] = (coords[3] * height - sub_tex->sub_y) / cogl_texture_get_height (tex);
} }
static void static void
@ -76,10 +81,10 @@ _cogl_sub_texture_map_quad (CoglSubTexture *sub_tex,
float width = cogl_texture_get_width (sub_tex->full_texture); float width = cogl_texture_get_width (sub_tex->full_texture);
float height = cogl_texture_get_height (sub_tex->full_texture); float height = cogl_texture_get_height (sub_tex->full_texture);
coords[0] = (coords[0] * tex->width + sub_tex->sub_x) / width; coords[0] = (coords[0] * cogl_texture_get_width (tex) + sub_tex->sub_x) / width;
coords[1] = (coords[1] * tex->height + sub_tex->sub_y) / height; coords[1] = (coords[1] * cogl_texture_get_height (tex) + sub_tex->sub_y) / height;
coords[2] = (coords[2] * tex->width + sub_tex->sub_x) / width; coords[2] = (coords[2] * cogl_texture_get_width (tex) + sub_tex->sub_x) / width;
coords[3] = (coords[3] * tex->height + sub_tex->sub_y) / height; coords[3] = (coords[3] * cogl_texture_get_height (tex) + sub_tex->sub_y) / height;
} }
typedef struct _CoglSubTextureForeachData typedef struct _CoglSubTextureForeachData
@ -129,7 +134,7 @@ _cogl_sub_texture_foreach_sub_texture_in_region (
_cogl_sub_texture_map_quad (sub_tex, mapped_coords); _cogl_sub_texture_map_quad (sub_tex, mapped_coords);
/* TODO: Add something like cogl_is_low_level_texture() */ /* TODO: Add something like cogl_is_low_level_texture() */
if (cogl_is_texture_2d (full_texture)) if (COGL_IS_TEXTURE_2D (full_texture))
{ {
callback (sub_tex->full_texture, callback (sub_tex->full_texture,
mapped_coords, mapped_coords,
@ -144,7 +149,7 @@ _cogl_sub_texture_foreach_sub_texture_in_region (
data.callback = callback; data.callback = callback;
data.user_data = user_data; data.user_data = user_data;
cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (full_texture), cogl_meta_texture_foreach_in_region (full_texture,
mapped_coords[0], mapped_coords[0],
mapped_coords[1], mapped_coords[1],
mapped_coords[2], mapped_coords[2],
@ -168,67 +173,6 @@ _cogl_sub_texture_gl_flush_legacy_texobj_wrap_modes (CoglTexture *tex,
wrap_mode_t); wrap_mode_t);
} }
static void
_cogl_sub_texture_free (CoglSubTexture *sub_tex)
{
cogl_object_unref (sub_tex->next_texture);
cogl_object_unref (sub_tex->full_texture);
/* Chain up */
_cogl_texture_free (COGL_TEXTURE (sub_tex));
}
CoglSubTexture *
cogl_sub_texture_new (CoglContext *ctx,
CoglTexture *next_texture,
int sub_x, int sub_y,
int sub_width, int sub_height)
{
CoglTexture *full_texture;
CoglSubTexture *sub_tex;
CoglTexture *tex;
unsigned int next_width, next_height;
next_width = cogl_texture_get_width (next_texture);
next_height = cogl_texture_get_height (next_texture);
/* The region must specify a non-zero subset of the full texture */
g_return_val_if_fail (sub_x >= 0 && sub_y >= 0, NULL);
g_return_val_if_fail (sub_width > 0 && sub_height > 0, NULL);
g_return_val_if_fail (sub_x + sub_width <= next_width, NULL);
g_return_val_if_fail (sub_y + sub_height <= next_height, NULL);
sub_tex = g_new (CoglSubTexture, 1);
tex = COGL_TEXTURE (sub_tex);
_cogl_texture_init (tex, ctx, sub_width, sub_height,
_cogl_texture_get_format (next_texture),
NULL, /* no loader */
&cogl_sub_texture_vtable);
/* If the next texture is also a sub texture we can avoid one level
of indirection by referencing the full texture of that texture
instead. */
if (cogl_is_sub_texture (next_texture))
{
CoglSubTexture *other_sub_tex = COGL_SUB_TEXTURE (next_texture);
full_texture = other_sub_tex->full_texture;
sub_x += other_sub_tex->sub_x;
sub_y += other_sub_tex->sub_y;
}
else
full_texture = next_texture;
sub_tex->next_texture = cogl_object_ref (next_texture);
sub_tex->full_texture = cogl_object_ref (full_texture);
sub_tex->sub_x = sub_x;
sub_tex->sub_y = sub_y;
return _cogl_sub_texture_object_new (sub_tex);
}
static gboolean static gboolean
_cogl_sub_texture_allocate (CoglTexture *tex, _cogl_sub_texture_allocate (CoglTexture *tex,
GError **error) GError **error)
@ -238,17 +182,12 @@ _cogl_sub_texture_allocate (CoglTexture *tex,
_cogl_texture_set_allocated (tex, _cogl_texture_set_allocated (tex,
_cogl_texture_get_format (sub_tex->full_texture), _cogl_texture_get_format (sub_tex->full_texture),
tex->width, tex->height); cogl_texture_get_width (tex),
cogl_texture_get_height (tex));
return status; return status;
} }
CoglTexture *
cogl_sub_texture_get_parent (CoglSubTexture *sub_texture)
{
return sub_texture->next_texture;
}
static int static int
_cogl_sub_texture_get_max_waste (CoglTexture *tex) _cogl_sub_texture_get_max_waste (CoglTexture *tex)
{ {
@ -272,9 +211,9 @@ _cogl_sub_texture_can_hardware_repeat (CoglTexture *tex)
/* We can hardware repeat if the subtexture actually represents all of the /* We can hardware repeat if the subtexture actually represents all of the
of the full texture */ of the full texture */
return (tex->width == return (cogl_texture_get_width (tex) ==
cogl_texture_get_width (sub_tex->full_texture) && cogl_texture_get_width (sub_tex->full_texture) &&
tex->height == cogl_texture_get_height (tex) ==
cogl_texture_get_height (sub_tex->full_texture) && cogl_texture_get_height (sub_tex->full_texture) &&
_cogl_texture_can_hardware_repeat (sub_tex->full_texture)); _cogl_texture_can_hardware_repeat (sub_tex->full_texture));
} }
@ -288,9 +227,9 @@ _cogl_sub_texture_transform_coords_to_gl (CoglTexture *tex,
/* This won't work if the sub texture is not the size of the full /* This won't work if the sub texture is not the size of the full
texture and the coordinates are outside the range [0,1] */ texture and the coordinates are outside the range [0,1] */
*s = ((*s * tex->width + sub_tex->sub_x) / *s = ((*s * cogl_texture_get_width (tex) + sub_tex->sub_x) /
cogl_texture_get_width (sub_tex->full_texture)); cogl_texture_get_width (sub_tex->full_texture));
*t = ((*t * tex->height + sub_tex->sub_y) / *t = ((*t * cogl_texture_get_height (tex) + sub_tex->sub_y) /
cogl_texture_get_height (sub_tex->full_texture)); cogl_texture_get_height (sub_tex->full_texture));
_cogl_texture_transform_coords_to_gl (sub_tex->full_texture, s, t); _cogl_texture_transform_coords_to_gl (sub_tex->full_texture, s, t);
@ -413,26 +352,92 @@ _cogl_sub_texture_get_gl_format (CoglTexture *tex)
return _cogl_texture_gl_get_format (sub_tex->full_texture); return _cogl_texture_gl_get_format (sub_tex->full_texture);
} }
static const CoglTextureVtable static void
cogl_sub_texture_vtable = cogl_sub_texture_class_init (CoglSubTextureClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
CoglTextureClass *texture_class = COGL_TEXTURE_CLASS (klass);
gobject_class->dispose = cogl_sub_texture_dispose;
texture_class->allocate = _cogl_sub_texture_allocate;
texture_class->set_region = _cogl_sub_texture_set_region;
texture_class->is_get_data_supported = _cogl_sub_texture_is_get_data_supported;
texture_class->foreach_sub_texture_in_region = _cogl_sub_texture_foreach_sub_texture_in_region;
texture_class->get_max_waste = _cogl_sub_texture_get_max_waste;
texture_class->is_sliced = _cogl_sub_texture_is_sliced;
texture_class->can_hardware_repeat = _cogl_sub_texture_can_hardware_repeat;
texture_class->transform_coords_to_gl = _cogl_sub_texture_transform_coords_to_gl;
texture_class->transform_quad_coords_to_gl = _cogl_sub_texture_transform_quad_coords_to_gl;
texture_class->get_gl_texture = _cogl_sub_texture_get_gl_texture;
texture_class->gl_flush_legacy_texobj_filters = _cogl_sub_texture_gl_flush_legacy_texobj_filters;
texture_class->pre_paint = _cogl_sub_texture_pre_paint;
texture_class->ensure_non_quad_rendering = _cogl_sub_texture_ensure_non_quad_rendering;
texture_class->gl_flush_legacy_texobj_wrap_modes = _cogl_sub_texture_gl_flush_legacy_texobj_wrap_modes;
texture_class->get_format = _cogl_sub_texture_get_format;
texture_class->get_gl_format = _cogl_sub_texture_get_gl_format;
}
static void
cogl_sub_texture_init (CoglSubTexture *self)
{
CoglTexture *texture = COGL_TEXTURE (self);
texture->is_primitive = FALSE;
}
CoglTexture *
cogl_sub_texture_new (CoglContext *ctx,
CoglTexture *next_texture,
int sub_x, int sub_y,
int sub_width, int sub_height)
{
CoglTexture *full_texture;
CoglSubTexture *sub_tex;
CoglTexture *tex;
unsigned int next_width, next_height;
next_width = cogl_texture_get_width (next_texture);
next_height = cogl_texture_get_height (next_texture);
/* The region must specify a non-zero subset of the full texture */
g_return_val_if_fail (sub_x >= 0 && sub_y >= 0, NULL);
g_return_val_if_fail (sub_width > 0 && sub_height > 0, NULL);
g_return_val_if_fail (sub_x + sub_width <= next_width, NULL);
g_return_val_if_fail (sub_y + sub_height <= next_height, NULL);
sub_tex = g_object_new (COGL_TYPE_SUB_TEXTURE, NULL);
tex = COGL_TEXTURE (sub_tex);
_cogl_texture_init (tex, ctx, sub_width, sub_height,
_cogl_texture_get_format (next_texture),
NULL);
/* If the next texture is also a sub texture we can avoid one level
of indirection by referencing the full texture of that texture
instead. */
if (COGL_IS_SUB_TEXTURE (next_texture))
{ {
FALSE, /* not primitive */ CoglSubTexture *other_sub_tex = COGL_SUB_TEXTURE (next_texture);
_cogl_sub_texture_allocate, full_texture = other_sub_tex->full_texture;
_cogl_sub_texture_set_region, sub_x += other_sub_tex->sub_x;
_cogl_sub_texture_is_get_data_supported, sub_y += other_sub_tex->sub_y;
NULL, /* get_data */ }
_cogl_sub_texture_foreach_sub_texture_in_region, else
_cogl_sub_texture_get_max_waste, full_texture = next_texture;
_cogl_sub_texture_is_sliced,
_cogl_sub_texture_can_hardware_repeat, sub_tex->next_texture = g_object_ref (next_texture);
_cogl_sub_texture_transform_coords_to_gl, sub_tex->full_texture = g_object_ref (full_texture);
_cogl_sub_texture_transform_quad_coords_to_gl,
_cogl_sub_texture_get_gl_texture, sub_tex->sub_x = sub_x;
_cogl_sub_texture_gl_flush_legacy_texobj_filters, sub_tex->sub_y = sub_y;
_cogl_sub_texture_pre_paint,
_cogl_sub_texture_ensure_non_quad_rendering, return tex;
_cogl_sub_texture_gl_flush_legacy_texobj_wrap_modes, }
_cogl_sub_texture_get_format,
_cogl_sub_texture_get_gl_format, CoglTexture *
NULL /* set_auto_mipmap */ cogl_sub_texture_get_parent (CoglSubTexture *sub_texture)
}; {
return sub_texture->next_texture;
}

View File

@ -38,26 +38,29 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/** /**
* SECTION:cogl-sub-texture * CoglSubTexture:
* @short_description: Functions for creating and manipulating *
* sub-textures. * Functions for creating and manipulating sub-textures.
* *
* These functions allow high-level textures to be created that * These functions allow high-level textures to be created that
* represent a sub-region of another texture. For example these * represent a sub-region of another texture. For example these
* can be used to implement custom texture atlasing schemes. * can be used to implement custom texture atlasing schemes.
*/ */
#define COGL_TYPE_SUB_TEXTURE (cogl_sub_texture_get_type ())
#define COGL_SUB_TEXTURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COGL_TYPE_SUB_TEXTURE, CoglSubTexture))
#define COGL_SUB_TEXTURE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COGL_TYPE_SUB_TEXTURE, CoglSubTexture const))
#define COGL_SUB_TEXTURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COGL_TYPE_SUB_TEXTURE, CoglSubTextureClass))
#define COGL_IS_SUB_TEXTURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COGL_TYPE_SUB_TEXTURE))
#define COGL_IS_SUB_TEXTURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COGL_TYPE_SUB_TEXTURE))
#define COGL_SUB_TEXTURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), COGL_TYPE_SUB_TEXTURE, CoglSubTextureClass))
typedef struct _CoglSubTextureClass CoglSubTextureClass;
#define COGL_SUB_TEXTURE(tex) ((CoglSubTexture *) tex)
typedef struct _CoglSubTexture CoglSubTexture; typedef struct _CoglSubTexture CoglSubTexture;
/** G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglSubTexture, g_object_unref)
* cogl_sub_texture_get_gtype:
*
* Returns: a #GType that can be used with the GLib type system.
*/
GType cogl_sub_texture_get_gtype (void);
COGL_EXPORT
GType cogl_sub_texture_get_type (void) G_GNUC_CONST;
/** /**
* cogl_sub_texture_new: * cogl_sub_texture_new:
* @ctx: A #CoglContext pointer * @ctx: A #CoglContext pointer
@ -86,7 +89,7 @@ GType cogl_sub_texture_get_gtype (void);
* Return value: (transfer full): A newly allocated #CoglSubTexture * Return value: (transfer full): A newly allocated #CoglSubTexture
* representing a sub-region of @parent_texture. * representing a sub-region of @parent_texture.
*/ */
COGL_EXPORT CoglSubTexture * COGL_EXPORT CoglTexture *
cogl_sub_texture_new (CoglContext *ctx, cogl_sub_texture_new (CoglContext *ctx,
CoglTexture *parent_texture, CoglTexture *parent_texture,
int sub_x, int sub_x,
@ -108,16 +111,4 @@ cogl_sub_texture_new (CoglContext *ctx,
COGL_EXPORT CoglTexture * COGL_EXPORT CoglTexture *
cogl_sub_texture_get_parent (CoglSubTexture *sub_texture); cogl_sub_texture_get_parent (CoglSubTexture *sub_texture);
/**
* cogl_is_sub_texture:
* @object: a #CoglObject
*
* Checks whether @object is a #CoglSubTexture.
*
* Return value: %TRUE if the passed @object represents a
* #CoglSubTexture and %FALSE otherwise.
*/
COGL_EXPORT gboolean
cogl_is_sub_texture (void *object);
G_END_DECLS G_END_DECLS

View File

@ -30,14 +30,13 @@
#pragma once #pragma once
#include "cogl/cogl-object-private.h"
#include "cogl/cogl-pipeline-private.h" #include "cogl/cogl-pipeline-private.h"
#include "cogl/cogl-texture-private.h" #include "cogl/cogl-texture-private.h"
#include "cogl/cogl-texture-2d.h" #include "cogl/cogl-texture-2d.h"
struct _CoglTexture2D struct _CoglTexture2D
{ {
CoglTexture _parent; CoglTexture parent_instance;
/* The internal format of the GL texture represented as a /* The internal format of the GL texture represented as a
CoglPixelFormat */ CoglPixelFormat */
@ -67,7 +66,12 @@ struct _CoglTexture2D
} egl_image_external; } egl_image_external;
}; };
CoglTexture2D * struct _CoglTexture2DClass
{
CoglTextureClass parent_class;
};
CoglTexture *
_cogl_texture_2d_create_base (CoglContext *ctx, _cogl_texture_2d_create_base (CoglContext *ctx,
int width, int width,
int height, int height,

View File

@ -39,7 +39,7 @@
struct _CoglTexture2DSliced struct _CoglTexture2DSliced
{ {
CoglTexture _parent; CoglTexture parent_instance;
GArray *slice_x_spans; GArray *slice_x_spans;
GArray *slice_y_spans; GArray *slice_y_spans;
@ -47,3 +47,8 @@ struct _CoglTexture2DSliced
int max_waste; int max_waste;
CoglPixelFormat internal_format; CoglPixelFormat internal_format;
}; };
struct _CoglTexture2DSlicedClass
{
CoglTextureClass parent_class;
};

File diff suppressed because it is too large Load Diff

View File

@ -36,10 +36,11 @@
#include "cogl/cogl-types.h" #include "cogl/cogl-types.h"
/** /**
* SECTION:cogl-texture-2d-sliced * CoglTexture2DSliced:
* @short_description: Functions for creating and manipulating 2D meta *
* textures that may internally be comprised of * Functions for creating and manipulating 2D meta textures
* multiple 2D textures with power-of-two sizes. * that may internally be comprised of multiple 2D textures
* with power-of-two sizes.
* *
* These functions allow high-level meta textures (See the * These functions allow high-level meta textures (See the
* #CoglMetaTexture interface) to be allocated that may internally be * #CoglMetaTexture interface) to be allocated that may internally be
@ -65,17 +66,21 @@
* max-waste threshold. The same logic for slicing from left to right * max-waste threshold. The same logic for slicing from left to right
* is also applied from top to bottom. * is also applied from top to bottom.
*/ */
#define COGL_TYPE_TEXTURE_2D_SLICED (cogl_texture_2d_sliced_get_type ())
#define COGL_TEXTURE_2D_SLICED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COGL_TYPE_TEXTURE_2D_SLICED, CoglTexture2DSliced))
#define COGL_TEXTURE_2D_SLICED_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COGL_TYPE_TEXTURE_2D_SLICED, CoglTexture2DSliced const))
#define COGL_TEXTURE_2D_SLICED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COGL_TYPE_TEXTURE_2D_SLICED, CoglTexture2DSlicedClass))
#define COGL_IS_TEXTURE_2D_SLICED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COGL_TYPE_TEXTURE_2D_SLICED))
#define COGL_IS_TEXTURE_2D_SLICED_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COGL_TYPE_TEXTURE_2D_SLICED))
#define COGL_TEXTURE_2D_SLICED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), COGL_TYPE_TEXTURE_2D_SLICED, CoglTexture2DSlicedClass))
typedef struct _CoglTexture2DSlicedClass CoglTexture2DSlicedClass;
typedef struct _CoglTexture2DSliced CoglTexture2DSliced; typedef struct _CoglTexture2DSliced CoglTexture2DSliced;
#define COGL_TEXTURE_2D_SLICED(X) ((CoglTexture2DSliced *)X)
/** G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglTexture2DSliced, g_object_unref)
* cogl_texture_2d_sliced_get_gtype:
*
* Returns: a #GType that can be used with the GLib type system.
*/
COGL_EXPORT COGL_EXPORT
GType cogl_texture_2d_sliced_get_gtype (void); GType cogl_texture_2d_sliced_get_type (void) G_GNUC_CONST;
/** /**
* cogl_texture_2d_sliced_new_with_size: (skip) * cogl_texture_2d_sliced_new_with_size: (skip)
@ -115,7 +120,7 @@ GType cogl_texture_2d_sliced_get_gtype (void);
* Returns: (transfer full): A new #CoglTexture2DSliced object with no storage * Returns: (transfer full): A new #CoglTexture2DSliced object with no storage
* allocated yet. * allocated yet.
*/ */
COGL_EXPORT CoglTexture2DSliced * COGL_EXPORT CoglTexture *
cogl_texture_2d_sliced_new_with_size (CoglContext *ctx, cogl_texture_2d_sliced_new_with_size (CoglContext *ctx,
int width, int width,
int height, int height,
@ -174,7 +179,7 @@ cogl_texture_2d_sliced_new_with_size (CoglContext *ctx,
* Return value: (transfer full): A newly created #CoglTexture2DSliced * Return value: (transfer full): A newly created #CoglTexture2DSliced
* or %NULL on failure and @error will be updated. * or %NULL on failure and @error will be updated.
*/ */
COGL_EXPORT CoglTexture2DSliced * COGL_EXPORT CoglTexture *
cogl_texture_2d_sliced_new_from_data (CoglContext *ctx, cogl_texture_2d_sliced_new_from_data (CoglContext *ctx,
int width, int width,
int height, int height,
@ -223,18 +228,6 @@ cogl_texture_2d_sliced_new_from_data (CoglContext *ctx,
* Return value: (transfer full): A newly created #CoglTexture2DSliced * Return value: (transfer full): A newly created #CoglTexture2DSliced
* or %NULL on failure and @error will be updated. * or %NULL on failure and @error will be updated.
*/ */
COGL_EXPORT CoglTexture2DSliced * COGL_EXPORT CoglTexture *
cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp, cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp,
int max_waste); int max_waste);
/**
* cogl_is_texture_2d_sliced:
* @object: A #CoglObject pointer
*
* Gets whether the given object references a #CoglTexture2DSliced.
*
* Return value: %TRUE if the object references a #CoglTexture2DSliced
* and %FALSE otherwise.
*/
COGL_EXPORT gboolean
cogl_is_texture_2d_sliced (void *object);

View File

@ -39,10 +39,8 @@
#include "cogl/cogl-texture-2d-private.h" #include "cogl/cogl-texture-2d-private.h"
#include "cogl/cogl-texture-driver.h" #include "cogl/cogl-texture-driver.h"
#include "cogl/cogl-context-private.h" #include "cogl/cogl-context-private.h"
#include "cogl/cogl-object-private.h"
#include "cogl/cogl-journal-private.h" #include "cogl/cogl-journal-private.h"
#include "cogl/cogl-framebuffer-private.h" #include "cogl/cogl-framebuffer-private.h"
#include "cogl/cogl-gtype-private.h"
#include "cogl/driver/gl/cogl-texture-2d-gl-private.h" #include "cogl/driver/gl/cogl-texture-2d-gl-private.h"
#ifdef COGL_HAS_EGL_SUPPORT #ifdef COGL_HAS_EGL_SUPPORT
#include "cogl/winsys/cogl-winsys-egl-private.h" #include "cogl/winsys/cogl-winsys-egl-private.h"
@ -51,13 +49,7 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
static void _cogl_texture_2d_free (CoglTexture2D *tex_2d); G_DEFINE_FINAL_TYPE (CoglTexture2D, cogl_texture_2d, COGL_TYPE_TEXTURE)
COGL_TEXTURE_DEFINE (Texture2D, texture_2d);
COGL_GTYPE_DEFINE_CLASS (Texture2D, texture_2d,
COGL_GTYPE_IMPLEMENT_INTERFACE (texture));
static const CoglTextureVtable cogl_texture_2d_vtable;
typedef struct _CoglTexture2DManualRepeatData typedef struct _CoglTexture2DManualRepeatData
{ {
@ -67,14 +59,14 @@ typedef struct _CoglTexture2DManualRepeatData
} CoglTexture2DManualRepeatData; } CoglTexture2DManualRepeatData;
static void static void
_cogl_texture_2d_free (CoglTexture2D *tex_2d) cogl_texture_2d_dispose (GObject *object)
{ {
CoglContext *ctx = COGL_TEXTURE (tex_2d)->context; CoglTexture2D *tex_2d = COGL_TEXTURE_2D (object);
CoglContext *ctx = cogl_texture_get_context (COGL_TEXTURE (tex_2d));
ctx->driver_vtable->texture_2d_free (tex_2d); ctx->driver_vtable->texture_2d_free (tex_2d);
/* Chain up */ G_OBJECT_CLASS (cogl_texture_2d_parent_class)->dispose (object);
_cogl_texture_free (COGL_TEXTURE (tex_2d));
} }
void void
@ -86,18 +78,17 @@ _cogl_texture_2d_set_auto_mipmap (CoglTexture *tex,
tex_2d->auto_mipmap = value; tex_2d->auto_mipmap = value;
} }
CoglTexture2D * CoglTexture *
_cogl_texture_2d_create_base (CoglContext *ctx, _cogl_texture_2d_create_base (CoglContext *ctx,
int width, int width,
int height, int height,
CoglPixelFormat internal_format, CoglPixelFormat internal_format,
CoglTextureLoader *loader) CoglTextureLoader *loader)
{ {
CoglTexture2D *tex_2d = g_new (CoglTexture2D, 1); CoglTexture2D *tex_2d = g_object_new (COGL_TYPE_TEXTURE_2D, NULL);
CoglTexture *tex = COGL_TEXTURE (tex_2d); CoglTexture *tex = COGL_TEXTURE (tex_2d);
_cogl_texture_init (tex, ctx, width, height, internal_format, loader, _cogl_texture_init (tex, ctx, width, height, internal_format, loader);
&cogl_texture_2d_vtable);
tex_2d->mipmaps_dirty = TRUE; tex_2d->mipmaps_dirty = TRUE;
tex_2d->auto_mipmap = TRUE; tex_2d->auto_mipmap = TRUE;
@ -107,171 +98,18 @@ _cogl_texture_2d_create_base (CoglContext *ctx,
ctx->driver_vtable->texture_2d_init (tex_2d); ctx->driver_vtable->texture_2d_init (tex_2d);
return _cogl_texture_2d_object_new (tex_2d); return tex;
}
CoglTexture2D *
cogl_texture_2d_new_with_format (CoglContext *ctx,
int width,
int height,
CoglPixelFormat format)
{
CoglTextureLoader *loader;
g_return_val_if_fail (width >= 1, NULL);
g_return_val_if_fail (height >= 1, NULL);
loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZE;
loader->src.sized.width = width;
loader->src.sized.height = height;
loader->src.sized.format = format;
return _cogl_texture_2d_create_base (ctx, width, height, format, loader);
}
CoglTexture2D *
cogl_texture_2d_new_with_size (CoglContext *ctx,
int width,
int height)
{
CoglTextureLoader *loader;
g_return_val_if_fail (width >= 1, NULL);
g_return_val_if_fail (height >= 1, NULL);
loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZE;
loader->src.sized.width = width;
loader->src.sized.height = height;
loader->src.sized.format = COGL_PIXEL_FORMAT_ANY;
return _cogl_texture_2d_create_base (ctx, width, height,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, loader);
} }
static gboolean static gboolean
_cogl_texture_2d_allocate (CoglTexture *tex, _cogl_texture_2d_allocate (CoglTexture *tex,
GError **error) GError **error)
{ {
CoglContext *ctx = tex->context; CoglContext *ctx = cogl_texture_get_context (tex);
return ctx->driver_vtable->texture_2d_allocate (tex, error); return ctx->driver_vtable->texture_2d_allocate (tex, error);
} }
CoglTexture2D *
cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp)
{
CoglTextureLoader *loader;
g_return_val_if_fail (bmp != NULL, NULL);
loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_BITMAP;
loader->src.bitmap.bitmap = g_object_ref (bmp);
return _cogl_texture_2d_create_base (_cogl_bitmap_get_context (bmp),
cogl_bitmap_get_width (bmp),
cogl_bitmap_get_height (bmp),
cogl_bitmap_get_format (bmp),
loader);
}
CoglTexture2D *
cogl_texture_2d_new_from_data (CoglContext *ctx,
int width,
int height,
CoglPixelFormat format,
int rowstride,
const uint8_t *data,
GError **error)
{
CoglBitmap *bmp;
CoglTexture2D *tex_2d;
g_return_val_if_fail (format != COGL_PIXEL_FORMAT_ANY, NULL);
g_return_val_if_fail (cogl_pixel_format_get_n_planes (format) == 1, NULL);
g_return_val_if_fail (data != NULL, NULL);
/* Rowstride from width if not given */
if (rowstride == 0)
rowstride = width * cogl_pixel_format_get_bytes_per_pixel (format, 0);
/* Wrap the data into a bitmap */
bmp = cogl_bitmap_new_for_data (ctx,
width, height,
format,
rowstride,
(uint8_t *) data);
tex_2d = cogl_texture_2d_new_from_bitmap (bmp);
g_object_unref (bmp);
if (tex_2d &&
!cogl_texture_allocate (COGL_TEXTURE (tex_2d), error))
{
cogl_object_unref (tex_2d);
return NULL;
}
return tex_2d;
}
#if defined (COGL_HAS_EGL_SUPPORT) && defined (EGL_KHR_image_base)
/* NB: The reason we require the width, height and format to be passed
* even though they may seem redundant is because GLES 1/2 don't
* provide a way to query these properties. */
CoglTexture2D *
cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
int width,
int height,
CoglPixelFormat format,
EGLImageKHR image,
CoglEglImageFlags flags,
GError **error)
{
CoglTextureLoader *loader;
CoglTexture2D *tex;
g_return_val_if_fail (_cogl_context_get_winsys (ctx)->constraints &
COGL_RENDERER_CONSTRAINT_USES_EGL,
NULL);
g_return_val_if_fail (_cogl_has_private_feature
(ctx,
COGL_PRIVATE_FEATURE_TEXTURE_2D_FROM_EGL_IMAGE),
NULL);
loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_EGL_IMAGE;
loader->src.egl_image.image = image;
loader->src.egl_image.width = width;
loader->src.egl_image.height = height;
loader->src.egl_image.format = format;
loader->src.egl_image.flags = flags;
tex = _cogl_texture_2d_create_base (ctx, width, height, format, loader);
if (!cogl_texture_allocate (COGL_TEXTURE (tex), error))
{
cogl_object_unref (tex);
return NULL;
}
return tex;
}
#endif /* defined (COGL_HAS_EGL_SUPPORT) && defined (EGL_KHR_image_base) */
void
_cogl_texture_2d_externally_modified (CoglTexture *texture)
{
if (!cogl_is_texture_2d (texture))
return;
COGL_TEXTURE_2D (texture)->mipmaps_dirty = TRUE;
}
void void
_cogl_texture_2d_copy_from_framebuffer (CoglTexture2D *tex_2d, _cogl_texture_2d_copy_from_framebuffer (CoglTexture2D *tex_2d,
int src_x, int src_x,
@ -284,7 +122,7 @@ _cogl_texture_2d_copy_from_framebuffer (CoglTexture2D *tex_2d,
int level) int level)
{ {
CoglTexture *tex = COGL_TEXTURE (tex_2d); CoglTexture *tex = COGL_TEXTURE (tex_2d);
CoglContext *ctx = tex->context; CoglContext *ctx = cogl_texture_get_context (tex);
/* Assert that the storage for this texture has been allocated */ /* Assert that the storage for this texture has been allocated */
cogl_texture_allocate (tex, NULL); /* (abort on error) */ cogl_texture_allocate (tex, NULL); /* (abort on error) */
@ -356,7 +194,7 @@ _cogl_texture_2d_get_gl_texture (CoglTexture *tex,
GLuint *out_gl_handle, GLuint *out_gl_handle,
GLenum *out_gl_target) GLenum *out_gl_target)
{ {
CoglContext *ctx = tex->context; CoglContext *ctx = cogl_texture_get_context (tex);
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex); CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
if (ctx->driver_vtable->texture_2d_get_gl_handle) if (ctx->driver_vtable->texture_2d_get_gl_handle)
@ -386,7 +224,7 @@ _cogl_texture_2d_pre_paint (CoglTexture *tex, CoglTexturePrePaintFlags flags)
if ((flags & COGL_TEXTURE_NEEDS_MIPMAP) && if ((flags & COGL_TEXTURE_NEEDS_MIPMAP) &&
tex_2d->auto_mipmap && tex_2d->mipmaps_dirty) tex_2d->auto_mipmap && tex_2d->mipmaps_dirty)
{ {
CoglContext *ctx = tex->context; CoglContext *ctx = cogl_texture_get_context (tex);
/* Since we are about to ask the GPU to generate mipmaps of tex, we /* Since we are about to ask the GPU to generate mipmaps of tex, we
* better make sure tex is up-to-date. * better make sure tex is up-to-date.
@ -421,7 +259,7 @@ _cogl_texture_2d_set_region (CoglTexture *tex,
CoglBitmap *bmp, CoglBitmap *bmp,
GError **error) GError **error)
{ {
CoglContext *ctx = tex->context; CoglContext *ctx = cogl_texture_get_context (tex);
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex); CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
if (!ctx->driver_vtable->texture_2d_copy_from_bitmap (tex_2d, if (!ctx->driver_vtable->texture_2d_copy_from_bitmap (tex_2d,
@ -447,7 +285,7 @@ static gboolean
_cogl_texture_2d_is_get_data_supported (CoglTexture *tex) _cogl_texture_2d_is_get_data_supported (CoglTexture *tex)
{ {
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex); CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
CoglContext *ctx = tex->context; CoglContext *ctx = cogl_texture_get_context (tex);
return ctx->driver_vtable->texture_2d_is_get_data_supported (tex_2d); return ctx->driver_vtable->texture_2d_is_get_data_supported (tex_2d);
} }
@ -458,7 +296,7 @@ _cogl_texture_2d_get_data (CoglTexture *tex,
int rowstride, int rowstride,
uint8_t *data) uint8_t *data)
{ {
CoglContext *ctx = tex->context; CoglContext *ctx = cogl_texture_get_context (tex);
if (ctx->driver_vtable->texture_2d_get_data) if (ctx->driver_vtable->texture_2d_get_data)
{ {
@ -482,26 +320,190 @@ _cogl_texture_2d_get_gl_format (CoglTexture *tex)
return COGL_TEXTURE_2D (tex)->gl_internal_format; return COGL_TEXTURE_2D (tex)->gl_internal_format;
} }
static const CoglTextureVtable static void
cogl_texture_2d_vtable = cogl_texture_2d_class_init (CoglTexture2DClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
CoglTextureClass *texture_class = COGL_TEXTURE_CLASS (klass);
gobject_class->dispose = cogl_texture_2d_dispose;
texture_class->allocate = _cogl_texture_2d_allocate;
texture_class->set_region = _cogl_texture_2d_set_region;
texture_class->is_get_data_supported = _cogl_texture_2d_is_get_data_supported;
texture_class->get_data = _cogl_texture_2d_get_data;
texture_class->get_max_waste = _cogl_texture_2d_get_max_waste;
texture_class->is_sliced = _cogl_texture_2d_is_sliced;
texture_class->can_hardware_repeat = _cogl_texture_2d_can_hardware_repeat;
texture_class->transform_coords_to_gl = _cogl_texture_2d_transform_coords_to_gl;
texture_class->transform_quad_coords_to_gl = _cogl_texture_2d_transform_quad_coords_to_gl;
texture_class->get_gl_texture = _cogl_texture_2d_get_gl_texture;
texture_class->gl_flush_legacy_texobj_filters = _cogl_texture_2d_gl_flush_legacy_texobj_filters;
texture_class->pre_paint = _cogl_texture_2d_pre_paint;
texture_class->ensure_non_quad_rendering = _cogl_texture_2d_ensure_non_quad_rendering;
texture_class->gl_flush_legacy_texobj_wrap_modes = _cogl_texture_2d_gl_flush_legacy_texobj_wrap_modes;
texture_class->get_format = _cogl_texture_2d_get_format;
texture_class->get_gl_format = _cogl_texture_2d_get_gl_format;
texture_class->set_auto_mipmap = _cogl_texture_2d_set_auto_mipmap;
}
static void
cogl_texture_2d_init (CoglTexture2D *self)
{
CoglTexture *texture = COGL_TEXTURE (self);
texture->is_primitive = TRUE;
}
CoglTexture *
cogl_texture_2d_new_with_format (CoglContext *ctx,
int width,
int height,
CoglPixelFormat format)
{
CoglTextureLoader *loader;
g_return_val_if_fail (width >= 1, NULL);
g_return_val_if_fail (height >= 1, NULL);
loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZE;
loader->src.sized.width = width;
loader->src.sized.height = height;
loader->src.sized.format = format;
return _cogl_texture_2d_create_base (ctx, width, height, format, loader);
}
CoglTexture *
cogl_texture_2d_new_with_size (CoglContext *ctx,
int width,
int height)
{
CoglTextureLoader *loader;
g_return_val_if_fail (width >= 1, NULL);
g_return_val_if_fail (height >= 1, NULL);
loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_SIZE;
loader->src.sized.width = width;
loader->src.sized.height = height;
loader->src.sized.format = COGL_PIXEL_FORMAT_ANY;
return _cogl_texture_2d_create_base (ctx, width, height,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, loader);
}
CoglTexture *
cogl_texture_2d_new_from_bitmap (CoglBitmap *bmp)
{
CoglTextureLoader *loader;
g_return_val_if_fail (bmp != NULL, NULL);
loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_BITMAP;
loader->src.bitmap.bitmap = g_object_ref (bmp);
return _cogl_texture_2d_create_base (_cogl_bitmap_get_context (bmp),
cogl_bitmap_get_width (bmp),
cogl_bitmap_get_height (bmp),
cogl_bitmap_get_format (bmp),
loader);
}
CoglTexture *
cogl_texture_2d_new_from_data (CoglContext *ctx,
int width,
int height,
CoglPixelFormat format,
int rowstride,
const uint8_t *data,
GError **error)
{
CoglBitmap *bmp;
CoglTexture *tex_2d;
g_return_val_if_fail (format != COGL_PIXEL_FORMAT_ANY, NULL);
g_return_val_if_fail (cogl_pixel_format_get_n_planes (format) == 1, NULL);
g_return_val_if_fail (data != NULL, NULL);
/* Rowstride from width if not given */
if (rowstride == 0)
rowstride = width * cogl_pixel_format_get_bytes_per_pixel (format, 0);
/* Wrap the data into a bitmap */
bmp = cogl_bitmap_new_for_data (ctx,
width, height,
format,
rowstride,
(uint8_t *) data);
tex_2d = cogl_texture_2d_new_from_bitmap (bmp);
g_object_unref (bmp);
if (tex_2d &&
!cogl_texture_allocate (COGL_TEXTURE (tex_2d), error))
{ {
TRUE, /* primitive */ g_object_unref (tex_2d);
_cogl_texture_2d_allocate, return NULL;
_cogl_texture_2d_set_region, }
_cogl_texture_2d_is_get_data_supported,
_cogl_texture_2d_get_data, return tex_2d;
NULL, /* foreach_sub_texture_in_region */ }
_cogl_texture_2d_get_max_waste,
_cogl_texture_2d_is_sliced, #if defined (COGL_HAS_EGL_SUPPORT) && defined (EGL_KHR_image_base)
_cogl_texture_2d_can_hardware_repeat, /* NB: The reason we require the width, height and format to be passed
_cogl_texture_2d_transform_coords_to_gl, * even though they may seem redundant is because GLES 1/2 don't
_cogl_texture_2d_transform_quad_coords_to_gl, * provide a way to query these properties. */
_cogl_texture_2d_get_gl_texture, CoglTexture *
_cogl_texture_2d_gl_flush_legacy_texobj_filters, cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
_cogl_texture_2d_pre_paint, int width,
_cogl_texture_2d_ensure_non_quad_rendering, int height,
_cogl_texture_2d_gl_flush_legacy_texobj_wrap_modes, CoglPixelFormat format,
_cogl_texture_2d_get_format, EGLImageKHR image,
_cogl_texture_2d_get_gl_format, CoglEglImageFlags flags,
_cogl_texture_2d_set_auto_mipmap GError **error)
}; {
CoglTextureLoader *loader;
CoglTexture *tex;
g_return_val_if_fail (_cogl_context_get_winsys (ctx)->constraints &
COGL_RENDERER_CONSTRAINT_USES_EGL,
NULL);
g_return_val_if_fail (_cogl_has_private_feature
(ctx,
COGL_PRIVATE_FEATURE_TEXTURE_2D_FROM_EGL_IMAGE),
NULL);
loader = _cogl_texture_create_loader ();
loader->src_type = COGL_TEXTURE_SOURCE_TYPE_EGL_IMAGE;
loader->src.egl_image.image = image;
loader->src.egl_image.width = width;
loader->src.egl_image.height = height;
loader->src.egl_image.format = format;
loader->src.egl_image.flags = flags;
tex = _cogl_texture_2d_create_base (ctx, width, height, format, loader);
if (!cogl_texture_allocate (COGL_TEXTURE (tex), error))
{
g_object_unref (tex);
return NULL;
}
return tex;
}
#endif /* defined (COGL_HAS_EGL_SUPPORT) && defined (EGL_KHR_image_base) */
void
_cogl_texture_2d_externally_modified (CoglTexture *texture)
{
if (!COGL_IS_TEXTURE_2D (texture))
return;
COGL_TEXTURE_2D (texture)->mipmaps_dirty = TRUE;
}

View File

@ -46,8 +46,9 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/** /**
* SECTION:cogl-texture-2d * CoglTexture2D:
* @short_description: Functions for creating and manipulating 2D textures *
* Functions for creating and manipulating 2D textures
* *
* These functions allow low-level 2D textures to be allocated. These * These functions allow low-level 2D textures to be allocated. These
* differ from sliced textures for example which may internally be * differ from sliced textures for example which may internally be
@ -56,8 +57,21 @@ G_BEGIN_DECLS
* by the GPU. * by the GPU.
*/ */
#define COGL_TYPE_TEXTURE_2D (cogl_texture_2d_get_type ())
#define COGL_TEXTURE_2D(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COGL_TYPE_TEXTURE_2D, CoglTexture2D))
#define COGL_TEXTURE_2D_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COGL_TYPE_TEXTURE_2D, CoglTexture2D const))
#define COGL_TEXTURE_2D_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COGL_TYPE_TEXTURE_2D, CoglTexture2DClass))
#define COGL_IS_TEXTURE_2D(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COGL_TYPE_TEXTURE_2D))
#define COGL_IS_TEXTURE_2D_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COGL_TYPE_TEXTURE_2D))
#define COGL_TEXTURE_2D_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), COGL_TYPE_TEXTURE_2D, CoglTexture2DClass))
typedef struct _CoglTexture2DClass CoglTexture2DClass;
typedef struct _CoglTexture2D CoglTexture2D; typedef struct _CoglTexture2D CoglTexture2D;
#define COGL_TEXTURE_2D(X) ((CoglTexture2D *)X)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglTexture2D, g_object_unref)
COGL_EXPORT
GType cogl_texture_2d_get_type (void) G_GNUC_CONST;
typedef enum _CoglEglImageFlags typedef enum _CoglEglImageFlags
{ {
@ -65,27 +79,6 @@ typedef enum _CoglEglImageFlags
COGL_EGL_IMAGE_FLAG_NO_GET_DATA = 1 << 0, COGL_EGL_IMAGE_FLAG_NO_GET_DATA = 1 << 0,
} CoglEglImageFlags; } CoglEglImageFlags;
/**
* cogl_texture_2d_get_gtype:
*
* Returns: a #GType that can be used with the GLib type system.
*/
COGL_EXPORT
GType cogl_texture_2d_get_gtype (void);
/**
* cogl_is_texture_2d:
* @object: A #CoglObject
*
* Gets whether the given object references an existing #CoglTexture2D
* object.
*
* Return value: %TRUE if the object references a #CoglTexture2D,
* %FALSE otherwise
*/
COGL_EXPORT gboolean
cogl_is_texture_2d (void *object);
/** /**
* cogl_texture_2d_new_with_format: (skip) * cogl_texture_2d_new_with_format: (skip)
* @ctx: A #CoglContext * @ctx: A #CoglContext
@ -111,7 +104,7 @@ cogl_is_texture_2d (void *object);
* *
* Since: 2.0 * Since: 2.0
*/ */
COGL_EXPORT CoglTexture2D * COGL_EXPORT CoglTexture *
cogl_texture_2d_new_with_format (CoglContext *ctx, cogl_texture_2d_new_with_format (CoglContext *ctx,
int width, int width,
int height, int height,
@ -139,7 +132,7 @@ cogl_texture_2d_new_with_format (CoglContext *ctx,
* *
* Returns: (transfer full): A new #CoglTexture2D object with no storage yet allocated. * Returns: (transfer full): A new #CoglTexture2D object with no storage yet allocated.
*/ */
COGL_EXPORT CoglTexture2D * COGL_EXPORT CoglTexture *
cogl_texture_2d_new_with_size (CoglContext *ctx, cogl_texture_2d_new_with_size (CoglContext *ctx,
int width, int width,
int height); int height);
@ -175,7 +168,7 @@ cogl_texture_2d_new_with_size (CoglContext *ctx,
* non-power-of-two size that the hardware doesn't support) * non-power-of-two size that the hardware doesn't support)
* it will return %NULL and set @error. * it will return %NULL and set @error.
*/ */
COGL_EXPORT CoglTexture2D * COGL_EXPORT CoglTexture *
cogl_texture_2d_new_from_data (CoglContext *ctx, cogl_texture_2d_new_from_data (CoglContext *ctx,
int width, int width,
int height, int height,
@ -204,7 +197,7 @@ cogl_texture_2d_new_from_data (CoglContext *ctx,
* *
* Returns: (transfer full): A newly allocated #CoglTexture2D * Returns: (transfer full): A newly allocated #CoglTexture2D
*/ */
COGL_EXPORT CoglTexture2D * COGL_EXPORT CoglTexture *
cogl_texture_2d_new_from_bitmap (CoglBitmap *bitmap); cogl_texture_2d_new_from_bitmap (CoglBitmap *bitmap);
/** /**
@ -214,7 +207,7 @@ cogl_texture_2d_new_from_bitmap (CoglBitmap *bitmap);
/* NB: The reason we require the width, height and format to be passed /* NB: The reason we require the width, height and format to be passed
* even though they may seem redundant is because GLES 1/2 don't * even though they may seem redundant is because GLES 1/2 don't
* provide a way to query these properties. */ * provide a way to query these properties. */
COGL_EXPORT CoglTexture2D * COGL_EXPORT CoglTexture *
cogl_egl_texture_2d_new_from_image (CoglContext *ctx, cogl_egl_texture_2d_new_from_image (CoglContext *ctx,
int width, int width,
int height, int height,
@ -230,7 +223,7 @@ typedef gboolean (*CoglTexture2DEGLImageExternalAlloc) (CoglTexture2D *tex_2d,
/** /**
* cogl_texture_2d_new_from_egl_image_external: (skip) * cogl_texture_2d_new_from_egl_image_external: (skip)
*/ */
COGL_EXPORT CoglTexture2D * COGL_EXPORT CoglTexture *
cogl_texture_2d_new_from_egl_image_external (CoglContext *ctx, cogl_texture_2d_new_from_egl_image_external (CoglContext *ctx,
int width, int width,
int height, int height,

View File

@ -31,7 +31,6 @@
#pragma once #pragma once
#include "cogl/cogl-bitmap-private.h" #include "cogl/cogl-bitmap-private.h"
#include "cogl/cogl-object-private.h"
#include "cogl/cogl-pipeline-private.h" #include "cogl/cogl-pipeline-private.h"
#include "cogl/cogl-spans.h" #include "cogl/cogl-spans.h"
#include "cogl/cogl-meta-texture.h" #include "cogl/cogl-meta-texture.h"
@ -42,8 +41,6 @@
#include "cogl/cogl-egl-defines.h" #include "cogl/cogl-egl-defines.h"
#endif #endif
typedef struct _CoglTextureVtable CoglTextureVtable;
/* Encodes three possibiloities result of transforming a quad */ /* Encodes three possibiloities result of transforming a quad */
typedef enum typedef enum
{ {
@ -66,13 +63,79 @@ typedef enum
COGL_TEXTURE_NEEDS_MIPMAP = 1 COGL_TEXTURE_NEEDS_MIPMAP = 1
} CoglTexturePrePaintFlags; } CoglTexturePrePaintFlags;
struct _CoglTextureVtable
typedef enum _CoglTextureSourceType {
COGL_TEXTURE_SOURCE_TYPE_SIZE = 1,
COGL_TEXTURE_SOURCE_TYPE_BITMAP,
COGL_TEXTURE_SOURCE_TYPE_EGL_IMAGE,
COGL_TEXTURE_SOURCE_TYPE_EGL_IMAGE_EXTERNAL
} CoglTextureSourceType;
typedef struct _CoglTextureLoader
{ {
/* Virtual functions that must be implemented for a texture CoglTextureSourceType src_type;
backend */ union {
struct {
int width;
int height;
int depth; /* for 3d textures */
CoglPixelFormat format;
} sized;
struct {
CoglBitmap *bitmap;
int height; /* for 3d textures */
int depth; /* for 3d textures */
} bitmap;
#if defined (COGL_HAS_EGL_SUPPORT) && defined (EGL_KHR_image_base)
struct {
EGLImageKHR image;
int width;
int height;
CoglPixelFormat format;
CoglEglImageFlags flags;
} egl_image;
#endif
#if defined (COGL_HAS_EGL_SUPPORT)
struct {
int width;
int height;
CoglTexture2DEGLImageExternalAlloc alloc;
CoglPixelFormat format;
} egl_image_external;
#endif
struct {
int width;
int height;
unsigned int gl_handle;
CoglPixelFormat format;
} gl_foreign;
} src;
} CoglTextureLoader;
struct _CoglTexture
{
GObject parent_instance;
CoglContext *context;
gboolean is_primitive; gboolean is_primitive;
CoglTextureLoader *loader;
GList *framebuffers;
int max_level_set;
int max_level_requested;
int width;
int height;
gboolean allocated;
/*
* Internal format
*/
CoglTextureComponents components;
unsigned int premultiplied : 1;
};
struct _CoglTextureClass
{
GObjectClass parent_class;
gboolean (* allocate) (CoglTexture *tex, gboolean (* allocate) (CoglTexture *tex,
GError **error); GError **error);
@ -133,7 +196,8 @@ struct _CoglTextureVtable
GLenum min_filter, GLenum min_filter,
GLenum mag_filter); GLenum mag_filter);
void (* pre_paint) (CoglTexture *tex, CoglTexturePrePaintFlags flags); void (* pre_paint) (CoglTexture *tex,
CoglTexturePrePaintFlags flags);
void (* ensure_non_quad_rendering) (CoglTexture *tex); void (* ensure_non_quad_rendering) (CoglTexture *tex);
/* OpenGL driver specific virtual function */ /* OpenGL driver specific virtual function */
@ -149,75 +213,6 @@ struct _CoglTextureVtable
gboolean value); gboolean value);
}; };
typedef enum _CoglTextureSourceType {
COGL_TEXTURE_SOURCE_TYPE_SIZE = 1,
COGL_TEXTURE_SOURCE_TYPE_BITMAP,
COGL_TEXTURE_SOURCE_TYPE_EGL_IMAGE,
COGL_TEXTURE_SOURCE_TYPE_EGL_IMAGE_EXTERNAL
} CoglTextureSourceType;
typedef struct _CoglTextureLoader
{
CoglTextureSourceType src_type;
union {
struct {
int width;
int height;
int depth; /* for 3d textures */
CoglPixelFormat format;
} sized;
struct {
CoglBitmap *bitmap;
int height; /* for 3d textures */
int depth; /* for 3d textures */
} bitmap;
#if defined (COGL_HAS_EGL_SUPPORT) && defined (EGL_KHR_image_base)
struct {
EGLImageKHR image;
int width;
int height;
CoglPixelFormat format;
CoglEglImageFlags flags;
} egl_image;
#endif
#if defined (COGL_HAS_EGL_SUPPORT)
struct {
int width;
int height;
CoglTexture2DEGLImageExternalAlloc alloc;
CoglPixelFormat format;
} egl_image_external;
#endif
struct {
int width;
int height;
unsigned int gl_handle;
CoglPixelFormat format;
} gl_foreign;
} src;
} CoglTextureLoader;
struct _CoglTexture
{
CoglObject _parent;
CoglContext *context;
CoglTextureLoader *loader;
GList *framebuffers;
int max_level_set;
int max_level_requested;
int width;
int height;
gboolean allocated;
/*
* Internal format
*/
CoglTextureComponents components;
unsigned int premultiplied:1;
const CoglTextureVtable *vtable;
};
typedef enum _CoglTextureChangeFlags typedef enum _CoglTextureChangeFlags
{ {
/* Whenever the internals of a texture are changed such that the /* Whenever the internals of a texture are changed such that the
@ -251,26 +246,8 @@ _cogl_texture_init (CoglTexture *texture,
int width, int width,
int height, int height,
CoglPixelFormat src_format, CoglPixelFormat src_format,
CoglTextureLoader *loader, CoglTextureLoader *loader);
const CoglTextureVtable *vtable);
void
_cogl_texture_free (CoglTexture *texture);
/* This is used to register a type to the list of handle types that
will be considered a texture in cogl_is_texture() */
void
_cogl_texture_register_texture_type (const CoglObjectClass *klass);
#define COGL_TEXTURE_DEFINE(TypeName, type_name) \
COGL_OBJECT_DEFINE_WITH_CODE_GTYPE \
(TypeName, type_name, \
_cogl_texture_register_texture_type (&_cogl_##type_name##_class))
#define COGL_TEXTURE_INTERNAL_DEFINE(TypeName, type_name) \
COGL_OBJECT_INTERNAL_DEFINE_WITH_CODE \
(TypeName, type_name, \
_cogl_texture_register_texture_type (&_cogl_##type_name##_class))
COGL_EXPORT gboolean COGL_EXPORT gboolean
_cogl_texture_can_hardware_repeat (CoglTexture *texture); _cogl_texture_can_hardware_repeat (CoglTexture *texture);
@ -403,3 +380,16 @@ _cogl_texture_create_loader (void);
void void
_cogl_texture_copy_internal_format (CoglTexture *src, _cogl_texture_copy_internal_format (CoglTexture *src,
CoglTexture *dest); CoglTexture *dest);
CoglContext *
cogl_texture_get_context (CoglTexture *texture);
CoglTextureLoader *
cogl_texture_get_loader (CoglTexture *texture);
int
cogl_texture_get_max_level_set (CoglTexture *texture);
void
cogl_texture_set_max_level_set (CoglTexture *texture,
int max_level_set);

View File

@ -50,94 +50,17 @@
#include "cogl/cogl-atlas-texture-private.h" #include "cogl/cogl-atlas-texture-private.h"
#include "cogl/cogl-pipeline.h" #include "cogl/cogl-pipeline.h"
#include "cogl/cogl-context-private.h" #include "cogl/cogl-context-private.h"
#include "cogl/cogl-object-private.h"
#include "cogl/cogl-object-private.h"
#include "cogl/cogl-offscreen-private.h" #include "cogl/cogl-offscreen-private.h"
#include "cogl/cogl-framebuffer-private.h" #include "cogl/cogl-framebuffer-private.h"
#include "cogl/cogl1-context.h" #include "cogl/cogl1-context.h"
#include "cogl/cogl-sub-texture.h" #include "cogl/cogl-sub-texture.h"
#include "cogl/cogl-primitive-texture.h" #include "cogl/cogl-primitive-texture.h"
#include "cogl/cogl-gtype-private.h"
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
COGL_GTYPE_DEFINE_INTERFACE (Texture, texture); G_DEFINE_ABSTRACT_TYPE (CoglTexture, cogl_texture, G_TYPE_OBJECT)
uint32_t
cogl_texture_error_quark (void)
{
return g_quark_from_static_string ("cogl-texture-error-quark");
}
/* XXX:
* The CoglObject macros don't support any form of inheritance, so for
* now we implement the CoglObject support for the CoglTexture
* abstract class manually.
*/
static GSList *_cogl_texture_types;
void
_cogl_texture_register_texture_type (const CoglObjectClass *klass)
{
_cogl_texture_types = g_slist_prepend (_cogl_texture_types, (void *) klass);
}
gboolean
cogl_is_texture (void *object)
{
CoglObject *obj = (CoglObject *)object;
GSList *l;
if (object == NULL)
return FALSE;
for (l = _cogl_texture_types; l; l = l->next)
if (l->data == obj->klass)
return TRUE;
return FALSE;
}
void
_cogl_texture_init (CoglTexture *texture,
CoglContext *context,
int width,
int height,
CoglPixelFormat src_format,
CoglTextureLoader *loader,
const CoglTextureVtable *vtable)
{
texture->context = context;
texture->max_level_set = 0;
texture->max_level_requested = 1000; /* OpenGL default GL_TEXTURE_MAX_LEVEL */
texture->width = width;
texture->height = height;
texture->allocated = FALSE;
texture->vtable = vtable;
texture->framebuffers = NULL;
texture->loader = loader;
_cogl_texture_set_internal_format (texture, src_format);
/* Although we want to initialize texture::components according
* to the source format, we always want the internal layout to
* be considered premultiplied by default.
*
* NB: this ->premultiplied state is user configurable so to avoid
* awkward documentation, setting this to 'true' does not depend on
* ->components having an alpha component (we will simply ignore the
* premultiplied status later if there is no alpha component).
* This way we don't have to worry about updating the
* ->premultiplied state in _set_components(). Similarly we don't
* have to worry about updating the ->components state in
* _set_premultiplied().
*/
texture->premultiplied = TRUE;
}
static void static void
_cogl_texture_free_loader (CoglTexture *texture) _cogl_texture_free_loader (CoglTexture *texture)
@ -160,20 +83,75 @@ _cogl_texture_free_loader (CoglTexture *texture)
} }
} }
static void
cogl_texture_dispose (GObject *object)
{
CoglTexture *texture = COGL_TEXTURE (object);
_cogl_texture_free_loader (texture);
G_OBJECT_CLASS (cogl_texture_parent_class)->dispose (object);
}
static void
cogl_texture_class_init (CoglTextureClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->dispose = cogl_texture_dispose;
}
static void
cogl_texture_init (CoglTexture *texture)
{
texture->max_level_set = 0;
texture->max_level_requested = 1000; /* OpenGL default GL_TEXTURE_MAX_LEVEL */
texture->allocated = FALSE;
texture->framebuffers = NULL;
}
uint32_t
cogl_texture_error_quark (void)
{
return g_quark_from_static_string ("cogl-texture-error-quark");
}
void
_cogl_texture_init (CoglTexture *texture,
CoglContext *context,
int width,
int height,
CoglPixelFormat src_format,
CoglTextureLoader *loader)
{
texture->context = context;
texture->width = width;
texture->height = height;
texture->loader = loader;
_cogl_texture_set_internal_format (texture, src_format);
/* Although we want to initialize texture::components according
* to the source format, we always want the internal layout to
* be considered premultiplied by default.
*
* NB: this ->premultiplied state is user configurable so to avoid
* awkward documentation, setting this to 'true' does not depend on
* ->components having an alpha component (we will simply ignore the
* premultiplied status later if there is no alpha component).
* This way we don't have to worry about updating the
* ->premultiplied state in _set_components(). Similarly we don't
* have to worry about updating the ->components state in
* _set_premultiplied().
*/
texture->premultiplied = TRUE;
}
CoglTextureLoader * CoglTextureLoader *
_cogl_texture_create_loader (void) _cogl_texture_create_loader (void)
{ {
return g_new0 (CoglTextureLoader, 1); return g_new0 (CoglTextureLoader, 1);
} }
void
_cogl_texture_free (CoglTexture *texture)
{
_cogl_texture_free_loader (texture);
g_free (texture);
}
gboolean gboolean
_cogl_texture_needs_premult_conversion (CoglPixelFormat src_format, _cogl_texture_needs_premult_conversion (CoglPixelFormat src_format,
CoglPixelFormat dst_format) CoglPixelFormat dst_format)
@ -188,8 +166,8 @@ _cogl_texture_needs_premult_conversion (CoglPixelFormat src_format,
gboolean gboolean
cogl_texture_is_get_data_supported (CoglTexture *texture) cogl_texture_is_get_data_supported (CoglTexture *texture)
{ {
if (texture->vtable->is_get_data_supported) if (COGL_TEXTURE_GET_CLASS (texture)->is_get_data_supported)
return texture->vtable->is_get_data_supported (texture); return COGL_TEXTURE_GET_CLASS (texture)->is_get_data_supported (texture);
else else
return TRUE; return TRUE;
} }
@ -197,7 +175,7 @@ cogl_texture_is_get_data_supported (CoglTexture *texture)
unsigned int unsigned int
cogl_texture_get_width (CoglTexture *texture) cogl_texture_get_width (CoglTexture *texture)
{ {
g_return_val_if_fail (cogl_is_texture (texture), 0); g_return_val_if_fail (COGL_IS_TEXTURE (texture), 0);
return texture->width; return texture->width;
} }
@ -205,7 +183,7 @@ cogl_texture_get_width (CoglTexture *texture)
unsigned int unsigned int
cogl_texture_get_height (CoglTexture *texture) cogl_texture_get_height (CoglTexture *texture)
{ {
g_return_val_if_fail (cogl_is_texture (texture), 0); g_return_val_if_fail (COGL_IS_TEXTURE (texture), 0);
return texture->height; return texture->height;
} }
@ -215,15 +193,16 @@ _cogl_texture_get_format (CoglTexture *texture)
{ {
if (!texture->allocated) if (!texture->allocated)
cogl_texture_allocate (texture, NULL); cogl_texture_allocate (texture, NULL);
return texture->vtable->get_format (texture);
return COGL_TEXTURE_GET_CLASS (texture)->get_format (texture);
} }
int int
cogl_texture_get_max_waste (CoglTexture *texture) cogl_texture_get_max_waste (CoglTexture *texture)
{ {
g_return_val_if_fail (cogl_is_texture (texture), 0); g_return_val_if_fail (COGL_IS_TEXTURE (texture), 0);
return texture->vtable->get_max_waste (texture); return COGL_TEXTURE_GET_CLASS (texture)->get_max_waste (texture);
} }
int int
@ -278,11 +257,12 @@ _cogl_texture_get_level_size (CoglTexture *texture,
gboolean gboolean
cogl_texture_is_sliced (CoglTexture *texture) cogl_texture_is_sliced (CoglTexture *texture)
{ {
g_return_val_if_fail (cogl_is_texture (texture), FALSE); g_return_val_if_fail (COGL_IS_TEXTURE (texture), FALSE);
if (!texture->allocated) if (!texture->allocated)
cogl_texture_allocate (texture, NULL); cogl_texture_allocate (texture, NULL);
return texture->vtable->is_sliced (texture);
return COGL_TEXTURE_GET_CLASS (texture)->is_sliced (texture);
} }
/* If this returns FALSE, that implies _foreach_sub_texture_in_region /* If this returns FALSE, that implies _foreach_sub_texture_in_region
@ -294,7 +274,7 @@ _cogl_texture_can_hardware_repeat (CoglTexture *texture)
{ {
if (!texture->allocated) if (!texture->allocated)
cogl_texture_allocate (texture, NULL); cogl_texture_allocate (texture, NULL);
return texture->vtable->can_hardware_repeat (texture); return COGL_TEXTURE_GET_CLASS (texture)->can_hardware_repeat (texture);
} }
/* NB: You can't use this with textures comprised of multiple sub textures (use /* NB: You can't use this with textures comprised of multiple sub textures (use
@ -305,14 +285,14 @@ _cogl_texture_transform_coords_to_gl (CoglTexture *texture,
float *s, float *s,
float *t) float *t)
{ {
texture->vtable->transform_coords_to_gl (texture, s, t); COGL_TEXTURE_GET_CLASS (texture)->transform_coords_to_gl (texture, s, t);
} }
CoglTransformResult CoglTransformResult
_cogl_texture_transform_quad_coords_to_gl (CoglTexture *texture, _cogl_texture_transform_quad_coords_to_gl (CoglTexture *texture,
float *coords) float *coords)
{ {
return texture->vtable->transform_quad_coords_to_gl (texture, coords); return COGL_TEXTURE_GET_CLASS (texture)->transform_quad_coords_to_gl (texture, coords);
} }
gboolean gboolean
@ -320,13 +300,14 @@ cogl_texture_get_gl_texture (CoglTexture *texture,
GLuint *out_gl_handle, GLuint *out_gl_handle,
GLenum *out_gl_target) GLenum *out_gl_target)
{ {
g_return_val_if_fail (cogl_is_texture (texture), FALSE); g_return_val_if_fail (COGL_IS_TEXTURE (texture), FALSE);
if (!texture->allocated) if (!texture->allocated)
cogl_texture_allocate (texture, NULL); cogl_texture_allocate (texture, NULL);
return texture->vtable->get_gl_texture (texture, return COGL_TEXTURE_GET_CLASS (texture)->get_gl_texture (texture,
out_gl_handle, out_gl_target); out_gl_handle,
out_gl_target);
} }
void void
@ -346,13 +327,14 @@ _cogl_texture_pre_paint (CoglTexture *texture, CoglTexturePrePaintFlags flags)
*/ */
cogl_texture_allocate (texture, NULL); cogl_texture_allocate (texture, NULL);
texture->vtable->pre_paint (texture, flags); COGL_TEXTURE_GET_CLASS (texture)->pre_paint (texture,
flags);
} }
void void
_cogl_texture_ensure_non_quad_rendering (CoglTexture *texture) _cogl_texture_ensure_non_quad_rendering (CoglTexture *texture)
{ {
texture->vtable->ensure_non_quad_rendering (texture); COGL_TEXTURE_GET_CLASS (texture)->ensure_non_quad_rendering (texture);
} }
gboolean gboolean
@ -383,7 +365,7 @@ _cogl_texture_set_region_from_bitmap (CoglTexture *texture,
always stored in an RGBA texture even if the texture format is always stored in an RGBA texture even if the texture format is
advertised as RGB. */ advertised as RGB. */
return texture->vtable->set_region (texture, return COGL_TEXTURE_GET_CLASS (texture)->set_region (texture,
src_x, src_y, src_x, src_y,
dst_x, dst_y, dst_x, dst_y,
width, height, width, height,
@ -405,7 +387,7 @@ cogl_texture_set_region_from_bitmap (CoglTexture *texture,
GError *ignore_error = NULL; GError *ignore_error = NULL;
gboolean status; gboolean status;
g_return_val_if_fail (cogl_is_texture (texture), FALSE); g_return_val_if_fail (COGL_IS_TEXTURE (texture), FALSE);
status = _cogl_texture_set_region_from_bitmap (texture, status = _cogl_texture_set_region_from_bitmap (texture,
src_x, src_y, src_x, src_y,
@ -431,7 +413,7 @@ _cogl_texture_set_region (CoglTexture *texture,
int level, int level,
GError **error) GError **error)
{ {
CoglContext *ctx = texture->context; CoglContext *ctx = cogl_texture_get_context (texture);
CoglBitmap *source_bmp; CoglBitmap *source_bmp;
gboolean ret; gboolean ret;
@ -481,7 +463,7 @@ cogl_texture_set_region (CoglTexture *texture,
int bytes_per_pixel; int bytes_per_pixel;
gboolean status; gboolean status;
g_return_val_if_fail (cogl_is_texture (texture), FALSE); g_return_val_if_fail (COGL_IS_TEXTURE (texture), FALSE);
g_return_val_if_fail (format != COGL_PIXEL_FORMAT_ANY, FALSE); g_return_val_if_fail (format != COGL_PIXEL_FORMAT_ANY, FALSE);
g_return_val_if_fail (cogl_pixel_format_get_n_planes (format) == 1, FALSE); g_return_val_if_fail (cogl_pixel_format_get_n_planes (format) == 1, FALSE);
@ -517,7 +499,7 @@ cogl_texture_set_data (CoglTexture *texture,
int level_width; int level_width;
int level_height; int level_height;
g_return_val_if_fail (cogl_is_texture (texture), FALSE); g_return_val_if_fail (COGL_IS_TEXTURE (texture), FALSE);
_cogl_texture_get_level_size (texture, _cogl_texture_get_level_size (texture,
level, level,
@ -547,7 +529,7 @@ get_texture_bits_via_offscreen (CoglTexture *meta_texture,
unsigned int dst_rowstride, unsigned int dst_rowstride,
CoglPixelFormat closest_format) CoglPixelFormat closest_format)
{ {
CoglContext *ctx = sub_texture->context; CoglContext *ctx = cogl_texture_get_context (sub_texture);
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
CoglFramebuffer *framebuffer; CoglFramebuffer *framebuffer;
CoglBitmap *bitmap; CoglBitmap *bitmap;
@ -628,7 +610,7 @@ get_texture_bits_via_copy (CoglTexture *texture,
full_rowstride = bpp * full_tex_width; full_rowstride = bpp * full_tex_width;
full_bits = g_malloc (full_rowstride * full_tex_height); full_bits = g_malloc (full_rowstride * full_tex_height);
if (texture->vtable->get_data (texture, if (COGL_TEXTURE_GET_CLASS (texture)->get_data (texture,
dst_format, dst_format,
full_rowstride, full_rowstride,
full_bits)) full_bits))
@ -702,7 +684,7 @@ texture_get_cb (CoglTexture *subtexture,
if (x_in_subtexture == 0 && y_in_subtexture == 0 && if (x_in_subtexture == 0 && y_in_subtexture == 0 &&
width == subtexture_width && height == subtexture_height) width == subtexture_width && height == subtexture_height)
{ {
if (subtexture->vtable->get_data (subtexture, if (COGL_TEXTURE_GET_CLASS (subtexture)->get_data (subtexture,
closest_format, closest_format,
rowstride, rowstride,
dst_bits)) dst_bits))
@ -752,7 +734,7 @@ cogl_texture_get_data (CoglTexture *texture,
GError *ignore_error = NULL; GError *ignore_error = NULL;
CoglTextureGetData tg_data; CoglTextureGetData tg_data;
g_return_val_if_fail (cogl_is_texture (texture), 0); g_return_val_if_fail (COGL_IS_TEXTURE (texture), 0);
texture_format = _cogl_texture_get_format (texture); texture_format = _cogl_texture_get_format (texture);
@ -776,7 +758,7 @@ cogl_texture_get_data (CoglTexture *texture,
if (data == NULL) if (data == NULL)
return byte_size; return byte_size;
ctx = texture->context; ctx = cogl_texture_get_context (texture);
closest_format = closest_format =
ctx->texture_driver->find_best_gl_get_data_format (ctx, ctx->texture_driver->find_best_gl_get_data_format (ctx,
format, format,
@ -856,7 +838,7 @@ cogl_texture_get_data (CoglTexture *texture,
* the data for a sliced texture, and allows us to do the * the data for a sliced texture, and allows us to do the
* read-from-framebuffer logic here in a simple fashion rather than * read-from-framebuffer logic here in a simple fashion rather than
* passing offsets down through the code. */ * passing offsets down through the code. */
cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (texture), cogl_meta_texture_foreach_in_region (texture,
0, 0, 1, 1, 0, 0, 1, 1,
COGL_PIPELINE_WRAP_MODE_REPEAT, COGL_PIPELINE_WRAP_MODE_REPEAT,
COGL_PIPELINE_WRAP_MODE_REPEAT, COGL_PIPELINE_WRAP_MODE_REPEAT,
@ -939,12 +921,12 @@ _cogl_texture_get_associated_framebuffers (CoglTexture *texture)
void void
_cogl_texture_flush_journal_rendering (CoglTexture *texture) _cogl_texture_flush_journal_rendering (CoglTexture *texture)
{ {
GList *l; const GList *l;
/* It could be that a referenced texture is part of a framebuffer /* It could be that a referenced texture is part of a framebuffer
* which has an associated journal that must be flushed before it * which has an associated journal that must be flushed before it
* can be sampled from by the current primitive... */ * can be sampled from by the current primitive... */
for (l = texture->framebuffers; l; l = l->next) for (l = _cogl_texture_get_associated_framebuffers (texture); l; l = l->next)
_cogl_framebuffer_flush_journal (l->data); _cogl_framebuffer_flush_journal (l->data);
} }
@ -1081,7 +1063,7 @@ gboolean
cogl_texture_allocate (CoglTexture *texture, cogl_texture_allocate (CoglTexture *texture,
GError **error) GError **error)
{ {
g_return_val_if_fail (cogl_is_texture (texture), FALSE); g_return_val_if_fail (COGL_IS_TEXTURE (texture), FALSE);
if (texture->allocated) if (texture->allocated)
return TRUE; return TRUE;
@ -1094,7 +1076,7 @@ cogl_texture_allocate (CoglTexture *texture,
"A red-green texture was requested but the driver " "A red-green texture was requested but the driver "
"does not support them"); "does not support them");
texture->allocated = texture->vtable->allocate (texture, error); texture->allocated = COGL_TEXTURE_GET_CLASS (texture)->allocate (texture, error);
return texture->allocated; return texture->allocated;
} }
@ -1138,14 +1120,14 @@ CoglPixelFormat
_cogl_texture_determine_internal_format (CoglTexture *texture, _cogl_texture_determine_internal_format (CoglTexture *texture,
CoglPixelFormat src_format) CoglPixelFormat src_format)
{ {
switch (texture->components) switch (cogl_texture_get_components (texture))
{ {
case COGL_TEXTURE_COMPONENTS_DEPTH: case COGL_TEXTURE_COMPONENTS_DEPTH:
if (src_format & COGL_DEPTH_BIT) if (src_format & COGL_DEPTH_BIT)
return src_format; return src_format;
else else
{ {
CoglContext *ctx = texture->context; CoglContext *ctx = cogl_texture_get_context (texture);
if (_cogl_has_private_feature (ctx, if (_cogl_has_private_feature (ctx,
COGL_PRIVATE_FEATURE_EXT_PACKED_DEPTH_STENCIL) || COGL_PRIVATE_FEATURE_EXT_PACKED_DEPTH_STENCIL) ||
@ -1177,7 +1159,7 @@ _cogl_texture_determine_internal_format (CoglTexture *texture,
else else
format = COGL_PIXEL_FORMAT_RGBA_8888; format = COGL_PIXEL_FORMAT_RGBA_8888;
if (texture->premultiplied) if (cogl_texture_get_premultiplied (texture))
{ {
if (COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT (format)) if (COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT (format))
return format |= COGL_PREMULT_BIT; return format |= COGL_PREMULT_BIT;
@ -1196,7 +1178,7 @@ void
cogl_texture_set_components (CoglTexture *texture, cogl_texture_set_components (CoglTexture *texture,
CoglTextureComponents components) CoglTextureComponents components)
{ {
g_return_if_fail (cogl_is_texture (texture)); g_return_if_fail (COGL_IS_TEXTURE (texture));
g_return_if_fail (!texture->allocated); g_return_if_fail (!texture->allocated);
if (texture->components == components) if (texture->components == components)
@ -1208,7 +1190,7 @@ cogl_texture_set_components (CoglTexture *texture,
CoglTextureComponents CoglTextureComponents
cogl_texture_get_components (CoglTexture *texture) cogl_texture_get_components (CoglTexture *texture)
{ {
g_return_val_if_fail (cogl_is_texture (texture), 0); g_return_val_if_fail (COGL_IS_TEXTURE (texture), 0);
return texture->components; return texture->components;
} }
@ -1217,7 +1199,7 @@ void
cogl_texture_set_premultiplied (CoglTexture *texture, cogl_texture_set_premultiplied (CoglTexture *texture,
gboolean premultiplied) gboolean premultiplied)
{ {
g_return_if_fail (cogl_is_texture (texture)); g_return_if_fail (COGL_IS_TEXTURE (texture));
g_return_if_fail (!texture->allocated); g_return_if_fail (!texture->allocated);
premultiplied = !!premultiplied; premultiplied = !!premultiplied;
@ -1231,7 +1213,7 @@ cogl_texture_set_premultiplied (CoglTexture *texture,
gboolean gboolean
cogl_texture_get_premultiplied (CoglTexture *texture) cogl_texture_get_premultiplied (CoglTexture *texture)
{ {
g_return_val_if_fail (cogl_is_texture (texture), FALSE); g_return_val_if_fail (COGL_IS_TEXTURE (texture), FALSE);
return texture->premultiplied; return texture->premultiplied;
} }
@ -1240,6 +1222,31 @@ void
_cogl_texture_copy_internal_format (CoglTexture *src, _cogl_texture_copy_internal_format (CoglTexture *src,
CoglTexture *dest) CoglTexture *dest)
{ {
cogl_texture_set_components (dest, src->components); cogl_texture_set_components (dest, cogl_texture_get_components (src));
cogl_texture_set_premultiplied (dest, src->premultiplied); cogl_texture_set_premultiplied (dest, cogl_texture_get_premultiplied (src));
}
CoglContext *
cogl_texture_get_context (CoglTexture *texture)
{
return texture->context;
}
CoglTextureLoader *
cogl_texture_get_loader (CoglTexture *texture)
{
return texture->loader;
}
int
cogl_texture_get_max_level_set (CoglTexture *texture)
{
return texture->max_level_set;
}
void
cogl_texture_set_max_level_set (CoglTexture *texture,
int max_level_set)
{
texture->max_level_set = max_level_set;
} }

View File

@ -34,21 +34,6 @@
#error "Only <cogl/cogl.h> can be included directly." #error "Only <cogl/cogl.h> can be included directly."
#endif #endif
/* We forward declare the CoglTexture type here to avoid some circular
* dependency issues with the following headers.
*/
#if defined(__COGL_H_INSIDE__) && !defined(COGL_ENABLE_MUTTER_API) && \
!defined(COGL_GIR_SCANNING)
/* For the public C api we typedef interface types as void to avoid needing
* lots of casting in code and instead we will rely on runtime type checking
* for these objects. */
typedef void CoglTexture;
#else
typedef struct _CoglTexture CoglTexture;
#define COGL_TEXTURE(X) ((CoglTexture *)X)
#endif
#include "cogl/cogl-types.h"
#include "cogl/cogl-macros.h" #include "cogl/cogl-macros.h"
#include "cogl/cogl-defines.h" #include "cogl/cogl-defines.h"
#include "cogl/cogl-pixel-buffer.h" #include "cogl/cogl-pixel-buffer.h"
@ -60,23 +45,32 @@ typedef struct _CoglTexture CoglTexture;
G_BEGIN_DECLS G_BEGIN_DECLS
/** /**
* SECTION:cogl-texture * CoglTexture:
* @short_description: Functions for creating and manipulating textures *
* Functions for creating and manipulating textures
* *
* Cogl allows creating and manipulating textures using a uniform * Cogl allows creating and manipulating textures using a uniform
* API that tries to hide all the various complexities of creating, * API that tries to hide all the various complexities of creating,
* loading and manipulating textures. * loading and manipulating textures.
*/ */
#define COGL_TEXTURE_MAX_WASTE 127 #define COGL_TYPE_TEXTURE (cogl_texture_get_type ())
#define COGL_TEXTURE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COGL_TYPE_TEXTURE, CoglTexture))
#define COGL_TEXTURE_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COGL_TYPE_TEXTURE, CoglTexture const))
#define COGL_TEXTURE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COGL_TYPE_TEXTURE, CoglTextureClass))
#define COGL_IS_TEXTURE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COGL_TYPE_TEXTURE))
#define COGL_IS_TEXTURE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COGL_TYPE_TEXTURE))
#define COGL_TEXTURE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), COGL_TYPE_TEXTURE, CoglTextureClass))
typedef struct _CoglTextureClass CoglTextureClass;
typedef struct _CoglTexture CoglTexture;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglTexture, g_object_unref)
/**
* cogl_texture_get_gtype:
*
* Returns: a #GType that can be used with the GLib type system.
*/
COGL_EXPORT COGL_EXPORT
GType cogl_texture_get_gtype (void); GType cogl_texture_get_type (void) G_GNUC_CONST;
#define COGL_TEXTURE_MAX_WASTE 127
/** /**
* COGL_TEXTURE_ERROR: * COGL_TEXTURE_ERROR:
@ -105,17 +99,6 @@ typedef enum
COGL_EXPORT COGL_EXPORT
uint32_t cogl_texture_error_quark (void); uint32_t cogl_texture_error_quark (void);
/**
* cogl_is_texture:
* @object: A #CoglObject pointer
*
* Gets whether the given object references a texture object.
*
* Return value: %TRUE if the @object references a texture, and
* %FALSE otherwise
*/
COGL_EXPORT gboolean
cogl_is_texture (void *object);
/** /**
* CoglTextureComponents: * CoglTextureComponents:

View File

@ -45,7 +45,4 @@
#if !defined(COGL_ENABLE_MUTTER_API) && !defined(COGL_GIR_SCANNING) #if !defined(COGL_ENABLE_MUTTER_API) && !defined(COGL_GIR_SCANNING)
#define COGL_BUFFER(X) (X) #define COGL_BUFFER(X) (X)
#define COGL_TEXTURE(X) (X)
#define COGL_META_TEXTURE(X) (X)
#define COGL_PRIMITIVE_TEXTURE(X) (X)
#endif #endif

View File

@ -503,7 +503,7 @@ flush_layers_common_gl_state_cb (CoglPipelineLayer *layer, void *user_data)
GLenum gl_target; GLenum gl_target;
if (texture == NULL) if (texture == NULL)
texture = COGL_TEXTURE (ctx->default_gl_texture_2d_tex); texture = ctx->default_gl_texture_2d_tex;
cogl_texture_get_gl_texture (texture, cogl_texture_get_gl_texture (texture,
&gl_texture, &gl_texture,

View File

@ -130,7 +130,7 @@ allocate_with_size (CoglTexture2D *tex_2d,
CoglPixelFormat internal_format; CoglPixelFormat internal_format;
int width = loader->src.sized.width; int width = loader->src.sized.width;
int height = loader->src.sized.height; int height = loader->src.sized.height;
CoglContext *ctx = tex->context; CoglContext *ctx = cogl_texture_get_context (tex);
GLenum gl_intformat; GLenum gl_intformat;
GLenum gl_format; GLenum gl_format;
GLenum gl_type; GLenum gl_type;
@ -267,7 +267,7 @@ allocate_from_egl_image (CoglTexture2D *tex_2d,
GError **error) GError **error)
{ {
CoglTexture *tex = COGL_TEXTURE (tex_2d); CoglTexture *tex = COGL_TEXTURE (tex_2d);
CoglContext *ctx = tex->context; CoglContext *ctx = cogl_texture_get_context (tex);
CoglPixelFormat internal_format = loader->src.egl_image.format; CoglPixelFormat internal_format = loader->src.egl_image.format;
tex_2d->gl_texture = tex_2d->gl_texture =
@ -301,7 +301,7 @@ allocate_custom_egl_image_external (CoglTexture2D *tex_2d,
GError **error) GError **error)
{ {
CoglTexture *tex = COGL_TEXTURE (tex_2d); CoglTexture *tex = COGL_TEXTURE (tex_2d);
CoglContext *ctx = tex->context; CoglContext *ctx = cogl_texture_get_context (tex);
CoglPixelFormat external_format; CoglPixelFormat external_format;
CoglPixelFormat internal_format; CoglPixelFormat internal_format;
@ -356,7 +356,7 @@ cogl_texture_2d_gl_bind_egl_image (CoglTexture2D *tex_2d,
EGLImageKHR image, EGLImageKHR image,
GError **error) GError **error)
{ {
CoglContext *ctx = COGL_TEXTURE (tex_2d)->context; CoglContext *ctx = cogl_texture_get_context (COGL_TEXTURE (tex_2d));
_cogl_bind_gl_texture_transient (GL_TEXTURE_2D, _cogl_bind_gl_texture_transient (GL_TEXTURE_2D,
tex_2d->gl_texture); tex_2d->gl_texture);
@ -376,7 +376,7 @@ cogl_texture_2d_gl_bind_egl_image (CoglTexture2D *tex_2d,
return TRUE; return TRUE;
} }
CoglTexture2D * CoglTexture *
cogl_texture_2d_new_from_egl_image_external (CoglContext *ctx, cogl_texture_2d_new_from_egl_image_external (CoglContext *ctx,
int width, int width,
int height, int height,
@ -404,14 +404,14 @@ cogl_texture_2d_new_from_egl_image_external (CoglContext *ctx,
loader->src.egl_image_external.alloc = alloc; loader->src.egl_image_external.alloc = alloc;
loader->src.egl_image_external.format = internal_format; loader->src.egl_image_external.format = internal_format;
tex_2d = _cogl_texture_2d_create_base (ctx, width, height, tex_2d = COGL_TEXTURE_2D (_cogl_texture_2d_create_base (ctx, width, height,
internal_format, loader); internal_format, loader));
tex_2d->egl_image_external.user_data = user_data; tex_2d->egl_image_external.user_data = user_data;
tex_2d->egl_image_external.destroy = destroy; tex_2d->egl_image_external.destroy = destroy;
return tex_2d; return COGL_TEXTURE (tex_2d);
} }
#endif /* defined (COGL_HAS_EGL_SUPPORT) */ #endif /* defined (COGL_HAS_EGL_SUPPORT) */
@ -420,7 +420,7 @@ _cogl_texture_2d_gl_allocate (CoglTexture *tex,
GError **error) GError **error)
{ {
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex); CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
CoglTextureLoader *loader = tex->loader; CoglTextureLoader *loader = cogl_texture_get_loader (tex);
g_return_val_if_fail (loader, FALSE); g_return_val_if_fail (loader, FALSE);
@ -453,7 +453,7 @@ _cogl_texture_2d_gl_flush_legacy_texobj_filters (CoglTexture *tex,
GLenum mag_filter) GLenum mag_filter)
{ {
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex); CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
CoglContext *ctx = tex->context; CoglContext *ctx = cogl_texture_get_context (tex);
if (min_filter == tex_2d->gl_legacy_texobj_min_filter if (min_filter == tex_2d->gl_legacy_texobj_min_filter
&& mag_filter == tex_2d->gl_legacy_texobj_mag_filter) && mag_filter == tex_2d->gl_legacy_texobj_mag_filter)
@ -485,7 +485,7 @@ _cogl_texture_2d_gl_flush_legacy_texobj_wrap_modes (CoglTexture *tex,
GLenum wrap_mode_t) GLenum wrap_mode_t)
{ {
CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex); CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex);
CoglContext *ctx = tex->context; CoglContext *ctx = cogl_texture_get_context (tex);
/* Only set the wrap mode if it's different from the current value /* Only set the wrap mode if it's different from the current value
to avoid too many GL calls. Texture 2D doesn't make use of the r to avoid too many GL calls. Texture 2D doesn't make use of the r
@ -519,7 +519,7 @@ _cogl_texture_2d_gl_copy_from_framebuffer (CoglTexture2D *tex_2d,
int level) int level)
{ {
CoglTexture *tex = COGL_TEXTURE (tex_2d); CoglTexture *tex = COGL_TEXTURE (tex_2d);
CoglContext *ctx = tex->context; CoglContext *ctx = cogl_texture_get_context (tex);
/* Make sure the current framebuffers are bound, though we don't need to /* Make sure the current framebuffers are bound, though we don't need to
* flush the clip state here since we aren't going to draw to the * flush the clip state here since we aren't going to draw to the
@ -565,7 +565,7 @@ _cogl_texture_2d_gl_copy_from_bitmap (CoglTexture2D *tex_2d,
GError **error) GError **error)
{ {
CoglTexture *tex = COGL_TEXTURE (tex_2d); CoglTexture *tex = COGL_TEXTURE (tex_2d);
CoglContext *ctx = tex->context; CoglContext *ctx = cogl_texture_get_context (tex);
CoglBitmap *upload_bmp; CoglBitmap *upload_bmp;
CoglPixelFormat upload_format; CoglPixelFormat upload_format;
GLenum gl_format; GLenum gl_format;
@ -592,7 +592,7 @@ _cogl_texture_2d_gl_copy_from_bitmap (CoglTexture2D *tex_2d,
&gl_format, &gl_format,
&gl_type); &gl_type);
if (tex->max_level_set < level) if (cogl_texture_get_max_level_set (tex) < level)
cogl_texture_gl_set_max_level (tex, level); cogl_texture_gl_set_max_level (tex, level);
status = ctx->texture_driver->upload_subregion_to_gl (ctx, status = ctx->texture_driver->upload_subregion_to_gl (ctx,
@ -623,9 +623,9 @@ _cogl_texture_2d_gl_get_data (CoglTexture2D *tex_2d,
int rowstride, int rowstride,
uint8_t *data) uint8_t *data)
{ {
CoglContext *ctx = COGL_TEXTURE (tex_2d)->context; CoglContext *ctx = cogl_texture_get_context (COGL_TEXTURE (tex_2d));
uint8_t bpp; uint8_t bpp;
int width = COGL_TEXTURE (tex_2d)->width; int width = cogl_texture_get_width (COGL_TEXTURE (tex_2d));
GLenum gl_format; GLenum gl_format;
GLenum gl_type; GLenum gl_type;

View File

@ -83,7 +83,7 @@ _cogl_texture_gl_flush_legacy_texobj_wrap_modes (CoglTexture *texture,
unsigned int wrap_mode_s, unsigned int wrap_mode_s,
unsigned int wrap_mode_t) unsigned int wrap_mode_t)
{ {
texture->vtable->gl_flush_legacy_texobj_wrap_modes (texture, COGL_TEXTURE_GET_CLASS (texture)->gl_flush_legacy_texobj_wrap_modes (texture,
wrap_mode_s, wrap_mode_s,
wrap_mode_t); wrap_mode_t);
} }
@ -93,8 +93,9 @@ _cogl_texture_gl_flush_legacy_texobj_filters (CoglTexture *texture,
unsigned int min_filter, unsigned int min_filter,
unsigned int mag_filter) unsigned int mag_filter)
{ {
texture->vtable->gl_flush_legacy_texobj_filters (texture, COGL_TEXTURE_GET_CLASS (texture)->gl_flush_legacy_texobj_filters (texture,
min_filter, mag_filter); min_filter,
mag_filter);
} }
/* GL and GLES3 have this by default, but GLES2 does not except via extension. /* GL and GLES3 have this by default, but GLES2 does not except via extension.
@ -110,7 +111,7 @@ void
cogl_texture_gl_set_max_level (CoglTexture *texture, cogl_texture_gl_set_max_level (CoglTexture *texture,
int max_level) int max_level)
{ {
CoglContext *ctx = texture->context; CoglContext *ctx = cogl_texture_get_context (texture);
if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_TEXTURE_MAX_LEVEL)) if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_TEXTURE_MAX_LEVEL))
{ {
@ -119,25 +120,25 @@ cogl_texture_gl_set_max_level (CoglTexture *texture,
cogl_texture_get_gl_texture (texture, &gl_handle, &gl_target); cogl_texture_get_gl_texture (texture, &gl_handle, &gl_target);
texture->max_level_set = max_level; cogl_texture_set_max_level_set (texture, max_level);
_cogl_bind_gl_texture_transient (gl_target, _cogl_bind_gl_texture_transient (gl_target,
gl_handle); gl_handle);
GE( ctx, glTexParameteri (gl_target, GE( ctx, glTexParameteri (gl_target,
GL_TEXTURE_MAX_LEVEL, texture->max_level_set)); GL_TEXTURE_MAX_LEVEL, cogl_texture_get_max_level_set (texture)));
} }
} }
void void
_cogl_texture_gl_generate_mipmaps (CoglTexture *texture) _cogl_texture_gl_generate_mipmaps (CoglTexture *texture)
{ {
CoglContext *ctx = texture->context; CoglContext *ctx = cogl_texture_get_context (texture);
int n_levels = _cogl_texture_get_n_levels (texture); int n_levels = _cogl_texture_get_n_levels (texture);
GLuint gl_handle; GLuint gl_handle;
GLenum gl_target; GLenum gl_target;
if (texture->max_level_set != n_levels - 1) if (cogl_texture_get_max_level_set (texture) != n_levels - 1)
cogl_texture_gl_set_max_level (texture, n_levels - 1); cogl_texture_gl_set_max_level (texture, n_levels - 1);
cogl_texture_get_gl_texture (texture, &gl_handle, &gl_target); cogl_texture_get_gl_texture (texture, &gl_handle, &gl_target);
@ -150,5 +151,5 @@ _cogl_texture_gl_generate_mipmaps (CoglTexture *texture)
GLenum GLenum
_cogl_texture_gl_get_format (CoglTexture *texture) _cogl_texture_gl_get_format (CoglTexture *texture)
{ {
return texture->vtable->get_gl_format (texture); return COGL_TEXTURE_GET_CLASS (texture)->get_gl_format (texture);
} }

View File

@ -250,7 +250,7 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
* glTexImage2D first to assert that the storage for this * glTexImage2D first to assert that the storage for this
* level exists. * level exists.
*/ */
if (texture->max_level_set < level) if (cogl_texture_get_max_level_set (texture) < level)
{ {
ctx->glTexImage2D (gl_target, ctx->glTexImage2D (gl_target,
level, level,

View File

@ -303,7 +303,7 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx,
* glTexImage2D first to assert that the storage for this * glTexImage2D first to assert that the storage for this
* level exists. * level exists.
*/ */
if (texture->max_level_set < level) if (cogl_texture_get_max_level_set (texture) < level)
{ {
ctx->glTexImage2D (gl_target, ctx->glTexImage2D (gl_target,
level, level,

View File

@ -40,7 +40,6 @@
#include <GL/glx.h> #include <GL/glx.h>
#endif #endif
#include "cogl/cogl-object-private.h"
#include "cogl/cogl-texture-private.h" #include "cogl/cogl-texture-private.h"
#include "cogl/winsys/cogl-texture-pixmap-x11.h" #include "cogl/winsys/cogl-texture-pixmap-x11.h"
@ -70,7 +69,7 @@ typedef enum
struct _CoglTexturePixmapX11 struct _CoglTexturePixmapX11
{ {
CoglTexture _parent; CoglTexture parent_instance;
CoglTexturePixmapStereoMode stereo_mode; CoglTexturePixmapStereoMode stereo_mode;
CoglTexturePixmapX11 *left; /* Set only if stereo_mode=RIGHT */ CoglTexturePixmapX11 *left; /* Set only if stereo_mode=RIGHT */
@ -97,3 +96,8 @@ struct _CoglTexturePixmapX11
texture */ texture */
gboolean use_winsys_texture; gboolean use_winsys_texture;
}; };
struct _CoglTexturePixmapX11Class
{
CoglTextureClass parent_class;
};

View File

@ -47,12 +47,10 @@
#include "cogl/cogl-context-private.h" #include "cogl/cogl-context-private.h"
#include "cogl/cogl-display-private.h" #include "cogl/cogl-display-private.h"
#include "cogl/cogl-renderer-private.h" #include "cogl/cogl-renderer-private.h"
#include "cogl/cogl-object-private.h"
#include "cogl/cogl-xlib.h" #include "cogl/cogl-xlib.h"
#include "cogl/cogl-xlib-renderer-private.h" #include "cogl/cogl-xlib-renderer-private.h"
#include "cogl/cogl-x11-renderer-private.h" #include "cogl/cogl-x11-renderer-private.h"
#include "cogl/cogl-private.h" #include "cogl/cogl-private.h"
#include "cogl/cogl-gtype-private.h"
#include "cogl/driver/gl/cogl-texture-gl-private.h" #include "cogl/driver/gl/cogl-texture-gl-private.h"
#include "cogl/winsys/cogl-winsys-private.h" #include "cogl/winsys/cogl-winsys-private.h"
@ -66,17 +64,36 @@
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
static void _cogl_texture_pixmap_x11_free (CoglTexturePixmapX11 *tex_pixmap); G_DEFINE_FINAL_TYPE (CoglTexturePixmapX11, cogl_texture_pixmap_x11, COGL_TYPE_TEXTURE)
COGL_TEXTURE_DEFINE (TexturePixmapX11, texture_pixmap_x11); static const CoglWinsysVtable *
COGL_GTYPE_DEFINE_CLASS (TexturePixmapX11, texture_pixmap_x11); _cogl_texture_pixmap_x11_get_winsys (CoglTexturePixmapX11 *tex_pixmap)
static const CoglTextureVtable cogl_texture_pixmap_x11_vtable;
uint32_t
cogl_texture_pixmap_x11_error_quark (void)
{ {
return g_quark_from_static_string ("cogl-texture-pixmap-error-quark"); /* FIXME: A CoglContext should be reachable from a CoglTexture
* pointer */
_COGL_GET_CONTEXT (ctx, NULL);
return ctx->display->renderer->winsys_vtable;
}
static int
_cogl_xlib_get_damage_base (void)
{
CoglX11Renderer *x11_renderer;
_COGL_GET_CONTEXT (ctxt, -1);
x11_renderer =
(CoglX11Renderer *) _cogl_xlib_renderer_get_data (ctxt->display->renderer);
return x11_renderer->damage_base;
}
static gboolean
cogl_damage_rectangle_is_whole (const CoglDamageRectangle *damage_rect,
unsigned int width,
unsigned int height)
{
return (damage_rect->x1 == 0 && damage_rect->y1 == 0
&& damage_rect->x2 == width && damage_rect->y2 == height);
} }
static void static void
@ -109,25 +126,6 @@ cogl_damage_rectangle_union (CoglDamageRectangle *damage_rect,
} }
} }
static gboolean
cogl_damage_rectangle_is_whole (const CoglDamageRectangle *damage_rect,
unsigned int width,
unsigned int height)
{
return (damage_rect->x1 == 0 && damage_rect->y1 == 0
&& damage_rect->x2 == width && damage_rect->y2 == height);
}
static const CoglWinsysVtable *
_cogl_texture_pixmap_x11_get_winsys (CoglTexturePixmapX11 *tex_pixmap)
{
/* FIXME: A CoglContext should be reachable from a CoglTexture
* pointer */
_COGL_GET_CONTEXT (ctx, NULL);
return ctx->display->renderer->winsys_vtable;
}
static void static void
process_damage_event (CoglTexturePixmapX11 *tex_pixmap, process_damage_event (CoglTexturePixmapX11 *tex_pixmap,
XDamageNotifyEvent *damage_event) XDamageNotifyEvent *damage_event)
@ -176,8 +174,8 @@ process_damage_event (CoglTexturePixmapX11 *tex_pixmap,
need to request the bounding box of the region because we're need to request the bounding box of the region because we're
going to update the whole texture anyway. */ going to update the whole texture anyway. */
if (cogl_damage_rectangle_is_whole (&tex_pixmap->damage_rect, if (cogl_damage_rectangle_is_whole (&tex_pixmap->damage_rect,
tex->width, cogl_texture_get_width (tex),
tex->height)) cogl_texture_get_height (tex)))
{ {
if (handle_mode != DO_NOTHING) if (handle_mode != DO_NOTHING)
XDamageSubtract (display, tex_pixmap->damage, None, None); XDamageSubtract (display, tex_pixmap->damage, None, None);
@ -232,17 +230,6 @@ process_damage_event (CoglTexturePixmapX11 *tex_pixmap,
} }
} }
static int
_cogl_xlib_get_damage_base (void)
{
CoglX11Renderer *x11_renderer;
_COGL_GET_CONTEXT (ctxt, -1);
x11_renderer =
(CoglX11Renderer *) _cogl_xlib_renderer_get_data (ctxt->display->renderer);
return x11_renderer->damage_base;
}
static CoglFilterReturn static CoglFilterReturn
_cogl_texture_pixmap_x11_filter (XEvent *event, void *data) _cogl_texture_pixmap_x11_filter (XEvent *event, void *data)
{ {
@ -293,171 +280,102 @@ set_damage_object_internal (CoglContext *ctx,
tex_pixmap); tex_pixmap);
} }
static CoglTexturePixmapX11 * static void
_cogl_texture_pixmap_x11_new (CoglContext *ctxt, cogl_texture_pixmap_x11_dispose (GObject *object)
uint32_t pixmap,
gboolean automatic_updates,
CoglTexturePixmapStereoMode stereo_mode,
GError **error)
{ {
CoglTexturePixmapX11 *tex_pixmap = g_new (CoglTexturePixmapX11, 1); CoglTexturePixmapX11 *tex_pixmap = COGL_TEXTURE_PIXMAP_X11 (object);
Display *display = cogl_xlib_renderer_get_display (ctxt->display->renderer);
Window pixmap_root_window;
int pixmap_x, pixmap_y;
unsigned int pixmap_width, pixmap_height;
unsigned int pixmap_border_width;
CoglPixelFormat internal_format;
CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
XWindowAttributes window_attributes;
int damage_base;
const CoglWinsysVtable *winsys;
if (!XGetGeometry (display, pixmap, &pixmap_root_window, Display *display;
&pixmap_x, &pixmap_y,
&pixmap_width, &pixmap_height, _COGL_GET_CONTEXT (ctxt, NO_RETVAL);
&pixmap_border_width, &tex_pixmap->depth))
if (tex_pixmap->stereo_mode == COGL_TEXTURE_PIXMAP_RIGHT)
{ {
g_free (tex_pixmap); g_object_unref (tex_pixmap->left);
g_set_error_literal (error, G_OBJECT_CLASS (cogl_texture_pixmap_x11_parent_class)->dispose (object);
COGL_TEXTURE_PIXMAP_X11_ERROR, return;
COGL_TEXTURE_PIXMAP_X11_ERROR_X11,
"Unable to query pixmap size");
return NULL;
} }
/* Note: the detailed pixel layout doesn't matter here, we are just display = cogl_xlib_renderer_get_display (ctxt->display->renderer);
* interested in RGB vs RGBA... */
internal_format = (tex_pixmap->depth >= 32
? COGL_PIXEL_FORMAT_RGBA_8888_PRE
: COGL_PIXEL_FORMAT_RGB_888);
_cogl_texture_init (tex, ctxt, pixmap_width, pixmap_height, set_damage_object_internal (ctxt, tex_pixmap, 0, 0);
internal_format,
NULL, /* no loader */
&cogl_texture_pixmap_x11_vtable);
tex_pixmap->pixmap = pixmap; if (tex_pixmap->image)
tex_pixmap->stereo_mode = stereo_mode; XDestroyImage (tex_pixmap->image);
tex_pixmap->left = NULL;
tex_pixmap->image = NULL;
tex_pixmap->shm_info.shmid = -1;
tex_pixmap->tex = NULL;
tex_pixmap->damage_owned = FALSE;
tex_pixmap->damage = 0;
/* We need a visual to use for shared memory images so we'll query if (tex_pixmap->shm_info.shmid != -1)
it from the pixmap's root window */
if (!XGetWindowAttributes (display, pixmap_root_window, &window_attributes))
{ {
g_free (tex_pixmap); XShmDetach (display, &tex_pixmap->shm_info);
g_set_error_literal (error, shmdt (tex_pixmap->shm_info.shmaddr);
COGL_TEXTURE_PIXMAP_X11_ERROR, shmctl (tex_pixmap->shm_info.shmid, IPC_RMID, 0);
COGL_TEXTURE_PIXMAP_X11_ERROR_X11,
"Unable to query root window attributes");
return NULL;
} }
tex_pixmap->visual = window_attributes.visual; if (tex_pixmap->tex)
g_object_unref (tex_pixmap->tex);
/* If automatic updates are requested and the Xlib connection if (tex_pixmap->winsys)
supports damage events then we'll register a damage object on the
pixmap */
damage_base = _cogl_xlib_get_damage_base ();
if (automatic_updates && damage_base >= 0)
{ {
Damage damage = XDamageCreate (display, const CoglWinsysVtable *winsys =
pixmap, _cogl_texture_pixmap_x11_get_winsys (tex_pixmap);
XDamageReportBoundingBox); winsys->texture_pixmap_x11_free (tex_pixmap);
set_damage_object_internal (ctxt,
tex_pixmap,
damage,
COGL_TEXTURE_PIXMAP_X11_DAMAGE_BOUNDING_BOX);
tex_pixmap->damage_owned = TRUE;
} }
/* Assume the entire pixmap is damaged to begin with */ G_OBJECT_CLASS (cogl_texture_pixmap_x11_parent_class)->dispose (object);
tex_pixmap->damage_rect.x1 = 0; }
tex_pixmap->damage_rect.x2 = pixmap_width;
tex_pixmap->damage_rect.y1 = 0;
tex_pixmap->damage_rect.y2 = pixmap_height;
winsys = _cogl_texture_pixmap_x11_get_winsys (tex_pixmap); static void
if (winsys->texture_pixmap_x11_create) _cogl_texture_pixmap_x11_set_use_winsys_texture (CoglTexturePixmapX11 *tex_pixmap,
gboolean new_value)
{
if (tex_pixmap->use_winsys_texture != new_value)
{ {
tex_pixmap->use_winsys_texture = /* Notify cogl-pipeline.c that the texture's underlying GL texture
winsys->texture_pixmap_x11_create (tex_pixmap); * storage is changing so it knows it may need to bind a new texture
* if the CoglTexture is reused with the same texture unit. */
_cogl_pipeline_texture_storage_change_notify (COGL_TEXTURE (tex_pixmap));
tex_pixmap->use_winsys_texture = new_value;
} }
else
tex_pixmap->use_winsys_texture = FALSE;
if (!tex_pixmap->use_winsys_texture)
tex_pixmap->winsys = NULL;
_cogl_texture_set_allocated (tex, internal_format,
pixmap_width, pixmap_height);
return _cogl_texture_pixmap_x11_object_new (tex_pixmap);
} }
CoglTexturePixmapX11 * static CoglTexture *
cogl_texture_pixmap_x11_new (CoglContext *ctxt, create_fallback_texture (CoglContext *ctx,
uint32_t pixmap, int width,
gboolean automatic_updates, int height,
GError **error) CoglPixelFormat internal_format)
{ {
return _cogl_texture_pixmap_x11_new (ctxt, pixmap, CoglTexture *tex;
automatic_updates, COGL_TEXTURE_PIXMAP_MONO, GError *skip_error = NULL;
error);
/* First try creating a fast-path non-sliced texture */
tex = cogl_texture_2d_new_with_size (ctx, width, height);
_cogl_texture_set_internal_format (tex, internal_format);
/* TODO: instead of allocating storage here it would be better
* if we had some api that let us just check that the size is
* supported by the hardware so storage could be allocated
* lazily when uploading data. */
if (!cogl_texture_allocate (tex, &skip_error))
{
g_error_free (skip_error);
g_object_unref (tex);
tex = NULL;
}
if (!tex)
{
tex =
cogl_texture_2d_sliced_new_with_size (ctx,
width,
height,
COGL_TEXTURE_MAX_WASTE);
_cogl_texture_set_internal_format (tex, internal_format);
}
return tex;
} }
CoglTexturePixmapX11 *
cogl_texture_pixmap_x11_new_left (CoglContext *ctxt,
uint32_t pixmap,
gboolean automatic_updates,
GError **error)
{
return _cogl_texture_pixmap_x11_new (ctxt, pixmap,
automatic_updates, COGL_TEXTURE_PIXMAP_LEFT,
error);
}
CoglTexturePixmapX11 *
cogl_texture_pixmap_x11_new_right (CoglTexturePixmapX11 *tfp_left)
{
CoglTexture *texture_left = COGL_TEXTURE (tfp_left);
CoglTexturePixmapX11 *tfp_right;
CoglPixelFormat internal_format;
g_return_val_if_fail (tfp_left->stereo_mode == COGL_TEXTURE_PIXMAP_LEFT, NULL);
tfp_right = g_new0 (CoglTexturePixmapX11, 1);
tfp_right->stereo_mode = COGL_TEXTURE_PIXMAP_RIGHT;
tfp_right->left = cogl_object_ref (tfp_left);
internal_format = (tfp_left->depth >= 32
? COGL_PIXEL_FORMAT_RGBA_8888_PRE
: COGL_PIXEL_FORMAT_RGB_888);
_cogl_texture_init (COGL_TEXTURE (tfp_right),
texture_left->context,
texture_left->width,
texture_left->height,
internal_format,
NULL, /* no loader */
&cogl_texture_pixmap_x11_vtable);
_cogl_texture_set_allocated (COGL_TEXTURE (tfp_right), internal_format,
texture_left->width, texture_left->height);
return _cogl_texture_pixmap_x11_object_new (tfp_right);
}
static gboolean
_cogl_texture_pixmap_x11_allocate (CoglTexture *tex,
GError **error)
{
return TRUE;
}
/* Tries to allocate enough shared mem to handle a full size /* Tries to allocate enough shared mem to handle a full size
* update size of the X Pixmap. */ * update size of the X Pixmap. */
@ -491,8 +409,8 @@ try_alloc_shm (CoglTexturePixmapX11 *tex_pixmap)
ZPixmap, ZPixmap,
NULL, NULL,
NULL, /* shminfo, */ NULL, /* shminfo, */
tex->width, cogl_texture_get_width (tex),
tex->height); cogl_texture_get_height (tex));
if (!dummy_image) if (!dummy_image)
goto failed_image_create; goto failed_image_create;
@ -532,80 +450,6 @@ try_alloc_shm (CoglTexturePixmapX11 *tex_pixmap)
tex_pixmap->shm_info.shmid = -1; tex_pixmap->shm_info.shmid = -1;
} }
void
cogl_texture_pixmap_x11_update_area (CoglTexturePixmapX11 *tex_pixmap,
int x,
int y,
int width,
int height)
{
/* We'll queue the update for both the GLX texture and the regular
texture because we can't determine which will be needed until we
actually render something */
if (tex_pixmap->stereo_mode == COGL_TEXTURE_PIXMAP_RIGHT)
tex_pixmap = tex_pixmap->left;
if (tex_pixmap->winsys)
{
const CoglWinsysVtable *winsys;
winsys = _cogl_texture_pixmap_x11_get_winsys (tex_pixmap);
winsys->texture_pixmap_x11_damage_notify (tex_pixmap);
}
cogl_damage_rectangle_union (&tex_pixmap->damage_rect,
x, y, width, height);
}
gboolean
cogl_texture_pixmap_x11_is_using_tfp_extension (CoglTexturePixmapX11 *tex_pixmap)
{
if (tex_pixmap->stereo_mode == COGL_TEXTURE_PIXMAP_RIGHT)
tex_pixmap = tex_pixmap->left;
return !!tex_pixmap->winsys;
}
static CoglTexture *
create_fallback_texture (CoglContext *ctx,
int width,
int height,
CoglPixelFormat internal_format)
{
CoglTexture *tex;
GError *skip_error = NULL;
/* First try creating a fast-path non-sliced texture */
tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, width, height));
_cogl_texture_set_internal_format (tex, internal_format);
/* TODO: instead of allocating storage here it would be better
* if we had some api that let us just check that the size is
* supported by the hardware so storage could be allocated
* lazily when uploading data. */
if (!cogl_texture_allocate (tex, &skip_error))
{
g_error_free (skip_error);
cogl_object_unref (tex);
tex = NULL;
}
if (!tex)
{
CoglTexture2DSliced *tex_2ds =
cogl_texture_2d_sliced_new_with_size (ctx,
width,
height,
COGL_TEXTURE_MAX_WASTE);
tex = COGL_TEXTURE (tex_2ds);
_cogl_texture_set_internal_format (tex, internal_format);
}
return tex;
}
static void static void
_cogl_texture_pixmap_x11_update_image_texture (CoglTexturePixmapX11 *tex_pixmap) _cogl_texture_pixmap_x11_update_image_texture (CoglTexturePixmapX11 *tex_pixmap)
{ {
@ -646,8 +490,8 @@ _cogl_texture_pixmap_x11_update_image_texture (CoglTexturePixmapX11 *tex_pixmap)
: COGL_PIXEL_FORMAT_RGB_888); : COGL_PIXEL_FORMAT_RGB_888);
tex_pixmap->tex = create_fallback_texture (ctx, tex_pixmap->tex = create_fallback_texture (ctx,
tex->width, cogl_texture_get_width (tex),
tex->height, cogl_texture_get_height (tex),
texture_format); texture_format);
} }
@ -671,7 +515,8 @@ _cogl_texture_pixmap_x11_update_image_texture (CoglTexturePixmapX11 *tex_pixmap)
tex_pixmap->image = XGetImage (display, tex_pixmap->image = XGetImage (display,
tex_pixmap->pixmap, tex_pixmap->pixmap,
0, 0, 0, 0,
tex->width, tex->height, cogl_texture_get_width (tex),
cogl_texture_get_height (tex),
AllPlanes, ZPixmap); AllPlanes, ZPixmap);
image = tex_pixmap->image; image = tex_pixmap->image;
src_x = x; src_x = x;
@ -747,21 +592,6 @@ _cogl_texture_pixmap_x11_update_image_texture (CoglTexturePixmapX11 *tex_pixmap)
memset (&tex_pixmap->damage_rect, 0, sizeof (CoglDamageRectangle)); memset (&tex_pixmap->damage_rect, 0, sizeof (CoglDamageRectangle));
} }
static void
_cogl_texture_pixmap_x11_set_use_winsys_texture (CoglTexturePixmapX11 *tex_pixmap,
gboolean new_value)
{
if (tex_pixmap->use_winsys_texture != new_value)
{
/* Notify cogl-pipeline.c that the texture's underlying GL texture
* storage is changing so it knows it may need to bind a new texture
* if the CoglTexture is reused with the same texture unit. */
_cogl_pipeline_texture_storage_change_notify (COGL_TEXTURE (tex_pixmap));
tex_pixmap->use_winsys_texture = new_value;
}
}
static void static void
_cogl_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap, _cogl_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
gboolean needs_mipmap) gboolean needs_mipmap)
@ -831,6 +661,13 @@ _cogl_texture_pixmap_x11_get_texture (CoglTexturePixmapX11 *tex_pixmap)
return NULL; return NULL;
} }
static gboolean
_cogl_texture_pixmap_x11_allocate (CoglTexture *tex,
GError **error)
{
return TRUE;
}
static gboolean static gboolean
_cogl_texture_pixmap_x11_set_region (CoglTexture *tex, _cogl_texture_pixmap_x11_set_region (CoglTexture *tex,
int src_x, int src_x,
@ -866,6 +703,15 @@ _cogl_texture_pixmap_x11_get_data (CoglTexture *tex,
return cogl_texture_get_data (child_tex, format, rowstride, data); return cogl_texture_get_data (child_tex, format, rowstride, data);
} }
static int
_cogl_texture_pixmap_x11_get_max_waste (CoglTexture *tex)
{
CoglTexturePixmapX11 *tex_pixmap = COGL_TEXTURE_PIXMAP_X11 (tex);
CoglTexture *child_tex = _cogl_texture_pixmap_x11_get_texture (tex_pixmap);
return cogl_texture_get_max_waste (child_tex);
}
static void static void
_cogl_texture_pixmap_x11_foreach_sub_texture_in_region _cogl_texture_pixmap_x11_foreach_sub_texture_in_region
(CoglTexture *tex, (CoglTexture *tex,
@ -880,7 +726,7 @@ _cogl_texture_pixmap_x11_foreach_sub_texture_in_region
CoglTexture *child_tex = _cogl_texture_pixmap_x11_get_texture (tex_pixmap); CoglTexture *child_tex = _cogl_texture_pixmap_x11_get_texture (tex_pixmap);
/* Forward on to the child texture */ /* Forward on to the child texture */
cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (child_tex), cogl_meta_texture_foreach_in_region (child_tex,
virtual_tx_1, virtual_tx_1,
virtual_ty_1, virtual_ty_1,
virtual_tx_2, virtual_tx_2,
@ -891,15 +737,6 @@ _cogl_texture_pixmap_x11_foreach_sub_texture_in_region
user_data); user_data);
} }
static int
_cogl_texture_pixmap_x11_get_max_waste (CoglTexture *tex)
{
CoglTexturePixmapX11 *tex_pixmap = COGL_TEXTURE_PIXMAP_X11 (tex);
CoglTexture *child_tex = _cogl_texture_pixmap_x11_get_texture (tex_pixmap);
return cogl_texture_get_max_waste (child_tex);
}
static gboolean static gboolean
_cogl_texture_pixmap_x11_is_sliced (CoglTexture *tex) _cogl_texture_pixmap_x11_is_sliced (CoglTexture *tex)
{ {
@ -1027,70 +864,234 @@ _cogl_texture_pixmap_x11_get_gl_format (CoglTexture *tex)
} }
static void static void
_cogl_texture_pixmap_x11_free (CoglTexturePixmapX11 *tex_pixmap) cogl_texture_pixmap_x11_class_init (CoglTexturePixmapX11Class *klass)
{ {
Display *display; GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
CoglTextureClass *texture_class = COGL_TEXTURE_CLASS (klass);
_COGL_GET_CONTEXT (ctxt, NO_RETVAL); gobject_class->dispose = cogl_texture_pixmap_x11_dispose;
texture_class->allocate = _cogl_texture_pixmap_x11_allocate;
texture_class->set_region = _cogl_texture_pixmap_x11_set_region;
texture_class->get_data = _cogl_texture_pixmap_x11_get_data;
texture_class->get_max_waste = _cogl_texture_pixmap_x11_get_max_waste;
texture_class->foreach_sub_texture_in_region = _cogl_texture_pixmap_x11_foreach_sub_texture_in_region;
texture_class->is_sliced = _cogl_texture_pixmap_x11_is_sliced;
texture_class->can_hardware_repeat = _cogl_texture_pixmap_x11_can_hardware_repeat;
texture_class->transform_coords_to_gl = _cogl_texture_pixmap_x11_transform_coords_to_gl;
texture_class->transform_quad_coords_to_gl = _cogl_texture_pixmap_x11_transform_quad_coords_to_gl;
texture_class->get_gl_texture = _cogl_texture_pixmap_x11_get_gl_texture;
texture_class->gl_flush_legacy_texobj_filters = _cogl_texture_pixmap_x11_gl_flush_legacy_texobj_filters;
texture_class->pre_paint = _cogl_texture_pixmap_x11_pre_paint;
texture_class->ensure_non_quad_rendering = _cogl_texture_pixmap_x11_ensure_non_quad_rendering;
texture_class->gl_flush_legacy_texobj_wrap_modes = _cogl_texture_pixmap_x11_gl_flush_legacy_texobj_wrap_modes;
texture_class->get_format = _cogl_texture_pixmap_x11_get_format;
texture_class->get_gl_format = _cogl_texture_pixmap_x11_get_gl_format;
}
static void
cogl_texture_pixmap_x11_init (CoglTexturePixmapX11 *self)
{
CoglTexture *texture = COGL_TEXTURE (self);
texture->is_primitive = FALSE;
}
uint32_t
cogl_texture_pixmap_x11_error_quark (void)
{
return g_quark_from_static_string ("cogl-texture-pixmap-error-quark");
}
static CoglTexture *
_cogl_texture_pixmap_x11_new (CoglContext *ctxt,
uint32_t pixmap,
gboolean automatic_updates,
CoglTexturePixmapStereoMode stereo_mode,
GError **error)
{
CoglTexturePixmapX11 *tex_pixmap = g_object_new (COGL_TYPE_TEXTURE_PIXMAP_X11, NULL);
Display *display = cogl_xlib_renderer_get_display (ctxt->display->renderer);
Window pixmap_root_window;
int pixmap_x, pixmap_y;
unsigned int pixmap_width, pixmap_height;
unsigned int pixmap_border_width;
CoglPixelFormat internal_format;
CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
XWindowAttributes window_attributes;
int damage_base;
const CoglWinsysVtable *winsys;
if (!XGetGeometry (display, pixmap, &pixmap_root_window,
&pixmap_x, &pixmap_y,
&pixmap_width, &pixmap_height,
&pixmap_border_width, &tex_pixmap->depth))
{
g_free (tex_pixmap);
g_set_error_literal (error,
COGL_TEXTURE_PIXMAP_X11_ERROR,
COGL_TEXTURE_PIXMAP_X11_ERROR_X11,
"Unable to query pixmap size");
return NULL;
}
/* Note: the detailed pixel layout doesn't matter here, we are just
* interested in RGB vs RGBA... */
internal_format = (tex_pixmap->depth >= 32
? COGL_PIXEL_FORMAT_RGBA_8888_PRE
: COGL_PIXEL_FORMAT_RGB_888);
_cogl_texture_init (tex, ctxt, pixmap_width, pixmap_height,
internal_format,
NULL);
tex_pixmap->pixmap = pixmap;
tex_pixmap->stereo_mode = stereo_mode;
tex_pixmap->left = NULL;
tex_pixmap->image = NULL;
tex_pixmap->shm_info.shmid = -1;
tex_pixmap->tex = NULL;
tex_pixmap->damage_owned = FALSE;
tex_pixmap->damage = 0;
/* We need a visual to use for shared memory images so we'll query
it from the pixmap's root window */
if (!XGetWindowAttributes (display, pixmap_root_window, &window_attributes))
{
g_free (tex_pixmap);
g_set_error_literal (error,
COGL_TEXTURE_PIXMAP_X11_ERROR,
COGL_TEXTURE_PIXMAP_X11_ERROR_X11,
"Unable to query root window attributes");
return NULL;
}
tex_pixmap->visual = window_attributes.visual;
/* If automatic updates are requested and the Xlib connection
supports damage events then we'll register a damage object on the
pixmap */
damage_base = _cogl_xlib_get_damage_base ();
if (automatic_updates && damage_base >= 0)
{
Damage damage = XDamageCreate (display,
pixmap,
XDamageReportBoundingBox);
set_damage_object_internal (ctxt,
tex_pixmap,
damage,
COGL_TEXTURE_PIXMAP_X11_DAMAGE_BOUNDING_BOX);
tex_pixmap->damage_owned = TRUE;
}
/* Assume the entire pixmap is damaged to begin with */
tex_pixmap->damage_rect.x1 = 0;
tex_pixmap->damage_rect.x2 = pixmap_width;
tex_pixmap->damage_rect.y1 = 0;
tex_pixmap->damage_rect.y2 = pixmap_height;
winsys = _cogl_texture_pixmap_x11_get_winsys (tex_pixmap);
if (winsys->texture_pixmap_x11_create)
{
tex_pixmap->use_winsys_texture =
winsys->texture_pixmap_x11_create (tex_pixmap);
}
else
tex_pixmap->use_winsys_texture = FALSE;
if (!tex_pixmap->use_winsys_texture)
tex_pixmap->winsys = NULL;
_cogl_texture_set_allocated (tex, internal_format,
pixmap_width, pixmap_height);
return COGL_TEXTURE (tex_pixmap);
}
CoglTexture *
cogl_texture_pixmap_x11_new (CoglContext *ctxt,
uint32_t pixmap,
gboolean automatic_updates,
GError **error)
{
return _cogl_texture_pixmap_x11_new (ctxt, pixmap,
automatic_updates, COGL_TEXTURE_PIXMAP_MONO,
error);
}
CoglTexture *
cogl_texture_pixmap_x11_new_left (CoglContext *ctxt,
uint32_t pixmap,
gboolean automatic_updates,
GError **error)
{
return _cogl_texture_pixmap_x11_new (ctxt, pixmap,
automatic_updates, COGL_TEXTURE_PIXMAP_LEFT,
error);
}
CoglTexture *
cogl_texture_pixmap_x11_new_right (CoglTexturePixmapX11 *tfp_left)
{
CoglTexture *texture_left = COGL_TEXTURE (tfp_left);
CoglTexturePixmapX11 *tfp_right;
CoglPixelFormat internal_format;
g_return_val_if_fail (tfp_left->stereo_mode == COGL_TEXTURE_PIXMAP_LEFT, NULL);
tfp_right = g_object_new (COGL_TYPE_TEXTURE_PIXMAP_X11, NULL);
tfp_right->stereo_mode = COGL_TEXTURE_PIXMAP_RIGHT;
tfp_right->left = g_object_ref (tfp_left);
internal_format = (tfp_left->depth >= 32
? COGL_PIXEL_FORMAT_RGBA_8888_PRE
: COGL_PIXEL_FORMAT_RGB_888);
_cogl_texture_init (COGL_TEXTURE (tfp_right),
cogl_texture_get_context (texture_left),
cogl_texture_get_width (texture_left),
cogl_texture_get_height (texture_left),
internal_format,
NULL);
_cogl_texture_set_allocated (COGL_TEXTURE (tfp_right), internal_format,
cogl_texture_get_width (texture_left),
cogl_texture_get_height (texture_left));
return COGL_TEXTURE (tfp_right);
}
void
cogl_texture_pixmap_x11_update_area (CoglTexturePixmapX11 *tex_pixmap,
int x,
int y,
int width,
int height)
{
/* We'll queue the update for both the GLX texture and the regular
texture because we can't determine which will be needed until we
actually render something */
if (tex_pixmap->stereo_mode == COGL_TEXTURE_PIXMAP_RIGHT) if (tex_pixmap->stereo_mode == COGL_TEXTURE_PIXMAP_RIGHT)
{ tex_pixmap = tex_pixmap->left;
cogl_object_unref (tex_pixmap->left);
/* Chain up */
_cogl_texture_free (COGL_TEXTURE (tex_pixmap));
return;
}
display = cogl_xlib_renderer_get_display (ctxt->display->renderer);
set_damage_object_internal (ctxt, tex_pixmap, 0, 0);
if (tex_pixmap->image)
XDestroyImage (tex_pixmap->image);
if (tex_pixmap->shm_info.shmid != -1)
{
XShmDetach (display, &tex_pixmap->shm_info);
shmdt (tex_pixmap->shm_info.shmaddr);
shmctl (tex_pixmap->shm_info.shmid, IPC_RMID, 0);
}
if (tex_pixmap->tex)
cogl_object_unref (tex_pixmap->tex);
if (tex_pixmap->winsys) if (tex_pixmap->winsys)
{ {
const CoglWinsysVtable *winsys = const CoglWinsysVtable *winsys;
_cogl_texture_pixmap_x11_get_winsys (tex_pixmap); winsys = _cogl_texture_pixmap_x11_get_winsys (tex_pixmap);
winsys->texture_pixmap_x11_free (tex_pixmap); winsys->texture_pixmap_x11_damage_notify (tex_pixmap);
} }
/* Chain up */ cogl_damage_rectangle_union (&tex_pixmap->damage_rect,
_cogl_texture_free (COGL_TEXTURE (tex_pixmap)); x, y, width, height);
}
gboolean
cogl_texture_pixmap_x11_is_using_tfp_extension (CoglTexturePixmapX11 *tex_pixmap)
{
if (tex_pixmap->stereo_mode == COGL_TEXTURE_PIXMAP_RIGHT)
tex_pixmap = tex_pixmap->left;
return !!tex_pixmap->winsys;
} }
static const CoglTextureVtable
cogl_texture_pixmap_x11_vtable =
{
FALSE, /* not primitive */
_cogl_texture_pixmap_x11_allocate,
_cogl_texture_pixmap_x11_set_region,
NULL, /* is_get_data_supported */
_cogl_texture_pixmap_x11_get_data,
_cogl_texture_pixmap_x11_foreach_sub_texture_in_region,
_cogl_texture_pixmap_x11_get_max_waste,
_cogl_texture_pixmap_x11_is_sliced,
_cogl_texture_pixmap_x11_can_hardware_repeat,
_cogl_texture_pixmap_x11_transform_coords_to_gl,
_cogl_texture_pixmap_x11_transform_quad_coords_to_gl,
_cogl_texture_pixmap_x11_get_gl_texture,
_cogl_texture_pixmap_x11_gl_flush_legacy_texobj_filters,
_cogl_texture_pixmap_x11_pre_paint,
_cogl_texture_pixmap_x11_ensure_non_quad_rendering,
_cogl_texture_pixmap_x11_gl_flush_legacy_texobj_wrap_modes,
_cogl_texture_pixmap_x11_get_format,
_cogl_texture_pixmap_x11_get_gl_format,
NULL /* set_auto_mipmap */
};

View File

@ -54,26 +54,30 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/** /**
* SECTION:cogl-texture-pixmap-x11 * CoglTexturePixmapX11:
* @short_description: Functions for creating and manipulating 2D meta *
* Functions for creating and manipulating 2D meta
* textures derived from X11 pixmaps. * textures derived from X11 pixmaps.
* *
* These functions allow high-level meta textures (See the * These functions allow high-level meta textures (See the
* #CoglMetaTexture interface) that derive their contents from an X11 * #CoglMetaTexture interface) that derive their contents from an X11
* pixmap. * pixmap.
*/ */
#define COGL_TYPE_TEXTURE_PIXMAP_X11 (cogl_texture_pixmap_x11_get_type ())
#define COGL_TEXTURE_PIXMAP_X11(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COGL_TYPE_TEXTURE_PIXMAP_X11, CoglTexturePixmapX11))
#define COGL_TEXTURE_PIXMAP_X11_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COGL_TYPE_TEXTURE_PIXMAP_X11, CoglTexturePixmapX11 const))
#define COGL_TEXTURE_PIXMAP_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), COGL_TYPE_TEXTURE_PIXMAP_X11, CoglTexturePixmapX11Class))
#define COGL_IS_TEXTURE_PIXMAP_X11(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COGL_TYPE_TEXTURE_PIXMAP_X11))
#define COGL_IS_TEXTURE_PIXMAP_X11_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), COGL_TYPE_TEXTURE_PIXMAP_X11))
#define COGL_TEXTURE_PIXMAP_X11_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), COGL_TYPE_TEXTURE_PIXMAP_X11, CoglTexturePixmapX11Class))
typedef struct _CoglTexturePixmapX11Class CoglTexturePixmapX11Class;
typedef struct _CoglTexturePixmapX11 CoglTexturePixmapX11; typedef struct _CoglTexturePixmapX11 CoglTexturePixmapX11;
#define COGL_TEXTURE_PIXMAP_X11(X) ((CoglTexturePixmapX11 *)X) G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglTexturePixmapX11, g_object_unref)
/**
* cogl_texture_pixmap_x11_get_gtype:
*
* Returns: a #GType that can be used with the GLib type system.
*/
COGL_EXPORT COGL_EXPORT
GType cogl_texture_pixmap_x11_get_gtype (void); GType cogl_texture_pixmap_x11_get_type (void) G_GNUC_CONST;
typedef enum typedef enum
{ {
@ -120,7 +124,7 @@ uint32_t cogl_texture_pixmap_x11_error_quark (void);
* *
* Return value: a new #CoglTexturePixmapX11 instance * Return value: a new #CoglTexturePixmapX11 instance
*/ */
COGL_EXPORT CoglTexturePixmapX11 * COGL_EXPORT CoglTexture *
cogl_texture_pixmap_x11_new (CoglContext *context, cogl_texture_pixmap_x11_new (CoglContext *context,
uint32_t pixmap, uint32_t pixmap,
gboolean automatic_updates, gboolean automatic_updates,
@ -156,7 +160,7 @@ cogl_texture_pixmap_x11_new (CoglContext *context,
* *
* Return value: a new #CoglTexturePixmapX11 instance * Return value: a new #CoglTexturePixmapX11 instance
*/ */
COGL_EXPORT CoglTexturePixmapX11 * COGL_EXPORT CoglTexture *
cogl_texture_pixmap_x11_new_left (CoglContext *context, cogl_texture_pixmap_x11_new_left (CoglContext *context,
uint32_t pixmap, uint32_t pixmap,
gboolean automatic_updates, gboolean automatic_updates,
@ -173,7 +177,7 @@ cogl_texture_pixmap_x11_new_left (CoglContext *context,
* *
* Return value: a new #CoglTexturePixmapX11 instance * Return value: a new #CoglTexturePixmapX11 instance
*/ */
COGL_EXPORT CoglTexturePixmapX11 * COGL_EXPORT CoglTexture *
cogl_texture_pixmap_x11_new_right (CoglTexturePixmapX11 *left_texture); cogl_texture_pixmap_x11_new_right (CoglTexturePixmapX11 *left_texture);
/** /**
@ -211,18 +215,6 @@ cogl_texture_pixmap_x11_update_area (CoglTexturePixmapX11 *texture,
COGL_EXPORT gboolean COGL_EXPORT gboolean
cogl_texture_pixmap_x11_is_using_tfp_extension (CoglTexturePixmapX11 *texture); cogl_texture_pixmap_x11_is_using_tfp_extension (CoglTexturePixmapX11 *texture);
/**
* cogl_is_texture_pixmap_x11:
* @object: A pointer to a #CoglObject
*
* Checks whether @object points to a #CoglTexturePixmapX11 instance.
*
* Return value: %TRUE if the object is a #CoglTexturePixmapX11, and
* %FALSE otherwise
*/
COGL_EXPORT gboolean
cogl_is_texture_pixmap_x11 (void *object);
G_END_DECLS G_END_DECLS
/* The gobject introspection scanner seems to parse public headers in /* The gobject introspection scanner seems to parse public headers in

View File

@ -455,7 +455,7 @@ static gboolean
_cogl_winsys_texture_pixmap_x11_create (CoglTexturePixmapX11 *tex_pixmap) _cogl_winsys_texture_pixmap_x11_create (CoglTexturePixmapX11 *tex_pixmap)
{ {
CoglTexture *tex = COGL_TEXTURE (tex_pixmap); CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
CoglContext *ctx = tex->context; CoglContext *ctx = cogl_texture_get_context (tex);
CoglTexturePixmapEGL *egl_tex_pixmap; CoglTexturePixmapEGL *egl_tex_pixmap;
EGLint attribs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; EGLint attribs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE};
CoglPixelFormat texture_format; CoglPixelFormat texture_format;
@ -489,14 +489,14 @@ _cogl_winsys_texture_pixmap_x11_create (CoglTexturePixmapX11 *tex_pixmap)
COGL_PIXEL_FORMAT_RGBA_8888_PRE : COGL_PIXEL_FORMAT_RGBA_8888_PRE :
COGL_PIXEL_FORMAT_RGB_888); COGL_PIXEL_FORMAT_RGB_888);
egl_tex_pixmap->texture = COGL_TEXTURE ( egl_tex_pixmap->texture =
cogl_egl_texture_2d_new_from_image (ctx, cogl_egl_texture_2d_new_from_image (ctx,
tex->width, cogl_texture_get_width (tex),
tex->height, cogl_texture_get_height (tex),
texture_format, texture_format,
egl_tex_pixmap->image, egl_tex_pixmap->image,
COGL_EGL_IMAGE_FLAG_NONE, COGL_EGL_IMAGE_FLAG_NONE,
NULL)); NULL);
/* The image is initially bound as part of the creation */ /* The image is initially bound as part of the creation */
egl_tex_pixmap->bind_tex_image_queued = FALSE; egl_tex_pixmap->bind_tex_image_queued = FALSE;
@ -521,7 +521,7 @@ _cogl_winsys_texture_pixmap_x11_free (CoglTexturePixmapX11 *tex_pixmap)
egl_tex_pixmap = tex_pixmap->winsys; egl_tex_pixmap = tex_pixmap->winsys;
if (egl_tex_pixmap->texture) if (egl_tex_pixmap->texture)
cogl_object_unref (egl_tex_pixmap->texture); g_object_unref (egl_tex_pixmap->texture);
if (egl_tex_pixmap->image != EGL_NO_IMAGE_KHR) if (egl_tex_pixmap->image != EGL_NO_IMAGE_KHR)
_cogl_egl_destroy_image (ctx, egl_tex_pixmap->image); _cogl_egl_destroy_image (ctx, egl_tex_pixmap->image);

View File

@ -1129,7 +1129,7 @@ static gboolean
_cogl_winsys_texture_pixmap_x11_create (CoglTexturePixmapX11 *tex_pixmap) _cogl_winsys_texture_pixmap_x11_create (CoglTexturePixmapX11 *tex_pixmap)
{ {
CoglTexturePixmapGLX *glx_tex_pixmap; CoglTexturePixmapGLX *glx_tex_pixmap;
CoglContext *ctx = COGL_TEXTURE (tex_pixmap)->context; CoglContext *ctx = cogl_texture_get_context (COGL_TEXTURE (tex_pixmap));
if (!_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_TEXTURE_FROM_PIXMAP)) if (!_cogl_winsys_has_feature (COGL_WINSYS_FEATURE_TEXTURE_FROM_PIXMAP))
{ {
@ -1221,13 +1221,14 @@ _cogl_winsys_texture_pixmap_x11_free (CoglTexturePixmapX11 *tex_pixmap)
glx_tex_pixmap = tex_pixmap->winsys; glx_tex_pixmap = tex_pixmap->winsys;
free_glx_pixmap (COGL_TEXTURE (tex_pixmap)->context, glx_tex_pixmap); free_glx_pixmap (cogl_texture_get_context (COGL_TEXTURE (tex_pixmap)),
glx_tex_pixmap);
if (glx_tex_pixmap->left.glx_tex) if (glx_tex_pixmap->left.glx_tex)
cogl_object_unref (glx_tex_pixmap->left.glx_tex); g_object_unref (glx_tex_pixmap->left.glx_tex);
if (glx_tex_pixmap->right.glx_tex) if (glx_tex_pixmap->right.glx_tex)
cogl_object_unref (glx_tex_pixmap->right.glx_tex); g_object_unref (glx_tex_pixmap->right.glx_tex);
tex_pixmap->winsys = NULL; tex_pixmap->winsys = NULL;
g_free (glx_tex_pixmap); g_free (glx_tex_pixmap);
@ -1239,7 +1240,7 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
gboolean needs_mipmap) gboolean needs_mipmap)
{ {
CoglTexture *tex = COGL_TEXTURE (tex_pixmap); CoglTexture *tex = COGL_TEXTURE (tex_pixmap);
CoglContext *ctx = COGL_TEXTURE (tex_pixmap)->context; CoglContext *ctx = cogl_texture_get_context (tex);
CoglTexturePixmapGLX *glx_tex_pixmap = tex_pixmap->winsys; CoglTexturePixmapGLX *glx_tex_pixmap = tex_pixmap->winsys;
CoglPixmapTextureEyeGLX *texture_info; CoglPixmapTextureEyeGLX *texture_info;
int buffer; int buffer;
@ -1272,8 +1273,10 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
COGL_PIXEL_FORMAT_RGBA_8888_PRE : COGL_PIXEL_FORMAT_RGBA_8888_PRE :
COGL_PIXEL_FORMAT_RGB_888); COGL_PIXEL_FORMAT_RGB_888);
texture_info->glx_tex = COGL_TEXTURE ( texture_info->glx_tex =
cogl_texture_2d_new_with_size (ctx, tex->width, tex->height)); cogl_texture_2d_new_with_size (ctx,
cogl_texture_get_width (tex),
cogl_texture_get_height (tex));
_cogl_texture_set_internal_format (tex, texture_format); _cogl_texture_set_internal_format (tex, texture_format);
@ -1314,7 +1317,7 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap,
"with mipmap support failed", tex_pixmap); "with mipmap support failed", tex_pixmap);
if (texture_info->glx_tex) if (texture_info->glx_tex)
cogl_object_unref (texture_info->glx_tex); g_object_unref (texture_info->glx_tex);
return FALSE; return FALSE;
} }

View File

@ -190,7 +190,7 @@ load_from_current_xcursor_image (MetaCursorSpriteXcursor *sprite_xcursor)
CoglPixelFormat cogl_format; CoglPixelFormat cogl_format;
ClutterBackend *clutter_backend; ClutterBackend *clutter_backend;
CoglContext *cogl_context; CoglContext *cogl_context;
CoglTexture2D *texture; CoglTexture *texture;
GError *error = NULL; GError *error = NULL;
int hotspot_x, hotspot_y; int hotspot_x, hotspot_y;
@ -234,10 +234,10 @@ load_from_current_xcursor_image (MetaCursorSpriteXcursor *sprite_xcursor)
hotspot_y = xc_image->yhot; hotspot_y = xc_image->yhot;
} }
meta_cursor_sprite_set_texture (sprite, meta_cursor_sprite_set_texture (sprite,
COGL_TEXTURE (texture), texture,
hotspot_x, hotspot_y); hotspot_x, hotspot_y);
g_clear_pointer (&texture, cogl_object_unref); g_clear_object (&texture);
} }
void void

View File

@ -96,7 +96,7 @@ meta_cursor_sprite_clear_texture (MetaCursorSprite *sprite)
MetaCursorSpritePrivate *priv = MetaCursorSpritePrivate *priv =
meta_cursor_sprite_get_instance_private (sprite); meta_cursor_sprite_get_instance_private (sprite);
g_clear_pointer (&priv->texture, cogl_object_unref); g_clear_object (&priv->texture);
meta_cursor_sprite_invalidate (sprite); meta_cursor_sprite_invalidate (sprite);
} }
@ -109,9 +109,9 @@ meta_cursor_sprite_set_texture (MetaCursorSprite *sprite,
MetaCursorSpritePrivate *priv = MetaCursorSpritePrivate *priv =
meta_cursor_sprite_get_instance_private (sprite); meta_cursor_sprite_get_instance_private (sprite);
g_clear_pointer (&priv->texture, cogl_object_unref); g_clear_object (&priv->texture);
if (texture) if (texture)
priv->texture = cogl_object_ref (texture); priv->texture = g_object_ref (COGL_TEXTURE_2D (texture));
priv->hot_x = hot_x; priv->hot_x = hot_x;
priv->hot_y = hot_y; priv->hot_y = hot_y;
@ -264,7 +264,7 @@ meta_cursor_sprite_constructed (GObject *object)
meta_cursor_tracker_register_cursor_sprite (priv->cursor_tracker, sprite); meta_cursor_tracker_register_cursor_sprite (priv->cursor_tracker, sprite);
g_clear_pointer (&priv->texture, cogl_object_unref); g_clear_object (&priv->texture);
G_OBJECT_CLASS (meta_cursor_sprite_parent_class)->constructed (object); G_OBJECT_CLASS (meta_cursor_sprite_parent_class)->constructed (object);
} }
@ -276,7 +276,7 @@ meta_cursor_sprite_finalize (GObject *object)
MetaCursorSpritePrivate *priv = MetaCursorSpritePrivate *priv =
meta_cursor_sprite_get_instance_private (sprite); meta_cursor_sprite_get_instance_private (sprite);
g_clear_pointer (&priv->texture, cogl_object_unref); g_clear_object (&priv->texture);
meta_cursor_tracker_unregister_cursor_sprite (priv->cursor_tracker, sprite); meta_cursor_tracker_unregister_cursor_sprite (priv->cursor_tracker, sprite);
g_clear_object (&priv->cursor_tracker); g_clear_object (&priv->cursor_tracker);

View File

@ -313,7 +313,7 @@ draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc *src,
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
CoglContext *cogl_context = CoglContext *cogl_context =
clutter_backend_get_cogl_context (clutter_backend); clutter_backend_get_cogl_context (clutter_backend);
CoglTexture2D *bitmap_texture; CoglTexture *bitmap_texture;
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
CoglFramebuffer *fb; CoglFramebuffer *fb;
CoglPipeline *pipeline; CoglPipeline *pipeline;
@ -322,17 +322,16 @@ draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc *src,
bitmap_texture = cogl_texture_2d_new_with_size (cogl_context, bitmap_texture = cogl_texture_2d_new_with_size (cogl_context,
bitmap_width, bitmap_height); bitmap_width, bitmap_height);
cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (bitmap_texture), cogl_primitive_texture_set_auto_mipmap (bitmap_texture, FALSE);
FALSE); if (!cogl_texture_allocate (bitmap_texture, error))
if (!cogl_texture_allocate (COGL_TEXTURE (bitmap_texture), error))
{ {
cogl_object_unref (bitmap_texture); g_object_unref (bitmap_texture);
return FALSE; return FALSE;
} }
offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (bitmap_texture)); offscreen = cogl_offscreen_new_with_texture (bitmap_texture);
fb = COGL_FRAMEBUFFER (offscreen); fb = COGL_FRAMEBUFFER (offscreen);
cogl_object_unref (bitmap_texture); g_object_unref (bitmap_texture);
if (!cogl_framebuffer_allocate (fb, error)) if (!cogl_framebuffer_allocate (fb, error))
{ {
g_object_unref (fb); g_object_unref (fb);

View File

@ -254,7 +254,7 @@ meta_drm_buffer_gbm_blit_to_framebuffer (CoglScanout *scanout,
CoglPixelFormat cogl_format; CoglPixelFormat cogl_format;
CoglEglImageFlags flags; CoglEglImageFlags flags;
CoglOffscreen *cogl_fbo = NULL; CoglOffscreen *cogl_fbo = NULL;
CoglTexture2D *cogl_tex; CoglTexture *cogl_tex;
uint32_t n_planes; uint32_t n_planes;
uint64_t *modifiers; uint64_t *modifiers;
uint32_t *strides; uint32_t *strides;
@ -332,8 +332,8 @@ meta_drm_buffer_gbm_blit_to_framebuffer (CoglScanout *scanout,
goto out; goto out;
} }
cogl_fbo = cogl_offscreen_new_with_texture (COGL_TEXTURE (cogl_tex)); cogl_fbo = cogl_offscreen_new_with_texture (cogl_tex);
cogl_object_unref (cogl_tex); g_object_unref (cogl_tex);
if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (cogl_fbo), error)) if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (cogl_fbo), error))
{ {

View File

@ -613,7 +613,7 @@ meta_renderer_native_create_dma_buf_framebuffer (MetaRendererNative *renderer_n
uint64_t modifiers[1]; uint64_t modifiers[1];
CoglPixelFormat cogl_format; CoglPixelFormat cogl_format;
CoglEglImageFlags flags; CoglEglImageFlags flags;
CoglTexture2D *cogl_tex; CoglTexture *cogl_tex;
CoglOffscreen *cogl_fbo; CoglOffscreen *cogl_fbo;
int ret; int ret;
@ -651,8 +651,8 @@ meta_renderer_native_create_dma_buf_framebuffer (MetaRendererNative *renderer_n
if (!cogl_tex) if (!cogl_tex)
return NULL; return NULL;
cogl_fbo = cogl_offscreen_new_with_texture (COGL_TEXTURE (cogl_tex)); cogl_fbo = cogl_offscreen_new_with_texture (cogl_tex);
cogl_object_unref (cogl_tex); g_object_unref (cogl_tex);
if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (cogl_fbo), error)) if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (cogl_fbo), error))
{ {
@ -1151,19 +1151,19 @@ meta_renderer_native_create_offscreen (MetaRendererNative *renderer,
GError **error) GError **error)
{ {
CoglOffscreen *fb; CoglOffscreen *fb;
CoglTexture2D *tex; CoglTexture *tex;
tex = cogl_texture_2d_new_with_size (context, view_width, view_height); tex = cogl_texture_2d_new_with_size (context, view_width, view_height);
cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (tex), FALSE); cogl_primitive_texture_set_auto_mipmap (tex, FALSE);
if (!cogl_texture_allocate (COGL_TEXTURE (tex), error)) if (!cogl_texture_allocate (tex, error))
{ {
cogl_object_unref (tex); g_object_unref (tex);
return FALSE; return FALSE;
} }
fb = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex)); fb = cogl_offscreen_new_with_texture (tex);
cogl_object_unref (tex); g_object_unref (tex);
if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (fb), error)) if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (fb), error))
{ {
g_object_unref (fb); g_object_unref (fb);

View File

@ -125,7 +125,7 @@ meta_cursor_sprite_xfixes_initable_init (GInitable *initable,
MetaX11Display *x11_display; MetaX11Display *x11_display;
Display *xdisplay; Display *xdisplay;
XFixesCursorImage *cursor_image; XFixesCursorImage *cursor_image;
CoglTexture2D *texture; CoglTexture *texture;
uint8_t *cursor_data; uint8_t *cursor_data;
gboolean free_cursor_data; gboolean free_cursor_data;
ClutterBackend *clutter_backend; ClutterBackend *clutter_backend;
@ -189,10 +189,10 @@ meta_cursor_sprite_xfixes_initable_init (GInitable *initable,
return FALSE; return FALSE;
meta_cursor_sprite_set_texture (sprite, meta_cursor_sprite_set_texture (sprite,
COGL_TEXTURE (texture), texture,
cursor_image->xhot, cursor_image->xhot,
cursor_image->yhot); cursor_image->yhot);
cogl_object_unref (texture); g_object_unref (texture);
XFree (cursor_image); XFree (cursor_image);
return TRUE; return TRUE;

View File

@ -75,12 +75,12 @@ create_offscreen (CoglContext *cogl_context,
int width, int width,
int height) int height)
{ {
CoglTexture2D *texture_2d; CoglTexture *texture_2d;
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
GError *error = NULL; GError *error = NULL;
texture_2d = cogl_texture_2d_new_with_size (cogl_context, width, height); texture_2d = cogl_texture_2d_new_with_size (cogl_context, width, height);
offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (texture_2d)); offscreen = cogl_offscreen_new_with_texture (texture_2d);
if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen), &error)) if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen), &error))
meta_fatal ("Couldn't allocate framebuffer: %s", error->message); meta_fatal ("Couldn't allocate framebuffer: %s", error->message);

View File

@ -92,7 +92,7 @@ meta_create_texture (int width,
CoglContext *ctx = clutter_backend_get_cogl_context (backend); CoglContext *ctx = clutter_backend_get_cogl_context (backend);
CoglTexture *texture; CoglTexture *texture;
texture = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, width, height)); texture = cogl_texture_2d_new_with_size (ctx, width, height);
cogl_texture_set_components (texture, components); cogl_texture_set_components (texture, components);
if ((flags & META_TEXTURE_ALLOW_SLICING) != 0) if ((flags & META_TEXTURE_ALLOW_SLICING) != 0)
@ -104,8 +104,8 @@ meta_create_texture (int width,
if (!cogl_texture_allocate (texture, &catch_error)) if (!cogl_texture_allocate (texture, &catch_error))
{ {
g_error_free (catch_error); g_error_free (catch_error);
cogl_object_unref (texture); g_object_unref (texture);
texture = COGL_TEXTURE (cogl_texture_2d_sliced_new_with_size (ctx, width, height, COGL_TEXTURE_MAX_WASTE)); texture = cogl_texture_2d_sliced_new_with_size (ctx, width, height, COGL_TEXTURE_MAX_WASTE);
cogl_texture_set_components (texture, components); cogl_texture_set_components (texture, components);
} }
} }

View File

@ -196,7 +196,7 @@ file_loaded (GObject *source_object,
{ {
g_warning ("Failed to create texture for background: %s", g_warning ("Failed to create texture for background: %s",
local_error->message); local_error->message);
cogl_clear_object (&texture); g_clear_object (&texture);
} }
image->texture = texture; image->texture = texture;
@ -218,7 +218,7 @@ out:
* image that is already in the process of loading or loaded. * image that is already in the process of loading or loaded.
* *
* In either case, what is returned is a [class@Meta.BackgroundImage] which can be dereferenced * In either case, what is returned is a [class@Meta.BackgroundImage] which can be dereferenced
* to get a [iface@Cogl.Texture]. If [method@Meta.BackgroundImage.is_loaded] returns %TRUE, * to get a [class@Cogl.Texture]. If [method@Meta.BackgroundImage.is_loaded] returns %TRUE,
* the background is loaded, otherwise the [signal@Meta.BackgroundImage::loaded] * the background is loaded, otherwise the [signal@Meta.BackgroundImage::loaded]
* signal will be emitted exactly once. The 'loaded' state means that the * signal will be emitted exactly once. The 'loaded' state means that the
* loading process finished, whether it succeeded or failed. * loading process finished, whether it succeeded or failed.
@ -294,7 +294,7 @@ meta_background_image_finalize (GObject *object)
g_hash_table_remove (image->cache->images, image->file); g_hash_table_remove (image->cache->images, image->file);
if (image->texture) if (image->texture)
cogl_object_unref (image->texture); g_object_unref (image->texture);
if (image->file) if (image->file)
g_object_unref (image->file); g_object_unref (image->file);

View File

@ -96,20 +96,20 @@ free_fbos (MetaBackground *self)
MetaBackgroundMonitor *monitor = &self->monitors[i]; MetaBackgroundMonitor *monitor = &self->monitors[i];
g_clear_object (&monitor->fbo); g_clear_object (&monitor->fbo);
cogl_clear_object (&monitor->texture); g_clear_object (&monitor->texture);
} }
} }
static void static void
free_color_texture (MetaBackground *self) free_color_texture (MetaBackground *self)
{ {
cogl_clear_object (&self->color_texture); g_clear_object (&self->color_texture);
} }
static void static void
free_wallpaper_texture (MetaBackground *self) free_wallpaper_texture (MetaBackground *self)
{ {
cogl_clear_object (&self->wallpaper_texture); g_clear_object (&self->wallpaper_texture);
self->wallpaper_allocation_failed = FALSE; self->wallpaper_allocation_failed = FALSE;
} }
@ -587,11 +587,11 @@ ensure_color_texture (MetaBackground *self)
pixels[5] = self->second_color.blue; pixels[5] = self->second_color.blue;
} }
self->color_texture = COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx, width, height, self->color_texture = cogl_texture_2d_new_from_data (ctx, width, height,
COGL_PIXEL_FORMAT_RGB_888, COGL_PIXEL_FORMAT_RGB_888,
width * 3, width * 3,
pixels, pixels,
&error)); &error);
if (error != NULL) if (error != NULL)
{ {
@ -680,7 +680,7 @@ ensure_wallpaper_texture (MetaBackground *self,
*/ */
g_error_free (catch_error); g_error_free (catch_error);
cogl_clear_object (&self->wallpaper_texture); g_clear_object (&self->wallpaper_texture);
g_object_unref (fbo); g_object_unref (fbo);
self->wallpaper_allocation_failed = TRUE; self->wallpaper_allocation_failed = TRUE;
@ -843,7 +843,7 @@ meta_background_get_texture (MetaBackground *self,
* we'll try again the next time this is called. (MetaBackgroundActor * we'll try again the next time this is called. (MetaBackgroundActor
* caches the result, so user might be left without a background.) * caches the result, so user might be left without a background.)
*/ */
cogl_clear_object (&monitor->texture); g_clear_object (&monitor->texture);
g_clear_object (&monitor->fbo); g_clear_object (&monitor->fbo);
g_error_free (catch_error); g_error_free (catch_error);

View File

@ -171,7 +171,7 @@ meta_multi_texture_finalize (GObject *object)
int i; int i;
for (i = 0; i < multi_texture->n_planes; i++) for (i = 0; i < multi_texture->n_planes; i++)
cogl_clear_object (&multi_texture->planes[i]); g_clear_object (&multi_texture->planes[i]);
g_free (multi_texture->planes); g_free (multi_texture->planes);

View File

@ -167,7 +167,7 @@ meta_shadow_unref (MetaShadow *shadow)
} }
meta_window_shape_unref (shadow->key.shape); meta_window_shape_unref (shadow->key.shape);
cogl_object_unref (shadow->texture); g_object_unref (shadow->texture);
cogl_object_unref (shadow->pipeline); cogl_object_unref (shadow->pipeline);
g_free (shadow); g_free (shadow);
@ -797,7 +797,7 @@ make_shadow (MetaShadow *shadow,
* in the case of top_fade >= 0. We also account for padding at the left for symmetry * in the case of top_fade >= 0. We also account for padding at the left for symmetry
* though that doesn't currently occur. * though that doesn't currently occur.
*/ */
shadow->texture = COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx, shadow->texture = cogl_texture_2d_new_from_data (ctx,
shadow->outer_border_left + extents.width + shadow->outer_border_right, shadow->outer_border_left + extents.width + shadow->outer_border_right,
shadow->outer_border_top + extents.height + shadow->outer_border_bottom, shadow->outer_border_top + extents.height + shadow->outer_border_bottom,
COGL_PIXEL_FORMAT_A_8, COGL_PIXEL_FORMAT_A_8,
@ -805,7 +805,7 @@ make_shadow (MetaShadow *shadow,
(buffer + (buffer +
(y_offset - shadow->outer_border_top) * buffer_width + (y_offset - shadow->outer_border_top) * buffer_width +
(x_offset - shadow->outer_border_left)), (x_offset - shadow->outer_border_left)),
&error)); &error);
if (error) if (error)
{ {

View File

@ -243,7 +243,7 @@ meta_shaped_texture_dispose (GObject *object)
g_clear_pointer (&stex->texture_mipmap, meta_texture_mipmap_free); g_clear_pointer (&stex->texture_mipmap, meta_texture_mipmap_free);
g_clear_pointer (&stex->texture, cogl_object_unref); g_clear_object (&stex->texture);
meta_shaped_texture_set_mask_texture (stex, NULL); meta_shaped_texture_set_mask_texture (stex, NULL);
meta_shaped_texture_reset_pipelines (stex); meta_shaped_texture_reset_pipelines (stex);
@ -980,12 +980,12 @@ meta_shaped_texture_set_mask_texture (MetaShapedTexture *stex,
{ {
g_return_if_fail (META_IS_SHAPED_TEXTURE (stex)); g_return_if_fail (META_IS_SHAPED_TEXTURE (stex));
g_clear_pointer (&stex->mask_texture, cogl_object_unref); g_clear_object (&stex->mask_texture);
if (mask_texture != NULL) if (mask_texture != NULL)
{ {
stex->mask_texture = mask_texture; stex->mask_texture = mask_texture;
cogl_object_ref (stex->mask_texture); g_object_ref (stex->mask_texture);
} }
clutter_content_invalidate (CLUTTER_CONTENT (stex)); clutter_content_invalidate (CLUTTER_CONTENT (stex));
@ -1464,12 +1464,12 @@ meta_shaped_texture_get_image (MetaShapedTexture *stex,
texture = meta_multi_texture_get_plane (stex->texture, 0); texture = meta_multi_texture_get_plane (stex->texture, 0);
if (image_clip) if (image_clip)
texture = COGL_TEXTURE (cogl_sub_texture_new (cogl_context, texture = cogl_sub_texture_new (cogl_context,
texture, texture,
image_clip->x, image_clip->x,
image_clip->y, image_clip->y,
image_clip->width, image_clip->width,
image_clip->height)); image_clip->height);
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
cogl_texture_get_width (texture), cogl_texture_get_width (texture),
@ -1482,7 +1482,7 @@ meta_shaped_texture_get_image (MetaShapedTexture *stex,
cairo_surface_mark_dirty (surface); cairo_surface_mark_dirty (surface);
if (image_clip) if (image_clip)
cogl_object_unref (texture); g_object_unref (texture);
return surface; return surface;
} }

View File

@ -122,7 +122,7 @@ set_pixmap (MetaSurfaceActorX11 *self,
g_assert (self->pixmap == None); g_assert (self->pixmap == None);
self->pixmap = pixmap; self->pixmap = pixmap;
cogl_texture = COGL_TEXTURE (cogl_texture_pixmap_x11_new (ctx, self->pixmap, FALSE, &error)); cogl_texture = cogl_texture_pixmap_x11_new (ctx, self->pixmap, FALSE, &error);
if (error != NULL) if (error != NULL)
{ {

View File

@ -165,16 +165,14 @@ ensure_mipmap_texture (MetaTextureMipmap *mipmap)
meta_multi_texture_get_height (mipmap->mipmap_texture) != height) meta_multi_texture_get_height (mipmap->mipmap_texture) != height)
{ {
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
CoglTexture2D *tex2d;
CoglTexture *tex; CoglTexture *tex;
free_mipmaps (mipmap); free_mipmaps (mipmap);
tex2d = cogl_texture_2d_new_with_size (ctx, width, height); tex = cogl_texture_2d_new_with_size (ctx, width, height);
if (!tex2d) if (!tex)
return; return;
tex = COGL_TEXTURE (tex2d);
mipmap->mipmap_texture = meta_multi_texture_new_simple (tex); mipmap->mipmap_texture = meta_multi_texture_new_simple (tex);
offscreen = cogl_offscreen_new_with_texture (tex); offscreen = cogl_offscreen_new_with_texture (tex);

View File

@ -784,7 +784,7 @@ build_and_scan_frame_mask (MetaWindowActorX11 *actor_x11,
uint8_t *mask_data; uint8_t *mask_data;
unsigned int tex_width, tex_height; unsigned int tex_width, tex_height;
MetaShapedTexture *stex; MetaShapedTexture *stex;
CoglTexture2D *mask_texture; CoglTexture *mask_texture;
int stride; int stride;
cairo_t *cr; cairo_t *cr;
cairo_surface_t *image; cairo_surface_t *image;
@ -868,8 +868,8 @@ build_and_scan_frame_mask (MetaWindowActorX11 *actor_x11,
if (mask_texture) if (mask_texture)
{ {
meta_shaped_texture_set_mask_texture (stex, COGL_TEXTURE (mask_texture)); meta_shaped_texture_set_mask_texture (stex, mask_texture);
cogl_object_unref (mask_texture); g_object_unref (mask_texture);
} }
else else
{ {

View File

@ -1574,7 +1574,7 @@ create_framebuffer_from_window_actor (MetaWindowActor *self,
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
CoglContext *cogl_context = CoglContext *cogl_context =
clutter_backend_get_cogl_context (clutter_backend); clutter_backend_get_cogl_context (clutter_backend);
CoglTexture2D *texture; CoglTexture *texture;
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
CoglFramebuffer *framebuffer; CoglFramebuffer *framebuffer;
CoglColor clear_color; CoglColor clear_color;
@ -1589,13 +1589,12 @@ create_framebuffer_from_window_actor (MetaWindowActor *self,
if (!texture) if (!texture)
return NULL; return NULL;
cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (texture), cogl_primitive_texture_set_auto_mipmap (texture, FALSE);
FALSE);
offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (texture)); offscreen = cogl_offscreen_new_with_texture (texture);
framebuffer = COGL_FRAMEBUFFER (offscreen); framebuffer = COGL_FRAMEBUFFER (offscreen);
cogl_object_unref (texture); g_object_unref (texture);
if (!cogl_framebuffer_allocate (framebuffer, error)) if (!cogl_framebuffer_allocate (framebuffer, error))
{ {

View File

@ -224,10 +224,10 @@ test_cogl_multitexture_main (int argc, char *argv[])
cogl_object_unref (state->pipeline1); cogl_object_unref (state->pipeline1);
cogl_object_unref (state->pipeline0); cogl_object_unref (state->pipeline0);
cogl_object_unref (state->alpha_tex); g_object_unref (state->alpha_tex);
cogl_object_unref (state->redhand_tex); g_object_unref (state->redhand_tex);
cogl_object_unref (state->light_tex0); g_object_unref (state->light_tex0);
cogl_object_unref (state->light_tex1); g_object_unref (state->light_tex1);
g_free (state); g_free (state);
return 0; return 0;

View File

@ -92,7 +92,7 @@ test_coglbox_dispose (GObject *object)
{ {
TestCoglbox *coglbox = TEST_COGLBOX (object); TestCoglbox *coglbox = TEST_COGLBOX (object);
cogl_object_unref (coglbox->texture_id); g_object_unref (coglbox->texture_id);
g_object_unref (coglbox->framebuffer); g_object_unref (coglbox->framebuffer);
G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object); G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object);

View File

@ -236,7 +236,7 @@ test_cogl_point_sprites_main (int argc, char *argv[])
tex = generate_round_texture (ctx); tex = generate_round_texture (ctx);
cogl_pipeline_set_layer_texture (data.pipeline, 0, tex); cogl_pipeline_set_layer_texture (data.pipeline, 0, tex);
cogl_object_unref (tex); g_object_unref (tex);
if (!cogl_pipeline_set_layer_point_sprite_coords_enabled (data.pipeline, if (!cogl_pipeline_set_layer_point_sprite_coords_enabled (data.pipeline,
0, TRUE, 0, TRUE,

View File

@ -219,8 +219,8 @@ test_coglbox_dispose (GObject *object)
{ {
TestCoglbox *coglbox = TEST_COGLBOX (object); TestCoglbox *coglbox = TEST_COGLBOX (object);
cogl_object_unref (coglbox->not_sliced_tex); g_object_unref (coglbox->not_sliced_tex);
cogl_object_unref (coglbox->sliced_tex); g_object_unref (coglbox->sliced_tex);
G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object); G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object);
} }

View File

@ -93,7 +93,7 @@ test_coglbox_dispose (GObject *object)
{ {
TestCoglbox *coglbox = TEST_COGLBOX (object); TestCoglbox *coglbox = TEST_COGLBOX (object);
cogl_object_unref (coglbox->cogl_tex_id); g_object_unref (coglbox->cogl_tex_id);
G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object); G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object);
} }

View File

@ -111,13 +111,13 @@ clutter_test_create_bitmap_from_file (CoglContext *ctx,
return bmp; return bmp;
} }
static inline CoglTexture2DSliced * static inline CoglTexture *
clutter_test_texture_2d_sliced_new_from_file (CoglContext *ctx, clutter_test_texture_2d_sliced_new_from_file (CoglContext *ctx,
const char *filename, const char *filename,
GError **error) GError **error)
{ {
CoglBitmap *bmp; CoglBitmap *bmp;
CoglTexture2DSliced *tex_2ds = NULL; CoglTexture *tex_2ds = NULL;
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@ -132,13 +132,13 @@ clutter_test_texture_2d_sliced_new_from_file (CoglContext *ctx,
return tex_2ds; return tex_2ds;
} }
static inline CoglTexture2D * static inline CoglTexture *
clutter_test_texture_2d_new_from_file (CoglContext *ctx, clutter_test_texture_2d_new_from_file (CoglContext *ctx,
const char *filename, const char *filename,
GError **error) GError **error)
{ {
CoglBitmap *bmp; CoglBitmap *bmp;
CoglTexture2D *tex_2d = NULL; CoglTexture *tex_2d = NULL;
g_return_val_if_fail (error == NULL || *error == NULL, NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL);

View File

@ -166,7 +166,7 @@ CoglTexture *
test_utils_create_color_texture (CoglContext *context, test_utils_create_color_texture (CoglContext *context,
uint32_t color) uint32_t color)
{ {
CoglTexture2D *tex_2d; CoglTexture *tex_2d;
color = GUINT32_TO_BE (color); color = GUINT32_TO_BE (color);
@ -177,7 +177,7 @@ test_utils_create_color_texture (CoglContext *context,
(uint8_t *) &color, (uint8_t *) &color,
NULL); NULL);
return COGL_TEXTURE (tex_2d); return tex_2d;
} }
gboolean gboolean
@ -192,8 +192,7 @@ set_auto_mipmap_cb (CoglTexture *sub_texture,
const float *meta_coords, const float *meta_coords,
void *user_data) void *user_data)
{ {
cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (sub_texture), cogl_primitive_texture_set_auto_mipmap (sub_texture, FALSE);
FALSE);
} }
CoglTexture * CoglTexture *
@ -207,14 +206,14 @@ test_utils_texture_new_with_size (CoglContext *ctx,
GError *skip_error = NULL; GError *skip_error = NULL;
/* First try creating a fast-path non-sliced texture */ /* First try creating a fast-path non-sliced texture */
tex = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, width, height)); tex = cogl_texture_2d_new_with_size (ctx, width, height);
cogl_texture_set_components (tex, components); cogl_texture_set_components (tex, components);
if (!cogl_texture_allocate (tex, &skip_error)) if (!cogl_texture_allocate (tex, &skip_error))
{ {
g_error_free (skip_error); g_error_free (skip_error);
cogl_object_unref (tex); g_object_unref (tex);
tex = NULL; tex = NULL;
} }
@ -223,13 +222,11 @@ test_utils_texture_new_with_size (CoglContext *ctx,
/* If it fails resort to sliced textures */ /* If it fails resort to sliced textures */
int max_waste = flags & TEST_UTILS_TEXTURE_NO_SLICING ? int max_waste = flags & TEST_UTILS_TEXTURE_NO_SLICING ?
-1 : COGL_TEXTURE_MAX_WASTE; -1 : COGL_TEXTURE_MAX_WASTE;
CoglTexture2DSliced *tex_2ds = tex =
cogl_texture_2d_sliced_new_with_size (ctx, cogl_texture_2d_sliced_new_with_size (ctx,
width, width,
height, height,
max_waste); max_waste);
tex = COGL_TEXTURE (tex_2ds);
cogl_texture_set_components (tex, components); cogl_texture_set_components (tex, components);
} }
@ -239,7 +236,7 @@ test_utils_texture_new_with_size (CoglContext *ctx,
* need to ensure the texture is allocated... */ * need to ensure the texture is allocated... */
cogl_texture_allocate (tex, NULL); /* don't catch exceptions */ cogl_texture_allocate (tex, NULL); /* don't catch exceptions */
cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (tex), cogl_meta_texture_foreach_in_region (tex,
0, 0, 1, 1, 0, 0, 1, 1,
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE, COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE, COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
@ -257,7 +254,7 @@ test_utils_texture_new_from_bitmap (CoglBitmap *bitmap,
TestUtilsTextureFlags flags, TestUtilsTextureFlags flags,
gboolean premultiplied) gboolean premultiplied)
{ {
CoglAtlasTexture *atlas_tex; CoglTexture *atlas_tex;
CoglTexture *tex; CoglTexture *tex;
GError *internal_error = NULL; GError *internal_error = NULL;
@ -266,18 +263,18 @@ test_utils_texture_new_from_bitmap (CoglBitmap *bitmap,
/* First try putting the texture in the atlas */ /* First try putting the texture in the atlas */
atlas_tex = cogl_atlas_texture_new_from_bitmap (bitmap); atlas_tex = cogl_atlas_texture_new_from_bitmap (bitmap);
cogl_texture_set_premultiplied (COGL_TEXTURE (atlas_tex), premultiplied); cogl_texture_set_premultiplied (atlas_tex, premultiplied);
if (cogl_texture_allocate (COGL_TEXTURE (atlas_tex), &internal_error)) if (cogl_texture_allocate (atlas_tex, &internal_error))
return COGL_TEXTURE (atlas_tex); return atlas_tex;
cogl_object_unref (atlas_tex); g_object_unref (atlas_tex);
} }
g_clear_error (&internal_error); g_clear_error (&internal_error);
/* If that doesn't work try a fast path 2D texture */ /* If that doesn't work try a fast path 2D texture */
tex = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (bitmap)); tex = cogl_texture_2d_new_from_bitmap (bitmap);
cogl_texture_set_premultiplied (tex, premultiplied); cogl_texture_set_premultiplied (tex, premultiplied);
@ -296,16 +293,15 @@ test_utils_texture_new_from_bitmap (CoglBitmap *bitmap,
/* Otherwise create a sliced texture */ /* Otherwise create a sliced texture */
int max_waste = flags & TEST_UTILS_TEXTURE_NO_SLICING ? int max_waste = flags & TEST_UTILS_TEXTURE_NO_SLICING ?
-1 : COGL_TEXTURE_MAX_WASTE; -1 : COGL_TEXTURE_MAX_WASTE;
CoglTexture2DSliced *tex_2ds = tex =
cogl_texture_2d_sliced_new_from_bitmap (bitmap, max_waste); cogl_texture_2d_sliced_new_from_bitmap (bitmap, max_waste);
tex = COGL_TEXTURE (tex_2ds);
cogl_texture_set_premultiplied (tex, premultiplied); cogl_texture_set_premultiplied (tex, premultiplied);
} }
if (flags & TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP) if (flags & TEST_UTILS_TEXTURE_NO_AUTO_MIPMAP)
{ {
cogl_meta_texture_foreach_in_region (COGL_META_TEXTURE (tex), cogl_meta_texture_foreach_in_region (tex,
0, 0, 1, 1, 0, 0, 1, 1,
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE, COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE, COGL_PIPELINE_WRAP_MODE_CLAMP_TO_EDGE,
@ -353,14 +349,14 @@ on_before_tests (MetaContext *context)
MetaBackend *backend = meta_context_get_backend (context); MetaBackend *backend = meta_context_get_backend (context);
ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend);
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
CoglTexture2D *tex; CoglTexture *tex;
GError *error = NULL; GError *error = NULL;
test_ctx = clutter_backend_get_cogl_context (clutter_backend); test_ctx = clutter_backend_get_cogl_context (clutter_backend);
tex = cogl_texture_2d_new_with_size (test_ctx, FB_WIDTH, FB_HEIGHT); tex = cogl_texture_2d_new_with_size (test_ctx, FB_WIDTH, FB_HEIGHT);
g_assert_nonnull (tex); g_assert_nonnull (tex);
offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex)); offscreen = cogl_offscreen_new_with_texture (tex);
g_assert_nonnull (offscreen); g_assert_nonnull (offscreen);
test_fb = COGL_FRAMEBUFFER (offscreen); test_fb = COGL_FRAMEBUFFER (offscreen);

View File

@ -3,7 +3,7 @@
#include "tests/cogl-test-utils.h" #include "tests/cogl-test-utils.h"
static CoglTexture2D * static CoglTexture *
create_texture (CoglContext *context) create_texture (CoglContext *context)
{ {
static const uint8_t data[] = static const uint8_t data[] =
@ -48,7 +48,7 @@ test_alpha_test (void)
1, 1); 1, 1);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
cogl_object_unref (tex); g_object_unref (tex);
/* The left side of the framebuffer should use the first pixel from /* The left side of the framebuffer should use the first pixel from
* the texture which is red */ * the texture which is red */

View File

@ -8,7 +8,7 @@ static void
create_pipeline (CoglTexture **tex_out, create_pipeline (CoglTexture **tex_out,
CoglPipeline **pipeline_out) CoglPipeline **pipeline_out)
{ {
CoglTexture2D *tex; CoglTexture *tex;
CoglPipeline *pipeline; CoglPipeline *pipeline;
static const uint8_t tex_data[] = static const uint8_t tex_data[] =
{ 0x00, 0x44, 0x88, 0xcc }; { 0x00, 0x44, 0x88, 0xcc };
@ -76,8 +76,8 @@ test_alpha_textures (void)
-1.0f, 0.0f, /* x1/y1 */ -1.0f, 0.0f, /* x1/y1 */
1.0f, -1.0f /* x2/y2 */); 1.0f, -1.0f /* x2/y2 */);
cogl_object_unref (tex1); g_object_unref (tex1);
cogl_object_unref (tex2); g_object_unref (tex2);
cogl_object_unref (pipeline1); cogl_object_unref (pipeline1);
cogl_object_unref (pipeline2); cogl_object_unref (pipeline2);

View File

@ -125,7 +125,7 @@ test_atlas_migration (void)
for (tex_num = 0; tex_num < N_TEXTURES; tex_num++) for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
textures[tex_num] = create_texture (tex_num + 1); textures[tex_num] = create_texture (tex_num + 1);
for (tex_num = 0; tex_num < N_TEXTURES; tex_num++) for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
cogl_object_unref (textures[tex_num]); g_object_unref (textures[tex_num]);
} }
/* Create all the textures again */ /* Create all the textures again */
@ -138,7 +138,7 @@ test_atlas_migration (void)
/* Destroy them all */ /* Destroy them all */
for (tex_num = 0; tex_num < N_TEXTURES; tex_num++) for (tex_num = 0; tex_num < N_TEXTURES; tex_num++)
cogl_object_unref (textures[tex_num]); g_object_unref (textures[tex_num]);
if (cogl_test_verbose ()) if (cogl_test_verbose ())
g_print ("OK\n"); g_print ("OK\n");

View File

@ -306,8 +306,8 @@ test_backface_culling (void)
paint (&state); paint (&state);
g_object_unref (state.offscreen); g_object_unref (state.offscreen);
cogl_object_unref (state.offscreen_tex); g_object_unref (state.offscreen_tex);
cogl_object_unref (state.texture); g_object_unref (state.texture);
if (cogl_test_verbose ()) if (cogl_test_verbose ())
g_print ("OK\n"); g_print ("OK\n");

View File

@ -217,8 +217,8 @@ test_tex_combine (TestState *state,
y * QUAD_WIDTH + QUAD_WIDTH); y * QUAD_WIDTH + QUAD_WIDTH);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
cogl_object_unref (tex0); g_object_unref (tex0);
cogl_object_unref (tex1); g_object_unref (tex1);
/* See what we got... */ /* See what we got... */

View File

@ -6,6 +6,7 @@
/* Keep track of the number of textures that we've created and are /* Keep track of the number of textures that we've created and are
* still alive */ * still alive */
static int alive_texture_mask = 0; static int alive_texture_mask = 0;
static GQuark texture_data_key = 0;
#define N_LAYERS 3 #define N_LAYERS 3
#define N_PIPELINES 4 #define N_PIPELINES 4
@ -28,8 +29,8 @@ create_texture (void)
{ {
static const guint8 data[] = static const guint8 data[] =
{ 0xff, 0xff, 0xff, 0xff }; { 0xff, 0xff, 0xff, 0xff };
static CoglUserDataKey texture_data_key; texture_data_key = g_quark_from_static_string ("-cogl-test-copy-replace-texture");
CoglTexture2D *tex_2d; CoglTexture *tex_2d;
static int texture_num = 1; static int texture_num = 1;
alive_texture_mask |= (1 << texture_num); alive_texture_mask |= (1 << texture_num);
@ -40,11 +41,10 @@ create_texture (void)
4, /* rowstride */ 4, /* rowstride */
data, data,
NULL); NULL);
/* Set some user data on the texture so we can track when it has /* Set some user data on the texture so we can track when it has
* been destroyed */ * been destroyed */
cogl_object_set_user_data (COGL_OBJECT (tex_2d), g_object_set_qdata_full (G_OBJECT (tex_2d),
&texture_data_key, texture_data_key,
GINT_TO_POINTER (texture_num), GINT_TO_POINTER (texture_num),
free_texture_cb); free_texture_cb);
@ -77,7 +77,7 @@ test_copy_replace_texture (void)
cogl_pipeline_set_layer_texture (pipelines[pipeline_num], cogl_pipeline_set_layer_texture (pipelines[pipeline_num],
layer_num, layer_num,
tex); tex);
cogl_object_unref (tex); g_object_unref (tex);
} }
} }

View File

@ -6,10 +6,10 @@ static void
test_framebuffer_get_bits (void) test_framebuffer_get_bits (void)
{ {
CoglRenderer *renderer; CoglRenderer *renderer;
CoglTexture2D *tex_a; CoglTexture *tex_a;
CoglOffscreen *offscreen_a; CoglOffscreen *offscreen_a;
CoglFramebuffer *fb_a; CoglFramebuffer *fb_a;
CoglTexture2D *tex_rgba; CoglTexture *tex_rgba;
CoglOffscreen *offscreen_rgba; CoglOffscreen *offscreen_rgba;
CoglFramebuffer *fb_rgba; CoglFramebuffer *fb_rgba;
@ -44,9 +44,9 @@ test_framebuffer_get_bits (void)
g_assert_cmpint (cogl_framebuffer_get_alpha_bits (fb_rgba), >=, 1); g_assert_cmpint (cogl_framebuffer_get_alpha_bits (fb_rgba), >=, 1);
g_object_unref (fb_rgba); g_object_unref (fb_rgba);
cogl_object_unref (tex_rgba); g_object_unref (tex_rgba);
g_object_unref (fb_a); g_object_unref (fb_a);
cogl_object_unref (tex_a); g_object_unref (tex_a);
} }
COGL_TEST_SUITE ( COGL_TEST_SUITE (

View File

@ -8,7 +8,7 @@
static void static void
test_journal_unref_flush (void) test_journal_unref_flush (void)
{ {
CoglTexture2D *texture; CoglTexture *texture;
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
CoglPipeline *pipeline; CoglPipeline *pipeline;
const int width = 1; const int width = 1;
@ -22,7 +22,7 @@ test_journal_unref_flush (void)
G_STATIC_ASSERT (sizeof data == sizeof reference_data); G_STATIC_ASSERT (sizeof data == sizeof reference_data);
texture = cogl_texture_2d_new_with_size (test_ctx, width, height); texture = cogl_texture_2d_new_with_size (test_ctx, width, height);
offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (texture)); offscreen = cogl_offscreen_new_with_texture (texture);
g_object_add_weak_pointer (G_OBJECT (offscreen), (gpointer *) &offscreen); g_object_add_weak_pointer (G_OBJECT (offscreen), (gpointer *) &offscreen);
pipeline = cogl_pipeline_new (test_ctx); pipeline = cogl_pipeline_new (test_ctx);
@ -35,13 +35,13 @@ test_journal_unref_flush (void)
g_object_unref (offscreen); g_object_unref (offscreen);
g_assert_null (offscreen); g_assert_null (offscreen);
cogl_texture_get_data (COGL_TEXTURE (texture), cogl_texture_get_data (texture,
COGL_PIXEL_FORMAT_RGBA_8888_PRE, COGL_PIXEL_FORMAT_RGBA_8888_PRE,
stride, data); stride, data);
g_assert_cmpmem (data, sizeof (data), g_assert_cmpmem (data, sizeof (data),
reference_data, sizeof (reference_data)); reference_data, sizeof (reference_data));
cogl_object_unref (texture); g_object_unref (texture);
} }
COGL_TEST_SUITE ( COGL_TEST_SUITE (

View File

@ -45,7 +45,7 @@ paint (TestState *state)
constant green color provided by a texture */ constant green color provided by a texture */
tex = create_dummy_texture (); tex = create_dummy_texture ();
cogl_pipeline_set_layer_texture (pipeline, 0, tex); cogl_pipeline_set_layer_texture (pipeline, 0, tex);
cogl_object_unref (tex); g_object_unref (tex);
if (!cogl_pipeline_set_layer_combine (pipeline, 0, if (!cogl_pipeline_set_layer_combine (pipeline, 0,
"RGBA=REPLACE(TEXTURE)", "RGBA=REPLACE(TEXTURE)",
&error)) &error))

View File

@ -25,7 +25,7 @@ vertex_data[4] =
static void static void
test_map_buffer_range (void) test_map_buffer_range (void)
{ {
CoglTexture2D *tex; CoglTexture *tex;
CoglPipeline *pipeline; CoglPipeline *pipeline;
int fb_width, fb_height; int fb_width, fb_height;
CoglAttributeBuffer *buffer; CoglAttributeBuffer *buffer;
@ -122,7 +122,7 @@ test_map_buffer_range (void)
g_object_unref (tex_coord_attribute); g_object_unref (tex_coord_attribute);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
cogl_object_unref (tex); g_object_unref (tex);
if (cogl_test_verbose ()) if (cogl_test_verbose ())
g_print ("OK\n"); g_print ("OK\n");

View File

@ -152,8 +152,8 @@ on_paint (ClutterActor *actor,
tex_coords, 8); tex_coords, 8);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
cogl_object_unref (tex0); g_object_unref (tex0);
cogl_object_unref (tex1); g_object_unref (tex1);
/* See what we got... */ /* See what we got... */

View File

@ -138,7 +138,7 @@ paint (void)
(y + 1) / 2.0f); (y + 1) / 2.0f);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
cogl_object_unref (texture); g_object_unref (texture);
} }
static void static void

View File

@ -85,7 +85,7 @@ test_offscreen_texture_formats_store_rgb10 (void)
for (i = 0; i < G_N_ELEMENTS (formats); i++) for (i = 0; i < G_N_ELEMENTS (formats); i++)
{ {
CoglTexture2D *tex; CoglTexture *tex;
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
uint32_t rgb8_readback[4]; uint32_t rgb8_readback[4];
int j, k; int j, k;
@ -93,7 +93,7 @@ test_offscreen_texture_formats_store_rgb10 (void)
/* Allocate 2x2 to ensure we avoid any fast paths. */ /* Allocate 2x2 to ensure we avoid any fast paths. */
tex = cogl_texture_2d_new_with_format (test_ctx, 2, 2, formats[i]); tex = cogl_texture_2d_new_with_format (test_ctx, 2, 2, formats[i]);
offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex)); offscreen = cogl_offscreen_new_with_texture (tex);
cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen), &error); cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen), &error);
g_assert_no_error (error); g_assert_no_error (error);
@ -179,7 +179,7 @@ test_offscreen_texture_formats_store_rgb10 (void)
} }
g_object_unref (offscreen); g_object_unref (offscreen);
cogl_object_unref (tex); g_object_unref (tex);
} }
} }
@ -207,7 +207,7 @@ test_offscreen_texture_formats_store_rgb8 (void)
for (i = 0; i < G_N_ELEMENTS (formats); i++) for (i = 0; i < G_N_ELEMENTS (formats); i++)
{ {
CoglTexture2D *tex; CoglTexture *tex;
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
GError *error = NULL; GError *error = NULL;
int j; int j;
@ -215,7 +215,7 @@ test_offscreen_texture_formats_store_rgb8 (void)
/* Allocate 2x2 to ensure we avoid any fast paths. */ /* Allocate 2x2 to ensure we avoid any fast paths. */
tex = cogl_texture_2d_new_with_format (test_ctx, 2, 2, formats[i]); tex = cogl_texture_2d_new_with_format (test_ctx, 2, 2, formats[i]);
offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex)); offscreen = cogl_offscreen_new_with_texture (tex);
cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen), &error); cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen), &error);
g_assert_no_error (error); g_assert_no_error (error);
@ -277,7 +277,7 @@ test_offscreen_texture_formats_store_rgb8 (void)
} }
g_object_unref (offscreen); g_object_unref (offscreen);
cogl_object_unref (tex); g_object_unref (tex);
} }
} }
@ -316,26 +316,26 @@ test_offscreen_texture_formats_paint_rgb10 (void)
for (i = 0; i < G_N_ELEMENTS (formats); i++) for (i = 0; i < G_N_ELEMENTS (formats); i++)
{ {
CoglTexture2D *tex_src; CoglTexture *tex_src;
CoglOffscreen *offscreen_src; CoglOffscreen *offscreen_src;
GError *error = NULL; GError *error = NULL;
int j; int j;
tex_src = cogl_texture_2d_new_with_format (test_ctx, 2, 2, formats[i]); tex_src = cogl_texture_2d_new_with_format (test_ctx, 2, 2, formats[i]);
offscreen_src = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex_src)); offscreen_src = cogl_offscreen_new_with_texture (tex_src);
cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen_src), &error); cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen_src), &error);
g_assert_no_error (error); g_assert_no_error (error);
for (j = 0; j < G_N_ELEMENTS (formats); j++) for (j = 0; j < G_N_ELEMENTS (formats); j++)
{ {
CoglTexture2D *tex_dst; CoglTexture *tex_dst;
CoglOffscreen *offscreen_dst; CoglOffscreen *offscreen_dst;
CoglPipeline *pipeline; CoglPipeline *pipeline;
uint32_t rgb10_readback[4]; uint32_t rgb10_readback[4];
int k; int k;
tex_dst = cogl_texture_2d_new_with_format (test_ctx, 2, 2, formats[j]); tex_dst = cogl_texture_2d_new_with_format (test_ctx, 2, 2, formats[j]);
offscreen_dst = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex_dst)); offscreen_dst = cogl_offscreen_new_with_texture (tex_dst);
cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen_dst), &error); cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen_dst), &error);
g_assert_no_error (error); g_assert_no_error (error);
@ -410,11 +410,11 @@ test_offscreen_texture_formats_paint_rgb10 (void)
} }
g_object_unref (offscreen_dst); g_object_unref (offscreen_dst);
cogl_object_unref (tex_dst); g_object_unref (tex_dst);
} }
g_object_unref (offscreen_src); g_object_unref (offscreen_src);
cogl_object_unref (tex_src); g_object_unref (tex_src);
} }
} }
@ -442,26 +442,26 @@ test_offscreen_texture_formats_paint_rgb8 (void)
for (i = 0; i < G_N_ELEMENTS (formats); i++) for (i = 0; i < G_N_ELEMENTS (formats); i++)
{ {
CoglTexture2D *tex_src; CoglTexture *tex_src;
CoglOffscreen *offscreen_src; CoglOffscreen *offscreen_src;
GError *error = NULL; GError *error = NULL;
int j; int j;
tex_src = cogl_texture_2d_new_with_format (test_ctx, 2, 2, formats[i]); tex_src = cogl_texture_2d_new_with_format (test_ctx, 2, 2, formats[i]);
offscreen_src = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex_src)); offscreen_src = cogl_offscreen_new_with_texture (tex_src);
cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen_src), &error); cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen_src), &error);
g_assert_no_error (error); g_assert_no_error (error);
for (j = 0; j < G_N_ELEMENTS (formats); j++) for (j = 0; j < G_N_ELEMENTS (formats); j++)
{ {
CoglTexture2D *tex_dst; CoglTexture *tex_dst;
CoglOffscreen *offscreen_dst; CoglOffscreen *offscreen_dst;
CoglPipeline *pipeline; CoglPipeline *pipeline;
uint8_t rgba_readback[4 * 4] = {}; uint8_t rgba_readback[4 * 4] = {};
int k; int k;
tex_dst = cogl_texture_2d_new_with_format (test_ctx, 2, 2, formats[j]); tex_dst = cogl_texture_2d_new_with_format (test_ctx, 2, 2, formats[j]);
offscreen_dst = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex_dst)); offscreen_dst = cogl_offscreen_new_with_texture (tex_dst);
cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen_dst), &error); cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen_dst), &error);
g_assert_no_error (error); g_assert_no_error (error);
@ -527,11 +527,11 @@ test_offscreen_texture_formats_paint_rgb8 (void)
} }
g_object_unref (offscreen_dst); g_object_unref (offscreen_dst);
cogl_object_unref (tex_dst); g_object_unref (tex_dst);
} }
g_object_unref (offscreen_src); g_object_unref (offscreen_src);
cogl_object_unref (tex_src); g_object_unref (tex_src);
} }
} }

View File

@ -40,17 +40,15 @@ check_quadrant (TestState *state,
static void static void
test_paint (TestState *state) test_paint (TestState *state)
{ {
CoglTexture2D *tex_2d;
CoglTexture *tex; CoglTexture *tex;
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
CoglFramebuffer *framebuffer; CoglFramebuffer *framebuffer;
CoglPipeline *opaque_pipeline; CoglPipeline *opaque_pipeline;
CoglPipeline *texture_pipeline; CoglPipeline *texture_pipeline;
tex_2d = cogl_texture_2d_new_with_size (test_ctx, tex = cogl_texture_2d_new_with_size (test_ctx,
state->fb_width, state->fb_width,
state->fb_height); state->fb_height);
tex = tex_2d;
offscreen = cogl_offscreen_new_with_texture (tex); offscreen = cogl_offscreen_new_with_texture (tex);
framebuffer = COGL_FRAMEBUFFER (offscreen); framebuffer = COGL_FRAMEBUFFER (offscreen);
@ -102,7 +100,7 @@ test_paint (TestState *state)
cogl_object_unref (opaque_pipeline); cogl_object_unref (opaque_pipeline);
cogl_object_unref (texture_pipeline); cogl_object_unref (texture_pipeline);
cogl_object_unref (tex_2d); g_object_unref (tex);
cogl_framebuffer_pop_matrix (test_fb); cogl_framebuffer_pop_matrix (test_fb);
@ -123,7 +121,6 @@ static void
test_flush (TestState *state) test_flush (TestState *state)
{ {
CoglPipeline *pipeline; CoglPipeline *pipeline;
CoglTexture2D *tex_2d;
CoglTexture *tex; CoglTexture *tex;
CoglOffscreen *offscreen; CoglOffscreen *offscreen;
CoglFramebuffer *framebuffer; CoglFramebuffer *framebuffer;
@ -139,9 +136,8 @@ test_flush (TestState *state)
the contents of the texture will automatically flush the the contents of the texture will automatically flush the
journal */ journal */
tex_2d = cogl_texture_2d_new_with_size (test_ctx, tex = cogl_texture_2d_new_with_size (test_ctx,
16, 16); /* width/height */ 16, 16); /* width/height */
tex = tex_2d;
offscreen = cogl_offscreen_new_with_texture (tex); offscreen = cogl_offscreen_new_with_texture (tex);
framebuffer = COGL_FRAMEBUFFER (offscreen); framebuffer = COGL_FRAMEBUFFER (offscreen);
@ -184,7 +180,7 @@ test_flush (TestState *state)
0xff0000ff); 0xff0000ff);
} }
cogl_object_unref (tex_2d); g_object_unref (tex);
g_object_unref (offscreen); g_object_unref (offscreen);
} }

View File

@ -5,7 +5,7 @@
/* Keep track of the number of textures that we've created and are /* Keep track of the number of textures that we've created and are
* still alive */ * still alive */
static int destroyed_texture_count = 0; static int destroyed_texture_count = 0;
static GQuark texture_data_key = 0;
#define N_TEXTURES 3 #define N_TEXTURES 3
static void static void
@ -19,8 +19,8 @@ create_texture (void)
{ {
static const guint8 data[] = static const guint8 data[] =
{ 0xff, 0xff, 0xff, 0xff }; { 0xff, 0xff, 0xff, 0xff };
static CoglUserDataKey texture_data_key; texture_data_key = g_quark_from_static_string ("-cogl-test-pipeline-cache-unrefs-texture");
CoglTexture2D *tex_2d; CoglTexture *tex_2d;
tex_2d = cogl_texture_2d_new_from_data (test_ctx, tex_2d = cogl_texture_2d_new_from_data (test_ctx,
1, 1, /* width / height */ 1, 1, /* width / height */
@ -31,8 +31,8 @@ create_texture (void)
/* Set some user data on the texture so we can track when it has /* Set some user data on the texture so we can track when it has
* been destroyed */ * been destroyed */
cogl_object_set_user_data (COGL_OBJECT (tex_2d), g_object_set_qdata_full (G_OBJECT (tex_2d),
&texture_data_key, texture_data_key,
GINT_TO_POINTER (1), GINT_TO_POINTER (1),
free_texture_cb); free_texture_cb);
@ -53,7 +53,7 @@ test_pipeline_cache_unrefs_texture (void)
{ {
CoglTexture *tex = create_texture (); CoglTexture *tex = create_texture ();
cogl_pipeline_set_layer_texture (pipeline, i, tex); cogl_pipeline_set_layer_texture (pipeline, i, tex);
cogl_object_unref (tex); g_object_unref (tex);
} }
/* Draw something with the pipeline to ensure it gets into the /* Draw something with the pipeline to ensure it gets into the

View File

@ -11,7 +11,7 @@ test_pipeline_shader_state (void)
CoglFramebuffer *fb; CoglFramebuffer *fb;
CoglPipeline *base_pipeline; CoglPipeline *base_pipeline;
CoglPipeline *draw_pipeline; CoglPipeline *draw_pipeline;
CoglTexture2D *tex; CoglTexture *tex;
CoglSnippet *snippet; CoglSnippet *snippet;
float width = cogl_framebuffer_get_width (test_fb); float width = cogl_framebuffer_get_width (test_fb);

View File

@ -122,8 +122,8 @@ paint (TestState *state)
0, 0, 0, 0,
state->width, state->height); state->width, state->height);
cogl_object_unref (tex1); g_object_unref (tex1);
cogl_object_unref (tex0); g_object_unref (tex0);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
} }

View File

@ -77,7 +77,7 @@ create_and_fill_bitmap (void)
static CoglTexture * static CoglTexture *
create_texture_from_bitmap (CoglBitmap *bitmap) create_texture_from_bitmap (CoglBitmap *bitmap)
{ {
CoglTexture2D *texture; CoglTexture *texture;
texture = cogl_texture_2d_new_from_bitmap (bitmap); texture = cogl_texture_2d_new_from_bitmap (bitmap);
@ -150,7 +150,7 @@ test_pixel_buffer_map (void)
1.0f, -1.0f); 1.0f, -1.0f);
g_object_unref (bitmap); g_object_unref (bitmap);
cogl_object_unref (texture); g_object_unref (texture);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
check_colours (0x0000ffff, check_colours (0x0000ffff,
@ -195,7 +195,7 @@ test_pixel_buffer_set_data (void)
1.0f, -1.0f); 1.0f, -1.0f);
g_object_unref (bitmap); g_object_unref (bitmap);
cogl_object_unref (texture); g_object_unref (texture);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
check_colours (0x0000ffff, check_colours (0x0000ffff,
@ -210,7 +210,7 @@ test_pixel_buffer_set_data (void)
static CoglTexture * static CoglTexture *
create_white_texture (void) create_white_texture (void)
{ {
CoglTexture2D *texture; CoglTexture *texture;
uint8_t *data = g_malloc (BITMAP_SIZE * BITMAP_SIZE * 4); uint8_t *data = g_malloc (BITMAP_SIZE * BITMAP_SIZE * 4);
memset (data, 255, BITMAP_SIZE * BITMAP_SIZE * 4); memset (data, 255, BITMAP_SIZE * BITMAP_SIZE * 4);
@ -256,7 +256,7 @@ test_pixel_buffer_sub_region (void)
1.0f, -1.0f); 1.0f, -1.0f);
g_object_unref (bitmap); g_object_unref (bitmap);
cogl_object_unref (texture); g_object_unref (texture);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
check_colours (0xffffffff, check_colours (0xffffffff,

View File

@ -26,7 +26,7 @@ do_test (gboolean check_orientation,
int fb_height = cogl_framebuffer_get_height (test_fb); int fb_height = cogl_framebuffer_get_height (test_fb);
CoglPrimitive *prim; CoglPrimitive *prim;
GError *error = NULL; GError *error = NULL;
CoglTexture2D *tex_2d; CoglTexture *tex_2d;
CoglPipeline *pipeline, *solid_pipeline; CoglPipeline *pipeline, *solid_pipeline;
int tex_height; int tex_height;
@ -136,7 +136,7 @@ do_test (gboolean check_orientation,
cogl_object_unref (prim); cogl_object_unref (prim);
cogl_object_unref (solid_pipeline); cogl_object_unref (solid_pipeline);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
cogl_object_unref (tex_2d); g_object_unref (tex_2d);
test_utils_check_pixel (test_fb, test_utils_check_pixel (test_fb,
POINT_SIZE - POINT_SIZE / 4, POINT_SIZE - POINT_SIZE / 4,

View File

@ -26,7 +26,7 @@ do_test (gboolean check_orientation,
int fb_height = cogl_framebuffer_get_height (test_fb); int fb_height = cogl_framebuffer_get_height (test_fb);
CoglPrimitive *prim; CoglPrimitive *prim;
GError *error = NULL; GError *error = NULL;
CoglTexture2D *tex_2d; CoglTexture *tex_2d;
CoglPipeline *pipeline, *solid_pipeline; CoglPipeline *pipeline, *solid_pipeline;
int tex_height; int tex_height;
@ -136,7 +136,7 @@ do_test (gboolean check_orientation,
cogl_object_unref (prim); cogl_object_unref (prim);
cogl_object_unref (solid_pipeline); cogl_object_unref (solid_pipeline);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
cogl_object_unref (tex_2d); g_object_unref (tex_2d);
test_utils_check_pixel (test_fb, test_utils_check_pixel (test_fb,
POINT_SIZE - POINT_SIZE / 4, POINT_SIZE - POINT_SIZE / 4,

View File

@ -49,7 +49,7 @@ make_texture (uint32_t color,
CoglPixelFormat src_format, CoglPixelFormat src_format,
MakeTextureFlags flags) MakeTextureFlags flags)
{ {
CoglTexture2D *tex_2d; CoglTexture *tex;
guchar *tex_data = gen_tex_data (color); guchar *tex_data = gen_tex_data (color);
CoglBitmap *bmp = cogl_bitmap_new_for_data (test_ctx, CoglBitmap *bmp = cogl_bitmap_new_for_data (test_ctx,
QUAD_WIDTH, QUAD_WIDTH,
@ -58,16 +58,16 @@ make_texture (uint32_t color,
QUAD_WIDTH * 4, QUAD_WIDTH * 4,
tex_data); tex_data);
tex_2d = cogl_texture_2d_new_from_bitmap (bmp); tex = cogl_texture_2d_new_from_bitmap (bmp);
if (flags & TEXTURE_FLAG_SET_PREMULTIPLIED) if (flags & TEXTURE_FLAG_SET_PREMULTIPLIED)
cogl_texture_set_premultiplied (tex_2d, TRUE); cogl_texture_set_premultiplied (tex, TRUE);
else if (flags & TEXTURE_FLAG_SET_UNPREMULTIPLIED) else if (flags & TEXTURE_FLAG_SET_UNPREMULTIPLIED)
cogl_texture_set_premultiplied (tex_2d, FALSE); cogl_texture_set_premultiplied (tex, FALSE);
g_object_unref (bmp); g_object_unref (bmp);
return tex_2d; return tex;
} }
static void static void

View File

@ -183,7 +183,7 @@ test_paint (TestState *state)
(PRIM_COLOR >> 8) & 0xff, (PRIM_COLOR >> 8) & 0xff,
(PRIM_COLOR >> 0) & 0xff); (PRIM_COLOR >> 0) & 0xff);
cogl_pipeline_set_layer_texture (pipeline, 0, tex); cogl_pipeline_set_layer_texture (pipeline, 0, tex);
cogl_object_unref (tex); g_object_unref (tex);
for (i = 0; i < G_N_ELEMENTS (test_prim_funcs); i++) for (i = 0; i < G_N_ELEMENTS (test_prim_funcs); i++)
{ {

View File

@ -11,7 +11,7 @@
static const uint8_t tex_data[4] = { 0x12, 0x34, 0x56, 0x78 }; static const uint8_t tex_data[4] = { 0x12, 0x34, 0x56, 0x78 };
static void static void
test_read_byte (CoglTexture2D *tex_2d, test_read_byte (CoglTexture *tex_2d,
CoglPixelFormat format, CoglPixelFormat format,
uint8_t expected_byte) uint8_t expected_byte)
{ {
@ -26,7 +26,7 @@ test_read_byte (CoglTexture2D *tex_2d,
} }
static void static void
test_read_short (CoglTexture2D *tex_2d, test_read_short (CoglTexture *tex_2d,
CoglPixelFormat format, CoglPixelFormat format,
...) ...)
{ {
@ -65,7 +65,7 @@ test_read_short (CoglTexture2D *tex_2d,
} }
static void static void
test_read_888 (CoglTexture2D *tex_2d, test_read_888 (CoglTexture *tex_2d,
CoglPixelFormat format, CoglPixelFormat format,
uint32_t expected_pixel) uint32_t expected_pixel)
{ {
@ -80,7 +80,7 @@ test_read_888 (CoglTexture2D *tex_2d,
} }
static void static void
test_read_88 (CoglTexture2D *tex_2d, test_read_88 (CoglTexture *tex_2d,
CoglPixelFormat format, CoglPixelFormat format,
uint32_t expected_pixel) uint32_t expected_pixel)
{ {
@ -97,7 +97,7 @@ test_read_88 (CoglTexture2D *tex_2d,
} }
static void static void
test_read_8888 (CoglTexture2D *tex_2d, test_read_8888 (CoglTexture *tex_2d,
CoglPixelFormat format, CoglPixelFormat format,
uint32_t expected_pixel) uint32_t expected_pixel)
{ {
@ -120,7 +120,7 @@ test_read_8888 (CoglTexture2D *tex_2d,
} }
static void static void
test_read_int (CoglTexture2D *tex_2d, test_read_int (CoglTexture *tex_2d,
CoglPixelFormat format, CoglPixelFormat format,
...) ...)
{ {
@ -161,7 +161,7 @@ test_read_int (CoglTexture2D *tex_2d,
static void static void
test_read_texture_formats (void) test_read_texture_formats (void)
{ {
CoglTexture2D *tex_2d; CoglTexture *tex_2d;
tex_2d = cogl_texture_2d_new_from_data (test_ctx, tex_2d = cogl_texture_2d_new_from_data (test_ctx,
1, 1, /* width / height */ 1, 1, /* width / height */
@ -215,7 +215,7 @@ test_read_texture_formats (void)
2, 0x78, 10, 0x56, 10, 0x34, 10, 0x12, 2, 0x78, 10, 0x56, 10, 0x34, 10, 0x12,
-1); -1);
cogl_object_unref (tex_2d); g_object_unref (tex_2d);
if (cogl_test_verbose ()) if (cogl_test_verbose ())
g_print ("OK\n"); g_print ("OK\n");

View File

@ -125,7 +125,7 @@ on_after_paint (ClutterActor *actor,
g_free (pixelsc); g_free (pixelsc);
cogl_object_unref (tex); g_object_unref (tex);
/* Restore the viewport and matrices state */ /* Restore the viewport and matrices state */
cogl_set_viewport (saved_viewport[0], cogl_set_viewport (saved_viewport[0],

Some files were not shown because too many files have changed in this diff Show More