[WINED3D|DDRAW|D3D8|D3D9]
authorKamil Hornicek <kamil.hornicek@reactos.org>
Thu, 1 Mar 2012 18:39:47 +0000 (18:39 +0000)
committerKamil Hornicek <kamil.hornicek@reactos.org>
Thu, 1 Mar 2012 18:39:47 +0000 (18:39 +0000)
Sync to Wine 1.3.37.

svn path=/trunk/; revision=55951

75 files changed:
reactos/dll/directx/wine/d3d8/buffer.c
reactos/dll/directx/wine/d3d8/cubetexture.c
reactos/dll/directx/wine/d3d8/d3d8_main.c
reactos/dll/directx/wine/d3d8/d3d8_private.h
reactos/dll/directx/wine/d3d8/device.c
reactos/dll/directx/wine/d3d8/directx.c
reactos/dll/directx/wine/d3d8/shader.c
reactos/dll/directx/wine/d3d8/surface.c
reactos/dll/directx/wine/d3d8/swapchain.c
reactos/dll/directx/wine/d3d8/texture.c
reactos/dll/directx/wine/d3d8/vertexdeclaration.c
reactos/dll/directx/wine/d3d8/volume.c
reactos/dll/directx/wine/d3d8/volumetexture.c
reactos/dll/directx/wine/d3d9/buffer.c
reactos/dll/directx/wine/d3d9/cubetexture.c
reactos/dll/directx/wine/d3d9/d3d9_main.c
reactos/dll/directx/wine/d3d9/d3d9_private.h
reactos/dll/directx/wine/d3d9/device.c
reactos/dll/directx/wine/d3d9/directx.c
reactos/dll/directx/wine/d3d9/shader.c
reactos/dll/directx/wine/d3d9/stateblock.c
reactos/dll/directx/wine/d3d9/surface.c
reactos/dll/directx/wine/d3d9/swapchain.c
reactos/dll/directx/wine/d3d9/texture.c
reactos/dll/directx/wine/d3d9/vertexdeclaration.c
reactos/dll/directx/wine/d3d9/volume.c
reactos/dll/directx/wine/d3d9/volumetexture.c
reactos/dll/directx/wine/ddraw/CMakeLists.txt
reactos/dll/directx/wine/ddraw/clipper.c
reactos/dll/directx/wine/ddraw/ddraw.c
reactos/dll/directx/wine/ddraw/ddraw.rc [new file with mode: 0644]
reactos/dll/directx/wine/ddraw/ddraw.rgs [new file with mode: 0644]
reactos/dll/directx/wine/ddraw/ddraw_private.h
reactos/dll/directx/wine/ddraw/device.c
reactos/dll/directx/wine/ddraw/executebuffer.c
reactos/dll/directx/wine/ddraw/light.c
reactos/dll/directx/wine/ddraw/main.c
reactos/dll/directx/wine/ddraw/material.c
reactos/dll/directx/wine/ddraw/palette.c
reactos/dll/directx/wine/ddraw/parent.c [deleted file]
reactos/dll/directx/wine/ddraw/regsvr.c [deleted file]
reactos/dll/directx/wine/ddraw/surface.c
reactos/dll/directx/wine/ddraw/utils.c
reactos/dll/directx/wine/ddraw/vertexbuffer.c
reactos/dll/directx/wine/ddraw/viewport.c
reactos/dll/directx/wine/wined3d/CMakeLists.txt
reactos/dll/directx/wine/wined3d/arb_program_shader.c
reactos/dll/directx/wine/wined3d/ati_fragment_shader.c
reactos/dll/directx/wine/wined3d/buffer.c
reactos/dll/directx/wine/wined3d/clipper.c [deleted file]
reactos/dll/directx/wine/wined3d/context.c
reactos/dll/directx/wine/wined3d/device.c
reactos/dll/directx/wine/wined3d/directx.c
reactos/dll/directx/wine/wined3d/drawprim.c
reactos/dll/directx/wine/wined3d/gl_compat.c
reactos/dll/directx/wine/wined3d/glsl_shader.c
reactos/dll/directx/wine/wined3d/nvidia_texture_shader.c
reactos/dll/directx/wine/wined3d/palette.c
reactos/dll/directx/wine/wined3d/query.c
reactos/dll/directx/wine/wined3d/resource.c
reactos/dll/directx/wine/wined3d/shader.c
reactos/dll/directx/wine/wined3d/shader_sm4.c
reactos/dll/directx/wine/wined3d/state.c
reactos/dll/directx/wine/wined3d/stateblock.c
reactos/dll/directx/wine/wined3d/surface.c
reactos/dll/directx/wine/wined3d/swapchain.c
reactos/dll/directx/wine/wined3d/texture.c
reactos/dll/directx/wine/wined3d/utils.c
reactos/dll/directx/wine/wined3d/vertexdeclaration.c
reactos/dll/directx/wine/wined3d/volume.c
reactos/dll/directx/wine/wined3d/wined3d.spec
reactos/dll/directx/wine/wined3d/wined3d_gl.h
reactos/dll/directx/wine/wined3d/wined3d_main.c
reactos/dll/directx/wine/wined3d/wined3d_private.h
reactos/include/reactos/wine/wined3d.h

index 8cf5531..4ab6524 100644 (file)
  */
 
 #include "config.h"
+#include <assert.h>
 #include "d3d8_private.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
 
+static inline IDirect3DVertexBuffer8Impl *impl_from_IDirect3DVertexBuffer8(IDirect3DVertexBuffer8 *iface)
+{
+    return CONTAINING_RECORD(iface, IDirect3DVertexBuffer8Impl, IDirect3DVertexBuffer8_iface);
+}
+
 static HRESULT WINAPI d3d8_vertexbuffer_QueryInterface(IDirect3DVertexBuffer8 *iface, REFIID riid, void **object)
 {
     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
@@ -42,7 +48,7 @@ static HRESULT WINAPI d3d8_vertexbuffer_QueryInterface(IDirect3DVertexBuffer8 *i
 
 static ULONG WINAPI d3d8_vertexbuffer_AddRef(IDirect3DVertexBuffer8 *iface)
 {
-    IDirect3DVertexBuffer8Impl *buffer = (IDirect3DVertexBuffer8Impl *)iface;
+    IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface);
     ULONG refcount = InterlockedIncrement(&buffer->ref);
 
     TRACE("%p increasing refcount to %u.\n", iface, refcount);
@@ -60,7 +66,7 @@ static ULONG WINAPI d3d8_vertexbuffer_AddRef(IDirect3DVertexBuffer8 *iface)
 
 static ULONG WINAPI d3d8_vertexbuffer_Release(IDirect3DVertexBuffer8 *iface)
 {
-    IDirect3DVertexBuffer8Impl *buffer = (IDirect3DVertexBuffer8Impl *)iface;
+    IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface);
     ULONG refcount = InterlockedDecrement(&buffer->ref);
 
     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
@@ -80,11 +86,14 @@ static ULONG WINAPI d3d8_vertexbuffer_Release(IDirect3DVertexBuffer8 *iface)
     return refcount;
 }
 
-static HRESULT WINAPI d3d8_vertexbuffer_GetDevice(IDirect3DVertexBuffer8 *iface, IDirect3DDevice8 **device)
+static HRESULT WINAPI d3d8_vertexbuffer_GetDevice(IDirect3DVertexBuffer8 *iface,
+        IDirect3DDevice8 **device)
 {
+    IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface);
+
     TRACE("iface %p, device %p.\n", iface, device);
 
-    *device = (IDirect3DDevice8 *)((IDirect3DVertexBuffer8Impl *)iface)->parentDevice;
+    *device = buffer->parentDevice;
     IDirect3DDevice8_AddRef(*device);
 
     TRACE("Returning device %p.\n", *device);
@@ -95,14 +104,16 @@ static HRESULT WINAPI d3d8_vertexbuffer_GetDevice(IDirect3DVertexBuffer8 *iface,
 static HRESULT WINAPI d3d8_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer8 *iface,
         REFGUID guid, const void *data, DWORD data_size, DWORD flags)
 {
+    IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
             iface, debugstr_guid(guid), data, data_size, flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_buffer_set_private_data(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer,
-            guid, data, data_size, flags);
+    resource = wined3d_buffer_get_resource(buffer->wineD3DVertexBuffer);
+    hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -111,14 +122,16 @@ static HRESULT WINAPI d3d8_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer8 *i
 static HRESULT WINAPI d3d8_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer8 *iface,
         REFGUID guid, void *data, DWORD *data_size)
 {
+    IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
             iface, debugstr_guid(guid), data, data_size);
 
     wined3d_mutex_lock();
-    hr = wined3d_buffer_get_private_data(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer,
-            guid, data, data_size);
+    resource = wined3d_buffer_get_resource(buffer->wineD3DVertexBuffer);
+    hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
     wined3d_mutex_unlock();
 
     return hr;
@@ -126,12 +139,15 @@ static HRESULT WINAPI d3d8_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer8 *i
 
 static HRESULT WINAPI d3d8_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer8 *iface, REFGUID guid)
 {
+    IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
 
     wined3d_mutex_lock();
-    hr = wined3d_buffer_free_private_data(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer, guid);
+    resource = wined3d_buffer_get_resource(buffer->wineD3DVertexBuffer);
+    hr = wined3d_resource_free_private_data(resource, guid);
     wined3d_mutex_unlock();
 
     return hr;
@@ -139,12 +155,13 @@ static HRESULT WINAPI d3d8_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer8 *
 
 static DWORD WINAPI d3d8_vertexbuffer_SetPriority(IDirect3DVertexBuffer8 *iface, DWORD priority)
 {
+    IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface);
     DWORD previous;
 
     TRACE("iface %p, priority %u.\n", iface, priority);
 
     wined3d_mutex_lock();
-    previous = wined3d_buffer_set_priority(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer, priority);
+    previous = wined3d_buffer_set_priority(buffer->wineD3DVertexBuffer, priority);
     wined3d_mutex_unlock();
 
     return previous;
@@ -152,12 +169,13 @@ static DWORD WINAPI d3d8_vertexbuffer_SetPriority(IDirect3DVertexBuffer8 *iface,
 
 static DWORD WINAPI d3d8_vertexbuffer_GetPriority(IDirect3DVertexBuffer8 *iface)
 {
+    IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface);
     DWORD priority;
 
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    priority = wined3d_buffer_get_priority(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer);
+    priority = wined3d_buffer_get_priority(buffer->wineD3DVertexBuffer);
     wined3d_mutex_unlock();
 
     return priority;
@@ -165,10 +183,12 @@ static DWORD WINAPI d3d8_vertexbuffer_GetPriority(IDirect3DVertexBuffer8 *iface)
 
 static void WINAPI d3d8_vertexbuffer_PreLoad(IDirect3DVertexBuffer8 *iface)
 {
+    IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface);
+
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    wined3d_buffer_preload(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer);
+    wined3d_buffer_preload(buffer->wineD3DVertexBuffer);
     wined3d_mutex_unlock();
 }
 
@@ -179,17 +199,17 @@ static D3DRESOURCETYPE WINAPI d3d8_vertexbuffer_GetType(IDirect3DVertexBuffer8 *
     return D3DRTYPE_VERTEXBUFFER;
 }
 
-static HRESULT WINAPI d3d8_vertexbuffer_Lock(IDirect3DVertexBuffer8 *iface,
-        UINT offset, UINT size, BYTE **data, DWORD flags)
+static HRESULT WINAPI d3d8_vertexbuffer_Lock(IDirect3DVertexBuffer8 *iface, UINT offset, UINT size,
+        BYTE **data, DWORD flags)
 {
+    IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface);
     HRESULT hr;
 
     TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
             iface, offset, size, data, flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_buffer_map(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer,
-            offset, size, data, flags);
+    hr = wined3d_buffer_map(buffer->wineD3DVertexBuffer, offset, size, data, flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -197,18 +217,21 @@ static HRESULT WINAPI d3d8_vertexbuffer_Lock(IDirect3DVertexBuffer8 *iface,
 
 static HRESULT WINAPI d3d8_vertexbuffer_Unlock(IDirect3DVertexBuffer8 *iface)
 {
+    IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface);
+
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    wined3d_buffer_unmap(((IDirect3DVertexBuffer8Impl *)iface)->wineD3DVertexBuffer);
+    wined3d_buffer_unmap(buffer->wineD3DVertexBuffer);
     wined3d_mutex_unlock();
 
     return D3D_OK;
 }
 
-static HRESULT WINAPI d3d8_vertexbuffer_GetDesc(IDirect3DVertexBuffer8 *iface, D3DVERTEXBUFFER_DESC *desc)
+static HRESULT WINAPI d3d8_vertexbuffer_GetDesc(IDirect3DVertexBuffer8 *iface,
+        D3DVERTEXBUFFER_DESC *desc)
 {
-    IDirect3DVertexBuffer8Impl *buffer = (IDirect3DVertexBuffer8Impl *)iface;
+    IDirect3DVertexBuffer8Impl *buffer = impl_from_IDirect3DVertexBuffer8(iface);
     struct wined3d_resource_desc wined3d_desc;
     struct wined3d_resource *wined3d_resource;
 
@@ -220,7 +243,7 @@ static HRESULT WINAPI d3d8_vertexbuffer_GetDesc(IDirect3DVertexBuffer8 *iface, D
     wined3d_mutex_unlock();
 
     desc->Type = D3DRTYPE_VERTEXBUFFER;
-    desc->Usage = wined3d_desc.usage;
+    desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
     desc->Pool = wined3d_desc.pool;
     desc->Size = wined3d_desc.size;
     desc->FVF = buffer->fvf;
@@ -265,13 +288,13 @@ HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Im
 {
     HRESULT hr;
 
-    buffer->lpVtbl = &Direct3DVertexBuffer8_Vtbl;
+    buffer->IDirect3DVertexBuffer8_iface.lpVtbl = &Direct3DVertexBuffer8_Vtbl;
     buffer->ref = 1;
     buffer->fvf = fvf;
 
     wined3d_mutex_lock();
     hr = wined3d_buffer_create_vb(device->wined3d_device, size, usage & WINED3DUSAGE_MASK,
-            (WINED3DPOOL)pool, buffer, &d3d8_vertexbuffer_wined3d_parent_ops, &buffer->wineD3DVertexBuffer);
+            (enum wined3d_pool)pool, buffer, &d3d8_vertexbuffer_wined3d_parent_ops, &buffer->wineD3DVertexBuffer);
     wined3d_mutex_unlock();
     if (FAILED(hr))
     {
@@ -285,6 +308,20 @@ HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Im
     return D3D_OK;
 }
 
+IDirect3DVertexBuffer8Impl *unsafe_impl_from_IDirect3DVertexBuffer8(IDirect3DVertexBuffer8 *iface)
+{
+    if (!iface)
+        return NULL;
+    assert(iface->lpVtbl == &Direct3DVertexBuffer8_Vtbl);
+
+    return impl_from_IDirect3DVertexBuffer8(iface);
+}
+
+static inline IDirect3DIndexBuffer8Impl *impl_from_IDirect3DIndexBuffer8(IDirect3DIndexBuffer8 *iface)
+{
+    return CONTAINING_RECORD(iface, IDirect3DIndexBuffer8Impl, IDirect3DIndexBuffer8_iface);
+}
+
 static HRESULT WINAPI d3d8_indexbuffer_QueryInterface(IDirect3DIndexBuffer8 *iface, REFIID riid, void **object)
 {
     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
@@ -306,7 +343,7 @@ static HRESULT WINAPI d3d8_indexbuffer_QueryInterface(IDirect3DIndexBuffer8 *ifa
 
 static ULONG WINAPI d3d8_indexbuffer_AddRef(IDirect3DIndexBuffer8 *iface)
 {
-    IDirect3DIndexBuffer8Impl *buffer = (IDirect3DIndexBuffer8Impl *)iface;
+    IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface);
     ULONG refcount = InterlockedIncrement(&buffer->ref);
 
     TRACE("%p increasing refcount to %u.\n", iface, refcount);
@@ -324,7 +361,7 @@ static ULONG WINAPI d3d8_indexbuffer_AddRef(IDirect3DIndexBuffer8 *iface)
 
 static ULONG WINAPI d3d8_indexbuffer_Release(IDirect3DIndexBuffer8 *iface)
 {
-    IDirect3DIndexBuffer8Impl *buffer = (IDirect3DIndexBuffer8Impl *)iface;
+    IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface);
     ULONG refcount = InterlockedDecrement(&buffer->ref);
 
     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
@@ -344,11 +381,14 @@ static ULONG WINAPI d3d8_indexbuffer_Release(IDirect3DIndexBuffer8 *iface)
     return refcount;
 }
 
-static HRESULT WINAPI d3d8_indexbuffer_GetDevice(IDirect3DIndexBuffer8 *iface, IDirect3DDevice8 **device)
+static HRESULT WINAPI d3d8_indexbuffer_GetDevice(IDirect3DIndexBuffer8 *iface,
+        IDirect3DDevice8 **device)
 {
+    IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface);
+
     TRACE("iface %p, device %p.\n", iface, device);
 
-    *device = (IDirect3DDevice8 *)((IDirect3DIndexBuffer8Impl *)iface)->parentDevice;
+    *device = buffer->parentDevice;
     IDirect3DDevice8_AddRef(*device);
 
     TRACE("Returning device %p.\n", *device);
@@ -359,14 +399,16 @@ static HRESULT WINAPI d3d8_indexbuffer_GetDevice(IDirect3DIndexBuffer8 *iface, I
 static HRESULT WINAPI d3d8_indexbuffer_SetPrivateData(IDirect3DIndexBuffer8 *iface,
         REFGUID guid, const void *data, DWORD data_size, DWORD flags)
 {
+    IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
             iface, debugstr_guid(guid), data, data_size, flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_buffer_set_private_data(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer,
-            guid, data, data_size, flags);
+    resource = wined3d_buffer_get_resource(buffer->wineD3DIndexBuffer);
+    hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -375,14 +417,16 @@ static HRESULT WINAPI d3d8_indexbuffer_SetPrivateData(IDirect3DIndexBuffer8 *ifa
 static HRESULT WINAPI d3d8_indexbuffer_GetPrivateData(IDirect3DIndexBuffer8 *iface,
         REFGUID guid, void *data, DWORD *data_size)
 {
+    IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
             iface, debugstr_guid(guid), data, data_size);
 
     wined3d_mutex_lock();
-    hr = wined3d_buffer_get_private_data(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer,
-            guid, data, data_size);
+    resource = wined3d_buffer_get_resource(buffer->wineD3DIndexBuffer);
+    hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
     wined3d_mutex_unlock();
 
     return hr;
@@ -390,12 +434,15 @@ static HRESULT WINAPI d3d8_indexbuffer_GetPrivateData(IDirect3DIndexBuffer8 *ifa
 
 static HRESULT WINAPI d3d8_indexbuffer_FreePrivateData(IDirect3DIndexBuffer8 *iface, REFGUID guid)
 {
+    IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
 
     wined3d_mutex_lock();
-    hr = wined3d_buffer_free_private_data(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer, guid);
+    resource = wined3d_buffer_get_resource(buffer->wineD3DIndexBuffer);
+    hr = wined3d_resource_free_private_data(resource, guid);
     wined3d_mutex_unlock();
 
     return hr;
@@ -403,12 +450,13 @@ static HRESULT WINAPI d3d8_indexbuffer_FreePrivateData(IDirect3DIndexBuffer8 *if
 
 static DWORD WINAPI d3d8_indexbuffer_SetPriority(IDirect3DIndexBuffer8 *iface, DWORD priority)
 {
+    IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface);
     DWORD previous;
 
     TRACE("iface %p, priority %u.\n", iface, priority);
 
     wined3d_mutex_lock();
-    previous = wined3d_buffer_set_priority(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer, priority);
+    previous = wined3d_buffer_set_priority(buffer->wineD3DIndexBuffer, priority);
     wined3d_mutex_unlock();
 
     return previous;
@@ -416,12 +464,13 @@ static DWORD WINAPI d3d8_indexbuffer_SetPriority(IDirect3DIndexBuffer8 *iface, D
 
 static DWORD WINAPI d3d8_indexbuffer_GetPriority(IDirect3DIndexBuffer8 *iface)
 {
+    IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface);
     DWORD priority;
 
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    priority = wined3d_buffer_get_priority(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer);
+    priority = wined3d_buffer_get_priority(buffer->wineD3DIndexBuffer);
     wined3d_mutex_unlock();
 
     return priority;
@@ -429,10 +478,12 @@ static DWORD WINAPI d3d8_indexbuffer_GetPriority(IDirect3DIndexBuffer8 *iface)
 
 static void WINAPI d3d8_indexbuffer_PreLoad(IDirect3DIndexBuffer8 *iface)
 {
+    IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface);
+
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    wined3d_buffer_preload(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer);
+    wined3d_buffer_preload(buffer->wineD3DIndexBuffer);
     wined3d_mutex_unlock();
 }
 
@@ -443,17 +494,17 @@ static D3DRESOURCETYPE WINAPI d3d8_indexbuffer_GetType(IDirect3DIndexBuffer8 *if
     return D3DRTYPE_INDEXBUFFER;
 }
 
-static HRESULT WINAPI d3d8_indexbuffer_Lock(IDirect3DIndexBuffer8 *iface,
-        UINT offset, UINT size, BYTE **data, DWORD flags)
+static HRESULT WINAPI d3d8_indexbuffer_Lock(IDirect3DIndexBuffer8 *iface, UINT offset, UINT size,
+        BYTE **data, DWORD flags)
 {
+    IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface);
     HRESULT hr;
 
     TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
             iface, offset, size, data, flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_buffer_map(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer,
-            offset, size, data, flags);
+    hr = wined3d_buffer_map(buffer->wineD3DIndexBuffer, offset, size, data, flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -461,18 +512,21 @@ static HRESULT WINAPI d3d8_indexbuffer_Lock(IDirect3DIndexBuffer8 *iface,
 
 static HRESULT WINAPI d3d8_indexbuffer_Unlock(IDirect3DIndexBuffer8 *iface)
 {
+    IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface);
+
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    wined3d_buffer_unmap(((IDirect3DIndexBuffer8Impl *)iface)->wineD3DIndexBuffer);
+    wined3d_buffer_unmap(buffer->wineD3DIndexBuffer);
     wined3d_mutex_unlock();
 
     return D3D_OK;
 }
 
-static HRESULT WINAPI d3d8_indexbuffer_GetDesc(IDirect3DIndexBuffer8 *iface, D3DINDEXBUFFER_DESC *desc)
+static HRESULT WINAPI d3d8_indexbuffer_GetDesc(IDirect3DIndexBuffer8 *iface,
+        D3DINDEXBUFFER_DESC *desc)
 {
-    IDirect3DIndexBuffer8Impl *buffer = (IDirect3DIndexBuffer8Impl *)iface;
+    IDirect3DIndexBuffer8Impl *buffer = impl_from_IDirect3DIndexBuffer8(iface);
     struct wined3d_resource_desc wined3d_desc;
     struct wined3d_resource *wined3d_resource;
 
@@ -485,7 +539,7 @@ static HRESULT WINAPI d3d8_indexbuffer_GetDesc(IDirect3DIndexBuffer8 *iface, D3D
 
     desc->Format = d3dformat_from_wined3dformat(buffer->format);
     desc->Type = D3DRTYPE_INDEXBUFFER;
-    desc->Usage = wined3d_desc.usage;
+    desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
     desc->Pool = wined3d_desc.pool;
     desc->Size = wined3d_desc.size;
 
@@ -528,13 +582,13 @@ HRESULT indexbuffer_init(IDirect3DIndexBuffer8Impl *buffer, IDirect3DDevice8Impl
 {
     HRESULT hr;
 
-    buffer->lpVtbl = &d3d8_indexbuffer_vtbl;
+    buffer->IDirect3DIndexBuffer8_iface.lpVtbl = &d3d8_indexbuffer_vtbl;
     buffer->ref = 1;
     buffer->format = wined3dformat_from_d3dformat(format);
 
     wined3d_mutex_lock();
     hr = wined3d_buffer_create_ib(device->wined3d_device, size, usage & WINED3DUSAGE_MASK,
-            (WINED3DPOOL)pool, buffer, &d3d8_indexbuffer_wined3d_parent_ops, &buffer->wineD3DIndexBuffer);
+            (enum wined3d_pool)pool, buffer, &d3d8_indexbuffer_wined3d_parent_ops, &buffer->wineD3DIndexBuffer);
     wined3d_mutex_unlock();
     if (FAILED(hr))
     {
@@ -547,3 +601,12 @@ HRESULT indexbuffer_init(IDirect3DIndexBuffer8Impl *buffer, IDirect3DDevice8Impl
 
     return D3D_OK;
 }
+
+IDirect3DIndexBuffer8Impl *unsafe_impl_from_IDirect3DIndexBuffer8(IDirect3DIndexBuffer8 *iface)
+{
+    if (!iface)
+        return NULL;
+    assert(iface->lpVtbl == &d3d8_indexbuffer_vtbl);
+
+    return impl_from_IDirect3DIndexBuffer8(iface);
+}
index 5915c54..f092f35 100644 (file)
@@ -97,7 +97,7 @@ static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetDevice(IDirect3DCubeTexture8
 
     TRACE("iface %p, device %p.\n", iface, device);
 
-    *device = (IDirect3DDevice8 *)This->parentDevice;
+    *device = This->parentDevice;
     IDirect3DDevice8_AddRef(*device);
 
     TRACE("Returning device %p.\n", *device);
@@ -109,13 +109,15 @@ static HRESULT WINAPI IDirect3DCubeTexture8Impl_SetPrivateData(IDirect3DCubeText
         REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
 {
     IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
             iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_set_private_data(This->wined3d_texture, refguid, pData, SizeOfData, Flags);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -125,13 +127,15 @@ static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetPrivateData(IDirect3DCubeText
         REFGUID refguid, void *pData, DWORD *pSizeOfData)
 {
     IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
             iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_get_private_data(This->wined3d_texture, refguid, pData, pSizeOfData);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData);
     wined3d_mutex_unlock();
 
     return hr;
@@ -141,12 +145,14 @@ static HRESULT WINAPI IDirect3DCubeTexture8Impl_FreePrivateData(IDirect3DCubeTex
         REFGUID refguid)
 {
     IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_free_private_data(This->wined3d_texture, refguid);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_free_private_data(resource, refguid);
     wined3d_mutex_unlock();
 
     return hr;
@@ -194,16 +200,9 @@ static void WINAPI IDirect3DCubeTexture8Impl_PreLoad(IDirect3DCubeTexture8 *ifac
 
 static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture8Impl_GetType(IDirect3DCubeTexture8 *iface)
 {
-    IDirect3DCubeTexture8Impl *This = impl_from_IDirect3DCubeTexture8(iface);
-    D3DRESOURCETYPE type;
-
     TRACE("iface %p.\n", iface);
 
-    wined3d_mutex_lock();
-    type = wined3d_texture_get_type(This->wined3d_texture);
-    wined3d_mutex_unlock();
-
-    return type;
+    return D3DRTYPE_CUBETEXTURE;
 }
 
 /* IDirect3DCubeTexture8 IDirect3DBaseTexture8 Interface follow: */
@@ -269,7 +268,7 @@ static HRESULT WINAPI IDirect3DCubeTexture8Impl_GetLevelDesc(IDirect3DCubeTextur
         wined3d_resource_get_desc(sub_resource, &wined3d_desc);
         desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
         desc->Type = wined3d_desc.resource_type;
-        desc->Usage = wined3d_desc.usage;
+        desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
         desc->Pool = wined3d_desc.pool;
         desc->Size = wined3d_desc.size;
         desc->MultiSampleType = wined3d_desc.multisample_type;
@@ -364,14 +363,14 @@ static HRESULT WINAPI IDirect3DCubeTexture8Impl_AddDirtyRect(IDirect3DCubeTextur
         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, NULL);
     else
     {
-        WINED3DBOX dirty_region;
-
-        dirty_region.Left = dirty_rect->left;
-        dirty_region.Top = dirty_rect->top;
-        dirty_region.Right = dirty_rect->right;
-        dirty_region.Bottom = dirty_rect->bottom;
-        dirty_region.Front = 0;
-        dirty_region.Back = 1;
+        struct wined3d_box dirty_region;
+
+        dirty_region.left = dirty_rect->left;
+        dirty_region.top = dirty_rect->top;
+        dirty_region.right = dirty_rect->right;
+        dirty_region.bottom = dirty_rect->bottom;
+        dirty_region.front = 0;
+        dirty_region.back = 1;
         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, &dirty_region);
     }
     wined3d_mutex_unlock();
index 7a25a93..7e7da43 100644 (file)
@@ -45,7 +45,7 @@ IDirect3D8* WINAPI DECLSPEC_HOTPATCH Direct3DCreate8(UINT SDKVersion) {
 
     object->IDirect3D8_iface.lpVtbl = &Direct3D8_Vtbl;
     object->ref = 1;
-    object->WineD3D = wined3d_create(8, &object->IDirect3D8_iface);
+    object->WineD3D = wined3d_create(8, WINED3D_LEGACY_DEPTH_BIAS, &object->IDirect3D8_iface);
 
     TRACE("Created Direct3D object @ %p, WineObj @ %p\n", object, object->WineD3D);
 
index 914dec5..c47d05a 100644 (file)
@@ -177,7 +177,8 @@ struct IDirect3DDevice8Impl
     IDirect3DDevice8        IDirect3DDevice8_iface;
     struct wined3d_device_parent device_parent;
     LONG                    ref;
-    struct wined3d_device *wined3d_device;
+    struct wined3d_device  *wined3d_device;
+    IDirect3D8             *d3d_parent;
     struct                  d3d8_handle_table handle_table;
 
     /* FVF management */
@@ -189,7 +190,7 @@ struct IDirect3DDevice8Impl
     BOOL lost;
 };
 
-HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT adapter,
+HRESULT device_init(IDirect3DDevice8Impl *device, IDirect3D8Impl *parent, struct wined3d *wined3d, UINT adapter,
         D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters) DECLSPEC_HIDDEN;
 
 /* ---------------- */
@@ -209,7 +210,7 @@ struct IDirect3DVolume8Impl
 };
 
 HRESULT volume_init(IDirect3DVolume8Impl *volume, IDirect3DDevice8Impl *device, UINT width, UINT height,
-        UINT depth, DWORD usage, enum wined3d_format_id format, WINED3DPOOL pool) DECLSPEC_HIDDEN;
+        UINT depth, DWORD usage, enum wined3d_format_id format, enum wined3d_pool pool) DECLSPEC_HIDDEN;
 
 /* ------------------- */
 /* IDirect3DSwapChain8 */
@@ -239,9 +240,8 @@ HRESULT swapchain_init(IDirect3DSwapChain8Impl *swapchain, IDirect3DDevice8Impl
  */
 struct IDirect3DSurface8Impl
 {
-    /* IUnknown fields */
-    const IDirect3DSurface8Vtbl *lpVtbl;
-    LONG                         ref;
+    IDirect3DSurface8 IDirect3DSurface8_iface;
+    LONG ref;
     struct wined3d_surface *wined3d_surface;
     IDirect3DDevice8 *parentDevice;
 
@@ -255,6 +255,7 @@ struct IDirect3DSurface8Impl
 HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *device,
         UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
         DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality) DECLSPEC_HIDDEN;
+IDirect3DSurface8Impl *unsafe_impl_from_IDirect3DSurface8(IDirect3DSurface8 *iface) DECLSPEC_HIDDEN;
 
 /* ---------------------- */
 /* IDirect3DVertexBuffer8 */
@@ -265,10 +266,8 @@ HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *devic
  */
 struct IDirect3DVertexBuffer8Impl
 {
-    /* IUnknown fields */
-    const IDirect3DVertexBuffer8Vtbl *lpVtbl;
-    LONG                              ref;
-
+    IDirect3DVertexBuffer8 IDirect3DVertexBuffer8_iface;
+    LONG ref;
     struct wined3d_buffer *wineD3DVertexBuffer;
     IDirect3DDevice8 *parentDevice;
     DWORD fvf;
@@ -276,6 +275,7 @@ struct IDirect3DVertexBuffer8Impl
 
 HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
         UINT size, DWORD usage, DWORD fvf, D3DPOOL pool) DECLSPEC_HIDDEN;
+IDirect3DVertexBuffer8Impl *unsafe_impl_from_IDirect3DVertexBuffer8(IDirect3DVertexBuffer8 *iface) DECLSPEC_HIDDEN;
 
 /* --------------------- */
 /* IDirect3DIndexBuffer8 */
@@ -286,10 +286,8 @@ HRESULT vertexbuffer_init(IDirect3DVertexBuffer8Impl *buffer, IDirect3DDevice8Im
  */
 struct IDirect3DIndexBuffer8Impl
 {
-    /* IUnknown fields */
-    const IDirect3DIndexBuffer8Vtbl *lpVtbl;
-    LONG                             ref;
-
+    IDirect3DIndexBuffer8 IDirect3DIndexBuffer8_iface;
+    LONG ref;
     struct wined3d_buffer *wineD3DIndexBuffer;
     IDirect3DDevice8 *parentDevice;
     enum wined3d_format_id format;
@@ -297,6 +295,7 @@ struct IDirect3DIndexBuffer8Impl
 
 HRESULT indexbuffer_init(IDirect3DIndexBuffer8Impl *buffer, IDirect3DDevice8Impl *device,
         UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
+IDirect3DIndexBuffer8Impl *unsafe_impl_from_IDirect3DIndexBuffer8(IDirect3DIndexBuffer8 *iface) DECLSPEC_HIDDEN;
 
 /* --------------------- */
 /* IDirect3DBaseTexture8 */
index aa85c61..91942e1 100644 (file)
@@ -301,6 +301,7 @@ static ULONG WINAPI IDirect3DDevice8Impl_Release(IDirect3DDevice8 *iface)
 
     if (ref == 0) {
         unsigned i;
+        IDirect3D8 *parent = This->d3d_parent;
 
         TRACE("Releasing wined3d device %p.\n", This->wined3d_device);
 
@@ -320,6 +321,8 @@ static ULONG WINAPI IDirect3DDevice8Impl_Release(IDirect3DDevice8 *iface)
         HeapFree(GetProcessHeap(), 0, This);
 
         wined3d_mutex_unlock();
+
+        IDirect3D8_Release(parent);
     }
     return ref;
 }
@@ -358,23 +361,20 @@ static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(IDirect3D
         DWORD Bytes)
 {
     IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
-    HRESULT hr;
 
     TRACE("iface %p, byte_count %u.\n", iface, Bytes);
-    FIXME("Byte count ignored.\n");
+    if (Bytes) FIXME("Byte count ignored.\n");
 
     wined3d_mutex_lock();
-    hr = wined3d_device_evict_managed_resources(This->wined3d_device);
+    wined3d_device_evict_managed_resources(This->wined3d_device);
     wined3d_mutex_unlock();
 
-    return hr;
+    return D3D_OK;
 }
 
 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(IDirect3DDevice8 *iface, IDirect3D8 **ppD3D8)
 {
     IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
-    struct wined3d *wined3d;
-    HRESULT hr;
 
     TRACE("iface %p, d3d8 %p.\n", iface, ppD3D8);
 
@@ -382,24 +382,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(IDirect3DDevice8 *iface,
         return D3DERR_INVALIDCALL;
     }
 
-    wined3d_mutex_lock();
-    hr = wined3d_device_get_wined3d(This->wined3d_device, &wined3d);
-    if (SUCCEEDED(hr) && wined3d)
-    {
-        *ppD3D8 = wined3d_get_parent(wined3d);
-        IDirect3D8_AddRef(*ppD3D8);
-        wined3d_decref(wined3d);
-    }
-    else
-    {
-        FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
-        *ppD3D8 = NULL;
-    }
-    wined3d_mutex_unlock();
-
-    TRACE("(%p) returning %p\n",This , *ppD3D8);
-
-    return hr;
+    return IDirect3D8_QueryInterface(This->d3d_parent, &IID_IDirect3D8, (void **)ppD3D8);
 }
 
 static HRESULT WINAPI IDirect3DDevice8Impl_GetDeviceCaps(IDirect3DDevice8 *iface, D3DCAPS8 *pCaps)
@@ -439,7 +422,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetDisplayMode(IDirect3DDevice8 *ifac
     TRACE("iface %p, mode %p.\n", iface, pMode);
 
     wined3d_mutex_lock();
-    hr = wined3d_device_get_display_mode(This->wined3d_device, 0, (WINED3DDISPLAYMODE *)pMode);
+    hr = wined3d_device_get_display_mode(This->wined3d_device, 0, (struct wined3d_display_mode *)pMode);
     wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -457,7 +440,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetCreationParameters(IDirect3DDevice
 
     wined3d_mutex_lock();
     hr = wined3d_device_get_creation_parameters(This->wined3d_device,
-            (WINED3DDEVICE_CREATION_PARAMETERS *)pParameters);
+            (struct wined3d_device_creation_parameters *)pParameters);
     wined3d_mutex_unlock();
 
     return hr;
@@ -467,7 +450,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetCursorProperties(IDirect3DDevice8
         UINT XHotSpot, UINT YHotSpot, IDirect3DSurface8 *pCursorBitmap)
 {
     IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
-    IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl*)pCursorBitmap;
+    IDirect3DSurface8Impl *pSurface = unsafe_impl_from_IDirect3DSurface8(pCursorBitmap);
     HRESULT hr;
 
     TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
@@ -544,21 +527,19 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(IDirect3DDe
     return D3D_OK;
 }
 
-static HRESULT WINAPI reset_enum_callback(struct wined3d_resource *resource, void *data)
+static HRESULT CDECL reset_enum_callback(struct wined3d_resource *resource)
 {
     struct wined3d_resource_desc desc;
-    BOOL *resources_ok = data;
 
     wined3d_resource_get_desc(resource, &desc);
-    if (desc.pool == WINED3DPOOL_DEFAULT)
+    if (desc.pool == WINED3D_POOL_DEFAULT)
     {
         IDirect3DSurface8 *surface;
 
-        if (desc.resource_type != WINED3DRTYPE_SURFACE)
+        if (desc.resource_type != WINED3D_RTYPE_SURFACE)
         {
             WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource);
-            *resources_ok = FALSE;
-            return S_FALSE;
+            return D3DERR_DEVICELOST;
         }
 
         surface = wined3d_resource_get_parent(resource);
@@ -567,68 +548,46 @@ static HRESULT WINAPI reset_enum_callback(struct wined3d_resource *resource, voi
         if (IDirect3DSurface8_Release(surface))
         {
             WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface, resource);
-            *resources_ok = FALSE;
-            return S_FALSE;
+            return D3DERR_DEVICELOST;
         }
 
         WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface, resource);
     }
 
-    return S_OK;
+    return D3D_OK;
 }
 
 static HRESULT WINAPI IDirect3DDevice8Impl_Reset(IDirect3DDevice8 *iface,
         D3DPRESENT_PARAMETERS *pPresentationParameters)
 {
     IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
-    WINED3DPRESENT_PARAMETERS localParameters;
-    BOOL resources_ok = TRUE;
+    struct wined3d_swapchain_desc swapchain_desc;
     HRESULT hr;
-    UINT i;
 
     TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
 
     wined3d_mutex_lock();
-    wined3d_device_set_index_buffer(This->wined3d_device, NULL, WINED3DFMT_UNKNOWN);
-    for (i = 0; i < 16; ++i)
-    {
-        wined3d_device_set_stream_source(This->wined3d_device, i, NULL, 0, 0);
-    }
-    for (i = 0; i < 16; ++i)
-    {
-        wined3d_device_set_texture(This->wined3d_device, i, NULL);
-    }
-
-    wined3d_device_enum_resources(This->wined3d_device, reset_enum_callback, &resources_ok);
-    if (!resources_ok)
-    {
-        WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset.\n");
-        This->lost = TRUE;
-        wined3d_mutex_unlock();
 
-        return D3DERR_DEVICELOST;
-    }
-
-    localParameters.BackBufferWidth                             = pPresentationParameters->BackBufferWidth;
-    localParameters.BackBufferHeight                            = pPresentationParameters->BackBufferHeight;
-    localParameters.BackBufferFormat                            = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
-    localParameters.BackBufferCount                             = pPresentationParameters->BackBufferCount;
-    localParameters.MultiSampleType                             = pPresentationParameters->MultiSampleType;
-    localParameters.MultiSampleQuality                          = 0; /* d3d9 only */
-    localParameters.SwapEffect                                  = pPresentationParameters->SwapEffect;
-    localParameters.hDeviceWindow                               = pPresentationParameters->hDeviceWindow;
-    localParameters.Windowed                                    = pPresentationParameters->Windowed;
-    localParameters.EnableAutoDepthStencil                      = pPresentationParameters->EnableAutoDepthStencil;
-    localParameters.AutoDepthStencilFormat                      = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
-    localParameters.Flags                                       = pPresentationParameters->Flags;
-    localParameters.FullScreen_RefreshRateInHz                  = pPresentationParameters->FullScreen_RefreshRateInHz;
-    localParameters.PresentationInterval                        = pPresentationParameters->FullScreen_PresentationInterval;
-    localParameters.AutoRestoreDisplayMode                      = TRUE;
-
-    hr = wined3d_device_reset(This->wined3d_device, &localParameters);
+    swapchain_desc.backbuffer_width = pPresentationParameters->BackBufferWidth;
+    swapchain_desc.backbuffer_height = pPresentationParameters->BackBufferHeight;
+    swapchain_desc.backbuffer_format = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
+    swapchain_desc.backbuffer_count = pPresentationParameters->BackBufferCount;
+    swapchain_desc.multisample_type = pPresentationParameters->MultiSampleType;
+    swapchain_desc.multisample_quality = 0; /* d3d9 only */
+    swapchain_desc.swap_effect = pPresentationParameters->SwapEffect;
+    swapchain_desc.device_window = pPresentationParameters->hDeviceWindow;
+    swapchain_desc.windowed = pPresentationParameters->Windowed;
+    swapchain_desc.enable_auto_depth_stencil = pPresentationParameters->EnableAutoDepthStencil;
+    swapchain_desc.auto_depth_stencil_format = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
+    swapchain_desc.flags = pPresentationParameters->Flags;
+    swapchain_desc.refresh_rate = pPresentationParameters->FullScreen_RefreshRateInHz;
+    swapchain_desc.swap_interval = pPresentationParameters->FullScreen_PresentationInterval;
+    swapchain_desc.auto_restore_display_mode = TRUE;
+
+    hr = wined3d_device_reset(This->wined3d_device, &swapchain_desc, reset_enum_callback);
     if (SUCCEEDED(hr))
     {
-        hr = wined3d_device_set_render_state(This->wined3d_device, WINED3DRS_POINTSIZE_MIN, 0);
+        hr = wined3d_device_set_render_state(This->wined3d_device, WINED3D_RS_POINTSIZE_MIN, 0);
         This->lost = FALSE;
     }
     else
@@ -637,20 +596,6 @@ static HRESULT WINAPI IDirect3DDevice8Impl_Reset(IDirect3DDevice8 *iface,
     }
     wined3d_mutex_unlock();
 
-    pPresentationParameters->BackBufferWidth                    = localParameters.BackBufferWidth;
-    pPresentationParameters->BackBufferHeight                   = localParameters.BackBufferHeight;
-    pPresentationParameters->BackBufferFormat                   = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
-    pPresentationParameters->BackBufferCount                    = localParameters.BackBufferCount;
-    pPresentationParameters->MultiSampleType                    = localParameters.MultiSampleType;
-    pPresentationParameters->SwapEffect                         = localParameters.SwapEffect;
-    pPresentationParameters->hDeviceWindow                      = localParameters.hDeviceWindow;
-    pPresentationParameters->Windowed                           = localParameters.Windowed;
-    pPresentationParameters->EnableAutoDepthStencil             = localParameters.EnableAutoDepthStencil;
-    pPresentationParameters->AutoDepthStencilFormat             = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
-    pPresentationParameters->Flags                              = localParameters.Flags;
-    pPresentationParameters->FullScreen_RefreshRateInHz         = localParameters.FullScreen_RefreshRateInHz;
-    pPresentationParameters->FullScreen_PresentationInterval    = localParameters.PresentationInterval;
-
     return hr;
 }
 
@@ -682,7 +627,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetBackBuffer(IDirect3DDevice8 *iface
 
     wined3d_mutex_lock();
     hr = wined3d_device_get_back_buffer(This->wined3d_device, 0,
-            BackBuffer, (WINED3DBACKBUFFER_TYPE)Type, &wined3d_surface);
+            BackBuffer, (enum wined3d_backbuffer_type)Type, &wined3d_surface);
     if (SUCCEEDED(hr) && wined3d_surface && ppBackBuffer)
     {
         *ppBackBuffer = wined3d_surface_get_parent(wined3d_surface);
@@ -703,7 +648,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetRasterStatus(IDirect3DDevice8 *ifa
     TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus);
 
     wined3d_mutex_lock();
-    hr = wined3d_device_get_raster_status(This->wined3d_device, 0, (WINED3DRASTER_STATUS *)pRasterStatus);
+    hr = wined3d_device_get_raster_status(This->wined3d_device, 0, (struct wined3d_raster_status *)pRasterStatus);
     wined3d_mutex_unlock();
 
     return hr;
@@ -716,9 +661,9 @@ static void WINAPI IDirect3DDevice8Impl_SetGammaRamp(IDirect3DDevice8 *iface, DW
 
     TRACE("iface %p, flags %#x, ramp %p.\n", iface, Flags, pRamp);
 
-    /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
+    /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
     wined3d_mutex_lock();
-    wined3d_device_set_gamma_ramp(This->wined3d_device, 0, Flags, (const WINED3DGAMMARAMP *)pRamp);
+    wined3d_device_set_gamma_ramp(This->wined3d_device, 0, Flags, (const struct wined3d_gamma_ramp *)pRamp);
     wined3d_mutex_unlock();
 }
 
@@ -728,9 +673,9 @@ static void WINAPI IDirect3DDevice8Impl_GetGammaRamp(IDirect3DDevice8 *iface, D3
 
     TRACE("iface %p, ramp %p.\n", iface, pRamp);
 
-    /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
+    /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
     wined3d_mutex_lock();
-    wined3d_device_get_gamma_ramp(This->wined3d_device, 0, (WINED3DGAMMARAMP *)pRamp);
+    wined3d_device_get_gamma_ramp(This->wined3d_device, 0, (struct wined3d_gamma_ramp *)pRamp);
     wined3d_mutex_unlock();
 }
 
@@ -855,7 +800,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateVertexBuffer(IDirect3DDevice8 *
     }
 
     TRACE("Created vertex buffer %p.\n", object);
-    *buffer = (IDirect3DVertexBuffer8 *)object;
+    *buffer = &object->IDirect3DVertexBuffer8_iface;
 
     return D3D_OK;
 }
@@ -886,7 +831,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateIndexBuffer(IDirect3DDevice8 *i
     }
 
     TRACE("Created index buffer %p.\n", object);
-    *buffer = (IDirect3DIndexBuffer8 *)object;
+    *buffer = &object->IDirect3DIndexBuffer8_iface;
 
     return D3D_OK;
 }
@@ -921,7 +866,7 @@ static HRESULT IDirect3DDevice8Impl_CreateSurface(IDirect3DDevice8Impl *device,
     }
 
     TRACE("Created surface %p.\n", object);
-    *ppSurface = (IDirect3DSurface8 *)object;
+    *ppSurface = &object->IDirect3DSurface8_iface;
 
     return D3D_OK;
 }
@@ -981,22 +926,26 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(IDirect3DDevice8 *iface,
         IDirect3DSurface8 *pSourceSurface, const RECT *pSourceRects, UINT cRects,
         IDirect3DSurface8 *pDestinationSurface, const POINT *pDestPoints)
 {
-    IDirect3DSurface8Impl *Source = (IDirect3DSurface8Impl *) pSourceSurface;
-    IDirect3DSurface8Impl *Dest = (IDirect3DSurface8Impl *) pDestinationSurface;
+    IDirect3DSurface8Impl *Source = unsafe_impl_from_IDirect3DSurface8(pSourceSurface);
+    IDirect3DSurface8Impl *Dest = unsafe_impl_from_IDirect3DSurface8(pDestinationSurface);
     enum wined3d_format_id srcFormat, destFormat;
     struct wined3d_resource_desc wined3d_desc;
     struct wined3d_resource *wined3d_resource;
+    UINT src_w, src_h;
+    HRESULT hr;
 
     TRACE("iface %p, src_surface %p, src_rects %p, rect_count %u, dst_surface %p, dst_points %p.\n",
             iface, pSourceSurface, pSourceRects, cRects, pDestinationSurface, pDestPoints);
 
-    /* Check that the source texture is in WINED3DPOOL_SYSTEMMEM and the
-     * destination texture is in WINED3DPOOL_DEFAULT. */
+    /* Check that the source texture is in WINED3D_POOL_SYSTEM_MEM and the
+     * destination texture is in WINED3D_POOL_DEFAULT. */
 
     wined3d_mutex_lock();
     wined3d_resource = wined3d_surface_get_resource(Source->wined3d_surface);
     wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
     srcFormat = wined3d_desc.format;
+    src_w = wined3d_desc.width;
+    src_h = wined3d_desc.height;
 
     wined3d_resource = wined3d_surface_get_resource(Dest->wined3d_surface);
     wined3d_resource_get_desc(wined3d_resource, &wined3d_desc);
@@ -1013,14 +962,21 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(IDirect3DDevice8 *iface,
     else if (WINED3DFMT_UNKNOWN == destFormat)
     {
         TRACE("(%p) : Converting destination surface from WINED3DFMT_UNKNOWN to the source format\n", iface);
-        wined3d_surface_set_format(Dest->wined3d_surface, srcFormat);
+        if (FAILED(hr = wined3d_surface_update_desc(Dest->wined3d_surface, wined3d_desc.width, wined3d_desc.height,
+                srcFormat, wined3d_desc.multisample_type, wined3d_desc.multisample_quality)))
+        {
+            WARN("Failed to update surface desc, hr %#x.\n", hr);
+            wined3d_mutex_unlock();
+            return hr;
+        }
     }
 
     /* Quick if complete copy ... */
     if (!cRects && !pSourceRects && !pDestPoints)
     {
-        wined3d_surface_bltfast(Dest->wined3d_surface, 0, 0,
-                Source->wined3d_surface, NULL, WINEDDBLTFAST_NOCOLORKEY);
+        RECT rect = {0, 0, src_w, src_h};
+        wined3d_surface_blt(Dest->wined3d_surface, &rect,
+                Source->wined3d_surface, &rect, 0, NULL, WINED3D_TEXF_POINT);
     }
     else
     {
@@ -1030,16 +986,25 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CopyRects(IDirect3DDevice8 *iface,
         {
             for (i = 0; i < cRects; ++i)
             {
-                wined3d_surface_bltfast(Dest->wined3d_surface, pDestPoints[i].x, pDestPoints[i].y,
-                        Source->wined3d_surface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
+                UINT w = pSourceRects[i].right - pSourceRects[i].left;
+                UINT h = pSourceRects[i].bottom - pSourceRects[i].top;
+                RECT dst_rect = {pDestPoints[i].x, pDestPoints[i].y,
+                        pDestPoints[i].x + w, pDestPoints[i].y + h};
+
+                wined3d_surface_blt(Dest->wined3d_surface, &dst_rect,
+                        Source->wined3d_surface, &pSourceRects[i], 0, NULL, WINED3D_TEXF_POINT);
             }
         }
         else
         {
             for (i = 0; i < cRects; ++i)
             {
-                wined3d_surface_bltfast(Dest->wined3d_surface, 0, 0,
-                        Source->wined3d_surface, &pSourceRects[i], WINEDDBLTFAST_NOCOLORKEY);
+                UINT w = pSourceRects[i].right - pSourceRects[i].left;
+                UINT h = pSourceRects[i].bottom - pSourceRects[i].top;
+                RECT dst_rect = {0, 0, w, h};
+
+                wined3d_surface_blt(Dest->wined3d_surface, &dst_rect,
+                        Source->wined3d_surface, &pSourceRects[i], 0, NULL, WINED3D_TEXF_POINT);
             }
         }
     }
@@ -1069,7 +1034,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetFrontBuffer(IDirect3DDevice8 *ifac
         IDirect3DSurface8 *pDestSurface)
 {
     IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
-    IDirect3DSurface8Impl *destSurface = (IDirect3DSurface8Impl *)pDestSurface;
+    IDirect3DSurface8Impl *destSurface = unsafe_impl_from_IDirect3DSurface8(pDestSurface);
     HRESULT hr;
 
     TRACE("iface %p, dst_surface %p.\n", iface, pDestSurface);
@@ -1090,8 +1055,8 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(IDirect3DDevice8 *ifa
         IDirect3DSurface8 *pRenderTarget, IDirect3DSurface8 *pNewZStencil)
 {
     IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
-    IDirect3DSurface8Impl *pSurface = (IDirect3DSurface8Impl *)pRenderTarget;
-    IDirect3DSurface8Impl *pZSurface = (IDirect3DSurface8Impl *)pNewZStencil;
+    IDirect3DSurface8Impl *pSurface = unsafe_impl_from_IDirect3DSurface8(pRenderTarget);
+    IDirect3DSurface8Impl *pZSurface = unsafe_impl_from_IDirect3DSurface8(pNewZStencil);
     struct wined3d_surface *original_ds = NULL;
     HRESULT hr;
 
@@ -1103,25 +1068,26 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderTarget(IDirect3DDevice8 *ifa
     {
         struct wined3d_resource_desc ds_desc, rt_desc;
         struct wined3d_resource *wined3d_resource;
-        IDirect3DSurface8 *orig_rt = NULL;
+        struct wined3d_surface *original_rt = NULL;
 
         /* If no render target is passed in check the size against the current RT */
         if (!pRenderTarget)
         {
-            hr = IDirect3DDevice8_GetRenderTarget(iface, &orig_rt);
-            if (FAILED(hr))
+            hr = wined3d_device_get_render_target(This->wined3d_device, 0, &original_rt);
+            if (FAILED(hr) || !original_rt)
             {
                 wined3d_mutex_unlock();
                 return hr;
             }
-            pSurface = (IDirect3DSurface8Impl *)orig_rt;
+            wined3d_resource = wined3d_surface_get_resource(original_rt);
+            wined3d_surface_decref(original_rt);
         }
+        else
+            wined3d_resource = wined3d_surface_get_resource(pSurface->wined3d_surface);
+        wined3d_resource_get_desc(wined3d_resource, &rt_desc);
 
         wined3d_resource = wined3d_surface_get_resource(pZSurface->wined3d_surface);
         wined3d_resource_get_desc(wined3d_resource, &ds_desc);
-        wined3d_resource = wined3d_surface_get_resource(pSurface->wined3d_surface);
-        wined3d_resource_get_desc(wined3d_resource, &rt_desc);
-        if (orig_rt) IDirect3DSurface8_Release(orig_rt);
 
         if (ds_desc.width < rt_desc.width || ds_desc.height < rt_desc.height)
         {
@@ -1241,17 +1207,24 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice8Impl_EndScene(IDirect3DD
     return hr;
 }
 
-static HRESULT WINAPI IDirect3DDevice8Impl_Clear(IDirect3DDevice8 *iface, DWORD Count,
-        const D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil)
+static HRESULT WINAPI IDirect3DDevice8Impl_Clear(IDirect3DDevice8 *iface, DWORD rect_count,
+        const D3DRECT *rects, DWORD flags, D3DCOLOR color, float z, DWORD stencil)
 {
+    const struct wined3d_color c =
+    {
+        ((color >> 16) & 0xff) / 255.0f,
+        ((color >>  8) & 0xff) / 255.0f,
+        (color & 0xff) / 255.0f,
+        ((color >> 24) & 0xff) / 255.0f,
+    };
     IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
     HRESULT hr;
 
     TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
-            iface, Count, pRects, Flags, Color, Z, Stencil);
+            iface, rect_count, rects, flags, color, z, stencil);
 
     wined3d_mutex_lock();
-    hr = wined3d_device_clear(This->wined3d_device, Count, (const RECT *)pRects, Flags, Color, Z, Stencil);
+    hr = wined3d_device_clear(This->wined3d_device, rect_count, (const RECT *)rects, flags, &c, z, stencil);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1265,9 +1238,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetTransform(IDirect3DDevice8 *iface,
 
     TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
 
-    /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
+    /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
     wined3d_mutex_lock();
-    hr = wined3d_device_set_transform(This->wined3d_device, State, (const WINED3DMATRIX *)lpMatrix);
+    hr = wined3d_device_set_transform(This->wined3d_device, State, (const struct wined3d_matrix *)lpMatrix);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1281,9 +1254,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetTransform(IDirect3DDevice8 *iface,
 
     TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
 
-    /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
+    /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
     wined3d_mutex_lock();
-    hr = wined3d_device_get_transform(This->wined3d_device, State, (WINED3DMATRIX *)pMatrix);
+    hr = wined3d_device_get_transform(This->wined3d_device, State, (struct wined3d_matrix *)pMatrix);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1297,9 +1270,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_MultiplyTransform(IDirect3DDevice8 *i
 
     TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
 
-    /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
+    /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
     wined3d_mutex_lock();
-    hr = wined3d_device_multiply_transform(This->wined3d_device, State, (const WINED3DMATRIX *)pMatrix);
+    hr = wined3d_device_multiply_transform(This->wined3d_device, State, (const struct wined3d_matrix *)pMatrix);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1313,9 +1286,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetViewport(IDirect3DDevice8 *iface,
 
     TRACE("iface %p, viewport %p.\n", iface, pViewport);
 
-    /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
+    /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */
     wined3d_mutex_lock();
-    hr = wined3d_device_set_viewport(This->wined3d_device, (const WINED3DVIEWPORT *)pViewport);
+    hr = wined3d_device_set_viewport(This->wined3d_device, (const struct wined3d_viewport *)pViewport);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1329,9 +1302,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetViewport(IDirect3DDevice8 *iface,
 
     TRACE("iface %p, viewport %p.\n", iface, pViewport);
 
-    /* Note: D3DVIEWPORT8 is compatible with WINED3DVIEWPORT */
+    /* Note: D3DVIEWPORT8 is compatible with struct wined3d_viewport. */
     wined3d_mutex_lock();
-    hr = wined3d_device_get_viewport(This->wined3d_device, (WINED3DVIEWPORT *)pViewport);
+    hr = wined3d_device_get_viewport(This->wined3d_device, (struct wined3d_viewport *)pViewport);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1345,9 +1318,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetMaterial(IDirect3DDevice8 *iface,
 
     TRACE("iface %p, material %p.\n", iface, pMaterial);
 
-    /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
+    /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
     wined3d_mutex_lock();
-    hr = wined3d_device_set_material(This->wined3d_device, (const WINED3DMATERIAL *)pMaterial);
+    hr = wined3d_device_set_material(This->wined3d_device, (const struct wined3d_material *)pMaterial);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1361,9 +1334,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetMaterial(IDirect3DDevice8 *iface,
 
     TRACE("iface %p, material %p.\n", iface, pMaterial);
 
-    /* Note: D3DMATERIAL8 is compatible with WINED3DMATERIAL */
+    /* Note: D3DMATERIAL8 is compatible with struct wined3d_material. */
     wined3d_mutex_lock();
-    hr = wined3d_device_get_material(This->wined3d_device, (WINED3DMATERIAL *)pMaterial);
+    hr = wined3d_device_get_material(This->wined3d_device, (struct wined3d_material *)pMaterial);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1377,9 +1350,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetLight(IDirect3DDevice8 *iface, DWO
 
     TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
 
-    /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
+    /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
     wined3d_mutex_lock();
-    hr = wined3d_device_set_light(This->wined3d_device, Index, (const WINED3DLIGHT *)pLight);
+    hr = wined3d_device_set_light(This->wined3d_device, Index, (const struct wined3d_light *)pLight);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1393,9 +1366,9 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetLight(IDirect3DDevice8 *iface, DWO
 
     TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
 
-    /* Note: D3DLIGHT8 is compatible with WINED3DLIGHT */
+    /* Note: D3DLIGHT8 is compatible with struct wined3d_light. */
     wined3d_mutex_lock();
-    hr = wined3d_device_get_light(This->wined3d_device, Index, (WINED3DLIGHT *)pLight);
+    hr = wined3d_device_get_light(This->wined3d_device, Index, (struct wined3d_light *)pLight);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1461,22 +1434,11 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetClipPlane(IDirect3DDevice8 *iface,
     return hr;
 }
 
-/* This factor is the result of a trial-and-error search. Both ZBIAS and DEPTHBIAS require
- * guesswork by design. d3d9 apps usually use a DEPTHBIAS of -0.00002(Mass Effect 2, WoW).
- * d3d8 apps(Final Fantasy XI) set ZBIAS to 15 and still expect the depth test to sort
- * objects properly. */
-static const float zbias_factor = -0.000005f;
-
 static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(IDirect3DDevice8 *iface,
         D3DRENDERSTATETYPE State, DWORD Value)
 {
     IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
     HRESULT hr;
-    union
-    {
-        DWORD d;
-        float f;
-    } wined3d_value;
 
     TRACE("iface %p, state %#x, value %#x.\n", iface, State, Value);
 
@@ -1484,8 +1446,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetRenderState(IDirect3DDevice8 *ifac
     switch (State)
     {
         case D3DRS_ZBIAS:
-            wined3d_value.f = Value * zbias_factor;
-            hr = wined3d_device_set_render_state(This->wined3d_device, WINED3DRS_DEPTHBIAS, wined3d_value.d);
+            hr = wined3d_device_set_render_state(This->wined3d_device, WINED3D_RS_DEPTHBIAS, Value);
             break;
 
         default:
@@ -1501,11 +1462,6 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(IDirect3DDevice8 *ifac
 {
     IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
     HRESULT hr;
-    union
-    {
-        DWORD d;
-        float f;
-    } wined3d_value;
 
     TRACE("iface %p, state %#x, value %p.\n", iface, State, pValue);
 
@@ -1513,8 +1469,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetRenderState(IDirect3DDevice8 *ifac
     switch (State)
     {
         case D3DRS_ZBIAS:
-            hr = wined3d_device_get_render_state(This->wined3d_device, WINED3DRS_DEPTHBIAS, &wined3d_value.d);
-            if (SUCCEEDED(hr)) *pValue = (DWORD)(wined3d_value.f / zbias_factor);
+            hr = wined3d_device_get_render_state(This->wined3d_device, WINED3D_RS_DEPTHBIAS, pValue);
             break;
 
         default:
@@ -1667,7 +1622,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_CreateStateBlock(IDirect3DDevice8 *if
     }
 
     wined3d_mutex_lock();
-    hr = wined3d_stateblock_create(This->wined3d_device, (WINED3DSTATEBLOCKTYPE)Type, &stateblock);
+    hr = wined3d_stateblock_create(This->wined3d_device, (enum wined3d_stateblock_type)Type, &stateblock);
     if (FAILED(hr))
     {
         wined3d_mutex_unlock();
@@ -1700,10 +1655,10 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetClipStatus(IDirect3DDevice8 *iface
     HRESULT hr;
 
     TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
-/* FIXME: Verify that D3DCLIPSTATUS8 ~= WINED3DCLIPSTATUS */
+    /* FIXME: Verify that D3DCLIPSTATUS8 ~= struct wined3d_clip_status. */
 
     wined3d_mutex_lock();
-    hr = wined3d_device_set_clip_status(This->wined3d_device, (const WINED3DCLIPSTATUS *)pClipStatus);
+    hr = wined3d_device_set_clip_status(This->wined3d_device, (const struct wined3d_clip_status *)pClipStatus);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1718,7 +1673,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetClipStatus(IDirect3DDevice8 *iface
     TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
 
     wined3d_mutex_lock();
-    hr = wined3d_device_get_clip_status(This->wined3d_device, (WINED3DCLIPSTATUS *)pClipStatus);
+    hr = wined3d_device_get_clip_status(This->wined3d_device, (struct wined3d_clip_status *)pClipStatus);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1781,39 +1736,39 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetTexture(IDirect3DDevice8 *iface, D
 static const struct tss_lookup
 {
     BOOL sampler_state;
-    DWORD state;
+    enum wined3d_texture_stage_state state;
 }
 tss_lookup[] =
 {
-    {FALSE, WINED3DTSS_FORCE_DWORD},            /*  0, unused */
-    {FALSE, WINED3DTSS_COLOROP},                /*  1, D3DTSS_COLOROP */
-    {FALSE, WINED3DTSS_COLORARG1},              /*  2, D3DTSS_COLORARG1 */
-    {FALSE, WINED3DTSS_COLORARG2},              /*  3, D3DTSS_COLORARG2 */
-    {FALSE, WINED3DTSS_ALPHAOP},                /*  4, D3DTSS_ALPHAOP */
-    {FALSE, WINED3DTSS_ALPHAARG1},              /*  5, D3DTSS_ALPHAARG1 */
-    {FALSE, WINED3DTSS_ALPHAARG2},              /*  6, D3DTSS_ALPHAARG2 */
-    {FALSE, WINED3DTSS_BUMPENVMAT00},           /*  7, D3DTSS_BUMPENVMAT00 */
-    {FALSE, WINED3DTSS_BUMPENVMAT01},           /*  8, D3DTSS_BUMPENVMAT01 */
-    {FALSE, WINED3DTSS_BUMPENVMAT10},           /*  9, D3DTSS_BUMPENVMAT10 */
-    {FALSE, WINED3DTSS_BUMPENVMAT11},           /* 10, D3DTSS_BUMPENVMAT11 */
-    {FALSE, WINED3DTSS_TEXCOORDINDEX},          /* 11, D3DTSS_TEXCOORDINDEX */
-    {FALSE, WINED3DTSS_FORCE_DWORD},            /* 12, unused */
-    {TRUE,  WINED3DSAMP_ADDRESSU},              /* 13, D3DTSS_ADDRESSU */
-    {TRUE,  WINED3DSAMP_ADDRESSV},              /* 14, D3DTSS_ADDRESSV */
-    {TRUE,  WINED3DSAMP_BORDERCOLOR},           /* 15, D3DTSS_BORDERCOLOR */
-    {TRUE,  WINED3DSAMP_MAGFILTER},             /* 16, D3DTSS_MAGFILTER */
-    {TRUE,  WINED3DSAMP_MINFILTER},             /* 17, D3DTSS_MINFILTER */
-    {TRUE,  WINED3DSAMP_MIPFILTER},             /* 18, D3DTSS_MIPFILTER */
-    {TRUE,  WINED3DSAMP_MIPMAPLODBIAS},         /* 19, D3DTSS_MIPMAPLODBIAS */
-    {TRUE,  WINED3DSAMP_MAXMIPLEVEL},           /* 20, D3DTSS_MAXMIPLEVEL */
-    {TRUE,  WINED3DSAMP_MAXANISOTROPY},         /* 21, D3DTSS_MAXANISOTROPY */
-    {FALSE, WINED3DTSS_BUMPENVLSCALE},          /* 22, D3DTSS_BUMPENVLSCALE */
-    {FALSE, WINED3DTSS_BUMPENVLOFFSET},         /* 23, D3DTSS_BUMPENVLOFFSET */
-    {FALSE, WINED3DTSS_TEXTURETRANSFORMFLAGS},  /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
-    {TRUE,  WINED3DSAMP_ADDRESSW},              /* 25, D3DTSS_ADDRESSW */
-    {FALSE, WINED3DTSS_COLORARG0},              /* 26, D3DTSS_COLORARG0 */
-    {FALSE, WINED3DTSS_ALPHAARG0},              /* 27, D3DTSS_ALPHAARG0 */
-    {FALSE, WINED3DTSS_RESULTARG},              /* 28, D3DTSS_RESULTARG */
+    {FALSE, WINED3D_TSS_INVALID},                   /*  0, unused */
+    {FALSE, WINED3D_TSS_COLOR_OP},                  /*  1, D3DTSS_COLOROP */
+    {FALSE, WINED3D_TSS_COLOR_ARG1},                /*  2, D3DTSS_COLORARG1 */
+    {FALSE, WINED3D_TSS_COLOR_ARG2},                /*  3, D3DTSS_COLORARG2 */
+    {FALSE, WINED3D_TSS_ALPHA_OP},                  /*  4, D3DTSS_ALPHAOP */
+    {FALSE, WINED3D_TSS_ALPHA_ARG1},                /*  5, D3DTSS_ALPHAARG1 */
+    {FALSE, WINED3D_TSS_ALPHA_ARG2},                /*  6, D3DTSS_ALPHAARG2 */
+    {FALSE, WINED3D_TSS_BUMPENV_MAT00},             /*  7, D3DTSS_BUMPENVMAT00 */
+    {FALSE, WINED3D_TSS_BUMPENV_MAT01},             /*  8, D3DTSS_BUMPENVMAT01 */
+    {FALSE, WINED3D_TSS_BUMPENV_MAT10},             /*  9, D3DTSS_BUMPENVMAT10 */
+    {FALSE, WINED3D_TSS_BUMPENV_MAT11},             /* 10, D3DTSS_BUMPENVMAT11 */
+    {FALSE, WINED3D_TSS_TEXCOORD_INDEX},            /* 11, D3DTSS_TEXCOORDINDEX */
+    {FALSE, WINED3D_TSS_INVALID},                   /* 12, unused */
+    {TRUE,  WINED3D_SAMP_ADDRESS_U},                /* 13, D3DTSS_ADDRESSU */
+    {TRUE,  WINED3D_SAMP_ADDRESS_V},                /* 14, D3DTSS_ADDRESSV */
+    {TRUE,  WINED3D_SAMP_BORDER_COLOR},             /* 15, D3DTSS_BORDERCOLOR */
+    {TRUE,  WINED3D_SAMP_MAG_FILTER},               /* 16, D3DTSS_MAGFILTER */
+    {TRUE,  WINED3D_SAMP_MIN_FILTER},               /* 17, D3DTSS_MINFILTER */
+    {TRUE,  WINED3D_SAMP_MIP_FILTER},               /* 18, D3DTSS_MIPFILTER */
+    {TRUE,  WINED3D_SAMP_MIPMAP_LOD_BIAS},          /* 19, D3DTSS_MIPMAPLODBIAS */
+    {TRUE,  WINED3D_SAMP_MAX_MIP_LEVEL},            /* 20, D3DTSS_MAXMIPLEVEL */
+    {TRUE,  WINED3D_SAMP_MAX_ANISOTROPY},           /* 21, D3DTSS_MAXANISOTROPY */
+    {FALSE, WINED3D_TSS_BUMPENV_LSCALE},            /* 22, D3DTSS_BUMPENVLSCALE */
+    {FALSE, WINED3D_TSS_BUMPENV_LOFFSET},           /* 23, D3DTSS_BUMPENVLOFFSET */
+    {FALSE, WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS},   /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
+    {TRUE,  WINED3D_SAMP_ADDRESS_W},                /* 25, D3DTSS_ADDRESSW */
+    {FALSE, WINED3D_TSS_COLOR_ARG0},                /* 26, D3DTSS_COLORARG0 */
+    {FALSE, WINED3D_TSS_ALPHA_ARG0},                /* 27, D3DTSS_ALPHAARG0 */
+    {FALSE, WINED3D_TSS_RESULT_ARG},                /* 28, D3DTSS_RESULTARG */
 };
 
 static HRESULT  WINAPI  IDirect3DDevice8Impl_GetTextureStageState(IDirect3DDevice8 *iface,
@@ -1896,61 +1851,36 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetInfo(IDirect3DDevice8 *iface,
 static HRESULT WINAPI IDirect3DDevice8Impl_SetPaletteEntries(IDirect3DDevice8 *iface,
         UINT PaletteNumber, const PALETTEENTRY *pEntries)
 {
-    IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
-    HRESULT hr;
+    FIXME("iface %p, palette_idx %u, entries %p unimplemented\n", iface, PaletteNumber, pEntries);
 
-    TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
+    /* GPUs stopped supporting palettized textures with the Shader Model 1 generation. Wined3d
+     * does not have a d3d8/9-style palette API */
 
-    wined3d_mutex_lock();
-    hr = wined3d_device_set_palette_entries(This->wined3d_device, PaletteNumber, pEntries);
-    wined3d_mutex_unlock();
-
-    return hr;
+    return D3DERR_INVALIDCALL;
 }
 
 static HRESULT WINAPI IDirect3DDevice8Impl_GetPaletteEntries(IDirect3DDevice8 *iface,
         UINT PaletteNumber, PALETTEENTRY *pEntries)
 {
-    IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
-    HRESULT hr;
-
-    TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
+    FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface, PaletteNumber, pEntries);
 
-    wined3d_mutex_lock();
-    hr = wined3d_device_get_palette_entries(This->wined3d_device, PaletteNumber, pEntries);
-    wined3d_mutex_unlock();
-
-    return hr;
+    return D3DERR_INVALIDCALL;
 }
 
 static HRESULT WINAPI IDirect3DDevice8Impl_SetCurrentTexturePalette(IDirect3DDevice8 *iface,
         UINT PaletteNumber)
 {
-    IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
-    HRESULT hr;
+    FIXME("iface %p, palette_idx %u unimplemented.\n", iface, PaletteNumber);
 
-    TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
-
-    wined3d_mutex_lock();
-    hr = wined3d_device_set_current_texture_palette(This->wined3d_device, PaletteNumber);
-    wined3d_mutex_unlock();
-
-    return hr;
+    return D3DERR_INVALIDCALL;
 }
 
 static HRESULT  WINAPI  IDirect3DDevice8Impl_GetCurrentTexturePalette(IDirect3DDevice8 *iface,
         UINT *PaletteNumber)
 {
-    IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
-    HRESULT hr;
-
-    TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
-
-    wined3d_mutex_lock();
-    hr = wined3d_device_get_current_texture_palette(This->wined3d_device, PaletteNumber);
-    wined3d_mutex_unlock();
+    FIXME("iface %p, palette_idx %p unimplemented.\n", iface, PaletteNumber);
 
-    return hr;
+    return D3DERR_INVALIDCALL;
 }
 
 static HRESULT WINAPI IDirect3DDevice8Impl_DrawPrimitive(IDirect3DDevice8 *iface,
@@ -2038,8 +1968,8 @@ static HRESULT WINAPI IDirect3DDevice8Impl_ProcessVertices(IDirect3DDevice8 *ifa
         DWORD Flags)
 {
     IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
+    IDirect3DVertexBuffer8Impl *dest = unsafe_impl_from_IDirect3DVertexBuffer8(pDestBuffer);
     HRESULT hr;
-    IDirect3DVertexBuffer8Impl *dest = (IDirect3DVertexBuffer8Impl *) pDestBuffer;
 
     TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, flags %#x.\n",
             iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, Flags);
@@ -2400,8 +2330,8 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetIndices(IDirect3DDevice8 *iface,
         IDirect3DIndexBuffer8 *pIndexData, UINT baseVertexIndex)
 {
     IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
+    IDirect3DIndexBuffer8Impl *ib = unsafe_impl_from_IDirect3DIndexBuffer8(pIndexData);
     HRESULT hr;
-    IDirect3DIndexBuffer8Impl *ib = (IDirect3DIndexBuffer8Impl *)pIndexData;
 
     TRACE("iface %p, buffer %p, base_vertex_idx %u.\n", iface, pIndexData, baseVertexIndex);
 
@@ -2675,7 +2605,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_DrawRectPatch(IDirect3DDevice8 *iface
 
     wined3d_mutex_lock();
     hr = wined3d_device_draw_rect_patch(This->wined3d_device, Handle,
-            pNumSegs, (const WINED3DRECTPATCH_INFO *)pRectPatchInfo);
+            pNumSegs, (const struct wined3d_rect_patch_info *)pRectPatchInfo);
     wined3d_mutex_unlock();
 
     return hr;
@@ -2692,7 +2622,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_DrawTriPatch(IDirect3DDevice8 *iface,
 
     wined3d_mutex_lock();
     hr = wined3d_device_draw_tri_patch(This->wined3d_device, Handle,
-            pNumSegs, (const WINED3DTRIPATCH_INFO *)pTriPatchInfo);
+            pNumSegs, (const struct wined3d_tri_patch_info *)pTriPatchInfo);
     wined3d_mutex_unlock();
 
     return hr;
@@ -2716,6 +2646,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(IDirect3DDevice8 *ifa
         UINT StreamNumber, IDirect3DVertexBuffer8 *pStreamData, UINT Stride)
 {
     IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
+    IDirect3DVertexBuffer8Impl *streamdata = unsafe_impl_from_IDirect3DVertexBuffer8(pStreamData);
     HRESULT hr;
 
     TRACE("iface %p, stream_idx %u, buffer %p, stride %u.\n",
@@ -2723,8 +2654,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_SetStreamSource(IDirect3DDevice8 *ifa
 
     wined3d_mutex_lock();
     hr = wined3d_device_set_stream_source(This->wined3d_device, StreamNumber,
-            pStreamData ? ((IDirect3DVertexBuffer8Impl *)pStreamData)->wineD3DVertexBuffer : NULL,
-            0/* Offset in bytes */, Stride);
+            streamdata ? streamdata->wineD3DVertexBuffer : NULL, 0/* Offset in bytes */, Stride);
     wined3d_mutex_unlock();
 
     return hr;
@@ -2875,9 +2805,14 @@ static void CDECL device_parent_wined3d_device_created(struct wined3d_device_par
     TRACE("device_parent %p, device %p\n", device_parent, device);
 }
 
+static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
+{
+    TRACE("device_parent %p.\n", device_parent);
+}
+
 static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent *device_parent,
         void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
-        WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, struct wined3d_surface **surface)
+        enum wined3d_pool pool, UINT level, enum wined3d_cubemap_face face, struct wined3d_surface **surface)
 {
     IDirect3DDevice8Impl *device = device_from_device_parent(device_parent);
     IDirect3DSurface8Impl *d3d_surface;
@@ -2889,7 +2824,8 @@ static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent *
             device_parent, container_parent, width, height, format, usage, pool, level, face, surface);
 
 
-    if (pool == WINED3DPOOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC)) lockable = FALSE;
+    if (pool == WINED3D_POOL_DEFAULT && !(usage & WINED3DUSAGE_DYNAMIC))
+        lockable = FALSE;
 
     hr = IDirect3DDevice8Impl_CreateSurface(device, width, height,
             d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
@@ -2907,7 +2843,7 @@ static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent *
     IUnknown_Release(d3d_surface->parentDevice);
     d3d_surface->parentDevice = NULL;
 
-    IDirect3DSurface8_Release((IDirect3DSurface8 *)d3d_surface);
+    IDirect3DSurface8_Release(&d3d_surface->IDirect3DSurface8_iface);
     d3d_surface->forwardReference = container_parent;
 
     return hr;
@@ -2915,7 +2851,7 @@ static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent *
 
 static HRESULT CDECL device_parent_create_rendertarget(struct wined3d_device_parent *device_parent,
         void *container_parent, UINT width, UINT height, enum wined3d_format_id format,
-        WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable,
+        enum wined3d_multisample_type multisample_type, DWORD multisample_quality, BOOL lockable,
         struct wined3d_surface **surface)
 {
     IDirect3DDevice8Impl *device = device_from_device_parent(device_parent);
@@ -2940,13 +2876,13 @@ static HRESULT CDECL device_parent_create_rendertarget(struct wined3d_device_par
 
     d3d_surface->container = (IUnknown *)&device->IDirect3DDevice8_iface;
     /* Implicit surfaces are created with an refcount of 0 */
-    IUnknown_Release((IUnknown *)d3d_surface);
+    IDirect3DSurface8_Release(&d3d_surface->IDirect3DSurface8_iface);
 
     return hr;
 }
 
 static HRESULT CDECL device_parent_create_depth_stencil(struct wined3d_device_parent *device_parent,
-        UINT width, UINT height, enum wined3d_format_id format, WINED3DMULTISAMPLE_TYPE multisample_type,
+        UINT width, UINT height, enum wined3d_format_id format, enum wined3d_multisample_type multisample_type,
         DWORD multisample_quality, BOOL discard, struct wined3d_surface **surface)
 {
     IDirect3DDevice8Impl *device = device_from_device_parent(device_parent);
@@ -2970,14 +2906,14 @@ static HRESULT CDECL device_parent_create_depth_stencil(struct wined3d_device_pa
 
     d3d_surface->container = (IUnknown *)&device->IDirect3DDevice8_iface;
     /* Implicit surfaces are created with an refcount of 0 */
-    IUnknown_Release((IUnknown *)d3d_surface);
+    IDirect3DSurface8_Release(&d3d_surface->IDirect3DSurface8_iface);
 
     return hr;
 }
 
 static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *device_parent,
         void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
-        WINED3DPOOL pool, DWORD usage, struct wined3d_volume **volume)
+        enum wined3d_pool pool, DWORD usage, struct wined3d_volume **volume)
 {
     IDirect3DDevice8Impl *device = device_from_device_parent(device_parent);
     IDirect3DVolume8Impl *object;
@@ -3018,29 +2954,29 @@ static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *d
 }
 
 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
-        WINED3DPRESENT_PARAMETERS *present_parameters, struct wined3d_swapchain **swapchain)
+        struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
 {
     IDirect3DDevice8Impl *device = device_from_device_parent(device_parent);
     D3DPRESENT_PARAMETERS local_parameters;
     IDirect3DSwapChain8 *d3d_swapchain;
     HRESULT hr;
 
-    TRACE("device_parent %p, present_parameters %p, swapchain %p.\n", device_parent, present_parameters, swapchain);
+    TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
 
     /* Copy the presentation parameters */
-    local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
-    local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
-    local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
-    local_parameters.BackBufferCount = present_parameters->BackBufferCount;
-    local_parameters.MultiSampleType = present_parameters->MultiSampleType;
-    local_parameters.SwapEffect = present_parameters->SwapEffect;
-    local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
-    local_parameters.Windowed = present_parameters->Windowed;
-    local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
-    local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
-    local_parameters.Flags = present_parameters->Flags;
-    local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
-    local_parameters.FullScreen_PresentationInterval = present_parameters->PresentationInterval;
+    local_parameters.BackBufferWidth = desc->backbuffer_width;
+    local_parameters.BackBufferHeight = desc->backbuffer_height;
+    local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(desc->backbuffer_format);
+    local_parameters.BackBufferCount = desc->backbuffer_count;
+    local_parameters.MultiSampleType = desc->multisample_type;
+    local_parameters.SwapEffect = desc->swap_effect;
+    local_parameters.hDeviceWindow = desc->device_window;
+    local_parameters.Windowed = desc->windowed;
+    local_parameters.EnableAutoDepthStencil = desc->enable_auto_depth_stencil;
+    local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(desc->auto_depth_stencil_format);
+    local_parameters.Flags = desc->flags;
+    local_parameters.FullScreen_RefreshRateInHz = desc->refresh_rate;
+    local_parameters.FullScreen_PresentationInterval = desc->swap_interval;
 
     hr = IDirect3DDevice8_CreateAdditionalSwapChain(&device->IDirect3DDevice8_iface,
             &local_parameters, &d3d_swapchain);
@@ -3056,19 +2992,19 @@ static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent
     IDirect3DSwapChain8_Release(d3d_swapchain);
 
     /* Copy back the presentation parameters */
-    present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
-    present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
-    present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
-    present_parameters->BackBufferCount = local_parameters.BackBufferCount;
-    present_parameters->MultiSampleType = local_parameters.MultiSampleType;
-    present_parameters->SwapEffect = local_parameters.SwapEffect;
-    present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
-    present_parameters->Windowed = local_parameters.Windowed;
-    present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
-    present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
-    present_parameters->Flags = local_parameters.Flags;
-    present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
-    present_parameters->PresentationInterval = local_parameters.FullScreen_PresentationInterval;
+    desc->backbuffer_width = local_parameters.BackBufferWidth;
+    desc->backbuffer_height = local_parameters.BackBufferHeight;
+    desc->backbuffer_format = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
+    desc->backbuffer_count = local_parameters.BackBufferCount;
+    desc->multisample_type = local_parameters.MultiSampleType;
+    desc->swap_effect = local_parameters.SwapEffect;
+    desc->device_window = local_parameters.hDeviceWindow;
+    desc->windowed = local_parameters.Windowed;
+    desc->enable_auto_depth_stencil = local_parameters.EnableAutoDepthStencil;
+    desc->auto_depth_stencil_format = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
+    desc->flags = local_parameters.Flags;
+    desc->refresh_rate = local_parameters.FullScreen_RefreshRateInHz;
+    desc->swap_interval = local_parameters.FullScreen_PresentationInterval;
 
     return hr;
 }
@@ -3076,6 +3012,7 @@ static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent
 static const struct wined3d_device_parent_ops d3d8_wined3d_device_parent_ops =
 {
     device_parent_wined3d_device_created,
+    device_parent_mode_changed,
     device_parent_create_surface,
     device_parent_create_rendertarget,
     device_parent_create_depth_stencil,
@@ -3090,15 +3027,20 @@ static void setup_fpu(void)
     __asm__ volatile ("fnstcw %0" : "=m" (cw));
     cw = (cw & ~0xf3f) | 0x3f;
     __asm__ volatile ("fldcw %0" : : "m" (cw));
+#elif defined(__i386__) && defined(_MSC_VER)
+    WORD cw;
+    __asm fnstcw cw;
+    cw = (cw & ~0xf3f) | 0x3f;
+    __asm fldcw cw;
 #else
     FIXME("FPU setup not implemented for this platform.\n");
 #endif
 }
 
-HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT adapter,
+HRESULT device_init(IDirect3DDevice8Impl *device, IDirect3D8Impl *parent, struct wined3d *wined3d, UINT adapter,
         D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
 {
-    WINED3DPRESENT_PARAMETERS wined3d_parameters;
+    struct wined3d_swapchain_desc swapchain_desc;
     HRESULT hr;
 
     device->IDirect3DDevice8_iface.lpVtbl = &Direct3DDevice8_Vtbl;
@@ -3116,7 +3058,7 @@ HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT
     if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
 
     wined3d_mutex_lock();
-    hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags,
+    hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags, 4,
             &device->device_parent, &device->wined3d_device);
     if (FAILED(hr))
     {
@@ -3151,23 +3093,23 @@ HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT
     if (flags & D3DCREATE_MULTITHREADED)
         wined3d_device_set_multithreaded(device->wined3d_device);
 
-    wined3d_parameters.BackBufferWidth = parameters->BackBufferWidth;
-    wined3d_parameters.BackBufferHeight = parameters->BackBufferHeight;
-    wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(parameters->BackBufferFormat);
-    wined3d_parameters.BackBufferCount = parameters->BackBufferCount;
-    wined3d_parameters.MultiSampleType = parameters->MultiSampleType;
-    wined3d_parameters.MultiSampleQuality = 0; /* d3d9 only */
-    wined3d_parameters.SwapEffect = parameters->SwapEffect;
-    wined3d_parameters.hDeviceWindow = parameters->hDeviceWindow;
-    wined3d_parameters.Windowed = parameters->Windowed;
-    wined3d_parameters.EnableAutoDepthStencil = parameters->EnableAutoDepthStencil;
-    wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(parameters->AutoDepthStencilFormat);
-    wined3d_parameters.Flags = parameters->Flags;
-    wined3d_parameters.FullScreen_RefreshRateInHz = parameters->FullScreen_RefreshRateInHz;
-    wined3d_parameters.PresentationInterval = parameters->FullScreen_PresentationInterval;
-    wined3d_parameters.AutoRestoreDisplayMode = TRUE;
-
-    hr = wined3d_device_init_3d(device->wined3d_device, &wined3d_parameters);
+    swapchain_desc.backbuffer_width = parameters->BackBufferWidth;
+    swapchain_desc.backbuffer_height = parameters->BackBufferHeight;
+    swapchain_desc.backbuffer_format = wined3dformat_from_d3dformat(parameters->BackBufferFormat);
+    swapchain_desc.backbuffer_count = parameters->BackBufferCount;
+    swapchain_desc.multisample_type = parameters->MultiSampleType;
+    swapchain_desc.multisample_quality = 0; /* d3d9 only */
+    swapchain_desc.swap_effect = parameters->SwapEffect;
+    swapchain_desc.device_window = parameters->hDeviceWindow;
+    swapchain_desc.windowed = parameters->Windowed;
+    swapchain_desc.enable_auto_depth_stencil = parameters->EnableAutoDepthStencil;
+    swapchain_desc.auto_depth_stencil_format = wined3dformat_from_d3dformat(parameters->AutoDepthStencilFormat);
+    swapchain_desc.flags = parameters->Flags;
+    swapchain_desc.refresh_rate = parameters->FullScreen_RefreshRateInHz;
+    swapchain_desc.swap_interval = parameters->FullScreen_PresentationInterval;
+    swapchain_desc.auto_restore_display_mode = TRUE;
+
+    hr = wined3d_device_init_3d(device->wined3d_device, &swapchain_desc);
     if (FAILED(hr))
     {
         WARN("Failed to initialize 3D, hr %#x.\n", hr);
@@ -3178,7 +3120,7 @@ HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT
         return hr;
     }
 
-    hr = wined3d_device_set_render_state(device->wined3d_device, WINED3DRS_POINTSIZE_MIN, 0);
+    hr = wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_POINTSIZE_MIN, 0);
     wined3d_mutex_unlock();
     if (FAILED(hr))
     {
@@ -3186,29 +3128,32 @@ HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT
         goto err;
     }
 
-    parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
-    parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
-    parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
-    parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
-    parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
-    parameters->SwapEffect = wined3d_parameters.SwapEffect;
-    parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
-    parameters->Windowed = wined3d_parameters.Windowed;
-    parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
-    parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
-    parameters->Flags = wined3d_parameters.Flags;
-    parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
-    parameters->FullScreen_PresentationInterval = wined3d_parameters.PresentationInterval;
+    parameters->BackBufferWidth = swapchain_desc.backbuffer_width;
+    parameters->BackBufferHeight = swapchain_desc.backbuffer_height;
+    parameters->BackBufferFormat = d3dformat_from_wined3dformat(swapchain_desc.backbuffer_format);
+    parameters->BackBufferCount = swapchain_desc.backbuffer_count;
+    parameters->MultiSampleType = swapchain_desc.multisample_type;
+    parameters->SwapEffect = swapchain_desc.swap_effect;
+    parameters->hDeviceWindow = swapchain_desc.device_window;
+    parameters->Windowed = swapchain_desc.windowed;
+    parameters->EnableAutoDepthStencil = swapchain_desc.enable_auto_depth_stencil;
+    parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(swapchain_desc.auto_depth_stencil_format);
+    parameters->Flags = swapchain_desc.flags;
+    parameters->FullScreen_RefreshRateInHz = swapchain_desc.refresh_rate;
+    parameters->FullScreen_PresentationInterval = swapchain_desc.swap_interval;
 
     device->declArraySize = 16;
     device->decls = HeapAlloc(GetProcessHeap(), 0, device->declArraySize * sizeof(*device->decls));
     if (!device->decls)
     {
-        ERR("Failed to allocate FVF vertex delcaration map memory.\n");
+        ERR("Failed to allocate FVF vertex declaration map memory.\n");
         hr = E_OUTOFMEMORY;
         goto err;
     }
 
+    device->d3d_parent = &parent->IDirect3D8_iface;
+    IDirect3D8_AddRef(device->d3d_parent);
+
     return D3D_OK;
 
 err:
index 249399e..0bb3b01 100644 (file)
@@ -123,7 +123,7 @@ static HRESULT WINAPI IDirect3D8Impl_GetAdapterIdentifier(LPDIRECT3D8 iface, UIN
         DWORD Flags, D3DADAPTER_IDENTIFIER8 *pIdentifier)
 {
     IDirect3D8Impl *This = impl_from_IDirect3D8(iface);
-    WINED3DADAPTER_IDENTIFIER adapter_id;
+    struct wined3d_adapter_identifier adapter_id;
     HRESULT hr;
 
     TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
@@ -175,7 +175,8 @@ static HRESULT WINAPI IDirect3D8Impl_EnumAdapterModes(LPDIRECT3D8 iface, UINT Ad
             iface, Adapter, Mode, pMode);
 
     wined3d_mutex_lock();
-    hr = wined3d_enum_adapter_modes(This->WineD3D, Adapter, WINED3DFMT_UNKNOWN, Mode, (WINED3DDISPLAYMODE *)pMode);
+    hr = wined3d_enum_adapter_modes(This->WineD3D, Adapter, WINED3DFMT_UNKNOWN,
+            Mode, (struct wined3d_display_mode *)pMode);
     wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -193,7 +194,7 @@ static HRESULT WINAPI IDirect3D8Impl_GetAdapterDisplayMode(LPDIRECT3D8 iface, UI
             iface, Adapter, pMode);
 
     wined3d_mutex_lock();
-    hr = wined3d_get_adapter_display_mode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *)pMode);
+    hr = wined3d_get_adapter_display_mode(This->WineD3D, Adapter, (struct wined3d_display_mode *)pMode);
     wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -223,34 +224,26 @@ static HRESULT WINAPI IDirect3D8Impl_CheckDeviceFormat(LPDIRECT3D8 iface, UINT A
         D3DFORMAT CheckFormat)
 {
     IDirect3D8Impl *This = impl_from_IDirect3D8(iface);
+    enum wined3d_resource_type wined3d_rtype;
     HRESULT hr;
-    WINED3DRESOURCETYPE WineD3DRType;
 
     TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n",
             iface, Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
 
-    if(CheckFormat == D3DFMT_R8G8B8)
-    {
-        /* See comment in dlls/d3d9/directx.c, IDirect3D9Impl_CheckDeviceFormat for details */
-        WARN("D3DFMT_R8G8B8 is not available on windows, returning D3DERR_NOTAVAILABLE\n");
-        return D3DERR_NOTAVAILABLE;
-    }
-
-
     switch(RType) {
         case D3DRTYPE_VERTEXBUFFER:
         case D3DRTYPE_INDEXBUFFER:
-            WineD3DRType = WINED3DRTYPE_BUFFER;
+            wined3d_rtype = WINED3D_RTYPE_BUFFER;
             break;
 
         default:
-            WineD3DRType = RType;
+            wined3d_rtype = RType;
             break;
     }
 
     wined3d_mutex_lock();
     hr = wined3d_check_device_format(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
-            Usage, WineD3DRType, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL);
+            Usage, wined3d_rtype, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL);
     wined3d_mutex_unlock();
 
     return hr;
@@ -268,7 +261,8 @@ static HRESULT WINAPI IDirect3D8Impl_CheckDeviceMultiSampleType(IDirect3D8 *ifac
 
     wined3d_mutex_lock();
     hr = wined3d_check_device_multisample_type(This->WineD3D, Adapter, DeviceType,
-            wined3dformat_from_d3dformat(SurfaceFormat), Windowed, (WINED3DMULTISAMPLE_TYPE)MultiSampleType, NULL);
+            wined3dformat_from_d3dformat(SurfaceFormat), Windowed,
+            (enum wined3d_multisample_type)MultiSampleType, NULL);
     wined3d_mutex_unlock();
 
     return hr;
@@ -296,12 +290,14 @@ static HRESULT WINAPI IDirect3D8Impl_CheckDepthStencilMatch(IDirect3D8 *iface, U
 void fixup_caps(WINED3DCAPS *caps)
 {
     /* D3D8 doesn't support SM 2.0 or higher, so clamp to 1.x */
-    if (caps->PixelShaderVersion > D3DPS_VERSION(1,4)) {
+    if (caps->PixelShaderVersion)
         caps->PixelShaderVersion = D3DPS_VERSION(1,4);
-    }
-    if (caps->VertexShaderVersion > D3DVS_VERSION(1,1)) {
+    else
+        caps->PixelShaderVersion = D3DPS_VERSION(0,0);
+    if (caps->VertexShaderVersion)
         caps->VertexShaderVersion = D3DVS_VERSION(1,1);
-    }
+    else
+        caps->VertexShaderVersion = D3DVS_VERSION(0,0);
     caps->MaxVertexShaderConst = min(D3D8_MAX_VERTEX_SHADER_CONSTANTF, caps->MaxVertexShaderConst);
 
     caps->StencilCaps &= ~WINED3DSTENCILCAPS_TWOSIDED;
@@ -368,7 +364,7 @@ static HRESULT WINAPI IDirect3D8Impl_CreateDevice(IDirect3D8 *iface, UINT adapte
         return E_OUTOFMEMORY;
     }
 
-    hr = device_init(object, This->WineD3D, adapter, device_type, focus_window, flags, parameters);
+    hr = device_init(object, This, This->WineD3D, adapter, device_type, focus_window, flags, parameters);
     if (FAILED(hr))
     {
         WARN("Failed to initialize device, hr %#x.\n", hr);
index e04c2a2..e7a0389 100644 (file)
@@ -177,7 +177,7 @@ HRESULT vertexshader_init(IDirect3DVertexShader8Impl *shader, IDirect3DDevice8Im
 
         wined3d_mutex_lock();
         hr = wined3d_shader_create_vs(device->wined3d_device, byte_code, NULL /* output signature */,
-                shader, &d3d8_vertexshader_wined3d_parent_ops, &shader->wined3d_shader);
+                shader, &d3d8_vertexshader_wined3d_parent_ops, &shader->wined3d_shader, 1);
         wined3d_mutex_unlock();
         if (FAILED(hr))
         {
@@ -278,7 +278,7 @@ HRESULT pixelshader_init(IDirect3DPixelShader8Impl *shader, IDirect3DDevice8Impl
 
     wined3d_mutex_lock();
     hr = wined3d_shader_create_ps(device->wined3d_device, byte_code, NULL, shader,
-            &d3d8_pixelshader_wined3d_parent_ops, &shader->wined3d_shader);
+            &d3d8_pixelshader_wined3d_parent_ops, &shader->wined3d_shader, 1);
     wined3d_mutex_unlock();
     if (FAILED(hr))
     {
index 8a07244..bfeae33 100644 (file)
  */
 
 #include "config.h"
+#include <assert.h>
 #include "d3d8_private.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
 
+static inline IDirect3DSurface8Impl *impl_from_IDirect3DSurface8(IDirect3DSurface8 *iface)
+{
+    return CONTAINING_RECORD(iface, IDirect3DSurface8Impl, IDirect3DSurface8_iface);
+}
+
 /* IDirect3DSurface8 IUnknown parts follow: */
-static HRESULT WINAPI IDirect3DSurface8Impl_QueryInterface(LPDIRECT3DSURFACE8 iface, REFIID riid, LPVOID *ppobj) {
-    IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
+static HRESULT WINAPI IDirect3DSurface8Impl_QueryInterface(IDirect3DSurface8 *iface, REFIID riid,
+        void **ppobj)
+{
+    IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface);
 
     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
 
@@ -42,8 +50,9 @@ static HRESULT WINAPI IDirect3DSurface8Impl_QueryInterface(LPDIRECT3DSURFACE8 if
     return E_NOINTERFACE;
 }
 
-static ULONG WINAPI IDirect3DSurface8Impl_AddRef(LPDIRECT3DSURFACE8 iface) {
-    IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
+static ULONG WINAPI IDirect3DSurface8Impl_AddRef(IDirect3DSurface8 *iface)
+{
+    IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface);
 
     TRACE("iface %p.\n", iface);
 
@@ -69,8 +78,9 @@ static ULONG WINAPI IDirect3DSurface8Impl_AddRef(LPDIRECT3DSURFACE8 iface) {
     }
 }
 
-static ULONG WINAPI IDirect3DSurface8Impl_Release(LPDIRECT3DSURFACE8 iface) {
-    IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
+static ULONG WINAPI IDirect3DSurface8Impl_Release(IDirect3DSurface8 *iface)
+{
+    IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface);
 
     TRACE("iface %p.\n", iface);
 
@@ -100,9 +110,10 @@ static ULONG WINAPI IDirect3DSurface8Impl_Release(LPDIRECT3DSURFACE8 iface) {
 }
 
 /* IDirect3DSurface8 IDirect3DResource8 Interface follow: */
-static HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(IDirect3DSurface8 *iface, IDirect3DDevice8 **device)
+static HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(IDirect3DSurface8 *iface,
+        IDirect3DDevice8 **device)
 {
-    IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
+    IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface);
 
     TRACE("iface %p, device %p.\n", iface, device);
 
@@ -123,7 +134,7 @@ static HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(IDirect3DSurface8 *iface,
         return hr;
     }
 
-    *device = (IDirect3DDevice8 *)This->parentDevice;
+    *device = This->parentDevice;
     IDirect3DDevice8_AddRef(*device);
 
     TRACE("Returning device %p.\n", *device);
@@ -131,50 +142,63 @@ static HRESULT WINAPI IDirect3DSurface8Impl_GetDevice(IDirect3DSurface8 *iface,
     return D3D_OK;
 }
 
-static HRESULT WINAPI IDirect3DSurface8Impl_SetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, CONST void *pData, DWORD SizeOfData, DWORD Flags) {
-    IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
+static HRESULT WINAPI IDirect3DSurface8Impl_SetPrivateData(IDirect3DSurface8 *iface, REFGUID guid,
+        const void *data, DWORD data_size, DWORD flags)
+{
+    IDirect3DSurface8Impl *surface = impl_from_IDirect3DSurface8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
-            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
+            iface, debugstr_guid(guid), data, data_size, flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_surface_set_private_data(This->wined3d_surface, refguid, pData, SizeOfData, Flags);
+    resource = wined3d_surface_get_resource(surface->wined3d_surface);
+    hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
     wined3d_mutex_unlock();
 
     return hr;
 }
 
-static HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid, void *pData, DWORD *pSizeOfData) {
-    IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
+static HRESULT WINAPI IDirect3DSurface8Impl_GetPrivateData(IDirect3DSurface8 *iface, REFGUID guid,
+        void *data, DWORD *data_size)
+{
+    IDirect3DSurface8Impl *surface = impl_from_IDirect3DSurface8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
-            iface, debugstr_guid(refguid), pData, pSizeOfData);
+            iface, debugstr_guid(guid), data, data_size);
 
     wined3d_mutex_lock();
-    hr = wined3d_surface_get_private_data(This->wined3d_surface, refguid, pData, pSizeOfData);
+    resource = wined3d_surface_get_resource(surface->wined3d_surface);
+    hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
     wined3d_mutex_unlock();
 
     return hr;
 }
 
-static HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(LPDIRECT3DSURFACE8 iface, REFGUID refguid) {
-    IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
+static HRESULT WINAPI IDirect3DSurface8Impl_FreePrivateData(IDirect3DSurface8 *iface, REFGUID guid)
+{
+    IDirect3DSurface8Impl *surface = impl_from_IDirect3DSurface8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
-    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
+    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
 
     wined3d_mutex_lock();
-    hr = wined3d_surface_free_private_data(This->wined3d_surface, refguid);
+    resource = wined3d_surface_get_resource(surface->wined3d_surface);
+    hr = wined3d_resource_free_private_data(resource, guid);
     wined3d_mutex_unlock();
 
     return hr;
 }
 
 /* IDirect3DSurface8 Interface follow: */
-static HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 iface, REFIID riid, void **ppContainer) {
-    IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
+static HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(IDirect3DSurface8 *iface, REFIID riid,
+        void **ppContainer)
+{
+    IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface);
     HRESULT res;
 
     TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), ppContainer);
@@ -189,7 +213,7 @@ static HRESULT WINAPI IDirect3DSurface8Impl_GetContainer(LPDIRECT3DSURFACE8 ifac
 
 static HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(IDirect3DSurface8 *iface, D3DSURFACE_DESC *desc)
 {
-    IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
+    IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface);
     struct wined3d_resource_desc wined3d_desc;
     struct wined3d_resource *wined3d_resource;
 
@@ -202,7 +226,7 @@ static HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(IDirect3DSurface8 *iface, D3
 
     desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
     desc->Type = wined3d_desc.resource_type;
-    desc->Usage = wined3d_desc.usage;
+    desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
     desc->Pool = wined3d_desc.pool;
     desc->Size = wined3d_desc.size;
     desc->MultiSampleType = wined3d_desc.multisample_type;
@@ -212,8 +236,10 @@ static HRESULT WINAPI IDirect3DSurface8Impl_GetDesc(IDirect3DSurface8 *iface, D3
     return D3D_OK;
 }
 
-static HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, DWORD Flags) {
-    IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
+static HRESULT WINAPI IDirect3DSurface8Impl_LockRect(IDirect3DSurface8 *iface,
+        D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags)
+{
+    IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface);
     HRESULT hr;
 
     TRACE("iface %p, locked_rect %p, rect %p, flags %#x.\n", iface, pLockedRect, pRect, Flags);
@@ -236,14 +262,15 @@ static HRESULT WINAPI IDirect3DSurface8Impl_LockRect(LPDIRECT3DSURFACE8 iface, D
         }
     }
 
-    hr = wined3d_surface_map(This->wined3d_surface, (WINED3DLOCKED_RECT *)pLockedRect, pRect, Flags);
+    hr = wined3d_surface_map(This->wined3d_surface, (struct wined3d_mapped_rect *)pLockedRect, pRect, Flags);
     wined3d_mutex_unlock();
 
     return hr;
 }
 
-static HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface) {
-    IDirect3DSurface8Impl *This = (IDirect3DSurface8Impl *)iface;
+static HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(IDirect3DSurface8 *iface)
+{
+    IDirect3DSurface8Impl *This = impl_from_IDirect3DSurface8(iface);
     HRESULT hr;
 
     TRACE("iface %p.\n", iface);
@@ -291,9 +318,10 @@ HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *devic
         UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
         DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality)
 {
+    DWORD flags = 0;
     HRESULT hr;
 
-    surface->lpVtbl = &Direct3DSurface8_Vtbl;
+    surface->IDirect3DSurface8_iface.lpVtbl = &Direct3DSurface8_Vtbl;
     surface->ref = 1;
 
     /* FIXME: Check MAX bounds of MultisampleQuality. */
@@ -303,10 +331,15 @@ HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *devic
         multisample_quality = 0;
     }
 
+    if (lockable)
+        flags |= WINED3D_SURFACE_MAPPABLE;
+    if (discard)
+        flags |= WINED3D_SURFACE_DISCARD;
+
     wined3d_mutex_lock();
     hr = wined3d_surface_create(device->wined3d_device, width, height, wined3dformat_from_d3dformat(format),
-            lockable, discard, level, usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, multisample_type,
-            multisample_quality, SURFACE_OPENGL, surface, &d3d8_surface_wined3d_parent_ops, &surface->wined3d_surface);
+            level, usage & WINED3DUSAGE_MASK, (enum wined3d_pool)pool, multisample_type, multisample_quality,
+            SURFACE_OPENGL, flags, surface, &d3d8_surface_wined3d_parent_ops, &surface->wined3d_surface);
     wined3d_mutex_unlock();
     if (FAILED(hr))
     {
@@ -319,3 +352,12 @@ HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *devic
 
     return D3D_OK;
 }
+
+IDirect3DSurface8Impl *unsafe_impl_from_IDirect3DSurface8(IDirect3DSurface8 *iface)
+{
+    if (!iface)
+        return NULL;
+    assert(iface->lpVtbl == &Direct3DSurface8_Vtbl);
+
+    return impl_from_IDirect3DSurface8(iface);
+}
index 866335f..5ed5c60 100644 (file)
@@ -117,7 +117,7 @@ static HRESULT WINAPI IDirect3DSwapChain8Impl_GetBackBuffer(IDirect3DSwapChain8
 
     wined3d_mutex_lock();
     hr = wined3d_swapchain_get_back_buffer(This->wined3d_swapchain,
-            iBackBuffer, (WINED3DBACKBUFFER_TYPE)Type, &wined3d_surface);
+            iBackBuffer, (enum wined3d_backbuffer_type)Type, &wined3d_surface);
     if (SUCCEEDED(hr) && wined3d_surface)
     {
         *ppBackBuffer = wined3d_surface_get_parent(wined3d_surface);
@@ -151,47 +151,47 @@ static const struct wined3d_parent_ops d3d8_swapchain_wined3d_parent_ops =
 HRESULT swapchain_init(IDirect3DSwapChain8Impl *swapchain, IDirect3DDevice8Impl *device,
         D3DPRESENT_PARAMETERS *present_parameters)
 {
-    WINED3DPRESENT_PARAMETERS wined3d_parameters;
+    struct wined3d_swapchain_desc desc;
     HRESULT hr;
 
     swapchain->ref = 1;
     swapchain->IDirect3DSwapChain8_iface.lpVtbl = &Direct3DSwapChain8_Vtbl;
 
-    wined3d_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
-    wined3d_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
-    wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat);
-    wined3d_parameters.BackBufferCount = max(1, present_parameters->BackBufferCount);
-    wined3d_parameters.MultiSampleType = present_parameters->MultiSampleType;
-    wined3d_parameters.MultiSampleQuality = 0; /* d3d9 only */
-    wined3d_parameters.SwapEffect = present_parameters->SwapEffect;
-    wined3d_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
-    wined3d_parameters.Windowed = present_parameters->Windowed;
-    wined3d_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
-    wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat);
-    wined3d_parameters.Flags = present_parameters->Flags;
-    wined3d_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
-    wined3d_parameters.PresentationInterval = present_parameters->FullScreen_PresentationInterval;
-    wined3d_parameters.AutoRestoreDisplayMode = TRUE;
+    desc.backbuffer_width = present_parameters->BackBufferWidth;
+    desc.backbuffer_height = present_parameters->BackBufferHeight;
+    desc.backbuffer_format = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat);
+    desc.backbuffer_count = max(1, present_parameters->BackBufferCount);
+    desc.multisample_type = present_parameters->MultiSampleType;
+    desc.multisample_quality = 0; /* d3d9 only */
+    desc.swap_effect = present_parameters->SwapEffect;
+    desc.device_window = present_parameters->hDeviceWindow;
+    desc.windowed = present_parameters->Windowed;
+    desc.enable_auto_depth_stencil = present_parameters->EnableAutoDepthStencil;
+    desc.auto_depth_stencil_format = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat);
+    desc.flags = present_parameters->Flags;
+    desc.refresh_rate = present_parameters->FullScreen_RefreshRateInHz;
+    desc.swap_interval = present_parameters->FullScreen_PresentationInterval;
+    desc.auto_restore_display_mode = TRUE;
 
     wined3d_mutex_lock();
-    hr = wined3d_swapchain_create(device->wined3d_device, &wined3d_parameters,
+    hr = wined3d_swapchain_create(device->wined3d_device, &desc,
             SURFACE_OPENGL, swapchain, &d3d8_swapchain_wined3d_parent_ops,
             &swapchain->wined3d_swapchain);
     wined3d_mutex_unlock();
 
-    present_parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
-    present_parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
-    present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
-    present_parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
-    present_parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
-    present_parameters->SwapEffect = wined3d_parameters.SwapEffect;
-    present_parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
-    present_parameters->Windowed = wined3d_parameters.Windowed;
-    present_parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
-    present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
-    present_parameters->Flags = wined3d_parameters.Flags;
-    present_parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
-    present_parameters->FullScreen_PresentationInterval = wined3d_parameters.PresentationInterval;
+    present_parameters->BackBufferWidth = desc.backbuffer_width;
+    present_parameters->BackBufferHeight = desc.backbuffer_height;
+    present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(desc.backbuffer_format);
+    present_parameters->BackBufferCount = desc.backbuffer_count;
+    present_parameters->MultiSampleType = desc.multisample_type;
+    present_parameters->SwapEffect = desc.swap_effect;
+    present_parameters->hDeviceWindow = desc.device_window;
+    present_parameters->Windowed = desc.windowed;
+    present_parameters->EnableAutoDepthStencil = desc.enable_auto_depth_stencil;
+    present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(desc.auto_depth_stencil_format);
+    present_parameters->Flags = desc.flags;
+    present_parameters->FullScreen_RefreshRateInHz = desc.refresh_rate;
+    present_parameters->FullScreen_PresentationInterval = desc.swap_interval;
 
     if (FAILED(hr))
     {
index 1b9db9d..f3f2b20 100644 (file)
@@ -96,7 +96,7 @@ static HRESULT WINAPI IDirect3DTexture8Impl_GetDevice(IDirect3DTexture8 *iface,
 
     TRACE("iface %p, device %p.\n", iface, device);
 
-    *device = (IDirect3DDevice8 *)This->parentDevice;
+    *device = This->parentDevice;
     IDirect3DDevice8_AddRef(*device);
 
     TRACE("Returning device %p.\n", *device);
@@ -108,13 +108,15 @@ static HRESULT WINAPI IDirect3DTexture8Impl_SetPrivateData(IDirect3DTexture8 *if
         REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
 {
     IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
             iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_set_private_data(This->wined3d_texture, refguid, pData, SizeOfData, Flags);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -124,13 +126,15 @@ static HRESULT WINAPI IDirect3DTexture8Impl_GetPrivateData(IDirect3DTexture8 *if
         REFGUID refguid, void *pData, DWORD *pSizeOfData)
 {
     IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
             iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_get_private_data(This->wined3d_texture, refguid, pData, pSizeOfData);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData);
     wined3d_mutex_unlock();
 
     return hr;
@@ -140,12 +144,14 @@ static HRESULT WINAPI IDirect3DTexture8Impl_FreePrivateData(IDirect3DTexture8 *i
         REFGUID refguid)
 {
     IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_free_private_data(This->wined3d_texture, refguid);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_free_private_data(resource, refguid);
     wined3d_mutex_unlock();
 
     return hr;
@@ -192,16 +198,9 @@ static void WINAPI IDirect3DTexture8Impl_PreLoad(IDirect3DTexture8 *iface)
 
 static D3DRESOURCETYPE WINAPI IDirect3DTexture8Impl_GetType(IDirect3DTexture8 *iface)
 {
-    IDirect3DTexture8Impl *This = impl_from_IDirect3DTexture8(iface);
-    D3DRESOURCETYPE type;
-
     TRACE("iface %p.\n", iface);
 
-    wined3d_mutex_lock();
-    type = wined3d_texture_get_type(This->wined3d_texture);
-    wined3d_mutex_unlock();
-
-    return type;
+    return D3DRTYPE_TEXTURE;
 }
 
 /* IDirect3DTexture8 IDirect3DBaseTexture8 Interface follow: */
@@ -266,7 +265,7 @@ static HRESULT WINAPI IDirect3DTexture8Impl_GetLevelDesc(IDirect3DTexture8 *ifac
         wined3d_resource_get_desc(sub_resource, &wined3d_desc);
         desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
         desc->Type = wined3d_desc.resource_type;
-        desc->Usage = wined3d_desc.usage;
+        desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
         desc->Pool = wined3d_desc.pool;
         desc->Size = wined3d_desc.size;
         desc->MultiSampleType = wined3d_desc.multisample_type;
@@ -352,14 +351,14 @@ static HRESULT WINAPI IDirect3DTexture8Impl_AddDirtyRect(IDirect3DTexture8 *ifac
         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, NULL);
     else
     {
-        WINED3DBOX dirty_region;
-
-        dirty_region.Left = dirty_rect->left;
-        dirty_region.Top = dirty_rect->top;
-        dirty_region.Right = dirty_rect->right;
-        dirty_region.Bottom = dirty_rect->bottom;
-        dirty_region.Front = 0;
-        dirty_region.Back = 1;
+        struct wined3d_box dirty_region;
+
+        dirty_region.left = dirty_rect->left;
+        dirty_region.top = dirty_rect->top;
+        dirty_region.right = dirty_rect->right;
+        dirty_region.bottom = dirty_rect->bottom;
+        dirty_region.front = 0;
+        dirty_region.back = 1;
         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, &dirty_region);
     }
     wined3d_mutex_unlock();
index 78a59d1..7ca8783 100644 (file)
@@ -193,7 +193,7 @@ size_t parse_token(const DWORD* pToken)
 
         default:
             TRACE(" 0x%08x UNKNOWN\n", token);
-            /* argg error */
+            /* arg error */
     }
 
     return tokenlen;
@@ -303,10 +303,10 @@ static const wined3d_usage_t wined3d_usage_lookup[] = {
 
 /* TODO: find out where rhw (or positionT) is for declaration8 */
 static UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3d8_elements_size,
-        WINED3DVERTEXELEMENT **wined3d_elements)
+        struct wined3d_vertex_element **wined3d_elements)
 {
+    struct wined3d_vertex_element *element;
     const DWORD *token = d3d8_elements;
-    WINED3DVERTEXELEMENT *element;
     D3DVSD_TOKENTYPE token_type;
     unsigned int element_count = 0;
     WORD stream = 0;
@@ -315,7 +315,7 @@ static UINT convert_to_wined3d_declaration(const DWORD *d3d8_elements, DWORD *d3
     TRACE("d3d8_elements %p, wined3d_elements %p\n", d3d8_elements, wined3d_elements);
 
     /* 128 should be enough for anyone... */
-    *wined3d_elements = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 128 * sizeof(WINED3DVERTEXELEMENT));
+    *wined3d_elements = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 128 * sizeof(**wined3d_elements));
     while (D3DVSD_END() != *token)
     {
         token_type = ((*token & D3DVSD_TOKENTYPEMASK) >> D3DVSD_TOKENTYPESHIFT);
@@ -380,7 +380,7 @@ static const struct wined3d_parent_ops d3d8_vertexdeclaration_wined3d_parent_ops
 HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration8Impl *declaration,
         IDirect3DDevice8Impl *device, const DWORD *elements, DWORD shader_handle)
 {
-    WINED3DVERTEXELEMENT *wined3d_elements;
+    struct wined3d_vertex_element *wined3d_elements;
     UINT wined3d_element_count;
     HRESULT hr;
 
index 2726880..0e009ee 100644 (file)
@@ -126,13 +126,15 @@ static HRESULT WINAPI IDirect3DVolume8Impl_SetPrivateData(IDirect3DVolume8 *ifac
         const void *pData, DWORD SizeOfData, DWORD Flags)
 {
     IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
             iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_volume_set_private_data(This->wined3d_volume, refguid, pData, SizeOfData, Flags);
+    resource = wined3d_volume_get_resource(This->wined3d_volume);
+    hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -142,13 +144,15 @@ static HRESULT WINAPI IDirect3DVolume8Impl_GetPrivateData(IDirect3DVolume8 *ifac
         void *pData, DWORD *pSizeOfData)
 {
     IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
             iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
-    hr = wined3d_volume_get_private_data(This->wined3d_volume, refguid, pData, pSizeOfData);
+    resource = wined3d_volume_get_resource(This->wined3d_volume);
+    hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData);
     wined3d_mutex_unlock();
 
     return hr;
@@ -157,12 +161,14 @@ static HRESULT WINAPI IDirect3DVolume8Impl_GetPrivateData(IDirect3DVolume8 *ifac
 static HRESULT WINAPI IDirect3DVolume8Impl_FreePrivateData(IDirect3DVolume8 *iface, REFGUID refguid)
 {
     IDirect3DVolume8Impl *This = impl_from_IDirect3DVolume8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
-    hr = wined3d_volume_free_private_data(This->wined3d_volume, refguid);
+    resource = wined3d_volume_get_resource(This->wined3d_volume);
+    hr = wined3d_resource_free_private_data(resource, refguid);
     wined3d_mutex_unlock();
 
     return hr;
@@ -201,7 +207,7 @@ static HRESULT WINAPI IDirect3DVolume8Impl_GetDesc(IDirect3DVolume8 *iface, D3DV
 
     desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
     desc->Type = wined3d_desc.resource_type;
-    desc->Usage = wined3d_desc.usage;
+    desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
     desc->Pool = wined3d_desc.pool;
     desc->Size = wined3d_desc.size;
     desc->Width = wined3d_desc.width;
@@ -221,8 +227,8 @@ static HRESULT WINAPI IDirect3DVolume8Impl_LockBox(IDirect3DVolume8 *iface,
             iface, pLockedVolume, pBox, Flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_volume_map(This->wined3d_volume, (WINED3DLOCKED_BOX *)pLockedVolume,
-            (const WINED3DBOX *)pBox, Flags);
+    hr = wined3d_volume_map(This->wined3d_volume, (struct wined3d_mapped_box *)pLockedVolume,
+            (const struct wined3d_box *)pBox, Flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -270,7 +276,7 @@ static const struct wined3d_parent_ops d3d8_volume_wined3d_parent_ops =
 };
 
 HRESULT volume_init(IDirect3DVolume8Impl *volume, IDirect3DDevice8Impl *device, UINT width, UINT height,
-        UINT depth, DWORD usage, enum wined3d_format_id format, WINED3DPOOL pool)
+        UINT depth, DWORD usage, enum wined3d_format_id format, enum wined3d_pool pool)
 {
     HRESULT hr;
 
index 08e3680..a713f16 100644 (file)
@@ -95,7 +95,7 @@ static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetDevice(IDirect3DVolumeTextu
 
     TRACE("iface %p, device %p.\n", iface, device);
 
-    *device = (IDirect3DDevice8 *)This->parentDevice;
+    *device = This->parentDevice;
     IDirect3DDevice8_AddRef(*device);
 
     TRACE("Returning device %p.\n", *device);
@@ -107,13 +107,15 @@ static HRESULT WINAPI IDirect3DVolumeTexture8Impl_SetPrivateData(IDirect3DVolume
         REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
 {
     IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
             iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_set_private_data(This->wined3d_texture, refguid, pData, SizeOfData, Flags);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -123,13 +125,15 @@ static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetPrivateData(IDirect3DVolume
         REFGUID refguid, void *pData, DWORD *pSizeOfData)
 {
     IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
             iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_get_private_data(This->wined3d_texture, refguid, pData, pSizeOfData);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData);
     wined3d_mutex_unlock();
 
     return hr;
@@ -139,12 +143,14 @@ static HRESULT WINAPI IDirect3DVolumeTexture8Impl_FreePrivateData(IDirect3DVolum
         REFGUID refguid)
 {
     IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_free_private_data(This->wined3d_texture, refguid);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_free_private_data(resource, refguid);
     wined3d_mutex_unlock();
 
     return hr;
@@ -192,16 +198,9 @@ static void WINAPI IDirect3DVolumeTexture8Impl_PreLoad(IDirect3DVolumeTexture8 *
 
 static D3DRESOURCETYPE WINAPI IDirect3DVolumeTexture8Impl_GetType(IDirect3DVolumeTexture8 *iface)
 {
-    IDirect3DVolumeTexture8Impl *This = impl_from_IDirect3DVolumeTexture8(iface);
-    D3DRESOURCETYPE type;
-
     TRACE("iface %p.\n", iface);
 
-    wined3d_mutex_lock();
-    type = wined3d_texture_get_type(This->wined3d_texture);
-    wined3d_mutex_unlock();
-
-    return type;
+    return D3DRTYPE_VOLUMETEXTURE;
 }
 
 /* IDirect3DVolumeTexture8 IDirect3DBaseTexture8 Interface follow: */
@@ -266,7 +265,7 @@ static HRESULT WINAPI IDirect3DVolumeTexture8Impl_GetLevelDesc(IDirect3DVolumeTe
         wined3d_resource_get_desc(sub_resource, &wined3d_desc);
         desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
         desc->Type = wined3d_desc.resource_type;
-        desc->Usage = wined3d_desc.usage;
+        desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
         desc->Pool = wined3d_desc.pool;
         desc->Size = wined3d_desc.size;
         desc->Width = wined3d_desc.width;
@@ -349,7 +348,7 @@ static HRESULT WINAPI IDirect3DVolumeTexture8Impl_AddDirtyBox(IDirect3DVolumeTex
     TRACE("iface %p, dirty_box %p.\n", iface, dirty_box);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const WINED3DBOX *)dirty_box);
+    hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const struct wined3d_box *)dirty_box);
     wined3d_mutex_unlock();
 
     return hr;
index d9a5564..1be06a5 100644 (file)
  */
 
 #include "config.h"
+#include <assert.h>
 #include "d3d9_private.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
 
+static inline IDirect3DVertexBuffer9Impl *impl_from_IDirect3DVertexBuffer9(IDirect3DVertexBuffer9 *iface)
+{
+    return CONTAINING_RECORD(iface, IDirect3DVertexBuffer9Impl, IDirect3DVertexBuffer9_iface);
+}
+
 static HRESULT WINAPI d3d9_vertexbuffer_QueryInterface(IDirect3DVertexBuffer9 *iface, REFIID riid, void **object)
 {
     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
@@ -44,7 +50,7 @@ static HRESULT WINAPI d3d9_vertexbuffer_QueryInterface(IDirect3DVertexBuffer9 *i
 
 static ULONG WINAPI d3d9_vertexbuffer_AddRef(IDirect3DVertexBuffer9 *iface)
 {
-    IDirect3DVertexBuffer9Impl *buffer = (IDirect3DVertexBuffer9Impl *)iface;
+    IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface);
     ULONG refcount = InterlockedIncrement(&buffer->ref);
 
     TRACE("%p increasing refcount to %u.\n", iface, refcount);
@@ -62,7 +68,7 @@ static ULONG WINAPI d3d9_vertexbuffer_AddRef(IDirect3DVertexBuffer9 *iface)
 
 static ULONG WINAPI d3d9_vertexbuffer_Release(IDirect3DVertexBuffer9 *iface)
 {
-    IDirect3DVertexBuffer9Impl *buffer = (IDirect3DVertexBuffer9Impl *)iface;
+    IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface);
     ULONG refcount = InterlockedDecrement(&buffer->ref);
 
     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
@@ -82,11 +88,14 @@ static ULONG WINAPI d3d9_vertexbuffer_Release(IDirect3DVertexBuffer9 *iface)
     return refcount;
 }
 
-static HRESULT WINAPI d3d9_vertexbuffer_GetDevice(IDirect3DVertexBuffer9 *iface, IDirect3DDevice9 **device)
+static HRESULT WINAPI d3d9_vertexbuffer_GetDevice(IDirect3DVertexBuffer9 *iface,
+        IDirect3DDevice9 **device)
 {
+    IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface);
+
     TRACE("iface %p, device %p.\n", iface, device);
 
-    *device = (IDirect3DDevice9 *)((IDirect3DVertexBuffer9Impl *)iface)->parentDevice;
+    *device = (IDirect3DDevice9 *)buffer->parentDevice;
     IDirect3DDevice9_AddRef(*device);
 
     TRACE("Returning device %p.\n", *device);
@@ -97,14 +106,16 @@ static HRESULT WINAPI d3d9_vertexbuffer_GetDevice(IDirect3DVertexBuffer9 *iface,
 static HRESULT WINAPI d3d9_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer9 *iface,
         REFGUID guid, const void *data, DWORD data_size, DWORD flags)
 {
+    IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
             iface, debugstr_guid(guid), data, data_size, flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_buffer_set_private_data(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer,
-            guid, data, data_size, flags);
+    resource = wined3d_buffer_get_resource(buffer->wineD3DVertexBuffer);
+    hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -113,14 +124,16 @@ static HRESULT WINAPI d3d9_vertexbuffer_SetPrivateData(IDirect3DVertexBuffer9 *i
 static HRESULT WINAPI d3d9_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer9 *iface,
         REFGUID guid, void *data, DWORD *data_size)
 {
+    IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
             iface, debugstr_guid(guid), data, data_size);
 
     wined3d_mutex_lock();
-    hr = wined3d_buffer_get_private_data(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer,
-            guid, data, data_size);
+    resource = wined3d_buffer_get_resource(buffer->wineD3DVertexBuffer);
+    hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
     wined3d_mutex_unlock();
 
     return hr;
@@ -128,12 +141,15 @@ static HRESULT WINAPI d3d9_vertexbuffer_GetPrivateData(IDirect3DVertexBuffer9 *i
 
 static HRESULT WINAPI d3d9_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer9 *iface, REFGUID guid)
 {
+    IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
 
     wined3d_mutex_lock();
-    hr = wined3d_buffer_free_private_data(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer, guid);
+    resource = wined3d_buffer_get_resource(buffer->wineD3DVertexBuffer);
+    hr = wined3d_resource_free_private_data(resource, guid);
     wined3d_mutex_unlock();
 
     return hr;
@@ -141,12 +157,13 @@ static HRESULT WINAPI d3d9_vertexbuffer_FreePrivateData(IDirect3DVertexBuffer9 *
 
 static DWORD WINAPI d3d9_vertexbuffer_SetPriority(IDirect3DVertexBuffer9 *iface, DWORD priority)
 {
+    IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface);
     DWORD previous;
 
     TRACE("iface %p, priority %u.\n", iface, priority);
 
     wined3d_mutex_lock();
-    previous = wined3d_buffer_set_priority(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer, priority);
+    previous = wined3d_buffer_set_priority(buffer->wineD3DVertexBuffer, priority);
     wined3d_mutex_unlock();
 
     return previous;
@@ -154,12 +171,13 @@ static DWORD WINAPI d3d9_vertexbuffer_SetPriority(IDirect3DVertexBuffer9 *iface,
 
 static DWORD WINAPI d3d9_vertexbuffer_GetPriority(IDirect3DVertexBuffer9 *iface)
 {
+    IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface);
     DWORD priority;
 
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    priority = wined3d_buffer_get_priority(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer);
+    priority = wined3d_buffer_get_priority(buffer->wineD3DVertexBuffer);
     wined3d_mutex_unlock();
 
     return priority;
@@ -167,10 +185,12 @@ static DWORD WINAPI d3d9_vertexbuffer_GetPriority(IDirect3DVertexBuffer9 *iface)
 
 static void WINAPI d3d9_vertexbuffer_PreLoad(IDirect3DVertexBuffer9 *iface)
 {
+    IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface);
+
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    wined3d_buffer_preload(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer);
+    wined3d_buffer_preload(buffer->wineD3DVertexBuffer);
     wined3d_mutex_unlock();
 }
 
@@ -181,17 +201,17 @@ static D3DRESOURCETYPE WINAPI d3d9_vertexbuffer_GetType(IDirect3DVertexBuffer9 *
     return D3DRTYPE_VERTEXBUFFER;
 }
 
-static HRESULT WINAPI d3d9_vertexbuffer_Lock(IDirect3DVertexBuffer9 *iface,
-        UINT offset, UINT size, void **data, DWORD flags)
+static HRESULT WINAPI d3d9_vertexbuffer_Lock(IDirect3DVertexBuffer9 *iface, UINT offset, UINT size,
+        void **data, DWORD flags)
 {
+    IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface);
     HRESULT hr;
 
     TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
             iface, offset, size, data, flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_buffer_map(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer,
-            offset, size, (BYTE **)data, flags);
+    hr = wined3d_buffer_map(buffer->wineD3DVertexBuffer, offset, size, (BYTE **)data, flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -199,18 +219,21 @@ static HRESULT WINAPI d3d9_vertexbuffer_Lock(IDirect3DVertexBuffer9 *iface,
 
 static HRESULT WINAPI d3d9_vertexbuffer_Unlock(IDirect3DVertexBuffer9 *iface)
 {
+    IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface);
+
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    wined3d_buffer_unmap(((IDirect3DVertexBuffer9Impl *)iface)->wineD3DVertexBuffer);
+    wined3d_buffer_unmap(buffer->wineD3DVertexBuffer);
     wined3d_mutex_unlock();
 
     return D3D_OK;
 }
 
-static HRESULT WINAPI d3d9_vertexbuffer_GetDesc(IDirect3DVertexBuffer9 *iface, D3DVERTEXBUFFER_DESC *desc)
+static HRESULT WINAPI d3d9_vertexbuffer_GetDesc(IDirect3DVertexBuffer9 *iface,
+        D3DVERTEXBUFFER_DESC *desc)
 {
-    IDirect3DVertexBuffer9Impl *buffer = (IDirect3DVertexBuffer9Impl *)iface;
+    IDirect3DVertexBuffer9Impl *buffer = impl_from_IDirect3DVertexBuffer9(iface);
     struct wined3d_resource_desc wined3d_desc;
     struct wined3d_resource *wined3d_resource;
 
@@ -222,7 +245,7 @@ static HRESULT WINAPI d3d9_vertexbuffer_GetDesc(IDirect3DVertexBuffer9 *iface, D
     wined3d_mutex_unlock();
 
     desc->Format = D3DFMT_VERTEXDATA;
-    desc->Usage = wined3d_desc.usage;
+    desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
     desc->Pool = wined3d_desc.pool;
     desc->Size = wined3d_desc.size;
     desc->Type = D3DRTYPE_VERTEXBUFFER;
@@ -267,13 +290,13 @@ HRESULT vertexbuffer_init(IDirect3DVertexBuffer9Impl *buffer, IDirect3DDevice9Im
 {
     HRESULT hr;
 
-    buffer->lpVtbl = &d3d9_vertexbuffer_vtbl;
+    buffer->IDirect3DVertexBuffer9_iface.lpVtbl = &d3d9_vertexbuffer_vtbl;
     buffer->ref = 1;
     buffer->fvf = fvf;
 
     wined3d_mutex_lock();
     hr = wined3d_buffer_create_vb(device->wined3d_device, size, usage & WINED3DUSAGE_MASK,
-            (WINED3DPOOL)pool, buffer, &d3d9_vertexbuffer_wined3d_parent_ops, &buffer->wineD3DVertexBuffer);
+            (enum wined3d_pool)pool, buffer, &d3d9_vertexbuffer_wined3d_parent_ops, &buffer->wineD3DVertexBuffer);
     wined3d_mutex_unlock();
     if (FAILED(hr))
     {
@@ -287,6 +310,20 @@ HRESULT vertexbuffer_init(IDirect3DVertexBuffer9Impl *buffer, IDirect3DDevice9Im
     return D3D_OK;
 }
 
+IDirect3DVertexBuffer9Impl *unsafe_impl_from_IDirect3DVertexBuffer9(IDirect3DVertexBuffer9 *iface)
+{
+    if (!iface)
+        return NULL;
+    assert(iface->lpVtbl == &d3d9_vertexbuffer_vtbl);
+
+    return impl_from_IDirect3DVertexBuffer9(iface);
+}
+
+static inline IDirect3DIndexBuffer9Impl *impl_from_IDirect3DIndexBuffer9(IDirect3DIndexBuffer9 *iface)
+{
+    return CONTAINING_RECORD(iface, IDirect3DIndexBuffer9Impl, IDirect3DIndexBuffer9_iface);
+}
+
 static HRESULT WINAPI d3d9_indexbuffer_QueryInterface(IDirect3DIndexBuffer9 *iface, REFIID riid, void **object)
 {
     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
@@ -308,7 +345,7 @@ static HRESULT WINAPI d3d9_indexbuffer_QueryInterface(IDirect3DIndexBuffer9 *ifa
 
 static ULONG WINAPI d3d9_indexbuffer_AddRef(IDirect3DIndexBuffer9 *iface)
 {
-    IDirect3DIndexBuffer9Impl *buffer = (IDirect3DIndexBuffer9Impl *)iface;
+    IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface);
     ULONG refcount = InterlockedIncrement(&buffer->ref);
 
     TRACE("%p increasing refcount to %u.\n", iface, refcount);
@@ -326,7 +363,7 @@ static ULONG WINAPI d3d9_indexbuffer_AddRef(IDirect3DIndexBuffer9 *iface)
 
 static ULONG WINAPI d3d9_indexbuffer_Release(IDirect3DIndexBuffer9 *iface)
 {
-    IDirect3DIndexBuffer9Impl *buffer = (IDirect3DIndexBuffer9Impl *)iface;
+    IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface);
     ULONG refcount = InterlockedDecrement(&buffer->ref);
 
     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
@@ -346,11 +383,14 @@ static ULONG WINAPI d3d9_indexbuffer_Release(IDirect3DIndexBuffer9 *iface)
     return refcount;
 }
 
-static HRESULT WINAPI d3d9_indexbuffer_GetDevice(IDirect3DIndexBuffer9 *iface, IDirect3DDevice9 **device)
+static HRESULT WINAPI d3d9_indexbuffer_GetDevice(IDirect3DIndexBuffer9 *iface,
+        IDirect3DDevice9 **device)
 {
+    IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface);
+
     TRACE("iface %p, device %p.\n", iface, device);
 
-    *device = (IDirect3DDevice9 *)((IDirect3DIndexBuffer9Impl *)iface)->parentDevice;
+    *device = (IDirect3DDevice9 *)buffer->parentDevice;
     IDirect3DDevice9_AddRef(*device);
 
     TRACE("Returning device %p.\n", *device);
@@ -361,14 +401,16 @@ static HRESULT WINAPI d3d9_indexbuffer_GetDevice(IDirect3DIndexBuffer9 *iface, I
 static HRESULT WINAPI d3d9_indexbuffer_SetPrivateData(IDirect3DIndexBuffer9 *iface,
         REFGUID guid, const void *data, DWORD data_size, DWORD flags)
 {
+    IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
             iface, debugstr_guid(guid), data, data_size, flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_buffer_set_private_data(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer,
-            guid, data, data_size, flags);
+    resource = wined3d_buffer_get_resource(buffer->wineD3DIndexBuffer);
+    hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -377,14 +419,16 @@ static HRESULT WINAPI d3d9_indexbuffer_SetPrivateData(IDirect3DIndexBuffer9 *ifa
 static HRESULT WINAPI d3d9_indexbuffer_GetPrivateData(IDirect3DIndexBuffer9 *iface,
         REFGUID guid, void *data, DWORD *data_size)
 {
+    IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
             iface, debugstr_guid(guid), data, data_size);
 
     wined3d_mutex_lock();
-    hr = wined3d_buffer_get_private_data(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer,
-            guid, data, data_size);
+    resource = wined3d_buffer_get_resource(buffer->wineD3DIndexBuffer);
+    hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
     wined3d_mutex_unlock();
 
     return hr;
@@ -392,12 +436,15 @@ static HRESULT WINAPI d3d9_indexbuffer_GetPrivateData(IDirect3DIndexBuffer9 *ifa
 
 static HRESULT WINAPI d3d9_indexbuffer_FreePrivateData(IDirect3DIndexBuffer9 *iface, REFGUID guid)
 {
+    IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
 
     wined3d_mutex_lock();
-    hr = wined3d_buffer_free_private_data(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer, guid);
+    resource = wined3d_buffer_get_resource(buffer->wineD3DIndexBuffer);
+    hr = wined3d_resource_free_private_data(resource, guid);
     wined3d_mutex_unlock();
 
     return hr;
@@ -405,12 +452,13 @@ static HRESULT WINAPI d3d9_indexbuffer_FreePrivateData(IDirect3DIndexBuffer9 *if
 
 static DWORD WINAPI d3d9_indexbuffer_SetPriority(IDirect3DIndexBuffer9 *iface, DWORD priority)
 {
+    IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface);
     DWORD previous;
 
     TRACE("iface %p, priority %u.\n", iface, priority);
 
     wined3d_mutex_lock();
-    previous = wined3d_buffer_set_priority(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer, priority);
+    previous = wined3d_buffer_set_priority(buffer->wineD3DIndexBuffer, priority);
     wined3d_mutex_unlock();
 
     return previous;
@@ -418,12 +466,13 @@ static DWORD WINAPI d3d9_indexbuffer_SetPriority(IDirect3DIndexBuffer9 *iface, D
 
 static DWORD WINAPI d3d9_indexbuffer_GetPriority(IDirect3DIndexBuffer9 *iface)
 {
+    IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface);
     DWORD priority;
 
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    priority = wined3d_buffer_get_priority(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer);
+    priority = wined3d_buffer_get_priority(buffer->wineD3DIndexBuffer);
     wined3d_mutex_unlock();
 
     return priority;
@@ -431,10 +480,12 @@ static DWORD WINAPI d3d9_indexbuffer_GetPriority(IDirect3DIndexBuffer9 *iface)
 
 static void WINAPI d3d9_indexbuffer_PreLoad(IDirect3DIndexBuffer9 *iface)
 {
+    IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface);
+
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    wined3d_buffer_preload(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer);
+    wined3d_buffer_preload(buffer->wineD3DIndexBuffer);
     wined3d_mutex_unlock();
 }
 
@@ -448,14 +499,14 @@ static D3DRESOURCETYPE WINAPI d3d9_indexbuffer_GetType(IDirect3DIndexBuffer9 *if
 static HRESULT WINAPI d3d9_indexbuffer_Lock(IDirect3DIndexBuffer9 *iface,
         UINT offset, UINT size, void **data, DWORD flags)
 {
+    IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface);
     HRESULT hr;
 
     TRACE("iface %p, offset %u, size %u, data %p, flags %#x.\n",
             iface, offset, size, data, flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_buffer_map(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer,
-            offset, size, (BYTE **)data, flags);
+    hr = wined3d_buffer_map(buffer->wineD3DIndexBuffer, offset, size, (BYTE **)data, flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -463,18 +514,21 @@ static HRESULT WINAPI d3d9_indexbuffer_Lock(IDirect3DIndexBuffer9 *iface,
 
 static HRESULT WINAPI d3d9_indexbuffer_Unlock(IDirect3DIndexBuffer9 *iface)
 {
+    IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface);
+
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    wined3d_buffer_unmap(((IDirect3DIndexBuffer9Impl *)iface)->wineD3DIndexBuffer);
+    wined3d_buffer_unmap(buffer->wineD3DIndexBuffer);
     wined3d_mutex_unlock();
 
     return D3D_OK;
 }
 
-static HRESULT WINAPI d3d9_indexbuffer_GetDesc(IDirect3DIndexBuffer9 *iface, D3DINDEXBUFFER_DESC *desc)
+static HRESULT WINAPI d3d9_indexbuffer_GetDesc(IDirect3DIndexBuffer9 *iface,
+        D3DINDEXBUFFER_DESC *desc)
 {
-    IDirect3DIndexBuffer9Impl *buffer = (IDirect3DIndexBuffer9Impl *)iface;
+    IDirect3DIndexBuffer9Impl *buffer = impl_from_IDirect3DIndexBuffer9(iface);
     struct wined3d_resource_desc wined3d_desc;
     struct wined3d_resource *wined3d_resource;
 
@@ -486,7 +540,7 @@ static HRESULT WINAPI d3d9_indexbuffer_GetDesc(IDirect3DIndexBuffer9 *iface, D3D
     wined3d_mutex_unlock();
 
     desc->Format = d3dformat_from_wined3dformat(buffer->format);
-    desc->Usage = wined3d_desc.usage;
+    desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
     desc->Pool = wined3d_desc.pool;
     desc->Size = wined3d_desc.size;
     desc->Type = D3DRTYPE_INDEXBUFFER;
@@ -530,13 +584,13 @@ HRESULT indexbuffer_init(IDirect3DIndexBuffer9Impl *buffer, IDirect3DDevice9Impl
 {
     HRESULT hr;
 
-    buffer->lpVtbl = &d3d9_indexbuffer_vtbl;
+    buffer->IDirect3DIndexBuffer9_iface.lpVtbl = &d3d9_indexbuffer_vtbl;
     buffer->ref = 1;
     buffer->format = wined3dformat_from_d3dformat(format);
 
     wined3d_mutex_lock();
     hr = wined3d_buffer_create_ib(device->wined3d_device, size, usage & WINED3DUSAGE_MASK,
-            (WINED3DPOOL)pool, buffer, &d3d9_indexbuffer_wined3d_parent_ops, &buffer->wineD3DIndexBuffer);
+            (enum wined3d_pool)pool, buffer, &d3d9_indexbuffer_wined3d_parent_ops, &buffer->wineD3DIndexBuffer);
     wined3d_mutex_unlock();
     if (FAILED(hr))
     {
@@ -549,3 +603,12 @@ HRESULT indexbuffer_init(IDirect3DIndexBuffer9Impl *buffer, IDirect3DDevice9Impl
 
     return D3D_OK;
 }
+
+IDirect3DIndexBuffer9Impl *unsafe_impl_from_IDirect3DIndexBuffer9(IDirect3DIndexBuffer9 *iface)
+{
+    if (!iface)
+        return NULL;
+    assert(iface->lpVtbl == &d3d9_indexbuffer_vtbl);
+
+    return impl_from_IDirect3DIndexBuffer9(iface);
+}
index 1f5e27b..349f790 100644 (file)
@@ -112,13 +112,15 @@ static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetPrivateData(IDirect3DCubeText
         REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
 {
     IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
             iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_set_private_data(This->wined3d_texture, refguid, pData, SizeOfData, Flags);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -128,13 +130,15 @@ static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetPrivateData(IDirect3DCubeText
         REFGUID refguid, void *pData, DWORD *pSizeOfData)
 {
     IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
             iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_get_private_data(This->wined3d_texture, refguid, pData, pSizeOfData);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData);
     wined3d_mutex_unlock();
 
     return hr;
@@ -144,12 +148,14 @@ static HRESULT WINAPI IDirect3DCubeTexture9Impl_FreePrivateData(IDirect3DCubeTex
         REFGUID refguid)
 {
     IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_free_private_data(This->wined3d_texture, refguid);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_free_private_data(resource, refguid);
     wined3d_mutex_unlock();
 
     return hr;
@@ -197,16 +203,9 @@ static void WINAPI IDirect3DCubeTexture9Impl_PreLoad(IDirect3DCubeTexture9 *ifac
 
 static D3DRESOURCETYPE WINAPI IDirect3DCubeTexture9Impl_GetType(IDirect3DCubeTexture9 *iface)
 {
-    IDirect3DCubeTexture9Impl *This = impl_from_IDirect3DCubeTexture9(iface);
-    D3DRESOURCETYPE ret;
-
     TRACE("iface %p.\n", iface);
 
-    wined3d_mutex_lock();
-    ret = wined3d_texture_get_type(This->wined3d_texture);
-    wined3d_mutex_unlock();
-
-    return ret;
+    return D3DRTYPE_CUBETEXTURE;
 }
 
 /* IDirect3DCubeTexture9 IDirect3DBaseTexture9 Interface follow: */
@@ -261,7 +260,7 @@ static HRESULT WINAPI IDirect3DCubeTexture9Impl_SetAutoGenFilterType(IDirect3DCu
     TRACE("iface %p, filter_type %#x.\n", iface, FilterType);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_set_autogen_filter_type(This->wined3d_texture, (WINED3DTEXTUREFILTERTYPE)FilterType);
+    hr = wined3d_texture_set_autogen_filter_type(This->wined3d_texture, (enum wined3d_texture_filter_type)FilterType);
     wined3d_mutex_unlock();
 
     return hr;
@@ -312,7 +311,7 @@ static HRESULT WINAPI IDirect3DCubeTexture9Impl_GetLevelDesc(IDirect3DCubeTextur
         wined3d_resource_get_desc(sub_resource, &wined3d_desc);
         desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
         desc->Type = wined3d_desc.resource_type;
-        desc->Usage = wined3d_desc.usage;
+        desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
         desc->Pool = wined3d_desc.pool;
         desc->MultiSampleType = wined3d_desc.multisample_type;
         desc->MultiSampleQuality = wined3d_desc.multisample_quality;
@@ -407,14 +406,14 @@ static HRESULT  WINAPI IDirect3DCubeTexture9Impl_AddDirtyRect(IDirect3DCubeTextu
         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, NULL);
     else
     {
-        WINED3DBOX dirty_region;
-
-        dirty_region.Left = dirty_rect->left;
-        dirty_region.Top = dirty_rect->top;
-        dirty_region.Right = dirty_rect->right;
-        dirty_region.Bottom = dirty_rect->bottom;
-        dirty_region.Front = 0;
-        dirty_region.Back = 1;
+        struct wined3d_box dirty_region;
+
+        dirty_region.left = dirty_rect->left;
+        dirty_region.top = dirty_rect->top;
+        dirty_region.right = dirty_rect->right;
+        dirty_region.bottom = dirty_rect->bottom;
+        dirty_region.front = 0;
+        dirty_region.back = 1;
         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, face, &dirty_region);
     }
     wined3d_mutex_unlock();
index 0d3ecec..abb98f3 100644 (file)
@@ -40,7 +40,7 @@ IDirect3D9* WINAPI DECLSPEC_HOTPATCH Direct3DCreate9(UINT SDKVersion) {
     object->ref = 1;
 
     wined3d_mutex_lock();
-    object->WineD3D = wined3d_create(9, object);
+    object->WineD3D = wined3d_create(9, 0, object);
     wined3d_mutex_unlock();
 
     TRACE("SDKVersion = %x, Created Direct3D object @ %p, WineObj @ %p\n", SDKVersion, object, object->WineD3D);
index 23e7f00..9feda66 100644 (file)
@@ -111,16 +111,15 @@ enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format) DECLSPEC_H
     _pD3D9Caps->DeclTypes                         = _pWineCaps->DeclTypes; \
     _pD3D9Caps->NumSimultaneousRTs                = _pWineCaps->NumSimultaneousRTs; \
     _pD3D9Caps->StretchRectFilterCaps             = _pWineCaps->StretchRectFilterCaps; \
-    _pD3D9Caps->VS20Caps.Caps                     = _pWineCaps->VS20Caps.Caps; \
-    _pD3D9Caps->VS20Caps.DynamicFlowControlDepth  = _pWineCaps->VS20Caps.DynamicFlowControlDepth; \
-    _pD3D9Caps->VS20Caps.NumTemps                 = _pWineCaps->VS20Caps.NumTemps; \
-    _pD3D9Caps->VS20Caps.NumTemps                 = _pWineCaps->VS20Caps.NumTemps; \
-    _pD3D9Caps->VS20Caps.StaticFlowControlDepth   = _pWineCaps->VS20Caps.StaticFlowControlDepth; \
-    _pD3D9Caps->PS20Caps.Caps                     = _pWineCaps->PS20Caps.Caps; \
-    _pD3D9Caps->PS20Caps.DynamicFlowControlDepth  = _pWineCaps->PS20Caps.DynamicFlowControlDepth; \
-    _pD3D9Caps->PS20Caps.NumTemps                 = _pWineCaps->PS20Caps.NumTemps; \
-    _pD3D9Caps->PS20Caps.StaticFlowControlDepth   = _pWineCaps->PS20Caps.StaticFlowControlDepth; \
-    _pD3D9Caps->PS20Caps.NumInstructionSlots      = _pWineCaps->PS20Caps.NumInstructionSlots; \
+    _pD3D9Caps->VS20Caps.Caps                     = _pWineCaps->VS20Caps.caps; \
+    _pD3D9Caps->VS20Caps.DynamicFlowControlDepth  = _pWineCaps->VS20Caps.dynamic_flow_control_depth; \
+    _pD3D9Caps->VS20Caps.NumTemps                 = _pWineCaps->VS20Caps.temp_count; \
+    _pD3D9Caps->VS20Caps.StaticFlowControlDepth   = _pWineCaps->VS20Caps.static_flow_control_depth; \
+    _pD3D9Caps->PS20Caps.Caps                     = _pWineCaps->PS20Caps.caps; \
+    _pD3D9Caps->PS20Caps.DynamicFlowControlDepth  = _pWineCaps->PS20Caps.dynamic_flow_control_depth; \
+    _pD3D9Caps->PS20Caps.NumTemps                 = _pWineCaps->PS20Caps.temp_count; \
+    _pD3D9Caps->PS20Caps.StaticFlowControlDepth   = _pWineCaps->PS20Caps.static_flow_control_depth; \
+    _pD3D9Caps->PS20Caps.NumInstructionSlots      = _pWineCaps->PS20Caps.instruction_slot_count; \
     _pD3D9Caps->VertexTextureFilterCaps           = _pWineCaps->VertexTextureFilterCaps; \
     _pD3D9Caps->MaxVShaderInstructionsExecuted    = _pWineCaps->MaxVShaderInstructionsExecuted; \
     _pD3D9Caps->MaxPShaderInstructionsExecuted    = _pWineCaps->MaxPShaderInstructionsExecuted; \
@@ -166,6 +165,7 @@ typedef struct IDirect3DDevice9Impl
     struct wined3d_device_parent device_parent;
     LONG ref;
     struct wined3d_device *wined3d_device;
+    IDirect3D9Ex *d3d_parent;
     /* Avoids recursion with nested ReleaseRef to 0 */
     BOOL                          inDestruction;
 
@@ -175,7 +175,7 @@ typedef struct IDirect3DDevice9Impl
     BOOL                          notreset;
 } IDirect3DDevice9Impl;
 
-HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT adapter, D3DDEVTYPE device_type,
+HRESULT device_init(IDirect3DDevice9Impl *device, IDirect3D9Impl *parent, struct wined3d *wined3d, UINT adapter, D3DDEVTYPE device_type,
         HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode) DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -192,7 +192,7 @@ typedef struct IDirect3DVolume9Impl
 } IDirect3DVolume9Impl;
 
 HRESULT volume_init(IDirect3DVolume9Impl *volume, IDirect3DDevice9Impl *device, UINT width, UINT height,
-        UINT depth, DWORD usage, enum wined3d_format_id format, WINED3DPOOL pool) DECLSPEC_HIDDEN;
+        UINT depth, DWORD usage, enum wined3d_format_id format, enum wined3d_pool pool) DECLSPEC_HIDDEN;
 
 /* ------------------- */
 /* IDirect3DSwapChain9 */
@@ -222,9 +222,8 @@ HRESULT swapchain_init(IDirect3DSwapChain9Impl *swapchain, IDirect3DDevice9Impl
  */
 typedef struct IDirect3DSurface9Impl
 {
-    /* IUnknown fields */
-    const IDirect3DSurface9Vtbl *lpVtbl;
-    LONG                    ref;
+    IDirect3DSurface9 IDirect3DSurface9_iface;
+    LONG ref;
     struct wined3d_surface *wined3d_surface;
     IDirect3DDevice9Ex *parentDevice;
 
@@ -240,6 +239,7 @@ typedef struct IDirect3DSurface9Impl
 HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *device,
         UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
         DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality) DECLSPEC_HIDDEN;
+IDirect3DSurface9Impl *unsafe_impl_from_IDirect3DSurface9(IDirect3DSurface9 *iface) DECLSPEC_HIDDEN;
 
 /* ---------------------- */
 /* IDirect3DVertexBuffer9 */
@@ -250,10 +250,8 @@ HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *devic
  */
 typedef struct IDirect3DVertexBuffer9Impl
 {
-    /* IUnknown fields */
-    const IDirect3DVertexBuffer9Vtbl *lpVtbl;
-    LONG                    ref;
-
+    IDirect3DVertexBuffer9 IDirect3DVertexBuffer9_iface;
+    LONG ref;
     struct wined3d_buffer *wineD3DVertexBuffer;
     IDirect3DDevice9Ex *parentDevice;
     DWORD fvf;
@@ -261,6 +259,7 @@ typedef struct IDirect3DVertexBuffer9Impl
 
 HRESULT vertexbuffer_init(IDirect3DVertexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
         UINT size, UINT usage, DWORD fvf, D3DPOOL pool) DECLSPEC_HIDDEN;
+IDirect3DVertexBuffer9Impl *unsafe_impl_from_IDirect3DVertexBuffer9(IDirect3DVertexBuffer9 *iface) DECLSPEC_HIDDEN;
 
 /* --------------------- */
 /* IDirect3DIndexBuffer9 */
@@ -271,10 +270,8 @@ HRESULT vertexbuffer_init(IDirect3DVertexBuffer9Impl *buffer, IDirect3DDevice9Im
  */
 typedef struct IDirect3DIndexBuffer9Impl
 {
-    /* IUnknown fields */
-    const IDirect3DIndexBuffer9Vtbl *lpVtbl;
-    LONG                    ref;
-
+    IDirect3DIndexBuffer9 IDirect3DIndexBuffer9_iface;
+    LONG ref;
     struct wined3d_buffer *wineD3DIndexBuffer;
     IDirect3DDevice9Ex *parentDevice;
     enum wined3d_format_id format;
@@ -282,6 +279,7 @@ typedef struct IDirect3DIndexBuffer9Impl
 
 HRESULT indexbuffer_init(IDirect3DIndexBuffer9Impl *buffer, IDirect3DDevice9Impl *device,
         UINT size, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
+IDirect3DIndexBuffer9Impl *unsafe_impl_from_IDirect3DIndexBuffer9(IDirect3DIndexBuffer9 *iface) DECLSPEC_HIDDEN;
 
 /* --------------------- */
 /* IDirect3DBaseTexture9 */
@@ -407,8 +405,7 @@ HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration9Impl *declaration,
  * IDirect3DVertexShader implementation structure
  */
 typedef struct IDirect3DVertexShader9Impl {
-  /* IUnknown fields */
-  const IDirect3DVertexShader9Vtbl *lpVtbl;
+  IDirect3DVertexShader9 IDirect3DVertexShader9_iface;
   LONG ref;
   struct wined3d_shader *wined3d_shader;
   IDirect3DDevice9Ex *parentDevice;
@@ -416,6 +413,7 @@ typedef struct IDirect3DVertexShader9Impl {
 
 HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader,
         IDirect3DDevice9Impl *device, const DWORD *byte_code) DECLSPEC_HIDDEN;
+IDirect3DVertexShader9Impl *unsafe_impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface) DECLSPEC_HIDDEN;
 
 #define D3D9_MAX_VERTEX_SHADER_CONSTANTF 256
 #define D3D9_MAX_SIMULTANEOUS_RENDERTARGETS 4
@@ -428,15 +426,15 @@ HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader,
  * IDirect3DPixelShader implementation structure
  */
 typedef struct IDirect3DPixelShader9Impl {
-  /* IUnknown fields */
-    const IDirect3DPixelShader9Vtbl *lpVtbl;
-    LONG                    ref;
+    IDirect3DPixelShader9 IDirect3DPixelShader9_iface;
+    LONG ref;
     struct wined3d_shader *wined3d_shader;
     IDirect3DDevice9Ex *parentDevice;
 } IDirect3DPixelShader9Impl;
 
 HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader,
         IDirect3DDevice9Impl *device, const DWORD *byte_code) DECLSPEC_HIDDEN;
+IDirect3DPixelShader9Impl *unsafe_impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface) DECLSPEC_HIDDEN;
 
 /* --------------- */
 /* IDirect3DQuery9 */
index 2af2c82..631ba5a 100644 (file)
@@ -265,6 +265,8 @@ static ULONG WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Release(IDirect3DDevi
       wined3d_device_decref(This->wined3d_device);
       wined3d_mutex_unlock();
 
+      IDirect3D9_Release(This->d3d_parent);
+
       HeapFree(GetProcessHeap(), 0, This);
     }
     return ref;
@@ -302,23 +304,20 @@ static UINT WINAPI IDirect3DDevice9Impl_GetAvailableTextureMem(IDirect3DDevice9E
 static HRESULT WINAPI IDirect3DDevice9Impl_EvictManagedResources(IDirect3DDevice9Ex *iface)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
-    HRESULT hr;
 
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    hr = wined3d_device_evict_managed_resources(This->wined3d_device);
+    wined3d_device_evict_managed_resources(This->wined3d_device);
     wined3d_mutex_unlock();
 
-    return hr;
+    return D3D_OK;
 }
 
 static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(IDirect3DDevice9Ex *iface,
         IDirect3D9 **ppD3D9)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
-    struct wined3d *wined3d;
-    HRESULT hr = D3D_OK;
 
     TRACE("iface %p, d3d9 %p.\n", iface, ppD3D9);
 
@@ -326,23 +325,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(IDirect3DDevice9Ex *iface
         return D3DERR_INVALIDCALL;
     }
 
-    wined3d_mutex_lock();
-    hr = wined3d_device_get_wined3d(This->wined3d_device, &wined3d);
-    if (hr == D3D_OK && wined3d)
-    {
-        *ppD3D9 = wined3d_get_parent(wined3d);
-        IDirect3D9_AddRef(*ppD3D9);
-        wined3d_decref(wined3d);
-    }
-    else
-    {
-        FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
-        *ppD3D9 = NULL;
-    }
-    TRACE("(%p) returning %p\n", This, *ppD3D9);
-    wined3d_mutex_unlock();
-
-    return hr;
+    return IDirect3D9Ex_QueryInterface(This->d3d_parent, &IID_IDirect3D9, (void **)ppD3D9);
 }
 
 static HRESULT WINAPI IDirect3DDevice9Impl_GetDeviceCaps(IDirect3DDevice9Ex *iface, D3DCAPS9 *pCaps)
@@ -388,7 +371,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetDisplayMode(IDirect3DDevice9Ex *if
     TRACE("iface %p, swapchain %u, mode %p.\n", iface, iSwapChain, pMode);
 
     wined3d_mutex_lock();
-    hr = wined3d_device_get_display_mode(This->wined3d_device, iSwapChain, (WINED3DDISPLAYMODE *)pMode);
+    hr = wined3d_device_get_display_mode(This->wined3d_device, iSwapChain, (struct wined3d_display_mode *)pMode);
     wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -406,7 +389,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetCreationParameters(IDirect3DDevice
 
     wined3d_mutex_lock();
     hr = wined3d_device_get_creation_parameters(This->wined3d_device,
-            (WINED3DDEVICE_CREATION_PARAMETERS *)pParameters);
+            (struct wined3d_device_creation_parameters *)pParameters);
     wined3d_mutex_unlock();
 
     return hr;
@@ -416,7 +399,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetCursorProperties(IDirect3DDevice9E
         UINT XHotSpot, UINT YHotSpot, IDirect3DSurface9 *pCursorBitmap)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
-    IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pCursorBitmap;
+    IDirect3DSurface9Impl *pSurface = unsafe_impl_from_IDirect3DSurface9(pCursorBitmap);
     HRESULT hr;
 
     TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
@@ -532,21 +515,19 @@ static UINT WINAPI IDirect3DDevice9Impl_GetNumberOfSwapChains(IDirect3DDevice9Ex
     return count;
 }
 
-static HRESULT WINAPI reset_enum_callback(struct wined3d_resource *resource, void *data)
+static HRESULT CDECL reset_enum_callback(struct wined3d_resource *resource)
 {
     struct wined3d_resource_desc desc;
-    BOOL *resources_ok = data;
 
     wined3d_resource_get_desc(resource, &desc);
-    if (desc.pool == WINED3DPOOL_DEFAULT)
+    if (desc.pool == WINED3D_POOL_DEFAULT)
     {
         IDirect3DSurface9 *surface;
 
-        if (desc.resource_type != WINED3DRTYPE_SURFACE)
+        if (desc.resource_type != WINED3D_RTYPE_SURFACE)
         {
             WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource);
-            *resources_ok = FALSE;
-            return S_FALSE;
+            return D3DERR_INVALIDCALL;
         }
 
         surface = wined3d_resource_get_parent(resource);
@@ -555,24 +536,21 @@ static HRESULT WINAPI reset_enum_callback(struct wined3d_resource *resource, voi
         if (IDirect3DSurface9_Release(surface))
         {
             WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface, resource);
-            *resources_ok = FALSE;
-            return S_FALSE;
+            return D3DERR_INVALIDCALL;
         }
 
         WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface, resource);
     }
 
-    return S_OK;
+    return D3D_OK;
 }
 
 static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Reset(IDirect3DDevice9Ex *iface,
         D3DPRESENT_PARAMETERS *pPresentationParameters)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
-    WINED3DPRESENT_PARAMETERS localParameters;
+    struct wined3d_swapchain_desc swapchain_desc;
     HRESULT hr;
-    BOOL resources_ok = TRUE;
-    UINT i;
 
     TRACE("iface %p, present_parameters %p.\n", iface, pPresentationParameters);
 
@@ -585,63 +563,28 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_Reset(IDirect3DDevi
      * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
      */
     wined3d_mutex_lock();
-    wined3d_device_set_index_buffer(This->wined3d_device, NULL, WINED3DFMT_UNKNOWN);
-    for (i = 0; i < 16; ++i)
-    {
-        wined3d_device_set_stream_source(This->wined3d_device, i, NULL, 0, 0);
-    }
-    for (i = 0; i < 16; ++i)
-    {
-        wined3d_device_set_texture(This->wined3d_device, i, NULL);
-    }
 
-    wined3d_device_enum_resources(This->wined3d_device, reset_enum_callback, &resources_ok);
-    if (!resources_ok)
-    {
-        WARN("The application is holding D3DPOOL_DEFAULT resources, rejecting reset\n");
-        This->notreset = TRUE;
-        wined3d_mutex_unlock();
-
-        return D3DERR_INVALIDCALL;
-    }
-
-    localParameters.BackBufferWidth                     = pPresentationParameters->BackBufferWidth;
-    localParameters.BackBufferHeight                    = pPresentationParameters->BackBufferHeight;
-    localParameters.BackBufferFormat                    = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
-    localParameters.BackBufferCount                     = pPresentationParameters->BackBufferCount;
-    localParameters.MultiSampleType                     = pPresentationParameters->MultiSampleType;
-    localParameters.MultiSampleQuality                  = pPresentationParameters->MultiSampleQuality;
-    localParameters.SwapEffect                          = pPresentationParameters->SwapEffect;
-    localParameters.hDeviceWindow                       = pPresentationParameters->hDeviceWindow;
-    localParameters.Windowed                            = pPresentationParameters->Windowed;
-    localParameters.EnableAutoDepthStencil              = pPresentationParameters->EnableAutoDepthStencil;
-    localParameters.AutoDepthStencilFormat              = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
-    localParameters.Flags                               = pPresentationParameters->Flags;
-    localParameters.FullScreen_RefreshRateInHz          = pPresentationParameters->FullScreen_RefreshRateInHz;
-    localParameters.PresentationInterval                = pPresentationParameters->PresentationInterval;
-    localParameters.AutoRestoreDisplayMode              = TRUE;
-
-    hr = wined3d_device_reset(This->wined3d_device, &localParameters);
-    if(FAILED(hr)) {
+    swapchain_desc.backbuffer_width = pPresentationParameters->BackBufferWidth;
+    swapchain_desc.backbuffer_height = pPresentationParameters->BackBufferHeight;
+    swapchain_desc.backbuffer_format = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
+    swapchain_desc.backbuffer_count = pPresentationParameters->BackBufferCount;
+    swapchain_desc.multisample_type = pPresentationParameters->MultiSampleType;
+    swapchain_desc.multisample_quality = pPresentationParameters->MultiSampleQuality;
+    swapchain_desc.swap_effect = pPresentationParameters->SwapEffect;
+    swapchain_desc.device_window = pPresentationParameters->hDeviceWindow;
+    swapchain_desc.windowed = pPresentationParameters->Windowed;
+    swapchain_desc.enable_auto_depth_stencil = pPresentationParameters->EnableAutoDepthStencil;
+    swapchain_desc.auto_depth_stencil_format = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
+    swapchain_desc.flags = pPresentationParameters->Flags;
+    swapchain_desc.refresh_rate = pPresentationParameters->FullScreen_RefreshRateInHz;
+    swapchain_desc.swap_interval = pPresentationParameters->PresentationInterval;
+    swapchain_desc.auto_restore_display_mode = TRUE;
+
+    hr = wined3d_device_reset(This->wined3d_device, &swapchain_desc, reset_enum_callback);
+    if (FAILED(hr))
         This->notreset = TRUE;
-
-        pPresentationParameters->BackBufferWidth            = localParameters.BackBufferWidth;
-        pPresentationParameters->BackBufferHeight           = localParameters.BackBufferHeight;
-        pPresentationParameters->BackBufferFormat           = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
-        pPresentationParameters->BackBufferCount            = localParameters.BackBufferCount;
-        pPresentationParameters->MultiSampleType            = localParameters.MultiSampleType;
-        pPresentationParameters->MultiSampleQuality         = localParameters.MultiSampleQuality;
-        pPresentationParameters->SwapEffect                 = localParameters.SwapEffect;
-        pPresentationParameters->hDeviceWindow              = localParameters.hDeviceWindow;
-        pPresentationParameters->Windowed                   = localParameters.Windowed;
-        pPresentationParameters->EnableAutoDepthStencil     = localParameters.EnableAutoDepthStencil;
-        pPresentationParameters->AutoDepthStencilFormat     = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
-        pPresentationParameters->Flags                      = localParameters.Flags;
-        pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
-        pPresentationParameters->PresentationInterval       = localParameters.PresentationInterval;
-    } else {
+    else
         This->notreset = FALSE;
-    }
 
     wined3d_mutex_unlock();
 
@@ -677,7 +620,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetBackBuffer(IDirect3DDevice9Ex *ifa
 
     wined3d_mutex_lock();
     hr = wined3d_device_get_back_buffer(This->wined3d_device, iSwapChain,
-            BackBuffer, (WINED3DBACKBUFFER_TYPE) Type, &wined3d_surface);
+            BackBuffer, (enum wined3d_backbuffer_type)Type, &wined3d_surface);
     if (SUCCEEDED(hr) && wined3d_surface && ppBackBuffer)
     {
         *ppBackBuffer = wined3d_surface_get_parent(wined3d_surface);
@@ -697,7 +640,8 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetRasterStatus(IDirect3DDevice9Ex *i
     TRACE("iface %p, swapchain %u, raster_status %p.\n", iface, iSwapChain, pRasterStatus);
 
     wined3d_mutex_lock();
-    hr = wined3d_device_get_raster_status(This->wined3d_device, iSwapChain, (WINED3DRASTER_STATUS *)pRasterStatus);
+    hr = wined3d_device_get_raster_status(This->wined3d_device,
+            iSwapChain, (struct wined3d_raster_status *)pRasterStatus);
     wined3d_mutex_unlock();
 
     return hr;
@@ -725,9 +669,9 @@ static void WINAPI IDirect3DDevice9Impl_SetGammaRamp(IDirect3DDevice9Ex *iface,
 
     TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface, iSwapChain, Flags, pRamp);
 
-    /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
+    /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
     wined3d_mutex_lock();
-    wined3d_device_set_gamma_ramp(This->wined3d_device, iSwapChain, Flags, (const WINED3DGAMMARAMP *)pRamp);
+    wined3d_device_set_gamma_ramp(This->wined3d_device, iSwapChain, Flags, (const struct wined3d_gamma_ramp *)pRamp);
     wined3d_mutex_unlock();
 }
 
@@ -738,9 +682,9 @@ static void WINAPI IDirect3DDevice9Impl_GetGammaRamp(IDirect3DDevice9Ex *iface,
 
     TRACE("iface %p, swapchain %u, ramp %p.\n", iface, iSwapChain, pRamp);
 
-    /* Note: D3DGAMMARAMP is compatible with WINED3DGAMMARAMP */
+    /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
     wined3d_mutex_lock();
-    wined3d_device_get_gamma_ramp(This->wined3d_device, iSwapChain, (WINED3DGAMMARAMP *)pRamp);
+    wined3d_device_get_gamma_ramp(This->wined3d_device, iSwapChain, (struct wined3d_gamma_ramp *)pRamp);
     wined3d_mutex_unlock();
 }
 
@@ -750,11 +694,24 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex *ifa
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
     IDirect3DTexture9Impl *object;
+    BOOL set_mem = FALSE;
     HRESULT hr;
 
     TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
             iface, width, height, levels, usage, format, pool, texture, shared_handle);
 
+    if (shared_handle)
+    {
+        if (pool == D3DPOOL_SYSTEMMEM)
+        {
+            if (levels != 1)
+                return D3DERR_INVALIDCALL;
+            set_mem = TRUE;
+        }
+        else
+            FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
+    }
+
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     if (!object)
     {
@@ -770,6 +727,16 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex *ifa
         return hr;
     }
 
+    if (set_mem)
+    {
+        struct wined3d_resource *resource;
+        IDirect3DSurface9Impl *surface;
+
+        resource = wined3d_texture_get_sub_resource(object->wined3d_texture, 0);
+        surface = wined3d_resource_get_parent(resource);
+        wined3d_surface_set_mem(surface->wined3d_surface, *shared_handle);
+    }
+
     TRACE("Created texture %p.\n", object);
     *texture = &object->IDirect3DTexture9_iface;
 
@@ -789,6 +756,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateVolumeTexture(IDirect3DDevice9E
     TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
             usage, format, pool, texture, shared_handle);
 
+    if (shared_handle)
+        FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
+
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     if (!object)
     {
@@ -821,6 +791,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateCubeTexture(IDirect3DDevice9Ex
     TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
             iface, edge_length, levels, usage, format, pool, texture, shared_handle);
 
+    if (shared_handle)
+        FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
+
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     if (!object)
     {
@@ -853,6 +826,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(IDirect3DDevice9Ex
     TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
             iface, size, usage, fvf, pool, buffer, shared_handle);
 
+    if (shared_handle)
+        FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
+
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     if (!object)
     {
@@ -869,7 +845,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexBuffer(IDirect3DDevice9Ex
     }
 
     TRACE("Created vertex buffer %p.\n", object);
-    *buffer = (IDirect3DVertexBuffer9 *)object;
+    *buffer = &object->IDirect3DVertexBuffer9_iface;
 
     return D3D_OK;
 }
@@ -885,6 +861,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex
     TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
             iface, size, usage, format, pool, buffer, shared_handle);
 
+    if (shared_handle)
+        FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
+
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     if (!object)
     {
@@ -901,7 +880,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateIndexBuffer(IDirect3DDevice9Ex
     }
 
     TRACE("Created index buffer %p.\n", object);
-    *buffer = (IDirect3DIndexBuffer9 *)object;
+    *buffer = &object->IDirect3DIndexBuffer9_iface;
 
     return D3D_OK;
 }
@@ -936,14 +915,14 @@ static HRESULT IDirect3DDevice9Impl_CreateSurface(IDirect3DDevice9Impl *device,
     }
 
     TRACE("Created surface %p.\n", object);
-    *ppSurface = (IDirect3DSurface9 *)object;
+    *ppSurface = &object->IDirect3DSurface9_iface;
 
     return D3D_OK;
 }
 
 static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex *iface, UINT Width,
         UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality,
-        BOOL Lockable, IDirect3DSurface9 **ppSurface, HANDLE *pSharedHandle)
+        BOOL Lockable, IDirect3DSurface9 **ppSurface, HANDLE *shared_handle)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
     HRESULT hr;
@@ -951,7 +930,10 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex
     TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
             "lockable %#x, surface %p, shared_handle %p.\n",
             iface, Width, Height, Format, MultiSample, MultisampleQuality,
-            Lockable, ppSurface, pSharedHandle);
+            Lockable, ppSurface, shared_handle);
+
+    if (shared_handle)
+        FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
 
     hr = IDirect3DDevice9Impl_CreateSurface(This, Width, Height, Format, Lockable,
             FALSE /* Discard */, 0 /* Level */, ppSurface, D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT,
@@ -963,7 +945,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateRenderTarget(IDirect3DDevice9Ex
 static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(IDirect3DDevice9Ex *iface,
         UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample,
         DWORD MultisampleQuality, BOOL Discard, IDirect3DSurface9 **ppSurface,
-        HANDLE *pSharedHandle)
+        HANDLE *shared_handle)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
     HRESULT hr;
@@ -971,7 +953,10 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateDepthStencilSurface(IDirect3DDe
     TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
             "discard %#x, surface %p, shared_handle %p.\n",
             iface, Width, Height, Format, MultiSample, MultisampleQuality,
-            Discard, ppSurface, pSharedHandle);
+            Discard, ppSurface, shared_handle);
+
+    if (shared_handle)
+        FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
 
     hr = IDirect3DDevice9Impl_CreateSurface(This, Width, Height, Format, TRUE /* Lockable */,
             Discard, 0 /* Level */, ppSurface, D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, MultiSample,
@@ -986,15 +971,16 @@ static HRESULT WINAPI IDirect3DDevice9Impl_UpdateSurface(IDirect3DDevice9Ex *ifa
         IDirect3DSurface9 *pDestinationSurface, const POINT *pDestPoint)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
+    IDirect3DSurface9Impl *src = unsafe_impl_from_IDirect3DSurface9(pSourceSurface);
+    IDirect3DSurface9Impl *dst = unsafe_impl_from_IDirect3DSurface9(pDestinationSurface);
     HRESULT hr;
 
     TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
             iface, pSourceSurface, pSourceRect, pDestinationSurface, pDestPoint);
 
     wined3d_mutex_lock();
-    hr = wined3d_device_update_surface(This->wined3d_device,
-            ((IDirect3DSurface9Impl *)pSourceSurface)->wined3d_surface, pSourceRect,
-            ((IDirect3DSurface9Impl *)pDestinationSurface)->wined3d_surface, pDestPoint);
+    hr = wined3d_device_update_surface(This->wined3d_device, src->wined3d_surface, pSourceRect,
+            dst->wined3d_surface, pDestPoint);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1020,15 +1006,14 @@ static HRESULT WINAPI IDirect3DDevice9Impl_UpdateTexture(IDirect3DDevice9Ex *ifa
 static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTargetData(IDirect3DDevice9Ex *iface,
         IDirect3DSurface9 *pRenderTarget, IDirect3DSurface9 *pDestSurface)
 {
-    IDirect3DSurface9Impl *renderTarget = (IDirect3DSurface9Impl *)pRenderTarget;
-    IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
+    IDirect3DSurface9Impl *renderTarget = unsafe_impl_from_IDirect3DSurface9(pRenderTarget);
+    IDirect3DSurface9Impl *destSurface = unsafe_impl_from_IDirect3DSurface9(pDestSurface);
     HRESULT hr;
 
     TRACE("iface %p, render_target %p, dst_surface %p.\n", iface, pRenderTarget, pDestSurface);
 
     wined3d_mutex_lock();
-    hr = wined3d_surface_bltfast(destSurface->wined3d_surface, 0, 0,
-            renderTarget->wined3d_surface, NULL, WINEDDBLTFAST_NOCOLORKEY);
+    hr = wined3d_surface_get_render_target_data(destSurface->wined3d_surface, renderTarget->wined3d_surface);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1038,7 +1023,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(IDirect3DDevice9Ex
         UINT iSwapChain, IDirect3DSurface9 *pDestSurface)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
-    IDirect3DSurface9Impl *destSurface = (IDirect3DSurface9Impl *)pDestSurface;
+    IDirect3DSurface9Impl *destSurface = unsafe_impl_from_IDirect3DSurface9(pDestSurface);
     HRESULT hr;
 
     TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface, iSwapChain, pDestSurface);
@@ -1053,8 +1038,8 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetFrontBufferData(IDirect3DDevice9Ex
 static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(IDirect3DDevice9Ex *iface, IDirect3DSurface9 *pSourceSurface,
         const RECT *pSourceRect, IDirect3DSurface9 *pDestSurface, const RECT *pDestRect, D3DTEXTUREFILTERTYPE Filter)
 {
-    IDirect3DSurface9Impl *src = (IDirect3DSurface9Impl *) pSourceSurface;
-    IDirect3DSurface9Impl *dst = (IDirect3DSurface9Impl *) pDestSurface;
+    IDirect3DSurface9Impl *src = unsafe_impl_from_IDirect3DSurface9(pSourceSurface);
+    IDirect3DSurface9Impl *dst = unsafe_impl_from_IDirect3DSurface9(pDestSurface);
     HRESULT hr;
 
     TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
@@ -1062,6 +1047,8 @@ static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(IDirect3DDevice9Ex *iface
 
     wined3d_mutex_lock();
     hr = wined3d_surface_blt(dst->wined3d_surface, pDestRect, src->wined3d_surface, pSourceRect, 0, NULL, Filter);
+    if (hr == WINEDDERR_INVALIDRECT)
+        hr = D3DERR_INVALIDCALL;
     wined3d_mutex_unlock();
 
     return hr;
@@ -1070,7 +1057,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_StretchRect(IDirect3DDevice9Ex *iface
 static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(IDirect3DDevice9Ex *iface,
         IDirect3DSurface9 *pSurface, const RECT *pRect, D3DCOLOR color)
 {
-    const WINED3DCOLORVALUE c =
+    const struct wined3d_color c =
     {
         ((color >> 16) & 0xff) / 255.0f,
         ((color >>  8) & 0xff) / 255.0f,
@@ -1078,7 +1065,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(IDirect3DDevice9Ex *iface,
         ((color >> 24) & 0xff) / 255.0f,
     };
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
-    IDirect3DSurface9Impl *surface = (IDirect3DSurface9Impl *)pSurface;
+    IDirect3DSurface9Impl *surface = unsafe_impl_from_IDirect3DSurface9(pSurface);
     struct wined3d_resource *wined3d_resource;
     struct wined3d_resource_desc desc;
     HRESULT hr;
@@ -1092,7 +1079,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(IDirect3DDevice9Ex *iface,
 
     /* This method is only allowed with surfaces that are render targets, or
      * offscreen plain surfaces in D3DPOOL_DEFAULT. */
-    if (!(desc.usage & WINED3DUSAGE_RENDERTARGET) && desc.pool != WINED3DPOOL_DEFAULT)
+    if (!(desc.usage & WINED3DUSAGE_RENDERTARGET) && desc.pool != WINED3D_POOL_DEFAULT)
     {
         wined3d_mutex_unlock();
         WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
@@ -1109,15 +1096,19 @@ static HRESULT WINAPI IDirect3DDevice9Impl_ColorFill(IDirect3DDevice9Ex *iface,
 
 static HRESULT  WINAPI  IDirect3DDevice9Impl_CreateOffscreenPlainSurface(IDirect3DDevice9Ex *iface,
         UINT Width, UINT Height, D3DFORMAT Format, D3DPOOL Pool, IDirect3DSurface9 **ppSurface,
-        HANDLE *pSharedHandle)
+        HANDLE *shared_handle)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
     HRESULT hr;
 
     TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
-            iface, Width, Height, Format, Pool, ppSurface, pSharedHandle);
+            iface, Width, Height, Format, Pool, ppSurface, shared_handle);
+
+    if (shared_handle)
+        FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
 
-    if(Pool == D3DPOOL_MANAGED ){
+    if (Pool == D3DPOOL_MANAGED)
+    {
         FIXME("Attempting to create a managed offscreen plain surface\n");
         return D3DERR_INVALIDCALL;
     }
@@ -1130,7 +1121,7 @@ static HRESULT  WINAPI  IDirect3DDevice9Impl_CreateOffscreenPlainSurface(IDirect
         */
     hr = IDirect3DDevice9Impl_CreateSurface(This, Width, Height, Format, TRUE /* Lockable */,
             FALSE /* Discard */, 0 /* Level */, ppSurface, 0 /* Usage (undefined/none) */,
-            (WINED3DPOOL)Pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
+            Pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
 
     return hr;
 }
@@ -1140,7 +1131,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetRenderTarget(IDirect3DDevice9Ex *i
         DWORD RenderTargetIndex, IDirect3DSurface9 *pRenderTarget)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
-    IDirect3DSurface9Impl *pSurface = (IDirect3DSurface9Impl*)pRenderTarget;
+    IDirect3DSurface9Impl *pSurface = unsafe_impl_from_IDirect3DSurface9(pRenderTarget);
     HRESULT hr;
 
     TRACE("iface %p, idx %u, surface %p.\n", iface, RenderTargetIndex, pRenderTarget);
@@ -1179,24 +1170,19 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetRenderTarget(IDirect3DDevice9Ex *i
     }
 
     wined3d_mutex_lock();
-
     hr = wined3d_device_get_render_target(This->wined3d_device, RenderTargetIndex, &wined3d_surface);
-
-    if (FAILED(hr))
-    {
-        FIXME("Call to IWineD3DDevice_GetRenderTarget failed, hr %#x\n", hr);
-    }
-    else if (!wined3d_surface)
-    {
-        *ppRenderTarget = NULL;
-    }
-    else
+    if (SUCCEEDED(hr))
     {
         *ppRenderTarget = wined3d_surface_get_parent(wined3d_surface);
         IDirect3DSurface9_AddRef(*ppRenderTarget);
         wined3d_surface_decref(wined3d_surface);
     }
-
+    else
+    {
+        if (hr != WINED3DERR_NOTFOUND)
+            WARN("Failed to get render target %u, hr %#x.\n", RenderTargetIndex, hr);
+        *ppRenderTarget = NULL;
+    }
     wined3d_mutex_unlock();
 
     return hr;
@@ -1206,13 +1192,11 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetDepthStencilSurface(IDirect3DDevic
         IDirect3DSurface9 *pZStencilSurface)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
-    IDirect3DSurface9Impl *pSurface;
+    IDirect3DSurface9Impl *pSurface = unsafe_impl_from_IDirect3DSurface9(pZStencilSurface);
     HRESULT hr;
 
     TRACE("iface %p, depth_stencil %p.\n", iface, pZStencilSurface);
 
-    pSurface = (IDirect3DSurface9Impl*)pZStencilSurface;
-
     wined3d_mutex_lock();
     hr = wined3d_device_set_depth_stencil(This->wined3d_device, pSurface ? pSurface->wined3d_surface : NULL);
     wined3d_mutex_unlock();
@@ -1280,18 +1264,24 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DDevice9Impl_EndScene(IDirect3DD
     return hr;
 }
 
-static HRESULT WINAPI IDirect3DDevice9Impl_Clear(IDirect3DDevice9Ex *iface, DWORD Count,
-        const D3DRECT *pRects, DWORD Flags, D3DCOLOR Color, float Z, DWORD Stencil)
+static HRESULT WINAPI IDirect3DDevice9Impl_Clear(IDirect3DDevice9Ex *iface, DWORD rect_count,
+        const D3DRECT *rects, DWORD flags, D3DCOLOR color, float z, DWORD stencil)
 {
+    const struct wined3d_color c =
+    {
+        ((color >> 16) & 0xff) / 255.0f,
+        ((color >>  8) & 0xff) / 255.0f,
+        (color & 0xff) / 255.0f,
+        ((color >> 24) & 0xff) / 255.0f,
+    };
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
     HRESULT hr;
 
     TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
-            iface, Count, pRects, Flags, Color, Z, Stencil);
+            iface, rect_count, rects, flags, color, z, stencil);
 
-    /* Note: D3DRECT is compatible with WINED3DRECT */
     wined3d_mutex_lock();
-    hr = wined3d_device_clear(This->wined3d_device, Count, (const RECT *)pRects, Flags, Color, Z, Stencil);
+    hr = wined3d_device_clear(This->wined3d_device, rect_count, (const RECT *)rects, flags, &c, z, stencil);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1305,9 +1295,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetTransform(IDirect3DDevice9Ex *ifac
 
     TRACE("iface %p, state %#x, matrix %p.\n", iface, State, lpMatrix);
 
-    /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
+    /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
     wined3d_mutex_lock();
-    hr = wined3d_device_set_transform(This->wined3d_device, State, (const WINED3DMATRIX *)lpMatrix);
+    hr = wined3d_device_set_transform(This->wined3d_device, State, (const struct wined3d_matrix *)lpMatrix);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1321,9 +1311,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetTransform(IDirect3DDevice9Ex *ifac
 
     TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
 
-    /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
+    /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
     wined3d_mutex_lock();
-    hr = wined3d_device_get_transform(This->wined3d_device, State, (WINED3DMATRIX *)pMatrix);
+    hr = wined3d_device_get_transform(This->wined3d_device, State, (struct wined3d_matrix *)pMatrix);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1337,9 +1327,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_MultiplyTransform(IDirect3DDevice9Ex
 
     TRACE("iface %p, state %#x, matrix %p.\n", iface, State, pMatrix);
 
-    /* Note: D3DMATRIX is compatible with WINED3DMATRIX */
+    /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
     wined3d_mutex_lock();
-    hr = wined3d_device_multiply_transform(This->wined3d_device, State, (const WINED3DMATRIX *)pMatrix);
+    hr = wined3d_device_multiply_transform(This->wined3d_device, State, (const struct wined3d_matrix *)pMatrix);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1353,9 +1343,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetViewport(IDirect3DDevice9Ex *iface
 
     TRACE("iface %p, viewport %p.\n", iface, pViewport);
 
-    /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
+    /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
     wined3d_mutex_lock();
-    hr = wined3d_device_set_viewport(This->wined3d_device, (const WINED3DVIEWPORT *)pViewport);
+    hr = wined3d_device_set_viewport(This->wined3d_device, (const struct wined3d_viewport *)pViewport);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1369,9 +1359,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetViewport(IDirect3DDevice9Ex *iface
 
     TRACE("iface %p, viewport %p.\n", iface, pViewport);
 
-    /* Note: D3DVIEWPORT9 is compatible with WINED3DVIEWPORT */
+    /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
     wined3d_mutex_lock();
-    hr = wined3d_device_get_viewport(This->wined3d_device, (WINED3DVIEWPORT *)pViewport);
+    hr = wined3d_device_get_viewport(This->wined3d_device, (struct wined3d_viewport *)pViewport);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1385,9 +1375,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetMaterial(IDirect3DDevice9Ex *iface
 
     TRACE("iface %p, material %p.\n", iface, pMaterial);
 
-    /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
+    /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
     wined3d_mutex_lock();
-    hr = wined3d_device_set_material(This->wined3d_device, (const WINED3DMATERIAL *)pMaterial);
+    hr = wined3d_device_set_material(This->wined3d_device, (const struct wined3d_material *)pMaterial);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1401,9 +1391,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetMaterial(IDirect3DDevice9Ex *iface
 
     TRACE("iface %p, material %p.\n", iface, pMaterial);
 
-    /* Note: D3DMATERIAL9 is compatible with WINED3DMATERIAL */
+    /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
     wined3d_mutex_lock();
-    hr = wined3d_device_get_material(This->wined3d_device, (WINED3DMATERIAL *)pMaterial);
+    hr = wined3d_device_get_material(This->wined3d_device, (struct wined3d_material *)pMaterial);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1417,9 +1407,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetLight(IDirect3DDevice9Ex *iface, D
 
     TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
 
-    /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
+    /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
     wined3d_mutex_lock();
-    hr = wined3d_device_set_light(This->wined3d_device, Index, (const WINED3DLIGHT *)pLight);
+    hr = wined3d_device_set_light(This->wined3d_device, Index, (const struct wined3d_light *)pLight);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1433,9 +1423,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetLight(IDirect3DDevice9Ex *iface, D
 
     TRACE("iface %p, index %u, light %p.\n", iface, Index, pLight);
 
-    /* Note: D3DLIGHT9 is compatible with WINED3DLIGHT */
+    /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
     wined3d_mutex_lock();
-    hr = wined3d_device_get_light(This->wined3d_device, Index, (WINED3DLIGHT *)pLight);
+    hr = wined3d_device_get_light(This->wined3d_device, Index, (struct wined3d_light *)pLight);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1636,7 +1626,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetClipStatus(IDirect3DDevice9Ex *ifa
     TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
 
     wined3d_mutex_lock();
-    hr = wined3d_device_set_clip_status(This->wined3d_device, (const WINED3DCLIPSTATUS *)pClipStatus);
+    hr = wined3d_device_set_clip_status(This->wined3d_device, (const struct wined3d_clip_status *)pClipStatus);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1651,7 +1641,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetClipStatus(IDirect3DDevice9Ex *ifa
     TRACE("iface %p, clip_status %p.\n", iface, pClipStatus);
 
     wined3d_mutex_lock();
-    hr = wined3d_device_get_clip_status(This->wined3d_device, (WINED3DCLIPSTATUS *)pClipStatus);
+    hr = wined3d_device_get_clip_status(This->wined3d_device, (struct wined3d_clip_status *)pClipStatus);
     wined3d_mutex_unlock();
 
     return hr;
@@ -1707,41 +1697,41 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetTexture(IDirect3DDevice9Ex *iface,
     return hr;
 }
 
-static const WINED3DTEXTURESTAGESTATETYPE tss_lookup[] =
-{
-    WINED3DTSS_FORCE_DWORD,             /*  0, unused */
-    WINED3DTSS_COLOROP,                 /*  1, D3DTSS_COLOROP */
-    WINED3DTSS_COLORARG1,               /*  2, D3DTSS_COLORARG1 */
-    WINED3DTSS_COLORARG2,               /*  3, D3DTSS_COLORARG2 */
-    WINED3DTSS_ALPHAOP,                 /*  4, D3DTSS_ALPHAOP */
-    WINED3DTSS_ALPHAARG1,               /*  5, D3DTSS_ALPHAARG1 */
-    WINED3DTSS_ALPHAARG2,               /*  6, D3DTSS_ALPHAARG2 */
-    WINED3DTSS_BUMPENVMAT00,            /*  7, D3DTSS_BUMPENVMAT00 */
-    WINED3DTSS_BUMPENVMAT01,            /*  8, D3DTSS_BUMPENVMAT01 */
-    WINED3DTSS_BUMPENVMAT10,            /*  9, D3DTSS_BUMPENVMAT10 */
-    WINED3DTSS_BUMPENVMAT11,            /* 10, D3DTSS_BUMPENVMAT11 */
-    WINED3DTSS_TEXCOORDINDEX,           /* 11, D3DTSS_TEXCOORDINDEX */
-    WINED3DTSS_FORCE_DWORD,             /* 12, unused */
-    WINED3DTSS_FORCE_DWORD,             /* 13, unused */
-    WINED3DTSS_FORCE_DWORD,             /* 14, unused */
-    WINED3DTSS_FORCE_DWORD,             /* 15, unused */
-    WINED3DTSS_FORCE_DWORD,             /* 16, unused */
-    WINED3DTSS_FORCE_DWORD,             /* 17, unused */
-    WINED3DTSS_FORCE_DWORD,             /* 18, unused */
-    WINED3DTSS_FORCE_DWORD,             /* 19, unused */
-    WINED3DTSS_FORCE_DWORD,             /* 20, unused */
-    WINED3DTSS_FORCE_DWORD,             /* 21, unused */
-    WINED3DTSS_BUMPENVLSCALE,           /* 22, D3DTSS_BUMPENVLSCALE */
-    WINED3DTSS_BUMPENVLOFFSET,          /* 23, D3DTSS_BUMPENVLOFFSET */
-    WINED3DTSS_TEXTURETRANSFORMFLAGS,   /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
-    WINED3DTSS_FORCE_DWORD,             /* 25, unused */
-    WINED3DTSS_COLORARG0,               /* 26, D3DTSS_COLORARG0 */
-    WINED3DTSS_ALPHAARG0,               /* 27, D3DTSS_ALPHAARG0 */
-    WINED3DTSS_RESULTARG,               /* 28, D3DTSS_RESULTARG */
-    WINED3DTSS_FORCE_DWORD,             /* 29, unused */
-    WINED3DTSS_FORCE_DWORD,             /* 30, unused */
-    WINED3DTSS_FORCE_DWORD,             /* 31, unused */
-    WINED3DTSS_CONSTANT,                /* 32, D3DTSS_CONSTANT */
+static const enum wined3d_texture_stage_state tss_lookup[] =
+{
+    WINED3D_TSS_INVALID,                    /*  0, unused */
+    WINED3D_TSS_COLOR_OP,                   /*  1, D3DTSS_COLOROP */
+    WINED3D_TSS_COLOR_ARG1,                 /*  2, D3DTSS_COLORARG1 */
+    WINED3D_TSS_COLOR_ARG2,                 /*  3, D3DTSS_COLORARG2 */
+    WINED3D_TSS_ALPHA_OP,                   /*  4, D3DTSS_ALPHAOP */
+    WINED3D_TSS_ALPHA_ARG1,                 /*  5, D3DTSS_ALPHAARG1 */
+    WINED3D_TSS_ALPHA_ARG2,                 /*  6, D3DTSS_ALPHAARG2 */
+    WINED3D_TSS_BUMPENV_MAT00,              /*  7, D3DTSS_BUMPENVMAT00 */
+    WINED3D_TSS_BUMPENV_MAT01,              /*  8, D3DTSS_BUMPENVMAT01 */
+    WINED3D_TSS_BUMPENV_MAT10,              /*  9, D3DTSS_BUMPENVMAT10 */
+    WINED3D_TSS_BUMPENV_MAT11,              /* 10, D3DTSS_BUMPENVMAT11 */
+    WINED3D_TSS_TEXCOORD_INDEX,             /* 11, D3DTSS_TEXCOORDINDEX */
+    WINED3D_TSS_INVALID,                    /* 12, unused */
+    WINED3D_TSS_INVALID,                    /* 13, unused */
+    WINED3D_TSS_INVALID,                    /* 14, unused */
+    WINED3D_TSS_INVALID,                    /* 15, unused */
+    WINED3D_TSS_INVALID,                    /* 16, unused */
+    WINED3D_TSS_INVALID,                    /* 17, unused */
+    WINED3D_TSS_INVALID,                    /* 18, unused */
+    WINED3D_TSS_INVALID,                    /* 19, unused */
+    WINED3D_TSS_INVALID,                    /* 20, unused */
+    WINED3D_TSS_INVALID,                    /* 21, unused */
+    WINED3D_TSS_BUMPENV_LSCALE,             /* 22, D3DTSS_BUMPENVLSCALE */
+    WINED3D_TSS_BUMPENV_LOFFSET,            /* 23, D3DTSS_BUMPENVLOFFSET */
+    WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS,    /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
+    WINED3D_TSS_INVALID,                    /* 25, unused */
+    WINED3D_TSS_COLOR_ARG0,                 /* 26, D3DTSS_COLORARG0 */
+    WINED3D_TSS_ALPHA_ARG0,                 /* 27, D3DTSS_ALPHAARG0 */
+    WINED3D_TSS_RESULT_ARG,                 /* 28, D3DTSS_RESULTARG */
+    WINED3D_TSS_INVALID,                    /* 29, unused */
+    WINED3D_TSS_INVALID,                    /* 30, unused */
+    WINED3D_TSS_INVALID,                    /* 31, unused */
+    WINED3D_TSS_CONSTANT,                   /* 32, D3DTSS_CONSTANT */
 };
 
 static HRESULT WINAPI IDirect3DDevice9Impl_GetTextureStageState(IDirect3DDevice9Ex *iface,
@@ -1834,61 +1824,33 @@ static HRESULT WINAPI IDirect3DDevice9Impl_ValidateDevice(IDirect3DDevice9Ex *if
 static HRESULT WINAPI IDirect3DDevice9Impl_SetPaletteEntries(IDirect3DDevice9Ex *iface,
         UINT PaletteNumber, const PALETTEENTRY *pEntries)
 {
-    IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
-    HRESULT hr;
-
-    TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
+    FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface, PaletteNumber, pEntries);
 
-    wined3d_mutex_lock();
-    hr = wined3d_device_set_palette_entries(This->wined3d_device, PaletteNumber, pEntries);
-    wined3d_mutex_unlock();
-
-    return hr;
+    return D3DERR_INVALIDCALL;
 }
 
 static HRESULT WINAPI IDirect3DDevice9Impl_GetPaletteEntries(IDirect3DDevice9Ex *iface,
         UINT PaletteNumber, PALETTEENTRY *pEntries)
 {
-    IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
-    HRESULT hr;
+    FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface, PaletteNumber, pEntries);
 
-    TRACE("iface %p, palette_idx %u, entries %p.\n", iface, PaletteNumber, pEntries);
-
-    wined3d_mutex_lock();
-    hr = wined3d_device_get_palette_entries(This->wined3d_device, PaletteNumber, pEntries);
-    wined3d_mutex_unlock();
-
-    return hr;
+    return D3DERR_INVALIDCALL;
 }
 
 static HRESULT WINAPI IDirect3DDevice9Impl_SetCurrentTexturePalette(IDirect3DDevice9Ex *iface,
         UINT PaletteNumber)
 {
-    IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
-    HRESULT hr;
+    FIXME("iface %p, palette_idx %u unimplemented.\n", iface, PaletteNumber);
 
-    TRACE("iface %p, palette_idx %u.\n", iface, PaletteNumber);
-
-    wined3d_mutex_lock();
-    hr = wined3d_device_set_current_texture_palette(This->wined3d_device, PaletteNumber);
-    wined3d_mutex_unlock();
-
-    return hr;
+    return D3DERR_INVALIDCALL;
 }
 
 static HRESULT WINAPI IDirect3DDevice9Impl_GetCurrentTexturePalette(IDirect3DDevice9Ex *iface,
         UINT *PaletteNumber)
 {
-    IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
-    HRESULT hr;
+    FIXME("iface %p, palette_idx %p.\n", iface, PaletteNumber);
 
-    TRACE("iface %p, palette_idx %p.\n", iface, PaletteNumber);
-
-    wined3d_mutex_lock();
-    hr = wined3d_device_get_current_texture_palette(This->wined3d_device, PaletteNumber);
-    wined3d_mutex_unlock();
-
-    return hr;
+    return D3DERR_INVALIDCALL;
 }
 
 static HRESULT WINAPI IDirect3DDevice9Impl_SetScissorRect(IDirect3DDevice9Ex *iface,
@@ -2065,9 +2027,9 @@ static HRESULT WINAPI IDirect3DDevice9Impl_ProcessVertices(IDirect3DDevice9Ex *i
         IDirect3DVertexDeclaration9 *pVertexDecl, DWORD Flags)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
+    IDirect3DVertexBuffer9Impl *dest = unsafe_impl_from_IDirect3DVertexBuffer9(pDestBuffer);
     IDirect3DVertexDeclaration9Impl *Decl = (IDirect3DVertexDeclaration9Impl *) pVertexDecl;
     HRESULT hr;
-    IDirect3DVertexBuffer9Impl *dest = (IDirect3DVertexBuffer9Impl *) pDestBuffer;
 
     TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
             iface, SrcStartIndex, DestIndex, VertexCount, pDestBuffer, pVertexDecl, Flags);
@@ -2305,7 +2267,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreateVertexShader(IDirect3DDevice9Ex
     }
 
     TRACE("Created vertex shader %p.\n", object);
-    *shader = (IDirect3DVertexShader9 *)object;
+    *shader = &object->IDirect3DVertexShader9_iface;
 
     return D3D_OK;
 }
@@ -2314,13 +2276,14 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetVertexShader(IDirect3DDevice9Ex *i
         IDirect3DVertexShader9 *shader)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
+    IDirect3DVertexShader9Impl *shader_obj = unsafe_impl_from_IDirect3DVertexShader9(shader);
     HRESULT hr;
 
     TRACE("iface %p, shader %p.\n", iface, shader);
 
     wined3d_mutex_lock();
     hr =  wined3d_device_set_vertex_shader(This->wined3d_device,
-            shader ? ((IDirect3DVertexShader9Impl *)shader)->wined3d_shader : NULL);
+            shader_obj ? shader_obj->wined3d_shader : NULL);
     wined3d_mutex_unlock();
 
     return hr;
@@ -2461,6 +2424,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(IDirect3DDevice9Ex *i
         UINT StreamNumber, IDirect3DVertexBuffer9 *pStreamData, UINT OffsetInBytes, UINT Stride)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
+    IDirect3DVertexBuffer9Impl *streamdata = unsafe_impl_from_IDirect3DVertexBuffer9(pStreamData);
     HRESULT hr;
 
     TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
@@ -2468,7 +2432,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetStreamSource(IDirect3DDevice9Ex *i
 
     wined3d_mutex_lock();
     hr = wined3d_device_set_stream_source(This->wined3d_device, StreamNumber,
-            pStreamData ? ((IDirect3DVertexBuffer9Impl *)pStreamData)->wineD3DVertexBuffer : NULL,
+            streamdata ? streamdata->wineD3DVertexBuffer : NULL,
             OffsetInBytes, Stride);
     wined3d_mutex_unlock();
 
@@ -2544,8 +2508,8 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetIndices(IDirect3DDevice9Ex *iface,
         IDirect3DIndexBuffer9 *pIndexData)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
+    IDirect3DIndexBuffer9Impl *ib = unsafe_impl_from_IDirect3DIndexBuffer9(pIndexData);
     HRESULT hr;
-    IDirect3DIndexBuffer9Impl *ib = (IDirect3DIndexBuffer9Impl *) pIndexData;
 
     TRACE("iface %p, buffer %p.\n", iface, pIndexData);
 
@@ -2614,7 +2578,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_CreatePixelShader(IDirect3DDevice9Ex
     }
 
     TRACE("Created pixel shader %p.\n", object);
-    *shader = (IDirect3DPixelShader9 *)object;
+    *shader = &object->IDirect3DPixelShader9_iface;
 
     return D3D_OK;
 }
@@ -2623,13 +2587,14 @@ static HRESULT WINAPI IDirect3DDevice9Impl_SetPixelShader(IDirect3DDevice9Ex *if
         IDirect3DPixelShader9 *shader)
 {
     IDirect3DDevice9Impl *This = impl_from_IDirect3DDevice9Ex(iface);
+    IDirect3DPixelShader9Impl *shader_obj = unsafe_impl_from_IDirect3DPixelShader9(shader);
     HRESULT hr;
 
     TRACE("iface %p, shader %p.\n", iface, shader);
 
     wined3d_mutex_lock();
     hr = wined3d_device_set_pixel_shader(This->wined3d_device,
-            shader ? ((IDirect3DPixelShader9Impl *)shader)->wined3d_shader : NULL);
+            shader_obj ? shader_obj->wined3d_shader : NULL);
     wined3d_mutex_unlock();
 
     return hr;
@@ -2765,7 +2730,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_DrawRectPatch(IDirect3DDevice9Ex *ifa
 
     wined3d_mutex_lock();
     hr = wined3d_device_draw_rect_patch(This->wined3d_device, Handle,
-            pNumSegs, (const WINED3DRECTPATCH_INFO *)pRectPatchInfo);
+            pNumSegs, (const struct wined3d_rect_patch_info *)pRectPatchInfo);
     wined3d_mutex_unlock();
 
     return hr;
@@ -2782,7 +2747,7 @@ static HRESULT WINAPI IDirect3DDevice9Impl_DrawTriPatch(IDirect3DDevice9Ex *ifac
 
     wined3d_mutex_lock();
     hr = wined3d_device_draw_tri_patch(This->wined3d_device, Handle,
-            pNumSegs, (const WINED3DTRIPATCH_INFO *)pTriPatchInfo);
+            pNumSegs, (const struct wined3d_tri_patch_info *)pTriPatchInfo);
     wined3d_mutex_unlock();
 
     return hr;
@@ -2931,6 +2896,9 @@ static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateRenderTargetEx(IDirect3DDevic
             iface, width, height, format, multisample_type, multisample_quality,
             lockable, surface, shared_handle, usage);
 
+    if (shared_handle)
+        FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
+
     return E_NOTIMPL;
 }
 
@@ -2953,6 +2921,9 @@ static HRESULT WINAPI IDirect3DDevice9ExImpl_CreateDepthStencilSurfaceEx(IDirect
             iface, width, height, format, multisample_type, multisample_quality,
             discard, surface, shared_handle, usage);
 
+    if (shared_handle)
+        FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
+
     return E_NOTIMPL;
 }
 
@@ -3124,9 +3095,14 @@ static void CDECL device_parent_wined3d_device_created(struct wined3d_device_par
     TRACE("device_parent %p, device %p.\n", device_parent, device);
 }
 
+static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
+{
+    TRACE("device_parent %p.\n", device_parent);
+}
+
 static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent *device_parent,
         void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
-        WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, struct wined3d_surface **surface)
+        enum wined3d_pool pool, UINT level, enum wined3d_cubemap_face face, struct wined3d_surface **surface)
 {
     struct IDirect3DDevice9Impl *device = device_from_device_parent(device_parent);
     IDirect3DSurface9Impl *d3d_surface;
@@ -3137,7 +3113,7 @@ static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent *
             "\tpool %#x, level %u, face %u, surface %p.\n",
             device_parent, container_parent, width, height, format, usage, pool, level, face, surface);
 
-    if (pool == WINED3DPOOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC))
+    if (pool == WINED3D_POOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC))
         lockable = FALSE;
 
     hr = IDirect3DDevice9Impl_CreateSurface(device, width, height,
@@ -3156,7 +3132,7 @@ static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent *
     IDirect3DDevice9Ex_Release(d3d_surface->parentDevice);
     d3d_surface->parentDevice = NULL;
 
-    IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
+    IDirect3DSurface9_Release(&d3d_surface->IDirect3DSurface9_iface);
     d3d_surface->forwardReference = container_parent;
 
     return hr;
@@ -3164,7 +3140,7 @@ static HRESULT CDECL device_parent_create_surface(struct wined3d_device_parent *
 
 static HRESULT CDECL device_parent_create_rendertarget(struct wined3d_device_parent *device_parent,
         void *container_parent, UINT width, UINT height, enum wined3d_format_id format,
-        WINED3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality, BOOL lockable,
+        enum wined3d_multisample_type multisample_type, DWORD multisample_quality, BOOL lockable,
         struct wined3d_surface **surface)
 {
     struct IDirect3DDevice9Impl *device = device_from_device_parent(device_parent);
@@ -3190,13 +3166,13 @@ static HRESULT CDECL device_parent_create_rendertarget(struct wined3d_device_par
 
     d3d_surface->container = container_parent;
     /* Implicit surfaces are created with an refcount of 0 */
-    IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
+    IDirect3DSurface9_Release(&d3d_surface->IDirect3DSurface9_iface);
 
     return hr;
 }
 
 static HRESULT CDECL device_parent_create_depth_stencil(struct wined3d_device_parent *device_parent,
-        UINT width, UINT height, enum wined3d_format_id format, WINED3DMULTISAMPLE_TYPE multisample_type,
+        UINT width, UINT height, enum wined3d_format_id format, enum wined3d_multisample_type multisample_type,
         DWORD multisample_quality, BOOL discard, struct wined3d_surface **surface)
 {
     struct IDirect3DDevice9Impl *device = device_from_device_parent(device_parent);
@@ -3220,14 +3196,14 @@ static HRESULT CDECL device_parent_create_depth_stencil(struct wined3d_device_pa
     wined3d_surface_incref(*surface);
     d3d_surface->container = (IUnknown *)&device->IDirect3DDevice9Ex_iface;
     /* Implicit surfaces are created with an refcount of 0 */
-    IDirect3DSurface9_Release((IDirect3DSurface9 *)d3d_surface);
+    IDirect3DSurface9_Release(&d3d_surface->IDirect3DSurface9_iface);
 
     return hr;
 }
 
 static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *device_parent,
         void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
-        WINED3DPOOL pool, DWORD usage, struct wined3d_volume **volume)
+        enum wined3d_pool pool, DWORD usage, struct wined3d_volume **volume)
 {
     struct IDirect3DDevice9Impl *device = device_from_device_parent(device_parent);
     IDirect3DVolume9Impl *object;
@@ -3268,30 +3244,30 @@ static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *d
 }
 
 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
-        WINED3DPRESENT_PARAMETERS *present_parameters, struct wined3d_swapchain **swapchain)
+        struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
 {
     struct IDirect3DDevice9Impl *device = device_from_device_parent(device_parent);
     D3DPRESENT_PARAMETERS local_parameters;
     IDirect3DSwapChain9 *d3d_swapchain;
     HRESULT hr;
 
-    TRACE("device_parent %p, present_parameters %p, swapchain %p\n", device_parent, present_parameters, swapchain);
+    TRACE("device_parent %p, desc %p, swapchain %p\n", device_parent, desc, swapchain);
 
     /* Copy the presentation parameters */
-    local_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
-    local_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
-    local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(present_parameters->BackBufferFormat);
-    local_parameters.BackBufferCount = present_parameters->BackBufferCount;
-    local_parameters.MultiSampleType = present_parameters->MultiSampleType;
-    local_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
-    local_parameters.SwapEffect = present_parameters->SwapEffect;
-    local_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
-    local_parameters.Windowed = present_parameters->Windowed;
-    local_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
-    local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(present_parameters->AutoDepthStencilFormat);
-    local_parameters.Flags = present_parameters->Flags;
-    local_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
-    local_parameters.PresentationInterval = present_parameters->PresentationInterval;
+    local_parameters.BackBufferWidth = desc->backbuffer_width;
+    local_parameters.BackBufferHeight = desc->backbuffer_height;
+    local_parameters.BackBufferFormat = d3dformat_from_wined3dformat(desc->backbuffer_format);
+    local_parameters.BackBufferCount = desc->backbuffer_count;
+    local_parameters.MultiSampleType = desc->multisample_type;
+    local_parameters.MultiSampleQuality = desc->multisample_quality;
+    local_parameters.SwapEffect = desc->swap_effect;
+    local_parameters.hDeviceWindow = desc->device_window;
+    local_parameters.Windowed = desc->windowed;
+    local_parameters.EnableAutoDepthStencil = desc->enable_auto_depth_stencil;
+    local_parameters.AutoDepthStencilFormat = d3dformat_from_wined3dformat(desc->auto_depth_stencil_format);
+    local_parameters.Flags = desc->flags;
+    local_parameters.FullScreen_RefreshRateInHz = desc->refresh_rate;
+    local_parameters.PresentationInterval = desc->swap_interval;
 
     hr = IDirect3DDevice9Impl_CreateAdditionalSwapChain(&device->IDirect3DDevice9Ex_iface,
             &local_parameters, &d3d_swapchain);
@@ -3307,20 +3283,20 @@ static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent
     IDirect3DSwapChain9_Release((IDirect3DSwapChain9 *)d3d_swapchain);
 
     /* Copy back the presentation parameters */
-    present_parameters->BackBufferWidth = local_parameters.BackBufferWidth;
-    present_parameters->BackBufferHeight = local_parameters.BackBufferHeight;
-    present_parameters->BackBufferFormat = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
-    present_parameters->BackBufferCount = local_parameters.BackBufferCount;
-    present_parameters->MultiSampleType = local_parameters.MultiSampleType;
-    present_parameters->MultiSampleQuality = local_parameters.MultiSampleQuality;
-    present_parameters->SwapEffect = local_parameters.SwapEffect;
-    present_parameters->hDeviceWindow = local_parameters.hDeviceWindow;
-    present_parameters->Windowed = local_parameters.Windowed;
-    present_parameters->EnableAutoDepthStencil = local_parameters.EnableAutoDepthStencil;
-    present_parameters->AutoDepthStencilFormat = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
-    present_parameters->Flags = local_parameters.Flags;
-    present_parameters->FullScreen_RefreshRateInHz = local_parameters.FullScreen_RefreshRateInHz;
-    present_parameters->PresentationInterval = local_parameters.PresentationInterval;
+    desc->backbuffer_width = local_parameters.BackBufferWidth;
+    desc->backbuffer_height = local_parameters.BackBufferHeight;
+    desc->backbuffer_format = wined3dformat_from_d3dformat(local_parameters.BackBufferFormat);
+    desc->backbuffer_count = local_parameters.BackBufferCount;
+    desc->multisample_type = local_parameters.MultiSampleType;
+    desc->multisample_quality = local_parameters.MultiSampleQuality;
+    desc->swap_effect = local_parameters.SwapEffect;
+    desc->device_window = local_parameters.hDeviceWindow;
+    desc->windowed = local_parameters.Windowed;
+    desc->enable_auto_depth_stencil = local_parameters.EnableAutoDepthStencil;
+    desc->auto_depth_stencil_format = wined3dformat_from_d3dformat(local_parameters.AutoDepthStencilFormat);
+    desc->flags = local_parameters.Flags;
+    desc->refresh_rate = local_parameters.FullScreen_RefreshRateInHz;
+    desc->swap_interval = local_parameters.PresentationInterval;
 
     return hr;
 }
@@ -3328,6 +3304,7 @@ static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent
 static const struct wined3d_device_parent_ops d3d9_wined3d_device_parent_ops =
 {
     device_parent_wined3d_device_created,
+    device_parent_mode_changed,
     device_parent_create_surface,
     device_parent_create_rendertarget,
     device_parent_create_depth_stencil,
@@ -3342,15 +3319,21 @@ static void setup_fpu(void)
     __asm__ volatile ("fnstcw %0" : "=m" (cw));
     cw = (cw & ~0xf3f) | 0x3f;
     __asm__ volatile ("fldcw %0" : : "m" (cw));
+#elif defined(__i386__) && defined(_MSC_VER)
+    WORD cw;
+    __asm fnstcw cw;
+    cw = (cw & ~0xf3f) | 0x3f;
+    __asm fldcw cw;
 #else
     FIXME("FPU setup not implemented for this platform.\n");
 #endif
 }
 
-HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT adapter, D3DDEVTYPE device_type,
-        HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode)
+HRESULT device_init(IDirect3DDevice9Impl *device, IDirect3D9Impl *parent, struct wined3d *wined3d,
+        UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags,
+        D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode)
 {
-    WINED3DPRESENT_PARAMETERS *wined3d_parameters;
+    struct wined3d_swapchain_desc *swapchain_desc;
     UINT i, count = 1;
     HRESULT hr;
 
@@ -3364,7 +3347,7 @@ HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT
     if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
 
     wined3d_mutex_lock();
-    hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags,
+    hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags, 4,
             &device->device_parent, &device->wined3d_device);
     if (FAILED(hr))
     {
@@ -3407,8 +3390,8 @@ HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT
         }
     }
 
-    wined3d_parameters = HeapAlloc(GetProcessHeap(), 0, sizeof(*wined3d_parameters) * count);
-    if (!wined3d_parameters)
+    swapchain_desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain_desc) * count);
+    if (!swapchain_desc)
     {
         ERR("Failed to allocate wined3d parameters.\n");
         wined3d_device_decref(device->wined3d_device);
@@ -3418,30 +3401,30 @@ HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT
 
     for (i = 0; i < count; ++i)
     {
-        wined3d_parameters[i].BackBufferWidth = parameters[i].BackBufferWidth;
-        wined3d_parameters[i].BackBufferHeight = parameters[i].BackBufferHeight;
-        wined3d_parameters[i].BackBufferFormat = wined3dformat_from_d3dformat(parameters[i].BackBufferFormat);
-        wined3d_parameters[i].BackBufferCount = parameters[i].BackBufferCount;
-        wined3d_parameters[i].MultiSampleType = parameters[i].MultiSampleType;
-        wined3d_parameters[i].MultiSampleQuality = parameters[i].MultiSampleQuality;
-        wined3d_parameters[i].SwapEffect = parameters[i].SwapEffect;
-        wined3d_parameters[i].hDeviceWindow = parameters[i].hDeviceWindow;
-        wined3d_parameters[i].Windowed = parameters[i].Windowed;
-        wined3d_parameters[i].EnableAutoDepthStencil = parameters[i].EnableAutoDepthStencil;
-        wined3d_parameters[i].AutoDepthStencilFormat =
+        swapchain_desc[i].backbuffer_width = parameters[i].BackBufferWidth;
+        swapchain_desc[i].backbuffer_height = parameters[i].BackBufferHeight;
+        swapchain_desc[i].backbuffer_format = wined3dformat_from_d3dformat(parameters[i].BackBufferFormat);
+        swapchain_desc[i].backbuffer_count = parameters[i].BackBufferCount;
+        swapchain_desc[i].multisample_type = parameters[i].MultiSampleType;
+        swapchain_desc[i].multisample_quality = parameters[i].MultiSampleQuality;
+        swapchain_desc[i].swap_effect = parameters[i].SwapEffect;
+        swapchain_desc[i].device_window = parameters[i].hDeviceWindow;
+        swapchain_desc[i].windowed = parameters[i].Windowed;
+        swapchain_desc[i].enable_auto_depth_stencil = parameters[i].EnableAutoDepthStencil;
+        swapchain_desc[i].auto_depth_stencil_format =
                 wined3dformat_from_d3dformat(parameters[i].AutoDepthStencilFormat);
-        wined3d_parameters[i].Flags = parameters[i].Flags;
-        wined3d_parameters[i].FullScreen_RefreshRateInHz = parameters[i].FullScreen_RefreshRateInHz;
-        wined3d_parameters[i].PresentationInterval = parameters[i].PresentationInterval;
-        wined3d_parameters[i].AutoRestoreDisplayMode = TRUE;
+        swapchain_desc[i].flags = parameters[i].Flags;
+        swapchain_desc[i].refresh_rate = parameters[i].FullScreen_RefreshRateInHz;
+        swapchain_desc[i].swap_interval = parameters[i].PresentationInterval;
+        swapchain_desc[i].auto_restore_display_mode = TRUE;
     }
 
-    hr = wined3d_device_init_3d(device->wined3d_device, wined3d_parameters);
+    hr = wined3d_device_init_3d(device->wined3d_device, swapchain_desc);
     if (FAILED(hr))
     {
         WARN("Failed to initialize 3D, hr %#x.\n", hr);
         wined3d_device_release_focus_window(device->wined3d_device);
-        HeapFree(GetProcessHeap(), 0, wined3d_parameters);
+        HeapFree(GetProcessHeap(), 0, swapchain_desc);
         wined3d_device_decref(device->wined3d_device);
         wined3d_mutex_unlock();
         return hr;
@@ -3451,23 +3434,23 @@ HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT
 
     for (i = 0; i < count; ++i)
     {
-        parameters[i].BackBufferWidth = wined3d_parameters[i].BackBufferWidth;
-        parameters[i].BackBufferHeight = wined3d_parameters[i].BackBufferHeight;
-        parameters[i].BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters[i].BackBufferFormat);
-        parameters[i].BackBufferCount = wined3d_parameters[i].BackBufferCount;
-        parameters[i].MultiSampleType = wined3d_parameters[i].MultiSampleType;
-        parameters[i].MultiSampleQuality = wined3d_parameters[i].MultiSampleQuality;
-        parameters[i].SwapEffect = wined3d_parameters[i].SwapEffect;
-        parameters[i].hDeviceWindow = wined3d_parameters[i].hDeviceWindow;
-        parameters[i].Windowed = wined3d_parameters[i].Windowed;
-        parameters[i].EnableAutoDepthStencil = wined3d_parameters[i].EnableAutoDepthStencil;
+        parameters[i].BackBufferWidth = swapchain_desc[i].backbuffer_width;
+        parameters[i].BackBufferHeight = swapchain_desc[i].backbuffer_height;
+        parameters[i].BackBufferFormat = d3dformat_from_wined3dformat(swapchain_desc[i].backbuffer_format);
+        parameters[i].BackBufferCount = swapchain_desc[i].backbuffer_count;
+        parameters[i].MultiSampleType = swapchain_desc[i].multisample_type;
+        parameters[i].MultiSampleQuality = swapchain_desc[i].multisample_quality;
+        parameters[i].SwapEffect = swapchain_desc[i].swap_effect;
+        parameters[i].hDeviceWindow = swapchain_desc[i].device_window;
+        parameters[i].Windowed = swapchain_desc[i].windowed;
+        parameters[i].EnableAutoDepthStencil = swapchain_desc[i].enable_auto_depth_stencil;
         parameters[i].AutoDepthStencilFormat =
-                d3dformat_from_wined3dformat(wined3d_parameters[i].AutoDepthStencilFormat);
-        parameters[i].Flags = wined3d_parameters[i].Flags;
-        parameters[i].FullScreen_RefreshRateInHz = wined3d_parameters[i].FullScreen_RefreshRateInHz;
-        parameters[i].PresentationInterval = wined3d_parameters[i].PresentationInterval;
+                d3dformat_from_wined3dformat(swapchain_desc[i].auto_depth_stencil_format);
+        parameters[i].Flags = swapchain_desc[i].flags;
+        parameters[i].FullScreen_RefreshRateInHz = swapchain_desc[i].refresh_rate;
+        parameters[i].PresentationInterval = swapchain_desc[i].swap_interval;
     }
-    HeapFree(GetProcessHeap(), 0, wined3d_parameters);
+    HeapFree(GetProcessHeap(), 0, swapchain_desc);
 
     /* Initialize the converted declaration array. This creates a valid pointer
      * and when adding decls HeapReAlloc() can be used without further checking. */
@@ -3483,5 +3466,8 @@ HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT
         return E_OUTOFMEMORY;
     }
 
+    device->d3d_parent = &parent->IDirect3D9Ex_iface;
+    IDirect3D9_AddRef(device->d3d_parent);
+
     return D3D_OK;
 }
index 7a22c30..218676a 100644 (file)
@@ -103,25 +103,25 @@ static HRESULT  WINAPI  IDirect3D9Impl_RegisterSoftwareDevice(IDirect3D9Ex *ifac
     return hr;
 }
 
-static UINT     WINAPI  IDirect3D9Impl_GetAdapterCount(IDirect3D9Ex *iface)
+static UINT WINAPI IDirect3D9Impl_GetAdapterCount(IDirect3D9Ex *iface)
 {
     IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
-    HRESULT hr;
+    UINT ret;
 
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    hr = wined3d_get_adapter_count(This->WineD3D);
+    ret = wined3d_get_adapter_count(This->WineD3D);
     wined3d_mutex_unlock();
 
-    return hr;
+    return ret;
 }
 
 static HRESULT WINAPI IDirect3D9Impl_GetAdapterIdentifier(IDirect3D9Ex *iface, UINT Adapter,
         DWORD Flags, D3DADAPTER_IDENTIFIER9 *pIdentifier)
 {
     IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
-    WINED3DADAPTER_IDENTIFIER adapter_id;
+    struct wined3d_adapter_identifier adapter_id;
     HRESULT hr;
 
     TRACE("iface %p, adapter %u, flags %#x, identifier %p.\n",
@@ -153,7 +153,7 @@ static UINT WINAPI IDirect3D9Impl_GetAdapterModeCount(IDirect3D9Ex *iface, UINT
         D3DFORMAT Format)
 {
     IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
-    HRESULT hr;
+    UINT ret;
 
     TRACE("iface %p, adapter %u, format %#x.\n", iface, Adapter, Format);
 
@@ -163,10 +163,10 @@ static UINT WINAPI IDirect3D9Impl_GetAdapterModeCount(IDirect3D9Ex *iface, UINT
     }
 
     wined3d_mutex_lock();
-    hr = wined3d_get_adapter_mode_count(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format));
+    ret = wined3d_get_adapter_mode_count(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format));
     wined3d_mutex_unlock();
 
-    return hr;
+    return ret;
 }
 
 static HRESULT WINAPI IDirect3D9Impl_EnumAdapterModes(IDirect3D9Ex *iface, UINT Adapter,
@@ -185,7 +185,7 @@ static HRESULT WINAPI IDirect3D9Impl_EnumAdapterModes(IDirect3D9Ex *iface, UINT
 
     wined3d_mutex_lock();
     hr = wined3d_enum_adapter_modes(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format),
-            Mode, (WINED3DDISPLAYMODE *) pMode);
+            Mode, (struct wined3d_display_mode *)pMode);
     wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -202,7 +202,7 @@ static HRESULT WINAPI IDirect3D9Impl_GetAdapterDisplayMode(IDirect3D9Ex *iface,
     TRACE("iface %p, adapter %u, mode %p.\n", iface, Adapter, pMode);
 
     wined3d_mutex_lock();
-    hr = wined3d_get_adapter_display_mode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *)pMode);
+    hr = wined3d_get_adapter_display_mode(This->WineD3D, Adapter, (struct wined3d_display_mode *)pMode);
     wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -232,38 +232,26 @@ static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormat(IDirect3D9Ex *iface, UINT
         D3DFORMAT CheckFormat)
 {
     IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
+    enum wined3d_resource_type wined3d_rtype;
     HRESULT hr;
-    WINED3DRESOURCETYPE WineD3DRType;
 
     TRACE("iface %p, adapter %u, device_type %#x, adapter_format %#x, usage %#x, resource_type %#x, format %#x.\n",
             iface, Adapter, DeviceType, AdapterFormat, Usage, RType, CheckFormat);
 
-    /* This format is nothing special and it is supported perfectly.
-     * However, ati and nvidia driver on windows do not mark this format as
-     * supported (tested with the dxCapsViewer) and pretending to
-     * support this format uncovers a bug in Battlefield 1942 (fonts are missing)
-     * So do the same as Windows drivers and pretend not to support it on dx8 and 9
-     */
-    if(CheckFormat == D3DFMT_R8G8B8)
-    {
-        WARN("D3DFMT_R8G8B8 is not available on windows, returning D3DERR_NOTAVAILABLE\n");
-        return D3DERR_NOTAVAILABLE;
-    }
-
     switch(RType) {
         case D3DRTYPE_VERTEXBUFFER:
         case D3DRTYPE_INDEXBUFFER:
-            WineD3DRType = WINED3DRTYPE_BUFFER;
+            wined3d_rtype = WINED3D_RTYPE_BUFFER;
             break;
 
         default:
-            WineD3DRType = RType;
+            wined3d_rtype = RType;
             break;
     }
 
     wined3d_mutex_lock();
     hr = wined3d_check_device_format(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
-            Usage, WineD3DRType, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL);
+            Usage, wined3d_rtype, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL);
     wined3d_mutex_unlock();
 
     return hr;
@@ -325,7 +313,8 @@ static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormatConversion(IDirect3D9Ex *i
 
 void filter_caps(D3DCAPS9* pCaps)
 {
-
+    DWORD ps_minor_version[] = {0, 4, 0, 0};
+    DWORD vs_minor_version[] = {0, 1, 0, 0};
     DWORD textureFilterCaps =
         D3DPTFILTERCAPS_MINFPOINT      | D3DPTFILTERCAPS_MINFLINEAR    | D3DPTFILTERCAPS_MINFANISOTROPIC |
         D3DPTFILTERCAPS_MINFPYRAMIDALQUAD                              | D3DPTFILTERCAPS_MINFGAUSSIANQUAD|
@@ -381,6 +370,22 @@ void filter_caps(D3DCAPS9* pCaps)
 
     pCaps->MaxVertexShaderConst = min(D3D9_MAX_VERTEX_SHADER_CONSTANTF, pCaps->MaxVertexShaderConst);
     pCaps->NumSimultaneousRTs = min(D3D9_MAX_SIMULTANEOUS_RENDERTARGETS, pCaps->NumSimultaneousRTs);
+
+    if (pCaps->PixelShaderVersion > 3)
+        pCaps->PixelShaderVersion = D3DPS_VERSION(3,0);
+    else
+    {
+        DWORD major = pCaps->PixelShaderVersion;
+        pCaps->PixelShaderVersion = D3DPS_VERSION(major,ps_minor_version[major]);
+    }
+
+    if (pCaps->VertexShaderVersion > 3)
+        pCaps->VertexShaderVersion = D3DVS_VERSION(3,0);
+    else
+    {
+        DWORD major = pCaps->VertexShaderVersion;
+        pCaps->VertexShaderVersion = D3DVS_VERSION(major,vs_minor_version[major]);
+    }
 }
 
 static HRESULT WINAPI IDirect3D9Impl_GetDeviceCaps(IDirect3D9Ex *iface, UINT Adapter,
@@ -449,7 +454,7 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9Impl_CreateDevice(IDirect3D9Ex
         return E_OUTOFMEMORY;
     }
 
-    hr = device_init(object, This->WineD3D, adapter, device_type, focus_window, flags, parameters, NULL);
+    hr = device_init(object, This, This->WineD3D, adapter, device_type, focus_window, flags, parameters, NULL);
     if (FAILED(hr))
     {
         WARN("Failed to initialize device, hr %#x.\n", hr);
@@ -468,7 +473,7 @@ static UINT WINAPI IDirect3D9ExImpl_GetAdapterModeCountEx(IDirect3D9Ex *iface,
 {
     FIXME("iface %p, adapter %u, filter %p stub!\n", iface, adapter, filter);
 
-    return E_NOTIMPL;
+    return 0;
 }
 
 static HRESULT WINAPI IDirect3D9ExImpl_EnumAdapterModesEx(IDirect3D9Ex *iface,
@@ -507,7 +512,7 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9ExImpl_CreateDeviceEx(IDirect3
         return E_OUTOFMEMORY;
     }
 
-    hr = device_init(object, d3d9->WineD3D, adapter, device_type, focus_window, flags, parameters, mode);
+    hr = device_init(object, d3d9, d3d9->WineD3D, adapter, device_type, focus_window, flags, parameters, mode);
     if (FAILED(hr))
     {
         WARN("Failed to initialize device, hr %#x.\n", hr);
@@ -524,7 +529,7 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9ExImpl_CreateDeviceEx(IDirect3
 static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterLUID(IDirect3D9Ex *iface, UINT adapter, LUID *luid)
 {
     IDirect3D9Impl *This = impl_from_IDirect3D9Ex(iface);
-    WINED3DADAPTER_IDENTIFIER adapter_id;
+    struct wined3d_adapter_identifier adapter_id;
     HRESULT hr;
 
     TRACE("iface %p, adapter %u, luid %p.\n", iface, adapter, luid);
index c36600d..b9de07c 100644 (file)
  */
 
 #include "config.h"
+#include <assert.h>
 #include "d3d9_private.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
 
+static inline IDirect3DVertexShader9Impl *impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface)
+{
+    return CONTAINING_RECORD(iface, IDirect3DVertexShader9Impl, IDirect3DVertexShader9_iface);
+}
+
 static HRESULT WINAPI d3d9_vertexshader_QueryInterface(IDirect3DVertexShader9 *iface, REFIID riid, void **object)
 {
     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
@@ -42,7 +48,7 @@ static HRESULT WINAPI d3d9_vertexshader_QueryInterface(IDirect3DVertexShader9 *i
 
 static ULONG WINAPI d3d9_vertexshader_AddRef(IDirect3DVertexShader9 *iface)
 {
-    IDirect3DVertexShader9Impl *shader = (IDirect3DVertexShader9Impl *)iface;
+    IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface);
     ULONG refcount = InterlockedIncrement(&shader->ref);
 
     TRACE("%p increasing refcount to %u.\n", iface, refcount);
@@ -60,7 +66,7 @@ static ULONG WINAPI d3d9_vertexshader_AddRef(IDirect3DVertexShader9 *iface)
 
 static ULONG WINAPI d3d9_vertexshader_Release(IDirect3DVertexShader9 *iface)
 {
-    IDirect3DVertexShader9Impl *shader = (IDirect3DVertexShader9Impl *)iface;
+    IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface);
     ULONG refcount = InterlockedDecrement(&shader->ref);
 
     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
@@ -82,9 +88,11 @@ static ULONG WINAPI d3d9_vertexshader_Release(IDirect3DVertexShader9 *iface)
 
 static HRESULT WINAPI d3d9_vertexshader_GetDevice(IDirect3DVertexShader9 *iface, IDirect3DDevice9 **device)
 {
+    IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface);
+
     TRACE("iface %p, device %p.\n", iface, device);
 
-    *device = (IDirect3DDevice9 *)((IDirect3DVertexShader9Impl *)iface)->parentDevice;
+    *device = (IDirect3DDevice9 *)shader->parentDevice;
     IDirect3DDevice9_AddRef(*device);
 
     TRACE("Returning device %p.\n", *device);
@@ -95,12 +103,13 @@ static HRESULT WINAPI d3d9_vertexshader_GetDevice(IDirect3DVertexShader9 *iface,
 static HRESULT WINAPI d3d9_vertexshader_GetFunction(IDirect3DVertexShader9 *iface,
         void *data, UINT *data_size)
 {
+    IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface);
     HRESULT hr;
 
     TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size);
 
     wined3d_mutex_lock();
-    hr = wined3d_shader_get_byte_code(((IDirect3DVertexShader9Impl *)iface)->wined3d_shader, data, data_size);
+    hr = wined3d_shader_get_byte_code(shader->wined3d_shader, data, data_size);
     wined3d_mutex_unlock();
 
     return hr;
@@ -132,11 +141,11 @@ HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader, IDirect3DDevice9Im
     HRESULT hr;
 
     shader->ref = 1;
-    shader->lpVtbl = &d3d9_vertexshader_vtbl;
+    shader->IDirect3DVertexShader9_iface.lpVtbl = &d3d9_vertexshader_vtbl;
 
     wined3d_mutex_lock();
     hr = wined3d_shader_create_vs(device->wined3d_device, byte_code, NULL,
-            shader, &d3d9_vertexshader_wined3d_parent_ops, &shader->wined3d_shader);
+            shader, &d3d9_vertexshader_wined3d_parent_ops, &shader->wined3d_shader, 3);
     wined3d_mutex_unlock();
     if (FAILED(hr))
     {
@@ -150,6 +159,20 @@ HRESULT vertexshader_init(IDirect3DVertexShader9Impl *shader, IDirect3DDevice9Im
     return D3D_OK;
 }
 
+IDirect3DVertexShader9Impl *unsafe_impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface)
+{
+    if (!iface)
+        return NULL;
+    assert(iface->lpVtbl == &d3d9_vertexshader_vtbl);
+
+    return impl_from_IDirect3DVertexShader9(iface);
+}
+
+static inline IDirect3DPixelShader9Impl *impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface)
+{
+    return CONTAINING_RECORD(iface, IDirect3DPixelShader9Impl, IDirect3DPixelShader9_iface);
+}
+
 static HRESULT WINAPI d3d9_pixelshader_QueryInterface(IDirect3DPixelShader9 *iface, REFIID riid, void **object)
 {
     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
@@ -170,7 +193,7 @@ static HRESULT WINAPI d3d9_pixelshader_QueryInterface(IDirect3DPixelShader9 *ifa
 
 static ULONG WINAPI d3d9_pixelshader_AddRef(IDirect3DPixelShader9 *iface)
 {
-    IDirect3DPixelShader9Impl *shader = (IDirect3DPixelShader9Impl *)iface;
+    IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface);
     ULONG refcount = InterlockedIncrement(&shader->ref);
 
     TRACE("%p increasing refcount to %u.\n", iface, refcount);
@@ -188,7 +211,7 @@ static ULONG WINAPI d3d9_pixelshader_AddRef(IDirect3DPixelShader9 *iface)
 
 static ULONG WINAPI d3d9_pixelshader_Release(IDirect3DPixelShader9 *iface)
 {
-    IDirect3DPixelShader9Impl *shader = (IDirect3DPixelShader9Impl *)iface;
+    IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface);
     ULONG refcount = InterlockedDecrement(&shader->ref);
 
     TRACE("%p decreasing refcount to %u.\n", iface, refcount);
@@ -208,11 +231,14 @@ static ULONG WINAPI d3d9_pixelshader_Release(IDirect3DPixelShader9 *iface)
     return refcount;
 }
 
-static HRESULT WINAPI d3d9_pixelshader_GetDevice(IDirect3DPixelShader9 *iface, IDirect3DDevice9 **device)
+static HRESULT WINAPI d3d9_pixelshader_GetDevice(IDirect3DPixelShader9 *iface,
+        IDirect3DDevice9 **device)
 {
+    IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface);
+
     TRACE("iface %p, device %p.\n", iface, device);
 
-    *device = (IDirect3DDevice9 *)((IDirect3DPixelShader9Impl *)iface)->parentDevice;
+    *device = (IDirect3DDevice9 *)shader->parentDevice;
     IDirect3DDevice9_AddRef(*device);
 
     TRACE("Returning device %p.\n", *device);
@@ -220,14 +246,16 @@ static HRESULT WINAPI d3d9_pixelshader_GetDevice(IDirect3DPixelShader9 *iface, I
     return D3D_OK;
 }
 
-static HRESULT WINAPI d3d9_pixelshader_GetFunction(IDirect3DPixelShader9 *iface, void *data, UINT *data_size)
+static HRESULT WINAPI d3d9_pixelshader_GetFunction(IDirect3DPixelShader9 *iface, void *data,
+        UINT *data_size)
 {
+    IDirect3DPixelShader9Impl *shader = impl_from_IDirect3DPixelShader9(iface);
     HRESULT hr;
 
     TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size);
 
     wined3d_mutex_lock();
-    hr = wined3d_shader_get_byte_code(((IDirect3DPixelShader9Impl *)iface)->wined3d_shader, data, data_size);
+    hr = wined3d_shader_get_byte_code(shader->wined3d_shader, data, data_size);
     wined3d_mutex_unlock();
 
     return hr;
@@ -259,11 +287,11 @@ HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader, IDirect3DDevice9Impl
     HRESULT hr;
 
     shader->ref = 1;
-    shader->lpVtbl = &d3d9_pixelshader_vtbl;
+    shader->IDirect3DPixelShader9_iface.lpVtbl = &d3d9_pixelshader_vtbl;
 
     wined3d_mutex_lock();
     hr = wined3d_shader_create_ps(device->wined3d_device, byte_code, NULL, shader,
-            &d3d9_pixelshader_wined3d_parent_ops, &shader->wined3d_shader);
+            &d3d9_pixelshader_wined3d_parent_ops, &shader->wined3d_shader, 3);
     wined3d_mutex_unlock();
     if (FAILED(hr))
     {
@@ -276,3 +304,12 @@ HRESULT pixelshader_init(IDirect3DPixelShader9Impl *shader, IDirect3DDevice9Impl
 
     return D3D_OK;
 }
+
+IDirect3DPixelShader9Impl *unsafe_impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface)
+{
+    if (!iface)
+        return NULL;
+    assert(iface->lpVtbl == &d3d9_pixelshader_vtbl);
+
+    return impl_from_IDirect3DPixelShader9(iface);
+}
index 06f8aed..6ecf596 100644 (file)
@@ -150,7 +150,7 @@ HRESULT stateblock_init(IDirect3DStateBlock9Impl *stateblock, IDirect3DDevice9Im
     {
         wined3d_mutex_lock();
         hr = wined3d_stateblock_create(device->wined3d_device,
-                (WINED3DSTATEBLOCKTYPE)type, &stateblock->wined3d_stateblock);
+                (enum wined3d_stateblock_type)type, &stateblock->wined3d_stateblock);
         wined3d_mutex_unlock();
         if (FAILED(hr))
         {
index 1d66bde..cb2546f 100644 (file)
  */
 
 #include "config.h"
+#include <assert.h>
 #include "d3d9_private.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
 
+static inline IDirect3DSurface9Impl *impl_from_IDirect3DSurface9(IDirect3DSurface9 *iface)
+{
+    return CONTAINING_RECORD(iface, IDirect3DSurface9Impl, IDirect3DSurface9_iface);
+}
+
 /* IDirect3DSurface9 IUnknown parts follow: */
-static HRESULT WINAPI IDirect3DSurface9Impl_QueryInterface(LPDIRECT3DSURFACE9 iface, REFIID riid, LPVOID* ppobj) {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+static HRESULT WINAPI IDirect3DSurface9Impl_QueryInterface(IDirect3DSurface9 *iface, REFIID riid,
+        void **ppobj)
+{
+    IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface);
 
     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
 
@@ -43,8 +51,9 @@ static HRESULT WINAPI IDirect3DSurface9Impl_QueryInterface(LPDIRECT3DSURFACE9 if
     return E_NOINTERFACE;
 }
 
-static ULONG WINAPI IDirect3DSurface9Impl_AddRef(LPDIRECT3DSURFACE9 iface) {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+static ULONG WINAPI IDirect3DSurface9Impl_AddRef(IDirect3DSurface9 *iface)
+{
+    IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface);
 
     TRACE("iface %p.\n", iface);
 
@@ -71,8 +80,9 @@ static ULONG WINAPI IDirect3DSurface9Impl_AddRef(LPDIRECT3DSURFACE9 iface) {
 
 }
 
-static ULONG WINAPI IDirect3DSurface9Impl_Release(LPDIRECT3DSURFACE9 iface) {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+static ULONG WINAPI IDirect3DSurface9Impl_Release(IDirect3DSurface9 *iface)
+{
+    IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface);
 
     TRACE("iface %p.\n", iface);
 
@@ -102,9 +112,10 @@ static ULONG WINAPI IDirect3DSurface9Impl_Release(LPDIRECT3DSURFACE9 iface) {
 }
 
 /* IDirect3DSurface9 IDirect3DResource9 Interface follow: */
-static HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(IDirect3DSurface9 *iface, IDirect3DDevice9 **device)
+static HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(IDirect3DSurface9 *iface,
+        IDirect3DDevice9 **device)
 {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+    IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface);
 
     TRACE("iface %p, device %p.\n", iface, device);
 
@@ -133,49 +144,61 @@ static HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(IDirect3DSurface9 *iface,
     return D3D_OK;
 }
 
-static HRESULT WINAPI IDirect3DSurface9Impl_SetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags) {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+static HRESULT WINAPI IDirect3DSurface9Impl_SetPrivateData(IDirect3DSurface9 *iface, REFGUID guid,
+        const void *data, DWORD data_size, DWORD flags)
+{
+    IDirect3DSurface9Impl *surface = impl_from_IDirect3DSurface9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
-            iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
+            iface, debugstr_guid(guid), data, data_size, flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_surface_set_private_data(This->wined3d_surface, refguid, pData, SizeOfData, Flags);
+    resource = wined3d_surface_get_resource(surface->wined3d_surface);
+    hr = wined3d_resource_set_private_data(resource, guid, data, data_size, flags);
     wined3d_mutex_unlock();
 
     return hr;
 }
 
-static HRESULT WINAPI IDirect3DSurface9Impl_GetPrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid, void* pData, DWORD* pSizeOfData) {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+static HRESULT WINAPI IDirect3DSurface9Impl_GetPrivateData(IDirect3DSurface9 *iface, REFGUID guid,
+        void *data, DWORD *data_size)
+{
+    IDirect3DSurface9Impl *surface = impl_from_IDirect3DSurface9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
-            iface, debugstr_guid(refguid), pData, pSizeOfData);
+            iface, debugstr_guid(guid), data, data_size);
 
     wined3d_mutex_lock();
-    hr = wined3d_surface_get_private_data(This->wined3d_surface, refguid, pData, pSizeOfData);
+    resource = wined3d_surface_get_resource(surface->wined3d_surface);
+    hr = wined3d_resource_get_private_data(resource, guid, data, data_size);
     wined3d_mutex_unlock();
 
     return hr;
 }
 
-static HRESULT WINAPI IDirect3DSurface9Impl_FreePrivateData(LPDIRECT3DSURFACE9 iface, REFGUID refguid) {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+static HRESULT WINAPI IDirect3DSurface9Impl_FreePrivateData(IDirect3DSurface9 *iface, REFGUID guid)
+{
+    IDirect3DSurface9Impl *surface = impl_from_IDirect3DSurface9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
-    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
+    TRACE("iface %p, guid %s.\n", iface, debugstr_guid(guid));
 
     wined3d_mutex_lock();
-    hr = wined3d_surface_free_private_data(This->wined3d_surface, refguid);
+    resource = wined3d_surface_get_resource(surface->wined3d_surface);
+    hr = wined3d_resource_free_private_data(resource, guid);
     wined3d_mutex_unlock();
 
     return hr;
 }
 
-static DWORD WINAPI IDirect3DSurface9Impl_SetPriority(LPDIRECT3DSURFACE9 iface, DWORD PriorityNew) {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+static DWORD WINAPI IDirect3DSurface9Impl_SetPriority(IDirect3DSurface9 *iface, DWORD PriorityNew)
+{
+    IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface);
     HRESULT hr;
 
     TRACE("iface %p, priority %u.\n", iface, PriorityNew);
@@ -187,8 +210,9 @@ static DWORD WINAPI IDirect3DSurface9Impl_SetPriority(LPDIRECT3DSURFACE9 iface,
     return hr;
 }
 
-static DWORD WINAPI IDirect3DSurface9Impl_GetPriority(LPDIRECT3DSURFACE9 iface) {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+static DWORD WINAPI IDirect3DSurface9Impl_GetPriority(IDirect3DSurface9 *iface)
+{
+    IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface);
     HRESULT hr;
 
     TRACE("iface %p.\n", iface);
@@ -200,8 +224,9 @@ static DWORD WINAPI IDirect3DSurface9Impl_GetPriority(LPDIRECT3DSURFACE9 iface)
     return hr;
 }
 
-static void WINAPI IDirect3DSurface9Impl_PreLoad(LPDIRECT3DSURFACE9 iface) {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+static void WINAPI IDirect3DSurface9Impl_PreLoad(IDirect3DSurface9 *iface)
+{
+    IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface);
 
     TRACE("iface %p.\n", iface);
 
@@ -218,8 +243,10 @@ static D3DRESOURCETYPE WINAPI IDirect3DSurface9Impl_GetType(IDirect3DSurface9 *i
 }
 
 /* IDirect3DSurface9 Interface follow: */
-static HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(LPDIRECT3DSURFACE9 iface, REFIID riid, void** ppContainer) {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+static HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(IDirect3DSurface9 *iface, REFIID riid,
+        void **ppContainer)
+{
+    IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface);
     HRESULT res;
 
     TRACE("iface %p, riid %s, container %p.\n", iface, debugstr_guid(riid), ppContainer);
@@ -235,7 +262,7 @@ static HRESULT WINAPI IDirect3DSurface9Impl_GetContainer(LPDIRECT3DSURFACE9 ifac
 
 static HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(IDirect3DSurface9 *iface, D3DSURFACE_DESC *desc)
 {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+    IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface);
     struct wined3d_resource_desc wined3d_desc;
     struct wined3d_resource *wined3d_resource;
 
@@ -248,7 +275,7 @@ static HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(IDirect3DSurface9 *iface, D3
 
     desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
     desc->Type = wined3d_desc.resource_type;
-    desc->Usage = wined3d_desc.usage;
+    desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
     desc->Pool = wined3d_desc.pool;
     desc->MultiSampleType = wined3d_desc.multisample_type;
     desc->MultiSampleQuality = wined3d_desc.multisample_quality;
@@ -258,21 +285,24 @@ static HRESULT WINAPI IDirect3DSurface9Impl_GetDesc(IDirect3DSurface9 *iface, D3
     return D3D_OK;
 }
 
-static HRESULT WINAPI IDirect3DSurface9Impl_LockRect(LPDIRECT3DSURFACE9 iface, D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags) {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+static HRESULT WINAPI IDirect3DSurface9Impl_LockRect(IDirect3DSurface9 *iface,
+        D3DLOCKED_RECT *pLockedRect, const RECT *pRect, DWORD Flags)
+{
+    IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface);
     HRESULT hr;
 
     TRACE("iface %p, locked_rect %p, rect %p, flags %#x.\n", iface, pLockedRect, pRect, Flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_surface_map(This->wined3d_surface, (WINED3DLOCKED_RECT *)pLockedRect, pRect, Flags);
+    hr = wined3d_surface_map(This->wined3d_surface, (struct wined3d_mapped_rect *)pLockedRect, pRect, Flags);
     wined3d_mutex_unlock();
 
     return hr;
 }
 
-static HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface) {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+static HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(IDirect3DSurface9 *iface)
+{
+    IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface);
     HRESULT hr;
 
     TRACE("iface %p.\n", iface);
@@ -288,8 +318,9 @@ static HRESULT WINAPI IDirect3DSurface9Impl_UnlockRect(LPDIRECT3DSURFACE9 iface)
     }
 }
 
-static HRESULT WINAPI IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface, HDC* phdc) {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+static HRESULT WINAPI IDirect3DSurface9Impl_GetDC(IDirect3DSurface9 *iface, HDC* phdc)
+{
+    IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface);
     HRESULT hr;
 
     TRACE("iface %p, hdc %p.\n", iface, phdc);
@@ -308,8 +339,9 @@ static HRESULT WINAPI IDirect3DSurface9Impl_GetDC(LPDIRECT3DSURFACE9 iface, HDC*
     return hr;
 }
 
-static HRESULT WINAPI IDirect3DSurface9Impl_ReleaseDC(LPDIRECT3DSURFACE9 iface, HDC hdc) {
-    IDirect3DSurface9Impl *This = (IDirect3DSurface9Impl *)iface;
+static HRESULT WINAPI IDirect3DSurface9Impl_ReleaseDC(IDirect3DSurface9 *iface, HDC hdc)
+{
+    IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface);
     HRESULT hr;
 
     TRACE("iface %p, hdc %p.\n", iface, hdc);
@@ -363,9 +395,10 @@ HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *devic
         UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
         DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality)
 {
+    DWORD flags = 0;
     HRESULT hr;
 
-    surface->lpVtbl = &Direct3DSurface9_Vtbl;
+    surface->IDirect3DSurface9_iface.lpVtbl = &Direct3DSurface9_Vtbl;
     surface->ref = 1;
 
     switch (format)
@@ -391,10 +424,15 @@ HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *devic
         multisample_quality = 0;
     }
 
+    if (lockable)
+        flags |= WINED3D_SURFACE_MAPPABLE;
+    if (discard)
+        flags |= WINED3D_SURFACE_DISCARD;
+
     wined3d_mutex_lock();
     hr = wined3d_surface_create(device->wined3d_device, width, height, wined3dformat_from_d3dformat(format),
-            lockable, discard, level, usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool, multisample_type,
-            multisample_quality, SURFACE_OPENGL, surface, &d3d9_surface_wined3d_parent_ops, &surface->wined3d_surface);
+            level, usage & WINED3DUSAGE_MASK, (enum wined3d_pool)pool, multisample_type, multisample_quality,
+            SURFACE_OPENGL, flags, surface, &d3d9_surface_wined3d_parent_ops, &surface->wined3d_surface);
     wined3d_mutex_unlock();
     if (FAILED(hr))
     {
@@ -407,3 +445,12 @@ HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *devic
 
     return D3D_OK;
 }
+
+IDirect3DSurface9Impl *unsafe_impl_from_IDirect3DSurface9(IDirect3DSurface9 *iface)
+{
+    if (!iface)
+        return NULL;
+    assert(iface->lpVtbl == &Direct3DSurface9_Vtbl);
+
+    return impl_from_IDirect3DSurface9(iface);
+}
index 2643707..7ad0021 100644 (file)
@@ -98,15 +98,17 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3DSwapChain9Impl_Present(LPDIRECT
     return hr;
 }
 
-static HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(LPDIRECT3DSWAPCHAIN9 iface, IDirect3DSurface9* pDestSurface) {
+static HRESULT WINAPI IDirect3DSwapChain9Impl_GetFrontBufferData(IDirect3DSwapChain9 *iface,
+        IDirect3DSurface9 *pDestSurface)
+{
     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
+    IDirect3DSurface9Impl *dst = unsafe_impl_from_IDirect3DSurface9(pDestSurface);
     HRESULT hr;
 
     TRACE("iface %p, surface %p.\n", iface, pDestSurface);
 
     wined3d_mutex_lock();
-    hr = wined3d_swapchain_get_front_buffer_data(This->wined3d_swapchain,
-            ((IDirect3DSurface9Impl *)pDestSurface)->wined3d_surface);
+    hr = wined3d_swapchain_get_front_buffer_data(This->wined3d_swapchain, dst->wined3d_surface);
     wined3d_mutex_unlock();
 
     return hr;
@@ -124,7 +126,7 @@ static HRESULT WINAPI IDirect3DSwapChain9Impl_GetBackBuffer(IDirect3DSwapChain9
 
     wined3d_mutex_lock();
     hr = wined3d_swapchain_get_back_buffer(This->wined3d_swapchain,
-            iBackBuffer, (WINED3DBACKBUFFER_TYPE)Type, &wined3d_surface);
+            iBackBuffer, (enum wined3d_backbuffer_type)Type, &wined3d_surface);
     if (SUCCEEDED(hr) && wined3d_surface)
     {
        *ppBackBuffer = wined3d_surface_get_parent(wined3d_surface);
@@ -144,7 +146,7 @@ static HRESULT WINAPI IDirect3DSwapChain9Impl_GetRasterStatus(LPDIRECT3DSWAPCHAI
     TRACE("iface %p, raster_status %p.\n", iface, pRasterStatus);
 
     wined3d_mutex_lock();
-    hr = wined3d_swapchain_get_raster_status(This->wined3d_swapchain, (WINED3DRASTER_STATUS *)pRasterStatus);
+    hr = wined3d_swapchain_get_raster_status(This->wined3d_swapchain, (struct wined3d_raster_status *)pRasterStatus);
     wined3d_mutex_unlock();
 
     return hr;
@@ -157,7 +159,7 @@ static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDisplayMode(LPDIRECT3DSWAPCHAIN
     TRACE("iface %p, mode %p.\n", iface, pMode);
 
     wined3d_mutex_lock();
-    hr = wined3d_swapchain_get_display_mode(This->wined3d_swapchain, (WINED3DDISPLAYMODE *)pMode);
+    hr = wined3d_swapchain_get_display_mode(This->wined3d_swapchain, (struct wined3d_display_mode *)pMode);
     wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -179,31 +181,33 @@ static HRESULT WINAPI IDirect3DSwapChain9Impl_GetDevice(IDirect3DSwapChain9 *ifa
     return D3D_OK;
 }
 
-static HRESULT WINAPI IDirect3DSwapChain9Impl_GetPresentParameters(LPDIRECT3DSWAPCHAIN9 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
+static HRESULT WINAPI IDirect3DSwapChain9Impl_GetPresentParameters(IDirect3DSwapChain9 *iface,
+        D3DPRESENT_PARAMETERS *pPresentationParameters)
+{
     IDirect3DSwapChain9Impl *This = (IDirect3DSwapChain9Impl *)iface;
-    WINED3DPRESENT_PARAMETERS winePresentParameters;
+    struct wined3d_swapchain_desc desc;
     HRESULT hr;
 
     TRACE("iface %p, parameters %p.\n", iface, pPresentationParameters);
 
     wined3d_mutex_lock();
-    hr = wined3d_swapchain_get_present_parameters(This->wined3d_swapchain, &winePresentParameters);
+    hr = wined3d_swapchain_get_desc(This->wined3d_swapchain, &desc);
     wined3d_mutex_unlock();
 
-    pPresentationParameters->BackBufferWidth            = winePresentParameters.BackBufferWidth;
-    pPresentationParameters->BackBufferHeight           = winePresentParameters.BackBufferHeight;
-    pPresentationParameters->BackBufferFormat           = d3dformat_from_wined3dformat(winePresentParameters.BackBufferFormat);
-    pPresentationParameters->BackBufferCount            = winePresentParameters.BackBufferCount;
-    pPresentationParameters->MultiSampleType            = winePresentParameters.MultiSampleType;
-    pPresentationParameters->MultiSampleQuality         = winePresentParameters.MultiSampleQuality;
-    pPresentationParameters->SwapEffect                 = winePresentParameters.SwapEffect;
-    pPresentationParameters->hDeviceWindow              = winePresentParameters.hDeviceWindow;
-    pPresentationParameters->Windowed                   = winePresentParameters.Windowed;
-    pPresentationParameters->EnableAutoDepthStencil     = winePresentParameters.EnableAutoDepthStencil;
-    pPresentationParameters->AutoDepthStencilFormat     = d3dformat_from_wined3dformat(winePresentParameters.AutoDepthStencilFormat);
-    pPresentationParameters->Flags                      = winePresentParameters.Flags;
-    pPresentationParameters->FullScreen_RefreshRateInHz = winePresentParameters.FullScreen_RefreshRateInHz;
-    pPresentationParameters->PresentationInterval       = winePresentParameters.PresentationInterval;
+    pPresentationParameters->BackBufferWidth = desc.backbuffer_width;
+    pPresentationParameters->BackBufferHeight = desc.backbuffer_height;
+    pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(desc.backbuffer_format);
+    pPresentationParameters->BackBufferCount = desc.backbuffer_count;
+    pPresentationParameters->MultiSampleType = desc.multisample_type;
+    pPresentationParameters->MultiSampleQuality = desc.multisample_quality;
+    pPresentationParameters->SwapEffect = desc.swap_effect;
+    pPresentationParameters->hDeviceWindow = desc.device_window;
+    pPresentationParameters->Windowed = desc.windowed;
+    pPresentationParameters->EnableAutoDepthStencil = desc.enable_auto_depth_stencil;
+    pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(desc.auto_depth_stencil_format);
+    pPresentationParameters->Flags = desc.flags;
+    pPresentationParameters->FullScreen_RefreshRateInHz = desc.refresh_rate;
+    pPresentationParameters->PresentationInterval = desc.swap_interval;
 
     return hr;
 }
@@ -236,48 +240,48 @@ static const struct wined3d_parent_ops d3d9_swapchain_wined3d_parent_ops =
 HRESULT swapchain_init(IDirect3DSwapChain9Impl *swapchain, IDirect3DDevice9Impl *device,
         D3DPRESENT_PARAMETERS *present_parameters)
 {
-    WINED3DPRESENT_PARAMETERS wined3d_parameters;
+    struct wined3d_swapchain_desc desc;
     HRESULT hr;
 
     swapchain->ref = 1;
     swapchain->lpVtbl = &Direct3DSwapChain9_Vtbl;
 
-    wined3d_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
-    wined3d_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
-    wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat);
-    wined3d_parameters.BackBufferCount = max(1, present_parameters->BackBufferCount);
-    wined3d_parameters.MultiSampleType = present_parameters->MultiSampleType;
-    wined3d_parameters.MultiSampleQuality = present_parameters->MultiSampleQuality;
-    wined3d_parameters.SwapEffect = present_parameters->SwapEffect;
-    wined3d_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
-    wined3d_parameters.Windowed = present_parameters->Windowed;
-    wined3d_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
-    wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat);
-    wined3d_parameters.Flags = present_parameters->Flags;
-    wined3d_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
-    wined3d_parameters.PresentationInterval = present_parameters->PresentationInterval;
-    wined3d_parameters.AutoRestoreDisplayMode = TRUE;
+    desc.backbuffer_width = present_parameters->BackBufferWidth;
+    desc.backbuffer_height = present_parameters->BackBufferHeight;
+    desc.backbuffer_format = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat);
+    desc.backbuffer_count = max(1, present_parameters->BackBufferCount);
+    desc.multisample_type = present_parameters->MultiSampleType;
+    desc.multisample_quality = present_parameters->MultiSampleQuality;
+    desc.swap_effect = present_parameters->SwapEffect;
+    desc.device_window = present_parameters->hDeviceWindow;
+    desc.windowed = present_parameters->Windowed;
+    desc.enable_auto_depth_stencil = present_parameters->EnableAutoDepthStencil;
+    desc.auto_depth_stencil_format = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat);
+    desc.flags = present_parameters->Flags;
+    desc.refresh_rate = present_parameters->FullScreen_RefreshRateInHz;
+    desc.swap_interval = present_parameters->PresentationInterval;
+    desc.auto_restore_display_mode = TRUE;
 
     wined3d_mutex_lock();
-    hr = wined3d_swapchain_create(device->wined3d_device, &wined3d_parameters,
+    hr = wined3d_swapchain_create(device->wined3d_device, &desc,
             SURFACE_OPENGL, swapchain, &d3d9_swapchain_wined3d_parent_ops,
             &swapchain->wined3d_swapchain);
     wined3d_mutex_unlock();
 
-    present_parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
-    present_parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
-    present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
-    present_parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
-    present_parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
-    present_parameters->MultiSampleQuality = wined3d_parameters.MultiSampleQuality;
-    present_parameters->SwapEffect = wined3d_parameters.SwapEffect;
-    present_parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
-    present_parameters->Windowed = wined3d_parameters.Windowed;
-    present_parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
-    present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
-    present_parameters->Flags = wined3d_parameters.Flags;
-    present_parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
-    present_parameters->PresentationInterval = wined3d_parameters.PresentationInterval;
+    present_parameters->BackBufferWidth = desc.backbuffer_width;
+    present_parameters->BackBufferHeight = desc.backbuffer_height;
+    present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(desc.backbuffer_format);
+    present_parameters->BackBufferCount = desc.backbuffer_count;
+    present_parameters->MultiSampleType = desc.multisample_type;
+    present_parameters->MultiSampleQuality = desc.multisample_quality;
+    present_parameters->SwapEffect = desc.swap_effect;
+    present_parameters->hDeviceWindow = desc.device_window;
+    present_parameters->Windowed = desc.windowed;
+    present_parameters->EnableAutoDepthStencil = desc.enable_auto_depth_stencil;
+    present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(desc.auto_depth_stencil_format);
+    present_parameters->Flags = desc.flags;
+    present_parameters->FullScreen_RefreshRateInHz = desc.refresh_rate;
+    present_parameters->PresentationInterval = desc.swap_interval;
 
     if (FAILED(hr))
     {
index d1df0f5..49a0fe6 100644 (file)
@@ -108,13 +108,15 @@ static HRESULT WINAPI IDirect3DTexture9Impl_SetPrivateData(IDirect3DTexture9 *if
         REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
 {
     IDirect3DTexture9Impl *This = impl_from_IDirect3DTexture9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
             iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_set_private_data(This->wined3d_texture, refguid, pData, SizeOfData, Flags);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -124,13 +126,15 @@ static HRESULT WINAPI IDirect3DTexture9Impl_GetPrivateData(IDirect3DTexture9 *if
         REFGUID refguid, void *pData, DWORD *pSizeOfData)
 {
     IDirect3DTexture9Impl *This = impl_from_IDirect3DTexture9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
             iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_get_private_data(This->wined3d_texture, refguid, pData, pSizeOfData);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData);
     wined3d_mutex_unlock();
 
     return hr;
@@ -140,12 +144,14 @@ static HRESULT WINAPI IDirect3DTexture9Impl_FreePrivateData(IDirect3DTexture9 *i
         REFGUID refguid)
 {
     IDirect3DTexture9Impl *This = impl_from_IDirect3DTexture9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_free_private_data(This->wined3d_texture, refguid);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_free_private_data(resource, refguid);
     wined3d_mutex_unlock();
 
     return hr;
@@ -192,16 +198,9 @@ static void WINAPI IDirect3DTexture9Impl_PreLoad(IDirect3DTexture9 *iface)
 
 static D3DRESOURCETYPE WINAPI IDirect3DTexture9Impl_GetType(IDirect3DTexture9 *iface)
 {
-    IDirect3DTexture9Impl *This = impl_from_IDirect3DTexture9(iface);
-    HRESULT ret;
-
     TRACE("iface %p.\n", iface);
 
-    wined3d_mutex_lock();
-    ret = wined3d_texture_get_type(This->wined3d_texture);
-    wined3d_mutex_unlock();
-
-    return ret;
+    return D3DRTYPE_TEXTURE;
 }
 
 /* IDirect3DTexture9 IDirect3DBaseTexture9 Interface follow: */
@@ -256,7 +255,7 @@ static HRESULT WINAPI IDirect3DTexture9Impl_SetAutoGenFilterType(IDirect3DTextur
     TRACE("iface %p, filter_type %#x.\n", iface, FilterType);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_set_autogen_filter_type(This->wined3d_texture, (WINED3DTEXTUREFILTERTYPE)FilterType);
+    hr = wined3d_texture_set_autogen_filter_type(This->wined3d_texture, (enum wined3d_texture_filter_type)FilterType);
     wined3d_mutex_unlock();
 
     return hr;
@@ -306,7 +305,7 @@ static HRESULT WINAPI IDirect3DTexture9Impl_GetLevelDesc(IDirect3DTexture9 *ifac
         wined3d_resource_get_desc(sub_resource, &wined3d_desc);
         desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
         desc->Type = wined3d_desc.resource_type;
-        desc->Usage = wined3d_desc.usage;
+        desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
         desc->Pool = wined3d_desc.pool;
         desc->MultiSampleType = wined3d_desc.multisample_type;
         desc->MultiSampleQuality = wined3d_desc.multisample_quality;
@@ -393,14 +392,14 @@ static HRESULT WINAPI IDirect3DTexture9Impl_AddDirtyRect(IDirect3DTexture9 *ifac
         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, NULL);
     else
     {
-        WINED3DBOX dirty_region;
-
-        dirty_region.Left = dirty_rect->left;
-        dirty_region.Top = dirty_rect->top;
-        dirty_region.Right = dirty_rect->right;
-        dirty_region.Bottom = dirty_rect->bottom;
-        dirty_region.Front = 0;
-        dirty_region.Back = 1;
+        struct wined3d_box dirty_region;
+
+        dirty_region.left = dirty_rect->left;
+        dirty_region.top = dirty_rect->top;
+        dirty_region.right = dirty_rect->right;
+        dirty_region.bottom = dirty_rect->bottom;
+        dirty_region.front = 0;
+        dirty_region.back = 1;
         hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, &dirty_region);
     }
     wined3d_mutex_unlock();
index 6224614..3b2198e 100644 (file)
@@ -320,8 +320,8 @@ static const struct wined3d_parent_ops d3d9_vertexdeclaration_wined3d_parent_ops
     d3d9_vertexdeclaration_wined3d_object_destroyed,
 };
 
-static HRESULT convert_to_wined3d_declaration(const D3DVERTEXELEMENT9d3d9_elements,
-        WINED3DVERTEXELEMENT **wined3d_elements, UINT *element_count)
+static HRESULT convert_to_wined3d_declaration(const D3DVERTEXELEMENT9 *d3d9_elements,
+        struct wined3d_vertex_element **wined3d_elements, UINT *element_count)
 {
     const D3DVERTEXELEMENT9* element;
     UINT count = 1;
@@ -337,7 +337,7 @@ static HRESULT convert_to_wined3d_declaration(const D3DVERTEXELEMENT9* d3d9_elem
     /* Skip the END element */
     --count;
 
-    *wined3d_elements = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WINED3DVERTEXELEMENT));
+    *wined3d_elements = HeapAlloc(GetProcessHeap(), 0, count * sizeof(**wined3d_elements));
     if (!*wined3d_elements) {
         FIXME("Memory allocation failed\n");
         return D3DERR_OUTOFVIDEOMEMORY;
@@ -368,7 +368,7 @@ static HRESULT convert_to_wined3d_declaration(const D3DVERTEXELEMENT9* d3d9_elem
 HRESULT vertexdeclaration_init(IDirect3DVertexDeclaration9Impl *declaration,
         IDirect3DDevice9Impl *device, const D3DVERTEXELEMENT9 *elements)
 {
-    WINED3DVERTEXELEMENT *wined3d_elements;
+    struct wined3d_vertex_element *wined3d_elements;
     UINT wined3d_element_count;
     UINT element_count;
     HRESULT hr;
index ba495b6..58e7827 100644 (file)
@@ -126,13 +126,15 @@ static HRESULT WINAPI IDirect3DVolume9Impl_SetPrivateData(IDirect3DVolume9 *ifac
         const void *pData, DWORD SizeOfData, DWORD Flags)
 {
     IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
             iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_volume_set_private_data(This->wined3d_volume, refguid, pData, SizeOfData, Flags);
+    resource = wined3d_volume_get_resource(This->wined3d_volume);
+    hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -142,13 +144,15 @@ static HRESULT WINAPI IDirect3DVolume9Impl_GetPrivateData(IDirect3DVolume9 *ifac
         void *pData, DWORD *pSizeOfData)
 {
     IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
             iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
-    hr = wined3d_volume_get_private_data(This->wined3d_volume, refguid, pData, pSizeOfData);
+    resource = wined3d_volume_get_resource(This->wined3d_volume);
+    hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData);
     wined3d_mutex_unlock();
 
     return hr;
@@ -157,12 +161,14 @@ static HRESULT WINAPI IDirect3DVolume9Impl_GetPrivateData(IDirect3DVolume9 *ifac
 static HRESULT WINAPI IDirect3DVolume9Impl_FreePrivateData(IDirect3DVolume9 *iface, REFGUID refguid)
 {
     IDirect3DVolume9Impl *This = impl_from_IDirect3DVolume9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
-    hr = wined3d_volume_free_private_data(This->wined3d_volume, refguid);
+    resource = wined3d_volume_get_resource(This->wined3d_volume);
+    hr = wined3d_resource_free_private_data(resource, refguid);
     wined3d_mutex_unlock();
 
     return hr;
@@ -200,7 +206,7 @@ static HRESULT WINAPI IDirect3DVolume9Impl_GetDesc(IDirect3DVolume9 *iface, D3DV
 
     desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
     desc->Type = wined3d_desc.resource_type;
-    desc->Usage = wined3d_desc.usage;
+    desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
     desc->Pool = wined3d_desc.pool;
     desc->Width = wined3d_desc.width;
     desc->Height = wined3d_desc.height;
@@ -219,8 +225,8 @@ static HRESULT WINAPI IDirect3DVolume9Impl_LockBox(IDirect3DVolume9 *iface,
             iface, pLockedVolume, pBox, Flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_volume_map(This->wined3d_volume, (WINED3DLOCKED_BOX *)pLockedVolume,
-            (const WINED3DBOX *)pBox, Flags);
+    hr = wined3d_volume_map(This->wined3d_volume, (struct wined3d_mapped_box *)pLockedVolume,
+            (const struct wined3d_box *)pBox, Flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -268,7 +274,7 @@ static const struct wined3d_parent_ops d3d9_volume_wined3d_parent_ops =
 };
 
 HRESULT volume_init(IDirect3DVolume9Impl *volume, IDirect3DDevice9Impl *device, UINT width, UINT height,
-        UINT depth, DWORD usage, enum wined3d_format_id format, WINED3DPOOL pool)
+        UINT depth, DWORD usage, enum wined3d_format_id format, enum wined3d_pool pool)
 {
     HRESULT hr;
 
index 9528e9b..d6d625b 100644 (file)
@@ -107,13 +107,15 @@ static HRESULT WINAPI IDirect3DVolumeTexture9Impl_SetPrivateData(IDirect3DVolume
         REFGUID refguid, const void *pData, DWORD SizeOfData, DWORD Flags)
 {
     IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %u, flags %#x.\n",
             iface, debugstr_guid(refguid), pData, SizeOfData, Flags);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_set_private_data(This->wined3d_texture, refguid, pData, SizeOfData, Flags);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_set_private_data(resource, refguid, pData, SizeOfData, Flags);
     wined3d_mutex_unlock();
 
     return hr;
@@ -123,13 +125,15 @@ static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetPrivateData(IDirect3DVolume
         REFGUID refguid, void *pData, DWORD *pSizeOfData)
 {
     IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s, data %p, data_size %p.\n",
             iface, debugstr_guid(refguid), pData, pSizeOfData);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_get_private_data(This->wined3d_texture, refguid, pData, pSizeOfData);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_get_private_data(resource, refguid, pData, pSizeOfData);
     wined3d_mutex_unlock();
 
     return hr;
@@ -139,12 +143,14 @@ static HRESULT WINAPI IDirect3DVolumeTexture9Impl_FreePrivateData(IDirect3DVolum
         REFGUID refguid)
 {
     IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface);
+    struct wined3d_resource *resource;
     HRESULT hr;
 
     TRACE("iface %p, guid %s.\n", iface, debugstr_guid(refguid));
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_free_private_data(This->wined3d_texture, refguid);
+    resource = wined3d_texture_get_resource(This->wined3d_texture);
+    hr = wined3d_resource_free_private_data(resource, refguid);
     wined3d_mutex_unlock();
 
     return hr;
@@ -192,16 +198,9 @@ static void WINAPI IDirect3DVolumeTexture9Impl_PreLoad(IDirect3DVolumeTexture9 *
 
 static D3DRESOURCETYPE WINAPI IDirect3DVolumeTexture9Impl_GetType(IDirect3DVolumeTexture9 *iface)
 {
-    IDirect3DVolumeTexture9Impl *This = impl_from_IDirect3DVolumeTexture9(iface);
-    D3DRESOURCETYPE type;
-
     TRACE("iface %p.\n", iface);
 
-    wined3d_mutex_lock();
-    type = wined3d_texture_get_type(This->wined3d_texture);
-    wined3d_mutex_unlock();
-
-    return type;
+    return D3DRTYPE_VOLUMETEXTURE;
 }
 
 static DWORD WINAPI IDirect3DVolumeTexture9Impl_SetLOD(IDirect3DVolumeTexture9 *iface, DWORD LODNew)
@@ -255,7 +254,7 @@ static HRESULT WINAPI IDirect3DVolumeTexture9Impl_SetAutoGenFilterType(IDirect3D
     TRACE("iface %p, filter_type %#x.\n", iface, FilterType);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_set_autogen_filter_type(This->wined3d_texture, (WINED3DTEXTUREFILTERTYPE)FilterType);
+    hr = wined3d_texture_set_autogen_filter_type(This->wined3d_texture, (enum wined3d_texture_filter_type)FilterType);
     wined3d_mutex_unlock();
 
     return hr;
@@ -305,7 +304,7 @@ static HRESULT WINAPI IDirect3DVolumeTexture9Impl_GetLevelDesc(IDirect3DVolumeTe
         wined3d_resource_get_desc(sub_resource, &wined3d_desc);
         desc->Format = d3dformat_from_wined3dformat(wined3d_desc.format);
         desc->Type = wined3d_desc.resource_type;
-        desc->Usage = wined3d_desc.usage;
+        desc->Usage = wined3d_desc.usage & WINED3DUSAGE_MASK;
         desc->Pool = wined3d_desc.pool;
         desc->Width = wined3d_desc.width;
         desc->Height = wined3d_desc.height;
@@ -387,7 +386,7 @@ static HRESULT WINAPI IDirect3DVolumeTexture9Impl_AddDirtyBox(IDirect3DVolumeTex
     TRACE("iface %p, dirty_box %p.\n", iface, dirty_box);
 
     wined3d_mutex_lock();
-    hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const WINED3DBOX *)dirty_box);
+    hr = wined3d_texture_add_dirty_region(texture->wined3d_texture, 0, (const struct wined3d_box *)dirty_box);
     wined3d_mutex_unlock();
 
     return hr;
index 300c52f..58a609c 100644 (file)
@@ -16,19 +16,18 @@ spec2def(ddraw.dll ddraw.spec)
 list(APPEND SOURCE
     clipper.c
     ddraw.c
+    ddraw.rc
     device.c
     executebuffer.c
     light.c
     main.c
     material.c
     palette.c
-    regsvr.c
     stubs.c
     surface.c
     utils.c
     vertexbuffer.c
     viewport.c
-    version.rc
     ${CMAKE_CURRENT_BINARY_DIR}/ddraw_stubs.c
     ${CMAKE_CURRENT_BINARY_DIR}/ddraw.def)
 
index c9290c8..81e9e8b 100644 (file)
 
 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
 
-/*****************************************************************************
- * IUnknown methods
- *****************************************************************************/
+static inline struct ddraw_clipper *impl_from_IDirectDrawClipper(IDirectDrawClipper *iface)
+{
+    return CONTAINING_RECORD(iface, struct ddraw_clipper, IDirectDrawClipper_iface);
+}
 
-/*****************************************************************************
- * IDirectDrawClipper::QueryInterface
- *
- * Can query the IUnknown and IDirectDrawClipper interface from a
- * Clipper object. The IUnknown Interface is equal to the IDirectDrawClipper
- * interface. Can't create other interfaces.
- *
- * Arguments:
- *  riid: Interface id asked for
- *  ppvObj: Returns the pointer to the interface
- *
- * Return values:
- *  DD_OK on success
- *  E_NOINTERFACE if the requested interface wasn't found.
- *
- *****************************************************************************/
-static HRESULT WINAPI IDirectDrawClipperImpl_QueryInterface(
-    LPDIRECTDRAWCLIPPER iface, REFIID riid, LPVOID* ppvObj
-) {
+static HRESULT WINAPI ddraw_clipper_QueryInterface(IDirectDrawClipper *iface, REFIID iid, void **object)
+{
+    struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface);
 
-    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppvObj);
+    TRACE("iface %p, iid %s, object %p.\n", iface, debugstr_guid(iid), object);
 
-    if (IsEqualGUID(&IID_IDirectDrawClipper, riid)
-            || IsEqualGUID(&IID_IUnknown, riid))
+    if (IsEqualGUID(&IID_IDirectDrawClipper, iid)
+            || IsEqualGUID(&IID_IUnknown, iid))
     {
-        IUnknown_AddRef(iface);
-        *ppvObj = iface;
+        IDirectDrawClipper_AddRef(&clipper->IDirectDrawClipper_iface);
+        *object = &clipper->IDirectDrawClipper_iface;
         return S_OK;
     }
 
+    WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
+    *object = NULL;
+
     return E_NOINTERFACE;
 }
 
-/*****************************************************************************
- * IDirectDrawClipper::AddRef
- *
- * Increases the reference count of the interface, returns the new count
- *
- *****************************************************************************/
-static ULONG WINAPI IDirectDrawClipperImpl_AddRef( LPDIRECTDRAWCLIPPER iface )
+static ULONG WINAPI ddraw_clipper_AddRef(IDirectDrawClipper *iface)
 {
-    IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
-    ULONG ref = InterlockedIncrement(&This->ref);
+    struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface);
+    ULONG refcount = InterlockedIncrement(&clipper->ref);
 
-    TRACE("%p increasing refcount to %u.\n", This, ref);
+    TRACE("%p increasing refcount to %u.\n", clipper, refcount);
 
-    return ref;
+    return refcount;
 }
 
-/*****************************************************************************
- * IDirectDrawClipper::Release
- *
- * Decreases the reference count of the interface, returns the new count
- * If the refcount is decreased to 0, the interface is destroyed.
- *
- *****************************************************************************/
-static ULONG WINAPI IDirectDrawClipperImpl_Release(IDirectDrawClipper *iface) {
-    IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
-    ULONG ref = InterlockedDecrement(&This->ref);
+static ULONG WINAPI ddraw_clipper_Release(IDirectDrawClipper *iface)
+{
+    struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface);
+    ULONG refcount = InterlockedDecrement(&clipper->ref);
 
-    TRACE("%p decreasing refcount to %u.\n", This, ref);
+    TRACE("%p decreasing refcount to %u.\n", clipper, refcount);
 
-    if (ref == 0)
+    if (!refcount)
     {
-        EnterCriticalSection(&ddraw_cs);
-        wined3d_clipper_decref(This->wineD3DClipper);
-        HeapFree(GetProcessHeap(), 0, This);
-        LeaveCriticalSection(&ddraw_cs);
-        return 0;
+        if (clipper->region)
+            DeleteObject(clipper->region);
+        HeapFree(GetProcessHeap(), 0, clipper);
     }
-    else return ref;
+
+    return refcount;
 }
 
-/*****************************************************************************
- * IDirectDrawClipper::SetHwnd
- *
- * Assigns a hWnd to the clipper interface.
- *
- * Arguments:
- *  Flags: Unsupported so far
- *  hWnd: The hWnd to set
- *
- * Return values:
- *  DD_OK on success
- *  DDERR_INVALIDPARAMS if Flags was != 0
- *
- *****************************************************************************/
+static HRESULT WINAPI ddraw_clipper_SetHWnd(IDirectDrawClipper *iface, DWORD flags, HWND window)
+{
+    struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface);
 
-static HRESULT WINAPI IDirectDrawClipperImpl_SetHwnd(
-    LPDIRECTDRAWCLIPPER iface, DWORD dwFlags, HWND hWnd
-) {
-    IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
-    HRESULT hr;
+    TRACE("iface %p, flags %#x, window %p.\n", iface, flags, window);
 
-    TRACE("iface %p, flags %#x, window %p.\n", iface, dwFlags, hWnd);
+    if (flags)
+    {
+        FIXME("flags %#x, not supported.\n", flags);
+        return DDERR_INVALIDPARAMS;
+    }
+
+    wined3d_mutex_lock();
+    clipper->window = window;
+    wined3d_mutex_unlock();
+
+    return DD_OK;
+}
+
+static HRGN get_window_region(HWND window)
+{
+    POINT origin = {0, 0};
+    RECT client_rect;
 
-    EnterCriticalSection(&ddraw_cs);
-    hr = wined3d_clipper_set_window(This->wineD3DClipper, dwFlags, hWnd);
-    LeaveCriticalSection(&ddraw_cs);
-    switch(hr)
+    if (!GetClientRect(window, &client_rect))
     {
-        case WINED3DERR_INVALIDCALL:        return DDERR_INVALIDPARAMS;
-        default:                            return hr;
+        /* This can happen if the window is destroyed, for example. */
+        WARN("Failed to get client rect.\n");
+        return NULL;
     }
+
+    if (!ClientToScreen(window, &origin))
+    {
+        ERR("Failed to translate origin.\n");
+        return NULL;
+    }
+
+    if (!OffsetRect(&client_rect, origin.x, origin.y))
+    {
+        ERR("Failed to translate client rect.\n");
+        return NULL;
+    }
+
+    return CreateRectRgnIndirect(&client_rect);
 }
 
 /*****************************************************************************
@@ -142,169 +130,197 @@ static HRESULT WINAPI IDirectDrawClipperImpl_SetHwnd(
  * Retrieve a copy of the clip list
  *
  * Arguments:
- *  Rect: Rectangle to be used to clip the clip list or NULL for the
- *        entire clip list
- *  ClipList: structure for the resulting copy of the clip list.
- *            If NULL, fills Size up to the number of bytes necessary to hold
- *            the entire clip.
- *  Size: Size of resulting clip list; size of the buffer at ClipList
- *        or, if ClipList is NULL, receives the required size of the buffer
- *        in bytes
+ *  rect: Rectangle to be used to clip the clip list or NULL for the
+ *      entire clip list.
+ *  clip_list: structure for the resulting copy of the clip list.
+ *      If NULL, fills Size up to the number of bytes necessary to hold
+ *      the entire clip.
+ *  clip_list_size: Size of resulting clip list; size of the buffer at clip_list
+ *      or, if clip_list is NULL, receives the required size of the buffer
+ *      in bytes.
  *
  * RETURNS
  *  Either DD_OK or DDERR_*
  ************************************************************************/
-static HRESULT WINAPI IDirectDrawClipperImpl_GetClipList(
-    LPDIRECTDRAWCLIPPER iface, LPRECT lpRect, LPRGNDATA lpClipList,
-    LPDWORD lpdwSize)
+static HRESULT WINAPI ddraw_clipper_GetClipList(IDirectDrawClipper *iface, RECT *rect,
+        RGNDATA *clip_list, DWORD *clip_list_size)
 {
-    IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
-    HRESULT hr;
+    struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface);
+    HRGN region;
 
     TRACE("iface %p, rect %s, clip_list %p, clip_list_size %p.\n",
-            iface, wine_dbgstr_rect(lpRect), lpClipList, lpdwSize);
+            iface, wine_dbgstr_rect(rect), clip_list, clip_list_size);
+
+    wined3d_mutex_lock();
+
+    if (clipper->window)
+    {
+        if (!(region = get_window_region(clipper->window)))
+        {
+            wined3d_mutex_unlock();
+            WARN("Failed to get window region.\n");
+            return E_FAIL;
+        }
+    }
+    else
+    {
+        if (!(region = clipper->region))
+        {
+            wined3d_mutex_unlock();
+            WARN("No clip list set.\n");
+            return DDERR_NOCLIPLIST;
+        }
+    }
+
+    if (rect)
+    {
+        HRGN clip_region;
+
+        if (!(clip_region = CreateRectRgnIndirect(rect)))
+        {
+            wined3d_mutex_unlock();
+            ERR("Failed to create region.\n");
+            if (clipper->window)
+                DeleteObject(region);
+            return E_FAIL;
+        }
+
+        if (CombineRgn(clip_region, region, clip_region, RGN_AND) == ERROR)
+        {
+            wined3d_mutex_unlock();
+            ERR("Failed to combine regions.\n");
+            DeleteObject(clip_region);
+            if (clipper->window)
+                DeleteObject(region);
+            return E_FAIL;
+        }
+
+        if (clipper->window)
+            DeleteObject(region);
+        region = clip_region;
+    }
 
-    EnterCriticalSection(&ddraw_cs);
-    hr = wined3d_clipper_get_clip_list(This->wineD3DClipper, lpRect, lpClipList, lpdwSize);
-    LeaveCriticalSection(&ddraw_cs);
-    return hr;
+    *clip_list_size = GetRegionData(region, *clip_list_size, clip_list);
+    if (rect || clipper->window)
+        DeleteObject(region);
+
+    wined3d_mutex_unlock();
+    return DD_OK;
 }
 
 /*****************************************************************************
  * IDirectDrawClipper::SetClipList
  *
- * Sets or deletes (if lprgn is NULL) the clip list
+ * Sets or deletes (if region is NULL) the clip list
  *
  * This implementation is a stub and returns DD_OK always to make the app
  * happy.
  *
  * PARAMS
- *  lprgn   Pointer to a LRGNDATA structure or NULL
- *  dwFlags not used, must be 0
+ *  region  Pointer to a LRGNDATA structure or NULL
+ *  flags   not used, must be 0
  * RETURNS
  *  Either DD_OK or DDERR_*
  *****************************************************************************/
-static HRESULT WINAPI IDirectDrawClipperImpl_SetClipList(
-    LPDIRECTDRAWCLIPPER iface,LPRGNDATA lprgn,DWORD dwFlag
-) {
-    IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
-    HRESULT hr;
-
-    TRACE("iface %p, clip_list %p, flags %#x.\n", iface, lprgn, dwFlag);
-
-    EnterCriticalSection(&ddraw_cs);
-    hr = wined3d_clipper_set_clip_list(This->wineD3DClipper, lprgn, dwFlag);
-    LeaveCriticalSection(&ddraw_cs);
-    return hr;
+static HRESULT WINAPI ddraw_clipper_SetClipList(IDirectDrawClipper *iface, RGNDATA *region, DWORD flags)
+{
+    struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface);
+
+    TRACE("iface %p, region %p, flags %#x.\n", iface, region, flags);
+
+    wined3d_mutex_lock();
+
+    if (clipper->window)
+    {
+        wined3d_mutex_unlock();
+        return DDERR_CLIPPERISUSINGHWND;
+    }
+
+    if (clipper->region)
+        DeleteObject(clipper->region);
+    if (!region)
+        clipper->region = NULL;
+    else if (!(clipper->region = ExtCreateRegion(NULL, 0, region)))
+    {
+        wined3d_mutex_unlock();
+        ERR("Failed to create region.\n");
+        return E_FAIL;
+    }
+
+    wined3d_mutex_unlock();
+
+    return DD_OK;
 }
 
-/*****************************************************************************
- * IDirectDrawClipper::GetHwnd
- *
- * Returns the hwnd assigned with SetHwnd
- *
- * Arguments:
- *  hWndPtr: Address to store the HWND at
- *
- * Return values:
- *  Always returns DD_OK;
- *****************************************************************************/
-static HRESULT WINAPI IDirectDrawClipperImpl_GetHWnd(
-    LPDIRECTDRAWCLIPPER iface, HWND* hWndPtr
-) {
-    IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
-    HRESULT hr;
-
-    TRACE("iface %p, window %p.\n", iface, hWndPtr);
-
-    EnterCriticalSection(&ddraw_cs);
-    hr = wined3d_clipper_get_window(This->wineD3DClipper, hWndPtr);
-    LeaveCriticalSection(&ddraw_cs);
-    return hr;
+static HRESULT WINAPI ddraw_clipper_GetHWnd(IDirectDrawClipper *iface, HWND *window)
+{
+    struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface);
+
+    TRACE("iface %p, window %p.\n", iface, window);
+
+    wined3d_mutex_lock();
+    *window = clipper->window;
+    wined3d_mutex_unlock();
+
+    return DD_OK;
 }
 
-/*****************************************************************************
- * IDirectDrawClipper::Initialize
- *
- * Initializes the interface. Well, there isn't much to do for this
- * implementation, but it stores the DirectDraw Interface.
- *
- * Arguments:
- *  DD: Pointer to a IDirectDraw interface
- *  Flags: Unsupported by now
- *
- * Return values:
- *  DD_OK on success
- *  DDERR_ALREADYINITIALIZED if this interface isn't initialized already
- *****************************************************************************/
-static HRESULT WINAPI IDirectDrawClipperImpl_Initialize(
-     LPDIRECTDRAWCLIPPER iface, LPDIRECTDRAW lpDD, DWORD dwFlags
-) {
-    IDirectDrawClipperImpl *This = (IDirectDrawClipperImpl *)iface;
+static HRESULT WINAPI ddraw_clipper_Initialize(IDirectDrawClipper *iface,
+        IDirectDraw *ddraw, DWORD flags)
+{
+    struct ddraw_clipper *clipper = impl_from_IDirectDrawClipper(iface);
 
-    TRACE("iface %p, ddraw %p, flags %#x.\n", iface, lpDD, dwFlags);
+    TRACE("iface %p, ddraw %p, flags %#x.\n", iface, ddraw, flags);
 
-    EnterCriticalSection(&ddraw_cs);
-    if (This->initialized)
+    wined3d_mutex_lock();
+    if (clipper->initialized)
     {
-        LeaveCriticalSection(&ddraw_cs);
+        wined3d_mutex_unlock();
         return DDERR_ALREADYINITIALIZED;
     }
 
-    This->initialized = TRUE;
+    clipper->initialized = TRUE;
+    wined3d_mutex_unlock();
 
-    LeaveCriticalSection(&ddraw_cs);
     return DD_OK;
 }
 
-/*****************************************************************************
- * IDirectDrawClipper::IsClipListChanged
- *
- * This function is a stub
- *
- * Arguments:
- *  Changed:
- *
- * Return values:
- *  DD_OK, because it's a stub
- *****************************************************************************/
-static HRESULT WINAPI IDirectDrawClipperImpl_IsClipListChanged(
-    LPDIRECTDRAWCLIPPER iface, BOOL* lpbChanged
-) {
-    FIXME("iface %p, changed %p stub!\n", iface, lpbChanged);
+static HRESULT WINAPI ddraw_clipper_IsClipListChanged(IDirectDrawClipper *iface, BOOL *changed)
+{
+    FIXME("iface %p, changed %p stub!\n", iface, changed);
 
     /* XXX What is safest? */
-    *lpbChanged = FALSE;
+    *changed = FALSE;
 
     return DD_OK;
 }
 
-/*****************************************************************************
- * The VTable
- *****************************************************************************/
 static const struct IDirectDrawClipperVtbl ddraw_clipper_vtbl =
 {
-    IDirectDrawClipperImpl_QueryInterface,
-    IDirectDrawClipperImpl_AddRef,
-    IDirectDrawClipperImpl_Release,
-    IDirectDrawClipperImpl_GetClipList,
-    IDirectDrawClipperImpl_GetHWnd,
-    IDirectDrawClipperImpl_Initialize,
-    IDirectDrawClipperImpl_IsClipListChanged,
-    IDirectDrawClipperImpl_SetClipList,
-    IDirectDrawClipperImpl_SetHwnd
+    ddraw_clipper_QueryInterface,
+    ddraw_clipper_AddRef,
+    ddraw_clipper_Release,
+    ddraw_clipper_GetClipList,
+    ddraw_clipper_GetHWnd,
+    ddraw_clipper_Initialize,
+    ddraw_clipper_IsClipListChanged,
+    ddraw_clipper_SetClipList,
+    ddraw_clipper_SetHWnd,
 };
 
-HRESULT ddraw_clipper_init(IDirectDrawClipperImpl *clipper)
+HRESULT ddraw_clipper_init(struct ddraw_clipper *clipper)
 {
-    clipper->lpVtbl = &ddraw_clipper_vtbl;
+    clipper->IDirectDrawClipper_iface.lpVtbl = &ddraw_clipper_vtbl;
     clipper->ref = 1;
-    clipper->wineD3DClipper = wined3d_clipper_create();
-    if (!clipper->wineD3DClipper)
-    {
-        WARN("Failed to create wined3d clipper.\n");
-        return E_OUTOFMEMORY;
-    }
 
     return DD_OK;
 }
+
+struct ddraw_clipper *unsafe_impl_from_IDirectDrawClipper(IDirectDrawClipper *iface)
+{
+    if (!iface)
+        return NULL;
+    assert(iface->lpVtbl == &ddraw_clipper_vtbl);
+
+    return impl_from_IDirectDrawClipper(iface);
+}
index 0c6ba3c..8397d5d 100644 (file)
@@ -39,6 +39,35 @@ static const DDDEVICEIDENTIFIER2 deviceidentifier =
     0
 };
 
+static struct enum_device_entry
+{
+    char interface_name[100];
+    char device_name[100];
+    const GUID *device_guid;
+} device_list7[] =
+{
+    /* T&L HAL device */
+    {
+        "WINE Direct3D7 Hardware Transform and Lighting acceleration using WineD3D",
+        "Wine D3D7 T&L HAL",
+        &IID_IDirect3DTnLHalDevice,
+    },
+
+    /* HAL device */
+    {
+        "WINE Direct3D7 Hardware acceleration using WineD3D",
+        "Direct3D HAL",
+        &IID_IDirect3DHALDevice,
+    },
+
+    /* RGB device */
+    {
+        "WINE Direct3D7 RGB Software Emulation using WineD3D",
+        "Wine D3D7 RGB",
+        &IID_IDirect3DRGBDevice,
+    },
+};
+
 static void STDMETHODCALLTYPE ddraw_null_wined3d_object_destroyed(void *parent) {}
 
 const struct wined3d_parent_ops ddraw_null_wined3d_parent_ops =
@@ -56,11 +85,6 @@ static inline IDirectDrawImpl *impl_from_IDirectDraw2(IDirectDraw2 *iface)
     return CONTAINING_RECORD(iface, IDirectDrawImpl, IDirectDraw2_iface);
 }
 
-static inline IDirectDrawImpl *impl_from_IDirectDraw3(IDirectDraw3 *iface)
-{
-    return CONTAINING_RECORD(iface, IDirectDrawImpl, IDirectDraw3_iface);
-}
-
 static inline IDirectDrawImpl *impl_from_IDirectDraw4(IDirectDraw4 *iface)
 {
     return CONTAINING_RECORD(iface, IDirectDrawImpl, IDirectDraw4_iface);
@@ -122,14 +146,14 @@ static HRESULT WINAPI ddraw7_QueryInterface(IDirectDraw7 *iface, REFIID refiid,
     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(refiid), obj);
 
     /* Can change surface impl type */
-    EnterCriticalSection(&ddraw_cs);
+    wined3d_mutex_lock();
 
     /* According to COM docs, if the QueryInterface fails, obj should be set to NULL */
     *obj = NULL;
 
     if(!refiid)
     {
-        LeaveCriticalSection(&ddraw_cs);
+        wined3d_mutex_unlock();
         return DDERR_INVALIDPARAMS;
     }
 
@@ -150,7 +174,7 @@ static HRESULT WINAPI ddraw7_QueryInterface(IDirectDraw7 *iface, REFIID refiid,
         /* This Interface exists in ddrawex.dll, it is implemented in a wrapper */
         WARN("IDirectDraw3 is not valid in ddraw.dll\n");
         *obj = NULL;
-        LeaveCriticalSection(&ddraw_cs);
+        wined3d_mutex_unlock();
         return E_NOINTERFACE;
     }
     else if ( IsEqualGUID( &IID_IDirectDraw2, refiid ) )
@@ -177,20 +201,7 @@ static HRESULT WINAPI ddraw7_QueryInterface(IDirectDraw7 *iface, REFIID refiid,
               IsEqualGUID( &IID_IDirect3D7 , refiid ) )
     {
         /* Check the surface implementation */
-        if(This->ImplType == SURFACE_UNKNOWN)
-        {
-            /* Apps may create the IDirect3D Interface before the primary surface.
-             * set the surface implementation */
-            This->ImplType = SURFACE_OPENGL;
-            TRACE("(%p) Choosing OpenGL surfaces because a Direct3D interface was requested\n", This);
-        }
-        else if(This->ImplType != SURFACE_OPENGL && DefaultSurfaceType == SURFACE_UNKNOWN)
-        {
-            ERR("(%p) The App is requesting a D3D device, but a non-OpenGL surface type was choosen. Prepare for trouble!\n", This);
-            ERR(" (%p) You may want to contact wine-devel for help\n", This);
-            /* Should I assert(0) here??? */
-        }
-        else if(This->ImplType != SURFACE_OPENGL)
+        if (DefaultSurfaceType != SURFACE_OPENGL)
         {
             WARN("The app requests a Direct3D interface, but non-opengl surfaces where set in winecfg\n");
             /* Do not abort here, only reject 3D Device creation */
@@ -225,12 +236,13 @@ static HRESULT WINAPI ddraw7_QueryInterface(IDirectDraw7 *iface, REFIID refiid,
     else
     {
         ERR("(%p)->(%s, %p): No interface found\n", This, debugstr_guid(refiid), obj);
-        LeaveCriticalSection(&ddraw_cs);
+        wined3d_mutex_unlock();
         return E_NOINTERFACE;
     }
 
     IUnknown_AddRef( (IUnknown *) *obj );
-    LeaveCriticalSection(&ddraw_cs);
+    wined3d_mutex_unlock();
+
     return S_OK;
 }
 
@@ -243,15 +255,6 @@ static HRESULT WINAPI ddraw4_QueryInterface(IDirectDraw4 *iface, REFIID riid, vo
     return ddraw7_QueryInterface(&This->IDirectDraw7_iface, riid, object);
 }
 
-static HRESULT WINAPI ddraw3_QueryInterface(IDirectDraw3 *iface, REFIID riid, void **object)
-{
-    IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
-
-    TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
-
-    return ddraw7_QueryInterface(&This->IDirectDraw7_iface, riid, object);
-}
-
 static HRESULT WINAPI ddraw2_QueryInterface(IDirectDraw2 *iface, REFIID riid, void **object)
 {
     IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
@@ -348,18 +351,6 @@ static ULONG WINAPI ddraw4_AddRef(IDirectDraw4 *iface)
     return ref;
 }
 
-static ULONG WINAPI ddraw3_AddRef(IDirectDraw3 *iface)
-{
-    IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
-    ULONG ref = InterlockedIncrement(&This->ref3);
-
-    TRACE("%p increasing refcount to %u.\n", This, ref);
-
-    if (ref == 1) InterlockedIncrement(&This->numIfaces);
-
-    return ref;
-}
-
 static ULONG WINAPI ddraw2_AddRef(IDirectDraw2 *iface)
 {
     IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
@@ -420,6 +411,51 @@ static ULONG WINAPI d3d1_AddRef(IDirect3D *iface)
     return ddraw1_AddRef(&This->IDirectDraw_iface);
 }
 
+void ddraw_destroy_swapchain(IDirectDrawImpl *ddraw)
+{
+    TRACE("Destroying the swapchain.\n");
+
+    wined3d_swapchain_decref(ddraw->wined3d_swapchain);
+    ddraw->wined3d_swapchain = NULL;
+
+    if (DefaultSurfaceType == SURFACE_OPENGL)
+    {
+        UINT i;
+
+        for (i = 0; i < ddraw->numConvertedDecls; ++i)
+        {
+            wined3d_vertex_declaration_decref(ddraw->decls[i].decl);
+        }
+        HeapFree(GetProcessHeap(), 0, ddraw->decls);
+        ddraw->numConvertedDecls = 0;
+
+        if (FAILED(wined3d_device_uninit_3d(ddraw->wined3d_device)))
+        {
+            ERR("Failed to uninit 3D.\n");
+        }
+        else
+        {
+            /* Free the d3d window if one was created. */
+            if (ddraw->d3d_window && ddraw->d3d_window != ddraw->dest_window)
+            {
+                TRACE("Destroying the hidden render window %p.\n", ddraw->d3d_window);
+                DestroyWindow(ddraw->d3d_window);
+                ddraw->d3d_window = 0;
+            }
+        }
+
+        ddraw->d3d_initialized = FALSE;
+    }
+    else
+    {
+        wined3d_device_uninit_gdi(ddraw->wined3d_device);
+    }
+
+    ddraw_set_swapchain_window(ddraw, NULL);
+
+    TRACE("Swapchain destroyed.\n");
+}
+
 /*****************************************************************************
  * ddraw_destroy
  *
@@ -443,13 +479,14 @@ static void ddraw_destroy(IDirectDrawImpl *This)
         This->devicewindow = 0;
     }
 
-    EnterCriticalSection(&ddraw_cs);
+    wined3d_mutex_lock();
     list_remove(&This->ddraw_list_entry);
-    LeaveCriticalSection(&ddraw_cs);
+    wined3d_mutex_unlock();
 
-    /* Release the attached WineD3D stuff */
+    if (This->wined3d_swapchain)
+        ddraw_destroy_swapchain(This);
     wined3d_device_decref(This->wined3d_device);
-    wined3d_decref(This->wineD3D);
+    wined3d_decref(This->wined3d);
 
     /* Now free the object */
     HeapFree(GetProcessHeap(), 0, This);
@@ -488,19 +525,6 @@ static ULONG WINAPI ddraw4_Release(IDirectDraw4 *iface)
     return ref;
 }
 
-static ULONG WINAPI ddraw3_Release(IDirectDraw3 *iface)
-{
-    IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
-    ULONG ref = InterlockedDecrement(&This->ref3);
-
-    TRACE("%p decreasing refcount to %u.\n", This, ref);
-
-    if (!ref && !InterlockedDecrement(&This->numIfaces))
-        ddraw_destroy(This);
-
-    return ref;
-}
-
 static ULONG WINAPI ddraw2_Release(IDirectDraw2 *iface)
 {
     IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
@@ -567,6 +591,127 @@ static ULONG WINAPI d3d1_Release(IDirect3D *iface)
  * IDirectDraw methods
  *****************************************************************************/
 
+static HRESULT ddraw_set_focus_window(IDirectDrawImpl *ddraw, HWND window)
+{
+    /* FIXME: This looks wrong, exclusive mode should imply a destination
+     * window. */
+    if ((ddraw->cooperative_level & DDSCL_EXCLUSIVE) && ddraw->dest_window)
+    {
+        TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET.\n");
+        return DDERR_HWNDALREADYSET;
+    }
+
+    ddraw->focuswindow = window;
+
+    /* Use the focus window for drawing too. */
+    ddraw->dest_window = ddraw->focuswindow;
+
+    return DD_OK;
+}
+
+static HRESULT ddraw_attach_d3d_device(IDirectDrawImpl *ddraw,
+        struct wined3d_swapchain_desc *swapchain_desc)
+{
+    HWND window = swapchain_desc->device_window;
+    HRESULT hr;
+
+    TRACE("ddraw %p.\n", ddraw);
+
+    if (!window || window == GetDesktopWindow())
+    {
+        window = CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME, "Hidden D3D Window",
+                WS_DISABLED, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
+                NULL, NULL, NULL, NULL);
+        if (!window)
+        {
+            ERR("Failed to create window, last error %#x.\n", GetLastError());
+            return E_FAIL;
+        }
+
+        ShowWindow(window, SW_HIDE);   /* Just to be sure */
+        WARN("No window for the Direct3DDevice, created hidden window %p.\n", window);
+
+        swapchain_desc->device_window = window;
+    }
+    else
+    {
+        TRACE("Using existing window %p for Direct3D rendering.\n", window);
+    }
+    ddraw->d3d_window = window;
+
+    /* Set this NOW, otherwise creating the depth stencil surface will cause a
+     * recursive loop until ram or emulated video memory is full. */
+    ddraw->d3d_initialized = TRUE;
+    hr = wined3d_device_init_3d(ddraw->wined3d_device, swapchain_desc);
+    if (FAILED(hr))
+    {
+        ddraw->d3d_initialized = FALSE;
+        return hr;
+    }
+
+    ddraw->declArraySize = 2;
+    ddraw->decls = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*ddraw->decls) * ddraw->declArraySize);
+    if (!ddraw->decls)
+    {
+        ERR("Error allocating an array for the converted vertex decls.\n");
+        ddraw->declArraySize = 0;
+        hr = wined3d_device_uninit_3d(ddraw->wined3d_device);
+        return E_OUTOFMEMORY;
+    }
+
+    TRACE("Successfully initialized 3D.\n");
+
+    return DD_OK;
+}
+
+static HRESULT ddraw_create_swapchain(IDirectDrawImpl *ddraw, HWND window, BOOL windowed)
+{
+    struct wined3d_swapchain_desc swapchain_desc;
+    struct wined3d_display_mode mode;
+    HRESULT hr = WINED3D_OK;
+
+    /* FIXME: wined3d_get_adapter_display_mode() would be more appropriate
+     * here, since we don't actually have a swapchain yet, but
+     * wined3d_device_get_display_mode() has some special handling for color
+     * depth changes. */
+    hr = wined3d_device_get_display_mode(ddraw->wined3d_device, 0, &mode);
+    if (FAILED(hr))
+    {
+        ERR("Failed to get display mode.\n");
+        return hr;
+    }
+
+    memset(&swapchain_desc, 0, sizeof(swapchain_desc));
+    swapchain_desc.backbuffer_width = mode.width;
+    swapchain_desc.backbuffer_height = mode.height;
+    swapchain_desc.backbuffer_format = mode.format_id;
+    swapchain_desc.swap_effect = WINED3D_SWAP_EFFECT_COPY;
+    swapchain_desc.device_window = window;
+    swapchain_desc.windowed = windowed;
+
+    if (DefaultSurfaceType == SURFACE_OPENGL)
+        hr = ddraw_attach_d3d_device(ddraw, &swapchain_desc);
+    else
+        hr = wined3d_device_init_gdi(ddraw->wined3d_device, &swapchain_desc);
+
+    if (FAILED(hr))
+    {
+        ERR("Failed to create swapchain, hr %#x.\n", hr);
+        return hr;
+    }
+
+    if (FAILED(hr = wined3d_device_get_swapchain(ddraw->wined3d_device, 0, &ddraw->wined3d_swapchain)))
+    {
+        ERR("Failed to get swapchain, hr %#x.\n", hr);
+        ddraw->wined3d_swapchain = NULL;
+        return hr;
+    }
+
+    ddraw_set_swapchain_window(ddraw, window);
+
+    return DD_OK;
+}
+
 /*****************************************************************************
  * IDirectDraw7::SetCooperativeLevel
  *
@@ -614,12 +759,16 @@ static ULONG WINAPI d3d1_Release(IDirect3D *iface)
 static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd, DWORD cooplevel)
 {
     IDirectDrawImpl *This = impl_from_IDirectDraw7(iface);
+    struct wined3d_stateblock *stateblock;
+    struct wined3d_surface *rt, *ds;
+    BOOL restore_state = FALSE;
     HWND window;
+    HRESULT hr;
 
     TRACE("iface %p, window %p, flags %#x.\n", iface, hwnd, cooplevel);
     DDRAW_dump_cooperativelevel(cooplevel);
 
-    EnterCriticalSection(&ddraw_cs);
+    wined3d_mutex_lock();
 
     /* Get the old window */
     window = This->dest_window;
@@ -630,69 +779,103 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd,
                       DDSCL_EXCLUSIVE      )))
     {
         TRACE("Incorrect cooplevel flags, returning DDERR_INVALIDPARAMS\n");
-        LeaveCriticalSection(&ddraw_cs);
+        wined3d_mutex_unlock();
+        return DDERR_INVALIDPARAMS;
+    }
+
+    if ((cooplevel & DDSCL_CREATEDEVICEWINDOW) && !(cooplevel & DDSCL_EXCLUSIVE))
+    {
+        WARN("DDSCL_CREATEDEVICEWINDOW requires DDSCL_EXCLUSIVE.\n");
+        wined3d_mutex_unlock();
         return DDERR_INVALIDPARAMS;
     }
 
     /* Handle those levels first which set various hwnds */
-    if(cooplevel & DDSCL_SETFOCUSWINDOW)
+    if ((cooplevel & DDSCL_SETFOCUSWINDOW) && !(cooplevel & DDSCL_CREATEDEVICEWINDOW))
     {
         /* This isn't compatible with a lot of flags */
-        if(cooplevel & ( DDSCL_MULTITHREADED      |
-                         DDSCL_CREATEDEVICEWINDOW |
-                         DDSCL_FPUSETUP           |
-                         DDSCL_FPUPRESERVE        |
-                         DDSCL_ALLOWREBOOT        |
-                         DDSCL_ALLOWMODEX         |
-                         DDSCL_SETDEVICEWINDOW    |
-                         DDSCL_NORMAL             |
-                         DDSCL_EXCLUSIVE          |
-                         DDSCL_FULLSCREEN         ) )
+        if (cooplevel & (DDSCL_MULTITHREADED
+                | DDSCL_FPUSETUP
+                | DDSCL_FPUPRESERVE
+                | DDSCL_ALLOWREBOOT
+                | DDSCL_ALLOWMODEX
+                | DDSCL_SETDEVICEWINDOW
+                | DDSCL_NORMAL
+                | DDSCL_EXCLUSIVE
+                | DDSCL_FULLSCREEN))
         {
-            TRACE("Called with incompatible flags, returning DDERR_INVALIDPARAMS\n");
-            LeaveCriticalSection(&ddraw_cs);
+            WARN("Called with incompatible flags, returning DDERR_INVALIDPARAMS.\n");
+            wined3d_mutex_unlock();
             return DDERR_INVALIDPARAMS;
         }
 
-        if( (This->cooperative_level & DDSCL_EXCLUSIVE) && window )
+        hr = ddraw_set_focus_window(This, hwnd);
+        wined3d_mutex_unlock();
+        return hr;
+    }
+
+    if (cooplevel & DDSCL_EXCLUSIVE)
+    {
+        if (!(cooplevel & DDSCL_FULLSCREEN) || !(hwnd || (cooplevel & DDSCL_CREATEDEVICEWINDOW)))
         {
-            TRACE("Setting DDSCL_SETFOCUSWINDOW with an already set window, returning DDERR_HWNDALREADYSET\n");
-            LeaveCriticalSection(&ddraw_cs);
-            return DDERR_HWNDALREADYSET;
+            WARN("DDSCL_EXCLUSIVE requires DDSCL_FULLSCREEN and a window.\n");
+            wined3d_mutex_unlock();
+            return DDERR_INVALIDPARAMS;
         }
 
-        This->focuswindow = hwnd;
-        /* Won't use the hwnd param for anything else */
-        hwnd = NULL;
+        if (cooplevel & DDSCL_CREATEDEVICEWINDOW)
+        {
+            HWND device_window;
+
+            if (!This->focuswindow && !(cooplevel & DDSCL_SETFOCUSWINDOW))
+            {
+                WARN("No focus window set.\n");
+                wined3d_mutex_unlock();
+                return DDERR_NOFOCUSWINDOW;
+            }
 
-        /* Use the focus window for drawing too */
-        This->dest_window = This->focuswindow;
+            device_window = CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME, "DirectDrawDeviceWnd",
+                    WS_POPUP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
+                    NULL, NULL, NULL, NULL);
+            if (!device_window)
+            {
+                ERR("Failed to create window, last error %#x.\n", GetLastError());
+                wined3d_mutex_unlock();
+                return E_FAIL;
+            }
 
-        /* Destroy the device window, if we have one */
-        if(This->devicewindow)
-        {
-            DestroyWindow(This->devicewindow);
-            This->devicewindow = NULL;
-        }
+            ShowWindow(device_window, SW_SHOW);
+            TRACE("Created a device window %p.\n", device_window);
 
-        LeaveCriticalSection(&ddraw_cs);
-        return DD_OK;
-    }
+            /* Native apparently leaks the created device window if setting the
+             * focus window below fails. */
+            This->cooperative_level |= DDSCL_CREATEDEVICEWINDOW;
+            This->devicewindow = device_window;
 
-    if(cooplevel & DDSCL_EXCLUSIVE)
-    {
-        if( !(cooplevel & DDSCL_FULLSCREEN) || !hwnd )
-        {
-            TRACE("(%p) DDSCL_EXCLUSIVE needs DDSCL_FULLSCREEN and a window\n", This);
-            LeaveCriticalSection(&ddraw_cs);
-            return DDERR_INVALIDPARAMS;
+            if (cooplevel & DDSCL_SETFOCUSWINDOW)
+            {
+                if (!hwnd)
+                {
+                    wined3d_mutex_unlock();
+                    return DDERR_NOHWND;
+                }
+
+                if (FAILED(hr = ddraw_set_focus_window(This, hwnd)))
+                {
+                    wined3d_mutex_unlock();
+                    return hr;
+                }
+            }
+
+            hwnd = device_window;
         }
     }
-    else if( !(cooplevel & DDSCL_NORMAL) )
+    else
     {
-        TRACE("(%p) SetCooperativeLevel needs at least SetFocusWindow or Exclusive or Normal mode\n", This);
-        LeaveCriticalSection(&ddraw_cs);
-        return DDERR_INVALIDPARAMS;
+        if (This->cooperative_level & DDSCL_CREATEDEVICEWINDOW)
+            DestroyWindow(This->devicewindow);
+        This->devicewindow = NULL;
+        This->focuswindow = NULL;
     }
 
     if ((This->cooperative_level & DDSCL_EXCLUSIVE)
@@ -706,22 +889,22 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd,
 
         if (cooplevel & DDSCL_FULLSCREEN)
         {
-            WINED3DDISPLAYMODE display_mode;
+            struct wined3d_display_mode display_mode;
 
-            wined3d_get_adapter_display_mode(This->wineD3D, WINED3DADAPTER_DEFAULT, &display_mode);
+            wined3d_get_adapter_display_mode(This->wined3d, WINED3DADAPTER_DEFAULT, &display_mode);
             wined3d_device_setup_fullscreen_window(This->wined3d_device, hwnd,
-                    display_mode.Width, display_mode.Height);
+                    display_mode.width, display_mode.height);
         }
     }
 
     if ((cooplevel & DDSCL_EXCLUSIVE)
             && (hwnd != window || !(This->cooperative_level & DDSCL_EXCLUSIVE)))
     {
-        HRESULT hr = wined3d_device_acquire_focus_window(This->wined3d_device, hwnd);
+        hr = wined3d_device_acquire_focus_window(This->wined3d_device, hwnd);
         if (FAILED(hr))
         {
             ERR("Failed to acquire focus window, hr %#x.\n", hr);
-            LeaveCriticalSection(&ddraw_cs);
+            wined3d_mutex_unlock();
             return hr;
         }
     }
@@ -730,31 +913,69 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd,
     if (hwnd && !This->focuswindow && !This->devicewindow && (hwnd != window))
         This->dest_window = hwnd;
 
-    if(cooplevel & DDSCL_CREATEDEVICEWINDOW)
+    if (cooplevel & DDSCL_MULTITHREADED && !(This->cooperative_level & DDSCL_MULTITHREADED))
+        wined3d_device_set_multithreaded(This->wined3d_device);
+
+    if (This->wined3d_swapchain)
     {
-        /* Don't create a device window if a focus window is set */
-        if( !(This->focuswindow) )
+        if (DefaultSurfaceType != SURFACE_GDI)
         {
-            HWND devicewindow = CreateWindowExA(0, DDRAW_WINDOW_CLASS_NAME, "DDraw device window",
-                    WS_POPUP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN),
-                    NULL, NULL, NULL, NULL);
-            if (!devicewindow)
+            restore_state = TRUE;
+
+            if (FAILED(hr = wined3d_stateblock_create(This->wined3d_device, WINED3D_SBT_ALL, &stateblock)))
             {
-                ERR("Failed to create window, last error %#x.\n", GetLastError());
-                LeaveCriticalSection(&ddraw_cs);
-                return E_FAIL;
+                ERR("Failed to create stateblock, hr %#x.\n", hr);
+                wined3d_mutex_unlock();
+                return hr;
             }
 
-            ShowWindow(devicewindow, SW_SHOW);   /* Just to be sure */
-            TRACE("(%p) Created a DDraw device window. HWND=%p\n", This, devicewindow);
+            if (FAILED(hr = wined3d_stateblock_capture(stateblock)))
+            {
+                ERR("Failed to capture stateblock, hr %#x.\n", hr);
+                wined3d_stateblock_decref(stateblock);
+                wined3d_mutex_unlock();
+                return hr;
+            }
+
+            wined3d_device_get_render_target(This->wined3d_device, 0, &rt);
+            if (rt == This->wined3d_frontbuffer)
+            {
+                wined3d_surface_decref(rt);
+                rt = NULL;
+            }
 
-            This->devicewindow = devicewindow;
-            This->dest_window = devicewindow;
+            wined3d_device_get_depth_stencil(This->wined3d_device, &ds);
         }
+
+        ddraw_destroy_swapchain(This);
     }
 
-    if (cooplevel & DDSCL_MULTITHREADED && !(This->cooperative_level & DDSCL_MULTITHREADED))
-        wined3d_device_set_multithreaded(This->wined3d_device);
+    if (FAILED(hr = ddraw_create_swapchain(This, This->dest_window, !(cooplevel & DDSCL_FULLSCREEN))))
+        ERR("Failed to create swapchain, hr %#x.\n", hr);
+
+    if (restore_state)
+    {
+        if (ds)
+        {
+            wined3d_device_set_depth_stencil(This->wined3d_device, ds);
+            wined3d_surface_decref(ds);
+        }
+
+        if (rt)
+        {
+            wined3d_device_set_render_target(This->wined3d_device, 0, rt, FALSE);
+            wined3d_surface_decref(rt);
+        }
+
+        hr = wined3d_stateblock_apply(stateblock);
+        wined3d_stateblock_decref(stateblock);
+        if (FAILED(hr))
+        {
+            ERR("Failed to apply stateblock, hr %#x.\n", hr);
+            wined3d_mutex_unlock();
+            return hr;
+        }
+    }
 
     /* Unhandled flags */
     if(cooplevel & DDSCL_ALLOWREBOOT)
@@ -767,7 +988,8 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd,
     /* Store the cooperative_level */
     This->cooperative_level = cooplevel;
     TRACE("SetCooperativeLevel retuning DD_OK\n");
-    LeaveCriticalSection(&ddraw_cs);
+    wined3d_mutex_unlock();
+
     return DD_OK;
 }
 
@@ -780,15 +1002,6 @@ static HRESULT WINAPI ddraw4_SetCooperativeLevel(IDirectDraw4 *iface, HWND windo
     return ddraw7_SetCooperativeLevel(&This->IDirectDraw7_iface, window, flags);
 }
 
-static HRESULT WINAPI ddraw3_SetCooperativeLevel(IDirectDraw3 *iface, HWND window, DWORD flags)
-{
-    IDirectDrawImpl *This = impl_from_IDirectDraw3(iface);
-
-    TRACE("iface %p, window %p, flags %#x.\n", iface, window, flags);
-
-    return ddraw7_SetCooperativeLevel(&This->IDirectDraw7_iface, window, flags);
-}
-
 static HRESULT WINAPI ddraw2_SetCooperativeLevel(IDirectDraw2 *iface, HWND window, DWORD flags)
 {
     IDirectDrawImpl *This = impl_from_IDirectDraw2(iface);
@@ -822,19 +1035,19 @@ static HRESULT WINAPI ddraw1_SetCooperativeLevel(IDirectDraw *iface, HWND window
 static HRESULT ddraw_set_display_mode(IDirectDrawImpl *ddraw, DWORD Width, DWORD Height,
         DWORD BPP, DWORD RefreshRate, DWORD Flags)
 {
+    struct wined3d_display_mode mode;
     enum wined3d_format_id format;
-    WINED3DDISPLAYMODE Mode;
     HRESULT hr;
 
     TRACE("ddraw %p, width %u, height %u, bpp %u, refresh_rate %u, flags %#x.\n", ddraw, Width,
             Height, BPP, RefreshRate, Flags);
 
-    EnterCriticalSection(&ddraw_cs);
+    wined3d_mutex_lock();
     if( !Width || !Height )
     {
         ERR("Width %u, Height %u, what to do?\n", Width, Height);
         /* It looks like Need for Speed Porsche Unleashed expects DD_OK here */
-        LeaveCriticalSection(&ddraw_cs);
+        wined3d_mutex_unlock();
         return DD_OK;
     }
 
@@ -8