From 0a315ba0653f8de70386b2424c595621f76bd453 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Tue, 29 Aug 2017 15:13:38 +0300 Subject: [PATCH] d2d1: Fix rounding when setting scissor rectangle. Signed-off-by: Nikolay Sivov Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d2d1/render_target.c | 8 ++--- dlls/d2d1/tests/d2d1.c | 66 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/dlls/d2d1/render_target.c b/dlls/d2d1/render_target.c index 04282451480..f37565d4ee7 100644 --- a/dlls/d2d1/render_target.c +++ b/dlls/d2d1/render_target.c @@ -166,10 +166,10 @@ static void d2d_rt_draw(struct d2d_d3d_render_target *render_target, enum d2d_sh const D2D1_RECT_F *clip_rect; clip_rect = &render_target->clip_stack.stack[render_target->clip_stack.count - 1]; - scissor_rect.left = clip_rect->left + 0.5f; - scissor_rect.top = clip_rect->top + 0.5f; - scissor_rect.right = clip_rect->right + 0.5f; - scissor_rect.bottom = clip_rect->bottom + 0.5f; + scissor_rect.left = ceilf(clip_rect->left - 0.5f); + scissor_rect.top = ceilf(clip_rect->top - 0.5f); + scissor_rect.right = ceilf(clip_rect->right - 0.5f); + scissor_rect.bottom = ceilf(clip_rect->bottom - 0.5f); } else { diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index c1ca98da796..f6261295b65 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -1059,6 +1059,72 @@ static void test_clip(void) match = compare_surface(surface, "035a44d4198d6e422e9de6185b5b2c2bac5e33c9"); ok(match, "Surface does not match.\n"); + /* Fractional clip rectangle coordinates, aliased mode. */ + set_matrix_identity(&matrix); + ID2D1RenderTarget_SetTransform(rt, &matrix); + ID2D1RenderTarget_SetDpi(rt, 96.0f, 96.0f); + + ID2D1RenderTarget_BeginDraw(rt); + + set_color(&color, 0.0f, 0.0f, 0.0f, 1.0f); + ID2D1RenderTarget_Clear(rt, &color); + + scale_matrix(&matrix, 2.0f, 2.0f); + ID2D1RenderTarget_SetTransform(rt, &matrix); + set_rect(&rect, 0.0f, 0.5f, 200.0f, 100.5f); + set_color(&color, 1.0f, 0.0f, 1.0f, 1.0f); + ID2D1RenderTarget_PushAxisAlignedClip(rt, &rect, D2D1_ANTIALIAS_MODE_ALIASED); + ID2D1RenderTarget_Clear(rt, &color); + ID2D1RenderTarget_PopAxisAlignedClip(rt); + + set_matrix_identity(&matrix); + ID2D1RenderTarget_SetTransform(rt, &matrix); + set_rect(&rect, 0.0f, 0.5f, 100.0f, 200.5f); + set_color(&color, 1.0f, 0.0f, 0.0f, 1.0f); + ID2D1RenderTarget_PushAxisAlignedClip(rt, &rect, D2D1_ANTIALIAS_MODE_ALIASED); + ID2D1RenderTarget_Clear(rt, &color); + ID2D1RenderTarget_PopAxisAlignedClip(rt); + + ID2D1RenderTarget_SetTransform(rt, &matrix); + set_rect(&rect, 0.5f, 250.0f, 100.5f, 300.0f); + set_color(&color, 1.0f, 1.0f, 0.0f, 1.0f); + ID2D1RenderTarget_PushAxisAlignedClip(rt, &rect, D2D1_ANTIALIAS_MODE_ALIASED); + ID2D1RenderTarget_Clear(rt, &color); + ID2D1RenderTarget_PopAxisAlignedClip(rt); + + translate_matrix(&matrix, 0.1f, 0.0f); + ID2D1RenderTarget_SetTransform(rt, &matrix); + set_rect(&rect, 110.0f, 250.25f, 150.0f, 300.25f); + set_color(&color, 0.0f, 0.5f, 1.0f, 1.0f); + ID2D1RenderTarget_PushAxisAlignedClip(rt, &rect, D2D1_ANTIALIAS_MODE_ALIASED); + ID2D1RenderTarget_Clear(rt, &color); + ID2D1RenderTarget_PopAxisAlignedClip(rt); + + set_rect(&rect, 160.0f, 250.75f, 200.0f, 300.75f); + set_color(&color, 0.0f, 0.0f, 1.0f, 1.0f); + ID2D1RenderTarget_PushAxisAlignedClip(rt, &rect, D2D1_ANTIALIAS_MODE_ALIASED); + ID2D1RenderTarget_Clear(rt, &color); + ID2D1RenderTarget_PopAxisAlignedClip(rt); + + ID2D1RenderTarget_SetDpi(rt, 48.0f, 192.0f); + set_rect(&rect, 160.25f, 0.0f, 200.25f, 100.0f); + set_color(&color, 1.0f, 0.0f, 1.0f, 1.0f); + ID2D1RenderTarget_PushAxisAlignedClip(rt, &rect, D2D1_ANTIALIAS_MODE_ALIASED); + ID2D1RenderTarget_Clear(rt, &color); + ID2D1RenderTarget_PopAxisAlignedClip(rt); + + ID2D1RenderTarget_SetDpi(rt, 192.0f, 48.0f); + set_rect(&rect, 160.75f, 100.0f, 200.75f, 120.0f); + set_color(&color, 0.0f, 1.0f, 1.0f, 1.0f); + ID2D1RenderTarget_PushAxisAlignedClip(rt, &rect, D2D1_ANTIALIAS_MODE_ALIASED); + ID2D1RenderTarget_Clear(rt, &color); + ID2D1RenderTarget_PopAxisAlignedClip(rt); + + hr = ID2D1RenderTarget_EndDraw(rt, NULL, NULL); + ok(SUCCEEDED(hr), "Failed to end draw, hr %#x.\n", hr); + match = compare_surface(surface, "a958d1fe69ee880200d47b206948e4c1ef382748"); + ok(match, "Surface does not match.\n"); + ID2D1RenderTarget_Release(rt); IDXGISurface_Release(surface); IDXGISwapChain_Release(swapchain);