mshtml: Moved readystate changes to separated function.
[wine] / dlls / d3d10core / shader.c
index 11e080d..e8602b5 100644 (file)
@@ -48,7 +48,7 @@ static HRESULT shdr_handler(const char *data, DWORD data_size, DWORD tag, void *
     return S_OK;
 }
 
-HRESULT shader_extract_from_dxbc(const void *dxbc, SIZE_T dxbc_length, struct d3d10_shader_info *shader_info)
+static HRESULT shader_extract_from_dxbc(const void *dxbc, SIZE_T dxbc_length, struct d3d10_shader_info *shader_info)
 {
     HRESULT hr;
 
@@ -161,6 +161,11 @@ static ULONG STDMETHODCALLTYPE d3d10_vertex_shader_AddRef(ID3D10VertexShader *if
 
     TRACE("%p increasing refcount to %u\n", This, refcount);
 
+    if (refcount == 1)
+    {
+        IWineD3DVertexShader_AddRef(This->wined3d_shader);
+    }
+
     return refcount;
 }
 
@@ -174,8 +179,6 @@ static ULONG STDMETHODCALLTYPE d3d10_vertex_shader_Release(ID3D10VertexShader *i
     if (!refcount)
     {
         IWineD3DVertexShader_Release(This->wined3d_shader);
-        shader_free_signature(&This->output_signature);
-        HeapFree(GetProcessHeap(), 0, This);
     }
 
     return refcount;
@@ -214,7 +217,7 @@ static HRESULT STDMETHODCALLTYPE d3d10_vertex_shader_SetPrivateDataInterface(ID3
     return E_NOTIMPL;
 }
 
-const struct ID3D10VertexShaderVtbl d3d10_vertex_shader_vtbl =
+static const struct ID3D10VertexShaderVtbl d3d10_vertex_shader_vtbl =
 {
     /* IUnknown methods */
     d3d10_vertex_shader_QueryInterface,
@@ -227,6 +230,48 @@ const struct ID3D10VertexShaderVtbl d3d10_vertex_shader_vtbl =
     d3d10_vertex_shader_SetPrivateDataInterface,
 };
 
+static void STDMETHODCALLTYPE d3d10_vertex_shader_wined3d_object_destroyed(void *parent)
+{
+    struct d3d10_vertex_shader *shader = parent;
+    shader_free_signature(&shader->output_signature);
+    HeapFree(GetProcessHeap(), 0, shader);
+}
+
+static const struct wined3d_parent_ops d3d10_vertex_shader_wined3d_parent_ops =
+{
+    d3d10_vertex_shader_wined3d_object_destroyed,
+};
+
+HRESULT d3d10_vertex_shader_init(struct d3d10_vertex_shader *shader, struct d3d10_device *device,
+        const void *byte_code, SIZE_T byte_code_length)
+{
+    struct d3d10_shader_info shader_info;
+    HRESULT hr;
+
+    shader->vtbl = &d3d10_vertex_shader_vtbl;
+    shader->refcount = 1;
+
+    shader_info.output_signature = &shader->output_signature;
+    hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info);
+    if (FAILED(hr))
+    {
+        ERR("Failed to extract shader, hr %#x.\n", hr);
+        return hr;
+    }
+
+    hr = IWineD3DDevice_CreateVertexShader(device->wined3d_device,
+            shader_info.shader_code, &shader->output_signature, &shader->wined3d_shader,
+            (IUnknown *)shader, &d3d10_vertex_shader_wined3d_parent_ops);
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
+        shader_free_signature(&shader->output_signature);
+        return hr;
+    }
+
+    return S_OK;
+}
+
 /* IUnknown methods */
 
 static HRESULT STDMETHODCALLTYPE d3d10_geometry_shader_QueryInterface(ID3D10GeometryShader *iface,
@@ -307,7 +352,7 @@ static HRESULT STDMETHODCALLTYPE d3d10_geometry_shader_SetPrivateDataInterface(I
     return E_NOTIMPL;
 }
 
-const struct ID3D10GeometryShaderVtbl d3d10_geometry_shader_vtbl =
+static const struct ID3D10GeometryShaderVtbl d3d10_geometry_shader_vtbl =
 {
     /* IUnknown methods */
     d3d10_geometry_shader_QueryInterface,
@@ -320,6 +365,14 @@ const struct ID3D10GeometryShaderVtbl d3d10_geometry_shader_vtbl =
     d3d10_geometry_shader_SetPrivateDataInterface,
 };
 
+HRESULT d3d10_geometry_shader_init(struct d3d10_geometry_shader *shader)
+{
+    shader->vtbl = &d3d10_geometry_shader_vtbl;
+    shader->refcount = 1;
+
+    return S_OK;
+}
+
 /* IUnknown methods */
 
 static HRESULT STDMETHODCALLTYPE d3d10_pixel_shader_QueryInterface(ID3D10PixelShader *iface,
@@ -349,6 +402,11 @@ static ULONG STDMETHODCALLTYPE d3d10_pixel_shader_AddRef(ID3D10PixelShader *ifac
 
     TRACE("%p increasing refcount to %u\n", This, refcount);
 
+    if (refcount == 1)
+    {
+        IWineD3DPixelShader_AddRef(This->wined3d_shader);
+    }
+
     return refcount;
 }
 
@@ -362,8 +420,6 @@ static ULONG STDMETHODCALLTYPE d3d10_pixel_shader_Release(ID3D10PixelShader *ifa
     if (!refcount)
     {
         IWineD3DPixelShader_Release(This->wined3d_shader);
-        shader_free_signature(&This->output_signature);
-        HeapFree(GetProcessHeap(), 0, This);
     }
 
     return refcount;
@@ -402,7 +458,7 @@ static HRESULT STDMETHODCALLTYPE d3d10_pixel_shader_SetPrivateDataInterface(ID3D
     return E_NOTIMPL;
 }
 
-const struct ID3D10PixelShaderVtbl d3d10_pixel_shader_vtbl =
+static const struct ID3D10PixelShaderVtbl d3d10_pixel_shader_vtbl =
 {
     /* IUnknown methods */
     d3d10_pixel_shader_QueryInterface,
@@ -414,3 +470,45 @@ const struct ID3D10PixelShaderVtbl d3d10_pixel_shader_vtbl =
     d3d10_pixel_shader_SetPrivateData,
     d3d10_pixel_shader_SetPrivateDataInterface,
 };
+
+static void STDMETHODCALLTYPE d3d10_pixel_shader_wined3d_object_destroyed(void *parent)
+{
+    struct d3d10_pixel_shader *shader = parent;
+    shader_free_signature(&shader->output_signature);
+    HeapFree(GetProcessHeap(), 0, shader);
+}
+
+static const struct wined3d_parent_ops d3d10_pixel_shader_wined3d_parent_ops =
+{
+    d3d10_pixel_shader_wined3d_object_destroyed,
+};
+
+HRESULT d3d10_pixel_shader_init(struct d3d10_pixel_shader *shader, struct d3d10_device *device,
+        const void *byte_code, SIZE_T byte_code_length)
+{
+    struct d3d10_shader_info shader_info;
+    HRESULT hr;
+
+    shader->vtbl = &d3d10_pixel_shader_vtbl;
+    shader->refcount = 1;
+
+    shader_info.output_signature = &shader->output_signature;
+    hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info);
+    if (FAILED(hr))
+    {
+        ERR("Failed to extract shader, hr %#x.\n", hr);
+        return hr;
+    }
+
+    hr = IWineD3DDevice_CreatePixelShader(device->wined3d_device,
+            shader_info.shader_code, &shader->output_signature, &shader->wined3d_shader,
+            (IUnknown *)shader, &d3d10_pixel_shader_wined3d_parent_ops);
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d pixel shader, hr %#x.\n", hr);
+        shader_free_signature(&shader->output_signature);
+        return hr;
+    }
+
+    return S_OK;
+}