swapchain.c 8.95 KB
Newer Older
1 2 3 4 5
/*
 * IDirect3DSwapChain9 implementation
 *
 * Copyright 2002-2003 Jason Edmeades
 *                     Raphael Junqueira
Oliver Stieber's avatar
Oliver Stieber committed
6
 * Copyright 2005 Oliver Stieber
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "config.h"
#include "d3d9_private.h"

Oliver Stieber's avatar
Oliver Stieber committed
26
WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27 28 29 30

/* IDirect3DSwapChain IUnknown parts follow: */
HRESULT WINAPI IDirect3DSwapChain9Impl_QueryInterface(LPDIRECT3DSWAPCHAIN9 iface, REFIID riid, LPVOID* ppobj)
{
31
    IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
32 33 34

    if (IsEqualGUID(riid, &IID_IUnknown)
        || IsEqualGUID(riid, &IID_IDirect3DSwapChain9)) {
Oliver Stieber's avatar
Oliver Stieber committed
35 36
        IUnknown_AddRef(iface);
        *ppobj = This;
37 38 39 40 41 42 43 44
        return D3D_OK;
    }

    WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
    return E_NOINTERFACE;
}

ULONG WINAPI IDirect3DSwapChain9Impl_AddRef(LPDIRECT3DSWAPCHAIN9 iface) {
45
    IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
46 47 48 49 50
    ULONG ref = InterlockedIncrement(&This->ref);

    TRACE("(%p) : AddRef from %ld\n", This, ref - 1);

    return ref;
51 52 53
}

ULONG WINAPI IDirect3DSwapChain9Impl_Release(LPDIRECT3DSWAPCHAIN9 iface) {
54
    IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
55 56 57 58
    ULONG ref = InterlockedDecrement(&This->ref);

    TRACE("(%p) : ReleaseRef to %ld\n", This, ref);

59
    if (ref == 0) {
60
        IWineD3DSwapChain_Release(This->wineD3DSwapChain);
61 62 63 64 65 66 67
        HeapFree(GetProcessHeap(), 0, This);
    }
    return ref;
}

/* IDirect3DSwapChain9 parts follow: */
HRESULT WINAPI IDirect3DSwapChain9Impl_Present(LPDIRECT3DSWAPCHAIN9 iface, CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion, DWORD dwFlags) {
68
    IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
Oliver Stieber's avatar
Oliver Stieber committed
69 70
    TRACE("(%p) Relay\n", This);
    return IWineD3DSwapChain_Present(This->wineD3DSwapChain, pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
71 72 73
}

HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface) {
74
    IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
Oliver Stieber's avatar
Oliver Stieber committed
75 76
    TRACE("(%p) Relay\n", This);
    return IWineD3DSwapChain_GetFrontBufferData(This->wineD3DSwapChain,  ((IDirect3DSurface9Impl *)pDestSurface)->wineD3DSurface);
77 78 79
}

HRESULT WINAPI IDirect3DSwapChain9Impl_GetBackBuffer(LPDIRECT3DSWAPCHAIN9 iface, UINT iBackBuffer, D3DBACKBUFFER_TYPE Type, IDirect3DSurface9** ppBackBuffer) {
80
    IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
Oliver Stieber's avatar
Oliver Stieber committed
81 82 83 84 85 86 87 88 89 90 91
    HRESULT hrc = D3D_OK;
    IWineD3DSurface *mySurface = NULL;

    TRACE("(%p) Relay\n", This);

    hrc = IWineD3DSwapChain_GetBackBuffer(This->wineD3DSwapChain, iBackBuffer, Type, &mySurface);
    if (hrc == D3D_OK && NULL != mySurface) {
       IWineD3DSurface_GetParent(mySurface, (IUnknown **)ppBackBuffer);
       IWineD3DSurface_Release(mySurface);
    }
    return hrc;
92 93 94
}

HRESULT WINAPI IDirect3DSwapChain9Impl_GetRasterStatus(LPDIRECT3DSWAPCHAIN9 iface, D3DRASTER_STATUS* pRasterStatus) {
95
    IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
Oliver Stieber's avatar
Oliver Stieber committed
96 97
    TRACE("(%p) Relay\n", This);
    return IWineD3DSwapChain_GetRasterStatus(This->wineD3DSwapChain, pRasterStatus);
98 99 100
}

HRESULT WINAPI IDirect3DSwapChain9Impl_GetDisplayMode(LPDIRECT3DSWAPCHAIN9 iface, D3DDISPLAYMODE* pMode) {
101
    IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
Oliver Stieber's avatar
Oliver Stieber committed
102 103
    TRACE("(%p) Relay\n", This);
    return IWineD3DSwapChain_GetDisplayMode(This->wineD3DSwapChain, pMode);
104 105 106
}

HRESULT WINAPI IDirect3DSwapChain9Impl_GetDevice(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DDevice9** ppDevice) {
Oliver Stieber's avatar
Oliver Stieber committed
107 108 109
    IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
    HRESULT hrc = D3D_OK;
    IWineD3DDevice *device = NULL;
110

Oliver Stieber's avatar
Oliver Stieber committed
111 112 113 114 115 116 117 118
    TRACE("(%p) Relay\n", This);

    hrc = IWineD3DSwapChain_GetDevice(This->wineD3DSwapChain, &device);
    if (hrc == D3D_OK && NULL != device) {
       IWineD3DDevice_GetParent(device, (IUnknown **)ppDevice);
       IWineD3DDevice_Release(device);
    }
    return hrc;
119 120 121
}

HRESULT WINAPI IDirect3DSwapChain9Impl_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
122
    IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
