Module Name:    xsrc
Committed By:   msaitoh
Date:           Sun Nov  9 07:40:31 UTC 2014

Modified Files:
        xsrc/external/mit/xf86-video-wsfb/dist/src [netbsd-6]: wsfb_driver.c

Log Message:
Pull up following revision(s) (requested by tsutsui in ticket #1183):
        external/mit/xf86-video-wsfb/dist/src/wsfb_driver.c: revision 1.22
        external/mit/xf86-video-wsfb/dist/src/wsfb_driver.c: revision 1.23
        external/mit/xf86-video-wsfb/dist/src/wsfb_driver.c: revision 1.25
Fix wrong VRAM size calculation on old drivers without GET_FBINFO ioctl.
The linebytes is a byte number of width so it should be
(linebytes * height), not (width * linebytes).
XXX: I'm not sure where WSDISPLAYIO_GET_FBINFO implementation was discussed
     but I wonder if we should use proper ifdef or macro to share this
     third party Xorg driver with OpenBSD...
No need to handle colormap ioctls if cmsize == 0 even in WSFB_CI case.
Add kludge to use luna68k 4/8bpp framebuffers as a monochrome server.
The idea is taken from mlterm-fb --depth option implementation.
This change should not affect other framebuffer types.
Tested on 4bpp on LUNA and 1bpp/8bpp on LUNA-II.


To generate a diff of this commit:
cvs rdiff -u -r1.13.2.3 -r1.13.2.4 \
    xsrc/external/mit/xf86-video-wsfb/dist/src/wsfb_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-wsfb/dist/src/wsfb_driver.c
diff -u xsrc/external/mit/xf86-video-wsfb/dist/src/wsfb_driver.c:1.13.2.3 xsrc/external/mit/xf86-video-wsfb/dist/src/wsfb_driver.c:1.13.2.4
--- xsrc/external/mit/xf86-video-wsfb/dist/src/wsfb_driver.c:1.13.2.3	Thu Aug  7 09:07:36 2014
+++ xsrc/external/mit/xf86-video-wsfb/dist/src/wsfb_driver.c	Sun Nov  9 07:40:31 2014
@@ -406,7 +406,7 @@ static Bool
 WsfbPreInit(ScrnInfoPtr pScrn, int flags)
 {
 	WsfbPtr fPtr;
-	int default_depth, wstype;
+	int default_depth, bitsperpixel, wstype;
 	char *dev, *s;
 	char *mod = NULL;
 	const char *reqSym = NULL;
@@ -498,13 +498,14 @@ WsfbPreInit(ScrnInfoPtr pScrn, int flags
 			fbi->fbi_subtype.fbi_cmapinfo.cmap_entries = info.cmsize;
 		}
 		fbi->fbi_flags = 0;
-		fbi->fbi_fbsize = info.width * lb;
+		fbi->fbi_fbsize = lb * info.height;
 
 	}
 	/*
 	 * Allocate room for saving the colormap.
 	 */
-	if (fPtr->fbi.fbi_pixeltype == WSFB_CI) {
+	if (fPtr->fbi.fbi_pixeltype == WSFB_CI &&
+	    fPtr->fbi.fbi_subtype.fbi_cmapinfo.cmap_entries > 0) {
 		fPtr->saved_cmap.red =
 		    (unsigned char *)xalloc(fPtr->fbi.fbi_subtype.fbi_cmapinfo.cmap_entries);
 		if (fPtr->saved_cmap.red == NULL) {
@@ -536,17 +537,34 @@ WsfbPreInit(ScrnInfoPtr pScrn, int flags
 
 	/* Handle depth */
 	default_depth = fPtr->fbi.fbi_bitsperpixel <= 24 ? fPtr->fbi.fbi_bitsperpixel : 24;
+	bitsperpixel = fPtr->fbi.fbi_bitsperpixel;
+#if defined(__NetBSD__) && defined(WSDISPLAY_TYPE_LUNA)
+	if (wstype == WSDISPLAY_TYPE_LUNA) {
+		/*
+		 * XXX
+		 * LUNA's color framebuffers support 4bpp or 8bpp
+		 * but they have multiple 1bpp VRAM planes like ancient VGA.
+		 * For now, Xorg server supports only the first one plane
+		 * as 1bpp monochrome server.
+		 *
+		 * Note OpenBSD/luna88k workarounds this by switching depth
+		 * and palette settings by WSDISPLAYIO_SETGFXMODE ioctl.
+		 */
+		default_depth = 1;
+		bitsperpixel = 1;
+	}
+#endif
 	if (!xf86SetDepthBpp(pScrn, default_depth, default_depth,
-		fPtr->fbi.fbi_bitsperpixel,
-		fPtr->fbi.fbi_bitsperpixel >= 24 ? Support24bppFb|Support32bppFb : 0))
+		bitsperpixel,
+		bitsperpixel >= 24 ? Support24bppFb|Support32bppFb : 0))
 		return FALSE;
 
 	/* Check consistency. */
-	if (pScrn->bitsPerPixel != fPtr->fbi.fbi_bitsperpixel) {
+	if (pScrn->bitsPerPixel != bitsperpixel) {
 		xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
 		    "specified depth (%d) or bpp (%d) doesn't match "
 		    "framebuffer depth (%d)\n", pScrn->depth, 
-		    pScrn->bitsPerPixel, fPtr->fbi.fbi_bitsperpixel);
+		    pScrn->bitsPerPixel, bitsperpixel);
 		return FALSE;
 	}
 	xf86PrintDepthBpp(pScrn);
@@ -1026,6 +1044,35 @@ WsfbScreenInit(int scrnIndex, ScreenPtr 
 				NULL, flags))
 		return FALSE;
 
+#if defined(__NetBSD__) && defined(WSDISPLAY_TYPE_LUNA)
+	if (wstype == WSDISPLAY_TYPE_LUNA) {
+		ncolors = fPtr->fbi.fbi_subtype.fbi_cmapinfo.cmap_entries;
+		if (ncolors > 0) {
+			/*
+			 * Override palette to use 4bpp/8bpp framebuffers as
+			 * monochrome server by using only the first plane.
+			 * See also comment in WsfbPreInit().
+			 */
+			struct wsdisplay_cmap cmap;
+			uint8_t r[256], g[256], b[256];
+			int p;
+
+			for (p = 0; p < ncolors; p++)
+				r[p] = g[p] = b[p] = (p & 1) ? 0xff : 0;
+			cmap.index = 0;
+			cmap.count = ncolors;
+			cmap.red   = r;
+			cmap.green = g;
+			cmap.blue  = b;
+			if (ioctl(fPtr->fd, WSDISPLAYIO_PUTCMAP, &cmap) == -1) {
+				xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
+				   "ioctl WSDISPLAYIO_PUTCMAP: %s\n",
+				   strerror(errno));
+			}
+		}
+	}
+#endif
+
 	pScreen->SaveScreen = WsfbSaveScreen;
 
 #ifdef XvExtension
