Commit bccd14f2 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

d2d1: Return bitmap options.

parent 39e19d2d
......@@ -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))
......@@ -369,6 +372,8 @@ HRESULT d2d_bitmap_create_shared(ID2D1DeviceContext *context, ID3D10Device *targ
d.pixelFormat = src_impl->format;
d.dpiX = src_impl->dpi_x;
d.dpiY = src_impl->dpi_y;
d.bitmapOptions = src_impl->options;
d.colorContext = NULL;
desc = &d;
}
......@@ -432,7 +437,22 @@ HRESULT d2d_bitmap_create_shared(ID2D1DeviceContext *context, ID3D10Device *targ
return E_OUTOFMEMORY;
}
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 +464,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 +482,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;
......@@ -505,6 +518,8 @@ HRESULT d2d_bitmap_create_from_wic_bitmap(ID2D1Factory *factory, ID3D10Device *d
bitmap_desc.pixelFormat.alphaMode = D2D1_ALPHA_MODE_UNKNOWN;
bitmap_desc.dpiX = 0.0f;
bitmap_desc.dpiY = 0.0f;
bitmap_desc.bitmapOptions = 0;
bitmap_desc.colorContext = NULL;
}
else
{
......
......@@ -343,14 +343,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
......
......@@ -328,14 +328,23 @@ static void STDMETHODCALLTYPE d2d_device_context_GetFactory(ID2D1DeviceContext *
static HRESULT STDMETHODCALLTYPE d2d_device_context_CreateBitmap(ID2D1DeviceContext *iface,
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);
struct d2d_device_context *context = 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(context->factory, context->device,
size, src_data, pitch, desc ? &bitmap_desc : NULL, &object)))
*bitmap = (ID2D1Bitmap *)&object->ID2D1Bitmap1_iface;
return hr;
......@@ -344,15 +353,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;
......@@ -361,14 +378,23 @@ 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;
......
......@@ -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,19 @@ 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);
ID2D1Bitmap1_Release(bitmap3);
ID2D1Bitmap_Release(bitmap2);
/* IDXGISurface1 is supported too. */
......@@ -6529,56 +6587,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)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment