File u_Change-shadow-fb-implementation-from-DDX-based-to-miext-damage-based.patch of Package xf86-video-mga

From: Egbert Eich <eich@freedesktop.org>
Date: Tue May 6 16:31:19 2014 +0200
Subject: [PATCH]Change shadow fb implementation from DDX based to miext/damage based
Patch-mainline: to be upstreamed
Git-commit: 2ef052a4baaed2d9fcc5e607a4673116b19c16b5
Git-repo: ssh://git.freedesktop.org/git/xorg/driver/xf86-video-mga
References: bnc#876098
Signed-off-by: Egbert Eich <eich@suse.com>

This fixes rendering artefacts with antialiased font drawing and
gets rid of some code.

Signed-off-by: Egbert Eich <eich@freedesktop.org>
---
 src/mga.h        |  12 +--
 src/mga_driver.c |  70 ++++++++-------
 src/mga_shadow.c | 266 +++++++++++--------------------------------------------
 3 files changed, 94 insertions(+), 254 deletions(-)

diff --git a/src/mga.h b/src/mga.h
index 5f75d37..3334331 100644
--- a/src/mga.h
+++ b/src/mga.h
@@ -545,7 +545,6 @@ typedef struct {
     Bool		ShowCache;
     Bool		ShadowFB;
     unsigned char *	ShadowPtr;
-    int			ShadowPitch;
     int			MemClk;
     int			MinClock;
     int			MaxClock;
@@ -582,6 +581,8 @@ typedef struct {
     void		(*PointerMoved)(SCRN_ARG_TYPE arg, int x, int y);
     CloseScreenProcPtr	CloseScreen;
     ScreenBlockHandlerProcPtr BlockHandler;
+/* shadowfb */
+    CreateScreenResourcesProcPtr	CreateScreenResources;
     unsigned int	(*ddc1Read)(ScrnInfoPtr);
     void (*DDC1SetSpeed)(ScrnInfoPtr, xf86ddcSpeed);
     Bool		(*i2cInit)(ScrnInfoPtr);
@@ -751,19 +752,14 @@ void MGAPolyArcThinSolid(DrawablePtr, GCPtr, int, xArc*);
 
 Bool MGADGAInit(ScreenPtr pScreen);
 
-void MGARefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
-void MGARefreshArea8(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
-void MGARefreshArea16(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
-void MGARefreshArea24(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
-void MGARefreshArea32(ScrnInfoPtr pScrn, int num, BoxPtr pbox);
-
 void mgaDoSetupForScreenToScreenCopy( ScrnInfoPtr pScrn, int xdir,
     int ydir, int rop, unsigned int planemask, int trans, unsigned int bpp );
 
 void mgaDoSetupForSolidFill( ScrnInfoPtr pScrn, int color, int rop,
     unsigned int planemask, unsigned int bpp );
 
-void MGAPointerMoved(SCRN_ARG_TYPE arg, int x, int y);
+Bool MGAShadowInit(ScreenPtr pScreen);
+void MGAShadowPointerMoved(SCRN_ARG_TYPE arg, int x, int y);
 
 void MGAInitVideo(ScreenPtr pScreen);
 void MGAResetVideo(ScrnInfoPtr pScrn);
diff --git a/src/mga_driver.c b/src/mga_driver.c
index 46478a6..08c836d 100644
--- a/src/mga_driver.c
+++ b/src/mga_driver.c
@@ -92,7 +92,7 @@
 #endif
 
 #include "xf86cmap.h"
-#include "shadowfb.h"
+#include "shadow.h"
 #include "fbdevhw.h"
 
 #ifdef MGADRI
@@ -2109,7 +2109,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags)
                 pMga->ShadowFB = TRUE;
                 pMga->NoAccel = TRUE;
                 pMga->HWCursor = FALSE;
-                pMga->Rotate = 1;
+                pMga->Rotate = 270;
                 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
                         "Rotating screen clockwise - acceleration disabled\n");
             } else
@@ -2117,10 +2117,17 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags)
                 pMga->ShadowFB = TRUE;
                 pMga->NoAccel = TRUE;
                 pMga->HWCursor = FALSE;
-                pMga->Rotate = -1;
+                pMga->Rotate = 90;
                 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
                         "Rotating screen counter clockwise - acceleration disabled\n");
