cogl: Port Snippet away from CoglObject

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3193>
This commit is contained in:
Bilal Elmoussaoui 2023-08-17 13:16:14 +02:00 committed by Marge Bot
parent 1da42dc3c0
commit 312d5c367e
23 changed files with 104 additions and 106 deletions

View File

@ -189,7 +189,7 @@ clutter_blur_effect_init (ClutterBlurEffect *self)
NULL); NULL);
cogl_snippet_set_replace (snippet, box_blur_glsl_shader); cogl_snippet_set_replace (snippet, box_blur_glsl_shader);
cogl_pipeline_add_layer_snippet (klass->base_pipeline, 0, snippet); cogl_pipeline_add_layer_snippet (klass->base_pipeline, 0, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_pipeline_set_layer_null_texture (klass->base_pipeline, 0); cogl_pipeline_set_layer_null_texture (klass->base_pipeline, 0);
} }

View File

@ -161,7 +161,7 @@ create_blur_pipeline (void)
NULL); NULL);
cogl_snippet_set_replace (snippet, gaussian_blur_glsl); cogl_snippet_set_replace (snippet, gaussian_blur_glsl);
cogl_pipeline_add_layer_snippet (blur_pipeline, 0, snippet); cogl_pipeline_add_layer_snippet (blur_pipeline, 0, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_context_set_named_pipeline (ctx, &blur_pipeline_key, blur_pipeline); cogl_context_set_named_pipeline (ctx, &blur_pipeline_key, blur_pipeline);
} }

View File

@ -381,7 +381,7 @@ clutter_brightness_contrast_effect_init (ClutterBrightnessContrastEffect *self)
brightness_contrast_decls, brightness_contrast_decls,
brightness_contrast_source); brightness_contrast_source);
cogl_pipeline_add_snippet (klass->base_pipeline, snippet); cogl_pipeline_add_snippet (klass->base_pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_pipeline_set_layer_null_texture (klass->base_pipeline, 0); cogl_pipeline_set_layer_null_texture (klass->base_pipeline, 0);
} }

View File

@ -225,7 +225,7 @@ clutter_colorize_effect_init (ClutterColorizeEffect *self)
colorize_glsl_declarations, colorize_glsl_declarations,
colorize_glsl_source); colorize_glsl_source);
cogl_pipeline_add_snippet (klass->base_pipeline, snippet); cogl_pipeline_add_snippet (klass->base_pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_pipeline_set_layer_null_texture (klass->base_pipeline, 0); cogl_pipeline_set_layer_null_texture (klass->base_pipeline, 0);
} }

View File

@ -228,7 +228,7 @@ clutter_desaturate_effect_init (ClutterDesaturateEffect *self)
desaturate_glsl_declarations, desaturate_glsl_declarations,
desaturate_glsl_source); desaturate_glsl_source);
cogl_pipeline_add_snippet (klass->base_pipeline, snippet); cogl_pipeline_add_snippet (klass->base_pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_pipeline_set_layer_null_texture (klass->base_pipeline, 0); cogl_pipeline_set_layer_null_texture (klass->base_pipeline, 0);
} }

View File

@ -681,7 +681,7 @@ cogl_pipeline_add_layer_snippet (CoglPipeline *pipeline,
CoglSnippet *snippet) CoglSnippet *snippet)
{ {
g_return_if_fail (cogl_is_pipeline (pipeline)); g_return_if_fail (cogl_is_pipeline (pipeline));
g_return_if_fail (cogl_is_snippet (snippet)); g_return_if_fail (COGL_IS_SNIPPET (snippet));
g_return_if_fail (snippet->hook >= COGL_SNIPPET_FIRST_LAYER_HOOK); g_return_if_fail (snippet->hook >= COGL_SNIPPET_FIRST_LAYER_HOOK);
if (snippet->hook < COGL_SNIPPET_FIRST_LAYER_FRAGMENT_HOOK) if (snippet->hook < COGL_SNIPPET_FIRST_LAYER_FRAGMENT_HOOK)

View File

@ -225,7 +225,7 @@ _cogl_pipeline_snippet_list_free (CoglPipelineSnippetList *list)
{ {
tmp = l->next; tmp = l->next;
cogl_object_unref (l->data); g_object_unref (l->data);
g_list_free_1 (l); g_list_free_1 (l);
} }
} }
@ -234,7 +234,7 @@ void
_cogl_pipeline_snippet_list_add (CoglPipelineSnippetList *list, _cogl_pipeline_snippet_list_add (CoglPipelineSnippetList *list,
CoglSnippet *snippet) CoglSnippet *snippet)
{ {
list->entries = g_list_append (list->entries, cogl_object_ref (snippet)); list->entries = g_list_append (list->entries, g_object_ref (snippet));
_cogl_snippet_make_immutable (snippet); _cogl_snippet_make_immutable (snippet);
} }
@ -247,7 +247,7 @@ _cogl_pipeline_snippet_list_copy (CoglPipelineSnippetList *dst,
const GList *l; const GList *l;
for (l = src->entries; l; l = l->next) for (l = src->entries; l; l = l->next)
g_queue_push_tail (&queue, cogl_object_ref (l->data)); g_queue_push_tail (&queue, g_object_ref (l->data));
dst->entries = queue.head; dst->entries = queue.head;
} }

