Commit 97b55258 authored by Stefan Dösinger's avatar Stefan Dösinger Committed by Alexandre Julliard

d3d8: Introduce a resource structure.

parent bda96fde
......@@ -48,7 +48,7 @@ static HRESULT WINAPI d3d8_vertexbuffer_QueryInterface(IDirect3DVertexBuffer8 *i
static ULONG WINAPI d3d8_vertexbuffer_AddRef(IDirect3DVertexBuffer8 *iface)
{
struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
ULONG refcount = InterlockedIncrement(&buffer->refcount);
ULONG refcount = InterlockedIncrement(&buffer->resource.refcount);
TRACE("%p increasing refcount to %u.\n", iface, refcount);
......@@ -66,7 +66,7 @@ static ULONG WINAPI d3d8_vertexbuffer_AddRef(IDirect3DVertexBuffer8 *iface)
static ULONG WINAPI d3d8_vertexbuffer_Release(IDirect3DVertexBuffer8 *iface)
{
struct d3d8_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer8(iface);
ULONG refcount = InterlockedDecrement(&buffer->refcount);
ULONG refcount = InterlockedDecrement(&buffer->resource.refcount);
TRACE("%p decreasing refcount to %u.\n", iface, refcount);
......@@ -274,7 +274,9 @@ static const IDirect3DVertexBuffer8Vtbl Direct3DVertexBuffer8_Vtbl =
static void STDMETHODCALLTYPE d3d8_vertexbuffer_wined3d_object_destroyed(void *parent)
{
HeapFree(GetProcessHeap(), 0, parent);
struct d3d8_vertexbuffer *buffer = parent;
d3d8_resource_cleanup(&buffer->resource);
HeapFree(GetProcessHeap(), 0, buffer);
}
static const struct wined3d_parent_ops d3d8_vertexbuffer_wined3d_parent_ops =
......@@ -288,7 +290,7 @@ HRESULT vertexbuffer_init(struct d3d8_vertexbuffer *buffer, struct d3d8_device *
HRESULT hr;
buffer->IDirect3DVertexBuffer8_iface.lpVtbl = &Direct3DVertexBuffer8_Vtbl;
buffer->refcount = 1;
d3d8_resource_init(&buffer->resource);
buffer->fvf = fvf;
wined3d_mutex_lock();
......@@ -343,7 +345,7 @@ static HRESULT WINAPI d3d8_indexbuffer_QueryInterface(IDirect3DIndexBuffer8 *ifa
static ULONG WINAPI d3d8_indexbuffer_AddRef(IDirect3DIndexBuffer8 *iface)
{
struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
ULONG refcount = InterlockedIncrement(&buffer->refcount);
ULONG refcount = InterlockedIncrement(&buffer->resource.refcount);
TRACE("%p increasing refcount to %u.\n", iface, refcount);
......@@ -361,7 +363,7 @@ static ULONG WINAPI d3d8_indexbuffer_AddRef(IDirect3DIndexBuffer8 *iface)
static ULONG WINAPI d3d8_indexbuffer_Release(IDirect3DIndexBuffer8 *iface)
{
struct d3d8_indexbuffer *buffer = impl_from_IDirect3DIndexBuffer8(iface);
ULONG refcount = InterlockedDecrement(&buffer->refcount);
ULONG refcount = InterlockedDecrement(&buffer->resource.refcount);
TRACE("%p decreasing refcount to %u.\n", iface, refcount);
......@@ -568,7 +570,9 @@ static const IDirect3DIndexBuffer8Vtbl d3d8_indexbuffer_vtbl =
static void STDMETHODCALLTYPE d3d8_indexbuffer_wined3d_object_destroyed(void *parent)
{
HeapFree(GetProcessHeap(), 0, parent);
struct d3d8_indexbuffer *buffer = parent;
d3d8_resource_cleanup(&buffer->resource);
HeapFree(GetProcessHeap(), 0, buffer);
}
static const struct wined3d_parent_ops d3d8_indexbuffer_wined3d_parent_ops =
......@@ -582,7 +586,7 @@ HRESULT indexbuffer_init(struct d3d8_indexbuffer *buffer, struct d3d8_device *de
HRESULT hr;
buffer->IDirect3DIndexBuffer8_iface.lpVtbl = &d3d8_indexbuffer_vtbl;
buffer->refcount = 1;
d3d8_resource_init(&buffer->resource);
buffer->format = wined3dformat_from_d3dformat(format);
wined3d_mutex_lock();
......
......@@ -137,3 +137,12 @@ HRESULT WINAPI ValidatePixelShader(DWORD* pixelshader, DWORD* reserved1, BOOL bo
}
return ret;
}
void d3d8_resource_cleanup(struct d3d8_resource *resource)
{
}
void d3d8_resource_init(struct d3d8_resource *resource)
{
resource->refcount = 1;
}
......@@ -174,10 +174,18 @@ struct d3d8_device
HRESULT device_init(struct d3d8_device *device, struct d3d8 *parent, struct wined3d *wined3d, UINT adapter,
D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters) DECLSPEC_HIDDEN;
struct d3d8_resource
{
LONG refcount;
};
void d3d8_resource_cleanup(struct d3d8_resource *resource) DECLSPEC_HIDDEN;
void d3d8_resource_init(struct d3d8_resource *resource) DECLSPEC_HIDDEN;
struct d3d8_volume
{
IDirect3DVolume8 IDirect3DVolume8_iface;
LONG refcount;
struct d3d8_resource resource;
struct wined3d_volume *wined3d_volume;
IUnknown *container;
IUnknown *forwardReference;
......@@ -200,7 +208,7 @@ HRESULT d3d8_swapchain_create(struct d3d8_device *device, struct wined3d_swapcha
struct d3d8_surface
{
IDirect3DSurface8 IDirect3DSurface8_iface;
LONG refcount;
struct d3d8_resource resource;
struct wined3d_surface *wined3d_surface;
IDirect3DDevice8 *parent_device;
......@@ -218,7 +226,7 @@ struct d3d8_surface *unsafe_impl_from_IDirect3DSurface8(IDirect3DSurface8 *iface
struct d3d8_vertexbuffer
{
IDirect3DVertexBuffer8 IDirect3DVertexBuffer8_iface;
LONG refcount;
struct d3d8_resource resource;
struct wined3d_buffer *wined3d_buffer;
IDirect3DDevice8 *parent_device;
DWORD fvf;
......@@ -231,7 +239,7 @@ struct d3d8_vertexbuffer *unsafe_impl_from_IDirect3DVertexBuffer8(IDirect3DVerte
struct d3d8_indexbuffer
{
IDirect3DIndexBuffer8 IDirect3DIndexBuffer8_iface;
LONG refcount;
struct d3d8_resource resource;
struct wined3d_buffer *wined3d_buffer;
IDirect3DDevice8 *parent_device;
enum wined3d_format_id format;
......@@ -244,7 +252,7 @@ struct d3d8_indexbuffer *unsafe_impl_from_IDirect3DIndexBuffer8(IDirect3DIndexBu
struct d3d8_texture
{
IDirect3DBaseTexture8 IDirect3DBaseTexture8_iface;
LONG refcount;
struct d3d8_resource resource;
struct wined3d_texture *wined3d_texture;
IDirect3DDevice8 *parent_device;
};
......
......@@ -600,7 +600,7 @@ static HRESULT CDECL reset_enum_callback(struct wined3d_resource *resource)
}
surface = wined3d_resource_get_parent(resource);
if (surface->refcount)
if (surface->resource.refcount)
{
WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface, resource);
return D3DERR_DEVICELOST;
......
......@@ -62,7 +62,7 @@ static ULONG WINAPI d3d8_surface_AddRef(IDirect3DSurface8 *iface)
else
{
/* No container, handle our own refcounting */
ULONG ref = InterlockedIncrement(&surface->refcount);
ULONG ref = InterlockedIncrement(&surface->resource.refcount);
TRACE("%p increasing refcount to %u.\n", iface, ref);
......@@ -94,7 +94,7 @@ static ULONG WINAPI d3d8_surface_Release(IDirect3DSurface8 *iface)
else
{
/* No container, handle our own refcounting */
ULONG ref = InterlockedDecrement(&surface->refcount);
ULONG ref = InterlockedDecrement(&surface->resource.refcount);
TRACE("%p decreasing refcount to %u.\n", iface, ref);
......@@ -325,7 +325,9 @@ static const IDirect3DSurface8Vtbl d3d8_surface_vtbl =
static void STDMETHODCALLTYPE surface_wined3d_object_destroyed(void *parent)
{
HeapFree(GetProcessHeap(), 0, parent);
struct d3d8_surface *surface = parent;
d3d8_resource_cleanup(&surface->resource);
HeapFree(GetProcessHeap(), 0, surface);
}
static const struct wined3d_parent_ops d3d8_surface_wined3d_parent_ops =
......@@ -337,7 +339,7 @@ void surface_init(struct d3d8_surface *surface, struct wined3d_surface *wined3d_
struct d3d8_device *device, const struct wined3d_parent_ops **parent_ops)
{
surface->IDirect3DSurface8_iface.lpVtbl = &d3d8_surface_vtbl;
surface->refcount = 1;
d3d8_resource_init(&surface->resource);
wined3d_surface_incref(wined3d_surface);
surface->wined3d_surface = wined3d_surface;
surface->parent_device = &device->IDirect3DDevice8_iface;
......
......@@ -59,7 +59,7 @@ static HRESULT WINAPI d3d8_texture_2d_QueryInterface(IDirect3DTexture8 *iface, R
static ULONG WINAPI d3d8_texture_2d_AddRef(IDirect3DTexture8 *iface)
{
struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
ULONG ref = InterlockedIncrement(&texture->refcount);
ULONG ref = InterlockedIncrement(&texture->resource.refcount);
TRACE("%p increasing refcount to %u.\n", iface, ref);
......@@ -77,7 +77,7 @@ static ULONG WINAPI d3d8_texture_2d_AddRef(IDirect3DTexture8 *iface)
static ULONG WINAPI d3d8_texture_2d_Release(IDirect3DTexture8 *iface)
{
struct d3d8_texture *texture = impl_from_IDirect3DTexture8(iface);
ULONG ref = InterlockedDecrement(&texture->refcount);
ULONG ref = InterlockedDecrement(&texture->resource.refcount);
TRACE("%p decreasing refcount to %u.\n", iface, ref);
......@@ -427,7 +427,7 @@ static HRESULT WINAPI d3d8_texture_cube_QueryInterface(IDirect3DCubeTexture8 *if
static ULONG WINAPI d3d8_texture_cube_AddRef(IDirect3DCubeTexture8 *iface)
{
struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
ULONG ref = InterlockedIncrement(&texture->refcount);
ULONG ref = InterlockedIncrement(&texture->resource.refcount);
TRACE("%p increasing refcount to %u.\n", iface, ref);
......@@ -445,7 +445,7 @@ static ULONG WINAPI d3d8_texture_cube_AddRef(IDirect3DCubeTexture8 *iface)
static ULONG WINAPI d3d8_texture_cube_Release(IDirect3DCubeTexture8 *iface)
{
struct d3d8_texture *texture = impl_from_IDirect3DCubeTexture8(iface);
ULONG ref = InterlockedDecrement(&texture->refcount);
ULONG ref = InterlockedDecrement(&texture->resource.refcount);
TRACE("%p decreasing refcount to %u.\n", iface, ref);
......@@ -820,7 +820,7 @@ static HRESULT WINAPI d3d8_texture_3d_QueryInterface(IDirect3DVolumeTexture8 *if
static ULONG WINAPI d3d8_texture_3d_AddRef(IDirect3DVolumeTexture8 *iface)
{
struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
ULONG ref = InterlockedIncrement(&texture->refcount);
ULONG ref = InterlockedIncrement(&texture->resource.refcount);
TRACE("%p increasing refcount to %u.\n", iface, ref);
......@@ -838,7 +838,7 @@ static ULONG WINAPI d3d8_texture_3d_AddRef(IDirect3DVolumeTexture8 *iface)
static ULONG WINAPI d3d8_texture_3d_Release(IDirect3DVolumeTexture8 *iface)
{
struct d3d8_texture *texture = impl_from_IDirect3DVolumeTexture8(iface);
ULONG ref = InterlockedDecrement(&texture->refcount);
ULONG ref = InterlockedDecrement(&texture->resource.refcount);
TRACE("%p decreasing refcount to %u.\n", iface, ref);
......@@ -1174,7 +1174,9 @@ struct d3d8_texture *unsafe_impl_from_IDirect3DBaseTexture8(IDirect3DBaseTexture
static void STDMETHODCALLTYPE d3d8_texture_wined3d_object_destroyed(void *parent)
{
HeapFree(GetProcessHeap(), 0, parent);
struct d3d8_texture *texture = parent;
d3d8_resource_cleanup(&texture->resource);
HeapFree(GetProcessHeap(), 0, texture);
}
static const struct wined3d_parent_ops d3d8_texture_wined3d_parent_ops =
......@@ -1190,7 +1192,7 @@ HRESULT texture_init(struct d3d8_texture *texture, struct d3d8_device *device,
HRESULT hr;
texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DTexture8_Vtbl;
texture->refcount = 1;
d3d8_resource_init(&texture->resource);
desc.resource_type = WINED3D_RTYPE_TEXTURE;
desc.format = wined3dformat_from_d3dformat(format);
......@@ -1231,7 +1233,7 @@ HRESULT cubetexture_init(struct d3d8_texture *texture, struct d3d8_device *devic
HRESULT hr;
texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DCubeTexture8_Vtbl;
texture->refcount = 1;
d3d8_resource_init(&texture->resource);
desc.resource_type = WINED3D_RTYPE_CUBE_TEXTURE;
desc.format = wined3dformat_from_d3dformat(format);
......@@ -1271,7 +1273,7 @@ HRESULT volumetexture_init(struct d3d8_texture *texture, struct d3d8_device *dev
HRESULT hr;
texture->IDirect3DBaseTexture8_iface.lpVtbl = (const IDirect3DBaseTexture8Vtbl *)&Direct3DVolumeTexture8_Vtbl;
texture->refcount = 1;
d3d8_resource_init(&texture->resource);
desc.resource_type = WINED3D_RTYPE_VOLUME_TEXTURE;
desc.format = wined3dformat_from_d3dformat(format);
......
......@@ -61,7 +61,7 @@ static ULONG WINAPI d3d8_volume_AddRef(IDirect3DVolume8 *iface)
else
{
/* No container, handle our own refcounting */
ULONG ref = InterlockedIncrement(&volume->refcount);
ULONG ref = InterlockedIncrement(&volume->resource.refcount);
TRACE("%p increasing refcount to %u.\n", iface, ref);
......@@ -91,7 +91,7 @@ static ULONG WINAPI d3d8_volume_Release(IDirect3DVolume8 *iface)
else
{
/* No container, handle our own refcounting */
ULONG ref = InterlockedDecrement(&volume->refcount);
ULONG ref = InterlockedDecrement(&volume->resource.refcount);
TRACE("%p decreasing refcount to %u.\n", iface, ref);
......@@ -275,7 +275,9 @@ static const IDirect3DVolume8Vtbl d3d8_volume_vtbl =
static void STDMETHODCALLTYPE volume_wined3d_object_destroyed(void *parent)
{
HeapFree(GetProcessHeap(), 0, parent);
struct d3d8_volume *volume = parent;
d3d8_resource_cleanup(&volume->resource);
HeapFree(GetProcessHeap(), 0, volume);
}
static const struct wined3d_parent_ops d3d8_volume_wined3d_parent_ops =
......@@ -287,7 +289,7 @@ void volume_init(struct d3d8_volume *volume, struct wined3d_volume *wined3d_volu
const struct wined3d_parent_ops **parent_ops)
{
volume->IDirect3DVolume8_iface.lpVtbl = &d3d8_volume_vtbl;
volume->refcount = 1;
d3d8_resource_init(&volume->resource);
wined3d_volume_incref(wined3d_volume);
volume->wined3d_volume = wined3d_volume;
......
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