2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: lib/ddraw/ddraw.c
5 * PURPOSE: DirectDraw Library
6 * PROGRAMMER: Magnus Olsen (greatlrd)
12 HMODULE hDllModule
= 0;
14 CRITICAL_SECTION ddcs
;
16 // This function is exported by the dll
22 } DirectDrawEnumerateProcData
;
26 TranslateCallbackA(GUID
*lpGUID
,
27 LPSTR lpDriverDescription
,
32 DirectDrawEnumerateProcData
*pEPD
= (DirectDrawEnumerateProcData
*)lpContext
;
33 return ((LPDDENUMCALLBACKA
) pEPD
->lpCallback
)(lpGUID
, lpDriverDescription
, lpDriverName
, pEPD
->lpContext
);
37 * @name DirectDrawCreateClipper
39 * The DirectDrawCreateClipper routine <FILLMEIN>.
44 * @param lplpDDClipper
55 HRESULT WINAPI
DirectDrawCreateClipper (DWORD dwFlags
,
56 LPDIRECTDRAWCLIPPER
* lplpDDClipper
, LPUNKNOWN pUnkOuter
)
60 return Main_DirectDraw_CreateClipper(NULL
, dwFlags
, lplpDDClipper
, pUnkOuter
);
64 * @name DirectDrawCreate
66 * The DirectDrawCreate routine <FILLMEIN>.
75 * Always set to NULL otherwise DirectDrawCreate will fail and return
76 * error code CLASS_E_NOAGGREGATION
86 DirectDrawCreate (LPGUID lpGUID
,
90 HRESULT retVal
= DDERR_GENERIC
;
92 remove this when UML diagram is in place
93 this api is finished and is working as it should
99 /* check if pUnkOuter is null or not */
102 retVal
= CLASS_E_NOAGGREGATION
;
106 retVal
= Create_DirectDraw (lpGUID
, (LPDIRECTDRAW
*)lplpDD
, &IID_IDirectDraw
, FALSE
);
109 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
118 * @name DirectDrawCreateEx
120 * The DirectDrawCreateEx routine <FILLMEIN>.
129 * Always set to NULL otherwise DirectDrawCreateEx will fail and return
130 * error code CLASS_E_NOAGGREGATION
132 * @return <FILLMEIN>.
139 DirectDrawCreateEx(LPGUID lpGUID
,
144 HRESULT retVal
= DDERR_GENERIC
;
146 remove this when UML diagram is in place
147 this api is finished and is working as it should
153 /* check see if pUnkOuter is null or not */
156 /* we are using same error code as MS*/
157 retVal
= CLASS_E_NOAGGREGATION
;
158 }/* Is it a DirectDraw 7 Request or not */
159 else if (!IsEqualGUID(id
, &IID_IDirectDraw7
))
161 retVal
= DDERR_INVALIDPARAMS
;
165 retVal
= Create_DirectDraw (lpGUID
, (LPDIRECTDRAW
*)lplpDD
, id
, FALSE
);
168 /* Create our DirectDraw interface */
170 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
180 DirectDrawEnumerateA( LPDDENUMCALLBACKA lpCallback
,
184 DirectDrawEnumerateProcData epd
;
188 epd
.lpCallback
= (LPVOID
) lpCallback
;
189 epd
.lpContext
= lpContext
;
191 if (!IsBadCodePtr((LPVOID
)lpCallback
))
193 return DirectDrawEnumerateExA((LPDDENUMCALLBACKEXA
)TranslateCallbackA
, &epd
, DDENUM_NONDISPLAYDEVICES
);
197 retValue
= DDERR_INVALIDPARAMS
;
208 DirectDrawEnumerateExA(LPDDENUMCALLBACKEXA lpCallback
,
216 BOOL EnumerateAttachedSecondaries
= FALSE
;
217 DWORD privateDWFlags
= 0;
218 CHAR strMsg
[RC_STRING_MAX_SIZE
];
219 HRESULT retVal
= DDERR_INVALIDPARAMS
;
223 if ((IsBadCodePtr((LPVOID
)lpCallback
) == 0) &&
224 ((dwFlags
& ~(DDENUM_NONDISPLAYDEVICES
|
225 DDENUM_DETACHEDSECONDARYDEVICES
|
226 DDENUM_ATTACHEDSECONDARYDEVICES
)) == 0))
228 LoadStringA(hDllModule
, STR_PRIMARY_DISPLAY
, (LPSTR
)&strMsg
, RC_STRING_MAX_SIZE
);
230 rc
= RegOpenKeyA(HKEY_LOCAL_MACHINE
, REGSTR_PATH_DDHW
, &hKey
);
231 if (rc
== ERROR_SUCCESS
)
233 /* Enumerate Attached Secondaries */
234 cbData
= sizeof(DWORD
);
235 rc
= RegQueryValueExA(hKey
, "EnumerateAttachedSecondaries", NULL
, NULL
, (LPBYTE
)&Value
, &cbData
);
236 if (rc
== ERROR_SUCCESS
)
240 EnumerateAttachedSecondaries
= TRUE
;
241 privateDWFlags
= DDENUM_ATTACHEDSECONDARYDEVICES
;
247 /* Call the user supplied callback function */
248 rc
= lpCallback(NULL
, strMsg
, "display", lpContext
, NULL
);
250 /* If the callback function returns DDENUMRET_CANCEL, we will stop enumerating devices */
251 if(rc
== DDENUMRET_CANCEL
)
258 retVal
= DDERR_UNSUPPORTED
;
267 DirectDrawEnumerateW(LPDDENUMCALLBACKW lpCallback
,
272 return DDERR_UNSUPPORTED
;
277 DirectDrawEnumerateExW(LPDDENUMCALLBACKEXW lpCallback
,
283 return DDERR_UNSUPPORTED
;
290 See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/
291 Display_d/hh/Display_d/d3d_21ac30ea-9803-401e-b541-6b08af79653d.xml.asp
293 for more info about this command see msdn documentation
295 The buffer start with D3DHAL_DP2COMMAND struct afer that follows either one struct or
297 example for command D3DDP2OP_VIEWPORTINFO
299 then lpCmd will look like this
300 ----------------------------------------
302 ----------------------------------------
303 | D3DHAL_DP2COMMAND | 0x00 - 0x03 |
304 ---------------------------------------
305 | D3DHAL_DP2VIEWPORTINFO | 0x04 - xxxx |
306 ---------------------------------------
308 to calculate the end of the lpCmd buffer in this exmaple
309 D3DHAL_DP2COMMAND->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO);
310 now you got number of bytes but we need to add the size of D3DHAL_DP2COMMAND
311 to get this right. the end should be
312 sizeof(D3DHAL_DP2COMMAND) + ( D3DHAL_DP2COMMAND->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO));
313 to get the xxxx end positions.
317 * @name D3DParseUnknownCommand
319 * The D3DParseUnknownCommand routine <FILLMEIN>.
322 * Is a typcast to LPD3DHAL_DP2COMMAND struct
323 * typedef struct _D3DHAL_DP2COMMAND
329 * WORD wPrimitiveCount;
332 * } D3DHAL_DP2COMMAND, *LPD3DHAL_DP2COMMAND;
335 * only accept D3DDP2OP_VIEWPORTINFO, and undocumented command 0x0D
336 * anything else will result in an error
339 * dp2command->bReserved
340 * is the size of the struct we got in wStateCount or how many wStateCount we got
341 * do not known more about it, no info in msdn about it either.
343 * Command D3DDP2OP_VIEWPORTINFO
349 * @return <FILLMEIN>.
357 D3DParseUnknownCommand( LPVOID lpCmd
,
360 DWORD retCode
= DD_OK
;
361 LPD3DHAL_DP2COMMAND dp2command
= lpCmd
;
365 /* prevent it crash if null pointer are being sent */
366 if ( (lpCmd
== NULL
) || (lpRetCmd
== NULL
) )
373 switch (dp2command
->bCommand
)
375 /* check for vaild command, only 3 commands are vaild */
376 case D3DDP2OP_VIEWPORTINFO
:
377 *(PBYTE
)lpRetCmd
+= ((dp2command
->wStateCount
* sizeof(D3DHAL_DP2VIEWPORTINFO
)) + sizeof(D3DHAL_DP2COMMAND
));
381 *(PBYTE
)lpRetCmd
+= (dp2command
->wStateCount
* sizeof(D3DHAL_DP2WINFO
)) + sizeof(D3DHAL_DP2COMMAND
);
384 case 0x0d: /* Undocumented in MSDN */
385 *(PBYTE
)lpRetCmd
+= ((dp2command
->wStateCount
* dp2command
->bReserved
) + sizeof(D3DHAL_DP2COMMAND
));
389 /* set the error code */
392 if ( (dp2command
->bCommand
<= D3DDP2OP_INDEXEDTRIANGLELIST
) || // dp2command->bCommand <= with 0 to 3
393 (dp2command
->bCommand
== D3DDP2OP_RENDERSTATE
) || // dp2command->bCommand == with 8
394 (dp2command
->bCommand
>= D3DDP2OP_LINELIST
) ) // dp2command->bCommand >= with 15 to 255
396 /* set error code for command 0 to 3, 8 and 15 to 255 */
397 retCode
= DDERR_INVALIDPARAMS
;
400 { /* set error code for 4 - 7, 9 - 12, 14 */
401 retCode
= D3DERR_COMMAND_UNPARSED
;
412 AcquireDDThreadLock()
416 EnterCriticalSection(&ddcs
);
421 ReleaseDDThreadLock()
425 LeaveCriticalSection(&ddcs
);
430 DllMain( HMODULE hModule
, DWORD ul_reason_for_call
, LPVOID lpReserved
)
433 hDllModule
= hModule
;
438 switch(ul_reason_for_call
)
440 case DLL_PROCESS_DETACH
:
441 DeleteCriticalSection( &ddcs
);
444 case DLL_PROCESS_ATTACH
:
445 DisableThreadLibraryCalls( hModule
);
446 InitializeCriticalSection( &ddcs
);
447 EnterCriticalSection( &ddcs
);
448 LeaveCriticalSection( &ddcs
);