View File

@ -1218,7 +1218,7 @@ cogl_pipeline_add_snippet (CoglPipeline *pipeline,
CoglSnippet *snippet) CoglSnippet *snippet)
{ {
g_return_if_fail (cogl_is_pipeline (pipeline)); g_return_if_fail (cogl_is_pipeline (pipeline));
g_return_if_fail (cogl_is_snippet (snippet)); g_return_if_fail (COGL_IS_SNIPPET (snippet));
g_return_if_fail (snippet->hook < COGL_SNIPPET_FIRST_LAYER_HOOK); g_return_if_fail (snippet->hook < COGL_SNIPPET_FIRST_LAYER_HOOK);
if (snippet->hook < COGL_SNIPPET_FIRST_PIPELINE_FRAGMENT_HOOK) if (snippet->hook < COGL_SNIPPET_FIRST_PIPELINE_FRAGMENT_HOOK)

View File

@ -36,7 +36,6 @@
#include <glib.h> #include <glib.h>
#include "cogl/cogl-snippet.h" #include "cogl/cogl-snippet.h"
#include "cogl/cogl-object-private.h"
/* These values are also used in the enum for CoglSnippetHook. They /* These values are also used in the enum for CoglSnippetHook. They
are copied here because we don't really want these names to be part are copied here because we don't really want these names to be part
@ -54,7 +53,7 @@
struct _CoglSnippet struct _CoglSnippet
{ {
CoglObject _parent; GObject parent_instance;
CoglSnippetHook hook; CoglSnippetHook hook;

View File

@ -36,22 +36,43 @@
#include "cogl/cogl-types.h" #include "cogl/cogl-types.h"
#include "cogl/cogl-snippet-private.h" #include "cogl/cogl-snippet-private.h"
#include "cogl/cogl-util.h" #include "cogl/cogl-util.h"
#include "cogl/cogl-gtype-private.h"
G_DEFINE_TYPE (CoglSnippet, cogl_snippet, G_TYPE_OBJECT);
static void static void
_cogl_snippet_free (CoglSnippet *snippet); cogl_snippet_dispose (GObject *object)
{
CoglSnippet *snippet = COGL_SNIPPET (object);
g_free (snippet->declarations);
g_free (snippet->pre);
g_free (snippet->replace);
g_free (snippet->post);
G_OBJECT_CLASS (cogl_snippet_parent_class)->dispose (object);
}
static void
cogl_snippet_init (CoglSnippet *display)
{
}
static void
cogl_snippet_class_init (CoglSnippetClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
object_class->dispose = cogl_snippet_dispose;
}
COGL_OBJECT_DEFINE (Snippet, snippet);
COGL_GTYPE_DEFINE_CLASS (Snippet, snippet);
CoglSnippet * CoglSnippet *
cogl_snippet_new (CoglSnippetHook hook, cogl_snippet_new (CoglSnippetHook hook,
const char *declarations, const char *declarations,
const char *post) const char *post)
{ {
CoglSnippet *snippet = g_new0 (CoglSnippet, 1); CoglSnippet *snippet = g_object_new (COGL_TYPE_SNIPPET, NULL);
_cogl_snippet_object_new (snippet);
snippet->hook = hook; snippet->hook = hook;
@ -64,7 +85,7 @@ cogl_snippet_new (CoglSnippetHook hook,
CoglSnippetHook CoglSnippetHook
cogl_snippet_get_hook (CoglSnippet *snippet) cogl_snippet_get_hook (CoglSnippet *snippet)
{ {
g_return_val_if_fail (cogl_is_snippet (snippet), 0); g_return_val_if_fail (COGL_IS_SNIPPET (snippet), 0);
return snippet->hook; return snippet->hook;
} }
@ -88,7 +109,7 @@ void
cogl_snippet_set_declarations (CoglSnippet *snippet, cogl_snippet_set_declarations (CoglSnippet *snippet,
const char *declarations) const char *declarations)
{ {
g_return_if_fail (cogl_is_snippet (snippet)); g_return_if_fail (COGL_IS_SNIPPET (snippet));
if (!_cogl_snippet_modify (snippet)) if (!_cogl_snippet_modify (snippet))
return; return;
@ -100,7 +121,7 @@ cogl_snippet_set_declarations (CoglSnippet *snippet,
const char * const char *
cogl_snippet_get_declarations (CoglSnippet *snippet) cogl_snippet_get_declarations (CoglSnippet *snippet)
{ {
g_return_val_if_fail (cogl_is_snippet (snippet), NULL); g_return_val_if_fail (COGL_IS_SNIPPET (snippet), NULL);
return snippet->declarations; return snippet->declarations;
} }
@ -109,7 +130,7 @@ void
cogl_snippet_set_pre (CoglSnippet *snippet, cogl_snippet_set_pre (CoglSnippet *snippet,
const char *pre) const char *pre)
{ {
g_return_if_fail (cogl_is_snippet (snippet)); g_return_if_fail (COGL_IS_SNIPPET (snippet));
if (!_cogl_snippet_modify (snippet)) if (!_cogl_snippet_modify (snippet))
return; return;
@ -121,7 +142,7 @@ cogl_snippet_set_pre (CoglSnippet *snippet,
const char * const char *
cogl_snippet_get_pre (CoglSnippet *snippet) cogl_snippet_get_pre (CoglSnippet *snippet)
{ {
g_return_val_if_fail (cogl_is_snippet (snippet), NULL); g_return_val_if_fail (COGL_IS_SNIPPET (snippet), NULL);
return snippet->pre; return snippet->pre;
} }
@ -130,7 +151,7 @@ void
cogl_snippet_set_replace (CoglSnippet *snippet, cogl_snippet_set_replace (CoglSnippet *snippet,
const char *replace) const char *replace)
{ {
g_return_if_fail (cogl_is_snippet (snippet)); g_return_if_fail (COGL_IS_SNIPPET (snippet));
if (!_cogl_snippet_modify (snippet)) if (!_cogl_snippet_modify (snippet))
return; return;
@ -142,7 +163,7 @@ cogl_snippet_set_replace (CoglSnippet *snippet,
const char * const char *
cogl_snippet_get_replace (CoglSnippet *snippet) cogl_snippet_get_replace (CoglSnippet *snippet)
{ {
g_return_val_if_fail (cogl_is_snippet (snippet), NULL); g_return_val_if_fail (COGL_IS_SNIPPET (snippet), NULL);
return snippet->replace; return snippet->replace;
} }
@ -151,7 +172,7 @@ void
cogl_snippet_set_post (CoglSnippet *snippet, cogl_snippet_set_post (CoglSnippet *snippet,
const char *post) const char *post)
{ {
g_return_if_fail (cogl_is_snippet (snippet)); g_return_if_fail (COGL_IS_SNIPPET (snippet));
if (!_cogl_snippet_modify (snippet)) if (!_cogl_snippet_modify (snippet))
return; return;
@ -163,7 +184,7 @@ cogl_snippet_set_post (CoglSnippet *snippet,
const char * const char *
cogl_snippet_get_post (CoglSnippet *snippet) cogl_snippet_get_post (CoglSnippet *snippet)
{ {
g_return_val_if_fail (cogl_is_snippet (snippet), NULL); g_return_val_if_fail (COGL_IS_SNIPPET (snippet), NULL);
return snippet->post; return snippet->post;
} }
@ -173,13 +194,3 @@ _cogl_snippet_make_immutable (CoglSnippet *snippet)
{ {
snippet->immutable = TRUE; snippet->immutable = TRUE;
} }
static void
_cogl_snippet_free (CoglSnippet *snippet)
{
g_free (snippet->declarations);
g_free (snippet->pre);
g_free (snippet->replace);
g_free (snippet->post);
g_free (snippet);
}

View File

@ -40,8 +40,9 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/** /**
* SECTION:cogl-snippet * CoglSnippet:
* @short_description: Functions for creating and manipulating shader snippets *
* Functions for creating and manipulating shader snippets
* *
* #CoglSnippet<!-- -->s are used to modify or replace parts of a * #CoglSnippet<!-- -->s are used to modify or replace parts of a
* #CoglPipeline using GLSL. GLSL is a programming language supported * #CoglPipeline using GLSL. GLSL is a programming language supported
@ -301,7 +302,7 @@ G_BEGIN_DECLS
* Here is an example of using a snippet to add a desaturate effect to the * Here is an example of using a snippet to add a desaturate effect to the
* generated color on a pipeline. * generated color on a pipeline.
* *
* <programlisting> * ```c
* CoglPipeline *pipeline = cogl_pipeline_new (); * CoglPipeline *pipeline = cogl_pipeline_new ();
* *
* /<!-- -->* Set up the pipeline here, ie by adding a texture or other * /<!-- -->* Set up the pipeline here, ie by adding a texture or other
@ -323,7 +324,7 @@ G_BEGIN_DECLS
* cogl_pipeline_add_snippet (pipeline, snippet); * cogl_pipeline_add_snippet (pipeline, snippet);
* /<!-- -->* The pipeline keeps a reference to the snippet * /<!-- -->* The pipeline keeps a reference to the snippet
* so we don't need to *<!-- -->/ * so we don't need to *<!-- -->/
* cogl_object_unref (snippet); * g_object_unref (snippet);
* *
* /<!-- -->* Update the custom uniform on the pipeline *<!-- -->/ * /<!-- -->* Update the custom uniform on the pipeline *<!-- -->/
* int location = cogl_pipeline_get_uniform_location (pipeline, "factor"); * int location = cogl_pipeline_get_uniform_location (pipeline, "factor");
@ -333,19 +334,18 @@ G_BEGIN_DECLS
* cogl_push_source (pipeline); * cogl_push_source (pipeline);
* cogl_rectangle (0, 0, 10, 10); * cogl_rectangle (0, 0, 10, 10);
* cogl_pop_source (); * cogl_pop_source ();
* </programlisting> * ```
*/ */
typedef struct _CoglSnippet CoglSnippet; typedef struct _CoglSnippet CoglSnippet;
#define COGL_SNIPPET(OBJECT) ((CoglSnippet *)OBJECT) #define COGL_TYPE_SNIPPET (cogl_snippet_get_type ())
/**
* cogl_snippet_get_gtype:
*
* Returns: a #GType that can be used with the GLib type system.
*/
COGL_EXPORT COGL_EXPORT
GType cogl_snippet_get_gtype (void); G_DECLARE_FINAL_TYPE (CoglSnippet,
cogl_snippet,
COGL,
SNIPPET,
GObject)
/* Enumeration of all the hook points that a snippet can be attached /* Enumeration of all the hook points that a snippet can be attached
to within a pipeline. */ to within a pipeline. */
@ -699,18 +699,6 @@ cogl_snippet_new (CoglSnippetHook hook,
COGL_EXPORT CoglSnippetHook COGL_EXPORT CoglSnippetHook
cogl_snippet_get_hook (CoglSnippet *snippet); cogl_snippet_get_hook (CoglSnippet *snippet);
/**
* cogl_is_snippet:
* @object: A #CoglObject pointer
*
* Gets whether the given @object references an existing snippet object.
*
* Returns: %TRUE if the @object references a #CoglSnippet,
* %FALSE otherwise
*/
COGL_EXPORT gboolean
cogl_is_snippet (void *object);
/** /**
* cogl_snippet_set_declarations: * cogl_snippet_set_declarations:
* @snippet: A #CoglSnippet * @snippet: A #CoglSnippet

View File

@ -249,7 +249,7 @@ meta_multi_texture_format_get_snippets (MetaMultiTextureFormat format,
CoglSnippet *globals_snippet; CoglSnippet *globals_snippet;
globals_snippet = g_once (&globals_once, create_globals_snippet, NULL); globals_snippet = g_once (&globals_once, create_globals_snippet, NULL);
*fragment_globals_snippet = cogl_object_ref (globals_snippet); *fragment_globals_snippet = g_object_ref (globals_snippet);
} }
if (fragment_snippet) if (fragment_snippet)
@ -259,7 +259,7 @@ meta_multi_texture_format_get_snippets (MetaMultiTextureFormat format,
format_snippet = g_once (&multi_format_table[format].snippet_once, format_snippet = g_once (&multi_format_table[format].snippet_once,
create_format_snippet, create_format_snippet,
GINT_TO_POINTER (format)); GINT_TO_POINTER (format));
*fragment_snippet = cogl_object_ref (format_snippet); *fragment_snippet = g_object_ref (format_snippet);
} }
return TRUE; return TRUE;

View File

@ -251,7 +251,7 @@ meta_shaped_texture_dispose (GObject *object)
g_clear_pointer (&stex->opaque_region, cairo_region_destroy); g_clear_pointer (&stex->opaque_region, cairo_region_destroy);
g_clear_pointer (&stex->clip_region, cairo_region_destroy); g_clear_pointer (&stex->clip_region, cairo_region_destroy);
g_clear_pointer (&stex->snippet, cogl_object_unref); g_clear_pointer (&stex->snippet, g_object_unref);
G_OBJECT_CLASS (meta_shaped_texture_parent_class)->dispose (object); G_OBJECT_CLASS (meta_shaped_texture_parent_class)->dispose (object);
} }
@ -364,8 +364,8 @@ get_combined_pipeline (MetaShapedTexture *stex,
cogl_pipeline_add_snippet (pipeline, fragment_globals_snippet); cogl_pipeline_add_snippet (pipeline, fragment_globals_snippet);
cogl_pipeline_add_snippet (pipeline, fragment_snippet); cogl_pipeline_add_snippet (pipeline, fragment_snippet);
cogl_clear_object (&fragment_globals_snippet); g_clear_object (&fragment_globals_snippet);
cogl_clear_object (&fragment_snippet); g_clear_object (&fragment_snippet);
stex->combined_pipeline = pipeline; stex->combined_pipeline = pipeline;
@ -1159,9 +1159,9 @@ meta_shaped_texture_set_snippet (MetaShapedTexture *stex,
meta_shaped_texture_reset_pipelines (stex); meta_shaped_texture_reset_pipelines (stex);
g_clear_pointer (&stex->snippet, cogl_object_unref); g_clear_pointer (&stex->snippet, g_object_unref);
if (snippet) if (snippet)
stex->snippet = cogl_object_ref (snippet); stex->snippet = g_object_ref (snippet);
} }
/** /**

View File

@ -232,8 +232,8 @@ ensure_mipmap_texture (MetaTextureMipmap *mipmap)
cogl_pipeline_add_snippet (mipmap->pipeline, fragment_globals_snippet); cogl_pipeline_add_snippet (mipmap->pipeline, fragment_globals_snippet);
cogl_pipeline_add_snippet (mipmap->pipeline, fragment_snippet); cogl_pipeline_add_snippet (mipmap->pipeline, fragment_snippet);
cogl_clear_object (&fragment_globals_snippet); g_clear_object (&fragment_globals_snippet);
cogl_clear_object (&fragment_snippet); g_clear_object (&fragment_snippet);
} }
for (i = 0; i < n_planes; i++) for (i = 0; i < n_planes; i++)

View File

@ -294,7 +294,7 @@ test_custom_attributes (void)
paint (&state); paint (&state);
cogl_object_unref (state.pipeline); cogl_object_unref (state.pipeline);
cogl_object_unref (snippet); g_object_unref (snippet);
if (cogl_test_verbose ()) if (cogl_test_verbose ())
g_print ("OK\n"); g_print ("OK\n");

View File

@ -47,7 +47,7 @@ test_pipeline_shader_state (void)
NULL, /* declarations */ NULL, /* declarations */
"cogl_color_out = vec4 (0.0, 1.0, 0.1, 1.1);"); "cogl_color_out = vec4 (0.0, 1.0, 0.1, 1.1);");
cogl_pipeline_add_snippet (draw_pipeline, snippet); cogl_pipeline_add_snippet (draw_pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_framebuffer_draw_rectangle (test_fb, draw_pipeline, cogl_framebuffer_draw_rectangle (test_fb, draw_pipeline,
0, 0, width, height); 0, 0, width, height);
@ -80,7 +80,7 @@ test_pipeline_shader_state (void)
NULL, /* declarations */ NULL, /* declarations */
"cogl_color_out = vec4 (0.0, 0.0, 1.1, 1.1);"); "cogl_color_out = vec4 (0.0, 0.0, 1.1, 1.1);");
cogl_pipeline_add_snippet (draw_pipeline, snippet); cogl_pipeline_add_snippet (draw_pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_framebuffer_draw_rectangle (test_fb, draw_pipeline, cogl_framebuffer_draw_rectangle (test_fb, draw_pipeline,
0, 0, width, height); 0, 0, width, height);

View File

@ -157,7 +157,7 @@ setup_snippet (CoglPipeline *pipeline)
"cogl_point_size_out = " "cogl_point_size_out = "
"my_super_duper_point_size_attrib;\n"); "my_super_duper_point_size_attrib;\n");
cogl_pipeline_add_snippet (pipeline, snippet); cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
} }
static void static void

