[PATCH] XftDrawSrcPicture: Use XRenderCreateSolidFill when available

Keith Packard keithp at keithp.com
Sun Oct 19 17:40:24 PDT 2014


Instead of creating 1x1 pictures, use the solid pictures added in
Render version 0.10

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 src/xftdpy.c  |  4 ++++
 src/xftdraw.c | 71 +++++++++++++++++++++++++++++++++++------------------------
 src/xftint.h  |  1 +
 3 files changed, 47 insertions(+), 29 deletions(-)

diff --git a/src/xftdpy.c b/src/xftdpy.c
index c5b756e..62b1ccf 100644
--- a/src/xftdpy.c
+++ b/src/xftdpy.c
@@ -106,6 +106,10 @@ _XftDisplayInfoGet (Display *dpy, FcBool createIfNecessary)
 	if (major < 0 || (major == 0 && minor <= 2))
 	    info->use_free_glyphs = FcFalse;
 
+	info->hasSolid = FcFalse;
+	if (major > 0 || (major == 0 && minor >= 10))
+	    info->hasSolid = FcTrue;
+
 	pf.type = PictTypeDirect;
 	pf.depth = 32;
 	pf.direct.redMask = 0xff;
diff --git a/src/xftdraw.c b/src/xftdraw.c
index 186bcb8..dfa97fb 100644
--- a/src/xftdraw.c
+++ b/src/xftdraw.c
@@ -333,39 +333,52 @@ XftDrawSrcPicture (XftDraw *draw, _Xconst XftColor *color)
      * Pick one to replace at random
      */
     i = (unsigned int) rand () % XFT_NUM_SOLID_COLOR;
-    /*
-     * Recreate if it was for the wrong screen
-     */
-    if (info->colors[i].screen != draw->screen && info->colors[i].pict)
-    {
-	XRenderFreePicture (dpy, info->colors[i].pict);
-	info->colors[i].pict = 0;
-    }
-    /*
-     * Create picture if necessary
-     */
-    if (!info->colors[i].pict)
-    {
-	Pixmap			    pix;
-        XRenderPictureAttributes    pa;
 
-	pix = XCreatePixmap (dpy, RootWindow (dpy, draw->screen), 1, 1,
-			     info->solidFormat->depth);
-	pa.repeat = True;
-	info->colors[i].pict = XRenderCreatePicture (draw->dpy,
-						     pix,
-						     info->solidFormat,
-						     CPRepeat, &pa);
-	XFreePixmap (dpy, pix);
+    if (info->hasSolid) {
+	/*
+	 * Free any existing entry
+	 */
+	if (info->colors[i].pict)
+	    XRenderFreePicture (dpy, info->colors[i].pict);
+	/*
+	 * Create picture
+	 */
+	info->colors[i].pict = XRenderCreateSolidFill (draw->dpy, &color->color);
+    } else {
+	if (info->colors[i].screen != draw->screen && info->colors[i].pict)
+	{
+	    XRenderFreePicture (dpy, info->colors[i].pict);
+	    info->colors[i].pict = 0;
+	}
+	/*
+	 * Create picture if necessary
+	 */
+	if (!info->colors[i].pict)
+	{
+	    Pixmap			    pix;
+	    XRenderPictureAttributes    pa;
+
+	    pix = XCreatePixmap (dpy, RootWindow (dpy, draw->screen), 1, 1,
+				 info->solidFormat->depth);
+	    pa.repeat = True;
+	    info->colors[i].pict = XRenderCreatePicture (draw->dpy,
+							 pix,
+							 info->solidFormat,
+							 CPRepeat, &pa);
+	    XFreePixmap (dpy, pix);
+	}
+	/*
+	 * Set to the new color
+	 */
+	info->colors[i].color = color->color;
+	info->colors[i].screen = draw->screen;
+	XRenderFillRectangle (dpy, PictOpSrc,
+			      info->colors[i].pict,
+			      &color->color, 0, 0, 1, 1);
     }
-    /*
-     * Set to the new color
-     */
     info->colors[i].color = color->color;
     info->colors[i].screen = draw->screen;
-    XRenderFillRectangle (dpy, PictOpSrc,
-			  info->colors[i].pict,
-			  &color->color, 0, 0, 1, 1);
+
     return info->colors[i].pict;
 }
 
diff --git a/src/xftint.h b/src/xftint.h
index 1658977..c06ac3c 100644
--- a/src/xftint.h
+++ b/src/xftint.h
@@ -245,6 +245,7 @@ typedef struct _XftDisplayInfo {
     XExtCodes		    *codes;
     FcPattern		    *defaults;
     FcBool		    hasRender;
+    FcBool		    hasSolid;
     XftFont		    *fonts;
     XRenderPictFormat	    *solidFormat;
     unsigned long	    glyph_memory;
-- 
2.1.1



More information about the xorg-devel mailing list