]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/mfb/mfbcmap.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / programs / Xserver / mfb / mfbcmap.c
1 /***********************************************************
2
3 Copyright (c) 1987  X Consortium
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 Except as contained in this notice, the name of the X Consortium shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from the X Consortium.
25
26
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28
29                         All Rights Reserved
30
31 Permission to use, copy, modify, and distribute this software and its 
32 documentation for any purpose and without fee is hereby granted, 
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in 
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.  
38
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 SOFTWARE.
46
47 ******************************************************************/
48 /* $XConsortium: mfbcmap.c,v 5.6 94/04/17 20:28:19 dpw Exp $ */
49 #include "X.h"
50 #include "scrnintstr.h"
51 #include "colormapst.h"
52 #include "resource.h"
53
54 /* A monochrome frame buffer is a static gray colormap with two entries.
55  * We have a "required list" of length 1.  Because we can only support 1
56  * colormap, we never have to change it, but we may have to change the 
57  * name we call it.  If someone installs a new colormap, we know it must
58  * look just like the old one (because we've checked in dispatch that it was
59  * a valid colormap identifier, and all the colormap IDs for this device
60  * look the same).  Nevertheless, we still have to uninstall the old colormap
61  * and install the new one.  Similarly, if someone uninstalls a colormap,
62  * we have to install the default map, even though we know those two looked
63  * alike.  
64  * The required list concept is pretty much irrelevant when you can only
65  * have one map installed at a time.  
66  */
67 static ColormapPtr InstalledMaps[MAXSCREENS];
68
69 int
70 mfbListInstalledColormaps(pScreen, pmaps)
71     ScreenPtr   pScreen;
72     Colormap    *pmaps;
73 {
74     /* By the time we are processing requests, we can guarantee that there
75      * is always a colormap installed */
76     *pmaps = InstalledMaps[pScreen->myNum]->mid;
77     return (1);
78 }
79
80
81 void
82 mfbInstallColormap(pmap)
83     ColormapPtr pmap;
84 {
85     int index = pmap->pScreen->myNum;
86     ColormapPtr oldpmap = InstalledMaps[index];
87
88     if(pmap != oldpmap)
89     {
90         /* Uninstall pInstalledMap. No hardware changes required, just
91          * notify all interested parties. */
92         if(oldpmap != (ColormapPtr)None)
93             WalkTree(pmap->pScreen, TellLostMap, (pointer)&oldpmap->mid);
94         /* Install pmap */
95         InstalledMaps[index] = pmap;
96         WalkTree(pmap->pScreen, TellGainedMap, (pointer)&pmap->mid);
97
98     }
99 }
100
101 void
102 mfbUninstallColormap(pmap)
103     ColormapPtr pmap;
104 {
105     int index = pmap->pScreen->myNum;
106     ColormapPtr curpmap = InstalledMaps[index];
107
108     if(pmap == curpmap)
109     {
110         if (pmap->mid != pmap->pScreen->defColormap)
111         {
112             curpmap = (ColormapPtr) LookupIDByType(pmap->pScreen->defColormap,
113                                                    RT_COLORMAP);
114             (*pmap->pScreen->InstallColormap)(curpmap);
115         }
116     }
117 }
118
119 /*ARGSUSED*/
120 void
121 mfbResolveColor (pred, pgreen, pblue, pVisual)
122     unsigned short      *pred;
123     unsigned short      *pgreen;
124     unsigned short      *pblue;
125     VisualPtr           pVisual;
126 {
127     /* 
128      * Gets intensity from RGB.  If intensity is >= half, pick white, else
129      * pick black.  This may well be more trouble than it's worth.
130      */
131     *pred = *pgreen = *pblue = 
132         (((30L * *pred +
133            59L * *pgreen +
134            11L * *pblue) >> 8) >= (((1<<8)-1)*50)) ? ~0 : 0;
135 }
136
137 Bool
138 mfbCreateColormap(pMap)
139     ColormapPtr pMap;
140 {
141     ScreenPtr   pScreen;
142     unsigned short  red0, green0, blue0;
143     unsigned short  red1, green1, blue1;
144     Pixel pix;
145     
146     pScreen = pMap->pScreen;
147     if (pScreen->whitePixel == 0)
148     {
149         red0 = green0 = blue0 = ~0;
150         red1 = green1 = blue1 = 0;
151     }
152     else
153     {
154         red0 = green0 = blue0 = 0;
155         red1 = green1 = blue1 = ~0;
156     }
157
158     /* this is a monochrome colormap, it only has two entries, just fill
159      * them in by hand.  If it were a more complex static map, it would be
160      * worth writing a for loop or three to initialize it */
161
162     /* this will be pixel 0 */
163     pix = 0;
164     if (AllocColor(pMap, &red0, &green0, &blue0, &pix, 0) != Success)
165         return FALSE;
166
167     /* this will be pixel 1 */
168     if (AllocColor(pMap, &red1, &green1, &blue1, &pix, 0) != Success)
169         return FALSE;
170     return TRUE;
171 }
172
173 /*ARGSUSED*/
174 void
175 mfbDestroyColormap (pMap)
176     ColormapPtr pMap;
177 {
178     return;
179 }
180
181 Bool
182 mfbCreateDefColormap (pScreen)
183     ScreenPtr   pScreen;
184 {
185     VisualPtr   pVisual;
186     ColormapPtr pColormap;
187     
188     for (pVisual = pScreen->visuals;
189          pVisual->vid != pScreen->rootVisual;
190          pVisual++)
191         ;
192     if (CreateColormap (pScreen->defColormap, pScreen, pVisual,
193                         &pColormap, AllocNone, 0) != Success)
194     {
195         return FALSE;
196     }
197     (*pScreen->InstallColormap) (pColormap);
198     return TRUE;
199 }