[mutter] clutter/image: Port to G_DECLARE_DERIVABLE_TYPE



commit a2c999b6b1d9638cc652f131862deee632dabad6
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Mar 31 12:56:53 2022 -0300

    clutter/image: Port to G_DECLARE_DERIVABLE_TYPE
    
    Cleanup all the boilerplate, and port the function to use the auto
    generated private helper. Remove the manual autocleanup declaration
    since this is now done in the clutter-image.h header.
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2355>

 clutter/clutter/clutter-autocleanups.h |  1 -
 clutter/clutter/clutter-image.c        | 40 +++++++++++++++++++---------------
 clutter/clutter/clutter-image.h        | 32 +++------------------------
 3 files changed, 26 insertions(+), 47 deletions(-)
---
diff --git a/clutter/clutter/clutter-autocleanups.h b/clutter/clutter/clutter-autocleanups.h
index 1d5af5ef87..9c44f0d23c 100644
--- a/clutter/clutter/clutter-autocleanups.h
+++ b/clutter/clutter/clutter-autocleanups.h
@@ -51,7 +51,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterEffect, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterFixedLayout, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterFlowLayout, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterGridLayout, g_object_unref)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterImage, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterInputDevice, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterInterval, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterKeyframeTransition, g_object_unref)
diff --git a/clutter/clutter/clutter-image.c b/clutter/clutter/clutter-image.c
index 2ca059fcb3..9ebf7c96ad 100644
--- a/clutter/clutter/clutter-image.c
+++ b/clutter/clutter/clutter-image.c
@@ -48,12 +48,12 @@
 #include "clutter-paint-nodes.h"
 #include "clutter-private.h"
 
-struct _ClutterImagePrivate
+typedef struct
 {
   CoglTexture *texture;
   gint width;
   gint height;
-};
+} ClutterImagePrivate;
 
 static void clutter_content_iface_init (ClutterContentInterface *iface);
 
