[metacity] compositor-xrender: move picture to MetaSurfaceXRender



commit 887153ee9ad8485845bc70b1a11437c10425af18
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Oct 6 16:29:52 2019 +0300

    compositor-xrender: move picture to MetaSurfaceXRender

 src/compositor/meta-compositor-xrender.c |  95 ++++----------------------
 src/compositor/meta-surface-private.h    |   4 +-
 src/compositor/meta-surface-vulkan.c     |   6 ++
 src/compositor/meta-surface-xrender.c    | 110 +++++++++++++++++++++++++++++++
 src/compositor/meta-surface-xrender.h    |   3 +
 src/compositor/meta-surface.c            |   2 +
 6 files changed, 135 insertions(+), 85 deletions(-)
---
diff --git a/src/compositor/meta-compositor-xrender.c b/src/compositor/meta-compositor-xrender.c
index be012257..d0c1f902 100644
--- a/src/compositor/meta-compositor-xrender.c
+++ b/src/compositor/meta-compositor-xrender.c
@@ -100,7 +100,6 @@ typedef struct _MetaCompWindow
 
   XserverRegion shape_region;
 
-  Picture picture;
   Picture mask;
   Picture alpha_pict;
 
@@ -1200,63 +1199,6 @@ get_visible_region (MetaDisplay    *display,
   return region;
 }
 
-static XRenderPictFormat *
-get_window_format (Display        *xdisplay,
-                   MetaCompWindow *cw)
-{
-  XRenderPictFormat *format;
-
-  format = XRenderFindVisualFormat (xdisplay, get_toplevel_xvisual (cw->window));
-
-  if (!format)
-    {
-      Visual *visual;
-
-      visual = DefaultVisual (xdisplay, DefaultScreen (xdisplay));
-      format = XRenderFindVisualFormat (xdisplay, visual);
-    }
-
-  return format;
-}
-
-static Picture
-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);
-
-  back_pixmap = meta_surface_get_pixmap (surface);
-
-  format = get_window_format (xdisplay, cw);
-  if (format)
-    {
-      Drawable draw;
-      Picture pict;
-
-      draw = back_pixmap != None ? back_pixmap : xwindow;
-      pa.subwindow_mode = IncludeInferiors;
-
-      meta_error_trap_push (display);
-      pict = XRenderCreatePicture (xdisplay, draw, format, CPSubwindowMode, &pa);
-      meta_error_trap_pop (display);
-
-      return pict;
-    }
-
-  return None;
-}
-
 static Picture
 get_window_mask (MetaDisplay    *display,
                  MetaCompWindow *cw)
