From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/d2d1/bitmap.c | 20 ++++++++++++++++++++ dlls/d2d1/tests/d2d1.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/dlls/d2d1/bitmap.c b/dlls/d2d1/bitmap.c index 8386f703b46..904d44cc075 100644 --- a/dlls/d2d1/bitmap.c +++ b/dlls/d2d1/bitmap.c @@ -336,6 +336,23 @@ static void d2d_bitmap_init(struct d2d_bitmap *bitmap, struct d2d_device_context } }
+static BOOL check_bitmap_options(unsigned int options) +{ + switch (options) + { + case D2D1_BITMAP_OPTIONS_NONE: + case D2D1_BITMAP_OPTIONS_TARGET: + case D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW: + case D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE: + case D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE: + case D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_CPU_READ: + return TRUE; + default: + WARN("Invalid bitmap options %#x.\n", options); + return FALSE; + } +} + HRESULT d2d_bitmap_create(struct d2d_device_context *context, D2D1_SIZE_U size, const void *src_data, UINT32 pitch, const D2D1_BITMAP_PROPERTIES1 *desc, struct d2d_bitmap **bitmap) { @@ -364,6 +381,9 @@ HRESULT d2d_bitmap_create(struct d2d_device_context *context, D2D1_SIZE_U size, return E_INVALIDARG; }
+ if (!check_bitmap_options(desc->bitmapOptions)) + return E_INVALIDARG; + texture_desc.Width = size.width; texture_desc.Height = size.height; if (!texture_desc.Width || !texture_desc.Height) diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 0069cf746bb..6f22436c892 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -11798,6 +11798,18 @@ static void test_bitmap_create(BOOL d3d11) { D2D1_BITMAP_OPTIONS_CPU_READ }, { D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE }, }; + static const struct + { + unsigned int options; + } valid_options[] = + { + { D2D1_BITMAP_OPTIONS_NONE }, + { D2D1_BITMAP_OPTIONS_TARGET }, + { D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW }, + { D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE }, + { D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE }, + { D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_CPU_READ }, + }; D2D1_BITMAP_PROPERTIES1 bitmap_desc; struct d2d1_test_context ctx; ID2D1Bitmap1 *bitmap; @@ -11820,10 +11832,25 @@ static void test_bitmap_create(BOOL d3d11) bitmap_desc.bitmapOptions = invalid_options[i].options; bitmap_desc.colorContext = NULL; hr = ID2D1DeviceContext_CreateBitmap(ctx.context, size, NULL, 0, &bitmap_desc, &bitmap); - todo_wine_if(i != 1) ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); - if (SUCCEEDED(hr)) - ID2D1Bitmap1_Release(bitmap); + + winetest_pop_context(); + } + + for (i = 0; i < ARRAY_SIZE(valid_options); ++i) + { + winetest_push_context("Test %u", i); + + set_size_u(&size, 4, 4); + bitmap_desc.dpiX = 96.0f; + bitmap_desc.dpiY = 96.0f; + bitmap_desc.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; + bitmap_desc.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE; + bitmap_desc.bitmapOptions = valid_options[i].options; + bitmap_desc.colorContext = NULL; + hr = ID2D1DeviceContext_CreateBitmap(ctx.context, size, NULL, 0, &bitmap_desc, &bitmap); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ID2D1Bitmap1_Release(bitmap);
winetest_pop_context(); }