Signed-off-by: Ziqing Hui zhui@codeweavers.com --- dlls/d2d1/tests/d2d1.c | 73 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)
diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 826526d9d38..5b72d79de0e 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -10764,6 +10764,78 @@ static void test_stroke_contains_point(BOOL d3d11) ID2D1Factory_Release(factory); }
+static void test_image_bounds(BOOL d3d11) +{ + D2D1_BITMAP_PROPERTIES bitmap_desc; + D2D_RECT_F bounds, expected_bounds; + struct d2d1_test_context ctx; + ID2D1DeviceContext *context; + ID2D1Factory1 *factory; + ID2D1Bitmap *bitmap; + D2D1_SIZE_F size; + unsigned int i; + HRESULT hr; + + const struct bitmap_bounds_test + { + float dpi_x; + float dpi_y; + D2D_SIZE_U pixel_size; + } + bitmap_bounds_tests[] = + { + {96.0f, 96.0f, {100, 100}}, + {48.0f, 48.0f, {100, 100}}, + {192.0f, 192.0f, {100, 100}}, + {96.0f, 48.0f, {100, 100}}, + {48.0f, 192.0f, {100, 100}}, + {150.0f, 150.0f, {100, 100}}, + {96.0f, 96.0f, {1, 1}}, + {192.0f, 192.0f, {1, 1}}, + }; + + if (!init_test_context(&ctx, d3d11)) + return; + + if (FAILED(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &IID_ID2D1Factory1, NULL, (void **)&factory))) + { + win_skip("ID2D1Factory1 is not supported.\n"); + release_test_context(&ctx); + return; + } + + hr = ID2D1RenderTarget_QueryInterface(ctx.rt, &IID_ID2D1DeviceContext, (void **)&context); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + for (i = 0; i < ARRAY_SIZE(bitmap_bounds_tests); ++i) + { + const struct bitmap_bounds_test *test = &bitmap_bounds_tests[i]; + winetest_push_context("Test %u", i); + + bitmap_desc.dpiX = test->dpi_x; + bitmap_desc.dpiY = test->dpi_y; + bitmap_desc.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; + bitmap_desc.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE; + hr = ID2D1RenderTarget_CreateBitmap(ctx.rt, test->pixel_size, NULL, 0, &bitmap_desc, &bitmap); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + set_rect(&bounds, 0.0f, 0.0f, 0.0f, 0.0f); + size = ID2D1Bitmap_GetSize(bitmap); + ID2D1DeviceContext_GetImageLocalBounds(context, (ID2D1Image *)bitmap, &bounds); + todo_wine ok(compare_rect(&bounds, 0.0f, 0.0f, size.width, size.height, 0), + "Got unexpected bounds {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n", + bounds.left, bounds.top, bounds.right, bounds.bottom, + expected_bounds.left, expected_bounds.top, expected_bounds.right, expected_bounds.bottom); + + ID2D1Bitmap_Release(bitmap); + winetest_pop_context(); + } + + ID2D1DeviceContext_Release(context); + ID2D1Factory1_Release(factory); + release_test_context(&ctx); +} + START_TEST(d2d1) { HMODULE d2d1_dll = GetModuleHandleA("d2d1.dll"); @@ -10835,6 +10907,7 @@ START_TEST(d2d1) queue_test(test_effect_crop); queue_test(test_effect_grayscale); queue_d3d10_test(test_stroke_contains_point); + queue_test(test_image_bounds);
run_queued_tests(); }
Signed-off-by: Ziqing Hui zhui@codeweavers.com --- dlls/d2d1/device.c | 19 ++++++++++++++++++- dlls/d2d1/tests/d2d1.c | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/dlls/d2d1/device.c b/dlls/d2d1/device.c index ea38ca41c8c..f304ec63015 100644 --- a/dlls/d2d1/device.c +++ b/dlls/d2d1/device.c @@ -1978,7 +1978,24 @@ static BOOL STDMETHODCALLTYPE d2d_device_context_IsBufferPrecisionSupported(ID2D static void STDMETHODCALLTYPE d2d_device_context_GetImageLocalBounds(ID2D1DeviceContext *iface, ID2D1Image *image, D2D1_RECT_F *local_bounds) { - FIXME("iface %p, image %p, local_bounds %p stub!\n", iface, image, local_bounds); + ID2D1Bitmap *bitmap; + D2D_SIZE_F size; + + TRACE("iface %p, image %p, local_bounds %p.\n", iface, image, local_bounds); + + if (SUCCEEDED(ID2D1Image_QueryInterface(image, &IID_ID2D1Bitmap, (void **)&bitmap))) + { + size = ID2D1Bitmap_GetSize(bitmap); + local_bounds->left = 0.0f; + local_bounds->top = 0.0f; + local_bounds->right = size.width; + local_bounds->bottom = size.height; + ID2D1Bitmap_Release(bitmap); + } + else + { + FIXME("Unable to get local bounds of image %p.\n", image); + } }
static HRESULT STDMETHODCALLTYPE d2d_device_context_GetImageWorldBounds(ID2D1DeviceContext *iface, diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 5b72d79de0e..220e84bf8f8 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -10822,7 +10822,7 @@ static void test_image_bounds(BOOL d3d11) set_rect(&bounds, 0.0f, 0.0f, 0.0f, 0.0f); size = ID2D1Bitmap_GetSize(bitmap); ID2D1DeviceContext_GetImageLocalBounds(context, (ID2D1Image *)bitmap, &bounds); - todo_wine ok(compare_rect(&bounds, 0.0f, 0.0f, size.width, size.height, 0), + ok(compare_rect(&bounds, 0.0f, 0.0f, size.width, size.height, 0), "Got unexpected bounds {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n", bounds.left, bounds.top, bounds.right, bounds.bottom, expected_bounds.left, expected_bounds.top, expected_bounds.right, expected_bounds.bottom);
On 4/7/22 11:09, Ziqing Hui wrote:
static void STDMETHODCALLTYPE d2d_device_context_GetImageLocalBounds(ID2D1DeviceContext *iface, ID2D1Image *image, D2D1_RECT_F *local_bounds) {
- FIXME("iface %p, image %p, local_bounds %p stub!\n", iface, image, local_bounds);
- ID2D1Bitmap *bitmap;
- D2D_SIZE_F size;
- TRACE("iface %p, image %p, local_bounds %p.\n", iface, image, local_bounds);
- if (SUCCEEDED(ID2D1Image_QueryInterface(image, &IID_ID2D1Bitmap, (void **)&bitmap)))
- {
size = ID2D1Bitmap_GetSize(bitmap);
local_bounds->left = 0.0f;
local_bounds->top = 0.0f;
local_bounds->right = size.width;
local_bounds->bottom = size.height;
ID2D1Bitmap_Release(bitmap);
- }
- else
- {
FIXME("Unable to get local bounds of image %p.\n", image);
- } }
According to docs, bounds are affected by context properties. Is this not the case?
OK, I think maybe you are right. I'll do more tests in the previous tests patch.
Ignore this patch set for now.
On 4/7/22 4:24 PM, Nikolay Sivov wrote:
On 4/7/22 11:09, Ziqing Hui wrote:
static void STDMETHODCALLTYPE d2d_device_context_GetImageLocalBounds(ID2D1DeviceContext *iface, ID2D1Image *image, D2D1_RECT_F *local_bounds) { - FIXME("iface %p, image %p, local_bounds %p stub!\n", iface, image, local_bounds); + ID2D1Bitmap *bitmap; + D2D_SIZE_F size;
+ TRACE("iface %p, image %p, local_bounds %p.\n", iface, image, local_bounds);
+ if (SUCCEEDED(ID2D1Image_QueryInterface(image, &IID_ID2D1Bitmap, (void **)&bitmap))) + { + size = ID2D1Bitmap_GetSize(bitmap); + local_bounds->left = 0.0f; + local_bounds->top = 0.0f; + local_bounds->right = size.width; + local_bounds->bottom = size.height; + ID2D1Bitmap_Release(bitmap); + } + else + { + FIXME("Unable to get local bounds of image %p.\n", image); + } }
According to docs, bounds are affected by context properties. Is this not the case?