Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / xwin / winnativegdi.c
CommitLineData
a09e091a
JB
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: Harold L Hunt II
29 */
30
31#ifdef HAVE_XWIN_CONFIG_H
32#include <xwin-config.h>
33#endif
34#include "win.h"
35
36/*
37 * Local function prototypes
38 */
39
40static Bool
41 winAllocateFBNativeGDI(ScreenPtr pScreen);
42
43static void
44 winShadowUpdateNativeGDI(ScreenPtr pScreen, shadowBufPtr pBuf);
45
46static Bool
47 winCloseScreenNativeGDI(ScreenPtr pScreen);
48
49static Bool
50 winInitVisualsNativeGDI(ScreenPtr pScreen);
51
52static Bool
53 winAdjustVideoModeNativeGDI(ScreenPtr pScreen);
54
55#if 0
56static Bool
57 winBltExposedRegionsNativeGDI(ScreenPtr pScreen);
58#endif
59
60static Bool
61 winActivateAppNativeGDI(ScreenPtr pScreen);
62
63static Bool
64 winRedrawScreenNativeGDI(ScreenPtr pScreen);
65
66static Bool
67 winRealizeInstalledPaletteNativeGDI(ScreenPtr pScreen);
68
69static Bool
70 winInstallColormapNativeGDI(ColormapPtr pColormap);
71
72static Bool
73 winStoreColorsNativeGDI(ColormapPtr pmap, int ndef, xColorItem * pdefs);
74
75static Bool
76 winCreateColormapNativeGDI(ColormapPtr pColormap);
77
78static Bool
79 winDestroyColormapNativeGDI(ColormapPtr pColormap);
80
81static Bool
82winAllocateFBNativeGDI(ScreenPtr pScreen)
83{
84 FatalError("winAllocateFBNativeGDI\n");
85
86 return TRUE;
87}
88
89static void
90winFreeFBNativeGDI(ScreenPtr pScreen)
91{
92 FatalError("winFreeFBNativeGDI\n");
93}
94
95static Bool
96winInitScreenNativeGDI(ScreenPtr pScreen)
97{
98 FatalError("winInitScreenNativeGDI\n");
99}
100
101/*
102 * We wrap whatever CloseScreen procedure was specified by fb;
103 * a pointer to said procedure is stored in our privates.
104 */
105
106static Bool
107winCloseScreenNativeGDI(ScreenPtr pScreen)
108{
109 winScreenPriv(pScreen);
110 winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
111
112 ErrorF("winCloseScreenNativeGDI - Freeing screen resources\n");
113
114 /* Flag that the screen is closed */
115 pScreenPriv->fClosed = TRUE;
116 pScreenPriv->fActive = FALSE;
117
118 /*
119 * NOTE: mi doesn't use a CloseScreen procedure, so we do not
120 * need to call a wrapped procedure here.
121 */
122
123 /* Delete the window property */
124 RemoveProp(pScreenPriv->hwndScreen, WIN_SCR_PROP);
125
126 ErrorF("winCloseScreenNativeGDI - Destroying window\n");
127
128 /* Delete tray icon, if we have one */
129 if (!pScreenInfo->fNoTrayIcon)
130 winDeleteNotifyIcon(pScreenPriv);
131
132 /* Free the exit confirmation dialog box, if it exists */
133 if (g_hDlgExit != NULL) {
134 DestroyWindow(g_hDlgExit);
135 g_hDlgExit = NULL;
136 }
137
138 /* Kill our window */
139 if (pScreenPriv->hwndScreen) {
140 DestroyWindow(pScreenPriv->hwndScreen);
141 pScreenPriv->hwndScreen = NULL;
142 }
143
144 /* Invalidate our screeninfo's pointer to the screen */
145 pScreenInfo->pScreen = NULL;
146
147 /* Free the screen privates for this screen */
148 free(pScreenPriv);
149
150 ErrorF("winCloseScreenNativeGDI - Returning\n");
151
152 return TRUE;
153}
154
155static void
156winShadowUpdateNativeGDI(ScreenPtr pScreen, shadowBufPtr pBuf)
157{
158 FatalError("winShadowUpdateNativeGDI\n");
159 return;
160}
161
162static Bool
163winInitVisualsNativeGDI(ScreenPtr pScreen)
164{
165 winScreenPriv(pScreen);
166 winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
167
168 /* Set the bitsPerRGB and bit masks */
169 switch (pScreenInfo->dwDepth) {
170 case 24:
171 pScreenPriv->dwBitsPerRGB = 8;
172 pScreenPriv->dwRedMask = 0x00FF0000;
173 pScreenPriv->dwGreenMask = 0x0000FF00;
174 pScreenPriv->dwBlueMask = 0x000000FF;
175 break;
176
177 case 16:
178 pScreenPriv->dwBitsPerRGB = 6;
179 pScreenPriv->dwRedMask = 0xF800;
180 pScreenPriv->dwGreenMask = 0x07E0;
181 pScreenPriv->dwBlueMask = 0x001F;
182 break;
183
184 case 15:
185 pScreenPriv->dwBitsPerRGB = 5;
186 pScreenPriv->dwRedMask = 0x7C00;
187 pScreenPriv->dwGreenMask = 0x03E0;
188 pScreenPriv->dwBlueMask = 0x001F;
189 break;
190
191 case 8:
192 pScreenPriv->dwBitsPerRGB = 8;
193 pScreenPriv->dwRedMask = 0;
194 pScreenPriv->dwGreenMask = 0;
195 pScreenPriv->dwBlueMask = 0;
196 break;
197
198 default:
199 ErrorF("winInitVisualsNativeGDI - Unknown screen depth\n");
200 return FALSE;
201 break;
202 }
203
204 /* Tell the user how many bits per RGB we are using */
205 ErrorF("winInitVisualsNativeGDI - Using dwBitsPerRGB: %d\n",
206 (int) pScreenPriv->dwBitsPerRGB);
207
208 /* Create a single visual according to the Windows screen depth */
209 switch (pScreenInfo->dwDepth) {
210 case 24:
211 case 16:
212 case 15:
213 if (!miSetVisualTypesAndMasks(pScreenInfo->dwDepth,
214 TrueColorMask,
215 pScreenPriv->dwBitsPerRGB,
216 TrueColor,
217 pScreenPriv->dwRedMask,
218 pScreenPriv->dwGreenMask,
219 pScreenPriv->dwBlueMask)) {
220 ErrorF("winInitVisuals - miSetVisualTypesAndMasks failed\n");
221 return FALSE;
222 }
223 break;
224
225 case 8:
226 ErrorF("winInitVisuals - Calling miSetVisualTypesAndMasks\n");
227 if (!miSetVisualTypesAndMasks(pScreenInfo->dwDepth,
228 StaticColorMask,
229 pScreenPriv->dwBitsPerRGB,
230 StaticColor,
231 pScreenPriv->dwRedMask,
232 pScreenPriv->dwGreenMask,
233 pScreenPriv->dwBlueMask)) {
234 ErrorF("winInitVisuals - miSetVisualTypesAndMasks failed\n");
235 return FALSE;
236 }
237 break;
238
239 default:
240 ErrorF("winInitVisualsNativeGDI - Unknown screen depth\n");
241 return FALSE;
242 }
243
244#if 1
245 ErrorF("winInitVisualsNativeGDI - Returning\n");
246#endif
247
248 return TRUE;
249}
250
251/* Adjust the video mode */
252static Bool
253winAdjustVideoModeNativeGDI(ScreenPtr pScreen)
254{
255 winScreenPriv(pScreen);
256 winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
257 HDC hdc = NULL;
258 DWORD dwBPP;
259
260 hdc = GetDC(NULL);
261
262 /* We're in serious trouble if we can't get a DC */
263 if (hdc == NULL) {
264 ErrorF("winAdjustVideoModeNativeGDI - GetDC () failed\n");
265 return FALSE;
266 }
267
268 /* Query GDI for current display depth */
269 dwBPP = GetDeviceCaps(hdc, BITSPIXEL);
270 pScreenInfo->dwDepth = GetDeviceCaps(hdc, PLANES);
271
272 switch (pScreenInfo->dwDepth) {
273 case 24:
274 case 16:
275 case 15:
276 case 8:
277 break;
278 default:
279 if (dwBPP == 32)
280 pScreenInfo->dwDepth = 24;
281 else
282 pScreenInfo->dwDepth = dwBPP;
283 break;
284 }
285
286 /* GDI cannot change the screen depth, so we'll use GDI's depth */
287 pScreenInfo->dwBPP = dwBPP;
288
289 /* Release our DC */
290 ReleaseDC(NULL, hdc);
291
292 return TRUE;
293}
294
295static Bool
296winActivateAppNativeGDI(ScreenPtr pScreen)
297{
298 winScreenPriv(pScreen);
299
300 /*
301 * Are we active?
302 * Are we fullscreen?
303 */
304 if (pScreenPriv != NULL
305 && pScreenPriv->fActive
306 && pScreenPriv->pScreenInfo && pScreenPriv->pScreenInfo->fFullScreen) {
307 /*
308 * Activating, attempt to bring our window
309 * to the top of the display
310 */
311 ShowWindow(pScreenPriv->hwndScreen, SW_RESTORE);
312 }
313
314 /*
315 * Are we inactive?
316 * Are we fullscreen?
317 */
318 if (pScreenPriv != NULL
319 && !pScreenPriv->fActive
320 && pScreenPriv->pScreenInfo && pScreenPriv->pScreenInfo->fFullScreen) {
321 /*
322 * Deactivating, stuff our window onto the
323 * task bar.
324 */
325 ShowWindow(pScreenPriv->hwndScreen, SW_MINIMIZE);
326 }
327
328 return TRUE;
329}
330
331HBITMAP
332winCreateDIBNativeGDI(int iWidth, int iHeight, int iDepth,
333 BYTE ** ppbBits, BITMAPINFO ** ppbmi)
334{
335 BITMAPINFOHEADER *pbmih = NULL;
336 HBITMAP hBitmap = NULL;
337 BITMAPINFO *pbmi = NULL;
338
339 /* Don't create an invalid bitmap */
340 if (iWidth == 0 || iHeight == 0 || iDepth == 0) {
341 ErrorF("\nwinCreateDIBNativeGDI - Invalid specs w %d h %d d %d\n\n",
342 iWidth, iHeight, iDepth);
343 return NULL;
344 }
345
346 /* Allocate bitmap info header */
347 pbmih = (BITMAPINFOHEADER *) malloc(sizeof(BITMAPINFOHEADER)
348 + 256 * sizeof(RGBQUAD));
349 if (pbmih == NULL) {
350 ErrorF("winCreateDIBNativeGDI - malloc () failed\n");
351 return FALSE;
352 }
353 ZeroMemory(pbmih, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
354
355 /* Describe bitmap to be created */
356 pbmih->biSize = sizeof(BITMAPINFOHEADER);
357 pbmih->biWidth = iWidth;
358 pbmih->biHeight = -iHeight;
359 pbmih->biPlanes = 1;
360 pbmih->biBitCount = iDepth;
361 pbmih->biCompression = BI_RGB;
362 pbmih->biSizeImage = 0;
363 pbmih->biXPelsPerMeter = 0;
364 pbmih->biYPelsPerMeter = 0;
365 pbmih->biClrUsed = 0;
366 pbmih->biClrImportant = 0;
367
368 /* Setup color table for mono DIBs */
369 if (iDepth == 1) {
370 pbmi = (BITMAPINFO *) pbmih;
371 pbmi->bmiColors[1].rgbBlue = 255;
372 pbmi->bmiColors[1].rgbGreen = 255;
373 pbmi->bmiColors[1].rgbRed = 255;
374 }
375
376 /* Create a DIB with a bit pointer */
377 hBitmap = CreateDIBSection(NULL,
378 (BITMAPINFO *) pbmih,
379 DIB_RGB_COLORS, (void **) ppbBits, NULL, 0);
380 if (hBitmap == NULL) {
381 ErrorF("winCreateDIBNativeGDI - CreateDIBSection () failed\n");
382 return NULL;
383 }
384
385 /* Free the bitmap info header memory */
386 if (ppbmi != NULL) {
387 /* Store the address of the BMIH in the ppbmih parameter */
388 *ppbmi = (BITMAPINFO *) pbmih;
389 }
390 else {
391 free(pbmih);
392 pbmih = NULL;
393 }
394
395 return hBitmap;
396}
397
398#if 0
399static Bool
400winBltExposedRegionsNativeGDI(ScreenPtr pScreen)
401{
402
403 return TRUE;
404}
405#endif
406
407static Bool
408winRedrawScreenNativeGDI(ScreenPtr pScreen)
409{
410 FatalError("winRedrawScreenNativeGDI\n");
411 return TRUE;
412}
413
414static Bool
415winRealizeInstalledPaletteNativeGDI(ScreenPtr pScreen)
416{
417 FatalError("winRealizeInstalledPaletteNativeGDI\n");
418 return TRUE;
419}
420
421static Bool
422winInstallColormapNativeGDI(ColormapPtr pColormap)
423{
424 FatalError("winInstallColormapNativeGDI\n");
425 return TRUE;
426}
427
428static Bool
429winStoreColorsNativeGDI(ColormapPtr pmap, int ndef, xColorItem * pdefs)
430{
431 FatalError("winStoreColorsNativeGDI\n");
432 return TRUE;
433}
434
435static Bool
436winCreateColormapNativeGDI(ColormapPtr pColormap)
437{
438 FatalError("winCreateColormapNativeGDI\n");
439 return TRUE;
440}
441
442static Bool
443winDestroyColormapNativeGDI(ColormapPtr pColormap)
444{
445 FatalError("winDestroyColormapNativeGDI\n");
446 return TRUE;
447}
448
449/* Set engine specific funtions */
450Bool
451winSetEngineFunctionsNativeGDI(ScreenPtr pScreen)
452{
453 winScreenPriv(pScreen);
454 winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
455
456 /* Set our pointers */
457 pScreenPriv->pwinAllocateFB = winAllocateFBNativeGDI;
458 pScreenPriv->pwinFreeFB = winFreeFBNativeGDI;
459 pScreenPriv->pwinShadowUpdate = winShadowUpdateNativeGDI;
460 pScreenPriv->pwinInitScreen = winInitScreenNativeGDI;
461 pScreenPriv->pwinCloseScreen = winCloseScreenNativeGDI;
462 pScreenPriv->pwinInitVisuals = winInitVisualsNativeGDI;
463 pScreenPriv->pwinAdjustVideoMode = winAdjustVideoModeNativeGDI;
464 if (pScreenInfo->fFullScreen)
465 pScreenPriv->pwinCreateBoundingWindow =
466 winCreateBoundingWindowFullScreen;
467 else
468 pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowWindowed;
469 pScreenPriv->pwinFinishScreenInit = winFinishScreenInitNativeGDI;
470 /*
471 * WARNING: Do not set the BltExposedRegions procedure pointer to anything
472 * other than NULL until a working painting procedure is in place.
473 * Else, winWindowProc will get stuck in an infinite loop because
474 * Windows expects the BeginPaint and EndPaint functions to be called
475 * before a WM_PAINT message can be removed from the queue. We are
476 * using NULL here as a signal for winWindowProc that it should
477 * not signal that the WM_PAINT message has been processed.
478 */
479 pScreenPriv->pwinBltExposedRegions = NULL;
480 pScreenPriv->pwinActivateApp = winActivateAppNativeGDI;
481 pScreenPriv->pwinRedrawScreen = winRedrawScreenNativeGDI;
482 pScreenPriv->pwinRealizeInstalledPalette =
483 winRealizeInstalledPaletteNativeGDI;
484 pScreenPriv->pwinInstallColormap = winInstallColormapNativeGDI;
485 pScreenPriv->pwinStoreColors = winStoreColorsNativeGDI;
486 pScreenPriv->pwinCreateColormap = winCreateColormapNativeGDI;
487 pScreenPriv->pwinDestroyColormap = winDestroyColormapNativeGDI;
488 pScreenPriv->pwinHotKeyAltTab =
489 (winHotKeyAltTabProcPtr) (void (*)(void)) NoopDDA;
490
491 return TRUE;
492}