Signed-off-by: Ziqing Hui zhui@codeweavers.com ---
v3: * Use IUnknown in d2d_shader. * Use d2d_array_reserve(count + 1) to avoid count checking.
dlls/d2d1/d2d1_private.h | 10 ++++++++++ dlls/d2d1/effect.c | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/dlls/d2d1/d2d1_private.h b/dlls/d2d1/d2d1_private.h index cb9ee6d5b80..b7e1a12b3b8 100644 --- a/dlls/d2d1/d2d1_private.h +++ b/dlls/d2d1/d2d1_private.h @@ -568,12 +568,22 @@ struct d2d_device
void d2d_device_init(struct d2d_device *device, ID2D1Factory1 *factory, IDXGIDevice *dxgi_device) DECLSPEC_HIDDEN;
+struct d2d_shader +{ + const GUID *id; + IUnknown *shader; +}; + struct d2d_effect_context { ID2D1EffectContext ID2D1EffectContext_iface; LONG refcount;
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, diff --git a/dlls/d2d1/effect.c b/dlls/d2d1/effect.c index a75e3e525f8..1615739f492 100644 --- a/dlls/d2d1/effect.c +++ b/dlls/d2d1/effect.c @@ -37,6 +37,15 @@ static inline struct d2d_effect_context *impl_from_ID2D1EffectContext(ID2D1Effec
static void d2d_effect_context_cleanup(struct d2d_effect_context *effect_context) { + unsigned int i; + + for (i = 0; i < effect_context->shader_count; ++i) + { + if (effect_context->shaders[i].shader) + IUnknown_Release(effect_context->shaders[i].shader); + } + heap_free(effect_context->shaders); + ID2D1DeviceContext_Release(&effect_context->device_context->ID2D1DeviceContext_iface); }
@@ -178,10 +187,35 @@ static HRESULT STDMETHODCALLTYPE d2d_effect_context_LoadPixelShader(ID2D1EffectC static HRESULT STDMETHODCALLTYPE d2d_effect_context_LoadVertexShader(ID2D1EffectContext *iface, REFGUID shader_id, const BYTE *buffer, UINT32 buffer_size) { - FIXME("iface %p, shader_id %s, buffer %p, buffer_size %u stub!\n", + struct d2d_effect_context *effect_context = impl_from_ID2D1EffectContext(iface); + ID3D11VertexShader *vertex_shader; + struct d2d_shader *shader; + HRESULT hr; + + TRACE("iface %p, shader_id %s, buffer %p, buffer_size %u.\n", iface, debugstr_guid(shader_id), buffer, buffer_size);
- return E_NOTIMPL; + if (FAILED(hr = ID3D11Device1_CreateVertexShader(effect_context->device_context->d3d_device, + buffer, buffer_size, NULL, &vertex_shader))) + { + WARN("Failed to create vertex shader, hr %#lx.\n", hr); + return hr; + } + + if (!d2d_array_reserve((void **)&effect_context->shaders, &effect_context->shaders_size, + effect_context->shader_count + 1, sizeof(*effect_context->shaders))) + { + ERR("Failed to resize shaders array.\n"); + ID3D11VertexShader_Release(vertex_shader); + return E_OUTOFMEMORY; + } + + effect_context->shader_count++; + shader = &effect_context->shaders[effect_context->shader_count - 1]; + shader->id = shader_id; + shader->shader = (IUnknown *)vertex_shader; + + return S_OK; }
static HRESULT STDMETHODCALLTYPE d2d_effect_context_LoadComputeShader(ID2D1EffectContext *iface,