1 /* 2 * COPYRIGHT: See COPYING in the top level directory 3 * PROJECT: ReactOS DirectX 4 * FILE: dll/directx/ddraw/Ddraw/GetCaps.c 5 * PURPOSE: IDirectDraw7 Implementation 6 * PROGRAMMER: Magnus Olsen 7 * 8 */ 9 10 /* TODO 11 * lpddNLVHELCaps and lpddNLVCaps 12 * Thouse two can be null or invalid in lpGBL 13 * we need add code in startup to detect if we have lpddNLVCaps set 14 * ms HEL does not support lpddNLVHELCaps shall we do that ? 15 * ms HEL does not support dwVidMemTotal and dwVidMemFree shall we implement a emulate of them ? 16 */ 17 18 #include "rosdraw.h" 19 20 #include <string.h> 21 22 HRESULT WINAPI 23 Main_DirectDraw_GetCaps( LPDDRAWI_DIRECTDRAW_INT This, LPDDCAPS pDriverCaps, 24 LPDDCAPS pHELCaps) 25 { 26 HRESULT retVal = DDERR_INVALIDPARAMS; 27 28 DX_WINDBG_trace(); 29 30 EnterCriticalSection( &ddcs ); 31 32 _SEH2_TRY 33 { 34 if ((!pDriverCaps) && (!pHELCaps)) 35 { 36 retVal = DDERR_INVALIDPARAMS; 37 _SEH2_LEAVE; 38 } 39 40 /* 41 * DDCAPS_DX6 and DDCAPS_DX7 have same size so 42 * we do not need check both only one of them 43 */ 44 if ( (pDriverCaps) && 45 (pDriverCaps->dwSize != sizeof(DDCAPS_DX1) ) && 46 (pDriverCaps->dwSize != sizeof(DDCAPS_DX3) ) && 47 (pDriverCaps->dwSize != sizeof(DDCAPS_DX5) ) && 48 (pDriverCaps->dwSize != sizeof(DDCAPS_DX7 )) ) 49 { 50 retVal = DDERR_INVALIDPARAMS; 51 _SEH2_LEAVE; 52 } 53 54 /* 55 * DDCAPS_DX6 and DDCAPS_DX7 have same size so 56 * we do not need check both only one of them 57 */ 58 if ( (pHELCaps) && 59 (pHELCaps->dwSize != sizeof(DDCAPS_DX1) ) && 60 (pHELCaps->dwSize != sizeof(DDCAPS_DX3) ) && 61 (pHELCaps->dwSize != sizeof(DDCAPS_DX5) ) && 62 (pHELCaps->dwSize != sizeof(DDCAPS_DX7 )) ) 63 { 64 retVal = DDERR_INVALIDPARAMS; 65 _SEH2_LEAVE; 66 } 67 68 if (pDriverCaps) 69 { 70 /* Setup hardware caps */ 71 DDSCAPS2 ddscaps = { 0 }; 72 LPDDCORECAPS CoreCaps = (LPDDCORECAPS)&This->lpLcl->lpGbl->ddCaps; 73 74 DWORD dwTotal = 0; 75 DWORD dwFree = 0; 76 77 Main_DirectDraw_GetAvailableVidMem4(This, &ddscaps, &dwTotal, &dwFree); 78 79 switch (pDriverCaps->dwSize) 80 { 81 case sizeof(DDCAPS_DX1): 82 { 83 LPDDCAPS_DX1 myCaps = (LPDDCAPS_DX1) pDriverCaps; 84 85 if (CoreCaps->dwSize == sizeof(DDCORECAPS)) 86 { 87 memcpy(myCaps, CoreCaps, sizeof(DDCAPS_DX1)); 88 } 89 90 myCaps->dwVidMemFree = dwFree; 91 myCaps->dwVidMemTotal = dwTotal; 92 myCaps->dwSize = sizeof(DDCAPS_DX1); 93 94 retVal = DD_OK; 95 } 96 break; 97 98 case sizeof(DDCAPS_DX3): 99 { 100 LPDDCAPS_DX3 myCaps = (LPDDCAPS_DX3) pDriverCaps; 101 102 if (CoreCaps->dwSize == sizeof(DDCORECAPS)) 103 { 104 memcpy(myCaps, CoreCaps, sizeof(DDCAPS_DX3)); 105 } 106 107 myCaps->dwVidMemFree = dwFree; 108 myCaps->dwVidMemTotal = dwTotal; 109 myCaps->dwSize = sizeof(DDCAPS_DX3); 110 111 retVal = DD_OK; 112 } 113 break; 114 115 case sizeof(DDCAPS_DX5): 116 { 117 LPDDCAPS_DX5 myCaps = (LPDDCAPS_DX5) pDriverCaps; 118 119 /* FIXME This->lpLcl->lpGbl->lpddNLVCaps are not set in startup.c 120 if (This->lpLcl->lpGbl->lpddNLVCaps->dwSize == sizeof(DDNONLOCALVIDMEMCAPS)) 121 { 122 memcpy(&myCaps->dwNLVBCaps, This->lpLcl->lpGbl->lpddNLVCaps, sizeof(DDNONLOCALVIDMEMCAPS)); 123 } 124 */ 125 memset(&myCaps->dwNLVBCaps,0,sizeof(DDNONLOCALVIDMEMCAPS)); 126 127 if (CoreCaps->dwSize == sizeof(DDCORECAPS)) 128 { 129 memcpy(myCaps, CoreCaps, sizeof(DDCORECAPS)); 130 } 131 132 myCaps->dwVidMemFree = dwFree; 133 myCaps->dwVidMemTotal = dwTotal; 134 myCaps->dwSize = sizeof(DDCAPS_DX5); 135 136 retVal = DD_OK; 137 } 138 break; 139 140 /* DDCAPS_DX6 is same as DDCAPS_DX7 */ 141 case sizeof(DDCAPS_DX7): 142 { 143 LPDDCAPS_DX7 myCaps = (LPDDCAPS_DX7) pDriverCaps; 144 145 /* FIXME This->lpLcl->lpGbl->lpddNLVCaps are not set in startup.c 146 if (This->lpLcl->lpGbl->lpddNLVCaps->dwSize == sizeof(DDNONLOCALVIDMEMCAPS)) 147 { 148 memcpy(&myCaps->dwNLVBCaps, This->lpLcl->lpGbl->lpddNLVCaps, sizeof(DDNONLOCALVIDMEMCAPS)); 149 } 150 */ 151 memset(&myCaps->dwNLVBCaps,0,sizeof(DDNONLOCALVIDMEMCAPS)); 152 153 if (CoreCaps->dwSize == sizeof(DDCORECAPS)) 154 { 155 memcpy(myCaps, CoreCaps, sizeof(DDCORECAPS)); 156 } 157 158 myCaps->dwVidMemFree = dwFree; 159 myCaps->dwVidMemTotal = dwTotal; 160 161 myCaps->ddsCaps.dwCaps = myCaps->ddsOldCaps.dwCaps; 162 myCaps->ddsCaps.dwCaps2 = 0; 163 myCaps->ddsCaps.dwCaps3 = 0; 164 myCaps->ddsCaps.dwCaps4 = 0; 165 myCaps->dwSize = sizeof(DDCAPS_DX7); 166 167 retVal = DD_OK; 168 169 } 170 break; 171 172 default: 173 retVal = DDERR_INVALIDPARAMS; 174 break; 175 } 176 } 177 178 if (pHELCaps) 179 { 180 /* Setup software caps */ 181 LPDDCORECAPS CoreCaps = (LPDDCORECAPS)&This->lpLcl->lpGbl->ddHELCaps; 182 183 DWORD dwTotal = 0; 184 DWORD dwFree = 0; 185 186 switch (pHELCaps->dwSize) 187 { 188 case sizeof(DDCAPS_DX1): 189 { 190 LPDDCAPS_DX1 myCaps = (LPDDCAPS_DX1) pHELCaps; 191 192 if (CoreCaps->dwSize == sizeof(DDCORECAPS)) 193 { 194 memcpy(myCaps, CoreCaps, sizeof(DDCAPS_DX1)); 195 } 196 197 myCaps->dwVidMemFree = dwFree; 198 myCaps->dwVidMemTotal = dwTotal; 199 myCaps->dwSize = sizeof(DDCAPS_DX1); 200 201 retVal = DD_OK; 202 } 203 break; 204 205 case sizeof(DDCAPS_DX3): 206 { 207 LPDDCAPS_DX3 myCaps = (LPDDCAPS_DX3) pHELCaps; 208 209 if (CoreCaps->dwSize == sizeof(DDCORECAPS)) 210 { 211 memcpy(myCaps, CoreCaps, sizeof(DDCAPS_DX3)); 212 } 213 214 myCaps->dwVidMemFree = dwFree; 215 myCaps->dwVidMemTotal = dwTotal; 216 myCaps->dwSize = sizeof(DDCAPS_DX3); 217 218 retVal = DD_OK; 219 } 220 break; 221 222 case sizeof(DDCAPS_DX5): 223 { 224 LPDDCAPS_DX5 myCaps = (LPDDCAPS_DX5) pHELCaps; 225 226 /* FIXME This->lpLcl->lpGbl->lpddNLVHELCaps are not set in startup.c 227 if (This->lpLcl->lpGbl->lpddNLVHELCaps->dwSize == sizeof(DDNONLOCALVIDMEMCAPS)) 228 { 229 memcpy(&myCaps->dwNLVBCaps, This->lpLcl->lpGbl->lpddNLVHELCaps, sizeof(DDNONLOCALVIDMEMCAPS)); 230 } 231 */ 232 memset(&myCaps->dwNLVBCaps,0,sizeof(DDNONLOCALVIDMEMCAPS)); 233 234 if (CoreCaps->dwSize == sizeof(DDCORECAPS)) 235 { 236 memcpy(myCaps, CoreCaps, sizeof(DDCORECAPS)); 237 } 238 239 myCaps->dwVidMemFree = dwFree; 240 myCaps->dwVidMemTotal = dwTotal; 241 myCaps->dwSize = sizeof(DDCAPS_DX5); 242 243 retVal = DD_OK; 244 } 245 break; 246 247 /* DDCAPS_DX6 is same as DDCAPS_DX7 */ 248 case sizeof(DDCAPS_DX7): 249 { 250 LPDDCAPS_DX7 myCaps = (LPDDCAPS_DX7) pHELCaps; 251 252 /* FIXME This->lpLcl->lpGbl->lpddNLVHELCaps are not set in startup.c 253 if (This->lpLcl->lpGbl->lpddNLVHELCaps->dwSize == sizeof(DDNONLOCALVIDMEMCAPS)) 254 { 255 memcpy(&myCaps->dwNLVBCaps, This->lpLcl->lpGbl->lpddNLVHELCaps, sizeof(DDNONLOCALVIDMEMCAPS)); 256 } 257 */ 258 memset(&myCaps->dwNLVBCaps,0,sizeof(DDNONLOCALVIDMEMCAPS)); 259 260 if (CoreCaps->dwSize == sizeof(DDCORECAPS)) 261 { 262 memcpy(myCaps, CoreCaps, sizeof(DDCORECAPS)); 263 } 264 265 myCaps->dwVidMemFree = dwFree; 266 myCaps->dwVidMemTotal = dwTotal; 267 268 myCaps->ddsCaps.dwCaps = myCaps->ddsOldCaps.dwCaps; 269 myCaps->ddsCaps.dwCaps2 = 0; 270 myCaps->ddsCaps.dwCaps3 = 0; 271 myCaps->ddsCaps.dwCaps4 = 0; 272 myCaps->dwSize = sizeof(DDCAPS_DX7); 273 274 retVal = DD_OK; 275 276 } 277 break; 278 279 default: 280 retVal = DDERR_INVALIDPARAMS; 281 break; 282 } 283 } 284 285 } 286 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) 287 { 288 retVal = DD_FALSE; 289 } 290 _SEH2_END; 291 292 LeaveCriticalSection( &ddcs ); 293 return retVal; 294 } 295 296