diff --git a/dlls/d2d1/bitmap.c b/dlls/d2d1/bitmap.c index 1cba26f5ca4..316d0f25ad6 100644 --- a/dlls/d2d1/bitmap.c +++ b/dlls/d2d1/bitmap.c @@ -544,15 +544,23 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid, goto failed; } - if (!desc) + if (desc) + { + d = *desc; + if (d.pixelFormat.format == DXGI_FORMAT_UNKNOWN) + d.pixelFormat.format = src_impl->format.format; + if (d.pixelFormat.alphaMode == D2D1_ALPHA_MODE_UNKNOWN) + d.pixelFormat.alphaMode = src_impl->format.alphaMode; + } + else { d.pixelFormat = src_impl->format; d.dpiX = src_impl->dpi_x; d.dpiY = src_impl->dpi_y; d.bitmapOptions = src_impl->options; d.colorContext = NULL; - desc = &d; } + desc = &d; if (!format_supported(&desc->pixelFormat)) { diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 1935955ec84..47efba66447 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -5254,6 +5254,68 @@ static void test_shared_bitmap(BOOL d3d11) } } + ID2D1Bitmap_Release(bitmap1); + + /* Create from another bitmap, with a different description. */ + set_size_u(&size, 4, 4); + bitmap_desc.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; + bitmap_desc.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED; + bitmap_desc.dpiX = 96.0f; + bitmap_desc.dpiY = 96.0f; + hr = ID2D1RenderTarget_CreateBitmap(rt2, size, NULL, 0, &bitmap_desc, &bitmap1); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + if (SUCCEEDED(hr)) + { + static const struct bitmap_format_test + { + D2D1_PIXEL_FORMAT original; + D2D1_PIXEL_FORMAT result; + HRESULT hr; + } + bitmap_format_tests[] = + { + { { DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_PREMULTIPLIED }, + { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED } }, + + { { DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_IGNORE }, + { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE } }, + + { { DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_UNKNOWN }, + { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED } }, + + { { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_UNKNOWN }, + { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED } }, + + { { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE }, + { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE } }, + + { { DXGI_FORMAT_UNKNOWN, D2D1_ALPHA_MODE_STRAIGHT }, { 0 }, D2DERR_UNSUPPORTED_PIXEL_FORMAT }, + { { DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_STRAIGHT }, { 0 }, D2DERR_UNSUPPORTED_PIXEL_FORMAT }, + }; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(bitmap_format_tests); ++i) + { + bitmap_desc.pixelFormat = bitmap_format_tests[i].original; + + hr = ID2D1RenderTarget_CreateSharedBitmap(rt2, &IID_ID2D1Bitmap, bitmap1, &bitmap_desc, &bitmap2); + ok(hr == bitmap_format_tests[i].hr, "%u: Got unexpected hr %#lx.\n", i, hr); + + if (SUCCEEDED(hr) && hr == bitmap_format_tests[i].hr) + { + pixel_format = ID2D1Bitmap_GetPixelFormat(bitmap2); + ok(pixel_format.format == bitmap_format_tests[i].result.format, "%u: unexpected pixel format %#x.\n", + i, pixel_format.format); + ok(pixel_format.alphaMode == bitmap_format_tests[i].result.alphaMode, "%u: unexpected alpha mode %d.\n", + i, pixel_format.alphaMode); + } + + if (SUCCEEDED(hr)) + ID2D1Bitmap_Release(bitmap2); + } + } + ID2D1RenderTarget_Release(rt2); ID2D1Bitmap_Release(bitmap1);