[metacity] compositor-xrender: move back_pixmap to MetaSurface



commit e4c1e31ef4fe93f33bdcb21a1461e73df15da86e
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Oct 6 00:46:38 2019 +0300

    compositor-xrender: move back_pixmap to MetaSurface

 src/compositor/meta-compositor-xrender.c |  59 +++++-----------
 src/compositor/meta-compositor.c         |   2 +
 src/compositor/meta-surface.c            | 117 +++++++++++++++++++++++++++++++
 src/compositor/meta-surface.h            |  10 +++
 4 files changed, 146 insertions(+), 42 deletions(-)
---
diff --git a/src/compositor/meta-compositor-xrender.c b/src/compositor/meta-compositor-xrender.c
index 3b05a250..be012257 100644
--- a/src/compositor/meta-compositor-xrender.c
+++ b/src/compositor/meta-compositor-xrender.c
@@ -92,7 +92,6 @@ typedef struct _MetaCompWindow
 
   MetaRectangle rect;
 
-  Pixmap back_pixmap;
   Pixmap mask_pixmap;
 
   int mode;
@@ -122,10 +121,9 @@ typedef struct _MetaCompWindow
 
   XserverRegion border_clip;
 
-  /* When the window is shaded back_pixmap will be replaced with the pixmap
-   * for the shaded window. This is a copy of the original unshaded window
-   * so that we can still see what the window looked like when it is needed
-   * for the _get_window_surface function.
+  /* This is a copy of the original unshaded window so that we can still see
+   * what the window looked like when it is needed for the _get_window_surface
+   * function.
    */
   cairo_surface_t *shaded_surface;
 } MetaCompWindow;
@@ -1222,25 +1220,23 @@ get_window_format (Display        *xdisplay,
 }
 
 static Picture
