From dfe1486e4b0c7fabe65fc64f70c039db90da6289 Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Fri, 10 Jul 2015 15:03:44 +0200 Subject: [PATCH] d2d1: Implement d2d_path_geometry_GetFigureCount(). --- dlls/d2d1/d2d1_private.h | 1 + dlls/d2d1/geometry.c | 12 ++++++++++-- dlls/d2d1/tests/d2d1.c | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/dlls/d2d1/d2d1_private.h b/dlls/d2d1/d2d1_private.h index 58462de353b..96507b376d2 100644 --- a/dlls/d2d1/d2d1_private.h +++ b/dlls/d2d1/d2d1_private.h @@ -205,6 +205,7 @@ struct d2d_geometry LONG refcount; enum d2d_geometry_state state; + UINT32 figure_count; }; void d2d_path_geometry_init(struct d2d_geometry *geometry) DECLSPEC_HIDDEN; diff --git a/dlls/d2d1/geometry.c b/dlls/d2d1/geometry.c index 9a94f77fe5b..4128f67880f 100644 --- a/dlls/d2d1/geometry.c +++ b/dlls/d2d1/geometry.c @@ -89,6 +89,7 @@ static void STDMETHODCALLTYPE d2d_geometry_sink_BeginFigure(ID2D1GeometrySink *i return; } geometry->state = D2D_GEOMETRY_STATE_FIGURE; + ++geometry->figure_count; } static void STDMETHODCALLTYPE d2d_geometry_sink_AddLines(ID2D1GeometrySink *iface, @@ -411,9 +412,16 @@ static HRESULT STDMETHODCALLTYPE d2d_path_geometry_GetSegmentCount(ID2D1PathGeom static HRESULT STDMETHODCALLTYPE d2d_path_geometry_GetFigureCount(ID2D1PathGeometry *iface, UINT32 *count) { - FIXME("iface %p, count %p stub!\n", iface, count); + struct d2d_geometry *geometry = impl_from_ID2D1PathGeometry(iface); - return E_NOTIMPL; + TRACE("iface %p, count %p.\n", iface, count); + + if (geometry->state != D2D_GEOMETRY_STATE_CLOSED) + return D2DERR_WRONG_STATE; + + *count = geometry->figure_count; + + return S_OK; } static const struct ID2D1PathGeometryVtbl d2d_path_geometry_vtbl = diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 8b3ffde75e5..6611385dbaf 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -884,6 +884,7 @@ static void test_path_geometry(void) IDXGISurface *surface; ID2D1Factory *factory; ULONG refcount; + UINT32 count; HWND window; HRESULT hr; @@ -904,13 +905,23 @@ static void test_path_geometry(void) /* Close() when closed. */ hr = ID2D1Factory_CreatePathGeometry(factory, &geometry); ok(SUCCEEDED(hr), "Failed to create path geometry, hr %#x.\n", hr); + hr = ID2D1PathGeometry_GetFigureCount(geometry, &count); + ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#x.\n", hr); hr = ID2D1PathGeometry_Open(geometry, &sink); ok(SUCCEEDED(hr), "Failed to open geometry sink, hr %#x.\n", hr); + hr = ID2D1PathGeometry_GetFigureCount(geometry, &count); + ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#x.\n", hr); hr = ID2D1GeometrySink_Close(sink); ok(SUCCEEDED(hr), "Failed to close geometry sink, hr %#x.\n", hr); + hr = ID2D1PathGeometry_GetFigureCount(geometry, &count); + ok(SUCCEEDED(hr), "Failed to get figure count, hr %#x.\n", hr); + ok(!count, "Got unexpected figure count %u.\n", count); hr = ID2D1GeometrySink_Close(sink); ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#x.\n", hr); ID2D1GeometrySink_Release(sink); + hr = ID2D1PathGeometry_GetFigureCount(geometry, &count); + ok(SUCCEEDED(hr), "Failed to get figure count, hr %#x.\n", hr); + ok(!count, "Got unexpected figure count %u.\n", count); ID2D1PathGeometry_Release(geometry); /* Open() when closed. */ @@ -923,6 +934,9 @@ static void test_path_geometry(void) ID2D1GeometrySink_Release(sink); hr = ID2D1PathGeometry_Open(geometry, &sink); ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#x.\n", hr); + hr = ID2D1PathGeometry_GetFigureCount(geometry, &count); + ok(SUCCEEDED(hr), "Failed to get figure count, hr %#x.\n", hr); + ok(!count, "Got unexpected figure count %u.\n", count); ID2D1PathGeometry_Release(geometry); /* Open() when open. */ @@ -935,6 +949,9 @@ static void test_path_geometry(void) hr = ID2D1GeometrySink_Close(sink); ok(SUCCEEDED(hr), "Failed to close geometry sink, hr %#x.\n", hr); ID2D1GeometrySink_Release(sink); + hr = ID2D1PathGeometry_GetFigureCount(geometry, &count); + ok(SUCCEEDED(hr), "Failed to get figure count, hr %#x.\n", hr); + ok(!count, "Got unexpected figure count %u.\n", count); ID2D1PathGeometry_Release(geometry); /* BeginFigure() without EndFigure(). */ @@ -949,6 +966,8 @@ static void test_path_geometry(void) hr = ID2D1GeometrySink_Close(sink); ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#x.\n", hr); ID2D1GeometrySink_Release(sink); + hr = ID2D1PathGeometry_GetFigureCount(geometry, &count); + ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#x.\n", hr); ID2D1PathGeometry_Release(geometry); /* EndFigure() without BeginFigure(). */ @@ -960,6 +979,8 @@ static void test_path_geometry(void) hr = ID2D1GeometrySink_Close(sink); ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#x.\n", hr); ID2D1GeometrySink_Release(sink); + hr = ID2D1PathGeometry_GetFigureCount(geometry, &count); + ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#x.\n", hr); ID2D1PathGeometry_Release(geometry); /* BeginFigure()/EndFigure() mismatch. */ @@ -989,6 +1010,23 @@ static void test_path_geometry(void) ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#x.\n", hr); ID2D1GeometrySink_AddLine(sink, point); ID2D1GeometrySink_Release(sink); + hr = ID2D1PathGeometry_GetFigureCount(geometry, &count); + ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#x.\n", hr); + ID2D1PathGeometry_Release(geometry); + + /* Empty figure. */ + hr = ID2D1Factory_CreatePathGeometry(factory, &geometry); + ok(SUCCEEDED(hr), "Failed to create path geometry, hr %#x.\n", hr); + hr = ID2D1PathGeometry_Open(geometry, &sink); + ok(SUCCEEDED(hr), "Failed to open geometry sink, hr %#x.\n", hr); + ID2D1GeometrySink_BeginFigure(sink, point, D2D1_FIGURE_BEGIN_FILLED); + ID2D1GeometrySink_EndFigure(sink, D2D1_FIGURE_END_CLOSED); + hr = ID2D1GeometrySink_Close(sink); + ok(SUCCEEDED(hr), "Failed to close geometry sink, hr %#x.\n", hr); + ID2D1GeometrySink_Release(sink); + hr = ID2D1PathGeometry_GetFigureCount(geometry, &count); + ok(SUCCEEDED(hr), "Failed to get figure count, hr %#x.\n", hr); + ok(count == 1, "Got unexpected figure count %u.\n", count); ID2D1PathGeometry_Release(geometry); ID2D1RenderTarget_Release(rt);