Module: wine Branch: master Commit: 0a9ac7e992824f28b81dc0f3f5a14deed4d781b0 URL: http://source.winehq.org/git/wine.git/?a=commit;h=0a9ac7e992824f28b81dc0f3f5...
Author: Henri Verbeet hverbeet@codeweavers.com Date: Sun Apr 15 18:57:11 2012 +0200
d3d10core: COM cleanup for the ID3D10Buffer interface.
---
dlls/d3d10core/buffer.c | 47 +++++++++++++++++++++++------------- dlls/d3d10core/d3d10core_private.h | 5 +++- dlls/d3d10core/device.c | 10 ++++--- dlls/d3d10core/inputlayout.c | 1 - dlls/d3d10core/shader.c | 1 - dlls/d3d10core/view.c | 1 - 6 files changed, 40 insertions(+), 25 deletions(-)
diff --git a/dlls/d3d10core/buffer.c b/dlls/d3d10core/buffer.c index fd2175e..90ff0e8 100644 --- a/dlls/d3d10core/buffer.c +++ b/dlls/d3d10core/buffer.c @@ -24,11 +24,16 @@
WINE_DEFAULT_DEBUG_CHANNEL(d3d10core);
+static inline struct d3d10_buffer *impl_from_ID3D10Buffer(ID3D10Buffer *iface) +{ + return CONTAINING_RECORD(iface, struct d3d10_buffer, ID3D10Buffer_iface); +} + /* IUnknown methods */
-static HRESULT STDMETHODCALLTYPE d3d10_buffer_QueryInterface(ID3D10Buffer *iface, REFIID riid, void **object) +static HRESULT STDMETHODCALLTYPE d3d10_buffer_QueryInterface(ID3D10Buffer *iface, REFIID riid, void **out) { - TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object); + TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
if (IsEqualGUID(riid, &IID_ID3D10Buffer) || IsEqualGUID(riid, &IID_ID3D10Resource) @@ -36,40 +41,38 @@ static HRESULT STDMETHODCALLTYPE d3d10_buffer_QueryInterface(ID3D10Buffer *iface || IsEqualGUID(riid, &IID_IUnknown)) { IUnknown_AddRef(iface); - *object = iface; + *out = iface; return S_OK; }
WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
- *object = NULL; + *out = NULL; return E_NOINTERFACE; }
static ULONG STDMETHODCALLTYPE d3d10_buffer_AddRef(ID3D10Buffer *iface) { - struct d3d10_buffer *This = (struct d3d10_buffer *)iface; - ULONG refcount = InterlockedIncrement(&This->refcount); + struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface); + ULONG refcount = InterlockedIncrement(&buffer->refcount);
- TRACE("%p increasing refcount to %u\n", This, refcount); + TRACE("%p increasing refcount to %u.\n", buffer, refcount);
if (refcount == 1) - wined3d_buffer_incref(This->wined3d_buffer); + wined3d_buffer_incref(buffer->wined3d_buffer);
return refcount; }
static ULONG STDMETHODCALLTYPE d3d10_buffer_Release(ID3D10Buffer *iface) { - struct d3d10_buffer *This = (struct d3d10_buffer *)iface; - ULONG refcount = InterlockedDecrement(&This->refcount); + struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface); + ULONG refcount = InterlockedDecrement(&buffer->refcount);
- TRACE("%p decreasing refcount to %u\n", This, refcount); + TRACE("%p decreasing refcount to %u.\n", buffer, refcount);
if (!refcount) - { - wined3d_buffer_decref(This->wined3d_buffer); - } + wined3d_buffer_decref(buffer->wined3d_buffer);
return refcount; } @@ -132,7 +135,7 @@ static UINT STDMETHODCALLTYPE d3d10_buffer_GetEvictionPriority(ID3D10Buffer *ifa
static HRESULT STDMETHODCALLTYPE d3d10_buffer_Map(ID3D10Buffer *iface, D3D10_MAP map_type, UINT map_flags, void **data) { - struct d3d10_buffer *buffer = (struct d3d10_buffer *)iface; + struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface);
TRACE("iface %p, map_type %u, map_flags %#x, data %p.\n", iface, map_type, map_flags, data);
@@ -146,9 +149,11 @@ static HRESULT STDMETHODCALLTYPE d3d10_buffer_Map(ID3D10Buffer *iface, D3D10_MAP
static void STDMETHODCALLTYPE d3d10_buffer_Unmap(ID3D10Buffer *iface) { + struct d3d10_buffer *buffer = impl_from_ID3D10Buffer(iface); + TRACE("iface %p.\n", iface);
- wined3d_buffer_unmap(((struct d3d10_buffer *)iface)->wined3d_buffer); + wined3d_buffer_unmap(buffer->wined3d_buffer); }
static void STDMETHODCALLTYPE d3d10_buffer_GetDesc(ID3D10Buffer *iface, D3D10_BUFFER_DESC *desc) @@ -177,6 +182,14 @@ static const struct ID3D10BufferVtbl d3d10_buffer_vtbl = d3d10_buffer_GetDesc, };
+struct d3d10_buffer *unsafe_impl_from_ID3D10Buffer(ID3D10Buffer *iface) +{ + if (!iface) + return NULL; + assert(iface->lpVtbl == &d3d10_buffer_vtbl); + return CONTAINING_RECORD(iface, struct d3d10_buffer, ID3D10Buffer_iface); +} + static void STDMETHODCALLTYPE d3d10_buffer_wined3d_object_released(void *parent) { HeapFree(GetProcessHeap(), 0, parent); @@ -193,7 +206,7 @@ HRESULT d3d10_buffer_init(struct d3d10_buffer *buffer, struct d3d10_device *devi struct wined3d_buffer_desc wined3d_desc; HRESULT hr;
- buffer->vtbl = &d3d10_buffer_vtbl; + buffer->ID3D10Buffer_iface.lpVtbl = &d3d10_buffer_vtbl; buffer->refcount = 1;
FIXME("Implement DXGI<->wined3d usage conversion\n"); diff --git a/dlls/d3d10core/d3d10core_private.h b/dlls/d3d10core/d3d10core_private.h index d99a337..5f320e0 100644 --- a/dlls/d3d10core/d3d10core_private.h +++ b/dlls/d3d10core/d3d10core_private.h @@ -21,6 +21,8 @@
#include "wine/debug.h"
+#include <assert.h> + #define COBJMACROS #include "winbase.h" #include "wingdi.h" @@ -111,7 +113,7 @@ HRESULT d3d10_texture3d_init(struct d3d10_texture3d *texture, struct d3d10_devic /* ID3D10Buffer */ struct d3d10_buffer { - const struct ID3D10BufferVtbl *vtbl; + ID3D10Buffer ID3D10Buffer_iface; LONG refcount;
struct wined3d_buffer *wined3d_buffer; @@ -119,6 +121,7 @@ struct d3d10_buffer
HRESULT d3d10_buffer_init(struct d3d10_buffer *buffer, struct d3d10_device *device, const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data) DECLSPEC_HIDDEN; +struct d3d10_buffer *unsafe_impl_from_ID3D10Buffer(ID3D10Buffer *iface) DECLSPEC_HIDDEN;
/* ID3D10DepthStencilView */ struct d3d10_depthstencil_view diff --git a/dlls/d3d10core/device.c b/dlls/d3d10core/device.c index cf21bba..637109f 100644 --- a/dlls/d3d10core/device.c +++ b/dlls/d3d10core/device.c @@ -203,9 +203,10 @@ static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device *ifac
for (i = 0; i < buffer_count; ++i) { + struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]); + wined3d_device_set_stream_source(This->wined3d_device, start_slot, - buffers[i] ? ((struct d3d10_buffer *)buffers[i])->wined3d_buffer : NULL, - offsets[i], strides[i]); + buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]); } }
@@ -213,12 +214,13 @@ static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device *iface, ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset) { struct d3d10_device *This = impl_from_ID3D10Device(iface); + struct d3d10_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
TRACE("iface %p, buffer %p, format %s, offset %u.\n", iface, buffer, debug_dxgi_format(format), offset);
wined3d_device_set_index_buffer(This->wined3d_device, - buffer ? ((struct d3d10_buffer *)buffer)->wined3d_buffer : NULL, + buffer_impl ? buffer_impl->wined3d_buffer : NULL, wined3dformat_from_dxgi_format(format)); if (offset) FIXME("offset %u not supported.\n", offset); } @@ -644,7 +646,7 @@ static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device *iface, return hr; }
- *buffer = (ID3D10Buffer *)object; + *buffer = &object->ID3D10Buffer_iface;
TRACE("Created ID3D10Buffer %p\n", object);
diff --git a/dlls/d3d10core/inputlayout.c b/dlls/d3d10core/inputlayout.c index d6ae787..09b8998 100644 --- a/dlls/d3d10core/inputlayout.c +++ b/dlls/d3d10core/inputlayout.c @@ -19,7 +19,6 @@
#include "config.h" #include "wine/port.h" -#include <assert.h>
#include "d3d10core_private.h"
diff --git a/dlls/d3d10core/shader.c b/dlls/d3d10core/shader.c index 82ddadc..c6803ed 100644 --- a/dlls/d3d10core/shader.c +++ b/dlls/d3d10core/shader.c @@ -19,7 +19,6 @@
#include "config.h" #include "wine/port.h" -#include <assert.h>
#include "d3d10core_private.h"
diff --git a/dlls/d3d10core/view.c b/dlls/d3d10core/view.c index 57c4148..57473e4 100644 --- a/dlls/d3d10core/view.c +++ b/dlls/d3d10core/view.c @@ -19,7 +19,6 @@
#include "config.h" #include "wine/port.h" -#include <assert.h>
#define NONAMELESSUNION #include "d3d10core_private.h"