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>
41 extern HWND g_hDlgExit
;
45 * Local function prototypes
49 winAllocateFBNativeGDI (ScreenPtr pScreen
);
52 winShadowUpdateNativeGDI (ScreenPtr pScreen
,
56 winCloseScreenNativeGDI (int nIndex
, ScreenPtr pScreen
);
59 winInitVisualsNativeGDI (ScreenPtr pScreen
);
62 winAdjustVideoModeNativeGDI (ScreenPtr pScreen
);
66 winBltExposedRegionsNativeGDI (ScreenPtr pScreen
);
70 winActivateAppNativeGDI (ScreenPtr pScreen
);
73 winRedrawScreenNativeGDI (ScreenPtr pScreen
);
76 winRealizeInstalledPaletteNativeGDI (ScreenPtr pScreen
);
79 winInstallColormapNativeGDI (ColormapPtr pColormap
);
82 winStoreColorsNativeGDI (ColormapPtr pmap
,
87 winCreateColormapNativeGDI (ColormapPtr pColormap
);
90 winDestroyColormapNativeGDI (ColormapPtr pColormap
);
95 winAllocateFBNativeGDI (ScreenPtr pScreen
)
97 FatalError ("winAllocateFBNativeGDI\n");
104 * We wrap whatever CloseScreen procedure was specified by fb;
105 * a pointer to said procedure is stored in our privates.
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
);
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 */
154 ErrorF ("winCloseScreenNativeGDI - Returning\n");
161 winShadowUpdateNativeGDI (ScreenPtr pScreen
,
164 FatalError ("winShadowUpdateNativeGDI\n");
170 winInitVisualsNativeGDI (ScreenPtr pScreen
)
172 winScreenPriv(pScreen
);
173 winScreenInfo
*pScreenInfo
= pScreenPriv
->pScreenInfo
;
175 /* Set the bitsPerRGB and bit masks */
176 switch (pScreenInfo
->dwDepth
)
179 pScreenPriv
->dwBitsPerRGB
= 8;
180 pScreenPriv
->dwRedMask
= 0x00FF0000;
181 pScreenPriv
->dwGreenMask
= 0x0000FF00;
182 pScreenPriv
->dwBlueMask
= 0x000000FF;
186 pScreenPriv
->dwBitsPerRGB
= 6;
187 pScreenPriv
->dwRedMask
= 0xF800;
188 pScreenPriv
->dwGreenMask
= 0x07E0;
189 pScreenPriv
->dwBlueMask
= 0x001F;
193 pScreenPriv
->dwBitsPerRGB
= 5;
194 pScreenPriv
->dwRedMask
= 0x7C00;
195 pScreenPriv
->dwGreenMask
= 0x03E0;
196 pScreenPriv
->dwBlueMask
= 0x001F;
200 pScreenPriv
->dwBitsPerRGB
= 8;
201 pScreenPriv
->dwRedMask
= 0;
202 pScreenPriv
->dwGreenMask
= 0;
203 pScreenPriv
->dwBlueMask
= 0;
207 ErrorF ("winInitVisualsNativeGDI - Unknown screen depth\n");
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
)
222 if (!miSetVisualTypesAndMasks (pScreenInfo
->dwDepth
,
224 pScreenPriv
->dwBitsPerRGB
,
226 pScreenPriv
->dwRedMask
,
227 pScreenPriv
->dwGreenMask
,
228 pScreenPriv
->dwBlueMask
))
230 ErrorF ("winInitVisuals - miSetVisualTypesAndMasks failed\n");
236 ErrorF ("winInitVisuals - Calling miSetVisualTypesAndMasks\n");
237 if (!miSetVisualTypesAndMasks (pScreenInfo
->dwDepth
,
239 pScreenPriv
->dwBitsPerRGB
,
241 pScreenPriv
->dwRedMask
,
242 pScreenPriv
->dwGreenMask
,
243 pScreenPriv
->dwBlueMask
))
245 ErrorF ("winInitVisuals - miSetVisualTypesAndMasks failed\n");
251 ErrorF ("winInitVisualsNativeGDI - Unknown screen depth\n");
256 ErrorF ("winInitVisualsNativeGDI - Returning\n");
263 /* Adjust the video mode */
265 winAdjustVideoModeNativeGDI (ScreenPtr pScreen
)
267 winScreenPriv(pScreen
);
268 winScreenInfo
*pScreenInfo
= pScreenPriv
->pScreenInfo
;
274 /* We're in serious trouble if we can't get a DC */
277 ErrorF ("winAdjustVideoModeNativeGDI - GetDC () failed\n");
281 /* Query GDI for current display depth */
282 dwBPP
= GetDeviceCaps (hdc
, BITSPIXEL
);
283 pScreenInfo
->dwDepth
= GetDeviceCaps (hdc
, PLANES
);
285 switch (pScreenInfo
->dwDepth
) {
293 pScreenInfo
->dwDepth
= 24;
295 pScreenInfo
->dwDepth
= dwBPP
;
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, "\
315 (int) pScreenInfo
->dwBPP
, (int) dwBPP
);
317 /* We'll use GDI's depth */
318 pScreenInfo
->dwBPP
= dwBPP
;
322 ReleaseDC (NULL
, hdc
);
329 winActivateAppNativeGDI (ScreenPtr pScreen
)
331 winScreenPriv(pScreen
);
332 winScreenInfo
*pScreenInfo
= pScreenPriv
->pScreenInfo
;
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
);
353 if (pScreenPriv
!= NULL
354 && !pScreenPriv
->fActive
355 && pScreenInfo
->fFullScreen
)
358 * Deactivating, stuff our window onto the
361 ShowWindow (pScreenPriv
->hwndScreen
, SW_MINIMIZE
);
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 */
381 ErrorF ("\nwinCreateDIBNativeGDI - Invalid specs w %d h %d d %d\n\n",
382 iWidth
, iHeight
, iDepth
);
386 /* Allocate bitmap info header */
387 pbmih
= (BITMAPINFOHEADER
*) malloc (sizeof (BITMAPINFOHEADER
)
388 + 256 * sizeof (RGBQUAD
));
391 ErrorF ("winCreateDIBNativeGDI - malloc () failed\n");
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
;
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 */
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
,
427 ErrorF ("winCreateDIBNativeGDI - CreateDIBSection () failed\n");
431 /* Free the bitmap info header memory */
434 /* Store the address of the BMIH in the ppbmih parameter */
435 *ppbmi
= (BITMAPINFO
*) pbmih
;
449 winBltExposedRegionsNativeGDI (ScreenPtr pScreen
)
458 winRedrawScreenNativeGDI (ScreenPtr pScreen
)
460 FatalError ("winRedrawScreenNativeGDI\n");
466 winRealizeInstalledPaletteNativeGDI (ScreenPtr pScreen
)
468 FatalError ("winRealizeInstalledPaletteNativeGDI\n");
474 winInstallColormapNativeGDI (ColormapPtr pColormap
)
476 FatalError ("winInstallColormapNativeGDI\n");
482 winStoreColorsNativeGDI (ColormapPtr pmap
,
486 FatalError ("winStoreColorsNativeGDI\n");
492 winCreateColormapNativeGDI (ColormapPtr pColormap
)
494 FatalError ("winCreateColormapNativeGDI\n");
500 winDestroyColormapNativeGDI (ColormapPtr pColormap
)
502 FatalError ("winDestroyColormapNativeGDI\n");
507 /* Set engine specific funtions */
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
;
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
;