058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * IDirect3DSwapChain9 implementation
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2002-2003 Jason Edmeades
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Raphael Junqueira
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync * Copyright 2005 Oliver Stieber
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 * 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 * 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
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.
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic inline struct d3d9_swapchain *impl_from_IDirect3DSwapChain9Ex(IDirect3DSwapChain9Ex *iface)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync return CONTAINING_RECORD(iface, struct d3d9_swapchain, IDirect3DSwapChain9Ex_iface);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_QueryInterface(IDirect3DSwapChain9Ex *iface, REFIID riid, void **out)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(swapchain->parent_device);
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 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE.\n");
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic ULONG WINAPI d3d9_swapchain_AddRef(IDirect3DSwapChain9Ex *iface)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG refcount = InterlockedIncrement(&swapchain->refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p increasing refcount to %u.\n", iface, refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice9Ex_AddRef(swapchain->parent_device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_swapchain_incref(swapchain->wined3d_swapchain);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic ULONG WINAPI d3d9_swapchain_Release(IDirect3DSwapChain9Ex *iface)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync ULONG refcount = InterlockedDecrement(&swapchain->refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("%p decreasing refcount to %u.\n", iface, refcount);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice9Ex *parent_device = swapchain->parent_device;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_swapchain_decref(swapchain->wined3d_swapchain);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync /* Release the device last, as it may cause the device to be destroyed. */
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_swapchain_Present(IDirect3DSwapChain9Ex *iface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
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 hr = wined3d_swapchain_present(swapchain->wined3d_swapchain, src_rect,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync dst_rect, dst_window_override, dirty_region, flags);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetFrontBufferData(IDirect3DSwapChain9Ex *iface, IDirect3DSurface9 *surface)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d9_surface *dst = unsafe_impl_from_IDirect3DSurface9(surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_swapchain_get_front_buffer_data(swapchain->wined3d_swapchain, dst->wined3d_surface);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetBackBuffer(IDirect3DSwapChain9Ex *iface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface9 **backbuffer)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync iface, backbuffer_idx, backbuffer_type, backbuffer);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if ((wined3d_surface = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync backbuffer_idx, (enum wined3d_backbuffer_type)backbuffer_type)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync surface_impl = wined3d_surface_get_parent(wined3d_surface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *backbuffer = &surface_impl->IDirect3DSurface9_iface;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetRasterStatus(IDirect3DSwapChain9Ex *iface, D3DRASTER_STATUS *raster_status)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, raster_status %p.\n", iface, raster_status);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_swapchain_get_raster_status(swapchain->wined3d_swapchain,
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetDisplayMode(IDirect3DSwapChain9Ex *iface, D3DDISPLAYMODE *mode)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_swapchain_get_display_mode(swapchain->wined3d_swapchain, &wined3d_mode, NULL);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetDevice(IDirect3DSwapChain9Ex *iface, IDirect3DDevice9 **device)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync *device = (IDirect3DDevice9 *)swapchain->parent_device;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetPresentParameters(IDirect3DSwapChain9Ex *iface,
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync TRACE("iface %p, parameters %p.\n", iface, parameters);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync wined3d_swapchain_get_desc(swapchain->wined3d_swapchain, &desc);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync present_parameters_from_wined3d_swapchain_desc(parameters, &desc);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetLastPresentCount(IDirect3DSwapChain9Ex *iface,
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync FIXME("iface %p, last_present_count %p, stub!\n", iface, last_present_count);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetPresentStatistics(IDirect3DSwapChain9Ex *iface,
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync FIXME("iface %p, present_stats %p, stub!\n", iface, present_stats);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic HRESULT WINAPI d3d9_swapchain_GetDisplayModeEx(IDirect3DSwapChain9Ex *iface,
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync TRACE("iface %p, mode %p, rotation %p.\n", iface, mode, rotation);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync hr = wined3d_swapchain_get_display_mode(swapchain->wined3d_swapchain, &wined3d_mode,
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync mode->ScanLineOrdering = wined3d_mode.scanline_ordering;
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsyncstatic const struct IDirect3DSwapChain9ExVtbl d3d9_swapchain_vtbl =
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync /* IUnknown */
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync /* IDirect3DSwapChain9 */
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync /* IDirect3DSwapChain9Ex */
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic void STDMETHODCALLTYPE d3d9_swapchain_wined3d_object_released(void *parent)
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic const struct wined3d_parent_ops d3d9_swapchain_wined3d_parent_ops =
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncstatic HRESULT swapchain_init(struct d3d9_swapchain *swapchain, struct d3d9_device *device,
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync swapchain->IDirect3DSwapChain9Ex_iface.lpVtbl = &d3d9_swapchain_vtbl;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_swapchain_create(device->wined3d_device, desc, swapchain,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync &d3d9_swapchain_wined3d_parent_ops, &swapchain->wined3d_swapchain);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync swapchain->parent_device = &device->IDirect3DDevice9Ex_iface;
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DDevice9Ex_AddRef(swapchain->parent_device);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncHRESULT d3d9_swapchain_create(struct d3d9_device *device, struct wined3d_swapchain_desc *desc,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync if (FAILED(hr = swapchain_init(object, device, desc)))
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync WARN("Failed to initialize swapchain, hr %#x.\n", hr);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsyncVBOXWINEEX_DECL(HRESULT) VBoxWineExD3DSwapchain9Present(IDirect3DSwapChain9 *iface,
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync IDirect3DSurface9 *surf) /* use the given surface as a frontbuffer content source */
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync struct d3d9_surface *rt = unsafe_impl_from_IDirect3DSurface9(surf);
058c0c53c37f5cb271aeb3c385c10766f84f4aefvboxsync hr = wined3d_swapchain_present_rt(swapchain->wined3d_swapchain, rt->wined3d_surface);
ea1cc8df95dba6fca9c36c94f565ef95c7802a36vboxsyncVBOXWINEEX_DECL(HRESULT) VBoxWineExD3DSwapchain9GetHostWinID(IDirect3DSwapChain9 *iface, int32_t *pi32Id)
76f3927069cc452e77bf72f32d9175c0256ed3b3vboxsync struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface);