058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync/*
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * IDirect3DSwapChain9 implementation
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2002-2003 Jason Edmeades
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Raphael Junqueira
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2005 Oliver Stieber
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * This library is free software; you can redistribute it and/or
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * modify it under the terms of the GNU Lesser General Public
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * License as published by the Free Software Foundation; either
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * version 2.1 of the License, or (at your option) any later version.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * This library is distributed in the hope that it will be useful,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * but WITHOUT ANY WARRANTY; without even the implied warranty of
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Lesser General Public License for more details.
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * You should have received a copy of the GNU Lesser General Public
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * License along with this library; if not, write to the Free Software
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync/*
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * a choice of LGPL license versions is made available with the language indicating
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * that LGPLv2 or any later version may be used, or where a choice of which version
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync * of the LGPL is applied is otherwise unspecified.
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync */
4237d5a79f48789aacc67dc43378d2d7813a39f4vboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include "config.h"
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#include "d3d9_private.h"
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncWINE_DEFAULT_DEBUG_CHANNEL(d3d9);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic inline struct d3d9_swapchain *impl_from_IDirect3DSwapChain9Ex(IDirect3DSwapChain9Ex *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync return CONTAINING_RECORD(iface, struct d3d9_swapchain, IDirect3DSwapChain9Ex_iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_QueryInterface(IDirect3DSwapChain9Ex *iface, REFIID riid, void **out)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (IsEqualGUID(riid, &IID_IDirect3DSwapChain9)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync || IsEqualGUID(riid, &IID_IUnknown))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync IDirect3DSwapChain9Ex_AddRef(iface);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync *out = iface;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync return S_OK;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync }
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync if (IsEqualGUID(riid, &IID_IDirect3DSwapChain9Ex))
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync {
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(swapchain->parent_device);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync * It doesn't matter with which function the device was created. */
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync if (!device->d3d_parent->extended)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync {
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE.\n");
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync *out = NULL;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync return E_NOINTERFACE;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync }
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync IDirect3DSwapChain9Ex_AddRef(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *out = iface;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return S_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *out = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_NOINTERFACE;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic ULONG WINAPI d3d9_swapchain_AddRef(IDirect3DSwapChain9Ex *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG refcount = InterlockedIncrement(&swapchain->refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p increasing refcount to %u.\n", iface, refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (refcount == 1)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (swapchain->parent_device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice9Ex_AddRef(swapchain->parent_device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_swapchain_incref(swapchain->wined3d_swapchain);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return refcount;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic ULONG WINAPI d3d9_swapchain_Release(IDirect3DSwapChain9Ex *iface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG refcount = InterlockedDecrement(&swapchain->refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p decreasing refcount to %u.\n", iface, refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!refcount)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice9Ex *parent_device = swapchain->parent_device;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_swapchain_decref(swapchain->wined3d_swapchain);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Release the device last, as it may cause the device to be destroyed. */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (parent_device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice9Ex_Release(parent_device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return refcount;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_swapchain_Present(IDirect3DSwapChain9Ex *iface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const RGNDATA *dirty_region, DWORD flags)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p, flags %#x.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync iface, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect),
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dst_window_override, dirty_region, flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_swapchain_present(swapchain->wined3d_swapchain, src_rect,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dst_rect, dst_window_override, dirty_region, flags);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetFrontBufferData(IDirect3DSwapChain9Ex *iface, IDirect3DSurface9 *surface)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d9_surface *dst = unsafe_impl_from_IDirect3DSurface9(surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, surface %p.\n", iface, surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_swapchain_get_front_buffer_data(swapchain->wined3d_swapchain, dst->wined3d_surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetBackBuffer(IDirect3DSwapChain9Ex *iface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface9 **backbuffer)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_surface *wined3d_surface = NULL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d9_surface *surface_impl;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr = D3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync iface, backbuffer_idx, backbuffer_type, backbuffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((wined3d_surface = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync backbuffer_idx, (enum wined3d_backbuffer_type)backbuffer_type)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_impl = wined3d_surface_get_parent(wined3d_surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *backbuffer = &surface_impl->IDirect3DSurface9_iface;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DSurface9_AddRef(*backbuffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync else
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = D3DERR_INVALIDCALL;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetRasterStatus(IDirect3DSwapChain9Ex *iface, D3DRASTER_STATUS *raster_status)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, raster_status %p.\n", iface, raster_status);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_swapchain_get_raster_status(swapchain->wined3d_swapchain,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync (struct wined3d_raster_status *)raster_status);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetDisplayMode(IDirect3DSwapChain9Ex *iface, D3DDISPLAYMODE *mode)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_display_mode wined3d_mode;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, mode %p.\n", iface, mode);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_swapchain_get_display_mode(swapchain->wined3d_swapchain, &wined3d_mode, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (SUCCEEDED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync mode->Width = wined3d_mode.width;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync mode->Height = wined3d_mode.height;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync mode->RefreshRate = wined3d_mode.refresh_rate;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetDevice(IDirect3DSwapChain9Ex *iface, IDirect3DDevice9 **device)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, device %p.\n", iface, device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *device = (IDirect3DDevice9 *)swapchain->parent_device;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice9_AddRef(*device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Returning device %p.\n", *device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return D3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetPresentParameters(IDirect3DSwapChain9Ex *iface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync D3DPRESENT_PARAMETERS *parameters)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_swapchain_desc desc;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, parameters %p.\n", iface, parameters);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_swapchain_get_desc(swapchain->wined3d_swapchain, &desc);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync present_parameters_from_wined3d_swapchain_desc(parameters, &desc);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return D3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetLastPresentCount(IDirect3DSwapChain9Ex *iface,
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync UINT *last_present_count)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync{
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync FIXME("iface %p, last_present_count %p, stub!\n", iface, last_present_count);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync if (last_present_count)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync *last_present_count = 0;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync return D3D_OK;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync}
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetPresentStatistics(IDirect3DSwapChain9Ex *iface,
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync D3DPRESENTSTATS *present_stats)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync{
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync FIXME("iface %p, present_stats %p, stub!\n", iface, present_stats);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync if (present_stats)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync memset(present_stats, 0, sizeof(*present_stats));
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync return D3D_OK;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync}
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetDisplayModeEx(IDirect3DSwapChain9Ex *iface,
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync{
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct wined3d_display_mode wined3d_mode;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync HRESULT hr;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync TRACE("iface %p, mode %p, rotation %p.\n", iface, mode, rotation);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync if (mode->Size != sizeof(*mode))
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync return D3DERR_INVALIDCALL;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync wined3d_mutex_lock();
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync hr = wined3d_swapchain_get_display_mode(swapchain->wined3d_swapchain, &wined3d_mode,
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync (enum wined3d_display_rotation *)rotation);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync wined3d_mutex_unlock();
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync if (SUCCEEDED(hr))
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync {
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync mode->Width = wined3d_mode.width;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync mode->Height = wined3d_mode.height;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync mode->RefreshRate = wined3d_mode.refresh_rate;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync mode->ScanLineOrdering = wined3d_mode.scanline_ordering;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync }
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync return hr;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic const struct IDirect3DSwapChain9ExVtbl d3d9_swapchain_vtbl =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync /* IUnknown */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d9_swapchain_QueryInterface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d9_swapchain_AddRef,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d9_swapchain_Release,
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync /* IDirect3DSwapChain9 */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d9_swapchain_Present,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d9_swapchain_GetFrontBufferData,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d9_swapchain_GetBackBuffer,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d9_swapchain_GetRasterStatus,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d9_swapchain_GetDisplayMode,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d9_swapchain_GetDevice,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d9_swapchain_GetPresentParameters,
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync /* IDirect3DSwapChain9Ex */
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync d3d9_swapchain_GetLastPresentCount,
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync d3d9_swapchain_GetPresentStatistics,
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync d3d9_swapchain_GetDisplayModeEx
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync};
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void STDMETHODCALLTYPE d3d9_swapchain_wined3d_object_released(void *parent)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, parent);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic const struct wined3d_parent_ops d3d9_swapchain_wined3d_parent_ops =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync d3d9_swapchain_wined3d_object_released,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync};
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT swapchain_init(struct d3d9_swapchain *swapchain, struct d3d9_device *device,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct wined3d_swapchain_desc *desc)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->refcount = 1;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync swapchain->IDirect3DSwapChain9Ex_iface.lpVtbl = &d3d9_swapchain_vtbl;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_swapchain_create(device->wined3d_device, desc, swapchain,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync &d3d9_swapchain_wined3d_parent_ops, &swapchain->wined3d_swapchain);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->parent_device = &device->IDirect3DDevice9Ex_iface;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice9Ex_AddRef(swapchain->parent_device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return D3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT d3d9_swapchain_create(struct d3d9_device *device, struct wined3d_swapchain_desc *desc,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d9_swapchain **swapchain)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d9_swapchain *object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return E_OUTOFMEMORY;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = swapchain_init(object, device, desc)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync {
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to initialize swapchain, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HeapFree(GetProcessHeap(), 0, object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync }
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("Created swapchain %p.\n", object);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *swapchain = object;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return D3D_OK;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#ifdef VBOX_WITH_WDDM
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncVBOXWINEEX_DECL(HRESULT) VBoxWineExD3DSwapchain9Present(IDirect3DSwapChain9 *iface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DSurface9 *surf) /* use the given surface as a frontbuffer content source */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync{
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d9_surface *rt = unsafe_impl_from_IDirect3DSurface9(surf);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync HRESULT hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_lock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_swapchain_present_rt(swapchain->wined3d_swapchain, rt->wined3d_surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_mutex_unlock();
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync return hr;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync}
7b6926b2bf44f326f40e1d9d1ce33a4dff0a2c67vboxsync
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsyncVBOXWINEEX_DECL(HRESULT) VBoxWineExD3DSwapchain9GetHostWinID(IDirect3DSwapChain9 *iface, int32_t *pi32Id)
7b6926b2bf44f326f40e1d9d1ce33a4dff0a2c67vboxsync{
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
7b6926b2bf44f326f40e1d9d1ce33a4dff0a2c67vboxsync HRESULT hr;
7b6926b2bf44f326f40e1d9d1ce33a4dff0a2c67vboxsync wined3d_mutex_lock();
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsync hr = wined3d_swapchain_get_host_win_id(swapchain->wined3d_swapchain, pi32Id);
7b6926b2bf44f326f40e1d9d1ce33a4dff0a2c67vboxsync wined3d_mutex_unlock();
7b6926b2bf44f326f40e1d9d1ce33a4dff0a2c67vboxsync return hr;
7b6926b2bf44f326f40e1d9d1ce33a4dff0a2c67vboxsync}
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync#endif