Oliver Stieber's avatar
Oliver Stieber committed
123 124
    FIXME("(%p) : inplement using WINED3DPRESENT_PARAMERS\n", This);
    return IWineD3DSwapChain_GetPresentParameters(This->wineD3DSwapChain, pPresentationParameters);
125 126 127
}


128
const IDirect3DSwapChain9Vtbl Direct3DSwapChain9_Vtbl =
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
{
    IDirect3DSwapChain9Impl_QueryInterface,
    IDirect3DSwapChain9Impl_AddRef,
    IDirect3DSwapChain9Impl_Release,
    IDirect3DSwapChain9Impl_Present,
    IDirect3DSwapChain9Impl_GetFrontBufferData,
    IDirect3DSwapChain9Impl_GetBackBuffer,
    IDirect3DSwapChain9Impl_GetRasterStatus,
    IDirect3DSwapChain9Impl_GetDisplayMode,
    IDirect3DSwapChain9Impl_GetDevice,
    IDirect3DSwapChain9Impl_GetPresentParameters
};


/* IDirect3DDevice9 IDirect3DSwapChain9 Methods follow: */
HRESULT  WINAPI  IDirect3DDevice9Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain9** pSwapChain) {
145
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
Oliver Stieber's avatar
Oliver Stieber committed
146 147 148 149 150 151 152 153
    IDirect3DSwapChain9Impl* object;
    HRESULT hrc = D3D_OK;
    WINED3DPRESENT_PARAMETERS localParameters;

    TRACE("(%p) Relay\n", This);

    object = HeapAlloc(GetProcessHeap(),  HEAP_ZERO_MEMORY, sizeof(*object));
    if (NULL == object) {
154
        FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
Oliver Stieber's avatar
Oliver Stieber committed
155 156 157 158 159 160 161 162
        return D3DERR_OUTOFVIDEOMEMORY;
    }
    object->ref = 1;
    object->lpVtbl = &Direct3DSwapChain9_Vtbl;

    /* Allocate an associated WineD3DDevice object */
    localParameters.BackBufferWidth                = &pPresentationParameters->BackBufferWidth;
    localParameters.BackBufferHeight               = &pPresentationParameters->BackBufferHeight;
163
    localParameters.BackBufferFormat               = (WINED3DFORMAT *)&pPresentationParameters->BackBufferFormat;
Oliver Stieber's avatar
Oliver Stieber committed
164 165 166 167 168 169 170
    localParameters.BackBufferCount                = &pPresentationParameters->BackBufferCount;
    localParameters.MultiSampleType                = &pPresentationParameters->MultiSampleType;
    localParameters.MultiSampleQuality             = &pPresentationParameters->MultiSampleQuality;
    localParameters.SwapEffect                     = &pPresentationParameters->SwapEffect;
    localParameters.hDeviceWindow                  = &pPresentationParameters->hDeviceWindow;
    localParameters.Windowed                       = &pPresentationParameters->Windowed;
    localParameters.EnableAutoDepthStencil         = &pPresentationParameters->EnableAutoDepthStencil;
171
    localParameters.AutoDepthStencilFormat         = (WINED3DFORMAT *)&pPresentationParameters->AutoDepthStencilFormat;
Oliver Stieber's avatar
Oliver Stieber committed
172 173 174 175 176 177 178 179 180 181 182
    localParameters.Flags                          = &pPresentationParameters->Flags;
    localParameters.FullScreen_RefreshRateInHz     = &pPresentationParameters->FullScreen_RefreshRateInHz;
    localParameters.PresentationInterval           = &pPresentationParameters->PresentationInterval;


    hrc = IWineD3DDevice_CreateAdditionalSwapChain(This->WineD3DDevice, &localParameters, &object->wineD3DSwapChain, (IUnknown*)object, D3D9CB_CreateRenderTarget, D3D9CB_CreateDepthStencilSurface);
    if (hrc != D3D_OK) {
        FIXME("(%p) call to IWineD3DDevice_CreateAdditionalSwapChain failed\n", This);
        HeapFree(GetProcessHeap(), 0 , object);
    }else{
        *pSwapChain = (IDirect3DSwapChain9 *)object;
183
        TRACE("(%p) : Created swapchain %p\n", This, *pSwapChain);
Oliver Stieber's avatar
Oliver Stieber committed
184 185
    }
    TRACE("(%p) returning %p\n", This, *pSwapChain);
186
    return hrc;
187 188 189
}

HRESULT  WINAPI  IDirect3DDevice9Impl_GetSwapChain(LPDIRECT3DDEVICE9 iface, UINT iSwapChain, IDirect3DSwapChain9** pSwapChain) {
190
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
Oliver Stieber's avatar
Oliver Stieber committed
191 192 193 194 195 196 197 198 199 200 201
    HRESULT hrc = D3D_OK;
    IWineD3DSwapChain *swapchain = NULL;

    TRACE("(%p) Relay\n", This);

    hrc = IWineD3DDevice_GetSwapChain(This->WineD3DDevice, iSwapChain, &swapchain);
    if (hrc == D3D_OK && NULL != swapchain) {
       IWineD3DSwapChain_GetParent(swapchain, (IUnknown **)pSwapChain);
       IWineD3DSwapChain_Release(swapchain);
    }
    return hrc;
202 203 204
}

UINT     WINAPI  IDirect3DDevice9Impl_GetNumberOfSwapChains(LPDIRECT3DDEVICE9 iface) {
205
    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
Oliver Stieber's avatar
Oliver Stieber committed
206 207
    TRACE("(%p) Relay\n", This);
    return IWineD3DDevice_GetNumberOfSwapChains(This->WineD3DDevice);
208
}