Module Name:    xsrc
Committed By:   macallan
Date:           Thu Apr 14 16:48:59 UTC 2011

Modified Files:
        xsrc/external/mit/xf86-video-suncg14/dist/src: cg14.h cg14_driver.c
Added Files:
        xsrc/external/mit/xf86-video-suncg14/dist/src: cg14_cursor.c

Log Message:
add shadowfb and hardware cursor support


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 xsrc/external/mit/xf86-video-suncg14/dist/src/cg14.h
cvs rdiff -u -r0 -r1.1 \
    xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_cursor.c
cvs rdiff -u -r1.5 -r1.6 \
    xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_driver.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: xsrc/external/mit/xf86-video-suncg14/dist/src/cg14.h
diff -u xsrc/external/mit/xf86-video-suncg14/dist/src/cg14.h:1.3 xsrc/external/mit/xf86-video-suncg14/dist/src/cg14.h:1.4
--- xsrc/external/mit/xf86-video-suncg14/dist/src/cg14.h:1.3	Thu Apr 14 01:37:22 2011
+++ xsrc/external/mit/xf86-video-suncg14/dist/src/cg14.h	Thu Apr 14 16:48:59 2011
@@ -51,17 +51,43 @@
 #define CG14_G32_VOFF		0xb0000000
 #define CG14_R32_VOFF		0xc0000000
 
+/* Hardware cursor map */
+#define CG14_CURS_SIZE		32
+struct cg14curs {
+	volatile uint32_t	curs_plane0[CG14_CURS_SIZE];	/* plane 0 */
+	volatile uint32_t	curs_plane1[CG14_CURS_SIZE];
+	volatile uint8_t	curs_ctl;	/* control register */
+#define CG14_CURS_ENABLE	0x4
+#define CG14_CURS_DOUBLEBUFFER	0x2 		/* use X-channel for curs */
+	volatile uint8_t	pad0[3];
+	volatile uint16_t	curs_x;		/* x position */
+	volatile uint16_t	curs_y;		/* y position */
+	volatile uint32_t	curs_color1;	/* color register 1 */
+	volatile uint32_t	curs_color2;	/* color register 2 */
+	volatile uint32_t	pad[444];	/* pad to 2KB boundary */
+	volatile uint32_t	curs_plane0incr[CG14_CURS_SIZE]; /* autoincr */
+	volatile uint32_t	curs_plane1incr[CG14_CURS_SIZE]; /* autoincr */
+};
+
 typedef struct {
-	unsigned int	*fb;
+	unsigned char	*fb;
 	unsigned char	*x32;
 	unsigned char	*xlut;
+	struct cg14curs	*curs;
 	int		width;
 	int		height;
+	int		use_shadow;
+	int		HWCursor;
+	void *		shadow;
 	sbusDevicePtr	psdp;
 	CloseScreenProcPtr CloseScreen;
+	CreateScreenResourcesProcPtr CreateScreenResources;
 	OptionInfoPtr	Options;
+	xf86CursorInfoPtr	CursorInfoRec;
 } Cg14Rec, *Cg14Ptr;
 
+Bool CG14SetupCursor(ScreenPtr);
+
 #define GET_CG14_FROM_SCRN(p)    ((Cg14Ptr)((p)->driverPrivate))
 
 /*

Index: xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_driver.c
diff -u xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_driver.c:1.5 xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_driver.c:1.6
--- xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_driver.c:1.5	Thu Apr 14 01:37:22 2011
+++ xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_driver.c	Thu Apr 14 16:48:59 2011
@@ -35,8 +35,11 @@
 
 #include "fb.h"
 #include "xf86cmap.h"
+#include "shadow.h"
 #include "cg14.h"
 
+#define static
+
 static const OptionInfoRec * CG14AvailableOptions(int chipid, int busid);
 static void	CG14Identify(int flags);
 static Bool	CG14Probe(DriverPtr drv, int flags);
@@ -49,6 +52,8 @@
 static Bool	CG14SaveScreen(ScreenPtr pScreen, int mode);
 static void	CG14InitCplane24(ScrnInfoPtr pScrn);
 static void	CG14ExitCplane24(ScrnInfoPtr pScrn);
+static void    *CG14WindowLinear(ScreenPtr, CARD32, CARD32, int, CARD32 *,
+			      void *);
 
 /* Required if the driver supports mode switching */
 static Bool	CG14SwitchMode(int scrnIndex, DisplayModePtr mode, int flags);
