Changed index and vertex buffer so that internal references are
[wine] / dlls / d3d8 / swapchain.c
1 /*
2  * IDirect3DSwapChain8 implementation
3  *
4  * Copyright 2002 Jason Edmeades
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22
23 #include <stdarg.h>
24
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "wingdi.h"
29 #include "wine/debug.h"
30
31 #include "d3d8_private.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
34
35 /* IDirect3DSwapChain IUnknown parts follow: */
36 HRESULT WINAPI IDirect3DSwapChain8Impl_QueryInterface(LPDIRECT3DSWAPCHAIN8 iface,REFIID riid,LPVOID *ppobj)
37 {
38     IDirect3DSwapChain8Impl *This = (IDirect3DSwapChain8Impl *)iface;
39
40     if (IsEqualGUID(riid, &IID_IUnknown)
41         || IsEqualGUID(riid, &IID_IDirect3DSwapChain8)) {
42         IDirect3DSwapChain8Impl_AddRef(iface);
43         *ppobj = This;
44         return D3D_OK;
45     }
46
47     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
48     return E_NOINTERFACE;
49 }
50
51 ULONG WINAPI IDirect3DSwapChain8Impl_AddRef(LPDIRECT3DSWAPCHAIN8 iface) {
52     IDirect3DSwapChain8Impl *This = (IDirect3DSwapChain8Impl *)iface;
53     ULONG ref = InterlockedIncrement(&This->ref);
54
55     TRACE("(%p) : AddRef from %ld\n", This, ref - 1);
56
57     return ref;
58 }
59
60 ULONG WINAPI IDirect3DSwapChain8Impl_Release(LPDIRECT3DSWAPCHAIN8 iface) {
61     IDirect3DSwapChain8Impl *This = (IDirect3DSwapChain8Impl *)iface;
62     ULONG ref = InterlockedDecrement(&This->ref);
63
64     TRACE("(%p) : ReleaseRef to %ld\n", This, ref);
65
66     if (ref == 0) {
67         HeapFree(GetProcessHeap(), 0, This);
68     }
69     return ref;
70 }
71
72 /* IDirect3DSwapChain parts follow: */
73 HRESULT WINAPI IDirect3DSwapChain8Impl_Present(LPDIRECT3DSWAPCHAIN8 iface, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride,CONST RGNDATA* pDirtyRegion) {
74     IDirect3DSwapChain8Impl *This = (IDirect3DSwapChain8Impl *)iface;
75     FIXME("(%p) : stub\n", This);
76     return D3D_OK;
77 }
78
79 HRESULT WINAPI IDirect3DSwapChain8Impl_GetBackBuffer(LPDIRECT3DSWAPCHAIN8 iface, UINT BackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface8** ppBackBuffer) {
80     IDirect3DSwapChain8Impl *This = (IDirect3DSwapChain8Impl *)iface;
81     *ppBackBuffer = (LPDIRECT3DSURFACE8) This->backBuffer;
82     TRACE("(%p) : BackBuf %d Type %d returning %p\n", This, BackBuffer, Type, *ppBackBuffer);
83
84     if (BackBuffer > This->PresentParms.BackBufferCount - 1) {
85         FIXME("Only one backBuffer currently supported\n");
86         return D3DERR_INVALIDCALL;
87     }
88
89     /* Note inc ref on returned surface */
90     IDirect3DSurface8Impl_AddRef((LPDIRECT3DSURFACE8) *ppBackBuffer);
91     return D3D_OK;
92 }
93
94 const IDirect3DSwapChain8Vtbl Direct3DSwapChain8_Vtbl =
95 {
96     IDirect3DSwapChain8Impl_QueryInterface,
97     IDirect3DSwapChain8Impl_AddRef,
98     IDirect3DSwapChain8Impl_Release,
99     IDirect3DSwapChain8Impl_Present,
100     IDirect3DSwapChain8Impl_GetBackBuffer
101 };