From 56703ff9a6ac6104e692b34544d8c3be572404de Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Thu, 4 Oct 2018 14:37:33 +0300 Subject: [PATCH] d2d1: Handle invalid interpolation mode in DrawBitmap(). Signed-off-by: Nikolay Sivov Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d2d1/device.c | 8 ++++++++ dlls/d2d1/tests/d2d1.c | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/dlls/d2d1/device.c b/dlls/d2d1/device.c index 45b22584cb5..75357b6e430 100644 --- a/dlls/d2d1/device.c +++ b/dlls/d2d1/device.c @@ -1006,6 +1006,7 @@ static void STDMETHODCALLTYPE d2d_device_context_DrawBitmap(ID2D1DeviceContext * ID2D1Bitmap *bitmap, const D2D1_RECT_F *dst_rect, float opacity, D2D1_BITMAP_INTERPOLATION_MODE interpolation_mode, const D2D1_RECT_F *src_rect) { + struct d2d_device_context *context = impl_from_ID2D1DeviceContext(iface); D2D1_BITMAP_BRUSH_PROPERTIES bitmap_brush_desc; D2D1_BRUSH_PROPERTIES brush_desc; ID2D1BitmapBrush *brush; @@ -1015,6 +1016,13 @@ static void STDMETHODCALLTYPE d2d_device_context_DrawBitmap(ID2D1DeviceContext * TRACE("iface %p, bitmap %p, dst_rect %s, opacity %.8e, interpolation_mode %#x, src_rect %s.\n", iface, bitmap, debug_d2d_rect_f(dst_rect), opacity, interpolation_mode, debug_d2d_rect_f(src_rect)); + if (interpolation_mode != D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR + && interpolation_mode != D2D1_BITMAP_INTERPOLATION_MODE_LINEAR) + { + context->error.code = E_INVALIDARG; + return; + } + if (src_rect) { s = *src_rect; diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 0bea1c80a8b..3b824709f2e 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -1815,6 +1815,19 @@ static void test_bitmap_brush(void) match = compare_surface(surface, "9437f4447d98feaad41a1c4202ee90aadc718ee6"); ok(match, "Surface does not match.\n"); + /* Invalid interpolation mode. */ + ID2D1RenderTarget_BeginDraw(rt); + + set_rect(&dst_rect, 1.0f, 8.0f, 4.0f, 12.0f); + set_rect(&src_rect, 2.0f, 1.0f, 4.0f, 3.0f); + ID2D1RenderTarget_DrawBitmap(rt, bitmap, &dst_rect, 1.0f, + D2D1_BITMAP_INTERPOLATION_MODE_LINEAR + 1, &src_rect); + + hr = ID2D1RenderTarget_EndDraw(rt, NULL, NULL); + ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr); + match = compare_surface(surface, "9437f4447d98feaad41a1c4202ee90aadc718ee6"); + ok(match, "Surface does not match.\n"); + ID2D1RenderTarget_BeginDraw(rt); ID2D1RenderTarget_Clear(rt, &color);