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.
This commit is contained in:
Emmanuele Bassi 2012-02-15 09:30:18 +00:00
parent d81ae9dd65
commit b1ff53d980
3 changed files with 60 additions and 56 deletions

View File

@ -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");

View File

@ -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");

View File

@ -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");