Commit f056fe7b authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

d3d8: Remove COM from the vertex declaration implementation.

parent d0347f51
......@@ -168,7 +168,7 @@ struct d3d8_handle_table
struct FvfToDecl
{
DWORD fvf;
struct IDirect3DVertexDeclaration8 *decl;
struct d3d8_vertex_declaration *declaration;
};
struct IDirect3DDevice8Impl
......@@ -366,47 +366,24 @@ struct IDirect3DVolumeTexture8Impl
HRESULT volumetexture_init(IDirect3DVolumeTexture8Impl *texture, IDirect3DDevice8Impl *device,
UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
DEFINE_GUID(IID_IDirect3DVertexDeclaration8,
0x5dd7478d, 0xcbf3, 0x41a6, 0x8c, 0xfd, 0xfd, 0x19, 0x2b, 0x11, 0xc7, 0x90);
DEFINE_GUID(IID_IDirect3DVertexShader8,
0xefc5557e, 0x6265, 0x4613, 0x8a, 0x94, 0x43, 0x85, 0x78, 0x89, 0xeb, 0x36);
DEFINE_GUID(IID_IDirect3DPixelShader8,
0x6d3bdbdc, 0x5b02, 0x4415, 0xb8, 0x52, 0xce, 0x5e, 0x8b, 0xcc, 0xb2, 0x89);
/*****************************************************************************
* IDirect3DVertexDeclaration8 interface
*/
#define INTERFACE IDirect3DVertexDeclaration8
DECLARE_INTERFACE_(IDirect3DVertexDeclaration8, IUnknown)
struct d3d8_vertex_declaration
{
/*** IUnknown methods ***/
STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID riid, void** obj_ptr) PURE;
STDMETHOD_(ULONG,AddRef)(THIS) PURE;
STDMETHOD_(ULONG,Release)(THIS) PURE;
};
#undef INTERFACE
/*** IUnknown methods ***/
#define IDirect3DVertexDeclaration8_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b)
#define IDirect3DVertexDeclaration8_AddRef(p) (p)->lpVtbl->AddRef(p)
#define IDirect3DVertexDeclaration8_Release(p) (p)->lpVtbl->Release(p)
typedef struct {
const IDirect3DVertexDeclaration8Vtbl *lpVtbl;
LONG ref_count;
DWORD *elements;
DWORD elements_size; /* Size of elements, in bytes */
struct wined3d_vertex_declaration *wined3d_vertex_declaration;
DWORD shader_handle;
} IDirect3DVertexDeclaration8Impl;
};
HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration,
void d3d8_vertex_declaration_destroy(struct d3d8_vertex_declaration *declaration) DECLSPEC_HIDDEN;
HRESULT d3d8_vertex_declaration_init(struct d3d8_vertex_declaration *declaration,
IDirect3DDevice8Impl *device, const DWORD *elements, DWORD shader_handle) DECLSPEC_HIDDEN;
HRESULT vertexdeclaration_init_fvf(IDirect3DVertexDeclaration8Impl *declaration,
HRESULT d3d8_vertex_declaration_init_fvf(struct d3d8_vertex_declaration *declaration,
IDirect3DDevice8Impl *device, DWORD fvf) DECLSPEC_HIDDEN;
/*****************************************************************************
......@@ -456,7 +433,7 @@ DECLARE_INTERFACE_(IDirect3DPixelShader8,IUnknown)
struct IDirect3DVertexShader8Impl {
IDirect3DVertexShader8 IDirect3DVertexShader8_iface;
LONG ref;
IDirect3DVertexDeclaration8 *vertex_declaration;
struct d3d8_vertex_declaration *vertex_declaration;
struct wined3d_shader *wined3d_shader;
};
......
......@@ -309,8 +309,9 @@ static ULONG WINAPI IDirect3DDevice8Impl_Release(IDirect3DDevice8 *iface)
This->inDestruction = TRUE;
for(i = 0; i < This->numConvertedDecls; i++) {
IDirect3DVertexDeclaration8_Release(This->decls[i].decl);
for (i = 0; i < This->numConvertedDecls; ++i)
{
d3d8_vertex_declaration_destroy(This->decls[i].declaration);
}
HeapFree(GetProcessHeap(), 0, This->decls);
......@@ -2033,9 +2034,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexShader(IDirect3DDevice8 *
return D3D_OK;
}
static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
static struct d3d8_vertex_declaration *IDirect3DDevice8Impl_FindDecl(IDirect3DDevice8Impl *This, DWORD fvf)
{
IDirect3DVertexDeclaration8Impl *d3d8_declaration;
struct d3d8_vertex_declaration *d3d8_declaration;
HRESULT hr;
int p, low, high; /* deliberately signed */
struct FvfToDecl *convertedDecls = This->decls;
......@@ -2047,10 +2048,13 @@ static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DD
while(low <= high) {
p = (low + high) >> 1;
TRACE("%d ", p);
if(convertedDecls[p].fvf == fvf) {
TRACE("found %p\n", convertedDecls[p].decl);
return (IDirect3DVertexDeclaration8Impl *)convertedDecls[p].decl;
} else if(convertedDecls[p].fvf < fvf) {
if (convertedDecls[p].fvf == fvf)
{
TRACE("found %p\n", convertedDecls[p].declaration);
return convertedDecls[p].declaration;
}
else if (convertedDecls[p].fvf < fvf)
{
low = p + 1;
} else {
high = p - 1;
......@@ -2065,7 +2069,7 @@ static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DD
return NULL;
}
hr = vertexdeclaration_init_fvf(d3d8_declaration, This, fvf);
hr = d3d8_vertex_declaration_init_fvf(d3d8_declaration, This, fvf);
if (FAILED(hr))
{
WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
......@@ -2076,10 +2080,10 @@ static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DD
if(This->declArraySize == This->numConvertedDecls) {
int grow = This->declArraySize / 2;
convertedDecls = HeapReAlloc(GetProcessHeap(), 0, convertedDecls,
sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
if(!convertedDecls) {
/* This will destroy it */
IDirect3DVertexDeclaration8_Release((IDirect3DVertexDeclaration8 *)d3d8_declaration);
sizeof(convertedDecls[0]) * (This->numConvertedDecls + grow));
if (!convertedDecls)
{
d3d8_vertex_declaration_destroy(d3d8_declaration);
return NULL;
}
This->decls = convertedDecls;
......@@ -2087,7 +2091,7 @@ static IDirect3DVertexDeclaration8Impl *IDirect3DDevice8Impl_FindDecl(IDirect3DD
}
memmove(convertedDecls + low + 1, convertedDecls + low, sizeof(convertedDecls[0]) * (This->numConvertedDecls - low));
convertedDecls[low].decl = (IDirect3DVertexDeclaration8 *)d3d8_declaration;
convertedDecls[low].declaration = d3d8_declaration;
convertedDecls[low].fvf = fvf;
This->numConvertedDecls++;
......@@ -2128,7 +2132,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetVertexShader(IDirect3DDevice8 *ifa
}
hr = wined3d_device_set_vertex_declaration(This->wined3d_device,
((IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration)->wined3d_vertex_declaration);
shader->vertex_declaration->wined3d_vertex_declaration);
if (SUCCEEDED(hr))
hr = wined3d_device_set_vertex_shader(This->wined3d_device, shader->wined3d_shader);
wined3d_mutex_unlock();
......@@ -2142,7 +2146,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(IDirect3DDevice8 *ifa
{
IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
struct wined3d_vertex_declaration *wined3d_declaration;
IDirect3DVertexDeclaration8 *d3d8_declaration;
struct d3d8_vertex_declaration *d3d8_declaration;
HRESULT hr;
TRACE("iface %p, shader %p.\n", iface, ppShader);
......@@ -2167,7 +2171,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShader(IDirect3DDevice8 *ifa
d3d8_declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration);
wined3d_vertex_declaration_decref(wined3d_declaration);
wined3d_mutex_unlock();
*ppShader = ((IDirect3DVertexDeclaration8Impl *)d3d8_declaration)->shader_handle;
*ppShader = d3d8_declaration->shader_handle;
TRACE("(%p) : returning %#x\n", This, *ppShader);
......@@ -2258,7 +2262,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(IDirect3DD
DWORD pVertexShader, void *pData, DWORD *pSizeOfData)
{
IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
IDirect3DVertexDeclaration8Impl *declaration;
struct d3d8_vertex_declaration *declaration;
IDirect3DVertexShader8Impl *shader;
TRACE("iface %p, shader %#x, data %p, data_size %p.\n",
......@@ -2273,7 +2277,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetVertexShaderDeclaration(IDirect3DD
WARN("Invalid handle (%#x) passed.\n", pVertexShader);
return D3DERR_INVALIDCALL;
}
declaration = (IDirect3DVertexDeclaration8Impl *)shader->vertex_declaration;
declaration = shader->vertex_declaration;
/* If pData is NULL, we just return the required size of the buffer. */
if (!pData) {
......
......@@ -65,7 +65,7 @@ static ULONG WINAPI d3d8_vertexshader_AddRef(IDirect3DVertexShader8 *iface)
static void STDMETHODCALLTYPE d3d8_vertexshader_wined3d_object_destroyed(void *parent)
{
IDirect3DVertexShader8Impl *shader = parent;
IDirect3DVertexDeclaration8_Release(shader->vertex_declaration);
d3d8_vertex_declaration_destroy(shader->vertex_declaration);
HeapFree(GetProcessHeap(), 0, shader);
}
......@@ -107,9 +107,9 @@ static const struct wined3d_parent_ops d3d8_vertexshader_wined3d_parent_ops =
};
static HRESULT d3d8_vertexshader_create_vertexdeclaration(IDirect3DDevice8Impl *device,
const DWORD *declaration, DWORD shader_handle, IDirect3DVertexDeclaration8 **decl_ptr)
const DWORD *declaration, DWORD shader_handle, struct d3d8_vertex_declaration **decl_ptr)
{
IDirect3DVertexDeclaration8Impl *object;
struct d3d8_vertex_declaration *object;
HRESULT hr;
TRACE("device %p, declaration %p, shader_handle %#x, decl_ptr %p.\n",
......@@ -122,7 +122,7 @@ static HRESULT d3d8_vertexshader_create_vertexdeclaration(IDirect3DDevice8Impl *
return E_OUTOFMEMORY;
}
hr = vertexdeclaration_init(object, device, declaration, shader_handle);
hr = d3d8_vertex_declaration_init(object, device, declaration, shader_handle);
if (FAILED(hr))
{
WARN("Failed to initialize vertex declaration, hr %#x.\n", hr);
......@@ -131,7 +131,7 @@ static HRESULT d3d8_vertexshader_create_vertexdeclaration(IDirect3DDevice8Impl *
}
TRACE("Created vertex declaration %p.\n", object);
*decl_ptr = (IDirect3DVertexDeclaration8 *)object;
*decl_ptr = object;
return D3D_OK;
}
......@@ -182,7 +182,7 @@ HRESULT vertexshader_init(IDirect3DVertexShader8Impl *shader, IDirect3DDevice8Im
if (FAILED(hr))
{
WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
IDirect3DVertexDeclaration8_Release(shader->vertex_declaration);
d3d8_vertex_declaration_destroy(shader->vertex_declaration);
return hr;
}
......
......@@ -26,56 +26,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
/* IUnknown */
static HRESULT WINAPI IDirect3DVertexDeclaration8Impl_QueryInterface(IDirect3DVertexDeclaration8 *iface, REFIID riid, void **obj_ptr)
{
TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), obj_ptr);
if (IsEqualGUID(riid, &IID_IUnknown)
|| IsEqualGUID(riid, &IID_IDirect3DVertexDeclaration8))
{
IUnknown_AddRef(iface);
*obj_ptr = iface;
return S_OK;
}
*obj_ptr = NULL;
return E_NOINTERFACE;
}
static ULONG WINAPI IDirect3DVertexDeclaration8Impl_AddRef(IDirect3DVertexDeclaration8 *iface)
{
IDirect3DVertexDeclaration8Impl *This = (IDirect3DVertexDeclaration8Impl *)iface;
ULONG ref_count = InterlockedIncrement(&This->ref_count);
TRACE("%p increasing refcount to %u.\n", iface, ref_count);
if (ref_count == 1)
{
wined3d_mutex_lock();
wined3d_vertex_declaration_incref(This->wined3d_vertex_declaration);
wined3d_mutex_unlock();
}
return ref_count;
}
static ULONG WINAPI IDirect3DVertexDeclaration8Impl_Release(IDirect3DVertexDeclaration8 *iface)
{
IDirect3DVertexDeclaration8Impl *This = (IDirect3DVertexDeclaration8Impl *)iface;
ULONG ref_count = InterlockedDecrement(&This->ref_count);
TRACE("%p decreasing refcount to %u.\n", iface, ref_count);
if (!ref_count) {
wined3d_mutex_lock();
wined3d_vertex_declaration_decref(This->wined3d_vertex_declaration);
wined3d_mutex_unlock();
}
return ref_count;
}
static const char *debug_d3dvsdt_type(D3DVSDT_TYPE d3dvsdt_type)
{
switch (d3dvsdt_type)
......@@ -359,34 +309,34 @@ static UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3
return element_count;
}
static const IDirect3DVertexDeclaration8Vtbl Direct3DVertexDeclaration8_Vtbl =
{
IDirect3DVertexDeclaration8Impl_QueryInterface,
IDirect3DVertexDeclaration8Impl_AddRef,
IDirect3DVertexDeclaration8Impl_Release
};
static void STDMETHODCALLTYPE d3d8_vertexdeclaration_wined3d_object_destroyed(void *parent)
{
IDirect3DVertexDeclaration8Impl *declaration = parent;
struct d3d8_vertex_declaration *declaration = parent;
HeapFree(GetProcessHeap(), 0, declaration->elements);
HeapFree(GetProcessHeap(), 0, declaration);
}
void d3d8_vertex_declaration_destroy(struct d3d8_vertex_declaration *declaration)
{
TRACE("declaration %p.\n", declaration);
wined3d_mutex_lock();
wined3d_vertex_declaration_decref(declaration->wined3d_vertex_declaration);
wined3d_mutex_unlock();
}
static const struct wined3d_parent_ops d3d8_vertexdeclaration_wined3d_parent_ops =
{
d3d8_vertexdeclaration_wined3d_object_destroyed,
};
HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration,
HRESULT d3d8_vertex_declaration_init(struct d3d8_vertex_declaration *declaration,
IDirect3DDevice8Impl *device, const DWORD *elements, DWORD shader_handle)
{
struct wined3d_vertex_element *wined3d_elements;
UINT wined3d_element_count;
HRESULT hr;
declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
declaration->ref_count = 1;
declaration->shader_handle = shader_handle;
wined3d_element_count = convert_to_wined3d_declaration(elements, &declaration->elements_size, &wined3d_elements);
......@@ -415,13 +365,11 @@ HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration,
return D3D_OK;
}
HRESULT vertexdeclaration_init_fvf(IDirect3DVertexDeclaration8Impl *declaration,
HRESULT d3d8_vertex_declaration_init_fvf(struct d3d8_vertex_declaration *declaration,
IDirect3DDevice8Impl *device, DWORD fvf)
{
HRESULT hr;
declaration->ref_count = 1;
declaration->lpVtbl = &Direct3DVertexDeclaration8_Vtbl;
declaration->elements = NULL;
declaration->elements_size = 0;
declaration->shader_handle = fvf;
......
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