[mutter] clutter/actor: Always return a resource scale in get_resource_scale()
- From: Jonas Ådahl <jadahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter] clutter/actor: Always return a resource scale in get_resource_scale()
- Date: Tue, 30 Jun 2020 13:41:13 +0000 (UTC)
commit 98df2dbd0564dadc74ea8ead1be575821229dc0d
Author: Jonas Dreßler <verdre v0yd nl>
Date: Fri Apr 10 11:41:58 2020 +0200
clutter/actor: Always return a resource scale in get_resource_scale()
Since we now always return a resource scale, we can remove the boolean
return value from clutter_actor_get_resource_scale() and
_clutter_actor_get_real_resource_scale(), and instead simply return the
scale.
While at it, also remove the underscore from the
_clutter_actor_get_real_resource_scale() private API.
https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1276
clutter/clutter/clutter-actor-private.h | 3 +--
clutter/clutter/clutter-actor.c | 36 +++++++++---------------------
clutter/clutter/clutter-actor.h | 3 +--
clutter/clutter/clutter-offscreen-effect.c | 25 +++++++++------------
clutter/clutter/clutter-stage.c | 4 +---
clutter/clutter/clutter-text.c | 25 +++++++--------------
src/compositor/meta-window-actor.c | 6 ++---
src/tests/clutter/conform/text.c | 3 +--
8 files changed, 35 insertions(+), 70 deletions(-)
---
diff --git a/clutter/clutter/clutter-actor-private.h b/clutter/clutter/clutter-actor-private.h
index 3269f66ad4..d1adcd38f0 100644
--- a/clutter/clutter/clutter-actor-private.h
+++ b/clutter/clutter/clutter-actor-private.h
@@ -283,8 +283,7 @@ void _clutter_actor_queue_relayout_on_clones
void _clutter_actor_queue_only_relayout (ClutterActor
*actor);
void clutter_actor_clear_stage_views_recursive (ClutterActor
*actor);
-gboolean _clutter_actor_get_real_resource_scale (ClutterActor *actor,
- float
*resource_scale);
+float clutter_actor_get_real_resource_scale (ClutterActor
*actor);
ClutterPaintNode * clutter_actor_create_texture_paint_node (ClutterActor *self,
CoglTexture
*texture);
diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c
index a31b48fa13..e6a9631399 100644
--- a/clutter/clutter/clutter-actor.c
+++ b/clutter/clutter/clutter-actor.c
@@ -15968,18 +15968,14 @@ clutter_actor_clear_stage_views_recursive (ClutterActor *self)
NULL);
}
-gboolean
-_clutter_actor_get_real_resource_scale (ClutterActor *self,
- gfloat *resource_scale)
+float
+clutter_actor_get_real_resource_scale (ClutterActor *self)
{
ClutterActorPrivate *priv = self->priv;
float guessed_scale;
if (priv->resource_scale != -1.f)
- {
- *resource_scale = priv->resource_scale;
- return TRUE;
- }
+ return priv->resource_scale;
/* If the scale hasn't been computed yet, we return a best guess */
@@ -15988,7 +15984,7 @@ _clutter_actor_get_real_resource_scale (ClutterActor *self,
/* If the scale hasn't been calculated yet, assume this actor is located
* inside its parents box and go up the hierarchy.
*/
- _clutter_actor_get_real_resource_scale (priv->parent, &guessed_scale);
+ guessed_scale = clutter_actor_get_real_resource_scale (priv->parent);
}
else if (CLUTTER_ACTOR_IS_TOPLEVEL (self))
{
@@ -16023,14 +16019,12 @@ _clutter_actor_get_real_resource_scale (ClutterActor *self,
*/
priv->resource_scale = guessed_scale;
- *resource_scale = priv->resource_scale;
- return TRUE;
+ return priv->resource_scale;
}
/**
* clutter_actor_get_resource_scale:
* @self: A #ClutterActor
- * @resource_scale: (out): return location for the resource scale
*
* Retrieves the resource scale for this actor.
*
@@ -16060,22 +16054,14 @@ _clutter_actor_get_real_resource_scale (ClutterActor *self,
* determine its position and size, this function will return the resource
* scale of a parent.
*
- * Returns: TRUE if resource scale is set for the actor, otherwise FALSE
+ * Returns: The resource scale the actor should use for its textures
*/
-gboolean
-clutter_actor_get_resource_scale (ClutterActor *self,
- gfloat *resource_scale)
+float
+clutter_actor_get_resource_scale (ClutterActor *self)
{
- g_return_val_if_fail (CLUTTER_IS_ACTOR (self), FALSE);
- g_return_val_if_fail (resource_scale != NULL, FALSE);
-
- if (_clutter_actor_get_real_resource_scale (self, resource_scale))
- {
- *resource_scale = ceilf (*resource_scale);
- return TRUE;
- }
+ g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 1.f);
- return FALSE;
+ return ceilf (clutter_actor_get_real_resource_scale (self));
}
static gboolean
@@ -16172,7 +16158,7 @@ update_resource_scale (ClutterActor *self)
/* Never notify the initial change, otherwise, to be consistent,
* we'd also have to notify if we guessed correctly in
- * _clutter_actor_get_real_resource_scale().
+ * clutter_actor_get_real_resource_scale().
*/
if (old_resource_scale == -1.f)
return;
diff --git a/clutter/clutter/clutter-actor.h b/clutter/clutter/clutter-actor.h
index fac28e74cd..9f795f6d3f 100644
--- a/clutter/clutter/clutter-actor.h
+++ b/clutter/clutter/clutter-actor.h
@@ -588,8 +588,7 @@ gboolean clutter_actor_get_paint_box
ClutterActorBox
*box);
CLUTTER_EXPORT
-gboolean clutter_actor_get_resource_scale (ClutterActor *self,
- gfloat
*resource_scale);
+float clutter_actor_get_resource_scale (ClutterActor *self);
CLUTTER_EXPORT
gboolean clutter_actor_has_overlaps (ClutterActor
*self);
diff --git a/clutter/clutter/clutter-offscreen-effect.c b/clutter/clutter/clutter-offscreen-effect.c
index a3b4b9d991..75174ef104 100644
--- a/clutter/clutter/clutter-offscreen-effect.c
+++ b/clutter/clutter/clutter-offscreen-effect.c
@@ -238,8 +238,8 @@ clutter_offscreen_effect_pre_paint (ClutterEffect *effect,
gfloat stage_width, stage_height;
gfloat target_width = -1, target_height = -1;
CoglFramebuffer *framebuffer;
- gfloat resource_scale;
- gfloat ceiled_resource_scale;
+ float resource_scale;
+ float ceiled_resource_scale;
graphene_point3d_t local_offset;
gfloat old_viewport[4];
@@ -254,17 +254,11 @@ clutter_offscreen_effect_pre_paint (ClutterEffect *effect,
stage = _clutter_actor_get_stage_internal (priv->actor);
clutter_actor_get_size (stage, &stage_width, &stage_height);
- if (_clutter_actor_get_real_resource_scale (priv->actor, &resource_scale))
- {
- ceiled_resource_scale = ceilf (resource_scale);
- stage_width *= ceiled_resource_scale;
- stage_height *= ceiled_resource_scale;
- }
- else
- {
- /* We are sure we have a resource scale set to a good value at paint */
- g_assert_not_reached ();
- }
+ resource_scale = clutter_actor_get_real_resource_scale (priv->actor);
+
+ ceiled_resource_scale = ceilf (resource_scale);
+ stage_width *= ceiled_resource_scale;
+ stage_height *= ceiled_resource_scale;
/* Get the minimal bounding box for what we want to paint, relative to the
* parent of priv->actor. Note that we may actually be painting a clone of
@@ -417,8 +411,9 @@ clutter_offscreen_effect_paint_texture (ClutterOffscreenEffect *effect,
*/
cogl_framebuffer_get_modelview_matrix (framebuffer, &modelview);
- if (clutter_actor_get_resource_scale (priv->actor, &resource_scale) &&
- resource_scale != 1.0f)
+ resource_scale = clutter_actor_get_resource_scale (priv->actor);
+
+ if (resource_scale != 1.0f)
{
float paint_scale = 1.0f / resource_scale;
cogl_matrix_scale (&modelview, paint_scale, paint_scale, 1);
diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c
index 4f64df66e6..99d2184412 100644
--- a/clutter/clutter/clutter-stage.c
+++ b/clutter/clutter/clutter-stage.c
@@ -3822,9 +3822,7 @@ clutter_stage_get_capture_final_size (ClutterStage *stage,
clutter_actor_get_allocation_box (CLUTTER_ACTOR (stage), &alloc);
clutter_actor_box_get_size (&alloc, &stage_width, &stage_height);
- if (!_clutter_actor_get_real_resource_scale (CLUTTER_ACTOR (stage),
- &max_scale))
- return FALSE;
+ max_scale = clutter_actor_get_real_resource_scale (CLUTTER_ACTOR (stage));
if (out_width)
*out_width = (gint) roundf (stage_width * max_scale);
diff --git a/clutter/clutter/clutter-text.c b/clutter/clutter/clutter-text.c
index db20be10df..b9241d7c42 100644
--- a/clutter/clutter/clutter-text.c
+++ b/clutter/clutter/clutter-text.c
@@ -595,9 +595,7 @@ ensure_effective_pango_scale_attribute (ClutterText *self)
float resource_scale;
ClutterTextPrivate *priv = self->priv;
- if (!clutter_actor_get_resource_scale (CLUTTER_ACTOR (self), &resource_scale) ||
- resource_scale == 1.0)
- return;
+ resource_scale = clutter_actor_get_resource_scale (CLUTTER_ACTOR (self));
if (priv->effective_attrs != NULL)
{
@@ -1122,8 +1120,7 @@ maybe_create_text_layout_with_resource_scale (ClutterText *text,
{
float resource_scale;
- if (!clutter_actor_get_resource_scale (CLUTTER_ACTOR (text), &resource_scale))
- return NULL;
+ resource_scale = clutter_actor_get_resource_scale (CLUTTER_ACTOR (text));
return create_text_layout_with_scale (text,
allocation_width,
@@ -1155,8 +1152,7 @@ clutter_text_coords_to_position (ClutterText *self,
g_return_val_if_fail (CLUTTER_IS_TEXT (self), 0);
- if (!clutter_actor_get_resource_scale (CLUTTER_ACTOR (self), &resource_scale))
- return 0;
+ resource_scale = clutter_actor_get_resource_scale (CLUTTER_ACTOR (self));
/* Take any offset due to scrolling into account, and normalize
* the coordinates to PangoScale units
@@ -1284,8 +1280,7 @@ clutter_text_position_to_coords (ClutterText *self,
g_return_val_if_fail (CLUTTER_IS_TEXT (self), FALSE);
- if (!clutter_actor_get_resource_scale (CLUTTER_ACTOR (self), &resource_scale))
- return FALSE;
+ resource_scale = clutter_actor_get_resource_scale (CLUTTER_ACTOR (self));
ret = clutter_text_position_to_coords_internal (self, position,
x, y, line_height);
@@ -2625,8 +2620,7 @@ clutter_text_paint (ClutterActor *self,
!clutter_text_should_draw_cursor (text))
return;
- if (!clutter_actor_get_resource_scale (CLUTTER_ACTOR (self), &resource_scale))
- return;
+ resource_scale = clutter_actor_get_resource_scale (CLUTTER_ACTOR (self));
clutter_actor_box_scale (&alloc, resource_scale);
clutter_actor_box_get_size (&alloc, &alloc_width, &alloc_height);
@@ -2858,8 +2852,7 @@ clutter_text_get_paint_volume (ClutterActor *self,
if (!clutter_actor_has_allocation (self))
return FALSE;
- if (!clutter_actor_get_resource_scale (self, &resource_scale))
- return FALSE;
+ resource_scale = clutter_actor_get_resource_scale (self);
_clutter_paint_volume_init_static (&priv->paint_volume, self);
@@ -2916,8 +2909,7 @@ clutter_text_get_preferred_width (ClutterActor *self,
gfloat layout_width;
gfloat resource_scale;
- if (!clutter_actor_get_resource_scale (self, &resource_scale))
- resource_scale = 1;
+ resource_scale = clutter_actor_get_resource_scale (self);
layout = clutter_text_create_layout (text, -1, -1);
pango_layout_get_extents (layout, NULL, &logical_rect);
@@ -2973,8 +2965,7 @@ clutter_text_get_preferred_height (ClutterActor *self,
gfloat layout_height;
gfloat resource_scale;
- if (!clutter_actor_get_resource_scale (self, &resource_scale))
- resource_scale = 1;
+ resource_scale = clutter_actor_get_resource_scale (self);
if (priv->single_line_mode)
for_width = -1;
diff --git a/src/compositor/meta-window-actor.c b/src/compositor/meta-window-actor.c
index e23b426a91..b35d90d247 100644
--- a/src/compositor/meta-window-actor.c
+++ b/src/compositor/meta-window-actor.c
@@ -1301,8 +1301,7 @@ meta_window_actor_blit_to_framebuffer (MetaScreenCastWindow *screen_cast_window,
if (width == 0 || height == 0)
return FALSE;
- if (!clutter_actor_get_resource_scale (actor, &resource_scale))
- return FALSE;
+ resource_scale = clutter_actor_get_resource_scale (actor);
clutter_actor_inhibit_culling (actor);
@@ -1460,8 +1459,7 @@ meta_window_actor_get_image (MetaWindowActor *self,
if (width == 0 || height == 0)
goto out;
- if (!clutter_actor_get_resource_scale (actor, &resource_scale))
- goto out;
+ resource_scale = clutter_actor_get_resource_scale (actor);
width = ceilf (width * resource_scale);
height = ceilf (height * resource_scale);
diff --git a/src/tests/clutter/conform/text.c b/src/tests/clutter/conform/text.c
index e1b0cae438..304fa1dd4c 100644
--- a/src/tests/clutter/conform/text.c
+++ b/src/tests/clutter/conform/text.c
@@ -475,8 +475,7 @@ validate_markup_attributes (ClutterText *text,
PangoAttrFloat *scale = (PangoAttrFloat*) a;
float resource_scale;
- if (!clutter_actor_get_resource_scale (CLUTTER_ACTOR (text), &resource_scale))
- resource_scale = 1.0;
+ resource_scale = clutter_actor_get_resource_scale (CLUTTER_ACTOR (text));
g_assert_cmpfloat (scale->value, ==, resource_scale);
g_slist_free_full (attributes, (GDestroyNotify) pango_attribute_destroy);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]