[xserver-commit] xserver/hw/kdrive/src Makefile.am,1.5,1.6 kaa.c,1.15,1.16 kasync.c,1.13,1.14 kcmap.c,1.8,1.9 kcurscol.c,1.7,1.8 kdrive.c,1.35,1.36 kdrive.h,1.40,1.41 kinput.c,1.35,1.36 knoop.c,1.4,1.5 koffscreen.c,1.9,1.10 kshadow.c,1.6,1.7 vga.c,1.7,1.8 vga.h,1.5,1.6

Keith Packard xserver-commit@pdx.freedesktop.org
Sun, 02 Nov 2003 11:56:13 -0800


Committed by: keithp

Update of /cvs/xserver/xserver/hw/kdrive/src
In directory pdx:/tmp/cvs-serv23831/hw/kdrive/src

Modified Files:
	Makefile.am kaa.c kasync.c kcmap.c kcurscol.c kdrive.c 
	kdrive.h kinput.c knoop.c koffscreen.c kshadow.c vga.c vga.h 
Log Message:
	merge xfixes_2_branch back to HEAD


Index: Makefile.am
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/src/Makefile.am,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Makefile.am	13 Oct 2003 00:19:58 -0000	1.5
+++ Makefile.am	2 Nov 2003 19:56:10 -0000	1.6
@@ -1,10 +1,6 @@
 INCLUDES = 					\
-	-I$(top_srcdir)/fb			\
-	-I$(top_srcdir)/mi			\
-	-I$(top_srcdir)/miext/shadow		\
-	-I$(top_srcdir)/randr			\
-	-I$(top_srcdir)/render			\
-	$(XSERVER_CFLAGS)
+	@KDRIVE_INCS@				\
+	@XSERVER_CFLAGS@
 
 noinst_LIBRARIES = libkdrive.a
 

Index: kaa.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/src/kaa.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- kaa.c	19 Oct 2003 20:46:23 -0000	1.15
+++ kaa.c	2 Nov 2003 19:56:10 -0000	1.16
@@ -50,10 +50,6 @@
 
 typedef struct {
     KaaScreenInfoPtr info;
-    
-    CreatePixmapProcPtr CreatePixmap;
-    DestroyPixmapProcPtr DestroyPixmap;
-    int	pixelOffset;	/* offset from pPixmap to pixels */
 } KaaScreenPrivRec, *KaaScreenPrivPtr;
 
 typedef struct {
@@ -71,22 +67,10 @@
 #define KaaGetScreenPriv(s)	((KaaScreenPrivPtr)(s)->devPrivates[kaaScreenPrivateIndex].ptr)
 #define KaaScreenPriv(s)	KaaScreenPrivPtr    pKaaScr = KaaGetScreenPriv(s)
 
-#define KaaGetPixmapPriv(p) ((KaaPixmapPrivPtr)(p)->devPrivates[kaaPixmapPrivateIndex].ptr)
-#define KaaSetPixmapPriv(p,a) ((p)->devPrivates[kaaPixmapPrivateIndex].ptr = (pointer) (a))
-#define KaaPixmapPriv(p) KaaPixmapPrivPtr pKaaPixmap = KaaGetPixmapPriv(p)
-
-#define KaaPixmapPitch(w) (((w) + (pKaaScr->info->offscreenPitch - 1)) & ~(pKaaScr->info->offscreenPitch - 1))
-#define KaaDrawableIsOffscreenPixmap(d) (d->type == DRAWABLE_PIXMAP && \
-					 KaaGetPixmapPriv((PixmapPtr)(d)) && \
-					 KaaGetPixmapPriv((PixmapPtr)(d))->area)
-#define KaaDrawableIsScreen(d)  (((d)->type == DRAWABLE_WINDOW) || \
-				 KaaDrawableIsOffscreenPixmap(d))
-
-#define KAA_SCREEN_PROLOGUE(pScreen, field) ((pScreen)->field = \
-   ((KaaScreenPrivPtr) (pScreen)->devPrivates[kaaScreenPrivateIndex].ptr)->field)
-
-#define KAA_SCREEN_EPILOGUE(pScreen, field, wrapper)\
-    ((pScreen)->field = wrapper)
+#define KaaGetPixmapPriv(p)	((KaaPixmapPrivPtr)(p)->devPrivates[kaaPixmapPrivateIndex].ptr)
+#define KaaSetPixmapPriv(p,a)	((p)->devPrivates[kaaPixmapPrivateIndex].ptr = (pointer) (a))
+#define KaaPixmapPriv(p)	KaaPixmapPrivPtr pKaaPixmap = KaaGetPixmapPriv(p)
+#define KaaPixmapPitch(w)	(((w) + (pKaaScr->info->offscreenPitch - 1)) & ~(pKaaScr->info->offscreenPitch - 1))
 
 #define MIN_OFFPIX_SIZE		(4096)
 
