Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/d3drm/tests/d3drm.c | 260 +++++++++++++++++++++++++++++++++++++-- dlls/d3drm/viewport.c | 26 +++- 2 files changed, 275 insertions(+), 11 deletions(-)
diff --git a/dlls/d3drm/tests/d3drm.c b/dlls/d3drm/tests/d3drm.c index 7317a316fa..01560ba1c2 100644 --- a/dlls/d3drm/tests/d3drm.c +++ b/dlls/d3drm/tests/d3drm.c @@ -6739,6 +6739,250 @@ static void test_viewport_qi(void) IDirect3DRM_Release(d3drm1); }
+static void test_viewport_configure1(void) +{ + IDirectDraw *ddraw; + IDirectDrawClipper *clipper; + IDirect3DRM *d3drm1; + IDirect3DRMFrame *frame1, *camera1; + IDirect3DRMDevice *device1; + IDirect3DViewport *d3d_viewport; + IDirect3DRMViewport *viewport1; + D3DVIEWPORT vp; + DWORD x, y, w, h; + HWND window; + GUID driver = IID_IDirect3DRGBDevice; + HRESULT hr; + RECT rc; + + /* Setup */ + window = create_window(); + GetClientRect(window, &rc); + hr = DirectDrawCreate(NULL, &ddraw, NULL); + ok(hr == D3D_OK, "Cannot create IDirectDraw interface (hr = %#x).\n", hr); + hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); + ok(hr == D3D_OK, "Failed to set cooperative level (hr = %#x).\n", hr); + hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL); + ok(hr == D3D_OK, "Cannot create clipper (hr = %#x).\n", hr); + hr = IDirectDrawClipper_SetHWnd(clipper, 0, window); + ok(hr == D3D_OK, "Cannot set HWnd to Clipper (hr = %#x)\n", hr); + hr = Direct3DRMCreate(&d3drm1); + ok(hr == D3D_OK, "Cannot get IDirect3DRM interface (hr = %#x).\n", hr); + hr = IDirect3DRM_CreateDeviceFromClipper(d3drm1, clipper, &driver, rc.right, rc.bottom, &device1); + ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice interface (hr = %#x)\n", hr); + hr = IDirect3DRM_CreateFrame(d3drm1, NULL, &frame1); + ok(hr == D3D_OK, "Cannot get IDirect3DRMFrame interface (hr = %#x)\n", hr); + hr = IDirect3DRM_CreateFrame(d3drm1, frame1, &camera1); + ok(hr == D3D_OK, "Cannot get IDirect3DRMFrame interface (hr = %#x)\n", hr); + hr = IDirect3DRM_CreateViewport(d3drm1, device1, camera1, 0, 0, rc.right, + rc.bottom, &viewport1); + ok(hr == D3D_OK, "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr); + + /* Check initial state of D3D viewport values */ + hr = IDirect3DRMViewport_GetDirect3DViewport(viewport1, &d3d_viewport); + ok(hr == D3D_OK, "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr); + vp.dwSize = sizeof(vp); + hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp); + ok(hr == D3D_OK, "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr); + ok(vp.dwX == 0, "Got unexpected viewport X position %u.\n", vp.dwX); + ok(vp.dwY == 0, "Got unexpected viewport Y position %u.\n", vp.dwY); + ok(vp.dwWidth == rc.right, "Got unexpected viewport width %u.\n", vp.dwWidth); + ok(vp.dwHeight == rc.bottom, "Got unexpected viewport height %u.\n", vp.dwHeight); + IDirect3DViewport_Release(d3d_viewport); + + /* Check initial state of X/Y/Width/Height values */ + x = IDirect3DRMViewport_GetX(viewport1); + y = IDirect3DRMViewport_GetY(viewport1); + w = IDirect3DRMViewport_GetWidth(viewport1); + h = IDirect3DRMViewport_GetHeight(viewport1); + ok(x == 0, "Got unexpected X %d.\n", x); + ok(y == 0, "Got unexpected Y %d.\n", y); + ok(w == rc.right, "Got unexpected width %d.\n", w); + ok(h == rc.bottom, "Got unexpected height %d.\n", h); + + hr = IDirect3DRMViewport_Configure(viewport1, rc.left + 10, rc.top + 10, + rc.right - 20, rc.bottom - 20); + ok(hr == D3D_OK, "Cannot configure viewport (hr = %#x).\n", hr); + + /* Verify that D3D viewport values did NOT change */ + hr = IDirect3DRMViewport_GetDirect3DViewport(viewport1, &d3d_viewport); + ok(hr == D3D_OK, "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr); + vp.dwSize = sizeof(vp); + hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp); + ok(hr == D3D_OK, "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr); + ok(vp.dwX == 0, "Got unexpected viewport X position %u.\n", vp.dwX); + ok(vp.dwY == 0, "Got unexpected viewport Y position %u.\n", vp.dwY); + ok(vp.dwWidth == rc.right, "Got unexpected viewport width %u.\n", vp.dwWidth); + ok(vp.dwHeight == rc.bottom, "Got unexpected viewport height %u.\n", vp.dwHeight); + IDirect3DViewport_Release(d3d_viewport); + + /* Verify that X/Y/Width/Height values changed */ + x = IDirect3DRMViewport_GetX(viewport1); + y = IDirect3DRMViewport_GetY(viewport1); + w = IDirect3DRMViewport_GetWidth(viewport1); + h = IDirect3DRMViewport_GetHeight(viewport1); + ok(x == rc.left + 10, "Got unexpected X %d.\n", x); + ok(y == rc.top + 10, "Got unexpected Y %d.\n", y); + ok(w == rc.right - 20, "Got unexpected width %d.\n", w); + ok(h == rc.bottom - 20, "Got unexpected height %d.\n", h); + + /* Test Configure with good values */ + hr = IDirect3DRMViewport_Configure(viewport1, rc.left, rc.top, rc.right, rc.bottom); + ok(hr == D3D_OK, "Unexpected hr %#x.\n", hr); + hr = IDirect3DRMViewport_Configure(viewport1, rc.left + 1, rc.top, rc.right - 1, rc.bottom); + ok(hr == D3D_OK, "Unexpected hr %#x.\n", hr); + hr = IDirect3DRMViewport_Configure(viewport1, rc.left, rc.top + 1, rc.right, rc.bottom - 1); + ok(hr == D3D_OK, "Unexpected hr %#x.\n", hr); + + /* Test Configure errors */ + hr = IDirect3DRMViewport_Configure(viewport1, rc.left + 1, rc.top, rc.right, rc.bottom); + ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr); + hr = IDirect3DRMViewport_Configure(viewport1, rc.left, rc.top + 1, rc.right, rc.bottom); + ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr); + hr = IDirect3DRMViewport_Configure(viewport1, rc.left, rc.top, rc.right + 1, rc.bottom); + ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr); + hr = IDirect3DRMViewport_Configure(viewport1, rc.left, rc.top, rc.right, rc.bottom + 1); + ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr); + hr = IDirect3DRMViewport_Configure(viewport1, -1, rc.top, rc.right, rc.bottom); + ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr); + hr = IDirect3DRMViewport_Configure(viewport1, rc.left, -1, rc.right, rc.bottom); + ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr); + + /* Teardown */ + IDirect3DRMViewport_Release(viewport1); + IDirect3DRMFrame_Release(frame1); + IDirect3DRMFrame_Release(camera1); + IDirect3DRMDevice_Release(device1); + IDirect3DRM_Release(d3drm1); + IDirectDrawClipper_Release(clipper); + IDirectDraw_Release(ddraw); + DestroyWindow(window); +} + +static void test_viewport_configure2(void) +{ + IDirectDraw *ddraw; + IDirectDrawClipper *clipper; + IDirect3DRM *d3drm1; + IDirect3DRM3 *d3drm3; + IDirect3DRMFrame3 *frame3, *camera3; + IDirect3DRMDevice3 *device3; + IDirect3DViewport *d3d_viewport; + IDirect3DRMViewport2 *viewport2; + D3DVIEWPORT vp; + DWORD x, y, w, h; + HWND window; + GUID driver = IID_IDirect3DRGBDevice; + HRESULT hr; + RECT rc; + + /* Setup */ + window = create_window(); + GetClientRect(window, &rc); + hr = DirectDrawCreate(NULL, &ddraw, NULL); + ok(hr == D3D_OK, "Cannot create IDirectDraw interface (hr = %#x).\n", hr); + hr = IDirectDraw_SetCooperativeLevel(ddraw, window, DDSCL_NORMAL); + ok(hr == D3D_OK, "Failed to set cooperative level (hr = %#x).\n", hr); + hr = IDirectDraw_CreateClipper(ddraw, 0, &clipper, NULL); + ok(hr == D3D_OK, "Cannot create clipper (hr = %#x).\n", hr); + hr = IDirectDrawClipper_SetHWnd(clipper, 0, window); + ok(hr == D3D_OK, "Cannot set HWnd to Clipper (hr = %#x)\n", hr); + hr = Direct3DRMCreate(&d3drm1); + ok(hr == D3D_OK, "Cannot get IDirect3DRM interface (hr = %#x).\n", hr); + hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3); + ok(hr == D3D_OK, "Cannot get IDirect3DRM3 interface (hr = %#x).\n", hr); + hr = IDirect3DRM3_CreateDeviceFromClipper(d3drm3, clipper, &driver, rc.right, rc.bottom, &device3); + ok(hr == D3DRM_OK, "Cannot get IDirect3DRMDevice3 interface (hr = %#x)\n", hr); + hr = IDirect3DRM3_CreateFrame(d3drm3, NULL, &frame3); + ok(hr == D3D_OK, "Cannot get IDirect3DRMFrame3 interface (hr = %#x)\n", hr); + hr = IDirect3DRM3_CreateFrame(d3drm3, frame3, &camera3); + ok(hr == D3D_OK, "Cannot get IDirect3DRMFrame3 interface (hr = %#x)\n", hr); + hr = IDirect3DRM3_CreateViewport(d3drm3, device3, camera3, 0, 0, rc.right, + rc.bottom, &viewport2); + ok(hr == D3D_OK, "Cannot get IDirect3DRMViewport2 interface (hr = %#x)\n", hr); + + /* Check initial state of D3D viewport values */ + hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport); + ok(hr == D3D_OK, "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr); + vp.dwSize = sizeof(vp); + hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp); + ok(hr == D3D_OK, "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr); + ok(vp.dwX == 0, "Got unexpected viewport X position %u.\n", vp.dwX); + ok(vp.dwY == 0, "Got unexpected viewport Y position %u.\n", vp.dwY); + ok(vp.dwWidth == rc.right, "Got unexpected viewport width %u.\n", vp.dwWidth); + ok(vp.dwHeight == rc.bottom, "Got unexpected viewport height %u.\n", vp.dwHeight); + IDirect3DViewport_Release(d3d_viewport); + + /* Check initial state of X/Y/Width/Height values */ + x = IDirect3DRMViewport2_GetX(viewport2); + y = IDirect3DRMViewport2_GetY(viewport2); + w = IDirect3DRMViewport2_GetWidth(viewport2); + h = IDirect3DRMViewport2_GetHeight(viewport2); + ok(x == 0, "Got unexpected X %d.\n", x); + ok(y == 0, "Got unexpected Y %d.\n", y); + ok(w == rc.right, "Got unexpected width %d.\n", w); + ok(h == rc.bottom, "Got unexpected height %d.\n", h); + + hr = IDirect3DRMViewport2_Configure(viewport2, rc.left + 10, rc.top + 10, + rc.right - 20, rc.bottom - 20); + ok(hr == D3D_OK, "Cannot configure viewport (hr = %#x).\n", hr); + + /* Verify that D3D viewport values did NOT change */ + hr = IDirect3DRMViewport2_GetDirect3DViewport(viewport2, &d3d_viewport); + ok(hr == D3D_OK, "Cannot get IDirect3DViewport interface (hr = %#x).\n", hr); + vp.dwSize = sizeof(vp); + hr = IDirect3DViewport_GetViewport(d3d_viewport, &vp); + ok(hr == D3D_OK, "Cannot get D3DVIEWPORT struct (hr = %#x).\n", hr); + ok(vp.dwX == 0, "Got unexpected viewport X position %u.\n", vp.dwX); + ok(vp.dwY == 0, "Got unexpected viewport Y position %u.\n", vp.dwY); + ok(vp.dwWidth == rc.right, "Got unexpected viewport width %u.\n", vp.dwWidth); + ok(vp.dwHeight == rc.bottom, "Got unexpected viewport height %u.\n", vp.dwHeight); + IDirect3DViewport_Release(d3d_viewport); + + /* Verify that X/Y/Width/Height values changed */ + x = IDirect3DRMViewport2_GetX(viewport2); + y = IDirect3DRMViewport2_GetY(viewport2); + w = IDirect3DRMViewport2_GetWidth(viewport2); + h = IDirect3DRMViewport2_GetHeight(viewport2); + ok(x == rc.left + 10, "Got unexpected X %d.\n", x); + ok(y == rc.top + 10, "Got unexpected Y %d.\n", y); + ok(w == rc.right - 20, "Got unexpected width %d.\n", w); + ok(h == rc.bottom - 20, "Got unexpected height %d.\n", h); + + /* Test Configure with good values */ + hr = IDirect3DRMViewport2_Configure(viewport2, rc.left, rc.top, rc.right, rc.bottom); + ok(hr == D3D_OK, "Unexpected hr %#x.\n", hr); + hr = IDirect3DRMViewport2_Configure(viewport2, rc.left + 1, rc.top, rc.right - 1, rc.bottom); + ok(hr == D3D_OK, "Unexpected hr %#x.\n", hr); + hr = IDirect3DRMViewport2_Configure(viewport2, rc.left, rc.top + 1, rc.right, rc.bottom - 1); + ok(hr == D3D_OK, "Unexpected hr %#x.\n", hr); + + /* Test Configure errors */ + hr = IDirect3DRMViewport2_Configure(viewport2, rc.left + 1, rc.top, rc.right, rc.bottom); + ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr); + hr = IDirect3DRMViewport2_Configure(viewport2, rc.left, rc.top + 1, rc.right, rc.bottom); + ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr); + hr = IDirect3DRMViewport2_Configure(viewport2, rc.left, rc.top, rc.right + 1, rc.bottom); + ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr); + hr = IDirect3DRMViewport2_Configure(viewport2, rc.left, rc.top, rc.right, rc.bottom + 1); + ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr); + hr = IDirect3DRMViewport2_Configure(viewport2, -1, rc.top, rc.right, rc.bottom); + ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr); + hr = IDirect3DRMViewport2_Configure(viewport2, rc.left, -1, rc.right, rc.bottom); + ok(hr == D3DRMERR_BADVALUE, "Unexpected hr %#x.\n", hr); + + /* Teardown */ + IDirect3DRMViewport2_Release(viewport2); + IDirect3DRMFrame3_Release(frame3); + IDirect3DRMFrame3_Release(camera3); + IDirect3DRMDevice3_Release(device3); + IDirect3DRM3_Release(d3drm3); + IDirect3DRM_Release(d3drm1); + IDirectDrawClipper_Release(clipper); + IDirectDraw_Release(ddraw); + DestroyWindow(window); +} + static D3DCOLOR get_surface_color(IDirectDrawSurface *surface, UINT x, UINT y) { RECT rect = { x, y, x + 1, y + 1 }; @@ -7083,7 +7327,7 @@ static void test_viewport_clear1(void) ok(ret_color == 0xff0000ff, "Expected scene color returned == 0xff00ff00, got %#x.\n", ret_color);
hr = IDirect3DRMViewport_Configure(viewport1, 0, 0, rc.right, rc.bottom); - todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr); + ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr); hr = IDirect3DRMViewport_Clear(viewport1); ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr); ret_color = get_surface_color(surface, 100, 200); @@ -7098,7 +7342,7 @@ static void test_viewport_clear1(void) ok(SUCCEEDED(hr), "Cannot get attached depth surface (hr = %x).\n", hr);
hr = IDirect3DRMViewport_Configure(viewport1, 0, 0, rc.right, rc.bottom); - todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr); + ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr); hr = IDirect3DRMViewport_Clear(viewport1); ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr); ret_color = get_surface_color(surface, 100, 200); @@ -7125,7 +7369,7 @@ static void test_viewport_clear1(void)
clear_depth_surface(ds, 0x7fff); hr = IDirect3DRMViewport_Configure(viewport1, 0, 0, rc.right, rc.bottom); - todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr); + ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr); hr = IDirect3DRMViewport_Clear(viewport1); ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
@@ -7309,7 +7553,7 @@ static void test_viewport_clear2(void) todo_wine ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
hr = IDirect3DRMViewport2_Configure(viewport2, 0, 0, rc.right, rc.bottom); - todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr); + ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr); hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL); ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
@@ -7337,7 +7581,7 @@ static void test_viewport_clear2(void)
/* This version of Clear still clears the depth surface even if it's deleted from the render target. */ hr = IDirect3DRMViewport2_Configure(viewport2, 0, 0, rc.right, rc.bottom); - todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr); + ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr); hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL); ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr);
@@ -7354,14 +7598,14 @@ static void test_viewport_clear2(void)
/* Clear with no flags */ hr = IDirect3DRMViewport2_Configure(viewport2, 0, 0, rc.right, rc.bottom); - todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr); + ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr); hr = IDirect3DRMViewport2_Clear(viewport2, 0); ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr); ret_color = get_surface_color(surface, 320, 240); todo_wine ok(compare_color(ret_color, 0x00bada55, 1), "Got unexpected color 0x%08x.\n", ret_color);
hr = IDirect3DRMViewport2_Configure(viewport2, 0, 0, rc.right, rc.bottom); - todo_wine ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr); + ok(SUCCEEDED(hr), "Cannot configure viewport (hr = %#x).\n", hr); hr = IDirect3DRMViewport2_Clear(viewport2, D3DRMCLEAR_ALL); ok(SUCCEEDED(hr), "Cannot clear viewport (hr = %#x).\n", hr); ret_color = get_surface_color(surface, 320, 240); @@ -8170,6 +8414,8 @@ START_TEST(d3drm) test_load_texture(); test_texture_qi(); test_viewport_qi(); + test_viewport_configure1(); + test_viewport_configure2(); test_viewport_clear1(); test_viewport_clear2(); test_create_texture_from_surface(); diff --git a/dlls/d3drm/viewport.c b/dlls/d3drm/viewport.c index 24fa198de5..4fde3206cf 100644 --- a/dlls/d3drm/viewport.c +++ b/dlls/d3drm/viewport.c @@ -691,17 +691,35 @@ static HRESULT WINAPI d3drm_viewport1_InverseTransform(IDirect3DRMViewport *ifac static HRESULT WINAPI d3drm_viewport2_Configure(IDirect3DRMViewport2 *iface, LONG x, LONG y, DWORD width, DWORD height) { - FIXME("iface %p, x %d, y %d, width %u, height %u stub!\n", iface, x, y, width, height); + struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport2(iface);
- return E_NOTIMPL; + TRACE("iface %p, x %d, y %d, width %u, height %u.\n", iface, x, y, width, height); + + if (!viewport->device) + return D3DRMERR_BADOBJECT; + + if (x < 0 || y < 0 + || FAILED(d3drm_viewport_check_device_dims(viewport->device, x, y, width, height))) + { + return D3DRMERR_BADVALUE; + } + + viewport->port.x = x; + viewport->port.y = y; + viewport->port.width = width; + viewport->port.height = height; + + return D3DRM_OK; }
static HRESULT WINAPI d3drm_viewport1_Configure(IDirect3DRMViewport *iface, LONG x, LONG y, DWORD width, DWORD height) { - FIXME("iface %p, x %d, y %d, width %u, height %u stub!\n", iface, x, y, width, height); + struct d3drm_viewport *viewport = impl_from_IDirect3DRMViewport(iface);
- return E_NOTIMPL; + TRACE("iface %p, x %d, y %d, width %u, height %u.\n", iface, x, y, width, height); + + return d3drm_viewport2_Configure(&viewport->IDirect3DRMViewport2_iface, x, y, width, height); }
static HRESULT WINAPI d3drm_viewport2_ForceUpdate(IDirect3DRMViewport2* iface,