From 76240e24f7981a2a0f7e4e83ff641ed7b3562894 Mon Sep 17 00:00:00 2001 From: Daniel van Vugt Date: Mon, 13 Jan 2020 21:02:39 +0800 Subject: [PATCH] background: Scale monitor_area after texture creation Scaling the `monitor_area` before texture creation was just wasting megabytes of memory on resolution that the monitor can't display. This was also hurting runtime performance. Example: Monitor is natively 1920x1080 and scale set to 3. Before: The monitor texture allocated was 5760x3250x4 = 74.6 MB After: The monitor texture allocated is 1920x1080x4 = 8.3 MB Closes: https://gitlab.gnome.org/GNOME/gnome-shell/issues/2118 https://gitlab.gnome.org/GNOME/mutter/merge_requests/1004 --- src/compositor/meta-background.c | 36 ++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/compositor/meta-background.c b/src/compositor/meta-background.c index 3bd52aa2f..30be33261 100644 --- a/src/compositor/meta-background.c +++ b/src/compositor/meta-background.c @@ -23,6 +23,7 @@ #include +#include "backends/meta-backend-private.h" #include "compositor/cogl-utils.h" #include "meta/display.h" #include "meta/meta-background-image.h" @@ -799,6 +800,30 @@ meta_background_get_texture (MetaBackground *self, { GError *catch_error = NULL; gboolean bare_region_visible = FALSE; + int texture_width, texture_height; + + if (meta_is_stage_views_scaled ()) + { + texture_width = monitor_area.width * monitor_scale; + texture_height = monitor_area.height * monitor_scale; + } + else + { + texture_width = monitor_area.width; + texture_height = monitor_area.height; + } + + if (monitor->texture == NULL) + { + CoglOffscreen *offscreen; + + monitor->texture = meta_create_texture (texture_width, + texture_height, + COGL_TEXTURE_COMPONENTS_RGBA, + META_TEXTURE_FLAGS_NONE); + offscreen = cogl_offscreen_new_with_texture (monitor->texture); + monitor->fbo = COGL_FRAMEBUFFER (offscreen); + } if (self->style != G_DESKTOP_BACKGROUND_STYLE_WALLPAPER) { @@ -808,17 +833,6 @@ meta_background_get_texture (MetaBackground *self, monitor_area.height *= monitor_scale; } - if (monitor->texture == NULL) - { - CoglOffscreen *offscreen; - - monitor->texture = meta_create_texture (monitor_area.width, monitor_area.height, - COGL_TEXTURE_COMPONENTS_RGBA, - META_TEXTURE_FLAGS_NONE); - offscreen = cogl_offscreen_new_with_texture (monitor->texture); - monitor->fbo = COGL_FRAMEBUFFER (offscreen); - } - if (!cogl_framebuffer_allocate (monitor->fbo, &catch_error)) { /* Texture or framebuffer allocation failed; it's unclear why this happened;