colorize-effect: Use macros for subclassing boilerplate
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3387>
This commit is contained in:
parent
99501482df
commit
7b32f06f44
@ -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 (ClutterBoxLayout, g_object_unref)
|
||||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterBrightnessContrastEffect, 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 (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 (ClutterDeformEffect, g_object_unref)
|
||||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterDesaturateEffect, g_object_unref)
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterDesaturateEffect, g_object_unref)
|
||||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterFixedLayout, g_object_unref)
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterFixedLayout, g_object_unref)
|
||||||
|
@ -31,10 +31,6 @@
|
|||||||
* colorizes an actor with the given tint.
|
* 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 "config.h"
|
||||||
|
|
||||||
#include "clutter/clutter-colorize-effect.h"
|
#include "clutter/clutter-colorize-effect.h"
|
||||||
@ -43,10 +39,9 @@
|
|||||||
|
|
||||||
#include "clutter/clutter-debug.h"
|
#include "clutter/clutter-debug.h"
|
||||||
#include "clutter/clutter-enum-types.h"
|
#include "clutter/clutter-enum-types.h"
|
||||||
#include "clutter/clutter-offscreen-effect.h"
|
|
||||||
#include "clutter/clutter-private.h"
|
#include "clutter/clutter-private.h"
|
||||||
|
|
||||||
struct _ClutterColorizeEffect
|
typedef struct _ClutterColorizeEffectPrivate
|
||||||
{
|
{
|
||||||
ClutterOffscreenEffect parent_instance;
|
ClutterOffscreenEffect parent_instance;
|
||||||
|
|
||||||
@ -56,14 +51,7 @@ struct _ClutterColorizeEffect
|
|||||||
gint tint_uniform;
|
gint tint_uniform;
|
||||||
|
|
||||||
CoglPipeline *pipeline;
|
CoglPipeline *pipeline;
|
||||||
};
|
} ClutterColorizeEffectPrivate;
|
||||||
|
|
||||||
struct _ClutterColorizeEffectClass
|
|
||||||
{
|
|
||||||
ClutterOffscreenEffectClass parent_class;
|
|
||||||
|
|
||||||
CoglPipeline *base_pipeline;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* the magic gray vec3 has been taken from the NTSC conversion weights
|
/* the magic gray vec3 has been taken from the NTSC conversion weights
|
||||||
* as defined by:
|
* as defined by:
|
||||||
@ -93,27 +81,31 @@ enum
|
|||||||
|
|
||||||
static GParamSpec *obj_props[PROP_LAST];
|
static GParamSpec *obj_props[PROP_LAST];
|
||||||
|
|
||||||
G_DEFINE_TYPE (ClutterColorizeEffect,
|
G_DEFINE_TYPE_WITH_PRIVATE (ClutterColorizeEffect,
|
||||||
clutter_colorize_effect,
|
clutter_colorize_effect,
|
||||||
CLUTTER_TYPE_OFFSCREEN_EFFECT);
|
CLUTTER_TYPE_OFFSCREEN_EFFECT);
|
||||||
|
|
||||||
static CoglPipeline *
|
static CoglPipeline *
|
||||||
clutter_colorize_effect_create_pipeline (ClutterOffscreenEffect *effect,
|
clutter_colorize_effect_create_pipeline (ClutterOffscreenEffect *effect,
|
||||||
CoglTexture *texture)
|
CoglTexture *texture)
|
||||||
{
|
{
|
||||||
ClutterColorizeEffect *colorize_effect = CLUTTER_COLORIZE_EFFECT (effect);
|
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
|
static void
|
||||||
clutter_colorize_effect_dispose (GObject *gobject)
|
clutter_colorize_effect_dispose (GObject *gobject)
|
||||||
{
|
{
|
||||||
ClutterColorizeEffect *self = CLUTTER_COLORIZE_EFFECT (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);
|
G_OBJECT_CLASS (clutter_colorize_effect_parent_class)->dispose (gobject);
|
||||||
}
|
}
|
||||||
@ -146,11 +138,13 @@ clutter_colorize_effect_get_property (GObject *gobject,
|
|||||||
GParamSpec *pspec)
|
GParamSpec *pspec)
|
||||||
{
|
{
|
||||||
ClutterColorizeEffect *effect = CLUTTER_COLORIZE_EFFECT (gobject);
|
ClutterColorizeEffect *effect = CLUTTER_COLORIZE_EFFECT (gobject);
|
||||||
|
ClutterColorizeEffectPrivate *priv =
|
||||||
|
clutter_colorize_effect_get_instance_private (effect);
|
||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
case PROP_TINT:
|
case PROP_TINT:
|
||||||
clutter_value_set_color (value, &effect->tint);
|
clutter_value_set_color (value, &priv->tint);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -189,16 +183,18 @@ clutter_colorize_effect_class_init (ClutterColorizeEffectClass *klass)
|
|||||||
static void
|
static void
|
||||||
update_tint_uniform (ClutterColorizeEffect *self)
|
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] = {
|
float tint[3] = {
|
||||||
self->tint.red / 255.0,
|
priv->tint.red / 255.0,
|
||||||
self->tint.green / 255.0,
|
priv->tint.green / 255.0,
|
||||||
self->tint.blue / 255.0
|
priv->tint.blue / 255.0
|
||||||
};
|
};
|
||||||
|
|
||||||
cogl_pipeline_set_uniform_float (self->pipeline,
|
cogl_pipeline_set_uniform_float (priv->pipeline,
|
||||||
self->tint_uniform,
|
priv->tint_uniform,
|
||||||
3, /* n_components */
|
3, /* n_components */
|
||||||
1, /* count */
|
1, /* count */
|
||||||
tint);
|
tint);
|
||||||
@ -209,7 +205,8 @@ static void
|
|||||||
clutter_colorize_effect_init (ClutterColorizeEffect *self)
|
clutter_colorize_effect_init (ClutterColorizeEffect *self)
|
||||||
{
|
{
|
||||||
ClutterColorizeEffectClass *klass = CLUTTER_COLORIZE_EFFECT_GET_CLASS (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))
|
if (G_UNLIKELY (klass->base_pipeline == NULL))
|
||||||
{
|
{
|
||||||
CoglSnippet *snippet;
|
CoglSnippet *snippet;
|
||||||
@ -227,12 +224,12 @@ clutter_colorize_effect_init (ClutterColorizeEffect *self)
|
|||||||
cogl_pipeline_set_layer_null_texture (klass->base_pipeline, 0);
|
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 =
|
priv->tint_uniform =
|
||||||
cogl_pipeline_get_uniform_location (self->pipeline, "tint");
|
cogl_pipeline_get_uniform_location (priv->pipeline, "tint");
|
||||||
|
|
||||||
self->tint = default_tint;
|
priv->tint = default_tint;
|
||||||
|
|
||||||
update_tint_uniform (self);
|
update_tint_uniform (self);
|
||||||
}
|
}
|
||||||
@ -265,9 +262,12 @@ void
|
|||||||
clutter_colorize_effect_set_tint (ClutterColorizeEffect *effect,
|
clutter_colorize_effect_set_tint (ClutterColorizeEffect *effect,
|
||||||
const ClutterColor *tint)
|
const ClutterColor *tint)
|
||||||
{
|
{
|
||||||
|
ClutterColorizeEffectPrivate *priv;
|
||||||
|
|
||||||
g_return_if_fail (CLUTTER_IS_COLORIZE_EFFECT (effect));
|
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);
|
update_tint_uniform (effect);
|
||||||
|
|
||||||
@ -287,8 +287,11 @@ void
|
|||||||
clutter_colorize_effect_get_tint (ClutterColorizeEffect *effect,
|
clutter_colorize_effect_get_tint (ClutterColorizeEffect *effect,
|
||||||
ClutterColor *tint)
|
ClutterColor *tint)
|
||||||
{
|
{
|
||||||
|
ClutterColorizeEffectPrivate *priv;
|
||||||
|
|
||||||
g_return_if_fail (CLUTTER_IS_COLORIZE_EFFECT (effect));
|
g_return_if_fail (CLUTTER_IS_COLORIZE_EFFECT (effect));
|
||||||
g_return_if_fail (tint != NULL);
|
g_return_if_fail (tint != NULL);
|
||||||
|
|
||||||
*tint = effect->tint;
|
priv = clutter_colorize_effect_get_instance_private (effect);
|
||||||
|
*tint = priv->tint;
|
||||||
}
|
}
|
||||||
|
@ -30,18 +30,24 @@
|
|||||||
|
|
||||||
#include "clutter/clutter-color.h"
|
#include "clutter/clutter-color.h"
|
||||||
#include "clutter/clutter-effect.h"
|
#include "clutter/clutter-effect.h"
|
||||||
|
#include "clutter/clutter-offscreen-effect.h"
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define CLUTTER_TYPE_COLORIZE_EFFECT (clutter_colorize_effect_get_type ())
|
#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
|
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
|
CLUTTER_EXPORT
|
||||||
ClutterEffect *clutter_colorize_effect_new (const ClutterColor *tint);
|
ClutterEffect *clutter_colorize_effect_new (const ClutterColor *tint);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user