ReactOS  0.4.14-dev-49-gfb4591c
GetCaps.c
Go to the documentation of this file.
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 
24  LPDDCAPS pHELCaps)
25 {
27 
29 
31 
32  _SEH2_TRY
33  {
34  if ((!pDriverCaps) && (!pHELCaps))
35  {
36  retVal = DDERR_INVALIDPARAMS;
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;
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;
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  }
287  {
288  retVal = DD_FALSE;
289  }
290  _SEH2_END;
291 
293  return retVal;
294 }
295 
DWORD dwSize
Definition: ddrawi.h:251
#define DX_WINDBG_trace()
Definition: rosdraw.h:262
CRITICAL_SECTION ddcs
Definition: main.c:14
DWORD dwVidMemTotal
Definition: ddraw.h:975
struct _DDCORECAPS * LPDDCORECAPS
DWORD dwCaps2
Definition: ddraw.h:733
DWORD dwCaps
Definition: ddraw.h:727
struct _DDCAPS_DX1 * LPDDCAPS_DX1
struct _DDCAPS_DX3 DDCAPS_DX3
DWORD dwVidMemFree
Definition: ddraw.h:855
DWORD dwCaps4
Definition: ddraw.h:737
DWORD dwNLVBCaps
Definition: ddraw.h:1011
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
_SEH2_TRY
Definition: create.c:4250
struct _DDCAPS_DX5 DDCAPS_DX5
DDSCAPS2 ddsCaps
Definition: ddraw.h:1016
#define DD_OK
Definition: ddraw.h:186
HRESULT WINAPI Main_DirectDraw_GetCaps(LPDDRAWI_DIRECTDRAW_INT This, LPDDCAPS pDriverCaps, LPDDCAPS pHELCaps)
Definition: GetCaps.c:23
HRESULT WINAPI Main_DirectDraw_GetAvailableVidMem4(LPDDRAWI_DIRECTDRAW_INT This, LPDDSCAPS2 ddscaps, LPDWORD dwTotal, LPDWORD dwFree)
Definition: ddraw_main.c:318
struct _DDCAPS_DX7 DDCAPS_DX7
DDSCAPS ddsOldCaps
Definition: ddraw.h:986
DWORD dwNLVBCaps
Definition: ddraw.h:890
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
DWORD dwCaps
Definition: ddraw.h:732
switch(r->id)
Definition: btrfs.c:2932
DWORD dwVidMemTotal
Definition: ddraw.h:799
struct _DDCAPS_DX3 * LPDDCAPS_DX3
DWORD dwSize
Definition: ddraw.h:784
struct _DDCAPS_DX5 * LPDDCAPS_DX5
DWORD dwSize
Definition: ddraw.h:960
LONG HRESULT
Definition: typedefs.h:77
DWORD dwVidMemFree
Definition: ddraw.h:760
#define WINAPI
Definition: msvc.h:8
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD dwCaps3
Definition: ddraw.h:734
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
DWORD dwVidMemTotal
Definition: ddraw.h:759
DWORD dwSize
Definition: ddraw.h:744
#define DD_FALSE
Definition: ddraw.h:187
_SEH2_END
Definition: create.c:4424
DWORD dwSize
Definition: ddraw.h:839
DWORD dwVidMemFree
Definition: ddraw.h:976
DWORD dwVidMemTotal
Definition: ddraw.h:854
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define _SEH2_LEAVE
Definition: filesup.c:20
#define memset(x, y, z)
Definition: compat.h:39
struct _DDCAPS_DX7 * LPDDCAPS_DX7
struct _DDCAPS_DX1 DDCAPS_DX1
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79
DWORD dwVidMemFree
Definition: ddraw.h:800