From a06ad3a923035fb10cfd536069b3416fad234046 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Wed, 20 Feb 2019 11:27:00 -0300 Subject: [PATCH] Replace ClutterSize by graphene_size_t https://gitlab.gnome.org/GNOME/mutter/merge_requests/458 --- clutter/clutter/clutter-actor-private.h | 4 +- clutter/clutter/clutter-actor.c | 32 +++--- clutter/clutter/clutter-autocleanups.h | 1 - clutter/clutter/clutter-base-types.c | 129 +---------------------- clutter/clutter/clutter-graphene.c | 19 ++++ clutter/clutter/clutter-script-parser.c | 22 ++-- clutter/clutter/clutter-script-private.h | 2 +- clutter/clutter/clutter-types.h | 61 +---------- 8 files changed, 51 insertions(+), 219 deletions(-) diff --git a/clutter/clutter/clutter-actor-private.h b/clutter/clutter/clutter-actor-private.h index b8201eacd..6a267f3ed 100644 --- a/clutter/clutter/clutter-actor-private.h +++ b/clutter/clutter/clutter-actor-private.h @@ -173,8 +173,8 @@ struct _ClutterLayoutInfo guint x_expand : 1; guint y_expand : 1; - ClutterSize minimum; - ClutterSize natural; + graphene_size_t minimum; + graphene_size_t natural; }; const ClutterLayoutInfo * _clutter_actor_get_layout_info_or_defaults (ClutterActor *self); diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c index cd9571997..18a5b46d7 100644 --- a/clutter/clutter/clutter-actor.c +++ b/clutter/clutter/clutter-actor.c @@ -5077,7 +5077,7 @@ clutter_actor_set_property (GObject *object, case PROP_SIZE: { - const ClutterSize *size = g_value_get_boxed (value); + const graphene_size_t *size = g_value_get_boxed (value); if (size != NULL) clutter_actor_set_size (actor, size->width, size->height); @@ -5431,11 +5431,11 @@ clutter_actor_get_property (GObject *object, case PROP_SIZE: { - ClutterSize size; + graphene_size_t size; - clutter_size_init (&size, - clutter_actor_get_width (actor), - clutter_actor_get_height (actor)); + graphene_size_init (&size, + clutter_actor_get_width (actor), + clutter_actor_get_height (actor)); g_value_set_boxed (value, &size); } break; @@ -6476,7 +6476,7 @@ clutter_actor_class_init (ClutterActorClass *klass) g_param_spec_boxed ("size", P_("Size"), P_("The size of the actor"), - CLUTTER_TYPE_SIZE, + GRAPHENE_TYPE_SIZE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | CLUTTER_PARAM_ANIMATABLE); @@ -10730,8 +10730,8 @@ clutter_actor_set_height_internal (ClutterActor *self, } static void -clutter_actor_set_size_internal (ClutterActor *self, - const ClutterSize *size) +clutter_actor_set_size_internal (ClutterActor *self, + const graphene_size_t *size) { if (size != NULL) { @@ -10767,11 +10767,11 @@ clutter_actor_set_size (ClutterActor *self, gfloat width, gfloat height) { - ClutterSize new_size; + graphene_size_t new_size; g_return_if_fail (CLUTTER_IS_ACTOR (self)); - clutter_size_init (&new_size, width, height); + graphene_size_init (&new_size, width, height); /* minor optimization: if we don't have a duration then we can * skip the get_size() below, to avoid the chance of going through @@ -10790,11 +10790,11 @@ clutter_actor_set_size (ClutterActor *self, } else { - ClutterSize cur_size; + graphene_size_t cur_size; - clutter_size_init (&cur_size, - clutter_actor_get_width (self), - clutter_actor_get_height (self)); + graphene_size_init (&cur_size, + clutter_actor_get_width (self), + clutter_actor_get_height (self)); _clutter_actor_create_transition (self, obj_props[PROP_SIZE], @@ -18314,8 +18314,8 @@ static const ClutterLayoutInfo default_layout_info = { CLUTTER_ACTOR_ALIGN_FILL, /* x-align */ CLUTTER_ACTOR_ALIGN_FILL, /* y-align */ FALSE, FALSE, /* expand */ - CLUTTER_SIZE_INIT_ZERO, /* minimum */ - CLUTTER_SIZE_INIT_ZERO, /* natural */ + GRAPHENE_SIZE_INIT_ZERO, /* minimum */ + GRAPHENE_SIZE_INIT_ZERO, /* natural */ }; static void diff --git a/clutter/clutter/clutter-autocleanups.h b/clutter/clutter/clutter-autocleanups.h index 25d8cc615..58925e7c6 100644 --- a/clutter/clutter/clutter-autocleanups.h +++ b/clutter/clutter/clutter-autocleanups.h @@ -96,7 +96,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPaintVolume, clutter_paint_volume_free) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPathNode, clutter_path_node_free) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPoint, clutter_point_free) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterRect, clutter_rect_free) -G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterSize, clutter_size_free) #endif /* __GI_SCANNER__ */ diff --git a/clutter/clutter/clutter-base-types.c b/clutter/clutter/clutter-base-types.c index 2790339d2..1d873ccda 100644 --- a/clutter/clutter/clutter-base-types.c +++ b/clutter/clutter/clutter-base-types.c @@ -400,133 +400,6 @@ G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterPoint, clutter_point, -/* - * ClutterSize - */ - -/** - * clutter_size_alloc: (constructor) - * - * Allocates a new #ClutterSize. - * - * Return value: (transfer full): the newly allocated #ClutterSize. - * Use clutter_size_free() to free its resources. - * - * Since: 1.12 - */ -ClutterSize * -clutter_size_alloc (void) -{ - return g_slice_new0 (ClutterSize); -} - -/** - * clutter_size_init: - * @size: a #ClutterSize - * @width: the width - * @height: the height - * - * Initializes a #ClutterSize with the given dimensions. - * - * Return value: (transfer none): the initialized #ClutterSize - * - * Since: 1.12 - */ -ClutterSize * -clutter_size_init (ClutterSize *size, - float width, - float height) -{ - g_return_val_if_fail (size != NULL, NULL); - - size->width = width; - size->height = height; - - return size; -} - -/** - * clutter_size_copy: - * @size: a #ClutterSize - * - * Creates a new #ClutterSize and duplicates @size. - * - * Return value: (transfer full): the newly allocated #ClutterSize. - * Use clutter_size_free() to free its resources. - * - * Since: 1.12 - */ -ClutterSize * -clutter_size_copy (const ClutterSize *size) -{ - return g_slice_dup (ClutterSize, size); -} - -/** - * clutter_size_free: - * @size: a #ClutterSize - * - * Frees the resources allocated for @size. - * - * Since: 1.12 - */ -void -clutter_size_free (ClutterSize *size) -{ - if (size != NULL) - g_slice_free (ClutterSize, size); -} - -/** - * clutter_size_equals: - * @a: a #ClutterSize to compare - * @b: a #ClutterSize to compare - * - * Compares two #ClutterSize for equality. - * - * Return value: %TRUE if the two #ClutterSize are equal - * - * Since: 1.12 - */ -gboolean -clutter_size_equals (const ClutterSize *a, - const ClutterSize *b) -{ - if (a == b) - return TRUE; - - if (a == NULL || b == NULL) - return FALSE; - - return fabsf (a->width - b->width) < FLOAT_EPSILON && - fabsf (a->height - b->height) < FLOAT_EPSILON; -} - -static gboolean -clutter_size_progress (const GValue *a, - const GValue *b, - gdouble progress, - GValue *retval) -{ - const ClutterSize *as = g_value_get_boxed (a); - const ClutterSize *bs = g_value_get_boxed (b); - ClutterSize res = CLUTTER_SIZE_INIT (0, 0); - - res.width = as->width + (bs->width - as->width) * progress; - res.height = as->height + (bs->height - as->height) * progress; - - g_value_set_boxed (retval, &res); - - return TRUE; -} - -G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterSize, clutter_size, - clutter_size_copy, - clutter_size_free, - CLUTTER_REGISTER_INTERVAL_PROGRESS (clutter_size_progress)) - - - /* * ClutterRect */ @@ -711,7 +584,7 @@ clutter_rect_equals (ClutterRect *a, clutter_rect_normalize_internal (b); return clutter_point_equals (&a->origin, &b->origin) && - clutter_size_equals (&a->size, &b->size); + graphene_size_equal (&a->size, &b->size); } /** diff --git a/clutter/clutter/clutter-graphene.c b/clutter/clutter/clutter-graphene.c index b09e544b0..590e320ed 100644 --- a/clutter/clutter/clutter-graphene.c +++ b/clutter/clutter/clutter-graphene.c @@ -43,9 +43,28 @@ graphene_point3d_progress (const GValue *a, return TRUE; } +static gboolean +graphene_size_progress (const GValue *a, + const GValue *b, + gdouble progress, + GValue *retval) +{ + const graphene_size_t *as = g_value_get_boxed (a); + const graphene_size_t *bs = g_value_get_boxed (b); + graphene_size_t res; + + graphene_size_interpolate (as, bs, progress, &res); + + g_value_set_boxed (retval, &res); + + return TRUE; +} + void clutter_graphene_init (void) { clutter_interval_register_progress_func (GRAPHENE_TYPE_POINT3D, graphene_point3d_progress); + clutter_interval_register_progress_func (GRAPHENE_TYPE_SIZE, + graphene_size_progress); } diff --git a/clutter/clutter/clutter-script-parser.c b/clutter/clutter/clutter-script-parser.c index 55e70dac9..8e9ac9639 100644 --- a/clutter/clutter/clutter-script-parser.c +++ b/clutter/clutter/clutter-script-parser.c @@ -546,8 +546,8 @@ _clutter_script_parse_point (ClutterScript *script, } static gboolean -parse_size_from_array (JsonArray *array, - ClutterSize *size) +parse_size_from_array (JsonArray *array, + graphene_size_t *size) { if (json_array_get_length (array) != 2) return FALSE; @@ -559,8 +559,8 @@ parse_size_from_array (JsonArray *array, } static gboolean -parse_size_from_object (JsonObject *object, - ClutterSize *size) +parse_size_from_object (JsonObject *object, + graphene_size_t *size) { if (json_object_has_member (object, "width")) size->width = json_object_get_double_member (object, "width"); @@ -576,9 +576,9 @@ parse_size_from_object (JsonObject *object, } gboolean -_clutter_script_parse_size (ClutterScript *script, - JsonNode *node, - ClutterSize *size) +_clutter_script_parse_size (ClutterScript *script, + JsonNode *node, + graphene_size_t *size) { g_return_val_if_fail (CLUTTER_IS_SCRIPT (script), FALSE); g_return_val_if_fail (node != NULL, FALSE); @@ -1374,9 +1374,9 @@ _clutter_script_parse_node (ClutterScript *script, return TRUE; } } - else if (p_type == CLUTTER_TYPE_SIZE) + else if (p_type == GRAPHENE_TYPE_SIZE) { - ClutterSize size = CLUTTER_SIZE_INIT_ZERO; + graphene_size_t size = GRAPHENE_SIZE_INIT_ZERO; if (_clutter_script_parse_size (script, node, &size)) { @@ -1451,9 +1451,9 @@ _clutter_script_parse_node (ClutterScript *script, return TRUE; } } - else if (G_VALUE_HOLDS (value, CLUTTER_TYPE_SIZE)) + else if (G_VALUE_HOLDS (value, GRAPHENE_TYPE_SIZE)) { - ClutterSize size = CLUTTER_SIZE_INIT_ZERO; + graphene_size_t size = GRAPHENE_SIZE_INIT_ZERO; if (_clutter_script_parse_size (script, node, &size)) { diff --git a/clutter/clutter/clutter-script-private.h b/clutter/clutter/clutter-script-private.h index 52a67bcdc..61276d359 100644 --- a/clutter/clutter/clutter-script-private.h +++ b/clutter/clutter/clutter-script-private.h @@ -135,7 +135,7 @@ gboolean _clutter_script_parse_point (ClutterScript *script, ClutterPoint *point); gboolean _clutter_script_parse_size (ClutterScript *script, JsonNode *node, - ClutterSize *size); + graphene_size_t *size); gboolean _clutter_script_parse_translatable_string (ClutterScript *script, JsonNode *node, diff --git a/clutter/clutter/clutter-types.h b/clutter/clutter/clutter-types.h index 1ed6eba77..5ccc2b7da 100644 --- a/clutter/clutter/clutter-types.h +++ b/clutter/clutter/clutter-types.h @@ -45,7 +45,6 @@ G_BEGIN_DECLS #define CLUTTER_TYPE_PAINT_VOLUME (clutter_paint_volume_get_type ()) #define CLUTTER_TYPE_PERSPECTIVE (clutter_perspective_get_type ()) #define CLUTTER_TYPE_POINT (clutter_point_get_type ()) -#define CLUTTER_TYPE_SIZE (clutter_size_get_type ()) #define CLUTTER_TYPE_RECT (clutter_rect_get_type ()) typedef struct _ClutterActor ClutterActor; @@ -85,7 +84,6 @@ typedef struct _ClutterMargin ClutterMargin; typedef struct _ClutterPerspective ClutterPerspective; typedef struct _ClutterPoint ClutterPoint; typedef struct _ClutterRect ClutterRect; -typedef struct _ClutterSize ClutterSize; typedef struct _ClutterAlpha ClutterAlpha; typedef struct _ClutterAnimation ClutterAnimation; @@ -199,63 +197,6 @@ float clutter_point_distance (const ClutterPoint *a, float *x_distance, float *y_distance); -/** - * ClutterSize: - * @width: the width, in pixels - * @height: the height, in pixels - * - * A size, in 2D space. - * - * Since: 1.12 - */ -struct _ClutterSize -{ - float width; - float height; -}; - -/** - * CLUTTER_SIZE_INIT: - * @width: the width - * @height: the height - * - * A simple macro for initializing a #ClutterSize when declaring it, e.g.: - * - * |[ - * ClutterSize s = CLUTTER_SIZE_INIT (200, 200); - * ]| - * - * Since: 1.12 - */ -#define CLUTTER_SIZE_INIT(width,height) { (width), (height) } - -/** - * CLUTTER_SIZE_INIT_ZERO: - * - * A simple macro for initializing a #ClutterSize to (0, 0) when - * declaring it. - * - * Since: 1.12 - */ -#define CLUTTER_SIZE_INIT_ZERO CLUTTER_SIZE_INIT (0.f, 0.f) - -CLUTTER_EXPORT -GType clutter_size_get_type (void) G_GNUC_CONST; - -CLUTTER_EXPORT -ClutterSize * clutter_size_alloc (void); -CLUTTER_EXPORT -ClutterSize * clutter_size_init (ClutterSize *size, - float width, - float height); -CLUTTER_EXPORT -ClutterSize * clutter_size_copy (const ClutterSize *size); -CLUTTER_EXPORT -void clutter_size_free (ClutterSize *size); -CLUTTER_EXPORT -gboolean clutter_size_equals (const ClutterSize *a, - const ClutterSize *b); - /** * ClutterRect: * @origin: the origin of the rectangle @@ -280,7 +221,7 @@ gboolean clutter_size_equals (const ClutterSize *a, struct _ClutterRect { ClutterPoint origin; - ClutterSize size; + graphene_size_t size; }; /**