Module: wine Branch: master Commit: 798d659f04250757ee18b009619f08d45e99b395 URL: https://gitlab.winehq.org/wine/wine/-/commit/798d659f04250757ee18b009619f08d...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Mon Nov 14 09:22:58 2022 +0300
d2d1: Silently ignore non-default state block implementations.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=53915 Signed-off-by: Nikolay Sivov nsivov@codeweavers.com
---
dlls/d2d1/device.c | 6 ++++-- dlls/d2d1/state_block.c | 6 +++++- dlls/d2d1/tests/d2d1.c | 10 ++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/dlls/d2d1/device.c b/dlls/d2d1/device.c index 72781a48d10..89d17149ca4 100644 --- a/dlls/d2d1/device.c +++ b/dlls/d2d1/device.c @@ -1735,11 +1735,12 @@ static HRESULT STDMETHODCALLTYPE d2d_device_context_Flush(ID2D1DeviceContext1 *i static void STDMETHODCALLTYPE d2d_device_context_SaveDrawingState(ID2D1DeviceContext1 *iface, ID2D1DrawingStateBlock *state_block) { - struct d2d_state_block *state_block_impl = unsafe_impl_from_ID2D1DrawingStateBlock(state_block); struct d2d_device_context *render_target = impl_from_ID2D1DeviceContext(iface); + struct d2d_state_block *state_block_impl;
TRACE("iface %p, state_block %p.\n", iface, state_block);
+ if (!(state_block_impl = unsafe_impl_from_ID2D1DrawingStateBlock(state_block))) return; state_block_impl->drawing_state = render_target->drawing_state; if (render_target->text_rendering_params) IDWriteRenderingParams_AddRef(render_target->text_rendering_params); @@ -1751,11 +1752,12 @@ static void STDMETHODCALLTYPE d2d_device_context_SaveDrawingState(ID2D1DeviceCon static void STDMETHODCALLTYPE d2d_device_context_RestoreDrawingState(ID2D1DeviceContext1 *iface, ID2D1DrawingStateBlock *state_block) { - struct d2d_state_block *state_block_impl = unsafe_impl_from_ID2D1DrawingStateBlock(state_block); struct d2d_device_context *context = impl_from_ID2D1DeviceContext(iface); + struct d2d_state_block *state_block_impl;
TRACE("iface %p, state_block %p.\n", iface, state_block);
+ if (!(state_block_impl = unsafe_impl_from_ID2D1DrawingStateBlock(state_block))) return; if (context->target.type == D2D_TARGET_COMMAND_LIST) { struct d2d_command_list *command_list = context->target.command_list; diff --git a/dlls/d2d1/state_block.c b/dlls/d2d1/state_block.c index 7415471ce3a..770c165fd90 100644 --- a/dlls/d2d1/state_block.c +++ b/dlls/d2d1/state_block.c @@ -186,6 +186,10 @@ struct d2d_state_block *unsafe_impl_from_ID2D1DrawingStateBlock(ID2D1DrawingStat { if (!iface) return NULL; - assert(iface->lpVtbl == (ID2D1DrawingStateBlockVtbl *)&d2d_state_block_vtbl); + if (iface->lpVtbl != (ID2D1DrawingStateBlockVtbl *)&d2d_state_block_vtbl) + { + WARN("Unexpected state block vtbl %p.\n", iface->lpVtbl); + return NULL; + } return CONTAINING_RECORD(iface, struct d2d_state_block, ID2D1DrawingStateBlock1_iface); } diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index 1dcce63381e..1935955ec84 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -1835,6 +1835,7 @@ static void test_state_block(BOOL d3d11) ID2D1Factory *factory; ULONG refcount; HRESULT hr; + void *ptr; static const D2D1_MATRIX_3X2_F identity = {{{ 1.0f, 0.0f, @@ -2078,6 +2079,15 @@ static void test_state_block(BOOL d3d11)
refcount = IDWriteRenderingParams_Release(text_rendering_params1); ok(!refcount, "Rendering params %lu references left.\n", refcount); + + /* State block object pointer is validated, but does not result in an error state. */ + ptr = (void *)0xdeadbeef; + ID2D1RenderTarget_BeginDraw(rt); + ID2D1RenderTarget_SaveDrawingState(rt, (ID2D1DrawingStateBlock *)&ptr); + ID2D1RenderTarget_RestoreDrawingState(rt, (ID2D1DrawingStateBlock *)&ptr); + hr = ID2D1RenderTarget_EndDraw(rt, NULL, NULL); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + release_test_context(&ctx); }