@@ -248,9 +232,6 @@
 static Bool
 kaaDestroyPixmap (PixmapPtr pPixmap)
 {
-    ScreenPtr pScreen = pPixmap->drawable.pScreen;
-    Bool ret;
-    
     if (pPixmap->refcnt == 1)
     {
 	KaaPixmapPriv (pPixmap);
@@ -267,58 +248,93 @@
 	    pPixmap->devKind = pKaaPixmap->devKind;
 	}
     }
-
-    KAA_SCREEN_PROLOGUE (pScreen, DestroyPixmap);
-    ret = (*pScreen->DestroyPixmap) (pPixmap);
-    KAA_SCREEN_EPILOGUE (pScreen, DestroyPixmap, kaaDestroyPixmap);
-    
-    return ret;
+    return fbDestroyPixmap (pPixmap);
 }
 
 static PixmapPtr 
 kaaCreatePixmap(ScreenPtr pScreen, int w, int h, int depth)
 {
-    PixmapPtr pPixmap = NULL;
+    PixmapPtr		pPixmap;
     KaaPixmapPrivPtr	pKaaPixmap;
+    int			bpp;
     
-    KAA_SCREEN_PROLOGUE (pScreen, CreatePixmap);
-    pPixmap = (* pScreen->CreatePixmap) (pScreen, w, h, depth);
-    KAA_SCREEN_EPILOGUE (pScreen, CreatePixmap, kaaCreatePixmap);
+    bpp = BitsPerPixel (depth);
+    if (bpp == 32 && depth == 24)
+    {
+	int fb;
+	KdScreenPriv (pScreen);
+	
+	for (fb = 0; fb < KD_MAX_FB && pScreenPriv->screen->fb[fb].depth; fb++)
+	    if (pScreenPriv->screen->fb[fb].depth == 24)
+	    {
+		bpp = pScreenPriv->screen->fb[fb].bitsPerPixel;
+		break;
+	    }
+    }
+    pPixmap = fbCreatePixmapBpp (pScreen, w, h, depth, bpp);
     if (!pPixmap)
 	return NULL;
     pKaaPixmap = KaaGetPixmapPriv(pPixmap);
     pKaaPixmap->score = 0;
     pKaaPixmap->area = NULL;
     
-    if ((pPixmap->devKind * h) >= MIN_OFFPIX_SIZE)
+    if (depth == pScreen->rootDepth &&
+	(pPixmap->devKind * h) >= MIN_OFFPIX_SIZE)
 	kaaPixmapAllocArea (pPixmap);
     return pPixmap;
 }
 
