[gtk/wip/otte/gdk: 7/12] surface: Make gdk_surface_update_size() update the size




commit 76b4fff03d1e3e223a2148f92cce75baa4afecdb
Author: Benjamin Otte <otte redhat com>
Date:   Thu Mar 18 04:45:33 2021 +0100

    surface: Make gdk_surface_update_size() update the size
    
    Only if the size changed of course.
    
    Return a boolean to the backend indicating if it actually did so.
    
    For now, we always notify the draw contexts, because the backends still
    update the width/height themselves before calling update_size().

 gdk/gdksurface.c        | 42 +++++++++++++++++++++++++++++++++++++-----
 gdk/gdksurfaceprivate.h |  6 ++++--
 2 files changed, 41 insertions(+), 7 deletions(-)
---
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index df10fe65d4..6b6b8d14dc 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -470,6 +470,7 @@ gdk_surface_init (GdkSurface *surface)
   surface->fullscreen_mode = GDK_FULLSCREEN_ON_CURRENT_MONITOR;
   surface->width = 1;
   surface->height = 1;
+  surface->scale_factor = 1;
 
   surface->alpha = 255;
 
@@ -813,19 +814,50 @@ gdk_surface_get_property (GObject    *object,
     }
 }
 
-void
-gdk_surface_update_size (GdkSurface *surface,
+gboolean
+gdk_surface_update_size (GdkSurface *self,
                          int         width,
                          int         height,
                          int         scale)
 {
   GSList *l;
 
-  for (l = surface->draw_contexts; l; l = l->next)
+  if (self->width == width && 
+      self->height == height &&
+      self->scale_factor == scale)
+    {
+      /* FIXME: Remove when all backends are updated */
+      for (l = self->draw_contexts; l; l = l->next)
+        gdk_draw_context_surface_resized (l->data);
+      return FALSE;
+    }
+
+  g_object_freeze_notify (G_OBJECT (self));
+
+  if (self->width != width)
+    {
+      self->width = width;
+      g_object_notify (G_OBJECT (self), "width");
+    }
+
+  if (self->height != height)
+    {
+      self->height = height;
+      g_object_notify (G_OBJECT (self), "height");
+    }
+
+  if (self->scale_factor != scale)
+    {
+      self->scale_factor = scale;
+      g_object_notify (G_OBJECT (self), "scale-factor");
+    }
+
+  for (l = self->draw_contexts; l; l = l->next)
     gdk_draw_context_surface_resized (l->data);
 
-  g_object_notify (G_OBJECT (surface), "width");
-  g_object_notify (G_OBJECT (surface), "height");
+  g_object_thaw_notify (G_OBJECT (self));
+
+  return TRUE;
 }
 
 static GdkSurface *
diff --git a/gdk/gdksurfaceprivate.h b/gdk/gdksurfaceprivate.h
index dfee670b40..184f29342d 100644
--- a/gdk/gdksurfaceprivate.h
+++ b/gdk/gdksurfaceprivate.h
@@ -89,7 +89,9 @@ struct _GdkSurface
 
   guint update_and_descendants_freeze_count;
 
-  int width, height;
+  int width;
+  int height;
+  int scale_factor;
 
   GdkCursor *cursor;
   GHashTable *device_cursor;
@@ -255,7 +257,7 @@ gdk_gravity_flip_vertically (GdkGravity anchor)
   g_assert_not_reached ();
 }
 
-void                    gdk_surface_update_size                 (GdkSurface             *surface,
+gboolean                gdk_surface_update_size                 (GdkSurface             *surface,
                                                                  int                     width,
                                                                  int                     height,
                                                                  int                     scale);


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