From 463d1877aeb46884358d014c68de1294c817a136 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Fri, 25 Nov 2016 10:15:24 +0300 Subject: [PATCH] d2d1: Fix GetGradientStops() when asked for more stops than collection has. Signed-off-by: Nikolay Sivov Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d2d1/brush.c | 2 -- dlls/d2d1/tests/d2d1.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/dlls/d2d1/brush.c b/dlls/d2d1/brush.c index d51f53ff535..601f40f8802 100644 --- a/dlls/d2d1/brush.c +++ b/dlls/d2d1/brush.c @@ -108,8 +108,6 @@ static void STDMETHODCALLTYPE d2d_gradient_GetGradientStops(ID2D1GradientStopCol TRACE("iface %p, stops %p, stop_count %u.\n", iface, stops, stop_count); memcpy(stops, gradient->stops, min(gradient->stop_count, stop_count) * sizeof(*stops)); - if (stop_count > gradient->stop_count) - memset(stops, 0, (stop_count - gradient->stop_count) * sizeof(*stops)); } static D2D1_GAMMA STDMETHODCALLTYPE d2d_gradient_GetColorInterpolationGamma(ID2D1GradientStopCollection *iface) diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 7fcda6418a5..a8f24f9133d 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -3475,6 +3475,65 @@ static void test_stroke_style(void) ID2D1Factory_Release(factory); } +static void test_gradient(void) +{ + ID2D1GradientStopCollection *gradient; + D2D1_GRADIENT_STOP stops[3], stops2[3]; + IDXGISwapChain *swapchain; + ID2D1RenderTarget *rt; + ID3D10Device1 *device; + IDXGISurface *surface; + D2D1_COLOR_F color; + unsigned int i; + UINT32 count; + HWND window; + HRESULT hr; + + if (!(device = create_device())) + { + skip("Failed to create device, skipping tests.\n"); + return; + } + window = CreateWindowA("static", "d2d1_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE, + 0, 0, 640, 480, NULL, NULL, NULL, NULL); + swapchain = create_swapchain(device, window, TRUE); + hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_IDXGISurface, (void **)&surface); + ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr); + rt = create_render_target(surface); + ok(!!rt, "Failed to create render target.\n"); + + stops2[0].position = 0.5f; + set_color(&stops2[0].color, 1.0f, 1.0f, 0.0f, 1.0f); + stops2[1] = stops2[0]; + hr = ID2D1RenderTarget_CreateGradientStopCollection(rt, stops2, 2, D2D1_GAMMA_2_2, + D2D1_EXTEND_MODE_CLAMP, &gradient); + ok(SUCCEEDED(hr), "Failed to create stop collection, hr %#x.\n", hr); + + count = ID2D1GradientStopCollection_GetGradientStopCount(gradient); + ok(count == 2, "Unexpected stop count %u.\n", count); + + /* Request more stops than collection has. */ + stops[0].position = 123.4f; + set_color(&stops[0].color, 1.0f, 0.5f, 0.4f, 1.0f); + color = stops[0].color; + stops[2] = stops[1] = stops[0]; + ID2D1GradientStopCollection_GetGradientStops(gradient, stops, sizeof(stops)/sizeof(stops[0])); + ok(!memcmp(stops, stops2, sizeof(*stops) * count), "Unexpected gradient stops array.\n"); + for (i = count; i < sizeof(stops)/sizeof(stops[0]); i++) + { + ok(stops[i].position == 123.4f, "%u: unexpected stop position %f.\n", i, stops[i].position); + ok(!memcmp(&stops[i].color, &color, sizeof(color)), "%u: unexpected stop color.\n", i); + } + + ID2D1GradientStopCollection_Release(gradient); + ID2D1RenderTarget_Release(rt); + + IDXGISurface_Release(surface); + IDXGISwapChain_Release(swapchain); + ID3D10Device1_Release(device); + DestroyWindow(window); +} + START_TEST(d2d1) { test_clip(); @@ -3496,4 +3555,5 @@ START_TEST(d2d1) test_bitmap_target(); test_desktop_dpi(); test_stroke_style(); + test_gradient(); } -- 2.11.4.GIT