View File

@ -87,7 +87,7 @@ do_test (gboolean check_orientation,
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet); cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
} }
else else
{ {

View File

@ -87,7 +87,7 @@ do_test (gboolean check_orientation,
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet); cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
} }
else else
{ {

View File

@ -57,7 +57,7 @@ simple_fragment_snippet (TestState *state)
NULL, /* declarations */ NULL, /* declarations */
"cogl_color_out.g += 1.0;"); "cogl_color_out.g += 1.0;");
cogl_pipeline_add_snippet (pipeline, snippet); cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 0, 0, 10, 10); cogl_framebuffer_draw_rectangle (test_fb, pipeline, 0, 0, 10, 10);
@ -81,7 +81,7 @@ simple_vertex_snippet (TestState *state)
NULL, NULL,
"cogl_color_out.b += 1.0;"); "cogl_color_out.b += 1.0;");
cogl_pipeline_add_snippet (pipeline, snippet); cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 10, 0, 20, 10); cogl_framebuffer_draw_rectangle (test_fb, pipeline, 10, 0, 20, 10);
@ -110,12 +110,12 @@ shared_uniform (TestState *state)
"uniform float a_value;", "uniform float a_value;",
"cogl_color_out.b += a_value;"); "cogl_color_out.b += a_value;");
cogl_pipeline_add_snippet (pipeline, snippet); cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT, snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
"uniform float a_value;", "uniform float a_value;",
"cogl_color_out.b += a_value;"); "cogl_color_out.b += a_value;");
cogl_pipeline_add_snippet (pipeline, snippet); cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_framebuffer_draw_rectangle (test_fb, cogl_framebuffer_draw_rectangle (test_fb,
pipeline, pipeline,
@ -156,7 +156,7 @@ lots_snippets (TestState *state)
declarations, declarations,
code); code);
cogl_pipeline_add_snippet (pipeline, snippet); cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
g_free (code); g_free (code);
g_free (uniform_name); g_free (uniform_name);
@ -187,7 +187,7 @@ shared_variable_pre_post (TestState *state)
"cogl_color_out = redvec;"); "cogl_color_out = redvec;");
cogl_snippet_set_pre (snippet, "vec4 redvec = vec4 (1.0, 0.0, 0.0, 1.0);"); cogl_snippet_set_pre (snippet, "vec4 redvec = vec4 (1.0, 0.0, 0.0, 1.0);");
cogl_pipeline_add_snippet (pipeline, snippet); cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 40, 0, 50, 10); cogl_framebuffer_draw_rectangle (test_fb, pipeline, 40, 0, 50, 10);
@ -224,7 +224,7 @@ test_pipeline_caching (TestState *state)
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 60, 0, 70, 10); cogl_framebuffer_draw_rectangle (test_fb, pipeline, 60, 0, 70, 10);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
cogl_object_unref (snippet); g_object_unref (snippet);
test_utils_check_pixel (test_fb, 55, 5, 0x00ff00ff); test_utils_check_pixel (test_fb, 55, 5, 0x00ff00ff);
test_utils_check_pixel (test_fb, 65, 5, 0x00ff00ff); test_utils_check_pixel (test_fb, 65, 5, 0x00ff00ff);
@ -252,7 +252,7 @@ test_replace_string (TestState *state)
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 70, 0, 80, 10); cogl_framebuffer_draw_rectangle (test_fb, pipeline, 70, 0, 80, 10);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
cogl_object_unref (snippet); g_object_unref (snippet);
test_utils_check_pixel (test_fb, 75, 5, 0x808000ff); test_utils_check_pixel (test_fb, 75, 5, 0x808000ff);
} }
@ -279,7 +279,7 @@ test_texture_lookup_hook (TestState *state)
0, 0, 0, 0); 0, 0, 0, 0);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
cogl_object_unref (snippet); g_object_unref (snippet);
test_utils_check_pixel (test_fb, 85, 5, 0x00ffffff); test_utils_check_pixel (test_fb, 85, 5, 0x00ffffff);
} }
@ -305,7 +305,7 @@ test_multiple_samples (TestState *state)
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 0, 0, 10, 10); cogl_framebuffer_draw_rectangle (test_fb, pipeline, 0, 0, 10, 10);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
cogl_object_unref (snippet); g_object_unref (snippet);
test_utils_check_pixel (test_fb, 5, 5, 0xffff00ff); test_utils_check_pixel (test_fb, 5, 5, 0xffff00ff);
} }
@ -328,7 +328,7 @@ test_replace_lookup_hook (TestState *state)
0, 0, 0, 0); 0, 0, 0, 0);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
cogl_object_unref (snippet); g_object_unref (snippet);
test_utils_check_pixel (test_fb, 95, 5, 0x0000ffff); test_utils_check_pixel (test_fb, 95, 5, 0x0000ffff);
} }
@ -346,14 +346,14 @@ test_replace_snippet (TestState *state)
NULL, NULL,
"cogl_color_out = vec4 (0.5, 0.5, 0.5, 1.0);"); "cogl_color_out = vec4 (0.5, 0.5, 0.5, 1.0);");
cogl_pipeline_add_snippet (pipeline, snippet); cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT, NULL, NULL); snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT, NULL, NULL);
cogl_snippet_set_pre (snippet, "cogl_color_out = vec4 (1.0, 1.0, 1.0, 1.0);"); cogl_snippet_set_pre (snippet, "cogl_color_out = vec4 (1.0, 1.0, 1.0, 1.0);");
cogl_snippet_set_replace (snippet, cogl_snippet_set_replace (snippet,
"cogl_color_out *= vec4 (1.0, 0.0, 0.0, 1.0);"); "cogl_color_out *= vec4 (1.0, 0.0, 0.0, 1.0);");
cogl_pipeline_add_snippet (pipeline, snippet); cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_framebuffer_draw_textured_rectangle (test_fb, cogl_framebuffer_draw_textured_rectangle (test_fb,
pipeline, pipeline,
@ -376,7 +376,7 @@ test_replace_fragment_layer (TestState *state)
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_LAYER_FRAGMENT, NULL, NULL); snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_LAYER_FRAGMENT, NULL, NULL);
cogl_snippet_set_replace (snippet, "cogl_layer = vec4 (0.0, 0.0, 1.0, 1.0);"); cogl_snippet_set_replace (snippet, "cogl_layer = vec4 (0.0, 0.0, 1.0, 1.0);");
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet); cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
/* Add a second layer which samples from the texture in the first /* Add a second layer which samples from the texture in the first
layer. The snippet override should cause the first layer not to layer. The snippet override should cause the first layer not to
@ -414,7 +414,7 @@ test_modify_fragment_layer (TestState *state)
"uniform float a_value;", "uniform float a_value;",
"cogl_layer.g = a_value;"); "cogl_layer.g = a_value;");
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet); cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_framebuffer_draw_textured_rectangle (test_fb, cogl_framebuffer_draw_textured_rectangle (test_fb,
pipeline, pipeline,
@ -443,7 +443,7 @@ test_modify_vertex_layer (TestState *state)
NULL, NULL,
"cogl_tex_coord.x = 1.0;"); "cogl_tex_coord.x = 1.0;");
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet); cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_framebuffer_draw_textured_rectangle (test_fb, cogl_framebuffer_draw_textured_rectangle (test_fb,
pipeline, pipeline,
@ -473,7 +473,7 @@ test_replace_vertex_layer (TestState *state)
NULL); NULL);
cogl_snippet_set_replace (snippet, "cogl_tex_coord.x = 1.0;\n"); cogl_snippet_set_replace (snippet, "cogl_tex_coord.x = 1.0;\n");
cogl_pipeline_add_layer_snippet (pipeline, 0, snippet); cogl_pipeline_add_layer_snippet (pipeline, 0, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_framebuffer_draw_textured_rectangle (test_fb, cogl_framebuffer_draw_textured_rectangle (test_fb,
pipeline, pipeline,
@ -508,7 +508,7 @@ test_vertex_transform_hook (TestState *state)
cogl_snippet_set_replace (snippet, "cogl_position_out = " cogl_snippet_set_replace (snippet, "cogl_position_out = "
"pmat * cogl_position_in;"); "pmat * cogl_position_in;");
cogl_pipeline_add_snippet (pipeline, snippet); cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
/* Copy the current projection matrix to a uniform */ /* Copy the current projection matrix to a uniform */
cogl_framebuffer_get_projection_matrix (test_fb, &matrix); cogl_framebuffer_get_projection_matrix (test_fb, &matrix);
@ -564,7 +564,7 @@ test_global_vertex_hook (TestState *state)
"This string shouldn't be used so " "This string shouldn't be used so "
"we can safely put garbage in here."); "we can safely put garbage in here.");
cogl_pipeline_add_snippet (pipeline, snippet); cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX, snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_VERTEX,
NULL, /* declarations */ NULL, /* declarations */
@ -574,7 +574,7 @@ test_global_vertex_hook (TestState *state)
"cogl_color_out.gba = vec3 (0.0, 0.0, 1.0);\n" "cogl_color_out.gba = vec3 (0.0, 0.0, 1.0);\n"
"cogl_position_out = cogl_position_in;\n"); "cogl_position_out = cogl_position_in;\n");
cogl_pipeline_add_snippet (pipeline, snippet); cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_framebuffer_draw_rectangle (test_fb, cogl_framebuffer_draw_rectangle (test_fb,
pipeline, pipeline,
@ -617,7 +617,7 @@ test_global_fragment_hook (TestState *state)
"This string shouldn't be used so " "This string shouldn't be used so "
"we can safely put garbage in here."); "we can safely put garbage in here.");
cogl_pipeline_add_snippet (pipeline, snippet); cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT, snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
NULL, /* declarations */ NULL, /* declarations */
@ -626,7 +626,7 @@ test_global_fragment_hook (TestState *state)
"cogl_color_out.r = multiply_by_four (0.25);\n" "cogl_color_out.r = multiply_by_four (0.25);\n"
"cogl_color_out.gba = vec3 (0.0, 0.0, 1.0);\n"); "cogl_color_out.gba = vec3 (0.0, 0.0, 1.0);\n");
cogl_pipeline_add_snippet (pipeline, snippet); cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_framebuffer_draw_rectangle (test_fb, cogl_framebuffer_draw_rectangle (test_fb,
pipeline, pipeline,
@ -660,14 +660,14 @@ test_snippet_order (TestState *state)
cogl_snippet_set_pre (snippet, "cogl_color_out.r = 0.5;\n"); cogl_snippet_set_pre (snippet, "cogl_color_out.r = 0.5;\n");
cogl_snippet_set_replace (snippet, "cogl_color_out.ba = vec2 (0.0, 1.0);"); cogl_snippet_set_replace (snippet, "cogl_color_out.ba = vec2 (0.0, 1.0);");
cogl_pipeline_add_snippet (pipeline, snippet); cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT, snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT,
NULL, NULL,
"cogl_color_out.g = 1.0;\n"); "cogl_color_out.g = 1.0;\n");
cogl_snippet_set_pre (snippet, "cogl_color_out.r = 1.0;\n"); cogl_snippet_set_pre (snippet, "cogl_color_out.r = 1.0;\n");
cogl_pipeline_add_snippet (pipeline, snippet); cogl_pipeline_add_snippet (pipeline, snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 160, 0, 170, 10); cogl_framebuffer_draw_rectangle (test_fb, pipeline, 160, 0, 170, 10);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
@ -706,7 +706,7 @@ test_naming_texture_units (TestState *state)
cogl_framebuffer_draw_rectangle (test_fb, pipeline, 0, 0, 10, 10); cogl_framebuffer_draw_rectangle (test_fb, pipeline, 0, 0, 10, 10);
cogl_object_unref (pipeline); cogl_object_unref (pipeline);
cogl_object_unref (snippet); g_object_unref (snippet);
cogl_object_unref (tex1); cogl_object_unref (tex1);
cogl_object_unref (tex2); cogl_object_unref (tex2);

