Jactry Zeng : d2d1: Limit source rectangle to the actual size for ID2D1RenderTarget_DrawBitmap().

Alexandre Julliard julliard at winehq.org
Fri Jan 15 15:39:45 CST 2021


Module: wine
Branch: master
Commit: 757ce04917f1f881c42bfad2c7b4b0d3586c174f
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=757ce04917f1f881c42bfad2c7b4b0d3586c174f

Author: Jactry Zeng <jzeng at codeweavers.com>
Date:   Fri Jan 15 22:55:37 2021 +0800

d2d1: Limit source rectangle to the actual size for ID2D1RenderTarget_DrawBitmap().

Signed-off-by: Jactry Zeng <jzeng at codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/d2d1/device.c     | 18 ++++++------------
 dlls/d2d1/tests/d2d1.c | 30 ++++++++++++++++++++++++++++--
 2 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/dlls/d2d1/device.c b/dlls/d2d1/device.c
index 3c8431ce8f4..b609a2c1e24 100644
--- a/dlls/d2d1/device.c
+++ b/dlls/d2d1/device.c
@@ -1072,25 +1072,19 @@ static void d2d_device_context_draw_bitmap(struct d2d_device_context *context, I
     D2D1_BITMAP_BRUSH_PROPERTIES1 bitmap_brush_desc;
     D2D1_BRUSH_PROPERTIES brush_desc;
     struct d2d_brush *brush;
+    D2D1_SIZE_F size;
     D2D1_RECT_F s, d;
     HRESULT hr;
 
     if (perspective_transform)
         FIXME("Perspective transform is ignored.\n");
 
-    if (src_rect)
+    size = ID2D1Bitmap_GetSize(bitmap);
+    d2d_rect_set(&s, 0.0f, 0.0f, size.width, size.height);
+    if (src_rect && src_rect->left <= src_rect->right
+            && src_rect->top <= src_rect->bottom)
     {
-        s = *src_rect;
-    }
-    else
-    {
-        D2D1_SIZE_F size;
-
-        size = ID2D1Bitmap_GetSize(bitmap);
-        s.left = 0.0f;
-        s.top = 0.0f;
-        s.right = size.width;
-        s.bottom = size.height;
+        d2d_rect_intersect(&s, src_rect);
     }
 
     if (dst_rect)
diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c
index d571cfe8d15..6e3bc4a51d2 100644
--- a/dlls/d2d1/tests/d2d1.c
+++ b/dlls/d2d1/tests/d2d1.c
@@ -1676,6 +1676,7 @@ static void test_bitmap_brush(void)
     IDXGISwapChain *swapchain;
     ID2D1BitmapBrush1 *brush1;
     ID2D1BitmapBrush *brush;
+    D2D1_SIZE_F image_size;
     ID2D1RenderTarget *rt;
     ID3D10Device1 *device;
     IDXGISurface *surface;
@@ -1740,6 +1741,7 @@ static void test_bitmap_brush(void)
     bitmap_desc.dpiY = 96.0f;
     hr = ID2D1RenderTarget_CreateBitmap(rt, size, bitmap_data, 4 * sizeof(*bitmap_data), &bitmap_desc, &bitmap);
     ok(SUCCEEDED(hr), "Failed to create bitmap, hr %#x.\n", hr);
+    image_size = ID2D1Bitmap_GetSize(bitmap);
 
     hr = ID2D1Bitmap_QueryInterface(bitmap, &IID_ID2D1Image, (void **)&image);
     ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Vista */, "Failed to get ID2D1Image, hr %#x.\n", hr);
@@ -1810,12 +1812,24 @@ static void test_bitmap_brush(void)
             D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, NULL);
     set_rect(&dst_rect, 0.0f, 8.0f, 4.0f, 12.0f);
     set_rect(&src_rect, 2.0f, 1.0f, 4.0f, 3.0f);
+    ID2D1RenderTarget_DrawBitmap(rt, bitmap, &dst_rect, 1.0f,
+            D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, &src_rect);
+    set_rect(&dst_rect, 4.0f, 12.0f, 12.0f, 20.0f);
+    set_rect(&src_rect, 0.0f, 0.0f, image_size.width * 2, image_size.height * 2);
+    ID2D1RenderTarget_DrawBitmap(rt, bitmap, &dst_rect, 1.0f,
+            D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, &src_rect);
+    set_rect(&dst_rect, 4.0f, 8.0f, 12.0f, 12.0f);
+    set_rect(&src_rect, image_size.width / 2, image_size.height / 2, image_size.width, image_size.height);
+    ID2D1RenderTarget_DrawBitmap(rt, bitmap, &dst_rect, 1.0f,
+            D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, &src_rect);
+    set_rect(&dst_rect, 0.0f, 4.0f, 4.0f, 8.0f);
+    set_rect(&src_rect, image_size.width, 0.0f, 0.0f, image_size.height);
     ID2D1RenderTarget_DrawBitmap(rt, bitmap, &dst_rect, 1.0f,
             D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, &src_rect);
 
     hr = ID2D1RenderTarget_EndDraw(rt, NULL, NULL);
     ok(SUCCEEDED(hr), "Failed to end draw, hr %#x.\n", hr);
-    match = compare_surface(surface, "9437f4447d98feaad41a1c4202ee90aadc718ee6");
+    match = compare_surface(surface, "f5d039c280fa33ba05496c9883192a34108efbbe");
     ok(match, "Surface does not match.\n");
 
     /* Invalid interpolation mode. */
@@ -1828,7 +1842,19 @@ static void test_bitmap_brush(void)
 
     hr = ID2D1RenderTarget_EndDraw(rt, NULL, NULL);
     ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
-    match = compare_surface(surface, "9437f4447d98feaad41a1c4202ee90aadc718ee6");
+    match = compare_surface(surface, "f5d039c280fa33ba05496c9883192a34108efbbe");
+    ok(match, "Surface does not match.\n");
+
+    ID2D1RenderTarget_BeginDraw(rt);
+    ID2D1RenderTarget_Clear(rt, &color);
+
+    set_rect(&src_rect, image_size.width, 0.0f, 0.0f, image_size.height);
+    ID2D1RenderTarget_DrawBitmap(rt, bitmap, NULL, 1.0f,
+            D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, &src_rect);
+
+    hr = ID2D1RenderTarget_EndDraw(rt, NULL, NULL);
+    ok(SUCCEEDED(hr), "Failed to end draw, hr %#x.\n", hr);
+    match = compare_surface(surface, "59043096393570ad800dbcbfdd644394b79493bd");
     ok(match, "Surface does not match.\n");
 
     ID2D1RenderTarget_BeginDraw(rt);




More information about the wine-cvs mailing list