Commit cabaeea5 authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

ddraw: Fix conversion of v1 viewport from v2 in d3d_viewport_GetViewport().

parent 03deff4e
......@@ -991,21 +991,21 @@ static void ViewportTest(void)
ret_vp1_data.dwSize = sizeof(vp1_data);
hr = IDirect3DViewport2_GetViewport(Viewport2, &ret_vp1_data);
ok(hr == D3D_OK, "IDirect3DViewport2_GetViewport returned %08x\n", hr);
ok(ret_vp1_data.dwX == vp2_data.dwX, "dwX is %u, expected %u\n", ret_vp1_data.dwX, vp2_data.dwX);
ok(ret_vp1_data.dwY == vp2_data.dwY, "dwY is %u, expected %u\n", ret_vp1_data.dwY, vp2_data.dwY);
ok(ret_vp1_data.dwWidth == vp2_data.dwWidth, "dwWidth is %u, expected %u\n", ret_vp1_data.dwWidth, vp2_data.dwWidth);
ok(ret_vp1_data.dwHeight == vp2_data.dwHeight, "dwHeight is %u, expected %u\n", ret_vp1_data.dwHeight, vp2_data.dwHeight);
ok(ret_vp1_data.dvMaxX == vp1_data.dvMaxX, "dvMaxX is %f, expected %f\n", ret_vp1_data.dvMaxX, vp1_data.dvMaxX);
ok(ret_vp1_data.dvMaxY == vp1_data.dvMaxY, "dvMaxY is %f, expected %f\n", ret_vp1_data.dvMaxY, vp1_data.dvMaxY);
todo_wine ok(ret_vp1_data.dvScaleX == infinity, "dvScaleX is %f, expected %f\n", ret_vp1_data.dvScaleX, infinity);
todo_wine ok(ret_vp1_data.dvScaleY == infinity, "dvScaleY is %f, expected %f\n", ret_vp1_data.dvScaleY, infinity);
todo_wine ok(ret_vp1_data.dvMinZ == 0.0, "dvMinZ is %f, expected 0.0\n", ret_vp1_data.dvMinZ);
todo_wine ok(ret_vp1_data.dvMaxZ == 1.0, "dvMaxZ is %f, expected 1.0\n", ret_vp1_data.dvMaxZ);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
ok(ret_vp1_data.dwX == vp2_data.dwX, "dwX is %u, expected %u.\n", ret_vp1_data.dwX, vp2_data.dwX);
ok(ret_vp1_data.dwY == vp2_data.dwY, "dwY is %u, expected %u.\n", ret_vp1_data.dwY, vp2_data.dwY);
ok(ret_vp1_data.dwWidth == vp2_data.dwWidth, "dwWidth is %u, expected %u.\n", ret_vp1_data.dwWidth, vp2_data.dwWidth);
ok(ret_vp1_data.dwHeight == vp2_data.dwHeight, "dwHeight is %u, expected %u.\n", ret_vp1_data.dwHeight, vp2_data.dwHeight);
ok(ret_vp1_data.dvMaxX == vp1_data.dvMaxX, "dvMaxX is %f, expected %f.\n", ret_vp1_data.dvMaxX, vp1_data.dvMaxX);
ok(ret_vp1_data.dvMaxY == vp1_data.dvMaxY, "dvMaxY is %f, expected %f.\n", ret_vp1_data.dvMaxY, vp1_data.dvMaxY);
ok(ret_vp1_data.dvScaleX == infinity, "dvScaleX is %f, expected %f.\n", ret_vp1_data.dvScaleX, infinity);
ok(ret_vp1_data.dvScaleY == infinity, "dvScaleY is %f, expected %f.\n", ret_vp1_data.dvScaleY, infinity);
ok(ret_vp1_data.dvMinZ == 0.0, "dvMinZ is %f, expected 0.0.\n", ret_vp1_data.dvMinZ);
ok(ret_vp1_data.dvMaxZ == 1.0, "dvMaxZ is %f, expected 1.0.\n", ret_vp1_data.dvMaxZ);
hr = IDirect3DViewport2_SetViewport2(Viewport2, &vp2_data);
ok(hr == D3D_OK, "IDirect3DViewport2_SetViewport2 returned %08x\n", hr);
ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
memset(&ret_vp2_data, 0xff, sizeof(ret_vp2_data));
ret_vp2_data.dwSize = sizeof(vp2_data);
......
......@@ -1591,19 +1591,19 @@ static ULONG get_refcount(IUnknown *test_iface)
static void test_viewport_object(void)
{
IDirectDraw4 *ddraw;
IDirect3D3 *d3d;
HRESULT hr, old_d3d_ref;
ULONG ref;
D3DVIEWPORT vp;
D3DVIEWPORT2 vp2;
IDirect3DViewport *viewport;
IDirect3DViewport2 *viewport2;
IDirect3DViewport3 *viewport3, *another_vp, *test_vp;
IDirectDrawGammaControl *gamma;
IDirect3DViewport2 *viewport2;
IDirect3DViewport *viewport;
IDirect3DDevice3 *device;
HRESULT hr, old_d3d_ref;
IDirectDraw4 *ddraw;
IUnknown *unknown;
D3DVIEWPORT2 vp2;
IDirect3D3 *d3d;
D3DVIEWPORT vp;
HWND window;
IDirect3DDevice3 *device;
ULONG ref;
union
{
D3DVIEWPORT2 vp2;
......@@ -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 == DD_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 == DD_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 == DD_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 == DD_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 == DD_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 == DD_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 == DD_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 == DD_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 == DD_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 == DD_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);
......@@ -1718,8 +1718,8 @@ 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(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
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(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
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 == DD_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 == DD_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 == DD_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 == DD_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 == DD_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 == DD_OK, "Got unexpected hr %#x.\n", hr);
memset(&vp, 0xff, sizeof(vp));
vp.dwSize = sizeof(vp);
hr = IDirect3DViewport3_GetViewport(viewport3, &vp);
ok(hr == DD_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 == DD_OK, "Got unexpected hr %#x.\n", hr);
memset(&vp, 0xff, sizeof(vp));
vp.dwSize = sizeof(vp);
hr = IDirect3DViewport3_GetViewport(viewport3, &vp);
ok(hr == DD_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);
......
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment