Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
-- v3: d2d1: Update DC target surface with current HDC contents on BeginDraw(). d2d1/tests: Add some tests for device context handling in the DC target.
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/d2d1/tests/d2d1.c | 106 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 105 insertions(+), 1 deletion(-)
diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index b2aa58d36b3..909944a8bf6 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -5952,6 +5952,7 @@ static void test_dc_target(BOOL d3d11) D2D1_ANTIALIAS_MODE aa_mode; ID2D1SolidColorBrush *brush; ID2D1RenderTarget *rt3; + D2D1_TAG tag1, tag2; FLOAT dpi_x, dpi_y; D2D1_COLOR_F color; HENHMETAFILE hemf; @@ -6152,13 +6153,116 @@ static void test_dc_target(BOOL d3d11) clr = GetPixel(hdc2, 0, 0); ok(clr == RGB(0, 0, 255), "Got unexpected colour 0x%08lx.\n", clr);
- DeleteDC(hdc); DeleteDC(hdc2);
+ /* Retaining original content. */ + SetRect(&rect, 0, 0, 16, 16); + + hr = ID2D1DCRenderTarget_BindDC(rt, hdc, &rect); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + FillRect(hdc, &rect, GetStockObject(GRAY_BRUSH)); + clr = GetPixel(hdc, 0, 0); + ok(clr == RGB(128, 128, 128), "Got unexpected colour 0x%08lx.\n", clr); + + ID2D1DCRenderTarget_BeginDraw(rt); + hr = ID2D1DCRenderTarget_EndDraw(rt, NULL, NULL); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + clr = GetPixel(hdc, 0, 0); + todo_wine + ok(clr == RGB(128, 128, 128), "Got unexpected colour 0x%08lx.\n", clr); + + /* Partially fill. */ + set_color(&color, 0.0f, 1.0f, 0.0f, 1.0f); + hr = ID2D1DCRenderTarget_CreateSolidColorBrush(rt, &color, NULL, &brush); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + ID2D1DCRenderTarget_BeginDraw(rt); + r.left = r.top = 0.0f; + r.bottom = 16.0f; + r.right = 8.0f; + ID2D1DCRenderTarget_FillRectangle(rt, &r, (ID2D1Brush *)brush); + hr = ID2D1DCRenderTarget_EndDraw(rt, NULL, NULL); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ID2D1SolidColorBrush_Release(brush); + + clr = GetPixel(hdc, 0, 0); + ok(clr == RGB(0, 255, 0), "Got unexpected colour 0x%08lx.\n", clr); + clr = GetPixel(hdc, 12, 0); + todo_wine + ok(clr == RGB(128, 128, 128), "Got unexpected colour 0x%08lx.\n", clr); + + /* Bind to a subrectangle. */ + SetRect(&rect, 0, 0, 16, 16); + FillRect(hdc, &rect, GetStockObject(GRAY_BRUSH)); + + SetRect(&rect, 8, 0, 16, 16); + hr = ID2D1DCRenderTarget_BindDC(rt, hdc, &rect); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + ID2D1DCRenderTarget_BeginDraw(rt); + hr = ID2D1DCRenderTarget_EndDraw(rt, NULL, NULL); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + clr = GetPixel(hdc, 0, 0); + ok(clr == RGB(128, 128, 128), "Got unexpected colour 0x%08lx.\n", clr); + clr = GetPixel(hdc, 12, 0); + todo_wine + ok(clr == RGB(128, 128, 128), "Got unexpected colour 0x%08lx.\n", clr); + + /* GDI-clear while drawing. */ + SetRect(&rect, 0, 0, 16, 16); + FillRect(hdc, &rect, GetStockObject(GRAY_BRUSH)); + + ID2D1DCRenderTarget_BeginDraw(rt); + FillRect(hdc, &rect, GetStockObject(LTGRAY_BRUSH)); + hr = ID2D1DCRenderTarget_EndDraw(rt, NULL, NULL); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + clr = GetPixel(hdc, 0, 0); + ok(clr == RGB(192, 192, 192), "Got unexpected colour 0x%08lx.\n", clr); + clr = GetPixel(hdc, 12, 0); + todo_wine + ok(clr == RGB(128, 128, 128), "Got unexpected colour 0x%08lx.\n", clr); + + ID2D1DCRenderTarget_Release(rt); + + /* Drawing attempt with no dc. */ + hr = ID2D1Factory_CreateDCRenderTarget(ctx.factory, &desc, &rt); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + ID2D1DCRenderTarget_SetTags(rt, 1, 2); + ID2D1DCRenderTarget_BeginDraw(rt); + ID2D1DCRenderTarget_SetTags(rt, 3, 4); + hr = ID2D1DCRenderTarget_EndDraw(rt, &tag1, &tag2); + ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#lx.\n", hr); + ok(!tag1, "Unexpected tag %s.\n", wine_dbgstr_longlong(tag1)); + ok(!tag2, "Unexpected tag %s.\n", wine_dbgstr_longlong(tag2)); + + /* Bind after BeginDraw(). */ + ID2D1DCRenderTarget_SetTags(rt, 1, 2); + ID2D1DCRenderTarget_BeginDraw(rt); + hr = ID2D1DCRenderTarget_BindDC(rt, hdc, &rect); + todo_wine + ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#lx.\n", hr); + ID2D1DCRenderTarget_SetTags(rt, 3, 4); + hr = ID2D1DCRenderTarget_EndDraw(rt, &tag1, &tag2); + todo_wine + ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#lx.\n", hr); + ok(!tag1, "Unexpected tag %s.\n", wine_dbgstr_longlong(tag1)); + ok(!tag2, "Unexpected tag %s.\n", wine_dbgstr_longlong(tag2)); + + ID2D1DCRenderTarget_Release(rt); + DeleteDC(hdc); + /* Metafile context. */ hdc = CreateMetaFileA(NULL); ok(!!hdc, "Failed to create a device context.\n");
+ hr = ID2D1Factory_CreateDCRenderTarget(ctx.factory, &desc, &rt); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + hr = ID2D1DCRenderTarget_BindDC(rt, hdc, &rect); ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
From: Hajo Nils Krabbenhöft hnk.git@hajo.me
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47165 Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/d2d1/dc_render_target.c | 12 ++++++++++++ dlls/d2d1/tests/d2d1.c | 4 ---- 2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/dlls/d2d1/dc_render_target.c b/dlls/d2d1/dc_render_target.c index adda6560deb..b09b77ff788 100644 --- a/dlls/d2d1/dc_render_target.c +++ b/dlls/d2d1/dc_render_target.c @@ -586,9 +586,21 @@ static void STDMETHODCALLTYPE d2d_dc_render_target_Clear(ID2D1DCRenderTarget *if static void STDMETHODCALLTYPE d2d_dc_render_target_BeginDraw(ID2D1DCRenderTarget *iface) { struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface); + const RECT *dst_rect = &render_target->dst_rect; + HDC hdc;
TRACE("iface %p.\n", iface);
+ if (render_target->dxgi_surface) + { + if (SUCCEEDED(IDXGISurface1_GetDC(render_target->dxgi_surface, TRUE, &hdc))) + { + BitBlt(hdc, 0, 0, dst_rect->right - dst_rect->left, dst_rect->bottom - dst_rect->top, + render_target->hdc, dst_rect->left, dst_rect->top, SRCCOPY); + IDXGISurface1_ReleaseDC(render_target->dxgi_surface, NULL); + } + } + ID2D1RenderTarget_BeginDraw(render_target->dxgi_target); }
diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 909944a8bf6..bb41d401bf3 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -6170,7 +6170,6 @@ static void test_dc_target(BOOL d3d11) ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
clr = GetPixel(hdc, 0, 0); - todo_wine ok(clr == RGB(128, 128, 128), "Got unexpected colour 0x%08lx.\n", clr);
/* Partially fill. */ @@ -6190,7 +6189,6 @@ static void test_dc_target(BOOL d3d11) clr = GetPixel(hdc, 0, 0); ok(clr == RGB(0, 255, 0), "Got unexpected colour 0x%08lx.\n", clr); clr = GetPixel(hdc, 12, 0); - todo_wine ok(clr == RGB(128, 128, 128), "Got unexpected colour 0x%08lx.\n", clr);
/* Bind to a subrectangle. */ @@ -6208,7 +6206,6 @@ static void test_dc_target(BOOL d3d11) clr = GetPixel(hdc, 0, 0); ok(clr == RGB(128, 128, 128), "Got unexpected colour 0x%08lx.\n", clr); clr = GetPixel(hdc, 12, 0); - todo_wine ok(clr == RGB(128, 128, 128), "Got unexpected colour 0x%08lx.\n", clr);
/* GDI-clear while drawing. */ @@ -6223,7 +6220,6 @@ static void test_dc_target(BOOL d3d11) clr = GetPixel(hdc, 0, 0); ok(clr == RGB(192, 192, 192), "Got unexpected colour 0x%08lx.\n", clr); clr = GetPixel(hdc, 12, 0); - todo_wine ok(clr == RGB(128, 128, 128), "Got unexpected colour 0x%08lx.\n", clr);
ID2D1DCRenderTarget_Release(rt);
This merge request was approved by Nikolay Sivov.