From: Zhiyi Zhang zzhang@codeweavers.com
--- dlls/d2d1/d2d1_private.h | 6 +++++- dlls/d2d1/dc_render_target.c | 2 +- dlls/d2d1/device.c | 20 ++++++++++++++++---- dlls/d2d1/factory.c | 34 ++++++++++------------------------ dlls/d2d1/hwnd_render_target.c | 2 +- dlls/d2d1/tests/d2d1.c | 30 ++++++------------------------ dlls/d2d1/wic_render_target.c | 2 +- 7 files changed, 40 insertions(+), 56 deletions(-)
diff --git a/dlls/d2d1/d2d1_private.h b/dlls/d2d1/d2d1_private.h index 58507fd2c0b..d6dad474cf3 100644 --- a/dlls/d2d1/d2d1_private.h +++ b/dlls/d2d1/d2d1_private.h @@ -613,6 +613,7 @@ struct d2d_device LONG refcount; ID2D1Factory1 *factory; IDXGIDevice *dxgi_device; + bool allow_get_dxgi_device;
struct d2d_indexed_objects shaders; }; @@ -706,13 +707,16 @@ static inline struct d2d_factory *unsafe_impl_from_ID2D1Factory(ID2D1Factory *if }
void d2d_effects_init_builtins(struct d2d_factory *factory); +HRESULT d2d_factory_create_device(ID2D1Factory1 *factory, IDXGIDevice *dxgi_device, + bool allow_get_dxgi_device, REFIID iid, void **device); struct d2d_effect_registration * d2d_factory_get_registered_effect(ID2D1Factory *factory, const GUID *effect_id); void d2d_factory_register_effect(struct d2d_factory *factory, struct d2d_effect_registration *effect); HRESULT d2d_effect_property_get_uint32_value(const struct d2d_effect_properties *properties, const struct d2d_effect_property *prop, UINT32 *value); -void d2d_device_init(struct d2d_device *device, struct d2d_factory *factory, IDXGIDevice *dxgi_device); +void d2d_device_init(struct d2d_device *device, ID2D1Factory1 *factory, IDXGIDevice *dxgi_device, + bool allow_get_dxgi_device);
struct d2d_transform { diff --git a/dlls/d2d1/dc_render_target.c b/dlls/d2d1/dc_render_target.c index aa0c715baa5..adda6560deb 100644 --- a/dlls/d2d1/dc_render_target.c +++ b/dlls/d2d1/dc_render_target.c @@ -856,7 +856,7 @@ HRESULT d2d_dc_render_target_init(struct d2d_dc_render_target *render_target, ID return hr; }
- hr = ID2D1Factory1_CreateDevice(factory, dxgi_device, &device); + hr = d2d_factory_create_device(factory, dxgi_device, false, &IID_ID2D1Device, (void **)&device); IDXGIDevice_Release(dxgi_device); if (FAILED(hr)) { diff --git a/dlls/d2d1/device.c b/dlls/d2d1/device.c index ce0175966b1..e0eb8dd1dd0 100644 --- a/dlls/d2d1/device.c +++ b/dlls/d2d1/device.c @@ -4426,9 +4426,19 @@ static void STDMETHODCALLTYPE d2d_device_FlushDeviceContexts(ID2D1Device6 *iface static HRESULT STDMETHODCALLTYPE d2d_device_GetDxgiDevice(ID2D1Device6 *iface, IDXGIDevice **dxgi_device) { - FIXME("iface %p, dxgi_device %p stub!\n", iface, dxgi_device); + struct d2d_device *device = impl_from_ID2D1Device(iface);
- return E_NOTIMPL; + TRACE("iface %p, dxgi_device %p.\n", iface, dxgi_device); + + if (!device->allow_get_dxgi_device) + { + *dxgi_device = NULL; + return D2DERR_INVALID_CALL; + } + + IDXGIDevice_AddRef(device->dxgi_device); + *dxgi_device = device->dxgi_device; + return S_OK; }
static HRESULT STDMETHODCALLTYPE d2d_device_ID2D1Device3_CreateDeviceContext(ID2D1Device6 *iface, @@ -4517,14 +4527,16 @@ struct d2d_device *unsafe_impl_from_ID2D1Device(ID2D1Device1 *iface) return CONTAINING_RECORD(iface, struct d2d_device, ID2D1Device6_iface); }
-void d2d_device_init(struct d2d_device *device, struct d2d_factory *factory, IDXGIDevice *dxgi_device) +void d2d_device_init(struct d2d_device *device, ID2D1Factory1 *factory, IDXGIDevice *dxgi_device, + bool allow_get_dxgi_device) { device->ID2D1Device6_iface.lpVtbl = &d2d_device_vtbl; device->refcount = 1; - device->factory = (ID2D1Factory1 *)&factory->ID2D1Factory7_iface; + device->factory = factory; ID2D1Factory1_AddRef(device->factory); device->dxgi_device = dxgi_device; IDXGIDevice_AddRef(device->dxgi_device); + device->allow_get_dxgi_device = allow_get_dxgi_device; }
HRESULT d2d_device_add_indexed_object(struct d2d_indexed_objects *objects, diff --git a/dlls/d2d1/factory.c b/dlls/d2d1/factory.c index 954d90efc0e..797a3b2fb1d 100644 --- a/dlls/d2d1/factory.c +++ b/dlls/d2d1/factory.c @@ -513,8 +513,8 @@ static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDCRenderTarget(ID2D1Factory7 return S_OK; }
-static HRESULT d2d_factory_create_device(struct d2d_factory *factory, IDXGIDevice *dxgi_device, - REFIID iid, void **device) +HRESULT d2d_factory_create_device(ID2D1Factory1 *factory, IDXGIDevice *dxgi_device, + bool allow_get_dxgi_device, REFIID iid, void **device) { struct d2d_device *object; HRESULT hr; @@ -522,7 +522,7 @@ static HRESULT d2d_factory_create_device(struct d2d_factory *factory, IDXGIDevic if (!(object = calloc(1, sizeof(*object)))) return E_OUTOFMEMORY;
- d2d_device_init(object, factory, dxgi_device); + d2d_device_init(object, factory, dxgi_device, allow_get_dxgi_device);
TRACE("Create device %p.\n", object);
@@ -535,11 +535,9 @@ static HRESULT d2d_factory_create_device(struct d2d_factory *factory, IDXGIDevic static HRESULT STDMETHODCALLTYPE d2d_factory_CreateDevice(ID2D1Factory7 *iface, IDXGIDevice *dxgi_device, ID2D1Device **device) { - struct d2d_factory *factory = impl_from_ID2D1Factory7(iface); - TRACE("iface %p, dxgi_device %p, device %p.\n", iface, dxgi_device, device);
- return d2d_factory_create_device(factory, dxgi_device, &IID_ID2D1Device, (void **)device); + return d2d_factory_create_device((ID2D1Factory1 *)iface, dxgi_device, true, &IID_ID2D1Device, (void **)device); }
static HRESULT STDMETHODCALLTYPE d2d_factory_CreateStrokeStyle1(ID2D1Factory7 *iface, @@ -1189,61 +1187,49 @@ static HRESULT STDMETHODCALLTYPE d2d_factory_GetEffectProperties(ID2D1Factory7 * static HRESULT STDMETHODCALLTYPE d2d_factory_ID2D1Factory2_CreateDevice(ID2D1Factory7 *iface, IDXGIDevice *dxgi_device, ID2D1Device1 **device) { - struct d2d_factory *factory = impl_from_ID2D1Factory7(iface); - TRACE("iface %p, dxgi_device %p, device %p.\n", iface, dxgi_device, device);
- return d2d_factory_create_device(factory, dxgi_device, &IID_ID2D1Device1, (void **)device); + return d2d_factory_create_device((ID2D1Factory1 *)iface, dxgi_device, true, &IID_ID2D1Device1, (void **)device); }
static HRESULT STDMETHODCALLTYPE d2d_factory_ID2D1Factory3_CreateDevice(ID2D1Factory7 *iface, IDXGIDevice *dxgi_device, ID2D1Device2 **device) { - struct d2d_factory *factory = impl_from_ID2D1Factory7(iface); - TRACE("iface %p, dxgi_device %p, device %p.\n", iface, dxgi_device, device);
- return d2d_factory_create_device(factory, dxgi_device, &IID_ID2D1Device2, (void **)device); + return d2d_factory_create_device((ID2D1Factory1 *)iface, dxgi_device, true, &IID_ID2D1Device2, (void **)device); }
static HRESULT STDMETHODCALLTYPE d2d_factory_ID2D1Factory4_CreateDevice(ID2D1Factory7 *iface, IDXGIDevice *dxgi_device, ID2D1Device3 **device) { - struct d2d_factory *factory = impl_from_ID2D1Factory7(iface); - TRACE("iface %p, dxgi_device %p, device %p.\n", iface, dxgi_device, device);
- return d2d_factory_create_device(factory, dxgi_device, &IID_ID2D1Device3, (void **)device); + return d2d_factory_create_device((ID2D1Factory1 *)iface, dxgi_device, true, &IID_ID2D1Device3, (void **)device); }
static HRESULT STDMETHODCALLTYPE d2d_factory_ID2D1Factory5_CreateDevice(ID2D1Factory7 *iface, IDXGIDevice *dxgi_device, ID2D1Device4 **device) { - struct d2d_factory *factory = impl_from_ID2D1Factory7(iface); - TRACE("iface %p, dxgi_device %p, device %p.\n", iface, dxgi_device, device);
- return d2d_factory_create_device(factory, dxgi_device, &IID_ID2D1Device4, (void **)device); + return d2d_factory_create_device((ID2D1Factory1 *)iface, dxgi_device, true, &IID_ID2D1Device4, (void **)device); }
static HRESULT STDMETHODCALLTYPE d2d_factory_ID2D1Factory6_CreateDevice(ID2D1Factory7 *iface, IDXGIDevice *dxgi_device, ID2D1Device5 **device) { - struct d2d_factory *factory = impl_from_ID2D1Factory7(iface); - TRACE("iface %p, dxgi_device %p, device %p.\n", iface, dxgi_device, device);
- return d2d_factory_create_device(factory, dxgi_device, &IID_ID2D1Device5, (void **)device); + return d2d_factory_create_device((ID2D1Factory1 *)iface, dxgi_device, true, &IID_ID2D1Device5, (void **)device); }
static HRESULT STDMETHODCALLTYPE d2d_factory_ID2D1Factory7_CreateDevice(ID2D1Factory7 *iface, IDXGIDevice *dxgi_device, ID2D1Device6 **device) { - struct d2d_factory *factory = impl_from_ID2D1Factory7(iface); - TRACE("iface %p, dxgi_device %p, device %p.\n", iface, dxgi_device, device);
- return d2d_factory_create_device(factory, dxgi_device, &IID_ID2D1Device6, (void **)device); + return d2d_factory_create_device((ID2D1Factory1 *)iface, dxgi_device, true, &IID_ID2D1Device6, (void **)device); }
static const struct ID2D1Factory7Vtbl d2d_factory_vtbl = diff --git a/dlls/d2d1/hwnd_render_target.c b/dlls/d2d1/hwnd_render_target.c index 7f16ff00d4e..dc0dbc61b0e 100644 --- a/dlls/d2d1/hwnd_render_target.c +++ b/dlls/d2d1/hwnd_render_target.c @@ -918,7 +918,7 @@ HRESULT d2d_hwnd_render_target_init(struct d2d_hwnd_render_target *render_target return hr; }
- hr = ID2D1Factory1_CreateDevice(factory, dxgi_device, &device); + hr = d2d_factory_create_device(factory, dxgi_device, false, &IID_ID2D1Device, (void **)&device); IDXGIDevice_Release(dxgi_device); if (FAILED(hr)) { diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index ab825cc8ae8..92979cd493e 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -15471,14 +15471,10 @@ static void test_get_dxgi_device(BOOL d3d11) hr = ID2D1Factory3_CreateDevice(ctx.factory3, ctx.device, &device2); ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); hr = ID2D1Device2_GetDxgiDevice(device2, &dxgi_device); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); - if (hr == S_OK) - { - ok(dxgi_device == ctx.device, "Got unexpected IDXGIDevice.\n"); - IDXGIDevice_Release(dxgi_device); - } + ok(dxgi_device == ctx.device, "Got unexpected IDXGIDevice.\n");
+ IDXGIDevice_Release(dxgi_device); ID2D1Device2_Release(device2);
/* WIC target */ @@ -15507,9 +15503,7 @@ static void test_get_dxgi_device(BOOL d3d11)
dxgi_device = (IDXGIDevice *)0xdeadbeef; hr = ID2D1Device2_GetDxgiDevice(device2, &dxgi_device); - todo_wine ok(hr == D2DERR_INVALID_CALL, "Got unexpected hr %#lx.\n", hr); - todo_wine ok(!dxgi_device, "Expected NULL DXGI device.\n");
ID2D1Device2_Release(device2); @@ -15544,9 +15538,7 @@ static void test_get_dxgi_device(BOOL d3d11)
dxgi_device = (IDXGIDevice *)0xdeadbeef; hr = ID2D1Device2_GetDxgiDevice(device2, &dxgi_device); - todo_wine ok(hr == D2DERR_INVALID_CALL, "Got unexpected hr %#lx.\n", hr); - todo_wine ok(!dxgi_device, "Expected NULL DXGI device.\n");
ID2D1Device2_Release(device2); @@ -15561,14 +15553,10 @@ static void test_get_dxgi_device(BOOL d3d11) ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
hr = ID2D1Device2_GetDxgiDevice(device2, &dxgi_device); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); - if (hr == S_OK) - { - ok(dxgi_device == ctx.device, "Got unexpected IDXGIDevice.\n"); - IDXGIDevice_Release(dxgi_device); - } + ok(dxgi_device == ctx.device, "Got unexpected IDXGIDevice.\n");
+ IDXGIDevice_Release(dxgi_device); ID2D1Device2_Release(device2); ID2D1Device_Release(device);
@@ -15586,14 +15574,10 @@ static void test_get_dxgi_device(BOOL d3d11)
dxgi_device = (IDXGIDevice *)0xdeadbeef; hr = ID2D1Device2_GetDxgiDevice(device2, &dxgi_device); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); - if (hr == S_OK) - { - ok(dxgi_device == ctx.device, "Got unexpected IDXGIDevice.\n"); - IDXGIDevice_Release(dxgi_device); - } + ok(dxgi_device == ctx.device, "Got unexpected IDXGIDevice.\n");
+ IDXGIDevice_Release(dxgi_device); ID2D1Device2_Release(device2); ID2D1Device_Release(device); ID2D1DeviceContext_Release(context); @@ -15618,9 +15602,7 @@ static void test_get_dxgi_device(BOOL d3d11)
dxgi_device = (IDXGIDevice *)0xdeadbeef; hr = ID2D1Device2_GetDxgiDevice(device2, &dxgi_device); - todo_wine ok(hr == D2DERR_INVALID_CALL, "Got unexpected hr %#lx.\n", hr); - todo_wine ok(!dxgi_device, "Expected NULL DXGI device.\n");
ID2D1Device2_Release(device2); diff --git a/dlls/d2d1/wic_render_target.c b/dlls/d2d1/wic_render_target.c index ccbe194d291..970d4ceaec9 100644 --- a/dlls/d2d1/wic_render_target.c +++ b/dlls/d2d1/wic_render_target.c @@ -252,7 +252,7 @@ HRESULT d2d_wic_render_target_init(struct d2d_wic_render_target *render_target, return hr; }
- hr = ID2D1Factory1_CreateDevice(factory, dxgi_device, &device); + hr = d2d_factory_create_device(factory, dxgi_device, false, &IID_ID2D1Device, (void **)&device); IDXGIDevice_Release(dxgi_device); if (FAILED(hr)) {