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