Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/d2d1/bitmap.c | 42 +++++++++------ dlls/d2d1/d2d1_private.h | 7 +-- dlls/d2d1/device.c | 37 +++++++++++--- dlls/d2d1/tests/d2d1.c | 107 +++++++++++++++++++++------------------ 4 files changed, 119 insertions(+), 74 deletions(-)
diff --git a/dlls/d2d1/bitmap.c b/dlls/d2d1/bitmap.c index 8282dca043..43af09272c 100644 --- a/dlls/d2d1/bitmap.c +++ b/dlls/d2d1/bitmap.c @@ -179,9 +179,11 @@ static void STDMETHODCALLTYPE d2d_bitmap_GetColorContext(ID2D1Bitmap1 *iface, ID
static D2D1_BITMAP_OPTIONS STDMETHODCALLTYPE d2d_bitmap_GetOptions(ID2D1Bitmap1 *iface) { - FIXME("iface %p stub!\n", iface); + struct d2d_bitmap *bitmap = impl_from_ID2D1Bitmap1(iface); + + TRACE("iface %p.\n", iface);
- return D2D1_BITMAP_OPTIONS_NONE; + return bitmap->options; }
static HRESULT STDMETHODCALLTYPE d2d_bitmap_GetSurface(ID2D1Bitmap1 *iface, IDXGISurface **surface) @@ -262,7 +264,7 @@ static BOOL format_supported(const D2D1_PIXEL_FORMAT *format) }
static void d2d_bitmap_init(struct d2d_bitmap *bitmap, ID2D1Factory *factory, - ID3D10ShaderResourceView *view, D2D1_SIZE_U size, const D2D1_BITMAP_PROPERTIES *desc) + ID3D10ShaderResourceView *view, D2D1_SIZE_U size, const D2D1_BITMAP_PROPERTIES1 *desc) { bitmap->ID2D1Bitmap1_iface.lpVtbl = &d2d_bitmap_vtbl; bitmap->refcount = 1; @@ -272,6 +274,7 @@ static void d2d_bitmap_init(struct d2d_bitmap *bitmap, ID2D1Factory *factory, bitmap->format = desc->pixelFormat; bitmap->dpi_x = desc->dpiX; bitmap->dpi_y = desc->dpiY; + bitmap->options = desc->bitmapOptions;
if (bitmap->dpi_x == 0.0f && bitmap->dpi_y == 0.0f) { @@ -281,7 +284,7 @@ static void d2d_bitmap_init(struct d2d_bitmap *bitmap, ID2D1Factory *factory, }
HRESULT d2d_bitmap_create(ID2D1Factory *factory, ID3D10Device *device, D2D1_SIZE_U size, const void *src_data, - UINT32 pitch, const D2D1_BITMAP_PROPERTIES *desc, struct d2d_bitmap **bitmap) + UINT32 pitch, const D2D1_BITMAP_PROPERTIES1 *desc, struct d2d_bitmap **bitmap) { D3D10_SUBRESOURCE_DATA resource_data; D3D10_TEXTURE2D_DESC texture_desc; @@ -338,9 +341,9 @@ HRESULT d2d_bitmap_create(ID2D1Factory *factory, ID3D10Device *device, D2D1_SIZE }
HRESULT d2d_bitmap_create_shared(ID2D1DeviceContext *context, ID3D10Device *target_device, - REFIID iid, void *data, const D2D1_BITMAP_PROPERTIES *desc, struct d2d_bitmap **bitmap) + REFIID iid, void *data, const D2D1_BITMAP_PROPERTIES1 *desc, struct d2d_bitmap **bitmap) { - D2D1_BITMAP_PROPERTIES d; + D2D1_BITMAP_PROPERTIES1 d; ID2D1Factory *factory;
if (IsEqualGUID(iid, &IID_ID2D1Bitmap)) @@ -433,6 +436,22 @@ HRESULT d2d_bitmap_create_shared(ID2D1DeviceContext *context, ID3D10Device *targ }
d = *desc; + + if (FAILED(hr = IDXGISurface_GetDesc(surface, &surface_desc))) + { + WARN("Failed to get surface desc, hr %#x.\n", hr); + ID3D10ShaderResourceView_Release(view); + return hr; + } + + if (!desc) + { + memset(&d, 0, sizeof(d)); + d.pixelFormat.format = surface_desc.Format; + } + else + d = *desc; + if (d.dpiX == 0.0f || d.dpiY == 0.0f) { float dpi_x, dpi_y; @@ -444,13 +463,6 @@ HRESULT d2d_bitmap_create_shared(ID2D1DeviceContext *context, ID3D10Device *targ d.dpiY = dpi_y; }
- if (FAILED(hr = IDXGISurface_GetDesc(surface, &surface_desc))) - { - WARN("Failed to get surface desc, hr %#x.\n", hr); - ID3D10ShaderResourceView_Release(view); - return hr; - } - pixel_size.width = surface_desc.Width; pixel_size.height = surface_desc.Height;
@@ -469,10 +481,10 @@ HRESULT d2d_bitmap_create_shared(ID2D1DeviceContext *context, ID3D10Device *targ }
HRESULT d2d_bitmap_create_from_wic_bitmap(ID2D1Factory *factory, ID3D10Device *device, IWICBitmapSource *bitmap_source, - const D2D1_BITMAP_PROPERTIES *desc, struct d2d_bitmap **bitmap) + const D2D1_BITMAP_PROPERTIES1 *desc, struct d2d_bitmap **bitmap) { const D2D1_PIXEL_FORMAT *d2d_format; - D2D1_BITMAP_PROPERTIES bitmap_desc; + D2D1_BITMAP_PROPERTIES1 bitmap_desc; WICPixelFormatGUID wic_format; unsigned int bpp, data_size; D2D1_SIZE_U size; diff --git a/dlls/d2d1/d2d1_private.h b/dlls/d2d1/d2d1_private.h index e00b942797..a427c91070 100644 --- a/dlls/d2d1/d2d1_private.h +++ b/dlls/d2d1/d2d1_private.h @@ -331,14 +331,15 @@ struct d2d_bitmap D2D1_PIXEL_FORMAT format; float dpi_x; float dpi_y; + D2D1_BITMAP_OPTIONS options; };
HRESULT d2d_bitmap_create(ID2D1Factory *factory, ID3D10Device *device, D2D1_SIZE_U size, const void *src_data, - UINT32 pitch, const D2D1_BITMAP_PROPERTIES *desc, struct d2d_bitmap **bitmap) DECLSPEC_HIDDEN; + UINT32 pitch, const D2D1_BITMAP_PROPERTIES1 *desc, struct d2d_bitmap **bitmap) DECLSPEC_HIDDEN; HRESULT d2d_bitmap_create_shared(ID2D1DeviceContext *context, ID3D10Device *device, REFIID iid, void *data, - const D2D1_BITMAP_PROPERTIES *desc, struct d2d_bitmap **bitmap) DECLSPEC_HIDDEN; + const D2D1_BITMAP_PROPERTIES1 *desc, struct d2d_bitmap **bitmap) DECLSPEC_HIDDEN; HRESULT d2d_bitmap_create_from_wic_bitmap(ID2D1Factory *factory, ID3D10Device *device, IWICBitmapSource *bitmap_source, - const D2D1_BITMAP_PROPERTIES *desc, struct d2d_bitmap **bitmap) DECLSPEC_HIDDEN; + const D2D1_BITMAP_PROPERTIES1 *desc, struct d2d_bitmap **bitmap) 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 bba4870dd4..57c473c8ad 100644 --- a/dlls/d2d1/device.c +++ b/dlls/d2d1/device.c @@ -290,13 +290,22 @@ static HRESULT STDMETHODCALLTYPE d2d_device_context_CreateBitmap(ID2D1DeviceCont D2D1_SIZE_U size, const void *src_data, UINT32 pitch, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap) { struct d2d_device_context *render_target = impl_from_ID2D1DeviceContext(iface); + D2D1_BITMAP_PROPERTIES1 bitmap_desc; 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);
- if (SUCCEEDED(hr = d2d_bitmap_create(render_target->factory, render_target->device, size, src_data, pitch, desc, &object))) + if (desc) + { + memcpy(&bitmap_desc, desc, sizeof(*desc)); + bitmap_desc.bitmapOptions = 0; + bitmap_desc.colorContext = NULL; + } + + if (SUCCEEDED(hr = d2d_bitmap_create(render_target->factory, render_target->device, size, src_data, pitch, + desc ? &bitmap_desc : NULL, &object))) *bitmap = (ID2D1Bitmap *)&object->ID2D1Bitmap1_iface;
return hr; @@ -305,15 +314,23 @@ static HRESULT STDMETHODCALLTYPE d2d_device_context_CreateBitmap(ID2D1DeviceCont static HRESULT STDMETHODCALLTYPE d2d_device_context_CreateBitmapFromWicBitmap(ID2D1DeviceContext *iface, IWICBitmapSource *bitmap_source, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap) { - struct d2d_device_context *render_target = impl_from_ID2D1DeviceContext(iface); + struct d2d_device_context *context = impl_from_ID2D1DeviceContext(iface); + D2D1_BITMAP_PROPERTIES1 bitmap_desc; struct d2d_bitmap *object; HRESULT hr;
TRACE("iface %p, bitmap_source %p, desc %p, bitmap %p.\n", iface, bitmap_source, desc, bitmap);
- if (SUCCEEDED(hr = d2d_bitmap_create_from_wic_bitmap(render_target->factory, render_target->device, bitmap_source, - desc, &object))) + if (desc) + { + memcpy(&bitmap_desc, desc, sizeof(*desc)); + bitmap_desc.bitmapOptions = 0; + bitmap_desc.colorContext = NULL; + } + + if (SUCCEEDED(hr = d2d_bitmap_create_from_wic_bitmap(context->factory, context->device, bitmap_source, + desc ? &bitmap_desc : NULL, &object))) *bitmap = (ID2D1Bitmap *)&object->ID2D1Bitmap1_iface;
return hr; @@ -322,14 +339,22 @@ static HRESULT STDMETHODCALLTYPE d2d_device_context_CreateBitmapFromWicBitmap(ID static HRESULT STDMETHODCALLTYPE d2d_device_context_CreateSharedBitmap(ID2D1DeviceContext *iface, REFIID iid, void *data, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap) { - struct d2d_device_context *render_target = impl_from_ID2D1DeviceContext(iface); + struct d2d_device_context *context = impl_from_ID2D1DeviceContext(iface); + D2D1_BITMAP_PROPERTIES1 bitmap_desc; struct d2d_bitmap *object; HRESULT hr;
TRACE("iface %p, iid %s, data %p, desc %p, bitmap %p.\n", iface, debugstr_guid(iid), data, desc, bitmap);
- if (SUCCEEDED(hr = d2d_bitmap_create_shared(iface, render_target->device, iid, data, desc, &object))) + if (desc) + { + memcpy(&bitmap_desc, desc, sizeof(*desc)); + bitmap_desc.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW; + bitmap_desc.colorContext = NULL; + } + + if (SUCCEEDED(hr = d2d_bitmap_create_shared(iface, context->device, iid, data, desc ? &bitmap_desc : NULL, &object))) *bitmap = (ID2D1Bitmap *)&object->ID2D1Bitmap1_iface;
return hr; diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index eeae75f841..7a8169242f 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -773,6 +773,56 @@ static ID2D1RenderTarget *create_render_target(IDXGISurface *surface) return create_render_target_desc(surface, &desc); }
+#define check_bitmap_surface(b, s, o) check_bitmap_surface_(__LINE__, b, s, o) +static void check_bitmap_surface_(unsigned int line, ID2D1Bitmap1 *bitmap, BOOL has_surface, DWORD expected_options) +{ + D2D1_BITMAP_OPTIONS options; + IDXGISurface *surface; + HRESULT hr; + + options = ID2D1Bitmap1_GetOptions(bitmap); + ok_(__FILE__, line)(options == expected_options, "Unexpected bitmap options %#x, expected %#x.\n", + options, expected_options); + + surface = (void *)0xdeadbeef; + hr = ID2D1Bitmap1_GetSurface(bitmap, &surface); + if (has_surface) + { + D3D10_TEXTURE2D_DESC desc; + ID3D10Texture2D *texture; + + todo_wine + ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get bitmap surface, hr %#x.\n", hr); + ok_(__FILE__, line)(!!surface, "Expected surface instance.\n"); + + if (SUCCEEDED(hr)) + { + /* Correlate with resource configuration. */ + hr = IDXGISurface_QueryInterface(surface, &IID_ID3D10Texture2D, (void **)&texture); + ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get texture pointer, hr %#x.\n", hr); + + 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); + 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); + + ID3D10Texture2D_Release(texture); + + IDXGISurface_Release(surface); + } + } + else + { + todo_wine { + ok_(__FILE__, line)(hr == D2DERR_INVALID_CALL, "Unexpected hr %#x.\n", hr); + ok_(__FILE__, line)(!surface, "Unexpected surface instance.\n"); + } + } +} + static inline struct geometry_sink *impl_from_ID2D1SimplifiedGeometrySink(ID2D1SimplifiedGeometrySink *iface) { return CONTAINING_RECORD(iface, struct geometry_sink, ID2D1SimplifiedGeometrySink_iface); @@ -4112,11 +4162,18 @@ static void test_shared_bitmap(void)
if (SUCCEEDED(hr)) { + ID2D1Bitmap1 *bitmap3; + size = ID2D1Bitmap_GetPixelSize(bitmap2); hr = IDXGISurface_GetDesc(surface2, &surface_desc); ok(SUCCEEDED(hr), "Failed to get surface description, hr %#x.\n", hr); ok(size.width == surface_desc.Width && size.height == surface_desc.Height, "Got wrong bitmap size.\n");
+ hr = ID2D1Bitmap_QueryInterface(bitmap2, &IID_ID2D1Bitmap1, (void **)&bitmap3); + ok(SUCCEEDED(hr), "Failed to get ID2D1Bitmap1 pointer, hr %#x.\n", hr); + + check_bitmap_surface(bitmap3, TRUE, D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW); + ID2D1Bitmap_Release(bitmap2);
/* IDXGISurface1 is supported too. */ @@ -6529,56 +6586,6 @@ static void test_create_device(void) ok(!refcount, "Factory has %u references left.\n", refcount); }
-#define check_bitmap_surface(b, s, o) check_bitmap_surface_(__LINE__, b, s, o) -static void check_bitmap_surface_(unsigned int line, ID2D1Bitmap1 *bitmap, BOOL has_surface, DWORD expected_options) -{ - D2D1_BITMAP_OPTIONS options; - IDXGISurface *surface; - HRESULT hr; - - options = ID2D1Bitmap1_GetOptions(bitmap); - ok_(__FILE__, line)(options == expected_options, "Unexpected bitmap options %#x, expected %#x.\n", - options, expected_options); - - surface = (void *)0xdeadbeef; - hr = ID2D1Bitmap1_GetSurface(bitmap, &surface); - if (has_surface) - { - D3D10_TEXTURE2D_DESC desc; - ID3D10Texture2D *texture; - - todo_wine - ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get bitmap surface, hr %#x.\n", hr); - ok_(__FILE__, line)(!!surface, "Expected surface instance.\n"); - - if (SUCCEEDED(hr)) - { - /* Correlate with resource configuration. */ - hr = IDXGISurface_QueryInterface(surface, &IID_ID3D10Texture2D, (void **)&texture); - ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get texture pointer, hr %#x.\n", hr); - - 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); - 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); - - ID3D10Texture2D_Release(texture); - - IDXGISurface_Release(surface); - } - } - else - { - todo_wine { - ok_(__FILE__, line)(hr == D2DERR_INVALID_CALL, "Unexpected hr %#x.\n", hr); - ok_(__FILE__, line)(!surface, "Unexpected surface instance.\n"); - } - } -} - #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) {