[PATCH 3/4] glamor: Ask the server to always allocate our private.

Eric Anholt eric at anholt.net
Tue Jul 7 17:26:46 PDT 2015


This avoids a lot of screwing around to attach our privates later.  It
means that non-glamor pixmaps now gain 120 bytes of glamor privates on
64-bit (which has quite a bit of fixable bloat), and glamor pixmaps
take one less pointer of storage (not counting malloc overhead).

Note that privates start out zero-filled, which matches the callocs we
were doing when making our own privates, and in the case of an fb
pixmap that has a priv where it didn't before, the type ends up being
GLAMOR_MEMORY as we would want.

Signed-off-by: Eric Anholt <eric at anholt.net>
---
 glamor/glamor.c      | 43 ++++++-------------------------------------
 glamor/glamor_fbo.c  |  6 ++++--
 glamor/glamor_priv.h | 15 ++-------------
 3 files changed, 12 insertions(+), 52 deletions(-)

diff --git a/glamor/glamor.c b/glamor/glamor.c
index 50d85ff..2470a8d 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -80,12 +80,7 @@ glamor_set_pixmap_type(PixmapPtr pixmap, glamor_pixmap_type_t type)
 {
     glamor_pixmap_private *pixmap_priv;
 
-    pixmap_priv = dixLookupPrivate(&pixmap->devPrivates,
-                                   &glamor_pixmap_private_key);
-    if (pixmap_priv == NULL) {
-        pixmap_priv = calloc(sizeof(*pixmap_priv), 1);
-        glamor_set_pixmap_private(pixmap, pixmap_priv);
-    }
+    pixmap_priv = glamor_get_pixmap_private(pixmap);
     pixmap_priv->type = type;
     glamor_init_pixmap_private_small(pixmap, pixmap_priv);
 }
@@ -171,13 +166,7 @@ glamor_create_pixmap(ScreenPtr screen, int w, int h, int depth,
     else
         pixmap = fbCreatePixmap(screen, 0, 0, depth, usage);
 
-    pixmap_priv = calloc(1, sizeof(*pixmap_priv));
-
-    if (!pixmap_priv) {
-        fbDestroyPixmap(pixmap);
-        return fbCreatePixmap(screen, w, h, depth, usage);
-    }
-    glamor_set_pixmap_private(pixmap, pixmap_priv);
+    pixmap_priv = glamor_get_pixmap_private(pixmap);
 
     format = gl_iformat_for_pixmap(pixmap);
 
@@ -223,7 +212,7 @@ glamor_destroy_textured_pixmap(PixmapPtr pixmap)
 #if GLAMOR_HAS_GBM
             glamor_egl_destroy_pixmap_image(pixmap);
 #endif
-            glamor_set_pixmap_private(pixmap, NULL);
+            glamor_pixmap_destroy_fbo(pixmap);
         }
     }
 }
@@ -455,7 +444,8 @@ glamor_init(ScreenPtr screen, unsigned int flags)
 
     glamor_set_screen_private(screen, glamor_priv);
 
