ReactOS 0.4.15-dev-8390-g075894b
ddraw_main.c File Reference
#include "rosdraw.h"
#include <string.h>
Include dependency graph for ddraw_main.c:

Go to the source code of this file.

Functions

LPDDRAWI_DIRECTDRAW_INT internal_directdraw_int_alloc (LPDDRAWI_DIRECTDRAW_INT This)
 
HRESULT WINAPI Main_DirectDraw_QueryInterface (LPDDRAWI_DIRECTDRAW_INT This, REFIID id, LPVOID *obj)
 
ULONG WINAPI Main_DirectDraw_AddRef (LPDDRAWI_DIRECTDRAW_INT This)
 
ULONG WINAPI Main_DirectDraw_Release (LPDDRAWI_DIRECTDRAW_INT This)
 
HRESULT WINAPI Main_DirectDraw_Initialize (LPDDRAWI_DIRECTDRAW_INT This, LPGUID lpGUID)
 
HRESULT WINAPI Main_DirectDraw_Compact (LPDDRAWI_DIRECTDRAW_INT This)
 
HRESULT WINAPI Main_DirectDraw_GetAvailableVidMem (LPDDRAWI_DIRECTDRAW_INT This, LPDDSCAPS ddscaps, LPDWORD dwTotal, LPDWORD dwFree)
 
HRESULT WINAPI Main_DirectDraw_GetAvailableVidMem4 (LPDDRAWI_DIRECTDRAW_INT This, LPDDSCAPS2 ddscaps, LPDWORD dwTotal, LPDWORD dwFree)
 
HRESULT WINAPI Main_DirectDraw_GetFourCCCodes (LPDDRAWI_DIRECTDRAW_INT This, LPDWORD lpNumCodes, LPDWORD lpCodes)
 
HRESULT WINAPI Main_DirectDraw_CreateSurface (LPDDRAWI_DIRECTDRAW_INT This, LPDDSURFACEDESC pDDSD, LPDDRAWI_DDRAWSURFACE_INT *ppSurf, IUnknown *pUnkOuter)
 
HRESULT WINAPI Main_DirectDraw_CreateSurface4 (LPDDRAWI_DIRECTDRAW_INT This, LPDDSURFACEDESC2 pDDSD, LPDDRAWI_DDRAWSURFACE_INT *ppSurf, IUnknown *pUnkOuter)
 
HRESULT WINAPI Main_DirectDraw_CreatePalette (LPDDRAWI_DIRECTDRAW_INT This, DWORD dwFlags, LPPALETTEENTRY palent, LPDIRECTDRAWPALETTE *ppPalette, LPUNKNOWN pUnkOuter)
 

Function Documentation

◆ internal_directdraw_int_alloc()

LPDDRAWI_DIRECTDRAW_INT internal_directdraw_int_alloc ( LPDDRAWI_DIRECTDRAW_INT  This)

Definition at line 23 of file ddraw_main.c.

24{
26 DxHeapMemAlloc(newThis, sizeof(DDRAWI_DIRECTDRAW_INT));
27 if (newThis)
28 {
29 newThis->lpLcl = This->lpLcl;
30 newThis->lpLink = This;
31 }
32
33 return newThis;
34}
#define DxHeapMemAlloc(p, m)
Definition: rosdraw.h:113
LPDDRAWI_DIRECTDRAW_LCL lpLcl
Definition: ddrawi.h:1148
LPDDRAWI_DIRECTDRAW_INT lpLink
Definition: ddrawi.h:1149

Referenced by Main_DirectDraw_QueryInterface().

◆ Main_DirectDraw_AddRef()

ULONG WINAPI Main_DirectDraw_AddRef ( LPDDRAWI_DIRECTDRAW_INT  This)

Definition at line 145 of file ddraw_main.c.

