[PATCH v2 5/8] d2d1: Move CreateEffect() implementation to effect context.
Ziqing Hui
zhui at codeweavers.com
Thu Apr 28 05:40:26 CDT 2022
Signed-off-by: Ziqing Hui <zhui at codeweavers.com>
---
We hold an effect context reference in effect.
See https://docs.microsoft.com/en-us/windows/win32/api/d2d1effectauthor/nn-d2d1effectauthor-id2d1effectcontext
"Each call to ID2D1EffectImpl::Initialize will be provided a different ID2D1EffectContext interface."
This means that device context and effect context are not one-on-one. And each effect has an effect context.
"This interface tracks resource allocations for the effect. When the effect is released,
the corresponding allocations will also be released."
dlls/d2d1/d2d1_private.h | 4 +++-
dlls/d2d1/device.c | 18 ++++++------------
dlls/d2d1/effect.c | 27 +++++++++++++++++++++++----
3 files changed, 32 insertions(+), 17 deletions(-)
diff --git a/dlls/d2d1/d2d1_private.h b/dlls/d2d1/d2d1_private.h
index eb2f71f7c03..8f8ffc5fd0e 100644
--- a/dlls/d2d1/d2d1_private.h
+++ b/dlls/d2d1/d2d1_private.h
@@ -597,12 +597,14 @@ struct d2d_effect
const struct d2d_effect_info *info;
ID2D1Factory *factory;
+ ID2D1EffectContext *effect_context;
ID2D1Image **inputs;
size_t inputs_size;
size_t input_count;
};
-HRESULT d2d_effect_init(struct d2d_effect *effect, ID2D1Factory *factory, const CLSID *effect_id) DECLSPEC_HIDDEN;
+HRESULT d2d_effect_init(struct d2d_effect *effect,
+ struct d2d_effect_context *effect_context, const CLSID *effect_id) DECLSPEC_HIDDEN;
static inline BOOL d2d_array_reserve(void **elements, size_t *capacity, size_t count, size_t size)
{
diff --git a/dlls/d2d1/device.c b/dlls/d2d1/device.c
index 13c99458cfa..03195c8c557 100644
--- a/dlls/d2d1/device.c
+++ b/dlls/d2d1/device.c
@@ -1890,25 +1890,19 @@ static HRESULT STDMETHODCALLTYPE d2d_device_context_CreateEffect(ID2D1DeviceCont
REFCLSID effect_id, ID2D1Effect **effect)
{
struct d2d_device_context *context = impl_from_ID2D1DeviceContext(iface);
- struct d2d_effect *object;
+ struct d2d_effect_context *effect_context;
HRESULT hr;
FIXME("iface %p, effect_id %s, effect %p stub!\n", iface, debugstr_guid(effect_id), effect);
- if (!(object = heap_alloc_zero(sizeof(*object))))
+ if (!(effect_context = heap_alloc_zero(sizeof(*effect_context))))
return E_OUTOFMEMORY;
+ d2d_effect_context_init(effect_context, iface);
- if (FAILED(hr = d2d_effect_init(object, context->factory, effect_id)))
- {
- WARN("Failed to initialise effect, hr %#lx.\n", hr);
- heap_free(object);
- return hr;
- }
+ hr = ID2D1EffectContext_CreateEffect(&effect_context->ID2D1EffectContext_iface, effect_id, effect);
- TRACE("Created effect %p.\n", object);
- *effect = &object->ID2D1Effect_iface;
-
- return S_OK;
+ ID2D1EffectContext_Release(&effect_context->ID2D1EffectContext_iface);
+ return hr;
}
static HRESULT STDMETHODCALLTYPE d2d_device_context_ID2D1DeviceContext_CreateGradientStopCollection(
diff --git a/dlls/d2d1/effect.c b/dlls/d2d1/effect.c
index bfb2e9d16d9..b14c2fae373 100644
--- a/dlls/d2d1/effect.c
+++ b/dlls/d2d1/effect.c
@@ -92,9 +92,26 @@ static void STDMETHODCALLTYPE d2d_effect_context_GetDpi(ID2D1EffectContext *ifac
static HRESULT STDMETHODCALLTYPE d2d_effect_context_CreateEffect(ID2D1EffectContext *iface,
REFCLSID clsid, ID2D1Effect **effect)
{
- FIXME("iface %p, clsid %s, effect %p stub!\n", iface, debugstr_guid(clsid), effect);
+ struct d2d_effect_context *effect_context = impl_from_ID2D1EffectContext(iface);
+ struct d2d_effect *object;
+ HRESULT hr;
- return E_NOTIMPL;
+ TRACE("iface %p, clsid %s, effect %p.\n", iface, debugstr_guid(clsid), effect);
+
+ if (!(object = heap_alloc_zero(sizeof(*object))))
+ return E_OUTOFMEMORY;
+
+ if (FAILED(hr = d2d_effect_init(object, effect_context, clsid)))
+ {
+ WARN("Failed to initialise effect, hr %#lx.\n", hr);
+ heap_free(object);
+ return hr;
+ }
+
+ TRACE("Created effect %p.\n", object);
+ *effect = &object->ID2D1Effect_iface;
+
+ return S_OK;
}
static HRESULT STDMETHODCALLTYPE d2d_effect_context_GetMaximumSupportedFeatureLevel(ID2D1EffectContext *iface,
@@ -308,6 +325,7 @@ static void d2d_effect_cleanup(struct d2d_effect *effect)
ID2D1Image_Release(effect->inputs[i]);
}
heap_free(effect->inputs);
+ ID2D1EffectContext_Release(effect->effect_context);
ID2D1Factory_Release(effect->factory);
}
@@ -635,7 +653,7 @@ static const ID2D1ImageVtbl d2d_effect_image_vtbl =
d2d_effect_image_GetFactory,
};
-HRESULT d2d_effect_init(struct d2d_effect *effect, ID2D1Factory *factory, const CLSID *effect_id)
+HRESULT d2d_effect_init(struct d2d_effect *effect, struct d2d_effect_context *effect_context, const CLSID *effect_id)
{
unsigned int i;
@@ -649,7 +667,8 @@ HRESULT d2d_effect_init(struct d2d_effect *effect, ID2D1Factory *factory, const
{
effect->info = &builtin_effects[i];
d2d_effect_SetInputCount(&effect->ID2D1Effect_iface, effect->info->default_input_count);
- ID2D1Factory_AddRef(effect->factory = factory);
+ ID2D1Factory_AddRef(effect->factory = effect_context->factory);
+ ID2D1EffectContext_AddRef(effect->effect_context = &effect_context->ID2D1EffectContext_iface);
return S_OK;
}
}
--
2.25.1
More information about the wine-devel
mailing list