-    if (!dixRegisterPrivateKey(&glamor_pixmap_private_key, PRIVATE_PIXMAP, 0)) {
+    if (!dixRegisterPrivateKey(&glamor_pixmap_private_key, PRIVATE_PIXMAP,
+                               sizeof(struct glamor_pixmap_private))) {
         LogMessage(X_WARNING,
                    "glamor%d: Failed to allocate pixmap private\n",
                    screen->myNum);
@@ -705,27 +695,6 @@ glamor_release_screen_priv(ScreenPtr screen)
     glamor_set_screen_private(screen, NULL);
 }
 
-_X_EXPORT void
-glamor_set_pixmap_private(PixmapPtr pixmap, glamor_pixmap_private *priv)
-{
-    glamor_pixmap_private *old_priv;
-
-    old_priv = dixGetPrivate(&pixmap->devPrivates, &glamor_pixmap_private_key);
-
-    if (priv) {
-        assert(old_priv == NULL);
-    }
-    else {
-        if (old_priv == NULL)
-            return;
-        glamor_pixmap_destroy_fbo(glamor_get_screen_private(pixmap->drawable.pScreen),
-                                  old_priv);
-        free(old_priv);
-    }
-
-    dixSetPrivate(&pixmap->devPrivates, &glamor_pixmap_private_key, priv);
-}
-
 Bool
 glamor_close_screen(ScreenPtr screen)
 {
@@ -759,7 +728,7 @@ glamor_close_screen(ScreenPtr screen)
     screen->SetWindowPixmap = glamor_priv->saved_procs.set_window_pixmap;
 
     screen_pixmap = screen->GetScreenPixmap(screen);
-    glamor_set_pixmap_private(screen_pixmap, NULL);
+    glamor_pixmap_destroy_fbo(screen_pixmap);
 
     glamor_release_screen_priv(screen);
 
diff --git a/glamor/glamor_fbo.c b/glamor/glamor_fbo.c
index 84f3b22..1eee304 100644
--- a/glamor/glamor_fbo.c
+++ b/glamor/glamor_fbo.c
@@ -471,9 +471,11 @@ glamor_pixmap_attach_fbo(PixmapPtr pixmap, glamor_pixmap_fbo *fbo)
 }
 
 void
-glamor_pixmap_destroy_fbo(glamor_screen_private *glamor_priv,
-                          glamor_pixmap_private *priv)
+glamor_pixmap_destroy_fbo(PixmapPtr pixmap)
 {
+    ScreenPtr screen = pixmap->drawable.pScreen;
+    glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
+    glamor_pixmap_private *priv = glamor_get_pixmap_private(pixmap);
     glamor_pixmap_fbo *fbo;
 
     if (glamor_pixmap_priv_is_large(priv)) {
diff --git a/glamor/glamor_priv.h b/glamor/glamor_priv.h
index 66e5012..fe65d9b 100644
--- a/glamor/glamor_priv.h
+++ b/glamor/glamor_priv.h
@@ -405,22 +405,12 @@ extern DevPrivateKeyRec glamor_pixmap_private_key;
 static inline glamor_pixmap_private *
 glamor_get_pixmap_private(PixmapPtr pixmap)
 {
-    glamor_pixmap_private *priv;
-
     if (pixmap == NULL)
         return NULL;
 
-    priv = dixLookupPrivate(&pixmap->devPrivates, &glamor_pixmap_private_key);
-    if (!priv) {
-        glamor_set_pixmap_type(pixmap, GLAMOR_MEMORY);
-        priv = dixLookupPrivate(&pixmap->devPrivates,
-                                &glamor_pixmap_private_key);
-    }
-    return priv;
+    return dixLookupPrivate(&pixmap->devPrivates, &glamor_pixmap_private_key);
 }
 
-void glamor_set_pixmap_private(PixmapPtr pixmap, glamor_pixmap_private *priv);
-
 /*
  * Returns TRUE if pixmap has no image object
  */
@@ -590,8 +580,7 @@ glamor_pixmap_fbo *glamor_create_fbo(glamor_screen_private *glamor_priv, int w,
                                      int h, GLenum format, int flag);
 void glamor_destroy_fbo(glamor_screen_private *glamor_priv,
                         glamor_pixmap_fbo *fbo);
-void glamor_pixmap_destroy_fbo(glamor_screen_private *glamor_priv,
-                               glamor_pixmap_private *priv);
+void glamor_pixmap_destroy_fbo(PixmapPtr pixmap);
 void glamor_init_pixmap_fbo(ScreenPtr screen);
 void glamor_fini_pixmap_fbo(ScreenPtr screen);
 Bool glamor_pixmap_fbo_fixup(ScreenPtr screen, PixmapPtr pixmap);
-- 
2.1.4



More information about the xorg-devel mailing list