@@ -1199,6 +1246,10 @@ WsfbLoadPalette(ScrnInfoPtr pScrn, int n
 
 	TRACE_ENTER("LoadPalette");
 
+	/* nothing to do if there is no color palette support */
+	if (fPtr->fbi.fbi_subtype.fbi_cmapinfo.cmap_entries == 0)
+		return;
+
 	cmap.count   = 1;
 	cmap.red   = red;
 	cmap.green = green;
@@ -1278,6 +1329,10 @@ WsfbSave(ScrnInfoPtr pScrn)
 	if (fPtr->fbi.fbi_pixeltype != WSFB_CI)
 		return;
 
+	/* nothing to do if no color palette support */
+	if (fPtr->fbi.fbi_subtype.fbi_cmapinfo.cmap_entries == 0)
+		return;
+
 	fPtr->saved_cmap.index = 0;
 	fPtr->saved_cmap.count = fPtr->fbi.fbi_subtype.fbi_cmapinfo.cmap_entries;
 	if (ioctl(fPtr->fd, WSDISPLAYIO_GETCMAP,
@@ -1297,7 +1352,8 @@ WsfbRestore(ScrnInfoPtr pScrn)
 
 	TRACE_ENTER("WsfbRestore");
 
-	if (fPtr->fbi.fbi_pixeltype == WSFB_CI) {
+	if (fPtr->fbi.fbi_pixeltype == WSFB_CI &&
+	    fPtr->fbi.fbi_subtype.fbi_cmapinfo.cmap_entries > 0) {
 		/* reset colormap for text mode */
 		if (ioctl(fPtr->fd, WSDISPLAYIO_PUTCMAP,
 			  &(fPtr->saved_cmap)) == -1) {

Reply via email to