@@ -1421,6 +1363,7 @@ paint_windows (MetaCompositorXRender *xrender,
   for (index = surfaces; index; index = index->next)
     {
       MetaSurface *surface;
+      Picture picture;
 
       /* Store the last window we dealt with */
       last = index;
@@ -1437,8 +1380,7 @@ paint_windows (MetaCompositorXRender *xrender,
       if (!meta_window_is_toplevel_mapped (cw->window))
         continue;
 
-      if (cw->picture == None)
-        cw->picture = get_window_picture (surface);
+      picture = meta_surface_xrender_get_picture (META_SURFACE_XRENDER (surface));
 
       if (cw->mask == None)
         cw->mask = get_window_mask (display, cw);
@@ -1471,7 +1413,7 @@ paint_windows (MetaCompositorXRender *xrender,
 
           XFixesSetPictureClipRegion (xdisplay, root_buffer,
                                       0, 0, paint_region);
-          XRenderComposite (xdisplay, PictOpSrc, cw->picture, None, root_buffer,
+          XRenderComposite (xdisplay, PictOpSrc, picture, None, root_buffer,
                             borders.total.left, borders.total.top, 0, 0,
                             x + borders.total.left, y + borders.total.top,
                             wid - borders.total.left - borders.total.right,
@@ -1517,11 +1459,14 @@ paint_windows (MetaCompositorXRender *xrender,
   for (index = last; index; index = index->prev)
     {
       MetaSurface *surface;
+      Picture picture;
 
       surface = META_SURFACE (index->data);
       cw = g_object_get_data (G_OBJECT (surface), "cw");
 
-      if (cw->picture)
+      picture = meta_surface_xrender_get_picture (META_SURFACE_XRENDER (surface));
+
+      if (picture)
         {
           int x, y, wid, hei;
 
@@ -1567,7 +1512,7 @@ paint_windows (MetaCompositorXRender *xrender,
                                 cw->alpha_pict, root_buffer, 0, 0, 0, 0,
                                 x, y, wid, hei);
 
-              XRenderComposite (xdisplay, PictOpAdd, cw->picture,
+              XRenderComposite (xdisplay, PictOpAdd, picture,
                                 cw->alpha_pict, root_buffer, 0, 0, 0, 0,
                                 x, y, wid, hei);
             }
@@ -1586,14 +1531,14 @@ paint_windows (MetaCompositorXRender *xrender,
                                 cw->alpha_pict, root_buffer, 0, 0, 0, 0,
                                 x, y, wid, hei);
 
-              XRenderComposite (xdisplay, PictOpAdd, cw->picture,
+              XRenderComposite (xdisplay, PictOpAdd, picture,
                                 cw->alpha_pict, root_buffer, 0, 0, 0, 0,
                                 x, y, wid, hei);
 
               XFixesIntersectRegion (xdisplay, clip, cw->border_clip, client);
               XFixesSetPictureClipRegion (xdisplay, root_buffer, 0, 0, clip);
 
-              XRenderComposite (xdisplay, PictOpOver, cw->picture,
+              XRenderComposite (xdisplay, PictOpOver, picture,
                                 cw->alpha_pict, root_buffer, 0, 0, 0, 0,
                                 x, y, wid, hei);
 
@@ -1602,7 +1547,7 @@ paint_windows (MetaCompositorXRender *xrender,
             }
           else if (cw->mode == WINDOW_ARGB && cw->mask == None)
             {
-              XRenderComposite (xdisplay, PictOpOver, cw->picture,
+              XRenderComposite (xdisplay, PictOpOver, picture,
                                 cw->alpha_pict, root_buffer, 0, 0, 0, 0,
                                 x, y, wid, hei);
             }
@@ -1711,12 +1656,6 @@ free_win (MetaCompWindow *cw,
       cw->shape_region = None;
     }
 
-  if (cw->picture)
-    {
-      XRenderFreePicture (xdisplay, cw->picture);
-      cw->picture = None;
-    }
-
   if (cw->mask)
     {
       XRenderFreePicture (xdisplay, cw->mask);
@@ -1909,12 +1848,6 @@ notify_decorated_cb (MetaWindow            *window,
       cw->shape_region = None;
     }
 
-  if (cw->picture != None)
-    {
-      XRenderFreePicture (xrender->xdisplay, cw->picture);
-      cw->picture = None;
-    }
-
   if (cw->mask != None)
     {
       XRenderFreePicture (xrender->xdisplay, cw->mask);
@@ -2762,12 +2695,6 @@ meta_compositor_xrender_sync_window_geometry (MetaCompositor *compositor,
           cw->mask_pixmap = None;
         }
 
-      if (cw->picture != None)
-        {
-          XRenderFreePicture (xrender->xdisplay, cw->picture);
-          cw->picture = None;
-        }
-
       if (cw->mask != None)
         {
           XRenderFreePicture (xrender->xdisplay, cw->mask);
diff --git a/src/compositor/meta-surface-private.h b/src/compositor/meta-surface-private.h
index 6d9a5d64..5eccbc31 100644
--- a/src/compositor/meta-surface-private.h
+++ b/src/compositor/meta-surface-private.h
@@ -26,7 +26,9 @@ struct _MetaSurfaceClass
 {
   GObjectClass parent_class;
 
-  void (* pre_paint) (MetaSurface *self);
+  void (* free_pixmap) (MetaSurface *self);
+
+  void (* pre_paint)   (MetaSurface *self);
 };
 
 G_END_DECLS
diff --git a/src/compositor/meta-surface-vulkan.c b/src/compositor/meta-surface-vulkan.c
index 626b3405..0935aeb5 100644
--- a/src/compositor/meta-surface-vulkan.c
+++ b/src/compositor/meta-surface-vulkan.c
@@ -25,6 +25,11 @@ struct _MetaSurfaceVulkan
 
 G_DEFINE_TYPE (MetaSurfaceVulkan, meta_surface_vulkan, META_TYPE_SURFACE)
 
+static void
+meta_surface_vulkan_free_pixmap (MetaSurface *surface)
+{
+}
+
 static void
 meta_surface_vulkan_pre_paint (MetaSurface *surface)
 {
@@ -37,6 +42,7 @@ meta_surface_vulkan_class_init (MetaSurfaceVulkanClass *self_class)
 
   surface_class = META_SURFACE_CLASS (self_class);
 
+  surface_class->free_pixmap = meta_surface_vulkan_free_pixmap;
   surface_class->pre_paint = meta_surface_vulkan_pre_paint;
 }
 
diff --git a/src/compositor/meta-surface-xrender.c b/src/compositor/meta-surface-xrender.c
index f4c88841..a6e95e2b 100644
--- a/src/compositor/meta-surface-xrender.c
+++ b/src/compositor/meta-surface-xrender.c
@@ -18,25 +18,129 @@
 #include "config.h"
 #include "meta-surface-xrender.h"
 
+#include "display.h"
+#include "errors.h"
+
 struct _MetaSurfaceXRender
 {
   MetaSurface parent;
+
+  Picture     picture;
 };
 
 G_DEFINE_TYPE (MetaSurfaceXRender, meta_surface_xrender, META_TYPE_SURFACE)
 
+static void
+free_picture (MetaSurfaceXRender *self)
+{
+  MetaWindow *window;
+  MetaDisplay *display;
+  Display *xdisplay;
+
+  if (self->picture == None)
+    return;
+
+  window = meta_surface_get_window (META_SURFACE (self));
+
+  display = meta_window_get_display (window);
+  xdisplay = meta_display_get_xdisplay (display);
+
+  XRenderFreePicture (xdisplay, self->picture);
+  self->picture = None;
+}
+
+static Picture
+get_window_picture (MetaSurfaceXRender *self)
+{
+  MetaWindow *window;
+  MetaDisplay *display;
+  Display *xdisplay;
+  Window xwindow;
+  Visual *xvisual;
+  XRenderPictFormat *format;
+  Pixmap pixmap;
+  Drawable drawable;
+  XRenderPictureAttributes pa;
+  unsigned int pa_mask;
+  Picture picture;
+
+  window = meta_surface_get_window (META_SURFACE (self));
+
+  display = meta_window_get_display (window);
+  xdisplay = meta_display_get_xdisplay (display);
+
+  xwindow = meta_window_get_toplevel_xwindow (window);
+  xvisual = meta_window_get_toplevel_xvisual (window);
+
+  format = XRenderFindVisualFormat (xdisplay, xvisual);
+
+  if (format == NULL)
+    {
+      xvisual = DefaultVisual (xdisplay, DefaultScreen (xdisplay));
+      format = XRenderFindVisualFormat (xdisplay, xvisual);
+    }
+
+  if (format == NULL)
+    return None;
+
+  pixmap = meta_surface_get_pixmap (META_SURFACE (self));
+  drawable = pixmap != None ? pixmap : xwindow;
+
+  pa.subwindow_mode = IncludeInferiors;
+  pa_mask = CPSubwindowMode;
+
+  meta_error_trap_push (display);
+  picture = XRenderCreatePicture (xdisplay, drawable, format, pa_mask, &pa);
+  meta_error_trap_pop (display);
+
+  return picture;
+}
+
+static void
+meta_surface_xrender_finalize (GObject *object)
+{
+  MetaSurfaceXRender *self;
+
+  self = META_SURFACE_XRENDER (object);
+
+  free_picture (self);
+
+  G_OBJECT_CLASS (meta_surface_xrender_parent_class)->finalize (object);
+}
+
+static void
+meta_surface_xrender_free_pixmap (MetaSurface *surface)
+{
+  MetaSurfaceXRender *self;
+
+  self = META_SURFACE_XRENDER (surface);
+
+  free_picture (self);
+}
+
 static void
 meta_surface_xrender_pre_paint (MetaSurface *surface)
 {
+  MetaSurfaceXRender *self;
+
+  self = META_SURFACE_XRENDER (surface);
+
+  if (self->picture == None)
+    self->picture = get_window_picture (self);
 }
 
 static void
 meta_surface_xrender_class_init (MetaSurfaceXRenderClass *self_class)
 {
+  GObjectClass *object_class;
   MetaSurfaceClass *surface_class;
 
+  object_class = G_OBJECT_CLASS (self_class);
   surface_class = META_SURFACE_CLASS (self_class);
 
+  object_class->finalize = meta_surface_xrender_finalize;
+
+  surface_class->free_pixmap = meta_surface_xrender_free_pixmap;
   surface_class->pre_paint = meta_surface_xrender_pre_paint;
 }
 
@@ -44,3 +148,9 @@ static void
 meta_surface_xrender_init (MetaSurfaceXRender *self)
 {
 }
+
+Picture
+meta_surface_xrender_get_picture (MetaSurfaceXRender *self)
+{
+  return self->picture;
+}
diff --git a/src/compositor/meta-surface-xrender.h b/src/compositor/meta-surface-xrender.h
index d6f13ef1..022a8d89 100644
--- a/src/compositor/meta-surface-xrender.h
+++ b/src/compositor/meta-surface-xrender.h
@@ -18,6 +18,7 @@
 #ifndef META_SURFACE_XRENDER_H
 #define META_SURFACE_XRENDER_H
 
+#include <X11/extensions/Xrender.h>
 #include "meta-surface-private.h"
 
 G_BEGIN_DECLS
@@ -26,6 +27,8 @@ G_BEGIN_DECLS
 G_DECLARE_FINAL_TYPE (MetaSurfaceXRender, meta_surface_xrender,
                       META, SURFACE_XRENDER, MetaSurface)
 
+Picture meta_surface_xrender_get_picture (MetaSurfaceXRender *self);
+
 G_END_DECLS
 
 #endif
diff --git a/src/compositor/meta-surface.c b/src/compositor/meta-surface.c
index 88b32d2e..e5a5492a 100644
--- a/src/compositor/meta-surface.c
+++ b/src/compositor/meta-surface.c
@@ -66,6 +66,8 @@ free_pixmap (MetaSurface *self)
   display = meta_compositor_get_display (priv->compositor);
   xdisplay = meta_display_get_xdisplay (display);
 
+  META_SURFACE_GET_CLASS (self)->free_pixmap (self);
+
   meta_error_trap_push (display);
 
   XFreePixmap (xdisplay, priv->pixmap);


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