146{
147 ULONG retValue = 0;
148
150
151 /* Lock the thread */
153
155 {
156 /* Increment the internal ref counter */
157 This->dwIntRefCnt++;
158
159 /* Increment the local internal ref counter */
160 This->lpLcl->dwLocalRefCnt++;
161
162 if (This->lpLcl->lpGbl != NULL)
163 {
164 /* Increment the global internal ref counter */
165 This->lpLcl->lpGbl->dwRefCnt++;
166 }
167 }
169 {
170 }
171 _SEH2_END;
172
174 {
175 retValue = This->dwIntRefCnt;
176 }
178 {
179 retValue = 0;
180 }
181 _SEH2_END;
182
183 /* Release the thread lock */
185
186 /* Return the local Ref counter */
187 return retValue;
188}
#define NULL
Definition: types.h:112
VOID WINAPI AcquireDDThreadLock()
Definition: main.c:412
VOID WINAPI ReleaseDDThreadLock()
Definition: main.c:421
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define DX_WINDBG_trace()
Definition: rosdraw.h:262
uint32_t ULONG
Definition: typedefs.h:59

Referenced by Create_DirectDraw(), Main_DirectDraw_CreatePalette(), Main_DirectDraw_CreateSurface4(), Main_DirectDraw_QueryInterface(), ThunkDirectDraw2_AddRef(), ThunkDirectDraw4_AddRef(), and ThunkDirectDraw_AddRef().

◆ Main_DirectDraw_Compact()

HRESULT WINAPI Main_DirectDraw_Compact ( LPDDRAWI_DIRECTDRAW_INT  This)

Definition at line 267 of file ddraw_main.c.

268{
269 HRESULT retVal = DD_OK;
270
272
273 /* Lock the thread */
275
277 {
278 /* Check if Exclusive mode has been activated */
279 if (This->lpLcl->lpGbl->lpExclusiveOwner != This->lpLcl)
280 {
281 retVal = DDERR_NOEXCLUSIVEMODE;
282 }
283 }
285 {
286 }
287 _SEH2_END;
288
289 /* Release the thread lock */
291
292 return retVal;
293}
#define DDERR_NOEXCLUSIVEMODE
Definition: ddraw.h:93
#define DD_OK
Definition: ddraw.h:186

Referenced by ThunkDirectDraw2_Compact(), ThunkDirectDraw4_Compact(), and ThunkDirectDraw_Compact().

◆ Main_DirectDraw_CreatePalette()

HRESULT WINAPI Main_DirectDraw_CreatePalette ( LPDDRAWI_DIRECTDRAW_INT  This,
DWORD  dwFlags,
LPPALETTEENTRY  palent,
LPDIRECTDRAWPALETTE ppPalette,
LPUNKNOWN  pUnkOuter 
)

Definition at line 545 of file ddraw_main.c.

547{
548 HRESULT ret = DD_OK;
550
552 *ppPalette = NULL;
553
555 {
556 ret = Internal_CreatePalette(This, dwFlags, palent, ppPalette, pUnkOuter);
557 }
559 {
561 }
562 _SEH2_END;
563
564 //Versions 7 and 4 are addref'ed
565 if((This->lpVtbl == &DirectDraw7_Vtable || This->lpVtbl == &DirectDraw4_Vtable) && *ppPalette != NULL)
567
569 return ret;
570}
HRESULT Internal_CreatePalette(LPDDRAWI_DIRECTDRAW_INT pDDraw, DWORD dwFlags, LPPALETTEENTRY palent, LPDIRECTDRAWPALETTE *ppPalette, LPUNKNOWN pUnkOuter)
Definition: createpalette.c:33
ULONG WINAPI Main_DirectDraw_AddRef(LPDDRAWI_DIRECTDRAW_INT This)
Definition: ddraw_main.c:145
CRITICAL_SECTION ddcs
Definition: main.c:14
IDirectDraw7Vtbl DirectDraw7_Vtable
IDirectDraw4Vtbl DirectDraw4_Vtable
Definition: ddraw_thunk.c:890
#define DDERR_INVALIDPARAMS
Definition: ddraw.h:79
int ret
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176

