From 176e60074b2b69d28d53adbe6606bf7c5eaf1fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Tue, 3 Jan 2017 13:46:33 +0100 Subject: [PATCH] d3d8: 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/d3d8/d3d8_private.h | 1 + dlls/d3d8/device.c | 7 ++++++- dlls/d3d8/surface.c | 7 +++++++ dlls/d3d8/tests/device.c | 6 +++--- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h index f55d2c2fdc..ffcd1cde73 100644 --- a/dlls/d3d8/d3d8_private.h +++ b/dlls/d3d8/d3d8_private.h @@ -242,6 +242,7 @@ struct d3d8_surface struct d3d8_texture *texture; }; +struct d3d8_device *d3d8_surface_get_device(const struct d3d8_surface *surface) DECLSPEC_HIDDEN; struct wined3d_rendertarget_view *d3d8_surface_get_rendertarget_view(struct d3d8_surface *surface) DECLSPEC_HIDDEN; void surface_init(struct d3d8_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/d3d8/device.c b/dlls/d3d8/device.c index fae561048f..5a5871f6bb 100644 --- a/dlls/d3d8/device.c +++ b/dlls/d3d8/device.c @@ -1161,6 +1161,12 @@ static HRESULT WINAPI d3d8_device_SetRenderTarget(IDirect3DDevice8 *iface, TRACE("iface %p, render_target %p, depth_stencil %p.\n", iface, render_target, depth_stencil); + if (rt_impl && d3d8_surface_get_device(rt_impl) != device) + { + WARN("Render target surface does not match device.\n"); + return D3DERR_INVALIDCALL; + } + wined3d_mutex_lock(); if (ds_impl) @@ -1200,7 +1206,6 @@ static HRESULT WINAPI d3d8_device_SetRenderTarget(IDirect3DDevice8 *iface, WARN("Multisample settings do not match, returning D3DERR_INVALIDCALL\n"); wined3d_mutex_unlock(); return D3DERR_INVALIDCALL; - } } diff --git a/dlls/d3d8/surface.c b/dlls/d3d8/surface.c index 565f642b62..137033eaa2 100644 --- a/dlls/d3d8/surface.c +++ b/dlls/d3d8/surface.c @@ -353,6 +353,13 @@ static const struct wined3d_parent_ops d3d8_view_wined3d_parent_ops = view_wined3d_object_destroyed, }; +struct d3d8_device *d3d8_surface_get_device(const struct d3d8_surface *surface) +{ + IDirect3DDevice8 *device; + device = surface->texture ? surface->texture->parent_device : surface->parent_device; + return impl_from_IDirect3DDevice8(device); +} + struct wined3d_rendertarget_view *d3d8_surface_get_rendertarget_view(struct d3d8_surface *surface) { HRESULT hr; diff --git a/dlls/d3d8/tests/device.c b/dlls/d3d8/tests/device.c index 2dbf9d8020..22667ec3ac 100644 --- a/dlls/d3d8/tests/device.c +++ b/dlls/d3d8/tests/device.c @@ -8115,7 +8115,7 @@ static void test_render_target_device_mismatch(void) ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr); hr = IDirect3DDevice8_SetRenderTarget(device, surface, NULL); - todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); IDirect3DSurface8_Release(surface); @@ -8123,13 +8123,13 @@ static void test_render_target_device_mismatch(void) ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr); hr = IDirect3DDevice8_SetRenderTarget(device, surface, NULL); - todo_wine ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); + ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr); IDirect3DSurface8_Release(surface); hr = IDirect3DDevice8_GetRenderTarget(device, &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); IDirect3DSurface8_Release(surface); IDirect3DSurface8_Release(rt);