xref: /OK3568_Linux_fs/external/xserver/hw/xwin/winshadgdi.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *Copyright (C) 2001-2004 Harold L Hunt II 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 HAROLD L HUNT II 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 Harold L Hunt II
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 Harold L Hunt II.
27*4882a593Smuzhiyun  *
28*4882a593Smuzhiyun  * Authors:	Harold L Hunt II
29*4882a593Smuzhiyun  */
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun #ifdef HAVE_XWIN_CONFIG_H
32*4882a593Smuzhiyun #include <xwin-config.h>
33*4882a593Smuzhiyun #endif
34*4882a593Smuzhiyun #include "win.h"
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun /*
37*4882a593Smuzhiyun  * Local function prototypes
38*4882a593Smuzhiyun  */
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun static wBOOL CALLBACK winRedrawAllProcShadowGDI(HWND hwnd, LPARAM lParam);
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun static wBOOL CALLBACK winRedrawDamagedWindowShadowGDI(HWND hwnd, LPARAM lParam);
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun static Bool
45*4882a593Smuzhiyun  winAllocateFBShadowGDI(ScreenPtr pScreen);
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun static void
48*4882a593Smuzhiyun  winShadowUpdateGDI(ScreenPtr pScreen, shadowBufPtr pBuf);
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun static Bool
51*4882a593Smuzhiyun  winCloseScreenShadowGDI(ScreenPtr pScreen);
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun static Bool
54*4882a593Smuzhiyun  winInitVisualsShadowGDI(ScreenPtr pScreen);
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun static Bool
57*4882a593Smuzhiyun  winAdjustVideoModeShadowGDI(ScreenPtr pScreen);
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun static Bool
60*4882a593Smuzhiyun  winBltExposedRegionsShadowGDI(ScreenPtr pScreen);
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun static Bool
63*4882a593Smuzhiyun  winActivateAppShadowGDI(ScreenPtr pScreen);
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun static Bool
66*4882a593Smuzhiyun  winRedrawScreenShadowGDI(ScreenPtr pScreen);
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun static Bool
69*4882a593Smuzhiyun  winRealizeInstalledPaletteShadowGDI(ScreenPtr pScreen);
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun static Bool
72*4882a593Smuzhiyun  winInstallColormapShadowGDI(ColormapPtr pColormap);
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun static Bool
75*4882a593Smuzhiyun  winStoreColorsShadowGDI(ColormapPtr pmap, int ndef, xColorItem * pdefs);
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun static Bool
78*4882a593Smuzhiyun  winCreateColormapShadowGDI(ColormapPtr pColormap);
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun static Bool
81*4882a593Smuzhiyun  winDestroyColormapShadowGDI(ColormapPtr pColormap);
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun /*
84*4882a593Smuzhiyun  * Internal function to get the DIB format that is compatible with the screen
85*4882a593Smuzhiyun  */
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun static
88*4882a593Smuzhiyun     Bool
winQueryScreenDIBFormat(ScreenPtr pScreen,BITMAPINFOHEADER * pbmih)89*4882a593Smuzhiyun winQueryScreenDIBFormat(ScreenPtr pScreen, BITMAPINFOHEADER * pbmih)
90*4882a593Smuzhiyun {
91*4882a593Smuzhiyun     winScreenPriv(pScreen);
92*4882a593Smuzhiyun     HBITMAP hbmp;
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun #if CYGDEBUG
95*4882a593Smuzhiyun     LPDWORD pdw = NULL;
96*4882a593Smuzhiyun #endif
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun     /* Create a memory bitmap compatible with the screen */
99*4882a593Smuzhiyun     hbmp = CreateCompatibleBitmap(pScreenPriv->hdcScreen, 1, 1);
100*4882a593Smuzhiyun     if (hbmp == NULL) {
101*4882a593Smuzhiyun         ErrorF("winQueryScreenDIBFormat - CreateCompatibleBitmap failed\n");
102*4882a593Smuzhiyun         return FALSE;
103*4882a593Smuzhiyun     }
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun     /* Initialize our bitmap info header */
106*4882a593Smuzhiyun     ZeroMemory(pbmih, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
107*4882a593Smuzhiyun     pbmih->biSize = sizeof(BITMAPINFOHEADER);
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun     /* Get the biBitCount */
110*4882a593Smuzhiyun     if (!GetDIBits(pScreenPriv->hdcScreen,
111*4882a593Smuzhiyun                    hbmp, 0, 1, NULL, (BITMAPINFO *) pbmih, DIB_RGB_COLORS)) {
112*4882a593Smuzhiyun         ErrorF("winQueryScreenDIBFormat - First call to GetDIBits failed\n");
113*4882a593Smuzhiyun         DeleteObject(hbmp);
114*4882a593Smuzhiyun         return FALSE;
115*4882a593Smuzhiyun     }
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun #if CYGDEBUG
118*4882a593Smuzhiyun     /* Get a pointer to bitfields */
119*4882a593Smuzhiyun     pdw = (DWORD *) ((CARD8 *) pbmih + sizeof(BITMAPINFOHEADER));
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun     winDebug("winQueryScreenDIBFormat - First call masks: %08x %08x %08x\n",
122*4882a593Smuzhiyun              (unsigned int)pdw[0], (unsigned int)pdw[1], (unsigned int)pdw[2]);
123*4882a593Smuzhiyun #endif
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun     /* Get optimal color table, or the optimal bitfields */
126*4882a593Smuzhiyun     if (!GetDIBits(pScreenPriv->hdcScreen,
127*4882a593Smuzhiyun                    hbmp, 0, 1, NULL, (BITMAPINFO *) pbmih, DIB_RGB_COLORS)) {
128*4882a593Smuzhiyun         ErrorF("winQueryScreenDIBFormat - Second call to GetDIBits "
129*4882a593Smuzhiyun                "failed\n");
130*4882a593Smuzhiyun         DeleteObject(hbmp);
131*4882a593Smuzhiyun         return FALSE;
132*4882a593Smuzhiyun     }
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun     /* Free memory */
135*4882a593Smuzhiyun     DeleteObject(hbmp);
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun     return TRUE;
138*4882a593Smuzhiyun }
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun /*
141*4882a593Smuzhiyun  * Internal function to determine the GDI bits per rgb and bit masks
142*4882a593Smuzhiyun  */
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun static
145*4882a593Smuzhiyun     Bool
winQueryRGBBitsAndMasks(ScreenPtr pScreen)146*4882a593Smuzhiyun winQueryRGBBitsAndMasks(ScreenPtr pScreen)
147*4882a593Smuzhiyun {
148*4882a593Smuzhiyun     winScreenPriv(pScreen);
149*4882a593Smuzhiyun     BITMAPINFOHEADER *pbmih = NULL;
150*4882a593Smuzhiyun     Bool fReturn = TRUE;
151*4882a593Smuzhiyun     LPDWORD pdw = NULL;
152*4882a593Smuzhiyun     DWORD dwRedBits, dwGreenBits, dwBlueBits;
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun     /* Color masks for 8 bpp are standardized */
155*4882a593Smuzhiyun     if (GetDeviceCaps(pScreenPriv->hdcScreen, RASTERCAPS) & RC_PALETTE) {
156*4882a593Smuzhiyun         /*
157*4882a593Smuzhiyun          * RGB BPP for 8 bit palletes is always 8
158*4882a593Smuzhiyun          * and the color masks are always 0.
159*4882a593Smuzhiyun          */
160*4882a593Smuzhiyun         pScreenPriv->dwBitsPerRGB = 8;
161*4882a593Smuzhiyun         pScreenPriv->dwRedMask = 0x0L;
162*4882a593Smuzhiyun         pScreenPriv->dwGreenMask = 0x0L;
163*4882a593Smuzhiyun         pScreenPriv->dwBlueMask = 0x0L;
164*4882a593Smuzhiyun         return TRUE;
165*4882a593Smuzhiyun     }
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun     /* Color masks for 24 bpp are standardized */
168*4882a593Smuzhiyun     if (GetDeviceCaps(pScreenPriv->hdcScreen, PLANES)
169*4882a593Smuzhiyun         * GetDeviceCaps(pScreenPriv->hdcScreen, BITSPIXEL) == 24) {
170*4882a593Smuzhiyun         ErrorF("winQueryRGBBitsAndMasks - GetDeviceCaps (BITSPIXEL) "
171*4882a593Smuzhiyun                "returned 24 for the screen.  Using default 24bpp masks.\n");
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun         /* 8 bits per primary color */
174*4882a593Smuzhiyun         pScreenPriv->dwBitsPerRGB = 8;
175*4882a593Smuzhiyun 
176*4882a593Smuzhiyun         /* Set screen privates masks */
177*4882a593Smuzhiyun         pScreenPriv->dwRedMask = WIN_24BPP_MASK_RED;
178*4882a593Smuzhiyun         pScreenPriv->dwGreenMask = WIN_24BPP_MASK_GREEN;
179*4882a593Smuzhiyun         pScreenPriv->dwBlueMask = WIN_24BPP_MASK_BLUE;
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun         return TRUE;
182*4882a593Smuzhiyun     }
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun     /* Allocate a bitmap header and color table */
185*4882a593Smuzhiyun     pbmih = malloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
186*4882a593Smuzhiyun     if (pbmih == NULL) {
187*4882a593Smuzhiyun         ErrorF("winQueryRGBBitsAndMasks - malloc failed\n");
188*4882a593Smuzhiyun         return FALSE;
189*4882a593Smuzhiyun     }
190*4882a593Smuzhiyun 
191*4882a593Smuzhiyun     /* Get screen description */
192*4882a593Smuzhiyun     if (winQueryScreenDIBFormat(pScreen, pbmih)) {
193*4882a593Smuzhiyun         /* Get a pointer to bitfields */
194*4882a593Smuzhiyun         pdw = (DWORD *) ((CARD8 *) pbmih + sizeof(BITMAPINFOHEADER));
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun #if CYGDEBUG
197*4882a593Smuzhiyun         winDebug("%s - Masks: %08x %08x %08x\n", __FUNCTION__,
198*4882a593Smuzhiyun                  (unsigned int)pdw[0], (unsigned int)pdw[1], (unsigned int)pdw[2]);
199*4882a593Smuzhiyun         winDebug("%s - Bitmap: %dx%d %d bpp %d planes\n", __FUNCTION__,
200*4882a593Smuzhiyun                  (int)pbmih->biWidth, (int)pbmih->biHeight, pbmih->biBitCount,
201*4882a593Smuzhiyun                  pbmih->biPlanes);
202*4882a593Smuzhiyun         winDebug("%s - Compression: %u %s\n", __FUNCTION__,
203*4882a593Smuzhiyun                  (unsigned int)pbmih->biCompression,
204*4882a593Smuzhiyun                  (pbmih->biCompression ==
205*4882a593Smuzhiyun                   BI_RGB ? "(BI_RGB)" : (pbmih->biCompression ==
206*4882a593Smuzhiyun                                          BI_RLE8 ? "(BI_RLE8)" : (pbmih->
207*4882a593Smuzhiyun                                                                   biCompression
208*4882a593Smuzhiyun                                                                   ==
209*4882a593Smuzhiyun                                                                   BI_RLE4 ?
210*4882a593Smuzhiyun                                                                   "(BI_RLE4)"
211*4882a593Smuzhiyun                                                                   : (pbmih->
212*4882a593Smuzhiyun                                                                      biCompression
213*4882a593Smuzhiyun                                                                      ==
214*4882a593Smuzhiyun                                                                      BI_BITFIELDS
215*4882a593Smuzhiyun                                                                      ?
216*4882a593Smuzhiyun                                                                      "(BI_BITFIELDS)"
217*4882a593Smuzhiyun                                                                      : "")))));
218*4882a593Smuzhiyun #endif
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun         /* Handle BI_RGB case, which is returned by Wine */
221*4882a593Smuzhiyun         if (pbmih->biCompression == BI_RGB) {
222*4882a593Smuzhiyun             dwRedBits = 5;
223*4882a593Smuzhiyun             dwGreenBits = 5;
224*4882a593Smuzhiyun             dwBlueBits = 5;
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun             pScreenPriv->dwBitsPerRGB = 5;
227*4882a593Smuzhiyun 
228*4882a593Smuzhiyun             /* Set screen privates masks */
229*4882a593Smuzhiyun             pScreenPriv->dwRedMask = 0x7c00;
230*4882a593Smuzhiyun             pScreenPriv->dwGreenMask = 0x03e0;
231*4882a593Smuzhiyun             pScreenPriv->dwBlueMask = 0x001f;
232*4882a593Smuzhiyun         }
233*4882a593Smuzhiyun         else {
234*4882a593Smuzhiyun             /* Count the number of bits in each mask */
235*4882a593Smuzhiyun             dwRedBits = winCountBits(pdw[0]);
236*4882a593Smuzhiyun             dwGreenBits = winCountBits(pdw[1]);
237*4882a593Smuzhiyun             dwBlueBits = winCountBits(pdw[2]);
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun             /* Find maximum bits per red, green, blue */
240*4882a593Smuzhiyun             if (dwRedBits > dwGreenBits && dwRedBits > dwBlueBits)
241*4882a593Smuzhiyun                 pScreenPriv->dwBitsPerRGB = dwRedBits;
242*4882a593Smuzhiyun             else if (dwGreenBits > dwRedBits && dwGreenBits > dwBlueBits)
243*4882a593Smuzhiyun                 pScreenPriv->dwBitsPerRGB = dwGreenBits;
244*4882a593Smuzhiyun             else
245*4882a593Smuzhiyun                 pScreenPriv->dwBitsPerRGB = dwBlueBits;
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun             /* Set screen privates masks */
248*4882a593Smuzhiyun             pScreenPriv->dwRedMask = pdw[0];
249*4882a593Smuzhiyun             pScreenPriv->dwGreenMask = pdw[1];
250*4882a593Smuzhiyun             pScreenPriv->dwBlueMask = pdw[2];
251*4882a593Smuzhiyun         }
252*4882a593Smuzhiyun     }
253*4882a593Smuzhiyun     else {
254*4882a593Smuzhiyun         ErrorF("winQueryRGBBitsAndMasks - winQueryScreenDIBFormat failed\n");
255*4882a593Smuzhiyun         fReturn = FALSE;
256*4882a593Smuzhiyun     }
257*4882a593Smuzhiyun 
258*4882a593Smuzhiyun     /* Free memory */
259*4882a593Smuzhiyun     free(pbmih);
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun     return fReturn;
262*4882a593Smuzhiyun }
263*4882a593Smuzhiyun 
264*4882a593Smuzhiyun /*
265*4882a593Smuzhiyun  * Redraw all ---?
266*4882a593Smuzhiyun  */
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun static wBOOL CALLBACK
winRedrawAllProcShadowGDI(HWND hwnd,LPARAM lParam)269*4882a593Smuzhiyun winRedrawAllProcShadowGDI(HWND hwnd, LPARAM lParam)
270*4882a593Smuzhiyun {
271*4882a593Smuzhiyun     if (hwnd == (HWND) lParam)
272*4882a593Smuzhiyun         return TRUE;
273*4882a593Smuzhiyun     InvalidateRect(hwnd, NULL, FALSE);
274*4882a593Smuzhiyun     UpdateWindow(hwnd);
275*4882a593Smuzhiyun     return TRUE;
276*4882a593Smuzhiyun }
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun static wBOOL CALLBACK
winRedrawDamagedWindowShadowGDI(HWND hwnd,LPARAM lParam)279*4882a593Smuzhiyun winRedrawDamagedWindowShadowGDI(HWND hwnd, LPARAM lParam)
280*4882a593Smuzhiyun {
281*4882a593Smuzhiyun     BoxPtr pDamage = (BoxPtr) lParam;
282*4882a593Smuzhiyun     RECT rcClient, rcDamage, rcRedraw;
283*4882a593Smuzhiyun     POINT topLeft, bottomRight;
284*4882a593Smuzhiyun 
285*4882a593Smuzhiyun     if (IsIconic(hwnd))
286*4882a593Smuzhiyun         return TRUE;            /* Don't care minimized windows */
287*4882a593Smuzhiyun 
288*4882a593Smuzhiyun     /* Convert the damaged area from Screen coords to Client coords */
289*4882a593Smuzhiyun     topLeft.x = pDamage->x1;
290*4882a593Smuzhiyun     topLeft.y = pDamage->y1;
291*4882a593Smuzhiyun     bottomRight.x = pDamage->x2;
292*4882a593Smuzhiyun     bottomRight.y = pDamage->y2;
293*4882a593Smuzhiyun     topLeft.x += GetSystemMetrics(SM_XVIRTUALSCREEN);
294*4882a593Smuzhiyun     bottomRight.x += GetSystemMetrics(SM_XVIRTUALSCREEN);
295*4882a593Smuzhiyun     topLeft.y += GetSystemMetrics(SM_YVIRTUALSCREEN);
296*4882a593Smuzhiyun     bottomRight.y += GetSystemMetrics(SM_YVIRTUALSCREEN);
297*4882a593Smuzhiyun     ScreenToClient(hwnd, &topLeft);
298*4882a593Smuzhiyun     ScreenToClient(hwnd, &bottomRight);
299*4882a593Smuzhiyun     SetRect(&rcDamage, topLeft.x, topLeft.y, bottomRight.x, bottomRight.y);
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun     GetClientRect(hwnd, &rcClient);
302*4882a593Smuzhiyun 
303*4882a593Smuzhiyun     if (IntersectRect(&rcRedraw, &rcClient, &rcDamage)) {
304*4882a593Smuzhiyun         InvalidateRect(hwnd, &rcRedraw, FALSE);
305*4882a593Smuzhiyun         UpdateWindow(hwnd);
306*4882a593Smuzhiyun     }
307*4882a593Smuzhiyun     return TRUE;
308*4882a593Smuzhiyun }
309*4882a593Smuzhiyun 
310*4882a593Smuzhiyun /*
311*4882a593Smuzhiyun  * Allocate a DIB for the shadow framebuffer GDI server
312*4882a593Smuzhiyun  */
313*4882a593Smuzhiyun 
314*4882a593Smuzhiyun static Bool
winAllocateFBShadowGDI(ScreenPtr pScreen)315*4882a593Smuzhiyun winAllocateFBShadowGDI(ScreenPtr pScreen)
316*4882a593Smuzhiyun {
317*4882a593Smuzhiyun     winScreenPriv(pScreen);
318*4882a593Smuzhiyun     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
319*4882a593Smuzhiyun     DIBSECTION dibsection;
320*4882a593Smuzhiyun     Bool fReturn = TRUE;
321*4882a593Smuzhiyun 
322*4882a593Smuzhiyun     /* Describe shadow bitmap to be created */
323*4882a593Smuzhiyun     pScreenPriv->pbmih->biWidth = pScreenInfo->dwWidth;
324*4882a593Smuzhiyun     pScreenPriv->pbmih->biHeight = -pScreenInfo->dwHeight;
325*4882a593Smuzhiyun 
326*4882a593Smuzhiyun     ErrorF("winAllocateFBShadowGDI - Creating DIB with width: %d height: %d "
327*4882a593Smuzhiyun            "depth: %d\n",
328*4882a593Smuzhiyun            (int) pScreenPriv->pbmih->biWidth,
329*4882a593Smuzhiyun            (int) -pScreenPriv->pbmih->biHeight, pScreenPriv->pbmih->biBitCount);
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun     /* Create a DI shadow bitmap with a bit pointer */
332*4882a593Smuzhiyun     pScreenPriv->hbmpShadow = CreateDIBSection(pScreenPriv->hdcScreen,
333*4882a593Smuzhiyun                                                (BITMAPINFO *) pScreenPriv->
334*4882a593Smuzhiyun                                                pbmih, DIB_RGB_COLORS,
335*4882a593Smuzhiyun                                                (VOID **) &pScreenInfo->pfb,
336*4882a593Smuzhiyun                                                NULL, 0);
337*4882a593Smuzhiyun     if (pScreenPriv->hbmpShadow == NULL || pScreenInfo->pfb == NULL) {
338*4882a593Smuzhiyun         winW32Error(2, "winAllocateFBShadowGDI - CreateDIBSection failed:");
339*4882a593Smuzhiyun         return FALSE;
340*4882a593Smuzhiyun     }
341*4882a593Smuzhiyun     else {
342*4882a593Smuzhiyun #if CYGDEBUG
343*4882a593Smuzhiyun         winDebug("winAllocateFBShadowGDI - Shadow buffer allocated\n");
344*4882a593Smuzhiyun #endif
345*4882a593Smuzhiyun     }
346*4882a593Smuzhiyun 
347*4882a593Smuzhiyun     /* Get information about the bitmap that was allocated */
348*4882a593Smuzhiyun     GetObject(pScreenPriv->hbmpShadow, sizeof(dibsection), &dibsection);
349*4882a593Smuzhiyun 
350*4882a593Smuzhiyun #if CYGDEBUG || YES
351*4882a593Smuzhiyun     /* Print information about bitmap allocated */
352*4882a593Smuzhiyun     winDebug("winAllocateFBShadowGDI - Dibsection width: %d height: %d "
353*4882a593Smuzhiyun              "depth: %d size image: %d\n",
354*4882a593Smuzhiyun              (int) dibsection.dsBmih.biWidth, (int) dibsection.dsBmih.biHeight,
355*4882a593Smuzhiyun              dibsection.dsBmih.biBitCount, (int) dibsection.dsBmih.biSizeImage);
356*4882a593Smuzhiyun #endif
357*4882a593Smuzhiyun 
358*4882a593Smuzhiyun     /* Select the shadow bitmap into the shadow DC */
359*4882a593Smuzhiyun     SelectObject(pScreenPriv->hdcShadow, pScreenPriv->hbmpShadow);
360*4882a593Smuzhiyun 
361*4882a593Smuzhiyun #if CYGDEBUG
362*4882a593Smuzhiyun     winDebug("winAllocateFBShadowGDI - Attempting a shadow blit\n");
363*4882a593Smuzhiyun #endif
364*4882a593Smuzhiyun 
365*4882a593Smuzhiyun     /* Do a test blit from the shadow to the screen, I think */
366*4882a593Smuzhiyun     fReturn = BitBlt(pScreenPriv->hdcScreen,
367*4882a593Smuzhiyun                      0, 0,
368*4882a593Smuzhiyun                      pScreenInfo->dwWidth, pScreenInfo->dwHeight,
369*4882a593Smuzhiyun                      pScreenPriv->hdcShadow, 0, 0, SRCCOPY);
370*4882a593Smuzhiyun     if (fReturn) {
371*4882a593Smuzhiyun #if CYGDEBUG
372*4882a593Smuzhiyun         winDebug("winAllocateFBShadowGDI - Shadow blit success\n");
373*4882a593Smuzhiyun #endif
374*4882a593Smuzhiyun     }
375*4882a593Smuzhiyun     else {
376*4882a593Smuzhiyun         winW32Error(2, "winAllocateFBShadowGDI - Shadow blit failure\n");
377*4882a593Smuzhiyun #if 0
378*4882a593Smuzhiyun         return FALSE;
379*4882a593Smuzhiyun #else
380*4882a593Smuzhiyun         /* ago: ignore this error. The blit fails with wine, but does not
381*4882a593Smuzhiyun          * cause any problems later. */
382*4882a593Smuzhiyun 
383*4882a593Smuzhiyun         fReturn = TRUE;
384*4882a593Smuzhiyun #endif
385*4882a593Smuzhiyun     }
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun     /* Look for height weirdness */
388*4882a593Smuzhiyun     if (dibsection.dsBmih.biHeight < 0) {
389*4882a593Smuzhiyun         dibsection.dsBmih.biHeight = -dibsection.dsBmih.biHeight;
390*4882a593Smuzhiyun     }
391*4882a593Smuzhiyun 
392*4882a593Smuzhiyun     /* Set screeninfo stride */
393*4882a593Smuzhiyun     pScreenInfo->dwStride = ((dibsection.dsBmih.biSizeImage
394*4882a593Smuzhiyun                               / dibsection.dsBmih.biHeight)
395*4882a593Smuzhiyun                              * 8) / pScreenInfo->dwBPP;
396*4882a593Smuzhiyun 
397*4882a593Smuzhiyun #if CYGDEBUG || YES
398*4882a593Smuzhiyun     winDebug("winAllocateFBShadowGDI - Created shadow stride: %d\n",
399*4882a593Smuzhiyun              (int) pScreenInfo->dwStride);
400*4882a593Smuzhiyun #endif
401*4882a593Smuzhiyun 
402*4882a593Smuzhiyun     /* Redraw all windows */
403*4882a593Smuzhiyun     if (pScreenInfo->fMultiWindow)
404*4882a593Smuzhiyun         EnumThreadWindows(g_dwCurrentThreadID, winRedrawAllProcShadowGDI, 0);
405*4882a593Smuzhiyun 
406*4882a593Smuzhiyun     return fReturn;
407*4882a593Smuzhiyun }
408*4882a593Smuzhiyun 
409*4882a593Smuzhiyun static void
winFreeFBShadowGDI(ScreenPtr pScreen)410*4882a593Smuzhiyun winFreeFBShadowGDI(ScreenPtr pScreen)
411*4882a593Smuzhiyun {
412*4882a593Smuzhiyun     winScreenPriv(pScreen);
413*4882a593Smuzhiyun     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
414*4882a593Smuzhiyun 
415*4882a593Smuzhiyun     /* Free the shadow bitmap */
416*4882a593Smuzhiyun     DeleteObject(pScreenPriv->hbmpShadow);
417*4882a593Smuzhiyun 
418*4882a593Smuzhiyun     /* Invalidate the ScreenInfo's fb pointer */
419*4882a593Smuzhiyun     pScreenInfo->pfb = NULL;
420*4882a593Smuzhiyun }
421*4882a593Smuzhiyun 
422*4882a593Smuzhiyun /*
423*4882a593Smuzhiyun  * Blit the damaged regions of the shadow fb to the screen
424*4882a593Smuzhiyun  */
425*4882a593Smuzhiyun 
426*4882a593Smuzhiyun static void
winShadowUpdateGDI(ScreenPtr pScreen,shadowBufPtr pBuf)427*4882a593Smuzhiyun winShadowUpdateGDI(ScreenPtr pScreen, shadowBufPtr pBuf)
428*4882a593Smuzhiyun {
429*4882a593Smuzhiyun     winScreenPriv(pScreen);
430*4882a593Smuzhiyun     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
431*4882a593Smuzhiyun     RegionPtr damage = DamageRegion(pBuf->pDamage);
432*4882a593Smuzhiyun     DWORD dwBox = RegionNumRects(damage);
433*4882a593Smuzhiyun     BoxPtr pBox = RegionRects(damage);
434*4882a593Smuzhiyun     int x, y, w, h;
435*4882a593Smuzhiyun     HRGN hrgnCombined = NULL;
436*4882a593Smuzhiyun 
437*4882a593Smuzhiyun #ifdef XWIN_UPDATESTATS
438*4882a593Smuzhiyun     static DWORD s_dwNonUnitRegions = 0;
439*4882a593Smuzhiyun     static DWORD s_dwTotalUpdates = 0;
440*4882a593Smuzhiyun     static DWORD s_dwTotalBoxes = 0;
441*4882a593Smuzhiyun #endif
442*4882a593Smuzhiyun     BoxPtr pBoxExtents = RegionExtents(damage);
443*4882a593Smuzhiyun 
444*4882a593Smuzhiyun     /*
445*4882a593Smuzhiyun      * Return immediately if the app is not active
446*4882a593Smuzhiyun      * and we are fullscreen, or if we have a bad display depth
447*4882a593Smuzhiyun      */
448*4882a593Smuzhiyun     if ((!pScreenPriv->fActive && pScreenInfo->fFullScreen)
449*4882a593Smuzhiyun         || pScreenPriv->fBadDepth)
450*4882a593Smuzhiyun         return;
451*4882a593Smuzhiyun 
452*4882a593Smuzhiyun #ifdef XWIN_UPDATESTATS
453*4882a593Smuzhiyun     ++s_dwTotalUpdates;
454*4882a593Smuzhiyun     s_dwTotalBoxes += dwBox;
455*4882a593Smuzhiyun 
456*4882a593Smuzhiyun     if (dwBox != 1) {
457*4882a593Smuzhiyun         ++s_dwNonUnitRegions;
458*4882a593Smuzhiyun         ErrorF("winShadowUpdatGDI - dwBox: %d\n", dwBox);
459*4882a593Smuzhiyun     }
460*4882a593Smuzhiyun 
461*4882a593Smuzhiyun     if ((s_dwTotalUpdates % 100) == 0)
462*4882a593Smuzhiyun         ErrorF("winShadowUpdateGDI - %d%% non-unity regions, avg boxes: %d "
463*4882a593Smuzhiyun                "nu: %d tu: %d\n",
464*4882a593Smuzhiyun                (s_dwNonUnitRegions * 100) / s_dwTotalUpdates,
465*4882a593Smuzhiyun                s_dwTotalBoxes / s_dwTotalUpdates,
466*4882a593Smuzhiyun                s_dwNonUnitRegions, s_dwTotalUpdates);
467*4882a593Smuzhiyun #endif                          /* XWIN_UPDATESTATS */
468*4882a593Smuzhiyun 
469*4882a593Smuzhiyun     /*
470*4882a593Smuzhiyun      * Handle small regions with multiple blits,
471*4882a593Smuzhiyun      * handle large regions by creating a clipping region and
472*4882a593Smuzhiyun      * doing a single blit constrained to that clipping region.
473*4882a593Smuzhiyun      */
474*4882a593Smuzhiyun     if (!pScreenInfo->fMultiWindow &&
475*4882a593Smuzhiyun         (pScreenInfo->dwClipUpdatesNBoxes == 0 ||
476*4882a593Smuzhiyun          dwBox < pScreenInfo->dwClipUpdatesNBoxes)) {
477*4882a593Smuzhiyun         /* Loop through all boxes in the damaged region */
478*4882a593Smuzhiyun         while (dwBox--) {
479*4882a593Smuzhiyun             /*
480*4882a593Smuzhiyun              * Calculate x offset, y offset, width, and height for
481*4882a593Smuzhiyun              * current damage box
482*4882a593Smuzhiyun              */
483*4882a593Smuzhiyun             x = pBox->x1;
484*4882a593Smuzhiyun             y = pBox->y1;
485*4882a593Smuzhiyun             w = pBox->x2 - pBox->x1;
486*4882a593Smuzhiyun             h = pBox->y2 - pBox->y1;
487*4882a593Smuzhiyun 
488*4882a593Smuzhiyun             BitBlt(pScreenPriv->hdcScreen,
489*4882a593Smuzhiyun                    x, y, w, h, pScreenPriv->hdcShadow, x, y, SRCCOPY);
490*4882a593Smuzhiyun 
491*4882a593Smuzhiyun             /* Get a pointer to the next box */
492*4882a593Smuzhiyun             ++pBox;
493*4882a593Smuzhiyun         }
494*4882a593Smuzhiyun     }
495*4882a593Smuzhiyun     else if (!pScreenInfo->fMultiWindow) {
496*4882a593Smuzhiyun 
497*4882a593Smuzhiyun         /* Compute a GDI region from the damaged region */
498*4882a593Smuzhiyun         hrgnCombined =
499*4882a593Smuzhiyun             CreateRectRgn(pBoxExtents->x1, pBoxExtents->y1, pBoxExtents->x2,
500*4882a593Smuzhiyun                           pBoxExtents->y2);
501*4882a593Smuzhiyun 
502*4882a593Smuzhiyun         /* Install the GDI region as a clipping region */
503*4882a593Smuzhiyun         SelectClipRgn(pScreenPriv->hdcScreen, hrgnCombined);
504*4882a593Smuzhiyun         DeleteObject(hrgnCombined);
505*4882a593Smuzhiyun         hrgnCombined = NULL;
506*4882a593Smuzhiyun 
507*4882a593Smuzhiyun         /*
508*4882a593Smuzhiyun          * Blit the shadow buffer to the screen,
509*4882a593Smuzhiyun          * constrained to the clipping region.
510*4882a593Smuzhiyun          */
511*4882a593Smuzhiyun         BitBlt(pScreenPriv->hdcScreen,
512*4882a593Smuzhiyun                pBoxExtents->x1, pBoxExtents->y1,
513*4882a593Smuzhiyun                pBoxExtents->x2 - pBoxExtents->x1,
514*4882a593Smuzhiyun                pBoxExtents->y2 - pBoxExtents->y1,
515*4882a593Smuzhiyun                pScreenPriv->hdcShadow,
516*4882a593Smuzhiyun                pBoxExtents->x1, pBoxExtents->y1, SRCCOPY);
517*4882a593Smuzhiyun 
518*4882a593Smuzhiyun         /* Reset the clip region */
519*4882a593Smuzhiyun         SelectClipRgn(pScreenPriv->hdcScreen, NULL);
520*4882a593Smuzhiyun     }
521*4882a593Smuzhiyun 
522*4882a593Smuzhiyun     /* Redraw all multiwindow windows */
523*4882a593Smuzhiyun     if (pScreenInfo->fMultiWindow)
524*4882a593Smuzhiyun         EnumThreadWindows(g_dwCurrentThreadID,
525*4882a593Smuzhiyun                           winRedrawDamagedWindowShadowGDI,
526*4882a593Smuzhiyun                           (LPARAM) pBoxExtents);
527*4882a593Smuzhiyun }
528*4882a593Smuzhiyun 
529*4882a593Smuzhiyun static Bool
winInitScreenShadowGDI(ScreenPtr pScreen)530*4882a593Smuzhiyun winInitScreenShadowGDI(ScreenPtr pScreen)
531*4882a593Smuzhiyun {
532*4882a593Smuzhiyun     winScreenPriv(pScreen);
533*4882a593Smuzhiyun 
534*4882a593Smuzhiyun     /* Get device contexts for the screen and shadow bitmap */
535*4882a593Smuzhiyun     pScreenPriv->hdcScreen = GetDC(pScreenPriv->hwndScreen);
536*4882a593Smuzhiyun     pScreenPriv->hdcShadow = CreateCompatibleDC(pScreenPriv->hdcScreen);
537*4882a593Smuzhiyun 
538*4882a593Smuzhiyun     /* Allocate bitmap info header */
539*4882a593Smuzhiyun     pScreenPriv->pbmih = malloc(sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
540*4882a593Smuzhiyun     if (pScreenPriv->pbmih == NULL) {
541*4882a593Smuzhiyun         ErrorF("winInitScreenShadowGDI - malloc () failed\n");
542*4882a593Smuzhiyun         return FALSE;
543*4882a593Smuzhiyun     }
544*4882a593Smuzhiyun 
545*4882a593Smuzhiyun     /* Query the screen format */
546*4882a593Smuzhiyun     if (!winQueryScreenDIBFormat(pScreen, pScreenPriv->pbmih)) {
547*4882a593Smuzhiyun         ErrorF("winInitScreenShadowGDI - winQueryScreenDIBFormat failed\n");
548*4882a593Smuzhiyun         return FALSE;
549*4882a593Smuzhiyun     }
550*4882a593Smuzhiyun 
551*4882a593Smuzhiyun     /* Determine our color masks */
552*4882a593Smuzhiyun     if (!winQueryRGBBitsAndMasks(pScreen)) {
553*4882a593Smuzhiyun         ErrorF("winInitScreenShadowGDI - winQueryRGBBitsAndMasks failed\n");
554*4882a593Smuzhiyun         return FALSE;
555*4882a593Smuzhiyun     }
556*4882a593Smuzhiyun 
557*4882a593Smuzhiyun     return winAllocateFBShadowGDI(pScreen);
558*4882a593Smuzhiyun }
559*4882a593Smuzhiyun 
560*4882a593Smuzhiyun /* See Porting Layer Definition - p. 33 */
561*4882a593Smuzhiyun /*
562*4882a593Smuzhiyun  * We wrap whatever CloseScreen procedure was specified by fb;
563*4882a593Smuzhiyun  * a pointer to said procedure is stored in our privates.
564*4882a593Smuzhiyun  */
565*4882a593Smuzhiyun 
566*4882a593Smuzhiyun static Bool
winCloseScreenShadowGDI(ScreenPtr pScreen)567*4882a593Smuzhiyun winCloseScreenShadowGDI(ScreenPtr pScreen)
568*4882a593Smuzhiyun {
569*4882a593Smuzhiyun     winScreenPriv(pScreen);
570*4882a593Smuzhiyun     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
571*4882a593Smuzhiyun     Bool fReturn = TRUE;
572*4882a593Smuzhiyun 
573*4882a593Smuzhiyun #if CYGDEBUG
574*4882a593Smuzhiyun     winDebug("winCloseScreenShadowGDI - Freeing screen resources\n");
575*4882a593Smuzhiyun #endif
576*4882a593Smuzhiyun 
577*4882a593Smuzhiyun     /* Flag that the screen is closed */
578*4882a593Smuzhiyun     pScreenPriv->fClosed = TRUE;
579*4882a593Smuzhiyun     pScreenPriv->fActive = FALSE;
580*4882a593Smuzhiyun 
581*4882a593Smuzhiyun     /* Call the wrapped CloseScreen procedure */
582*4882a593Smuzhiyun     WIN_UNWRAP(CloseScreen);
583*4882a593Smuzhiyun     if (pScreen->CloseScreen)
584*4882a593Smuzhiyun         fReturn = (*pScreen->CloseScreen) (pScreen);
585*4882a593Smuzhiyun 
586*4882a593Smuzhiyun     /* Delete the window property */
587*4882a593Smuzhiyun     RemoveProp(pScreenPriv->hwndScreen, WIN_SCR_PROP);
588*4882a593Smuzhiyun 
589*4882a593Smuzhiyun     /* Free the shadow DC; which allows the bitmap to be freed */
590*4882a593Smuzhiyun     DeleteDC(pScreenPriv->hdcShadow);
591*4882a593Smuzhiyun 
592*4882a593Smuzhiyun     winFreeFBShadowGDI(pScreen);
593*4882a593Smuzhiyun 
594*4882a593Smuzhiyun     /* Free the screen DC */
595*4882a593Smuzhiyun     ReleaseDC(pScreenPriv->hwndScreen, pScreenPriv->hdcScreen);
596*4882a593Smuzhiyun 
597*4882a593Smuzhiyun     /* Delete tray icon, if we have one */
598*4882a593Smuzhiyun     if (!pScreenInfo->fNoTrayIcon)
599*4882a593Smuzhiyun         winDeleteNotifyIcon(pScreenPriv);
600*4882a593Smuzhiyun 
601*4882a593Smuzhiyun     /* Free the exit confirmation dialog box, if it exists */
602*4882a593Smuzhiyun     if (g_hDlgExit != NULL) {
603*4882a593Smuzhiyun         DestroyWindow(g_hDlgExit);
604*4882a593Smuzhiyun         g_hDlgExit = NULL;
605*4882a593Smuzhiyun     }
606*4882a593Smuzhiyun 
607*4882a593Smuzhiyun     /* Kill our window */
608*4882a593Smuzhiyun     if (pScreenPriv->hwndScreen) {
609*4882a593Smuzhiyun         DestroyWindow(pScreenPriv->hwndScreen);
610*4882a593Smuzhiyun         pScreenPriv->hwndScreen = NULL;
611*4882a593Smuzhiyun     }
612*4882a593Smuzhiyun 
613*4882a593Smuzhiyun     /* Destroy the thread startup mutex */
614*4882a593Smuzhiyun     pthread_mutex_destroy(&pScreenPriv->pmServerStarted);
615*4882a593Smuzhiyun 
616*4882a593Smuzhiyun     /* Invalidate our screeninfo's pointer to the screen */
617*4882a593Smuzhiyun     pScreenInfo->pScreen = NULL;
618*4882a593Smuzhiyun 
619*4882a593Smuzhiyun     /* Free the screen privates for this screen */
620*4882a593Smuzhiyun     free((void *) pScreenPriv);
621*4882a593Smuzhiyun 
622*4882a593Smuzhiyun     return fReturn;
623*4882a593Smuzhiyun }
624*4882a593Smuzhiyun 
625*4882a593Smuzhiyun /*
626*4882a593Smuzhiyun  * Tell mi what sort of visuals we need.
627*4882a593Smuzhiyun  *
628*4882a593Smuzhiyun  * Generally we only need one visual, as our screen can only
629*4882a593Smuzhiyun  * handle one format at a time, I believe.  You may want
630*4882a593Smuzhiyun  * to verify that last sentence.
631*4882a593Smuzhiyun  */
632*4882a593Smuzhiyun 
633*4882a593Smuzhiyun static Bool
winInitVisualsShadowGDI(ScreenPtr pScreen)634*4882a593Smuzhiyun winInitVisualsShadowGDI(ScreenPtr pScreen)
635*4882a593Smuzhiyun {
636*4882a593Smuzhiyun     winScreenPriv(pScreen);
637*4882a593Smuzhiyun     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
638*4882a593Smuzhiyun 
639*4882a593Smuzhiyun     /* Display debugging information */
640*4882a593Smuzhiyun     ErrorF("winInitVisualsShadowGDI - Masks %08x %08x %08x BPRGB %d d %d "
641*4882a593Smuzhiyun            "bpp %d\n",
642*4882a593Smuzhiyun            (unsigned int) pScreenPriv->dwRedMask,
643*4882a593Smuzhiyun            (unsigned int) pScreenPriv->dwGreenMask,
644*4882a593Smuzhiyun            (unsigned int) pScreenPriv->dwBlueMask,
645*4882a593Smuzhiyun            (int) pScreenPriv->dwBitsPerRGB,
646*4882a593Smuzhiyun            (int) pScreenInfo->dwDepth, (int) pScreenInfo->dwBPP);
647*4882a593Smuzhiyun 
648*4882a593Smuzhiyun     /* Create a single visual according to the Windows screen depth */
649*4882a593Smuzhiyun     switch (pScreenInfo->dwDepth) {
650*4882a593Smuzhiyun     case 24:
651*4882a593Smuzhiyun     case 16:
652*4882a593Smuzhiyun     case 15:
653*4882a593Smuzhiyun         /* Setup the real visual */
654*4882a593Smuzhiyun         if (!miSetVisualTypesAndMasks(pScreenInfo->dwDepth,
655*4882a593Smuzhiyun                                       TrueColorMask,
656*4882a593Smuzhiyun                                       pScreenPriv->dwBitsPerRGB,
657*4882a593Smuzhiyun                                       -1,
658*4882a593Smuzhiyun                                       pScreenPriv->dwRedMask,
659*4882a593Smuzhiyun                                       pScreenPriv->dwGreenMask,
660*4882a593Smuzhiyun                                       pScreenPriv->dwBlueMask)) {
661*4882a593Smuzhiyun             ErrorF("winInitVisualsShadowGDI - miSetVisualTypesAndMasks "
662*4882a593Smuzhiyun                    "failed\n");
663*4882a593Smuzhiyun             return FALSE;
664*4882a593Smuzhiyun         }
665*4882a593Smuzhiyun 
666*4882a593Smuzhiyun #ifdef XWIN_EMULATEPSEUDO
667*4882a593Smuzhiyun         if (!pScreenInfo->fEmulatePseudo)
668*4882a593Smuzhiyun             break;
669*4882a593Smuzhiyun 
670*4882a593Smuzhiyun         /* Setup a pseudocolor visual */
671*4882a593Smuzhiyun         if (!miSetVisualTypesAndMasks(8, PseudoColorMask, 8, -1, 0, 0, 0)) {
672*4882a593Smuzhiyun             ErrorF("winInitVisualsShadowGDI - miSetVisualTypesAndMasks "
673*4882a593Smuzhiyun                    "failed for PseudoColor\n");
674*4882a593Smuzhiyun             return FALSE;
675*4882a593Smuzhiyun         }
676*4882a593Smuzhiyun #endif
677*4882a593Smuzhiyun         break;
678*4882a593Smuzhiyun 
679*4882a593Smuzhiyun     case 8:
680*4882a593Smuzhiyun         if (!miSetVisualTypesAndMasks(pScreenInfo->dwDepth,
681*4882a593Smuzhiyun                                       PseudoColorMask,
682*4882a593Smuzhiyun                                       pScreenPriv->dwBitsPerRGB,
683*4882a593Smuzhiyun                                       PseudoColor,
684*4882a593Smuzhiyun                                       pScreenPriv->dwRedMask,
685*4882a593Smuzhiyun                                       pScreenPriv->dwGreenMask,
686*4882a593Smuzhiyun                                       pScreenPriv->dwBlueMask)) {
687*4882a593Smuzhiyun             ErrorF("winInitVisualsShadowGDI - miSetVisualTypesAndMasks "
688*4882a593Smuzhiyun                    "failed\n");
689*4882a593Smuzhiyun             return FALSE;
690*4882a593Smuzhiyun         }
691*4882a593Smuzhiyun         break;
692*4882a593Smuzhiyun 
693*4882a593Smuzhiyun     default:
694*4882a593Smuzhiyun         ErrorF("winInitVisualsShadowGDI - Unknown screen depth\n");
695*4882a593Smuzhiyun         return FALSE;
696*4882a593Smuzhiyun     }
697*4882a593Smuzhiyun 
698*4882a593Smuzhiyun #if CYGDEBUG
699*4882a593Smuzhiyun     winDebug("winInitVisualsShadowGDI - Returning\n");
700*4882a593Smuzhiyun #endif
701*4882a593Smuzhiyun 
702*4882a593Smuzhiyun     return TRUE;
703*4882a593Smuzhiyun }
704*4882a593Smuzhiyun 
705*4882a593Smuzhiyun /*
706*4882a593Smuzhiyun  * Adjust the proposed video mode
707*4882a593Smuzhiyun  */
708*4882a593Smuzhiyun 
709*4882a593Smuzhiyun static Bool
winAdjustVideoModeShadowGDI(ScreenPtr pScreen)710*4882a593Smuzhiyun winAdjustVideoModeShadowGDI(ScreenPtr pScreen)
711*4882a593Smuzhiyun {
712*4882a593Smuzhiyun     winScreenPriv(pScreen);
713*4882a593Smuzhiyun     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
714*4882a593Smuzhiyun     HDC hdc;
715*4882a593Smuzhiyun     DWORD dwBPP;
716*4882a593Smuzhiyun 
717*4882a593Smuzhiyun     hdc = GetDC(NULL);
718*4882a593Smuzhiyun 
719*4882a593Smuzhiyun     /* We're in serious trouble if we can't get a DC */
720*4882a593Smuzhiyun     if (hdc == NULL) {
721*4882a593Smuzhiyun         ErrorF("winAdjustVideoModeShadowGDI - GetDC () failed\n");
722*4882a593Smuzhiyun         return FALSE;
723*4882a593Smuzhiyun     }
724*4882a593Smuzhiyun 
725*4882a593Smuzhiyun     /* Query GDI for current display depth */
726*4882a593Smuzhiyun     dwBPP = GetDeviceCaps(hdc, BITSPIXEL);
727*4882a593Smuzhiyun 
728*4882a593Smuzhiyun     /* GDI cannot change the screen depth, so always use GDI's depth */
729*4882a593Smuzhiyun     pScreenInfo->dwBPP = dwBPP;
730*4882a593Smuzhiyun 
731*4882a593Smuzhiyun     /* Release our DC */
732*4882a593Smuzhiyun     ReleaseDC(NULL, hdc);
733*4882a593Smuzhiyun     hdc = NULL;
734*4882a593Smuzhiyun 
735*4882a593Smuzhiyun     return TRUE;
736*4882a593Smuzhiyun }
737*4882a593Smuzhiyun 
738*4882a593Smuzhiyun /*
739*4882a593Smuzhiyun  * Blt exposed regions to the screen
740*4882a593Smuzhiyun  */
741*4882a593Smuzhiyun 
742*4882a593Smuzhiyun static Bool
winBltExposedRegionsShadowGDI(ScreenPtr pScreen)743*4882a593Smuzhiyun winBltExposedRegionsShadowGDI(ScreenPtr pScreen)
744*4882a593Smuzhiyun {
745*4882a593Smuzhiyun     winScreenPriv(pScreen);
746*4882a593Smuzhiyun     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
747*4882a593Smuzhiyun     winPrivCmapPtr pCmapPriv = NULL;
748*4882a593Smuzhiyun     HDC hdcUpdate;
749*4882a593Smuzhiyun     PAINTSTRUCT ps;
750*4882a593Smuzhiyun 
751*4882a593Smuzhiyun     /* BeginPaint gives us an hdc that clips to the invalidated region */
752*4882a593Smuzhiyun     hdcUpdate = BeginPaint(pScreenPriv->hwndScreen, &ps);
753*4882a593Smuzhiyun 
754*4882a593Smuzhiyun     /* Realize the palette, if we have one */
755*4882a593Smuzhiyun     if (pScreenPriv->pcmapInstalled != NULL) {
756*4882a593Smuzhiyun         pCmapPriv = winGetCmapPriv(pScreenPriv->pcmapInstalled);
757*4882a593Smuzhiyun 
758*4882a593Smuzhiyun         SelectPalette(hdcUpdate, pCmapPriv->hPalette, FALSE);
759*4882a593Smuzhiyun         RealizePalette(hdcUpdate);
760*4882a593Smuzhiyun     }
761*4882a593Smuzhiyun 
762*4882a593Smuzhiyun     /* Our BitBlt will be clipped to the invalidated region */
763*4882a593Smuzhiyun     BitBlt(hdcUpdate,
764*4882a593Smuzhiyun            0, 0,
765*4882a593Smuzhiyun            pScreenInfo->dwWidth, pScreenInfo->dwHeight,
766*4882a593Smuzhiyun            pScreenPriv->hdcShadow, 0, 0, SRCCOPY);
767*4882a593Smuzhiyun 
768*4882a593Smuzhiyun     /* EndPaint frees the DC */
769*4882a593Smuzhiyun     EndPaint(pScreenPriv->hwndScreen, &ps);
770*4882a593Smuzhiyun 
771*4882a593Smuzhiyun     /* Redraw all windows */
772*4882a593Smuzhiyun     if (pScreenInfo->fMultiWindow)
773*4882a593Smuzhiyun         EnumThreadWindows(g_dwCurrentThreadID, winRedrawAllProcShadowGDI,
774*4882a593Smuzhiyun                           (LPARAM) pScreenPriv->hwndScreen);
775*4882a593Smuzhiyun 
776*4882a593Smuzhiyun     return TRUE;
777*4882a593Smuzhiyun }
778*4882a593Smuzhiyun 
779*4882a593Smuzhiyun /*
780*4882a593Smuzhiyun  * Do any engine-specific appliation-activation processing
781*4882a593Smuzhiyun  */
782*4882a593Smuzhiyun 
783*4882a593Smuzhiyun static Bool
winActivateAppShadowGDI(ScreenPtr pScreen)784*4882a593Smuzhiyun winActivateAppShadowGDI(ScreenPtr pScreen)
785*4882a593Smuzhiyun {
786*4882a593Smuzhiyun     winScreenPriv(pScreen);
787*4882a593Smuzhiyun     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
788*4882a593Smuzhiyun 
789*4882a593Smuzhiyun     /*
790*4882a593Smuzhiyun      * 2004/04/12 - Harold - We perform the restoring or minimizing
791*4882a593Smuzhiyun      * manually for ShadowGDI in fullscreen modes so that this engine
792*4882a593Smuzhiyun      * will perform just like ShadowDD and ShadowDDNL in fullscreen mode;
793*4882a593Smuzhiyun      * if we do not do this then our fullscreen window will appear in the
794*4882a593Smuzhiyun      * z-order when it is deactivated and it can be uncovered by resizing
795*4882a593Smuzhiyun      * or minimizing another window that is on top of it, which is not how
796*4882a593Smuzhiyun      * the DirectDraw engines work.  Therefore we keep this code here to
797*4882a593Smuzhiyun      * make sure that all engines work the same in fullscreen mode.
798*4882a593Smuzhiyun      */
799*4882a593Smuzhiyun 
800*4882a593Smuzhiyun     /*
801*4882a593Smuzhiyun      * Are we active?
802*4882a593Smuzhiyun      * Are we fullscreen?
803*4882a593Smuzhiyun      */
804*4882a593Smuzhiyun     if (pScreenPriv->fActive && pScreenInfo->fFullScreen) {
805*4882a593Smuzhiyun         /*
806*4882a593Smuzhiyun          * Activating, attempt to bring our window
807*4882a593Smuzhiyun          * to the top of the display
808*4882a593Smuzhiyun          */
809*4882a593Smuzhiyun         ShowWindow(pScreenPriv->hwndScreen, SW_RESTORE);
810*4882a593Smuzhiyun     }
811*4882a593Smuzhiyun     else if (!pScreenPriv->fActive && pScreenInfo->fFullScreen) {
812*4882a593Smuzhiyun         /*
813*4882a593Smuzhiyun          * Deactivating, stuff our window onto the
814*4882a593Smuzhiyun          * task bar.
815*4882a593Smuzhiyun          */
816*4882a593Smuzhiyun         ShowWindow(pScreenPriv->hwndScreen, SW_MINIMIZE);
817*4882a593Smuzhiyun     }
818*4882a593Smuzhiyun 
819*4882a593Smuzhiyun     return TRUE;
820*4882a593Smuzhiyun }
821*4882a593Smuzhiyun 
822*4882a593Smuzhiyun /*
823*4882a593Smuzhiyun  * Reblit the shadow framebuffer to the screen.
824*4882a593Smuzhiyun  */
825*4882a593Smuzhiyun 
826*4882a593Smuzhiyun static Bool
winRedrawScreenShadowGDI(ScreenPtr pScreen)827*4882a593Smuzhiyun winRedrawScreenShadowGDI(ScreenPtr pScreen)
828*4882a593Smuzhiyun {
829*4882a593Smuzhiyun     winScreenPriv(pScreen);
830*4882a593Smuzhiyun     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
831*4882a593Smuzhiyun 
832*4882a593Smuzhiyun     /* Redraw the whole window, to take account for the new colors */
833*4882a593Smuzhiyun     BitBlt(pScreenPriv->hdcScreen,
834*4882a593Smuzhiyun            0, 0,
835*4882a593Smuzhiyun            pScreenInfo->dwWidth, pScreenInfo->dwHeight,
836*4882a593Smuzhiyun            pScreenPriv->hdcShadow, 0, 0, SRCCOPY);
837*4882a593Smuzhiyun 
838*4882a593Smuzhiyun     /* Redraw all windows */
839*4882a593Smuzhiyun     if (pScreenInfo->fMultiWindow)
840*4882a593Smuzhiyun         EnumThreadWindows(g_dwCurrentThreadID, winRedrawAllProcShadowGDI, 0);
841*4882a593Smuzhiyun 
842*4882a593Smuzhiyun     return TRUE;
843*4882a593Smuzhiyun }
844*4882a593Smuzhiyun 
845*4882a593Smuzhiyun /*
846*4882a593Smuzhiyun  * Realize the currently installed colormap
847*4882a593Smuzhiyun  */
848*4882a593Smuzhiyun 
849*4882a593Smuzhiyun static Bool
winRealizeInstalledPaletteShadowGDI(ScreenPtr pScreen)850*4882a593Smuzhiyun winRealizeInstalledPaletteShadowGDI(ScreenPtr pScreen)
851*4882a593Smuzhiyun {
852*4882a593Smuzhiyun     winScreenPriv(pScreen);
853*4882a593Smuzhiyun     winPrivCmapPtr pCmapPriv = NULL;
854*4882a593Smuzhiyun 
855*4882a593Smuzhiyun #if CYGDEBUG
856*4882a593Smuzhiyun     winDebug("winRealizeInstalledPaletteShadowGDI\n");
857*4882a593Smuzhiyun #endif
858*4882a593Smuzhiyun 
859*4882a593Smuzhiyun     /* Don't do anything if there is not a colormap */
860*4882a593Smuzhiyun     if (pScreenPriv->pcmapInstalled == NULL) {
861*4882a593Smuzhiyun #if CYGDEBUG
862*4882a593Smuzhiyun         winDebug("winRealizeInstalledPaletteShadowGDI - No colormap "
863*4882a593Smuzhiyun                  "installed\n");
864*4882a593Smuzhiyun #endif
865*4882a593Smuzhiyun         return TRUE;
866*4882a593Smuzhiyun     }
867*4882a593Smuzhiyun 
868*4882a593Smuzhiyun     pCmapPriv = winGetCmapPriv(pScreenPriv->pcmapInstalled);
869*4882a593Smuzhiyun 
870*4882a593Smuzhiyun     /* Realize our palette for the screen */
871*4882a593Smuzhiyun     if (RealizePalette(pScreenPriv->hdcScreen) == GDI_ERROR) {
872*4882a593Smuzhiyun         ErrorF("winRealizeInstalledPaletteShadowGDI - RealizePalette () "
873*4882a593Smuzhiyun                "failed\n");
874*4882a593Smuzhiyun         return FALSE;
875*4882a593Smuzhiyun     }
876*4882a593Smuzhiyun 
877*4882a593Smuzhiyun     /* Set the DIB color table */
878*4882a593Smuzhiyun     if (SetDIBColorTable(pScreenPriv->hdcShadow,
879*4882a593Smuzhiyun                          0,
880*4882a593Smuzhiyun                          WIN_NUM_PALETTE_ENTRIES, pCmapPriv->rgbColors) == 0) {
881*4882a593Smuzhiyun         ErrorF("winRealizeInstalledPaletteShadowGDI - SetDIBColorTable () "
882*4882a593Smuzhiyun                "failed\n");
883*4882a593Smuzhiyun         return FALSE;
884*4882a593Smuzhiyun     }
885*4882a593Smuzhiyun 
886*4882a593Smuzhiyun     return TRUE;
887*4882a593Smuzhiyun }
888*4882a593Smuzhiyun 
889*4882a593Smuzhiyun /*
890*4882a593Smuzhiyun  * Install the specified colormap
891*4882a593Smuzhiyun  */
892*4882a593Smuzhiyun 
893*4882a593Smuzhiyun static Bool
winInstallColormapShadowGDI(ColormapPtr pColormap)894*4882a593Smuzhiyun winInstallColormapShadowGDI(ColormapPtr pColormap)
895*4882a593Smuzhiyun {
896*4882a593Smuzhiyun     ScreenPtr pScreen = pColormap->pScreen;
897*4882a593Smuzhiyun 
898*4882a593Smuzhiyun     winScreenPriv(pScreen);
899*4882a593Smuzhiyun     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
900*4882a593Smuzhiyun 
901*4882a593Smuzhiyun     winCmapPriv(pColormap);
902*4882a593Smuzhiyun 
903*4882a593Smuzhiyun     /*
904*4882a593Smuzhiyun      * Tell Windows to install the new colormap
905*4882a593Smuzhiyun      */
906*4882a593Smuzhiyun     if (SelectPalette(pScreenPriv->hdcScreen,
907*4882a593Smuzhiyun                       pCmapPriv->hPalette, FALSE) == NULL) {
908*4882a593Smuzhiyun         ErrorF("winInstallColormapShadowGDI - SelectPalette () failed\n");
909*4882a593Smuzhiyun         return FALSE;
910*4882a593Smuzhiyun     }
911*4882a593Smuzhiyun 
912*4882a593Smuzhiyun     /* Realize the palette */
913*4882a593Smuzhiyun     if (GDI_ERROR == RealizePalette(pScreenPriv->hdcScreen)) {
914*4882a593Smuzhiyun         ErrorF("winInstallColormapShadowGDI - RealizePalette () failed\n");
915*4882a593Smuzhiyun         return FALSE;
916*4882a593Smuzhiyun     }
917*4882a593Smuzhiyun 
918*4882a593Smuzhiyun     /* Set the DIB color table */
919*4882a593Smuzhiyun     if (SetDIBColorTable(pScreenPriv->hdcShadow,
920*4882a593Smuzhiyun                          0,
921*4882a593Smuzhiyun                          WIN_NUM_PALETTE_ENTRIES, pCmapPriv->rgbColors) == 0) {
922*4882a593Smuzhiyun         ErrorF("winInstallColormapShadowGDI - SetDIBColorTable () failed\n");
923*4882a593Smuzhiyun         return FALSE;
924*4882a593Smuzhiyun     }
925*4882a593Smuzhiyun 
926*4882a593Smuzhiyun     /* Redraw the whole window, to take account for the new colors */
927*4882a593Smuzhiyun     BitBlt(pScreenPriv->hdcScreen,
928*4882a593Smuzhiyun            0, 0,
929*4882a593Smuzhiyun            pScreenInfo->dwWidth, pScreenInfo->dwHeight,
930*4882a593Smuzhiyun            pScreenPriv->hdcShadow, 0, 0, SRCCOPY);
931*4882a593Smuzhiyun 
932*4882a593Smuzhiyun     /* Save a pointer to the newly installed colormap */
933*4882a593Smuzhiyun     pScreenPriv->pcmapInstalled = pColormap;
934*4882a593Smuzhiyun 
935*4882a593Smuzhiyun     /* Redraw all windows */
936*4882a593Smuzhiyun     if (pScreenInfo->fMultiWindow)
937*4882a593Smuzhiyun         EnumThreadWindows(g_dwCurrentThreadID, winRedrawAllProcShadowGDI, 0);
938*4882a593Smuzhiyun 
939*4882a593Smuzhiyun     return TRUE;
940*4882a593Smuzhiyun }
941*4882a593Smuzhiyun 
942*4882a593Smuzhiyun /*
943*4882a593Smuzhiyun  * Store the specified colors in the specified colormap
944*4882a593Smuzhiyun  */
945*4882a593Smuzhiyun 
946*4882a593Smuzhiyun static Bool
winStoreColorsShadowGDI(ColormapPtr pColormap,int ndef,xColorItem * pdefs)947*4882a593Smuzhiyun winStoreColorsShadowGDI(ColormapPtr pColormap, int ndef, xColorItem * pdefs)
948*4882a593Smuzhiyun {
949*4882a593Smuzhiyun     ScreenPtr pScreen = pColormap->pScreen;
950*4882a593Smuzhiyun 
951*4882a593Smuzhiyun     winScreenPriv(pScreen);
952*4882a593Smuzhiyun     winCmapPriv(pColormap);
953*4882a593Smuzhiyun     ColormapPtr curpmap = pScreenPriv->pcmapInstalled;
954*4882a593Smuzhiyun 
955*4882a593Smuzhiyun     /* Put the X colormap entries into the Windows logical palette */
956*4882a593Smuzhiyun     if (SetPaletteEntries(pCmapPriv->hPalette,
957*4882a593Smuzhiyun                           pdefs[0].pixel,
958*4882a593Smuzhiyun                           ndef, pCmapPriv->peColors + pdefs[0].pixel) == 0) {
959*4882a593Smuzhiyun         ErrorF("winStoreColorsShadowGDI - SetPaletteEntries () failed\n");
960*4882a593Smuzhiyun         return FALSE;
961*4882a593Smuzhiyun     }
962*4882a593Smuzhiyun 
963*4882a593Smuzhiyun     /* Don't install the Windows palette if the colormap is not installed */
964*4882a593Smuzhiyun     if (pColormap != curpmap) {
965*4882a593Smuzhiyun         return TRUE;
966*4882a593Smuzhiyun     }
967*4882a593Smuzhiyun 
968*4882a593Smuzhiyun     /* Try to install the newly modified colormap */
969*4882a593Smuzhiyun     if (!winInstallColormapShadowGDI(pColormap)) {
970*4882a593Smuzhiyun         ErrorF("winInstallColormapShadowGDI - winInstallColormapShadowGDI "
971*4882a593Smuzhiyun                "failed\n");
972*4882a593Smuzhiyun         return FALSE;
973*4882a593Smuzhiyun     }
974*4882a593Smuzhiyun 
975*4882a593Smuzhiyun #if 0
976*4882a593Smuzhiyun     /* Tell Windows that the palette has changed */
977*4882a593Smuzhiyun     RealizePalette(pScreenPriv->hdcScreen);
978*4882a593Smuzhiyun 
979*4882a593Smuzhiyun     /* Set the DIB color table */
980*4882a593Smuzhiyun     if (SetDIBColorTable(pScreenPriv->hdcShadow,
981*4882a593Smuzhiyun                          pdefs[0].pixel,
982*4882a593Smuzhiyun                          ndef, pCmapPriv->rgbColors + pdefs[0].pixel) == 0) {
983*4882a593Smuzhiyun         ErrorF("winInstallColormapShadowGDI - SetDIBColorTable () failed\n");
984*4882a593Smuzhiyun         return FALSE;
985*4882a593Smuzhiyun     }
986*4882a593Smuzhiyun 
987*4882a593Smuzhiyun     /* Save a pointer to the newly installed colormap */
988*4882a593Smuzhiyun     pScreenPriv->pcmapInstalled = pColormap;
989*4882a593Smuzhiyun #endif
990*4882a593Smuzhiyun 
991*4882a593Smuzhiyun     return TRUE;
992*4882a593Smuzhiyun }
993*4882a593Smuzhiyun 
994*4882a593Smuzhiyun /*
995*4882a593Smuzhiyun  * Colormap initialization procedure
996*4882a593Smuzhiyun  */
997*4882a593Smuzhiyun 
998*4882a593Smuzhiyun static Bool
winCreateColormapShadowGDI(ColormapPtr pColormap)999*4882a593Smuzhiyun winCreateColormapShadowGDI(ColormapPtr pColormap)
1000*4882a593Smuzhiyun {
1001*4882a593Smuzhiyun     LPLOGPALETTE lpPaletteNew = NULL;
1002*4882a593Smuzhiyun     DWORD dwEntriesMax;
1003*4882a593Smuzhiyun     VisualPtr pVisual;
1004*4882a593Smuzhiyun     HPALETTE hpalNew = NULL;
1005*4882a593Smuzhiyun 
1006*4882a593Smuzhiyun     winCmapPriv(pColormap);
1007*4882a593Smuzhiyun 
1008*4882a593Smuzhiyun     /* Get a pointer to the visual that the colormap belongs to */
1009*4882a593Smuzhiyun     pVisual = pColormap->pVisual;
1010*4882a593Smuzhiyun 
1011*4882a593Smuzhiyun     /* Get the maximum number of palette entries for this visual */
1012*4882a593Smuzhiyun     dwEntriesMax = pVisual->ColormapEntries;
1013*4882a593Smuzhiyun 
1014*4882a593Smuzhiyun     /* Allocate a Windows logical color palette with max entries */
1015*4882a593Smuzhiyun     lpPaletteNew = malloc(sizeof(LOGPALETTE)
1016*4882a593Smuzhiyun                           + (dwEntriesMax - 1) * sizeof(PALETTEENTRY));
1017*4882a593Smuzhiyun     if (lpPaletteNew == NULL) {
1018*4882a593Smuzhiyun         ErrorF("winCreateColormapShadowGDI - Couldn't allocate palette "
1019*4882a593Smuzhiyun                "with %d entries\n", (int) dwEntriesMax);
1020*4882a593Smuzhiyun         return FALSE;
1021*4882a593Smuzhiyun     }
1022*4882a593Smuzhiyun 
1023*4882a593Smuzhiyun     /* Zero out the colormap */
1024*4882a593Smuzhiyun     ZeroMemory(lpPaletteNew, sizeof(LOGPALETTE)
1025*4882a593Smuzhiyun                + (dwEntriesMax - 1) * sizeof(PALETTEENTRY));
1026*4882a593Smuzhiyun 
1027*4882a593Smuzhiyun     /* Set the logical palette structure */
1028*4882a593Smuzhiyun     lpPaletteNew->palVersion = 0x0300;
1029*4882a593Smuzhiyun     lpPaletteNew->palNumEntries = dwEntriesMax;
1030*4882a593Smuzhiyun 
1031*4882a593Smuzhiyun     /* Tell Windows to create the palette */
1032*4882a593Smuzhiyun     hpalNew = CreatePalette(lpPaletteNew);
1033*4882a593Smuzhiyun     if (hpalNew == NULL) {
1034*4882a593Smuzhiyun         ErrorF("winCreateColormapShadowGDI - CreatePalette () failed\n");
1035*4882a593Smuzhiyun         free(lpPaletteNew);
1036*4882a593Smuzhiyun         return FALSE;
1037*4882a593Smuzhiyun     }
1038*4882a593Smuzhiyun 
1039*4882a593Smuzhiyun     /* Save the Windows logical palette handle in the X colormaps' privates */
1040*4882a593Smuzhiyun     pCmapPriv->hPalette = hpalNew;
1041*4882a593Smuzhiyun 
1042*4882a593Smuzhiyun     /* Free the palette initialization memory */
1043*4882a593Smuzhiyun     free(lpPaletteNew);
1044*4882a593Smuzhiyun 
1045*4882a593Smuzhiyun     return TRUE;
1046*4882a593Smuzhiyun }
1047*4882a593Smuzhiyun 
1048*4882a593Smuzhiyun /*
1049*4882a593Smuzhiyun  * Colormap destruction procedure
1050*4882a593Smuzhiyun  */
1051*4882a593Smuzhiyun 
1052*4882a593Smuzhiyun static Bool
winDestroyColormapShadowGDI(ColormapPtr pColormap)1053*4882a593Smuzhiyun winDestroyColormapShadowGDI(ColormapPtr pColormap)
1054*4882a593Smuzhiyun {
1055*4882a593Smuzhiyun     winScreenPriv(pColormap->pScreen);
1056*4882a593Smuzhiyun     winCmapPriv(pColormap);
1057*4882a593Smuzhiyun 
1058*4882a593Smuzhiyun     /*
1059*4882a593Smuzhiyun      * Is colormap to be destroyed the default?
1060*4882a593Smuzhiyun      *
1061*4882a593Smuzhiyun      * Non-default colormaps should have had winUninstallColormap
1062*4882a593Smuzhiyun      * called on them before we get here.  The default colormap
1063*4882a593Smuzhiyun      * will not have had winUninstallColormap called on it.  Thus,
1064*4882a593Smuzhiyun      * we need to handle the default colormap in a special way.
1065*4882a593Smuzhiyun      */
1066*4882a593Smuzhiyun     if (pColormap->flags & IsDefault) {
1067*4882a593Smuzhiyun #if CYGDEBUG
1068*4882a593Smuzhiyun         winDebug("winDestroyColormapShadowGDI - Destroying default "
1069*4882a593Smuzhiyun                  "colormap\n");
1070*4882a593Smuzhiyun #endif
1071*4882a593Smuzhiyun 
1072*4882a593Smuzhiyun         /*
1073*4882a593Smuzhiyun          * FIXME: Walk the list of all screens, popping the default
1074*4882a593Smuzhiyun          * palette out of each screen device context.
1075*4882a593Smuzhiyun          */
1076*4882a593Smuzhiyun 
1077*4882a593Smuzhiyun         /* Pop the palette out of the device context */
1078*4882a593Smuzhiyun         SelectPalette(pScreenPriv->hdcScreen,
1079*4882a593Smuzhiyun                       GetStockObject(DEFAULT_PALETTE), FALSE);
1080*4882a593Smuzhiyun 
1081*4882a593Smuzhiyun         /* Clear our private installed colormap pointer */
1082*4882a593Smuzhiyun         pScreenPriv->pcmapInstalled = NULL;
1083*4882a593Smuzhiyun     }
1084*4882a593Smuzhiyun 
1085*4882a593Smuzhiyun     /* Try to delete the logical palette */
1086*4882a593Smuzhiyun     if (DeleteObject(pCmapPriv->hPalette) == 0) {
1087*4882a593Smuzhiyun         ErrorF("winDestroyColormap - DeleteObject () failed\n");
1088*4882a593Smuzhiyun         return FALSE;
1089*4882a593Smuzhiyun     }
1090*4882a593Smuzhiyun 
1091*4882a593Smuzhiyun     /* Invalidate the colormap privates */
1092*4882a593Smuzhiyun     pCmapPriv->hPalette = NULL;
1093*4882a593Smuzhiyun 
1094*4882a593Smuzhiyun     return TRUE;
1095*4882a593Smuzhiyun }
1096*4882a593Smuzhiyun 
1097*4882a593Smuzhiyun /*
1098*4882a593Smuzhiyun  * Set engine specific funtions
1099*4882a593Smuzhiyun  */
1100*4882a593Smuzhiyun 
1101*4882a593Smuzhiyun Bool
winSetEngineFunctionsShadowGDI(ScreenPtr pScreen)1102*4882a593Smuzhiyun winSetEngineFunctionsShadowGDI(ScreenPtr pScreen)
1103*4882a593Smuzhiyun {
1104*4882a593Smuzhiyun     winScreenPriv(pScreen);
1105*4882a593Smuzhiyun     winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
1106*4882a593Smuzhiyun 
1107*4882a593Smuzhiyun     /* Set our pointers */
1108*4882a593Smuzhiyun     pScreenPriv->pwinAllocateFB = winAllocateFBShadowGDI;
1109*4882a593Smuzhiyun     pScreenPriv->pwinFreeFB = winFreeFBShadowGDI;
1110*4882a593Smuzhiyun     pScreenPriv->pwinShadowUpdate = winShadowUpdateGDI;
1111*4882a593Smuzhiyun     pScreenPriv->pwinInitScreen = winInitScreenShadowGDI;
1112*4882a593Smuzhiyun     pScreenPriv->pwinCloseScreen = winCloseScreenShadowGDI;
1113*4882a593Smuzhiyun     pScreenPriv->pwinInitVisuals = winInitVisualsShadowGDI;
1114*4882a593Smuzhiyun     pScreenPriv->pwinAdjustVideoMode = winAdjustVideoModeShadowGDI;
1115*4882a593Smuzhiyun     if (pScreenInfo->fFullScreen)
1116*4882a593Smuzhiyun         pScreenPriv->pwinCreateBoundingWindow =
1117*4882a593Smuzhiyun             winCreateBoundingWindowFullScreen;
1118*4882a593Smuzhiyun     else
1119*4882a593Smuzhiyun         pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowWindowed;
1120*4882a593Smuzhiyun     pScreenPriv->pwinFinishScreenInit = winFinishScreenInitFB;
1121*4882a593Smuzhiyun     pScreenPriv->pwinBltExposedRegions = winBltExposedRegionsShadowGDI;
1122*4882a593Smuzhiyun     pScreenPriv->pwinActivateApp = winActivateAppShadowGDI;
1123*4882a593Smuzhiyun     pScreenPriv->pwinRedrawScreen = winRedrawScreenShadowGDI;
1124*4882a593Smuzhiyun     pScreenPriv->pwinRealizeInstalledPalette =
1125*4882a593Smuzhiyun         winRealizeInstalledPaletteShadowGDI;
1126*4882a593Smuzhiyun     pScreenPriv->pwinInstallColormap = winInstallColormapShadowGDI;
1127*4882a593Smuzhiyun     pScreenPriv->pwinStoreColors = winStoreColorsShadowGDI;
1128*4882a593Smuzhiyun     pScreenPriv->pwinCreateColormap = winCreateColormapShadowGDI;
1129*4882a593Smuzhiyun     pScreenPriv->pwinDestroyColormap = winDestroyColormapShadowGDI;
1130*4882a593Smuzhiyun     pScreenPriv->pwinCreatePrimarySurface = NULL;
1131*4882a593Smuzhiyun     pScreenPriv->pwinReleasePrimarySurface = NULL;
1132*4882a593Smuzhiyun 
1133*4882a593Smuzhiyun     return TRUE;
1134*4882a593Smuzhiyun }
1135