-PixmapPtr
-kaaGetDrawingPixmap (DrawablePtr pDrawable, int *x, int *y)
+static Bool
+kaaPixmapIsOffscreen(PixmapPtr p)
 {
-    if (pDrawable->type == DRAWABLE_WINDOW) {
-	if (x)
-	    *x = pDrawable->x;
-	if (y)
-	    *y = pDrawable->y;
+    ScreenPtr	pScreen = p->drawable.pScreen;
+    KdScreenPriv(pScreen);
 
-	return (*pDrawable->pScreen->GetScreenPixmap) (pDrawable->pScreen);
+    return ((unsigned long) ((CARD8 *) p->devPrivate.ptr - 
+			     (CARD8 *) pScreenPriv->screen->memory_base) <
+	    pScreenPriv->screen->memory_size);
+}
+
+static PixmapPtr
+kaaGetOffscreenPixmap (DrawablePtr pDrawable, int *xp, int *yp)
+{
+    PixmapPtr	pPixmap;
+    int		x, y;
+    
+    if (pDrawable->type == DRAWABLE_WINDOW) {
+	pPixmap = (*pDrawable->pScreen->GetWindowPixmap) ((WindowPtr) pDrawable);
+	x = pDrawable->x;
+	y = pDrawable->y;
     }
-    else if (KaaDrawableIsOffscreenPixmap (pDrawable))
+    else
     {
-	if (x)
-	    *x = 0;
-	if (y)
-	    *y = 0;
-	return ((PixmapPtr)pDrawable);
+	pPixmap = (PixmapPtr) pDrawable;
+	x = 0;
+	y = 0;
+    }
+    if (kaaPixmapIsOffscreen (pPixmap))
+    {
+	x += pPixmap->drawable.x;
+	y += pPixmap->drawable.y;
+	if (xp) *xp = x;
+	if (yp) *yp = y;
+	return pPixmap;
     }
+    return NULL;
+}
+
+static Bool
+kaaDrawableIsOffscreen (DrawablePtr pDrawable)
+{
+    PixmapPtr	pPixmap;
+    if (pDrawable->type == DRAWABLE_WINDOW)
+	pPixmap = (*pDrawable->pScreen->GetWindowPixmap) ((WindowPtr) pDrawable);
     else
-	return NULL;
+	pPixmap = (PixmapPtr) pDrawable;
+    return kaaPixmapIsOffscreen (pPixmap);
 }
 
-void
+static void
 kaaFillSpans(DrawablePtr pDrawable, GCPtr pGC, int n, 
 	     DDXPointPtr ppt, int *pwidth, int fSorted)
 {
@@ -335,7 +351,7 @@
 
     if (!pScreenPriv->enabled ||
 	pGC->fillStyle != FillSolid ||
-	!(pPixmap = kaaGetDrawingPixmap (pDrawable, NULL, NULL)) ||
+	!(pPixmap = kaaGetOffscreenPixmap (pDrawable, NULL, NULL)) ||
 	!(*pKaaScr->info->PrepareSolid) (pPixmap,
 					 pGC->alu,
 					 pGC->planemask,
@@ -389,7 +405,8 @@
 		    if (partX2 > fullX2)
 			partX2 = fullX2;
 		    if (partX2 > partX1)
-			(*pKaaScr->info->Solid) (partX1, fullY1, partX2, fullY1 + 1);
+			(*pKaaScr->info->Solid) (partX1, fullY1,
+						 partX2, fullY1 + 1);
 		}
 		pbox++;
 	    }
@@ -399,7 +416,7 @@
     KdMarkSync(pDrawable->pScreen);
 }
 
-void
+static void
 kaaCopyNtoN (DrawablePtr    pSrcDrawable,
 	     DrawablePtr    pDstDrawable,
 	     GCPtr	    pGC,
@@ -418,15 +435,15 @@
 
     /* Migrate pixmaps to same place as destination */
     if (pScreenPriv->enabled && pSrcDrawable->type == DRAWABLE_PIXMAP) {
-	if (KaaDrawableIsScreen (pDstDrawable))
+	if (kaaDrawableIsOffscreen (pDstDrawable))
 	    kaaPixmapUseScreen ((PixmapPtr) pSrcDrawable);
 	else
 	    kaaPixmapUseMemory ((PixmapPtr) pSrcDrawable);
     }
 
     if (pScreenPriv->enabled &&
-	(pSrcPixmap = kaaGetDrawingPixmap (pSrcDrawable, NULL, NULL)) &&
-	(pDstPixmap = kaaGetDrawingPixmap (pDstDrawable, NULL, NULL)) && 
+	(pSrcPixmap = kaaGetOffscreenPixmap (pSrcDrawable, NULL, NULL)) &&
+	(pDstPixmap = kaaGetOffscreenPixmap (pDstDrawable, NULL, NULL)) && 
 	(*pKaaScr->info->PrepareCopy) (pSrcPixmap,
 				       pDstPixmap,
 				       dx,
@@ -454,7 +471,7 @@
     }
 }
 
-RegionPtr
+static RegionPtr
 kaaCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GCPtr pGC,
 	    int srcx, int srcy, int width, int height, int dstx, int dsty)
 {
@@ -463,7 +480,7 @@
 		     dstx, dsty, kaaCopyNtoN, 0, 0);
 }
 