@@ -87,7 +92,14 @@
     0
 };
 
+typedef enum {
+	OPTION_SHADOW_FB,
+	OPTION_HW_CURSOR,
+	OPTION_SW_CURSOR
+} CG14Opts;
+
 static const OptionInfoRec CG14Options[] = {
+    { OPTION_SHADOW_FB, "ShadowFB", OPTV_BOOLEAN, {0}, TRUE},
     { -1,			NULL,		OPTV_NONE,	{0}, FALSE }
 };
 
@@ -283,7 +295,7 @@
 {
     Cg14Ptr pCg14;
     sbusDevicePtr psdp = NULL;
-    int i;
+    int i, from;
 
     if (flags & PROBE_DETECT) return FALSE;
 
@@ -352,6 +364,8 @@
 	return FALSE;
     memcpy(pCg14->Options, CG14Options, sizeof(CG14Options));
     xf86ProcessOptions(pScrn->scrnIndex, pScrn->options, pCg14->Options);
+    pCg14->use_shadow = xf86ReturnOptValBool(pCg14->Options, OPTION_SHADOW_FB,
+        TRUE);
 
     /*
      * This must happen after pScrn->display has been set because
@@ -395,6 +409,25 @@
 	return FALSE;
     }
 
+    if (pCg14->use_shadow) {
+	xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Using shadow framebuffer\n");
+	if (xf86LoadSubModule(pScrn, "shadow") == NULL) {
+	    CG14FreeRec(pScrn);
+	    return FALSE;
+	}
+    }
+
+    from = X_DEFAULT;
+    pCg14->HWCursor = TRUE;
+    if (xf86GetOptValBool(pCg14->Options, OPTION_HW_CURSOR, &pCg14->HWCursor))
+	from = X_CONFIG;
+    if (xf86ReturnOptValBool(pCg14->Options, OPTION_SW_CURSOR, FALSE)) {
+	from = X_CONFIG;
+	pCg14->HWCursor = FALSE;
+    }
+    xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n",
+		pCg14->HWCursor ? "HW" : "SW");
+
     /*********************
     set up clock and mode stuff
     *********************/
@@ -418,6 +451,46 @@
     return TRUE;
 }
 
+static Bool
+CG14CreateScreenResources(ScreenPtr pScreen)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    Cg14Ptr pCg14 = GET_CG14_FROM_SCRN(pScrn);
+    PixmapPtr pPixmap;
+    Bool ret;
+
+    pScreen->CreateScreenResources = pCg14->CreateScreenResources;
+    ret = pScreen->CreateScreenResources(pScreen);
+    pScreen->CreateScreenResources = CG14CreateScreenResources;
+
+    if (!ret)
+	return FALSE;
+
+    pPixmap = pScreen->GetScreenPixmap(pScreen);
+
+    if (!shadowAdd(pScreen, pPixmap, shadowUpdatePackedWeak(),
+	CG14WindowLinear, 0, NULL)) {
+	return FALSE;
+    }
+    return TRUE;
+}
+
+
+static Bool
+CG14ShadowInit(ScreenPtr pScreen)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    Cg14Ptr pCg14 = GET_CG14_FROM_SCRN(pScrn);
+
+    if (!shadowSetup(pScreen)) {
+	return FALSE;
+    }
+
+    pCg14->CreateScreenResources = pScreen->CreateScreenResources;
+    pScreen->CreateScreenResources = CG14CreateScreenResources;
+
+    return TRUE;
+}
 /* Mandatory */
 
 /* This gets called at the start of each server generation */
