Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmain.c
Go to the documentation of this file.
00001 00002 /* $Id: main.c 37776 2008-11-30 19:28:11Z hyperion $ 00003 * 00004 * COPYRIGHT: See COPYING in the top level directory 00005 * PROJECT: ReactOS kernel 00006 * FILE: lib/ddraw/ddraw.c 00007 * PURPOSE: DirectDraw Library 00008 * PROGRAMMER: Magnus Olsen (greatlrd) 00009 * 00010 */ 00011 00012 00013 #include "rosdraw.h" 00014 HMODULE hDllModule = 0; 00015 00016 CRITICAL_SECTION ddcs; 00017 00018 // This function is exported by the dll 00019 00020 typedef struct 00021 { 00022 LPVOID lpCallback; 00023 LPVOID lpContext; 00024 } DirectDrawEnumerateProcData; 00025 00026 BOOL 00027 CALLBACK 00028 TranslateCallbackA(GUID *lpGUID, 00029 LPSTR lpDriverDescription, 00030 LPSTR lpDriverName, 00031 LPVOID lpContext, 00032 HMONITOR hm) 00033 { 00034 DirectDrawEnumerateProcData *pEPD = (DirectDrawEnumerateProcData*)lpContext; 00035 return ((LPDDENUMCALLBACKA) pEPD->lpCallback)(lpGUID, lpDriverDescription, lpDriverName, pEPD->lpContext); 00036 } 00037 00038 /*++ 00039 * @name DirectDrawCreateClipper 00040 * 00041 * The DirectDrawCreateClipper routine <FILLMEIN>. 00042 * 00043 * @param dwFlags 00044 * <FILLMEIN>. 00045 * 00046 * @param lplpDDClipper 00047 * <FILLMEIN>. 00048 * 00049 * @param pUnkOuter 00050 * <FILLMEIN>. 00051 * 00052 * @return <FILLMEIN>. 00053 * 00054 * @remarks None. 00055 * 00056 *--*/ 00057 HRESULT WINAPI DirectDrawCreateClipper (DWORD dwFlags, 00058 LPDIRECTDRAWCLIPPER* lplpDDClipper, LPUNKNOWN pUnkOuter) 00059 { 00060 DX_WINDBG_trace(); 00061 00062 return Main_DirectDraw_CreateClipper(NULL, dwFlags, lplpDDClipper, pUnkOuter); 00063 } 00064 00065 /*++ 00066 * @name DirectDrawCreate 00067 * 00068 * The DirectDrawCreate routine <FILLMEIN>. 00069 * 00070 * @param lpGUID 00071 * <FILLMEIN>. 00072 * 00073 * @param lplpDD 00074 * <FILLMEIN>. 00075 * 00076 * @param pUnkOuter 00077 * Always set to NULL otherwise DirectDrawCreate will fail and return 00078 * error code CLASS_E_NOAGGREGATION 00079 * 00080 * @return <FILLMEIN>. 00081 * 00082 * @remarks None. 00083 * 00084 *--*/ 00085 00086 HRESULT 00087 WINAPI 00088 DirectDrawCreate (LPGUID lpGUID, 00089 LPDIRECTDRAW* lplpDD, 00090 LPUNKNOWN pUnkOuter) 00091 { 00092 HRESULT retVal = DDERR_GENERIC; 00093 /* 00094 remove this when UML diagram is in place 00095 this api is finished and is working as it should 00096 */ 00097 00098 DX_WINDBG_trace(); 00099 _SEH2_TRY 00100 { 00101 /* check if pUnkOuter is null or not */ 00102 if (pUnkOuter) 00103 { 00104 retVal = CLASS_E_NOAGGREGATION; 00105 } 00106 else 00107 { 00108 retVal = Create_DirectDraw (lpGUID, (LPDIRECTDRAW*)lplpDD, &IID_IDirectDraw, FALSE); 00109 } 00110 } 00111 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) 00112 { 00113 } 00114 _SEH2_END; 00115 00116 return retVal; 00117 } 00118 00119 /*++ 00120 * @name DirectDrawCreateEx 00121 * 00122 * The DirectDrawCreateEx routine <FILLMEIN>. 00123 * 00124 * @param lpGUID 00125 * <FILLMEIN>. 00126 * 00127 * @param lplpDD 00128 * <FILLMEIN>. 00129 * 00130 * @param pUnkOuter 00131 * Always set to NULL otherwise DirectDrawCreateEx will fail and return 00132 * error code CLASS_E_NOAGGREGATION 00133 * 00134 * @return <FILLMEIN>. 00135 * 00136 * @remarks None. 00137 * 00138 *--*/ 00139 HRESULT 00140 WINAPI 00141 DirectDrawCreateEx(LPGUID lpGUID, 00142 LPVOID* lplpDD, 00143 REFIID id, 00144 LPUNKNOWN pUnkOuter) 00145 { 00146 HRESULT retVal = DDERR_GENERIC; 00147 /* 00148 remove this when UML diagram is in place 00149 this api is finished and is working as it should 00150 */ 00151 DX_WINDBG_trace(); 00152 00153 _SEH2_TRY 00154 { 00155 /* check see if pUnkOuter is null or not */ 00156 if (pUnkOuter) 00157 { 00158 /* we are using same error code as MS*/ 00159 retVal = CLASS_E_NOAGGREGATION; 00160 }/* Is it a DirectDraw 7 Request or not */ 00161 else if (!IsEqualGUID(id, &IID_IDirectDraw7)) 00162 { 00163 retVal = DDERR_INVALIDPARAMS; 00164 } 00165 else 00166 { 00167 retVal = Create_DirectDraw (lpGUID, (LPDIRECTDRAW*)lplpDD, id, FALSE); 00168 } 00169 00170 /* Create our DirectDraw interface */ 00171 } 00172 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) 00173 { 00174 } 00175 _SEH2_END; 00176 00177 return retVal; 00178 } 00179 00180 HRESULT 00181 WINAPI 00182 DirectDrawEnumerateA( LPDDENUMCALLBACKA lpCallback, 00183 LPVOID lpContext) 00184 { 00185 HRESULT retValue; 00186 DirectDrawEnumerateProcData epd; 00187 00188 DX_WINDBG_trace(); 00189 00190 epd.lpCallback = (LPVOID) lpCallback; 00191 epd.lpContext = lpContext; 00192 00193 if (!IsBadCodePtr((LPVOID)lpCallback)) 00194 { 00195 return DirectDrawEnumerateExA((LPDDENUMCALLBACKEXA)TranslateCallbackA, &epd, DDENUM_NONDISPLAYDEVICES); 00196 } 00197 else 00198 { 00199 retValue = DDERR_INVALIDPARAMS; 00200 } 00201 return retValue; 00202 } 00203 00204 /* 00205 * UNIMPLEMENT 00206 */ 00207 00208 HRESULT 00209 WINAPI 00210 DirectDrawEnumerateExA(LPDDENUMCALLBACKEXA lpCallback, 00211 LPVOID lpContext, 00212 DWORD dwFlags) 00213 { 00214 HKEY hKey; 00215 DWORD cbData = 0; 00216 DWORD Value = 0; 00217 LONG rc; 00218 BOOL EnumerateAttachedSecondaries = FALSE; 00219 DWORD privateDWFlags = 0; 00220 CHAR strMsg[RC_STRING_MAX_SIZE]; 00221 HRESULT retVal = DDERR_INVALIDPARAMS; 00222 00223 DX_WINDBG_trace(); 00224 00225 if ((IsBadCodePtr((LPVOID)lpCallback) == 0) && 00226 ((dwFlags & ~(DDENUM_NONDISPLAYDEVICES | 00227 DDENUM_DETACHEDSECONDARYDEVICES | 00228 DDENUM_ATTACHEDSECONDARYDEVICES)) == 0)) 00229 { 00230 LoadStringA(hDllModule, STR_PRIMARY_DISPLAY, (LPSTR)&strMsg, RC_STRING_MAX_SIZE); 00231 00232 rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, REGSTR_PATH_DDHW, &hKey); 00233 if (rc == ERROR_SUCCESS) 00234 { 00235 /* Enumerate Attached Secondaries */ 00236 cbData = sizeof(DWORD); 00237 rc = RegQueryValueExA(hKey, "EnumerateAttachedSecondaries", NULL, NULL, (LPBYTE)&Value, &cbData); 00238 if (rc == ERROR_SUCCESS) 00239 { 00240 if (Value != 0) 00241 { 00242 EnumerateAttachedSecondaries = TRUE; 00243 privateDWFlags = DDENUM_ATTACHEDSECONDARYDEVICES; 00244 } 00245 } 00246 RegCloseKey(hKey); 00247 } 00248 00249 /* Call the user supplied callback function */ 00250 rc = lpCallback(NULL, strMsg, "display", lpContext, NULL); 00251 00252 /* If the callback function returns DDENUMRET_CANCEL, we will stop enumerating devices */ 00253 if(rc == DDENUMRET_CANCEL) 00254 { 00255 retVal = DD_OK; 00256 } 00257 else 00258 { 00259 // not finished 00260 retVal = DDERR_UNSUPPORTED; 00261 } 00262 } 00263 00264 return retVal; 00265 } 00266 00267 HRESULT 00268 WINAPI 00269 DirectDrawEnumerateW(LPDDENUMCALLBACKW lpCallback, 00270 LPVOID lpContext) 00271 { 00272 DX_WINDBG_trace(); 00273 00274 return DDERR_UNSUPPORTED; 00275 } 00276 00277 HRESULT 00278 WINAPI 00279 DirectDrawEnumerateExW(LPDDENUMCALLBACKEXW lpCallback, 00280 LPVOID lpContext, 00281 DWORD dwFlags) 00282 { 00283 DX_WINDBG_trace(); 00284 00285 return DDERR_UNSUPPORTED; 00286 } 00287 00288 00289 00290 00291 /* 00292 See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ 00293 Display_d/hh/Display_d/d3d_21ac30ea-9803-401e-b541-6b08af79653d.xml.asp 00294 00295 for more info about this command see msdn documentation 00296 00297 The buffer start with D3DHAL_DP2COMMAND struct afer that follows either one struct or 00298 no struct at at all 00299 example for command D3DDP2OP_VIEWPORTINFO 00300 00301 then lpCmd will look like this 00302 ---------------------------------------- 00303 | struct | Pos | 00304 ---------------------------------------- 00305 | D3DHAL_DP2COMMAND | 0x00 - 0x03 | 00306 --------------------------------------- 00307 | D3DHAL_DP2VIEWPORTINFO | 0x04 - xxxx | 00308 --------------------------------------- 00309 00310 to calculate the end of the lpCmd buffer in this exmaple 00311 D3DHAL_DP2COMMAND->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO); 00312 now you got number of bytes but we need to add the size of D3DHAL_DP2COMMAND 00313 to get this right. the end should be 00314 sizeof(D3DHAL_DP2COMMAND) + ( D3DHAL_DP2COMMAND->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO)); 00315 to get the xxxx end positions. 00316 */ 00317 00318 /*++ 00319 * @name D3DParseUnknownCommand 00320 * 00321 * The D3DParseUnknownCommand routine <FILLMEIN>. 00322 * 00323 * @param lpCmd 00324 * Is a typcast to LPD3DHAL_DP2COMMAND struct 00325 * typedef struct _D3DHAL_DP2COMMAND 00326 * { 00327 * BYTE bCommand; 00328 * BYTE bReserved; 00329 * union 00330 * { 00331 * WORD wPrimitiveCount; 00332 * WORD wStateCount; 00333 * }; 00334 * } D3DHAL_DP2COMMAND, *LPD3DHAL_DP2COMMAND; 00335 * 00336 * lpCmd->bCommand 00337 * only accept D3DDP2OP_VIEWPORTINFO, and undocumented command 0x0D 00338 * anything else will result in an error 00339 * 00340 Command 0x0D 00341 * dp2command->bReserved 00342 * is the size of the struct we got in wStateCount or how many wStateCount we got 00343 * do not known more about it, no info in msdn about it either. 00344 * 00345 * Command D3DDP2OP_VIEWPORTINFO 00346 * <FILLMEIN>. 00347 * 00348 * @param lpRetCmd 00349 * <FILLMEIN>. 00350 * 00351 * @return <FILLMEIN>. 00352 * 00353 * @remarks 00354 00355 * 00356 *--*/ 00357 00358 HRESULT WINAPI 00359 D3DParseUnknownCommand( LPVOID lpCmd, 00360 LPVOID *lpRetCmd) 00361 { 00362 DWORD retCode = DD_OK; 00363 LPD3DHAL_DP2COMMAND dp2command = lpCmd; 00364 00365 DX_WINDBG_trace(); 00366 00367 /* prevent it crash if null pointer are being sent */ 00368 if ( (lpCmd == NULL) || (lpRetCmd == NULL) ) 00369 { 00370 return E_FAIL; 00371 } 00372 00373 *lpRetCmd = lpCmd; 00374 00375 switch (dp2command->bCommand) 00376 { 00377 /* check for vaild command, only 3 commands are vaild */ 00378 case D3DDP2OP_VIEWPORTINFO: 00379 *(PBYTE)lpRetCmd += ((dp2command->wStateCount * sizeof(D3DHAL_DP2VIEWPORTINFO)) + sizeof(D3DHAL_DP2COMMAND)); 00380 break; 00381 00382 case D3DDP2OP_WINFO: 00383 *(PBYTE)lpRetCmd += (dp2command->wStateCount * sizeof(D3DHAL_DP2WINFO)) + sizeof(D3DHAL_DP2COMMAND); 00384 break; 00385 00386 case 0x0d: /* Undocumented in MSDN */ 00387 *(PBYTE)lpRetCmd += ((dp2command->wStateCount * dp2command->bReserved) + sizeof(D3DHAL_DP2COMMAND)); 00388 break; 00389 00390 00391 /* set the error code */ 00392 default: 00393 00394 if ( (dp2command->bCommand <= D3DDP2OP_INDEXEDTRIANGLELIST) || // dp2command->bCommand <= with 0 to 3 00395 (dp2command->bCommand == D3DDP2OP_RENDERSTATE) || // dp2command->bCommand == with 8 00396 (dp2command->bCommand >= D3DDP2OP_LINELIST) ) // dp2command->bCommand >= with 15 to 255 00397 { 00398 /* set error code for command 0 to 3, 8 and 15 to 255 */ 00399 retCode = DDERR_INVALIDPARAMS; 00400 } 00401 else 00402 { /* set error code for 4 - 7, 9 - 12, 14 */ 00403 retCode = D3DERR_COMMAND_UNPARSED; 00404 } 00405 00406 } 00407 00408 return retCode; 00409 } 00410 00411 00412 VOID 00413 WINAPI 00414 AcquireDDThreadLock() 00415 { 00416 DX_WINDBG_trace(); 00417 00418 EnterCriticalSection(&ddcs); 00419 } 00420 00421 VOID 00422 WINAPI 00423 ReleaseDDThreadLock() 00424 { 00425 DX_WINDBG_trace(); 00426 00427 LeaveCriticalSection(&ddcs); 00428 } 00429 00430 00431 BOOL APIENTRY 00432 DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) 00433 { 00434 00435 hDllModule = hModule; 00436 00437 DX_WINDBG_trace(); 00438 00439 00440 switch(ul_reason_for_call) 00441 { 00442 case DLL_PROCESS_DETACH: 00443 DeleteCriticalSection( &ddcs ); 00444 break; 00445 00446 case DLL_PROCESS_ATTACH: 00447 DisableThreadLibraryCalls( hModule ); 00448 InitializeCriticalSection( &ddcs ); 00449 EnterCriticalSection( &ddcs ); 00450 LeaveCriticalSection( &ddcs ); 00451 break; 00452 00453 default: 00454 break; 00455 } 00456 00457 return TRUE; 00458 } Generated on Fri May 25 2012 04:15:02 for ReactOS by
1.7.6.1
|