From cb9842e4a4740df9f5e0fbcb084c6260cfee41a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Thu, 28 May 2020 14:39:11 +0200 Subject: [PATCH 1/3] Use new clutter_actor_get_resource_scale() API Update the existing users of clutter_actor_get_resource_scale() to the new API which doesn't return a boolean value. https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1287 --- src/shell-screenshot.c | 3 +- src/st/st-drawing-area.c | 24 +++++--------- src/st/st-icon.c | 3 +- src/st/st-label.c | 68 +++++++++++++++++++--------------------- src/st/st-private.c | 3 +- src/st/st-widget.c | 9 +++--- 6 files changed, 48 insertions(+), 62 deletions(-) diff --git a/src/shell-screenshot.c b/src/shell-screenshot.c index e60d5891b1..36ca2fb24b 100644 --- a/src/shell-screenshot.c +++ b/src/shell-screenshot.c @@ -393,8 +393,7 @@ grab_window_screenshot (ClutterActor *stage, if (meta_window_get_client_type (window) == META_WINDOW_CLIENT_TYPE_WAYLAND) { float resource_scale; - if (!clutter_actor_get_resource_scale (window_actor, &resource_scale)) - resource_scale = 1.0f; + resource_scale = clutter_actor_get_resource_scale (window_actor); cairo_surface_set_device_scale (priv->image, resource_scale, resource_scale); } diff --git a/src/st/st-drawing-area.c b/src/st/st-drawing-area.c index a9daca562d..44d7c0add9 100644 --- a/src/st/st-drawing-area.c +++ b/src/st/st-drawing-area.c @@ -85,12 +85,7 @@ st_drawing_area_allocate (ClutterActor *self, int width, height; float resource_scale; - if (!st_widget_get_resource_scale (ST_WIDGET (self), &resource_scale)) - { - ClutterActorBox empty = CLUTTER_ACTOR_BOX_INIT_ZERO; - clutter_actor_set_allocation (self, &empty); - return; - } + resource_scale = clutter_actor_get_resource_scale (self); clutter_actor_set_allocation (self, box); st_theme_node_get_content_box (theme_node, box, &content_box); @@ -116,8 +111,8 @@ st_drawing_area_resource_scale_changed (StWidget *self) float resource_scale; ClutterContent *content = clutter_actor_get_content (CLUTTER_ACTOR (self)); - if (st_widget_get_resource_scale (ST_WIDGET (self), &resource_scale)) - clutter_canvas_set_scale_factor (CLUTTER_CANVAS (content), resource_scale); + resource_scale = clutter_actor_get_resource_scale (CLUTTER_ACTOR (self)); + clutter_canvas_set_scale_factor (CLUTTER_CANVAS (content), resource_scale); } static void @@ -215,15 +210,10 @@ st_drawing_area_get_surface_size (StDrawingArea *area, content = clutter_actor_get_content (CLUTTER_ACTOR (area)); clutter_content_get_preferred_size (content, &w, &h); - if (st_widget_get_resource_scale (ST_WIDGET (area), &resource_scale)) - { - w /= resource_scale; - h /= resource_scale; - } - else - { - w = h = 0.0f; - } + resource_scale = clutter_actor_get_resource_scale (CLUTTER_ACTOR (area)); + + w /= resource_scale; + h /= resource_scale; if (width) *width = ceilf (w); diff --git a/src/st/st-icon.c b/src/st/st-icon.c index 38d58205d5..3657ccc2c8 100644 --- a/src/st/st-icon.c +++ b/src/st/st-icon.c @@ -425,8 +425,7 @@ st_icon_update (StIcon *icon) return; } - if (!st_widget_get_resource_scale (ST_WIDGET (icon), &resource_scale)) - return; + resource_scale = clutter_actor_get_resource_scale (CLUTTER_ACTOR (icon)); theme_node = st_widget_peek_theme_node (ST_WIDGET (icon)); if (theme_node == NULL) diff --git a/src/st/st-label.c b/src/st/st-label.c index 7415dec29c..4d8271d694 100644 --- a/src/st/st-label.c +++ b/src/st/st-label.c @@ -201,44 +201,42 @@ st_label_paint (ClutterActor *actor, if (shadow_spec) { + ClutterActorBox allocation; + float width, height; float resource_scale; - if (clutter_actor_get_resource_scale (priv->label, &resource_scale)) + clutter_actor_get_allocation_box (priv->label, &allocation); + clutter_actor_box_get_size (&allocation, &width, &height); + + resource_scale = clutter_actor_get_resource_scale (priv->label); + + width *= resource_scale; + height *= resource_scale; + + if (priv->text_shadow_pipeline == NULL || + width != priv->shadow_width || + height != priv->shadow_height) + { + g_clear_pointer (&priv->text_shadow_pipeline, cogl_object_unref); + + priv->shadow_width = width; + priv->shadow_height = height; + priv->text_shadow_pipeline = + _st_create_shadow_pipeline_from_actor (shadow_spec, + priv->label); + } + + if (priv->text_shadow_pipeline != NULL) { - ClutterActorBox allocation; - float width, height; - - clutter_actor_get_allocation_box (priv->label, &allocation); - clutter_actor_box_get_size (&allocation, &width, &height); - - width *= resource_scale; - height *= resource_scale; - - if (priv->text_shadow_pipeline == NULL || - width != priv->shadow_width || - height != priv->shadow_height) - { - g_clear_pointer (&priv->text_shadow_pipeline, cogl_object_unref); - - priv->shadow_width = width; - priv->shadow_height = height; - priv->text_shadow_pipeline = - _st_create_shadow_pipeline_from_actor (shadow_spec, - priv->label); - } - - if (priv->text_shadow_pipeline != NULL) - { - CoglFramebuffer *framebuffer; - - framebuffer = - clutter_paint_context_get_framebuffer (paint_context); - _st_paint_shadow_with_opacity (shadow_spec, - framebuffer, - priv->text_shadow_pipeline, - &allocation, - clutter_actor_get_paint_opacity (priv->label)); - } + CoglFramebuffer *framebuffer; + + framebuffer = + clutter_paint_context_get_framebuffer (paint_context); + _st_paint_shadow_with_opacity (shadow_spec, + framebuffer, + priv->text_shadow_pipeline, + &allocation, + clutter_actor_get_paint_opacity (priv->label)); } } diff --git a/src/st/st-private.c b/src/st/st-private.c index 16a5e15dd6..a491c19535 100644 --- a/src/st/st-private.c +++ b/src/st/st-private.c @@ -461,8 +461,7 @@ _st_create_shadow_pipeline_from_actor (StShadow *shadow_spec, if (width == 0 || height == 0) return NULL; - if (!clutter_actor_get_resource_scale (actor, &resource_scale)) - return NULL; + resource_scale = clutter_actor_get_resource_scale (actor); width = ceilf (width * resource_scale); height = ceilf (height * resource_scale); diff --git a/src/st/st-widget.c b/src/st/st-widget.c index 9efffbd762..3d732a74a7 100644 --- a/src/st/st-widget.c +++ b/src/st/st-widget.c @@ -412,8 +412,7 @@ st_widget_paint_background (StWidget *widget, float resource_scale; guint8 opacity; - if (!st_widget_get_resource_scale (widget, &resource_scale)) - return; + resource_scale = clutter_actor_get_resource_scale (CLUTTER_ACTOR (widget)); framebuffer = clutter_paint_context_get_framebuffer (paint_context); theme_node = st_widget_get_theme_node (widget); @@ -1413,8 +1412,10 @@ gboolean st_widget_get_resource_scale (StWidget *widget, float *resource_scale) { - return clutter_actor_get_resource_scale (CLUTTER_ACTOR (widget), - resource_scale); + if (resource_scale) + *resource_scale = clutter_actor_get_resource_scale (CLUTTER_ACTOR (widget)); + + return TRUE; } static void -- GitLab From 1524abc947bc16eaa58a5f692d2a3d208afd7eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Thu, 28 May 2020 14:43:26 +0200 Subject: [PATCH 2/3] Switch to ClutterActors resource-scale-changed signal Instead of using the "notify::resource-scale" signal and StWidgets "resource-scale-changed" signal, use the new "resource-scale-changed" signal of ClutterActor, which replaces its "resource-scale" property. Since we'd now have two "resource-scale-changed" signals, one on ClutterActor and one on StWidget, remove the StWidget one in favour of the new one. https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1287 --- src/shell-recorder.c | 19 +++++++-------- src/st/st-drawing-area.c | 11 +++++---- src/st/st-icon.c | 9 +++++--- src/st/st-label.c | 9 +++++--- src/st/st-widget.c | 50 +++++++++++++--------------------------- src/st/st-widget.h | 1 - 6 files changed, 45 insertions(+), 54 deletions(-) diff --git a/src/shell-recorder.c b/src/shell-recorder.c index 7a01d5fd17..231eab82c0 100644 --- a/src/shell-recorder.c +++ b/src/shell-recorder.c @@ -508,9 +508,7 @@ recorder_update_size (ShellRecorder *recorder) } static void -recorder_on_stage_notify_size (GObject *object, - GParamSpec *pspec, - ShellRecorder *recorder) +recorder_on_stage_notify_size (ShellRecorder *recorder) { recorder_update_size (recorder); @@ -614,12 +612,15 @@ recorder_connect_stage_callbacks (ShellRecorder *recorder) G_CALLBACK (recorder_on_stage_destroy), recorder); g_signal_connect_after (recorder->stage, "paint", G_CALLBACK (recorder_on_stage_paint), recorder); - g_signal_connect (recorder->stage, "notify::width", - G_CALLBACK (recorder_on_stage_notify_size), recorder); - g_signal_connect (recorder->stage, "notify::height", - G_CALLBACK (recorder_on_stage_notify_size), recorder); - g_signal_connect (recorder->stage, "notify::resource-scale", - G_CALLBACK (recorder_on_stage_notify_size), recorder); + g_signal_connect_swapped (recorder->stage, "notify::width", + G_CALLBACK (recorder_on_stage_notify_size), + recorder); + g_signal_connect_swapped (recorder->stage, "notify::height", + G_CALLBACK (recorder_on_stage_notify_size), + recorder); + g_signal_connect_swapped (recorder->stage, "resource-scale-changed", + G_CALLBACK (recorder_on_stage_notify_size), + recorder); } static void diff --git a/src/st/st-drawing-area.c b/src/st/st-drawing-area.c index 44d7c0add9..3f916e8a3b 100644 --- a/src/st/st-drawing-area.c +++ b/src/st/st-drawing-area.c @@ -106,13 +106,16 @@ st_drawing_area_style_changed (StWidget *self) } static void -st_drawing_area_resource_scale_changed (StWidget *self) +st_drawing_area_resource_scale_changed (ClutterActor *self) { float resource_scale; - ClutterContent *content = clutter_actor_get_content (CLUTTER_ACTOR (self)); + ClutterContent *content = clutter_actor_get_content (self); - resource_scale = clutter_actor_get_resource_scale (CLUTTER_ACTOR (self)); + resource_scale = clutter_actor_get_resource_scale (self); clutter_canvas_set_scale_factor (CLUTTER_CANVAS (content), resource_scale); + + if (CLUTTER_ACTOR_CLASS (st_drawing_area_parent_class)->resource_scale_changed) + CLUTTER_ACTOR_CLASS (st_drawing_area_parent_class)->resource_scale_changed (self); } static void @@ -123,7 +126,7 @@ st_drawing_area_class_init (StDrawingAreaClass *klass) actor_class->allocate = st_drawing_area_allocate; widget_class->style_changed = st_drawing_area_style_changed; - widget_class->resource_scale_changed = st_drawing_area_resource_scale_changed; + actor_class->resource_scale_changed = st_drawing_area_resource_scale_changed; st_drawing_area_signals[REPAINT] = g_signal_new ("repaint", diff --git a/src/st/st-icon.c b/src/st/st-icon.c index 3657ccc2c8..d6a6c4c22a 100644 --- a/src/st/st-icon.c +++ b/src/st/st-icon.c @@ -231,9 +231,12 @@ st_icon_style_changed (StWidget *widget) } static void -st_icon_resource_scale_changed (StWidget *widget) +st_icon_resource_scale_changed (ClutterActor *actor) { - st_icon_update (ST_ICON (widget)); + st_icon_update (ST_ICON (actor)); + + if (CLUTTER_ACTOR_CLASS (st_icon_parent_class)->resource_scale_changed) + CLUTTER_ACTOR_CLASS (st_icon_parent_class)->resource_scale_changed (actor); } static void @@ -250,7 +253,7 @@ st_icon_class_init (StIconClass *klass) actor_class->paint = st_icon_paint; widget_class->style_changed = st_icon_style_changed; - widget_class->resource_scale_changed = st_icon_resource_scale_changed; + actor_class->resource_scale_changed = st_icon_resource_scale_changed; props[PROP_GICON] = g_param_spec_object ("gicon", diff --git a/src/st/st-label.c b/src/st/st-label.c index 4d8271d694..9c4ad31d43 100644 --- a/src/st/st-label.c +++ b/src/st/st-label.c @@ -244,11 +244,14 @@ st_label_paint (ClutterActor *actor, } static void -st_label_resource_scale_changed (StWidget *widget) +st_label_resource_scale_changed (ClutterActor *actor) { - StLabelPrivate *priv = ST_LABEL (widget)->priv; + StLabelPrivate *priv = ST_LABEL (actor)->priv; g_clear_pointer (&priv->text_shadow_pipeline, cogl_object_unref); + + if (CLUTTER_ACTOR_CLASS (st_label_parent_class)->resource_scale_changed) + CLUTTER_ACTOR_CLASS (st_label_parent_class)->resource_scale_changed (actor); } static void @@ -266,9 +269,9 @@ st_label_class_init (StLabelClass *klass) actor_class->allocate = st_label_allocate; actor_class->get_preferred_width = st_label_get_preferred_width; actor_class->get_preferred_height = st_label_get_preferred_height; + actor_class->resource_scale_changed = st_label_resource_scale_changed; widget_class->style_changed = st_label_style_changed; - widget_class->resource_scale_changed = st_label_resource_scale_changed; widget_class->get_accessible_type = st_label_accessible_get_type; props[PROP_CLUTTER_TEXT] = diff --git a/src/st/st-widget.c b/src/st/st-widget.c index 3d732a74a7..c8bc9edef0 100644 --- a/src/st/st-widget.c +++ b/src/st/st-widget.c @@ -124,7 +124,6 @@ enum { STYLE_CHANGED, POPUP_MENU, - RESOURCE_SCALE_CHANGED, LAST_SIGNAL }; @@ -819,6 +818,20 @@ st_widget_real_get_focus_chain (StWidget *widget) return g_list_reverse (visible); } +static void +st_widget_resource_scale_changed (ClutterActor *actor) +{ + StWidget *widget = ST_WIDGET (actor); + StWidgetPrivate *priv = st_widget_get_instance_private (widget); + int i; + + for (i = 0; i < G_N_ELEMENTS (priv->paint_states); i++) + st_theme_node_paint_state_invalidate (&priv->paint_states[i]); + + if (CLUTTER_ACTOR_CLASS (st_widget_parent_class)->resource_scale_changed) + CLUTTER_ACTOR_CLASS (st_widget_parent_class)->resource_scale_changed (actor); +} + static void st_widget_class_init (StWidgetClass *klass) { @@ -848,6 +861,8 @@ st_widget_class_init (StWidgetClass *klass) actor_class->get_accessible = st_widget_get_accessible; actor_class->has_accessible = st_widget_has_accessible; + actor_class->resource_scale_changed = st_widget_resource_scale_changed; + klass->style_changed = st_widget_real_style_changed; klass->navigate_focus = st_widget_real_navigate_focus; klass->get_accessible_type = st_widget_accessible_get_type; @@ -1001,21 +1016,6 @@ st_widget_class_init (StWidgetClass *klass) G_STRUCT_OFFSET (StWidgetClass, popup_menu), NULL, NULL, NULL, G_TYPE_NONE, 0); - - /** - * StWidget::resource-scale-changed: - * @widget: the #StWidget - * - * Emitted when the paint scale that the widget will be painted as - * changed. - */ - signals[RESOURCE_SCALE_CHANGED] = - g_signal_new ("resource-scale-changed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (StWidgetClass, resource_scale_changed), - NULL, NULL, NULL, - G_TYPE_NONE, 0); } static const gchar * @@ -1484,23 +1484,6 @@ st_widget_name_notify (StWidget *widget, st_widget_style_changed (widget); } -static void -st_widget_resource_scale_notify (StWidget *widget, - GParamSpec *pspec, - gpointer data) -{ - StWidgetPrivate *priv = st_widget_get_instance_private (widget); - int i; - - for (i = 0; i < G_N_ELEMENTS (priv->paint_states); i++) - st_theme_node_paint_state_invalidate (&priv->paint_states[i]); - - g_signal_emit (widget, signals[RESOURCE_SCALE_CHANGED], 0); - - if (clutter_actor_is_mapped (CLUTTER_ACTOR (widget))) - clutter_actor_queue_redraw (CLUTTER_ACTOR (widget)); -} - static void st_widget_reactive_notify (StWidget *widget, GParamSpec *pspec, @@ -1652,7 +1635,6 @@ st_widget_init (StWidget *actor) /* connect style changed */ g_signal_connect (actor, "notify::name", G_CALLBACK (st_widget_name_notify), NULL); - g_signal_connect (actor, "notify::resource-scale", G_CALLBACK (st_widget_resource_scale_notify), NULL); g_signal_connect (actor, "notify::reactive", G_CALLBACK (st_widget_reactive_notify), NULL); g_signal_connect (actor, "notify::visible", G_CALLBACK (st_widget_visible_notify), NULL); diff --git a/src/st/st-widget.h b/src/st/st-widget.h index 82fd7d0b44..99644d7864 100644 --- a/src/st/st-widget.h +++ b/src/st/st-widget.h @@ -63,7 +63,6 @@ struct _StWidgetClass /* signals */ void (* style_changed) (StWidget *self); void (* popup_menu) (StWidget *self); - void (* resource_scale_changed) (StWidget *self); /* vfuncs */ -- GitLab From d88548639757c9c38726a0797d9a5fc773e8bee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Thu, 28 May 2020 14:47:17 +0200 Subject: [PATCH 3/3] st/widget: Remove get_resource_scale function ClutterActor provides the same function, but with a different return value. So since we already switched to the ClutterActor implementation in our C code, we can now safely remove st_widget_get_resource_scale() and update the JS code that's still using the old API. https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1287 --- js/gdm/loginDialog.js | 4 ++-- js/ui/animation.js | 8 +------- src/st/st-widget.c | 19 ------------------- src/st/st-widget.h | 2 -- 4 files changed, 3 insertions(+), 30 deletions(-) diff --git a/js/gdm/loginDialog.js b/js/gdm/loginDialog.js index 4246b8616f..46ddc51f57 100644 --- a/js/gdm/loginDialog.js +++ b/js/gdm/loginDialog.js @@ -810,8 +810,8 @@ var LoginDialog = GObject.registerClass({ return; this._logoBin.destroy_all_children(); - const [valid, resourceScale] = this._logoBin.get_resource_scale(); - if (this._logoFile && valid) { + const resourceScale = this._logoBin.get_resource_scale(); + if (this._logoFile) { let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor; this._logoBin.add_child(this._textureCache.load_file_async(this._logoFile, -1, -1, diff --git a/js/ui/animation.js b/js/ui/animation.js index fa8cad932a..5cb3a83c13 100644 --- a/js/ui/animation.js +++ b/js/ui/animation.js @@ -60,7 +60,7 @@ class Animation extends St.Bin { } _loadFile(file, width, height) { - let [validResourceScale, resourceScale] = this.get_resource_scale(); + const resourceScale = this.get_resource_scale(); let wasPlaying = this._isPlaying; if (this._isPlaying) @@ -69,12 +69,6 @@ class Animation extends St.Bin { this._isLoaded = false; this.destroy_all_children(); - if (!validResourceScale) { - if (wasPlaying) - this.play(); - return; - } - let textureCache = St.TextureCache.get_default(); let scaleFactor = St.ThemeContext.get_for_stage(global.stage).scale_factor; this._animations = textureCache.load_sliced_image(file, width, height, diff --git a/src/st/st-widget.c b/src/st/st-widget.c index c8bc9edef0..6fd7a11a9d 100644 --- a/src/st/st-widget.c +++ b/src/st/st-widget.c @@ -1399,25 +1399,6 @@ st_widget_get_style (StWidget *actor) return ST_WIDGET_PRIVATE (actor)->inline_style; } -/** - * st_widget_get_resource_scale: - * @widget: A #StWidget - * @resource_scale: (out): return location for the resource scale - * - * Retrieves the resource scale for this #StWidget, if available. - * - * The resource scale refers to the scale the actor should use for its resources. - */ -gboolean -st_widget_get_resource_scale (StWidget *widget, - float *resource_scale) -{ - if (resource_scale) - *resource_scale = clutter_actor_get_resource_scale (CLUTTER_ACTOR (widget)); - - return TRUE; -} - static void st_widget_set_first_visible_child (StWidget *widget, ClutterActor *actor) diff --git a/src/st/st-widget.h b/src/st/st-widget.h index 99644d7864..9a4d28fb18 100644 --- a/src/st/st-widget.h +++ b/src/st/st-widget.h @@ -134,8 +134,6 @@ StThemeNode * st_widget_peek_theme_node (StWidget *widg GList * st_widget_get_focus_chain (StWidget *widget); void st_widget_paint_background (StWidget *widget, ClutterPaintContext *paint_context); -gboolean st_widget_get_resource_scale (StWidget *widget, - float *resource_scale); /* debug methods */ char *st_describe_actor (ClutterActor *actor); -- GitLab