Module Name: xsrc Committed By: mrg Date: Mon Nov 9 05:19:11 UTC 2009
Modified Files: xsrc/external/mit/xf86-video-wsfb/dist/src: wsfb_driver.c Log Message: merge xf86-video-wsfb 0.3.0 To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.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.3 xsrc/external/mit/xf86-video-wsfb/dist/src/wsfb_driver.c:1.4 --- xsrc/external/mit/xf86-video-wsfb/dist/src/wsfb_driver.c:1.3 Fri Jun 12 01:53:00 2009 +++ xsrc/external/mit/xf86-video-wsfb/dist/src/wsfb_driver.c Mon Nov 9 05:19:11 2009 @@ -1,4 +1,4 @@ -/* $OpenBSD: wsfb_driver.c,v 1.19 2003/04/27 16:42:32 matthieu Exp $ */ +/* $OpenBSD: wsfb_driver.c,v 1.16 2009/09/13 19:33:49 matthieu Exp $ */ /* * Copyright (c) 2001 Matthieu Herrb * All rights reserved. @@ -40,13 +40,15 @@ #include "config.h" #endif +#include <errno.h> #include <fcntl.h> #include <sys/types.h> +#include <sys/mman.h> #include <sys/time.h> #include <errno.h> #include <dev/wscons/wsconsio.h> -/* all driver need this */ +/* All drivers need this. */ #include "xf86.h" #include "xf86_OSproc.h" @@ -58,11 +60,19 @@ #include "shadow.h" #include "dgaproc.h" -/* for visuals */ +/* For visuals */ +#ifdef HAVE_XF1BPP +# include "xf1bpp.h" +#endif +#ifdef HAVE_XF4BPP +# include "xf4bpp.h" +#endif #include "fb.h" +#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6 #include "xf86Resources.h" #include "xf86RAC.h" +#endif #ifdef XvExtension #include "xf86xv.h" @@ -74,7 +84,7 @@ #include <sys/mman.h> -#ifdef USE_PRIVSEP +#ifdef X_PRIVSEP extern int priv_open_device(const char *); #else #define priv_open_device(n) open(n,O_RDWR|O_NONBLOCK|O_EXCL) @@ -122,7 +132,7 @@ static void WsfbSave(ScrnInfoPtr); static void WsfbRestore(ScrnInfoPtr); -/* dga stuff */ +/* DGA stuff */ #ifdef XFreeXDGA static Bool WsfbDGAOpenFramebuffer(ScrnInfoPtr, char **, unsigned char **, int *, int *, int *); @@ -133,7 +143,7 @@ static Bool WsfbDriverFunc(ScrnInfoPtr pScrn, xorgDriverFuncOp op, pointer ptr); -/* helper functions */ +/* Helper functions */ static int wsfb_open(char *); static pointer wsfb_mmap(size_t, off_t, int); @@ -144,8 +154,8 @@ }; /* - * This is intentionally screen-independent. It indicates the binding - * choice made in the first PreInit. + * This is intentionally screen-independent. + * It indicates the binding choice made in the first PreInit. */ static int pix24bpp = 0; @@ -231,7 +241,7 @@ static Bool setupDone = FALSE; const char *osname; - /* Check that we're being loaded on a OpenBSD or NetBSD system */ + /* Check that we're being loaded on a OpenBSD or NetBSD system. */ LoaderGetOS(&osname, NULL, NULL, NULL); if (!osname || (strcmp(osname, "openbsd") != 0 && strcmp(osname, "netbsd") != 0)) { @@ -289,18 +299,18 @@ WsfbChipsets); } -/* Open the framebuffer device */ +/* Open the framebuffer device. */ static int wsfb_open(char *dev) { int fd = -1; - /* try argument from XF86Config first */ + /* Try argument from XF86Config first. */ if (dev == NULL || ((fd = priv_open_device(dev)) == -1)) { - /* second: environment variable */ + /* Second: environment variable. */ dev = getenv("XDEVICE"); if (dev == NULL || ((fd = priv_open_device(dev)) == -1)) { - /* last try: default device */ + /* Last try: default device. */ dev = WSFB_DEFAULT_DEV; if ((fd = priv_open_device(dev)) == -1) { return -1; @@ -310,7 +320,7 @@ return fd; } -/* Map the framebuffer's memory */ +/* Map the framebuffer's memory. */ static pointer wsfb_mmap(size_t len, off_t off, int fd) { @@ -323,7 +333,7 @@ addr = 0; /* - * try and make it private first, that way once we get it, an + * Try and make it private first, that way once we get it, an * interloper, e.g. another server, can't get this frame buffer, * and if another server already has it, this one won't. */ @@ -416,8 +426,10 @@ fPtr->pEnt = xf86GetEntityInfo(pScrn->entityList[0]); +#if GET_ABI_MAJOR(ABI_VIDEODRV_VERSION) < 6 pScrn->racMemFlags = RAC_FB | RAC_COLORMAP | RAC_CURSOR | RAC_VIEWPORT; pScrn->racIoFlags = pScrn->racMemFlags; +#endif dev = xf86FindOptionValue(fPtr->pEnt->device->options, "device"); fPtr->fd = wsfb_open(dev); @@ -444,7 +456,7 @@ return FALSE; } /* - * Allocate room for saving the colormap + * Allocate room for saving the colormap. */ if (fPtr->info.cmsize != 0) { fPtr->saved_cmap.red = @@ -480,7 +492,7 @@ fPtr->info.depth >= 24 ? Support24bppFb|Support32bppFb : 0)) return FALSE; - /* Check consistency */ + /* Check consistency. */ if (pScrn->bitsPerPixel != fPtr->info.depth) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "specified depth (%d) or bpp (%d) doesn't match " @@ -490,11 +502,11 @@ } xf86PrintDepthBpp(pScrn); - /* Get the depth24 pixmap format */ + /* Get the depth24 pixmap format. */ if (pScrn->depth == 24 && pix24bpp == 0) pix24bpp = xf86GetBppFromDepth(pScrn, 24); - /* color weight */ + /* Color weight */ if (pScrn->depth > 8) { rgb zeros = { 0, 0, 0 }, masks; @@ -516,11 +528,11 @@ return FALSE; } - /* visual init */ + /* Visual init */ if (!xf86SetDefaultVisual(pScrn, -1)) return FALSE; - /* We don't currently support DirectColor at > 8bpp */ + /* We don't currently support DirectColor at > 8bpp . */ if (pScrn->depth > 8 && pScrn->defaultVisual != TrueColor) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "Given default visual" " (%s) is not supported at depth %d\n", @@ -539,7 +551,7 @@ xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Vidmem: %dk\n", pScrn->videoRam/1024); - /* handle options */ + /* Handle options. */ xf86CollectOptions(pScrn, NULL); if (!(fPtr->Options = xalloc(sizeof(WsfbOptions)))) return FALSE; @@ -547,7 +559,7 @@ xf86ProcessOptions(pScrn->scrnIndex, fPtr->pEnt->device->options, fPtr->Options); - /* use shadow framebuffer by default, on depth >= 8 */ + /* Use shadow framebuffer by default, on depth >= 8 */ if (pScrn->depth >= 8) fPtr->shadowFB = xf86ReturnOptValBool(fPtr->Options, OPTION_SHADOW_FB, TRUE); @@ -558,7 +570,7 @@ "Shadow FB option ignored on depth < 8"); } - /* rotation */ + /* Rotation */ fPtr->rotate = WSFB_ROTATE_NONE; if ((s = xf86GetOptValString(fPtr->Options, OPTION_ROTATE))) { if (pScrn->depth >= 8) { @@ -591,7 +603,7 @@ } } - /* fake video mode struct */ + /* Fake video mode struct. */ mode = (DisplayModePtr)xalloc(sizeof(DisplayModeRec)); mode->prev = mode; mode->next = mode; @@ -619,7 +631,7 @@ pScrn->virtualY = fPtr->info.height; pScrn->displayWidth = pScrn->virtualX; - /* Set the display resolution */ + /* Set the display resolution. */ xf86SetDpi(pScrn, 0, 0); from = X_DEFAULT; @@ -633,15 +645,27 @@ xf86DrvMsg(pScrn->scrnIndex, from, "Using %s cursor\n", fPtr->HWCursor ? "HW" : "SW"); - /* Load bpp-specific modules */ + /* Load bpp-specific modules. */ switch(pScrn->bitsPerPixel) { +#ifdef HAVE_XF1BPP + case 1: + mod = "xf1bpp"; + reqSym = "xf1bppScreenInit"; + break; +#endif +#ifdef HAVE_XF4BPP + case 4: + mod = "xf4bpp"; + reqSym = "xf4bppScreenInit"; + break; +#endif default: mod = "fb"; break; } - /* Load shadow if needed */ + /* Load shadow if needed. */ if (fPtr->shadowFB) { xf86DrvMsg(pScrn->scrnIndex, X_CONFIG, "Using \"Shadow Framebuffer\"\n"); @@ -649,7 +673,6 @@ WsfbFreeRec(pScrn); return FALSE; } - xf86LoaderReqSymLists(shadowSymbols, NULL); } if (mod && xf86LoadSubModule(pScrn, mod) == NULL) { @@ -765,7 +788,7 @@ "unsupported depth %d\n", fPtr->info.depth); return FALSE; } - /* Switch to graphics mode - required before mmap */ + /* Switch to graphics mode - required before mmap. */ if (ioctl(fPtr->fd, WSDISPLAYIO_SMODE, &wsmode) == -1) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "ioctl WSDISPLAYIO_SMODE: %s\n", @@ -784,7 +807,7 @@ WsfbSave(pScrn); pScrn->vtSema = TRUE; - /* mi layer */ + /* MI layer */ miClearVisualTypes(); if (pScrn->bitsPerPixel > 8) { if (!miSetVisualTypes(pScrn->depth, TrueColorMask, @@ -812,7 +835,34 @@ fPtr->fbstart = fPtr->fbmem; + if (fPtr->shadowFB) { + fPtr->shadow = xcalloc(1, pScrn->virtualX * pScrn->virtualY * + pScrn->bitsPerPixel); + + if (!fPtr->shadow) { + xf86DrvMsg(pScrn->scrnIndex, X_ERROR, + "Failed to allocate shadow framebuffer\n"); + return FALSE; + } + } + switch (pScrn->bitsPerPixel) { + case 1: +#ifdef HAVE_XF1BPP + ret = xf1bppScreenInit(pScreen, fPtr->fbstart, + pScrn->virtualX, pScrn->virtualY, + pScrn->xDpi, pScrn->yDpi, + pScrn->displayWidth); + break; +#endif + case 4: +#ifdef HAVE_XF4BPP + ret = xf4bppScreenInit(pScreen, fPtr->fbstart, + pScrn->virtualX, pScrn->virtualY, + pScrn->xDpi, pScrn->yDpi, + pScrn->displayWidth); + break; +#endif case 8: case 16: case 24: @@ -833,7 +883,7 @@ return FALSE; if (pScrn->bitsPerPixel > 8) { - /* Fixup RGB ordering */ + /* Fixup RGB ordering. */ visual = pScreen->visuals + pScreen->numVisuals; while (--visual >= pScreen->visuals) { if ((visual->class | DynamicClass) == DirectColor) { @@ -878,19 +928,26 @@ miInitializeBackingStore(pScreen); xf86SetBackingStore(pScreen); - /* software cursor */ + /* Software cursor. */ miDCInitialize(pScreen, xf86GetPointerScreenFuncs()); /* check for hardware cursor support */ if (fPtr->HWCursor) WsfbSetupCursor(pScreen); - /* colormap */ + /* + * Colormap + * + * Note that, even on less than 8 bit depth frame buffers, we + * expect the colormap to be programmable with 8 bit values. + * As of now, this is indeed the case on all OpenBSD supported + * graphics hardware. + */ if (!miCreateDefColormap(pScreen)) return FALSE; flags = CMAP_RELOAD_ON_MODE_SWITCH; ncolors = fPtr->info.cmsize; - /* on StaticGray visuals, fake a 256 entries colormap */ + /* On StaticGray visuals, fake a 256 entries colormap. */ if (ncolors == 0) ncolors = 256; if(!xf86HandleColormaps(pScreen, ncolors, 8, WsfbLoadPalette, @@ -910,7 +967,7 @@ } #endif - /* Wrap the current CloseScreen function */ + /* Wrap the current CloseScreen function. */ fPtr->CloseScreen = pScreen->CloseScreen; pScreen->CloseScreen = WsfbCloseScreen; @@ -922,10 +979,15 @@ WsfbCloseScreen(int scrnIndex, ScreenPtr pScreen) { ScrnInfoPtr pScrn = xf86Screens[scrnIndex]; + PixmapPtr pPixmap; WsfbPtr fPtr = WSFBPTR(pScrn); + TRACE_ENTER("WsfbCloseScreen"); + pPixmap = pScreen->GetScreenPixmap(pScreen); + shadowRemove(pScreen, pPixmap); + if (pScrn->vtSema) { WsfbRestore(pScrn); if (munmap(fPtr->fbmem, fPtr->fbmem_len) == -1) { @@ -944,8 +1006,9 @@ #endif pScrn->vtSema = FALSE; - /* unwrap CloseScreen */ + /* Unwrap CloseScreen. */ pScreen->CloseScreen = fPtr->CloseScreen; + TRACE_EXIT("WsfbCloseScreen"); return (*pScreen->CloseScreen)(scrnIndex, pScreen); } @@ -1011,6 +1074,7 @@ TRACE_ENTER("EnterVT"); pScrn->vtSema = TRUE; + TRACE_EXIT("EnterVT"); return TRUE; } @@ -1032,7 +1096,7 @@ #endif TRACE_ENTER("SwitchMode"); - /* Nothing else to do */ + /* Nothing else to do. */ return TRUE; } @@ -1072,8 +1136,10 @@ if (ioctl(fPtr->fd,WSDISPLAYIO_PUTCMAP, &cmap) == -1) ErrorF("ioctl FBIOPUTCMAP: %s\n", strerror(errno)); } else { - /* Change all colors in 2 syscalls */ - /* and limit the data to be transfered */ + /* + * Change all colors in 2 ioctls + * and limit the data to be transfered. + */ for (i = 0; i < numColors; i++) { if (indices[i] < indexMin) indexMin = indices[i]; @@ -1085,16 +1151,16 @@ cmap.red = &red[indexMin]; cmap.green = &green[indexMin]; cmap.blue = &blue[indexMin]; - /* Get current map */ + /* Get current map. */ if (ioctl(fPtr->fd, WSDISPLAYIO_GETCMAP, &cmap) == -1) ErrorF("ioctl FBIOGETCMAP: %s\n", strerror(errno)); - /* Change the colors that require updating */ + /* Change the colors that require updating. */ for (i = 0; i < numColors; i++) { red[indices[i]] = colors[indices[i]].red; green[indices[i]] = colors[indices[i]].green; blue[indices[i]] = colors[indices[i]].blue; } - /* Write the colormap back */ + /* Write the colormap back. */ if (ioctl(fPtr->fd,WSDISPLAYIO_PUTCMAP, &cmap) == -1) ErrorF("ioctl FBIOPUTCMAP: %s\n", strerror(errno)); } @@ -1119,6 +1185,7 @@ ioctl(fPtr->fd, WSDISPLAYIO_SVIDEO, &state); } + TRACE_EXIT("SaveScreen"); return TRUE; } @@ -1140,6 +1207,7 @@ xf86DrvMsg(pScrn->scrnIndex, X_ERROR, "error saving colormap %s\n", strerror(errno)); } + TRACE_EXIT("WsfbSave"); } @@ -1161,10 +1229,10 @@ } } - /* Clear the screen */ + /* Clear the screen. */ memset(fPtr->fbmem, 0, fPtr->fbmem_len); - /* Restore the text mode */ + /* Restore the text mode. */ mode = WSDISPLAYIO_MODE_EMUL; if (ioctl(fPtr->fd, WSDISPLAYIO_SMODE, &mode) == -1) { xf86DrvMsg(pScrn->scrnIndex, X_ERROR,