From: Dmitry Timoshkov dmitry@baikal.ru
Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/d2d1/tests/d2d1.c | 206 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+)
diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index d5fa6f26e4d..0319b146ff2 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -11584,6 +11584,211 @@ static void test_image_bounds(BOOL d3d11) release_test_context(&ctx); }
+static void test_bitmap_map(BOOL d3d11) +{ + static const struct + { + unsigned int options; + } invalid_map_options[] = + { + { D2D1_BITMAP_OPTIONS_NONE }, + { D2D1_BITMAP_OPTIONS_TARGET }, + { D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_TARGET }, + { D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE }, + }; + static const struct + { + unsigned int options; + } valid_map_options[] = + { + { D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_CPU_READ }, + }; + D2D1_BITMAP_PROPERTIES1 bitmap_desc; + D3D11_TEXTURE2D_DESC texture_desc; + struct d2d1_test_context ctx; + D2D1_MAPPED_RECT mapped_rect; + ID3D11Device *d3d_device; + ID3D11Texture2D *texture; + IDXGISurface *surface; + ID2D1Bitmap1 *bitmap; + D2D1_SIZE_U size; + unsigned int i; + HRESULT hr; + + if (!init_test_context(&ctx, d3d11)) + return; + + for (i = 0; i < ARRAY_SIZE(invalid_map_options); ++i) + { + winetest_push_context("Test %u", i); + + set_size_u(&size, 4, 4); + bitmap_desc.dpiX = 96.0f; + bitmap_desc.dpiY = 96.0f; + bitmap_desc.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; + bitmap_desc.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE; + bitmap_desc.bitmapOptions = invalid_map_options[i].options; + bitmap_desc.colorContext = NULL; + hr = ID2D1DeviceContext_CreateBitmap(ctx.context, size, NULL, 0, &bitmap_desc, &bitmap); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_NONE, &mapped_rect); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_READ, &mapped_rect); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_WRITE, &mapped_rect); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + + hr = ID2D1Bitmap1_GetSurface(bitmap, &surface); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDXGISurface_QueryInterface(surface, &IID_ID3D11Texture2D, (void **)&texture); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ID3D11Texture2D_GetDesc(texture, &texture_desc); + ok(!texture_desc.CPUAccessFlags, "Unexpected CPU access flags %#x.\n", texture_desc.CPUAccessFlags); + ID3D11Texture2D_Release(texture); + IDXGISurface_Release(surface); + + ID2D1Bitmap1_Release(bitmap); + + winetest_pop_context(); + } + + for (i = 0; i < ARRAY_SIZE(valid_map_options); ++i) + { + winetest_push_context("Test %u", i); + + set_size_u(&size, 4, 4); + bitmap_desc.dpiX = 96.0f; + bitmap_desc.dpiY = 96.0f; + bitmap_desc.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; + bitmap_desc.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE; + bitmap_desc.bitmapOptions = valid_map_options[i].options; + bitmap_desc.colorContext = NULL; + hr = ID2D1DeviceContext_CreateBitmap(ctx.context, size, NULL, 0, &bitmap_desc, &bitmap); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_NONE, &mapped_rect); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_READ, &mapped_rect); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_READ, &mapped_rect); + todo_wine + ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#lx.\n", hr); + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_WRITE, &mapped_rect); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + + hr = ID2D1Bitmap1_Unmap(bitmap); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + hr = ID2D1Bitmap1_Unmap(bitmap); + todo_wine + ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#lx.\n", hr); + + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_WRITE, &mapped_rect); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_READ | D2D1_MAP_OPTIONS_DISCARD, &mapped_rect); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_WRITE | D2D1_MAP_OPTIONS_DISCARD, &mapped_rect); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_READ | D2D1_MAP_OPTIONS_WRITE, &mapped_rect); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + + hr = ID2D1Bitmap1_GetSurface(bitmap, &surface); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + hr = IDXGISurface_QueryInterface(surface, &IID_ID3D11Texture2D, (void **)&texture); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ID3D11Texture2D_GetDesc(texture, &texture_desc); + todo_wine + ok(texture_desc.Usage == D3D11_USAGE_STAGING, "Unexpected usage %u.\n", texture_desc.Usage); + ok(!texture_desc.BindFlags, "Unexpected bind flags %#x.\n", texture_desc.BindFlags); + todo_wine + ok(texture_desc.CPUAccessFlags == D3D11_CPU_ACCESS_READ, "Unexpected CPU access flags %#x.\n", + texture_desc.CPUAccessFlags); + ok(!texture_desc.MiscFlags, "Unexpected misc flags %#x.\n", texture_desc.MiscFlags); + ID3D11Texture2D_Release(texture); + IDXGISurface_Release(surface); + + ID2D1Bitmap1_Release(bitmap); + + winetest_pop_context(); + } + + hr = IDXGIDevice_QueryInterface(ctx.device, &IID_ID3D11Device, (void **)&d3d_device); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + texture_desc.Width = 4; + texture_desc.Height = 4; + texture_desc.MipLevels = 1; + texture_desc.ArraySize = 1; + texture_desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; + texture_desc.SampleDesc.Count = 1; + texture_desc.SampleDesc.Quality = 0; + texture_desc.Usage = D3D11_USAGE_STAGING; + texture_desc.BindFlags = 0; + texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; + texture_desc.MiscFlags = 0; + + hr = ID3D11Device_CreateTexture2D(d3d_device, &texture_desc, NULL, &texture); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + bitmap_desc.bitmapOptions = D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_CPU_READ; + hr = ID2D1DeviceContext_CreateBitmapFromDxgiSurface(ctx.context, surface, &bitmap_desc, &bitmap); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_READ | D2D1_MAP_OPTIONS_DISCARD, &mapped_rect); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_READ, &mapped_rect); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + hr = ID2D1Bitmap1_Unmap(bitmap); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_WRITE, &mapped_rect); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + hr = ID2D1Bitmap1_Unmap(bitmap); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_WRITE | D2D1_MAP_OPTIONS_READ, &mapped_rect); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + hr = ID2D1Bitmap1_Unmap(bitmap); + todo_wine + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_WRITE | D2D1_MAP_OPTIONS_DISCARD, &mapped_rect); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_WRITE | D2D1_MAP_OPTIONS_READ | D2D1_MAP_OPTIONS_DISCARD, &mapped_rect); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + + ID2D1Bitmap1_Release(bitmap); + + ID3D11Texture2D_Release(texture); + IDXGISurface_Release(surface); + + ID3D11Device_Release(d3d_device); + + release_test_context(&ctx); +} + START_TEST(d2d1) { HMODULE d2d1_dll = GetModuleHandleA("d2d1.dll"); @@ -11660,6 +11865,7 @@ START_TEST(d2d1) queue_test(test_effect_grayscale); queue_d3d10_test(test_stroke_contains_point); queue_test(test_image_bounds); + queue_test(test_bitmap_map);
run_queued_tests(); }
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/d2d1/tests/d2d1.c | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 0319b146ff2..e8f07976d54 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -11789,6 +11789,50 @@ static void test_bitmap_map(BOOL d3d11) release_test_context(&ctx); }
+static void test_bitmap_create(BOOL d3d11) +{ + static const struct + { + unsigned int options; + } invalid_options[] = + { + { D2D1_BITMAP_OPTIONS_CANNOT_DRAW }, + { D2D1_BITMAP_OPTIONS_CPU_READ }, + { D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE }, + }; + D2D1_BITMAP_PROPERTIES1 bitmap_desc; + struct d2d1_test_context ctx; + ID2D1Bitmap1 *bitmap; + D2D1_SIZE_U size; + unsigned int i; + HRESULT hr; + + if (!init_test_context(&ctx, d3d11)) + return; + + for (i = 0; i < ARRAY_SIZE(invalid_options); ++i) + { + winetest_push_context("Test %u", i); + + set_size_u(&size, 4, 4); + bitmap_desc.dpiX = 96.0f; + bitmap_desc.dpiY = 96.0f; + bitmap_desc.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; + bitmap_desc.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE; + bitmap_desc.bitmapOptions = invalid_options[i].options; + bitmap_desc.colorContext = NULL; + hr = ID2D1DeviceContext_CreateBitmap(ctx.context, size, NULL, 0, &bitmap_desc, &bitmap); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) + ID2D1Bitmap1_Release(bitmap); + + winetest_pop_context(); + } + + release_test_context(&ctx); +} + START_TEST(d2d1) { HMODULE d2d1_dll = GetModuleHandleA("d2d1.dll"); @@ -11866,6 +11910,7 @@ START_TEST(d2d1) queue_d3d10_test(test_stroke_contains_point); queue_test(test_image_bounds); queue_test(test_bitmap_map); + queue_test(test_bitmap_create);
run_queued_tests(); }
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/d2d1/bitmap.c | 4 ++++ dlls/d2d1/tests/d2d1.c | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/dlls/d2d1/bitmap.c b/dlls/d2d1/bitmap.c index 971e3c7ff6b..8386f703b46 100644 --- a/dlls/d2d1/bitmap.c +++ b/dlls/d2d1/bitmap.c @@ -374,12 +374,16 @@ HRESULT d2d_bitmap_create(struct d2d_device_context *context, D2D1_SIZE_U size, texture_desc.SampleDesc.Count = 1; texture_desc.SampleDesc.Quality = 0; texture_desc.Usage = D3D11_USAGE_DEFAULT; + if (desc->bitmapOptions & D2D1_BITMAP_OPTIONS_CPU_READ) + texture_desc.Usage = D3D11_USAGE_STAGING; texture_desc.BindFlags = 0; if (desc->bitmapOptions & D2D1_BITMAP_OPTIONS_TARGET) texture_desc.BindFlags |= D3D11_BIND_RENDER_TARGET; if (!(desc->bitmapOptions & D2D1_BITMAP_OPTIONS_CANNOT_DRAW)) texture_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE; texture_desc.CPUAccessFlags = 0; + if (desc->bitmapOptions & D2D1_BITMAP_OPTIONS_CPU_READ) + texture_desc.CPUAccessFlags |= D3D11_CPU_ACCESS_READ; texture_desc.MiscFlags = 0; if (desc->bitmapOptions & D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE) texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE; diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index e8f07976d54..0069cf746bb 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -11709,10 +11709,8 @@ static void test_bitmap_map(BOOL d3d11) hr = IDXGISurface_QueryInterface(surface, &IID_ID3D11Texture2D, (void **)&texture); ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); ID3D11Texture2D_GetDesc(texture, &texture_desc); - todo_wine ok(texture_desc.Usage == D3D11_USAGE_STAGING, "Unexpected usage %u.\n", texture_desc.Usage); ok(!texture_desc.BindFlags, "Unexpected bind flags %#x.\n", texture_desc.BindFlags); - todo_wine ok(texture_desc.CPUAccessFlags == D3D11_CPU_ACCESS_READ, "Unexpected CPU access flags %#x.\n", texture_desc.CPUAccessFlags); ok(!texture_desc.MiscFlags, "Unexpected misc flags %#x.\n", texture_desc.MiscFlags); @@ -11822,7 +11820,7 @@ static void test_bitmap_create(BOOL d3d11) bitmap_desc.bitmapOptions = invalid_options[i].options; bitmap_desc.colorContext = NULL; hr = ID2D1DeviceContext_CreateBitmap(ctx.context, size, NULL, 0, &bitmap_desc, &bitmap); - todo_wine + todo_wine_if(i != 1) ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); if (SUCCEEDED(hr)) ID2D1Bitmap1_Release(bitmap);
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/d2d1/bitmap.c | 20 ++++++++++++++++++++ dlls/d2d1/tests/d2d1.c | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/dlls/d2d1/bitmap.c b/dlls/d2d1/bitmap.c index 8386f703b46..904d44cc075 100644 --- a/dlls/d2d1/bitmap.c +++ b/dlls/d2d1/bitmap.c @@ -336,6 +336,23 @@ static void d2d_bitmap_init(struct d2d_bitmap *bitmap, struct d2d_device_context } }
+static BOOL check_bitmap_options(unsigned int options) +{ + switch (options) + { + case D2D1_BITMAP_OPTIONS_NONE: + case D2D1_BITMAP_OPTIONS_TARGET: + case D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW: + case D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE: + case D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE: + case D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_CPU_READ: + return TRUE; + default: + WARN("Invalid bitmap options %#x.\n", options); + return FALSE; + } +} + HRESULT d2d_bitmap_create(struct d2d_device_context *context, D2D1_SIZE_U size, const void *src_data, UINT32 pitch, const D2D1_BITMAP_PROPERTIES1 *desc, struct d2d_bitmap **bitmap) { @@ -364,6 +381,9 @@ HRESULT d2d_bitmap_create(struct d2d_device_context *context, D2D1_SIZE_U size, return E_INVALIDARG; }
+ if (!check_bitmap_options(desc->bitmapOptions)) + return E_INVALIDARG; + texture_desc.Width = size.width; texture_desc.Height = size.height; if (!texture_desc.Width || !texture_desc.Height) diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 0069cf746bb..6f22436c892 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -11798,6 +11798,18 @@ static void test_bitmap_create(BOOL d3d11) { D2D1_BITMAP_OPTIONS_CPU_READ }, { D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE }, }; + static const struct + { + unsigned int options; + } valid_options[] = + { + { D2D1_BITMAP_OPTIONS_NONE }, + { D2D1_BITMAP_OPTIONS_TARGET }, + { D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW }, + { D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE }, + { D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE }, + { D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_CPU_READ }, + }; D2D1_BITMAP_PROPERTIES1 bitmap_desc; struct d2d1_test_context ctx; ID2D1Bitmap1 *bitmap; @@ -11820,10 +11832,25 @@ static void test_bitmap_create(BOOL d3d11) bitmap_desc.bitmapOptions = invalid_options[i].options; bitmap_desc.colorContext = NULL; hr = ID2D1DeviceContext_CreateBitmap(ctx.context, size, NULL, 0, &bitmap_desc, &bitmap); - todo_wine_if(i != 1) ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); - if (SUCCEEDED(hr)) - ID2D1Bitmap1_Release(bitmap); + + winetest_pop_context(); + } + + for (i = 0; i < ARRAY_SIZE(valid_options); ++i) + { + winetest_push_context("Test %u", i); + + set_size_u(&size, 4, 4); + bitmap_desc.dpiX = 96.0f; + bitmap_desc.dpiY = 96.0f; + bitmap_desc.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; + bitmap_desc.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE; + bitmap_desc.bitmapOptions = valid_options[i].options; + bitmap_desc.colorContext = NULL; + hr = ID2D1DeviceContext_CreateBitmap(ctx.context, size, NULL, 0, &bitmap_desc, &bitmap); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ID2D1Bitmap1_Release(bitmap);
winetest_pop_context(); }
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/d2d1/tests/d2d1.c | 46 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-)
diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 6f22436c892..ac96c1a0d50 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -11609,10 +11609,11 @@ static void test_bitmap_map(BOOL d3d11) D2D1_MAPPED_RECT mapped_rect; ID3D11Device *d3d_device; ID3D11Texture2D *texture; + unsigned int i, options; IDXGISurface *surface; ID2D1Bitmap1 *bitmap; + ID2D1Bitmap *bitmap2; D2D1_SIZE_U size; - unsigned int i; HRESULT hr;
if (!init_test_context(&ctx, d3d11)) @@ -11779,6 +11780,49 @@ static void test_bitmap_map(BOOL d3d11)
ID2D1Bitmap1_Release(bitmap);
+ /* Options are derived from the surface properties. */ + bitmap_desc.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM; + bitmap_desc.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE; + bitmap_desc.dpiX = bitmap_desc.dpiY = 0.0f; + hr = ID2D1DeviceContext_CreateSharedBitmap(ctx.context, &IID_IDXGISurface, surface, + (const D2D1_BITMAP_PROPERTIES *)&bitmap_desc, &bitmap2); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + hr = ID2D1Bitmap_QueryInterface(bitmap2, &IID_ID2D1Bitmap1, (void **)&bitmap); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + options = ID2D1Bitmap1_GetOptions(bitmap); + todo_wine + ok(options == (D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_CPU_READ), + "Unexpected options %#x.\n", options); + + ID2D1Bitmap1_Release(bitmap); + ID2D1Bitmap_Release(bitmap2); + + hr = ID2D1DeviceContext_CreateBitmapFromDxgiSurface(ctx.context, surface, NULL, &bitmap); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + options = ID2D1Bitmap1_GetOptions(bitmap); + todo_wine + ok(options == (D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_CPU_READ), + "Unexpected options %#x.\n", options); + ID2D1Bitmap1_Release(bitmap); + + /* Options incompatible with the surface. */ + bitmap_desc.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET; + hr = ID2D1DeviceContext_CreateBitmapFromDxgiSurface(ctx.context, surface, &bitmap_desc, &bitmap); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) ID2D1Bitmap1_Release(bitmap); + bitmap_desc.bitmapOptions = D2D1_BITMAP_OPTIONS_NONE; + hr = ID2D1DeviceContext_CreateBitmapFromDxgiSurface(ctx.context, surface, &bitmap_desc, &bitmap); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) ID2D1Bitmap1_Release(bitmap); + bitmap_desc.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW; + hr = ID2D1DeviceContext_CreateBitmapFromDxgiSurface(ctx.context, surface, &bitmap_desc, &bitmap); + todo_wine + ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) ID2D1Bitmap1_Release(bitmap); + ID3D11Texture2D_Release(texture); IDXGISurface_Release(surface);
From: Nikolay Sivov nsivov@codeweavers.com
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/d2d1/bitmap.c | 72 +++++++++++++++++++++++++++++++++++++--- dlls/d2d1/d2d1_private.h | 1 + dlls/d2d1/tests/d2d1.c | 21 +----------- 3 files changed, 70 insertions(+), 24 deletions(-)
diff --git a/dlls/d2d1/bitmap.c b/dlls/d2d1/bitmap.c index 904d44cc075..6a02279b91b 100644 --- a/dlls/d2d1/bitmap.c +++ b/dlls/d2d1/bitmap.c @@ -26,6 +26,25 @@ static inline struct d2d_bitmap *impl_from_ID2D1Bitmap1(ID2D1Bitmap1 *iface) return CONTAINING_RECORD(iface, struct d2d_bitmap, ID2D1Bitmap1_iface); }
+static HRESULT d2d_bitmap_unmap(struct d2d_bitmap *bitmap) +{ + ID3D11DeviceContext *context; + ID3D11Device *device; + + if (!bitmap->mapped_resource.pData) + return D2DERR_WRONG_STATE; + + ID3D11Resource_GetDevice(bitmap->resource, &device); + ID3D11Device_GetImmediateContext(device, &context); + ID3D11DeviceContext_Unmap(context, bitmap->resource, 0); + ID3D11DeviceContext_Release(context); + ID3D11Device_Release(device); + + memset(&bitmap->mapped_resource, 0, sizeof(bitmap->mapped_resource)); + + return S_OK; +} + static HRESULT STDMETHODCALLTYPE d2d_bitmap_QueryInterface(ID2D1Bitmap1 *iface, REFIID iid, void **out) { TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out); @@ -229,16 +248,61 @@ static HRESULT STDMETHODCALLTYPE d2d_bitmap_GetSurface(ID2D1Bitmap1 *iface, IDXG static HRESULT STDMETHODCALLTYPE d2d_bitmap_Map(ID2D1Bitmap1 *iface, D2D1_MAP_OPTIONS options, D2D1_MAPPED_RECT *mapped_rect) { - FIXME("iface %p, options %#x, mapped_rect %p stub!\n", iface, options, mapped_rect); + struct d2d_bitmap *bitmap = impl_from_ID2D1Bitmap1(iface); + D3D11_MAPPED_SUBRESOURCE mapped_resource; + ID3D11DeviceContext *context; + ID3D11Device *device; + D3D11_MAP map_type; + HRESULT hr;
- return E_NOTIMPL; + TRACE("iface %p, options %#x, mapped_rect %p.\n", iface, options, mapped_rect); + + if (bitmap->mapped_resource.pData) + return D2DERR_WRONG_STATE; + + if (options == D2D1_MAP_OPTIONS_READ) + map_type = D3D11_MAP_READ; + else if (options == D2D1_MAP_OPTIONS_WRITE) + map_type = D3D11_MAP_WRITE; + else if (options == (D2D1_MAP_OPTIONS_READ | D2D1_MAP_OPTIONS_WRITE)) + map_type = D3D11_MAP_READ_WRITE; + else if (options == (D2D1_MAP_OPTIONS_WRITE | D2D1_MAP_OPTIONS_DISCARD)) + map_type = D3D11_MAP_WRITE_DISCARD; + else + { + WARN("Invalid mapping options %#x.\n", options); + return E_INVALIDARG; + } + + ID3D11Resource_GetDevice(bitmap->resource, &device); + ID3D11Device_GetImmediateContext(device, &context); + if (SUCCEEDED(hr = ID3D11DeviceContext_Map(context, bitmap->resource, 0, map_type, + 0, &mapped_resource))) + { + bitmap->mapped_resource = mapped_resource; + } + ID3D11DeviceContext_Release(context); + ID3D11Device_Release(device); + + if (FAILED(hr)) + { + WARN("Failed to map resource, hr %#lx.\n", hr); + return E_INVALIDARG; + } + + mapped_rect->pitch = bitmap->mapped_resource.RowPitch; + mapped_rect->bits = bitmap->mapped_resource.pData; + + return S_OK; }
static HRESULT STDMETHODCALLTYPE d2d_bitmap_Unmap(ID2D1Bitmap1 *iface) { - FIXME("iface %p stub!\n", iface); + struct d2d_bitmap *bitmap = impl_from_ID2D1Bitmap1(iface);
- return E_NOTIMPL; + TRACE("iface %p.\n", iface); + + return d2d_bitmap_unmap(bitmap); }
static const struct ID2D1Bitmap1Vtbl d2d_bitmap_vtbl = diff --git a/dlls/d2d1/d2d1_private.h b/dlls/d2d1/d2d1_private.h index 8edfa030ee1..48649f6a916 100644 --- a/dlls/d2d1/d2d1_private.h +++ b/dlls/d2d1/d2d1_private.h @@ -395,6 +395,7 @@ struct d2d_bitmap ID3D11RenderTargetView *rtv; IDXGISurface *surface; ID3D11Resource *resource; + D3D11_MAPPED_SUBRESOURCE mapped_resource; D2D1_SIZE_U pixel_size; D2D1_PIXEL_FORMAT format; float dpi_x; diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index ac96c1a0d50..807a7be5ae6 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -11634,13 +11634,10 @@ static void test_bitmap_map(BOOL d3d11) ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_NONE, &mapped_rect); - todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_READ, &mapped_rect); - todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_WRITE, &mapped_rect); - todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
hr = ID2D1Bitmap1_GetSurface(bitmap, &surface); @@ -11672,37 +11669,28 @@ static void test_bitmap_map(BOOL d3d11) ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_NONE, &mapped_rect); - todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_READ, &mapped_rect); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_READ, &mapped_rect); - todo_wine ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#lx.\n", hr); hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_WRITE, &mapped_rect); todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
hr = ID2D1Bitmap1_Unmap(bitmap); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); hr = ID2D1Bitmap1_Unmap(bitmap); - todo_wine ok(hr == D2DERR_WRONG_STATE, "Got unexpected hr %#lx.\n", hr);
hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_WRITE, &mapped_rect); - todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_READ | D2D1_MAP_OPTIONS_DISCARD, &mapped_rect); - todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_WRITE | D2D1_MAP_OPTIONS_DISCARD, &mapped_rect); - todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_READ | D2D1_MAP_OPTIONS_WRITE, &mapped_rect); - todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
hr = ID2D1Bitmap1_GetSurface(bitmap, &surface); @@ -11748,34 +11736,27 @@ static void test_bitmap_map(BOOL d3d11) ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_READ | D2D1_MAP_OPTIONS_DISCARD, &mapped_rect); - todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_READ, &mapped_rect); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); hr = ID2D1Bitmap1_Unmap(bitmap); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_WRITE, &mapped_rect); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); hr = ID2D1Bitmap1_Unmap(bitmap); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_WRITE | D2D1_MAP_OPTIONS_READ, &mapped_rect); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); hr = ID2D1Bitmap1_Unmap(bitmap); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_WRITE | D2D1_MAP_OPTIONS_DISCARD, &mapped_rect); todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr); + if (SUCCEEDED(hr)) ID2D1Bitmap1_Unmap(bitmap); hr = ID2D1Bitmap1_Map(bitmap, D2D1_MAP_OPTIONS_WRITE | D2D1_MAP_OPTIONS_READ | D2D1_MAP_OPTIONS_DISCARD, &mapped_rect); - todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#lx.\n", hr);
ID2D1Bitmap1_Release(bitmap);
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=115730
Your paranoid android.
=== debian11 (64 bit WoW report) ===
d2d1: d2d1: Timeout