~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/kdrive/src/kcmap.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Id: kcmap.c,v 1.1 1999/11/02 03:54:46 keithp Exp $
 
3
 *
 
4
 * Copyright ļæ½ 1999 Keith Packard
 
5
 *
 
6
 * Permission to use, copy, modify, distribute, and sell this software and its
 
7
 * documentation for any purpose is hereby granted without fee, provided that
 
8
 * the above copyright notice appear in all copies and that both that
 
9
 * copyright notice and this permission notice appear in supporting
 
10
 * documentation, and that the name of Keith Packard not be used in
 
11
 * advertising or publicity pertaining to distribution of the software without
 
12
 * specific, written prior permission.  Keith Packard makes no
 
13
 * representations about the suitability of this software for any purpose.  It
 
14
 * is provided "as is" without express or implied warranty.
 
15
 *
 
16
 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 
17
 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 
18
 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 
19
 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 
20
 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 
21
 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 
22
 * PERFORMANCE OF THIS SOFTWARE.
 
23
 */
 
24
/* $RCSId: xc/programs/Xserver/hw/kdrive/kcmap.c,v 1.4 2000/05/24 23:57:56 keithp Exp $ */
 
25
 
 
26
#ifdef HAVE_CONFIG_H
 
27
#include <kdrive-config.h>
 
28
#endif
 
29
#include "kdrive.h"
 
30
 
 
31
/*
 
32
 * Put the entire colormap into the DAC
 
33
 */
 
34
 
 
35
void
 
36
KdSetColormap (ScreenPtr pScreen, int fb)
 
37
{
 
38
    KdScreenPriv(pScreen);
 
39
    ColormapPtr pCmap = pScreenPriv->pInstalledmap[fb];
 
40
    Pixel       pixels[KD_MAX_PSEUDO_SIZE];
 
41
    xrgb        colors[KD_MAX_PSEUDO_SIZE];
 
42
    xColorItem  defs[KD_MAX_PSEUDO_SIZE];
 
43
    int         i;
 
44
 
 
45
    if (!pScreenPriv->card->cfuncs->putColors)
 
46
        return;
 
47
    if (pScreenPriv->screen->fb[fb].depth > KD_MAX_PSEUDO_DEPTH)
 
48
        return;
 
49
    
 
50
    if (!pScreenPriv->enabled)
 
51
        return;
 
52
    
 
53
    if (!pCmap)
 
54
        return;
 
55
 
 
56
    /*
 
57
     * Make DIX convert pixels into RGB values -- this handles
 
58
     * true/direct as well as pseudo/static visuals
 
59
     */
 
60
    
 
61
    for (i = 0; i < (1 << pScreenPriv->screen->fb[fb].depth); i++)
 
62
        pixels[i] = i;
 
63
 
 
64
    QueryColors (pCmap, (1 << pScreenPriv->screen->fb[fb].depth), pixels, colors);
 
65
    
 
66
    for (i = 0; i < (1 << pScreenPriv->screen->fb[fb].depth); i++)
 
67
    {
 
68
        defs[i].pixel = i;
 
69
        defs[i].red = colors[i].red;
 
70
        defs[i].green = colors[i].green;
 
71
        defs[i].blue = colors[i].blue;
 
72
        defs[i].flags = DoRed|DoGreen|DoBlue;
 
73
    }
 
74
 
 
75
    (*pScreenPriv->card->cfuncs->putColors) (pCmap->pScreen, fb,
 
76
                                             (1 << pScreenPriv->screen->fb[fb].depth),
 
77
                                             defs);
 
78
 
 
79
    /* recolor hardware cursor */
 
80
    if (pScreenPriv->card->cfuncs->recolorCursor)
 
81
        (*pScreenPriv->card->cfuncs->recolorCursor) (pCmap->pScreen, 0, 0);
 
82
}
 
83
 
 
84
/*
 
85
 * When the hardware is enabled, save the hardware colors and store
 
86
 * the current colormap
 
87
 */
 
88
void
 
89
KdEnableColormap (ScreenPtr pScreen)
 
