xref: /OK3568_Linux_fs/external/xserver/hw/xwin/winallpriv.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  *Permission is hereby granted, free of charge, to any person obtaining
5*4882a593Smuzhiyun  * a copy of this software and associated documentation files (the
6*4882a593Smuzhiyun  *"Software"), to deal in the Software without restriction, including
7*4882a593Smuzhiyun  *without limitation the rights to use, copy, modify, merge, publish,
8*4882a593Smuzhiyun  *distribute, sublicense, and/or sell copies of the Software, and to
9*4882a593Smuzhiyun  *permit persons to whom the Software is furnished to do so, subject to
10*4882a593Smuzhiyun  *the following conditions:
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  *The above copyright notice and this permission notice shall be
13*4882a593Smuzhiyun  *included in all copies or substantial portions of the Software.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16*4882a593Smuzhiyun  *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17*4882a593Smuzhiyun  *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18*4882a593Smuzhiyun  *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
19*4882a593Smuzhiyun  *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20*4882a593Smuzhiyun  *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21*4882a593Smuzhiyun  *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  *Except as contained in this notice, the name of the XFree86 Project
24*4882a593Smuzhiyun  *shall not be used in advertising or otherwise to promote the sale, use
25*4882a593Smuzhiyun  *or other dealings in this Software without prior written authorization
26*4882a593Smuzhiyun  *from the XFree86 Project.
27*4882a593Smuzhiyun  *
28*4882a593Smuzhiyun  * Authors:	Keith Packard, MIT X Consortium
29*4882a593Smuzhiyun  *		Harold L Hunt II
30*4882a593Smuzhiyun  */
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun #ifdef HAVE_XWIN_CONFIG_H
33*4882a593Smuzhiyun #include <xwin-config.h>
34*4882a593Smuzhiyun #endif
35*4882a593Smuzhiyun #include "win.h"
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun /* See Porting Layer Definition - p. 58 */
38*4882a593Smuzhiyun /*
39*4882a593Smuzhiyun  * Allocate indexes for the privates that we use.
40*4882a593Smuzhiyun  * Allocate memory directly for the screen privates.
41*4882a593Smuzhiyun  * Reserve space in GCs and Pixmaps for our privates.
42*4882a593Smuzhiyun  * Colormap privates are handled in winAllocateCmapPrivates ()
43*4882a593Smuzhiyun  */
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun Bool
winAllocatePrivates(ScreenPtr pScreen)46*4882a593Smuzhiyun winAllocatePrivates(ScreenPtr pScreen)
47*4882a593Smuzhiyun {
48*4882a593Smuzhiyun     winPrivScreenPtr pScreenPriv;
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun #if CYGDEBUG
51*4882a593Smuzhiyun     winDebug("winAllocateScreenPrivates - g_ulServerGeneration: %lu "
52*4882a593Smuzhiyun              "serverGeneration: %lu\n", g_ulServerGeneration, serverGeneration);
53*4882a593Smuzhiyun #endif
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun     /* We need a new slot for our privates if the screen gen has changed */
56*4882a593Smuzhiyun     if (g_ulServerGeneration != serverGeneration) {
57*4882a593Smuzhiyun         g_ulServerGeneration = serverGeneration;
58*4882a593Smuzhiyun     }
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun     /* Allocate memory for the screen private structure */
61*4882a593Smuzhiyun     pScreenPriv = malloc(sizeof(winPrivScreenRec));
62*4882a593Smuzhiyun     if (!pScreenPriv) {
63*4882a593Smuzhiyun         ErrorF("winAllocateScreenPrivates - malloc () failed\n");
64*4882a593Smuzhiyun         return FALSE;
65*4882a593Smuzhiyun     }
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun     /* Initialize the memory of the private structure */
68*4882a593Smuzhiyun     ZeroMemory(pScreenPriv, sizeof(winPrivScreenRec));
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun     /* Intialize private structure members */
71*4882a593Smuzhiyun     pScreenPriv->fActive = TRUE;
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun     /* Register our screen private */
74*4882a593Smuzhiyun     if (!dixRegisterPrivateKey(g_iScreenPrivateKey, PRIVATE_SCREEN, 0)) {
75*4882a593Smuzhiyun         ErrorF("winAllocatePrivates - AllocateScreenPrivate () failed\n");
76*4882a593Smuzhiyun         return FALSE;
77*4882a593Smuzhiyun     }
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun     /* Save the screen private pointer */
80*4882a593Smuzhiyun     winSetScreenPriv(pScreen, pScreenPriv);
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun     /* Reserve Pixmap memory for our privates */
83*4882a593Smuzhiyun     if (!dixRegisterPrivateKey
84*4882a593Smuzhiyun         (g_iPixmapPrivateKey, PRIVATE_PIXMAP, sizeof(winPrivPixmapRec))) {
85*4882a593Smuzhiyun         ErrorF("winAllocatePrivates - AllocatePixmapPrivates () failed\n");
86*4882a593Smuzhiyun         return FALSE;
87*4882a593Smuzhiyun     }
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun     /* Reserve Window memory for our privates */
90*4882a593Smuzhiyun     if (!dixRegisterPrivateKey
91*4882a593Smuzhiyun         (g_iWindowPrivateKey, PRIVATE_WINDOW, sizeof(winPrivWinRec))) {
92*4882a593Smuzhiyun         ErrorF("winAllocatePrivates () - AllocateWindowPrivates () failed\n");
93*4882a593Smuzhiyun         return FALSE;
94*4882a593Smuzhiyun     }
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun     return TRUE;
97*4882a593Smuzhiyun }
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun /*
100*4882a593Smuzhiyun  * Colormap privates may be allocated after the default colormap has
101*4882a593Smuzhiyun  * already been created for some screens.  This initialization procedure
102*4882a593Smuzhiyun  * is called for each default colormap that is found.
103*4882a593Smuzhiyun  */
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun Bool
winInitCmapPrivates(ColormapPtr pcmap,int i)106*4882a593Smuzhiyun winInitCmapPrivates(ColormapPtr pcmap, int i)
107*4882a593Smuzhiyun {
108*4882a593Smuzhiyun #if CYGDEBUG
109*4882a593Smuzhiyun     winDebug("winInitCmapPrivates\n");
110*4882a593Smuzhiyun #endif
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun     /*
113*4882a593Smuzhiyun      * I see no way that this function can do anything useful
114*4882a593Smuzhiyun      * with only a ColormapPtr.  We don't have the index for
115*4882a593Smuzhiyun      * our dev privates yet, so we can't really initialize
116*4882a593Smuzhiyun      * anything.  Perhaps I am misunderstanding the purpose
117*4882a593Smuzhiyun      * of this function.
118*4882a593Smuzhiyun      */
119*4882a593Smuzhiyun     /*  That's definitely true.
120*4882a593Smuzhiyun      *  I therefore changed the API and added the index as argument.
121*4882a593Smuzhiyun      */
122*4882a593Smuzhiyun     return TRUE;
123*4882a593Smuzhiyun }
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun /*
126*4882a593Smuzhiyun  * Allocate memory for our colormap privates
127*4882a593Smuzhiyun  */
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun Bool
winAllocateCmapPrivates(ColormapPtr pCmap)130*4882a593Smuzhiyun winAllocateCmapPrivates(ColormapPtr pCmap)
131*4882a593Smuzhiyun {
132*4882a593Smuzhiyun     winPrivCmapPtr pCmapPriv;
133*4882a593Smuzhiyun     static unsigned long s_ulPrivateGeneration = 0;
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun #if CYGDEBUG
136*4882a593Smuzhiyun     winDebug("winAllocateCmapPrivates\n");
137*4882a593Smuzhiyun #endif
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun     /* Get a new privates index when the server generation changes */
140*4882a593Smuzhiyun     if (s_ulPrivateGeneration != serverGeneration) {
141*4882a593Smuzhiyun         /* Save the new server generation */
142*4882a593Smuzhiyun         s_ulPrivateGeneration = serverGeneration;
143*4882a593Smuzhiyun     }
144*4882a593Smuzhiyun 
145*4882a593Smuzhiyun     /* Allocate memory for our private structure */
146*4882a593Smuzhiyun     pCmapPriv = malloc(sizeof(winPrivCmapRec));
147*4882a593Smuzhiyun     if (!pCmapPriv) {
148*4882a593Smuzhiyun         ErrorF("winAllocateCmapPrivates - malloc () failed\n");
149*4882a593Smuzhiyun         return FALSE;
150*4882a593Smuzhiyun     }
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun     /* Initialize the memory of the private structure */
153*4882a593Smuzhiyun     ZeroMemory(pCmapPriv, sizeof(winPrivCmapRec));
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun     /* Register our colourmap private */
156*4882a593Smuzhiyun     if (!dixRegisterPrivateKey(g_iCmapPrivateKey, PRIVATE_COLORMAP, 0)) {
157*4882a593Smuzhiyun         ErrorF("winAllocateCmapPrivates - AllocateCmapPrivate () failed\n");
158*4882a593Smuzhiyun         return FALSE;
159*4882a593Smuzhiyun     }
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun     /* Save the cmap private pointer */
162*4882a593Smuzhiyun     winSetCmapPriv(pCmap, pCmapPriv);
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun #if CYGDEBUG
165*4882a593Smuzhiyun     winDebug("winAllocateCmapPrivates - Returning\n");
166*4882a593Smuzhiyun #endif
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun     return TRUE;
169*4882a593Smuzhiyun }
170