From 8db1df50973abc79cfe91517354f08d8a4b95e2f Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Mon, 3 Nov 2014 08:59:38 +0100 Subject: [PATCH] d2d1: Implement d2d_gradient_GetGradientStops(). --- dlls/d2d1/brush.c | 18 ++++++++++++++++-- dlls/d2d1/d2d1_private.h | 3 ++- dlls/d2d1/render_target.c | 8 +++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/dlls/d2d1/brush.c b/dlls/d2d1/brush.c index 4d7a5ad8d9e..99b111ff33b 100644 --- a/dlls/d2d1/brush.c +++ b/dlls/d2d1/brush.c @@ -66,7 +66,10 @@ static ULONG STDMETHODCALLTYPE d2d_gradient_Release(ID2D1GradientStopCollection TRACE("%p decreasing refcount to %u.\n", iface, refcount); if (!refcount) + { + HeapFree(GetProcessHeap(), 0, gradient->stops); HeapFree(GetProcessHeap(), 0, gradient); + } return refcount; } @@ -90,7 +93,13 @@ static UINT32 STDMETHODCALLTYPE d2d_gradient_GetGradientStopCount(ID2D1GradientS static void STDMETHODCALLTYPE d2d_gradient_GetGradientStops(ID2D1GradientStopCollection *iface, D2D1_GRADIENT_STOP *stops, UINT32 stop_count) { - FIXME("iface %p, stops %p, stop_count %u stub!\n", iface, stops, stop_count); + struct d2d_gradient *gradient = impl_from_ID2D1GradientStopCollection(iface); + + 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) @@ -119,7 +128,7 @@ static const struct ID2D1GradientStopCollectionVtbl d2d_gradient_vtbl = d2d_gradient_GetExtendMode, }; -void d2d_gradient_init(struct d2d_gradient *gradient, ID2D1RenderTarget *render_target, +HRESULT d2d_gradient_init(struct d2d_gradient *gradient, ID2D1RenderTarget *render_target, const D2D1_GRADIENT_STOP *stops, UINT32 stop_count, D2D1_GAMMA gamma, D2D1_EXTEND_MODE extend_mode) { FIXME("Ignoring gradient properties.\n"); @@ -128,6 +137,11 @@ void d2d_gradient_init(struct d2d_gradient *gradient, ID2D1RenderTarget *render_ gradient->refcount = 1; gradient->stop_count = stop_count; + if (!(gradient->stops = HeapAlloc(GetProcessHeap(), 0, stop_count * sizeof(*stops)))) + return E_OUTOFMEMORY; + memcpy(gradient->stops, stops, stop_count * sizeof(*stops)); + + return S_OK; } static void d2d_brush_init(struct d2d_brush *brush, ID2D1RenderTarget *render_target, diff --git a/dlls/d2d1/d2d1_private.h b/dlls/d2d1/d2d1_private.h index 3fd3cdd7cb0..294c765425e 100644 --- a/dlls/d2d1/d2d1_private.h +++ b/dlls/d2d1/d2d1_private.h @@ -86,10 +86,11 @@ struct d2d_gradient ID2D1GradientStopCollection ID2D1GradientStopCollection_iface; LONG refcount; + D2D1_GRADIENT_STOP *stops; UINT32 stop_count; }; -void d2d_gradient_init(struct d2d_gradient *gradient, ID2D1RenderTarget *render_target, +HRESULT d2d_gradient_init(struct d2d_gradient *gradient, ID2D1RenderTarget *render_target, const D2D1_GRADIENT_STOP *stops, UINT32 stop_count, D2D1_GAMMA gamma, D2D1_EXTEND_MODE extend_mode) DECLSPEC_HIDDEN; diff --git a/dlls/d2d1/render_target.c b/dlls/d2d1/render_target.c index a50f4733eaa..035df2be195 100644 --- a/dlls/d2d1/render_target.c +++ b/dlls/d2d1/render_target.c @@ -335,6 +335,7 @@ static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateGradientStopCollect ID2D1GradientStopCollection **gradient) { struct d2d_gradient *object; + HRESULT hr; TRACE("iface %p, stops %p, stop_count %u, gamma %#x, extend_mode %#x, gradient %p.\n", iface, stops, stop_count, gamma, extend_mode, gradient); @@ -342,7 +343,12 @@ static HRESULT STDMETHODCALLTYPE d2d_d3d_render_target_CreateGradientStopCollect if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)))) return E_OUTOFMEMORY; - d2d_gradient_init(object, iface, stops, stop_count, gamma, extend_mode); + if (FAILED(hr = d2d_gradient_init(object, iface, stops, stop_count, gamma, extend_mode))) + { + WARN("Failed to initialize gradient, hr %#x.\n", hr); + HeapFree(GetProcessHeap(), 0, object); + return hr; + } TRACE("Created gradient %p.\n", object); *gradient = &object->ID2D1GradientStopCollection_iface;