90
{
 
91
    KdScreenPriv(pScreen);
 
92
    int     i;
 
93
    int     fb;
 
94
    Bool    done = FALSE;
 
95
 
 
96
    if (!pScreenPriv->card->cfuncs->putColors)
 
97
        return;
 
98
    for (fb = 0; fb < KD_MAX_FB && pScreenPriv->screen->fb[fb].depth; fb++)
 
99
    {
 
100
        if (pScreenPriv->screen->fb[fb].depth <= KD_MAX_PSEUDO_DEPTH && !done)
 
101
        {
 
102
            for (i = 0; i < (1 << pScreenPriv->screen->fb[fb].depth); i++)
 
103
                pScreenPriv->systemPalette[i].pixel = i;
 
104
            (*pScreenPriv->card->cfuncs->getColors) (pScreen, fb,
 
105
                                                   (1 << pScreenPriv->screen->fb[fb].depth),
 
106
                                                   pScreenPriv->systemPalette);
 
107
            done = TRUE;
 
108
        }
 
109
        KdSetColormap (pScreen, fb);
 
110
    }
 
111
}
 
112
 
 
113
void
 
114
KdDisableColormap (ScreenPtr pScreen)
 
115
{
 
116
    KdScreenPriv(pScreen);
 
117
    int     fb;
 
118
 
 
119
    if (!pScreenPriv->card->cfuncs->putColors)
 
120
        return;
 
121
    for (fb = 0; fb < KD_MAX_FB && pScreenPriv->screen->fb[fb].depth; fb++)
 
122
    {
 
123
        if (pScreenPriv->screen->fb[fb].depth <= KD_MAX_PSEUDO_DEPTH)
 
124
        {
 
125
            (*pScreenPriv->card->cfuncs->putColors) (pScreen, fb,
 
126
                                                     (1 << pScreenPriv->screen->fb[fb].depth),
 
127
                                                     pScreenPriv->systemPalette);
 
128
            break;
 
129
        }
 
130
    }
 
131
}
 
132
 
 
133
static int
 
134
KdColormapFb (ColormapPtr   pCmap)
 
135
{
 
136
    ScreenPtr   pScreen = pCmap->pScreen;
 
137
    KdScreenPriv (pScreen);
 
138
    KdScreenInfo    *screen = pScreenPriv->screen;
 
139
    int         d;
 
140
    DepthPtr    depth;
 
141
    int         v;
 
142
    VisualID    vid = pCmap->pVisual->vid;
 
143
    int         fb;
 
144
 
 
145
    if (screen->fb[1].depth)
 
146
    {
 
147
        for (d = 0; d < pScreen->numDepths; d++)
 
148
        {
 
149
            depth = &pScreen->allowedDepths[d];
 
150
            for (v = 0; v < depth->numVids; v++)
 
151
            {
 
152
                if (depth->vids[v] == vid)
 
153
                {
 
154
                    for (fb = 0; fb < KD_MAX_FB && screen->fb[fb].depth; fb++)
 
155
                    {
 
156
                        if (depth->depth == screen->fb[fb].depth)
 
157
                            return fb;
 
158
                    }
 
159
                }
 
160
            }
 
161
        }
 
162
    }
 
163
    return 0;
 
164
}
 
165
 
 
166
/*
 
167
 * KdInstallColormap
 
168
 *
 
169
 * This function is called when the server receives a request to install a
 
170
 * colormap or when the server needs to install one on its own, like when
 
171
 * there's no window manager running and the user has moved the pointer over
 
172
 * an X client window.  It needs to build an identity Windows palette for the
 
173
 * colormap and realize it into the Windows system palette.
 
174
 */
 
175
void
 
176
KdInstallColormap (ColormapPtr pCmap)
 
177
{
 
178
    KdScreenPriv(pCmap->pScreen);
 
179
    int         fb = KdColormapFb (pCmap);
 
180
 
 
181
    if (pCmap == pScreenPriv->pInstalledmap[fb])
 
182
        return;
 
183
 
 
184
    /* Tell X clients that the installed colormap is going away. */
 
185
    if (pScreenPriv->pInstalledmap[fb])
 
186
        WalkTree(pScreenPriv->pInstalledmap[fb]->pScreen, TellLostMap,
 
187
                 (pointer) &(pScreenPriv->pInstalledmap[fb]->mid));
 
188
 
 
189
    /* Take note of the new installed colorscreen-> */
 
190
    pScreenPriv->pInstalledmap[fb] = pCmap;
 
191
 
 
192
    KdSetColormap (pCmap->pScreen, fb);
 
193
    
 
194
    /* Tell X clients of the new colormap */
 
195
    WalkTree(pCmap->pScreen, TellGainedMap, (pointer) &(pCmap->mid));
 
196
}
 
