From 1cd678d6a0638698f27f9f3e4a1f42bb566e524f Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Mon, 15 Mar 2021 10:38:15 +0300 Subject: [PATCH] d2d1: Implement d2d_geometry_group_GetBounds(). Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50411 Signed-off-by: Nikolay Sivov Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d2d1/geometry.c | 19 ++++++++++++++-- dlls/d2d1/tests/d2d1.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/dlls/d2d1/geometry.c b/dlls/d2d1/geometry.c index c32de310353..6da93de3eb4 100644 --- a/dlls/d2d1/geometry.c +++ b/dlls/d2d1/geometry.c @@ -4880,9 +4880,24 @@ static void STDMETHODCALLTYPE d2d_geometry_group_GetFactory(ID2D1GeometryGroup * static HRESULT STDMETHODCALLTYPE d2d_geometry_group_GetBounds(ID2D1GeometryGroup *iface, const D2D1_MATRIX_3X2_F *transform, D2D1_RECT_F *bounds) { - FIXME("iface %p, transform %p, bounds %p stub!.\n", iface, transform, bounds); + struct d2d_geometry *geometry = impl_from_ID2D1GeometryGroup(iface); + D2D1_RECT_F rect; + unsigned int i; - return E_NOTIMPL; + TRACE("iface %p, transform %p, bounds %p.\n", iface, transform, bounds); + + bounds->left = FLT_MAX; + bounds->top = FLT_MAX; + bounds->right = -FLT_MAX; + bounds->bottom = -FLT_MAX; + + for (i = 0; i < geometry->u.group.geometry_count; ++i) + { + if (SUCCEEDED(ID2D1Geometry_GetBounds(geometry->u.group.src_geometries[i], transform, &rect))) + d2d_rect_union(bounds, &rect); + } + + return S_OK; } static HRESULT STDMETHODCALLTYPE d2d_geometry_group_GetWidenedBounds(ID2D1GeometryGroup *iface, diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 1dc7a27ca5b..a046a21c7f6 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -9566,6 +9566,54 @@ static void test_colour_space(BOOL d3d11) } } +static void test_geometry_group(BOOL d3d11) +{ + ID2D1Factory *factory; + ID2D1GeometryGroup *group; + ID2D1Geometry *geometries[2]; + D2D1_RECT_F rect; + HRESULT hr; + D2D1_MATRIX_3X2_F matrix; + BOOL match; + + hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &IID_ID2D1Factory, NULL, (void **)&factory); + ok(SUCCEEDED(hr), "Failed to create factory, hr %#x.\n", hr); + + set_rect(&rect, -1.0f, -1.0f, 1.0f, 1.0f); + hr = ID2D1Factory_CreateRectangleGeometry(factory, &rect, (ID2D1RectangleGeometry **)&geometries[0]); + ok(SUCCEEDED(hr), "Failed to create geometry, hr %#x.\n", hr); + + set_rect(&rect, -2.0f, -2.0f, 0.0f, 2.0f); + hr = ID2D1Factory_CreateRectangleGeometry(factory, &rect, (ID2D1RectangleGeometry **)&geometries[1]); + ok(SUCCEEDED(hr), "Failed to create geometry, hr %#x.\n", hr); + + hr = ID2D1Factory_CreateGeometryGroup(factory, D2D1_FILL_MODE_ALTERNATE, geometries, 2, &group); + ok(SUCCEEDED(hr), "Failed to create geometry group, hr %#x.\n", hr); + + set_rect(&rect, 0.0f, 0.0f, 0.0f, 0.0f); + hr = ID2D1GeometryGroup_GetBounds(group, NULL, &rect); + ok(SUCCEEDED(hr), "Failed to get geometry group bounds, hr %#x.\n", hr); + match = compare_rect(&rect, -2.0f, -2.0f, 1.0f, 2.0f, 0); + ok(match, "Got unexpected rectangle {%.8e, %.8e, %.8e, %.8e}.\n", + rect.left, rect.top, rect.right, rect.bottom); + + set_matrix_identity(&matrix); + translate_matrix(&matrix, 80.0f, 640.0f); + scale_matrix(&matrix, 2.0f, 0.5f); + hr = ID2D1GeometryGroup_GetBounds(group, &matrix, &rect); + ok(SUCCEEDED(hr), "Failed to get geometry group bounds, hr %#x.\n", hr); + match = compare_rect(&rect, 76.0f, 639.0f, 82.0f, 641.0f, 0); + ok(match, "Got unexpected rectangle {%.8e, %.8e, %.8e, %.8e}.\n", + rect.left, rect.top, rect.right, rect.bottom); + + ID2D1GeometryGroup_Release(group); + + ID2D1Geometry_Release(geometries[0]); + ID2D1Geometry_Release(geometries[1]); + + ID2D1Factory_Release(factory); +} + START_TEST(d2d1) { HMODULE d2d1_dll = GetModuleHandleA("d2d1.dll"); @@ -9625,6 +9673,7 @@ START_TEST(d2d1) queue_test(test_wic_bitmap_format); queue_d3d10_test(test_math); queue_d3d10_test(test_colour_space); + queue_test(test_geometry_group); run_queued_tests(); }