-get_window_picture (MetaDisplay    *display,
-                    MetaCompWindow *cw)
+get_window_picture (MetaSurface *surface)
 {
+  MetaCompWindow *cw;
+  MetaDisplay *display;
   Display *xdisplay;
   Window xwindow;
+  Pixmap back_pixmap;
   XRenderPictureAttributes pa;
   XRenderPictFormat *format;
 
+  cw = g_object_get_data (G_OBJECT (surface), "cw");
+
+  display = meta_window_get_display (cw->window);
   xdisplay = meta_display_get_xdisplay (display);
   xwindow = meta_window_get_toplevel_xwindow (cw->window);
 
-  if (cw->back_pixmap == None)
-    {
-      meta_error_trap_push (display);
-      cw->back_pixmap = XCompositeNameWindowPixmap (xdisplay, xwindow);
-
-      if (meta_error_trap_pop_with_return (display) != 0)
-        cw->back_pixmap = None;
-    }
+  back_pixmap = meta_surface_get_pixmap (surface);
 
   format = get_window_format (xdisplay, cw);
   if (format)
@@ -1248,7 +1244,7 @@ get_window_picture (MetaDisplay    *display,
       Drawable draw;
       Picture pict;
 
-      draw = cw->back_pixmap != None ? cw->back_pixmap : xwindow;
+      draw = back_pixmap != None ? back_pixmap : xwindow;
       pa.subwindow_mode = IncludeInferiors;
 
       meta_error_trap_push (display);
@@ -1442,7 +1438,7 @@ paint_windows (MetaCompositorXRender *xrender,
         continue;
 
       if (cw->picture == None)
-        cw->picture = get_window_picture (display, cw);
+        cw->picture = get_window_picture (surface);
 
       if (cw->mask == None)
         cw->mask = get_window_mask (display, cw);
@@ -1702,11 +1698,6 @@ free_win (MetaCompWindow *cw,
   meta_error_trap_push (display);
 
   /* See comment in map_win */
-  if (cw->back_pixmap && destroy)
-    {
-      XFreePixmap (xdisplay, cw->back_pixmap);
-      cw->back_pixmap = None;
-    }
 
   if (cw->mask_pixmap && destroy)
     {
@@ -1807,11 +1798,6 @@ map_win (MetaCompositorXRender *xrender,
   /* The reason we deallocate this here and not in unmap
      is so that we will still have a valid pixmap for
      whenever the window is unmapped */
-  if (cw->back_pixmap)
-    {
-      XFreePixmap (xdisplay, cw->back_pixmap);
-      cw->back_pixmap = None;
-    }
 
   if (cw->mask_pixmap)
     {
@@ -1911,12 +1897,6 @@ notify_decorated_cb (MetaWindow            *window,
 
   meta_error_trap_push (window->display);
 
-  if (cw->back_pixmap != None)
-    {
-      XFreePixmap (xrender->xdisplay, cw->back_pixmap);
-      cw->back_pixmap = None;
-    }
-
   if (cw->mask_pixmap != None)
     {
       XFreePixmap (xrender->xdisplay, cw->mask_pixmap);
@@ -2001,6 +1981,7 @@ get_window_surface (MetaSurface *surface)
   MetaFrame *frame;
   MetaDisplay *display;
   Display *xdisplay;
+  Pixmap back_pixmap;
   XserverRegion xclient_region;
   cairo_region_t *client_region;
   cairo_surface_t *back_surface;
@@ -2013,7 +1994,8 @@ get_window_surface (MetaSurface *surface)
   display = meta_window_get_display (cw->window);
   xdisplay = meta_display_get_xdisplay (display);
 
-  if (cw->back_pixmap == None)
+  back_pixmap = meta_surface_get_pixmap (surface);
+  if (back_pixmap == None)
     return NULL;
 
   if (frame != NULL && cw->mask_pixmap == None)
@@ -2036,7 +2018,7 @@ get_window_surface (MetaSurface *surface)
   if (frame != NULL && client_region == NULL)
     return NULL;
 
-  back_surface = cairo_xlib_surface_create (xdisplay, cw->back_pixmap,
+  back_surface = cairo_xlib_surface_create (xdisplay, back_pixmap,
                                             get_toplevel_xvisual (cw->window),
                                             cw->rect.width, cw->rect.height);
 
@@ -2432,7 +2414,6 @@ meta_compositor_xrender_add_window (MetaCompositor *compositor,
                            G_CALLBACK (notify_shaded_cb),
                            surface, 0);
 
-  cw->back_pixmap = None;
   cw->mask_pixmap = None;
 
   cw->damaged = FALSE;
@@ -2775,12 +2756,6 @@ meta_compositor_xrender_sync_window_geometry (MetaCompositor *compositor,
 
   if (cw->rect.width != old_rect.width || cw->rect.height != old_rect.height)
     {
-      if (cw->back_pixmap != None)
-        {
-          XFreePixmap (xrender->xdisplay, cw->back_pixmap);
-          cw->back_pixmap = None;
-        }
-
       if (cw->mask_pixmap != None)
         {
           XFreePixmap (xrender->xdisplay, cw->mask_pixmap);
diff --git a/src/compositor/meta-compositor.c b/src/compositor/meta-compositor.c
index 723f050d..a6ae23c1 100644
--- a/src/compositor/meta-compositor.c
+++ b/src/compositor/meta-compositor.c
@@ -446,6 +446,7 @@ meta_compositor_show_window (MetaCompositor *compositor,
     return;
 
   compositor_class->show_window (compositor, surface, effect);
+  meta_surface_show (surface);
 }
 
 void
@@ -635,6 +636,7 @@ meta_compositor_sync_window_geometry (MetaCompositor *compositor,
     return;
 
   compositor_class->sync_window_geometry (compositor, surface);
+  meta_surface_sync_geometry (surface);
 }
 
 gboolean
diff --git a/src/compositor/meta-surface.c b/src/compositor/meta-surface.c
index c62633b2..88b32d2e 100644
--- a/src/compositor/meta-surface.c
+++ b/src/compositor/meta-surface.c
@@ -18,6 +18,8 @@
 #include "config.h"
 #include "meta-surface-private.h"
 
+#include <X11/extensions/Xcomposite.h>
+
 #include "display-private.h"
 #include "errors.h"
 #include "meta-compositor-private.h"
@@ -29,6 +31,10 @@ typedef struct
   MetaWindow     *window;
 
   Damage          damage;
+  Pixmap          pixmap;
+
+  int             width;
+  int             height;
 } MetaSurfacePrivate;
 
 enum
@@ -45,6 +51,53 @@ static GParamSpec *surface_properties[LAST_PROP] = { NULL };
 
 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaSurface, meta_surface, G_TYPE_OBJECT)
 
+static void
+free_pixmap (MetaSurface *self)
+{
+  MetaSurfacePrivate *priv;
+  MetaDisplay *display;
+  Display *xdisplay;
+
+  priv = meta_surface_get_instance_private (self);
+
+  if (priv->pixmap == None)
+    return;
+
+  display = meta_compositor_get_display (priv->compositor);
+  xdisplay = meta_display_get_xdisplay (display);
+
+  meta_error_trap_push (display);
+
+  XFreePixmap (xdisplay, priv->pixmap);
+  priv->pixmap = None;
+
+  meta_error_trap_pop (display);
+}
+
+static void
+ensure_pixmap (MetaSurface *self)
+{
+  MetaSurfacePrivate *priv;
+  MetaDisplay *display;
+  Display *xdisplay;
+  Window xwindow;
+
+  priv = meta_surface_get_instance_private (self);
+  display = meta_compositor_get_display (priv->compositor);
+  xdisplay = meta_display_get_xdisplay (display);
+
+  if (priv->pixmap != None)
+    return;
+
+  meta_error_trap_push (display);
+
+  xwindow = meta_window_get_toplevel_xwindow (priv->window);
+  priv->pixmap = XCompositeNameWindowPixmap (xdisplay, xwindow);
+
+  if (meta_error_trap_pop_with_return (display) != 0)
+    priv->pixmap = None;
+}
+
 static void
 destroy_damage (MetaSurface *self)
 {
@@ -95,6 +148,8 @@ notify_decorated_cb (MetaWindow  *window,
                      MetaSurface *self)
 {
   destroy_damage (self);
+  free_pixmap (self);
+
   create_damage (self);
 }
 
@@ -124,6 +179,7 @@ meta_surface_finalize (GObject *object)
   self = META_SURFACE (object);
 
   destroy_damage (self);
+  free_pixmap (self);
 
   G_OBJECT_CLASS (meta_surface_parent_class)->finalize (object);
 }
@@ -245,6 +301,45 @@ meta_surface_get_window (MetaSurface *self)
   return priv->window;
 }
 
+Pixmap
+meta_surface_get_pixmap (MetaSurface *self)
+{
+  MetaSurfacePrivate *priv;
+
+  priv = meta_surface_get_instance_private (self);
+
+  return priv->pixmap;
+}
+
+int
+meta_surface_get_width (MetaSurface *self)
+{
+  MetaSurfacePrivate *priv;
+
+  priv = meta_surface_get_instance_private (self);
+
+  return priv->width;
+}
+
+int
+meta_surface_get_height (MetaSurface *self)
+{
+  MetaSurfacePrivate *priv;
+
+  priv = meta_surface_get_instance_private (self);
+
+  return priv->height;
+}
+
+void
+meta_surface_show (MetaSurface *self)
+{
+  /* The reason we free pixmap here is so that we will still have
+   * a valid pixmap when the window is unmapped.
+   */
+  free_pixmap (self);
+}
+
 void
 meta_surface_process_damage (MetaSurface        *self,
                              XDamageNotifyEvent *event)
@@ -282,5 +377,27 @@ meta_surface_pre_paint (MetaSurface *self)
   meta_compositor_add_damage (priv->compositor, "meta_surface_pre_paint", parts);
   XFixesDestroyRegion (xdisplay, parts);
 
+  ensure_pixmap (self);
+
   META_SURFACE_GET_CLASS (self)->pre_paint (self);
 }
+
+void
+meta_surface_sync_geometry (MetaSurface *self)
+{
+  MetaSurfacePrivate *priv;
+  MetaRectangle rect;
+
+  priv = meta_surface_get_instance_private (self);
+
+  meta_window_get_input_rect (priv->window, &rect);
+
+  if (priv->width != rect.width ||
+      priv->height != rect.height)
+    {
+      free_pixmap (self);
+
+      priv->width = rect.width;
+      priv->height = rect.height;
+    }
+}
diff --git a/src/compositor/meta-surface.h b/src/compositor/meta-surface.h
index ab17b5db..d898ce59 100644
--- a/src/compositor/meta-surface.h
+++ b/src/compositor/meta-surface.h
@@ -31,11 +31,21 @@ MetaCompositor *meta_surface_get_compositor (MetaSurface        *self);
 
 MetaWindow     *meta_surface_get_window     (MetaSurface        *self);
 
+Pixmap          meta_surface_get_pixmap     (MetaSurface        *self);
+
+int             meta_surface_get_width      (MetaSurface        *self);
+
+int             meta_surface_get_height     (MetaSurface        *self);
+
+void            meta_surface_show           (MetaSurface        *self);
+
 void            meta_surface_process_damage (MetaSurface        *self,
                                              XDamageNotifyEvent *event);
 
 void            meta_surface_pre_paint      (MetaSurface        *self);
 
+void            meta_surface_sync_geometry  (MetaSurface        *self);
+
 G_END_DECLS
 
 #endif


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