@@ -425,28 +498,27 @@
 static Bool
 CG14ScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, char **argv)
 {
-    ScrnInfoPtr pScrn;
-    Cg14Ptr pCg14;
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    Cg14Ptr pCg14 = GET_CG14_FROM_SCRN(pScrn);
     VisualPtr visual;
     int ret;
 
-    /* 
-     * First get the ScrnInfoRec
-     */
-    pScrn = xf86Screens[pScreen->myNum];
-
-    pCg14 = GET_CG14_FROM_SCRN(pScrn);
-
     /* Map the CG14 memory */
     pCg14->fb = xf86MapSbusMem (pCg14->psdp, CG14_BGR_VOFF, 4 *
 				(pCg14->psdp->width * pCg14->psdp->height));
     pCg14->x32 = xf86MapSbusMem (pCg14->psdp, CG14_X32_VOFF,
 				 (pCg14->psdp->width * pCg14->psdp->height));
     pCg14->xlut = xf86MapSbusMem (pCg14->psdp, CG14_XLUT_VOFF, 4096);
+    pCg14->curs = xf86MapSbusMem (pCg14->psdp, CG14_CURSOR_VOFF, 4096);
 
-    if (! pCg14->fb || !pCg14->x32 || !pCg14->xlut) {
-    	xf86Msg(X_ERROR, "can't mmap something: fd %08x  x32 %08x xlut %08x\n",
-	    (uint32_t)pCg14->fb, (uint32_t)pCg14->x32, (uint32_t)pCg14->xlut);
+    pCg14->width = pCg14->psdp->width;
+    pCg14->height = pCg14->psdp->height;
+
+    if (! pCg14->fb || !pCg14->x32 || !pCg14->xlut || !pCg14->curs) {
+    	xf86Msg(X_ERROR,
+	    "can't mmap something: fd %08x  x32 %08x xlut %08x cursor %08x\n",
+	    (uint32_t)pCg14->fb, (uint32_t)pCg14->x32, (uint32_t)pCg14->xlut,
+	    (uint32_t)pCg14->curs);
 	return FALSE;
     }
 
@@ -475,19 +547,40 @@
 
     miSetPixmapDepths ();
 
+    if (pCg14->use_shadow) {
+	pCg14->shadow = xcalloc(1, pScrn->virtualX * pScrn->virtualY * 4);
+		
+	if (!pCg14->shadow) {
+	    xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+	        "Failed to allocate shadow framebuffer\n");
+	    return FALSE;
+	}
+    }
+
     /*
      * Call the framebuffer layer's ScreenInit function, and fill in other
      * pScreen fields.
      */
 
     CG14InitCplane24(pScrn);
-    ret = fbScreenInit(pScreen, pCg14->fb, pScrn->virtualX,
+    ret = fbScreenInit(pScreen, pCg14->use_shadow ? pCg14->shadow : pCg14->fb,
+    		       pScrn->virtualX,
 		       pScrn->virtualY, pScrn->xDpi, pScrn->yDpi,
 		       pScrn->virtualX, pScrn->bitsPerPixel);
 
     if (!ret)
 	return FALSE;
 
+    /* must be after RGB ordering fixed */
+    fbPictureInit (pScreen, 0, 0);
+
+xf86DrvMsg(scrnIndex, X_ERROR, "calling CG14ShadowInit\n");
+    if (pCg14->use_shadow && !CG14ShadowInit(pScreen)) {
+	xf86DrvMsg(scrnIndex, X_ERROR,
+		    "shadow framebuffer initialization failed\n");
+	return FALSE;
+    }
+
     miInitializeBackingStore(pScreen);
     xf86SetBackingStore(pScreen);
     xf86SetSilkenMouse(pScreen);
@@ -509,14 +602,13 @@
 	}
     }
 
-#ifdef RENDER
-    /* must be after RGB ordering fixed */
-    fbPictureInit (pScreen, 0, 0);
-#endif
-
     /* Initialise cursor functions */
     miDCInitialize (pScreen, xf86GetPointerScreenFuncs());
 
+    /* check for hardware cursor support */
+    if (pCg14->HWCursor)
+	CG14SetupCursor(pScreen);
+
     /* Initialise default colourmap */
     if (!miCreateDefColormap(pScreen))
 	return FALSE;
@@ -601,6 +693,14 @@
 {
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     Cg14Ptr pCg14 = GET_CG14_FROM_SCRN(pScrn);
+    PixmapPtr pPixmap;
+
+    if (pCg14->use_shadow) {
+
+	pPixmap = pScreen->GetScreenPixmap(pScreen);
+	shadowRemove(pScreen, pPixmap);
+	pCg14->use_shadow = FALSE;
+    }
 
     pScrn->vtSema = FALSE;
     CG14ExitCplane24 (pScrn);
@@ -609,12 +709,22 @@
     xf86UnmapSbusMem(pCg14->psdp, pCg14->x32,
 		     (pCg14->psdp->width * pCg14->psdp->height));
     xf86UnmapSbusMem(pCg14->psdp, pCg14->xlut, 4096);
+    xf86UnmapSbusMem(pCg14->psdp, pCg14->curs, 4096);
     
     pScreen->CloseScreen = pCg14->CloseScreen;
     return (*pScreen->CloseScreen)(scrnIndex, pScreen);
-    return FALSE;
 }
 