Referenced by ThunkDirectDraw2_CreatePalette(), ThunkDirectDraw4_CreatePalette(), and ThunkDirectDraw_CreatePalette().

◆ Main_DirectDraw_CreateSurface()

HRESULT WINAPI Main_DirectDraw_CreateSurface ( LPDDRAWI_DIRECTDRAW_INT  This,
LPDDSURFACEDESC  pDDSD,
LPDDRAWI_DDRAWSURFACE_INT ppSurf,
IUnknown pUnkOuter 
)

Definition at line 478 of file ddraw_main.c.

480{
482 DDSURFACEDESC2 dd_desc_v2;
483
485
487 *ppSurf = NULL;
488
490 {
491 if (pDDSD->dwSize == sizeof(DDSURFACEDESC))
492 {
493 CopyDDSurfDescToDDSurfDesc2(&dd_desc_v2, (LPDDSURFACEDESC)pDDSD);
495 &dd_desc_v2,
496 ppSurf,
497 pUnkOuter);
498 }
499 else
500 {
502 }
503 }
505 {
507 }
508 _SEH2_END;
510 return ret;
511}
void CopyDDSurfDescToDDSurfDesc2(LPDDSURFACEDESC2 dst_pDesc, LPDDSURFACEDESC src_pDesc)
HRESULT Internal_CreateSurface(LPDDRAWI_DIRECTDRAW_INT pDDraw, LPDDSURFACEDESC2 pDDSD, LPDDRAWI_DDRAWSURFACE_INT *ppSurf, IUnknown *pUnkOuter)
Definition: createsurface.c:18
#define DDERR_GENERIC
Definition: ddraw.h:72

Referenced by ThunkDirectDraw2_CreateSurface(), ThunkDirectDraw4_CreateSurface(), and ThunkDirectDraw_CreateSurface().

◆ Main_DirectDraw_CreateSurface4()

HRESULT WINAPI Main_DirectDraw_CreateSurface4 ( LPDDRAWI_DIRECTDRAW_INT  This,
LPDDSURFACEDESC2  pDDSD,
LPDDRAWI_DDRAWSURFACE_INT ppSurf,
IUnknown pUnkOuter 
)

Definition at line 516 of file ddraw_main.c.

518{
519 HRESULT ret = DD_OK;
521
523 *ppSurf = NULL;
524
526 {
527 ret = Internal_CreateSurface(This, pDDSD, ppSurf, pUnkOuter);
528 }
530 {
532 }
533 _SEH2_END;
534
535 if(*ppSurf != NULL)
537
539 return ret;
540}

◆ Main_DirectDraw_GetAvailableVidMem()

HRESULT WINAPI Main_DirectDraw_GetAvailableVidMem ( LPDDRAWI_DIRECTDRAW_INT  This,
LPDDSCAPS  ddscaps,
LPDWORD  dwTotal,
LPDWORD  dwFree 
)

Definition at line 296 of file ddraw_main.c.

297{
298 DDSCAPS2 myddscaps;
299 HRESULT retValue = DD_OK;
300
301 ZeroMemory(&myddscaps, sizeof(DDSCAPS2));
302
304 {
305 myddscaps.dwCaps = ddscaps->dwCaps;
306 retValue = Main_DirectDraw_GetAvailableVidMem4(This, &myddscaps, dwTotal, dwFree);
307 }
309 {
310 retValue = DDERR_INVALIDPARAMS;
311 }
312 _SEH2_END;
313
314 return retValue;
315}
HRESULT WINAPI Main_DirectDraw_GetAvailableVidMem4(LPDDRAWI_DIRECTDRAW_INT This, LPDDSCAPS2 ddscaps, LPDWORD dwTotal, LPDWORD dwFree)
Definition: ddraw_main.c:318
DWORD dwCaps
Definition: ddraw.h:732
DWORD dwCaps
Definition: ddraw.h:727
#define ZeroMemory
Definition: winbase.h:1712

◆ Main_DirectDraw_GetAvailableVidMem4()

