2 * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Thomas Roell not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Thomas Roell makes no representations
11 * about the suitability of this software for any purpose. It is provided
12 * "as is" without express or implied warranty.
14 * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
25 #ifdef HAVE_XORG_CONFIG_H
26 #include <xorg-config.h>
30 #include <X11/Xproto.h>
31 #include "windowstr.h"
33 #include "mipointer.h"
39 #include <X11/extensions/xf86dgaproto.h>
43 #define NOMAPYET (ColormapPtr) 0
46 vgaListInstalledColormaps(pScreen, pmaps)
50 /* By the time we are processing requests, we can guarantee that there
51 * is always a colormap installed */
53 *pmaps = GetInstalledmiColormap(pScreen)->mid;
58 vgaGetInstalledColormaps(pScreen, pmaps)
62 /* By the time we are processing requests, we can guarantee that there
63 * is always a colormap installed */
65 *pmaps = GetInstalledmiColormap(pScreen);
69 int vgaCheckColorMap(ColormapPtr pmap)
71 return (pmap != GetInstalledmiColormap(pmap->pScreen));
76 vgaStoreColors(pmap, ndef, pdefs)
82 unsigned char *cmap, *tmp = NULL;
83 xColorItem directDefs[256];
84 Bool new_overscan = FALSE;
87 /* This can get called before the ScrnInfoRec is installed so we
88 can't rely on getting it with XF86SCRNINFO() */
89 int scrnIndex = pmap->pScreen->myNum;
90 ScrnInfoPtr scrninfp = xf86Screens[scrnIndex];
91 vgaHWPtr hwp = VGAHWPTR(scrninfp);
93 unsigned char overscan = hwp->ModeReg.Attribute[OVERSCAN];
94 unsigned char tmp_overscan = 0;
96 if (vgaCheckColorMap(pmap))
99 if ((pmap->pVisual->class | DynamicClass) == DirectColor)
101 ndef = miExpandDirectColors (pmap, ndef, pdefs, directDefs);
105 writeColormap = scrninfp->vtSema;
106 if (DGAAvailable(scrnIndex))
108 writeColormap = writeColormap ||
109 (DGAGetDirectMode(scrnIndex) &&
110 !(DGAGetFlags(scrnIndex) & XF86DGADirectColormap)) ||
111 (DGAGetFlags(scrnIndex) & XF86DGAHasColormap);
115 hwp->enablePalette(hwp);
117 for(i = 0; i < ndef; i++)
119 if (pdefs[i].pixel == overscan)
123 cmap = &(hwp->ModeReg.DAC[pdefs[i].pixel*3]);
124 if (scrninfp->rgbBits == 8) {
125 cmap[0] = pdefs[i].red >> 8;
126 cmap[1] = pdefs[i].green >> 8;
127 cmap[2] = pdefs[i].blue >> 8;
130 cmap[0] = pdefs[i].red >> 10;
131 cmap[1] = pdefs[i].green >> 10;
132 cmap[2] = pdefs[i].blue >> 10;
137 /* The LCD doesn't like white */
138 if (cmap[0] == 63) cmap[0]= 62;
139 if (cmap[1] == 63) cmap[1]= 62;
140 if (cmap[2] == 63) cmap[2]= 62;
146 if (hwp->ShowOverscan && i == 255)
148 hwp->writeDacWriteAddr(hwp, pdefs[i].pixel);
150 hwp->writeDacData(hwp, cmap[0]);
152 hwp->writeDacData(hwp, cmap[1]);
154 hwp->writeDacData(hwp, cmap[2]);
158 if (new_overscan && !hwp->ShowOverscan)
160 new_overscan = FALSE;
161 for(i = 0; i < ndef; i++)
163 if (pdefs[i].pixel == overscan)
165 if ((pdefs[i].red != 0) ||
166 (pdefs[i].green != 0) ||
167 (pdefs[i].blue != 0))
170 tmp_overscan = overscan;
171 tmp = &(hwp->ModeReg.DAC[pdefs[i].pixel*3]);
179 * Find a black pixel, or the nearest match.
181 for (i=255; i >= 0; i--)
183 cmap = &(hwp->ModeReg.DAC[i*3]);
184 if ((cmap[0] == 0) && (cmap[1] == 0) && (cmap[2] == 0))
191 if ((cmap[0] < tmp[0]) &&
192 (cmap[1] < tmp[1]) && (cmap[2] < tmp[2]))
201 overscan = tmp_overscan;
203 hwp->ModeReg.Attribute[OVERSCAN] = overscan;
206 hwp->writeAttr(hwp, OVERSCAN, overscan);
212 hwp->disablePalette(hwp);
217 vgaInstallColormap(pmap)
220 ColormapPtr oldmap = GetInstalledmiColormap(pmap->pScreen);
231 if ((pmap->pVisual->class | DynamicClass) == DirectColor)
232 entries = (pmap->pVisual->redMask |
233 pmap->pVisual->greenMask |
234 pmap->pVisual->blueMask) + 1;
236 entries = pmap->pVisual->ColormapEntries;
238 ppix = (Pixel *)malloc( entries * sizeof(Pixel));
239 prgb = (xrgb *)malloc( entries * sizeof(xrgb));
240 defs = (xColorItem *)malloc(entries * sizeof(xColorItem));
242 if ( oldmap != NOMAPYET)
243 WalkTree( pmap->pScreen, TellLostMap, &oldmap->mid);
245 SetInstalledmiColormap(pmap->pScreen, pmap);
247 for ( i=0; i<entries; i++) ppix[i] = i;
249 QueryColors(pmap, entries, ppix, prgb, serverClient);
251 for ( i=0; i<entries; i++) /* convert xrgbs to xColorItems */
253 defs[i].pixel = ppix[i];
254 defs[i].red = prgb[i].red;
255 defs[i].green = prgb[i].green;
256 defs[i].blue = prgb[i].blue;
257 defs[i].flags = DoRed|DoGreen|DoBlue;
259 pmap->pScreen->StoreColors(pmap, entries, defs);
261 WalkTree(pmap->pScreen, TellGainedMap, &pmap->mid);
270 vgaUninstallColormap(pmap)
274 ColormapPtr defColormap;
276 if ( pmap != GetInstalledmiColormap(pmap->pScreen))
279 dixLookupResourceByType((pointer *)&defColormap, pmap->pScreen->defColormap,
280 RT_COLORMAP, serverClient, DixInstallAccess);
282 if (defColormap == GetInstalledmiColormap(pmap->pScreen))
285 (*pmap->pScreen->InstallColormap) (defColormap);
290 vgaHandleColormaps(ScreenPtr pScreen, ScrnInfoPtr scrnp)
292 if (scrnp->bitsPerPixel > 1) {
293 if (scrnp->bitsPerPixel <= 8) { /* For 8bpp SVGA and VGA16 */
294 pScreen->InstallColormap = vgaInstallColormap;
295 pScreen->UninstallColormap = vgaUninstallColormap;
296 pScreen->ListInstalledColormaps = vgaListInstalledColormaps;
297 pScreen->StoreColors = vgaStoreColors;