From: Zhiyi Zhang zzhang@codeweavers.com
--- dlls/d2d1/bitmap.c | 42 +++++++++++++++++++++++++++++++++++++++--- dlls/d2d1/device.c | 3 ++- dlls/d2d1/tests/d2d1.c | 4 ++-- 3 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/dlls/d2d1/bitmap.c b/dlls/d2d1/bitmap.c index e5048611519..8f1b4d19ebc 100644 --- a/dlls/d2d1/bitmap.c +++ b/dlls/d2d1/bitmap.c @@ -363,6 +363,41 @@ static BOOL format_supported(const D2D1_PIXEL_FORMAT *format) return FALSE; }
+static HRESULT d2d_get_resource_from_surface(IDXGISurface *surface, REFIID resource_iid, void **resource) +{ + D3D11_TEXTURE2D_DESC desc; + ID3D11Texture2D *texture; + IDXGISurface2 *surface2; + UINT index; + HRESULT hr; + + if (SUCCEEDED(IDXGISurface_QueryInterface(surface, resource_iid, resource))) + return S_OK; + + /* Try getting the parent resource if the surface is a subresource surface */ + if (FAILED(hr = IDXGISurface_QueryInterface(surface, &IID_IDXGISurface2, (void **)&surface2))) + return hr; + + if (FAILED(hr = IDXGISurface2_GetResource(surface2, &IID_ID3D11Texture2D, (void **)&texture, &index))) + { + IDXGISurface2_Release(surface2); + return hr; + } + + ID3D11Texture2D_GetDesc(texture, &desc); + ID3D11Texture2D_Release(texture); + /* Parent resource with more than one subresource is currently unsupported */ + if (desc.ArraySize * desc.MipLevels != 1) + { + IDXGISurface2_Release(surface2); + return E_NOTIMPL; + } + + hr = IDXGISurface2_GetResource(surface2, resource_iid, resource, &index); + IDXGISurface2_Release(surface2); + return hr; +} + static void d2d_bitmap_init(struct d2d_bitmap *bitmap, struct d2d_device_context *context, ID3D11Resource *resource, D2D1_SIZE_U size, const D2D1_BITMAP_PROPERTIES1 *desc) { @@ -501,7 +536,7 @@ unsigned int d2d_get_bitmap_options_for_surface(IDXGISurface *surface) unsigned int options = 0; ID3D11Texture2D *texture;
- if (FAILED(IDXGISurface_QueryInterface(surface, &IID_ID3D11Texture2D, (void **)&texture))) + if (FAILED(d2d_get_resource_from_surface(surface, &IID_ID3D11Texture2D, (void **)&texture))) return 0;
ID3D11Texture2D_GetDesc(texture, &desc); @@ -583,7 +618,8 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid, return hr; }
- if (IsEqualGUID(iid, &IID_IDXGISurface) || IsEqualGUID(iid, &IID_IDXGISurface1)) + if (IsEqualGUID(iid, &IID_IDXGISurface) || IsEqualGUID(iid, &IID_IDXGISurface1) + || IsEqualGUID(iid, &IID_IDXGISurface2)) { DXGI_SURFACE_DESC surface_desc; IDXGISurface *surface = data; @@ -592,7 +628,7 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid, ID3D11Device *device; HRESULT hr;
- if (FAILED(IDXGISurface_QueryInterface(surface, &IID_ID3D11Resource, (void **)&resource))) + if (FAILED(d2d_get_resource_from_surface(surface, &IID_ID3D11Resource, (void **)&resource))) { WARN("Failed to get d3d resource from dxgi surface.\n"); return E_FAIL; diff --git a/dlls/d2d1/device.c b/dlls/d2d1/device.c index 3969046d5b3..86bead7f52a 100644 --- a/dlls/d2d1/device.c +++ b/dlls/d2d1/device.c @@ -418,7 +418,8 @@ static HRESULT STDMETHODCALLTYPE d2d_device_context_CreateSharedBitmap(ID2D1Devi if (desc) { memcpy(&bitmap_desc, desc, sizeof(*desc)); - if (IsEqualIID(iid, &IID_IDXGISurface) || IsEqualIID(iid, &IID_IDXGISurface1)) + if (IsEqualIID(iid, &IID_IDXGISurface) || IsEqualIID(iid, &IID_IDXGISurface1) + || IsEqualIID(iid, &IID_IDXGISurface2)) bitmap_desc.bitmapOptions = d2d_get_bitmap_options_for_surface(data); else bitmap_desc.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW; diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 5f27a9fd20f..4b631154349 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -14521,7 +14521,7 @@ static void test_bitmap_create(BOOL d3d11) bitmap_desc.bitmapOptions = subresource_tests[i].options; hr = ID2D1DeviceContext_CreateSharedBitmap(ctx.context, &IID_IDXGISurface2, surface2, (const D2D1_BITMAP_PROPERTIES *)&bitmap_desc, &bitmap2); - todo_wine + todo_wine_if(subresource_count != 1) ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); if (hr == S_OK) { @@ -14532,7 +14532,7 @@ static void test_bitmap_create(BOOL d3d11)
hr = ID2D1DeviceContext_CreateBitmapFromDxgiSurface(ctx.context, (IDXGISurface *)surface2, &bitmap_desc, &bitmap); - todo_wine + todo_wine_if(subresource_count != 1) ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); if (hr == S_OK) {