From 863163cc6e33778268efdba7c184d4a2d7962fe4 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Mon, 18 Sep 2023 16:58:36 +0200 Subject: [PATCH] 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: --- clutter/clutter/clutter-blur.c | 14 +- clutter/clutter/clutter-canvas.c | 6 +- clutter/clutter/clutter-image.c | 12 +- clutter/clutter/clutter-offscreen-effect.c | 6 +- clutter/clutter/clutter-paint-nodes.c | 10 +- clutter/clutter/clutter-stage-view.c | 13 +- clutter/clutter/clutter-stage.c | 12 +- clutter/clutter/clutter-texture-content.c | 25 +- cogl/cogl-pango/cogl-pango-display-list.c | 4 +- cogl/cogl-pango/cogl-pango-glyph-cache.c | 16 +- cogl/cogl-pango/cogl-pango-pipeline-cache.c | 8 +- cogl/cogl-pango/cogl-pango-render.c | 2 +- cogl/cogl/cogl-atlas-texture-private.h | 11 +- cogl/cogl/cogl-atlas-texture.c | 255 ++-- cogl/cogl/cogl-atlas-texture.h | 44 +- cogl/cogl/cogl-atlas.c | 47 +- cogl/cogl/cogl-blit.c | 8 +- cogl/cogl/cogl-context-private.h | 2 +- cogl/cogl/cogl-context.c | 2 +- cogl/cogl/cogl-gtype-private.h | 55 - cogl/cogl/cogl-meta-texture.c | 30 +- cogl/cogl/cogl-meta-texture.h | 13 +- cogl/cogl/cogl-offscreen.c | 8 +- cogl/cogl/cogl-pipeline-layer-state.c | 6 +- cogl/cogl/cogl-pipeline-layer.c | 4 +- cogl/cogl/cogl-pipeline.c | 4 +- cogl/cogl/cogl-primitive-texture.c | 21 +- cogl/cogl/cogl-primitive-texture.h | 52 +- cogl/cogl/cogl-primitives.c | 7 +- cogl/cogl/cogl-sub-texture-private.h | 7 +- cogl/cogl/cogl-sub-texture.c | 227 +-- cogl/cogl/cogl-sub-texture.h | 39 +- cogl/cogl/cogl-texture-2d-private.h | 10 +- cogl/cogl/cogl-texture-2d-sliced-private.h | 7 +- cogl/cogl/cogl-texture-2d-sliced.c | 1301 +++++++++-------- cogl/cogl/cogl-texture-2d-sliced.h | 47 +- cogl/cogl/cogl-texture-2d.c | 404 ++--- cogl/cogl/cogl-texture-2d.h | 53 +- cogl/cogl/cogl-texture-private.h | 204 ++- cogl/cogl/cogl-texture.c | 285 ++-- cogl/cogl/cogl-texture.h | 53 +- cogl/cogl/deprecated/cogl-type-casts.h | 3 - cogl/cogl/driver/gl/cogl-pipeline-opengl.c | 2 +- cogl/cogl/driver/gl/cogl-texture-2d-gl.c | 32 +- cogl/cogl/driver/gl/cogl-texture-gl.c | 23 +- .../driver/gl/gl/cogl-texture-driver-gl.c | 2 +- .../driver/gl/gles/cogl-texture-driver-gles.c | 2 +- .../winsys/cogl-texture-pixmap-x11-private.h | 8 +- cogl/cogl/winsys/cogl-texture-pixmap-x11.c | 691 ++++----- cogl/cogl/winsys/cogl-texture-pixmap-x11.h | 42 +- cogl/cogl/winsys/cogl-winsys-egl-x11.c | 12 +- cogl/cogl/winsys/cogl-winsys-glx.c | 19 +- src/backends/meta-cursor-sprite-xcursor.c | 6 +- src/backends/meta-cursor.c | 10 +- src/backends/meta-screen-cast-stream-src.c | 13 +- src/backends/native/meta-drm-buffer-gbm.c | 6 +- src/backends/native/meta-renderer-native.c | 18 +- .../x11/cm/meta-cursor-sprite-xfixes.c | 18 +- .../x11/nested/meta-renderer-x11-nested.c | 4 +- src/compositor/cogl-utils.c | 6 +- src/compositor/meta-background-image.c | 6 +- src/compositor/meta-background.c | 20 +- src/compositor/meta-multi-texture.c | 2 +- src/compositor/meta-shadow-factory.c | 20 +- src/compositor/meta-shaped-texture.c | 20 +- src/compositor/meta-surface-actor-x11.c | 2 +- src/compositor/meta-texture-mipmap.c | 6 +- src/compositor/meta-window-actor-x11.c | 6 +- src/compositor/meta-window-actor.c | 9 +- .../interactive/test-cogl-multitexture.c | 8 +- .../clutter/interactive/test-cogl-offscreen.c | 2 +- .../interactive/test-cogl-point-sprites.c | 2 +- .../interactive/test-cogl-tex-polygon.c | 4 +- .../clutter/interactive/test-cogl-tex-tile.c | 2 +- src/tests/clutter/test-utils.h | 8 +- src/tests/cogl-test-utils.c | 38 +- src/tests/cogl/conform/test-alpha-test.c | 4 +- src/tests/cogl/conform/test-alpha-textures.c | 6 +- src/tests/cogl/conform/test-atlas-migration.c | 4 +- .../cogl/conform/test-backface-culling.c | 4 +- src/tests/cogl/conform/test-blend-strings.c | 4 +- .../cogl/conform/test-copy-replace-texture.c | 16 +- .../cogl/conform/test-framebuffer-get-bits.c | 8 +- src/tests/cogl/conform/test-journal.c | 8 +- .../cogl/conform/test-just-vertex-shader.c | 2 +- .../cogl/conform/test-map-buffer-range.c | 4 +- src/tests/cogl/conform/test-multitexture.c | 4 +- src/tests/cogl/conform/test-npot-texture.c | 2 +- .../conform/test-offscreen-texture-formats.c | 36 +- src/tests/cogl/conform/test-offscreen.c | 18 +- .../test-pipeline-cache-unrefs-texture.c | 16 +- .../cogl/conform/test-pipeline-shader-state.c | 2 +- .../cogl/conform/test-pipeline-user-matrix.c | 4 +- src/tests/cogl/conform/test-pixel-buffer.c | 10 +- .../conform/test-point-sprite-known-failure.c | 4 +- src/tests/cogl/conform/test-point-sprite.c | 4 +- src/tests/cogl/conform/test-premult.c | 10 +- src/tests/cogl/conform/test-primitive.c | 2 +- .../cogl/conform/test-read-texture-formats.c | 24 +- src/tests/cogl/conform/test-readpixels.c | 2 +- src/tests/cogl/conform/test-snippets.c | 6 +- src/tests/cogl/conform/test-sparse-pipeline.c | 4 +- src/tests/cogl/conform/test-sub-texture.c | 34 +- .../cogl/conform/test-texture-get-set-data.c | 2 +- src/tests/cogl/conform/test-texture-mipmaps.c | 2 +- .../cogl/conform/test-texture-no-allocate.c | 8 +- src/tests/cogl/conform/test-texture-rg.c | 6 +- src/tests/cogl/conform/test-viewport.c | 2 +- src/tests/cogl/conform/test-wrap-modes.c | 6 +- .../cogl/conform/test-write-texture-formats.c | 8 +- src/wayland/meta-wayland-buffer.c | 19 +- src/wayland/meta-wayland-dma-buf.c | 8 +- src/wayland/meta-wayland-egl-stream.c | 10 +- src/wayland/meta-wayland-egl-stream.h | 4 +- .../meta-wayland-single-pixel-buffer.c | 4 +- 115 files changed, 2278 insertions(+), 2449 deletions(-) diff --git a/clutter/clutter/clutter-blur.c b/clutter/clutter/clutter-blur.c index c630dc7e0..6a43baa4f 100644 --- a/clutter/clutter/clutter-blur.c +++ b/clutter/clutter/clutter-blur.c @@ -230,7 +230,7 @@ create_fbo (ClutterBlur *blur, float height; float width; - cogl_clear_object (&pass->texture); + g_clear_object (&pass->texture); g_clear_object (&pass->framebuffer); width = cogl_texture_get_width (blur->source_texture); @@ -238,9 +238,9 @@ create_fbo (ClutterBlur *blur, scaled_width = floorf (width / blur->downscale_factor); scaled_height = floorf (height / blur->downscale_factor); - pass->texture = COGL_TEXTURE (cogl_texture_2d_new_with_size (ctx, - scaled_width, - scaled_height)); + pass->texture = cogl_texture_2d_new_with_size (ctx, + scaled_width, + scaled_height); if (!pass->texture) return FALSE; @@ -327,7 +327,7 @@ static void clear_blur_pass (BlurPass *pass) { cogl_clear_object (&pass->pipeline); - cogl_clear_object (&pass->texture); + g_clear_object (&pass->texture); g_clear_object (&pass->framebuffer); } @@ -358,7 +358,7 @@ clutter_blur_new (CoglTexture *texture, blur = g_new0 (ClutterBlur, 1); 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); 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[HORIZONTAL]); - cogl_clear_object (&blur->source_texture); + g_clear_object (&blur->source_texture); g_free (blur); } diff --git a/clutter/clutter/clutter-canvas.c b/clutter/clutter/clutter-canvas.c index 13a26c149..1026e104e 100644 --- a/clutter/clutter/clutter-canvas.c +++ b/clutter/clutter/clutter-canvas.c @@ -128,7 +128,7 @@ clutter_canvas_finalize (GObject *gobject) ClutterCanvasPrivate *priv = CLUTTER_CANVAS (gobject)->priv; g_clear_object (&priv->buffer); - cogl_clear_object (&priv->texture); + g_clear_object (&priv->texture); G_OBJECT_CLASS (clutter_canvas_parent_class)->finalize (gobject); } @@ -317,10 +317,10 @@ clutter_canvas_paint_content (ClutterContent *content, return; if (priv->dirty) - cogl_clear_object (&priv->texture); + g_clear_object (&priv->texture); 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) return; diff --git a/clutter/clutter/clutter-image.c b/clutter/clutter/clutter-image.c index 3b0a8f2b4..c0cb09e03 100644 --- a/clutter/clutter/clutter-image.c +++ b/clutter/clutter/clutter-image.c @@ -70,7 +70,7 @@ create_texture_from_data (unsigned int width, { CoglContext *ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ()); - CoglTexture2D *texture_2d; + CoglTexture *texture_2d; texture_2d = cogl_texture_2d_new_from_data (ctx, width, @@ -80,7 +80,7 @@ create_texture_from_data (unsigned int width, data, error); - return texture_2d ? COGL_TEXTURE (texture_2d) : NULL; + return texture_2d; } static void @@ -111,7 +111,7 @@ clutter_image_finalize (GObject *gobject) ClutterImage *image = CLUTTER_IMAGE (gobject); 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); } @@ -248,7 +248,7 @@ clutter_image_set_data (ClutterImage *image, priv = clutter_image_get_instance_private (image); if (priv->texture != NULL) - cogl_object_unref (priv->texture); + g_object_unref (priv->texture); priv->texture = create_texture_from_data (width, height, @@ -306,7 +306,7 @@ clutter_image_set_bytes (ClutterImage *image, priv = clutter_image_get_instance_private (image); if (priv->texture != NULL) - cogl_object_unref (priv->texture); + g_object_unref (priv->texture); priv->texture = create_texture_from_data (width, height, @@ -391,7 +391,7 @@ clutter_image_set_area (ClutterImage *image, if (!res) { - cogl_clear_object (&priv->texture); + g_clear_object (&priv->texture); } } diff --git a/clutter/clutter/clutter-offscreen-effect.c b/clutter/clutter/clutter-offscreen-effect.c index 371271e97..dc62eec10 100644 --- a/clutter/clutter/clutter-offscreen-effect.c +++ b/clutter/clutter/clutter-offscreen-effect.c @@ -155,7 +155,7 @@ clutter_offscreen_effect_real_create_texture (ClutterOffscreenEffect *effect, CoglContext *ctx = 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 @@ -256,7 +256,7 @@ update_fbo (ClutterEffect *effect, return TRUE; } - g_clear_pointer (&priv->texture, cogl_object_unref); + g_clear_object (&priv->texture); g_clear_object (&priv->offscreen); priv->texture = @@ -576,7 +576,7 @@ clutter_offscreen_effect_finalize (GObject *gobject) ClutterOffscreenEffectPrivate *priv = self->priv; 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_OBJECT_CLASS (clutter_offscreen_effect_parent_class)->finalize (gobject); diff --git a/clutter/clutter/clutter-paint-nodes.c b/clutter/clutter/clutter-paint-nodes.c index 3fec0d609..f551a098b 100644 --- a/clutter/clutter/clutter-paint-nodes.c +++ b/clutter/clutter/clutter-paint-nodes.c @@ -710,7 +710,7 @@ clutter_scaling_filter_to_cogl_pipeline_filter (ClutterScalingFilter filter) * Creates a new #ClutterPaintNode that will paint the passed @texture. * * 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 * 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; 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); @@ -1782,7 +1782,6 @@ clutter_blur_node_new (unsigned int width, g_autoptr (GError) error = NULL; ClutterLayerNode *layer_node; ClutterBlurNode *blur_node; - CoglTexture2D *tex_2d; CoglContext *context; CoglTexture *texture; 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->sigma = sigma; 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); offscreen = cogl_offscreen_new_with_texture (texture); - cogl_object_unref (tex_2d); + g_object_unref (texture); if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (offscreen), &error)) { g_warning ("Unable to allocate paint node offscreen: %s", diff --git a/clutter/clutter/clutter-stage-view.c b/clutter/clutter/clutter-stage-view.c index 168746dd4..b12b61b9a 100644 --- a/clutter/clutter/clutter-stage-view.c +++ b/clutter/clutter/clutter-stage-view.c @@ -381,20 +381,19 @@ create_offscreen_framebuffer (CoglContext *context, GError **error) { CoglOffscreen *framebuffer; - CoglTexture2D *texture; + CoglTexture *texture; texture = cogl_texture_2d_new_with_size (context, width, height); - cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (texture), - FALSE); + cogl_primitive_texture_set_auto_mipmap (texture, 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; } - framebuffer = cogl_offscreen_new_with_texture (COGL_TEXTURE (texture)); - cogl_object_unref (texture); + framebuffer = cogl_offscreen_new_with_texture (texture); + g_object_unref (texture); if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (framebuffer), error)) { g_object_unref (framebuffer); diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c index 07e934ee0..58d61f299 100644 --- a/clutter/clutter/clutter-stage.c +++ b/clutter/clutter/clutter-stage.c @@ -2784,7 +2784,7 @@ clutter_stage_paint_to_buffer (ClutterStage *stage, CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend); int texture_width, texture_height; - CoglTexture2D *texture; + CoglTexture *texture; CoglOffscreen *offscreen; CoglFramebuffer *framebuffer; CoglBitmap *bitmap; @@ -2802,10 +2802,10 @@ clutter_stage_paint_to_buffer (ClutterStage *stage, return FALSE; } - offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (texture)); + offscreen = cogl_offscreen_new_with_texture (texture); framebuffer = COGL_FRAMEBUFFER (offscreen); - cogl_object_unref (texture); + g_object_unref (texture); if (!cogl_framebuffer_allocate (framebuffer, error)) return FALSE; @@ -2853,7 +2853,7 @@ clutter_stage_paint_to_content (ClutterStage *stage, CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend); int texture_width, texture_height; - CoglTexture2D *texture; + CoglTexture *texture; CoglOffscreen *offscreen; g_autoptr (CoglFramebuffer) framebuffer = NULL; @@ -2870,10 +2870,10 @@ clutter_stage_paint_to_content (ClutterStage *stage, return NULL; } - offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (texture)); + offscreen = cogl_offscreen_new_with_texture (texture); framebuffer = COGL_FRAMEBUFFER (offscreen); - cogl_object_unref (texture); + g_object_unref (texture); if (!cogl_framebuffer_allocate (framebuffer, error)) return NULL; diff --git a/clutter/clutter/clutter-texture-content.c b/clutter/clutter/clutter-texture-content.c index c90c4716c..78e2f6073 100644 --- a/clutter/clutter/clutter-texture-content.c +++ b/clutter/clutter/clutter-texture-content.c @@ -51,7 +51,7 @@ clutter_texture_content_finalize (GObject *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); } @@ -114,7 +114,7 @@ clutter_content_iface_init (ClutterContentInterface *iface) * Creates a new [class@TextureContent] instance for @texture, taking an * 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] * 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) { - texture_content->texture = - COGL_TEXTURE (cogl_sub_texture_new (cogl_context, - texture, - clip->x, - clip->y, - clip->width, - clip->height)); + texture_content->texture = cogl_sub_texture_new (cogl_context, + texture, + clip->x, + clip->y, + clip->width, + clip->height); } else { - texture_content->texture = cogl_object_ref (texture); + texture_content->texture = g_object_ref (texture); } return CLUTTER_CONTENT (texture_content); @@ -155,13 +154,13 @@ clutter_texture_content_new_from_texture (CoglTexture *texture, * clutter_texture_content_get_texture: * @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] * 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 * clutter_texture_content_get_texture (ClutterTextureContent *texture_content) diff --git a/cogl/cogl-pango/cogl-pango-display-list.c b/cogl/cogl-pango/cogl-pango-display-list.c index c66e07456..8accef760 100644 --- a/cogl/cogl-pango/cogl-pango-display-list.c +++ b/cogl/cogl-pango/cogl-pango-display-list.c @@ -167,7 +167,7 @@ _cogl_pango_display_list_add_texture (CoglPangoDisplayList *dl, node->color_override = dl->color_override; node->color = dl->color; node->pipeline = NULL; - node->d.texture.texture = cogl_object_ref (texture); + node->d.texture.texture = g_object_ref (texture); node->d.texture.rectangles = g_array_new (FALSE, FALSE, sizeof (CoglPangoDisplayListRectangle)); 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); 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) cogl_object_unref (node->d.texture.primitive); } diff --git a/cogl/cogl-pango/cogl-pango-glyph-cache.c b/cogl/cogl-pango/cogl-pango-glyph-cache.c index cb77efcda..820d28c30 100644 --- a/cogl/cogl-pango/cogl-pango-glyph-cache.c +++ b/cogl/cogl-pango/cogl-pango-glyph-cache.c @@ -76,7 +76,7 @@ static void cogl_pango_glyph_cache_value_free (CoglPangoGlyphCacheValue *value) { if (value->texture) - cogl_object_unref (value->texture); + g_object_unref (value->texture); g_free (value); } @@ -184,16 +184,16 @@ cogl_pango_glyph_cache_free (CoglPangoGlyphCache *cache) } static void -cogl_pango_glyph_cache_update_position_cb (void *user_data, - CoglTexture *new_texture, +cogl_pango_glyph_cache_update_position_cb (void *user_data, + CoglTexture *new_texture, const CoglRectangleMapEntry *rect) { CoglPangoGlyphCacheValue *value = user_data; float tex_width, tex_height; if (value->texture) - cogl_object_unref (value->texture); - value->texture = cogl_object_ref (new_texture); + g_object_unref (value->texture); + value->texture = g_object_ref (new_texture); tex_width = cogl_texture_get_width (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, CoglPangoGlyphCacheValue *value) { - CoglAtlasTexture *texture; + CoglTexture *texture; GError *ignore_error = NULL; 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, value->draw_width, value->draw_height); - if (!cogl_texture_allocate (COGL_TEXTURE (texture), &ignore_error)) + if (!cogl_texture_allocate (texture, &ignore_error)) { g_error_free (ignore_error); return FALSE; } - value->texture = COGL_TEXTURE (texture); + value->texture = texture; value->tx1 = 0; value->ty1 = 0; value->tx2 = 1; diff --git a/cogl/cogl-pango/cogl-pango-pipeline-cache.c b/cogl/cogl-pango/cogl-pango-pipeline-cache.c index 0aa7e0db8..f1720acef 100644 --- a/cogl/cogl-pango/cogl-pango-pipeline-cache.c +++ b/cogl/cogl-pango/cogl-pango-pipeline-cache.c @@ -64,7 +64,7 @@ _cogl_pango_pipeline_cache_value_destroy (void *data) CoglPangoPipelineCacheEntry *cache_entry = data; 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 reference */ @@ -169,7 +169,7 @@ pipeline_destroy_notify_cb (void *user_data) CoglPipeline * _cogl_pango_pipeline_cache_get (CoglPangoPipelineCache *cache, - CoglTexture *texture) + CoglTexture *texture) { CoglPangoPipelineCacheEntry *entry; PipelineDestroyNotifyData *destroy_data; @@ -188,7 +188,7 @@ _cogl_pango_pipeline_cache_get (CoglPangoPipelineCache *cache, { 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) base = get_base_texture_alpha_pipeline (cache); @@ -216,7 +216,7 @@ _cogl_pango_pipeline_cache_get (CoglPangoPipelineCache *cache, pipeline_destroy_notify_cb); g_hash_table_insert (cache->hash_table, - texture ? cogl_object_ref (texture) : NULL, + texture ? g_object_ref (texture) : NULL, entry); /* This doesn't take a reference on the pipeline so that it will use diff --git a/cogl/cogl-pango/cogl-pango-render.c b/cogl/cogl-pango/cogl-pango-render.c index 0e96822a1..a86105d1d 100644 --- a/cogl/cogl-pango/cogl-pango-render.c +++ b/cogl/cogl-pango/cogl-pango-render.c @@ -175,7 +175,7 @@ cogl_pango_renderer_draw_glyph (CoglPangoRenderer *priv, the neighbouring glyphs are coming from the same atlas and bundle 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->ty1, cache_value->tx2, diff --git a/cogl/cogl/cogl-atlas-texture-private.h b/cogl/cogl/cogl-atlas-texture-private.h index 9217dfdbf..251a2c3b6 100644 --- a/cogl/cogl/cogl-atlas-texture-private.h +++ b/cogl/cogl/cogl-atlas-texture-private.h @@ -30,7 +30,6 @@ #pragma once -#include "cogl/cogl-object-private.h" #include "cogl/cogl-texture-private.h" #include "cogl/cogl-rectangle-map.h" #include "cogl/cogl-atlas.h" @@ -38,7 +37,7 @@ struct _CoglAtlasTexture { - CoglTexture _parent; + CoglTexture parent_instance; /* The format that the texture is in. This isn't necessarily the same format as the atlas texture because we can store @@ -60,6 +59,11 @@ struct _CoglAtlasTexture CoglTexture *sub_texture; }; +struct _CoglAtlasTextureClass +{ + CoglTextureClass parent_class; +}; + COGL_EXPORT void _cogl_atlas_texture_add_reorganize_callback (CoglContext *ctx, GHookFunc callback, @@ -69,6 +73,3 @@ COGL_EXPORT void _cogl_atlas_texture_remove_reorganize_callback (CoglContext *ctx, GHookFunc callback, void *user_data); - -gboolean -_cogl_is_atlas_texture (void *object); diff --git a/cogl/cogl/cogl-atlas-texture.c b/cogl/cogl/cogl-atlas-texture.c index bef2db8ff..31cd0f6e8 100644 --- a/cogl/cogl/cogl-atlas-texture.c +++ b/cogl/cogl/cogl-atlas-texture.c @@ -40,31 +40,50 @@ #include "cogl/cogl-texture-2d-private.h" #include "cogl/cogl-sub-texture-private.h" #include "cogl/cogl-context-private.h" -#include "cogl/cogl-object-private.h" #include "cogl/cogl-texture-driver.h" #include "cogl/cogl-rectangle-map.h" #include "cogl/cogl-journal-private.h" #include "cogl/cogl-atlas.h" #include "cogl/cogl1-context.h" #include "cogl/cogl-sub-texture.h" -#include "cogl/cogl-gtype-private.h" #include "cogl/driver/gl/cogl-texture-gl-private.h" #include -static void _cogl_atlas_texture_free (CoglAtlasTexture *sub_tex); static GQuark atlas_private_key = 0; -COGL_TEXTURE_DEFINE (AtlasTexture, atlas_texture); -COGL_GTYPE_DEFINE_CLASS (AtlasTexture, atlas_texture); +G_DEFINE_FINAL_TYPE (CoglAtlasTexture, cogl_atlas_texture, COGL_TYPE_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, 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 1-pixel border */ return cogl_sub_texture_new (ctx, @@ -84,9 +103,9 @@ _cogl_atlas_texture_update_position_cb (void *user_data, /* Update the sub texture */ if (atlas_tex->sub_texture) - cogl_object_unref (atlas_tex->sub_texture); - atlas_tex->sub_texture = COGL_TEXTURE ( - _cogl_atlas_texture_create_sub_texture (new_texture, rectangle)); + g_object_unref (atlas_tex->sub_texture); + atlas_tex->sub_texture = + _cogl_atlas_texture_create_sub_texture (new_texture, rectangle); /* Update the position */ 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 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 * 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 in the atlas but it isn't a valid object yet */ if (data.textures[i]->atlas) - cogl_object_unref (data.textures[i]); + g_object_unref (data.textures[i]); } g_free (data.textures); @@ -237,10 +256,9 @@ _cogl_atlas_texture_foreach_sub_texture_in_region ( void *user_data) { CoglAtlasTexture *atlas_tex = COGL_ATLAS_TEXTURE (tex); - CoglMetaTexture *meta_texture = COGL_META_TEXTURE (atlas_tex->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_ty_1, virtual_tx_2, @@ -264,31 +282,6 @@ _cogl_atlas_texture_gl_flush_legacy_texobj_wrap_modes (CoglTexture *tex, 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 _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 to be used if it is used from a layer that is left in a texture unit */ - cogl_object_unref (atlas_tex->sub_texture); + g_object_unref (atlas_tex->sub_texture); atlas_tex->sub_texture = standalone_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); } -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 allocate_space (CoglAtlasTexture *atlas_tex, int width, @@ -710,7 +649,7 @@ allocate_space (CoglAtlasTexture *atlas_tex, GError **error) { CoglTexture *tex = COGL_TEXTURE (atlas_tex); - CoglContext *ctx = tex->context; + CoglContext *ctx = cogl_texture_get_context (tex); CoglAtlas *atlas; GSList *l; @@ -795,7 +734,7 @@ allocate_with_size (CoglAtlasTexture *atlas_tex, internal_format, error)) { - _cogl_texture_set_allocated (COGL_TEXTURE (atlas_tex), + _cogl_texture_set_allocated (tex, internal_format, loader->src.sized.width, loader->src.sized.height); @@ -869,7 +808,7 @@ _cogl_atlas_texture_allocate (CoglTexture *tex, GError **error) { 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); @@ -886,7 +825,95 @@ _cogl_atlas_texture_allocate (CoglTexture *tex, 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) { CoglTextureLoader *loader; @@ -904,7 +931,7 @@ cogl_atlas_texture_new_from_bitmap (CoglBitmap *bmp) loader); } -CoglAtlasTexture * +CoglTexture * cogl_atlas_texture_new_from_data (CoglContext *ctx, int width, int height, @@ -914,7 +941,7 @@ cogl_atlas_texture_new_from_data (CoglContext *ctx, GError **error) { CoglBitmap *bmp; - CoglAtlasTexture *atlas_tex; + CoglTexture *atlas_tex; 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); @@ -938,7 +965,7 @@ cogl_atlas_texture_new_from_data (CoglContext *ctx, if (atlas_tex && !cogl_texture_allocate (COGL_TEXTURE (atlas_tex), error)) { - cogl_object_unref (atlas_tex); + g_object_unref (atlas_tex); return NULL; } @@ -969,27 +996,3 @@ _cogl_atlas_texture_remove_reorganize_callback (CoglContext *ctx, if (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 */ - }; diff --git a/cogl/cogl/cogl-atlas-texture.h b/cogl/cogl/cogl-atlas-texture.h index 512f75087..e342b4258 100644 --- a/cogl/cogl/cogl-atlas-texture.h +++ b/cogl/cogl/cogl-atlas-texture.h @@ -41,9 +41,10 @@ G_BEGIN_DECLS /** - * SECTION:cogl-atlas-texture - * @short_description: Functions for managing textures in Cogl's global - * set of texture atlases + * CoglAtlasTexture: + * + * Functions for managing textures in Cogl's global + * set of texture atlases * * A texture atlas is a texture that contains many smaller images that * an application is interested in. These are packed together as a way @@ -63,18 +64,21 @@ G_BEGIN_DECLS * some limitations to be aware of. Please see the documentation for * #CoglMetaTexture for more details. */ +#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; -#define COGL_ATLAS_TEXTURE(tex) ((CoglAtlasTexture *) tex) -/** - * cogl_atlas_texture_get_gtype: - * - * Returns: a #GType that can be used with the GLib type system. - */ +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglAtlasTexture, g_object_unref) + 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: @@ -106,7 +110,7 @@ GType cogl_atlas_texture_get_gtype (void); * * Returns: (transfer full): A new #CoglAtlasTexture object. */ -COGL_EXPORT CoglAtlasTexture * +COGL_EXPORT CoglTexture * cogl_atlas_texture_new_with_size (CoglContext *ctx, int width, int height); @@ -149,7 +153,7 @@ cogl_atlas_texture_new_with_size (CoglContext *ctx, * Return value: (transfer full): A new #CoglAtlasTexture object or * %NULL on failure and @error will be updated. */ -COGL_EXPORT CoglAtlasTexture * +COGL_EXPORT CoglTexture * cogl_atlas_texture_new_from_data (CoglContext *ctx, int width, int height, @@ -187,19 +191,7 @@ cogl_atlas_texture_new_from_data (CoglContext *ctx, * * Returns: (transfer full): A new #CoglAtlasTexture object. */ -COGL_EXPORT CoglAtlasTexture * +COGL_EXPORT CoglTexture * 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 diff --git a/cogl/cogl/cogl-atlas.c b/cogl/cogl/cogl-atlas.c index 98a2f042f..bc565d770 100644 --- a/cogl/cogl/cogl-atlas.c +++ b/cogl/cogl/cogl-atlas.c @@ -55,7 +55,7 @@ cogl_atlas_dispose (GObject *object) COGL_NOTE (ATLAS, "%p: Atlas destroyed", atlas); if (atlas->texture) - cogl_object_unref (atlas->texture); + g_object_unref (atlas->texture); if (atlas->map) _cogl_rectangle_map_free (atlas->map); @@ -291,12 +291,12 @@ _cogl_atlas_create_map (CoglPixelFormat format, return NULL; } -static CoglTexture2D * +static CoglTexture * _cogl_atlas_create_texture (CoglAtlas *atlas, int width, int height) { - CoglTexture2D *tex; + CoglTexture *tex; GError *ignore_error = 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); - _cogl_texture_set_internal_format (COGL_TEXTURE (tex), + _cogl_texture_set_internal_format (tex, atlas->texture_format); - if (!cogl_texture_allocate (COGL_TEXTURE (tex), &ignore_error)) + if (!cogl_texture_allocate (tex, &ignore_error)) { g_error_free (ignore_error); - cogl_object_unref (tex); + g_object_unref (tex); tex = NULL; } @@ -341,13 +341,13 @@ _cogl_atlas_create_texture (CoglAtlas *atlas, { 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); - if (!cogl_texture_allocate (COGL_TEXTURE (tex), &ignore_error)) + if (!cogl_texture_allocate (tex, &ignore_error)) { g_error_free (ignore_error); - cogl_object_unref (tex); + g_object_unref (tex); tex = NULL; } } @@ -389,7 +389,7 @@ _cogl_atlas_reserve_space (CoglAtlas *atlas, { CoglAtlasGetRectanglesData data; CoglRectangleMap *new_map; - CoglTexture2D *new_tex; + CoglTexture *new_tex; unsigned int map_width = 0, map_height = 0; gboolean ret; CoglRectangleMapEntry new_position; @@ -516,20 +516,20 @@ _cogl_atlas_reserve_space (CoglAtlas *atlas, data.n_textures, data.textures, atlas->texture, - COGL_TEXTURE (new_tex), + new_tex, user_data); _cogl_rectangle_map_free (atlas->map); - cogl_object_unref (atlas->texture); + g_object_unref (atlas->texture); } else /* We know there's only one texture so we can just directly update the rectangle from its new position */ atlas->update_position_cb (data.textures[0].user_data, - COGL_TEXTURE (new_tex), + new_tex, &data.textures[0].new_position); atlas->map = new_map; - atlas->texture = COGL_TEXTURE (new_tex); + atlas->texture = new_tex; waste = (_cogl_rectangle_map_get_remaining_space (atlas->map) * 100 / (_cogl_rectangle_map_get_width (atlas->map) * @@ -582,7 +582,7 @@ create_migration_texture (CoglContext *ctx, 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)); + tex = cogl_texture_2d_new_with_size (ctx, width, height); _cogl_texture_set_internal_format (tex, internal_format); @@ -593,22 +593,19 @@ create_migration_texture (CoglContext *ctx, if (!cogl_texture_allocate (tex, &skip_error)) { g_error_free (skip_error); - cogl_object_unref (tex); + g_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_2d_sliced_new_with_size (ctx, + width, + height, + COGL_TEXTURE_MAX_WASTE); - _cogl_texture_set_internal_format (COGL_TEXTURE (tex_2ds), + _cogl_texture_set_internal_format (tex, internal_format); - - tex = COGL_TEXTURE (tex_2ds); } return tex; @@ -633,7 +630,7 @@ _cogl_atlas_copy_rectangle (CoglAtlas *atlas, if (!cogl_texture_allocate (tex, &ignore_error)) { g_error_free (ignore_error); - cogl_object_unref (tex); + g_object_unref (tex); return NULL; } diff --git a/cogl/cogl/cogl-blit.c b/cogl/cogl/cogl-blit.c index f1b136cfa..037d720a8 100644 --- a/cogl/cogl/cogl-blit.c +++ b/cogl/cogl/cogl-blit.c @@ -48,7 +48,7 @@ static const CoglBlitMode *_cogl_blit_default_mode = NULL; static gboolean _cogl_blit_texture_render_begin (CoglBlitData *data) { - CoglContext *ctx = data->src_tex->context; + CoglContext *ctx = cogl_texture_get_context (data->src_tex); CoglOffscreen *offscreen; CoglFramebuffer *fb; CoglPipeline *pipeline; @@ -129,7 +129,7 @@ _cogl_blit_texture_render_blit (CoglBlitData *data, static void _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 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 _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; CoglFramebuffer *dst_fb, *src_fb; GError *ignore_error = NULL; @@ -228,7 +228,7 @@ _cogl_blit_copy_tex_sub_image_begin (CoglBlitData *data) GError *ignore_error = NULL; /* 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; offscreen = _cogl_offscreen_new_with_texture_full diff --git a/cogl/cogl/cogl-context-private.h b/cogl/cogl/cogl-context-private.h index 40f40ff0d..4c0bc4bea 100644 --- a/cogl/cogl/cogl-context-private.h +++ b/cogl/cogl/cogl-context-private.h @@ -134,7 +134,7 @@ struct _CoglContext CoglPipelineCache *pipeline_cache; /* Textures */ - CoglTexture2D *default_gl_texture_2d_tex; + CoglTexture *default_gl_texture_2d_tex; /* Central list of all framebuffers so all journals can be flushed * at any time. */ diff --git a/cogl/cogl/cogl-context.c b/cogl/cogl/cogl-context.c index c12bb3752..cda8f83de 100644 --- a/cogl/cogl/cogl-context.c +++ b/cogl/cogl/cogl-context.c @@ -78,7 +78,7 @@ cogl_context_dispose (GObject *object) winsys->context_deinit (context); 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) cogl_object_unref (context->opaque_color_pipeline); diff --git a/cogl/cogl/cogl-gtype-private.h b/cogl/cogl/cogl-gtype-private.h index 8d5304c12..815c62e9e 100644 --- a/cogl/cogl/cogl-gtype-private.h +++ b/cogl/cogl/cogl-gtype-private.h @@ -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) \ GType \ cogl_##name##_get_gtype (void) \ @@ -121,52 +112,6 @@ cogl_##name##_get_gtype (void) \ {__VA_ARGS__;} \ _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) \ \ static void name##_init (Name *self); \ diff --git a/cogl/cogl/cogl-meta-texture.c b/cogl/cogl/cogl-meta-texture.c index f6fa22d57..1e9494528 100644 --- a/cogl/cogl/cogl-meta-texture.c +++ b/cogl/cogl/cogl-meta-texture.c @@ -36,6 +36,7 @@ #include "cogl/cogl-spans.h" #include "cogl/cogl-meta-texture.h" #include "cogl/cogl-texture-private.h" +#include "cogl/cogl-pipeline-layer-state.h" #include #include @@ -277,7 +278,7 @@ clamp_t_cb (CoglTexture *sub_texture, } static gboolean -foreach_clamped_region (CoglMetaTexture *meta_texture, +foreach_clamped_region (CoglTexture *texture, float *tx_1, float *ty_1, float *tx_2, @@ -287,7 +288,7 @@ foreach_clamped_region (CoglMetaTexture *meta_texture, CoglMetaTextureCallback callback, void *user_data) { - float width = cogl_texture_get_width (COGL_TEXTURE (meta_texture)); + float width = cogl_texture_get_width (texture); ClampData clamp_data; /* 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.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_2, 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.end = *tx_2; - cogl_meta_texture_foreach_in_region (meta_texture, + cogl_meta_texture_foreach_in_region (texture, max_s_coord - half_texel_width, *ty_1, 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) { - float height = cogl_texture_get_height (COGL_TEXTURE (meta_texture)); + float height = cogl_texture_get_height (texture); float max_t_coord = 1.0; float half_texel_height; @@ -377,7 +378,7 @@ foreach_clamped_region (CoglMetaTexture *meta_texture, { clamp_data.start = *ty_1; 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_2, half_texel_height, wrap_s, @@ -397,7 +398,7 @@ foreach_clamped_region (CoglMetaTexture *meta_texture, { clamp_data.start = MAX (max_t_coord, *ty_1); clamp_data.end = *ty_2; - cogl_meta_texture_foreach_in_region (meta_texture, + cogl_meta_texture_foreach_in_region (texture, *tx_1, max_t_coord - half_texel_height, *tx_2, @@ -452,7 +453,7 @@ normalize_meta_coords_cb (CoglTexture *slice_texture, } void -cogl_meta_texture_foreach_in_region (CoglMetaTexture *meta_texture, +cogl_meta_texture_foreach_in_region (CoglTexture *texture, float tx_1, float ty_1, float tx_2, @@ -462,7 +463,6 @@ cogl_meta_texture_foreach_in_region (CoglMetaTexture *meta_texture, CoglMetaTextureCallback callback, void *user_data) { - CoglTexture *texture = COGL_TEXTURE (meta_texture); float width = cogl_texture_get_width (texture); float height = cogl_texture_get_height (texture); 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 || 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, wrap_s, wrap_t, callback, @@ -512,7 +512,7 @@ cogl_meta_texture_foreach_in_region (CoglMetaTexture *meta_texture, * vtable, instead there will be a separate CoglMetaTexture * interface vtable. */ - if (texture->vtable->foreach_sub_texture_in_region) + if (COGL_TEXTURE_GET_CLASS (texture)->foreach_sub_texture_in_region) { ForeachData data; @@ -554,10 +554,10 @@ cogl_meta_texture_foreach_in_region (CoglMetaTexture *meta_texture, * that we can batch geometry. */ - texture->vtable->foreach_sub_texture_in_region (texture, - 0, 0, 1, 1, - create_grid_and_repeat_cb, - &data); + COGL_TEXTURE_GET_CLASS (texture)->foreach_sub_texture_in_region (texture, + 0, 0, 1, 1, + create_grid_and_repeat_cb, + &data); } else { diff --git a/cogl/cogl/cogl-meta-texture.h b/cogl/cogl/cogl-meta-texture.h index 51fb141a9..ec86ea61b 100644 --- a/cogl/cogl/cogl-meta-texture.h +++ b/cogl/cogl/cogl-meta-texture.h @@ -89,17 +89,6 @@ G_BEGIN_DECLS * meta-textures. */ -#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: * @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. */ COGL_EXPORT void -cogl_meta_texture_foreach_in_region (CoglMetaTexture *meta_texture, +cogl_meta_texture_foreach_in_region (CoglTexture *texture, float tx_1, float ty_1, float tx_2, diff --git a/cogl/cogl/cogl-offscreen.c b/cogl/cogl/cogl-offscreen.c index 728a17ee3..e6877b8c8 100644 --- a/cogl/cogl/cogl-offscreen.c +++ b/cogl/cogl/cogl-offscreen.c @@ -48,12 +48,12 @@ _cogl_offscreen_new_with_texture_full (CoglTexture *texture, CoglOffscreenFlags flags, int level) { - CoglContext *ctx = texture->context; + CoglContext *ctx = cogl_texture_get_context (texture); CoglFramebufferDriverConfig driver_config; CoglOffscreen *offscreen; 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) { .type = COGL_FRAMEBUFFER_DRIVER_TYPE_FBO, @@ -64,7 +64,7 @@ _cogl_offscreen_new_with_texture_full (CoglTexture *texture, "context", ctx, "driver-config", &driver_config, NULL); - offscreen->texture = cogl_object_ref (texture); + offscreen->texture = g_object_ref (texture); offscreen->texture_level = level; fb = COGL_FRAMEBUFFER (offscreen); @@ -141,7 +141,7 @@ cogl_offscreen_dispose (GObject *object) G_OBJECT_CLASS (cogl_offscreen_parent_class)->dispose (object); - cogl_clear_object (&offscreen->texture); + g_clear_object (&offscreen->texture); } static void diff --git a/cogl/cogl/cogl-pipeline-layer-state.c b/cogl/cogl/cogl-pipeline-layer-state.c index 29c855f58..cd09cab55 100644 --- a/cogl/cogl/cogl-pipeline-layer-state.c +++ b/cogl/cogl/cogl-pipeline-layer-state.c @@ -180,7 +180,7 @@ _cogl_pipeline_set_layer_texture_data (CoglPipeline *pipeline, layer->differences &= ~change; if (layer->texture != NULL) - cogl_object_unref (layer->texture); + g_object_unref (layer->texture); g_assert (layer->owner == pipeline); if (layer->differences == 0) @@ -192,10 +192,10 @@ _cogl_pipeline_set_layer_texture_data (CoglPipeline *pipeline, } if (texture != NULL) - cogl_object_ref (texture); + g_object_ref (texture); if (layer == authority && layer->texture != NULL) - cogl_object_unref (layer->texture); + g_object_unref (layer->texture); layer->texture = texture; /* If we weren't previously the authority on this state then we need diff --git a/cogl/cogl/cogl-pipeline-layer.c b/cogl/cogl/cogl-pipeline-layer.c index 3d13a738c..6a4baa769 100644 --- a/cogl/cogl/cogl-pipeline-layer.c +++ b/cogl/cogl/cogl-pipeline-layer.c @@ -189,7 +189,7 @@ _cogl_pipeline_layer_copy_differences (CoglPipelineLayer *dest, case COGL_PIPELINE_LAYER_STATE_TEXTURE_DATA_INDEX: dest->texture = src->texture; if (dest->texture) - cogl_object_ref (dest->texture); + g_object_ref (dest->texture); break; 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 && layer->texture != NULL) - cogl_object_unref (layer->texture); + g_object_unref (layer->texture); if (layer->differences & COGL_PIPELINE_LAYER_STATE_VERTEX_SNIPPETS) _cogl_pipeline_snippet_list_free (&layer->big_state->vertex_snippets); diff --git a/cogl/cogl/cogl-pipeline.c b/cogl/cogl/cogl-pipeline.c index fa0f65993..f9c7e9bd3 100644 --- a/cogl/cogl/cogl-pipeline.c +++ b/cogl/cogl/cogl-pipeline.c @@ -1752,7 +1752,7 @@ fallback_layer_cb (CoglPipelineLayer *layer, void *user_data) 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) { @@ -1760,7 +1760,7 @@ fallback_layer_cb (CoglPipelineLayer *layer, void *user_data) "in for an invalid pipeline layer, since it was " "using an unsupported texture target "); /* 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); diff --git a/cogl/cogl/cogl-primitive-texture.c b/cogl/cogl/cogl-primitive-texture.c index 7d28d8891..c501d4f81 100644 --- a/cogl/cogl/cogl-primitive-texture.c +++ b/cogl/cogl/cogl-primitive-texture.c @@ -35,24 +35,15 @@ #include "cogl/cogl-primitive-texture.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 -cogl_primitive_texture_set_auto_mipmap (CoglPrimitiveTexture *primitive_texture, - gboolean value) +cogl_primitive_texture_set_auto_mipmap (CoglTexture *texture, + 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); - - g_assert (texture->vtable->set_auto_mipmap != NULL); - - texture->vtable->set_auto_mipmap (texture, value); + COGL_TEXTURE_GET_CLASS (texture)->set_auto_mipmap (texture, value); } diff --git a/cogl/cogl/cogl-primitive-texture.h b/cogl/cogl/cogl-primitive-texture.h index a9fdda6b1..98de61c3b 100644 --- a/cogl/cogl/cogl-primitive-texture.h +++ b/cogl/cogl/cogl-primitive-texture.h @@ -34,56 +34,10 @@ #error "Only can be included directly." #endif -#include "cogl/cogl-types.h" +#include "cogl/cogl-texture.h" 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. - * - * 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. - */ - -#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: * @primitive_texture: A #CoglPrimitiveTexture @@ -97,7 +51,7 @@ cogl_is_primitive_texture (void *object); * levels. By default auto mipmapping is enabled. */ COGL_EXPORT void -cogl_primitive_texture_set_auto_mipmap (CoglPrimitiveTexture *primitive_texture, - gboolean value); +cogl_primitive_texture_set_auto_mipmap (CoglTexture *primitive_texture, + gboolean value); G_END_DECLS diff --git a/cogl/cogl/cogl-primitives.c b/cogl/cogl/cogl-primitives.c index 6d2892e72..72ede8075 100644 --- a/cogl/cogl/cogl-primitives.c +++ b/cogl/cogl/cogl-primitives.c @@ -272,7 +272,7 @@ _cogl_texture_quad_multiple_primitives (CoglFramebuffer *framebuffer, if (wrap_t == COGL_PIPELINE_WRAP_MODE_AUTOMATIC) 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, wrap_s, wrap_t, @@ -580,7 +580,7 @@ _cogl_rectangles_validate_layer_cb (CoglPipeline *pipeline, else { static gboolean warning_seen = FALSE; - CoglTexture2D *tex_2d; + CoglTexture *tex_2d; if (!warning_seen) 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. */ tex_2d = state->ctx->default_gl_texture_2d_tex; - cogl_pipeline_set_layer_texture (pipeline, layer_index, - COGL_TEXTURE (tex_2d)); + cogl_pipeline_set_layer_texture (pipeline, layer_index, tex_2d); return TRUE; } } diff --git a/cogl/cogl/cogl-sub-texture-private.h b/cogl/cogl/cogl-sub-texture-private.h index 377d4e8b5..45c9002b8 100644 --- a/cogl/cogl/cogl-sub-texture-private.h +++ b/cogl/cogl/cogl-sub-texture-private.h @@ -36,7 +36,7 @@ struct _CoglSubTexture { - CoglTexture _parent; + CoglTexture parent_instance; /* This is the texture that was passed in to _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_y; }; + +struct _CoglSubTextureClass +{ + CoglTextureClass parent_class; +}; diff --git a/cogl/cogl/cogl-sub-texture.c b/cogl/cogl/cogl-sub-texture.c index 35e9d9802..66a416a54 100644 --- a/cogl/cogl/cogl-sub-texture.c +++ b/cogl/cogl/cogl-sub-texture.c @@ -38,21 +38,26 @@ #include "cogl/cogl-sub-texture-private.h" #include "cogl/cogl-sub-texture.h" #include "cogl/cogl-context-private.h" -#include "cogl/cogl-object.h" #include "cogl/cogl-texture-driver.h" #include "cogl/cogl-texture-2d.h" -#include "cogl/cogl-gtype-private.h" #include "cogl/driver/gl/cogl-texture-gl-private.h" #include #include -static void _cogl_sub_texture_free (CoglSubTexture *sub_tex); -COGL_TEXTURE_DEFINE (SubTexture, sub_texture); -COGL_GTYPE_DEFINE_CLASS (SubTexture, sub_texture); +G_DEFINE_FINAL_TYPE (CoglSubTexture, cogl_sub_texture, COGL_TYPE_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 _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 height = cogl_texture_get_height (sub_tex->full_texture); - coords[0] = (coords[0] * width - sub_tex->sub_x) / tex->width; - coords[1] = (coords[1] * height - sub_tex->sub_y) / tex->height; - coords[2] = (coords[2] * width - sub_tex->sub_x) / tex->width; - coords[3] = (coords[3] * height - sub_tex->sub_y) / tex->height; + coords[0] = (coords[0] * width - sub_tex->sub_x) / cogl_texture_get_width (tex); + coords[1] = (coords[1] * height - sub_tex->sub_y) / cogl_texture_get_height (tex); + coords[2] = (coords[2] * width - sub_tex->sub_x) / cogl_texture_get_width (tex); + coords[3] = (coords[3] * height - sub_tex->sub_y) / cogl_texture_get_height (tex); } 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 height = cogl_texture_get_height (sub_tex->full_texture); - coords[0] = (coords[0] * tex->width + sub_tex->sub_x) / width; - coords[1] = (coords[1] * tex->height + sub_tex->sub_y) / height; - coords[2] = (coords[2] * tex->width + sub_tex->sub_x) / width; - coords[3] = (coords[3] * tex->height + sub_tex->sub_y) / height; + coords[0] = (coords[0] * cogl_texture_get_width (tex) + sub_tex->sub_x) / width; + coords[1] = (coords[1] * cogl_texture_get_height (tex) + sub_tex->sub_y) / height; + coords[2] = (coords[2] * cogl_texture_get_width (tex) + sub_tex->sub_x) / width; + coords[3] = (coords[3] * cogl_texture_get_height (tex) + sub_tex->sub_y) / height; } typedef struct _CoglSubTextureForeachData @@ -129,7 +134,7 @@ _cogl_sub_texture_foreach_sub_texture_in_region ( _cogl_sub_texture_map_quad (sub_tex, mapped_coords); /* 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, mapped_coords, @@ -144,7 +149,7 @@ _cogl_sub_texture_foreach_sub_texture_in_region ( data.callback = callback; 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[1], mapped_coords[2], @@ -168,67 +173,6 @@ _cogl_sub_texture_gl_flush_legacy_texobj_wrap_modes (CoglTexture *tex, 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 _cogl_sub_texture_allocate (CoglTexture *tex, GError **error) @@ -238,17 +182,12 @@ _cogl_sub_texture_allocate (CoglTexture *tex, _cogl_texture_set_allocated (tex, _cogl_texture_get_format (sub_tex->full_texture), - tex->width, tex->height); + cogl_texture_get_width (tex), + cogl_texture_get_height (tex)); return status; } -CoglTexture * -cogl_sub_texture_get_parent (CoglSubTexture *sub_texture) -{ - return sub_texture->next_texture; -} - static int _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 of the full texture */ - return (tex->width == + return (cogl_texture_get_width (tex) == 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_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 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)); - *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_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); } -static const CoglTextureVtable -cogl_sub_texture_vtable = - { - FALSE, /* not primitive */ - _cogl_sub_texture_allocate, - _cogl_sub_texture_set_region, - _cogl_sub_texture_is_get_data_supported, - NULL, /* get_data */ - _cogl_sub_texture_foreach_sub_texture_in_region, - _cogl_sub_texture_get_max_waste, - _cogl_sub_texture_is_sliced, - _cogl_sub_texture_can_hardware_repeat, - _cogl_sub_texture_transform_coords_to_gl, - _cogl_sub_texture_transform_quad_coords_to_gl, - _cogl_sub_texture_get_gl_texture, - _cogl_sub_texture_gl_flush_legacy_texobj_filters, - _cogl_sub_texture_pre_paint, - _cogl_sub_texture_ensure_non_quad_rendering, - _cogl_sub_texture_gl_flush_legacy_texobj_wrap_modes, - _cogl_sub_texture_get_format, - _cogl_sub_texture_get_gl_format, - NULL /* set_auto_mipmap */ - }; +static void +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)) + { + 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 = g_object_ref (next_texture); + sub_tex->full_texture = g_object_ref (full_texture); + + sub_tex->sub_x = sub_x; + sub_tex->sub_y = sub_y; + + return tex; +} + +CoglTexture * +cogl_sub_texture_get_parent (CoglSubTexture *sub_texture) +{ + return sub_texture->next_texture; +} diff --git a/cogl/cogl/cogl-sub-texture.h b/cogl/cogl/cogl-sub-texture.h index 673e41cb1..f3451608a 100644 --- a/cogl/cogl/cogl-sub-texture.h +++ b/cogl/cogl/cogl-sub-texture.h @@ -38,26 +38,29 @@ G_BEGIN_DECLS /** - * SECTION:cogl-sub-texture - * @short_description: Functions for creating and manipulating - * sub-textures. + * CoglSubTexture: + * + * Functions for creating and manipulating sub-textures. * * These functions allow high-level textures to be created that * represent a sub-region of another texture. For example these * 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)) - -#define COGL_SUB_TEXTURE(tex) ((CoglSubTexture *) tex) +typedef struct _CoglSubTextureClass CoglSubTextureClass; typedef struct _CoglSubTexture CoglSubTexture; -/** - * cogl_sub_texture_get_gtype: - * - * Returns: a #GType that can be used with the GLib type system. - */ -GType cogl_sub_texture_get_gtype (void); +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglSubTexture, g_object_unref) +COGL_EXPORT +GType cogl_sub_texture_get_type (void) G_GNUC_CONST; /** * cogl_sub_texture_new: * @ctx: A #CoglContext pointer @@ -86,7 +89,7 @@ GType cogl_sub_texture_get_gtype (void); * Return value: (transfer full): A newly allocated #CoglSubTexture * representing a sub-region of @parent_texture. */ -COGL_EXPORT CoglSubTexture * +COGL_EXPORT CoglTexture * cogl_sub_texture_new (CoglContext *ctx, CoglTexture *parent_texture, int sub_x, @@ -108,16 +111,4 @@ cogl_sub_texture_new (CoglContext *ctx, COGL_EXPORT CoglTexture * 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 diff --git a/cogl/cogl/cogl-texture-2d-private.h b/cogl/cogl/cogl-texture-2d-private.h index a59a79d0b..0b976f2e0 100644 --- a/cogl/cogl/cogl-texture-2d-private.h +++ b/cogl/cogl/cogl-texture-2d-private.h @@ -30,14 +30,13 @@ #pragma once -#include "cogl/cogl-object-private.h" #include "cogl/cogl-pipeline-private.h" #include "cogl/cogl-texture-private.h" #include "cogl/cogl-texture-2d.h" struct _CoglTexture2D { - CoglTexture _parent; + CoglTexture parent_instance; /* The internal format of the GL texture represented as a CoglPixelFormat */ @@ -67,7 +66,12 @@ struct _CoglTexture2D } egl_image_external; }; -CoglTexture2D * +struct _CoglTexture2DClass +{ + CoglTextureClass parent_class; +}; + +CoglTexture * _cogl_texture_2d_create_base (CoglContext *ctx, int width, int height, diff --git a/cogl/cogl/cogl-texture-2d-sliced-private.h b/cogl/cogl/cogl-texture-2d-sliced-private.h index 13647a2cd..d7f391d41 100644 --- a/cogl/cogl/cogl-texture-2d-sliced-private.h +++ b/cogl/cogl/cogl-texture-2d-sliced-private.h @@ -39,7 +39,7 @@ struct _CoglTexture2DSliced { - CoglTexture _parent; + CoglTexture parent_instance; GArray *slice_x_spans; GArray *slice_y_spans; @@ -47,3 +47,8 @@ struct _CoglTexture2DSliced int max_waste; CoglPixelFormat internal_format; }; + +struct _CoglTexture2DSlicedClass +{ + CoglTextureClass parent_class; +}; diff --git a/cogl/cogl/cogl-texture-2d-sliced.c b/cogl/cogl/cogl-texture-2d-sliced.c index 166d5084a..793cc7e85 100644 --- a/cogl/cogl/cogl-texture-2d-sliced.c +++ b/cogl/cogl/cogl-texture-2d-sliced.c @@ -45,24 +45,16 @@ #include "cogl/cogl-texture-2d-sliced-private.h" #include "cogl/cogl-texture-driver.h" #include "cogl/cogl-context-private.h" -#include "cogl/cogl-object-private.h" #include "cogl/cogl-spans.h" #include "cogl/cogl-journal-private.h" #include "cogl/cogl-primitive-texture.h" -#include "cogl/cogl-gtype-private.h" #include "cogl/driver/gl/cogl-texture-gl-private.h" #include #include #include -static void _cogl_texture_2d_sliced_free (CoglTexture2DSliced *tex_2ds); - -COGL_TEXTURE_DEFINE (Texture2DSliced, texture_2d_sliced); -COGL_GTYPE_DEFINE_CLASS (Texture2DSliced, texture_2d_sliced, - COGL_GTYPE_IMPLEMENT_INTERFACE (texture)); - -static const CoglTextureVtable cogl_texture_2d_sliced_vtable; +G_DEFINE_FINAL_TYPE (CoglTexture2DSliced, cogl_texture_2d_sliced, COGL_TYPE_TEXTURE) typedef struct _ForeachData { @@ -72,76 +64,308 @@ typedef struct _ForeachData float y_normalize_factor; } ForeachData; -static void -re_normalize_sub_texture_coords_cb (CoglTexture *sub_texture, - const float *sub_texture_coords, - const float *meta_coords, - void *user_data) -{ - ForeachData *data = user_data; - /* The coordinates passed to the span iterating code were - * un-normalized so we need to renormalize them before passing them - * on */ - float re_normalized_coords[4] = - { - meta_coords[0] * data->x_normalize_factor, - meta_coords[1] * data->y_normalize_factor, - meta_coords[2] * data->x_normalize_factor, - meta_coords[3] * data->y_normalize_factor - }; - data->callback (sub_texture, sub_texture_coords, re_normalized_coords, - data->user_data); +static void +free_spans (CoglTexture2DSliced *tex_2ds) +{ + if (tex_2ds->slice_x_spans != NULL) + { + g_array_free (tex_2ds->slice_x_spans, TRUE); + tex_2ds->slice_x_spans = NULL; + } + + if (tex_2ds->slice_y_spans != NULL) + { + g_array_free (tex_2ds->slice_y_spans, TRUE); + tex_2ds->slice_y_spans = NULL; + } } static void -_cogl_texture_2d_sliced_foreach_sub_texture_in_region ( - CoglTexture *tex, - float virtual_tx_1, - float virtual_ty_1, - float virtual_tx_2, - float virtual_ty_2, - CoglMetaTextureCallback callback, - void *user_data) +free_slices (CoglTexture2DSliced *tex_2ds) { - CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex); - CoglSpan *x_spans = (CoglSpan *)tex_2ds->slice_x_spans->data; - CoglSpan *y_spans = (CoglSpan *)tex_2ds->slice_y_spans->data; - CoglTexture **textures = (CoglTexture **)tex_2ds->slice_textures->data; - float un_normalized_coords[4]; - ForeachData data; + if (tex_2ds->slice_textures != NULL) + { + int i; - /* NB: its convenient for us to store non-normalized coordinates in - * our CoglSpans but that means we need to un-normalize the incoming - * virtual coordinates and make sure we re-normalize the coordinates - * before calling the given callback. - */ + for (i = 0; i < tex_2ds->slice_textures->len; i++) + { + CoglTexture2D *slice_tex = + g_array_index (tex_2ds->slice_textures, CoglTexture2D *, i); + g_object_unref (slice_tex); + } - data.callback = callback; - data.user_data = user_data; - data.x_normalize_factor = 1.0f / tex->width; - data.y_normalize_factor = 1.0f / tex->height; + g_array_free (tex_2ds->slice_textures, TRUE); + tex_2ds->slice_textures = NULL; + } - un_normalized_coords[0] = virtual_tx_1 * tex->width; - un_normalized_coords[1] = virtual_ty_1 * tex->height; - un_normalized_coords[2] = virtual_tx_2 * tex->width; - un_normalized_coords[3] = virtual_ty_2 * tex->height; + free_spans (tex_2ds); +} - /* Note that the normalize factors passed here are the reciprocal of - * the factors calculated above because the span iterating code - * normalizes by dividing by the factor instead of multiplying */ - _cogl_texture_spans_foreach_in_region (x_spans, - tex_2ds->slice_x_spans->len, - y_spans, - tex_2ds->slice_y_spans->len, - textures, - un_normalized_coords, - tex->width, - tex->height, - COGL_PIPELINE_WRAP_MODE_REPEAT, - COGL_PIPELINE_WRAP_MODE_REPEAT, - re_normalize_sub_texture_coords_cb, - &data); +static void +cogl_texture_2d_sliced_dispose (GObject *object) +{ + CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (object); + + free_slices (tex_2ds); + + G_OBJECT_CLASS (cogl_texture_2d_sliced_parent_class)->dispose (object); +} + +static int +_cogl_rect_slices_for_size (int size_to_fill, + int max_span_size, + int max_waste, + GArray *out_spans) +{ + int n_spans = 0; + CoglSpan span; + + /* Init first slice span */ + span.start = 0; + span.size = max_span_size; + span.waste = 0; + + /* Repeat until whole area covered */ + while (size_to_fill >= span.size) + { + /* Add another slice span of same size */ + if (out_spans) + g_array_append_val (out_spans, span); + span.start += span.size; + size_to_fill -= span.size; + n_spans++; + } + + /* Add one last smaller slice span */ + if (size_to_fill > 0) + { + span.size = size_to_fill; + if (out_spans) + g_array_append_val (out_spans, span); + n_spans++; + } + + return n_spans; +} + +static gboolean +setup_spans (CoglContext *ctx, + CoglTexture2DSliced *tex_2ds, + int width, + int height, + int max_waste, + CoglPixelFormat internal_format, + GError **error) +{ + int max_width; + int max_height; + int n_x_slices; + int n_y_slices; + + int (*slices_for_size) (int, int, int, GArray*); + + /* Initialize size of largest slice according to supported features */ + max_width = width; + max_height = height; + slices_for_size = _cogl_rect_slices_for_size; + + /* Negative number means no slicing forced by the user */ + if (max_waste <= -1) + { + CoglSpan span; + + /* Check if size supported else bail out */ + if (!ctx->driver_vtable->texture_2d_can_create (ctx, + max_width, + max_height, + internal_format)) + { + g_set_error (error, COGL_TEXTURE_ERROR, COGL_TEXTURE_ERROR_SIZE, + "Sliced texture size of %d x %d not possible " + "with max waste set to -1", + width, + height); + return FALSE; + } + + n_x_slices = 1; + n_y_slices = 1; + + /* Init span arrays */ + tex_2ds->slice_x_spans = g_array_sized_new (FALSE, FALSE, + sizeof (CoglSpan), + 1); + + tex_2ds->slice_y_spans = g_array_sized_new (FALSE, FALSE, + sizeof (CoglSpan), + 1); + + /* Add a single span for width and height */ + span.start = 0; + span.size = max_width; + span.waste = max_width - width; + g_array_append_val (tex_2ds->slice_x_spans, span); + + span.size = max_height; + span.waste = max_height - height; + g_array_append_val (tex_2ds->slice_y_spans, span); + } + else + { + /* Decrease the size of largest slice until supported by GL */ + while (!ctx->driver_vtable->texture_2d_can_create (ctx, + max_width, + max_height, + internal_format)) + { + /* Alternate between width and height */ + if (max_width > max_height) + max_width /= 2; + else + max_height /= 2; + + if (max_width == 0 || max_height == 0) + { + /* Maybe it would be ok to just g_warn_if_reached() for this + * codepath */ + g_set_error (error, COGL_TEXTURE_ERROR, COGL_TEXTURE_ERROR_SIZE, + "No suitable slice geometry found"); + free_spans (tex_2ds); + return FALSE; + } + } + + /* Determine the slices required to cover the bitmap area */ + n_x_slices = slices_for_size (width, + max_width, max_waste, + NULL); + + n_y_slices = slices_for_size (height, + max_height, max_waste, + NULL); + + /* Init span arrays with reserved size */ + tex_2ds->slice_x_spans = g_array_sized_new (FALSE, FALSE, + sizeof (CoglSpan), + n_x_slices); + + tex_2ds->slice_y_spans = g_array_sized_new (FALSE, FALSE, + sizeof (CoglSpan), + n_y_slices); + + /* Fill span arrays with info */ + slices_for_size (width, + max_width, max_waste, + tex_2ds->slice_x_spans); + + slices_for_size (height, + max_height, max_waste, + tex_2ds->slice_y_spans); + } + + return TRUE; +} + +static gboolean +allocate_slices (CoglTexture2DSliced *tex_2ds, + int width, + int height, + int max_waste, + CoglPixelFormat internal_format, + GError **error) +{ + CoglTexture *tex = COGL_TEXTURE (tex_2ds); + CoglContext *ctx = cogl_texture_get_context (tex); + int n_x_slices; + int n_y_slices; + int n_slices; + int x, y; + CoglSpan *x_span; + CoglSpan *y_span; + + tex_2ds->internal_format = internal_format; + + if (!setup_spans (ctx, tex_2ds, + width, + height, + max_waste, + internal_format, + error)) + { + return FALSE; + } + + n_x_slices = tex_2ds->slice_x_spans->len; + n_y_slices = tex_2ds->slice_y_spans->len; + n_slices = n_x_slices * n_y_slices; + + tex_2ds->slice_textures = g_array_sized_new (FALSE, FALSE, + sizeof (CoglTexture2D *), + n_slices); + + /* Allocate each slice */ + for (y = 0; y < n_y_slices; ++y) + { + y_span = &g_array_index (tex_2ds->slice_y_spans, CoglSpan, y); + + for (x = 0; x < n_x_slices; ++x) + { + CoglTexture *slice; + + x_span = &g_array_index (tex_2ds->slice_x_spans, CoglSpan, x); + + COGL_NOTE (SLICING, "CREATE SLICE (%d,%d)\tsize (%d,%d)", + x, y, + (int)(x_span->size - x_span->waste), + (int)(y_span->size - y_span->waste)); + + slice = + cogl_texture_2d_new_with_size (ctx, + x_span->size, y_span->size); + + _cogl_texture_copy_internal_format (tex, slice); + + g_array_append_val (tex_2ds->slice_textures, slice); + if (!cogl_texture_allocate (slice, error)) + { + free_slices (tex_2ds); + return FALSE; + } + } + } + + return TRUE; +} + +static gboolean +allocate_with_size (CoglTexture2DSliced *tex_2ds, + CoglTextureLoader *loader, + GError **error) +{ + CoglTexture *tex = COGL_TEXTURE (tex_2ds); + CoglPixelFormat internal_format; + + g_warn_if_fail (loader->src.sized.format == COGL_PIXEL_FORMAT_ANY); + + internal_format = + _cogl_texture_determine_internal_format (tex, COGL_PIXEL_FORMAT_ANY); + + if (allocate_slices (tex_2ds, + loader->src.sized.width, + loader->src.sized.height, + tex_2ds->max_waste, + internal_format, + error)) + { + _cogl_texture_set_allocated (tex, + internal_format, + loader->src.sized.width, + loader->src.sized.height); + return TRUE; + } + else + return FALSE; } static uint8_t * @@ -193,7 +417,7 @@ _cogl_texture_2d_sliced_set_waste (CoglTexture2DSliced *tex_2ds, GError **error) { gboolean need_x, need_y; - CoglContext *ctx = COGL_TEXTURE (tex_2ds)->context; + CoglContext *ctx = cogl_texture_get_context (COGL_TEXTURE (tex_2ds)); /* If the x_span is sliced and the upload touches the rightmost pixels then fill the waste with copies of the @@ -434,549 +658,6 @@ _cogl_texture_2d_sliced_upload_bitmap (CoglTexture2DSliced *tex_2ds, return TRUE; } -static gboolean -_cogl_texture_2d_sliced_upload_subregion (CoglTexture2DSliced *tex_2ds, - int src_x, - int src_y, - int dst_x, - int dst_y, - int width, - int height, - CoglBitmap *source_bmp, - GError **error) -{ - CoglTexture *tex = COGL_TEXTURE (tex_2ds); - CoglSpan *x_span; - CoglSpan *y_span; - CoglSpanIter x_iter; - CoglSpanIter y_iter; - CoglTexture2D *slice_tex; - int source_x = 0, source_y = 0; - int inter_w = 0, inter_h = 0; - int local_x = 0, local_y = 0; - uint8_t *waste_buf; - CoglPixelFormat source_format; - - source_format = cogl_bitmap_get_format (source_bmp); - - waste_buf = - _cogl_texture_2d_sliced_allocate_waste_buffer (tex_2ds, source_format); - - /* Iterate vertical spans */ - for (source_y = src_y, - _cogl_span_iter_begin (&y_iter, - (CoglSpan *)tex_2ds->slice_y_spans->data, - tex_2ds->slice_y_spans->len, - tex->height, - dst_y, - dst_y + height, - COGL_PIPELINE_WRAP_MODE_REPEAT); - - !_cogl_span_iter_end (&y_iter); - - _cogl_span_iter_next (&y_iter), - source_y += inter_h ) - { - y_span = &g_array_index (tex_2ds->slice_y_spans, CoglSpan, - y_iter.index); - - /* Iterate horizontal spans */ - for (source_x = src_x, - _cogl_span_iter_begin (&x_iter, - (CoglSpan *)tex_2ds->slice_x_spans->data, - tex_2ds->slice_x_spans->len, - tex->width, - dst_x, - dst_x + width, - COGL_PIPELINE_WRAP_MODE_REPEAT); - - !_cogl_span_iter_end (&x_iter); - - _cogl_span_iter_next (&x_iter), - source_x += inter_w ) - { - int slice_num; - - x_span = &g_array_index (tex_2ds->slice_x_spans, CoglSpan, - x_iter.index); - - /* Pick intersection width and height */ - inter_w = (x_iter.intersect_end - x_iter.intersect_start); - inter_h = (y_iter.intersect_end - y_iter.intersect_start); - - /* Localize intersection top-left corner to slice*/ - local_x = (x_iter.intersect_start - x_iter.pos); - local_y = (y_iter.intersect_start - y_iter.pos); - - slice_num = y_iter.index * tex_2ds->slice_x_spans->len + x_iter.index; - - /* Pick slice texture */ - slice_tex = g_array_index (tex_2ds->slice_textures, - CoglTexture2D *, slice_num); - - if (!_cogl_texture_set_region_from_bitmap (COGL_TEXTURE (slice_tex), - source_x, - source_y, - inter_w, /* width */ - inter_h, /* height */ - source_bmp, - local_x, /* dst x */ - local_y, /* dst y */ - 0, /* level */ - error)) - { - if (waste_buf) - g_free (waste_buf); - return FALSE; - } - - if (!_cogl_texture_2d_sliced_set_waste (tex_2ds, - source_bmp, - slice_tex, - waste_buf, - x_span, y_span, - &x_iter, &y_iter, - src_x, src_y, - dst_x, dst_y, - error)) - { - if (waste_buf) - g_free (waste_buf); - return FALSE; - } - } - } - - if (waste_buf) - g_free (waste_buf); - - return TRUE; -} - -static int -_cogl_rect_slices_for_size (int size_to_fill, - int max_span_size, - int max_waste, - GArray *out_spans) -{ - int n_spans = 0; - CoglSpan span; - - /* Init first slice span */ - span.start = 0; - span.size = max_span_size; - span.waste = 0; - - /* Repeat until whole area covered */ - while (size_to_fill >= span.size) - { - /* Add another slice span of same size */ - if (out_spans) - g_array_append_val (out_spans, span); - span.start += span.size; - size_to_fill -= span.size; - n_spans++; - } - - /* Add one last smaller slice span */ - if (size_to_fill > 0) - { - span.size = size_to_fill; - if (out_spans) - g_array_append_val (out_spans, span); - n_spans++; - } - - return n_spans; -} - -static void -_cogl_texture_2d_sliced_gl_flush_legacy_texobj_wrap_modes (CoglTexture *tex, - GLenum wrap_mode_s, - GLenum wrap_mode_t) -{ - CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex); - int i; - - /* Pass the set wrap mode on to all of the child textures */ - for (i = 0; i < tex_2ds->slice_textures->len; i++) - { - CoglTexture2D *slice_tex = g_array_index (tex_2ds->slice_textures, - CoglTexture2D *, - i); - - _cogl_texture_gl_flush_legacy_texobj_wrap_modes (COGL_TEXTURE (slice_tex), - wrap_mode_s, - wrap_mode_t); - } -} - -static void -free_spans (CoglTexture2DSliced *tex_2ds) -{ - if (tex_2ds->slice_x_spans != NULL) - { - g_array_free (tex_2ds->slice_x_spans, TRUE); - tex_2ds->slice_x_spans = NULL; - } - - if (tex_2ds->slice_y_spans != NULL) - { - g_array_free (tex_2ds->slice_y_spans, TRUE); - tex_2ds->slice_y_spans = NULL; - } -} - -static gboolean -setup_spans (CoglContext *ctx, - CoglTexture2DSliced *tex_2ds, - int width, - int height, - int max_waste, - CoglPixelFormat internal_format, - GError **error) -{ - int max_width; - int max_height; - int n_x_slices; - int n_y_slices; - - int (*slices_for_size) (int, int, int, GArray*); - - /* Initialize size of largest slice according to supported features */ - max_width = width; - max_height = height; - slices_for_size = _cogl_rect_slices_for_size; - - /* Negative number means no slicing forced by the user */ - if (max_waste <= -1) - { - CoglSpan span; - - /* Check if size supported else bail out */ - if (!ctx->driver_vtable->texture_2d_can_create (ctx, - max_width, - max_height, - internal_format)) - { - g_set_error (error, COGL_TEXTURE_ERROR, COGL_TEXTURE_ERROR_SIZE, - "Sliced texture size of %d x %d not possible " - "with max waste set to -1", - width, - height); - return FALSE; - } - - n_x_slices = 1; - n_y_slices = 1; - - /* Init span arrays */ - tex_2ds->slice_x_spans = g_array_sized_new (FALSE, FALSE, - sizeof (CoglSpan), - 1); - - tex_2ds->slice_y_spans = g_array_sized_new (FALSE, FALSE, - sizeof (CoglSpan), - 1); - - /* Add a single span for width and height */ - span.start = 0; - span.size = max_width; - span.waste = max_width - width; - g_array_append_val (tex_2ds->slice_x_spans, span); - - span.size = max_height; - span.waste = max_height - height; - g_array_append_val (tex_2ds->slice_y_spans, span); - } - else - { - /* Decrease the size of largest slice until supported by GL */ - while (!ctx->driver_vtable->texture_2d_can_create (ctx, - max_width, - max_height, - internal_format)) - { - /* Alternate between width and height */ - if (max_width > max_height) - max_width /= 2; - else - max_height /= 2; - - if (max_width == 0 || max_height == 0) - { - /* Maybe it would be ok to just g_warn_if_reached() for this - * codepath */ - g_set_error (error, COGL_TEXTURE_ERROR, COGL_TEXTURE_ERROR_SIZE, - "No suitable slice geometry found"); - free_spans (tex_2ds); - return FALSE; - } - } - - /* Determine the slices required to cover the bitmap area */ - n_x_slices = slices_for_size (width, - max_width, max_waste, - NULL); - - n_y_slices = slices_for_size (height, - max_height, max_waste, - NULL); - - /* Init span arrays with reserved size */ - tex_2ds->slice_x_spans = g_array_sized_new (FALSE, FALSE, - sizeof (CoglSpan), - n_x_slices); - - tex_2ds->slice_y_spans = g_array_sized_new (FALSE, FALSE, - sizeof (CoglSpan), - n_y_slices); - - /* Fill span arrays with info */ - slices_for_size (width, - max_width, max_waste, - tex_2ds->slice_x_spans); - - slices_for_size (height, - max_height, max_waste, - tex_2ds->slice_y_spans); - } - - return TRUE; -} - -static void -free_slices (CoglTexture2DSliced *tex_2ds) -{ - if (tex_2ds->slice_textures != NULL) - { - int i; - - for (i = 0; i < tex_2ds->slice_textures->len; i++) - { - CoglTexture2D *slice_tex = - g_array_index (tex_2ds->slice_textures, CoglTexture2D *, i); - cogl_object_unref (slice_tex); - } - - g_array_free (tex_2ds->slice_textures, TRUE); - tex_2ds->slice_textures = NULL; - } - - free_spans (tex_2ds); -} - -static gboolean -allocate_slices (CoglTexture2DSliced *tex_2ds, - int width, - int height, - int max_waste, - CoglPixelFormat internal_format, - GError **error) -{ - CoglTexture *tex = COGL_TEXTURE (tex_2ds); - CoglContext *ctx = tex->context; - int n_x_slices; - int n_y_slices; - int n_slices; - int x, y; - CoglSpan *x_span; - CoglSpan *y_span; - - tex_2ds->internal_format = internal_format; - - if (!setup_spans (ctx, tex_2ds, - width, - height, - max_waste, - internal_format, - error)) - { - return FALSE; - } - - n_x_slices = tex_2ds->slice_x_spans->len; - n_y_slices = tex_2ds->slice_y_spans->len; - n_slices = n_x_slices * n_y_slices; - - tex_2ds->slice_textures = g_array_sized_new (FALSE, FALSE, - sizeof (CoglTexture2D *), - n_slices); - - /* Allocate each slice */ - for (y = 0; y < n_y_slices; ++y) - { - y_span = &g_array_index (tex_2ds->slice_y_spans, CoglSpan, y); - - for (x = 0; x < n_x_slices; ++x) - { - CoglTexture *slice; - - x_span = &g_array_index (tex_2ds->slice_x_spans, CoglSpan, x); - - COGL_NOTE (SLICING, "CREATE SLICE (%d,%d)\tsize (%d,%d)", - x, y, - (int)(x_span->size - x_span->waste), - (int)(y_span->size - y_span->waste)); - - slice = COGL_TEXTURE ( - cogl_texture_2d_new_with_size (ctx, - x_span->size, y_span->size)); - - _cogl_texture_copy_internal_format (tex, slice); - - g_array_append_val (tex_2ds->slice_textures, slice); - if (!cogl_texture_allocate (slice, error)) - { - free_slices (tex_2ds); - return FALSE; - } - } - } - - return TRUE; -} - -static void -_cogl_texture_2d_sliced_free (CoglTexture2DSliced *tex_2ds) -{ - free_slices (tex_2ds); - - /* Chain up */ - _cogl_texture_free (COGL_TEXTURE (tex_2ds)); -} - -static CoglTexture2DSliced * -_cogl_texture_2d_sliced_create_base (CoglContext *ctx, - int width, - int height, - int max_waste, - CoglPixelFormat internal_format, - CoglTextureLoader *loader) -{ - CoglTexture2DSliced *tex_2ds = g_new0 (CoglTexture2DSliced, 1); - - _cogl_texture_init (COGL_TEXTURE (tex_2ds), ctx, width, height, - internal_format, loader, - &cogl_texture_2d_sliced_vtable); - - tex_2ds->max_waste = max_waste; - - return _cogl_texture_2d_sliced_object_new (tex_2ds); -} - -CoglTexture2DSliced * -cogl_texture_2d_sliced_new_with_size (CoglContext *ctx, - int width, - int height, - int max_waste) -{ - CoglTextureLoader *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_sliced_create_base (ctx, - width, - height, - max_waste, - COGL_PIXEL_FORMAT_RGBA_8888_PRE, - loader); -} - -CoglTexture2DSliced * -cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp, - int max_waste) -{ - CoglTextureLoader *loader; - - g_return_val_if_fail (COGL_IS_BITMAP (bmp), 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_sliced_create_base (_cogl_bitmap_get_context (bmp), - cogl_bitmap_get_width (bmp), - cogl_bitmap_get_height (bmp), - max_waste, - cogl_bitmap_get_format (bmp), - loader); -} - -CoglTexture2DSliced * -cogl_texture_2d_sliced_new_from_data (CoglContext *ctx, - int width, - int height, - int max_waste, - CoglPixelFormat format, - int rowstride, - const uint8_t *data, - GError **error) -{ - CoglBitmap *bmp; - CoglTexture2DSliced *tex_2ds; - - 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_2ds = cogl_texture_2d_sliced_new_from_bitmap (bmp, max_waste); - - g_object_unref (bmp); - - if (tex_2ds && - !cogl_texture_allocate (COGL_TEXTURE (tex_2ds), error)) - { - cogl_object_unref (tex_2ds); - return NULL; - } - - return tex_2ds; -} - -static gboolean -allocate_with_size (CoglTexture2DSliced *tex_2ds, - CoglTextureLoader *loader, - GError **error) -{ - CoglTexture *tex = COGL_TEXTURE (tex_2ds); - CoglPixelFormat internal_format; - - g_warn_if_fail (loader->src.sized.format == COGL_PIXEL_FORMAT_ANY); - - internal_format = - _cogl_texture_determine_internal_format (tex, COGL_PIXEL_FORMAT_ANY); - - if (allocate_slices (tex_2ds, - loader->src.sized.width, - loader->src.sized.height, - tex_2ds->max_waste, - internal_format, - error)) - { - _cogl_texture_set_allocated (COGL_TEXTURE (tex_2ds), - internal_format, - loader->src.sized.width, - loader->src.sized.height); - return TRUE; - } - else - return FALSE; -} - static gboolean allocate_from_bitmap (CoglTexture2DSliced *tex_2ds, CoglTextureLoader *loader, @@ -1033,7 +714,7 @@ _cogl_texture_2d_sliced_allocate (CoglTexture *tex, GError **error) { CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex); - CoglTextureLoader *loader = tex->loader; + CoglTextureLoader *loader = cogl_texture_get_loader (tex); g_return_val_if_fail (loader, FALSE); @@ -1114,8 +795,8 @@ _cogl_texture_2d_sliced_transform_coords_to_gl (CoglTexture *tex, x_span = &g_array_index (tex_2ds->slice_x_spans, CoglSpan, 0); y_span = &g_array_index (tex_2ds->slice_y_spans, CoglSpan, 0); - *s *= tex->width / (float)x_span->size; - *t *= tex->height / (float)y_span->size; + *s *= cogl_texture_get_width (tex) / (float)x_span->size; + *t *= cogl_texture_get_height (tex) / (float)y_span->size; /* Let the child texture further transform the coords */ slice_tex = g_array_index (tex_2ds->slice_textures, CoglTexture2D *, 0); @@ -1228,6 +909,160 @@ _cogl_texture_2d_sliced_ensure_non_quad_rendering (CoglTexture *tex) } } +static void +_cogl_texture_2d_sliced_gl_flush_legacy_texobj_wrap_modes (CoglTexture *tex, + GLenum wrap_mode_s, + GLenum wrap_mode_t) +{ + CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex); + int i; + + /* Pass the set wrap mode on to all of the child textures */ + for (i = 0; i < tex_2ds->slice_textures->len; i++) + { + CoglTexture2D *slice_tex = g_array_index (tex_2ds->slice_textures, + CoglTexture2D *, + i); + + _cogl_texture_gl_flush_legacy_texobj_wrap_modes (COGL_TEXTURE (slice_tex), + wrap_mode_s, + wrap_mode_t); + } +} + +static GLenum +_cogl_texture_2d_sliced_get_gl_format (CoglTexture *tex) +{ + CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex); + CoglTexture2D *slice_tex; + + /* Assert that we've allocated our slices at this point */ + cogl_texture_allocate (tex, NULL); /* (abort on error) */ + + /* Pass the call on to the first slice */ + slice_tex = g_array_index (tex_2ds->slice_textures, CoglTexture2D *, 0); + return _cogl_texture_gl_get_format (COGL_TEXTURE (slice_tex)); +} + +static gboolean +_cogl_texture_2d_sliced_upload_subregion (CoglTexture2DSliced *tex_2ds, + int src_x, + int src_y, + int dst_x, + int dst_y, + int width, + int height, + CoglBitmap *source_bmp, + GError **error) +{ + CoglTexture *tex = COGL_TEXTURE (tex_2ds); + CoglSpan *x_span; + CoglSpan *y_span; + CoglSpanIter x_iter; + CoglSpanIter y_iter; + CoglTexture2D *slice_tex; + int source_x = 0, source_y = 0; + int inter_w = 0, inter_h = 0; + int local_x = 0, local_y = 0; + uint8_t *waste_buf; + CoglPixelFormat source_format; + + source_format = cogl_bitmap_get_format (source_bmp); + + waste_buf = + _cogl_texture_2d_sliced_allocate_waste_buffer (tex_2ds, source_format); + + /* Iterate vertical spans */ + for (source_y = src_y, + _cogl_span_iter_begin (&y_iter, + (CoglSpan *)tex_2ds->slice_y_spans->data, + tex_2ds->slice_y_spans->len, + cogl_texture_get_height (tex), + dst_y, + dst_y + height, + COGL_PIPELINE_WRAP_MODE_REPEAT); + + !_cogl_span_iter_end (&y_iter); + + _cogl_span_iter_next (&y_iter), + source_y += inter_h ) + { + y_span = &g_array_index (tex_2ds->slice_y_spans, CoglSpan, + y_iter.index); + + /* Iterate horizontal spans */ + for (source_x = src_x, + _cogl_span_iter_begin (&x_iter, + (CoglSpan *)tex_2ds->slice_x_spans->data, + tex_2ds->slice_x_spans->len, + cogl_texture_get_width (tex), + dst_x, + dst_x + width, + COGL_PIPELINE_WRAP_MODE_REPEAT); + + !_cogl_span_iter_end (&x_iter); + + _cogl_span_iter_next (&x_iter), + source_x += inter_w ) + { + int slice_num; + + x_span = &g_array_index (tex_2ds->slice_x_spans, CoglSpan, + x_iter.index); + + /* Pick intersection width and height */ + inter_w = (x_iter.intersect_end - x_iter.intersect_start); + inter_h = (y_iter.intersect_end - y_iter.intersect_start); + + /* Localize intersection top-left corner to slice*/ + local_x = (x_iter.intersect_start - x_iter.pos); + local_y = (y_iter.intersect_start - y_iter.pos); + + slice_num = y_iter.index * tex_2ds->slice_x_spans->len + x_iter.index; + + /* Pick slice texture */ + slice_tex = g_array_index (tex_2ds->slice_textures, + CoglTexture2D *, slice_num); + + if (!_cogl_texture_set_region_from_bitmap (COGL_TEXTURE (slice_tex), + source_x, + source_y, + inter_w, /* width */ + inter_h, /* height */ + source_bmp, + local_x, /* dst x */ + local_y, /* dst y */ + 0, /* level */ + error)) + { + if (waste_buf) + g_free (waste_buf); + return FALSE; + } + + if (!_cogl_texture_2d_sliced_set_waste (tex_2ds, + source_bmp, + slice_tex, + waste_buf, + x_span, y_span, + &x_iter, &y_iter, + src_x, src_y, + dst_x, dst_y, + error)) + { + if (waste_buf) + g_free (waste_buf); + return FALSE; + } + } + } + + if (waste_buf) + g_free (waste_buf); + + return TRUE; +} + static gboolean _cogl_texture_2d_sliced_set_region (CoglTexture *tex, int src_x, @@ -1261,6 +1096,78 @@ _cogl_texture_2d_sliced_set_region (CoglTexture *tex, return status; } +static void +re_normalize_sub_texture_coords_cb (CoglTexture *sub_texture, + const float *sub_texture_coords, + const float *meta_coords, + void *user_data) +{ + ForeachData *data = user_data; + /* The coordinates passed to the span iterating code were + * un-normalized so we need to renormalize them before passing them + * on */ + float re_normalized_coords[4] = + { + meta_coords[0] * data->x_normalize_factor, + meta_coords[1] * data->y_normalize_factor, + meta_coords[2] * data->x_normalize_factor, + meta_coords[3] * data->y_normalize_factor + }; + + data->callback (sub_texture, sub_texture_coords, re_normalized_coords, + data->user_data); +} + +static void +_cogl_texture_2d_sliced_foreach_sub_texture_in_region ( + CoglTexture *tex, + float virtual_tx_1, + float virtual_ty_1, + float virtual_tx_2, + float virtual_ty_2, + CoglMetaTextureCallback callback, + void *user_data) +{ + CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex); + CoglSpan *x_spans = (CoglSpan *)tex_2ds->slice_x_spans->data; + CoglSpan *y_spans = (CoglSpan *)tex_2ds->slice_y_spans->data; + CoglTexture **textures = (CoglTexture **)tex_2ds->slice_textures->data; + float un_normalized_coords[4]; + ForeachData data; + + /* NB: its convenient for us to store non-normalized coordinates in + * our CoglSpans but that means we need to un-normalize the incoming + * virtual coordinates and make sure we re-normalize the coordinates + * before calling the given callback. + */ + + data.callback = callback; + data.user_data = user_data; + data.x_normalize_factor = 1.0f / cogl_texture_get_width (tex); + data.y_normalize_factor = 1.0f / cogl_texture_get_height (tex); + + un_normalized_coords[0] = virtual_tx_1 * cogl_texture_get_width (tex); + un_normalized_coords[1] = virtual_ty_1 * cogl_texture_get_height (tex); + un_normalized_coords[2] = virtual_tx_2 * cogl_texture_get_width (tex); + un_normalized_coords[3] = virtual_ty_2 * cogl_texture_get_height (tex); + + /* Note that the normalize factors passed here are the reciprocal of + * the factors calculated above because the span iterating code + * normalizes by dividing by the factor instead of multiplying */ + _cogl_texture_spans_foreach_in_region (x_spans, + tex_2ds->slice_x_spans->len, + y_spans, + tex_2ds->slice_y_spans->len, + textures, + un_normalized_coords, + cogl_texture_get_width (tex), + cogl_texture_get_height (tex), + COGL_PIPELINE_WRAP_MODE_REPEAT, + COGL_PIPELINE_WRAP_MODE_REPEAT, + re_normalize_sub_texture_coords_cb, + &data); +} + static CoglPixelFormat _cogl_texture_2d_sliced_get_format (CoglTexture *tex) { @@ -1269,40 +1176,136 @@ _cogl_texture_2d_sliced_get_format (CoglTexture *tex) return tex_2ds->internal_format; } -static GLenum -_cogl_texture_2d_sliced_get_gl_format (CoglTexture *tex) +static void +cogl_texture_2d_sliced_class_init (CoglTexture2DSlicedClass *klass) { - CoglTexture2DSliced *tex_2ds = COGL_TEXTURE_2D_SLICED (tex); - CoglTexture2D *slice_tex; + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + CoglTextureClass *texture_class = COGL_TEXTURE_CLASS (klass); - /* Assert that we've allocated our slices at this point */ - cogl_texture_allocate (tex, NULL); /* (abort on error) */ + gobject_class->dispose = cogl_texture_2d_sliced_dispose; - /* Pass the call on to the first slice */ - slice_tex = g_array_index (tex_2ds->slice_textures, CoglTexture2D *, 0); - return _cogl_texture_gl_get_format (COGL_TEXTURE (slice_tex)); + texture_class->allocate = _cogl_texture_2d_sliced_allocate; + texture_class->set_region = _cogl_texture_2d_sliced_set_region; + texture_class->foreach_sub_texture_in_region = _cogl_texture_2d_sliced_foreach_sub_texture_in_region; + texture_class->get_max_waste = _cogl_texture_2d_sliced_get_max_waste; + texture_class->is_sliced = _cogl_texture_2d_sliced_is_sliced; + texture_class->can_hardware_repeat = _cogl_texture_2d_sliced_can_hardware_repeat; + texture_class->transform_coords_to_gl = _cogl_texture_2d_sliced_transform_coords_to_gl; + texture_class->transform_quad_coords_to_gl = _cogl_texture_2d_sliced_transform_quad_coords_to_gl; + texture_class->get_gl_texture = _cogl_texture_2d_sliced_get_gl_texture; + texture_class->gl_flush_legacy_texobj_filters = _cogl_texture_2d_sliced_gl_flush_legacy_texobj_filters; + texture_class->pre_paint = _cogl_texture_2d_sliced_pre_paint; + texture_class->ensure_non_quad_rendering = _cogl_texture_2d_sliced_ensure_non_quad_rendering; + texture_class->gl_flush_legacy_texobj_wrap_modes = _cogl_texture_2d_sliced_gl_flush_legacy_texobj_wrap_modes; + texture_class->get_format = _cogl_texture_2d_sliced_get_format; + texture_class->get_gl_format = _cogl_texture_2d_sliced_get_gl_format; +} + +static void +cogl_texture_2d_sliced_init (CoglTexture2DSliced *self) +{ + CoglTexture *texture = COGL_TEXTURE (self); + + texture->is_primitive = FALSE; +} + +static CoglTexture * +_cogl_texture_2d_sliced_create_base (CoglContext *ctx, + int width, + int height, + int max_waste, + CoglPixelFormat internal_format, + CoglTextureLoader *loader) +{ + CoglTexture2DSliced *tex_2ds = g_object_new (COGL_TYPE_TEXTURE_2D_SLICED, NULL); + + _cogl_texture_init (COGL_TEXTURE (tex_2ds), ctx, width, height, + internal_format, loader); + + tex_2ds->max_waste = max_waste; + + return COGL_TEXTURE (tex_2ds); +} + +CoglTexture * +cogl_texture_2d_sliced_new_with_size (CoglContext *ctx, + int width, + int height, + int max_waste) +{ + CoglTextureLoader *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_sliced_create_base (ctx, + width, + height, + max_waste, + COGL_PIXEL_FORMAT_RGBA_8888_PRE, + loader); +} + +CoglTexture * +cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp, + int max_waste) +{ + CoglTextureLoader *loader; + + g_return_val_if_fail (COGL_IS_BITMAP (bmp), 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_sliced_create_base (_cogl_bitmap_get_context (bmp), + cogl_bitmap_get_width (bmp), + cogl_bitmap_get_height (bmp), + max_waste, + cogl_bitmap_get_format (bmp), + loader); +} + +CoglTexture * +cogl_texture_2d_sliced_new_from_data (CoglContext *ctx, + int width, + int height, + int max_waste, + CoglPixelFormat format, + int rowstride, + const uint8_t *data, + GError **error) +{ + CoglBitmap *bmp; + CoglTexture *tex_2ds; + + 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_2ds = cogl_texture_2d_sliced_new_from_bitmap (bmp, max_waste); + + g_object_unref (bmp); + + if (tex_2ds && + !cogl_texture_allocate (COGL_TEXTURE (tex_2ds), error)) + { + g_object_unref (tex_2ds); + return NULL; + } + + return tex_2ds; } -static const CoglTextureVtable -cogl_texture_2d_sliced_vtable = - { - FALSE, /* not primitive */ - _cogl_texture_2d_sliced_allocate, - _cogl_texture_2d_sliced_set_region, - NULL, /* is_get_data_supported */ - NULL, /* get_data */ - _cogl_texture_2d_sliced_foreach_sub_texture_in_region, - _cogl_texture_2d_sliced_get_max_waste, - _cogl_texture_2d_sliced_is_sliced, - _cogl_texture_2d_sliced_can_hardware_repeat, - _cogl_texture_2d_sliced_transform_coords_to_gl, - _cogl_texture_2d_sliced_transform_quad_coords_to_gl, - _cogl_texture_2d_sliced_get_gl_texture, - _cogl_texture_2d_sliced_gl_flush_legacy_texobj_filters, - _cogl_texture_2d_sliced_pre_paint, - _cogl_texture_2d_sliced_ensure_non_quad_rendering, - _cogl_texture_2d_sliced_gl_flush_legacy_texobj_wrap_modes, - _cogl_texture_2d_sliced_get_format, - _cogl_texture_2d_sliced_get_gl_format, - NULL /* set_auto_mipmap */ - }; diff --git a/cogl/cogl/cogl-texture-2d-sliced.h b/cogl/cogl/cogl-texture-2d-sliced.h index 7baf60587..bb13f0113 100644 --- a/cogl/cogl/cogl-texture-2d-sliced.h +++ b/cogl/cogl/cogl-texture-2d-sliced.h @@ -36,10 +36,11 @@ #include "cogl/cogl-types.h" /** - * SECTION:cogl-texture-2d-sliced - * @short_description: Functions for creating and manipulating 2D meta - * textures that may internally be comprised of - * multiple 2D textures with power-of-two sizes. + * CoglTexture2DSliced: + * + * Functions for creating and manipulating 2D meta textures + * that may internally be comprised of multiple 2D textures + * with power-of-two sizes. * * These functions allow high-level meta textures (See the * #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 * 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; -#define COGL_TEXTURE_2D_SLICED(X) ((CoglTexture2DSliced *)X) -/** - * cogl_texture_2d_sliced_get_gtype: - * - * Returns: a #GType that can be used with the GLib type system. - */ +G_DEFINE_AUTOPTR_CLEANUP_FUNC (CoglTexture2DSliced, g_object_unref) + 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) @@ -115,7 +120,7 @@ GType cogl_texture_2d_sliced_get_gtype (void); * Returns: (transfer full): A new #CoglTexture2DSliced object with no storage * allocated yet. */ -COGL_EXPORT CoglTexture2DSliced * +COGL_EXPORT CoglTexture * cogl_texture_2d_sliced_new_with_size (CoglContext *ctx, int width, int height, @@ -174,7 +179,7 @@ cogl_texture_2d_sliced_new_with_size (CoglContext *ctx, * Return value: (transfer full): A newly created #CoglTexture2DSliced * or %NULL on failure and @error will be updated. */ -COGL_EXPORT CoglTexture2DSliced * +COGL_EXPORT CoglTexture * cogl_texture_2d_sliced_new_from_data (CoglContext *ctx, int width, int height, @@ -223,18 +228,6 @@ cogl_texture_2d_sliced_new_from_data (CoglContext *ctx, * Return value: (transfer full): A newly created #CoglTexture2DSliced * or %NULL on failure and @error will be updated. */ -COGL_EXPORT CoglTexture2DSliced * +COGL_EXPORT CoglTexture * cogl_texture_2d_sliced_new_from_bitmap (CoglBitmap *bmp, - 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); + int max_waste); diff --git a/cogl/cogl/cogl-texture-2d.c b/cogl/cogl/cogl-texture-2d.c index 752b6cec6..ba8610022 100644 --- a/cogl/cogl/cogl-texture-2d.c +++ b/cogl/cogl/cogl-texture-2d.c @@ -39,10 +39,8 @@ #include "cogl/cogl-texture-2d-private.h" #include "cogl/cogl-texture-driver.h" #include "cogl/cogl-context-private.h" -#include "cogl/cogl-object-private.h" #include "cogl/cogl-journal-private.h" #include "cogl/cogl-framebuffer-private.h" -#include "cogl/cogl-gtype-private.h" #include "cogl/driver/gl/cogl-texture-2d-gl-private.h" #ifdef COGL_HAS_EGL_SUPPORT #include "cogl/winsys/cogl-winsys-egl-private.h" @@ -51,13 +49,7 @@ #include #include -static void _cogl_texture_2d_free (CoglTexture2D *tex_2d); - -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; +G_DEFINE_FINAL_TYPE (CoglTexture2D, cogl_texture_2d, COGL_TYPE_TEXTURE) typedef struct _CoglTexture2DManualRepeatData { @@ -67,14 +59,14 @@ typedef struct _CoglTexture2DManualRepeatData } CoglTexture2DManualRepeatData; 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); - /* Chain up */ - _cogl_texture_free (COGL_TEXTURE (tex_2d)); + G_OBJECT_CLASS (cogl_texture_2d_parent_class)->dispose (object); } void @@ -86,18 +78,17 @@ _cogl_texture_2d_set_auto_mipmap (CoglTexture *tex, tex_2d->auto_mipmap = value; } -CoglTexture2D * +CoglTexture * _cogl_texture_2d_create_base (CoglContext *ctx, int width, int height, CoglPixelFormat internal_format, 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); - _cogl_texture_init (tex, ctx, width, height, internal_format, loader, - &cogl_texture_2d_vtable); + _cogl_texture_init (tex, ctx, width, height, internal_format, loader); tex_2d->mipmaps_dirty = 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); - return _cogl_texture_2d_object_new (tex_2d); -} - -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); + return tex; } static gboolean _cogl_texture_2d_allocate (CoglTexture *tex, GError **error) { - CoglContext *ctx = tex->context; + CoglContext *ctx = cogl_texture_get_context (tex); 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 _cogl_texture_2d_copy_from_framebuffer (CoglTexture2D *tex_2d, int src_x, @@ -284,7 +122,7 @@ _cogl_texture_2d_copy_from_framebuffer (CoglTexture2D *tex_2d, int level) { 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 */ cogl_texture_allocate (tex, NULL); /* (abort on error) */ @@ -356,7 +194,7 @@ _cogl_texture_2d_get_gl_texture (CoglTexture *tex, GLuint *out_gl_handle, GLenum *out_gl_target) { - CoglContext *ctx = tex->context; + CoglContext *ctx = cogl_texture_get_context (tex); CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex); 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) && 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 * better make sure tex is up-to-date. @@ -421,7 +259,7 @@ _cogl_texture_2d_set_region (CoglTexture *tex, CoglBitmap *bmp, GError **error) { - CoglContext *ctx = tex->context; + CoglContext *ctx = cogl_texture_get_context (tex); CoglTexture2D *tex_2d = COGL_TEXTURE_2D (tex); 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) { 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); } @@ -458,7 +296,7 @@ _cogl_texture_2d_get_data (CoglTexture *tex, int rowstride, uint8_t *data) { - CoglContext *ctx = tex->context; + CoglContext *ctx = cogl_texture_get_context (tex); 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; } -static const CoglTextureVtable -cogl_texture_2d_vtable = - { - TRUE, /* primitive */ - _cogl_texture_2d_allocate, - _cogl_texture_2d_set_region, - _cogl_texture_2d_is_get_data_supported, - _cogl_texture_2d_get_data, - NULL, /* foreach_sub_texture_in_region */ - _cogl_texture_2d_get_max_waste, - _cogl_texture_2d_is_sliced, - _cogl_texture_2d_can_hardware_repeat, - _cogl_texture_2d_transform_coords_to_gl, - _cogl_texture_2d_transform_quad_coords_to_gl, - _cogl_texture_2d_get_gl_texture, - _cogl_texture_2d_gl_flush_legacy_texobj_filters, - _cogl_texture_2d_pre_paint, - _cogl_texture_2d_ensure_non_quad_rendering, - _cogl_texture_2d_gl_flush_legacy_texobj_wrap_modes, - _cogl_texture_2d_get_format, - _cogl_texture_2d_get_gl_format, - _cogl_texture_2d_set_auto_mipmap - }; +static void +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)) + { + g_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. */ +CoglTexture * +cogl_egl_texture_2d_new_from_image (CoglContext *ctx, + int width, + int height, + CoglPixelFormat format, + EGLImageKHR image, + CoglEglImageFlags flags, + 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; +} diff --git a/cogl/cogl/cogl-texture-2d.h b/cogl/cogl/cogl-texture-2d.h index bc76695d2..1ef693567 100644 --- a/cogl/cogl/cogl-texture-2d.h +++ b/cogl/cogl/cogl-texture-2d.h @@ -46,8 +46,9 @@ G_BEGIN_DECLS /** - * SECTION:cogl-texture-2d - * @short_description: Functions for creating and manipulating 2D textures + * CoglTexture2D: + * + * Functions for creating and manipulating 2D textures * * These functions allow low-level 2D textures to be allocated. These * differ from sliced textures for example which may internally be @@ -56,8 +57,21 @@ G_BEGIN_DECLS * 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; -#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 { @@ -65,27 +79,6 @@ typedef enum _CoglEglImageFlags COGL_EGL_IMAGE_FLAG_NO_GET_DATA = 1 << 0, } 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) * @ctx: A #CoglContext @@ -111,7 +104,7 @@ cogl_is_texture_2d (void *object); * * Since: 2.0 */ -COGL_EXPORT CoglTexture2D * +COGL_EXPORT CoglTexture * cogl_texture_2d_new_with_format (CoglContext *ctx, int width, 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. */ -COGL_EXPORT CoglTexture2D * +COGL_EXPORT CoglTexture * cogl_texture_2d_new_with_size (CoglContext *ctx, int width, 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) * it will return %NULL and set @error. */ -COGL_EXPORT CoglTexture2D * +COGL_EXPORT CoglTexture * cogl_texture_2d_new_from_data (CoglContext *ctx, int width, int height, @@ -204,7 +197,7 @@ cogl_texture_2d_new_from_data (CoglContext *ctx, * * Returns: (transfer full): A newly allocated #CoglTexture2D */ -COGL_EXPORT CoglTexture2D * +COGL_EXPORT CoglTexture * 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 * even though they may seem redundant is because GLES 1/2 don't * provide a way to query these properties. */ -COGL_EXPORT CoglTexture2D * +COGL_EXPORT CoglTexture * cogl_egl_texture_2d_new_from_image (CoglContext *ctx, int width, int height, @@ -230,7 +223,7 @@ typedef gboolean (*CoglTexture2DEGLImageExternalAlloc) (CoglTexture2D *tex_2d, /** * 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, int width, int height, diff --git a/cogl/cogl/cogl-texture-private.h b/cogl/cogl/cogl-texture-private.h index f63fa5709..c3fce9aa5 100644 --- a/cogl/cogl/cogl-texture-private.h +++ b/cogl/cogl/cogl-texture-private.h @@ -31,7 +31,6 @@ #pragma once #include "cogl/cogl-bitmap-private.h" -#include "cogl/cogl-object-private.h" #include "cogl/cogl-pipeline-private.h" #include "cogl/cogl-spans.h" #include "cogl/cogl-meta-texture.h" @@ -42,8 +41,6 @@ #include "cogl/cogl-egl-defines.h" #endif -typedef struct _CoglTextureVtable CoglTextureVtable; - /* Encodes three possibiloities result of transforming a quad */ typedef enum { @@ -66,88 +63,6 @@ typedef enum COGL_TEXTURE_NEEDS_MIPMAP = 1 } CoglTexturePrePaintFlags; -struct _CoglTextureVtable -{ - /* Virtual functions that must be implemented for a texture - backend */ - - gboolean is_primitive; - - gboolean (* allocate) (CoglTexture *tex, - GError **error); - - /* This should update the specified sub region of the texture with a - sub region of the given bitmap. The bitmap is not converted - before being set so the caller is expected to have called - _cogl_bitmap_convert_for_upload with a suitable internal_format - before passing here */ - gboolean (* set_region) (CoglTexture *tex, - int src_x, - int src_y, - int dst_x, - int dst_y, - int dst_width, - int dst_height, - int level, - CoglBitmap *bitmap, - GError **error); - - gboolean (* is_get_data_supported) (CoglTexture *texture); - - /* This should copy the image data of the texture into @data. The - requested format will have been first passed through - ctx->texture_driver->find_best_gl_get_data_format so it should - always be a format that is valid for GL (ie, no conversion should - be necessary). */ - gboolean (* get_data) (CoglTexture *tex, - CoglPixelFormat format, - int rowstride, - uint8_t *data); - - void (* foreach_sub_texture_in_region) (CoglTexture *tex, - float virtual_tx_1, - float virtual_ty_1, - float virtual_tx_2, - float virtual_ty_2, - CoglMetaTextureCallback callback, - void *user_data); - - int (* get_max_waste) (CoglTexture *tex); - - gboolean (* is_sliced) (CoglTexture *tex); - - gboolean (* can_hardware_repeat) (CoglTexture *tex); - - void (* transform_coords_to_gl) (CoglTexture *tex, - float *s, - float *t); - CoglTransformResult (* transform_quad_coords_to_gl) (CoglTexture *tex, - float *coords); - - gboolean (* get_gl_texture) (CoglTexture *tex, - GLuint *out_gl_handle, - GLenum *out_gl_target); - - /* OpenGL driver specific virtual function */ - void (* gl_flush_legacy_texobj_filters) (CoglTexture *tex, - GLenum min_filter, - GLenum mag_filter); - - void (* pre_paint) (CoglTexture *tex, CoglTexturePrePaintFlags flags); - void (* ensure_non_quad_rendering) (CoglTexture *tex); - - /* OpenGL driver specific virtual function */ - void (* gl_flush_legacy_texobj_wrap_modes) (CoglTexture *tex, - GLenum wrap_mode_s, - GLenum wrap_mode_t); - - CoglPixelFormat (* get_format) (CoglTexture *tex); - GLenum (* get_gl_format) (CoglTexture *tex); - - /* Only needs to be implemented if is_primitive == TRUE */ - void (* set_auto_mipmap) (CoglTexture *texture, - gboolean value); -}; typedef enum _CoglTextureSourceType { COGL_TEXTURE_SOURCE_TYPE_SIZE = 1, @@ -199,8 +114,10 @@ typedef struct _CoglTextureLoader struct _CoglTexture { - CoglObject _parent; + GObject parent_instance; + CoglContext *context; + gboolean is_primitive; CoglTextureLoader *loader; GList *framebuffers; int max_level_set; @@ -213,9 +130,87 @@ struct _CoglTexture * Internal format */ CoglTextureComponents components; - unsigned int premultiplied:1; + unsigned int premultiplied : 1; +}; - const CoglTextureVtable *vtable; +struct _CoglTextureClass +{ + GObjectClass parent_class; + gboolean (* allocate) (CoglTexture *tex, + GError **error); + + /* This should update the specified sub region of the texture with a + sub region of the given bitmap. The bitmap is not converted + before being set so the caller is expected to have called + _cogl_bitmap_convert_for_upload with a suitable internal_format + before passing here */ + gboolean (* set_region) (CoglTexture *tex, + int src_x, + int src_y, + int dst_x, + int dst_y, + int dst_width, + int dst_height, + int level, + CoglBitmap *bitmap, + GError **error); + + gboolean (* is_get_data_supported) (CoglTexture *texture); + + /* This should copy the image data of the texture into @data. The + requested format will have been first passed through + ctx->texture_driver->find_best_gl_get_data_format so it should + always be a format that is valid for GL (ie, no conversion should + be necessary). */ + gboolean (* get_data) (CoglTexture *tex, + CoglPixelFormat format, + int rowstride, + uint8_t *data); + + void (* foreach_sub_texture_in_region) (CoglTexture *tex, + float virtual_tx_1, + float virtual_ty_1, + float virtual_tx_2, + float virtual_ty_2, + CoglMetaTextureCallback callback, + void *user_data); + + int (* get_max_waste) (CoglTexture *tex); + + gboolean (* is_sliced) (CoglTexture *tex); + + gboolean (* can_hardware_repeat) (CoglTexture *tex); + + void (* transform_coords_to_gl) (CoglTexture *tex, + float *s, + float *t); + CoglTransformResult (* transform_quad_coords_to_gl) (CoglTexture *tex, + float *coords); + + gboolean (* get_gl_texture) (CoglTexture *tex, + GLuint *out_gl_handle, + GLenum *out_gl_target); + + /* OpenGL driver specific virtual function */ + void (* gl_flush_legacy_texobj_filters) (CoglTexture *tex, + GLenum min_filter, + GLenum mag_filter); + + void (* pre_paint) (CoglTexture *tex, + CoglTexturePrePaintFlags flags); + void (* ensure_non_quad_rendering) (CoglTexture *tex); + + /* OpenGL driver specific virtual function */ + void (* gl_flush_legacy_texobj_wrap_modes) (CoglTexture *tex, + GLenum wrap_mode_s, + GLenum wrap_mode_t); + + CoglPixelFormat (* get_format) (CoglTexture *tex); + GLenum (* get_gl_format) (CoglTexture *tex); + + /* Only needs to be implemented if is_primitive == TRUE */ + void (* set_auto_mipmap) (CoglTexture *texture, + gboolean value); }; typedef enum _CoglTextureChangeFlags @@ -251,26 +246,8 @@ _cogl_texture_init (CoglTexture *texture, int width, int height, CoglPixelFormat src_format, - CoglTextureLoader *loader, - const CoglTextureVtable *vtable); + CoglTextureLoader *loader); -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_texture_can_hardware_repeat (CoglTexture *texture); @@ -403,3 +380,16 @@ _cogl_texture_create_loader (void); void _cogl_texture_copy_internal_format (CoglTexture *src, 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); diff --git a/cogl/cogl/cogl-texture.c b/cogl/cogl/cogl-texture.c index ec0fd0a54..8ee6253ff 100644 --- a/cogl/cogl/cogl-texture.c +++ b/cogl/cogl/cogl-texture.c @@ -50,94 +50,17 @@ #include "cogl/cogl-atlas-texture-private.h" #include "cogl/cogl-pipeline.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-framebuffer-private.h" #include "cogl/cogl1-context.h" #include "cogl/cogl-sub-texture.h" #include "cogl/cogl-primitive-texture.h" -#include "cogl/cogl-gtype-private.h" #include #include #include -COGL_GTYPE_DEFINE_INTERFACE (Texture, texture); - -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; -} +G_DEFINE_ABSTRACT_TYPE (CoglTexture, cogl_texture, G_TYPE_OBJECT) static void _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 * _cogl_texture_create_loader (void) { return g_new0 (CoglTextureLoader, 1); } -void -_cogl_texture_free (CoglTexture *texture) -{ - _cogl_texture_free_loader (texture); - - g_free (texture); -} - gboolean _cogl_texture_needs_premult_conversion (CoglPixelFormat src_format, CoglPixelFormat dst_format) @@ -188,8 +166,8 @@ _cogl_texture_needs_premult_conversion (CoglPixelFormat src_format, gboolean cogl_texture_is_get_data_supported (CoglTexture *texture) { - if (texture->vtable->is_get_data_supported) - return texture->vtable->is_get_data_supported (texture); + if (COGL_TEXTURE_GET_CLASS (texture)->is_get_data_supported) + return COGL_TEXTURE_GET_CLASS (texture)->is_get_data_supported (texture); else return TRUE; } @@ -197,7 +175,7 @@ cogl_texture_is_get_data_supported (CoglTexture *texture) unsigned int 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; } @@ -205,7 +183,7 @@ cogl_texture_get_width (CoglTexture *texture) unsigned int 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; } @@ -215,15 +193,16 @@ _cogl_texture_get_format (CoglTexture *texture) { if (!texture->allocated) cogl_texture_allocate (texture, NULL); - return texture->vtable->get_format (texture); + + return COGL_TEXTURE_GET_CLASS (texture)->get_format (texture); } int 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 @@ -278,11 +257,12 @@ _cogl_texture_get_level_size (CoglTexture *texture, gboolean 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) 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 @@ -294,7 +274,7 @@ _cogl_texture_can_hardware_repeat (CoglTexture *texture) { if (!texture->allocated) 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 @@ -305,14 +285,14 @@ _cogl_texture_transform_coords_to_gl (CoglTexture *texture, float *s, float *t) { - texture->vtable->transform_coords_to_gl (texture, s, t); + COGL_TEXTURE_GET_CLASS (texture)->transform_coords_to_gl (texture, s, t); } CoglTransformResult _cogl_texture_transform_quad_coords_to_gl (CoglTexture *texture, 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 @@ -320,13 +300,14 @@ cogl_texture_get_gl_texture (CoglTexture *texture, GLuint *out_gl_handle, 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) cogl_texture_allocate (texture, NULL); - return texture->vtable->get_gl_texture (texture, - out_gl_handle, out_gl_target); + return COGL_TEXTURE_GET_CLASS (texture)->get_gl_texture (texture, + out_gl_handle, + out_gl_target); } void @@ -346,13 +327,14 @@ _cogl_texture_pre_paint (CoglTexture *texture, CoglTexturePrePaintFlags flags) */ cogl_texture_allocate (texture, NULL); - texture->vtable->pre_paint (texture, flags); + COGL_TEXTURE_GET_CLASS (texture)->pre_paint (texture, + flags); } void _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 @@ -383,13 +365,13 @@ _cogl_texture_set_region_from_bitmap (CoglTexture *texture, always stored in an RGBA texture even if the texture format is advertised as RGB. */ - return texture->vtable->set_region (texture, - src_x, src_y, - dst_x, dst_y, - width, height, - level, - bmp, - error); + return COGL_TEXTURE_GET_CLASS (texture)->set_region (texture, + src_x, src_y, + dst_x, dst_y, + width, height, + level, + bmp, + error); } gboolean @@ -405,7 +387,7 @@ cogl_texture_set_region_from_bitmap (CoglTexture *texture, GError *ignore_error = NULL; 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, src_x, src_y, @@ -431,7 +413,7 @@ _cogl_texture_set_region (CoglTexture *texture, int level, GError **error) { - CoglContext *ctx = texture->context; + CoglContext *ctx = cogl_texture_get_context (texture); CoglBitmap *source_bmp; gboolean ret; @@ -481,7 +463,7 @@ cogl_texture_set_region (CoglTexture *texture, int bytes_per_pixel; 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 (cogl_pixel_format_get_n_planes (format) == 1, FALSE); @@ -517,7 +499,7 @@ cogl_texture_set_data (CoglTexture *texture, int level_width; 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, level, @@ -547,7 +529,7 @@ get_texture_bits_via_offscreen (CoglTexture *meta_texture, unsigned int dst_rowstride, CoglPixelFormat closest_format) { - CoglContext *ctx = sub_texture->context; + CoglContext *ctx = cogl_texture_get_context (sub_texture); CoglOffscreen *offscreen; CoglFramebuffer *framebuffer; CoglBitmap *bitmap; @@ -628,10 +610,10 @@ get_texture_bits_via_copy (CoglTexture *texture, full_rowstride = bpp * full_tex_width; full_bits = g_malloc (full_rowstride * full_tex_height); - if (texture->vtable->get_data (texture, - dst_format, - full_rowstride, - full_bits)) + if (COGL_TEXTURE_GET_CLASS (texture)->get_data (texture, + dst_format, + full_rowstride, + full_bits)) { uint8_t *dst = dst_bits; uint8_t *src = full_bits + x * bpp + y * full_rowstride; @@ -702,10 +684,10 @@ texture_get_cb (CoglTexture *subtexture, if (x_in_subtexture == 0 && y_in_subtexture == 0 && width == subtexture_width && height == subtexture_height) { - if (subtexture->vtable->get_data (subtexture, - closest_format, - rowstride, - dst_bits)) + if (COGL_TEXTURE_GET_CLASS (subtexture)->get_data (subtexture, + closest_format, + rowstride, + dst_bits)) return; } @@ -752,7 +734,7 @@ cogl_texture_get_data (CoglTexture *texture, GError *ignore_error = NULL; 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); @@ -776,7 +758,7 @@ cogl_texture_get_data (CoglTexture *texture, if (data == NULL) return byte_size; - ctx = texture->context; + ctx = cogl_texture_get_context (texture); closest_format = ctx->texture_driver->find_best_gl_get_data_format (ctx, format, @@ -856,7 +838,7 @@ cogl_texture_get_data (CoglTexture *texture, * the data for a sliced texture, and allows us to do the * read-from-framebuffer logic here in a simple fashion rather than * 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, COGL_PIPELINE_WRAP_MODE_REPEAT, COGL_PIPELINE_WRAP_MODE_REPEAT, @@ -939,12 +921,12 @@ _cogl_texture_get_associated_framebuffers (CoglTexture *texture) void _cogl_texture_flush_journal_rendering (CoglTexture *texture) { - GList *l; + const GList *l; /* It could be that a referenced texture is part of a framebuffer * which has an associated journal that must be flushed before it * 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); } @@ -1081,7 +1063,7 @@ gboolean cogl_texture_allocate (CoglTexture *texture, 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) return TRUE; @@ -1094,7 +1076,7 @@ cogl_texture_allocate (CoglTexture *texture, "A red-green texture was requested but the driver " "does not support them"); - texture->allocated = texture->vtable->allocate (texture, error); + texture->allocated = COGL_TEXTURE_GET_CLASS (texture)->allocate (texture, error); return texture->allocated; } @@ -1138,14 +1120,14 @@ CoglPixelFormat _cogl_texture_determine_internal_format (CoglTexture *texture, CoglPixelFormat src_format) { - switch (texture->components) + switch (cogl_texture_get_components (texture)) { case COGL_TEXTURE_COMPONENTS_DEPTH: if (src_format & COGL_DEPTH_BIT) return src_format; else { - CoglContext *ctx = texture->context; + CoglContext *ctx = cogl_texture_get_context (texture); if (_cogl_has_private_feature (ctx, COGL_PRIVATE_FEATURE_EXT_PACKED_DEPTH_STENCIL) || @@ -1177,7 +1159,7 @@ _cogl_texture_determine_internal_format (CoglTexture *texture, else format = COGL_PIXEL_FORMAT_RGBA_8888; - if (texture->premultiplied) + if (cogl_texture_get_premultiplied (texture)) { if (COGL_PIXEL_FORMAT_CAN_HAVE_PREMULT (format)) return format |= COGL_PREMULT_BIT; @@ -1196,7 +1178,7 @@ void cogl_texture_set_components (CoglTexture *texture, CoglTextureComponents components) { - g_return_if_fail (cogl_is_texture (texture)); + g_return_if_fail (COGL_IS_TEXTURE (texture)); g_return_if_fail (!texture->allocated); if (texture->components == components) @@ -1208,7 +1190,7 @@ cogl_texture_set_components (CoglTexture *texture, CoglTextureComponents 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; } @@ -1217,7 +1199,7 @@ void cogl_texture_set_premultiplied (CoglTexture *texture, gboolean premultiplied) { - g_return_if_fail (cogl_is_texture (texture)); + g_return_if_fail (COGL_IS_TEXTURE (texture)); g_return_if_fail (!texture->allocated); premultiplied = !!premultiplied; @@ -1231,7 +1213,7 @@ cogl_texture_set_premultiplied (CoglTexture *texture, gboolean 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; } @@ -1240,6 +1222,31 @@ void _cogl_texture_copy_internal_format (CoglTexture *src, CoglTexture *dest) { - cogl_texture_set_components (dest, src->components); - cogl_texture_set_premultiplied (dest, src->premultiplied); + cogl_texture_set_components (dest, cogl_texture_get_components (src)); + 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; +} \ No newline at end of file diff --git a/cogl/cogl/cogl-texture.h b/cogl/cogl/cogl-texture.h index 6139c41b5..61552c9c2 100644 --- a/cogl/cogl/cogl-texture.h +++ b/cogl/cogl/cogl-texture.h @@ -34,21 +34,6 @@ #error "Only can be included directly." #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-defines.h" #include "cogl/cogl-pixel-buffer.h" @@ -60,23 +45,32 @@ typedef struct _CoglTexture CoglTexture; G_BEGIN_DECLS /** - * SECTION:cogl-texture - * @short_description: Functions for creating and manipulating textures + * CoglTexture: + * + * Functions for creating and manipulating textures * * Cogl allows creating and manipulating textures using a uniform * API that tries to hide all the various complexities of creating, * 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 -GType cogl_texture_get_gtype (void); +GType cogl_texture_get_type (void) G_GNUC_CONST; + +#define COGL_TEXTURE_MAX_WASTE 127 /** * COGL_TEXTURE_ERROR: @@ -105,17 +99,6 @@ typedef enum COGL_EXPORT 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: diff --git a/cogl/cogl/deprecated/cogl-type-casts.h b/cogl/cogl/deprecated/cogl-type-casts.h index db917d623..61025884b 100644 --- a/cogl/cogl/deprecated/cogl-type-casts.h +++ b/cogl/cogl/deprecated/cogl-type-casts.h @@ -45,7 +45,4 @@ #if !defined(COGL_ENABLE_MUTTER_API) && !defined(COGL_GIR_SCANNING) #define COGL_BUFFER(X) (X) -#define COGL_TEXTURE(X) (X) -#define COGL_META_TEXTURE(X) (X) -#define COGL_PRIMITIVE_TEXTURE(X) (X) #endif diff --git a/cogl/cogl/driver/gl/cogl-pipeline-opengl.c b/cogl/cogl/driver/gl/cogl-pipeline-opengl.c index 6c3ea2555..8c9406c50 100644 --- a/cogl/cogl/driver/gl/cogl-pipeline-opengl.c +++ b/cogl/cogl/driver/gl/cogl-pipeline-opengl.c @@ -503,7 +503,7 @@ flush_layers_common_gl_state_cb (CoglPipelineLayer *layer, void *user_data) GLenum gl_target; 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, &gl_texture, diff --git a/cogl/cogl/driver/gl/cogl-texture-2d-gl.c b/cogl/cogl/driver/gl/cogl-texture-2d-gl.c index 484589eca..6212f408c 100644 --- a/cogl/cogl/driver/gl/cogl-texture-2d-gl.c +++ b/cogl/cogl/driver/gl/cogl-texture-2d-gl.c @@ -130,7 +130,7 @@ allocate_with_size (CoglTexture2D *tex_2d, CoglPixelFormat internal_format; int width = loader->src.sized.width; int height = loader->src.sized.height; - CoglContext *ctx = tex->context; + CoglContext *ctx = cogl_texture_get_context (tex); GLenum gl_intformat; GLenum gl_format; GLenum gl_type; @@ -267,7 +267,7 @@ allocate_from_egl_image (CoglTexture2D *tex_2d, GError **error) { 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; tex_2d->gl_texture = @@ -301,7 +301,7 @@ allocate_custom_egl_image_external (CoglTexture2D *tex_2d, GError **error) { CoglTexture *tex = COGL_TEXTURE (tex_2d); - CoglContext *ctx = tex->context; + CoglContext *ctx = cogl_texture_get_context (tex); CoglPixelFormat external_format; CoglPixelFormat internal_format; @@ -356,7 +356,7 @@ cogl_texture_2d_gl_bind_egl_image (CoglTexture2D *tex_2d, EGLImageKHR image, 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, tex_2d->gl_texture); @@ -376,7 +376,7 @@ cogl_texture_2d_gl_bind_egl_image (CoglTexture2D *tex_2d, return TRUE; } -CoglTexture2D * +CoglTexture * cogl_texture_2d_new_from_egl_image_external (CoglContext *ctx, int width, 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.format = internal_format; - tex_2d = _cogl_texture_2d_create_base (ctx, width, height, - internal_format, loader); + tex_2d = COGL_TEXTURE_2D (_cogl_texture_2d_create_base (ctx, width, height, + internal_format, loader)); tex_2d->egl_image_external.user_data = user_data; tex_2d->egl_image_external.destroy = destroy; - return tex_2d; + return COGL_TEXTURE (tex_2d); } #endif /* defined (COGL_HAS_EGL_SUPPORT) */ @@ -420,7 +420,7 @@ _cogl_texture_2d_gl_allocate (CoglTexture *tex, GError **error) { 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); @@ -453,7 +453,7 @@ _cogl_texture_2d_gl_flush_legacy_texobj_filters (CoglTexture *tex, GLenum mag_filter) { 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 && 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) { 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 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) { 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 * 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) { CoglTexture *tex = COGL_TEXTURE (tex_2d); - CoglContext *ctx = tex->context; + CoglContext *ctx = cogl_texture_get_context (tex); CoglBitmap *upload_bmp; CoglPixelFormat upload_format; GLenum gl_format; @@ -592,7 +592,7 @@ _cogl_texture_2d_gl_copy_from_bitmap (CoglTexture2D *tex_2d, &gl_format, &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); status = ctx->texture_driver->upload_subregion_to_gl (ctx, @@ -623,9 +623,9 @@ _cogl_texture_2d_gl_get_data (CoglTexture2D *tex_2d, int rowstride, uint8_t *data) { - CoglContext *ctx = COGL_TEXTURE (tex_2d)->context; + CoglContext *ctx = cogl_texture_get_context (COGL_TEXTURE (tex_2d)); 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_type; diff --git a/cogl/cogl/driver/gl/cogl-texture-gl.c b/cogl/cogl/driver/gl/cogl-texture-gl.c index 2644e3cd0..ee5c3c5c8 100644 --- a/cogl/cogl/driver/gl/cogl-texture-gl.c +++ b/cogl/cogl/driver/gl/cogl-texture-gl.c @@ -83,9 +83,9 @@ _cogl_texture_gl_flush_legacy_texobj_wrap_modes (CoglTexture *texture, unsigned int wrap_mode_s, unsigned int wrap_mode_t) { - texture->vtable->gl_flush_legacy_texobj_wrap_modes (texture, - wrap_mode_s, - wrap_mode_t); + COGL_TEXTURE_GET_CLASS (texture)->gl_flush_legacy_texobj_wrap_modes (texture, + wrap_mode_s, + wrap_mode_t); } void @@ -93,8 +93,9 @@ _cogl_texture_gl_flush_legacy_texobj_filters (CoglTexture *texture, unsigned int min_filter, unsigned int mag_filter) { - texture->vtable->gl_flush_legacy_texobj_filters (texture, - min_filter, mag_filter); + COGL_TEXTURE_GET_CLASS (texture)->gl_flush_legacy_texobj_filters (texture, + min_filter, + mag_filter); } /* 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, 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)) { @@ -119,25 +120,25 @@ cogl_texture_gl_set_max_level (CoglTexture *texture, 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, gl_handle); 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 _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); GLuint gl_handle; 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_get_gl_texture (texture, &gl_handle, &gl_target); @@ -150,5 +151,5 @@ _cogl_texture_gl_generate_mipmaps (CoglTexture *texture) GLenum _cogl_texture_gl_get_format (CoglTexture *texture) { - return texture->vtable->get_gl_format (texture); + return COGL_TEXTURE_GET_CLASS (texture)->get_gl_format (texture); } diff --git a/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c b/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c index e2b92892e..2c04f834c 100644 --- a/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c +++ b/cogl/cogl/driver/gl/gl/cogl-texture-driver-gl.c @@ -250,7 +250,7 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx, * glTexImage2D first to assert that the storage for this * level exists. */ - if (texture->max_level_set < level) + if (cogl_texture_get_max_level_set (texture) < level) { ctx->glTexImage2D (gl_target, level, diff --git a/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c b/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c index 36f106157..01d7afb8a 100644 --- a/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c +++ b/cogl/cogl/driver/gl/gles/cogl-texture-driver-gles.c @@ -303,7 +303,7 @@ _cogl_texture_driver_upload_subregion_to_gl (CoglContext *ctx, * glTexImage2D first to assert that the storage for this * level exists. */ - if (texture->max_level_set < level) + if (cogl_texture_get_max_level_set (texture) < level) { ctx->glTexImage2D (gl_target, level, diff --git a/cogl/cogl/winsys/cogl-texture-pixmap-x11-private.h b/cogl/cogl/winsys/cogl-texture-pixmap-x11-private.h index b340620df..cb83af7ea 100644 --- a/cogl/cogl/winsys/cogl-texture-pixmap-x11-private.h +++ b/cogl/cogl/winsys/cogl-texture-pixmap-x11-private.h @@ -40,7 +40,6 @@ #include #endif -#include "cogl/cogl-object-private.h" #include "cogl/cogl-texture-private.h" #include "cogl/winsys/cogl-texture-pixmap-x11.h" @@ -70,7 +69,7 @@ typedef enum struct _CoglTexturePixmapX11 { - CoglTexture _parent; + CoglTexture parent_instance; CoglTexturePixmapStereoMode stereo_mode; CoglTexturePixmapX11 *left; /* Set only if stereo_mode=RIGHT */ @@ -97,3 +96,8 @@ struct _CoglTexturePixmapX11 texture */ gboolean use_winsys_texture; }; + +struct _CoglTexturePixmapX11Class +{ + CoglTextureClass parent_class; +}; diff --git a/cogl/cogl/winsys/cogl-texture-pixmap-x11.c b/cogl/cogl/winsys/cogl-texture-pixmap-x11.c index f6c5c48e1..3f3d99c70 100644 --- a/cogl/cogl/winsys/cogl-texture-pixmap-x11.c +++ b/cogl/cogl/winsys/cogl-texture-pixmap-x11.c @@ -47,12 +47,10 @@ #include "cogl/cogl-context-private.h" #include "cogl/cogl-display-private.h" #include "cogl/cogl-renderer-private.h" -#include "cogl/cogl-object-private.h" #include "cogl/cogl-xlib.h" #include "cogl/cogl-xlib-renderer-private.h" #include "cogl/cogl-x11-renderer-private.h" #include "cogl/cogl-private.h" -#include "cogl/cogl-gtype-private.h" #include "cogl/driver/gl/cogl-texture-gl-private.h" #include "cogl/winsys/cogl-winsys-private.h" @@ -66,17 +64,36 @@ #include #include -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); -COGL_GTYPE_DEFINE_CLASS (TexturePixmapX11, texture_pixmap_x11); - -static const CoglTextureVtable cogl_texture_pixmap_x11_vtable; - -uint32_t -cogl_texture_pixmap_x11_error_quark (void) +static const CoglWinsysVtable * +_cogl_texture_pixmap_x11_get_winsys (CoglTexturePixmapX11 *tex_pixmap) { - 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 @@ -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 process_damage_event (CoglTexturePixmapX11 *tex_pixmap, 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 going to update the whole texture anyway. */ if (cogl_damage_rectangle_is_whole (&tex_pixmap->damage_rect, - tex->width, - tex->height)) + cogl_texture_get_width (tex), + cogl_texture_get_height (tex))) { if (handle_mode != DO_NOTHING) 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 _cogl_texture_pixmap_x11_filter (XEvent *event, void *data) { @@ -293,171 +280,102 @@ set_damage_object_internal (CoglContext *ctx, tex_pixmap); } -static CoglTexturePixmapX11 * -_cogl_texture_pixmap_x11_new (CoglContext *ctxt, - uint32_t pixmap, - gboolean automatic_updates, - CoglTexturePixmapStereoMode stereo_mode, - GError **error) +static void +cogl_texture_pixmap_x11_dispose (GObject *object) { - CoglTexturePixmapX11 *tex_pixmap = g_new (CoglTexturePixmapX11, 1); - 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; + CoglTexturePixmapX11 *tex_pixmap = COGL_TEXTURE_PIXMAP_X11 (object); - if (!XGetGeometry (display, pixmap, &pixmap_root_window, - &pixmap_x, &pixmap_y, - &pixmap_width, &pixmap_height, - &pixmap_border_width, &tex_pixmap->depth)) + Display *display; + + _COGL_GET_CONTEXT (ctxt, NO_RETVAL); + + if (tex_pixmap->stereo_mode == COGL_TEXTURE_PIXMAP_RIGHT) { - 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; + g_object_unref (tex_pixmap->left); + G_OBJECT_CLASS (cogl_texture_pixmap_x11_parent_class)->dispose (object); + return; } - /* 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); + display = cogl_xlib_renderer_get_display (ctxt->display->renderer); - _cogl_texture_init (tex, ctxt, pixmap_width, pixmap_height, - internal_format, - NULL, /* no loader */ - &cogl_texture_pixmap_x11_vtable); + set_damage_object_internal (ctxt, tex_pixmap, 0, 0); - 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; + if (tex_pixmap->image) + XDestroyImage (tex_pixmap->image); - /* 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)) + if (tex_pixmap->shm_info.shmid != -1) { - 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; + XShmDetach (display, &tex_pixmap->shm_info); + shmdt (tex_pixmap->shm_info.shmaddr); + shmctl (tex_pixmap->shm_info.shmid, IPC_RMID, 0); } - 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 - 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) + if (tex_pixmap->winsys) { - 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; + const CoglWinsysVtable *winsys = + _cogl_texture_pixmap_x11_get_winsys (tex_pixmap); + winsys->texture_pixmap_x11_free (tex_pixmap); } - /* 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; + G_OBJECT_CLASS (cogl_texture_pixmap_x11_parent_class)->dispose (object); +} - winsys = _cogl_texture_pixmap_x11_get_winsys (tex_pixmap); - if (winsys->texture_pixmap_x11_create) +static void +_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 = - winsys->texture_pixmap_x11_create (tex_pixmap); + /* 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; } - 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 * -cogl_texture_pixmap_x11_new (CoglContext *ctxt, - uint32_t pixmap, - gboolean automatic_updates, - GError **error) - +static CoglTexture * +create_fallback_texture (CoglContext *ctx, + int width, + int height, + CoglPixelFormat internal_format) { - return _cogl_texture_pixmap_x11_new (ctxt, pixmap, - automatic_updates, COGL_TEXTURE_PIXMAP_MONO, - error); + CoglTexture *tex; + GError *skip_error = NULL; + + /* 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 * update size of the X Pixmap. */ @@ -491,8 +409,8 @@ try_alloc_shm (CoglTexturePixmapX11 *tex_pixmap) ZPixmap, NULL, NULL, /* shminfo, */ - tex->width, - tex->height); + cogl_texture_get_width (tex), + cogl_texture_get_height (tex)); if (!dummy_image) goto failed_image_create; @@ -532,80 +450,6 @@ try_alloc_shm (CoglTexturePixmapX11 *tex_pixmap) 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 _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); tex_pixmap->tex = create_fallback_texture (ctx, - tex->width, - tex->height, + cogl_texture_get_width (tex), + cogl_texture_get_height (tex), texture_format); } @@ -671,7 +515,8 @@ _cogl_texture_pixmap_x11_update_image_texture (CoglTexturePixmapX11 *tex_pixmap) tex_pixmap->image = XGetImage (display, tex_pixmap->pixmap, 0, 0, - tex->width, tex->height, + cogl_texture_get_width (tex), + cogl_texture_get_height (tex), AllPlanes, ZPixmap); image = tex_pixmap->image; 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)); } -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 _cogl_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap, gboolean needs_mipmap) @@ -831,6 +661,13 @@ _cogl_texture_pixmap_x11_get_texture (CoglTexturePixmapX11 *tex_pixmap) return NULL; } +static gboolean +_cogl_texture_pixmap_x11_allocate (CoglTexture *tex, + GError **error) +{ + return TRUE; +} + static gboolean _cogl_texture_pixmap_x11_set_region (CoglTexture *tex, 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); } +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 _cogl_texture_pixmap_x11_foreach_sub_texture_in_region (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); /* 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_ty_1, virtual_tx_2, @@ -891,15 +737,6 @@ _cogl_texture_pixmap_x11_foreach_sub_texture_in_region 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 _cogl_texture_pixmap_x11_is_sliced (CoglTexture *tex) { @@ -1027,70 +864,234 @@ _cogl_texture_pixmap_x11_get_gl_format (CoglTexture *tex) } 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) - { - 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); + tex_pixmap = tex_pixmap->left; if (tex_pixmap->winsys) { - const CoglWinsysVtable *winsys = - _cogl_texture_pixmap_x11_get_winsys (tex_pixmap); - winsys->texture_pixmap_x11_free (tex_pixmap); + const CoglWinsysVtable *winsys; + winsys = _cogl_texture_pixmap_x11_get_winsys (tex_pixmap); + winsys->texture_pixmap_x11_damage_notify (tex_pixmap); } - /* Chain up */ - _cogl_texture_free (COGL_TEXTURE (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 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 */ - }; diff --git a/cogl/cogl/winsys/cogl-texture-pixmap-x11.h b/cogl/cogl/winsys/cogl-texture-pixmap-x11.h index f39ed1c47..e3d218885 100644 --- a/cogl/cogl/winsys/cogl-texture-pixmap-x11.h +++ b/cogl/cogl/winsys/cogl-texture-pixmap-x11.h @@ -54,26 +54,30 @@ G_BEGIN_DECLS /** - * SECTION:cogl-texture-pixmap-x11 - * @short_description: Functions for creating and manipulating 2D meta - * textures derived from X11 pixmaps. + * CoglTexturePixmapX11: + * + * Functions for creating and manipulating 2D meta + * textures derived from X11 pixmaps. * * These functions allow high-level meta textures (See the * #CoglMetaTexture interface) that derive their contents from an X11 * 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; -#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 -GType cogl_texture_pixmap_x11_get_gtype (void); +GType cogl_texture_pixmap_x11_get_type (void) G_GNUC_CONST; typedef enum { @@ -120,7 +124,7 @@ uint32_t cogl_texture_pixmap_x11_error_quark (void); * * Return value: a new #CoglTexturePixmapX11 instance */ -COGL_EXPORT CoglTexturePixmapX11 * +COGL_EXPORT CoglTexture * cogl_texture_pixmap_x11_new (CoglContext *context, uint32_t pixmap, gboolean automatic_updates, @@ -156,7 +160,7 @@ cogl_texture_pixmap_x11_new (CoglContext *context, * * Return value: a new #CoglTexturePixmapX11 instance */ -COGL_EXPORT CoglTexturePixmapX11 * +COGL_EXPORT CoglTexture * cogl_texture_pixmap_x11_new_left (CoglContext *context, uint32_t pixmap, gboolean automatic_updates, @@ -173,7 +177,7 @@ cogl_texture_pixmap_x11_new_left (CoglContext *context, * * Return value: a new #CoglTexturePixmapX11 instance */ -COGL_EXPORT CoglTexturePixmapX11 * +COGL_EXPORT CoglTexture * 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_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 /* The gobject introspection scanner seems to parse public headers in diff --git a/cogl/cogl/winsys/cogl-winsys-egl-x11.c b/cogl/cogl/winsys/cogl-winsys-egl-x11.c index af4df1814..461ec5309 100644 --- a/cogl/cogl/winsys/cogl-winsys-egl-x11.c +++ b/cogl/cogl/winsys/cogl-winsys-egl-x11.c @@ -455,7 +455,7 @@ static gboolean _cogl_winsys_texture_pixmap_x11_create (CoglTexturePixmapX11 *tex_pixmap) { CoglTexture *tex = COGL_TEXTURE (tex_pixmap); - CoglContext *ctx = tex->context; + CoglContext *ctx = cogl_texture_get_context (tex); CoglTexturePixmapEGL *egl_tex_pixmap; EGLint attribs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE}; 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_RGB_888); - egl_tex_pixmap->texture = COGL_TEXTURE ( + egl_tex_pixmap->texture = cogl_egl_texture_2d_new_from_image (ctx, - tex->width, - tex->height, + cogl_texture_get_width (tex), + cogl_texture_get_height (tex), texture_format, egl_tex_pixmap->image, COGL_EGL_IMAGE_FLAG_NONE, - NULL)); + NULL); /* The image is initially bound as part of the creation */ 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; 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) _cogl_egl_destroy_image (ctx, egl_tex_pixmap->image); diff --git a/cogl/cogl/winsys/cogl-winsys-glx.c b/cogl/cogl/winsys/cogl-winsys-glx.c index 553fdc888..7a8f0e0d0 100644 --- a/cogl/cogl/winsys/cogl-winsys-glx.c +++ b/cogl/cogl/winsys/cogl-winsys-glx.c @@ -1129,7 +1129,7 @@ static gboolean _cogl_winsys_texture_pixmap_x11_create (CoglTexturePixmapX11 *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)) { @@ -1221,13 +1221,14 @@ _cogl_winsys_texture_pixmap_x11_free (CoglTexturePixmapX11 *tex_pixmap) 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) - 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) - cogl_object_unref (glx_tex_pixmap->right.glx_tex); + g_object_unref (glx_tex_pixmap->right.glx_tex); tex_pixmap->winsys = NULL; g_free (glx_tex_pixmap); @@ -1239,7 +1240,7 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap, gboolean needs_mipmap) { 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; CoglPixmapTextureEyeGLX *texture_info; int buffer; @@ -1272,8 +1273,10 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap, COGL_PIXEL_FORMAT_RGBA_8888_PRE : COGL_PIXEL_FORMAT_RGB_888); - texture_info->glx_tex = COGL_TEXTURE ( - cogl_texture_2d_new_with_size (ctx, tex->width, tex->height)); + texture_info->glx_tex = + 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); @@ -1314,7 +1317,7 @@ _cogl_winsys_texture_pixmap_x11_update (CoglTexturePixmapX11 *tex_pixmap, "with mipmap support failed", tex_pixmap); if (texture_info->glx_tex) - cogl_object_unref (texture_info->glx_tex); + g_object_unref (texture_info->glx_tex); return FALSE; } diff --git a/src/backends/meta-cursor-sprite-xcursor.c b/src/backends/meta-cursor-sprite-xcursor.c index 742e1a0bf..1ad444c06 100644 --- a/src/backends/meta-cursor-sprite-xcursor.c +++ b/src/backends/meta-cursor-sprite-xcursor.c @@ -190,7 +190,7 @@ load_from_current_xcursor_image (MetaCursorSpriteXcursor *sprite_xcursor) CoglPixelFormat cogl_format; ClutterBackend *clutter_backend; CoglContext *cogl_context; - CoglTexture2D *texture; + CoglTexture *texture; GError *error = NULL; int hotspot_x, hotspot_y; @@ -234,10 +234,10 @@ load_from_current_xcursor_image (MetaCursorSpriteXcursor *sprite_xcursor) hotspot_y = xc_image->yhot; } meta_cursor_sprite_set_texture (sprite, - COGL_TEXTURE (texture), + texture, hotspot_x, hotspot_y); - g_clear_pointer (&texture, cogl_object_unref); + g_clear_object (&texture); } void diff --git a/src/backends/meta-cursor.c b/src/backends/meta-cursor.c index ee67f2722..79430e01c 100644 --- a/src/backends/meta-cursor.c +++ b/src/backends/meta-cursor.c @@ -96,7 +96,7 @@ meta_cursor_sprite_clear_texture (MetaCursorSprite *sprite) MetaCursorSpritePrivate *priv = 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); } @@ -109,9 +109,9 @@ meta_cursor_sprite_set_texture (MetaCursorSprite *sprite, MetaCursorSpritePrivate *priv = meta_cursor_sprite_get_instance_private (sprite); - g_clear_pointer (&priv->texture, cogl_object_unref); + g_clear_object (&priv->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_y = hot_y; @@ -264,7 +264,7 @@ meta_cursor_sprite_constructed (GObject *object) 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); } @@ -276,7 +276,7 @@ meta_cursor_sprite_finalize (GObject *object) MetaCursorSpritePrivate *priv = 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); g_clear_object (&priv->cursor_tracker); diff --git a/src/backends/meta-screen-cast-stream-src.c b/src/backends/meta-screen-cast-stream-src.c index 273c085d5..7d1c2beb3 100644 --- a/src/backends/meta-screen-cast-stream-src.c +++ b/src/backends/meta-screen-cast-stream-src.c @@ -313,7 +313,7 @@ draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc *src, ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend); - CoglTexture2D *bitmap_texture; + CoglTexture *bitmap_texture; CoglOffscreen *offscreen; CoglFramebuffer *fb; CoglPipeline *pipeline; @@ -322,17 +322,16 @@ draw_cursor_sprite_via_offscreen (MetaScreenCastStreamSrc *src, bitmap_texture = cogl_texture_2d_new_with_size (cogl_context, bitmap_width, bitmap_height); - cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (bitmap_texture), - FALSE); - if (!cogl_texture_allocate (COGL_TEXTURE (bitmap_texture), error)) + cogl_primitive_texture_set_auto_mipmap (bitmap_texture, FALSE); + if (!cogl_texture_allocate (bitmap_texture, error)) { - cogl_object_unref (bitmap_texture); + g_object_unref (bitmap_texture); return FALSE; } - offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (bitmap_texture)); + offscreen = cogl_offscreen_new_with_texture (bitmap_texture); fb = COGL_FRAMEBUFFER (offscreen); - cogl_object_unref (bitmap_texture); + g_object_unref (bitmap_texture); if (!cogl_framebuffer_allocate (fb, error)) { g_object_unref (fb); diff --git a/src/backends/native/meta-drm-buffer-gbm.c b/src/backends/native/meta-drm-buffer-gbm.c index 048888c2b..0d785695c 100644 --- a/src/backends/native/meta-drm-buffer-gbm.c +++ b/src/backends/native/meta-drm-buffer-gbm.c @@ -254,7 +254,7 @@ meta_drm_buffer_gbm_blit_to_framebuffer (CoglScanout *scanout, CoglPixelFormat cogl_format; CoglEglImageFlags flags; CoglOffscreen *cogl_fbo = NULL; - CoglTexture2D *cogl_tex; + CoglTexture *cogl_tex; uint32_t n_planes; uint64_t *modifiers; uint32_t *strides; @@ -332,8 +332,8 @@ meta_drm_buffer_gbm_blit_to_framebuffer (CoglScanout *scanout, goto out; } - cogl_fbo = cogl_offscreen_new_with_texture (COGL_TEXTURE (cogl_tex)); - cogl_object_unref (cogl_tex); + cogl_fbo = cogl_offscreen_new_with_texture (cogl_tex); + g_object_unref (cogl_tex); if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (cogl_fbo), error)) { diff --git a/src/backends/native/meta-renderer-native.c b/src/backends/native/meta-renderer-native.c index e6c653e26..f6aeb0f75 100644 --- a/src/backends/native/meta-renderer-native.c +++ b/src/backends/native/meta-renderer-native.c @@ -613,7 +613,7 @@ meta_renderer_native_create_dma_buf_framebuffer (MetaRendererNative *renderer_n uint64_t modifiers[1]; CoglPixelFormat cogl_format; CoglEglImageFlags flags; - CoglTexture2D *cogl_tex; + CoglTexture *cogl_tex; CoglOffscreen *cogl_fbo; int ret; @@ -651,8 +651,8 @@ meta_renderer_native_create_dma_buf_framebuffer (MetaRendererNative *renderer_n if (!cogl_tex) return NULL; - cogl_fbo = cogl_offscreen_new_with_texture (COGL_TEXTURE (cogl_tex)); - cogl_object_unref (cogl_tex); + cogl_fbo = cogl_offscreen_new_with_texture (cogl_tex); + g_object_unref (cogl_tex); if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (cogl_fbo), error)) { @@ -1151,19 +1151,19 @@ meta_renderer_native_create_offscreen (MetaRendererNative *renderer, GError **error) { CoglOffscreen *fb; - CoglTexture2D *tex; + CoglTexture *tex; 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; } - fb = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex)); - cogl_object_unref (tex); + fb = cogl_offscreen_new_with_texture (tex); + g_object_unref (tex); if (!cogl_framebuffer_allocate (COGL_FRAMEBUFFER (fb), error)) { g_object_unref (fb); diff --git a/src/backends/x11/cm/meta-cursor-sprite-xfixes.c b/src/backends/x11/cm/meta-cursor-sprite-xfixes.c index 721fb47ac..a2d973652 100644 --- a/src/backends/x11/cm/meta-cursor-sprite-xfixes.c +++ b/src/backends/x11/cm/meta-cursor-sprite-xfixes.c @@ -125,7 +125,7 @@ meta_cursor_sprite_xfixes_initable_init (GInitable *initable, MetaX11Display *x11_display; Display *xdisplay; XFixesCursorImage *cursor_image; - CoglTexture2D *texture; + CoglTexture *texture; uint8_t *cursor_data; gboolean free_cursor_data; ClutterBackend *clutter_backend; @@ -175,12 +175,12 @@ meta_cursor_sprite_xfixes_initable_init (GInitable *initable, clutter_backend = clutter_get_default_backend (); cogl_context = clutter_backend_get_cogl_context (clutter_backend); texture = cogl_texture_2d_new_from_data (cogl_context, - cursor_image->width, - cursor_image->height, - COGL_PIXEL_FORMAT_CAIRO_ARGB32_COMPAT, - cursor_image->width * 4, /* stride */ - cursor_data, - error); + cursor_image->width, + cursor_image->height, + COGL_PIXEL_FORMAT_CAIRO_ARGB32_COMPAT, + cursor_image->width * 4, /* stride */ + cursor_data, + error); if (free_cursor_data) g_free (cursor_data); @@ -189,10 +189,10 @@ meta_cursor_sprite_xfixes_initable_init (GInitable *initable, return FALSE; meta_cursor_sprite_set_texture (sprite, - COGL_TEXTURE (texture), + texture, cursor_image->xhot, cursor_image->yhot); - cogl_object_unref (texture); + g_object_unref (texture); XFree (cursor_image); return TRUE; diff --git a/src/backends/x11/nested/meta-renderer-x11-nested.c b/src/backends/x11/nested/meta-renderer-x11-nested.c index d89ca1e8c..36448baa2 100644 --- a/src/backends/x11/nested/meta-renderer-x11-nested.c +++ b/src/backends/x11/nested/meta-renderer-x11-nested.c @@ -75,12 +75,12 @@ create_offscreen (CoglContext *cogl_context, int width, int height) { - CoglTexture2D *texture_2d; + CoglTexture *texture_2d; CoglOffscreen *offscreen; GError *error = NULL; 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)) meta_fatal ("Couldn't allocate framebuffer: %s", error->message); diff --git a/src/compositor/cogl-utils.c b/src/compositor/cogl-utils.c index 0a39755a5..c752bd229 100644 --- a/src/compositor/cogl-utils.c +++ b/src/compositor/cogl-utils.c @@ -92,7 +92,7 @@ meta_create_texture (int width, CoglContext *ctx = clutter_backend_get_cogl_context (backend); 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); if ((flags & META_TEXTURE_ALLOW_SLICING) != 0) @@ -104,8 +104,8 @@ meta_create_texture (int width, if (!cogl_texture_allocate (texture, &catch_error)) { g_error_free (catch_error); - cogl_object_unref (texture); - texture = COGL_TEXTURE (cogl_texture_2d_sliced_new_with_size (ctx, width, height, COGL_TEXTURE_MAX_WASTE)); + g_object_unref (texture); + texture = cogl_texture_2d_sliced_new_with_size (ctx, width, height, COGL_TEXTURE_MAX_WASTE); cogl_texture_set_components (texture, components); } } diff --git a/src/compositor/meta-background-image.c b/src/compositor/meta-background-image.c index 98a7658b6..c27c36e1b 100644 --- a/src/compositor/meta-background-image.c +++ b/src/compositor/meta-background-image.c @@ -196,7 +196,7 @@ file_loaded (GObject *source_object, { g_warning ("Failed to create texture for background: %s", local_error->message); - cogl_clear_object (&texture); + g_clear_object (&texture); } image->texture = texture; @@ -218,7 +218,7 @@ out: * 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 - * 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] * signal will be emitted exactly once. The 'loaded' state means that the * 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); if (image->texture) - cogl_object_unref (image->texture); + g_object_unref (image->texture); if (image->file) g_object_unref (image->file); diff --git a/src/compositor/meta-background.c b/src/compositor/meta-background.c index 49dcf2a87..286643b3c 100644 --- a/src/compositor/meta-background.c +++ b/src/compositor/meta-background.c @@ -96,20 +96,20 @@ free_fbos (MetaBackground *self) MetaBackgroundMonitor *monitor = &self->monitors[i]; g_clear_object (&monitor->fbo); - cogl_clear_object (&monitor->texture); + g_clear_object (&monitor->texture); } } static void free_color_texture (MetaBackground *self) { - cogl_clear_object (&self->color_texture); + g_clear_object (&self->color_texture); } static void free_wallpaper_texture (MetaBackground *self) { - cogl_clear_object (&self->wallpaper_texture); + g_clear_object (&self->wallpaper_texture); self->wallpaper_allocation_failed = FALSE; } @@ -587,11 +587,11 @@ ensure_color_texture (MetaBackground *self) pixels[5] = self->second_color.blue; } - self->color_texture = COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx, width, height, - COGL_PIXEL_FORMAT_RGB_888, - width * 3, - pixels, - &error)); + self->color_texture = cogl_texture_2d_new_from_data (ctx, width, height, + COGL_PIXEL_FORMAT_RGB_888, + width * 3, + pixels, + &error); if (error != NULL) { @@ -680,7 +680,7 @@ ensure_wallpaper_texture (MetaBackground *self, */ g_error_free (catch_error); - cogl_clear_object (&self->wallpaper_texture); + g_clear_object (&self->wallpaper_texture); g_object_unref (fbo); 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 * 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_error_free (catch_error); diff --git a/src/compositor/meta-multi-texture.c b/src/compositor/meta-multi-texture.c index c756ddaea..bb17a03a4 100644 --- a/src/compositor/meta-multi-texture.c +++ b/src/compositor/meta-multi-texture.c @@ -171,7 +171,7 @@ meta_multi_texture_finalize (GObject *object) int 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); diff --git a/src/compositor/meta-shadow-factory.c b/src/compositor/meta-shadow-factory.c index 3875b8d3e..dff93032c 100644 --- a/src/compositor/meta-shadow-factory.c +++ b/src/compositor/meta-shadow-factory.c @@ -167,7 +167,7 @@ meta_shadow_unref (MetaShadow *shadow) } meta_window_shape_unref (shadow->key.shape); - cogl_object_unref (shadow->texture); + g_object_unref (shadow->texture); cogl_object_unref (shadow->pipeline); g_free (shadow); @@ -797,15 +797,15 @@ make_shadow (MetaShadow *shadow, * in the case of top_fade >= 0. We also account for padding at the left for symmetry * though that doesn't currently occur. */ - shadow->texture = COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx, - shadow->outer_border_left + extents.width + shadow->outer_border_right, - shadow->outer_border_top + extents.height + shadow->outer_border_bottom, - COGL_PIXEL_FORMAT_A_8, - buffer_width, - (buffer + - (y_offset - shadow->outer_border_top) * buffer_width + - (x_offset - shadow->outer_border_left)), - &error)); + shadow->texture = cogl_texture_2d_new_from_data (ctx, + shadow->outer_border_left + extents.width + shadow->outer_border_right, + shadow->outer_border_top + extents.height + shadow->outer_border_bottom, + COGL_PIXEL_FORMAT_A_8, + buffer_width, + (buffer + + (y_offset - shadow->outer_border_top) * buffer_width + + (x_offset - shadow->outer_border_left)), + &error); if (error) { diff --git a/src/compositor/meta-shaped-texture.c b/src/compositor/meta-shaped-texture.c index 94cc60622..c83b48c58 100644 --- a/src/compositor/meta-shaped-texture.c +++ b/src/compositor/meta-shaped-texture.c @@ -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, cogl_object_unref); + g_clear_object (&stex->texture); meta_shaped_texture_set_mask_texture (stex, NULL); 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_clear_pointer (&stex->mask_texture, cogl_object_unref); + g_clear_object (&stex->mask_texture); if (mask_texture != NULL) { stex->mask_texture = mask_texture; - cogl_object_ref (stex->mask_texture); + g_object_ref (stex->mask_texture); } 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); if (image_clip) - texture = COGL_TEXTURE (cogl_sub_texture_new (cogl_context, - texture, - image_clip->x, - image_clip->y, - image_clip->width, - image_clip->height)); + texture = cogl_sub_texture_new (cogl_context, + texture, + image_clip->x, + image_clip->y, + image_clip->width, + image_clip->height); surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, cogl_texture_get_width (texture), @@ -1482,7 +1482,7 @@ meta_shaped_texture_get_image (MetaShapedTexture *stex, cairo_surface_mark_dirty (surface); if (image_clip) - cogl_object_unref (texture); + g_object_unref (texture); return surface; } diff --git a/src/compositor/meta-surface-actor-x11.c b/src/compositor/meta-surface-actor-x11.c index 7834982e3..d19d39259 100644 --- a/src/compositor/meta-surface-actor-x11.c +++ b/src/compositor/meta-surface-actor-x11.c @@ -122,7 +122,7 @@ set_pixmap (MetaSurfaceActorX11 *self, g_assert (self->pixmap == None); 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) { diff --git a/src/compositor/meta-texture-mipmap.c b/src/compositor/meta-texture-mipmap.c index dfac02f18..b7558a328 100644 --- a/src/compositor/meta-texture-mipmap.c +++ b/src/compositor/meta-texture-mipmap.c @@ -165,16 +165,14 @@ ensure_mipmap_texture (MetaTextureMipmap *mipmap) meta_multi_texture_get_height (mipmap->mipmap_texture) != height) { CoglOffscreen *offscreen; - CoglTexture2D *tex2d; CoglTexture *tex; free_mipmaps (mipmap); - tex2d = cogl_texture_2d_new_with_size (ctx, width, height); - if (!tex2d) + tex = cogl_texture_2d_new_with_size (ctx, width, height); + if (!tex) return; - tex = COGL_TEXTURE (tex2d); mipmap->mipmap_texture = meta_multi_texture_new_simple (tex); offscreen = cogl_offscreen_new_with_texture (tex); diff --git a/src/compositor/meta-window-actor-x11.c b/src/compositor/meta-window-actor-x11.c index 70c5fa642..47a358e07 100644 --- a/src/compositor/meta-window-actor-x11.c +++ b/src/compositor/meta-window-actor-x11.c @@ -784,7 +784,7 @@ build_and_scan_frame_mask (MetaWindowActorX11 *actor_x11, uint8_t *mask_data; unsigned int tex_width, tex_height; MetaShapedTexture *stex; - CoglTexture2D *mask_texture; + CoglTexture *mask_texture; int stride; cairo_t *cr; cairo_surface_t *image; @@ -868,8 +868,8 @@ build_and_scan_frame_mask (MetaWindowActorX11 *actor_x11, if (mask_texture) { - meta_shaped_texture_set_mask_texture (stex, COGL_TEXTURE (mask_texture)); - cogl_object_unref (mask_texture); + meta_shaped_texture_set_mask_texture (stex, mask_texture); + g_object_unref (mask_texture); } else { diff --git a/src/compositor/meta-window-actor.c b/src/compositor/meta-window-actor.c index f79a5bd06..147c85568 100644 --- a/src/compositor/meta-window-actor.c +++ b/src/compositor/meta-window-actor.c @@ -1574,7 +1574,7 @@ create_framebuffer_from_window_actor (MetaWindowActor *self, ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend); - CoglTexture2D *texture; + CoglTexture *texture; CoglOffscreen *offscreen; CoglFramebuffer *framebuffer; CoglColor clear_color; @@ -1589,13 +1589,12 @@ create_framebuffer_from_window_actor (MetaWindowActor *self, if (!texture) return NULL; - cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (texture), - FALSE); + cogl_primitive_texture_set_auto_mipmap (texture, FALSE); - offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (texture)); + offscreen = cogl_offscreen_new_with_texture (texture); framebuffer = COGL_FRAMEBUFFER (offscreen); - cogl_object_unref (texture); + g_object_unref (texture); if (!cogl_framebuffer_allocate (framebuffer, error)) { diff --git a/src/tests/clutter/interactive/test-cogl-multitexture.c b/src/tests/clutter/interactive/test-cogl-multitexture.c index 5cdf7510e..c8f55298f 100644 --- a/src/tests/clutter/interactive/test-cogl-multitexture.c +++ b/src/tests/clutter/interactive/test-cogl-multitexture.c @@ -224,10 +224,10 @@ test_cogl_multitexture_main (int argc, char *argv[]) cogl_object_unref (state->pipeline1); cogl_object_unref (state->pipeline0); - cogl_object_unref (state->alpha_tex); - cogl_object_unref (state->redhand_tex); - cogl_object_unref (state->light_tex0); - cogl_object_unref (state->light_tex1); + g_object_unref (state->alpha_tex); + g_object_unref (state->redhand_tex); + g_object_unref (state->light_tex0); + g_object_unref (state->light_tex1); g_free (state); return 0; diff --git a/src/tests/clutter/interactive/test-cogl-offscreen.c b/src/tests/clutter/interactive/test-cogl-offscreen.c index 4659f1af6..ffc8f43cd 100644 --- a/src/tests/clutter/interactive/test-cogl-offscreen.c +++ b/src/tests/clutter/interactive/test-cogl-offscreen.c @@ -92,7 +92,7 @@ test_coglbox_dispose (GObject *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_CLASS (test_coglbox_parent_class)->dispose (object); diff --git a/src/tests/clutter/interactive/test-cogl-point-sprites.c b/src/tests/clutter/interactive/test-cogl-point-sprites.c index 3561499b3..82e783018 100644 --- a/src/tests/clutter/interactive/test-cogl-point-sprites.c +++ b/src/tests/clutter/interactive/test-cogl-point-sprites.c @@ -236,7 +236,7 @@ test_cogl_point_sprites_main (int argc, char *argv[]) tex = generate_round_texture (ctx); 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, 0, TRUE, diff --git a/src/tests/clutter/interactive/test-cogl-tex-polygon.c b/src/tests/clutter/interactive/test-cogl-tex-polygon.c index d57537abe..04a835197 100644 --- a/src/tests/clutter/interactive/test-cogl-tex-polygon.c +++ b/src/tests/clutter/interactive/test-cogl-tex-polygon.c @@ -219,8 +219,8 @@ test_coglbox_dispose (GObject *object) { TestCoglbox *coglbox = TEST_COGLBOX (object); - cogl_object_unref (coglbox->not_sliced_tex); - cogl_object_unref (coglbox->sliced_tex); + g_object_unref (coglbox->not_sliced_tex); + g_object_unref (coglbox->sliced_tex); G_OBJECT_CLASS (test_coglbox_parent_class)->dispose (object); } diff --git a/src/tests/clutter/interactive/test-cogl-tex-tile.c b/src/tests/clutter/interactive/test-cogl-tex-tile.c index d8a57d15b..5dee46367 100644 --- a/src/tests/clutter/interactive/test-cogl-tex-tile.c +++ b/src/tests/clutter/interactive/test-cogl-tex-tile.c @@ -93,7 +93,7 @@ test_coglbox_dispose (GObject *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); } diff --git a/src/tests/clutter/test-utils.h b/src/tests/clutter/test-utils.h index 5b07ef28a..4efad3dfe 100644 --- a/src/tests/clutter/test-utils.h +++ b/src/tests/clutter/test-utils.h @@ -111,13 +111,13 @@ clutter_test_create_bitmap_from_file (CoglContext *ctx, return bmp; } -static inline CoglTexture2DSliced * +static inline CoglTexture * clutter_test_texture_2d_sliced_new_from_file (CoglContext *ctx, const char *filename, GError **error) { CoglBitmap *bmp; - CoglTexture2DSliced *tex_2ds = NULL; + CoglTexture *tex_2ds = 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; } -static inline CoglTexture2D * +static inline CoglTexture * clutter_test_texture_2d_new_from_file (CoglContext *ctx, const char *filename, GError **error) { CoglBitmap *bmp; - CoglTexture2D *tex_2d = NULL; + CoglTexture *tex_2d = NULL; g_return_val_if_fail (error == NULL || *error == NULL, NULL); diff --git a/src/tests/cogl-test-utils.c b/src/tests/cogl-test-utils.c index 1cd75e956..4795385be 100644 --- a/src/tests/cogl-test-utils.c +++ b/src/tests/cogl-test-utils.c @@ -166,7 +166,7 @@ CoglTexture * test_utils_create_color_texture (CoglContext *context, uint32_t color) { - CoglTexture2D *tex_2d; + CoglTexture *tex_2d; color = GUINT32_TO_BE (color); @@ -177,7 +177,7 @@ test_utils_create_color_texture (CoglContext *context, (uint8_t *) &color, NULL); - return COGL_TEXTURE (tex_2d); + return tex_2d; } gboolean @@ -192,8 +192,7 @@ set_auto_mipmap_cb (CoglTexture *sub_texture, const float *meta_coords, void *user_data) { - cogl_primitive_texture_set_auto_mipmap (COGL_PRIMITIVE_TEXTURE (sub_texture), - FALSE); + cogl_primitive_texture_set_auto_mipmap (sub_texture, FALSE); } CoglTexture * @@ -207,14 +206,14 @@ test_utils_texture_new_with_size (CoglContext *ctx, 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)); + tex = cogl_texture_2d_new_with_size (ctx, width, height); cogl_texture_set_components (tex, components); if (!cogl_texture_allocate (tex, &skip_error)) { g_error_free (skip_error); - cogl_object_unref (tex); + g_object_unref (tex); tex = NULL; } @@ -223,13 +222,11 @@ test_utils_texture_new_with_size (CoglContext *ctx, /* If it fails resort to sliced textures */ int max_waste = flags & TEST_UTILS_TEXTURE_NO_SLICING ? -1 : COGL_TEXTURE_MAX_WASTE; - CoglTexture2DSliced *tex_2ds = + tex = cogl_texture_2d_sliced_new_with_size (ctx, width, height, max_waste); - tex = COGL_TEXTURE (tex_2ds); - 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... */ 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, 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, gboolean premultiplied) { - CoglAtlasTexture *atlas_tex; + CoglTexture *atlas_tex; CoglTexture *tex; GError *internal_error = NULL; @@ -266,18 +263,18 @@ test_utils_texture_new_from_bitmap (CoglBitmap *bitmap, /* First try putting the texture in the atlas */ 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)) - return COGL_TEXTURE (atlas_tex); + if (cogl_texture_allocate (atlas_tex, &internal_error)) + return atlas_tex; - cogl_object_unref (atlas_tex); + g_object_unref (atlas_tex); } g_clear_error (&internal_error); /* 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); @@ -296,16 +293,15 @@ test_utils_texture_new_from_bitmap (CoglBitmap *bitmap, /* Otherwise create a sliced texture */ int max_waste = flags & TEST_UTILS_TEXTURE_NO_SLICING ? -1 : COGL_TEXTURE_MAX_WASTE; - CoglTexture2DSliced *tex_2ds = + tex = cogl_texture_2d_sliced_new_from_bitmap (bitmap, max_waste); - tex = COGL_TEXTURE (tex_2ds); cogl_texture_set_premultiplied (tex, premultiplied); } 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, 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); ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); CoglOffscreen *offscreen; - CoglTexture2D *tex; + CoglTexture *tex; GError *error = NULL; test_ctx = clutter_backend_get_cogl_context (clutter_backend); tex = cogl_texture_2d_new_with_size (test_ctx, FB_WIDTH, FB_HEIGHT); g_assert_nonnull (tex); - offscreen = cogl_offscreen_new_with_texture (COGL_TEXTURE (tex)); + offscreen = cogl_offscreen_new_with_texture (tex); g_assert_nonnull (offscreen); test_fb = COGL_FRAMEBUFFER (offscreen); diff --git a/src/tests/cogl/conform/test-alpha-test.c b/src/tests/cogl/conform/test-alpha-test.c index 746852953..aa611682d 100644 --- a/src/tests/cogl/conform/test-alpha-test.c +++ b/src/tests/cogl/conform/test-alpha-test.c @@ -3,7 +3,7 @@ #include "tests/cogl-test-utils.h" -static CoglTexture2D * +static CoglTexture * create_texture (CoglContext *context) { static const uint8_t data[] = @@ -48,7 +48,7 @@ test_alpha_test (void) 1, 1); 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 texture which is red */ diff --git a/src/tests/cogl/conform/test-alpha-textures.c b/src/tests/cogl/conform/test-alpha-textures.c index ebba4a26e..52a71c78a 100644 --- a/src/tests/cogl/conform/test-alpha-textures.c +++ b/src/tests/cogl/conform/test-alpha-textures.c @@ -8,7 +8,7 @@ static void create_pipeline (CoglTexture **tex_out, CoglPipeline **pipeline_out) { - CoglTexture2D *tex; + CoglTexture *tex; CoglPipeline *pipeline; static const uint8_t tex_data[] = { 0x00, 0x44, 0x88, 0xcc }; @@ -76,8 +76,8 @@ test_alpha_textures (void) -1.0f, 0.0f, /* x1/y1 */ 1.0f, -1.0f /* x2/y2 */); - cogl_object_unref (tex1); - cogl_object_unref (tex2); + g_object_unref (tex1); + g_object_unref (tex2); cogl_object_unref (pipeline1); cogl_object_unref (pipeline2); diff --git a/src/tests/cogl/conform/test-atlas-migration.c b/src/tests/cogl/conform/test-atlas-migration.c index c1910bc4e..2376490e7 100644 --- a/src/tests/cogl/conform/test-atlas-migration.c +++ b/src/tests/cogl/conform/test-atlas-migration.c @@ -125,7 +125,7 @@ test_atlas_migration (void) for (tex_num = 0; tex_num < N_TEXTURES; tex_num++) textures[tex_num] = create_texture (tex_num + 1); 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 */ @@ -138,7 +138,7 @@ test_atlas_migration (void) /* Destroy them all */ 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 ()) g_print ("OK\n"); diff --git a/src/tests/cogl/conform/test-backface-culling.c b/src/tests/cogl/conform/test-backface-culling.c index 6a3f821c5..784a7ff95 100644 --- a/src/tests/cogl/conform/test-backface-culling.c +++ b/src/tests/cogl/conform/test-backface-culling.c @@ -306,8 +306,8 @@ test_backface_culling (void) paint (&state); g_object_unref (state.offscreen); - cogl_object_unref (state.offscreen_tex); - cogl_object_unref (state.texture); + g_object_unref (state.offscreen_tex); + g_object_unref (state.texture); if (cogl_test_verbose ()) g_print ("OK\n"); diff --git a/src/tests/cogl/conform/test-blend-strings.c b/src/tests/cogl/conform/test-blend-strings.c index 98ffa749e..eaff48b96 100644 --- a/src/tests/cogl/conform/test-blend-strings.c +++ b/src/tests/cogl/conform/test-blend-strings.c @@ -217,8 +217,8 @@ test_tex_combine (TestState *state, y * QUAD_WIDTH + QUAD_WIDTH); cogl_object_unref (pipeline); - cogl_object_unref (tex0); - cogl_object_unref (tex1); + g_object_unref (tex0); + g_object_unref (tex1); /* See what we got... */ diff --git a/src/tests/cogl/conform/test-copy-replace-texture.c b/src/tests/cogl/conform/test-copy-replace-texture.c index 9f5408098..3e3120084 100644 --- a/src/tests/cogl/conform/test-copy-replace-texture.c +++ b/src/tests/cogl/conform/test-copy-replace-texture.c @@ -6,6 +6,7 @@ /* Keep track of the number of textures that we've created and are * still alive */ static int alive_texture_mask = 0; +static GQuark texture_data_key = 0; #define N_LAYERS 3 #define N_PIPELINES 4 @@ -28,8 +29,8 @@ create_texture (void) { static const guint8 data[] = { 0xff, 0xff, 0xff, 0xff }; - static CoglUserDataKey texture_data_key; - CoglTexture2D *tex_2d; + texture_data_key = g_quark_from_static_string ("-cogl-test-copy-replace-texture"); + CoglTexture *tex_2d; static int texture_num = 1; alive_texture_mask |= (1 << texture_num); @@ -40,13 +41,12 @@ create_texture (void) 4, /* rowstride */ data, NULL); - /* Set some user data on the texture so we can track when it has * been destroyed */ - cogl_object_set_user_data (COGL_OBJECT (tex_2d), - &texture_data_key, - GINT_TO_POINTER (texture_num), - free_texture_cb); + g_object_set_qdata_full (G_OBJECT (tex_2d), + texture_data_key, + GINT_TO_POINTER (texture_num), + free_texture_cb); texture_num++; @@ -77,7 +77,7 @@ test_copy_replace_texture (void) cogl_pipeline_set_layer_texture (pipelines[pipeline_num], layer_num, tex); - cogl_object_unref (tex); + g_object_unref (tex); } } diff --git a/src/tests/cogl/conform/test-framebuffer-get-bits.c b/src/tests/cogl/conform/test-framebuffer-get-bits.c index 54db6f84b..5fe6d2ffa 100644 --- a/src/tests/cogl/conform/test-framebuffer-get-bits.c +++ b/src/tests/cogl/conform/test-framebuffer-get-bits.c @@ -6,10 +6,10 @@ static void test_framebuffer_get_bits (void) { CoglRenderer *renderer; - CoglTexture2D *tex_a; + CoglTexture *tex_a; CoglOffscreen *offscreen_a; CoglFramebuffer *fb_a; - CoglTexture2D *tex_rgba; + CoglTexture *tex_rgba; CoglOffscreen *offscreen_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_object_unref (fb_rgba); - cogl_object_unref (tex_rgba); + g_object_unref (tex_rgba); g_object_unref (fb_a); - cogl_object_unref (tex_a); + g_object_unref (tex_a); } COGL_TEST_SUITE ( diff --git a/src/tests/cogl/conform/test-journal.c b/src/tests/cogl/conform/test-journal.c index 3b16ee3a8..f0d2c9c1a 100644 --- a/src/tests/cogl/conform/test-journal.c +++ b/src/tests/cogl/conform/test-journal.c @@ -8,7 +8,7 @@ static void test_journal_unref_flush (void) { - CoglTexture2D *texture; + CoglTexture *texture; CoglOffscreen *offscreen; CoglPipeline *pipeline; const int width = 1; @@ -22,7 +22,7 @@ test_journal_unref_flush (void) G_STATIC_ASSERT (sizeof data == sizeof reference_data); 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); pipeline = cogl_pipeline_new (test_ctx); @@ -35,13 +35,13 @@ test_journal_unref_flush (void) g_object_unref (offscreen); g_assert_null (offscreen); - cogl_texture_get_data (COGL_TEXTURE (texture), + cogl_texture_get_data (texture, COGL_PIXEL_FORMAT_RGBA_8888_PRE, stride, data); g_assert_cmpmem (data, sizeof (data), reference_data, sizeof (reference_data)); - cogl_object_unref (texture); + g_object_unref (texture); } COGL_TEST_SUITE ( diff --git a/src/tests/cogl/conform/test-just-vertex-shader.c b/src/tests/cogl/conform/test-just-vertex-shader.c index b9fa9060b..d2f346096 100644 --- a/src/tests/cogl/conform/test-just-vertex-shader.c +++ b/src/tests/cogl/conform/test-just-vertex-shader.c @@ -45,7 +45,7 @@ paint (TestState *state) constant green color provided by a texture */ tex = create_dummy_texture (); cogl_pipeline_set_layer_texture (pipeline, 0, tex); - cogl_object_unref (tex); + g_object_unref (tex); if (!cogl_pipeline_set_layer_combine (pipeline, 0, "RGBA=REPLACE(TEXTURE)", &error)) diff --git a/src/tests/cogl/conform/test-map-buffer-range.c b/src/tests/cogl/conform/test-map-buffer-range.c index d2dc077b7..12f87b429 100644 --- a/src/tests/cogl/conform/test-map-buffer-range.c +++ b/src/tests/cogl/conform/test-map-buffer-range.c @@ -25,7 +25,7 @@ vertex_data[4] = static void test_map_buffer_range (void) { - CoglTexture2D *tex; + CoglTexture *tex; CoglPipeline *pipeline; int fb_width, fb_height; CoglAttributeBuffer *buffer; @@ -122,7 +122,7 @@ test_map_buffer_range (void) g_object_unref (tex_coord_attribute); cogl_object_unref (pipeline); - cogl_object_unref (tex); + g_object_unref (tex); if (cogl_test_verbose ()) g_print ("OK\n"); diff --git a/src/tests/cogl/conform/test-multitexture.c b/src/tests/cogl/conform/test-multitexture.c index db36e09da..02ef3bf80 100644 --- a/src/tests/cogl/conform/test-multitexture.c +++ b/src/tests/cogl/conform/test-multitexture.c @@ -152,8 +152,8 @@ on_paint (ClutterActor *actor, tex_coords, 8); cogl_object_unref (pipeline); - cogl_object_unref (tex0); - cogl_object_unref (tex1); + g_object_unref (tex0); + g_object_unref (tex1); /* See what we got... */ diff --git a/src/tests/cogl/conform/test-npot-texture.c b/src/tests/cogl/conform/test-npot-texture.c index ce5d3e29b..1184d179d 100644 --- a/src/tests/cogl/conform/test-npot-texture.c +++ b/src/tests/cogl/conform/test-npot-texture.c @@ -138,7 +138,7 @@ paint (void) (y + 1) / 2.0f); cogl_object_unref (pipeline); - cogl_object_unref (texture); + g_object_unref (texture); } static void diff --git a/src/tests/cogl/conform/test-offscreen-texture-formats.c b/src/tests/cogl/conform/test-offscreen-texture-formats.c index 828398d97..2127bceca 100644 --- a/src/tests/cogl/conform/test-offscreen-texture-formats.c +++ b/src/tests/cogl/conform/test-offscreen-texture-formats.c @@ -85,7 +85,7 @@ test_offscreen_texture_formats_store_rgb10 (void) for (i = 0; i < G_N_ELEMENTS (formats); i++) { - CoglTexture2D *tex; + CoglTexture *tex; CoglOffscreen *offscreen; uint32_t rgb8_readback[4]; int j, k; @@ -93,7 +93,7 @@ test_offscreen_texture_formats_store_rgb10 (void) /* Allocate 2x2 to ensure we avoid any fast paths. */ 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); g_assert_no_error (error); @@ -179,7 +179,7 @@ test_offscreen_texture_formats_store_rgb10 (void) } 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++) { - CoglTexture2D *tex; + CoglTexture *tex; CoglOffscreen *offscreen; GError *error = NULL; int j; @@ -215,7 +215,7 @@ test_offscreen_texture_formats_store_rgb8 (void) /* Allocate 2x2 to ensure we avoid any fast paths. */ 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); g_assert_no_error (error); @@ -277,7 +277,7 @@ test_offscreen_texture_formats_store_rgb8 (void) } 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++) { - CoglTexture2D *tex_src; + CoglTexture *tex_src; CoglOffscreen *offscreen_src; GError *error = NULL; int j; 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); g_assert_no_error (error); for (j = 0; j < G_N_ELEMENTS (formats); j++) { - CoglTexture2D *tex_dst; + CoglTexture *tex_dst; CoglOffscreen *offscreen_dst; CoglPipeline *pipeline; uint32_t rgb10_readback[4]; int k; 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); g_assert_no_error (error); @@ -410,11 +410,11 @@ test_offscreen_texture_formats_paint_rgb10 (void) } g_object_unref (offscreen_dst); - cogl_object_unref (tex_dst); + g_object_unref (tex_dst); } 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++) { - CoglTexture2D *tex_src; + CoglTexture *tex_src; CoglOffscreen *offscreen_src; GError *error = NULL; int j; 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); g_assert_no_error (error); for (j = 0; j < G_N_ELEMENTS (formats); j++) { - CoglTexture2D *tex_dst; + CoglTexture *tex_dst; CoglOffscreen *offscreen_dst; CoglPipeline *pipeline; uint8_t rgba_readback[4 * 4] = {}; int k; 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); g_assert_no_error (error); @@ -527,11 +527,11 @@ test_offscreen_texture_formats_paint_rgb8 (void) } g_object_unref (offscreen_dst); - cogl_object_unref (tex_dst); + g_object_unref (tex_dst); } g_object_unref (offscreen_src); - cogl_object_unref (tex_src); + g_object_unref (tex_src); } } diff --git a/src/tests/cogl/conform/test-offscreen.c b/src/tests/cogl/conform/test-offscreen.c index ae63123e5..ca86a9b2d 100644 --- a/src/tests/cogl/conform/test-offscreen.c +++ b/src/tests/cogl/conform/test-offscreen.c @@ -40,17 +40,15 @@ check_quadrant (TestState *state, static void test_paint (TestState *state) { - CoglTexture2D *tex_2d; CoglTexture *tex; CoglOffscreen *offscreen; CoglFramebuffer *framebuffer; CoglPipeline *opaque_pipeline; CoglPipeline *texture_pipeline; - tex_2d = cogl_texture_2d_new_with_size (test_ctx, - state->fb_width, - state->fb_height); - tex = tex_2d; + tex = cogl_texture_2d_new_with_size (test_ctx, + state->fb_width, + state->fb_height); offscreen = cogl_offscreen_new_with_texture (tex); framebuffer = COGL_FRAMEBUFFER (offscreen); @@ -102,7 +100,7 @@ test_paint (TestState *state) cogl_object_unref (opaque_pipeline); cogl_object_unref (texture_pipeline); - cogl_object_unref (tex_2d); + g_object_unref (tex); cogl_framebuffer_pop_matrix (test_fb); @@ -123,7 +121,6 @@ static void test_flush (TestState *state) { CoglPipeline *pipeline; - CoglTexture2D *tex_2d; CoglTexture *tex; CoglOffscreen *offscreen; CoglFramebuffer *framebuffer; @@ -139,9 +136,8 @@ test_flush (TestState *state) the contents of the texture will automatically flush the journal */ - tex_2d = cogl_texture_2d_new_with_size (test_ctx, - 16, 16); /* width/height */ - tex = tex_2d; + tex = cogl_texture_2d_new_with_size (test_ctx, + 16, 16); /* width/height */ offscreen = cogl_offscreen_new_with_texture (tex); framebuffer = COGL_FRAMEBUFFER (offscreen); @@ -184,7 +180,7 @@ test_flush (TestState *state) 0xff0000ff); } - cogl_object_unref (tex_2d); + g_object_unref (tex); g_object_unref (offscreen); } diff --git a/src/tests/cogl/conform/test-pipeline-cache-unrefs-texture.c b/src/tests/cogl/conform/test-pipeline-cache-unrefs-texture.c index 08a3d7ad9..f0f8227c9 100644 --- a/src/tests/cogl/conform/test-pipeline-cache-unrefs-texture.c +++ b/src/tests/cogl/conform/test-pipeline-cache-unrefs-texture.c @@ -5,7 +5,7 @@ /* Keep track of the number of textures that we've created and are * still alive */ static int destroyed_texture_count = 0; - +static GQuark texture_data_key = 0; #define N_TEXTURES 3 static void @@ -19,8 +19,8 @@ create_texture (void) { static const guint8 data[] = { 0xff, 0xff, 0xff, 0xff }; - static CoglUserDataKey texture_data_key; - CoglTexture2D *tex_2d; + texture_data_key = g_quark_from_static_string ("-cogl-test-pipeline-cache-unrefs-texture"); + CoglTexture *tex_2d; tex_2d = cogl_texture_2d_new_from_data (test_ctx, 1, 1, /* width / height */ @@ -31,10 +31,10 @@ create_texture (void) /* Set some user data on the texture so we can track when it has * been destroyed */ - cogl_object_set_user_data (COGL_OBJECT (tex_2d), - &texture_data_key, - GINT_TO_POINTER (1), - free_texture_cb); + g_object_set_qdata_full (G_OBJECT (tex_2d), + texture_data_key, + GINT_TO_POINTER (1), + free_texture_cb); return tex_2d; } @@ -53,7 +53,7 @@ test_pipeline_cache_unrefs_texture (void) { CoglTexture *tex = create_texture (); 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 diff --git a/src/tests/cogl/conform/test-pipeline-shader-state.c b/src/tests/cogl/conform/test-pipeline-shader-state.c index a639bf882..1ed1ec1e2 100644 --- a/src/tests/cogl/conform/test-pipeline-shader-state.c +++ b/src/tests/cogl/conform/test-pipeline-shader-state.c @@ -11,7 +11,7 @@ test_pipeline_shader_state (void) CoglFramebuffer *fb; CoglPipeline *base_pipeline; CoglPipeline *draw_pipeline; - CoglTexture2D *tex; + CoglTexture *tex; CoglSnippet *snippet; float width = cogl_framebuffer_get_width (test_fb); diff --git a/src/tests/cogl/conform/test-pipeline-user-matrix.c b/src/tests/cogl/conform/test-pipeline-user-matrix.c index 9137d7864..333e15865 100644 --- a/src/tests/cogl/conform/test-pipeline-user-matrix.c +++ b/src/tests/cogl/conform/test-pipeline-user-matrix.c @@ -122,8 +122,8 @@ paint (TestState *state) 0, 0, state->width, state->height); - cogl_object_unref (tex1); - cogl_object_unref (tex0); + g_object_unref (tex1); + g_object_unref (tex0); cogl_object_unref (pipeline); } diff --git a/src/tests/cogl/conform/test-pixel-buffer.c b/src/tests/cogl/conform/test-pixel-buffer.c index 446ef90a9..0ae92316e 100644 --- a/src/tests/cogl/conform/test-pixel-buffer.c +++ b/src/tests/cogl/conform/test-pixel-buffer.c @@ -77,7 +77,7 @@ create_and_fill_bitmap (void) static CoglTexture * create_texture_from_bitmap (CoglBitmap *bitmap) { - CoglTexture2D *texture; + CoglTexture *texture; texture = cogl_texture_2d_new_from_bitmap (bitmap); @@ -150,7 +150,7 @@ test_pixel_buffer_map (void) 1.0f, -1.0f); g_object_unref (bitmap); - cogl_object_unref (texture); + g_object_unref (texture); cogl_object_unref (pipeline); check_colours (0x0000ffff, @@ -195,7 +195,7 @@ test_pixel_buffer_set_data (void) 1.0f, -1.0f); g_object_unref (bitmap); - cogl_object_unref (texture); + g_object_unref (texture); cogl_object_unref (pipeline); check_colours (0x0000ffff, @@ -210,7 +210,7 @@ test_pixel_buffer_set_data (void) static CoglTexture * create_white_texture (void) { - CoglTexture2D *texture; + CoglTexture *texture; uint8_t *data = g_malloc (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); g_object_unref (bitmap); - cogl_object_unref (texture); + g_object_unref (texture); cogl_object_unref (pipeline); check_colours (0xffffffff, diff --git a/src/tests/cogl/conform/test-point-sprite-known-failure.c b/src/tests/cogl/conform/test-point-sprite-known-failure.c index efc4baca4..3fd42aafd 100644 --- a/src/tests/cogl/conform/test-point-sprite-known-failure.c +++ b/src/tests/cogl/conform/test-point-sprite-known-failure.c @@ -26,7 +26,7 @@ do_test (gboolean check_orientation, int fb_height = cogl_framebuffer_get_height (test_fb); CoglPrimitive *prim; GError *error = NULL; - CoglTexture2D *tex_2d; + CoglTexture *tex_2d; CoglPipeline *pipeline, *solid_pipeline; int tex_height; @@ -136,7 +136,7 @@ do_test (gboolean check_orientation, cogl_object_unref (prim); cogl_object_unref (solid_pipeline); cogl_object_unref (pipeline); - cogl_object_unref (tex_2d); + g_object_unref (tex_2d); test_utils_check_pixel (test_fb, POINT_SIZE - POINT_SIZE / 4, diff --git a/src/tests/cogl/conform/test-point-sprite.c b/src/tests/cogl/conform/test-point-sprite.c index 6b6f459e8..6c2256a6a 100644 --- a/src/tests/cogl/conform/test-point-sprite.c +++ b/src/tests/cogl/conform/test-point-sprite.c @@ -26,7 +26,7 @@ do_test (gboolean check_orientation, int fb_height = cogl_framebuffer_get_height (test_fb); CoglPrimitive *prim; GError *error = NULL; - CoglTexture2D *tex_2d; + CoglTexture *tex_2d; CoglPipeline *pipeline, *solid_pipeline; int tex_height; @@ -136,7 +136,7 @@ do_test (gboolean check_orientation, cogl_object_unref (prim); cogl_object_unref (solid_pipeline); cogl_object_unref (pipeline); - cogl_object_unref (tex_2d); + g_object_unref (tex_2d); test_utils_check_pixel (test_fb, POINT_SIZE - POINT_SIZE / 4, diff --git a/src/tests/cogl/conform/test-premult.c b/src/tests/cogl/conform/test-premult.c index 1755ca621..783ea692e 100644 --- a/src/tests/cogl/conform/test-premult.c +++ b/src/tests/cogl/conform/test-premult.c @@ -49,7 +49,7 @@ make_texture (uint32_t color, CoglPixelFormat src_format, MakeTextureFlags flags) { - CoglTexture2D *tex_2d; + CoglTexture *tex; guchar *tex_data = gen_tex_data (color); CoglBitmap *bmp = cogl_bitmap_new_for_data (test_ctx, QUAD_WIDTH, @@ -58,16 +58,16 @@ make_texture (uint32_t color, QUAD_WIDTH * 4, 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) - cogl_texture_set_premultiplied (tex_2d, TRUE); + cogl_texture_set_premultiplied (tex, TRUE); else if (flags & TEXTURE_FLAG_SET_UNPREMULTIPLIED) - cogl_texture_set_premultiplied (tex_2d, FALSE); + cogl_texture_set_premultiplied (tex, FALSE); g_object_unref (bmp); - return tex_2d; + return tex; } static void diff --git a/src/tests/cogl/conform/test-primitive.c b/src/tests/cogl/conform/test-primitive.c index b95be43ab..1a16eebfc 100644 --- a/src/tests/cogl/conform/test-primitive.c +++ b/src/tests/cogl/conform/test-primitive.c @@ -183,7 +183,7 @@ test_paint (TestState *state) (PRIM_COLOR >> 8) & 0xff, (PRIM_COLOR >> 0) & 0xff); 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++) { diff --git a/src/tests/cogl/conform/test-read-texture-formats.c b/src/tests/cogl/conform/test-read-texture-formats.c index 3098bc70b..772746c73 100644 --- a/src/tests/cogl/conform/test-read-texture-formats.c +++ b/src/tests/cogl/conform/test-read-texture-formats.c @@ -11,9 +11,9 @@ static const uint8_t tex_data[4] = { 0x12, 0x34, 0x56, 0x78 }; static void -test_read_byte (CoglTexture2D *tex_2d, +test_read_byte (CoglTexture *tex_2d, CoglPixelFormat format, - uint8_t expected_byte) + uint8_t expected_byte) { uint8_t received_byte; @@ -26,7 +26,7 @@ test_read_byte (CoglTexture2D *tex_2d, } static void -test_read_short (CoglTexture2D *tex_2d, +test_read_short (CoglTexture *tex_2d, CoglPixelFormat format, ...) { @@ -65,9 +65,9 @@ test_read_short (CoglTexture2D *tex_2d, } static void -test_read_888 (CoglTexture2D *tex_2d, +test_read_888 (CoglTexture *tex_2d, CoglPixelFormat format, - uint32_t expected_pixel) + uint32_t expected_pixel) { uint8_t pixel[4]; @@ -80,9 +80,9 @@ test_read_888 (CoglTexture2D *tex_2d, } static void -test_read_88 (CoglTexture2D *tex_2d, +test_read_88 (CoglTexture *tex_2d, CoglPixelFormat format, - uint32_t expected_pixel) + uint32_t expected_pixel) { uint8_t pixel[4]; @@ -97,9 +97,9 @@ test_read_88 (CoglTexture2D *tex_2d, } static void -test_read_8888 (CoglTexture2D *tex_2d, +test_read_8888 (CoglTexture *tex_2d, CoglPixelFormat format, - uint32_t expected_pixel) + uint32_t expected_pixel) { uint32_t received_pixel; char *received_value_str; @@ -120,7 +120,7 @@ test_read_8888 (CoglTexture2D *tex_2d, } static void -test_read_int (CoglTexture2D *tex_2d, +test_read_int (CoglTexture *tex_2d, CoglPixelFormat format, ...) { @@ -161,7 +161,7 @@ test_read_int (CoglTexture2D *tex_2d, static void test_read_texture_formats (void) { - CoglTexture2D *tex_2d; + CoglTexture *tex_2d; tex_2d = cogl_texture_2d_new_from_data (test_ctx, 1, 1, /* width / height */ @@ -215,7 +215,7 @@ test_read_texture_formats (void) 2, 0x78, 10, 0x56, 10, 0x34, 10, 0x12, -1); - cogl_object_unref (tex_2d); + g_object_unref (tex_2d); if (cogl_test_verbose ()) g_print ("OK\n"); diff --git a/src/tests/cogl/conform/test-readpixels.c b/src/tests/cogl/conform/test-readpixels.c index a82c99e63..7e04d675c 100644 --- a/src/tests/cogl/conform/test-readpixels.c +++ b/src/tests/cogl/conform/test-readpixels.c @@ -125,7 +125,7 @@ on_after_paint (ClutterActor *actor, g_free (pixelsc); - cogl_object_unref (tex); + g_object_unref (tex); /* Restore the viewport and matrices state */ cogl_set_viewport (saved_viewport[0], diff --git a/src/tests/cogl/conform/test-snippets.c b/src/tests/cogl/conform/test-snippets.c index 8dceccc95..c523899dd 100644 --- a/src/tests/cogl/conform/test-snippets.c +++ b/src/tests/cogl/conform/test-snippets.c @@ -37,7 +37,7 @@ create_texture_pipeline (TestState *state) COGL_PIPELINE_FILTER_NEAREST, COGL_PIPELINE_FILTER_NEAREST); - cogl_object_unref (tex); + g_object_unref (tex); return pipeline; } @@ -707,8 +707,8 @@ test_naming_texture_units (TestState *state) cogl_object_unref (pipeline); g_object_unref (snippet); - cogl_object_unref (tex1); - cogl_object_unref (tex2); + g_object_unref (tex1); + g_object_unref (tex2); test_utils_check_pixel (test_fb, 5, 5, 0xffff00ff); } diff --git a/src/tests/cogl/conform/test-sparse-pipeline.c b/src/tests/cogl/conform/test-sparse-pipeline.c index 142d2ad2c..95a2b4f30 100644 --- a/src/tests/cogl/conform/test-sparse-pipeline.c +++ b/src/tests/cogl/conform/test-sparse-pipeline.c @@ -38,8 +38,8 @@ test_sparse_layer_combine (TestState *state) test_utils_check_pixel (test_fb, 2, 2, 0xffff00ff); cogl_object_unref (pipeline); - cogl_object_unref (tex1); - cogl_object_unref (tex2); + g_object_unref (tex1); + g_object_unref (tex2); } static void diff --git a/src/tests/cogl/conform/test-sub-texture.c b/src/tests/cogl/conform/test-sub-texture.c index 808791d31..cbf78ec99 100644 --- a/src/tests/cogl/conform/test-sub-texture.c +++ b/src/tests/cogl/conform/test-sub-texture.c @@ -22,15 +22,15 @@ corner_colors[SOURCE_DIVISIONS_X * SOURCE_DIVISIONS_Y] = typedef struct _TestState { - CoglTexture2D *tex; + CoglTexture *tex; } TestState; -static CoglTexture2D * +static CoglTexture * create_source (TestState *state) { int dx, dy; uint8_t *data = g_malloc (SOURCE_SIZE * SOURCE_SIZE * 4); - CoglTexture2D *tex; + CoglTexture *tex; /* Create a texture with a different coloured rectangle at each corner */ @@ -63,10 +63,10 @@ create_source (TestState *state) return tex; } -static CoglTexture2D * +static CoglTexture * create_test_texture (TestState *state) { - CoglTexture2D *tex; + CoglTexture *tex; uint8_t *data = g_malloc (256 * 256 * 4), *p = data; int x, y; @@ -97,8 +97,7 @@ create_test_texture (TestState *state) static void paint (TestState *state) { - CoglTexture2D *full_texture; - CoglSubTexture *sub_texture, *sub_sub_texture; + CoglTexture *full_texture, *sub_texture, *sub_sub_texture; CoglPipeline *pipeline = cogl_pipeline_new (test_ctx); /* Create a sub texture of the bottom right quarter of the texture */ @@ -111,7 +110,7 @@ paint (TestState *state) /* Paint it */ cogl_pipeline_set_layer_texture (pipeline, 0, sub_texture); - cogl_object_unref (sub_texture); + g_object_unref (sub_texture); cogl_framebuffer_draw_rectangle (test_fb, pipeline, 0.0f, 0.0f, DIVISION_WIDTH, DIVISION_HEIGHT); @@ -125,7 +124,7 @@ paint (TestState *state) SOURCE_SIZE, DIVISION_HEIGHT); cogl_pipeline_set_layer_texture (pipeline, 0, sub_texture); - cogl_object_unref (sub_texture); + g_object_unref (sub_texture); cogl_framebuffer_draw_textured_rectangle (test_fb, pipeline, 0.0f, SOURCE_SIZE, @@ -139,13 +138,13 @@ paint (TestState *state) sub_texture = cogl_sub_texture_new (test_ctx, full_texture, 20, 10, 30, 20); - cogl_object_unref (full_texture); + g_object_unref (full_texture); sub_sub_texture = cogl_sub_texture_new (test_ctx, sub_texture, 20, 10, 10, 10); - cogl_object_unref (sub_texture); + g_object_unref (sub_texture); cogl_pipeline_set_layer_texture (pipeline, 0, sub_sub_texture); - cogl_object_unref (sub_sub_texture); + g_object_unref (sub_sub_texture); cogl_framebuffer_draw_rectangle (test_fb, pipeline, 0.0f, SOURCE_SIZE * 2.0f, 10.0f, SOURCE_SIZE * 2.0f + 10.0f); @@ -192,8 +191,7 @@ static void validate_result (TestState *state) { int i, division_num, x, y; - CoglTexture2D *test_tex; - CoglSubTexture *sub_texture; + CoglTexture *test_tex, *sub_texture; uint8_t *texture_data, *p; int tex_width, tex_height; @@ -254,7 +252,7 @@ validate_result (TestState *state) p += 4; } g_free (texture_data); - cogl_object_unref (sub_texture); + g_object_unref (sub_texture); /* Create a 256x256 test texture */ test_tex = create_test_texture (state); @@ -269,7 +267,7 @@ validate_result (TestState *state) COGL_PIXEL_FORMAT_RGBA_8888_PRE, 256 * 4, texture_data); g_free (texture_data); - cogl_object_unref (sub_texture); + g_object_unref (sub_texture); /* Get the texture data */ p = texture_data = g_malloc (256 * 256 * 4); cogl_texture_get_data (test_tex, @@ -297,7 +295,7 @@ validate_result (TestState *state) } } g_free (texture_data); - cogl_object_unref (test_tex); + g_object_unref (test_tex); } static void @@ -317,7 +315,7 @@ test_sub_texture (void) paint (&state); validate_result (&state); - cogl_object_unref (state.tex); + g_object_unref (state.tex); if (cogl_test_verbose ()) g_print ("OK\n"); diff --git a/src/tests/cogl/conform/test-texture-get-set-data.c b/src/tests/cogl/conform/test-texture-get-set-data.c index fd69db02c..03005aa5f 100644 --- a/src/tests/cogl/conform/test-texture-get-set-data.c +++ b/src/tests/cogl/conform/test-texture-get-set-data.c @@ -124,7 +124,7 @@ check_texture (int width, int height, TestUtilsTextureFlags flags) p += 4; } - cogl_object_unref (tex); + g_object_unref (tex); g_free (data); } diff --git a/src/tests/cogl/conform/test-texture-mipmaps.c b/src/tests/cogl/conform/test-texture-mipmaps.c index 537e4dcc7..635790619 100644 --- a/src/tests/cogl/conform/test-texture-mipmaps.c +++ b/src/tests/cogl/conform/test-texture-mipmaps.c @@ -56,7 +56,7 @@ on_paint (ClutterActor *actor, tex = make_texture (); pipeline = cogl_pipeline_new (); cogl_pipeline_set_layer (pipeline, 0, tex); - cogl_object_unref (tex); + g_object_unref (tex); /* Render a 1x1 pixel quad without mipmaps */ cogl_set_source (pipeline); diff --git a/src/tests/cogl/conform/test-texture-no-allocate.c b/src/tests/cogl/conform/test-texture-no-allocate.c index c77495839..cad6d1672 100644 --- a/src/tests/cogl/conform/test-texture-no-allocate.c +++ b/src/tests/cogl/conform/test-texture-no-allocate.c @@ -15,7 +15,7 @@ test_texture_no_allocate (void) { uint8_t *tex_data; CoglTexture *texture; - CoglTexture2D *texture_2d; + CoglTexture *texture_2d; GError *error = NULL; tex_data = g_malloc (BIG_TEX_WIDTH * BIG_TEX_HEIGHT * 4); @@ -45,7 +45,7 @@ test_texture_no_allocate (void) if (texture == NULL) g_error_free (error); else - cogl_object_unref (texture); + g_object_unref (texture); /* Try to create a sliced texture without allocating it */ texture = @@ -53,12 +53,12 @@ test_texture_no_allocate (void) BIG_TEX_WIDTH, BIG_TEX_HEIGHT, COGL_TEXTURE_MAX_WASTE); - cogl_object_unref (texture); + g_object_unref (texture); /* 2D texture */ texture_2d = cogl_texture_2d_new_with_size (test_ctx, 64, 64); - cogl_object_unref (texture_2d); + g_object_unref (texture_2d); } COGL_TEST_SUITE ( diff --git a/src/tests/cogl/conform/test-texture-rg.c b/src/tests/cogl/conform/test-texture-rg.c index 6d476359e..ae59e8a23 100644 --- a/src/tests/cogl/conform/test-texture-rg.c +++ b/src/tests/cogl/conform/test-texture-rg.c @@ -7,7 +7,7 @@ #define TEX_WIDTH 8 #define TEX_HEIGHT 8 -static CoglTexture2D * +static CoglTexture * make_texture (void) { uint8_t tex_data[TEX_WIDTH * TEX_HEIGHT * 2], *p = tex_data; @@ -32,7 +32,7 @@ static void test_texture_rg (void) { CoglPipeline *pipeline; - CoglTexture2D *tex; + CoglTexture *tex; int fb_width, fb_height; int x, y; @@ -76,7 +76,7 @@ test_texture_rg (void) } cogl_object_unref (pipeline); - cogl_object_unref (tex); + g_object_unref (tex); } COGL_TEST_SUITE ( diff --git a/src/tests/cogl/conform/test-viewport.c b/src/tests/cogl/conform/test-viewport.c index 48621683d..57a709ec8 100644 --- a/src/tests/cogl/conform/test-viewport.c +++ b/src/tests/cogl/conform/test-viewport.c @@ -363,7 +363,7 @@ on_after_paint (ClutterActor *actor, cogl_rectangle (-1, 1, 1, -1); #endif - cogl_object_unref (tex); + g_object_unref (tex); /* Finally restore the stage's original state... */ cogl_pop_matrix (); diff --git a/src/tests/cogl/conform/test-wrap-modes.c b/src/tests/cogl/conform/test-wrap-modes.c index 8d01dadd2..e21b5aa19 100644 --- a/src/tests/cogl/conform/test-wrap-modes.c +++ b/src/tests/cogl/conform/test-wrap-modes.c @@ -199,7 +199,7 @@ paint (TestState *state) /* Draw the tests first with a non atlased texture */ state->texture = create_texture (TEST_UTILS_TEXTURE_NO_ATLAS); draw_tests (state); - cogl_object_unref (state->texture); + g_object_unref (state->texture); /* Draw the tests again with a possible atlased texture. This should end up testing software repeats */ @@ -208,7 +208,7 @@ paint (TestState *state) cogl_framebuffer_translate (test_fb, 0.0f, TEX_SIZE * 2.0f, 0.0f); draw_tests (state); cogl_framebuffer_pop_matrix (test_fb); - cogl_object_unref (state->texture); + g_object_unref (state->texture); /* Draw the tests using CoglPrimitive */ state->texture = create_texture (TEST_UTILS_TEXTURE_NO_ATLAS); @@ -217,7 +217,7 @@ paint (TestState *state) 0.0f, TEX_SIZE * 4.0f, 0.0f); draw_tests_polygon (state); cogl_framebuffer_pop_matrix (test_fb); - cogl_object_unref (state->texture); + g_object_unref (state->texture); validate_result (state); } diff --git a/src/tests/cogl/conform/test-write-texture-formats.c b/src/tests/cogl/conform/test-write-texture-formats.c index 6019c02f3..5389c907e 100644 --- a/src/tests/cogl/conform/test-write-texture-formats.c +++ b/src/tests/cogl/conform/test-write-texture-formats.c @@ -41,7 +41,7 @@ test_write_byte (CoglContext *context, test_color (texture, expected_pixel); - cogl_object_unref (texture); + g_object_unref (texture); } static void @@ -63,7 +63,7 @@ test_write_short (CoglContext *context, test_color (texture, expected_pixel); - cogl_object_unref (texture); + g_object_unref (texture); } static void @@ -87,7 +87,7 @@ test_write_bytes (CoglContext *context, test_color (texture, expected_pixel); - cogl_object_unref (texture); + g_object_unref (texture); } static void @@ -127,7 +127,7 @@ test_write_int (CoglContext *context, test_color (texture, expected_pixel); - cogl_object_unref (texture); + g_object_unref (texture); } static void diff --git a/src/wayland/meta-wayland-buffer.c b/src/wayland/meta-wayland-buffer.c index 3fc7ee4ca..465b4b67c 100644 --- a/src/wayland/meta-wayland-buffer.c +++ b/src/wayland/meta-wayland-buffer.c @@ -147,7 +147,7 @@ meta_wayland_buffer_realize (MetaWaylandBuffer *buffer) stream = meta_wayland_egl_stream_new (buffer, NULL); if (stream) { - CoglTexture2D *texture; + CoglTexture *texture; texture = meta_wayland_egl_stream_create_texture (stream, NULL); if (!texture) @@ -155,7 +155,7 @@ meta_wayland_buffer_realize (MetaWaylandBuffer *buffer) buffer->egl_stream.stream = stream; buffer->type = META_WAYLAND_BUFFER_TYPE_EGL_STREAM; - buffer->egl_stream.texture = meta_multi_texture_new_simple (COGL_TEXTURE (texture)); + buffer->egl_stream.texture = meta_multi_texture_new_simple (texture); buffer->is_y_inverted = meta_wayland_egl_stream_is_y_inverted (stream); return TRUE; @@ -382,24 +382,21 @@ shm_buffer_attach (MetaWaylandBuffer *buffer, stride, wl_shm_buffer_get_data (shm_buffer)); - new_cogl_tex = COGL_TEXTURE (cogl_texture_2d_new_from_bitmap (bitmap)); + new_cogl_tex = cogl_texture_2d_new_from_bitmap (bitmap); if (!cogl_texture_allocate (new_cogl_tex, error)) { - g_clear_pointer (&new_cogl_tex, cogl_object_unref); + g_clear_object (&new_cogl_tex); if (g_error_matches (*error, COGL_TEXTURE_ERROR, COGL_TEXTURE_ERROR_SIZE)) { - CoglTexture2DSliced *texture_sliced; - g_clear_error (error); - texture_sliced = + new_cogl_tex = cogl_texture_2d_sliced_new_from_bitmap (bitmap, COGL_TEXTURE_MAX_WASTE); - new_cogl_tex = COGL_TEXTURE (texture_sliced); if (!cogl_texture_allocate (new_cogl_tex, error)) - g_clear_pointer (&new_cogl_tex, cogl_object_unref); + g_clear_object (&new_cogl_tex); } } @@ -432,7 +429,7 @@ egl_image_buffer_attach (MetaWaylandBuffer *buffer, CoglPixelFormat cogl_format; EGLImageKHR egl_image; CoglEglImageFlags flags; - CoglTexture2D *texture_2d; + CoglTexture *texture_2d; if (buffer->egl_image.texture) { @@ -498,7 +495,7 @@ egl_image_buffer_attach (MetaWaylandBuffer *buffer, if (!texture_2d) return FALSE; - buffer->egl_image.texture = meta_multi_texture_new_simple (COGL_TEXTURE (texture_2d)); + buffer->egl_image.texture = meta_multi_texture_new_simple (texture_2d); buffer->is_y_inverted = !!y_inverted; g_clear_object (texture); diff --git a/src/wayland/meta-wayland-dma-buf.c b/src/wayland/meta-wayland-dma-buf.c index 79a0f1409..a3ec774d0 100644 --- a/src/wayland/meta-wayland-dma-buf.c +++ b/src/wayland/meta-wayland-dma-buf.c @@ -387,7 +387,7 @@ meta_wayland_dma_buf_realize_texture (MetaWaylandBuffer *buffer, { EGLImageKHR egl_image; CoglEglImageFlags flags; - CoglTexture2D *cogl_texture; + CoglTexture *cogl_texture; uint64_t modifiers[META_WAYLAND_DMA_BUF_MAX_FDS]; uint32_t n_planes; @@ -428,7 +428,7 @@ meta_wayland_dma_buf_realize_texture (MetaWaylandBuffer *buffer, return FALSE; buffer->dma_buf.texture = - meta_multi_texture_new_simple (COGL_TEXTURE (cogl_texture)); + meta_multi_texture_new_simple (cogl_texture); } else { @@ -443,7 +443,7 @@ meta_wayland_dma_buf_realize_texture (MetaWaylandBuffer *buffer, n_planes = meta_multi_texture_format_get_n_planes (multi_format); /* Each EGLImage is a plane in the final CoglMultiPlaneTexture */ - planes = g_ptr_array_new_full (n_planes, cogl_object_unref); + planes = g_ptr_array_new_full (n_planes, g_object_unref); meta_multi_texture_format_get_subformats (multi_format, subformats); meta_multi_texture_format_get_plane_indices (multi_format, plane_indices); meta_multi_texture_format_get_subsampling_factors (multi_format, @@ -454,7 +454,7 @@ meta_wayland_dma_buf_realize_texture (MetaWaylandBuffer *buffer, { EGLImageKHR egl_image; CoglEglImageFlags flags; - CoglTexture2D *cogl_texture; + CoglTexture *cogl_texture; uint32_t drm_format = 0; int plane_index, j; diff --git a/src/wayland/meta-wayland-egl-stream.c b/src/wayland/meta-wayland-egl-stream.c index 36d977888..1a0fe6200 100644 --- a/src/wayland/meta-wayland-egl-stream.c +++ b/src/wayland/meta-wayland-egl-stream.c @@ -135,7 +135,7 @@ struct _MetaWaylandEglStream EGLStreamKHR egl_stream; MetaWaylandBuffer *buffer; - CoglTexture2D *texture; + CoglTexture *texture; gboolean is_y_inverted; CoglSnippet *snippet; }; @@ -207,7 +207,7 @@ alloc_egl_stream_texture (CoglTexture2D *texture, error); } -CoglTexture2D * +CoglTexture * meta_wayland_egl_stream_create_texture (MetaWaylandEglStream *stream, GError **error) { @@ -218,7 +218,7 @@ meta_wayland_egl_stream_create_texture (MetaWaylandEglStream *stream, ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); CoglContext *cogl_context = clutter_backend_get_cogl_context (clutter_backend); EGLDisplay egl_display = cogl_egl_context_get_egl_display (cogl_context); - CoglTexture2D *texture; + CoglTexture *texture; int width, height; int y_inverted; @@ -253,9 +253,9 @@ meta_wayland_egl_stream_create_texture (MetaWaylandEglStream *stream, return NULL; } - if (!cogl_texture_allocate (COGL_TEXTURE (texture), error)) + if (!cogl_texture_allocate (texture, error)) { - cogl_object_unref (texture); + g_object_unref (texture); return NULL; } diff --git a/src/wayland/meta-wayland-egl-stream.h b/src/wayland/meta-wayland-egl-stream.h index 494935c3f..453285e7f 100644 --- a/src/wayland/meta-wayland-egl-stream.h +++ b/src/wayland/meta-wayland-egl-stream.h @@ -42,8 +42,8 @@ MetaWaylandEglStream * meta_wayland_egl_stream_new (MetaWaylandBuffer *buffer, gboolean meta_wayland_egl_stream_attach (MetaWaylandEglStream *stream, GError **error); -CoglTexture2D * meta_wayland_egl_stream_create_texture (MetaWaylandEglStream *stream, - GError **error); +CoglTexture * meta_wayland_egl_stream_create_texture (MetaWaylandEglStream *stream, + GError **error); CoglSnippet * meta_wayland_egl_stream_create_snippet (MetaWaylandEglStream *stream); gboolean meta_wayland_egl_stream_is_y_inverted (MetaWaylandEglStream *stream); diff --git a/src/wayland/meta-wayland-single-pixel-buffer.c b/src/wayland/meta-wayland-single-pixel-buffer.c index 0c7d2e031..e57d831f0 100644 --- a/src/wayland/meta-wayland-single-pixel-buffer.c +++ b/src/wayland/meta-wayland-single-pixel-buffer.c @@ -119,7 +119,7 @@ meta_wayland_single_pixel_buffer_attach (MetaWaylandBuffer *buffer, wl_resource_get_user_data (buffer->resource); uint8_t data[4]; CoglPixelFormat pixel_format; - CoglTexture2D *tex_2d; + CoglTexture *tex_2d; if (buffer->single_pixel.texture) return TRUE; @@ -143,7 +143,7 @@ meta_wayland_single_pixel_buffer_attach (MetaWaylandBuffer *buffer, return FALSE; buffer->single_pixel.texture = - meta_multi_texture_new_simple (COGL_TEXTURE (tex_2d)); + meta_multi_texture_new_simple (tex_2d); g_clear_object (texture); *texture = g_object_ref (buffer->single_pixel.texture);