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>
37 * Local function prototypes
41 winAllocateFBNativeGDI(ScreenPtr pScreen
);
44 winShadowUpdateNativeGDI(ScreenPtr pScreen
, shadowBufPtr pBuf
);
47 winCloseScreenNativeGDI(ScreenPtr pScreen
);
50 winInitVisualsNativeGDI(ScreenPtr pScreen
);
53 winAdjustVideoModeNativeGDI(ScreenPtr pScreen
);
57 winBltExposedRegionsNativeGDI(ScreenPtr pScreen
);
61 winActivateAppNativeGDI(ScreenPtr pScreen
);
64 winRedrawScreenNativeGDI(ScreenPtr pScreen
);
67 winRealizeInstalledPaletteNativeGDI(ScreenPtr pScreen
);
70 winInstallColormapNativeGDI(ColormapPtr pColormap
);
73 winStoreColorsNativeGDI(ColormapPtr pmap
, int ndef
, xColorItem
* pdefs
);
76 winCreateColormapNativeGDI(ColormapPtr pColormap
);
79 winDestroyColormapNativeGDI(ColormapPtr pColormap
);
82 winAllocateFBNativeGDI(ScreenPtr pScreen
)
84 FatalError("winAllocateFBNativeGDI\n");
90 winFreeFBNativeGDI(ScreenPtr pScreen
)
92 FatalError("winFreeFBNativeGDI\n");
96 winInitScreenNativeGDI(ScreenPtr pScreen
)
98 FatalError("winInitScreenNativeGDI\n");
102 * We wrap whatever CloseScreen procedure was specified by fb;
103 * a pointer to said procedure is stored in our privates.
107 winCloseScreenNativeGDI(ScreenPtr pScreen
)
109 winScreenPriv(pScreen
);
110 winScreenInfo
*pScreenInfo
= pScreenPriv
->pScreenInfo
;
112 ErrorF("winCloseScreenNativeGDI - Freeing screen resources\n");
114 /* Flag that the screen is closed */
115 pScreenPriv
->fClosed
= TRUE
;
116 pScreenPriv
->fActive
= FALSE
;
119 * NOTE: mi doesn't use a CloseScreen procedure, so we do not
120 * need to call a wrapped procedure here.
123 /* Delete the window property */
124 RemoveProp(pScreenPriv
->hwndScreen
, WIN_SCR_PROP
);
126 ErrorF("winCloseScreenNativeGDI - Destroying window\n");
128 /* Delete tray icon, if we have one */
129 if (!pScreenInfo
->fNoTrayIcon
)
130 winDeleteNotifyIcon(pScreenPriv
);
132 /* Free the exit confirmation dialog box, if it exists */
133 if (g_hDlgExit
!= NULL
) {
134 DestroyWindow(g_hDlgExit
);
138 /* Kill our window */
139 if (pScreenPriv
->hwndScreen
) {
140 DestroyWindow(pScreenPriv
->hwndScreen
);
141 pScreenPriv
->hwndScreen
= NULL
;
144 /* Invalidate our screeninfo's pointer to the screen */
145 pScreenInfo
->pScreen
= NULL
;
147 /* Free the screen privates for this screen */
150 ErrorF("winCloseScreenNativeGDI - Returning\n");
156 winShadowUpdateNativeGDI(ScreenPtr pScreen
, shadowBufPtr pBuf
)
158 FatalError("winShadowUpdateNativeGDI\n");
163 winInitVisualsNativeGDI(ScreenPtr pScreen
)
165 winScreenPriv(pScreen
);
166 winScreenInfo
*pScreenInfo
= pScreenPriv
->pScreenInfo
;
168 /* Set the bitsPerRGB and bit masks */
169 switch (pScreenInfo
->dwDepth
) {
171 pScreenPriv
->dwBitsPerRGB
= 8;
172 pScreenPriv
->dwRedMask
= 0x00FF0000;
173 pScreenPriv
->dwGreenMask
= 0x0000FF00;
174 pScreenPriv
->dwBlueMask
= 0x000000FF;
178 pScreenPriv
->dwBitsPerRGB
= 6;
179 pScreenPriv
->dwRedMask
= 0xF800;
180 pScreenPriv
->dwGreenMask
= 0x07E0;
181 pScreenPriv
->dwBlueMask
= 0x001F;
185 pScreenPriv
->dwBitsPerRGB
= 5;
186 pScreenPriv
->dwRedMask
= 0x7C00;
187 pScreenPriv
->dwGreenMask
= 0x03E0;
188 pScreenPriv
->dwBlueMask
= 0x001F;
192 pScreenPriv
->dwBitsPerRGB
= 8;
193 pScreenPriv
->dwRedMask
= 0;
194 pScreenPriv
->dwGreenMask
= 0;
195 pScreenPriv
->dwBlueMask
= 0;
199 ErrorF("winInitVisualsNativeGDI - Unknown screen depth\n");
204 /* Tell the user how many bits per RGB we are using */
205 ErrorF("winInitVisualsNativeGDI - Using dwBitsPerRGB: %d\n",
206 (int) pScreenPriv
->dwBitsPerRGB
);
208 /* Create a single visual according to the Windows screen depth */
209 switch (pScreenInfo
->dwDepth
) {
213 if (!miSetVisualTypesAndMasks(pScreenInfo
->dwDepth
,
215 pScreenPriv
->dwBitsPerRGB
,
217 pScreenPriv
->dwRedMask
,
218 pScreenPriv
->dwGreenMask
,
219 pScreenPriv
->dwBlueMask
)) {
220 ErrorF("winInitVisuals - miSetVisualTypesAndMasks failed\n");
226 ErrorF("winInitVisuals - Calling miSetVisualTypesAndMasks\n");
227 if (!miSetVisualTypesAndMasks(pScreenInfo
->dwDepth
,
229 pScreenPriv
->dwBitsPerRGB
,
231 pScreenPriv
->dwRedMask
,
232 pScreenPriv
->dwGreenMask
,
233 pScreenPriv
->dwBlueMask
)) {
234 ErrorF("winInitVisuals - miSetVisualTypesAndMasks failed\n");
240 ErrorF("winInitVisualsNativeGDI - Unknown screen depth\n");
245 ErrorF("winInitVisualsNativeGDI - Returning\n");
251 /* Adjust the video mode */
253 winAdjustVideoModeNativeGDI(ScreenPtr pScreen
)
255 winScreenPriv(pScreen
);
256 winScreenInfo
*pScreenInfo
= pScreenPriv
->pScreenInfo
;
262 /* We're in serious trouble if we can't get a DC */
264 ErrorF("winAdjustVideoModeNativeGDI - GetDC () failed\n");
268 /* Query GDI for current display depth */
269 dwBPP
= GetDeviceCaps(hdc
, BITSPIXEL
);
270 pScreenInfo
->dwDepth
= GetDeviceCaps(hdc
, PLANES
);
272 switch (pScreenInfo
->dwDepth
) {
280 pScreenInfo
->dwDepth
= 24;
282 pScreenInfo
->dwDepth
= dwBPP
;
286 /* GDI cannot change the screen depth, so we'll use GDI's depth */
287 pScreenInfo
->dwBPP
= dwBPP
;
290 ReleaseDC(NULL
, hdc
);
296 winActivateAppNativeGDI(ScreenPtr pScreen
)
298 winScreenPriv(pScreen
);
304 if (pScreenPriv
!= NULL
305 && pScreenPriv
->fActive
306 && pScreenPriv
->pScreenInfo
&& pScreenPriv
->pScreenInfo
->fFullScreen
) {
308 * Activating, attempt to bring our window
309 * to the top of the display
311 ShowWindow(pScreenPriv
->hwndScreen
, SW_RESTORE
);
318 if (pScreenPriv
!= NULL
319 && !pScreenPriv
->fActive
320 && pScreenPriv
->pScreenInfo
&& pScreenPriv
->pScreenInfo
->fFullScreen
) {
322 * Deactivating, stuff our window onto the
325 ShowWindow(pScreenPriv
->hwndScreen
, SW_MINIMIZE
);
332 winCreateDIBNativeGDI(int iWidth
, int iHeight
, int iDepth
,
333 BYTE
** ppbBits
, BITMAPINFO
** ppbmi
)
335 BITMAPINFOHEADER
*pbmih
= NULL
;
336 HBITMAP hBitmap
= NULL
;
337 BITMAPINFO
*pbmi
= NULL
;
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
);
346 /* Allocate bitmap info header */
347 pbmih
= (BITMAPINFOHEADER
*) malloc(sizeof(BITMAPINFOHEADER
)
348 + 256 * sizeof(RGBQUAD
));
350 ErrorF("winCreateDIBNativeGDI - malloc () failed\n");
353 ZeroMemory(pbmih
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
355 /* Describe bitmap to be created */
356 pbmih
->biSize
= sizeof(BITMAPINFOHEADER
);
357 pbmih
->biWidth
= iWidth
;
358 pbmih
->biHeight
= -iHeight
;
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;
368 /* Setup color table for mono DIBs */
370 pbmi
= (BITMAPINFO
*) pbmih
;
371 pbmi
->bmiColors
[1].rgbBlue
= 255;
372 pbmi
->bmiColors
[1].rgbGreen
= 255;
373 pbmi
->bmiColors
[1].rgbRed
= 255;
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");
385 /* Free the bitmap info header memory */
387 /* Store the address of the BMIH in the ppbmih parameter */
388 *ppbmi
= (BITMAPINFO
*) pbmih
;
400 winBltExposedRegionsNativeGDI(ScreenPtr pScreen
)
408 winRedrawScreenNativeGDI(ScreenPtr pScreen
)
410 FatalError("winRedrawScreenNativeGDI\n");
415 winRealizeInstalledPaletteNativeGDI(ScreenPtr pScreen
)
417 FatalError("winRealizeInstalledPaletteNativeGDI\n");
422 winInstallColormapNativeGDI(ColormapPtr pColormap
)
424 FatalError("winInstallColormapNativeGDI\n");
429 winStoreColorsNativeGDI(ColormapPtr pmap
, int ndef
, xColorItem
* pdefs
)
431 FatalError("winStoreColorsNativeGDI\n");
436 winCreateColormapNativeGDI(ColormapPtr pColormap
)
438 FatalError("winCreateColormapNativeGDI\n");
443 winDestroyColormapNativeGDI(ColormapPtr pColormap
)
445 FatalError("winDestroyColormapNativeGDI\n");
449 /* Set engine specific funtions */
451 winSetEngineFunctionsNativeGDI(ScreenPtr pScreen
)
453 winScreenPriv(pScreen
);
454 winScreenInfo
*pScreenInfo
= pScreenPriv
->pScreenInfo
;
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
;
468 pScreenPriv
->pwinCreateBoundingWindow
= winCreateBoundingWindowWindowed
;
469 pScreenPriv
->pwinFinishScreenInit
= winFinishScreenInitNativeGDI
;
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.
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
;