197
 
 
198
/*
 
199
 * KdUninstallColormap
 
200
 *
 
201
 * This function uninstalls a colormap by either installing 
 
202
 * the default X colormap or erasing the installed colormap pointer.
 
203
 * The default X colormap itself cannot be uninstalled.
 
204
 */
 
205
void
 
206
KdUninstallColormap (ColormapPtr pCmap)
 
207
{
 
208
    KdScreenPriv(pCmap->pScreen);
 
209
    int         fb = KdColormapFb (pCmap);
 
210
    Colormap    defMapID;
 
211
    ColormapPtr defMap;
 
212
 
 
213
    /* ignore if not installed */
 
214
    if (pCmap != pScreenPriv->pInstalledmap[fb])
 
215
        return;
 
216
 
 
217
    /* ignore attempts to uninstall default colormap */
 
218
    defMapID = pCmap->pScreen->defColormap;
 
219
    if ((Colormap) pCmap->mid == defMapID)
 
220
        return;
 
221
 
 
222
    /* install default if on same fb */
 
223
    defMap = (ColormapPtr) LookupIDByType(defMapID, RT_COLORMAP);
 
224
    if (defMap && KdColormapFb (defMap) == fb)
 
225
        (*pCmap->pScreen->InstallColormap)(defMap);
 
226
    else
 
227
    {
 
228
        /* uninstall and clear colormap pointer */
 
229
        WalkTree(pCmap->pScreen, TellLostMap,
 
230
                 (pointer) &(pCmap->mid));
 
231
        pScreenPriv->pInstalledmap[fb] = 0;
 
232
    }
 
233
}
 
234
 
 
235
int
 
236
KdListInstalledColormaps (ScreenPtr pScreen, Colormap *pCmaps)
 
237
{
 
238
    KdScreenPriv(pScreen);
 
239
    int         fb;
 
240
    int         n = 0;
 
241
    
 
242
    for (fb = 0; fb < KD_MAX_FB && pScreenPriv->screen->fb[fb].depth; fb++)
 
243
    {
 
244
        if (pScreenPriv->pInstalledmap[fb])
 
245
        {
 
246
            *pCmaps++ = pScreenPriv->pInstalledmap[fb]->mid;
 
247
            n++;
 
248
        }
 
249
    }
 
250
    return n;
 
251
}
 
252
 
 
253
/*
 
254
 * KdStoreColors
 
255
 *
 
256
 * This function is called whenever the server receives a request to store
 
257
 * color values into one or more entries in the currently installed X
 
258
 * colormap; it can be either the default colormap or a private colorscreen->
 
259
 */
 
260
void
 
261
KdStoreColors (ColormapPtr pCmap, int ndef, xColorItem *pdefs)
 
262
{
 
263
    KdScreenPriv(pCmap->pScreen);
 
264
    VisualPtr           pVisual;
 
265
    xColorItem          expanddefs[KD_MAX_PSEUDO_SIZE];
 
266
    int                 fb = KdColormapFb (pCmap);
 
267
 
 
268
    if (pCmap != pScreenPriv->pInstalledmap[fb])
 
269
        return;
 
270
    
 
271
    if (!pScreenPriv->card->cfuncs->putColors)
 
272
        return;
 
273
    
 
274
    if (pScreenPriv->screen->fb[fb].depth > KD_MAX_PSEUDO_DEPTH)
 
275
        return;
 
276
    
 
277
    if (!pScreenPriv->enabled)
 
278
        return;
 
279
    
 
280
    /* Check for DirectColor or TrueColor being simulated on a PseudoColor device. */
 
281
    pVisual = pCmap->pVisual;
 
282
    if ((pVisual->class | DynamicClass) == DirectColor)
 
283
    {
 
284
        /*
 
285
         * Expand DirectColor or TrueColor color values into a PseudoColor
 
286
         * format.  Defer to the Color Framebuffer (CFB) code to do that.
 
287
         */
 
288
        ndef = fbExpandDirectColors(pCmap, ndef, pdefs, expanddefs);
 
289
        pdefs = expanddefs;
 
290
    }
 
291
 
 
292
    (*pScreenPriv->card->cfuncs->putColors) (pCmap->pScreen, fb, ndef, pdefs);
 
293
    
 
294
    /* recolor hardware cursor */
 
295
    if (pScreenPriv->card->cfuncs->recolorCursor)
 
296
        (*pScreenPriv->card->cfuncs->recolorCursor) (pCmap->pScreen, ndef, pdefs);
 
297
}