4 * COPYRIGHT: See COPYING in the top level directory
5 * PROJECT: ReactOS kernel
6 * FILE: lib/ddraw/ddraw.c
7 * PURPOSE: DirectDraw Library
8 * PROGRAMMER: Magnus Olsen (greatlrd)
14 HMODULE hDllModule
= 0;
16 CRITICAL_SECTION ddcs
;
18 // This function is exported by the dll
24 } DirectDrawEnumerateProcData
;
28 TranslateCallbackA(GUID
*lpGUID
,
29 LPSTR lpDriverDescription
,
34 DirectDrawEnumerateProcData
*pEPD
= (DirectDrawEnumerateProcData
*)lpContext
;
35 return ((LPDDENUMCALLBACKA
) pEPD
->lpCallback
)(lpGUID
, lpDriverDescription
, lpDriverName
, pEPD
->lpContext
);
39 * @name DirectDrawCreateClipper
41 * The DirectDrawCreateClipper routine <FILLMEIN>.
46 * @param lplpDDClipper
57 HRESULT WINAPI
DirectDrawCreateClipper (DWORD dwFlags
,
58 LPDIRECTDRAWCLIPPER
* lplpDDClipper
, LPUNKNOWN pUnkOuter
)
62 return Main_DirectDraw_CreateClipper(NULL
, dwFlags
, lplpDDClipper
, pUnkOuter
);
66 * @name DirectDrawCreate
68 * The DirectDrawCreate routine <FILLMEIN>.
77 * Always set to NULL otherwise DirectDrawCreate will fail and return
78 * error code CLASS_E_NOAGGREGATION
88 DirectDrawCreate (LPGUID lpGUID
,
92 HRESULT retVal
= DDERR_GENERIC
;
94 remove this when UML diagram is in place
95 this api is finished and is working as it should
101 /* check if pUnkOuter is null or not */
104 retVal
= CLASS_E_NOAGGREGATION
;
108 retVal
= Create_DirectDraw (lpGUID
, (LPDIRECTDRAW
*)lplpDD
, &IID_IDirectDraw
, FALSE
);
111 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
120 * @name DirectDrawCreateEx
122 * The DirectDrawCreateEx routine <FILLMEIN>.
131 * Always set to NULL otherwise DirectDrawCreateEx will fail and return
132 * error code CLASS_E_NOAGGREGATION
134 * @return <FILLMEIN>.
141 DirectDrawCreateEx(LPGUID lpGUID
,
146 HRESULT retVal
= DDERR_GENERIC
;
148 remove this when UML diagram is in place
149 this api is finished and is working as it should
155 /* check see if pUnkOuter is null or not */
158 /* we are using same error code as MS*/
159 retVal
= CLASS_E_NOAGGREGATION
;
160 }/* Is it a DirectDraw 7 Request or not */
161 else if (!IsEqualGUID(id
, &IID_IDirectDraw7
))
163 retVal
= DDERR_INVALIDPARAMS
;
167 retVal
= Create_DirectDraw (lpGUID
, (LPDIRECTDRAW
*)lplpDD
, id
, FALSE
);
170 /* Create our DirectDraw interface */
172 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
182 DirectDrawEnumerateA( LPDDENUMCALLBACKA lpCallback
,
186 DirectDrawEnumerateProcData epd
;
190 epd
.lpCallback
= (LPVOID
) lpCallback
;
191 epd
.lpContext
= lpContext
;
193 if (!IsBadCodePtr((LPVOID
)lpCallback
))
195 return DirectDrawEnumerateExA((LPDDENUMCALLBACKEXA
)TranslateCallbackA
, &epd
, DDENUM_NONDISPLAYDEVICES
);
199 retValue
= DDERR_INVALIDPARAMS
;
210 DirectDrawEnumerateExA(LPDDENUMCALLBACKEXA lpCallback
,
218 BOOL EnumerateAttachedSecondaries
= FALSE
;
219 DWORD privateDWFlags
= 0;
220 CHAR strMsg
[RC_STRING_MAX_SIZE
];
221 HRESULT retVal
= DDERR_INVALIDPARAMS
;
225 if ((IsBadCodePtr((LPVOID
)lpCallback
) == 0) &&
226 ((dwFlags
& ~(DDENUM_NONDISPLAYDEVICES
|
227 DDENUM_DETACHEDSECONDARYDEVICES
|
228 DDENUM_ATTACHEDSECONDARYDEVICES
)) == 0))
230 LoadStringA(hDllModule
, STR_PRIMARY_DISPLAY
, (LPSTR
)&strMsg
, RC_STRING_MAX_SIZE
);
232 rc
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, REGSTR_PATH_DDHW
, &hKey
);
233 if (rc
== ERROR_SUCCESS
)
235 /* Enumerate Attached Secondaries */
236 cbData
= sizeof(DWORD
);
237 rc
= RegQueryValueExA(hKey
, "EnumerateAttachedSecondaries", NULL
, NULL
, (LPBYTE
)&Value
, &cbData
);
238 if (rc
== ERROR_SUCCESS
)
242 EnumerateAttachedSecondaries
= TRUE
;
243 privateDWFlags
= DDENUM_ATTACHEDSECONDARYDEVICES
;
249 /* Call the user supplied callback function */
250 rc
= lpCallback(NULL
, strMsg
, "display", lpContext
, NULL
);
252 /* If the callback function returns DDENUMRET_CANCEL, we will stop enumerating devices */
253 if(rc
== DDENUMRET_CANCEL
)
260 retVal
= DDERR_UNSUPPORTED
;
269 DirectDrawEnumerateW(LPDDENUMCALLBACKW lpCallback
,
274 return DDERR_UNSUPPORTED
;
279 DirectDrawEnumerateExW(LPDDENUMCALLBACKEXW lpCallback
,
285 return DDERR_UNSUPPORTED
;
292 See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/
293 Display_d/hh/Display_d/d3d_21ac30ea-9803-401e-b541-6b08af79653d.xml.asp
295 for more info about this command see msdn documentation
297 The buffer start with D3DHAL_DP2COMMAND struct afer that follows either one struct or
299 example for command D3DDP2OP_VIEWPORTINFO
301 then lpCmd will look like this
302 ----------------------------------------
304 ----------------------------------------
305 | D3DHAL_DP2COMMAND | 0x00 - 0x03 |
306 ---------------------------------------
307 | D3DHAL_DP2VIEWPORTINFO | 0x04 - xxxx |
308 ---------------------------------------
310 to calculate the end of the lpCmd buffer in this exmaple
311 D3DHAL_DP2COMMAND->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO);
312 now you got number of bytes but we need to add the size of D3DHAL_DP2COMMAND
313 to get this right. the end should be
314 sizeof(D3DHAL_DP2COMMAND) + ( D3DHAL_DP2COMMAND->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO));
315 to get the xxxx end positions.
319 * @name D3DParseUnknownCommand
321 * The D3DParseUnknownCommand routine <FILLMEIN>.
324 * Is a typcast to LPD3DHAL_DP2COMMAND struct
325 * typedef struct _D3DHAL_DP2COMMAND
331 * WORD wPrimitiveCount;
334 * } D3DHAL_DP2COMMAND, *LPD3DHAL_DP2COMMAND;
337 * only accept D3DDP2OP_VIEWPORTINFO, and undocumented command 0x0D
338 * anything else will result in an error
341 * dp2command->bReserved
342 * is the size of the struct we got in wStateCount or how many wStateCount we got
343 * do not known more about it, no info in msdn about it either.
345 * Command D3DDP2OP_VIEWPORTINFO
351 * @return <FILLMEIN>.
359 D3DParseUnknownCommand( LPVOID lpCmd
,
362 DWORD retCode
= DD_OK
;
363 LPD3DHAL_DP2COMMAND dp2command
= lpCmd
;
367 /* prevent it crash if null pointer are being sent */
368 if ( (lpCmd
== NULL
) || (lpRetCmd
== NULL
) )
375 switch (dp2command
->bCommand
)
377 /* check for vaild command, only 3 commands are vaild */
378 case D3DDP2OP_VIEWPORTINFO
:
379 *(PBYTE
)lpRetCmd
+= ((dp2command
->wStateCount
* sizeof(D3DHAL_DP2VIEWPORTINFO
)) + sizeof(D3DHAL_DP2COMMAND
));
383 *(PBYTE
)lpRetCmd
+= (dp2command
->wStateCount
* sizeof(D3DHAL_DP2WINFO
)) + sizeof(D3DHAL_DP2COMMAND
);
386 case 0x0d: /* Undocumented in MSDN */
387 *(PBYTE
)lpRetCmd
+= ((dp2command
->wStateCount
* dp2command
->bReserved
) + sizeof(D3DHAL_DP2COMMAND
));
391 /* set the error code */
394 if ( (dp2command
->bCommand
<= D3DDP2OP_INDEXEDTRIANGLELIST
) || // dp2command->bCommand <= with 0 to 3
395 (dp2command
->bCommand
== D3DDP2OP_RENDERSTATE
) || // dp2command->bCommand == with 8
396 (dp2command
->bCommand
>= D3DDP2OP_LINELIST
) ) // dp2command->bCommand >= with 15 to 255
398 /* set error code for command 0 to 3, 8 and 15 to 255 */
399 retCode
= DDERR_INVALIDPARAMS
;
402 { /* set error code for 4 - 7, 9 - 12, 14 */
403 retCode
= D3DERR_COMMAND_UNPARSED
;
414 AcquireDDThreadLock()
418 EnterCriticalSection(&ddcs
);
423 ReleaseDDThreadLock()
427 LeaveCriticalSection(&ddcs
);
432 DllMain( HMODULE hModule
, DWORD ul_reason_for_call
, LPVOID lpReserved
)
435 hDllModule
= hModule
;
440 switch(ul_reason_for_call
)
442 case DLL_PROCESS_DETACH
:
443 DeleteCriticalSection( &ddcs
);
446 case DLL_PROCESS_ATTACH
:
447 DisableThreadLibraryCalls( hModule
);
448 InitializeCriticalSection( &ddcs
);
449 EnterCriticalSection( &ddcs
);
450 LeaveCriticalSection( &ddcs
);