Signed-off-by: Ziqing Hui zhui@codeweavers.com ---
v2: Test changing context dpi and unit mode.
dlls/d2d1/tests/d2d1.c | 94 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+)
diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 826526d9d38..cd068f78bfa 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -10764,6 +10764,99 @@ static void test_stroke_contains_point(BOOL d3d11) ID2D1Factory_Release(factory); }
+static void test_image_bounds(BOOL d3d11) +{ + D2D1_BITMAP_PROPERTIES bitmap_desc; + struct d2d1_test_context ctx; + ID2D1DeviceContext *context; + D2D1_UNIT_MODE unit_mode; + ID2D1Factory1 *factory; + ID2D1Bitmap *bitmap; + float dpi_x, dpi_y; + D2D_RECT_F bounds; + 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, 10.0f, {100, 100}}, + {50.0f, 100.0f, {100, 100}}, + {150.0f, 150.0f, {100, 100}}, + {48.0f, 48.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, 0.0f, 0.0f, size.width, size.height); + + /* Test bitmap local bounds after changing context dpi */ + ID2D1DeviceContext_GetDpi(context, &dpi_x, &dpi_y); + ID2D1DeviceContext_SetDpi(context, dpi_x * 2.0f, dpi_y * 2.0f); + 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, 0.0f, 0.0f, size.width, size.height); + ID2D1DeviceContext_SetDpi(context, dpi_x, dpi_y); + + /* Test bitmap local bounds after changing context unit mode */ + unit_mode = ID2D1DeviceContext_GetUnitMode(context); + ok(unit_mode == D2D1_UNIT_MODE_DIPS, "Got unexpected unit mode %#x.\n", unit_mode); + ID2D1DeviceContext_SetUnitMode(context, D2D1_UNIT_MODE_PIXELS); + ID2D1DeviceContext_GetImageLocalBounds(context, (ID2D1Image *)bitmap, &bounds); + todo_wine ok(compare_rect(&bounds, 0.0f, 0.0f, test->pixel_size.width, test->pixel_size.height, 0), + "Got unexpected bounds {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n", + bounds.left, bounds.top, bounds.right, bounds.bottom, 0.0f, 0.0f, + (float)test->pixel_size.width, (float)test->pixel_size.height); + ID2D1DeviceContext_SetUnitMode(context, unit_mode); + + 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 +10928,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 ---
v2: Consider context unit mode.
dlls/d2d1/device.c | 36 +++++++++++++++++++++++++++++++++++- dlls/d2d1/tests/d2d1.c | 7 ++++--- 2 files changed, 39 insertions(+), 4 deletions(-)
diff --git a/dlls/d2d1/device.c b/dlls/d2d1/device.c index ea38ca41c8c..43c65ebddc1 100644 --- a/dlls/d2d1/device.c +++ b/dlls/d2d1/device.c @@ -1978,7 +1978,41 @@ 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); + struct d2d_device_context *context = impl_from_ID2D1DeviceContext(iface); + D2D_SIZE_U pixel_size; + 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))) + { + local_bounds->left = 0.0f; + local_bounds->top = 0.0f; + switch (context->drawing_state.unitMode) + { + case D2D1_UNIT_MODE_DIPS: + size = ID2D1Bitmap_GetSize(bitmap); + local_bounds->right = size.width; + local_bounds->bottom = size.height; + break; + + case D2D1_UNIT_MODE_PIXELS: + pixel_size = ID2D1Bitmap_GetPixelSize(bitmap); + local_bounds->right = pixel_size.width; + local_bounds->bottom = pixel_size.height; + break; + + default: + WARN("Unknown unit mode %#x.\n", context->drawing_state.unitMode); + break; + } + 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 cd068f78bfa..e412459ebf2 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -10824,7 +10824,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, 0.0f, 0.0f, size.width, size.height);
@@ -10832,7 +10832,7 @@ static void test_image_bounds(BOOL d3d11) ID2D1DeviceContext_GetDpi(context, &dpi_x, &dpi_y); ID2D1DeviceContext_SetDpi(context, dpi_x * 2.0f, dpi_y * 2.0f); 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, 0.0f, 0.0f, size.width, size.height); ID2D1DeviceContext_SetDpi(context, dpi_x, dpi_y); @@ -10842,7 +10842,8 @@ static void test_image_bounds(BOOL d3d11) ok(unit_mode == D2D1_UNIT_MODE_DIPS, "Got unexpected unit mode %#x.\n", unit_mode); ID2D1DeviceContext_SetUnitMode(context, D2D1_UNIT_MODE_PIXELS); ID2D1DeviceContext_GetImageLocalBounds(context, (ID2D1Image *)bitmap, &bounds); - todo_wine ok(compare_rect(&bounds, 0.0f, 0.0f, test->pixel_size.width, test->pixel_size.height, 0), + todo_wine_if(!compare_float(test->dpi_x, 96.0f, 0) || !compare_float(test->dpi_y, 96.0f, 0)) + ok(compare_rect(&bounds, 0.0f, 0.0f, test->pixel_size.width, test->pixel_size.height, 0), "Got unexpected bounds {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n", bounds.left, bounds.top, bounds.right, bounds.bottom, 0.0f, 0.0f, (float)test->pixel_size.width, (float)test->pixel_size.height);
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=112286
Your paranoid android.
=== debian11 (32 bit report) ===
Report validation errors: d2d1:d2d1 prints too much data (34918 bytes)
=== debian11 (32 bit Arabic:Morocco report) ===
Report validation errors: d2d1:d2d1 prints too much data (34918 bytes)
=== debian11 (32 bit German report) ===
Report validation errors: d2d1:d2d1 prints too much data (34918 bytes)
=== debian11 (32 bit French report) ===
Report validation errors: d2d1:d2d1 prints too much data (34918 bytes)
=== debian11 (32 bit Hebrew:Israel report) ===
Report validation errors: d2d1:d2d1 prints too much data (34918 bytes)
=== debian11 (32 bit Hindi:India report) ===
Report validation errors: d2d1:d2d1 prints too much data (34918 bytes)
=== debian11 (32 bit Japanese:Japan report) ===
Report validation errors: d2d1:d2d1 prints too much data (34918 bytes)
=== debian11 (32 bit Chinese:China report) ===
Report validation errors: d2d1:d2d1 prints too much data (34918 bytes)
=== debian11 (32 bit WoW report) ===
Report validation errors: d2d1:d2d1 prints too much data (34918 bytes)
=== debian11 (64 bit WoW report) ===
d2d1: d2d1.c:6854: Test failed: Test 4: Got unexpected hr 0x88990029.
Report validation errors: d2d1:d2d1 prints too much data (34854 bytes)