@@ -88,20 +88,21 @@ create_texture_from_data (unsigned int      width,
 static void
 update_image_size (ClutterImage *self)
 {
+  ClutterImagePrivate *priv = clutter_image_get_instance_private (self);
   gint width, height;
 
-  if (self->priv->texture == NULL)
+  if (priv->texture == NULL)
     return;
 
-  width = cogl_texture_get_width (self->priv->texture);
-  height = cogl_texture_get_height (self->priv->texture);
+  width = cogl_texture_get_width (priv->texture);
+  height = cogl_texture_get_height (priv->texture);
 
-  if (self->priv->width == width &&
-      self->priv->height == height)
+  if (priv->width == width &&
+      priv->height == height)
     return;
 
-  self->priv->width = width;
-  self->priv->height = height;
+  priv->width = width;
+  priv->height = height;
 
   clutter_content_invalidate_size (CLUTTER_CONTENT (self));
 }
@@ -109,7 +110,8 @@ update_image_size (ClutterImage *self)
 static void
 clutter_image_finalize (GObject *gobject)
 {
-  ClutterImagePrivate *priv = CLUTTER_IMAGE (gobject)->priv;
+  ClutterImage *image = CLUTTER_IMAGE (gobject);
+  ClutterImagePrivate *priv = clutter_image_get_instance_private (image);
 
   if (priv->texture != NULL)
     {
@@ -129,7 +131,6 @@ clutter_image_class_init (ClutterImageClass *klass)
 static void
 clutter_image_init (ClutterImage *self)
 {
-  self->priv = clutter_image_get_instance_private (self);
 }
 
 static void
@@ -138,7 +139,8 @@ clutter_image_paint_content (ClutterContent      *content,
                              ClutterPaintNode    *root,
                              ClutterPaintContext *paint_context)
 {
-  ClutterImagePrivate *priv = CLUTTER_IMAGE (content)->priv;
+  ClutterImage *image = CLUTTER_IMAGE (content);
+  ClutterImagePrivate *priv = clutter_image_get_instance_private (image);
   ClutterPaintNode *node;
 
   if (priv->texture == NULL)
@@ -155,7 +157,8 @@ clutter_image_get_preferred_size (ClutterContent *content,
                                   gfloat         *width,
                                   gfloat         *height)
 {
-  ClutterImagePrivate *priv = CLUTTER_IMAGE (content)->priv;
+  ClutterImage *image = CLUTTER_IMAGE (content);
+  ClutterImagePrivate *priv = clutter_image_get_instance_private (image);
 
   if (priv->texture == NULL)
     return FALSE;
@@ -252,7 +255,7 @@ clutter_image_set_data (ClutterImage     *image,
   g_return_val_if_fail (CLUTTER_IS_IMAGE (image), FALSE);
   g_return_val_if_fail (data != NULL, FALSE);
 
-  priv = image->priv;
+  priv = clutter_image_get_instance_private (image);
 
   if (priv->texture != NULL)
     cogl_object_unref (priv->texture);
@@ -312,7 +315,7 @@ clutter_image_set_bytes (ClutterImage     *image,
   g_return_val_if_fail (CLUTTER_IS_IMAGE (image), FALSE);
   g_return_val_if_fail (data != NULL, FALSE);
 
-  priv = image->priv;
+  priv = clutter_image_get_instance_private (image);
 
   if (priv->texture != NULL)
     cogl_object_unref (priv->texture);
@@ -376,7 +379,7 @@ clutter_image_set_area (ClutterImage                 *image,
   g_return_val_if_fail (data != NULL, FALSE);
   g_return_val_if_fail (area != NULL, FALSE);
 
-  priv = image->priv;
+  priv = clutter_image_get_instance_private (image);
 
   if (priv->texture == NULL)
     {
@@ -434,7 +437,10 @@ clutter_image_set_area (ClutterImage                 *image,
 CoglTexture *
 clutter_image_get_texture (ClutterImage *image)
 {
+  ClutterImagePrivate *priv;
+
   g_return_val_if_fail (CLUTTER_IS_IMAGE (image), NULL);
 
-  return image->priv->texture;
+  priv = clutter_image_get_instance_private (image);
+  return priv->texture;
 }
diff --git a/clutter/clutter/clutter-image.h b/clutter/clutter/clutter-image.h
index b220a49f84..c54f8bb914 100644
--- a/clutter/clutter/clutter-image.h
+++ b/clutter/clutter/clutter-image.h
@@ -34,33 +34,10 @@
 
 G_BEGIN_DECLS
 
-#define CLUTTER_TYPE_IMAGE              (clutter_image_get_type ())
-#define CLUTTER_IMAGE(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_IMAGE, 
ClutterImage))
-#define CLUTTER_IS_IMAGE(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_IMAGE))
-#define CLUTTER_IMAGE_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_IMAGE, 
ClutterImageClass))
-#define CLUTTER_IS_IMAGE_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_IMAGE))
-#define CLUTTER_IMAGE_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_IMAGE, 
ClutterImageClass))
+#define CLUTTER_TYPE_IMAGE (clutter_image_get_type ())
 
-typedef struct _ClutterImage           ClutterImage;
-typedef struct _ClutterImagePrivate    ClutterImagePrivate;
-typedef struct _ClutterImageClass      ClutterImageClass;
-
-/**
- * ClutterImage:
- *
- * The #ClutterImage structure contains
- * private data and should only be accessed using the provided
- * API.
- *
- * Since: 1.10
- */
-struct _ClutterImage
-{
-  /*< private >*/
-  GObject parent_instance;
-
-  ClutterImagePrivate *priv;
-};
+CLUTTER_EXPORT
+G_DECLARE_DERIVABLE_TYPE (ClutterImage, clutter_image, CLUTTER, IMAGE, GObject)
 
 /**
  * ClutterImageClass:
@@ -78,9 +55,6 @@ struct _ClutterImageClass
   gpointer _padding[16];
 };
 
-CLUTTER_EXPORT
-GType clutter_image_get_type (void) G_GNUC_CONST;
-
 CLUTTER_EXPORT
 ClutterContent *        clutter_image_new               (void);
 CLUTTER_EXPORT


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]