From 7b32f06f44f21491c81c4f41b47387455c66e161 Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Fri, 10 Nov 2023 17:37:56 +0100 Subject: [PATCH] colorize-effect: Use macros for subclassing boilerplate Part-of: --- clutter/clutter/clutter-autocleanups.h | 1 - clutter/clutter/clutter-colorize-effect.c | 73 ++++++++++++----------- clutter/clutter/clutter-colorize-effect.h | 18 ++++-- 3 files changed, 50 insertions(+), 42 deletions(-) diff --git a/clutter/clutter/clutter-autocleanups.h b/clutter/clutter/clutter-autocleanups.h index cb791321c..9db2132c7 100644 --- a/clutter/clutter/clutter-autocleanups.h +++ b/clutter/clutter/clutter-autocleanups.h @@ -35,7 +35,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterBlurEffect, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterBoxLayout, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterBrightnessContrastEffect, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterClone, g_object_unref) -G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterColorizeEffect, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterDeformEffect, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterDesaturateEffect, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterFixedLayout, g_object_unref) diff --git a/clutter/clutter/clutter-colorize-effect.c b/clutter/clutter/clutter-colorize-effect.c index 455ac654e..3d643146d 100644 --- a/clutter/clutter/clutter-colorize-effect.c +++ b/clutter/clutter/clutter-colorize-effect.c @@ -24,17 +24,13 @@ /** * ClutterColorizeEffect: - * + * * A colorization effect * * #ClutterColorizeEffect is a sub-class of #ClutterEffect that * colorizes an actor with the given tint. */ -#define CLUTTER_COLORIZE_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_COLORIZE_EFFECT, ClutterColorizeEffectClass)) -#define CLUTTER_IS_COLORIZE_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_COLORIZE_EFFECT)) -#define CLUTTER_COLORIZE_EFFECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_COLORIZE_EFFECT, ClutterColorizeEffectClass)) - #include "config.h" #include "clutter/clutter-colorize-effect.h" @@ -43,10 +39,9 @@ #include "clutter/clutter-debug.h" #include "clutter/clutter-enum-types.h" -#include "clutter/clutter-offscreen-effect.h" #include "clutter/clutter-private.h" -struct _ClutterColorizeEffect +typedef struct _ClutterColorizeEffectPrivate { ClutterOffscreenEffect parent_instance; @@ -56,14 +51,7 @@ struct _ClutterColorizeEffect gint tint_uniform; CoglPipeline *pipeline; -}; - -struct _ClutterColorizeEffectClass -{ - ClutterOffscreenEffectClass parent_class; - - CoglPipeline *base_pipeline; -}; +} ClutterColorizeEffectPrivate; /* the magic gray vec3 has been taken from the NTSC conversion weights * as defined by: @@ -93,27 +81,31 @@ enum static GParamSpec *obj_props[PROP_LAST]; -G_DEFINE_TYPE (ClutterColorizeEffect, - clutter_colorize_effect, - CLUTTER_TYPE_OFFSCREEN_EFFECT); +G_DEFINE_TYPE_WITH_PRIVATE (ClutterColorizeEffect, + clutter_colorize_effect, + CLUTTER_TYPE_OFFSCREEN_EFFECT); static CoglPipeline * clutter_colorize_effect_create_pipeline (ClutterOffscreenEffect *effect, CoglTexture *texture) { ClutterColorizeEffect *colorize_effect = CLUTTER_COLORIZE_EFFECT (effect); + ClutterColorizeEffectPrivate *priv = + clutter_colorize_effect_get_instance_private (colorize_effect); - cogl_pipeline_set_layer_texture (colorize_effect->pipeline, 0, texture); + cogl_pipeline_set_layer_texture (priv->pipeline, 0, texture); - return g_object_ref (colorize_effect->pipeline); + return g_object_ref (priv->pipeline); } static void clutter_colorize_effect_dispose (GObject *gobject) { ClutterColorizeEffect *self = CLUTTER_COLORIZE_EFFECT (gobject); + ClutterColorizeEffectPrivate *priv = + clutter_colorize_effect_get_instance_private (self); - g_clear_object (&self->pipeline); + g_clear_object (&priv->pipeline); G_OBJECT_CLASS (clutter_colorize_effect_parent_class)->dispose (gobject); } @@ -146,11 +138,13 @@ clutter_colorize_effect_get_property (GObject *gobject, GParamSpec *pspec) { ClutterColorizeEffect *effect = CLUTTER_COLORIZE_EFFECT (gobject); + ClutterColorizeEffectPrivate *priv = + clutter_colorize_effect_get_instance_private (effect); switch (prop_id) { case PROP_TINT: - clutter_value_set_color (value, &effect->tint); + clutter_value_set_color (value, &priv->tint); break; default: @@ -189,16 +183,18 @@ clutter_colorize_effect_class_init (ClutterColorizeEffectClass *klass) static void update_tint_uniform (ClutterColorizeEffect *self) { - if (self->tint_uniform > -1) + ClutterColorizeEffectPrivate *priv = + clutter_colorize_effect_get_instance_private (self); + if (priv->tint_uniform > -1) { float tint[3] = { - self->tint.red / 255.0, - self->tint.green / 255.0, - self->tint.blue / 255.0 + priv->tint.red / 255.0, + priv->tint.green / 255.0, + priv->tint.blue / 255.0 }; - cogl_pipeline_set_uniform_float (self->pipeline, - self->tint_uniform, + cogl_pipeline_set_uniform_float (priv->pipeline, + priv->tint_uniform, 3, /* n_components */ 1, /* count */ tint); @@ -209,7 +205,8 @@ static void clutter_colorize_effect_init (ClutterColorizeEffect *self) { ClutterColorizeEffectClass *klass = CLUTTER_COLORIZE_EFFECT_GET_CLASS (self); - + ClutterColorizeEffectPrivate *priv = + clutter_colorize_effect_get_instance_private (self); if (G_UNLIKELY (klass->base_pipeline == NULL)) { CoglSnippet *snippet; @@ -227,12 +224,12 @@ clutter_colorize_effect_init (ClutterColorizeEffect *self) cogl_pipeline_set_layer_null_texture (klass->base_pipeline, 0); } - self->pipeline = cogl_pipeline_copy (klass->base_pipeline); + priv->pipeline = cogl_pipeline_copy (klass->base_pipeline); - self->tint_uniform = - cogl_pipeline_get_uniform_location (self->pipeline, "tint"); + priv->tint_uniform = + cogl_pipeline_get_uniform_location (priv->pipeline, "tint"); - self->tint = default_tint; + priv->tint = default_tint; update_tint_uniform (self); } @@ -265,9 +262,12 @@ void clutter_colorize_effect_set_tint (ClutterColorizeEffect *effect, const ClutterColor *tint) { + ClutterColorizeEffectPrivate *priv; + g_return_if_fail (CLUTTER_IS_COLORIZE_EFFECT (effect)); - effect->tint = *tint; + priv = clutter_colorize_effect_get_instance_private (effect); + priv->tint = *tint; update_tint_uniform (effect); @@ -287,8 +287,11 @@ void clutter_colorize_effect_get_tint (ClutterColorizeEffect *effect, ClutterColor *tint) { + ClutterColorizeEffectPrivate *priv; + g_return_if_fail (CLUTTER_IS_COLORIZE_EFFECT (effect)); g_return_if_fail (tint != NULL); - *tint = effect->tint; + priv = clutter_colorize_effect_get_instance_private (effect); + *tint = priv->tint; } diff --git a/clutter/clutter/clutter-colorize-effect.h b/clutter/clutter/clutter-colorize-effect.h index de6dbe365..5f5f46aec 100644 --- a/clutter/clutter/clutter-colorize-effect.h +++ b/clutter/clutter/clutter-colorize-effect.h @@ -30,18 +30,24 @@ #include "clutter/clutter-color.h" #include "clutter/clutter-effect.h" +#include "clutter/clutter-offscreen-effect.h" G_BEGIN_DECLS #define CLUTTER_TYPE_COLORIZE_EFFECT (clutter_colorize_effect_get_type ()) -#define CLUTTER_COLORIZE_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_COLORIZE_EFFECT, ClutterColorizeEffect)) -#define CLUTTER_IS_COLORIZE_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_COLORIZE_EFFECT)) - -typedef struct _ClutterColorizeEffect ClutterColorizeEffect; -typedef struct _ClutterColorizeEffectClass ClutterColorizeEffectClass; CLUTTER_EXPORT -GType clutter_colorize_effect_get_type (void) G_GNUC_CONST; +G_DECLARE_DERIVABLE_TYPE (ClutterColorizeEffect, + clutter_colorize_effect, + CLUTTER, COLORIZE_EFFECT, + ClutterOffscreenEffect) + +struct _ClutterColorizeEffectClass +{ + ClutterOffscreenEffectClass parent_class; + + CoglPipeline *base_pipeline; +}; CLUTTER_EXPORT ClutterEffect *clutter_colorize_effect_new (const ClutterColor *tint);