winallpriv.c revision 706f2543
1706f2543Smrg/*
2706f2543Smrg *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
3706f2543Smrg *
4706f2543Smrg *Permission is hereby granted, free of charge, to any person obtaining
5706f2543Smrg * a copy of this software and associated documentation files (the
6706f2543Smrg *"Software"), to deal in the Software without restriction, including
7706f2543Smrg *without limitation the rights to use, copy, modify, merge, publish,
8706f2543Smrg *distribute, sublicense, and/or sell copies of the Software, and to
9706f2543Smrg *permit persons to whom the Software is furnished to do so, subject to
10706f2543Smrg *the following conditions:
11706f2543Smrg *
12706f2543Smrg *The above copyright notice and this permission notice shall be
13706f2543Smrg *included in all copies or substantial portions of the Software.
14706f2543Smrg *
15706f2543Smrg *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16706f2543Smrg *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17706f2543Smrg *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18706f2543Smrg *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
19706f2543Smrg *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20706f2543Smrg *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21706f2543Smrg *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22706f2543Smrg *
23706f2543Smrg *Except as contained in this notice, the name of the XFree86 Project
24706f2543Smrg *shall not be used in advertising or otherwise to promote the sale, use
25706f2543Smrg *or other dealings in this Software without prior written authorization
26706f2543Smrg *from the XFree86 Project.
27706f2543Smrg *
28706f2543Smrg * Authors:	Keith Packard, MIT X Consortium
29706f2543Smrg *		Harold L Hunt II
30706f2543Smrg */
31706f2543Smrg
32706f2543Smrg#ifdef HAVE_XWIN_CONFIG_H
33706f2543Smrg#include <xwin-config.h>
34706f2543Smrg#endif
35706f2543Smrg#include "win.h"
36706f2543Smrg
37706f2543Smrg
38706f2543Smrg/* See Porting Layer Definition - p. 58 */
39706f2543Smrg/*
40706f2543Smrg * Allocate indexes for the privates that we use.
41706f2543Smrg * Allocate memory directly for the screen privates.
42706f2543Smrg * Reserve space in GCs and Pixmaps for our privates.
43706f2543Smrg * Colormap privates are handled in winAllocateCmapPrivates ()
44706f2543Smrg */
45706f2543Smrg
46706f2543SmrgBool
47706f2543SmrgwinAllocatePrivates (ScreenPtr pScreen)
48706f2543Smrg{
49706f2543Smrg  winPrivScreenPtr	pScreenPriv;
50706f2543Smrg
51706f2543Smrg#if CYGDEBUG
52706f2543Smrg  winDebug ("winAllocateScreenPrivates - g_ulServerGeneration: %d "
53706f2543Smrg	  "serverGeneration: %d\n",
54706f2543Smrg	  g_ulServerGeneration, serverGeneration);
55706f2543Smrg#endif
56706f2543Smrg
57706f2543Smrg  /* We need a new slot for our privates if the screen gen has changed */
58706f2543Smrg  if (g_ulServerGeneration != serverGeneration)
59706f2543Smrg    {
60706f2543Smrg      g_ulServerGeneration = serverGeneration;
61706f2543Smrg    }
62706f2543Smrg
63706f2543Smrg  /* Allocate memory for the screen private structure */
64706f2543Smrg  pScreenPriv = (winPrivScreenPtr) malloc (sizeof (winPrivScreenRec));
65706f2543Smrg  if (!pScreenPriv)
66706f2543Smrg    {
67706f2543Smrg      ErrorF ("winAllocateScreenPrivates - malloc () failed\n");
68706f2543Smrg      return FALSE;
69706f2543Smrg    }
70706f2543Smrg
71706f2543Smrg  /* Initialize the memory of the private structure */
72706f2543Smrg  ZeroMemory (pScreenPriv, sizeof (winPrivScreenRec));
73706f2543Smrg
74706f2543Smrg  /* Intialize private structure members */
75706f2543Smrg  pScreenPriv->fActive = TRUE;
76706f2543Smrg
77706f2543Smrg  /* Register our screen private */
78706f2543Smrg  if (!dixRegisterPrivateKey(g_iScreenPrivateKey, PRIVATE_SCREEN, 0))
79706f2543Smrg    {
80706f2543Smrg      ErrorF ("winAllocatePrivates - AllocateScreenPrivate () failed\n");
81706f2543Smrg      return FALSE;
82706f2543Smrg    }
83706f2543Smrg
84706f2543Smrg  /* Save the screen private pointer */
85706f2543Smrg  winSetScreenPriv (pScreen, pScreenPriv);
86706f2543Smrg
87706f2543Smrg  /* Reserve GC memory for our privates */
88706f2543Smrg  if (!dixRegisterPrivateKey(g_iGCPrivateKey, PRIVATE_GC, sizeof (winPrivGCRec)))
89706f2543Smrg    {
90706f2543Smrg      ErrorF ("winAllocatePrivates - AllocateGCPrivate () failed\n");
91706f2543Smrg      return FALSE;
92706f2543Smrg    }
93706f2543Smrg
94706f2543Smrg  /* Reserve Pixmap memory for our privates */
95706f2543Smrg  if (!dixRegisterPrivateKey(g_iPixmapPrivateKey, PRIVATE_PIXMAP, sizeof (winPrivPixmapRec)))
96706f2543Smrg    {
97706f2543Smrg      ErrorF ("winAllocatePrivates - AllocatePixmapPrivates () failed\n");
98706f2543Smrg      return FALSE;
99706f2543Smrg    }
100706f2543Smrg
101706f2543Smrg  /* Reserve Window memory for our privates */
102706f2543Smrg  if (!dixRegisterPrivateKey(g_iWindowPrivateKey, PRIVATE_WINDOW, sizeof (winPrivWinRec)))
103706f2543Smrg    {
104706f2543Smrg      ErrorF ("winAllocatePrivates () - AllocateWindowPrivates () failed\n");
105706f2543Smrg       return FALSE;
106706f2543Smrg     }
107706f2543Smrg
108706f2543Smrg  return TRUE;
109706f2543Smrg}
110706f2543Smrg
111706f2543Smrg
112706f2543Smrg/*
113706f2543Smrg * Colormap privates may be allocated after the default colormap has
114706f2543Smrg * already been created for some screens.  This initialization procedure
115706f2543Smrg * is called for each default colormap that is found.
116706f2543Smrg */
117706f2543Smrg
118706f2543SmrgBool
119706f2543SmrgwinInitCmapPrivates (ColormapPtr pcmap, int index)
120706f2543Smrg{
121706f2543Smrg#if CYGDEBUG
122706f2543Smrg  winDebug ("winInitCmapPrivates\n");
123706f2543Smrg#endif
124706f2543Smrg
125706f2543Smrg  /*
126706f2543Smrg   * I see no way that this function can do anything useful
127706f2543Smrg   * with only a ColormapPtr.  We don't have the index for
128706f2543Smrg   * our dev privates yet, so we can't really initialize
129706f2543Smrg   * anything.  Perhaps I am misunderstanding the purpose
130706f2543Smrg   * of this function.
131706f2543Smrg   */
132706f2543Smrg  /*  That's definitely true.
133706f2543Smrg   *  I therefore changed the API and added the index as argument.
134706f2543Smrg   */
135706f2543Smrg  return TRUE;
136706f2543Smrg}
137706f2543Smrg
138706f2543Smrg
139706f2543Smrg/*
140706f2543Smrg * Allocate memory for our colormap privates
141706f2543Smrg */
142706f2543Smrg
143706f2543SmrgBool
144706f2543SmrgwinAllocateCmapPrivates (ColormapPtr pCmap)
145706f2543Smrg{
146706f2543Smrg  winPrivCmapPtr		pCmapPriv;
147706f2543Smrg  static unsigned long		s_ulPrivateGeneration = 0;
148706f2543Smrg
149706f2543Smrg#if CYGDEBUG
150706f2543Smrg  winDebug ("winAllocateCmapPrivates\n");
151706f2543Smrg#endif
152706f2543Smrg
153706f2543Smrg  /* Get a new privates index when the server generation changes */
154706f2543Smrg  if (s_ulPrivateGeneration != serverGeneration)
155706f2543Smrg    {
156706f2543Smrg      /* Save the new server generation */
157706f2543Smrg      s_ulPrivateGeneration = serverGeneration;
158706f2543Smrg    }
159706f2543Smrg
160706f2543Smrg  /* Allocate memory for our private structure */
161706f2543Smrg  pCmapPriv = (winPrivCmapPtr) malloc (sizeof (winPrivCmapRec));
162706f2543Smrg  if (!pCmapPriv)
163706f2543Smrg    {
164706f2543Smrg      ErrorF ("winAllocateCmapPrivates - malloc () failed\n");
165706f2543Smrg      return FALSE;
166706f2543Smrg    }
167706f2543Smrg
168706f2543Smrg  /* Initialize the memory of the private structure */
169706f2543Smrg  ZeroMemory (pCmapPriv, sizeof (winPrivCmapRec));
170706f2543Smrg
171706f2543Smrg  /* Register our colourmap private */
172706f2543Smrg  if (!dixRegisterPrivateKey(g_iCmapPrivateKey, PRIVATE_COLORMAP, 0))
173706f2543Smrg    {
174706f2543Smrg      ErrorF ("winAllocateCmapPrivates - AllocateCmapPrivate () failed\n");
175706f2543Smrg      return FALSE;
176706f2543Smrg    }
177706f2543Smrg
178706f2543Smrg  /* Save the cmap private pointer */
179706f2543Smrg  winSetCmapPriv (pCmap, pCmapPriv);
180706f2543Smrg
181706f2543Smrg#if CYGDEBUG
182706f2543Smrg  winDebug ("winAllocateCmapPrivates - Returning\n");
183706f2543Smrg#endif
184706f2543Smrg
185706f2543Smrg  return TRUE;
186706f2543Smrg}
187