[PATCH 2/5] d2d1: Partially implement RegisterEffectFromStream().
Ziqing Hui
zhui at codeweavers.com
Mon Jun 6 02:35:22 CDT 2022
Signed-off-by: Ziqing Hui <zhui at codeweavers.com>
---
List is used here rather than array. Because we will remove node in UnregisterEffect().
dlls/d2d1/Makefile.in | 2 +-
dlls/d2d1/d2d1_private.h | 16 +++++
dlls/d2d1/factory.c | 134 ++++++++++++++++++++++++++++++++++++++-
3 files changed, 149 insertions(+), 3 deletions(-)
diff --git a/dlls/d2d1/Makefile.in b/dlls/d2d1/Makefile.in
index 413571338ba..2456c63c336 100644
--- a/dlls/d2d1/Makefile.in
+++ b/dlls/d2d1/Makefile.in
@@ -1,6 +1,6 @@
MODULE = d2d1.dll
IMPORTLIB = d2d1
-IMPORTS = d3d10_1 dxguid uuid gdi32 user32 advapi32
+IMPORTS = d3d10_1 dxguid uuid gdi32 user32 advapi32 ole32 xmllite
DELAYIMPORTS = dwrite
C_SRCS = \
diff --git a/dlls/d2d1/d2d1_private.h b/dlls/d2d1/d2d1_private.h
index efc9247a822..cc625ff5719 100644
--- a/dlls/d2d1/d2d1_private.h
+++ b/dlls/d2d1/d2d1_private.h
@@ -768,4 +768,20 @@ static inline const char *debug_d2d_ellipse(const D2D1_ELLIPSE *ellipse)
ellipse->point.x, ellipse->point.y, ellipse->radiusX, ellipse->radiusY);
}
+static inline WCHAR *heap_strdupW(const WCHAR *str)
+{
+ WCHAR *ret = NULL;
+ size_t size;
+
+ if(!str)
+ return ret;
+
+ size = (wcslen(str) + 1) * sizeof(*str);
+ if(!(ret = heap_alloc(size)))
+ return ret;
+ memcpy(ret, str, size);
+
+ return ret;
+}
+
#endif /* __WINE_D2D1_PRIVATE_H */
diff --git a/dlls/d2d1/factory.c b/dlls/d2d1/factory.c
index 01dac8051c0..e8aa1fab012 100644
--- a/dlls/d2d1/factory.c
+++ b/dlls/d2d1/factory.c
@@ -18,6 +18,8 @@
#define D2D1_INIT_GUID
#include "d2d1_private.h"
+#include "xmllite.h"
+#include "wine/list.h"
WINE_DECLARE_DEBUG_CHANNEL(winediag);
WINE_DEFAULT_DEBUG_CHANNEL(d2d);
@@ -27,6 +29,16 @@ struct d2d_settings d2d_settings =
~0u, /* No ID2D1Factory version limit by default. */
};
+struct d2d_effect_reg
+{
+ PD2D1_EFFECT_FACTORY factory;
+ UINT32 count;
+
+ struct d2d_effect_info *info;
+
+ struct list entry;
+};
+
struct d2d_factory
{
ID2D1Factory3 ID2D1Factory3_iface;
@@ -39,6 +51,8 @@ struct d2d_factory
float dpi_y;
CRITICAL_SECTION cs;
+
+ struct list effect_regs;
};
static inline struct d2d_factory *impl_from_ID2D1Factory3(ID2D1Factory3 *iface)
@@ -51,6 +65,15 @@ static inline struct d2d_factory *impl_from_ID2D1Multithread(ID2D1Multithread *i
return CONTAINING_RECORD(iface, struct d2d_factory, ID2D1Multithread_iface);
}
+static void d2d_effect_reg_cleanup(struct d2d_effect_reg *reg)
+{
+ if (!reg)
+ return;
+
+ heap_free(reg->info);
+ heap_free(reg);
+}
+
static HRESULT d2d_factory_reload_sysmetrics(struct d2d_factory *factory)
{
HDC hdc;
@@ -112,6 +135,7 @@ static ULONG STDMETHODCALLTYPE d2d_factory_Release(ID2D1Factory3 *iface)
{
struct d2d_factory *factory = impl_from_ID2D1Factory3(iface);
ULONG refcount = InterlockedDecrement(&factory->refcount);
+ struct d2d_effect_reg *iter, *iter2;
TRACE("%p decreasing refcount to %lu.\n", iface, refcount);
@@ -120,6 +144,8 @@ static ULONG STDMETHODCALLTYPE d2d_factory_Release(ID2D1Factory3 *iface)
if (factory->device)
ID3D10Device1_Release(factory->device);
DeleteCriticalSection(&factory->cs);
+ LIST_FOR_EACH_ENTRY_SAFE(iter, iter2, &factory->effect_regs, struct d2d_effect_reg, entry)
+ d2d_effect_reg_cleanup(iter);
heap_free(factory);
}
@@ -564,14 +590,117 @@ static HRESULT STDMETHODCALLTYPE d2d_factory_CreateGdiMetafile(ID2D1Factory3 *if
return E_NOTIMPL;
}
+static HRESULT parse_effect_xml(IStream *property_xml, struct d2d_effect_reg *reg)
+{
+ unsigned int i, len, depth, input_count = 0;
+ IXmlReader *xml_reader;
+ WCHAR *node_name[3];
+ const WCHAR *value;
+ XmlNodeType type;
+ HRESULT hr;
+
+ if (FAILED(hr = CreateXmlReader(&IID_IXmlReader, (void **)&xml_reader, NULL)))
+ return hr;
+ if (FAILED(hr = IXmlReader_SetInput(xml_reader, (IUnknown *)property_xml)))
+ goto done;
+
+ memset(node_name, 0, sizeof(node_name));
+ while (IXmlReader_Read(xml_reader, &type) == S_OK)
+ {
+ if (FAILED(hr = IXmlReader_GetDepth(xml_reader, &depth)))
+ goto done;
+ if (depth >= 3)
+ continue;
+ if (FAILED(hr = IXmlReader_GetLocalName(xml_reader, &value, &len)))
+ goto done;
+ if (node_name[depth] && wcslen(node_name[depth]) <= len)
+ {
+ wcscpy(node_name[depth], value);
+ }
+ else
+ {
+ heap_free(node_name[depth]);
+ node_name[depth] = heap_strdupW(value);
+ }
+
+ if (type != XmlNodeType_Element)
+ continue;
+
+ switch (depth)
+ {
+ case 1:
+ if (!wcscmp(node_name[depth - 1], L"Effect")
+ && !wcscmp(node_name[depth], L"Property"))
+ {
+ FIXME("Property is ignored.\n");
+ }
+ break;
+ case 2:
+ if (!wcscmp(node_name[depth - 1], L"Inputs")
+ && !wcscmp(node_name[depth], L"Input"))
+ {
+ ++input_count;
+ }
+ else if (!wcscmp(node_name[depth - 1], L"Property")
+ && !wcscmp(node_name[depth], L"Property"))
+ {
+ FIXME("Sub property is ignored.\n");
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ reg->info->default_input_count = input_count;
+ reg->info->min_inputs = input_count;
+ reg->info->max_inputs = input_count;
+
+done:
+ for (i = 0; i < ARRAY_SIZE(node_name); ++i)
+ heap_free(node_name[i]);
+ IXmlReader_Release(xml_reader);
+ return hr;
+}
+
static HRESULT STDMETHODCALLTYPE d2d_factory_RegisterEffectFromStream(ID2D1Factory3 *iface,
REFCLSID effect_id, IStream *property_xml, const D2D1_PROPERTY_BINDING *bindings,
UINT32 binding_count, PD2D1_EFFECT_FACTORY effect_factory)
{
- FIXME("iface %p, effect_id %s, property_xml %p, bindings %p, binding_count %u, effect_factory %p stub!\n",
+ struct d2d_factory *factory = impl_from_ID2D1Factory3(iface);
+ struct d2d_effect_reg *iter, *entry = NULL;
+ HRESULT hr;
+
+ TRACE("iface %p, effect_id %s, property_xml %p, bindings %p, binding_count %u, effect_factory %p.\n",
iface, debugstr_guid(effect_id), property_xml, bindings, binding_count, effect_factory);
- return E_NOTIMPL;
+ LIST_FOR_EACH_ENTRY(iter, &factory->effect_regs, struct d2d_effect_reg, entry)
+ {
+ if (IsEqualGUID(effect_id, iter->info->clsid))
+ {
+ ++iter->count;
+ return S_OK;
+ }
+ }
+
+ if (!(entry = heap_alloc_zero(sizeof(*entry))) || !(entry->info = heap_alloc_zero(sizeof(*entry->info))))
+ {
+ hr = E_OUTOFMEMORY;
+ goto done;
+ }
+
+ if (FAILED(hr = parse_effect_xml(property_xml, entry)))
+ goto done;
+
+ entry->count = 1;
+ entry->info->clsid = effect_id;
+ entry->factory = effect_factory;
+ list_add_tail(&factory->effect_regs, &entry->entry);
+
+done:
+ if (hr != S_OK)
+ d2d_effect_reg_cleanup(entry);
+ return hr;
}
static HRESULT STDMETHODCALLTYPE d2d_factory_RegisterEffectFromString(ID2D1Factory3 *iface,
@@ -743,6 +872,7 @@ static void d2d_factory_init(struct d2d_factory *factory, D2D1_FACTORY_TYPE fact
factory->refcount = 1;
d2d_factory_reload_sysmetrics(factory);
InitializeCriticalSection(&factory->cs);
+ list_init(&factory->effect_regs);
}
HRESULT WINAPI D2D1CreateFactory(D2D1_FACTORY_TYPE factory_type, REFIID iid,
--
2.25.1
More information about the wine-devel
mailing list