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