From c69547147547471e50df28aee20c5320570f6099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sat, 23 Dec 2017 04:17:03 +0100 Subject: [PATCH] clutter/stage: Add private API to get max view scale for rect Move the same code from ClutterActor as this is something we can reuse elsewhere. https://bugzilla.gnome.org/show_bug.cgi?id=765011 https://gitlab.gnome.org/GNOME/mutter/merge_requests/3 --- clutter/clutter/clutter-actor.c | 20 +++-------------- clutter/clutter/clutter-stage-private.h | 3 +++ clutter/clutter/clutter-stage.c | 29 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c index d0f7434ef..fd38338c7 100644 --- a/clutter/clutter/clutter-actor.c +++ b/clutter/clutter/clutter-actor.c @@ -17785,29 +17785,15 @@ _clutter_actor_get_resource_scale_for_rect (ClutterActor *self, float *resource_scale) { ClutterActor *stage; - GList *views; - GList *l; float max_scale = 0; stage = _clutter_actor_get_stage_internal (self); if (!stage) return FALSE; - views = _clutter_stage_peek_stage_views (CLUTTER_STAGE (stage)); - for (l = views; l; l = l->next) - { - ClutterStageView *view = l->data; - cairo_rectangle_int_t view_layout; - ClutterRect view_rect; - - clutter_stage_view_get_layout (view, &view_layout); - _clutter_util_rect_from_rectangle (&view_layout, &view_rect); - - if (clutter_rect_intersection (&view_rect, bounding_rect, NULL)) - max_scale = MAX (clutter_stage_view_get_scale (view), max_scale); - } - - if (max_scale == 0) + if (!_clutter_stage_get_max_view_scale_factor_for_rect (CLUTTER_STAGE (stage), + bounding_rect, + &max_scale)) return FALSE; *resource_scale = max_scale; diff --git a/clutter/clutter/clutter-stage-private.h b/clutter/clutter/clutter-stage-private.h index 688768bac..4799c29e1 100644 --- a/clutter/clutter/clutter-stage-private.h +++ b/clutter/clutter/clutter-stage-private.h @@ -124,6 +124,9 @@ gboolean _clutter_stage_update_state (ClutterStage *stag void _clutter_stage_set_scale_factor (ClutterStage *stage, int factor); +gboolean _clutter_stage_get_max_view_scale_factor_for_rect (ClutterStage *stage, + ClutterRect *rect, + float *view_scale); void _clutter_stage_presented (ClutterStage *stage, CoglFrameEvent frame_event, diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c index d284692c0..7ed83184a 100644 --- a/clutter/clutter/clutter-stage.c +++ b/clutter/clutter/clutter-stage.c @@ -5018,3 +5018,32 @@ clutter_stage_update_resource_scales (ClutterStage *stage) { _clutter_actor_queue_update_resource_scale_recursive (CLUTTER_ACTOR (stage)); } + +gboolean +_clutter_stage_get_max_view_scale_factor_for_rect (ClutterStage *stage, + ClutterRect *rect, + float *view_scale) +{ + ClutterStagePrivate *priv = stage->priv; + float scale = 0.0f; + GList *l; + + for (l = _clutter_stage_window_get_views (priv->impl); l; l = l->next) + { + ClutterStageView *view = l->data; + cairo_rectangle_int_t view_layout; + ClutterRect view_rect; + + clutter_stage_view_get_layout (view, &view_layout); + _clutter_util_rect_from_rectangle (&view_layout, &view_rect); + + if (clutter_rect_intersection (&view_rect, rect, NULL)) + scale = MAX (clutter_stage_view_get_scale (view), scale); + } + + if (scale == 0.0) + return FALSE; + + *view_scale = scale; + return TRUE; +}