From c1aba7cd8b35f100e594805956964b962dc30a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Tue, 3 Jan 2017 13:46:32 +0100 Subject: [PATCH] d3d9: Reject render target surfaces created for other devices. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Józef Kucia Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d3d9/d3d9_private.h | 1 + dlls/d3d9/device.c | 10 ++++++++-- dlls/d3d9/surface.c | 7 +++++++ dlls/d3d9/tests/device.c | 6 +++--- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h index 3317e9cfce5..20c4c5c37c9 100644 --- a/dlls/d3d9/d3d9_private.h +++ b/dlls/d3d9/d3d9_private.h @@ -230,6 +230,7 @@ struct d3d9_surface struct d3d9_texture *texture; }; +struct d3d9_device *d3d9_surface_get_device(const struct d3d9_surface *surface) DECLSPEC_HIDDEN; struct wined3d_rendertarget_view *d3d9_surface_get_rendertarget_view(struct d3d9_surface *surface) DECLSPEC_HIDDEN; void surface_init(struct d3d9_surface *surface, struct wined3d_texture *wined3d_texture, unsigned int sub_resource_idx, const struct wined3d_parent_ops **parent_ops) DECLSPEC_HIDDEN; diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c index dab19ab5a8d..d47c705bb95 100644 --- a/dlls/d3d9/device.c +++ b/dlls/d3d9/device.c @@ -1523,8 +1523,14 @@ static HRESULT WINAPI d3d9_device_SetRenderTarget(IDirect3DDevice9Ex *iface, DWO if (!idx && !surface_impl) { - WARN("Trying to set render target 0 to NULL.\n"); - return D3DERR_INVALIDCALL; + WARN("Trying to set render target 0 to NULL.\n"); + return D3DERR_INVALIDCALL; + } + + if (surface_impl && d3d9_surface_get_device(surface_impl) != device) + { + WARN("Render target surface does not match device.\n"); + return D3DERR_INVALIDCALL; } wined3d_mutex_lock(); diff --git a/dlls/d3d9/surface.c b/dlls/d3d9/surface.c index be686821167..12e0f397c77 100644 --- a/dlls/d3d9/surface.c +++ b/dlls/d3d9/surface.c @@ -389,6 +389,13 @@ static const struct wined3d_parent_ops d3d9_view_wined3d_parent_ops = view_wined3d_object_destroyed, }; +struct d3d9_device *d3d9_surface_get_device(const struct d3d9_surface *surface) +{ + IDirect3DDevice9Ex *device; + device = surface->texture ? surface->texture->parent_device : surface->parent_device; + return impl_from_IDirect3DDevice9Ex(device); +} + struct wined3d_rendertarget_view *d3d9_surface_get_rendertarget_view(struct d3d9_surface *surface) { HRESULT hr; diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c index fbae9d6be36..aa266a5186e 100644 --- a/dlls/d3d9/tests/device.c +++ b/dlls/d3d9/tests/device.c @@ -11375,7 +11375,7 @@ static void test_render_target_device_mismatch(void) ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr); hr = IDirect3DDevice9_SetRenderTarget(device, 0, surface); - todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); IDirect3DSurface9_Release(surface); @@ -11383,13 +11383,13 @@ static void test_render_target_device_mismatch(void) ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr); hr = IDirect3DDevice9_SetRenderTarget(device, 0, surface); - todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); IDirect3DSurface9_Release(surface); hr = IDirect3DDevice9_GetRenderTarget(device, 0, &surface); ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr); - todo_wine ok(surface == rt, "Got unexpected render target %p, expected %p.\n", surface, rt); + ok(surface == rt, "Got unexpected render target %p, expected %p.\n", surface, rt); IDirect3DSurface9_Release(surface); IDirect3DSurface9_Release(rt);