From eae4cffc9df3b79475f56f91bffc7e68914bfe72 Mon Sep 17 00:00:00 2001
From: Roderick Colenbrander <thunderbird2k@gmail.com>
Date: Tue, 6 Oct 2009 20:56:06 +0200
Subject: [PATCH] Introduce xrender_get_picture to retrieve a XRender picture for a physDev and which creates one if needed.

---
 dlls/winex11.drv/xrender.c |   73 +++++++++++++++++++++++++++-----------------
 1 files changed, 45 insertions(+), 28 deletions(-)

diff --git a/dlls/winex11.drv/xrender.c b/dlls/winex11.drv/xrender.c
index f8933e9..5b00af9 100644
--- a/dlls/winex11.drv/xrender.c
+++ b/dlls/winex11.drv/xrender.c
@@ -482,6 +482,37 @@ static WineXRenderFormat *get_xrender_format_from_color_shifts(int depth, ColorS
     return NULL;
 }
 
+static Picture get_xrender_picture(X11DRV_PDEVICE *physDev)
+{
+    XRENDERINFO info = get_xrender_info(physDev);
+    if(!info)
+    {
+        ERR("Unable to obtain xrender info!\n");
+        return 0;
+    }
+
+    if(!info->pict)
+    {
+        WineXRenderFormat *fmt;
+        XRenderPictureAttributes pa;
+        pa.subwindow_mode = IncludeInferiors;
+
+        fmt = get_xrender_format_from_color_shifts(physDev->depth, physDev->color_shifts);
+        if(!fmt)
+        {
+            ERR("No xrender format found for physDev=%p, expect issues!\n", physDev);
+            return 0;
+        }
+
+        wine_tsx11_lock();
+        info->pict = pXRenderCreatePicture(gdi_display, physDev->drawable, fmt->pict_format, CPSubwindowMode, &pa);
+        wine_tsx11_unlock();
+
+        TRACE("Allocing pict = %lx dc = %p drawable = %08lx fmt=%#x\n", info->pict, physDev->hdc, physDev->drawable, fmt->format);
+    }
+    return info->pict;
+}
+
 static BOOL fontcmp(LFANDSIZE *p1, LFANDSIZE *p2)
 {
   if(p1->hash != p2->hash) return TRUE;
@@ -1438,7 +1469,6 @@ BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flag
     gsCacheEntry *entry;
     gsCacheEntryFormat *formatEntry;
     BOOL retv = FALSE;
-    HDC hdc = physDev->hdc;
     int textPixel, backgroundPixel;
     HRGN saved_region = 0;
     BOOL disable_antialias = FALSE;
@@ -1519,33 +1549,19 @@ BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flag
         DeleteObject( clip_region );
     }
 
-    if(X11DRV_XRender_Installed) {
-        if(!physDev->xrender->pict) {
-	    XRenderPictureAttributes pa;
-	    pa.subwindow_mode = IncludeInferiors;
-
-	    wine_tsx11_lock();
-	    physDev->xrender->pict = pXRenderCreatePicture(gdi_display,
-							   physDev->drawable, dst_format->pict_format,
-							   CPSubwindowMode, &pa);
-	    wine_tsx11_unlock();
-
-	    TRACE("allocing pict = %lx dc = %p drawable = %08lx\n",
-                  physDev->xrender->pict, hdc, physDev->drawable);
-	} else {
-	    TRACE("using existing pict = %lx dc = %p drawable = %08lx\n",
-                  physDev->xrender->pict, hdc, physDev->drawable);
-	}
+    if(X11DRV_XRender_Installed)
+    {
+        Picture pict = get_xrender_picture(physDev);
 
-	if ((data = X11DRV_GetRegionData( physDev->region, 0 )))
-	{
-	    wine_tsx11_lock();
-	    pXRenderSetPictureClipRectangles( gdi_display, physDev->xrender->pict,
-					      physDev->dc_rect.left, physDev->dc_rect.top,
-					      (XRectangle *)data->Buffer, data->rdh.nCount );
-	    wine_tsx11_unlock();
-	    HeapFree( GetProcessHeap(), 0, data );
-	}
+        if ((data = X11DRV_GetRegionData( physDev->region, 0 )))
+        {
+            wine_tsx11_lock();
+            pXRenderSetPictureClipRectangles( gdi_display, pict,
+                            physDev->dc_rect.left, physDev->dc_rect.top,
+                            (XRectangle *)data->Buffer, data->rdh.nCount );
+            wine_tsx11_unlock();
+            HeapFree( GetProcessHeap(), 0, data );
+        }
     }
 
     EnterCriticalSection(&xrender_cs);
@@ -1582,6 +1598,7 @@ BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flag
         INT offset = 0;
         POINT desired, current;
         int render_op = PictOpOver;
+        Picture pict = get_xrender_picture(physDev);
 
         /* There's a bug in XRenderCompositeText that ignores the xDst and yDst parameters.
            So we pass zeros to the function and move to our starting position using the first
@@ -1624,7 +1641,7 @@ BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flag
         wine_tsx11_lock();
         pXRenderCompositeText16(gdi_display, render_op,
                                 tile_pict,
-                                physDev->xrender->pict,
+                                pict,
                                 formatEntry->font_format->pict_format,
                                 0, 0, 0, 0, elts, count);
         wine_tsx11_unlock();
-- 
1.6.0.4

