[mutter] background: Scale monitor_area after texture creation



commit 76240e24f7981a2a0f7e4e83ff641ed7b3562894
Author: Daniel van Vugt <daniel van vugt canonical com>
Date:   Mon Jan 13 21:02:39 2020 +0800

    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 | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 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 <string.h>
 
+#include "backends/meta-backend-private.h"
 #include "compositor/cogl-utils.h"
 #include "meta/display.h"
 #include "meta/meta-background-image.h"
@@ -799,26 +800,39 @@ meta_background_get_texture (MetaBackground         *self,
     {
       GError *catch_error = NULL;
       gboolean bare_region_visible = FALSE;
+      int texture_width, texture_height;
 
-      if (self->style != G_DESKTOP_BACKGROUND_STYLE_WALLPAPER)
+      if (meta_is_stage_views_scaled ())
         {
-          monitor_area.x *= monitor_scale;
-          monitor_area.y *= monitor_scale;
-          monitor_area.width *= monitor_scale;
-          monitor_area.height *= monitor_scale;
+          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 (monitor_area.width, monitor_area.height,
+          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)
+        {
+          monitor_area.x *= monitor_scale;
+          monitor_area.y *= monitor_scale;
+          monitor_area.width *= monitor_scale;
+          monitor_area.height *= monitor_scale;
+        }
+
       if (!cogl_framebuffer_allocate (monitor->fbo, &catch_error))
         {
           /* Texture or framebuffer allocation failed; it's unclear why this happened;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]