From: Ken Thomases Subject: [PATCH 2/2] d3d9/tests: Test that Direct3D restores the pixel format on the window it targets. (try 2) Message-Id: <8411755B-263E-4A54-894D-1DBA02721C52@codeweavers.com> Date: Thu, 6 Feb 2014 19:13:53 -0600 try 2: skip rather than fail if can't find a pixel format or if SetPixelFormat() fails. --- dlls/d3d9/tests/device.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/dlls/d3d9/tests/device.c b/dlls/d3d9/tests/device.c index 6877a0b..e591b44 100644 --- a/dlls/d3d9/tests/device.c +++ b/dlls/d3d9/tests/device.c @@ -7393,6 +7393,123 @@ static void test_shared_handle(void) DestroyWindow(window); } +static void test_pixel_format(void) +{ + HWND hwnd; + HDC hdc; + int format, test_format; + PIXELFORMATDESCRIPTOR pfd; + BOOL succeeded; + IDirect3D9 *d3d9 = NULL; + D3DPRESENT_PARAMETERS present_parameters; + IDirect3DDevice9 *device = NULL; + HRESULT hr; + static const float point[3] = {0.0, 0.0, 0.0}; + + hwnd = CreateWindowA("d3d9_test_wc", "d3d9_test", WS_OVERLAPPEDWINDOW, + 100, 100, 160, 160, NULL, NULL, NULL, NULL); + if (!hwnd) + { + skip("Failed to create window\n"); + return; + } + + hdc = GetDC(hwnd); + if (!hdc) + { + skip("Failed to get DC\n"); + goto cleanup; + } + + format = GetPixelFormat(hdc); + ok(format == 0, "new window has pixel format %d\n", format); + + ZeroMemory(&pfd, sizeof(pfd)); + pfd.nSize = sizeof(pfd); + pfd.nVersion = 1; + pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.iLayerType = PFD_MAIN_PLANE; + format = ChoosePixelFormat(hdc, &pfd); + if (format <= 0) + { + skip("no pixel format available\n"); + goto cleanup; + } + + if (!SetPixelFormat(hdc, format, &pfd) || GetPixelFormat(hdc) != format) + { + skip("failed to set pixel format\n"); + goto cleanup; + } + + d3d9 = Direct3DCreate9(D3D_SDK_VERSION); + if (!d3d9) + { + skip("Failed to create IDirect3D9 object\n"); + goto cleanup; + } + + test_format = GetPixelFormat(hdc); + ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format); + + ZeroMemory(&present_parameters, sizeof(present_parameters)); + present_parameters.Windowed = TRUE; + present_parameters.hDeviceWindow = hwnd; + present_parameters.SwapEffect = D3DSWAPEFFECT_DISCARD; + + hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, + hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device); + if (FAILED(hr) || !device) + { + skip("Failed to create device\n"); + goto cleanup; + } + + test_format = GetPixelFormat(hdc); + ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format); + + hr = IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ); + ok(SUCCEEDED(hr), "Failed to set FVF, hr %#x.\n", hr); + + test_format = GetPixelFormat(hdc); + ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format); + + hr = IDirect3DDevice9_BeginScene(device); + ok(SUCCEEDED(hr), "BeginScene failed %#x\n", hr); + + test_format = GetPixelFormat(hdc); + ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format); + + hr = IDirect3DDevice9_DrawPrimitiveUP(device, D3DPT_POINTLIST, 1, point, 3 * sizeof(float)); + ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr); + + test_format = GetPixelFormat(hdc); + ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format); + + hr = IDirect3DDevice9_EndScene(device); + ok(SUCCEEDED(hr), "EndScene failed %#x\n", hr); + + test_format = GetPixelFormat(hdc); + ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format); + + hr = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL); + ok(SUCCEEDED(hr), "Present failed %#x\n", hr); + + test_format = GetPixelFormat(hdc); + ok(test_format == format, "window has pixel format %d, expected %d\n", test_format, format); + +cleanup: + if (device) + { + UINT refcount = IDirect3DDevice9_Release(device); + ok(!refcount, "Device has %u references left.\n", refcount); + } + if (d3d9) IDirect3D9_Release(d3d9); + if (hdc) ReleaseDC(hwnd, hdc); + if (hwnd) DestroyWindow(hwnd); +} + START_TEST(device) { WNDCLASSA wc = {0}; @@ -7477,6 +7594,7 @@ START_TEST(device) test_volume_blocks(); test_lockbox_invalid(); test_shared_handle(); + test_pixel_format(); UnregisterClassA("d3d9_test_wc", GetModuleHandleA(NULL)); }