Commit e0ab89b8 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

d2d1: Keep effect shader objects at device level.

parent 9e4ee3e4
...@@ -592,22 +592,31 @@ HRESULT d2d_geometry_group_init(struct d2d_geometry *geometry, ID2D1Factory *fac ...@@ -592,22 +592,31 @@ HRESULT d2d_geometry_group_init(struct d2d_geometry *geometry, ID2D1Factory *fac
D2D1_FILL_MODE fill_mode, ID2D1Geometry **src_geometries, unsigned int geometry_count); D2D1_FILL_MODE fill_mode, ID2D1Geometry **src_geometries, unsigned int geometry_count);
struct d2d_geometry *unsafe_impl_from_ID2D1Geometry(ID2D1Geometry *iface); struct d2d_geometry *unsafe_impl_from_ID2D1Geometry(ID2D1Geometry *iface);
struct d2d_shader
{
GUID id;
IUnknown *shader;
};
struct d2d_device struct d2d_device
{ {
ID2D1Device1 ID2D1Device1_iface; ID2D1Device1 ID2D1Device1_iface;
LONG refcount; LONG refcount;
ID2D1Factory1 *factory; ID2D1Factory1 *factory;
IDXGIDevice *dxgi_device; IDXGIDevice *dxgi_device;
struct
{
struct d2d_shader *objects;
size_t size;
size_t count;
} shaders;
}; };
void d2d_device_init(struct d2d_device *device, ID2D1Factory1 *factory, IDXGIDevice *dxgi_device); void d2d_device_init(struct d2d_device *device, ID2D1Factory1 *factory, IDXGIDevice *dxgi_device);
struct d2d_device *unsafe_impl_from_ID2D1Device(ID2D1Device1 *iface); struct d2d_device *unsafe_impl_from_ID2D1Device(ID2D1Device1 *iface);
HRESULT d2d_device_add_shader(struct d2d_device *device, REFGUID shader_id, IUnknown *shader);
struct d2d_shader BOOL d2d_device_is_shader_loaded(struct d2d_device *device, REFGUID shader_id);
{
GUID id;
IUnknown *shader;
};
struct d2d_effect_context struct d2d_effect_context
{ {
...@@ -615,10 +624,6 @@ struct d2d_effect_context ...@@ -615,10 +624,6 @@ struct d2d_effect_context
LONG refcount; LONG refcount;
struct d2d_device_context *device_context; struct d2d_device_context *device_context;
struct d2d_shader *shaders;
size_t shaders_size;
size_t shader_count;
}; };
void d2d_effect_context_init(struct d2d_effect_context *effect_context, void d2d_effect_context_init(struct d2d_effect_context *effect_context,
......
...@@ -4528,6 +4528,7 @@ static ULONG WINAPI d2d_device_Release(ID2D1Device1 *iface) ...@@ -4528,6 +4528,7 @@ static ULONG WINAPI d2d_device_Release(ID2D1Device1 *iface)
{ {
struct d2d_device *device = impl_from_ID2D1Device(iface); struct d2d_device *device = impl_from_ID2D1Device(iface);
ULONG refcount = InterlockedDecrement(&device->refcount); ULONG refcount = InterlockedDecrement(&device->refcount);
size_t i;
TRACE("%p decreasing refcount to %lu.\n", iface, refcount); TRACE("%p decreasing refcount to %lu.\n", iface, refcount);
...@@ -4535,6 +4536,9 @@ static ULONG WINAPI d2d_device_Release(ID2D1Device1 *iface) ...@@ -4535,6 +4536,9 @@ static ULONG WINAPI d2d_device_Release(ID2D1Device1 *iface)
{ {
IDXGIDevice_Release(device->dxgi_device); IDXGIDevice_Release(device->dxgi_device);
ID2D1Factory1_Release(device->factory); ID2D1Factory1_Release(device->factory);
for (i = 0; i < device->shaders.count; ++i)
IUnknown_Release(device->shaders.objects[i].shader);
free(device->shaders.objects);
free(device); free(device);
} }
...@@ -4670,3 +4674,35 @@ void d2d_device_init(struct d2d_device *device, ID2D1Factory1 *iface, IDXGIDevic ...@@ -4670,3 +4674,35 @@ void d2d_device_init(struct d2d_device *device, ID2D1Factory1 *iface, IDXGIDevic
device->dxgi_device = dxgi_device; device->dxgi_device = dxgi_device;
IDXGIDevice_AddRef(device->dxgi_device); IDXGIDevice_AddRef(device->dxgi_device);
} }
HRESULT d2d_device_add_shader(struct d2d_device *device, REFGUID shader_id, IUnknown *shader)
{
struct d2d_shader *entry;
if (!d2d_array_reserve((void **)&device->shaders.objects, &device->shaders.size,
device->shaders.count + 1, sizeof(*device->shaders.objects)))
{
WARN("Failed to resize shaders array.\n");
return E_OUTOFMEMORY;
}
entry = &device->shaders.objects[device->shaders.count++];
entry->id = *shader_id;
entry->shader = shader;
IUnknown_AddRef(entry->shader);
return S_OK;
}
BOOL d2d_device_is_shader_loaded(struct d2d_device *device, REFGUID shader_id)
{
size_t i;
for (i = 0; i < device->shaders.count; ++i)
{
if (IsEqualGUID(shader_id, &device->shaders.objects[i].id))
return TRUE;
}
return FALSE;
}
...@@ -624,37 +624,6 @@ static inline struct d2d_effect_context *impl_from_ID2D1EffectContext(ID2D1Effec ...@@ -624,37 +624,6 @@ static inline struct d2d_effect_context *impl_from_ID2D1EffectContext(ID2D1Effec
return CONTAINING_RECORD(iface, struct d2d_effect_context, ID2D1EffectContext_iface); return CONTAINING_RECORD(iface, struct d2d_effect_context, ID2D1EffectContext_iface);
} }
static void d2d_effect_context_cleanup(struct d2d_effect_context *effect_context)
{
size_t i;
for (i = 0; i < effect_context->shader_count; ++i)
IUnknown_Release(effect_context->shaders[i].shader);
free(effect_context->shaders);
ID2D1DeviceContext1_Release(&effect_context->device_context->ID2D1DeviceContext1_iface);
}
static HRESULT d2d_effect_context_add_shader(struct d2d_effect_context *effect_context,
REFGUID shader_id, void *shader)
{
struct d2d_shader *entry;
if (!d2d_array_reserve((void **)&effect_context->shaders, &effect_context->shaders_size,
effect_context->shader_count + 1, sizeof(*effect_context->shaders)))
{
WARN("Failed to resize shaders array.\n");
return E_OUTOFMEMORY;
}
entry = &effect_context->shaders[effect_context->shader_count++];
entry->id = *shader_id;
entry->shader = shader;
IUnknown_AddRef(entry->shader);
return S_OK;
}
static HRESULT STDMETHODCALLTYPE d2d_effect_context_QueryInterface(ID2D1EffectContext *iface, REFIID iid, void **out) static HRESULT STDMETHODCALLTYPE d2d_effect_context_QueryInterface(ID2D1EffectContext *iface, REFIID iid, void **out)
{ {
TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out); TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
...@@ -692,7 +661,7 @@ static ULONG STDMETHODCALLTYPE d2d_effect_context_Release(ID2D1EffectContext *if ...@@ -692,7 +661,7 @@ static ULONG STDMETHODCALLTYPE d2d_effect_context_Release(ID2D1EffectContext *if
if (!refcount) if (!refcount)
{ {
d2d_effect_context_cleanup(effect_context); ID2D1DeviceContext1_Release(&effect_context->device_context->ID2D1DeviceContext1_iface);
free(effect_context); free(effect_context);
} }
...@@ -787,7 +756,7 @@ static HRESULT STDMETHODCALLTYPE d2d_effect_context_LoadPixelShader(ID2D1EffectC ...@@ -787,7 +756,7 @@ static HRESULT STDMETHODCALLTYPE d2d_effect_context_LoadPixelShader(ID2D1EffectC
return hr; return hr;
} }
hr = d2d_effect_context_add_shader(effect_context, shader_id, shader); hr = d2d_device_add_shader(effect_context->device_context->device, shader_id, (IUnknown *)shader);
ID3D11PixelShader_Release(shader); ID3D11PixelShader_Release(shader);
return hr; return hr;
...@@ -797,7 +766,7 @@ static HRESULT STDMETHODCALLTYPE d2d_effect_context_LoadVertexShader(ID2D1Effect ...@@ -797,7 +766,7 @@ static HRESULT STDMETHODCALLTYPE d2d_effect_context_LoadVertexShader(ID2D1Effect
REFGUID shader_id, const BYTE *buffer, UINT32 buffer_size) REFGUID shader_id, const BYTE *buffer, UINT32 buffer_size)
{ {
struct d2d_effect_context *effect_context = impl_from_ID2D1EffectContext(iface); struct d2d_effect_context *effect_context = impl_from_ID2D1EffectContext(iface);
ID3D11VertexShader *vertex_shader; ID3D11VertexShader *shader;
HRESULT hr; HRESULT hr;
TRACE("iface %p, shader_id %s, buffer %p, buffer_size %u.\n", TRACE("iface %p, shader_id %s, buffer %p, buffer_size %u.\n",
...@@ -807,14 +776,14 @@ static HRESULT STDMETHODCALLTYPE d2d_effect_context_LoadVertexShader(ID2D1Effect ...@@ -807,14 +776,14 @@ static HRESULT STDMETHODCALLTYPE d2d_effect_context_LoadVertexShader(ID2D1Effect
return S_OK; return S_OK;
if (FAILED(hr = ID3D11Device1_CreateVertexShader(effect_context->device_context->d3d_device, if (FAILED(hr = ID3D11Device1_CreateVertexShader(effect_context->device_context->d3d_device,
buffer, buffer_size, NULL, &vertex_shader))) buffer, buffer_size, NULL, &shader)))
{ {
WARN("Failed to create vertex shader, hr %#lx.\n", hr); WARN("Failed to create vertex shader, hr %#lx.\n", hr);
return hr; return hr;
} }
hr = d2d_effect_context_add_shader(effect_context, shader_id, vertex_shader); hr = d2d_device_add_shader(effect_context->device_context->device, shader_id, (IUnknown *)shader);
ID3D11VertexShader_Release(vertex_shader); ID3D11VertexShader_Release(shader);
return hr; return hr;
} }
...@@ -839,7 +808,7 @@ static HRESULT STDMETHODCALLTYPE d2d_effect_context_LoadComputeShader(ID2D1Effec ...@@ -839,7 +808,7 @@ static HRESULT STDMETHODCALLTYPE d2d_effect_context_LoadComputeShader(ID2D1Effec
return hr; return hr;
} }
hr = d2d_effect_context_add_shader(effect_context, shader_id, shader); hr = d2d_device_add_shader(effect_context->device_context->device, shader_id, (IUnknown *)shader);
ID3D11ComputeShader_Release(shader); ID3D11ComputeShader_Release(shader);
return hr; return hr;
...@@ -848,17 +817,10 @@ static HRESULT STDMETHODCALLTYPE d2d_effect_context_LoadComputeShader(ID2D1Effec ...@@ -848,17 +817,10 @@ static HRESULT STDMETHODCALLTYPE d2d_effect_context_LoadComputeShader(ID2D1Effec
static BOOL STDMETHODCALLTYPE d2d_effect_context_IsShaderLoaded(ID2D1EffectContext *iface, REFGUID shader_id) static BOOL STDMETHODCALLTYPE d2d_effect_context_IsShaderLoaded(ID2D1EffectContext *iface, REFGUID shader_id)
{ {
struct d2d_effect_context *effect_context = impl_from_ID2D1EffectContext(iface); struct d2d_effect_context *effect_context = impl_from_ID2D1EffectContext(iface);
size_t i;
TRACE("iface %p, shader_id %s.\n", iface, debugstr_guid(shader_id)); TRACE("iface %p, shader_id %s.\n", iface, debugstr_guid(shader_id));
for (i = 0; i < effect_context->shader_count; ++i) return d2d_device_is_shader_loaded(effect_context->device_context->device, shader_id);
{
if (IsEqualGUID(shader_id, &effect_context->shaders[i].id))
return TRUE;
}
return FALSE;
} }
static HRESULT STDMETHODCALLTYPE d2d_effect_context_CreateResourceTexture(ID2D1EffectContext *iface, static HRESULT STDMETHODCALLTYPE d2d_effect_context_CreateResourceTexture(ID2D1EffectContext *iface,
......
...@@ -11483,7 +11483,6 @@ static void test_effect_context(BOOL d3d11) ...@@ -11483,7 +11483,6 @@ static void test_effect_context(BOOL d3d11)
ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
loaded = ID2D1EffectContext_IsShaderLoaded(effect_context2, &GUID_TestPixelShader); loaded = ID2D1EffectContext_IsShaderLoaded(effect_context2, &GUID_TestPixelShader);
todo_wine
ok(loaded, "Unexpected shader loaded state.\n"); ok(loaded, "Unexpected shader loaded state.\n");
ID2D1Effect_Release(effect2); ID2D1Effect_Release(effect2);
...@@ -11524,7 +11523,6 @@ static void test_effect_context(BOOL d3d11) ...@@ -11524,7 +11523,6 @@ static void test_effect_context(BOOL d3d11)
ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
loaded = ID2D1EffectContext_IsShaderLoaded(effect_context, &GUID_TestPixelShader); loaded = ID2D1EffectContext_IsShaderLoaded(effect_context, &GUID_TestPixelShader);
todo_wine
ok(loaded, "Unexpected shader loaded state.\n"); ok(loaded, "Unexpected shader loaded state.\n");
ID2D1Effect_Release(effect); ID2D1Effect_Release(effect);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment