From b1ff53d98017089667e29135c49bf451446a4f74 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Wed, 15 Feb 2012 09:30:18 +0000 Subject: [PATCH] effects: Delay the creation of the base pipeline Unconditionally creating CoglPipeline and CoglSnippets inside the class initialization functions does not seem to be enough when dealing with headless builds. Our last resort is to lazily create the base pipeline the first time we try to copy it, during the instance initialization. --- clutter/clutter-blur-effect.c | 37 ++++++++++++++------------ clutter/clutter-colorize-effect.c | 40 ++++++++++++++--------------- clutter/clutter-desaturate-effect.c | 39 ++++++++++++++-------------- 3 files changed, 60 insertions(+), 56 deletions(-) diff --git a/clutter/clutter-blur-effect.c b/clutter/clutter-blur-effect.c index bed7360d4..69811b1f5 100644 --- a/clutter/clutter-blur-effect.c +++ b/clutter/clutter-blur-effect.c @@ -221,7 +221,6 @@ clutter_blur_effect_class_init (ClutterBlurEffectClass *klass) ClutterEffectClass *effect_class = CLUTTER_EFFECT_CLASS (klass); GObjectClass *gobject_class = G_OBJECT_CLASS (klass); ClutterOffscreenEffectClass *offscreen_class; - CoglSnippet *snippet; gobject_class->dispose = clutter_blur_effect_dispose; @@ -230,28 +229,32 @@ clutter_blur_effect_class_init (ClutterBlurEffectClass *klass) offscreen_class = CLUTTER_OFFSCREEN_EFFECT_CLASS (klass); offscreen_class->paint_target = clutter_blur_effect_paint_target; - - klass->base_pipeline = cogl_pipeline_new (); - - snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_TEXTURE_LOOKUP, - box_blur_glsl_declarations, - NULL); - cogl_snippet_set_replace (snippet, box_blur_glsl_shader); - cogl_pipeline_add_layer_snippet (klass->base_pipeline, 0, snippet); - cogl_object_unref (snippet); - - cogl_pipeline_set_layer_null_texture (klass->base_pipeline, - 0, /* layer number */ - COGL_TEXTURE_TYPE_2D); } static void clutter_blur_effect_init (ClutterBlurEffect *self) { - CoglPipeline *base_pipeline = - CLUTTER_BLUR_EFFECT_GET_CLASS (self)->base_pipeline; + ClutterBlurEffectClass *klass = CLUTTER_BLUR_EFFECT_GET_CLASS (self); - self->pipeline = cogl_pipeline_copy (base_pipeline); + if (G_UNLIKELY (klass->base_pipeline == NULL)) + { + CoglSnippet *snippet; + + klass->base_pipeline = cogl_pipeline_new (); + + snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_TEXTURE_LOOKUP, + box_blur_glsl_declarations, + NULL); + cogl_snippet_set_replace (snippet, box_blur_glsl_shader); + cogl_pipeline_add_layer_snippet (klass->base_pipeline, 0, snippet); + cogl_object_unref (snippet); + + cogl_pipeline_set_layer_null_texture (klass->base_pipeline, + 0, /* layer number */ + COGL_TEXTURE_TYPE_2D); + } + + self->pipeline = cogl_pipeline_copy (klass->base_pipeline); self->pixel_step_uniform = cogl_pipeline_get_uniform_location (self->pipeline, "pixel_step"); diff --git a/clutter/clutter-colorize-effect.c b/clutter/clutter-colorize-effect.c index 82b1f47e9..e55f3ba37 100644 --- a/clutter/clutter-colorize-effect.c +++ b/clutter/clutter-colorize-effect.c @@ -227,7 +227,6 @@ clutter_colorize_effect_class_init (ClutterColorizeEffectClass *klass) ClutterEffectClass *effect_class = CLUTTER_EFFECT_CLASS (klass); GObjectClass *gobject_class = G_OBJECT_CLASS (klass); ClutterOffscreenEffectClass *offscreen_class; - CoglSnippet *snippet; offscreen_class = CLUTTER_OFFSCREEN_EFFECT_CLASS (klass); offscreen_class->paint_target = clutter_colorize_effect_paint_target; @@ -252,22 +251,7 @@ clutter_colorize_effect_class_init (ClutterColorizeEffectClass *klass) &default_tint, CLUTTER_PARAM_READWRITE); - g_object_class_install_properties (gobject_class, - PROP_LAST, - obj_props); - - - klass->base_pipeline = cogl_pipeline_new (); - - snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT, - colorize_glsl_declarations, - colorize_glsl_source); - cogl_pipeline_add_snippet (klass->base_pipeline, snippet); - cogl_object_unref (snippet); - - cogl_pipeline_set_layer_null_texture (klass->base_pipeline, - 0, /* layer number */ - COGL_TEXTURE_TYPE_2D); + g_object_class_install_properties (gobject_class, PROP_LAST, obj_props); } static void @@ -292,10 +276,26 @@ update_tint_uniform (ClutterColorizeEffect *self) static void clutter_colorize_effect_init (ClutterColorizeEffect *self) { - CoglPipeline *base_pipeline = - CLUTTER_COLORIZE_EFFECT_GET_CLASS (self)->base_pipeline; + ClutterColorizeEffectClass *klass = CLUTTER_COLORIZE_EFFECT_GET_CLASS (self); - self->pipeline = cogl_pipeline_copy (base_pipeline); + if (G_UNLIKELY (klass->base_pipeline == NULL)) + { + CoglSnippet *snippet; + + klass->base_pipeline = cogl_pipeline_new (); + + snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT, + colorize_glsl_declarations, + colorize_glsl_source); + cogl_pipeline_add_snippet (klass->base_pipeline, snippet); + cogl_object_unref (snippet); + + cogl_pipeline_set_layer_null_texture (klass->base_pipeline, + 0, /* layer number */ + COGL_TEXTURE_TYPE_2D); + } + + self->pipeline = cogl_pipeline_copy (klass->base_pipeline); self->tint_uniform = cogl_pipeline_get_uniform_location (self->pipeline, "tint"); diff --git a/clutter/clutter-desaturate-effect.c b/clutter/clutter-desaturate-effect.c index fc3c26346..d127bd586 100644 --- a/clutter/clutter-desaturate-effect.c +++ b/clutter/clutter-desaturate-effect.c @@ -249,7 +249,6 @@ clutter_desaturate_effect_class_init (ClutterDesaturateEffectClass *klass) ClutterEffectClass *effect_class = CLUTTER_EFFECT_CLASS (klass); GObjectClass *gobject_class = G_OBJECT_CLASS (klass); ClutterOffscreenEffectClass *offscreen_class; - CoglSnippet *snippet; offscreen_class = CLUTTER_OFFSCREEN_EFFECT_CLASS (klass); offscreen_class->paint_target = clutter_desaturate_effect_paint_target; @@ -276,30 +275,32 @@ clutter_desaturate_effect_class_init (ClutterDesaturateEffectClass *klass) gobject_class->set_property = clutter_desaturate_effect_set_property; gobject_class->get_property = clutter_desaturate_effect_get_property; - g_object_class_install_properties (gobject_class, - PROP_LAST, - obj_props); - - klass->base_pipeline = cogl_pipeline_new (); - - snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT, - desaturate_glsl_declarations, - desaturate_glsl_source); - cogl_pipeline_add_snippet (klass->base_pipeline, snippet); - cogl_object_unref (snippet); - - cogl_pipeline_set_layer_null_texture (klass->base_pipeline, - 0, /* layer number */ - COGL_TEXTURE_TYPE_2D); + g_object_class_install_properties (gobject_class, PROP_LAST, obj_props); } static void clutter_desaturate_effect_init (ClutterDesaturateEffect *self) { - CoglPipeline *base_pipeline = - CLUTTER_DESATURATE_EFFECT_GET_CLASS (self)->base_pipeline; + ClutterDesaturateEffectClass *klass = CLUTTER_DESATURATE_EFFECT_GET_CLASS (self); - self->pipeline = cogl_pipeline_copy (base_pipeline); + if (G_UNLIKELY (klass->base_pipeline == NULL)) + { + CoglSnippet *snippet; + + klass->base_pipeline = cogl_pipeline_new (); + + snippet = cogl_snippet_new (COGL_SNIPPET_HOOK_FRAGMENT, + desaturate_glsl_declarations, + desaturate_glsl_source); + cogl_pipeline_add_snippet (klass->base_pipeline, snippet); + cogl_object_unref (snippet); + + cogl_pipeline_set_layer_null_texture (klass->base_pipeline, + 0, /* layer number */ + COGL_TEXTURE_TYPE_2D); + } + + self->pipeline = cogl_pipeline_copy (klass->base_pipeline); self->factor_uniform = cogl_pipeline_get_uniform_location (self->pipeline, "factor");