Jactry Zeng : d2d1: Partially implement d2d_device_context_DrawImage().
Alexandre Julliard
julliard at winehq.org
Fri Jan 15 15:39:45 CST 2021
Module: wine
Branch: master
Commit: c19fc01d363e06fa9a3a19d6f5f8cbd2d6057f9e
URL: https://source.winehq.org/git/wine.git/?a=commit;h=c19fc01d363e06fa9a3a19d6f5f8cbd2d6057f9e
Author: Jactry Zeng <jzeng at codeweavers.com>
Date: Fri Jan 15 22:55:39 2021 +0800
d2d1: Partially implement d2d_device_context_DrawImage().
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 | 34 +++++++++++++++++++---
dlls/d2d1/tests/d2d1.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 108 insertions(+), 5 deletions(-)
diff --git a/dlls/d2d1/device.c b/dlls/d2d1/device.c
index e8bc7207a67..5f04c3aa833 100644
--- a/dlls/d2d1/device.c
+++ b/dlls/d2d1/device.c
@@ -1067,7 +1067,8 @@ static void STDMETHODCALLTYPE d2d_device_context_FillOpacityMask(ID2D1DeviceCont
static void d2d_device_context_draw_bitmap(struct d2d_device_context *context, ID2D1Bitmap *bitmap,
const D2D1_RECT_F *dst_rect, float opacity, D2D1_INTERPOLATION_MODE interpolation_mode,
- const D2D1_RECT_F *src_rect, const D2D1_MATRIX_4X4_F *perspective_transform)
+ const D2D1_RECT_F *src_rect, const D2D1_POINT_2F *offset,
+ const D2D1_MATRIX_4X4_F *perspective_transform)
{
D2D1_BITMAP_BRUSH_PROPERTIES1 bitmap_brush_desc;
D2D1_BRUSH_PROPERTIES brush_desc;
@@ -1102,6 +1103,14 @@ static void d2d_device_context_draw_bitmap(struct d2d_device_context *context, I
d.bottom = s.bottom - s.top;
}
+ if (offset)
+ {
+ d.left += offset->x;
+ d.top += offset->y;
+ d.right += offset->x;
+ d.bottom += offset->y;
+ }
+
bitmap_brush_desc.extendModeX = D2D1_EXTEND_MODE_CLAMP;
bitmap_brush_desc.extendModeY = D2D1_EXTEND_MODE_CLAMP;
bitmap_brush_desc.interpolationMode = interpolation_mode;
@@ -1141,7 +1150,7 @@ static void STDMETHODCALLTYPE d2d_device_context_DrawBitmap(ID2D1DeviceContext *
}
d2d_device_context_draw_bitmap(context, bitmap, dst_rect, opacity, d2d1_1_interp_mode_from_d2d1(interpolation_mode),
- src_rect, NULL);
+ src_rect, NULL, NULL);
}
static void STDMETHODCALLTYPE d2d_device_context_DrawText(ID2D1DeviceContext *iface,
@@ -2211,9 +2220,26 @@ static void STDMETHODCALLTYPE d2d_device_context_DrawImage(ID2D1DeviceContext *i
const D2D1_POINT_2F *target_offset, const D2D1_RECT_F *image_rect, D2D1_INTERPOLATION_MODE interpolation_mode,
D2D1_COMPOSITE_MODE composite_mode)
{
- FIXME("iface %p, image %p, target_offset %s, image_rect %s, interpolation_mode %#x, composite_mode %#x stub!\n",
+ struct d2d_device_context *context = impl_from_ID2D1DeviceContext(iface);
+ ID2D1Bitmap *bitmap;
+
+ TRACE("iface %p, image %p, target_offset %s, image_rect %s, interpolation_mode %#x, composite_mode %#x.\n",
iface, image, debug_d2d_point_2f(target_offset), debug_d2d_rect_f(image_rect),
interpolation_mode, composite_mode);
+
+ if (composite_mode != D2D1_COMPOSITE_MODE_SOURCE_OVER)
+ FIXME("Unhandled composite mode %#x.\n", composite_mode);
+
+ if (SUCCEEDED(ID2D1Image_QueryInterface(image, &IID_ID2D1Bitmap, (void **)&bitmap)))
+ {
+ d2d_device_context_draw_bitmap(context, bitmap, NULL, 1.0f, d2d1_1_interp_mode_from_d2d1(interpolation_mode),
+ image_rect, target_offset, NULL);
+
+ ID2D1Bitmap_Release(bitmap);
+ return;
+ }
+
+ FIXME("Unhandled image %p.\n", image);
}
static void STDMETHODCALLTYPE d2d_device_context_DrawGdiMetafile(ID2D1DeviceContext *iface,
@@ -2235,7 +2261,7 @@ static void STDMETHODCALLTYPE d2d_device_context_ID2D1DeviceContext_DrawBitmap(I
debug_d2d_rect_f(src_rect), perspective_transform);
d2d_device_context_draw_bitmap(context, bitmap, dst_rect, opacity, interpolation_mode, src_rect,
- perspective_transform);
+ NULL, perspective_transform);
}
static void STDMETHODCALLTYPE d2d_device_context_ID2D1DeviceContext_PushLayer(ID2D1DeviceContext *iface,
diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c
index 19bb94530c2..8627f5ebef6 100644
--- a/dlls/d2d1/tests/d2d1.c
+++ b/dlls/d2d1/tests/d2d1.c
@@ -1746,7 +1746,84 @@ static void test_bitmap_brush(void)
hr = ID2D1Bitmap_QueryInterface(bitmap, &IID_ID2D1Image, (void **)&image);
ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Vista */, "Failed to get ID2D1Image, hr %#x.\n", hr);
if (hr == S_OK)
- ID2D1Image_Release(image);
+ {
+ ID2D1DeviceContext *context;
+ D2D1_POINT_2F offset;
+ D2D1_RECT_F src_rect;
+
+ hr = ID2D1RenderTarget_QueryInterface(rt, &IID_ID2D1DeviceContext, (void **)&context);
+ ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
+
+ ID2D1RenderTarget_BeginDraw(rt);
+ set_color(&color, 0.0f, 0.0f, 1.0f, 1.0f);
+ ID2D1RenderTarget_Clear(rt, &color);
+
+ ID2D1RenderTarget_GetTransform(rt, &tmp_matrix);
+ set_matrix_identity(&matrix);
+ translate_matrix(&matrix, 20.0f, 12.0f);
+ scale_matrix(&matrix, 2.0f, 6.0f);
+ ID2D1RenderTarget_SetTransform(rt, &matrix);
+
+ /* Crash on Windows 7+ */
+ if (0)
+ {
+ ID2D1DeviceContext_DrawImage(context, NULL, NULL, NULL, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
+ D2D1_COMPOSITE_MODE_SOURCE_OVER);
+ }
+
+ ID2D1DeviceContext_DrawImage(context, image, NULL, NULL, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
+ D2D1_COMPOSITE_MODE_SOURCE_OVER);
+
+ set_rect(&src_rect, 0.0f, 0.0f, image_size.width, image_size.height);
+
+ ID2D1DeviceContext_DrawImage(context, image, NULL, &src_rect, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
+ D2D1_COMPOSITE_MODE_SOURCE_OVER);
+
+ offset.x = -1;
+ offset.y = -1;
+ ID2D1DeviceContext_DrawImage(context, image, &offset, NULL, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
+ D2D1_COMPOSITE_MODE_SOURCE_OVER);
+
+ offset.x = image_size.width * 2;
+ offset.y = image_size.height;
+ ID2D1DeviceContext_DrawImage(context, image, &offset, NULL, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
+ D2D1_COMPOSITE_MODE_SOURCE_OVER);
+
+ offset.x = image_size.width * 3;
+ set_rect(&src_rect, image_size.width / 2, image_size.height / 2, image_size.width, image_size.height);
+ ID2D1DeviceContext_DrawImage(context, image, &offset, &src_rect, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
+ D2D1_COMPOSITE_MODE_SOURCE_OVER);
+
+ offset.x = image_size.width * 4;
+ set_rect(&src_rect, 0.0f, 0.0f, image_size.width * 2, image_size.height * 2);
+ ID2D1DeviceContext_DrawImage(context, image, &offset, &src_rect, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
+ D2D1_COMPOSITE_MODE_SOURCE_OVER);
+
+ offset.x = image_size.width * 5;
+ set_rect(&src_rect, image_size.width, image_size.height, 0.0f, 0.0f);
+ ID2D1DeviceContext_DrawImage(context, image, &offset, &src_rect, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
+ D2D1_COMPOSITE_MODE_SOURCE_OVER);
+
+ hr = ID2D1RenderTarget_EndDraw(rt, NULL, NULL);
+ ok(SUCCEEDED(hr), "Failed to end draw, hr %#x.\n", hr);
+ match = compare_surface(surface, "95675fbc4a16404c9568d41b14e8f6be64240998");
+ ok(match, "Surface does not match.\n");
+
+ ID2D1RenderTarget_BeginDraw(rt);
+
+ offset.x = image_size.width * 6;
+ set_rect(&src_rect, 1.0f, 0.0f, 1.0f, image_size.height);
+ ID2D1DeviceContext_DrawImage(context, image, &offset, &src_rect, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR,
+ D2D1_COMPOSITE_MODE_SOURCE_OVER);
+
+ hr = ID2D1RenderTarget_EndDraw(rt, NULL, NULL);
+ ok(SUCCEEDED(hr), "Failed to end draw, hr %#x.\n", hr);
+ match = compare_surface(surface, "95675fbc4a16404c9568d41b14e8f6be64240998");
+ ok(match, "Surface does not match.\n");
+
+ ID2D1RenderTarget_SetTransform(rt, &tmp_matrix);
+ ID2D1DeviceContext_Release(context);
+ }
/* Creating a brush with a NULL bitmap crashes on Vista, but works fine on
* Windows 7+. */
More information about the wine-cvs
mailing list