From: Akihiro Sagawa Subject: [PATCH 3/3] d2d1: Improve DPI value handling when creating from a bitmap. Message-Id: <20191006235448.509C.375B48EC@gmail.com> Date: Sun, 06 Oct 2019 23:57:33 +0900 Signed-off-by: Akihiro Sagawa --- dlls/d2d1/bitmap.c | 18 ++++++++++++++---- dlls/d2d1/tests/d2d1.c | 10 ++++------ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/dlls/d2d1/bitmap.c b/dlls/d2d1/bitmap.c index dc5ed9e..dcfab16 100644 --- a/dlls/d2d1/bitmap.c +++ b/dlls/d2d1/bitmap.c @@ -313,6 +313,7 @@ HRESULT d2d_bitmap_create(struct d2d_device_context *context, D2D1_SIZE_U size, UINT32 pitch, const D2D1_BITMAP_PROPERTIES1 *desc, struct d2d_bitmap **bitmap) { D3D10_SUBRESOURCE_DATA resource_data; + D2D1_BITMAP_PROPERTIES1 bitmap_desc; D3D10_TEXTURE2D_DESC texture_desc; ID3D10Texture2D *texture; HRESULT hr; @@ -324,6 +325,15 @@ HRESULT d2d_bitmap_create(struct d2d_device_context *context, D2D1_SIZE_U size, return D2DERR_UNSUPPORTED_PIXEL_FORMAT; } + bitmap_desc = *desc; + if (bitmap_desc.dpiX == 0.0f && bitmap_desc.dpiY == 0.0f) + { + bitmap_desc.dpiX = context->desc.dpiX; + bitmap_desc.dpiY = context->desc.dpiY; + } + else if (bitmap_desc.dpiX <= 0.0f || bitmap_desc.dpiY <= 0.0f) + return E_INVALIDARG; + texture_desc.Width = size.width; texture_desc.Height = size.height; if (!texture_desc.Width || !texture_desc.Height) @@ -335,13 +345,13 @@ HRESULT d2d_bitmap_create(struct d2d_device_context *context, D2D1_SIZE_U size, texture_desc.SampleDesc.Quality = 0; texture_desc.Usage = D3D10_USAGE_DEFAULT; texture_desc.BindFlags = 0; - if (desc->bitmapOptions & D2D1_BITMAP_OPTIONS_TARGET) + if (bitmap_desc.bitmapOptions & D2D1_BITMAP_OPTIONS_TARGET) texture_desc.BindFlags |= D3D10_BIND_RENDER_TARGET; - if (!(desc->bitmapOptions & D2D1_BITMAP_OPTIONS_CANNOT_DRAW)) + if (!(bitmap_desc.bitmapOptions & D2D1_BITMAP_OPTIONS_CANNOT_DRAW)) texture_desc.BindFlags |= D3D10_BIND_SHADER_RESOURCE; texture_desc.CPUAccessFlags = 0; texture_desc.MiscFlags = 0; - if (desc->bitmapOptions & D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE) + if (bitmap_desc.bitmapOptions & D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE) texture_desc.MiscFlags |= D3D10_RESOURCE_MISC_GDI_COMPATIBLE; resource_data.pSysMem = src_data; @@ -356,7 +366,7 @@ HRESULT d2d_bitmap_create(struct d2d_device_context *context, D2D1_SIZE_U size, if ((*bitmap = heap_alloc_zero(sizeof(**bitmap)))) { - d2d_bitmap_init(*bitmap, context, (ID3D10Resource *)texture, size, desc); + d2d_bitmap_init(*bitmap, context, (ID3D10Resource *)texture, size, &bitmap_desc); TRACE("Created bitmap %p.\n", *bitmap); } ID3D10Texture2D_Release(texture); diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 4a20a7b..9f6cf4e 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -8176,7 +8176,6 @@ static void test_device_context_target(void) &bitmap_desc, &bitmap); IWICBitmapSource_Release(wic_bitmap_src); - todo_wine_if(FAILED(create_dpi_tests[i].hr)) ok(hr == create_dpi_tests[i].hr, "Wrong return code, hr %#x, expected %#x, test %u.\n", hr, create_dpi_tests[i].hr, i); @@ -8189,9 +8188,9 @@ static void test_device_context_target(void) if (bitmap_desc.dpiX == 0.0f && bitmap_desc.dpiY == 0.0f) { /* Bitmap DPI values are inherited at creation time. */ - todo_wine ok(dpi_x == init_dpi_x, "Wrong dpi_x %.8e, expected %.8e, test %u\n", + ok(dpi_x == init_dpi_x, "Wrong dpi_x %.8e, expected %.8e, test %u\n", dpi_x, init_dpi_x, i); - todo_wine ok(dpi_y == init_dpi_y, "Wrong dpi_y %.8e, expected %.8e, test %u\n", + ok(dpi_y == init_dpi_y, "Wrong dpi_y %.8e, expected %.8e, test %u\n", dpi_y, init_dpi_y, i); } else @@ -8235,7 +8234,6 @@ static void test_device_context_target(void) hr = ID2D1DeviceContext_CreateBitmap(device_context, size, NULL, 0, &bitmap_desc, &bitmap); - todo_wine_if(FAILED(create_dpi_tests[i].hr)) ok(hr == create_dpi_tests[i].hr, "Wrong return code, hr %#x, expected %#x, test %u.\n", hr, create_dpi_tests[i].hr, i); @@ -8248,9 +8246,9 @@ static void test_device_context_target(void) if (bitmap_desc.dpiX == 0.0f && bitmap_desc.dpiY == 0.0f) { /* Bitmap DPI values are inherited at creation time. */ - todo_wine ok(dpi_x == init_dpi_x, "Wrong dpi_x %.8e, expected %.8e, test %u\n", + ok(dpi_x == init_dpi_x, "Wrong dpi_x %.8e, expected %.8e, test %u\n", dpi_x, init_dpi_x, i); - todo_wine ok(dpi_y == init_dpi_y, "Wrong dpi_y %.8e, expected %.8e, test %u\n", + ok(dpi_y == init_dpi_y, "Wrong dpi_y %.8e, expected %.8e, test %u\n", dpi_y, init_dpi_y, i); } else