blur-effect: Use macros for subclassing boilerplate
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3387>
This commit is contained in:
parent
9bd12d7e88
commit
764c3ef602
@ -31,7 +31,6 @@
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterActor, g_object_unref)
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterBackend, g_object_unref)
|
||||
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)
|
||||
|
@ -24,17 +24,12 @@
|
||||
|
||||
/**
|
||||
* ClutterBlurEffect:
|
||||
*
|
||||
*
|
||||
* A blur effect
|
||||
*
|
||||
* #ClutterBlurEffect is a sub-class of #ClutterEffect that allows blurring a
|
||||
* actor and its contents.
|
||||
*/
|
||||
|
||||
#define CLUTTER_BLUR_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_BLUR_EFFECT, ClutterBlurEffectClass))
|
||||
#define CLUTTER_IS_BLUR_EFFECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_BLUR_EFFECT))
|
||||
#define CLUTTER_BLUR_EFFECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_BLUR_EFFECT, ClutterBlurEffectClass))
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "clutter/clutter-blur-effect.h"
|
||||
@ -42,7 +37,6 @@
|
||||
#include "cogl/cogl.h"
|
||||
|
||||
#include "clutter/clutter-debug.h"
|
||||
#include "clutter/clutter-offscreen-effect.h"
|
||||
#include "clutter/clutter-private.h"
|
||||
|
||||
#define BLUR_PADDING 2
|
||||
@ -68,36 +62,30 @@ static const gchar *box_blur_glsl_shader =
|
||||
" cogl_texel /= 9.0;\n";
|
||||
#undef SAMPLE
|
||||
|
||||
struct _ClutterBlurEffect
|
||||
typedef struct _ClutterBlurEffectPrivate
|
||||
{
|
||||
ClutterOffscreenEffect parent_instance;
|
||||
|
||||
/* a back pointer to our actor, so that we can query it */
|
||||
ClutterActor *actor;
|
||||
|
||||
gint pixel_step_uniform;
|
||||
|
||||
CoglPipeline *pipeline;
|
||||
};
|
||||
} ClutterBlurEffectPrivate;
|
||||
|
||||
struct _ClutterBlurEffectClass
|
||||
{
|
||||
ClutterOffscreenEffectClass parent_class;
|
||||
|
||||
CoglPipeline *base_pipeline;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (ClutterBlurEffect,
|
||||
clutter_blur_effect,
|
||||
CLUTTER_TYPE_OFFSCREEN_EFFECT);
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (ClutterBlurEffect,
|
||||
clutter_blur_effect,
|
||||
CLUTTER_TYPE_OFFSCREEN_EFFECT);
|
||||
|
||||
static CoglPipeline *
|
||||
clutter_blur_effect_create_pipeline (ClutterOffscreenEffect *effect,
|
||||
CoglTexture *texture)
|
||||
{
|
||||
ClutterBlurEffect *blur_effect = CLUTTER_BLUR_EFFECT (effect);
|
||||
ClutterBlurEffectPrivate *priv =
|
||||
clutter_blur_effect_get_instance_private (blur_effect);
|
||||
|
||||
if (blur_effect->pixel_step_uniform > -1)
|
||||
if (priv->pixel_step_uniform > -1)
|
||||
{
|
||||
float pixel_step[2];
|
||||
int tex_width, tex_height;
|
||||
@ -108,16 +96,16 @@ clutter_blur_effect_create_pipeline (ClutterOffscreenEffect *effect,
|
||||
pixel_step[0] = 1.0f / tex_width;
|
||||
pixel_step[1] = 1.0f / tex_height;
|
||||
|
||||
cogl_pipeline_set_uniform_float (blur_effect->pipeline,
|
||||
blur_effect->pixel_step_uniform,
|
||||
cogl_pipeline_set_uniform_float (priv->pipeline,
|
||||
priv->pixel_step_uniform,
|
||||
2, /* n_components */
|
||||
1, /* count */
|
||||
pixel_step);
|
||||
}
|
||||
|
||||
cogl_pipeline_set_layer_texture (blur_effect->pipeline, 0, texture);
|
||||
cogl_pipeline_set_layer_texture (priv->pipeline, 0, texture);
|
||||
|
||||
return g_object_ref (blur_effect->pipeline);
|
||||
return g_object_ref (priv->pipeline);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -146,8 +134,10 @@ static void
|
||||
clutter_blur_effect_dispose (GObject *gobject)
|
||||
{
|
||||
ClutterBlurEffect *self = CLUTTER_BLUR_EFFECT (gobject);
|
||||
ClutterBlurEffectPrivate *priv =
|
||||
clutter_blur_effect_get_instance_private (self);
|
||||
|
||||
g_clear_object (&self->pipeline);
|
||||
g_clear_object (&priv->pipeline);
|
||||
|
||||
G_OBJECT_CLASS (clutter_blur_effect_parent_class)->dispose (gobject);
|
||||
}
|
||||
@ -171,6 +161,8 @@ static void
|
||||
clutter_blur_effect_init (ClutterBlurEffect *self)
|
||||
{
|
||||
ClutterBlurEffectClass *klass = CLUTTER_BLUR_EFFECT_GET_CLASS (self);
|
||||
ClutterBlurEffectPrivate *priv =
|
||||
clutter_blur_effect_get_instance_private (self);
|
||||
|
||||
if (G_UNLIKELY (klass->base_pipeline == NULL))
|
||||
{
|
||||
@ -190,10 +182,10 @@ clutter_blur_effect_init (ClutterBlurEffect *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->pixel_step_uniform =
|
||||
cogl_pipeline_get_uniform_location (self->pipeline, "pixel_step");
|
||||
priv->pixel_step_uniform =
|
||||
cogl_pipeline_get_uniform_location (priv->pipeline, "pixel_step");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,18 +29,24 @@
|
||||
#endif
|
||||
|
||||
#include "clutter/clutter-effect.h"
|
||||
#include "clutter/clutter-offscreen-effect.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define CLUTTER_TYPE_BLUR_EFFECT (clutter_blur_effect_get_type ())
|
||||
#define CLUTTER_BLUR_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_BLUR_EFFECT, ClutterBlurEffect))
|
||||
#define CLUTTER_IS_BLUR_EFFECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_BLUR_EFFECT))
|
||||
|
||||
typedef struct _ClutterBlurEffect ClutterBlurEffect;
|
||||
typedef struct _ClutterBlurEffectClass ClutterBlurEffectClass;
|
||||
|
||||
CLUTTER_EXPORT
|
||||
GType clutter_blur_effect_get_type (void) G_GNUC_CONST;
|
||||
G_DECLARE_DERIVABLE_TYPE (ClutterBlurEffect,
|
||||
clutter_blur_effect,
|
||||
CLUTTER, BLUR_EFFECT,
|
||||
ClutterOffscreenEffect)
|
||||
|
||||
struct _ClutterBlurEffectClass
|
||||
{
|
||||
ClutterOffscreenEffectClass parent_class;
|
||||
|
||||
CoglPipeline *base_pipeline;
|
||||
};
|
||||
|
||||
CLUTTER_EXPORT
|
||||
ClutterEffect *clutter_blur_effect_new (void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user