HRESULT WINAPI Main_DirectDraw_GetAvailableVidMem4 ( LPDDRAWI_DIRECTDRAW_INT  This,
LPDDSCAPS2  ddscaps,
LPDWORD  dwTotal,
LPDWORD  dwFree 
)

Definition at line 318 of file ddraw_main.c.

320{
321 HRESULT retVal = DD_OK;
323
325
327 {
328 // There is no HEL implementation of this api
329 if (!(This->lpLcl->lpDDCB->HALDDMiscellaneous.dwFlags & DDHAL_MISCCB32_GETAVAILDRIVERMEMORY) ||
330 (This->lpLcl->lpGbl->dwFlags & DDRAWI_NOHARDWARE) )
331 {
332 retVal = DDERR_NODIRECTDRAWHW;
333 }
334 else
335 {
336 if ((!dwTotal && !dwFree) || !ddscaps)
337 {
338 retVal = DDERR_INVALIDPARAMS;
340 }
341
345 {
346 retVal = DDERR_INVALIDPARAMS;
348 }
349
350
351 /* ddscaps->dwCaps2 & 0x01
352 this flag is outdate and are
353 set to 0 in ms dxsdk the name of
354 this flag is DDSCAPS2_HARDWAREDEINTERLACE
355 */
356
357 if ( ddscaps->dwCaps2 & 0x01)
358 {
359 retVal = DDERR_INVALIDCAPS;
361 }
362
367 {
368 retVal = DDERR_INVALIDCAPS;
370 }
371
372 if ( ddscaps->dwCaps4)
373 {
374 retVal = DDERR_INVALIDCAPS;
376 }
377
379 memdata.lpDD = This->lpLcl->lpGbl;
380 memdata.ddRVal = DDERR_INVALIDPARAMS;
381
382 memdata.ddsCapsEx.dwCaps2 = ddscaps->dwCaps2;
383 memdata.ddsCapsEx.dwCaps3 = ddscaps->dwCaps3;
384
385 This->lpLcl->lpGbl->hDD = This->lpLcl->hDD;
386
387 if (This->lpLcl->lpDDCB->HALDDMiscellaneous.GetAvailDriverMemory(&memdata) == DDHAL_DRIVER_NOTHANDLED)
388 {
389 retVal = DDERR_NODIRECTDRAWHW;
390
391 if (dwTotal)
392 *dwTotal = 0;
393
394 if (dwFree)
395 *dwFree = 0;
396 }
397 else
398 {
399 if (dwTotal)
400 *dwTotal = memdata.dwTotal;
401
402 if (dwFree)
403 *dwFree = memdata.dwFree;
404
405 retVal = memdata.ddRVal;
406 }
407 }
408 }
410 {
411 }
412 _SEH2_END;
413
414 return retVal;
415}
#define DDRAWI_NOHARDWARE
Definition: ddrawi.h:1301
#define DDHAL_MISCCB32_GETAVAILDRIVERMEMORY
Definition: ddrawi.h:688
#define DDHAL_DRIVER_NOTHANDLED
Definition: ddrawi.h:320
#define _SEH2_LEAVE
Definition: filesup.c:20
#define DDSCAPS_FRONTBUFFER
Definition: ddraw.h:254
#define DDSCAPS3_AUTOGENMIPMAP
Definition: ddraw.h:326
#define DDSCAPS_VISIBLE
Definition: ddraw.h:265
#define DDSCAPS3_DMAP
Definition: ddraw.h:327
#define DDERR_INVALIDCAPS
Definition: ddraw.h:75
#define DDSCAPS_WRITEONLY
Definition: ddraw.h:266
#define DDSCAPS3_MULTISAMPLE_QUALITY_MASK
Definition: ddraw.h:321
#define DDSCAPS_PALETTE
Definition: ddraw.h:257
#define DDSCAPS3_RESERVED1
Definition: ddraw.h:323
#define DDSCAPS_FLIP
Definition: ddraw.h:253
#define DDSCAPS3_MULTISAMPLE_MASK
Definition: ddraw.h:320
#define DDSCAPS_BACKBUFFER
Definition: ddraw.h:251
#define DDSCAPS3_RESERVED2
Definition: ddraw.h:324
#define DDSCAPS_OWNDC
Definition: ddraw.h:268
#define DDERR_NODIRECTDRAWHW
Definition: ddraw.h:137
#define DDSCAPS_SYSTEMMEMORY
Definition: ddraw.h:261
#define DDSCAPS3_LIGHTWEIGHTMIPMAP
Definition: ddraw.h:325
#define DDSCAPS_COMPLEX
Definition: ddraw.h:252
LPDDRAWI_DIRECTDRAW_GBL lpDD
Definition: ddrawi.h:1754
DWORD dwCaps4
Definition: ddraw.h:737
DWORD dwCaps3
Definition: ddraw.h:734
DWORD dwCaps2
Definition: ddraw.h:733
DWORD dwCaps3
Definition: ddraw.h:1060
DWORD dwCaps2
Definition: ddraw.h:1059

