From 7e616af6ea8e0e310e7d08611f63069d87af11e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B3zef=20Kucia?= Date: Thu, 5 Jan 2017 11:50:55 +0100 Subject: [PATCH] d3d9/tests: Add d3d9ex test for backbuffer resize. 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/tests/d3d9ex.c | 102 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/dlls/d3d9/tests/d3d9ex.c b/dlls/d3d9/tests/d3d9ex.c index b40a9798fc9..f949f5ceec8 100644 --- a/dlls/d3d9/tests/d3d9ex.c +++ b/dlls/d3d9/tests/d3d9ex.c @@ -3600,6 +3600,107 @@ static void test_swapchain_parameters(void) DestroyWindow(window); } +static void test_backbuffer_resize(void) +{ + D3DPRESENT_PARAMETERS present_parameters = {0}; + IDirect3DSurface9 *backbuffer, *old_backbuffer; + D3DSURFACE_DESC surface_desc; + IDirect3DDevice9Ex *device; + D3DCOLOR color; + ULONG refcount; + HWND window; + HRESULT hr; + + static const struct + { + float position[3]; + DWORD diffuse; + } + quad[] = + { + {{-1.0f, -1.0f, 0.1f}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)}, + {{-1.0f, 1.0f, 0.1f}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)}, + {{ 1.0f, -1.0f, 0.1f}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)}, + {{ 1.0f, 1.0f, 0.1f}, D3DCOLOR_ARGB(0xff, 0x00, 0xff, 0x00)}, + }; + + window = create_window(); + if (!(device = create_device(window, NULL))) + { + skip("Failed to create a D3D device.\n"); + DestroyWindow(window); + return; + } + + hr = IDirect3DDevice9_SetRenderState(device, D3DRS_CLIPPING, FALSE); + ok(SUCCEEDED(hr), "Failed to disable clipping, hr %#x.\n", hr); + hr = IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, FALSE); + ok(SUCCEEDED(hr), "Failed to disable Z test, hr %#x.\n", hr); + hr = IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE); + ok(SUCCEEDED(hr), "Failed to disable lighting, hr %#x.\n", hr); + hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE); + ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr); + + hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); + ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr); + hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer); + ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr); + + hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 1.0f, 0); + ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr); + color = get_pixel_color(device, 1, 1); + ok(color == 0x00ff0000, "Got unexpected color 0x%08x.\n", color); + + present_parameters.BackBufferWidth = 800; + present_parameters.BackBufferHeight = 600; + present_parameters.BackBufferFormat = D3DFMT_A8R8G8B8; + present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD; + present_parameters.hDeviceWindow = NULL; + present_parameters.Windowed = TRUE; + present_parameters.EnableAutoDepthStencil = TRUE; + present_parameters.AutoDepthStencilFormat = D3DFMT_D24S8; + hr = IDirect3DDevice9_Reset(device, &present_parameters); + ok(SUCCEEDED(hr), "Failed to reset, hr %#x.\n", hr); + + old_backbuffer = backbuffer; + hr = IDirect3DSurface9_GetDesc(old_backbuffer, &surface_desc); + ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr); + todo_wine ok(surface_desc.Width == 640, "Got unexpected width %u.\n", surface_desc.Width); + todo_wine ok(surface_desc.Height == 480, "Got unexpected height %u.\n", surface_desc.Height); + refcount = IDirect3DSurface9_Release(old_backbuffer); + ok(!refcount, "Surface has %u references left.\n", refcount); + + hr = IDirect3DDevice9_GetBackBuffer(device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); + ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr); + todo_wine ok(backbuffer != old_backbuffer, "Expected new backbuffer surface.\n"); + + hr = IDirect3DDevice9_SetRenderTarget(device, 0, backbuffer); + ok(SUCCEEDED(hr), "Failed to set render target, hr %#x.\n", hr); + + hr = IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffffff00, 1.0f, 0); + ok(SUCCEEDED(hr), "Failed to clear, hr %#x.\n", hr); + color = get_pixel_color(device, 1, 1); + ok(color == 0x00ffff00, "Got unexpected color 0x%08x.\n", color); + color = get_pixel_color(device, 700, 500); + ok(color == 0x00ffff00, "Got unexpected color 0x%08x.\n", color); + + hr = IDirect3DDevice9_BeginScene(device); + ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr); + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_TRIANGLESTRIP, 2, quad, sizeof(*quad)); + ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr); + hr = IDirect3DDevice9_EndScene(device); + ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr); + color = get_pixel_color(device, 1, 1); + ok(color == 0x0000ff00, "Got unexpected color 0x%08x.\n", color); + color = get_pixel_color(device, 700, 500); + ok(color == 0x0000ff00, "Got unexpected color 0x%08x.\n", color); + + IDirect3DSurface9_Release(backbuffer); + refcount = IDirect3DDevice9_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); + DestroyWindow(window); +} + START_TEST(d3d9ex) { DEVMODEW current_mode; @@ -3647,4 +3748,5 @@ START_TEST(d3d9ex) test_wndproc_windowed(); test_window_style(); test_swapchain_parameters(); + test_backbuffer_resize(); }