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
This commit is contained in:
Jonas Dreßler 2020-04-10 11:41:58 +02:00 committed by Jonas Ådahl
parent 4a72ac0516
commit 98df2dbd05
8 changed files with 35 additions and 70 deletions

View File

@ -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);

View File

@ -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);
g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 1.f);
if (_clutter_actor_get_real_resource_scale (self, resource_scale))
{
*resource_scale = ceilf (*resource_scale);
return TRUE;
}
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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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);