d2d1: Update to ID2D1DrawingStateBlock1.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2018-09-14 08:50:30 +03:00 committed by Alexandre Julliard
parent 575c1c9066
commit 8b3a7c2581
4 changed files with 144 additions and 34 deletions

View File

@ -146,7 +146,7 @@ struct d2d_device_context
ID3D10BlendState *bs;
struct d2d_error_state error;
D2D1_DRAWING_STATE_DESCRIPTION drawing_state;
D2D1_DRAWING_STATE_DESCRIPTION1 drawing_state;
IDWriteRenderingParams *text_rendering_params;
IDWriteRenderingParams *default_text_rendering_params;
@ -356,16 +356,16 @@ struct d2d_bitmap *unsafe_impl_from_ID2D1Bitmap(ID2D1Bitmap *iface) DECLSPEC_HID
struct d2d_state_block
{
ID2D1DrawingStateBlock ID2D1DrawingStateBlock_iface;
ID2D1DrawingStateBlock1 ID2D1DrawingStateBlock1_iface;
LONG refcount;
ID2D1Factory *factory;
D2D1_DRAWING_STATE_DESCRIPTION drawing_state;
D2D1_DRAWING_STATE_DESCRIPTION1 drawing_state;
IDWriteRenderingParams *text_rendering_params;
};
void d2d_state_block_init(struct d2d_state_block *state_block, ID2D1Factory *factory,
const D2D1_DRAWING_STATE_DESCRIPTION *desc, IDWriteRenderingParams *text_rendering_params) DECLSPEC_HIDDEN;
const D2D1_DRAWING_STATE_DESCRIPTION1 *desc, IDWriteRenderingParams *text_rendering_params) DECLSPEC_HIDDEN;
struct d2d_state_block *unsafe_impl_from_ID2D1DrawingStateBlock(ID2D1DrawingStateBlock *iface) DECLSPEC_HIDDEN;
enum d2d_geometry_state

View File