-void
+static void
 kaaPolyFillRect(DrawablePtr pDrawable, 
 		GCPtr	    pGC, 
 		int	    nrect,
@@ -483,7 +500,7 @@
     
     if (!pScreenPriv->enabled ||
 	pGC->fillStyle != FillSolid ||
-	!(pPixmap = kaaGetDrawingPixmap (pDrawable, &xorg, &yorg)) || 
+	!(pPixmap = kaaGetOffscreenPixmap (pDrawable, &xorg, &yorg)) || 
 	!(*pKaaScr->info->PrepareSolid) (pPixmap,
 					 pGC->alu,
 					 pGC->planemask,
@@ -559,7 +576,7 @@
     KdMarkSync(pDrawable->pScreen);
 }
     
-void
+static void
 kaaSolidBoxClipped (DrawablePtr	pDrawable,
 		    RegionPtr	pClip,
 		    FbBits	pm,
@@ -577,7 +594,7 @@
     int		partX1, partX2, partY1, partY2;
 
     if (!pScreenPriv->enabled ||
-	!(pPixmap = kaaGetDrawingPixmap (pDrawable, NULL, NULL)) ||
+	!(pPixmap = kaaGetOffscreenPixmap (pDrawable, NULL, NULL)) ||
 	!(*pKaaScr->info->PrepareSolid) (pPixmap, GXcopy, pm, fg))
     {
 	KdCheckSync (pDrawable->pScreen);
@@ -619,7 +636,7 @@
     KdMarkSync(pDrawable->pScreen);
 }
 
-void
+static void
 kaaImageGlyphBlt (DrawablePtr	pDrawable,
 		  GCPtr		pGC,
 		  int		x, 
@@ -776,12 +793,12 @@
 #endif
 };
 
-void
+static void
 kaaValidateGC (GCPtr pGC, Mask changes, DrawablePtr pDrawable)
 {
     fbValidateGC (pGC, changes, pDrawable);
 
-    if (KaaDrawableIsScreen (pDrawable))
+    if (kaaDrawableIsOffscreen (pDrawable))
 	pGC->ops = (GCOps *) &kaaOps;
     else
 	pGC->ops = (GCOps *) &kdAsyncPixmapGCOps;
@@ -797,7 +814,7 @@
     miCopyClip
 };
 
-int
+static int
 kaaCreateGC (GCPtr pGC)
 {
     if (!fbCreateGC (pGC))
@@ -809,7 +826,7 @@
 }
 
 
-void
+static void
 kaaCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
 {
     RegionRec	rgnDst;
@@ -833,7 +850,7 @@
     REGION_UNINIT(pWin->drawable.pScreen, &rgnDst);
 }
 
-void
+static void
 kaaFillRegionSolid (DrawablePtr	pDrawable,
 		    RegionPtr	pRegion,
 		    Pixel	pixel)
@@ -843,7 +860,7 @@
     PixmapPtr pPixmap;
 
     if (pScreenPriv->enabled &&
-	(pPixmap = kaaGetDrawingPixmap (pDrawable, NULL, NULL)) &&
+	(pPixmap = kaaGetOffscreenPixmap (pDrawable, NULL, NULL)) &&
 	(*pKaaScr->info->PrepareSolid) (pPixmap, GXcopy, FB_ALLONES, pixel))
     {
 	int	nbox = REGION_NUM_RECTS (pRegion);
@@ -865,7 +882,7 @@
     }
 }
 
-void
+static void
 kaaPaintWindow(WindowPtr pWin, RegionPtr pRegion, int what)
 {
 
@@ -933,7 +950,8 @@
 	     KaaScreenInfoPtr	pScreenInfo)
 {
     KaaScreenPrivPtr pKaaScr;
-    KdScreenInfo *screen = KdGetScreenPriv (pScreen)->screen;
+    KdScreenPriv(pScreen);
+    KdScreenInfo *screen = pScreenPriv->screen;
 #ifdef RENDER
     PictureScreenPtr	ps = GetPictureScreenIfSet(pScreen);
 #endif
@@ -974,15 +992,13 @@
      * Hookup offscreen pixmaps
      */
     if ((pKaaScr->info->flags & KAA_OFFSCREEN_PIXMAPS) &&
-	screen->off_screen_size > 0)
+	screen->off_screen_base < screen->memory_size)
     {
-	pKaaScr->CreatePixmap = pScreen->CreatePixmap;
-	pScreen->CreatePixmap = kaaCreatePixmap;
-	pKaaScr->DestroyPixmap = pScreen->DestroyPixmap;
-	pScreen->DestroyPixmap = kaaDestroyPixmap;
 	if (!AllocatePixmapPrivate(pScreen, kaaPixmapPrivateIndex,
 				   sizeof (KaaPixmapPrivRec)))
 	    return FALSE;
+	pScreen->CreatePixmap = kaaCreatePixmap;
+	pScreen->DestroyPixmap = kaaDestroyPixmap;
     }
     else
     {
@@ -993,3 +1009,10 @@
     return TRUE;
 }
 
+void
+kaaDrawFini (ScreenPtr pScreen)
+{
+    KaaScreenPriv(pScreen);
+
+    xfree (pKaaScr);
+}

Index: kasync.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/src/kasync.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- kasync.c	14 Oct 2003 21:10:53 -0000	1.13
+++ kasync.c	2 Nov 2003 19:56:10 -0000	1.14
@@ -305,11 +305,3 @@
     ,NULL
 #endif
 };
-
-void
-KdAssertSync (ScreenPtr pScreen)
-{
-    KdScreenPriv(pScreen);
-    KdCardInfo	*card = pScreenPriv->card;
-    assert (!card->needSync);
-}

Index: kcmap.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/src/kcmap.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- kcmap.c	14 Oct 2003 05:07:39 -0000	1.8
+++ kcmap.c	2 Nov 2003 19:56:10 -0000	1.9
@@ -130,7 +130,7 @@
     }
 }
 
