From: Zhiyi Zhang <zzhang@codeweavers.com> --- dlls/d2d1/tests/d2d1.c | 126 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 644e291bb03..6225a3a6ebf 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -17822,6 +17822,131 @@ static void test_begin_end_draw(BOOL d3d11) release_test_context(&ctx); } +static void test_device_context_flush(BOOL d3d11) +{ + static const D2D1_COLOR_F white = {1.0f, 1.0f, 1.0f, 1.0f}; + D2D1_BITMAP_PROPERTIES1 bitmap_desc1; + ID2D1CommandList *command_list; + struct d2d1_test_context ctx; + ID2D1DeviceContext *context; + ID2D1Bitmap1 *bitmap1; + D2D1_TAG tag1, tag2; + D2D1_SIZE_U size; + HRESULT hr; + + if (!init_test_context(&ctx, d3d11)) + return; + + if (!ctx.factory1) + { + win_skip("Command lists are not supported.\n"); + release_test_context(&ctx); + return; + } + + context = ctx.context; + + /* Not inside BeginDraw()/EndDraw() */ + tag1 = 0xdeadbeef; + tag2 = 0xdeadbeef; + hr = ID2D1DeviceContext_Flush(context, &tag1, &tag2); + todo_wine + ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#lx.\n", hr); + todo_wine + ok(tag1 == 0, "Got unexpected tag1 %#I64x.\n", tag1); + todo_wine + ok(tag2 == 0, "Got unexpected tag2 %#I64x.\n", tag2); + + /* Flush() doesn't clear the error code when not inside BeginDraw()/EndDraw() */ + tag1 = 0xdeadbeef; + tag2 = 0xdeadbeef; + hr = ID2D1DeviceContext_Flush(context, &tag1, &tag2); + todo_wine + ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#lx.\n", hr); + todo_wine + ok(tag1 == 0, "Got unexpected tag1 %#I64x.\n", tag1); + todo_wine + ok(tag2 == 0, "Got unexpected tag2 %#I64x.\n", tag2); + + /* Inside BeginDraw()/EndDraw() */ + ID2D1DeviceContext_BeginDraw(context); + + tag1 = 0xdeadbeef; + tag2 = 0xdeadbeef; + hr = ID2D1DeviceContext_Flush(context, &tag1, &tag2); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + todo_wine + ok(tag1 == 0, "Got unexpected tag1 %#I64x.\n", tag1); + todo_wine + ok(tag2 == 0, "Got unexpected tag2 %#I64x.\n", tag2); + + hr = ID2D1DeviceContext_EndDraw(context, NULL, NULL); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + /* Command list target */ + ID2D1DeviceContext_BeginDraw(context); + hr = ID2D1DeviceContext_CreateCommandList(context, &command_list); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ID2D1DeviceContext_SetTarget(context, (ID2D1Image *)command_list); + ID2D1DeviceContext_Clear(context, &white); + + hr = ID2D1DeviceContext_Flush(context, NULL, NULL); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + hr = ID2D1CommandList_Close(command_list); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ID2D1CommandList_Release(command_list); + hr = ID2D1DeviceContext_EndDraw(context, NULL, NULL); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + /* Bitmap target */ + ID2D1DeviceContext_BeginDraw(context); + set_size_u(&size, 4, 4); + memset(&bitmap_desc1, 0, sizeof(bitmap_desc1)); + bitmap_desc1.dpiX = 96.0f; + bitmap_desc1.dpiY = 96.0f; + bitmap_desc1.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; + bitmap_desc1.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE; + bitmap_desc1.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW; + hr = ID2D1DeviceContext_CreateBitmap(context, size, NULL, 0, &bitmap_desc1, &bitmap1); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ID2D1DeviceContext_SetTarget(context, (ID2D1Image *)bitmap1); + ID2D1DeviceContext_Clear(context, &white); + + hr = ID2D1DeviceContext_Flush(context, NULL, NULL); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + ID2D1Bitmap1_Release(bitmap1); + hr = ID2D1DeviceContext_EndDraw(context, NULL, NULL); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + /* No target */ + ID2D1DeviceContext_BeginDraw(context); + ID2D1DeviceContext_SetTarget(context, NULL); + ID2D1DeviceContext_Clear(context, &white); + + hr = ID2D1DeviceContext_Flush(context, NULL, NULL); + todo_wine + ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#lx.\n", hr); + + /* The last Flush() call clears the error code */ + hr = ID2D1DeviceContext_Flush(context, NULL, NULL); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + hr = ID2D1DeviceContext_EndDraw(context, NULL, NULL); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + release_test_context(&ctx); +} + START_TEST(d2d1) { HMODULE d2d1_dll = GetModuleHandleA("d2d1.dll"); @@ -17946,6 +18071,7 @@ START_TEST(d2d1) queue_d3d10_test(test_transformed_geometry); queue_d3d10_test(test_glyph_run_world_bounds); queue_test(test_begin_end_draw); + queue_test(test_device_context_flush); run_queued_tests(); } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9961