sunCfb24.c revision b9325ec5
1b9325ec5Stsutsui/* $Xorg: sunCfb24.c,v 1.4 2001/02/09 02:04:43 xorgcvs Exp $ */ 2b9325ec5Stsutsui 3b9325ec5Stsutsui/* 4b9325ec5Stsutsui 5b9325ec5StsutsuiCopyright 1994, 1998 The Open Group 6b9325ec5Stsutsui 7b9325ec5StsutsuiPermission to use, copy, modify, distribute, and sell this software and its 8b9325ec5Stsutsuidocumentation for any purpose is hereby granted without fee, provided that 9b9325ec5Stsutsuithe above copyright notice appear in all copies and that both that 10b9325ec5Stsutsuicopyright notice and this permission notice appear in supporting 11b9325ec5Stsutsuidocumentation. 12b9325ec5Stsutsui 13b9325ec5StsutsuiThe above copyright notice and this permission notice shall be included in all 14b9325ec5Stsutsuicopies or substantial portions of the Software. 15b9325ec5Stsutsui 16b9325ec5StsutsuiTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17b9325ec5StsutsuiIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18b9325ec5StsutsuiFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X 19b9325ec5StsutsuiCONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 20b9325ec5StsutsuiACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 21b9325ec5StsutsuiWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22b9325ec5Stsutsui 23b9325ec5StsutsuiExcept as contained in this notice, the name of The Open Group shall not be 24b9325ec5Stsutsuiused in advertising or otherwise to promote the sale, use or other dealings in 25b9325ec5Stsutsuithis Software without prior written authorization from The Open Group. 26b9325ec5Stsutsui 27b9325ec5Stsutsui*/ 28b9325ec5Stsutsui/* $XFree86: xc/programs/Xserver/hw/sun/sunCfb24.c,v 1.3 2001/12/14 19:59:42 dawes Exp $ */ 29b9325ec5Stsutsui 30b9325ec5Stsutsui/* 31b9325ec5Stsutsui * The CG8 is similar to the CG4 in that it has a mono plane, an enable 32b9325ec5Stsutsui * plane, and a color plane. While the CG4 only has an 8-bit color 33b9325ec5Stsutsui * plane the CG8 has a 24-bit color plane. 34b9325ec5Stsutsui * 35b9325ec5Stsutsui * If you have a CG4 you know that you can switch between the mono and 36b9325ec5Stsutsui * the color screens merely by dragging the pointer off the edge of the 37b9325ec5Stsutsui * screen, causing the other screen to be switched in. However this is 38b9325ec5Stsutsui * the cause of some consternation on the part of those people who have 39b9325ec5Stsutsui * both a CG4 and another frame buffer. 40b9325ec5Stsutsui * 41b9325ec5Stsutsui * Because of this problem, and some other considerations, I have chosen 42b9325ec5Stsutsui * to ignore the mono plane of the CG8 in this code. 43b9325ec5Stsutsui */ 44b9325ec5Stsutsui 45b9325ec5Stsutsui#define PSZ 32 46b9325ec5Stsutsui#include "sun.h" 47b9325ec5Stsutsui#include "fb.h" 48b9325ec5Stsutsui 49b9325ec5Stsutsui#define PIXPG_24BIT_COLOR 5 50b9325ec5Stsutsui#define PIXPG_24BIT_COLOR_INDEX (PIXPG_24BIT_COLOR << 25) 51b9325ec5Stsutsui#define PR_FORCE_UPDATE (1 << 24) 52b9325ec5Stsutsui 53b9325ec5Stsutsuistatic void CG24UpdateColormap(ScreenPtr, int, int, u_char *, u_char *, u_char *); 54b9325ec5Stsutsuistatic void CG24StoreColors(ColormapPtr, int, xColorItem *); 55b9325ec5Stsutsuistatic void CG24ScreenInit(ScreenPtr); 56b9325ec5Stsutsui 57b9325ec5Stsutsuistatic void 58b9325ec5StsutsuiCG24UpdateColormap(ScreenPtr pScreen, int index, int count, u_char *rmap, u_char *gmap, u_char *bmap) 59b9325ec5Stsutsui{ 60b9325ec5Stsutsui struct fbcmap sunCmap; 61b9325ec5Stsutsui 62b9325ec5Stsutsui sunCmap.index = index | PIXPG_24BIT_COLOR_INDEX | PR_FORCE_UPDATE; 63b9325ec5Stsutsui sunCmap.count = count; 64b9325ec5Stsutsui sunCmap.red = &rmap[index]; 65b9325ec5Stsutsui sunCmap.green = &gmap[index]; 66b9325ec5Stsutsui sunCmap.blue = &bmap[index]; 67b9325ec5Stsutsui 68b9325ec5Stsutsui if (ioctl(sunFbs[pScreen->myNum].fd, FBIOPUTCMAP, &sunCmap) == -1) 69b9325ec5Stsutsui FatalError( "CG24UpdateColormap: FBIOPUTCMAP failed\n"); 70b9325ec5Stsutsui} 71b9325ec5Stsutsui 72b9325ec5Stsutsuistatic void 73b9325ec5StsutsuiCG24StoreColors(ColormapPtr pmap, int ndef, xColorItem *pdefs) 74b9325ec5Stsutsui{ 75b9325ec5Stsutsui u_char rmap[256], gmap[256], bmap[256]; 76b9325ec5Stsutsui sunScreenPtr pPrivate = sunGetScreenPrivate(pmap->pScreen); 77b9325ec5Stsutsui VisualPtr pVisual = pmap->pVisual; 78b9325ec5Stsutsui int i; 79b9325ec5Stsutsui 80b9325ec5Stsutsui if (pPrivate->installedMap != NULL && pPrivate->installedMap != pmap) 81b9325ec5Stsutsui return; 82b9325ec5Stsutsui for (i = 0; i < 256; i++) { 83b9325ec5Stsutsui rmap[i] = pmap->red[i].co.local.red >> 8; 84b9325ec5Stsutsui gmap[i] = pmap->green[i].co.local.green >> 8; 85b9325ec5Stsutsui bmap[i] = pmap->blue[i].co.local.blue >> 8; 86b9325ec5Stsutsui } 87b9325ec5Stsutsui while (ndef--) { 88b9325ec5Stsutsui i = pdefs->pixel; 89b9325ec5Stsutsui if (pdefs->flags & DoRed) 90b9325ec5Stsutsui rmap[(i & pVisual->redMask) >> pVisual->offsetRed] = (pdefs->red >> 8); 91b9325ec5Stsutsui if (pdefs->flags & DoGreen) 92b9325ec5Stsutsui gmap[(i & pVisual->greenMask) >> pVisual->offsetGreen] = (pdefs->green >> 8); 93b9325ec5Stsutsui if (pdefs->flags & DoBlue) 94b9325ec5Stsutsui bmap[(i & pVisual->blueMask) >> pVisual->offsetBlue] = (pdefs->blue >> 8); 95b9325ec5Stsutsui pdefs++; 96b9325ec5Stsutsui } 97b9325ec5Stsutsui CG24UpdateColormap (pmap->pScreen, 0, 256, rmap, gmap, bmap); 98b9325ec5Stsutsui} 99b9325ec5Stsutsui 100b9325ec5Stsutsui#define CG8_COLOR_OFFSET 0x40000 101b9325ec5Stsutsui 102b9325ec5Stsutsuistatic void 103b9325ec5StsutsuiCG24ScreenInit(ScreenPtr pScreen) 104b9325ec5Stsutsui{ 105b9325ec5Stsutsui#ifndef STATIC_COLOR 106b9325ec5Stsutsui sunScreenPtr pPrivate = sunGetScreenPrivate(pScreen); 107b9325ec5Stsutsui#endif 108b9325ec5Stsutsui int i; 109b9325ec5Stsutsui 110b9325ec5Stsutsui /* Make sure the overlay plane is disabled */ 111b9325ec5Stsutsui for (i = 0; i < CG8_COLOR_OFFSET; i++) 112b9325ec5Stsutsui sunFbs[pScreen->myNum].fb[i] = 0; 113b9325ec5Stsutsui 114b9325ec5Stsutsui#ifndef STATIC_COLOR 115b9325ec5Stsutsui pScreen->InstallColormap = sunInstallColormap; 116b9325ec5Stsutsui pScreen->UninstallColormap = sunUninstallColormap; 117b9325ec5Stsutsui pScreen->ListInstalledColormaps = sunListInstalledColormaps; 118b9325ec5Stsutsui pScreen->StoreColors = CG24StoreColors; 119b9325ec5Stsutsui pPrivate->UpdateColormap = CG24UpdateColormap; 120b9325ec5Stsutsui if (sunFlipPixels) { 121b9325ec5Stsutsui Pixel pixel = pScreen->whitePixel; 122b9325ec5Stsutsui pScreen->whitePixel = pScreen->blackPixel; 123b9325ec5Stsutsui pScreen->blackPixel = pixel; 124b9325ec5Stsutsui } 125b9325ec5Stsutsui#endif 126b9325ec5Stsutsui} 127b9325ec5Stsutsui 128b9325ec5StsutsuiBool 129b9325ec5StsutsuisunCG8Init( 130b9325ec5Stsutsui int screen, /* what screen am I going to be */ 131b9325ec5Stsutsui ScreenPtr pScreen, /* The Screen to initialize */ 132b9325ec5Stsutsui int argc, /* The number of the Server's arguments. */ 133b9325ec5Stsutsui char **argv /* The arguments themselves. Don't change! */ 134b9325ec5Stsutsui) 135b9325ec5Stsutsui{ 136b9325ec5Stsutsui sunFbs[screen].EnterLeave = (void (*)(ScreenPtr, int))NoopDDA; 137b9325ec5Stsutsui return sunInitCommon (screen, pScreen, (off_t) 0, 138b9325ec5Stsutsui fbScreenInit, CG24ScreenInit, 139b9325ec5Stsutsui fbCreateDefColormap, sunSaveScreen, CG8_COLOR_OFFSET); 140b9325ec5Stsutsui} 141b9325ec5Stsutsui 142