View File

@ -27,7 +27,7 @@ create_pipelines (CoglPipeline **pipelines,
pipelines[i] = cogl_pipeline_new (test_ctx); pipelines[i] = cogl_pipeline_new (test_ctx);
cogl_pipeline_add_snippet (pipelines[i], snippet); cogl_pipeline_add_snippet (pipelines[i], snippet);
cogl_object_unref (snippet); g_object_unref (snippet);
} }
/* Test that drawing with them works. This should create the entries /* Test that drawing with them works. This should create the entries

View File

@ -200,7 +200,7 @@ meta_wayland_actor_surface_real_sync_actor_state (MetaWaylandActorSurface *actor
meta_shaped_texture_set_snippet (stex, snippet); meta_shaped_texture_set_snippet (stex, snippet);
meta_shaped_texture_set_is_y_inverted (stex, is_y_inverted); meta_shaped_texture_set_is_y_inverted (stex, is_y_inverted);
meta_shaped_texture_set_buffer_scale (stex, surface->scale); meta_shaped_texture_set_buffer_scale (stex, surface->scale);
cogl_clear_object (&snippet); g_clear_object (&snippet);
} }
else else
{ {

View File

@ -316,7 +316,7 @@ meta_wayland_egl_stream_create_snippet (MetaWaylandEglStream *stream)
stream->snippet = snippet; stream->snippet = snippet;
} }
return cogl_object_ref (stream->snippet); return g_object_ref (stream->snippet);
} }
gboolean gboolean
@ -361,7 +361,7 @@ meta_wayland_egl_stream_finalize (GObject *object)
meta_egl_destroy_stream (egl, egl_display, stream->egl_stream, NULL); meta_egl_destroy_stream (egl, egl_display, stream->egl_stream, NULL);
cogl_clear_object (&stream->snippet); g_clear_object (&stream->snippet);
G_OBJECT_CLASS (meta_wayland_egl_stream_parent_class)->finalize (object); G_OBJECT_CLASS (meta_wayland_egl_stream_parent_class)->finalize (object);
} }