[PATCH 7/9] d2d1: Partially implement ID2D1Device
Lucian Poston
lucian.poston at gmail.com
Tue Nov 21 02:41:11 CST 2017
https://bugs.winehq.org/show_bug.cgi?id=44052
Signed-off-by: Lucian Poston <lucian.poston at gmail.com>
---
dlls/d2d1/d2d1_private.h | 10 ++++++++
dlls/d2d1/device.c | 61 +++++++++++++++++++++++++++++++++++++-----------
dlls/d2d1/factory.c | 16 +++++++++++--
3 files changed, 71 insertions(+), 16 deletions(-)
diff --git a/dlls/d2d1/d2d1_private.h b/dlls/d2d1/d2d1_private.h
index 69560e93f0..edeed5106b 100644
--- a/dlls/d2d1/d2d1_private.h
+++ b/dlls/d2d1/d2d1_private.h
@@ -535,4 +535,14 @@ static inline const char *debug_d2d_rect_f(const D2D1_RECT_F *rect)
return wine_dbg_sprintf("(%.8e,%.8e)-(%.8e,%.8e)", rect->left, rect->top, rect->right, rect->bottom );
}
+struct d2d_device
+{
+ ID2D1Device ID2D1Device_iface;
+ LONG refcount;
+ ID2D1Factory1 *factory;
+ IDXGIDevice *dxgi_device;
+};
+
+void d2d_device_init(struct d2d_device *This, ID2D1Factory1 *iface, IDXGIDevice *dxgiDevice) DECLSPEC_HIDDEN;
+
#endif /* __WINE_D2D1_PRIVATE_H */
diff --git a/dlls/d2d1/device.c b/dlls/d2d1/device.c
index 900541759e..b5007a9dd5 100644
--- a/dlls/d2d1/device.c
+++ b/dlls/d2d1/device.c
@@ -23,12 +23,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(d2d);
-struct d2d_device
-{
- ID2D1Device ID2D1Device_iface;
- LONG refcount;
-};
-
static inline struct d2d_device *impl_from_ID2D1Device(ID2D1Device *iface)
{
return CONTAINING_RECORD(iface, struct d2d_device, ID2D1Device_iface);
@@ -39,25 +33,48 @@ static HRESULT WINAPI d2d_device_QueryInterface(
REFIID riid,
void **ppvObject)
{
- struct d2d_device *This = impl_from_ID2D1Device(iface);
- FIXME("%p stub!\n", This);
- return E_NOTIMPL;
+ TRACE("iface %p, riid %s, ppvObject %p.\n", iface, debugstr_guid(riid), ppvObject);
+ if (ppvObject == NULL)
+ return E_POINTER;
+
+ if (IsEqualGUID(riid, &IID_ID2D1Device)
+ || IsEqualGUID(riid, &IID_ID2D1Resource)
+ || IsEqualGUID(riid, &IID_IUnknown))
+ {
+ ID2D1Device_AddRef(iface);
+ *ppvObject = iface;
+ return S_OK;
+ }
+
+ WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
+ *ppvObject = NULL;
+ return E_NOINTERFACE;
}
static ULONG WINAPI d2d_device_AddRef(
ID2D1Device *iface)
{
struct d2d_device *This = impl_from_ID2D1Device(iface);
- FIXME("%p stub!\n", This);
- return 0;
+ ULONG refcount = InterlockedIncrement(&This->refcount);
+ TRACE("%p increasing refcount to %u.\n", iface, refcount);
+ return refcount;
}
static ULONG WINAPI d2d_device_Release(
ID2D1Device *iface)
{
struct d2d_device *This = impl_from_ID2D1Device(iface);
- FIXME("%p stub!\n", This);
- return 0;
+ ULONG refcount = InterlockedDecrement(&This->refcount);
+ TRACE("%p decreasing refcount to %u.\n", iface, refcount);
+
+ if (refcount == 0)
+ {
+ IDXGIDevice_Release(This->dxgi_device);
+ ID2D1Factory1_Release(This->factory);
+ HeapFree(GetProcessHeap(), 0, This);
+ }
+
+ return refcount;
}
static void WINAPI d2d_device_GetFactory(
@@ -65,7 +82,13 @@ static void WINAPI d2d_device_GetFactory(
ID2D1Factory **factory)
{
struct d2d_device *This = impl_from_ID2D1Device(iface);
- FIXME("%p stub!\n", This);
+
+ TRACE("iface %p, factory %p.\n", iface, factory);
+ if (factory == NULL)
+ return;
+
+ *factory = (ID2D1Factory *)This->factory;
+ ID2D1Factory1_AddRef(This->factory);
}
static HRESULT WINAPI d2d_device_CreateDeviceContext(
@@ -127,3 +150,13 @@ static const struct ID2D1DeviceVtbl d2d_device_vtbl =
d2d_device_GetMaximumTextureMemory,
d2d_device_ClearResources,
};
+
+void d2d_device_init(struct d2d_device *This, ID2D1Factory1 *iface, IDXGIDevice *dxgiDevice)
+{
+ This->ID2D1Device_iface.lpVtbl = &d2d_device_vtbl;
+ This->refcount = 1;
+ This->factory = iface;
+ ID2D1Factory1_AddRef(This->factory);
+ This->dxgi_device = dxgiDevice;
+ IDXGIDevice_AddRef(This->dxgi_device);
+}
diff --git a/dlls/d2d1/factory.c b/dlls/d2d1/factory.c
index b3ec865dac..c740894fc9 100644
--- a/dlls/d2d1/factory.c
+++ b/dlls/d2d1/factory.c
@@ -372,8 +372,20 @@ static HRESULT WINAPI d2d_factory1_CreateDevice(
ID2D1Device **d2dDevice)
{
struct d2d_factory *This = impl_from_ID2D1Factory(iface);
- FIXME("%p stub!\n", This);
- return E_NOTIMPL;
+ struct d2d_device *object;
+
+ TRACE("This %p, dxgiDevice %p\n", This, dxgiDevice);
+ if (d2dDevice == NULL)
+ return E_POINTER;
+
+ if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
+ return E_OUTOFMEMORY;
+
+ d2d_device_init(object, iface, dxgiDevice);
+ *d2dDevice = &object->ID2D1Device_iface;
+ TRACE("Created device %p.\n", object);
+
+ return S_OK;
}
static HRESULT WINAPI d2d_factory1_ID2D1Factory1_CreateStrokeStyle(
--
2.13.6
More information about the wine-devel
mailing list