@ -245,6 +245,7 @@ static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDrawingStateBlock(ID2D1Factor
const D2D1_DRAWING_STATE_DESCRIPTION *desc, IDWriteRenderingParams *text_rendering_params,
ID2D1DrawingStateBlock **state_block)
{
D2D1_DRAWING_STATE_DESCRIPTION1 state_desc;
struct d2d_state_block *object;
TRACE("iface %p, desc %p, text_rendering_params %p, state_block %p.\n",
@ -253,10 +254,17 @@ static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDrawingStateBlock(ID2D1Factor
if (!(object = heap_alloc_zero(sizeof(*object))))
return E_OUTOFMEMORY;
d2d_state_block_init(object, (ID2D1Factory *)iface, desc, text_rendering_params);
if (desc)
{
memcpy(&state_desc, desc, sizeof(*desc));
state_desc.primitiveBlend = D2D1_PRIMITIVE_BLEND_SOURCE_OVER;
state_desc.unitMode = D2D1_UNIT_MODE_DIPS;
}
d2d_state_block_init(object, (ID2D1Factory *)iface, desc ? &state_desc : NULL, text_rendering_params);
TRACE("Created state block %p.\n", object);
*state_block = &object->ID2D1DrawingStateBlock_iface;
*state_block = (ID2D1DrawingStateBlock *)&object->ID2D1DrawingStateBlock1_iface;
return S_OK;
}
@ -411,10 +419,20 @@ static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDrawingStateBlock1(ID2D1Facto
const D2D1_DRAWING_STATE_DESCRIPTION1 *desc, IDWriteRenderingParams *text_rendering_params,
ID2D1DrawingStateBlock1 **state_block)
{
FIXME("iface %p, desc %p, text_rendering_params %p, state_block %p stub!\n",
struct d2d_state_block *object;
TRACE("iface %p, desc %p, text_rendering_params %p, state_block %p.\n",
iface, desc, text_rendering_params, state_block);
return E_NOTIMPL;
if (!(object = heap_alloc_zero(sizeof(*object))))
return E_OUTOFMEMORY;
d2d_state_block_init(object, (ID2D1Factory *)iface, desc, text_rendering_params);
TRACE("Created state block %p.\n", object);
*state_block = &object->ID2D1DrawingStateBlock1_iface;
return S_OK;
}
static HRESULT STDMETHODCALLTYPE d2d_factory_CreateGdiMetafile(ID2D1Factory1 *iface,

View File

@ -23,20 +23,21 @@
WINE_DEFAULT_DEBUG_CHANNEL(d2d);
static inline struct d2d_state_block *impl_from_ID2D1DrawingStateBlock(ID2D1DrawingStateBlock *iface)
static inline struct d2d_state_block *impl_from_ID2D1DrawingStateBlock1(ID2D1DrawingStateBlock1 *iface)
{
return CONTAINING_RECORD(iface, struct d2d_state_block, ID2D1DrawingStateBlock_iface);
return CONTAINING_RECORD(iface, struct d2d_state_block, ID2D1DrawingStateBlock1_iface);
}
static HRESULT STDMETHODCALLTYPE d2d_state_block_QueryInterface(ID2D1DrawingStateBlock *iface, REFIID iid, void **out)
static HRESULT STDMETHODCALLTYPE d2d_state_block_QueryInterface(ID2D1DrawingStateBlock1 *iface, REFIID iid, void **out)
{
TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
if (IsEqualGUID(iid, &IID_ID2D1DrawingStateBlock)
if (IsEqualGUID(iid, &IID_ID2D1DrawingStateBlock1)
|| IsEqualGUID(iid, &IID_ID2D1DrawingStateBlock)
|| IsEqualGUID(iid, &IID_ID2D1Resource)
|| IsEqualGUID(iid, &IID_IUnknown))
{
ID2D1DrawingStateBlock_AddRef(iface);
ID2D1DrawingStateBlock1_AddRef(iface);
*out = iface;
return S_OK;
}
@ -47,9 +48,9 @@ static HRESULT STDMETHODCALLTYPE d2d_state_block_QueryInterface(ID2D1DrawingStat
return E_NOINTERFACE;
}
static ULONG STDMETHODCALLTYPE d2d_state_block_AddRef(ID2D1DrawingStateBlock *iface)
static ULONG STDMETHODCALLTYPE d2d_state_block_AddRef(ID2D1DrawingStateBlock1 *iface)
{
struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock(iface);
struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
ULONG refcount = InterlockedIncrement(&state_block->refcount);
TRACE("%p increasing refcount to %u.\n", iface, refcount);
@ -57,9 +58,9 @@ static ULONG STDMETHODCALLTYPE d2d_state_block_AddRef(ID2D1DrawingStateBlock *if
return refcount;
}
static ULONG STDMETHODCALLTYPE d2d_state_block_Release(ID2D1DrawingStateBlock *iface)
static ULONG STDMETHODCALLTYPE d2d_state_block_Release(ID2D1DrawingStateBlock1 *iface)
{
struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock(iface);
struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
ULONG refcount = InterlockedDecrement(&state_block->refcount);
TRACE("%p decreasing refcount to %u.\n", iface, refcount);
@ -75,39 +76,39 @@ static ULONG STDMETHODCALLTYPE d2d_state_block_Release(ID2D1DrawingStateBlock *i
return refcount;
}
static void STDMETHODCALLTYPE d2d_state_block_GetFactory(ID2D1DrawingStateBlock *iface, ID2D1Factory **factory)
static void STDMETHODCALLTYPE d2d_state_block_GetFactory(ID2D1DrawingStateBlock1 *iface, ID2D1Factory **factory)
{
struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock(iface);
struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
TRACE("iface %p, factory %p.\n", iface, factory);
ID2D1Factory_AddRef(*factory = state_block->factory);
}
static void STDMETHODCALLTYPE d2d_state_block_GetDescription(ID2D1DrawingStateBlock *iface,
static void STDMETHODCALLTYPE d2d_state_block_GetDescription(ID2D1DrawingStateBlock1 *iface,
D2D1_DRAWING_STATE_DESCRIPTION *desc)
{
struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock(iface);
struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
TRACE("iface %p, desc %p.\n", iface, desc);
*desc = state_block->drawing_state;
memcpy(desc, &state_block->drawing_state, sizeof(*desc));
}
static void STDMETHODCALLTYPE d2d_state_block_SetDescription(ID2D1DrawingStateBlock *iface,
static void STDMETHODCALLTYPE d2d_state_block_SetDescription(ID2D1DrawingStateBlock1 *iface,
const D2D1_DRAWING_STATE_DESCRIPTION *desc)
{
struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock(iface);
struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
TRACE("iface %p, desc %p.\n", iface, desc);
state_block->drawing_state = *desc;
memcpy(&state_block->drawing_state, desc, sizeof(*desc));
}
static void STDMETHODCALLTYPE d2d_state_block_SetTextRenderingParams(ID2D1DrawingStateBlock *iface,
static void STDMETHODCALLTYPE d2d_state_block_SetTextRenderingParams(ID2D1DrawingStateBlock1 *iface,
IDWriteRenderingParams *text_rendering_params)
{
struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock(iface);
struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
TRACE("iface %p, text_rendering_params %p.\n", iface, text_rendering_params);
@ -118,10 +119,10 @@ static void STDMETHODCALLTYPE d2d_state_block_SetTextRenderingParams(ID2D1Drawin
state_block->text_rendering_params = text_rendering_params;
}
static void STDMETHODCALLTYPE d2d_state_block_GetTextRenderingParams(ID2D1DrawingStateBlock *iface,
static void STDMETHODCALLTYPE d2d_state_block_GetTextRenderingParams(ID2D1DrawingStateBlock1 *iface,
IDWriteRenderingParams **text_rendering_params)
{
struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock(iface);
struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
TRACE("iface %p, text_rendering_params %p.\n", iface, text_rendering_params);
@ -129,7 +130,27 @@ static void STDMETHODCALLTYPE d2d_state_block_GetTextRenderingParams(ID2D1Drawin
IDWriteRenderingParams_AddRef(*text_rendering_params);
}
static const struct ID2D1DrawingStateBlockVtbl d2d_state_block_vtbl =
static void STDMETHODCALLTYPE d2d_state_block_GetDescription1(ID2D1DrawingStateBlock1 *iface,
D2D1_DRAWING_STATE_DESCRIPTION1 *desc)
{
struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
TRACE("iface %p, desc %p.\n", iface, desc);
*desc = state_block->drawing_state;
}
static void STDMETHODCALLTYPE d2d_state_block_SetDescription1(ID2D1DrawingStateBlock1 *iface,
const D2D1_DRAWING_STATE_DESCRIPTION1 *desc)
{
struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
TRACE("iface %p, desc %p.\n", iface, desc);
state_block->drawing_state = *desc;
}
static const struct ID2D1DrawingStateBlock1Vtbl d2d_state_block_vtbl =
{
d2d_state_block_QueryInterface,
d2d_state_block_AddRef,
@ -139,10 +160,12 @@ static const struct ID2D1DrawingStateBlockVtbl d2d_state_block_vtbl =
d2d_state_block_SetDescription,
d2d_state_block_SetTextRenderingParams,
d2d_state_block_GetTextRenderingParams,
d2d_state_block_GetDescription1,
d2d_state_block_SetDescription1,
};
void d2d_state_block_init(struct d2d_state_block *state_block, ID2D1Factory *factory,
const D2D1_DRAWING_STATE_DESCRIPTION *desc, IDWriteRenderingParams *text_rendering_params)
const D2D1_DRAWING_STATE_DESCRIPTION1 *desc, IDWriteRenderingParams *text_rendering_params)
{
static const D2D1_MATRIX_3X2_F identity =
{
@ -151,7 +174,7 @@ void d2d_state_block_init(struct d2d_state_block *state_block, ID2D1Factory *fac
0.0f, 0.0f,
};
state_block->ID2D1DrawingStateBlock_iface.lpVtbl = &d2d_state_block_vtbl;
state_block->ID2D1DrawingStateBlock1_iface.lpVtbl = &d2d_state_block_vtbl;
state_block->refcount = 1;
ID2D1Factory_AddRef(state_block->factory = factory);
if (desc)
@ -166,6 +189,6 @@ struct d2d_state_block *unsafe_impl_from_ID2D1DrawingStateBlock(ID2D1DrawingStat
{
if (!iface)
return NULL;
assert(iface->lpVtbl == &d2d_state_block_vtbl);
return CONTAINING_RECORD(iface, struct d2d_state_block, ID2D1DrawingStateBlock_iface);
assert(iface->lpVtbl == (ID2D1DrawingStateBlockVtbl *)&d2d_state_block_vtbl);
return CONTAINING_RECORD(iface, struct d2d_state_block, ID2D1DrawingStateBlock1_iface);
}

View File

@ -1277,6 +1277,7 @@ static void test_state_block(void)
ID2D1DrawingStateBlock *state_block;
IDWriteFactory *dwrite_factory;
IDXGISwapChain *swapchain;
ID2D1Factory1 *factory1;
ID2D1RenderTarget *rt;
ID3D10Device1 *device;
IDXGISurface *surface;
@ -1463,6 +1464,74 @@ static void test_state_block(void)
text_rendering_params2, text_rendering_params1);
IDWriteRenderingParams_Release(text_rendering_params2);
if (SUCCEEDED(ID2D1Factory_QueryInterface(factory, &IID_ID2D1Factory1, (void **)&factory1)))
{
D2D1_DRAWING_STATE_DESCRIPTION1 drawing_state1;
ID2D1DrawingStateBlock1 *state_block1;
hr = ID2D1DrawingStateBlock_QueryInterface(state_block, &IID_ID2D1DrawingStateBlock1, (void **)&state_block1);
ok(SUCCEEDED(hr), "Failed to get ID2D1DrawingStateBlock1 interface, hr %#x.\n", hr);
ID2D1DrawingStateBlock1_GetDescription(state_block1, &drawing_state1);
ok(drawing_state1.antialiasMode == D2D1_ANTIALIAS_MODE_ALIASED,
"Got unexpected antialias mode %#x.\n", drawing_state1.antialiasMode);
ok(drawing_state1.textAntialiasMode == D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE,
"Got unexpected text antialias mode %#x.\n", drawing_state1.textAntialiasMode);
ok(drawing_state1.tag1 == 3 && drawing_state1.tag2 == 4, "Got unexpected tags %s:%s.\n",
wine_dbgstr_longlong(drawing_state1.tag1), wine_dbgstr_longlong(drawing_state1.tag2));
ok(!memcmp(&drawing_state1.transform, &transform1, sizeof(drawing_state1.transform)),
"Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n",
drawing_state1.transform._11, drawing_state1.transform._12, drawing_state1.transform._21,
drawing_state1.transform._22, drawing_state1.transform._31, drawing_state1.transform._32);
ok(drawing_state1.primitiveBlend == D2D1_PRIMITIVE_BLEND_SOURCE_OVER,
"Got unexpected primitive blend mode %#x.\n", drawing_state1.primitiveBlend);
ok(drawing_state1.unitMode == D2D1_UNIT_MODE_DIPS, "Got unexpected unit mode %#x.\n", drawing_state1.unitMode);
ID2D1DrawingStateBlock1_GetTextRenderingParams(state_block1, &text_rendering_params2);
ok(text_rendering_params2 == text_rendering_params1, "Got unexpected text rendering params %p, expected %p.\n",
text_rendering_params2, text_rendering_params1);
IDWriteRenderingParams_Release(text_rendering_params2);
drawing_state1.primitiveBlend = D2D1_PRIMITIVE_BLEND_COPY;
drawing_state1.unitMode = D2D1_UNIT_MODE_PIXELS;
ID2D1DrawingStateBlock1_SetDescription(state_block1, &drawing_state1);
ID2D1DrawingStateBlock1_GetDescription(state_block1, &drawing_state1);
ok(drawing_state1.primitiveBlend == D2D1_PRIMITIVE_BLEND_COPY,
"Got unexpected primitive blend mode %#x.\n", drawing_state1.primitiveBlend);
ok(drawing_state1.unitMode == D2D1_UNIT_MODE_PIXELS,
"Got unexpected unit mode %#x.\n", drawing_state1.unitMode);
ID2D1DrawingStateBlock_SetDescription(state_block, &drawing_state);
ID2D1DrawingStateBlock1_GetDescription(state_block1, &drawing_state1);
ok(drawing_state1.primitiveBlend == D2D1_PRIMITIVE_BLEND_COPY,
"Got unexpected primitive blend mode %#x.\n", drawing_state1.primitiveBlend);
ok(drawing_state1.unitMode == D2D1_UNIT_MODE_PIXELS,
"Got unexpected unit mode %#x.\n", drawing_state1.unitMode);
ID2D1DrawingStateBlock1_Release(state_block1);
hr = ID2D1Factory1_CreateDrawingStateBlock(factory1, NULL, NULL, &state_block1);
ok(SUCCEEDED(hr), "Failed to create drawing state block, hr %#x\n", hr);
ID2D1DrawingStateBlock1_GetDescription(state_block1, &drawing_state1);
ok(drawing_state1.antialiasMode == D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
"Got unexpected antialias mode %#x.\n", drawing_state1.antialiasMode);
ok(drawing_state1.textAntialiasMode == D2D1_TEXT_ANTIALIAS_MODE_DEFAULT,
"Got unexpected text antialias mode %#x.\n", drawing_state1.textAntialiasMode);
ok(drawing_state1.tag1 == 0 && drawing_state1.tag2 == 0, "Got unexpected tags %s:%s.\n",
wine_dbgstr_longlong(drawing_state1.tag1), wine_dbgstr_longlong(drawing_state1.tag2));
ok(!memcmp(&drawing_state1.transform, &identity, sizeof(drawing_state1.transform)),
"Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n",
drawing_state1.transform._11, drawing_state1.transform._12, drawing_state1.transform._21,
drawing_state1.transform._22, drawing_state1.transform._31, drawing_state1.transform._32);
ok(drawing_state1.primitiveBlend == D2D1_PRIMITIVE_BLEND_SOURCE_OVER,
"Got unexpected primitive blend mode %#x.\n", drawing_state1.primitiveBlend);
ok(drawing_state1.unitMode == D2D1_UNIT_MODE_DIPS, "Got unexpected unit mode %#x.\n", drawing_state1.unitMode);
ID2D1DrawingStateBlock1_GetTextRenderingParams(state_block1, &text_rendering_params2);
ok(!text_rendering_params2, "Got unexpected text rendering params %p.\n", text_rendering_params2);
ID2D1DrawingStateBlock1_Release(state_block1);
ID2D1Factory1_Release(factory1);
}
ID2D1DrawingStateBlock_Release(state_block);
refcount = IDWriteRenderingParams_Release(text_rendering_params1);