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.
24 #ifdef HAVE_XORG_CONFIG_H
25 #include <xorg-config.h>
29 #include <X11/Xproto.h>
30 #include "windowstr.h"
32 #include "mipointer.h"
38 #include <X11/extensions/xf86dgaproto.h>
41 #define NOMAPYET (ColormapPtr) 0
44 vgaListInstalledColormaps(pScreen
, pmaps
)
48 /* By the time we are processing requests, we can guarantee that there
49 * is always a colormap installed */
51 *pmaps
= GetInstalledmiColormap(pScreen
)->mid
;
56 vgaGetInstalledColormaps(pScreen
, pmaps
)
60 /* By the time we are processing requests, we can guarantee that there
61 * is always a colormap installed */
63 *pmaps
= GetInstalledmiColormap(pScreen
);
68 vgaCheckColorMap(ColormapPtr pmap
)
70 return (pmap
!= GetInstalledmiColormap(pmap
->pScreen
));
74 vgaStoreColors(pmap
, ndef
, pdefs
)
80 unsigned char *cmap
, *tmp
= NULL
;
81 xColorItem directDefs
[256];
82 Bool new_overscan
= FALSE
;
84 int scrnIndex
= pmap
->pScreen
->myNum
;
85 ScrnInfoPtr scrninfp
= xf86ScreenToScrn(pmap
->pScreen
);
86 vgaHWPtr hwp
= VGAHWPTR(scrninfp
);
88 unsigned char overscan
= hwp
->ModeReg
.Attribute
[OVERSCAN
];
89 unsigned char tmp_overscan
= 0;
91 if (vgaCheckColorMap(pmap
))
94 if ((pmap
->pVisual
->class | DynamicClass
) == DirectColor
) {
95 ndef
= miExpandDirectColors(pmap
, ndef
, pdefs
, directDefs
);
99 writeColormap
= scrninfp
->vtSema
;
100 if (DGAScreenAvailable(pmap
->pScreen
)) {
101 writeColormap
= writeColormap
||
102 (DGAGetDirectMode(scrnIndex
) &&
103 !(DGAGetFlags(scrnIndex
) & XF86DGADirectColormap
)) ||
104 (DGAGetFlags(scrnIndex
) & XF86DGAHasColormap
);
108 hwp
->enablePalette(hwp
);
110 for (i
= 0; i
< ndef
; i
++) {
111 if (pdefs
[i
].pixel
== overscan
) {
114 cmap
= &(hwp
->ModeReg
.DAC
[pdefs
[i
].pixel
* 3]);
115 if (scrninfp
->rgbBits
== 8) {
116 cmap
[0] = pdefs
[i
].red
>> 8;
117 cmap
[1] = pdefs
[i
].green
>> 8;
118 cmap
[2] = pdefs
[i
].blue
>> 8;
121 cmap
[0] = pdefs
[i
].red
>> 10;
122 cmap
[1] = pdefs
[i
].green
>> 10;
123 cmap
[2] = pdefs
[i
].blue
>> 10;
127 /* The LCD doesn't like white */
138 if (hwp
->ShowOverscan
&& i
== 255)
140 hwp
->writeDacWriteAddr(hwp
, pdefs
[i
].pixel
);
142 hwp
->writeDacData(hwp
, cmap
[0]);
144 hwp
->writeDacData(hwp
, cmap
[1]);
146 hwp
->writeDacData(hwp
, cmap
[2]);
150 if (new_overscan
&& !hwp
->ShowOverscan
) {
151 new_overscan
= FALSE
;
152 for (i
= 0; i
< ndef
; i
++) {
153 if (pdefs
[i
].pixel
== overscan
) {
154 if ((pdefs
[i
].red
!= 0) ||
155 (pdefs
[i
].green
!= 0) || (pdefs
[i
].blue
!= 0)) {
157 tmp_overscan
= overscan
;
158 tmp
= &(hwp
->ModeReg
.DAC
[pdefs
[i
].pixel
* 3]);
165 * Find a black pixel, or the nearest match.
167 for (i
= 255; i
>= 0; i
--) {
168 cmap
= &(hwp
->ModeReg
.DAC
[i
* 3]);
169 if ((cmap
[0] == 0) && (cmap
[1] == 0) && (cmap
[2] == 0)) {
174 if ((cmap
[0] < tmp
[0]) &&
175 (cmap
[1] < tmp
[1]) && (cmap
[2] < tmp
[2])) {
182 overscan
= tmp_overscan
;
184 hwp
->ModeReg
.Attribute
[OVERSCAN
] = overscan
;
186 hwp
->writeAttr(hwp
, OVERSCAN
, overscan
);
192 hwp
->disablePalette(hwp
);
196 vgaInstallColormap(pmap
)
199 ColormapPtr oldmap
= GetInstalledmiColormap(pmap
->pScreen
);
209 if ((pmap
->pVisual
->class | DynamicClass
) == DirectColor
)
210 entries
= (pmap
->pVisual
->redMask
|
211 pmap
->pVisual
->greenMask
| pmap
->pVisual
->blueMask
) + 1;
213 entries
= pmap
->pVisual
->ColormapEntries
;
215 ppix
= (Pixel
*) malloc(entries
* sizeof(Pixel
));
216 prgb
= (xrgb
*) malloc(entries
* sizeof(xrgb
));
217 defs
= (xColorItem
*) malloc(entries
* sizeof(xColorItem
));
219 if (oldmap
!= NOMAPYET
)
220 WalkTree(pmap
->pScreen
, TellLostMap
, &oldmap
->mid
);
222 SetInstalledmiColormap(pmap
->pScreen
, pmap
);
224 for (i
= 0; i
< entries
; i
++)
227 QueryColors(pmap
, entries
, ppix
, prgb
, serverClient
);
229 for (i
= 0; i
< entries
; i
++) { /* convert xrgbs to xColorItems */
230 defs
[i
].pixel
= ppix
[i
];
231 defs
[i
].red
= prgb
[i
].red
;
232 defs
[i
].green
= prgb
[i
].green
;
233 defs
[i
].blue
= prgb
[i
].blue
;
234 defs
[i
].flags
= DoRed
| DoGreen
| DoBlue
;
236 pmap
->pScreen
->StoreColors(pmap
, entries
, defs
);
238 WalkTree(pmap
->pScreen
, TellGainedMap
, &pmap
->mid
);
246 vgaUninstallColormap(pmap
)
250 ColormapPtr defColormap
;
252 if (pmap
!= GetInstalledmiColormap(pmap
->pScreen
))
255 dixLookupResourceByType((pointer
*) &defColormap
,
256 pmap
->pScreen
->defColormap
, RT_COLORMAP
,
257 serverClient
, DixInstallAccess
);
259 if (defColormap
== GetInstalledmiColormap(pmap
->pScreen
))
262 (*pmap
->pScreen
->InstallColormap
) (defColormap
);
266 vgaHandleColormaps(ScreenPtr pScreen
, ScrnInfoPtr scrnp
)
268 if (scrnp
->bitsPerPixel
> 1) {
269 if (scrnp
->bitsPerPixel
<= 8) { /* For 8bpp SVGA and VGA16 */
270 pScreen
->InstallColormap
= vgaInstallColormap
;
271 pScreen
->UninstallColormap
= vgaUninstallColormap
;
272 pScreen
->ListInstalledColormaps
= vgaListInstalledColormaps
;
273 pScreen
->StoreColors
= vgaStoreColors
;