Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/d2d1/tests/d2d1.c | 196 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 181 insertions(+), 15 deletions(-)
diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 3005b43e44..be26994b30 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -795,6 +795,8 @@ static void check_bitmap_surface_(unsigned int line, ID2D1Bitmap *bitmap, BOOL h { D3D10_TEXTURE2D_DESC desc; ID3D10Texture2D *texture; + D2D1_SIZE_U pixel_size; + DWORD bind_flags;
ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get bitmap surface, hr %#x.\n", hr); ok_(__FILE__, line)(!!surface, "Expected surface instance.\n"); @@ -805,12 +807,29 @@ static void check_bitmap_surface_(unsigned int line, ID2D1Bitmap *bitmap, BOOL h
ID3D10Texture2D_GetDesc(texture, &desc); ok_(__FILE__, line)(desc.Usage == 0, "Unexpected usage %#x.\n", desc.Usage); - ok_(__FILE__, line)(desc.BindFlags == (options & D2D1_BITMAP_OPTIONS_TARGET ? - D3D10_BIND_RENDER_TARGET : D3D10_BIND_SHADER_RESOURCE), - "Unexpected bind flags %#x, bitmap options %#x.\n", desc.BindFlags, options); + + switch (options & (D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW)) + { + case D2D1_BITMAP_OPTIONS_TARGET: + bind_flags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE; + break; + case D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW: + bind_flags = D3D10_BIND_RENDER_TARGET; + break; + default: + bind_flags = D3D10_BIND_SHADER_RESOURCE; + break; + } + + ok_(__FILE__, line)(desc.BindFlags == bind_flags, "Unexpected bind flags %#x, bitmap options %#x.\n", + desc.BindFlags, options); ok_(__FILE__, line)(desc.CPUAccessFlags == 0, "Unexpected cpu access flags %#x.\n", desc.CPUAccessFlags); ok_(__FILE__, line)(desc.MiscFlags == 0, "Unexpected misc flags %#x.\n", desc.MiscFlags);
+ pixel_size = ID2D1Bitmap_GetPixelSize(bitmap); + ok_(__FILE__, line)(desc.Width == pixel_size.width && desc.Height == pixel_size.height, + "Mismatching texture size.\n"); + ID3D10Texture2D_Release(texture);
IDXGISurface_Release(surface); @@ -5234,6 +5253,129 @@ static void test_hwnd_target(void) ID2D1Factory_Release(factory); }
+static void test_compatible_target_size(ID2D1RenderTarget *rt) +{ + float dpi_x, dpi_y, rt_dpi_x, rt_dpi_y; + ID2D1BitmapRenderTarget *bitmap_rt; + ID2D1DeviceContext *context; + D2D1_SIZE_U pixel_size; + D2D1_SIZE_F size; + HRESULT hr; + + ID2D1RenderTarget_GetDpi(rt, &rt_dpi_x, &rt_dpi_y); + + pixel_size.height = pixel_size.width = 0; + hr = ID2D1RenderTarget_CreateCompatibleRenderTarget(rt, NULL, &pixel_size, NULL, + D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE, &bitmap_rt); +todo_wine + ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr); + if (FAILED(hr)) + return; + + pixel_size = ID2D1BitmapRenderTarget_GetPixelSize(bitmap_rt); +todo_wine + ok(pixel_size.width == 0 && pixel_size.height == 0, "Unexpected target size %u x %u.\n", + pixel_size.width, pixel_size.height); + ID2D1BitmapRenderTarget_GetDpi(bitmap_rt, &dpi_x, &dpi_y); + ok(dpi_x == rt_dpi_x && dpi_y == rt_dpi_y, "Unexpected target dpi %.8e x %.8e.\n", dpi_x, dpi_y); + ID2D1BitmapRenderTarget_Release(bitmap_rt); + + pixel_size.height = pixel_size.width = 0; + size.height = size.width = 0.0f; + hr = ID2D1RenderTarget_CreateCompatibleRenderTarget(rt, &size, &pixel_size, NULL, + D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE, &bitmap_rt); + ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr); + pixel_size = ID2D1BitmapRenderTarget_GetPixelSize(bitmap_rt); +todo_wine + ok(pixel_size.width == 0 && pixel_size.height == 0, "Unexpected target size %u x %u.\n", + pixel_size.width, pixel_size.height); + ID2D1BitmapRenderTarget_GetDpi(bitmap_rt, &dpi_x, &dpi_y); + ok(dpi_x == rt_dpi_x && dpi_y == rt_dpi_y, "Unexpected target dpi %.8e x %.8e.\n", dpi_x, dpi_y); + ID2D1BitmapRenderTarget_Release(bitmap_rt); + + size.height = size.width = 0.0f; + hr = ID2D1RenderTarget_CreateCompatibleRenderTarget(rt, &size, NULL, NULL, + D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE, &bitmap_rt); + ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr); + pixel_size = ID2D1BitmapRenderTarget_GetPixelSize(bitmap_rt); +todo_wine + ok(pixel_size.width == 0 && pixel_size.height == 0, "Unexpected target size %u x %u.\n", + pixel_size.width, pixel_size.height); + ID2D1BitmapRenderTarget_GetDpi(bitmap_rt, &dpi_x, &dpi_y); + ok(dpi_x == rt_dpi_x && dpi_y == rt_dpi_y, "Unexpected target dpi %.8e x %.8e.\n", dpi_x, dpi_y); + ID2D1BitmapRenderTarget_Release(bitmap_rt); + + size.height = 1.0f; + size.width = 0.0f; + hr = ID2D1RenderTarget_CreateCompatibleRenderTarget(rt, &size, NULL, NULL, + D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE, &bitmap_rt); + ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr); + pixel_size = ID2D1BitmapRenderTarget_GetPixelSize(bitmap_rt); +todo_wine + ok(pixel_size.width == 0, "Unexpected target width %u.\n", pixel_size.width); + ok(pixel_size.height == ceilf((size.height * rt_dpi_y) / 96.0f), + "Unexpected target height %u.\n", pixel_size.height); + ID2D1BitmapRenderTarget_GetDpi(bitmap_rt, &dpi_x, &dpi_y); + ok(dpi_x == rt_dpi_x && dpi_y == rt_dpi_y, "Unexpected target dpi %.8e x %.8e.\n", dpi_x, dpi_y); + ID2D1BitmapRenderTarget_Release(bitmap_rt); + + size.height = 1.0f; + size.width = 1.0f; + hr = ID2D1RenderTarget_CreateCompatibleRenderTarget(rt, &size, NULL, NULL, + D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE, &bitmap_rt); + ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr); + pixel_size = ID2D1BitmapRenderTarget_GetPixelSize(bitmap_rt); + ok(pixel_size.width == ceilf((size.width * rt_dpi_x / 96.0f)) + && pixel_size.height == ceilf((size.height * rt_dpi_y) / 96.0f), + "Unexpected target size %u x %u.\n", pixel_size.width, pixel_size.height); + ID2D1BitmapRenderTarget_GetDpi(bitmap_rt, &dpi_x, &dpi_y); + ok(dpi_x == rt_dpi_x && dpi_y == rt_dpi_y, "Unexpected target dpi %.8e x %.8e.\n", dpi_x, dpi_y); + ID2D1BitmapRenderTarget_Release(bitmap_rt); + + size.height = size.width = 1.0f; + pixel_size.height = pixel_size.width = 1; + hr = ID2D1RenderTarget_CreateCompatibleRenderTarget(rt, &size, &pixel_size, NULL, + D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE, &bitmap_rt); + ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr); + pixel_size = ID2D1BitmapRenderTarget_GetPixelSize(bitmap_rt); + ok(pixel_size.width == 1 && pixel_size.height == 1, "Unexpected target size %u x %u.\n", + pixel_size.width, pixel_size.height); + ID2D1BitmapRenderTarget_GetDpi(bitmap_rt, &dpi_x, &dpi_y); + ok(dpi_x == 96.0f && dpi_y == 96.0f, "Unexpected target dpi %.8e x %.8e.\n", dpi_x, dpi_y); + ID2D1BitmapRenderTarget_Release(bitmap_rt); + + pixel_size.height = pixel_size.width = 0; + hr = ID2D1RenderTarget_CreateCompatibleRenderTarget(rt, NULL, &pixel_size, NULL, + D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE, &bitmap_rt); + ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr); + + pixel_size = ID2D1BitmapRenderTarget_GetPixelSize(bitmap_rt); +todo_wine + ok(pixel_size.width == 0 && pixel_size.height == 0, "Unexpected target size %u x %u.\n", + pixel_size.width, pixel_size.height); + + if (SUCCEEDED(ID2D1BitmapRenderTarget_QueryInterface(bitmap_rt, &IID_ID2D1DeviceContext, (void **)&context))) + { + ID2D1Bitmap *bitmap; + + pixel_size = ID2D1DeviceContext_GetPixelSize(context); + todo_wine + ok(pixel_size.width == 0 && pixel_size.height == 0, "Unexpected target size %u x %u.\n", + pixel_size.width, pixel_size.height); + + ID2D1DeviceContext_GetTarget(context, (ID2D1Image **)&bitmap); + pixel_size = ID2D1Bitmap_GetPixelSize(bitmap); + todo_wine + ok(pixel_size.width == 0 && pixel_size.height == 0, "Unexpected target size %u x %u.\n", + pixel_size.width, pixel_size.height); + ID2D1Bitmap_Release(bitmap); + + ID2D1DeviceContext_Release(context); + } + + ID2D1BitmapRenderTarget_Release(bitmap_rt); +} + static void test_bitmap_target(void) { D2D1_HWND_RENDER_TARGET_PROPERTIES hwnd_rt_desc; @@ -5280,6 +5422,8 @@ static void test_bitmap_target(void) hr = ID2D1Factory_CreateHwndRenderTarget(factory, &desc, &hwnd_rt_desc, &hwnd_rt); ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
+ test_compatible_target_size((ID2D1RenderTarget *)hwnd_rt); + hr = ID2D1HwndRenderTarget_CreateCompatibleRenderTarget(hwnd_rt, NULL, NULL, NULL, D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE, &rt); ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr); @@ -5393,13 +5537,15 @@ static void test_bitmap_target(void) desc.type = D2D1_RENDER_TARGET_TYPE_DEFAULT; desc.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; desc.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED; - desc.dpiX = 96.0f; + desc.dpiX = 192.0f; desc.dpiY = 96.0f; desc.usage = D2D1_RENDER_TARGET_USAGE_NONE; desc.minLevel = D2D1_FEATURE_LEVEL_DEFAULT; hr = ID2D1Factory_CreateDCRenderTarget(factory, &desc, &dc_rt); ok(SUCCEEDED(hr), "Failed to create target, hr %#x.\n", hr);
+ test_compatible_target_size((ID2D1RenderTarget *)dc_rt); + hr = ID2D1DCRenderTarget_CreateCompatibleRenderTarget(dc_rt, NULL, NULL, NULL, D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE, &rt); ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr); @@ -6748,13 +6894,13 @@ static void test_create_device(void) #define check_rt_bitmap_surface(r, s, o) check_rt_bitmap_surface_(__LINE__, r, s, o) static void check_rt_bitmap_surface_(unsigned int line, ID2D1RenderTarget *rt, BOOL has_surface, DWORD options) { + ID2D1BitmapRenderTarget *compatible_rt; D2D1_BITMAP_PROPERTIES bitmap_desc; - ID2D1RenderTarget *compatible_rt; IWICImagingFactory *wic_factory; + ID2D1Bitmap *bitmap, *bitmap2; ID2D1DeviceContext *context; ID2D1DCRenderTarget *dc_rt; IWICBitmap *wic_bitmap; - ID2D1Bitmap *bitmap; ID2D1Image *target; D2D1_SIZE_U size; HRESULT hr; @@ -6833,10 +6979,10 @@ static void check_rt_bitmap_surface_(unsigned int line, ID2D1RenderTarget *rt, B ID2D1DeviceContext_GetDevice(context, &device);
hr = ID2D1RenderTarget_CreateCompatibleRenderTarget(rt, NULL, NULL, NULL, - D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE, (ID2D1BitmapRenderTarget **)&compatible_rt); + D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE, &compatible_rt); ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create compatible render target, hr %#x.\n", hr);
- hr = ID2D1RenderTarget_QueryInterface(compatible_rt, &IID_ID2D1DeviceContext, (void **)&context2); + hr = ID2D1BitmapRenderTarget_QueryInterface(compatible_rt, &IID_ID2D1DeviceContext, (void **)&context2); ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get device context, hr %#x.\n", hr);
ID2D1DeviceContext_GetDevice(context2, &device2); @@ -6845,20 +6991,34 @@ static void check_rt_bitmap_surface_(unsigned int line, ID2D1RenderTarget *rt, B ID2D1Device_Release(device); ID2D1Device_Release(device2);
- ID2D1DeviceContext_Release(context2); - - hr = ID2D1RenderTarget_CreateBitmap(compatible_rt, size, bitmap_data, sizeof(*bitmap_data), &bitmap_desc, &bitmap); + hr = ID2D1BitmapRenderTarget_CreateBitmap(compatible_rt, size, bitmap_data, sizeof(*bitmap_data), &bitmap_desc, &bitmap); ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create bitmap, hr %#x.\n", hr); - check_bitmap_surface_(line, bitmap, has_surface, options); - ID2D1RenderTarget_Release(compatible_rt); + ID2D1Bitmap_Release(bitmap); + + hr = ID2D1BitmapRenderTarget_GetBitmap(compatible_rt, &bitmap); + ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get compatible target bitmap, hr %#x.\n", hr); + + bitmap2 = NULL; + ID2D1DeviceContext_GetTarget(context2, (ID2D1Image **)&bitmap2); + todo_wine + ok_(__FILE__, line)(bitmap2 == bitmap, "Unexpected bitmap.\n");
+ if (bitmap2) + { + check_bitmap_surface_(line, bitmap, has_surface, D2D1_BITMAP_OPTIONS_TARGET); + + ID2D1Bitmap_Release(bitmap2); + } ID2D1Bitmap_Release(bitmap); + + ID2D1BitmapRenderTarget_Release(compatible_rt); + ID2D1DeviceContext_Release(context2); } else { hr = ID2D1RenderTarget_CreateCompatibleRenderTarget(rt, NULL, NULL, NULL, - D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE, (ID2D1BitmapRenderTarget **)&compatible_rt); + D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE, &compatible_rt); todo_wine ok_(__FILE__, line)(hr == WINCODEC_ERR_UNSUPPORTEDPIXELFORMAT, "Unexpected hr %#x.\n", hr); } @@ -7024,7 +7184,13 @@ if (SUCCEEDED(hr)) hr = ID2D1Factory1_CreateDCRenderTarget(factory, &rt_desc, (ID2D1DCRenderTarget **)&rt); ok(SUCCEEDED(hr), "Failed to create target, hr %#x.\n", hr);
- check_rt_bitmap_surface(rt, FALSE, D2D1_BITMAP_OPTIONS_NONE); + hr = ID2D1RenderTarget_QueryInterface(rt, &IID_ID2D1DeviceContext, (void **)&device_context); + ok(SUCCEEDED(hr), "Failed to get device context, hr %#x.\n", hr); + + ID2D1DeviceContext_GetTarget(device_context, (ID2D1Image **)&bitmap); + ok(!bitmap, "Unexpected target.\n"); + + ID2D1DeviceContext_Release(device_context); ID2D1RenderTarget_Release(rt);
/* HWND target */
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/d2d1/device.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/dlls/d2d1/device.c b/dlls/d2d1/device.c index be31ecafc8..d1c1845171 100644 --- a/dlls/d2d1/device.c +++ b/dlls/d2d1/device.c @@ -1783,10 +1783,17 @@ static HRESULT STDMETHODCALLTYPE d2d_device_context_ID2D1DeviceContext_CreateBit D2D1_SIZE_U size, const void *src_data, UINT32 pitch, const D2D1_BITMAP_PROPERTIES1 *desc, ID2D1Bitmap1 **bitmap) { - FIXME("iface %p, size {%u, %u}, src_data %p, pitch %u, desc %p, bitmap %p stub!\n", + struct d2d_device_context *context = impl_from_ID2D1DeviceContext(iface); + struct d2d_bitmap *object; + HRESULT hr; + + TRACE("iface %p, size {%u, %u}, src_data %p, pitch %u, desc %p, bitmap %p.\n", iface, size.width, size.height, src_data, pitch, desc, bitmap);
- return E_NOTIMPL; + if (SUCCEEDED(hr = d2d_bitmap_create(context, size, src_data, pitch, desc, &object))) + *bitmap = &object->ID2D1Bitmap1_iface; + + return hr; }
static HRESULT STDMETHODCALLTYPE d2d_device_context_ID2D1DeviceContext_CreateBitmapFromWicBitmap(
Signed-off-by: Henri Verbeet hverbeet@codeweavers.com
On 27 September 2018 at 17:47, Nikolay Sivov nsivov@codeweavers.com wrote:
+static void test_compatible_target_size(ID2D1RenderTarget *rt) +{
- float dpi_x, dpi_y, rt_dpi_x, rt_dpi_y;
- ID2D1BitmapRenderTarget *bitmap_rt;
- ID2D1DeviceContext *context;
- D2D1_SIZE_U pixel_size;
- D2D1_SIZE_F size;
- HRESULT hr;
- ID2D1RenderTarget_GetDpi(rt, &rt_dpi_x, &rt_dpi_y);
- pixel_size.height = pixel_size.width = 0;
- hr = ID2D1RenderTarget_CreateCompatibleRenderTarget(rt, NULL, &pixel_size, NULL,
D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_NONE, &bitmap_rt);
+todo_wine
- ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
- if (FAILED(hr))
return;
I'd typically suggest to use ok_() for helpers like this one. In this case, that doesn't help a lot for the "target dpi" tests though. Any chance you could make those table-driven and then prefix the ok-message with the index?