Nikolay Sivov : d2d1: Derive bitmap options from surface description in CreateBitmapFromDxgiSurface().

Alexandre Julliard julliard at winehq.org
Tue May 31 15:58:00 CDT 2022


Module: wine
Branch: master
Commit: 08be8fd5ab372042e2b6be9a57216570f6746804
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=08be8fd5ab372042e2b6be9a57216570f6746804

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Mon May 30 10:13:14 2022 +0300

d2d1: Derive bitmap options from surface description in CreateBitmapFromDxgiSurface().

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>

---

 dlls/d2d1/bitmap.c       | 24 ++++++++++++++++++++++++
 dlls/d2d1/d2d1_private.h |  1 +
 dlls/d2d1/device.c       |  2 +-
 dlls/d2d1/tests/d2d1.c   |  1 -
 4 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/dlls/d2d1/bitmap.c b/dlls/d2d1/bitmap.c
index 1c6383ae4a9..097d984e3ae 100644
--- a/dlls/d2d1/bitmap.c
+++ b/dlls/d2d1/bitmap.c
@@ -495,6 +495,30 @@ HRESULT d2d_bitmap_create(struct d2d_device_context *context, D2D1_SIZE_U size,
     return *bitmap ? S_OK : E_OUTOFMEMORY;
 }
 
+unsigned int d2d_get_bitmap_options_for_surface(IDXGISurface *surface)
+{
+    D3D11_TEXTURE2D_DESC desc;
+    unsigned int options = 0;
+    ID3D11Texture2D *texture;
+
+    if (FAILED(IDXGISurface_QueryInterface(surface, &IID_ID3D11Texture2D, (void **)&texture)))
+        return 0;
+
+    ID3D11Texture2D_GetDesc(texture, &desc);
+    ID3D11Texture2D_Release(texture);
+
+    if (desc.BindFlags & D3D11_BIND_RENDER_TARGET)
+        options |= D2D1_BITMAP_OPTIONS_TARGET;
+    if (!(desc.BindFlags & D3D11_BIND_SHADER_RESOURCE))
+        options |= D2D1_BITMAP_OPTIONS_CANNOT_DRAW;
+    if (desc.MiscFlags & D3D11_RESOURCE_MISC_GDI_COMPATIBLE)
+        options |= D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE;
+    if (desc.Usage == D3D11_USAGE_STAGING && desc.CPUAccessFlags & D3D11_CPU_ACCESS_READ)
+        options |= D2D1_BITMAP_OPTIONS_CPU_READ;
+
+    return options;
+}
+
 HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid, void *data,
         const D2D1_BITMAP_PROPERTIES1 *desc, struct d2d_bitmap **bitmap)
 {
diff --git a/dlls/d2d1/d2d1_private.h b/dlls/d2d1/d2d1_private.h
index 48649f6a916..efc9247a822 100644
--- a/dlls/d2d1/d2d1_private.h
+++ b/dlls/d2d1/d2d1_private.h
@@ -409,6 +409,7 @@ HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid,
         const D2D1_BITMAP_PROPERTIES1 *desc, struct d2d_bitmap **bitmap) DECLSPEC_HIDDEN;
 HRESULT d2d_bitmap_create_from_wic_bitmap(struct d2d_device_context *context, IWICBitmapSource *bitmap_source,
         const D2D1_BITMAP_PROPERTIES1 *desc, struct d2d_bitmap **bitmap) DECLSPEC_HIDDEN;
+unsigned int d2d_get_bitmap_options_for_surface(IDXGISurface *surface) DECLSPEC_HIDDEN;
 struct d2d_bitmap *unsafe_impl_from_ID2D1Bitmap(ID2D1Bitmap *iface) DECLSPEC_HIDDEN;
 
 struct d2d_state_block
diff --git a/dlls/d2d1/device.c b/dlls/d2d1/device.c
index eb0c1935ebb..64b573da974 100644
--- a/dlls/d2d1/device.c
+++ b/dlls/d2d1/device.c
@@ -1876,7 +1876,7 @@ static HRESULT STDMETHODCALLTYPE d2d_device_context_CreateBitmapFromDxgiSurface(
         memset(&bitmap_desc, 0, sizeof(bitmap_desc));
         bitmap_desc.pixelFormat.format = surface_desc.Format;
         bitmap_desc.pixelFormat.alphaMode = D2D1_ALPHA_MODE_PREMULTIPLIED;
-        bitmap_desc.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW;
+        bitmap_desc.bitmapOptions = d2d_get_bitmap_options_for_surface(surface);
         desc = &bitmap_desc;
     }
 
diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c
index 9706b02528b..515c14e5adb 100644
--- a/dlls/d2d1/tests/d2d1.c
+++ b/dlls/d2d1/tests/d2d1.c
@@ -11782,7 +11782,6 @@ static void test_bitmap_map(BOOL d3d11)
     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);




More information about the wine-cvs mailing list