-int
+static int
 KdColormapFb (ColormapPtr   pCmap)
 {
     ScreenPtr	pScreen = pCmap->pScreen;

Index: kcurscol.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/src/kcurscol.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- kcurscol.c	11 Sep 2003 05:15:08 -0000	1.7
+++ kcurscol.c	2 Nov 2003 19:56:10 -0000	1.8
@@ -28,7 +28,7 @@
 #include "kdrive.h"
 #include "cursorstr.h"
 
-int
+static int
 KdComputeCmapShift (unsigned long mask)
 {
     int	shift;

Index: kdrive.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/src/kdrive.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- kdrive.c	14 Oct 2003 21:10:53 -0000	1.35
+++ kdrive.c	2 Nov 2003 19:56:10 -0000	1.36
@@ -225,7 +225,7 @@
     (*pScreenPriv->card->cfuncs->disable) (pScreen);
 }
 
-void
+static void
 KdDoSwitchCmd (char *reason)
 {
     if (kdSwitchCmd)
@@ -382,7 +382,7 @@
 Bool	kdDumbDriver;
 Bool	kdSoftCursor;
 
-char *
+static char *
 KdParseFindNext (char *cur, char *delim, char *save, char *last)
 {
     while (*cur && !strchr (delim, *cur))
@@ -833,6 +833,22 @@
 }
 
 Bool
+KdCreateScreenResources (ScreenPtr pScreen)
+{
+    KdScreenPriv(pScreen);
+    KdCardInfo	    *card = pScreenPriv->card;
+    Bool ret;
+
+    pScreen->CreateScreenResources = pScreenPriv->CreateScreenResources;
+    ret = (*pScreen->CreateScreenResources) (pScreen);
+    pScreenPriv->CreateScreenResources = pScreen->CreateScreenResources;
+    pScreen->CreateScreenResources = KdCreateScreenResources;
+    if (ret && card->cfuncs->createRes)
+	ret = (*card->cfuncs->createRes) (pScreen);
+    return ret;
+}
+
+Bool
 KdCloseScreen (int index, ScreenPtr pScreen)
 {
     KdScreenPriv(pScreen);
@@ -844,7 +860,7 @@
     pScreen->CloseScreen = pScreenPriv->CloseScreen;
     ret = (*pScreen->CloseScreen) (index, pScreen);
     
-    if (screen->off_screen_size > 0)
+    if (screen->off_screen_base < screen->memory_size)
 	KdOffscreenFini (pScreen);
     
     if (pScreenPriv->dpmsState != KD_DPMS_NORMAL)
@@ -930,7 +946,7 @@
     return TRUE;
 }
 
-Bool
+static Bool
 KdCreateWindow (WindowPtr pWin)
 {
 #ifndef PHOENIX
@@ -1015,11 +1031,32 @@
     KdCardInfo		*card = screen->card;
     KdPrivScreenPtr	pScreenPriv;
     int			fb;
+    /*
+     * note that screen->fb is set up for the nominal orientation
+     * of the screen; that means if randr is rotated, the values
+     * there should reflect a rotated frame buffer (or shadow).
+     */
+    Bool		rotated = (screen->randr & (RR_Rotate_90|RR_Rotate_270)) != 0;
+    int			width, height, *width_mmp, *height_mmp;
 
     KdAllocatePrivates (pScreen);
 
     pScreenPriv = KdGetScreenPriv(pScreen);
     
+    if (!rotated)
+    {
+	width = screen->width;
+	height = screen->height;
+	width_mmp = &screen->width_mm;
+	height_mmp = &screen->height_mm;
+    }
+    else
+    {
+	width = screen->height;
+	height = screen->width;
+	width_mmp = &screen->height_mm;
+	height_mmp = &screen->width_mm;
+    }
     screen->pScreen = pScreen;
     pScreenPriv->screen = screen;
     pScreenPriv->card = card;
@@ -1039,7 +1076,7 @@
      */
     if (!fbSetupScreen (pScreen, 
 			screen->fb[0].frameBuffer, 
-			screen->width, screen->height, 
+			width, height, 
 			monitorResolution, monitorResolution, 
 			screen->fb[0].pixelStride,
 			screen->fb[0].bitsPerPixel))
@@ -1072,7 +1109,7 @@
 	if (!fbOverlayFinishScreenInit (pScreen, 
 					screen->fb[0].frameBuffer, 
 					screen->fb[1].frameBuffer, 
-					screen->width, screen->height, 
+					width, height, 
 					monitorResolution, monitorResolution,
 					screen->fb[0].pixelStride,
 					screen->fb[1].pixelStride,
@@ -1089,7 +1126,7 @@
     {
 	if (!fbFinishScreenInit (pScreen, 
 				 screen->fb[0].frameBuffer, 
-				 screen->width, screen->height,
+				 width, height,
 				 monitorResolution, monitorResolution,
 				 screen->fb[0].pixelStride,
 				 screen->fb[0].bitsPerPixel))
@@ -1102,14 +1139,14 @@
      * Fix screen sizes; for some reason mi takes dpi instead of mm.
      * Rounding errors are annoying
      */
-    if (screen->width_mm)
-	pScreen->mmWidth = screen->width_mm;
+    if (*width_mmp)
+	pScreen->mmWidth = *width_mmp;
     else
-	screen->width_mm = pScreen->mmWidth;
-    if (screen->height_mm)
-	pScreen->mmHeight = screen->height_mm;
+	*width_mmp = pScreen->mmWidth;
+    if (*height_mmp)
+	pScreen->mmHeight = *height_mmp;
     else
-	screen->height_mm = pScreen->mmHeight;
+	*height_mmp = pScreen->mmHeight;
     
     /*
      * Plug in our own block/wakeup handlers.
@@ -1130,7 +1167,7 @@
 	if (!(*card->cfuncs->initAccel) (pScreen))
 	    screen->dumb = TRUE;
 
-    if (screen->off_screen_size > 0)
+    if (screen->off_screen_base < screen->memory_size)
 	KdOffscreenInit (pScreen);
     
 #ifdef PSEUDO8
@@ -1163,6 +1200,9 @@
      */
     pScreenPriv->CloseScreen = pScreen->CloseScreen;
     pScreen->CloseScreen = KdCloseScreen;
+
+    pScreenPriv->CreateScreenResources = pScreen->CreateScreenResources;
+    pScreen->CreateScreenResources = KdCreateScreenResources;
     
     if (screen->softCursor ||
 	!card->cfuncs->initCursor || 
@@ -1222,7 +1262,7 @@
 	screen->softCursor = TRUE;
 }
 
-Bool
+static Bool
 KdSetPixmapFormats (ScreenInfo	*pScreenInfo)
 {
     CARD8	    depthToBpp[33];	/* depth -> bpp map */
@@ -1287,7 +1327,7 @@
     return TRUE;
 }
 
-void
+static void
 KdAddScreen (ScreenInfo	    *pScreenInfo,
 	     KdScreenInfo   *screen,
 	     int	    argc,

Index: kdrive.h
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/src/kdrive.h,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -r1.40 -r1.41
--- kdrive.h	16 Oct 2003 08:03:25 -0000	1.40
+++ kdrive.h	2 Nov 2003 19:56:10 -0000	1.41
@@ -93,6 +93,7 @@
     int		bitsPerPixel;
     int		pixelStride;
     int		byteStride;
+    Bool	shadow;
     unsigned long   visuals;
     Pixel       redMask, greenMask, blueMask;
     void	*closure;
@@ -119,8 +120,8 @@
     DDXPointRec	origin;
     KdFrameBuffer   fb[KD_MAX_FB];
     CARD8	*memory_base;
-    int         off_screen_base;
-    int         off_screen_size;
+    unsigned long   memory_size;
+    unsigned long   off_screen_base;
     struct _RealOffscreenArea	*off_screen_areas;
 } KdScreenInfo;
 
@@ -128,6 +129,8 @@
     Bool	(*cardinit) (KdCardInfo *); /* detect and map device */
     Bool	(*scrinit) (KdScreenInfo *);/* initialize screen information */
     Bool	(*initScreen) (ScreenPtr);  /* initialize ScreenRec */
+    Bool	(*finishInitScreen) (ScreenPtr pScreen);
+    Bool	(*createRes) (ScreenPtr);   /* create screen resources */
     void	(*preserve) (KdCardInfo *); /* save graphics card state */
     Bool        (*enable) (ScreenPtr);      /* set up for rendering */
     Bool	(*dpms) (ScreenPtr, int);   /* set DPMS screen saver */
@@ -151,7 +154,6 @@
     void        (*getColors) (ScreenPtr, int, int, xColorItem *);
     void        (*putColors) (ScreenPtr, int, int, xColorItem *);
 
-    Bool	(*finishInitScreen) (ScreenPtr pScreen);
 } KdCardFuncs;
 
 #define KD_MAX_PSEUDO_DEPTH 8
@@ -170,6 +172,7 @@
     ColormapPtr     pInstalledmap[KD_MAX_FB];         /* current colormap */
     xColorItem      systemPalette[KD_MAX_PSEUDO_SIZE];/* saved windows colors */
 
+    CreateScreenResourcesProcPtr    CreateScreenResources;
     CloseScreenProcPtr  CloseScreen;
 #ifdef FB_OLD_SCREEN
     miBSFuncRec	    BackingStoreFuncs;
@@ -216,6 +219,7 @@
 extern int KdCurScreen;
 
 KdMouseInfo *KdMouseInfoAdd (void);
+void	    KdMouseInfoDispose (KdMouseInfo *mi);
 void	    KdParseMouse (char *);
 
 typedef struct _KdMouseFuncs {
@@ -352,6 +356,9 @@
 	     KaaScreenInfoPtr   pScreenInfo);
 
 void
+kaaDrawFini (ScreenPtr	        pScreen);
+
+void
 kaaWrapGC (GCPtr pGC);
 
 void
@@ -565,6 +572,9 @@
 KdAllocatePrivates (ScreenPtr pScreen);
 
 Bool
+KdCreateScreenResources (ScreenPtr pScreen);
+
+Bool
 KdCloseScreen (int index, ScreenPtr pScreen);
 
 Bool
@@ -689,7 +699,7 @@
 KdEnableInput (void);
 
 void
-ProcessInputEvents ();
+ProcessInputEvents (void);
 
 extern KdMouseFuncs	LinuxMouseFuncs;
 extern KdMouseFuncs	Ps2MouseFuncs;
@@ -771,13 +781,16 @@
 
 /* kshadow.c */
 Bool
-KdShadowScreenInit (KdScreenInfo *screen);
+KdShadowFbAlloc (KdScreenInfo *screen, int fb, Bool rotate);
 
-Bool
-KdShadowInitScreen (ScreenPtr pScreen, ShadowUpdateProc update, ShadowWindowProc window);
+void
+KdShadowFbFree (KdScreenInfo *screen, int fb);
 
+Bool
+KdShadowSet (ScreenPtr pScreen, int randr, ShadowUpdateProc update, ShadowWindowProc window);
+    
 void
-KdShadowScreenFini (KdScreenInfo *screen);
+KdShadowUnset (ScreenPtr pScreen);
 
 /* ktest.c */
 Bool

Index: kinput.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/src/kinput.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -d -r1.35 -r1.36
--- kinput.c	14 Oct 2003 05:07:39 -0000	1.35
+++ kinput.c	2 Nov 2003 19:56:10 -0000	1.36
@@ -92,7 +92,7 @@
 int		kdNumInputFds;
 int		kdInputTypeSequence;
 
-void
+static void
 KdSigio (int sig)
 {
     int	i;
@@ -101,7 +101,7 @@
 	(*kdInputFds[i].read) (kdInputFds[i].fd, kdInputFds[i].closure);
 }
 
-void
+static void
 KdBlockSigio (void)
 {
     sigset_t	set;
@@ -111,7 +111,7 @@
     sigprocmask (SIG_BLOCK, &set, 0);
 }
 
-void
+static void
 KdUnblockSigio (void)
 {
     sigset_t	set;
@@ -158,7 +158,7 @@
     fcntl (fd, F_SETFL, flags);
 }
 
-void
+static void
 KdAddFd (int fd)
 {
     struct sigaction	act;
@@ -179,7 +179,7 @@
     sigprocmask (SIG_SETMASK, &set, 0);
 }
 
-void
+static void
 KdRemoveFd (int fd)
 {
     struct sigaction	act;
@@ -915,7 +915,7 @@
 #define EventX(e)   ((e)->u.keyButtonPointer.rootX)
 #define EventY(e)   ((e)->u.keyButtonPointer.rootY)
 
-int
+static int
 KdInsideEmulationWindow (KdMouseInfo *mi, xEvent *ev)
 {
     if (ev->u.keyButtonPointer.pad1)
@@ -932,7 +932,7 @@
 	    abs (mi->emulationDy) < EMULATION_WINDOW);
 }
 				     
-KdInputClass
+static KdInputClass
 KdClassifyInput (KdMouseInfo *mi, xEvent *ev)
 {
     switch (ev->u.u.type) {
@@ -1083,7 +1083,7 @@
     }
 }
 
-void
+static void
 KdHandleMouseEvent (KdMouseInfo *mi, xEvent *ev)
 {
     if (mi->emulateMiddleButton)
@@ -1092,7 +1092,7 @@
 	KdQueueEvent (ev);
 }
 
-void
+static void
 KdReceiveTimeout (KdMouseInfo *mi)
 {
     KdRunMouseMachine (mi, timeout, 0);
@@ -1122,7 +1122,7 @@
 
 extern int nClients;
 
-void
+static void
 KdCheckSpecialKeys(xEvent *xE)
 {
     KeySym	sym = KEYCOL1(xE->u.u.detail);
@@ -1195,7 +1195,7 @@
  *
  */
 
-void
+static void
 KdHandleKeyboardEvent (xEvent *ev)
 {
     int		key = ev->u.u.detail;
@@ -1236,7 +1236,7 @@
     KdUnblockSigio ();
 }
 
-void
+static void
 KdCheckLock (void)
 {
     KeyClassPtr	    keyc = pKdKeyboard->key;

Index: knoop.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/src/knoop.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- knoop.c	11 Sep 2003 05:15:08 -0000	1.4
+++ knoop.c	2 Nov 2003 19:56:10 -0000	1.5
@@ -255,14 +255,14 @@
 #endif
 );
 
-RegionPtr
+static RegionPtr
 KdNoopCopyArea(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GCPtr pGC,
 	    int srcx, int srcy, int width, int height, int dstx, int dsty)
 {
     return NullRegion;
 }
 
-RegionPtr 
+static RegionPtr 
 KdNoopCopyPlane(DrawablePtr pSrcDrawable, DrawablePtr pDstDrawable, GCPtr pGC,
 		 int srcx, int srcy, int width, int height, 
 		 int dstx, int dsty, unsigned long bitPlane)

Index: koffscreen.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/src/koffscreen.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- koffscreen.c	19 Oct 2003 20:46:23 -0000	1.9
+++ koffscreen.c	2 Nov 2003 19:56:10 -0000	1.10
@@ -21,7 +21,6 @@
  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  * PERFORMANCE OF THIS SOFTWARE.
  */
-/* $Header$ */
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -61,7 +60,7 @@
 	    
 	prev = area;
     }
-    assert (prev->area.offset + prev->area.size == pScreenPriv->screen->off_screen_size);
+    assert (prev->area.offset + prev->area.size == pScreenPriv->screen->memory_size);
 }
 #else
 #define KdOffscreenValidate(s)
@@ -97,7 +96,7 @@
     }
 
     /* throw out requests that cannot fit */
-    if (size > pScreenPriv->screen->off_screen_size)
+    if (size > (pScreenPriv->screen->memory_size - pScreenPriv->screen->off_screen_base))
     {
 	DBG_OFFSCREEN (("Alloc 0x%x -> TOBIG\n", size));
 	return NULL;
@@ -280,7 +279,7 @@
 
     area->area.screen = NULL;
     area->area.offset = pScreenPriv->screen->off_screen_base;
-    area->area.size = pScreenPriv->screen->off_screen_size;
+    area->area.size = pScreenPriv->screen->memory_size - area->area.offset;
     area->save = 0;
     area->locked = FALSE;
     area->next = NULL;

Index: kshadow.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/src/kshadow.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- kshadow.c	14 Oct 2003 05:07:39 -0000	1.6
+++ kshadow.c	2 Nov 2003 19:56:10 -0000	1.7
@@ -28,29 +28,59 @@
 #include "kdrive.h"
 
 Bool
-KdShadowScreenInit (KdScreenInfo *screen)
+KdShadowFbAlloc (KdScreenInfo *screen, int fb, Bool rotate)
 {
+    int	    paddedWidth;
     void    *buf;
+    int	    width = rotate ? screen->height : screen->width;
+    int	    height = rotate ? screen->width : screen->height;
+    int	    bpp = screen->fb[fb].bitsPerPixel;
 
-    buf = shadowAlloc (screen->width, screen->height, screen->fb[0].bitsPerPixel);
+    /* use fb computation for width */
+    paddedWidth = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof (FbBits);
+    buf = xalloc (paddedWidth * height);
     if (!buf)
 	return FALSE;
-    screen->fb[0].frameBuffer = buf;
-    screen->fb[0].byteStride = BitmapBytePad (screen->width * screen->fb[0].bitsPerPixel);
-    screen->fb[0].pixelStride = screen->fb[0].byteStride * 8 / screen->fb[0].bitsPerPixel;
-    screen->dumb = TRUE;
+    if (screen->fb[fb].shadow)
+	xfree (screen->fb[fb].frameBuffer);
+    screen->fb[fb].shadow = TRUE;
+    screen->fb[fb].frameBuffer = buf;
+    screen->fb[fb].byteStride = paddedWidth;
+    screen->fb[fb].pixelStride = paddedWidth * 8 / bpp;
     return TRUE;
 }
 
+void
+KdShadowFbFree (KdScreenInfo *screen, int fb)
+{
+    if (screen->fb[fb].shadow)
+    {
+	xfree (screen->fb[fb].frameBuffer);
+	screen->fb[fb].frameBuffer = 0;
+	screen->fb[fb].shadow = FALSE;
+    }
+}
+
 Bool
-KdShadowInitScreen (ScreenPtr pScreen, ShadowUpdateProc update, ShadowWindowProc window)
+KdShadowSet (ScreenPtr pScreen, int randr, ShadowUpdateProc update, ShadowWindowProc window)
 {
-    return shadowInit (pScreen, update, window);
+    KdScreenPriv(pScreen);
+    KdScreenInfo *screen = pScreenPriv->screen;
+    int	 fb;
+
+    for (fb = 0; fb < KD_MAX_FB && screen->fb[fb].depth; fb++)
+    {
+	if (screen->fb[fb].shadow)
+	    return shadowSet (pScreen, (*pScreen->GetScreenPixmap) (pScreen), 
+			      update, window, randr, 0);
+	else
+	    shadowUnset (pScreen);
+    }
+    return TRUE;
 }
 
 void
-KdShadowScreenFini (KdScreenInfo *screen)
+KdShadowUnset (ScreenPtr pScreen)
 {
-    if (screen->fb[0].frameBuffer)
-	xfree (screen->fb[0].frameBuffer);
+    shadowUnset (pScreen);
 }

Index: vga.c
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/src/vga.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- vga.c	14 Oct 2003 05:07:39 -0000	1.7
+++ vga.c	2 Nov 2003 19:56:10 -0000	1.8
@@ -210,7 +210,7 @@
 }
 
 
-void
+static void
 _VgaSync (VgaCard *card, VGA16 id)
 {
     if (!(card->values[id].flags & VGA_VALUE_VALID))

Index: vga.h
===================================================================
RCS file: /cvs/xserver/xserver/hw/kdrive/src/vga.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- vga.h	7 Jul 2003 19:12:57 -0000	1.5
+++ vga.h	2 Nov 2003 19:56:10 -0000	1.6
@@ -126,6 +126,12 @@
 void
 VgaRestore (VgaCard *card);
 
+void
+VgaFinish (VgaCard *card);
+
+void
+VgaFlushReg (VgaCard *card, VgaReg *reg);
+
 VGA8
 VgaFetch (VgaCard *card, VGA16 id);