Referenced by Main_DirectDraw_GetAvailableVidMem(), and Main_DirectDraw_GetCaps().

◆ Main_DirectDraw_GetFourCCCodes()

HRESULT WINAPI Main_DirectDraw_GetFourCCCodes ( LPDDRAWI_DIRECTDRAW_INT  This,
LPDWORD  lpNumCodes,
LPDWORD  lpCodes 
)

Definition at line 418 of file ddraw_main.c.

419{
420 HRESULT retVal = DD_OK;
421
423
424
425 // EnterCriticalSection(&ddcs);
426
428 {
429 if(IsBadWritePtr(lpNumCodes,sizeof(LPDWORD)))
430 {
431 retVal = DDERR_INVALIDPARAMS;
432 }
433 else
434 {
435 if(!(IsBadWritePtr(lpNumCodes,sizeof(LPDWORD))))
436 {
437 DWORD size;
438
439 if (*lpNumCodes > This->lpLcl->lpGbl->dwNumFourCC)
440 {
441 *lpNumCodes = This->lpLcl->lpGbl->dwNumFourCC;
442 }
443
444 size = *lpNumCodes * sizeof(DWORD);
445
446 if(!IsBadWritePtr(lpCodes, size ))
447 {
448 memcpy(lpCodes, This->lpLcl->lpGbl->lpdwFourCC, size );
449 }
450 else
451 {
452 *lpNumCodes = This->lpLcl->lpGbl->dwNumFourCC;
453 }
454 }
455 }
456 }
458 {
459 }
460 _SEH2_END;
461
462 //LeaveCriticalSection(&ddcs);
463 return retVal;
464}
BOOL NTAPI IsBadWritePtr(IN LPVOID lp, IN UINT_PTR ucb)
Definition: except.c:883
unsigned long DWORD
Definition: ntddk_ex.h:95
GLsizeiptr size
Definition: glext.h:5919
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define DWORD
Definition: nt_native.h:44
uint32_t * LPDWORD
Definition: typedefs.h:59

Referenced by ThunkDirectDraw2_GetFourCCCodes(), ThunkDirectDraw4_GetFourCCCodes(), and ThunkDirectDraw_GetFourCCCodes().

◆ Main_DirectDraw_Initialize()

HRESULT WINAPI Main_DirectDraw_Initialize ( LPDDRAWI_DIRECTDRAW_INT  This,
LPGUID  lpGUID 
)

Definition at line 247 of file ddraw_main.c.

248{
250}
#define DDERR_ALREADYINITIALIZED
Definition: ddraw.h:67

◆ Main_DirectDraw_QueryInterface()

HRESULT WINAPI Main_DirectDraw_QueryInterface ( LPDDRAWI_DIRECTDRAW_INT  This,
REFIID  id,
LPVOID obj 
)

Definition at line 37 of file ddraw_main.c.

