ReactOS  0.4.14-dev-358-gbef841c
d3d9_baseobject.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS ReactX
4  * FILE: dll/directx/d3d9/d3d9_baseobject.c
5  * PURPOSE: Direct3D9's base object
6  * PROGRAMERS: Gregor Gullwi <gbrunmar (dot) ros (at) gmail (dot) com>
7  */
8 #include "d3d9_baseobject.h"
9 #include "d3d9_device.h"
10 
11 #include <debug.h>
12 #include "d3d9_helpers.h"
13 
15 {
16  if (bFreeThis)
17  {
18  AlignedFree((LPVOID*) pBaseObject);
19  }
20 }
21 
23 {
24  /* D3D9BaseObject */
26 };
27 
29 {
30  pBaseObject->lpVtbl = &D3D9BaseObject_Vtbl;
31  pBaseObject->RefType = RefType;
32  pBaseObject->pUnknown = pUnknown;
33 }
34 
36 {
37  if (pBaseObject->pUnknown)
38  {
39  pBaseObject->pUnknown->lpVtbl->AddRef((IUnknown*) &pBaseObject->pUnknown->lpVtbl);
40  }
41 
42  return InterlockedIncrement(&pBaseObject->lRefCnt);
43 }
44 
46 {
47  ULONG Ref = 0;
48 
49  if (pBaseObject)
50  {
51  Ref = InterlockedDecrement(&pBaseObject->lRefCnt);
52 
53  if (Ref == 0)
54  {
55  if (pBaseObject->pUnknown)
56  {
57  pBaseObject->pUnknown->lpVtbl->Release((IUnknown*) &pBaseObject->pUnknown->lpVtbl);
58  }
59  }
60  }
61 
62  return Ref;
63 }
64 
65 HRESULT D3D9BaseObject_GetDevice(D3D9BaseObject* pBaseObject, IDirect3DDevice9** ppDevice)
66 {
67  if (pBaseObject->pUnknown)
68  {
69  return IUnknown_QueryInterface(pBaseObject->pUnknown, &IID_IDirect3DDevice9, (void**)ppDevice);
70  }
71 
72  return E_NOINTERFACE;
73 }
74 
76 {
77  if (NULL == ppDevice)
78  return D3DERR_INVALIDCALL;
79 
80  *ppDevice = NULL;
81 
82  if (pBaseObject->pUnknown)
83  {
84  LPDIRECT3DDEVICE9 pDevice;
85  if (FAILED(IUnknown_QueryInterface(pBaseObject->pUnknown, &IID_IDirect3DDevice9, (void**)&pDevice)))
86  return E_NOINTERFACE;
87 
88  *ppDevice = IDirect3DDevice9ToImpl(pDevice);
89  return D3D_OK;
90  }
91 
92  return E_NOINTERFACE;
93 }
94 
96 {
97  DIRECT3DDEVICE9_INT* pDevice;
98  if (FAILED(D3D9BaseObject_GetDeviceInt(pBaseObject, &pDevice)))
99  return;
100 
101  if (pDevice->bLockDevice)
103 }
104 
106 {
107  DIRECT3DDEVICE9_INT* pDevice;
108  if (FAILED(D3D9BaseObject_GetDeviceInt(pBaseObject, &pDevice)))
109  return;
110 
111  if (pDevice->bLockDevice)
113 }
ULONG D3D9BaseObject_AddRef(D3D9BaseObject *pBaseObject)
VOID AlignedFree(IN OUT LPVOID pObject)
Definition: d3d9_helpers.c:130
#define E_NOINTERFACE
Definition: winerror.h:2364
struct IDirect3DDevice9 * LPDIRECT3DDEVICE9
Definition: d3d9.h:130
ID3D9BaseObjectVtbl * lpVtbl
IUnknown * pUnknown
#define D3DERR_INVALIDCALL
ID3D9BaseObjectVtbl D3D9BaseObject_Vtbl
HRESULT D3D9BaseObject_GetDeviceInt(D3D9BaseObject *pBaseObject, DIRECT3DDEVICE9_INT **ppDevice)
ULONG D3D9BaseObject_Release(D3D9BaseObject *pBaseObject)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
VOID D3D9BaseObject_UnlockDevice(D3D9BaseObject *pBaseObject)
unsigned int BOOL
Definition: ntddk_ex.h:94
ULONG Release()
HRESULT D3D9BaseObject_GetDevice(D3D9BaseObject *pBaseObject, IDirect3DDevice9 **ppDevice)
smooth NULL
Definition: ftsmooth.c:416
_In_ PUNKNOWN pUnknown
Definition: drmk.h:76
LONG HRESULT
Definition: typedefs.h:77
LPDIRECT3DDEVICE9_INT IDirect3DDevice9ToImpl(LPDIRECT3DDEVICE9 iface)
Definition: d3d9_device.c:19
ULONG AddRef()
REF_TYPE
#define InterlockedDecrement
Definition: armddk.h:52
#define D3D_OK
Definition: d3d.h:106
#define InterlockedIncrement
Definition: armddk.h:53
VOID D3D9BaseObject_LockDevice(D3D9BaseObject *pBaseObject)
VOID D3D9BaseObject_Destroy(D3D9BaseObject *pBaseObject, BOOL bFreeThis)
CRITICAL_SECTION CriticalSection
Definition: d3d9_device.h:89
VOID InitD3D9BaseObject(D3D9BaseObject *pBaseObject, enum REF_TYPE RefType, IUnknown *pUnknown)
unsigned int ULONG
Definition: retypes.h:1
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
enum REF_TYPE RefType