Spotted in https://bugs.winehq.org/show_bug.cgi?id=19471.
Signed-off-by: Paul Gofman gofmanp@gmail.com --- dlls/ddraw/tests/ddraw4.c | 84 +++++++++++++++++++++++++++++---------- dlls/ddraw/viewport.c | 13 +++--- 2 files changed, 70 insertions(+), 27 deletions(-)
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c index e61d67d723..ffa510a8b3 100644 --- a/dlls/ddraw/tests/ddraw4.c +++ b/dlls/ddraw/tests/ddraw4.c @@ -1619,13 +1619,13 @@ static void test_viewport_object(void) return; } hr = IDirect3DDevice3_GetDirect3D(device, &d3d); - ok(SUCCEEDED(hr), "Failed to get Direct3D3 interface, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw); - ok(SUCCEEDED(hr), "Failed to get DirectDraw4 interface, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); old_d3d_ref = get_refcount((IUnknown *) d3d);
hr = IDirect3D3_CreateViewport(d3d, &viewport3, NULL); - ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); ref = get_refcount((IUnknown *)viewport3); ok(ref == 1, "Got unexpected refcount %u.\n", ref); ref = get_refcount((IUnknown *)d3d); @@ -1654,11 +1654,11 @@ static void test_viewport_object(void) gamma = (IDirectDrawGammaControl *)0xdeadbeef; hr = IDirect3DViewport2_QueryInterface(viewport3, &IID_IDirectDrawGammaControl, (void **)&gamma); ok(hr == E_NOINTERFACE, "Got unexpected hr %#x.\n", hr); - ok(!gamma, "Interface not set to NULL by failed QI call: %p\n", gamma); + ok(!gamma, "Interface not set to NULL by failed QI call: %p.\n", gamma); /* NULL iid: Segfaults */
hr = IDirect3DViewport3_QueryInterface(viewport3, &IID_IDirect3DViewport, (void **)&viewport); - ok(SUCCEEDED(hr), "Failed to QI IDirect3DViewport, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); ref = get_refcount((IUnknown *)viewport); ok(ref == 2, "Got unexpected refcount %u.\n", ref); ref = get_refcount((IUnknown *)viewport3); @@ -1667,7 +1667,7 @@ static void test_viewport_object(void) viewport = NULL;
hr = IDirect3DViewport3_QueryInterface(viewport3, &IID_IDirect3DViewport3, (void **)&viewport2); - ok(SUCCEEDED(hr), "Failed to QI IDirect3DViewport3, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); ref = get_refcount((IUnknown *)viewport2); ok(ref == 2, "Got unexpected refcount %u.\n", ref); ref = get_refcount((IUnknown *)viewport3); @@ -1675,7 +1675,7 @@ static void test_viewport_object(void) IDirect3DViewport3_Release(viewport2);
hr = IDirect3DViewport3_QueryInterface(viewport3, &IID_IUnknown, (void **)&unknown); - ok(SUCCEEDED(hr), "Failed to QI IUnknown, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); ref = get_refcount((IUnknown *)viewport3); ok(ref == 2, "Got unexpected refcount %u.\n", ref); ref = get_refcount(unknown); @@ -1688,7 +1688,7 @@ static void test_viewport_object(void) ok(hr == D3DERR_NOCURRENTVIEWPORT, "Got unexpected hr %#x.\n", hr);
hr = IDirect3D3_CreateViewport(d3d, &another_vp, NULL); - ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
/* Setting a viewport not in the viewport list fails */ hr = IDirect3DDevice3_SetCurrentViewport(device, another_vp); @@ -1696,21 +1696,21 @@ static void test_viewport_object(void)
/* AddViewport(NULL): Segfault */ hr = IDirect3DDevice3_AddViewport(device, viewport3); - ok(SUCCEEDED(hr), "Failed to add viewport to device, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); ref = get_refcount((IUnknown *) viewport3); ok(ref == 2, "Got unexpected refcount %u.\n", ref); hr = IDirect3DDevice3_AddViewport(device, another_vp); - ok(SUCCEEDED(hr), "Failed to add viewport to device, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); ref = get_refcount((IUnknown *) another_vp); ok(ref == 2, "Got unexpected refcount %u.\n", ref);
test_vp = (IDirect3DViewport3 *) 0xbaadc0de; hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp); ok(hr == D3DERR_NOCURRENTVIEWPORT, "Got unexpected hr %#x.\n", hr); - ok(test_vp == (IDirect3DViewport3 *) 0xbaadc0de, "Got unexpected pointer %p\n", test_vp); + ok(test_vp == (IDirect3DViewport3 *) 0xbaadc0de, "Got unexpected pointer %p.\n", test_vp);
hr = IDirect3DDevice3_SetCurrentViewport(device, viewport3); - ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); ref = get_refcount((IUnknown *) viewport3); ok(ref == 3, "Got unexpected refcount %u.\n", ref); ref = get_refcount((IUnknown *) device); @@ -1719,7 +1719,7 @@ static void test_viewport_object(void) test_vp = NULL; hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - ok(test_vp == viewport3, "Got unexpected viewport %p\n", test_vp); + ok(test_vp == viewport3, "Got unexpected viewport %p.\n", test_vp); ref = get_refcount((IUnknown *) viewport3); ok(ref == 4, "Got unexpected refcount %u.\n", ref); if (test_vp) @@ -1729,17 +1729,17 @@ static void test_viewport_object(void)
/* Cannot set the viewport to NULL */ hr = IDirect3DDevice3_SetCurrentViewport(device, NULL); - ok(hr == DDERR_INVALIDPARAMS, "Failed to set viewport to NULL, hr %#x.\n", hr); + ok(hr == DDERR_INVALIDPARAMS, "Got unexpected hr %#x.\n", hr); test_vp = NULL; hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp); ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); - ok(test_vp == viewport3, "Got unexpected viewport %p\n", test_vp); + ok(test_vp == viewport3, "Got unexpected viewport %p.\n", test_vp); if (test_vp) IDirect3DViewport3_Release(test_vp);
/* SetCurrentViewport properly releases the old viewport's reference */ hr = IDirect3DDevice3_SetCurrentViewport(device, another_vp); - ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); ref = get_refcount((IUnknown *) viewport3); ok(ref == 2, "Got unexpected refcount %u.\n", ref); ref = get_refcount((IUnknown *) another_vp); @@ -1748,7 +1748,7 @@ static void test_viewport_object(void) /* Unlike device2::DeleteViewport, device3::DeleteViewport releases the * reference held by SetCurrentViewport */ hr = IDirect3DDevice3_DeleteViewport(device, another_vp); - ok(SUCCEEDED(hr), "Failed to delete viewport from device, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); ref = get_refcount((IUnknown *) another_vp); ok(ref == 1, "Got unexpected refcount %u.\n", ref);
@@ -1756,11 +1756,11 @@ static void test_viewport_object(void) test_vp = NULL; hr = IDirect3DDevice3_GetCurrentViewport(device, &test_vp); ok(hr == D3DERR_NOCURRENTVIEWPORT, "Got unexpected hr %#x.\n", hr); - ok(!test_vp, "Got unexpected viewport %p\n", test_vp); + ok(!test_vp, "Got unexpected viewport %p.\n", test_vp);
/* Setting a different viewport doesn't have any surprises now */ hr = IDirect3DDevice3_SetCurrentViewport(device, viewport3); - ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); ref = get_refcount((IUnknown *) viewport3); ok(ref == 3, "Got unexpected refcount %u.\n", ref); ref = get_refcount((IUnknown *) another_vp); @@ -1790,10 +1790,52 @@ static void test_viewport_object(void)
vp.dwSize = sizeof(vp); hr = IDirect3DViewport3_SetViewport(viewport3, &vp); - ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); vp2.dwSize = sizeof(vp2); hr = IDirect3DViewport3_SetViewport2(viewport3, &vp2); - ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + vp2.dwSize = sizeof(vp2); + vp2.dwX = 160; + vp2.dwY = 120; + vp2.dwWidth = 640 - vp2.dwX; + vp2.dwHeight = 480 - vp2.dwY; + vp2.dvClipX = 2.0f; + vp2.dvClipY = -1.75f; + vp2.dvClipWidth = 2.5f; + vp2.dvClipHeight = -1.5f; + vp2.dvMinZ = 0.5f; + vp2.dvMaxZ = 2.0f; + hr = IDirect3DViewport3_SetViewport2(viewport3, &vp2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + memset(&vp, 0xff, sizeof(vp)); + vp.dwSize = sizeof(vp); + hr = IDirect3DViewport3_GetViewport(viewport3, &vp); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(vp.dvMaxX == 4.5f && vp.dvMaxY == -1.75f && vp.dvScaleX == 192.0f + && vp.dvScaleY == -240.0f && vp.dvMinZ == 0.0f && vp.dvMaxZ == 1.0f, + "Got unexpected values %g, %g, %g, %g, %g, %g.\n", + vp.dvMaxX, vp.dvMaxY, vp.dvScaleX, vp.dvScaleY, vp.dvMinZ, vp.dvMaxZ); + + vp2.dvClipX = -1.5f; + vp2.dvClipY = 1.75f; + vp2.dvClipWidth = -1.5f; + vp2.dvClipHeight = 2.0f; + vp2.dvMinZ = 2.0f; + vp2.dvMaxZ = 0.5f; + + hr = IDirect3DViewport3_SetViewport2(viewport3, &vp2); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + + memset(&vp, 0xff, sizeof(vp)); + vp.dwSize = sizeof(vp); + hr = IDirect3DViewport3_GetViewport(viewport3, &vp); + ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr); + ok(vp.dvMaxX == -3.0f && vp.dvMaxY == 1.75f && vp.dvScaleX == -320.0f + && vp.dvScaleY == 180.0f && vp.dvMinZ == 0.0f && vp.dvMaxZ == 1.0f, + "Got unexpected values %g, %g, %g, %g, %g, %g.\n", + vp.dvMaxX, vp.dvMaxY, vp.dvScaleX, vp.dvScaleY, vp.dvMinZ, vp.dvMaxZ);
/* Destroying the device removes the viewport and releases the reference */ IDirect3DDevice3_Release(device); diff --git a/dlls/ddraw/viewport.c b/dlls/ddraw/viewport.c index 5fc7a4b2be..ceb5582524 100644 --- a/dlls/ddraw/viewport.c +++ b/dlls/ddraw/viewport.c @@ -350,12 +350,13 @@ static HRESULT WINAPI d3d_viewport_GetViewport(IDirect3DViewport3 *iface, D3DVIE vp1.dwY = viewport->viewports.vp2.dwY; vp1.dwWidth = viewport->viewports.vp2.dwWidth; vp1.dwHeight = viewport->viewports.vp2.dwHeight; - vp1.dvMaxX = 0.0f; - vp1.dvMaxY = 0.0f; - vp1.dvScaleX = 0.0f; - vp1.dvScaleY = 0.0f; - vp1.dvMinZ = viewport->viewports.vp2.dvMinZ; - vp1.dvMaxZ = viewport->viewports.vp2.dvMaxZ; + + vp1.dvScaleX = vp1.dwWidth / viewport->viewports.vp2.dvClipWidth; + vp1.dvScaleY = vp1.dwHeight / viewport->viewports.vp2.dvClipHeight; + vp1.dvMaxX = viewport->viewports.vp2.dvClipWidth + viewport->viewports.vp2.dvClipX; + vp1.dvMaxY = viewport->viewports.vp2.dvClipY; + vp1.dvMinZ = 0.0f; + vp1.dvMaxZ = 1.0f; memcpy(vp, &vp1, size); }