sunCfb24.c revision ee7c6486
11.1Sjtc/* $Xorg: sunCfb24.c,v 1.4 2001/02/09 02:04:43 xorgcvs Exp $ */
21.1Sjtc
31.1Sjtc/*
41.1Sjtc
51.1SjtcCopyright 1994, 1998  The Open Group
61.1Sjtc
71.1SjtcPermission to use, copy, modify, distribute, and sell this software and its
81.1Sjtcdocumentation for any purpose is hereby granted without fee, provided that
91.1Sjtcthe above copyright notice appear in all copies and that both that
101.1Sjtccopyright notice and this permission notice appear in supporting
111.6Ssimonbdocumentation.
121.1Sjtc
131.1SjtcThe above copyright notice and this permission notice shall be included in all
141.1Sjtccopies or substantial portions of the Software.
151.1Sjtc
161.5SlukemTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
171.3SjtcIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
181.8SdrochnerFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE X
191.1SjtcCONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
201.1SjtcACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
211.1SjtcWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
221.1Sjtc
231.1SjtcExcept as contained in this notice, the name of The Open Group shall not be
241.1Sjtcused in advertising or otherwise to promote the sale, use or other dealings in
251.1Sjtcthis Software without prior written authorization from The Open Group.
261.1Sjtc
271.1Sjtc*/
281.1Sjtc/* $XFree86: xc/programs/Xserver/hw/sun/sunCfb24.c,v 1.3 2001/12/14 19:59:42 dawes Exp $ */
291.1Sjtc
301.7Swiz/*
311.7Swiz * The CG8 is similar to the CG4 in that it has a mono plane, an enable
321.1Sjtc * plane, and a color plane. While the CG4 only has an 8-bit color
331.2Sjtc * plane the CG8 has a 24-bit color plane.
341.2Sjtc *
351.8Sdrochner * If you have a CG4 you know that you can switch between the mono and
361.8Sdrochner * the color screens merely by dragging the pointer off the edge of the
371.8Sdrochner * screen, causing the other screen to be switched in. However this is
381.8Sdrochner * the cause of some consternation on the part of those people who have
391.8Sdrochner * both a CG4 and another frame buffer.
401.1Sjtc *
411.1Sjtc * Because of this problem, and some other considerations, I have chosen
421.1Sjtc * to ignore the mono plane of the CG8 in this code.
431.1Sjtc */
441.6Ssimonb
451.1Sjtc#define PSZ 32
461.1Sjtc#include "sun.h"
471.1Sjtc#include "fb.h"
481.1Sjtc
491.1Sjtc#define PIXPG_24BIT_COLOR 5
501.1Sjtc#define PIXPG_24BIT_COLOR_INDEX (PIXPG_24BIT_COLOR << 25)
511.1Sjtc#define PR_FORCE_UPDATE (1 << 24)
521.1Sjtc
531.1Sjtcstatic void CG24UpdateColormap(ScreenPtr, int, int, u_char *, u_char *, u_char *);
541.1Sjtcstatic void CG24StoreColors(ColormapPtr, int, xColorItem *);
551.1Sjtcstatic void CG24ScreenInit(ScreenPtr);
561.1Sjtc
571.1Sjtcstatic void
581.1SjtcCG24UpdateColormap(ScreenPtr pScreen, int index, int count, u_char *rmap, u_char *gmap, u_char *bmap)
591.1Sjtc{
601.1Sjtc    struct fbcmap sunCmap;
611.1Sjtc
621.1Sjtc    sunCmap.index = index | PIXPG_24BIT_COLOR_INDEX | PR_FORCE_UPDATE;
631.1Sjtc    sunCmap.count = count;
641.1Sjtc    sunCmap.red = &rmap[index];
651.1Sjtc    sunCmap.green = &gmap[index];
661.1Sjtc    sunCmap.blue = &bmap[index];
671.1Sjtc
681.1Sjtc    if (ioctl(sunFbs[pScreen->myNum].fd, FBIOPUTCMAP, &sunCmap) == -1)
69	FatalError( "CG24UpdateColormap: FBIOPUTCMAP failed\n");
70}
71
72static void
73CG24StoreColors(ColormapPtr pmap, int ndef, xColorItem *pdefs)
74{
75  u_char rmap[256], gmap[256], bmap[256];
76  sunScreenPtr pPrivate = sunGetScreenPrivate(pmap->pScreen);
77  VisualPtr pVisual = pmap->pVisual;
78  int i;
79
80  if (pPrivate->installedMap != NULL && pPrivate->installedMap != pmap)
81    return;
82  for (i = 0; i < 256; i++) {
83    rmap[i] = pmap->red[i].co.local.red >> 8;
84    gmap[i] = pmap->green[i].co.local.green >> 8;
85    bmap[i] = pmap->blue[i].co.local.blue >> 8;
86  }
87  while (ndef--) {
88    i = pdefs->pixel;
89    if (pdefs->flags & DoRed)
90      rmap[(i & pVisual->redMask) >> pVisual->offsetRed] = (pdefs->red >> 8);
91    if (pdefs->flags & DoGreen)
92      gmap[(i & pVisual->greenMask) >> pVisual->offsetGreen] = (pdefs->green >> 8);
93    if (pdefs->flags & DoBlue)
94      bmap[(i & pVisual->blueMask) >> pVisual->offsetBlue] = (pdefs->blue >> 8);
95    pdefs++;
96  }
97  CG24UpdateColormap (pmap->pScreen, 0, 256, rmap, gmap, bmap);
98}
99
100#define CG8_COLOR_OFFSET 0x40000
101
102static void
103CG24ScreenInit(ScreenPtr pScreen)
104{
105#ifndef STATIC_COLOR
106    sunScreenPtr pPrivate = sunGetScreenPrivate(pScreen);
107#endif
108    int i;
109
110    /* Make sure the overlay plane is disabled */
111    for (i = 0; i < CG8_COLOR_OFFSET; i++)
112	sunFbs[pScreen->myNum].fb[i] = 0;
113
114#ifndef STATIC_COLOR
115    pScreen->InstallColormap = sunInstallColormap;
116    pScreen->UninstallColormap = sunUninstallColormap;
117    pScreen->ListInstalledColormaps = sunListInstalledColormaps;
118    pScreen->StoreColors = CG24StoreColors;
119    pPrivate->UpdateColormap = CG24UpdateColormap;
120    if (sunFlipPixels) {
121	Pixel pixel = pScreen->whitePixel;
122	pScreen->whitePixel = pScreen->blackPixel;
123	pScreen->blackPixel = pixel;
124    }
125#endif
126}
127
128Bool
129sunCG8Init(
130    ScreenPtr	    pScreen,  	/* The Screen to initialize */
131    int		    argc,    	/* The number of the Server's arguments. */
132    char	    **argv   	/* The arguments themselves. Don't change! */
133)
134{
135    int	screen = pScreen->myNum;
136
137    sunFbs[screen].EnterLeave = (void (*)(ScreenPtr, int))NoopDDA;
138    return sunInitCommon (screen, pScreen, (off_t) 0,
139	fbScreenInit, CG24ScreenInit,
140	fbCreateDefColormap, sunSaveScreen, CG8_COLOR_OFFSET);
141}
142
143