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/* See Porting Layer Definition - p. 58 */ 38/* 39 * Allocate indexes for the privates that we use. 40 * Allocate memory directly for the screen privates. 41 * Reserve space in GCs and Pixmaps for our privates. 42 * Colormap privates are handled in winAllocateCmapPrivates () 43 */ 44 45Bool 46winAllocatePrivates(ScreenPtr pScreen) 47{ 48 winPrivScreenPtr pScreenPriv; 49 50#if CYGDEBUG 51 winDebug("winAllocateScreenPrivates - g_ulServerGeneration: %lu " 52 "serverGeneration: %lu\n", g_ulServerGeneration, serverGeneration); 53#endif 54 55 /* We need a new slot for our privates if the screen gen has changed */ 56 if (g_ulServerGeneration != serverGeneration) { 57 g_ulServerGeneration = serverGeneration; 58 } 59 60 /* Allocate memory for the screen private structure */ 61 pScreenPriv = malloc(sizeof(winPrivScreenRec)); 62 if (!pScreenPriv) { 63 ErrorF("winAllocateScreenPrivates - malloc () failed\n"); 64 return FALSE; 65 } 66 67 /* Initialize the memory of the private structure */ 68 ZeroMemory(pScreenPriv, sizeof(winPrivScreenRec)); 69 70 /* Initialize private structure members */ 71 pScreenPriv->fActive = TRUE; 72 73 /* Register our screen private */ 74 if (!dixRegisterPrivateKey(g_iScreenPrivateKey, PRIVATE_SCREEN, 0)) { 75 ErrorF("winAllocatePrivates - AllocateScreenPrivate () failed\n"); 76 return FALSE; 77 } 78 79 /* Save the screen private pointer */ 80 winSetScreenPriv(pScreen, pScreenPriv); 81 82 /* Reserve Pixmap memory for our privates */ 83 if (!dixRegisterPrivateKey 84 (g_iPixmapPrivateKey, PRIVATE_PIXMAP, sizeof(winPrivPixmapRec))) { 85 ErrorF("winAllocatePrivates - AllocatePixmapPrivates () failed\n"); 86 return FALSE; 87 } 88 89 /* Reserve Window memory for our privates */ 90 if (!dixRegisterPrivateKey 91 (g_iWindowPrivateKey, PRIVATE_WINDOW, sizeof(winPrivWinRec))) { 92 ErrorF("winAllocatePrivates () - AllocateWindowPrivates () failed\n"); 93 return FALSE; 94 } 95 96 return TRUE; 97} 98 99/* 100 * Colormap privates may be allocated after the default colormap has 101 * already been created for some screens. This initialization procedure 102 * is called for each default colormap that is found. 103 */ 104 105Bool 106winInitCmapPrivates(ColormapPtr pcmap, int i) 107{ 108#if CYGDEBUG 109 winDebug("winInitCmapPrivates\n"); 110#endif 111 112 /* 113 * I see no way that this function can do anything useful 114 * with only a ColormapPtr. We don't have the index for 115 * our dev privates yet, so we can't really initialize 116 * anything. Perhaps I am misunderstanding the purpose 117 * of this function. 118 */ 119 /* That's definitely true. 120 * I therefore changed the API and added the index as argument. 121 */ 122 return TRUE; 123} 124 125/* 126 * Allocate memory for our colormap privates 127 */ 128 129Bool 130winAllocateCmapPrivates(ColormapPtr pCmap) 131{ 132 winPrivCmapPtr pCmapPriv; 133 static unsigned long s_ulPrivateGeneration = 0; 134 135#if CYGDEBUG 136 winDebug("winAllocateCmapPrivates\n"); 137#endif 138 139 /* Get a new privates index when the server generation changes */ 140 if (s_ulPrivateGeneration != serverGeneration) { 141 /* Save the new server generation */ 142 s_ulPrivateGeneration = serverGeneration; 143 } 144 145 /* Allocate memory for our private structure */ 146 pCmapPriv = malloc(sizeof(winPrivCmapRec)); 147 if (!pCmapPriv) { 148 ErrorF("winAllocateCmapPrivates - malloc () failed\n"); 149 return FALSE; 150 } 151 152 /* Initialize the memory of the private structure */ 153 ZeroMemory(pCmapPriv, sizeof(winPrivCmapRec)); 154 155 /* Register our colourmap private */ 156 if (!dixRegisterPrivateKey(g_iCmapPrivateKey, PRIVATE_COLORMAP, 0)) { 157 ErrorF("winAllocateCmapPrivates - AllocateCmapPrivate () failed\n"); 158 return FALSE; 159 } 160 161 /* Save the cmap private pointer */ 162 winSetCmapPriv(pCmap, pCmapPriv); 163 164#if CYGDEBUG 165 winDebug("winAllocateCmapPrivates - Returning\n"); 166#endif 167 168 return TRUE; 169} 170