-            } else {
+            } else if(!xf86NameCmp(s, "UD")) {
+                pMga->ShadowFB = TRUE;
+                pMga->NoAccel = TRUE;
+                pMga->HWCursor = FALSE;
+                pMga->Rotate = 180;
+                xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
+                        "Rotating screen upside down - acceleration disabled\n");
+	    } else {
                 xf86DrvMsg(pScrn->scrnIndex, X_CONFIG,
                         "\"%s\" is not a valid value for Option \"Rotate\"\n", s);
                 xf86DrvMsg(pScrn->scrnIndex, X_INFO,
@@ -2141,6 +2148,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags)
 		           "Falling back to shadowfb\n");
 		pMga->ShadowFB = TRUE;
 		pMga->NoAccel = TRUE;
+                pMga->HWCursor = FALSE;
 	    }
 	} else {
 #endif
@@ -2150,6 +2158,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags)
 		           "Falling back to shadowfb\n");
 		pMga->ShadowFB = TRUE;
 		pMga->NoAccel = TRUE;
+                pMga->HWCursor = FALSE;
 	    }
 #endif
 #ifdef USE_EXA
@@ -2662,7 +2671,7 @@ MGAPreInit(ScrnInfoPtr pScrn, int flags)
 
     /* Load shadowfb if needed */
     if (pMga->ShadowFB) {
-	if (!xf86LoadSubModule(pScrn, "shadowfb")) {
+	if (!xf86LoadSubModule(pScrn, "shadow")) {
 	    MGAFreeRec(pScrn);
 	    return FALSE;
 	}
@@ -3207,7 +3216,6 @@ MGACrtc2FillStrip(ScrnInfoPtr pScrn)
     }
 }
 
-
 /* Mandatory */
 
 /* This gets called at the start of each server generation */
@@ -3391,9 +3399,8 @@ MGAScreenInit(SCREEN_INIT_ARGS_DECL)
     }
 
     if(pMga->ShadowFB) {
- 	pMga->ShadowPitch = BitmapBytePad(pScrn->bitsPerPixel * width);
-	pMga->ShadowPtr = malloc(pMga->ShadowPitch * height);
-	displayWidth = pMga->ShadowPitch / (pScrn->bitsPerPixel >> 3);
+	pMga->ShadowPtr = (unsigned char *)xnfcalloc(1, width * height *
+                                                     (pScrn->bitsPerPixel >> 3));
         FBStart = pMga->ShadowPtr;
     } else {
 	pMga->ShadowPtr = NULL;
@@ -3436,7 +3443,7 @@ MGAScreenInit(SCREEN_INIT_ARGS_DECL)
 	  "Static buffer allocation failed, not initializing the DRI\n");
        xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 	  "Need at least %d kB video memory at this resolution, bit depth\n",
-	  (3 * displayWidth * height * (pScrn->bitsPerPixel >> 3)) / 1024 );
+          (3 * pScrn->displayWidth * height * (pScrn->bitsPerPixel >> 3)) / 1024 );
        pMga->directRenderingEnabled = FALSE;
        driFrom = X_PROBED;
     }
@@ -3447,7 +3454,7 @@ MGAScreenInit(SCREEN_INIT_ARGS_DECL)
 
 
     if (!fbScreenInit(pScreen, FBStart, width, height, pScrn->xDpi,
-		      pScrn->yDpi, displayWidth, pScrn->bitsPerPixel)) {
+		      pScrn->yDpi, pScrn->displayWidth, pScrn->bitsPerPixel)) {
 	return FALSE;
     }
 
@@ -3470,6 +3477,20 @@ MGAScreenInit(SCREEN_INIT_ARGS_DECL)
     /* must be after RGB ordering fixed */
     fbPictureInit (pScreen, 0, 0);
 
+    if (pMga->ShadowFB) {
+	if(pMga->Rotate) {
+	    if (!pMga->PointerMoved) {
+	    pMga->PointerMoved = pScrn->PointerMoved;
+	    pScrn->PointerMoved = MGAShadowPointerMoved;
+	    }
+	}
+        if (!MGAShadowInit(pScreen)) {
+            xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+                       "shadow framebuffer initialization failed\n");
+            return FALSE;
+        }
+    }
+
     xf86SetBlackWhitePixels(pScreen);
 
     pMga->BlockHandler = pScreen->BlockHandler;
@@ -3526,26 +3547,6 @@ MGAScreenInit(SCREEN_INIT_ARGS_DECL)
 	NULL, f))
 	return FALSE;
 