+static void *
+CG14WindowLinear(ScreenPtr pScreen, CARD32 row, CARD32 offset, int mode,
+		CARD32 *size, void *closure)
+{
+    ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+    Cg14Ptr pCg14 = GET_CG14_FROM_SCRN(pScrn);
+
+    *size = pCg14->width << 2;
+    return (CARD8 *)pCg14->fb + row * (pCg14->width << 2) + offset;
+}
 
 /* Free up any per-generation data structures */
 

Added files:

Index: xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_cursor.c
diff -u /dev/null xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_cursor.c:1.1
--- /dev/null	Thu Apr 14 16:48:59 2011
+++ xsrc/external/mit/xf86-video-suncg14/dist/src/cg14_cursor.c	Thu Apr 14 16:48:59 2011
@@ -0,0 +1,131 @@
+/* $NetBSD: cg14_cursor.c,v 1.1 2011/04/14 16:48:59 macallan Exp $ */
+/*
+ * Copyright (c) 2005 Michael Lorenz
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *    - Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *    - Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/endian.h>
+#include <dev/wscons/wsconsio.h>
+#include <errno.h>
+
+/* all driver need this */
+#include "xf86.h"
+#include "xf86_OSproc.h"
+
+#include "cg14.h"
+
+static void CG14LoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src);
+static void CG14SetCursorPosition(ScrnInfoPtr pScrn, int x, int y);
+static void CG14SetCursorColors(ScrnInfoPtr pScrn, int bg, int fg);
+
+static void
+CG14LoadCursorImage(ScrnInfoPtr pScrn, unsigned char *src)
+{
+	Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn);
+	uint32_t buf[64];
+	uint32_t *img = buf;
+	int i;
+
+	memcpy(buf, src, 256); /* to make sure it's aligned */
+	for (i = 0; i < 32; i++) {
+		pCG14->curs->curs_plane0[i] = *img;
+		img++;
+	}
+	for (i = 0; i < 32; i++) {
+		pCG14->curs->curs_plane1[i] = *img;
+		img++;
+	}
+}
+
+void 
+CG14ShowCursor(ScrnInfoPtr pScrn)
+{
+	Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn);
+
+	pCG14->curs->curs_ctl = CG14_CURS_ENABLE;
+}
+
+void
+CG14HideCursor(ScrnInfoPtr pScrn)
+{
+	Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn);
+
+	pCG14->curs->curs_ctl = 0;
+}
+
+static void
+CG14SetCursorPosition(ScrnInfoPtr pScrn, int x, int y)
+{
+	Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn);
+
+	pCG14->curs->curs_x = x;
+	pCG14->curs->curs_y = y;
+}
+
+static void
+CG14SetCursorColors(ScrnInfoPtr pScrn, int bg, int fg)
+{
+	Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn);
+#define RGB2BGR(x) (((x & 0xff0000) >> 16) | (x & 0xff00) | ((x & 0xff) << 16))
+	pCG14->curs->curs_color1 = RGB2BGR(bg);
+	pCG14->curs->curs_color2 = RGB2BGR(fg);
+}
+
+Bool 
+CG14SetupCursor(ScreenPtr pScreen)
+{
+	ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];
+	Cg14Ptr pCG14 = GET_CG14_FROM_SCRN(pScrn);
+	xf86CursorInfoPtr infoPtr;
+	
+	pCG14->curs->curs_ctl = 0;
+
+	infoPtr = xf86CreateCursorInfoRec();
+	if(!infoPtr) return FALSE;
+    
+	pCG14->CursorInfoRec = infoPtr;
+		
+	xf86Msg(X_INFO, "HW cursor enabled\n");
+
+	infoPtr->MaxWidth = 32;
+	infoPtr->MaxHeight = 32;
+	
+	infoPtr->Flags = HARDWARE_CURSOR_AND_SOURCE_WITH_MASK |
+	    HARDWARE_CURSOR_TRUECOLOR_AT_8BPP |
+	    HARDWARE_CURSOR_SWAP_SOURCE_AND_MASK;
+	infoPtr->SetCursorColors = CG14SetCursorColors;
+	infoPtr->SetCursorPosition = CG14SetCursorPosition;
+	infoPtr->LoadCursorImage = CG14LoadCursorImage;
+	infoPtr->HideCursor = CG14HideCursor;
+	infoPtr->ShowCursor = CG14ShowCursor;
+	infoPtr->UseHWCursor = NULL;
+
+	return xf86InitCursor(pScreen, infoPtr);
+}

Reply via email to