40{
41 HRESULT retVal = DD_OK;
42
44
46 {
47 /* FIXME
48 the D3D object can be obtained from here
49 Direct3D7
50 */
51 if (IsEqualGUID(&IID_IDirectDraw7, id))
52 {
53 if (This->lpVtbl != &DirectDraw7_Vtable)
54 {
56 if (!This)
57 {
60 }
61 }
62
63 This->lpVtbl = &DirectDraw7_Vtable;
64 *obj = This;
66 }
67 else if (IsEqualGUID(&IID_IDirectDraw4, id))
68 {
69 if (This->lpVtbl != &DirectDraw4_Vtable)
70 {
72 if (!This)
73 {
76 }
77 }
78
79 This->lpVtbl = &DirectDraw4_Vtable;
80 *obj = This;
82 }
83
84 else if (IsEqualGUID(&IID_IDirectDraw2, id))
85 {
86 if (This->lpVtbl != &DirectDraw2_Vtable)
87 {
89 if (!This)
90 {
93 }
94 }
95
96 This->lpVtbl = &DirectDraw2_Vtable;
97 *obj = This;
99 }
100 else if (IsEqualGUID(&IID_IDirectDraw, id))
101 {
102 if (This->lpVtbl != &DirectDraw_Vtable)
103 {
105 if (!This)
106 {
107 retVal = DDERR_OUTOFVIDEOMEMORY;
109 }
110 }
111
112 This->lpVtbl = &DirectDraw_Vtable;
113 *obj = This;
115 }
116 else
117 {
118 *obj = NULL;
119 DX_STUB_str("E_NOINTERFACE");
120 retVal = E_NOINTERFACE;
121 }
122 }
124 {
125 }
126 _SEH2_END;
127
128 return retVal;
129}
LPDDRAWI_DIRECTDRAW_INT internal_directdraw_int_alloc(LPDDRAWI_DIRECTDRAW_INT This)
Definition: ddraw_main.c:23
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define DX_STUB_str(x)
Definition: rosdraw.h:254
IDirectDraw2Vtbl DirectDraw2_Vtable
Definition: ddraw_thunk.c:862
IDirectDrawVtbl DirectDraw_Vtable
Definition: ddraw_thunk.c:835
#define DDERR_OUTOFVIDEOMEMORY
Definition: ddraw.h:112
#define E_NOINTERFACE
Definition: winerror.h:2364

Referenced by ThunkDirectDraw2_QueryInterface(), ThunkDirectDraw4_QueryInterface(), and ThunkDirectDraw_QueryInterface().

◆ Main_DirectDraw_Release()

ULONG WINAPI Main_DirectDraw_Release ( LPDDRAWI_DIRECTDRAW_INT  This)

Definition at line 194 of file ddraw_main.c.

195{
196 ULONG Counter = 0;
197
199
200 /* Lock the thread */
202
204 {
205 if (This!=NULL)
206 {
207 This->lpLcl->dwLocalRefCnt--;
208 This->dwIntRefCnt--;
209
210 if (This->lpLcl->lpGbl != NULL)
211 {
212 This->lpLcl->lpGbl->dwRefCnt--;
213 }
214
215 if ( This->lpLcl->lpGbl->dwRefCnt == 0)
216 {
217 // set resolution back to the one in registry
218 /*if(This->cooperative_level & DDSCL_EXCLUSIVE)
219 {
220 ChangeDisplaySettings(NULL, 0);
221 }*/
222
223 Cleanup(This);
224 }
225
226 /* FIXME cleanup being not call why ?? */
227 Counter = This->dwIntRefCnt;
228 }
229 else
230 {
231 Counter = This->dwIntRefCnt;
232 }
233 }
235 {
236 }
237 _SEH2_END;
238
239 /* Release the thread lock */
241
242 return Counter;
243}
static const WCHAR Cleanup[]
Definition: register.c:80
static LARGE_INTEGER Counter
Definition: clock.c:43

Referenced by DirectDrawPalette_Release(), Main_DDrawSurface_Release4(), ThunkDirectDraw2_Release(), ThunkDirectDraw4_Release(), and ThunkDirectDraw_Release().