-    if(pMga->ShadowFB) {
-	RefreshAreaFuncPtr refreshArea = MGARefreshArea;
-
-	if(pMga->Rotate) {
-	    if (!pMga->PointerMoved) {
-	    pMga->PointerMoved = pScrn->PointerMoved;
-	    pScrn->PointerMoved = MGAPointerMoved;
-	    }
-
-	   switch(pScrn->bitsPerPixel) {
-	   case 8:	refreshArea = MGARefreshArea8;	break;
-	   case 16:	refreshArea = MGARefreshArea16;	break;
-	   case 24:	refreshArea = MGARefreshArea24;	break;
-	   case 32:	refreshArea = MGARefreshArea32;	break;
-	   }
-	}
-
-	ShadowFBInit(pScreen, refreshArea);
-    }
-
     xf86DPMSInit(pScreen, mga_dpms_set_proc, 0);
 
     pScrn->memPhysBase = pMga->FbAddress;
@@ -3869,7 +3870,11 @@ MGACloseScreen(CLOSE_SCREEN_ARGS_DECL)
 #endif
     if (pMga->CursorInfoRec)
     	xf86DestroyCursorInfoRec(pMga->CursorInfoRec);
-    free(pMga->ShadowPtr);
+    if (pMga->ShadowFB) {
+        shadowRemove(pScreen, pScreen->GetScreenPixmap(pScreen));
+        free(pMga->ShadowPtr);
+        pMga->ShadowPtr = NULL;
+    }
     free(pMga->DGAModes);
     free(pMga->adaptor);
     free(pMga->portPrivate);
@@ -4272,3 +4277,4 @@ MGAG100BlackMagic(ScrnInfoPtr pScrn)
     OUTREG(MGAREG_MACCESS, 1<<15);
     usleep(10);
 }
+
diff --git a/src/mga_shadow.c b/src/mga_shadow.c
index a8d5cfb..93badb6 100644
--- a/src/mga_shadow.c
+++ b/src/mga_shadow.c
@@ -9,244 +9,82 @@
 
 #include "xf86.h"
 #include "xf86_OSproc.h"
-#include "xf86Pci.h"
-#include "mga_reg.h"
 #include "mga.h"
-#include "shadowfb.h"
+#include "shadow.h"
 #include "servermd.h"
 
-
-
-void
-MGARefreshArea(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
+static void *
+MGAShadowWindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode,
+		 CARD32 *size, void *closure)
 {
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     MGAPtr pMga = MGAPTR(pScrn);
-    int width, height, Bpp, FBPitch;
-    unsigned char *src, *dst;
-   
-    Bpp = pScrn->bitsPerPixel >> 3;
-    FBPitch = BitmapBytePad(pScrn->displayWidth * pScrn->bitsPerPixel);
-
-    while(num--) {
-	width = (pbox->x2 - pbox->x1) * Bpp;
-	height = pbox->y2 - pbox->y1;
-	src = pMga->ShadowPtr + (pbox->y1 * pMga->ShadowPitch) + 
-						(pbox->x1 * Bpp);
-	dst = pMga->FbStart + (pbox->y1 * FBPitch) + (pbox->x1 * Bpp);
-
-	while(height--) {
-	    memcpy(dst, src, width);
-	    dst += FBPitch;
-	    src += pMga->ShadowPitch;
-	}
-	
-	pbox++;
-    }
-} 
+    void *pointer;
 
-void
-MGAPointerMoved(SCRN_ARG_TYPE arg, int x, int y)
-{
-    SCRN_INFO_PTR(arg);
-    MGAPtr pMga = MGAPTR(pScrn);
-    int newX, newY;
-
-    if(pMga->Rotate == 1) {
-	newX = pScrn->pScreen->height - y - 1;
-	newY = x;
-    } else {
-	newX = y;
-	newY = pScrn->pScreen->width - x - 1;
-    }
+    if (!pScrn->vtSema)
+        return NULL;
 
-    (*pMga->PointerMoved)(arg, newX, newY);
+    *size = pScrn->displayWidth * (pScrn->bitsPerPixel >> 3);
+    return ((CARD8 *)pMga->FbStart + (row * *size) + offset);
 }
 
