    This makes fbCreatePixmap and fbDestroyPixmap call fbPrepareAccess and
    fbDestroyAccess (respectively) when the pixmap usage hint is
    CREATE_PIXMAP_USAGE_SCRATCH.
    
    This fixes a bug where some mi functions create a scratch pixmap but
    can't call fbPrepareAccess by themselves.
    
    Signed-off-by: Renato Caldas <seventhguardian at gmail dot com>

diff --git a/fb/fbpixmap.c b/fb/fbpixmap.c
index 311da9e..12f6321 100644
--- a/fb/fbpixmap.c
+++ b/fb/fbpixmap.c
@@ -79,6 +79,11 @@ fbCreatePixmapBpp (ScreenPtr pScreen, int width, int height, int depth, int bpp,
 
     pPixmap->usage_hint = usage_hint;
 
+    /* some mi operations create a scratch pixmap, but they can't call
+     * fbPrepareAccess by themselves. Do it here instead. */
+    if (usage_hint == CREATE_PIXMAP_USAGE_SCRATCH)
+        fbPrepareAccess(&pPixmap->drawable);
+
     return pPixmap;
 }
 
@@ -100,6 +105,8 @@ fbDestroyPixmap (PixmapPtr pPixmap)
 {
     if(--pPixmap->refcnt)
 	return TRUE;
+    if (pPixmap->usage_hint == CREATE_PIXMAP_USAGE_SCRATCH)
+        fbFinishAccess(&pPixmap->drawable);
     dixFreePrivates(pPixmap->devPrivates);
     xfree(pPixmap);
     return TRUE;
