Nikolay Sivov : d2d1/effect: Add a helper to append shader objects to the context.

Alexandre Julliard julliard at winehq.org
Wed May 25 16:51:46 CDT 2022


Module: wine
Branch: master
Commit: 5317f869e09a84d5f4f9ee3d743c446e0f3cced4
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=5317f869e09a84d5f4f9ee3d743c446e0f3cced4

Author: Nikolay Sivov <nsivov at codeweavers.com>
Date:   Wed May 25 10:29:13 2022 +0300

d2d1/effect: Add a helper to append shader objects to the context.

Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/d2d1/effect.c | 46 +++++++++++++++++++++++++---------------------
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/dlls/d2d1/effect.c b/dlls/d2d1/effect.c
index ff808475a78..79d704dd949 100644
--- a/dlls/d2d1/effect.c
+++ b/dlls/d2d1/effect.c
@@ -37,18 +37,35 @@ 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;
+    size_t i;
 
     for (i = 0; i < effect_context->shader_count; ++i)
-    {
-        if (effect_context->shaders[i].shader)
-            IUnknown_Release(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);
 }
 
+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)
 {
     TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
@@ -189,7 +206,6 @@ static HRESULT STDMETHODCALLTYPE d2d_effect_context_LoadVertexShader(ID2D1Effect
 {
     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",
@@ -205,22 +221,10 @@ static HRESULT STDMETHODCALLTYPE d2d_effect_context_LoadVertexShader(ID2D1Effect
         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;
-    }
-    memset(effect_context->shaders + effect_context->shader_count, 0,
-            sizeof(*effect_context->shaders) * (effect_context->shaders_size - effect_context->shader_count));
+    hr = d2d_effect_context_add_shader(effect_context, shader_id, vertex_shader);
+    ID3D11VertexShader_Release(vertex_shader);
 
-    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;
+    return hr;
 }
 
 static HRESULT STDMETHODCALLTYPE d2d_effect_context_LoadComputeShader(ID2D1EffectContext *iface,




More information about the wine-cvs mailing list