-void
-MGARefreshArea8(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
+static Bool
+MGAShadowCreateScreenResources(ScreenPtr pScreen)
 {
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     MGAPtr pMga = MGAPTR(pScrn);
-    int count, width, height, y1, y2, dstPitch, srcPitch;
-    CARD8 *dstPtr, *srcPtr, *src;
-    CARD32 *dst;
-
-    dstPitch = pScrn->displayWidth;
-    srcPitch = -pMga->Rotate * pMga->ShadowPitch;
-
-    while(num--) {
-	width = pbox->x2 - pbox->x1;
-	y1 = pbox->y1 & ~3;
-	y2 = (pbox->y2 + 3) & ~3;
-	height = (y2 - y1) >> 2;  /* in dwords */
-
-	if(pMga->Rotate == 1) {
-	    dstPtr = pMga->FbStart + 
-			(pbox->x1 * dstPitch) + pScrn->virtualX - y2;
-	    srcPtr = pMga->ShadowPtr + ((1 - y2) * srcPitch) + pbox->x1;
-	} else {
-	    dstPtr = pMga->FbStart + 
-			((pScrn->virtualY - pbox->x2) * dstPitch) + y1;
-	    srcPtr = pMga->ShadowPtr + (y1 * srcPitch) + pbox->x2 - 1;
-	}
-
-	while(width--) {
-	    src = srcPtr;
-	    dst = (CARD32*)dstPtr;
-	    count = height;
-	    while(count--) {
-		*(dst++) = src[0] | (src[srcPitch] << 8) | 
-					(src[srcPitch * 2] << 16) | 
-					(src[srcPitch * 3] << 24);
-		src += srcPitch * 4;
-	    }
-	    srcPtr += pMga->Rotate;
-	    dstPtr += dstPitch;
-	}
-
-	pbox++;
-    }
-} 
+    PixmapPtr pPixmap;
+    Bool ret;
 
+    pScreen->CreateScreenResources = pMga->CreateScreenResources;
+    ret = pScreen->CreateScreenResources(pScreen);
+    pScreen->CreateScreenResources = MGAShadowCreateScreenResources;
 
-void
-MGARefreshArea16(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
-{
-    MGAPtr pMga = MGAPTR(pScrn);
-    int count, width, height, y1, y2, dstPitch, srcPitch;
-    CARD16 *dstPtr, *srcPtr, *src;
-    CARD32 *dst;
-
-    dstPitch = pScrn->displayWidth;
-    srcPitch = -pMga->Rotate * pMga->ShadowPitch >> 1;
-
-    while(num--) {
-	width = pbox->x2 - pbox->x1;
-	y1 = pbox->y1 & ~1;
-	y2 = (pbox->y2 + 1) & ~1;
-	height = (y2 - y1) >> 1;  /* in dwords */
-
-	if(pMga->Rotate == 1) {
-	    dstPtr = (CARD16*)pMga->FbStart + 
-			(pbox->x1 * dstPitch) + pScrn->virtualX - y2;
-	    srcPtr = (CARD16*)pMga->ShadowPtr + 
-			((1 - y2) * srcPitch) + pbox->x1;
-	} else {
-	    dstPtr = (CARD16*)pMga->FbStart + 
-			((pScrn->virtualY - pbox->x2) * dstPitch) + y1;
-	    srcPtr = (CARD16*)pMga->ShadowPtr + 
-			(y1 * srcPitch) + pbox->x2 - 1;
-	}
-
-	while(width--) {
-	    src = srcPtr;
-	    dst = (CARD32*)dstPtr;
-	    count = height;
-	    while(count--) {
-		*(dst++) = src[0] | (src[srcPitch] << 16);
-		src += srcPitch * 2;
-	    }
-	    srcPtr += pMga->Rotate;
-	    dstPtr += dstPitch;
-	}
-
-	pbox++;
+    if (!ret)
+	return FALSE;
+
+    pPixmap = pScreen->GetScreenPixmap(pScreen);
+
+    if (!shadowAdd(pScreen, pPixmap, pMga->Rotate ?
+		   shadowUpdateRotatePackedWeak() : shadowUpdatePackedWeak(),
+		   MGAShadowWindowLinear, pMga->Rotate, NULL)) {
+	return FALSE;
     }
-}
 
+    return TRUE;
+}
 
-/* this one could be faster */
-void
-MGARefreshArea24(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
+Bool
+MGAShadowInit(ScreenPtr pScreen)
 {
+    ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
     MGAPtr pMga = MGAPTR(pScrn);
-    int count, width, height, y1, y2, dstPitch, srcPitch;
-    CARD8 *dstPtr, *srcPtr, *src;
-    CARD32 *dst;
-
-    dstPitch = BitmapBytePad(pScrn->displayWidth * 24);
-    srcPitch = -pMga->Rotate * pMga->ShadowPitch;
-
-    while(num--) {
-        width = pbox->x2 - pbox->x1;
-        y1 = pbox->y1 & ~3;
-        y2 = (pbox->y2 + 3) & ~3;
-        height = (y2 - y1) >> 2;  /* blocks of 3 dwords */
-
-	if(pMga->Rotate == 1) {
-	    dstPtr = pMga->FbStart + 
-			(pbox->x1 * dstPitch) + ((pScrn->virtualX - y2) * 3);
-	    srcPtr = pMga->ShadowPtr + ((1 - y2) * srcPitch) + (pbox->x1 * 3);
-	} else {
-	    dstPtr = pMga->FbStart + 
-			((pScrn->virtualY - pbox->x2) * dstPitch) + (y1 * 3);
-	    srcPtr = pMga->ShadowPtr + (y1 * srcPitch) + (pbox->x2 * 3) - 3;
-	}
-
-	while(width--) {
-	    src = srcPtr;
-	    dst = (CARD32*)dstPtr;
-	    count = height;
-	    while(count--) {
-		dst[0] = src[0] | (src[1] << 8) | (src[2] << 16) |
-				(src[srcPitch] << 24);		
-		dst[1] = src[srcPitch + 1] | (src[srcPitch + 2] << 8) |
-				(src[srcPitch * 2] << 16) |
-				(src[(srcPitch * 2) + 1] << 24);		
-		dst[2] = src[(srcPitch * 2) + 2] | (src[srcPitch * 3] << 8) |
-				(src[(srcPitch * 3) + 1] << 16) |
-				(src[(srcPitch * 3) + 2] << 24);	
-		dst += 3;
-		src += srcPitch * 4;
-	    }
-	    srcPtr += pMga->Rotate * 3;
-	    dstPtr += dstPitch; 
-	}
-
-	pbox++;
+
+    if (!shadowSetup(pScreen)) {
+	return FALSE;
     }
+
+    pMga->CreateScreenResources = pScreen->CreateScreenResources;
+    pScreen->CreateScreenResources = MGAShadowCreateScreenResources;
+
+    return TRUE;
 }
 
 void
-MGARefreshArea32(ScrnInfoPtr pScrn, int num, BoxPtr pbox)
+MGAShadowPointerMoved(SCRN_ARG_TYPE arg, int x, int y)
 {
+    SCRN_INFO_PTR(arg);
     MGAPtr pMga = MGAPTR(pScrn);
-    int count, width, height, dstPitch, srcPitch;
-    CARD32 *dstPtr, *srcPtr, *src, *dst;
-
-    dstPitch = pScrn->displayWidth;
-    srcPitch = -pMga->Rotate * pMga->ShadowPitch >> 2;
-
-    while(num--) {
-	width = pbox->x2 - pbox->x1;
-	height = pbox->y2 - pbox->y1;
-
-	if(pMga->Rotate == 1) {
-	    dstPtr = (CARD32*)pMga->FbStart + 
-			(pbox->x1 * dstPitch) + pScrn->virtualX - pbox->y2;
-	    srcPtr = (CARD32*)pMga->ShadowPtr + 
-			((1 - pbox->y2) * srcPitch) + pbox->x1;
-	} else {
-	    dstPtr = (CARD32*)pMga->FbStart + 
-			((pScrn->virtualY - pbox->x2) * dstPitch) + pbox->y1;
-	    srcPtr = (CARD32*)pMga->ShadowPtr + 
-			(pbox->y1 * srcPitch) + pbox->x2 - 1;
-	}
-
-	while(width--) {
-	    src = srcPtr;
-	    dst = dstPtr;
-	    count = height;
-	    while(count--) {
-		*(dst++) = *src;
-		src += srcPitch;
-	    }
-	    srcPtr += pMga->Rotate;
-	    dstPtr += dstPitch;
-	}
-
-	pbox++;
-    }
-}
+    int newX, newY;
 
+    if(pMga->Rotate == 1) {
+	newX = pScrn->pScreen->height - y - 1;
+	newY = x;
+    } else {
+	newX = y;
+	newY = pScrn->pScreen->width - x - 1;
+    }
 
+    (*pMga->PointerMoved)(arg, newX, newY);
+}
openSUSE Build Service is sponsored by