2 *Copyright (C) 2001-2004 Harold L Hunt II 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 HAROLD L HUNT II 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 Harold L Hunt II
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 Harold L Hunt II.
28 * Authors: Harold L Hunt II
31 #ifdef HAVE_XWIN_CONFIG_H
32 #include <xwin-config.h>
38 * Global variables for function pointers into
39 * dynamically loaded libraries
41 FARPROC g_fpDirectDrawCreate
= NULL
;
42 FARPROC g_fpDirectDrawCreateClipper
= NULL
;
45 module handle for dynamically loaded directdraw library
47 static HMODULE g_hmodDirectDraw
= NULL
;
50 * Detect engines supported by current Windows version
51 * DirectDraw version and hardware
55 winDetectSupportedEngines(void)
59 /* Initialize the engine support flags */
60 g_dwEnginesSupported
= WIN_SERVER_SHADOW_GDI
;
63 g_dwEnginesSupported
|= WIN_SERVER_NATIVE_GDI
;
66 /* Get operating system version information */
67 ZeroMemory(&osvi
, sizeof(osvi
));
68 osvi
.dwOSVersionInfoSize
= sizeof(osvi
);
71 /* Do we have DirectDraw? */
72 if (g_hmodDirectDraw
!= NULL
) {
73 LPDIRECTDRAW lpdd
= NULL
;
74 LPDIRECTDRAW4 lpdd4
= NULL
;
77 /* Was the DirectDrawCreate function found? */
78 if (g_fpDirectDrawCreate
== NULL
) {
79 /* No DirectDraw support */
83 /* DirectDrawCreate exists, try to call it */
84 /* Create a DirectDraw object, store the address at lpdd */
85 ddrval
= (*g_fpDirectDrawCreate
) (NULL
, (void **) &lpdd
, NULL
);
87 /* No DirectDraw support */
89 "winDetectSupportedEngines - DirectDraw not installed\n");
93 /* We have DirectDraw */
95 "winDetectSupportedEngines - DirectDraw installed, allowing ShadowDD\n");
96 g_dwEnginesSupported
|= WIN_SERVER_SHADOW_DD
;
99 /* Allow PrimaryDD engine if NT */
100 if (osvi
.dwPlatformId
== VER_PLATFORM_WIN32_NT
) {
101 g_dwEnginesSupported
|= WIN_SERVER_PRIMARY_DD
;
103 "winDetectSupportedEngines - Windows NT, allowing PrimaryDD\n");
108 /* Try to query for DirectDraw4 interface */
109 ddrval
= IDirectDraw_QueryInterface(lpdd
,
112 if (SUCCEEDED(ddrval
)) {
113 /* We have DirectDraw4 */
115 "winDetectSupportedEngines - DirectDraw4 installed, allowing ShadowDDNL\n");
116 g_dwEnginesSupported
|= WIN_SERVER_SHADOW_DDNL
;
119 /* Cleanup DirectDraw interfaces */
121 IDirectDraw_Release(lpdd4
);
123 IDirectDraw_Release(lpdd
);
127 "winDetectSupportedEngines - Returning, supported engines %08x\n",
128 (unsigned int) g_dwEnginesSupported
);
132 * Set the engine type, depending on the engines
133 * supported for this screen, and whether the user
134 * suggested an engine type
138 winSetEngine(ScreenPtr pScreen
)
140 winScreenPriv(pScreen
);
141 winScreenInfo
*pScreenInfo
= pScreenPriv
->pScreenInfo
;
148 ErrorF("winSetEngine - Couldn't get an HDC\n");
153 * pScreenInfo->dwBPP may be 0 to indicate that the current screen
154 * depth is to be used. Thus, we must query for the current display
157 dwBPP
= GetDeviceCaps(hdc
, BITSPIXEL
);
160 ReleaseDC(NULL
, hdc
);
163 /* ShadowGDI is the only engine that supports windowed PseudoColor */
164 if (dwBPP
== 8 && !pScreenInfo
->fFullScreen
) {
166 "winSetEngine - Windowed && PseudoColor => ShadowGDI\n");
167 pScreenInfo
->dwEngine
= WIN_SERVER_SHADOW_GDI
;
169 /* Set engine function pointers */
170 winSetEngineFunctionsShadowGDI(pScreen
);
174 /* ShadowGDI is the only engine that supports Multi Window Mode */
176 #ifdef XWIN_MULTIWINDOWEXTWM
177 || pScreenInfo
->fMWExtWM
179 #ifdef XWIN_MULTIWINDOW
180 || pScreenInfo
->fMultiWindow
184 "winSetEngine - Multi Window or Rootless => ShadowGDI\n");
185 pScreenInfo
->dwEngine
= WIN_SERVER_SHADOW_GDI
;
187 /* Set engine function pointers */
188 winSetEngineFunctionsShadowGDI(pScreen
);
192 /* If the user's choice is supported, we'll use that */
193 if (g_dwEnginesSupported
& pScreenInfo
->dwEnginePreferred
) {
194 winErrorFVerb(2, "winSetEngine - Using user's preference: %d\n",
195 (int) pScreenInfo
->dwEnginePreferred
);
196 pScreenInfo
->dwEngine
= pScreenInfo
->dwEnginePreferred
;
198 /* Setup engine function pointers */
199 switch (pScreenInfo
->dwEngine
) {
200 case WIN_SERVER_SHADOW_GDI
:
201 winSetEngineFunctionsShadowGDI(pScreen
);
203 case WIN_SERVER_SHADOW_DD
:
204 winSetEngineFunctionsShadowDD(pScreen
);
206 case WIN_SERVER_SHADOW_DDNL
:
207 winSetEngineFunctionsShadowDDNL(pScreen
);
209 #ifdef XWIN_PRIMARYFB
210 case WIN_SERVER_PRIMARY_DD
:
211 winSetEngineFunctionsPrimaryDD(pScreen
);
214 #ifdef XWIN_NATIVEGDI
215 case WIN_SERVER_NATIVE_GDI
:
216 winSetEngineFunctionsNativeGDI(pScreen
);
220 FatalError("winSetEngine - Invalid engine type\n");
225 /* ShadowDDNL has good performance, so why not */
226 if (g_dwEnginesSupported
& WIN_SERVER_SHADOW_DDNL
) {
227 winErrorFVerb(2, "winSetEngine - Using Shadow DirectDraw NonLocking\n");
228 pScreenInfo
->dwEngine
= WIN_SERVER_SHADOW_DDNL
;
230 /* Set engine function pointers */
231 winSetEngineFunctionsShadowDDNL(pScreen
);
235 /* ShadowDD is next in line */
236 if (g_dwEnginesSupported
& WIN_SERVER_SHADOW_DD
) {
237 winErrorFVerb(2, "winSetEngine - Using Shadow DirectDraw\n");
238 pScreenInfo
->dwEngine
= WIN_SERVER_SHADOW_DD
;
240 /* Set engine function pointers */
241 winSetEngineFunctionsShadowDD(pScreen
);
245 /* ShadowGDI is next in line */
246 if (g_dwEnginesSupported
& WIN_SERVER_SHADOW_GDI
) {
247 winErrorFVerb(2, "winSetEngine - Using Shadow GDI DIB\n");
248 pScreenInfo
->dwEngine
= WIN_SERVER_SHADOW_GDI
;
250 /* Set engine function pointers */
251 winSetEngineFunctionsShadowGDI(pScreen
);
259 * Get procedure addresses for DirectDrawCreate and DirectDrawCreateClipper
263 winGetDDProcAddresses(void)
267 /* Load the DirectDraw library */
268 g_hmodDirectDraw
= LoadLibraryEx("ddraw.dll", NULL
, 0);
269 if (g_hmodDirectDraw
== NULL
) {
270 ErrorF("winGetDDProcAddresses - Could not load ddraw.dll\n");
272 goto winGetDDProcAddresses_Exit
;
275 /* Try to get the DirectDrawCreate address */
276 g_fpDirectDrawCreate
= GetProcAddress(g_hmodDirectDraw
, "DirectDrawCreate");
277 if (g_fpDirectDrawCreate
== NULL
) {
278 ErrorF("winGetDDProcAddresses - Could not get DirectDrawCreate "
281 goto winGetDDProcAddresses_Exit
;
284 /* Try to get the DirectDrawCreateClipper address */
285 g_fpDirectDrawCreateClipper
= GetProcAddress(g_hmodDirectDraw
,
286 "DirectDrawCreateClipper");
287 if (g_fpDirectDrawCreateClipper
== NULL
) {
288 ErrorF("winGetDDProcAddresses - Could not get "
289 "DirectDrawCreateClipper address\n");
291 goto winGetDDProcAddresses_Exit
;
295 * Note: Do not unload ddraw.dll here. Do it in GiveUp
298 winGetDDProcAddresses_Exit
:
299 /* Unload the DirectDraw library if we failed to initialize */
300 if (!fReturn
&& g_hmodDirectDraw
!= NULL
) {
301 FreeLibrary(g_hmodDirectDraw
);
302 g_hmodDirectDraw
= NULL
;
309 winReleaseDDProcAddresses(void)
311 if (g_hmodDirectDraw
!= NULL
) {
312 FreeLibrary(g_hmodDirectDraw
);
313 g_hmodDirectDraw
= NULL
;
314 g_fpDirectDrawCreate
= NULL
;
315 g_fpDirectDrawCreateClipper
= NULL
;