]> git.cworth.org Git - apitrace/blob - d3d9/idirect3d_swapchain9.cpp
Dump flags.
[apitrace] / d3d9 / idirect3d_swapchain9.cpp
1 #include "StdAfx.h"
2
3 TraceDirect3DSwapChain9::TraceDirect3DSwapChain9(IDirect3DSwapChain9* pOriginal, IDirect3DDevice9* pDevice) {
4     m_pIDirect3DSwapChain9 = pOriginal; // store the pointer to original object
5     m_pIDirect3DDevice9 = pDevice;
6 }
7
8 TraceDirect3DSwapChain9::~TraceDirect3DSwapChain9(void) {
9     m_pIDirect3DSwapChain9 = NULL;
10 }
11
12 HRESULT TraceDirect3DSwapChain9::QueryInterface(REFIID riid, void** ppvObj) {
13     // check if original dll can provide interface. then send *our* address
14     *ppvObj = NULL;
15
16     HRESULT hRes = m_pIDirect3DSwapChain9->QueryInterface(riid, ppvObj);
17
18     if (hRes == NOERROR) {
19         *ppvObj = this;
20     }
21
22     return hRes;
23 }
24
25 ULONG TraceDirect3DSwapChain9::AddRef(void) {
26     return (m_pIDirect3DSwapChain9->AddRef());
27 }
28
29 ULONG TraceDirect3DSwapChain9::Release(void) {
30     // ATTENTION: This is a booby-trap ! Watch out !
31     // If we create our own sprites, surfaces, etc. (thus increasing the ref counter
32     // by external action), we need to delete that objects before calling the original
33     // Release function 
34
35     // global var
36     extern TraceDirect3DSwapChain9* gl_pmyIDirect3DSwapChain9;
37
38     // release/delete own objects
39     // .....
40
41     // Calling original function now
42     ULONG count = m_pIDirect3DSwapChain9->Release();
43
44     if (count == 0) {
45         // now, the Original Object has deleted itself, so do we here
46         gl_pmyIDirect3DSwapChain9 = NULL;
47         delete (this); // destructor will be called automatically
48     }
49
50     return (count);
51 }
52
53 HRESULT TraceDirect3DSwapChain9::Present(CONST RECT* pSourceRect,CONST RECT* pDestRect,HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion,DWORD dwFlags)
54 {
55     // Some games use this one for presenting. They ignore the Device's present routine
56
57     // we may want to draw own things here before flipping surfaces
58     // ... draw own stuff ...
59     this->ShowWeAreHere();
60
61     // call original routine
62     HRESULT hres = m_pIDirect3DSwapChain9->Present(pSourceRect,pDestRect,hDestWindowOverride,pDirtyRegion,dwFlags);
63
64     return (hres);
65 }
66
67 HRESULT TraceDirect3DSwapChain9::GetFrontBufferData(IDirect3DSurface9* pDestSurface) {
68     return (m_pIDirect3DSwapChain9->GetFrontBufferData(pDestSurface));
69 }
70
71 HRESULT TraceDirect3DSwapChain9::GetBackBuffer(UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) {
72     return (m_pIDirect3DSwapChain9->GetBackBuffer(iBackBuffer, Type, ppBackBuffer));
73 }
74
75 HRESULT TraceDirect3DSwapChain9::GetRasterStatus(D3DRASTER_STATUS* pRasterStatus) {
76     return (m_pIDirect3DSwapChain9->GetRasterStatus(pRasterStatus));
77 }
78
79 HRESULT TraceDirect3DSwapChain9::GetDisplayMode(D3DDISPLAYMODE* pMode) {
80     return (m_pIDirect3DSwapChain9->GetDisplayMode(pMode));
81 }
82
83 HRESULT TraceDirect3DSwapChain9::GetDevice(IDirect3DDevice9** ppDevice) {
84     return (m_pIDirect3DSwapChain9->GetDevice(ppDevice));
85 }
86
87 HRESULT TraceDirect3DSwapChain9::GetPresentParameters(D3DPRESENT_PARAMETERS* pPresentationParameters) {
88     return (m_pIDirect3DSwapChain9->GetPresentParameters(pPresentationParameters));
89 }
90
91 // This is our test function
92 void TraceDirect3DSwapChain9::ShowWeAreHere(void) {
93     D3DRECT rec = { 100, 1, 150, 50 };
94     m_pIDirect3DDevice9->Clear(1, &rec, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255, 255, 255, 0), 0, 0);
95 }
96