ReactOS 0.4.16-dev-336-gb667d82
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
65HRESULT 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 {
85 if (FAILED(IUnknown_QueryInterface(pBaseObject->pUnknown, &IID_IDirect3DDevice9, (void**)&pDevice)))
86 return E_NOINTERFACE;
87
89 return D3D_OK;
90 }
91
92 return E_NOINTERFACE;
93}
94
96{
98 if (FAILED(D3D9BaseObject_GetDeviceInt(pBaseObject, &pDevice)))
99 return;
100
101 if (pDevice->bLockDevice)
102 EnterCriticalSection(&pDevice->CriticalSection);
103}
104
106{
108 if (FAILED(D3D9BaseObject_GetDeviceInt(pBaseObject, &pDevice)))
109 return;
110
111 if (pDevice->bLockDevice)
112 LeaveCriticalSection(&pDevice->CriticalSection);
113}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
struct IDirect3DDevice9 * LPDIRECT3DDEVICE9
Definition: d3d9.h:130
VOID D3D9BaseObject_LockDevice(D3D9BaseObject *pBaseObject)
HRESULT D3D9BaseObject_GetDevice(D3D9BaseObject *pBaseObject, IDirect3DDevice9 **ppDevice)
ULONG D3D9BaseObject_Release(D3D9BaseObject *pBaseObject)
ULONG D3D9BaseObject_AddRef(D3D9BaseObject *pBaseObject)
VOID InitD3D9BaseObject(D3D9BaseObject *pBaseObject, enum REF_TYPE RefType, IUnknown *pUnknown)
VOID D3D9BaseObject_Destroy(D3D9BaseObject *pBaseObject, BOOL bFreeThis)
HRESULT D3D9BaseObject_GetDeviceInt(D3D9BaseObject *pBaseObject, DIRECT3DDEVICE9_INT **ppDevice)
ID3D9BaseObjectVtbl D3D9BaseObject_Vtbl
VOID D3D9BaseObject_UnlockDevice(D3D9BaseObject *pBaseObject)
REF_TYPE
LPDIRECT3DDEVICE9_INT IDirect3DDevice9ToImpl(LPDIRECT3DDEVICE9 iface)
Definition: d3d9_device.c:19
VOID AlignedFree(IN OUT LPVOID pObject)
Definition: d3d9_helpers.c:130
#define D3D_OK
Definition: d3d.h:106
#define D3DERR_INVALIDCALL
#define NULL
Definition: types.h:112
_In_ PUNKNOWN pUnknown
Definition: drmk.h:76
unsigned int BOOL
Definition: ntddk_ex.h:94
FxDevice * pDevice
ULONG AddRef()
ULONG Release()
#define FAILED(hr)
Definition: intsafe.h:51
ID3D9BaseObjectVtbl * lpVtbl
enum REF_TYPE RefType
IUnknown * pUnknown
uint32_t ULONG
Definition: typedefs.h:59
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define E_NOINTERFACE
Definition: winerror.h:2364