First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xwin / winnativegdi.c
blob48a467a2c9f21f31bdc1dbaf6a6a9067f5613e56
1 /*
2 *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
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:
12 *The above copyright notice and this permission notice shall be
13 *included in all copies or substantial portions of the Software.
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.
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.
28 * Authors: Harold L Hunt II
31 #ifdef HAVE_XWIN_CONFIG_H
32 #include <xwin-config.h>
33 #endif
34 #include "win.h"
38 * External symbols
41 extern HWND g_hDlgExit;
45 * Local function prototypes
48 static Bool
49 winAllocateFBNativeGDI (ScreenPtr pScreen);
51 static void
52 winShadowUpdateNativeGDI (ScreenPtr pScreen,
53 shadowBufPtr pBuf);
55 static Bool
56 winCloseScreenNativeGDI (int nIndex, ScreenPtr pScreen);
58 static Bool
59 winInitVisualsNativeGDI (ScreenPtr pScreen);
61 static Bool
62 winAdjustVideoModeNativeGDI (ScreenPtr pScreen);
64 #if 0
65 static Bool
66 winBltExposedRegionsNativeGDI (ScreenPtr pScreen);
67 #endif
69 static Bool
70 winActivateAppNativeGDI (ScreenPtr pScreen);
72 static Bool
73 winRedrawScreenNativeGDI (ScreenPtr pScreen);
75 static Bool
76 winRealizeInstalledPaletteNativeGDI (ScreenPtr pScreen);
78 static Bool
79 winInstallColormapNativeGDI (ColormapPtr pColormap);
81 static Bool
82 winStoreColorsNativeGDI (ColormapPtr pmap,
83 int ndef,
84 xColorItem *pdefs);
86 static Bool
87 winCreateColormapNativeGDI (ColormapPtr pColormap);
89 static Bool
90 winDestroyColormapNativeGDI (ColormapPtr pColormap);
94 static Bool
95 winAllocateFBNativeGDI (ScreenPtr pScreen)
97 FatalError ("winAllocateFBNativeGDI\n");
99 return TRUE;
104 * We wrap whatever CloseScreen procedure was specified by fb;
105 * a pointer to said procedure is stored in our privates.
108 static Bool
109 winCloseScreenNativeGDI (int nIndex, ScreenPtr pScreen)
111 winScreenPriv(pScreen);
112 winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
114 ErrorF ("winCloseScreenNativeGDI - Freeing screen resources\n");
116 /* Flag that the screen is closed */
117 pScreenPriv->fClosed = TRUE;
118 pScreenPriv->fActive = FALSE;
121 * NOTE: mi doesn't use a CloseScreen procedure, so we do not
122 * need to call a wrapped procedure here.
125 /* Delete the window property */
126 RemoveProp (pScreenPriv->hwndScreen, WIN_SCR_PROP);
128 ErrorF ("winCloseScreenNativeGDI - Destroying window\n");
130 /* Delete tray icon, if we have one */
131 if (!pScreenInfo->fNoTrayIcon)
132 winDeleteNotifyIcon (pScreenPriv);
134 /* Free the exit confirmation dialog box, if it exists */
135 if (g_hDlgExit != NULL)
137 DestroyWindow (g_hDlgExit);
138 g_hDlgExit = NULL;
141 /* Kill our window */
142 if (pScreenPriv->hwndScreen)
144 DestroyWindow (pScreenPriv->hwndScreen);
145 pScreenPriv->hwndScreen = NULL;
148 /* Invalidate our screeninfo's pointer to the screen */
149 pScreenInfo->pScreen = NULL;
151 /* Free the screen privates for this screen */
152 free (pScreenPriv);
154 ErrorF ("winCloseScreenNativeGDI - Returning\n");
156 return TRUE;
160 static void
161 winShadowUpdateNativeGDI (ScreenPtr pScreen,
162 shadowBufPtr pBuf)
164 FatalError ("winShadowUpdateNativeGDI\n");
165 return;
169 static Bool
170 winInitVisualsNativeGDI (ScreenPtr pScreen)
172 winScreenPriv(pScreen);
173 winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
175 /* Set the bitsPerRGB and bit masks */
176 switch (pScreenInfo->dwDepth)
178 case 24:
179 pScreenPriv->dwBitsPerRGB = 8;
180 pScreenPriv->dwRedMask = 0x00FF0000;
181 pScreenPriv->dwGreenMask = 0x0000FF00;
182 pScreenPriv->dwBlueMask = 0x000000FF;
183 break;
185 case 16:
186 pScreenPriv->dwBitsPerRGB = 6;
187 pScreenPriv->dwRedMask = 0xF800;
188 pScreenPriv->dwGreenMask = 0x07E0;
189 pScreenPriv->dwBlueMask = 0x001F;
190 break;
192 case 15:
193 pScreenPriv->dwBitsPerRGB = 5;
194 pScreenPriv->dwRedMask = 0x7C00;
195 pScreenPriv->dwGreenMask = 0x03E0;
196 pScreenPriv->dwBlueMask = 0x001F;
197 break;
199 case 8:
200 pScreenPriv->dwBitsPerRGB = 8;
201 pScreenPriv->dwRedMask = 0;
202 pScreenPriv->dwGreenMask = 0;
203 pScreenPriv->dwBlueMask = 0;
204 break;
206 default:
207 ErrorF ("winInitVisualsNativeGDI - Unknown screen depth\n");
208 return FALSE;
209 break;
212 /* Tell the user how many bits per RGB we are using */
213 ErrorF ("winInitVisualsNativeGDI - Using dwBitsPerRGB: %d\n",
214 (int) pScreenPriv->dwBitsPerRGB);
216 /* Create a single visual according to the Windows screen depth */
217 switch (pScreenInfo->dwDepth)
219 case 24:
220 case 16:
221 case 15:
222 if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth,
223 TrueColorMask,
224 pScreenPriv->dwBitsPerRGB,
225 TrueColor,
226 pScreenPriv->dwRedMask,
227 pScreenPriv->dwGreenMask,
228 pScreenPriv->dwBlueMask))
230 ErrorF ("winInitVisuals - miSetVisualTypesAndMasks failed\n");
231 return FALSE;
233 break;
235 case 8:
236 ErrorF ("winInitVisuals - Calling miSetVisualTypesAndMasks\n");
237 if (!miSetVisualTypesAndMasks (pScreenInfo->dwDepth,
238 StaticColorMask,
239 pScreenPriv->dwBitsPerRGB,
240 StaticColor,
241 pScreenPriv->dwRedMask,
242 pScreenPriv->dwGreenMask,
243 pScreenPriv->dwBlueMask))
245 ErrorF ("winInitVisuals - miSetVisualTypesAndMasks failed\n");
246 return FALSE;
248 break;
250 default:
251 ErrorF ("winInitVisualsNativeGDI - Unknown screen depth\n");
252 return FALSE;
255 #if 1
256 ErrorF ("winInitVisualsNativeGDI - Returning\n");
257 #endif
259 return TRUE;
263 /* Adjust the video mode */
264 static Bool
265 winAdjustVideoModeNativeGDI (ScreenPtr pScreen)
267 winScreenPriv(pScreen);
268 winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
269 HDC hdc = NULL;
270 DWORD dwBPP;
272 hdc = GetDC (NULL);
274 /* We're in serious trouble if we can't get a DC */
275 if (hdc == NULL)
277 ErrorF ("winAdjustVideoModeNativeGDI - GetDC () failed\n");
278 return FALSE;
281 /* Query GDI for current display depth */
282 dwBPP = GetDeviceCaps (hdc, BITSPIXEL);
283 pScreenInfo->dwDepth = GetDeviceCaps (hdc, PLANES);
285 switch (pScreenInfo->dwDepth) {
286 case 24:
287 case 16:
288 case 15:
289 case 8:
290 break;
291 default:
292 if (dwBPP == 32)
293 pScreenInfo->dwDepth = 24;
294 else
295 pScreenInfo->dwDepth = dwBPP;
296 break;
299 /* GDI cannot change the screen depth */
300 if (pScreenInfo->dwBPP == WIN_DEFAULT_BPP)
302 /* No -depth parameter passed, let the user know the depth being used */
303 ErrorF ("winAdjustVideoModeNativeGDI - Using Windows display "
304 "depth of %d bits per pixel, %d depth\n",
305 (int) dwBPP, (int) pScreenInfo->dwDepth);
307 /* Use GDI's depth */
308 pScreenInfo->dwBPP = dwBPP;
310 else if (dwBPP != pScreenInfo->dwBPP)
312 /* Warn user if GDI depth is different than -depth parameter */
313 ErrorF ("winAdjustVideoModeNativeGDI - Command line bpp: %d, "\
314 "using bpp: %d\n",
315 (int) pScreenInfo->dwBPP, (int) dwBPP);
317 /* We'll use GDI's depth */
318 pScreenInfo->dwBPP = dwBPP;
321 /* Release our DC */
322 ReleaseDC (NULL, hdc);
324 return TRUE;
328 static Bool
329 winActivateAppNativeGDI (ScreenPtr pScreen)
331 winScreenPriv(pScreen);
332 winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
335 * Are we active?
336 * Are we fullscreen?
338 if (pScreenPriv != NULL
339 && pScreenPriv->fActive
340 && pScreenInfo->fFullScreen)
343 * Activating, attempt to bring our window
344 * to the top of the display
346 ShowWindow (pScreenPriv->hwndScreen, SW_RESTORE);
350 * Are we inactive?
351 * Are we fullscreen?
353 if (pScreenPriv != NULL
354 && !pScreenPriv->fActive
355 && pScreenInfo->fFullScreen)
358 * Deactivating, stuff our window onto the
359 * task bar.
361 ShowWindow (pScreenPriv->hwndScreen, SW_MINIMIZE);
364 return TRUE;
368 HBITMAP
369 winCreateDIBNativeGDI (int iWidth, int iHeight, int iDepth,
370 BYTE **ppbBits, BITMAPINFO **ppbmi)
372 BITMAPINFOHEADER *pbmih = NULL;
373 HBITMAP hBitmap = NULL;
374 BITMAPINFO *pbmi = NULL;
376 /* Don't create an invalid bitmap */
377 if (iWidth == 0
378 || iHeight == 0
379 || iDepth == 0)
381 ErrorF ("\nwinCreateDIBNativeGDI - Invalid specs w %d h %d d %d\n\n",
382 iWidth, iHeight, iDepth);
383 return NULL;
386 /* Allocate bitmap info header */
387 pbmih = (BITMAPINFOHEADER*) malloc (sizeof (BITMAPINFOHEADER)
388 + 256 * sizeof (RGBQUAD));
389 if (pbmih == NULL)
391 ErrorF ("winCreateDIBNativeGDI - malloc () failed\n");
392 return FALSE;
394 ZeroMemory (pbmih, sizeof(BITMAPINFOHEADER) + 256 * sizeof (RGBQUAD));
396 /* Describe bitmap to be created */
397 pbmih->biSize = sizeof (BITMAPINFOHEADER);
398 pbmih->biWidth = iWidth;
399 pbmih->biHeight = -iHeight;
400 pbmih->biPlanes = 1;
401 pbmih->biBitCount = iDepth;
402 pbmih->biCompression = BI_RGB;
403 pbmih->biSizeImage = 0;
404 pbmih->biXPelsPerMeter = 0;
405 pbmih->biYPelsPerMeter = 0;
406 pbmih->biClrUsed = 0;
407 pbmih->biClrImportant = 0;
409 /* Setup color table for mono DIBs */
410 if (iDepth == 1)
412 pbmi = (BITMAPINFO*) pbmih;
413 pbmi->bmiColors[1].rgbBlue = 255;
414 pbmi->bmiColors[1].rgbGreen = 255;
415 pbmi->bmiColors[1].rgbRed = 255;
418 /* Create a DIB with a bit pointer */
419 hBitmap = CreateDIBSection (NULL,
420 (BITMAPINFO *) pbmih,
421 DIB_RGB_COLORS,
422 (void **) ppbBits,
423 NULL,
425 if (hBitmap == NULL)
427 ErrorF ("winCreateDIBNativeGDI - CreateDIBSection () failed\n");
428 return NULL;
431 /* Free the bitmap info header memory */
432 if (ppbmi != NULL)
434 /* Store the address of the BMIH in the ppbmih parameter */
435 *ppbmi = (BITMAPINFO *) pbmih;
437 else
439 free (pbmih);
440 pbmih = NULL;
443 return hBitmap;
447 #if 0
448 static Bool
449 winBltExposedRegionsNativeGDI (ScreenPtr pScreen)
452 return TRUE;
454 #endif
457 static Bool
458 winRedrawScreenNativeGDI (ScreenPtr pScreen)
460 FatalError ("winRedrawScreenNativeGDI\n");
461 return TRUE;
465 static Bool
466 winRealizeInstalledPaletteNativeGDI (ScreenPtr pScreen)
468 FatalError ("winRealizeInstalledPaletteNativeGDI\n");
469 return TRUE;
473 static Bool
474 winInstallColormapNativeGDI (ColormapPtr pColormap)
476 FatalError ("winInstallColormapNativeGDI\n");
477 return TRUE;
481 static Bool
482 winStoreColorsNativeGDI (ColormapPtr pmap,
483 int ndef,
484 xColorItem *pdefs)
486 FatalError ("winStoreColorsNativeGDI\n");
487 return TRUE;
491 static Bool
492 winCreateColormapNativeGDI (ColormapPtr pColormap)
494 FatalError ("winCreateColormapNativeGDI\n");
495 return TRUE;
499 static Bool
500 winDestroyColormapNativeGDI (ColormapPtr pColormap)
502 FatalError ("winDestroyColormapNativeGDI\n");
503 return TRUE;
507 /* Set engine specific funtions */
508 Bool
509 winSetEngineFunctionsNativeGDI (ScreenPtr pScreen)
511 winScreenPriv(pScreen);
512 winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
514 /* Set our pointers */
515 pScreenPriv->pwinAllocateFB = winAllocateFBNativeGDI;
516 pScreenPriv->pwinShadowUpdate = winShadowUpdateNativeGDI;
517 pScreenPriv->pwinCloseScreen = winCloseScreenNativeGDI;
518 pScreenPriv->pwinInitVisuals = winInitVisualsNativeGDI;
519 pScreenPriv->pwinAdjustVideoMode = winAdjustVideoModeNativeGDI;
520 if (pScreenInfo->fFullScreen)
521 pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowFullScreen;
522 else
523 pScreenPriv->pwinCreateBoundingWindow = winCreateBoundingWindowWindowed;
524 pScreenPriv->pwinFinishScreenInit = winFinishScreenInitNativeGDI;
526 * WARNING: Do not set the BltExposedRegions procedure pointer to anything
527 * other than NULL until a working painting procedure is in place.
528 * Else, winWindowProc will get stuck in an infinite loop because
529 * Windows expects the BeginPaint and EndPaint functions to be called
530 * before a WM_PAINT message can be removed from the queue. We are
531 * using NULL here as a signal for winWindowProc that it should
532 * not signal that the WM_PAINT message has been processed.
534 pScreenPriv->pwinBltExposedRegions = NULL;
535 pScreenPriv->pwinActivateApp = winActivateAppNativeGDI;
536 pScreenPriv->pwinRedrawScreen = winRedrawScreenNativeGDI;
537 pScreenPriv->pwinRealizeInstalledPalette =
538 winRealizeInstalledPaletteNativeGDI;
539 pScreenPriv->pwinInstallColormap = winInstallColormapNativeGDI;
540 pScreenPriv->pwinStoreColors = winStoreColorsNativeGDI;
541 pScreenPriv->pwinCreateColormap = winCreateColormapNativeGDI;
542 pScreenPriv->pwinDestroyColormap = winDestroyColormapNativeGDI;
543 pScreenPriv->pwinHotKeyAltTab = (winHotKeyAltTabProcPtr) (void (*)(void))NoopDDA;
545 return TRUE;