[PATCH 3/4] wined3d: Remove COM from IWineD3D.

Henri Verbeet hverbeet at codeweavers.com
Tue Feb 1 12:39:53 CST 2011


---
 dlls/d3d8/d3d8_main.c          |    2 +-
 dlls/d3d8/d3d8_private.h       |    6 +-
 dlls/d3d8/device.c             |   14 +-
 dlls/d3d8/directx.c            |   28 +-
 dlls/d3d9/d3d9_main.c          |    2 +-
 dlls/d3d9/d3d9_private.h       |    5 +-
 dlls/d3d9/device.c             |   23 +-
 dlls/d3d9/directx.c            |   30 +-
 dlls/ddraw/ddraw.c             |   44 +-
 dlls/ddraw/ddraw_private.h     |    5 +-
 dlls/ddraw/device.c            |   37 +-
 dlls/dxgi/adapter.c            |    6 +-
 dlls/dxgi/device.c             |    8 +-
 dlls/dxgi/dxgi_private.h       |    2 +-
 dlls/dxgi/factory.c            |   12 +-
 dlls/dxgi/output.c             |   12 +-
 dlls/wined3d/device.c          |   56 ++-
 dlls/wined3d/directx.c         | 1057 +++++++++++++++++++---------------------
 dlls/wined3d/swapchain.c       |    2 +-
 dlls/wined3d/swapchain_base.c  |    2 +-
 dlls/wined3d/wined3d.spec      |   21 +-
 dlls/wined3d/wined3d_main.c    |    2 +-
 dlls/wined3d/wined3d_private.h |   18 +-
 include/wine/wined3d.idl       |  128 ++----
 include/wine/winedxgi.idl      |    2 +-
 25 files changed, 721 insertions(+), 803 deletions(-)

diff --git a/dlls/d3d8/d3d8_main.c b/dlls/d3d8/d3d8_main.c
index 19adfea..7a25a93 100644
--- a/dlls/d3d8/d3d8_main.c
+++ b/dlls/d3d8/d3d8_main.c
@@ -45,7 +45,7 @@ IDirect3D8* WINAPI DECLSPEC_HOTPATCH Direct3DCreate8(UINT SDKVersion) {
 
     object->IDirect3D8_iface.lpVtbl = &Direct3D8_Vtbl;
     object->ref = 1;
-    object->WineD3D = WineDirect3DCreate(8, (IUnknown *)&object->IDirect3D8_iface);
+    object->WineD3D = wined3d_create(8, &object->IDirect3D8_iface);
 
     TRACE("Created Direct3D object @ %p, WineObj @ %p\n", object, object->WineD3D);
 
diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h
index ce34ca6..ed7c81a 100644
--- a/dlls/d3d8/d3d8_private.h
+++ b/dlls/d3d8/d3d8_private.h
@@ -133,9 +133,7 @@ struct IDirect3D8Impl
 {
     IDirect3D8 IDirect3D8_iface;
     LONG       ref;
-
-    /* The WineD3D device */
-    IWineD3D   *WineD3D;
+    struct wined3d *WineD3D;
 };
 
 /*****************************************************************************
@@ -191,7 +189,7 @@ struct IDirect3DDevice8Impl
     BOOL                    inDestruction;
 };
 
-HRESULT device_init(IDirect3DDevice8Impl *device, IWineD3D *wined3d, UINT adapter,
+HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT adapter,
         D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters) DECLSPEC_HIDDEN;
 
 /* ---------------- */
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index f7807d4..1ac9cea 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -382,7 +382,7 @@ static HRESULT WINAPI IDirect3DDevice8Impl_ResourceManagerDiscardBytes(IDirect3D
 static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(IDirect3DDevice8 *iface, IDirect3D8 **ppD3D8)
 {
     IDirect3DDevice8Impl *This = impl_from_IDirect3DDevice8(iface);
-    IWineD3D *pWineD3D;
+    struct wined3d *wined3d;
     HRESULT hr;
 
     TRACE("iface %p, d3d8 %p.\n", iface, ppD3D8);
@@ -392,12 +392,12 @@ static HRESULT WINAPI IDirect3DDevice8Impl_GetDirect3D(IDirect3DDevice8 *iface,
     }
 
     wined3d_mutex_lock();
-    hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
-    if (SUCCEEDED(hr) && pWineD3D)
+    hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &wined3d);
+    if (SUCCEEDED(hr) && wined3d)
     {
-        *ppD3D8 = IWineD3D_GetParent(pWineD3D);
+        *ppD3D8 = wined3d_get_parent(wined3d);
         IDirect3D8_AddRef(*ppD3D8);
-        IWineD3D_Release(pWineD3D);
+        wined3d_decref(wined3d);
     }
     else
     {
@@ -2966,7 +2966,7 @@ static void setup_fpu(void)
 #endif
 }
 
-HRESULT device_init(IDirect3DDevice8Impl *device, IWineD3D *wined3d, UINT adapter,
+HRESULT device_init(IDirect3DDevice8Impl *device, struct wined3d *wined3d, UINT adapter,
         D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
 {
     WINED3DPRESENT_PARAMETERS wined3d_parameters;
@@ -2987,7 +2987,7 @@ HRESULT device_init(IDirect3DDevice8Impl *device, IWineD3D *wined3d, UINT adapte
     if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
 
     wined3d_mutex_lock();
-    hr = IWineD3D_CreateDevice(wined3d, adapter, device_type, focus_window, flags,
+    hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags,
             &device->IWineD3DDeviceParent_iface, &device->WineD3DDevice);
     if (FAILED(hr))
     {
diff --git a/dlls/d3d8/directx.c b/dlls/d3d8/directx.c
index f2e6323..249399e 100644
--- a/dlls/d3d8/directx.c
+++ b/dlls/d3d8/directx.c
@@ -81,7 +81,7 @@ static ULONG WINAPI IDirect3D8Impl_Release(LPDIRECT3D8 iface)
         TRACE("Releasing wined3d %p\n", This->WineD3D);
 
         wined3d_mutex_lock();
-        IWineD3D_Release(This->WineD3D);
+        wined3d_decref(This->WineD3D);
         wined3d_mutex_unlock();
 
         HeapFree(GetProcessHeap(), 0, This);
@@ -99,7 +99,7 @@ static HRESULT WINAPI IDirect3D8Impl_RegisterSoftwareDevice(LPDIRECT3D8 iface,
     TRACE("iface %p, init_function %p.\n", iface, pInitializeFunction);
 
     wined3d_mutex_lock();
-    hr = IWineD3D_RegisterSoftwareDevice(This->WineD3D, pInitializeFunction);
+    hr = wined3d_register_software_device(This->WineD3D, pInitializeFunction);
     wined3d_mutex_unlock();
 
     return hr;
@@ -113,7 +113,7 @@ static UINT WINAPI IDirect3D8Impl_GetAdapterCount(LPDIRECT3D8 iface)
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    hr = IWineD3D_GetAdapterCount(This->WineD3D);
+    hr = wined3d_get_adapter_count(This->WineD3D);
     wined3d_mutex_unlock();
 
     return hr;
@@ -137,7 +137,7 @@ static HRESULT WINAPI IDirect3D8Impl_GetAdapterIdentifier(LPDIRECT3D8 iface, UIN
     adapter_id.device_name_size = 0; /* d3d9 only */
 
     wined3d_mutex_lock();
-    hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
+    hr = wined3d_get_adapter_identifier(This->WineD3D, Adapter, Flags, &adapter_id);
     wined3d_mutex_unlock();
 
     pIdentifier->DriverVersion = adapter_id.driver_version;
@@ -159,7 +159,7 @@ static UINT WINAPI IDirect3D8Impl_GetAdapterModeCount(LPDIRECT3D8 iface,UINT Ada
     TRACE("iface %p, adapter %u.\n", iface, Adapter);
 
     wined3d_mutex_lock();
-    hr = IWineD3D_GetAdapterModeCount(This->WineD3D, Adapter, 0 /* format */);
+    hr = wined3d_get_adapter_mode_count(This->WineD3D, Adapter, 0);
     wined3d_mutex_unlock();
 
     return hr;
@@ -175,7 +175,7 @@ static HRESULT WINAPI IDirect3D8Impl_EnumAdapterModes(LPDIRECT3D8 iface, UINT Ad
             iface, Adapter, Mode, pMode);
 
     wined3d_mutex_lock();
-    hr = IWineD3D_EnumAdapterModes(This->WineD3D, Adapter, WINED3DFMT_UNKNOWN, Mode, (WINED3DDISPLAYMODE *) pMode);
+    hr = wined3d_enum_adapter_modes(This->WineD3D, Adapter, WINED3DFMT_UNKNOWN, Mode, (WINED3DDISPLAYMODE *)pMode);
     wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -193,7 +193,7 @@ static HRESULT WINAPI IDirect3D8Impl_GetAdapterDisplayMode(LPDIRECT3D8 iface, UI
             iface, Adapter, pMode);
 
     wined3d_mutex_lock();
-    hr = IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *) pMode);
+    hr = wined3d_get_adapter_display_mode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *)pMode);
     wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -211,7 +211,7 @@ static HRESULT WINAPI IDirect3D8Impl_CheckDeviceType(LPDIRECT3D8 iface, UINT Ada
             iface, Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed);
 
     wined3d_mutex_lock();
-    hr = IWineD3D_CheckDeviceType(This->WineD3D, Adapter, CheckType, wined3dformat_from_d3dformat(DisplayFormat),
+    hr = wined3d_check_device_type(This->WineD3D, Adapter, CheckType, wined3dformat_from_d3dformat(DisplayFormat),
             wined3dformat_from_d3dformat(BackBufferFormat), Windowed);
     wined3d_mutex_unlock();
 
@@ -249,7 +249,7 @@ static HRESULT WINAPI IDirect3D8Impl_CheckDeviceFormat(LPDIRECT3D8 iface, UINT A
     }
 
     wined3d_mutex_lock();
-    hr = IWineD3D_CheckDeviceFormat(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
+    hr = wined3d_check_device_format(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
             Usage, WineD3DRType, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL);
     wined3d_mutex_unlock();
 
@@ -267,8 +267,8 @@ static HRESULT WINAPI IDirect3D8Impl_CheckDeviceMultiSampleType(IDirect3D8 *ifac
             iface, Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType);
 
     wined3d_mutex_lock();
-    hr = IWineD3D_CheckDeviceMultiSampleType(This->WineD3D, Adapter, DeviceType,
-            wined3dformat_from_d3dformat(SurfaceFormat), Windowed, (WINED3DMULTISAMPLE_TYPE) MultiSampleType, NULL);
+    hr = wined3d_check_device_multisample_type(This->WineD3D, Adapter, DeviceType,
+            wined3dformat_from_d3dformat(SurfaceFormat), Windowed, (WINED3DMULTISAMPLE_TYPE)MultiSampleType, NULL);
     wined3d_mutex_unlock();
 
     return hr;
@@ -285,7 +285,7 @@ static HRESULT WINAPI IDirect3D8Impl_CheckDepthStencilMatch(IDirect3D8 *iface, U
             iface, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
 
     wined3d_mutex_lock();
-    hr = IWineD3D_CheckDepthStencilMatch(This->WineD3D, Adapter, DeviceType,
+    hr = wined3d_check_depth_stencil_match(This->WineD3D, Adapter, DeviceType,
             wined3dformat_from_d3dformat(AdapterFormat), wined3dformat_from_d3dformat(RenderTargetFormat),
             wined3dformat_from_d3dformat(DepthStencilFormat));
     wined3d_mutex_unlock();
@@ -325,7 +325,7 @@ static HRESULT  WINAPI  IDirect3D8Impl_GetDeviceCaps(LPDIRECT3D8 iface, UINT Ada
     }
 
     wined3d_mutex_lock();
-    hrc = IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, pWineCaps);
+    hrc = wined3d_get_device_caps(This->WineD3D, Adapter, DeviceType, pWineCaps);
     wined3d_mutex_unlock();
 
     fixup_caps(pWineCaps);
@@ -344,7 +344,7 @@ static HMONITOR WINAPI  IDirect3D8Impl_GetAdapterMonitor(LPDIRECT3D8 iface, UINT
     TRACE("iface %p, adapter %u.\n", iface, Adapter);
 
     wined3d_mutex_lock();
-    ret = IWineD3D_GetAdapterMonitor(This->WineD3D, Adapter);
+    ret = wined3d_get_adapter_monitor(This->WineD3D, Adapter);
     wined3d_mutex_unlock();
 
     return ret;
diff --git a/dlls/d3d9/d3d9_main.c b/dlls/d3d9/d3d9_main.c
index c405a57..4ac481a 100644
--- a/dlls/d3d9/d3d9_main.c
+++ b/dlls/d3d9/d3d9_main.c
@@ -40,7 +40,7 @@ IDirect3D9* WINAPI DECLSPEC_HOTPATCH Direct3DCreate9(UINT SDKVersion) {
     object->ref = 1;
 
     wined3d_mutex_lock();
-    object->WineD3D = WineDirect3DCreate(9, (IUnknown *)object);
+    object->WineD3D = wined3d_create(9, object);
     wined3d_mutex_unlock();
 
     TRACE("SDKVersion = %x, Created Direct3D object @ %p, WineObj @ %p\n", SDKVersion, object, object->WineD3D);
diff --git a/dlls/d3d9/d3d9_private.h b/dlls/d3d9/d3d9_private.h
index e2429d1..9f9e5a9 100644
--- a/dlls/d3d9/d3d9_private.h
+++ b/dlls/d3d9/d3d9_private.h
@@ -149,8 +149,7 @@ typedef struct IDirect3D9Impl
     const IDirect3D9ExVtbl   *lpVtbl;
     LONG                    ref;
 
-    /* The WineD3D device */
-    IWineD3D               *WineD3D;
+    struct wined3d *WineD3D;
 
     /* Created via Direct3DCreate9Ex? Can QI extended interfaces */
     BOOL                    extended;
@@ -180,7 +179,7 @@ typedef struct IDirect3DDevice9Impl
     BOOL                          notreset;
 } IDirect3DDevice9Impl;
 
-HRESULT device_init(IDirect3DDevice9Impl *device, IWineD3D *wined3d, UINT adapter, D3DDEVTYPE device_type,
+HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT adapter, D3DDEVTYPE device_type,
         HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode) DECLSPEC_HIDDEN;
 
 /*****************************************************************************
diff --git a/dlls/d3d9/device.c b/dlls/d3d9/device.c
index cb75f2d..ca61934 100644
--- a/dlls/d3d9/device.c
+++ b/dlls/d3d9/device.c
@@ -323,10 +323,11 @@ static HRESULT  WINAPI  IDirect3DDevice9Impl_EvictManagedResources(LPDIRECT3DDEV
     return hr;
 }
 
-static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(LPDIRECT3DDEVICE9EX iface, IDirect3D9** ppD3D9) {
+static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(IDirect3DDevice9Ex *iface, IDirect3D9 **ppD3D9)
+{
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    struct wined3d *wined3d;
     HRESULT hr = D3D_OK;
-    IWineD3D* pWineD3D;
 
     TRACE("iface %p, d3d9 %p.\n", iface, ppD3D9);
 
@@ -335,13 +336,15 @@ static HRESULT WINAPI IDirect3DDevice9Impl_GetDirect3D(LPDIRECT3DDEVICE9EX iface
     }
 
     wined3d_mutex_lock();
-    hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &pWineD3D);
-    if (hr == D3D_OK && pWineD3D != NULL)
+    hr = IWineD3DDevice_GetDirect3D(This->WineD3DDevice, &wined3d);
+    if (hr == D3D_OK && wined3d)
     {
-        *ppD3D9 = IWineD3D_GetParent(pWineD3D);
+        *ppD3D9 = wined3d_get_parent(wined3d);
         IDirect3D9_AddRef(*ppD3D9);
-        IWineD3D_Release(pWineD3D);
-    } else {
+        wined3d_decref(wined3d);
+    }
+    else
+    {
         FIXME("Call to IWineD3DDevice_GetDirect3D failed\n");
         *ppD3D9 = NULL;
     }
@@ -3251,7 +3254,7 @@ static void setup_fpu(void)
 #endif
 }
 
-HRESULT device_init(IDirect3DDevice9Impl *device, IWineD3D *wined3d, UINT adapter, D3DDEVTYPE device_type,
+HRESULT device_init(IDirect3DDevice9Impl *device, struct wined3d *wined3d, UINT adapter, D3DDEVTYPE device_type,
         HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode)
 {
     WINED3DPRESENT_PARAMETERS *wined3d_parameters;
@@ -3268,7 +3271,7 @@ HRESULT device_init(IDirect3DDevice9Impl *device, IWineD3D *wined3d, UINT adapte
     if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
 
     wined3d_mutex_lock();
-    hr = IWineD3D_CreateDevice(wined3d, adapter, device_type, focus_window, flags,
+    hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags,
             (IWineD3DDeviceParent *)&device->device_parent_vtbl, &device->WineD3DDevice);
     if (FAILED(hr))
     {
@@ -3281,7 +3284,7 @@ HRESULT device_init(IDirect3DDevice9Impl *device, IWineD3D *wined3d, UINT adapte
     {
         WINED3DCAPS caps;
 
-        IWineD3D_GetDeviceCaps(wined3d, adapter, device_type, &caps);
+        wined3d_get_device_caps(wined3d, adapter, device_type, &caps);
         count = caps.NumberOfAdaptersInGroup;
     }
 
diff --git a/dlls/d3d9/directx.c b/dlls/d3d9/directx.c
index 3aa92a4..91524bb 100644
--- a/dlls/d3d9/directx.c
+++ b/dlls/d3d9/directx.c
@@ -72,7 +72,7 @@ static ULONG WINAPI IDirect3D9Impl_Release(LPDIRECT3D9EX iface) {
 
     if (ref == 0) {
         wined3d_mutex_lock();
-        IWineD3D_Release(This->WineD3D);
+        wined3d_decref(This->WineD3D);
         wined3d_mutex_unlock();
 
         HeapFree(GetProcessHeap(), 0, This);
@@ -89,7 +89,7 @@ static HRESULT  WINAPI  IDirect3D9Impl_RegisterSoftwareDevice(LPDIRECT3D9EX ifac
     TRACE("iface %p, init_function %p.\n", iface, pInitializeFunction);
 
     wined3d_mutex_lock();
-    hr = IWineD3D_RegisterSoftwareDevice(This->WineD3D, pInitializeFunction);
+    hr = wined3d_register_software_device(This->WineD3D, pInitializeFunction);
     wined3d_mutex_unlock();
 
     return hr;
@@ -102,7 +102,7 @@ static UINT     WINAPI  IDirect3D9Impl_GetAdapterCount(LPDIRECT3D9EX iface) {
     TRACE("iface %p.\n", iface);
 
     wined3d_mutex_lock();
-    hr = IWineD3D_GetAdapterCount(This->WineD3D);
+    hr = wined3d_get_adapter_count(This->WineD3D);
     wined3d_mutex_unlock();
 
     return hr;
@@ -124,7 +124,7 @@ static HRESULT WINAPI IDirect3D9Impl_GetAdapterIdentifier(LPDIRECT3D9EX iface, U
     adapter_id.device_name_size = sizeof(pIdentifier->DeviceName);
 
     wined3d_mutex_lock();
-    hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, Adapter, Flags, &adapter_id);
+    hr = wined3d_get_adapter_identifier(This->WineD3D, Adapter, Flags, &adapter_id);
     wined3d_mutex_unlock();
 
     pIdentifier->DriverVersion = adapter_id.driver_version;
@@ -150,7 +150,7 @@ static UINT WINAPI IDirect3D9Impl_GetAdapterModeCount(LPDIRECT3D9EX iface, UINT
     }
 
     wined3d_mutex_lock();
-    hr = IWineD3D_GetAdapterModeCount(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format));
+    hr = wined3d_get_adapter_mode_count(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format));
     wined3d_mutex_unlock();
 
     return hr;
@@ -169,7 +169,7 @@ static HRESULT WINAPI IDirect3D9Impl_EnumAdapterModes(LPDIRECT3D9EX iface, UINT
         return D3DERR_INVALIDCALL;
 
     wined3d_mutex_lock();
-    hr = IWineD3D_EnumAdapterModes(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format),
+    hr = wined3d_enum_adapter_modes(This->WineD3D, Adapter, wined3dformat_from_d3dformat(Format),
             Mode, (WINED3DDISPLAYMODE *) pMode);
     wined3d_mutex_unlock();
 
@@ -185,7 +185,7 @@ static HRESULT WINAPI IDirect3D9Impl_GetAdapterDisplayMode(LPDIRECT3D9EX iface,
     TRACE("iface %p, adapter %u, mode %p.\n", iface, Adapter, pMode);
 
     wined3d_mutex_lock();
-    hr = IWineD3D_GetAdapterDisplayMode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *) pMode);
+    hr = wined3d_get_adapter_display_mode(This->WineD3D, Adapter, (WINED3DDISPLAYMODE *)pMode);
     wined3d_mutex_unlock();
 
     if (SUCCEEDED(hr)) pMode->Format = d3dformat_from_wined3dformat(pMode->Format);
@@ -203,7 +203,7 @@ static HRESULT WINAPI IDirect3D9Impl_CheckDeviceType(IDirect3D9Ex *iface, UINT A
             iface, Adapter, CheckType, DisplayFormat, BackBufferFormat, Windowed);
 
     wined3d_mutex_lock();
-    hr = IWineD3D_CheckDeviceType(This->WineD3D, Adapter, CheckType, wined3dformat_from_d3dformat(DisplayFormat),
+    hr = wined3d_check_device_type(This->WineD3D, Adapter, CheckType, wined3dformat_from_d3dformat(DisplayFormat),
             wined3dformat_from_d3dformat(BackBufferFormat), Windowed);
     wined3d_mutex_unlock();
 
@@ -244,7 +244,7 @@ static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormat(IDirect3D9Ex *iface, UINT
     }
 
     wined3d_mutex_lock();
-    hr = IWineD3D_CheckDeviceFormat(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
+    hr = wined3d_check_device_format(This->WineD3D, Adapter, DeviceType, wined3dformat_from_d3dformat(AdapterFormat),
             Usage, WineD3DRType, wined3dformat_from_d3dformat(CheckFormat), SURFACE_OPENGL);
     wined3d_mutex_unlock();
 
@@ -262,7 +262,7 @@ static HRESULT WINAPI IDirect3D9Impl_CheckDeviceMultiSampleType(IDirect3D9Ex *if
             iface, Adapter, DeviceType, SurfaceFormat, Windowed, MultiSampleType, pQualityLevels);
 
     wined3d_mutex_lock();
-    hr = IWineD3D_CheckDeviceMultiSampleType(This->WineD3D, Adapter, DeviceType,
+    hr = wined3d_check_device_multisample_type(This->WineD3D, Adapter, DeviceType,
             wined3dformat_from_d3dformat(SurfaceFormat), Windowed, MultiSampleType, pQualityLevels);
     wined3d_mutex_unlock();
 
@@ -279,7 +279,7 @@ static HRESULT WINAPI IDirect3D9Impl_CheckDepthStencilMatch(IDirect3D9Ex *iface,
             iface, Adapter, DeviceType, AdapterFormat, RenderTargetFormat, DepthStencilFormat);
 
     wined3d_mutex_lock();
-    hr = IWineD3D_CheckDepthStencilMatch(This->WineD3D, Adapter, DeviceType,
+    hr = wined3d_check_depth_stencil_match(This->WineD3D, Adapter, DeviceType,
             wined3dformat_from_d3dformat(AdapterFormat), wined3dformat_from_d3dformat(RenderTargetFormat),
             wined3dformat_from_d3dformat(DepthStencilFormat));
     wined3d_mutex_unlock();
@@ -295,7 +295,7 @@ static HRESULT WINAPI IDirect3D9Impl_CheckDeviceFormatConversion(LPDIRECT3D9EX i
             iface, Adapter, DeviceType, SourceFormat, TargetFormat);
 
     wined3d_mutex_lock();
-    hr = IWineD3D_CheckDeviceFormatConversion(This->WineD3D, Adapter, DeviceType,
+    hr = wined3d_check_device_format_conversion(This->WineD3D, Adapter, DeviceType,
             wined3dformat_from_d3dformat(SourceFormat), wined3dformat_from_d3dformat(TargetFormat));
     wined3d_mutex_unlock();
 
@@ -379,7 +379,7 @@ static HRESULT WINAPI IDirect3D9Impl_GetDeviceCaps(LPDIRECT3D9EX iface, UINT Ada
     memset(pCaps, 0, sizeof(*pCaps));
 
     wined3d_mutex_lock();
-    hrc = IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, pWineCaps);
+    hrc = wined3d_get_device_caps(This->WineD3D, Adapter, DeviceType, pWineCaps);
     wined3d_mutex_unlock();
 
     WINECAPSTOD3D9CAPS(pCaps, pWineCaps)
@@ -401,7 +401,7 @@ static HMONITOR WINAPI IDirect3D9Impl_GetAdapterMonitor(LPDIRECT3D9EX iface, UIN
     TRACE("iface %p, adapter %u.\n", iface, Adapter);
 
     wined3d_mutex_lock();
-    ret = IWineD3D_GetAdapterMonitor(This->WineD3D, Adapter);
+    ret = wined3d_get_adapter_monitor(This->WineD3D, Adapter);
     wined3d_mutex_unlock();
 
     return ret;
@@ -510,7 +510,7 @@ static HRESULT WINAPI IDirect3D9ExImpl_GetAdapterLUID(IDirect3D9Ex *iface, UINT
     adapter_id.device_name_size = 0;
 
     wined3d_mutex_lock();
-    hr = IWineD3D_GetAdapterIdentifier(This->WineD3D, adapter, 0, &adapter_id);
+    hr = wined3d_get_adapter_identifier(This->WineD3D, adapter, 0, &adapter_id);
     wined3d_mutex_unlock();
 
     memcpy(luid, &adapter_id.adapter_luid, sizeof(*luid));
diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c
index f148e29..01de508 100644
--- a/dlls/ddraw/ddraw.c
+++ b/dlls/ddraw/ddraw.c
@@ -454,7 +454,7 @@ static void ddraw_destroy(IDirectDrawImpl *This)
 
     /* Release the attached WineD3D stuff */
     IWineD3DDevice_Release(This->wineD3DDevice);
-    IWineD3D_Release(This->wineD3D);
+    wined3d_decref(This->wineD3D);
 
     /* Now free the object */
     HeapFree(GetProcessHeap(), 0, This);
@@ -714,7 +714,7 @@ static HRESULT WINAPI ddraw7_SetCooperativeLevel(IDirectDraw7 *iface, HWND hwnd,
         {
             WINED3DDISPLAYMODE display_mode;
 
-            IWineD3D_GetAdapterDisplayMode(This->wineD3D, WINED3DADAPTER_DEFAULT, &display_mode);
+            wined3d_get_adapter_display_mode(This->wineD3D, WINED3DADAPTER_DEFAULT, &display_mode);
             IWineD3DDevice_SetupFullscreenWindow(This->wineD3DDevice, hwnd, display_mode.Width, display_mode.Height);
         }
     }
@@ -1364,20 +1364,15 @@ static HRESULT WINAPI ddraw7_GetFourCCCodes(IDirectDraw7 *iface, DWORD *NumCodes
 
     if(type == SURFACE_UNKNOWN) type = SURFACE_GDI;
 
-    for(i = 0; i < (sizeof(formats) / sizeof(formats[0])); i++) {
-        hr = IWineD3D_CheckDeviceFormat(This->wineD3D,
-                                        WINED3DADAPTER_DEFAULT,
-                                        WINED3DDEVTYPE_HAL,
-                                        d3ddm.Format /* AdapterFormat */,
-                                        0 /* usage */,
-                                        WINED3DRTYPE_SURFACE,
-                                        formats[i],
-                                        type);
-        if(SUCCEEDED(hr)) {
-            if(count < outsize) {
+    for (i = 0; i < (sizeof(formats) / sizeof(formats[0])); ++i)
+    {
+        hr = wined3d_check_device_format(This->wineD3D, WINED3DADAPTER_DEFAULT, WINED3DDEVTYPE_HAL,
+                d3ddm.Format, 0, WINED3DRTYPE_SURFACE, formats[i], type);
+        if (SUCCEEDED(hr))
+        {
+            if (count < outsize)
                 Codes[count] = formats[i];
-            }
-            count++;
+            ++count;
         }
     }
     if(NumCodes) {
@@ -2145,11 +2140,8 @@ static HRESULT WINAPI ddraw7_EnumDisplayModes(IDirectDraw7 *iface, DWORD Flags,
         }
 
         modenum = 0;
-        while(IWineD3D_EnumAdapterModes(This->wineD3D,
-                                        WINED3DADAPTER_DEFAULT,
-                                        checkFormatList[fmt],
-                                        modenum++,
-                                        &mode) == WINED3D_OK)
+        while (wined3d_enum_adapter_modes(This->wineD3D, WINED3DADAPTER_DEFAULT,
+                checkFormatList[fmt], modenum++, &mode) == WINED3D_OK)
         {
             if(DDSD)
             {
@@ -5027,7 +5019,7 @@ static HRESULT WINAPI d3d7_EnumZBufferFormats(IDirect3D7 *iface, REFCLSID device
 
     for (i = 0; i < (sizeof(formats) / sizeof(*formats)); ++i)
     {
-        hr = IWineD3D_CheckDeviceFormat(This->wineD3D, WINED3DADAPTER_DEFAULT, type, d3ddm.Format,
+        hr = wined3d_check_device_format(This->wineD3D, WINED3DADAPTER_DEFAULT, type, d3ddm.Format,
                 WINED3DUSAGE_DEPTHSTENCIL, WINED3DRTYPE_SURFACE, formats[i], SURFACE_OPENGL);
         if (SUCCEEDED(hr))
         {
@@ -5111,7 +5103,7 @@ static HRESULT WINAPI d3d3_EvictManagedTextures(IDirect3D3 *iface)
  *  D3D_OK on success, or the return value of IWineD3D::GetCaps
  *
  *****************************************************************************/
-HRESULT IDirect3DImpl_GetCaps(IWineD3D *wined3d, D3DDEVICEDESC *desc1, D3DDEVICEDESC7 *desc7)
+HRESULT IDirect3DImpl_GetCaps(const struct wined3d *wined3d, D3DDEVICEDESC *desc1, D3DDEVICEDESC7 *desc7)
 {
     WINED3DCAPS wined3d_caps;
     HRESULT hr;
@@ -5121,7 +5113,7 @@ HRESULT IDirect3DImpl_GetCaps(IWineD3D *wined3d, D3DDEVICEDESC *desc1, D3DDEVICE
     memset(&wined3d_caps, 0, sizeof(wined3d_caps));
 
     EnterCriticalSection(&ddraw_cs);
-    hr = IWineD3D_GetDeviceCaps(wined3d, 0, WINED3DDEVTYPE_HAL, &wined3d_caps);
+    hr = wined3d_get_device_caps(wined3d, 0, WINED3DDEVTYPE_HAL, &wined3d_caps);
     LeaveCriticalSection(&ddraw_cs);
     if (FAILED(hr))
     {
@@ -6010,19 +6002,19 @@ HRESULT ddraw_init(IDirectDrawImpl *ddraw, WINED3DDEVTYPE device_type)
     ddraw->orig_width = GetSystemMetrics(SM_CXSCREEN);
     ddraw->orig_height = GetSystemMetrics(SM_CYSCREEN);
 
-    ddraw->wineD3D = WineDirect3DCreate(7, &ddraw->IDirectDraw7_iface);
+    ddraw->wineD3D = wined3d_create(7, &ddraw->IDirectDraw7_iface);
     if (!ddraw->wineD3D)
     {
         WARN("Failed to create a wined3d object.\n");
         return E_OUTOFMEMORY;
     }
 
-    hr = IWineD3D_CreateDevice(ddraw->wineD3D, WINED3DADAPTER_DEFAULT, device_type, NULL, 0,
+    hr = wined3d_device_create(ddraw->wineD3D, WINED3DADAPTER_DEFAULT, device_type, NULL, 0,
             (IWineD3DDeviceParent *)&ddraw->device_parent_vtbl, &ddraw->wineD3DDevice);
     if (FAILED(hr))
     {
         WARN("Failed to create a wined3d device, hr %#x.\n", hr);
-        IWineD3D_Release(ddraw->wineD3D);
+        wined3d_decref(ddraw->wineD3D);
         return hr;
     }
 
diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h
index 1fea09f..cb12faf 100644
--- a/dlls/ddraw/ddraw_private.h
+++ b/dlls/ddraw/ddraw_private.h
@@ -111,7 +111,7 @@ struct IDirectDrawImpl
     LONG                    ref7, ref4, ref2, ref3, ref1, numIfaces;
 
     /* WineD3D linkage */
-    IWineD3D                *wineD3D;
+    struct wined3d *wineD3D;
     IWineD3DDevice          *wineD3DDevice;
     BOOL                    d3d_initialized;
 
@@ -368,7 +368,8 @@ HRESULT d3d_device_init(IDirect3DDeviceImpl *device, IDirectDrawImpl *ddraw,
 extern const GUID IID_D3DDEVICE_WineD3D DECLSPEC_HIDDEN;
 
 /* Helper functions */
-HRESULT IDirect3DImpl_GetCaps(IWineD3D *WineD3D, D3DDEVICEDESC *Desc123, D3DDEVICEDESC7 *Desc7) DECLSPEC_HIDDEN;
+HRESULT IDirect3DImpl_GetCaps(const struct wined3d *wined3d,
+        D3DDEVICEDESC *Desc123, D3DDEVICEDESC7 *Desc7) DECLSPEC_HIDDEN;
 WINED3DZBUFFERTYPE IDirect3DDeviceImpl_UpdateDepthStencil(IDirect3DDeviceImpl *This) DECLSPEC_HIDDEN;
 
 static inline IDirect3DDeviceImpl *device_from_device1(IDirect3DDevice *iface)
diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c
index 217ca4e..73feb38 100644
--- a/dlls/ddraw/device.c
+++ b/dlls/ddraw/device.c
@@ -1114,15 +1114,9 @@ IDirect3DDeviceImpl_7_EnumTextureFormats(IDirect3DDevice7 *iface,
 
     for (i = 0; i < sizeof(FormatList) / sizeof(*FormatList); ++i)
     {
-        hr = IWineD3D_CheckDeviceFormat(This->ddraw->wineD3D,
-                                        WINED3DADAPTER_DEFAULT,
-                                        WINED3DDEVTYPE_HAL,
-                                        mode.Format,
-                                        0 /* Usage */,
-                                        WINED3DRTYPE_TEXTURE,
-                                        FormatList[i],
-                                        SURFACE_OPENGL);
-        if(hr == D3D_OK)
+        hr = wined3d_check_device_format(This->ddraw->wineD3D, WINED3DADAPTER_DEFAULT, WINED3DDEVTYPE_HAL,
+                mode.Format, 0, WINED3DRTYPE_TEXTURE, FormatList[i], SURFACE_OPENGL);
+        if (hr == D3D_OK)
         {
             DDPIXELFORMAT pformat;
 
@@ -1143,15 +1137,10 @@ IDirect3DDeviceImpl_7_EnumTextureFormats(IDirect3DDevice7 *iface,
 
     for (i = 0; i < sizeof(BumpFormatList) / sizeof(*BumpFormatList); ++i)
     {
-        hr = IWineD3D_CheckDeviceFormat(This->ddraw->wineD3D,
-                                        WINED3DADAPTER_DEFAULT,
-                                        WINED3DDEVTYPE_HAL,
-                                        mode.Format,
-                                        WINED3DUSAGE_QUERY_LEGACYBUMPMAP,
-                                        WINED3DRTYPE_TEXTURE,
-                                        BumpFormatList[i],
-                                        SURFACE_OPENGL);
-        if(hr == D3D_OK)
+        hr = wined3d_check_device_format(This->ddraw->wineD3D, WINED3DADAPTER_DEFAULT,
+                WINED3DDEVTYPE_HAL, mode.Format, WINED3DUSAGE_QUERY_LEGACYBUMPMAP,
+                WINED3DRTYPE_TEXTURE, BumpFormatList[i], SURFACE_OPENGL);
+        if (hr == D3D_OK)
         {
             DDPIXELFORMAT pformat;
 
@@ -1264,15 +1253,9 @@ IDirect3DDeviceImpl_2_EnumTextureFormats(IDirect3DDevice2 *iface,
 
     for (i = 0; i < sizeof(FormatList) / sizeof(*FormatList); ++i)
     {
-        hr = IWineD3D_CheckDeviceFormat(This->ddraw->wineD3D,
-                                        0 /* Adapter */,
-                                        WINED3DDEVTYPE_HAL,
-                                        mode.Format,
-                                        0 /* Usage */,
-                                        WINED3DRTYPE_TEXTURE,
-                                        FormatList[i],
-                                        SURFACE_OPENGL);
-        if(hr == D3D_OK)
+        hr = wined3d_check_device_format(This->ddraw->wineD3D, 0, WINED3DDEVTYPE_HAL,
+                mode.Format, 0, WINED3DRTYPE_TEXTURE, FormatList[i], SURFACE_OPENGL);
+        if (hr == D3D_OK)
         {
             DDSURFACEDESC sdesc;
 
diff --git a/dlls/dxgi/adapter.c b/dlls/dxgi/adapter.c
index 7046d7c..7cd808f 100644
--- a/dlls/dxgi/adapter.c
+++ b/dlls/dxgi/adapter.c
@@ -135,7 +135,7 @@ static HRESULT STDMETHODCALLTYPE dxgi_adapter_GetDesc(IWineDXGIAdapter *iface, D
     struct dxgi_adapter *This = (struct dxgi_adapter *)iface;
     WINED3DADAPTER_IDENTIFIER adapter_id;
     char description[128];
-    IWineD3D *wined3d;
+    struct wined3d *wined3d;
     HRESULT hr;
 
     TRACE("iface %p, desc %p.\n", iface, desc);
@@ -149,8 +149,8 @@ static HRESULT STDMETHODCALLTYPE dxgi_adapter_GetDesc(IWineDXGIAdapter *iface, D
     adapter_id.device_name_size = 0;
 
     EnterCriticalSection(&dxgi_cs);
-    hr = IWineD3D_GetAdapterIdentifier(wined3d, This->ordinal, 0, &adapter_id);
-    IWineD3D_Release(wined3d);
+    hr = wined3d_get_adapter_identifier(wined3d, This->ordinal, 0, &adapter_id);
+    wined3d_decref(wined3d);
     LeaveCriticalSection(&dxgi_cs);
 
     if (SUCCEEDED(hr))
diff --git a/dlls/dxgi/device.c b/dlls/dxgi/device.c
index 64c874a..ab9d938 100644
--- a/dlls/dxgi/device.c
+++ b/dlls/dxgi/device.c
@@ -340,7 +340,7 @@ HRESULT dxgi_device_init(struct dxgi_device *device, struct dxgi_device_layer *l
     IWineD3DDeviceParent *wined3d_device_parent;
     IWineDXGIAdapter *wine_adapter;
     UINT adapter_ordinal;
-    IWineD3D *wined3d;
+    struct wined3d *wined3d;
     void *layer_base;
     HRESULT hr;
 
@@ -370,7 +370,7 @@ HRESULT dxgi_device_init(struct dxgi_device *device, struct dxgi_device_layer *l
     {
         WARN("This is not the adapter we're looking for, returning %#x.\n", hr);
         EnterCriticalSection(&dxgi_cs);
-        IWineD3D_Release(wined3d);
+        wined3d_decref(wined3d);
         LeaveCriticalSection(&dxgi_cs);
         goto fail;
     }
@@ -386,10 +386,10 @@ HRESULT dxgi_device_init(struct dxgi_device *device, struct dxgi_device_layer *l
 
     FIXME("Ignoring adapter type.\n");
     EnterCriticalSection(&dxgi_cs);
-    hr = IWineD3D_CreateDevice(wined3d, adapter_ordinal, WINED3DDEVTYPE_HAL, NULL, 0,
+    hr = wined3d_device_create(wined3d, adapter_ordinal, WINED3DDEVTYPE_HAL, NULL, 0,
             wined3d_device_parent, &device->wined3d_device);
     IWineD3DDeviceParent_Release(wined3d_device_parent);
-    IWineD3D_Release(wined3d);
+    wined3d_decref(wined3d);
     LeaveCriticalSection(&dxgi_cs);
     if (FAILED(hr))
     {
diff --git a/dlls/dxgi/dxgi_private.h b/dlls/dxgi/dxgi_private.h
index f4e098f..0c0fe86 100644
--- a/dlls/dxgi/dxgi_private.h
+++ b/dlls/dxgi/dxgi_private.h
@@ -79,7 +79,7 @@ struct dxgi_factory
 {
     const struct IWineDXGIFactoryVtbl *vtbl;
     LONG refcount;
-    IWineD3D *wined3d;
+    struct wined3d *wined3d;
     UINT adapter_count;
     IDXGIAdapter **adapters;
 };
diff --git a/dlls/dxgi/factory.c b/dlls/dxgi/factory.c
index 6b0a681..4e89d44 100644
--- a/dlls/dxgi/factory.c
+++ b/dlls/dxgi/factory.c
@@ -74,7 +74,7 @@ static ULONG STDMETHODCALLTYPE dxgi_factory_Release(IWineDXGIFactory *iface)
         HeapFree(GetProcessHeap(), 0, This->adapters);
 
         EnterCriticalSection(&dxgi_cs);
-        IWineD3D_Release(This->wined3d);
+        wined3d_decref(This->wined3d);
         LeaveCriticalSection(&dxgi_cs);
         HeapFree(GetProcessHeap(), 0, This);
     }
@@ -256,14 +256,14 @@ static HRESULT STDMETHODCALLTYPE dxgi_factory_CreateSoftwareAdapter(IWineDXGIFac
 
 /* IWineDXGIFactory methods */
 
-static IWineD3D * STDMETHODCALLTYPE dxgi_factory_get_wined3d(IWineDXGIFactory *iface)
+static struct wined3d * STDMETHODCALLTYPE dxgi_factory_get_wined3d(IWineDXGIFactory *iface)
 {
     struct dxgi_factory *This = (struct dxgi_factory *)iface;
 
     TRACE("iface %p\n", iface);
 
     EnterCriticalSection(&dxgi_cs);
-    IWineD3D_AddRef(This->wined3d);
+    wined3d_incref(This->wined3d);
     LeaveCriticalSection(&dxgi_cs);
     return This->wined3d;
 }
@@ -298,14 +298,14 @@ HRESULT dxgi_factory_init(struct dxgi_factory *factory)
     factory->refcount = 1;
 
     EnterCriticalSection(&dxgi_cs);
-    factory->wined3d = WineDirect3DCreate(10, (IUnknown *)factory);
+    factory->wined3d = wined3d_create(10, factory);
     if (!factory->wined3d)
     {
         LeaveCriticalSection(&dxgi_cs);
         return DXGI_ERROR_UNSUPPORTED;
     }
 
-    factory->adapter_count = IWineD3D_GetAdapterCount(factory->wined3d);
+    factory->adapter_count = wined3d_get_adapter_count(factory->wined3d);
     LeaveCriticalSection(&dxgi_cs);
     factory->adapters = HeapAlloc(GetProcessHeap(), 0, factory->adapter_count * sizeof(*factory->adapters));
     if (!factory->adapters)
@@ -355,7 +355,7 @@ HRESULT dxgi_factory_init(struct dxgi_factory *factory)
 fail:
     HeapFree(GetProcessHeap(), 0, factory->adapters);
     EnterCriticalSection(&dxgi_cs);
-    IWineD3D_Release(factory->wined3d);
+    wined3d_decref(factory->wined3d);
     LeaveCriticalSection(&dxgi_cs);
     return hr;
 }
diff --git a/dlls/dxgi/output.c b/dlls/dxgi/output.c
index c1f989b..46311fe 100644
--- a/dlls/dxgi/output.c
+++ b/dlls/dxgi/output.c
@@ -119,7 +119,7 @@ static HRESULT STDMETHODCALLTYPE dxgi_output_GetDisplayModeList(IDXGIOutput *ifa
 {
     struct dxgi_output *This = (struct dxgi_output *)iface;
     enum wined3d_format_id wined3d_format;
-    IWineD3D *wined3d;
+    struct wined3d *wined3d;
     UINT i;
 
     TRACE("iface %p, format %s, flags %#x, mode_count %p, desc %p.\n",
@@ -131,8 +131,8 @@ static HRESULT STDMETHODCALLTYPE dxgi_output_GetDisplayModeList(IDXGIOutput *ifa
     if (!desc)
     {
         EnterCriticalSection(&dxgi_cs);
-        *mode_count = IWineD3D_GetAdapterModeCount(wined3d, This->adapter->ordinal, wined3d_format);
-        IWineD3D_Release(wined3d);
+        *mode_count = wined3d_get_adapter_mode_count(wined3d, This->adapter->ordinal, wined3d_format);
+        wined3d_decref(wined3d);
         LeaveCriticalSection(&dxgi_cs);
 
         return S_OK;
@@ -144,11 +144,11 @@ static HRESULT STDMETHODCALLTYPE dxgi_output_GetDisplayModeList(IDXGIOutput *ifa
         WINED3DDISPLAYMODE mode;
         HRESULT hr;
 
-        hr = IWineD3D_EnumAdapterModes(wined3d, This->adapter->ordinal, wined3d_format, i, &mode);
+        hr = wined3d_enum_adapter_modes(wined3d, This->adapter->ordinal, wined3d_format, i, &mode);
         if (FAILED(hr))
         {
             WARN("EnumAdapterModes failed, hr %#x.\n", hr);
-            IWineD3D_Release(wined3d);
+            wined3d_decref(wined3d);
             LeaveCriticalSection(&dxgi_cs);
             return hr;
         }
@@ -161,7 +161,7 @@ static HRESULT STDMETHODCALLTYPE dxgi_output_GetDisplayModeList(IDXGIOutput *ifa
         desc[i].ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; /* FIXME */
         desc[i].Scaling = DXGI_MODE_SCALING_UNSPECIFIED; /* FIXME */
     }
-    IWineD3D_Release(wined3d);
+    wined3d_decref(wined3d);
     LeaveCriticalSection(&dxgi_cs);
 
     return S_OK;
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index 5e6df84..381cd46 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -882,7 +882,7 @@ static ULONG WINAPI IWineD3DDeviceImpl_Release(IWineD3DDevice *iface) {
         if (This->hardwareCursor) DestroyCursor(This->hardwareCursor);
         This->haveHardwareCursor = FALSE;
 
-        IWineD3D_Release(This->wined3d);
+        wined3d_decref(This->wined3d);
         This->wined3d = NULL;
         HeapFree(GetProcessHeap(), 0, This);
         TRACE("Freed device  %p\n", This);
@@ -2359,12 +2359,18 @@ static HRESULT WINAPI IWineD3DDeviceImpl_SetDisplayMode(IWineD3DDevice *iface, U
     return WINED3D_OK;
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_GetDirect3D(IWineD3DDevice *iface, IWineD3D **ppD3D) {
-   IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-   *ppD3D = This->wined3d;
-   TRACE("Returning %p.\n", *ppD3D);
-   IWineD3D_AddRef(*ppD3D);
-   return WINED3D_OK;
+static HRESULT WINAPI IWineD3DDeviceImpl_GetDirect3D(IWineD3DDevice *iface, struct wined3d **wined3d)
+{
+    IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)iface;
+
+    TRACE("iface %p, wined3d %p.\n", iface, wined3d);
+
+    *wined3d = device->wined3d;
+    wined3d_incref(*wined3d);
+
+    TRACE("Returning %p.\n", *wined3d);
+
+    return WINED3D_OK;
 }
 
 static UINT WINAPI IWineD3DDeviceImpl_GetAvailableTextureMem(IWineD3DDevice *iface) {
@@ -4596,10 +4602,13 @@ static HRESULT WINAPI IWineD3DDeviceImpl_GetBackBuffer(IWineD3DDevice *iface, UI
     return WINED3D_OK;
 }
 
-static HRESULT WINAPI IWineD3DDeviceImpl_GetDeviceCaps(IWineD3DDevice *iface, WINED3DCAPS* pCaps) {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-    WARN("(%p) : stub, calling idirect3d for now\n", This);
-    return IWineD3D_GetDeviceCaps(This->wined3d, This->adapter->ordinal, This->devType, pCaps);
+static HRESULT WINAPI IWineD3DDeviceImpl_GetDeviceCaps(IWineD3DDevice *iface, WINED3DCAPS *caps)
+{
+    IWineD3DDeviceImpl *device = (IWineD3DDeviceImpl *)iface;
+
+    TRACE("iface %p, caps %p.\n", iface, caps);
+
+    return wined3d_get_device_caps(device->wined3d, device->adapter->ordinal, device->devType, caps);
 }
 
 static HRESULT WINAPI IWineD3DDeviceImpl_GetDisplayMode(IWineD3DDevice *iface, UINT iSwapChain, WINED3DDISPLAYMODE* pMode) {
@@ -6180,17 +6189,16 @@ static BOOL is_display_mode_supported(IWineD3DDeviceImpl *This, const WINED3DPRE
     if(!pp->BackBufferWidth) return TRUE;
     if(!pp->BackBufferHeight) return TRUE;
 
-    count = IWineD3D_GetAdapterModeCount(This->wined3d, This->adapter->ordinal, WINED3DFMT_UNKNOWN);
-    for(i = 0; i < count; i++) {
+    count = wined3d_get_adapter_mode_count(This->wined3d, This->adapter->ordinal, WINED3DFMT_UNKNOWN);
+    for (i = 0; i < count; ++i)
+    {
         memset(&m, 0, sizeof(m));
-        hr = IWineD3D_EnumAdapterModes(This->wined3d, This->adapter->ordinal, WINED3DFMT_UNKNOWN, i, &m);
-        if(FAILED(hr)) {
-            ERR("EnumAdapterModes failed\n");
-        }
-        if(m.Width == pp->BackBufferWidth && m.Height == pp->BackBufferHeight) {
-            /* Mode found, it is supported */
+        hr = wined3d_enum_adapter_modes(This->wined3d, This->adapter->ordinal, WINED3DFMT_UNKNOWN, i, &m);
+        if (FAILED(hr))
+            ERR("Failed to enumerate adapter mode.\n");
+        if (m.Width == pp->BackBufferWidth && m.Height == pp->BackBufferHeight)
+            /* Mode found, it is supported. */
             return TRUE;
-        }
     }
     /* Mode not found -> not supported */
     return FALSE;
@@ -6935,7 +6943,7 @@ HRESULT device_init(IWineD3DDeviceImpl *device, IWineD3DImpl *wined3d,
     device->lpVtbl = &IWineD3DDevice_Vtbl;
     device->ref = 1;
     device->wined3d = (IWineD3D *)wined3d;
-    IWineD3D_AddRef(device->wined3d);
+    wined3d_incref(device->wined3d);
     device->adapter = wined3d->adapter_count ? adapter : NULL;
     device->device_parent = device_parent;
     list_init(&device->resources);
@@ -6944,11 +6952,11 @@ HRESULT device_init(IWineD3DDeviceImpl *device, IWineD3DImpl *wined3d,
     device->surface_alignment = wined3d->dxVersion == 7 ? DDRAW_PITCH_ALIGNMENT : D3D8_PITCH_ALIGNMENT;
 
     /* Get the initial screen setup for ddraw. */
-    hr = IWineD3D_GetAdapterDisplayMode((IWineD3D *)wined3d, adapter_idx, &mode);
+    hr = wined3d_get_adapter_display_mode(wined3d, adapter_idx, &mode);
     if (FAILED(hr))
     {
         ERR("Failed to get the adapter's display mode, hr %#x.\n", hr);
-        IWineD3D_Release(device->wined3d);
+        wined3d_decref(device->wined3d);
         return hr;
     }
     device->ddraw_width = mode.Width;
@@ -6986,7 +6994,7 @@ HRESULT device_init(IWineD3DDeviceImpl *device, IWineD3DImpl *wined3d,
         if (FAILED(hr))
         {
             ERR("Failed to compile state table, hr %#x.\n", hr);
-            IWineD3D_Release(device->wined3d);
+            wined3d_decref(device->wined3d);
             return hr;
         }
     }
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
index 84fdc87..68edd41 100644
--- a/dlls/wined3d/directx.c
+++ b/dlls/wined3d/directx.c
@@ -343,52 +343,33 @@ static void wined3d_adapter_cleanup(struct wined3d_adapter *adapter)
     HeapFree(GetProcessHeap(), 0, adapter->cfgs);
 }
 
-/**********************************************************
- * IUnknown parts follows
- **********************************************************/
-
-static HRESULT WINAPI IWineD3DImpl_QueryInterface(IWineD3D *iface,REFIID riid,LPVOID *ppobj)
+ULONG CDECL wined3d_incref(struct wined3d *wined3d)
 {
-    IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
-
-    TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppobj);
-    if (IsEqualGUID(riid, &IID_IUnknown)
-        || IsEqualGUID(riid, &IID_IWineD3DBase)
-        || IsEqualGUID(riid, &IID_IWineD3DDevice)) {
-        IUnknown_AddRef(iface);
-        *ppobj = This;
-        return S_OK;
-    }
-    *ppobj = NULL;
-    return E_NOINTERFACE;
-}
+    ULONG refcount = InterlockedIncrement(&wined3d->ref);
 
-static ULONG WINAPI IWineD3DImpl_AddRef(IWineD3D *iface) {
-    IWineD3DImpl *This = (IWineD3DImpl *)iface;
-    ULONG refCount = InterlockedIncrement(&This->ref);
+    TRACE("%p increasing refcount to %u.\n", wined3d, refcount);
 
-    TRACE("(%p) : AddRef increasing from %d\n", This, refCount - 1);
-    return refCount;
+    return refcount;
 }
 
-static ULONG WINAPI IWineD3DImpl_Release(IWineD3D *iface) {
-    IWineD3DImpl *This = (IWineD3DImpl *)iface;
-    ULONG ref;
-    TRACE("(%p) : Releasing from %d\n", This, This->ref);
-    ref = InterlockedDecrement(&This->ref);
+ULONG CDECL wined3d_decref(struct wined3d *wined3d)
+{
+    ULONG refcount = InterlockedDecrement(&wined3d->ref);
+
+    TRACE("%p decreasing refcount to %u.\n", wined3d, refcount);
 
-    if (!ref)
+    if (!refcount)
     {
         unsigned int i;
 
-        for (i = 0; i < This->adapter_count; ++i)
+        for (i = 0; i < wined3d->adapter_count; ++i)
         {
-            wined3d_adapter_cleanup(&This->adapters[i]);
+            wined3d_adapter_cleanup(&wined3d->adapters[i]);
         }
-        HeapFree(GetProcessHeap(), 0, This);
+        HeapFree(GetProcessHeap(), 0, wined3d);
     }
 
-    return ref;
+    return refcount;
 }
 
 /**********************************************************
@@ -2595,55 +2576,47 @@ static BOOL IWineD3DImpl_FillGLCaps(struct wined3d_adapter *adapter)
     return TRUE;
 }
 
-/**********************************************************
- * IWineD3D implementation follows
- **********************************************************/
-
-static UINT     WINAPI IWineD3DImpl_GetAdapterCount (IWineD3D *iface) {
-    IWineD3DImpl *This = (IWineD3DImpl *)iface;
-
-    TRACE_(d3d_caps)("(%p): Reporting %u adapters\n", This, This->adapter_count);
+UINT CDECL wined3d_get_adapter_count(const struct wined3d *wined3d)
+{
+    TRACE_(d3d_caps)("wined3d %p, reporting %u adapters.\n",
+            wined3d, wined3d->adapter_count);
 
-    return This->adapter_count;
+    return wined3d->adapter_count;
 }
 
-static HRESULT WINAPI IWineD3DImpl_RegisterSoftwareDevice(IWineD3D *iface, void *init_function)
+HRESULT CDECL wined3d_register_software_device(struct wined3d *wined3d, void *init_function)
 {
-    FIXME("iface %p, init_function %p stub!\n", iface, init_function);
+    FIXME("wined3d %p, init_function %p stub!\n", wined3d, init_function);
 
     return WINED3D_OK;
 }
 
-static HMONITOR WINAPI IWineD3DImpl_GetAdapterMonitor(IWineD3D *iface, UINT Adapter) {
-    IWineD3DImpl *This = (IWineD3DImpl *)iface;
-
-    TRACE_(d3d_caps)("(%p)->(%d)\n", This, Adapter);
+HMONITOR CDECL wined3d_get_adapter_monitor(const struct wined3d *wined3d, UINT adapter_idx)
+{
+    TRACE_(d3d_caps)("wined3d %p, adapter_idx %u.\n", wined3d, adapter_idx);
 
-    if (Adapter >= IWineD3DImpl_GetAdapterCount(iface)) {
+    if (adapter_idx >= wined3d->adapter_count)
         return NULL;
-    }
 
-    return MonitorFromPoint(This->adapters[Adapter].monitorPoint, MONITOR_DEFAULTTOPRIMARY);
+    return MonitorFromPoint(wined3d->adapters[adapter_idx].monitorPoint, MONITOR_DEFAULTTOPRIMARY);
 }
 
 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
      of the same bpp but different resolutions                                  */
 
 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
-static UINT WINAPI IWineD3DImpl_GetAdapterModeCount(IWineD3D *iface, UINT Adapter, enum wined3d_format_id format_id)
+UINT CDECL wined3d_get_adapter_mode_count(const struct wined3d *wined3d, UINT adapter_idx,
+        enum wined3d_format_id format_id)
 {
-    IWineD3DImpl *This = (IWineD3DImpl *)iface;
+    TRACE_(d3d_caps)("wined3d %p, adapter_idx %u, format %s.\n", wined3d, adapter_idx, debug_d3dformat(format_id));
 
-    TRACE_(d3d_caps)("iface %p, adapter %u, format_id: %s.\n", iface, Adapter, debug_d3dformat(format_id));
-
-    if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
+    if (adapter_idx >= wined3d->adapter_count)
         return 0;
-    }
 
     /* TODO: Store modes per adapter and read it from the adapter structure */
-    if (Adapter == 0)
+    if (!adapter_idx)
     {
-        const struct wined3d_format *format = wined3d_get_format(&This->adapters[Adapter].gl_info, format_id);
+        const struct wined3d_format *format = wined3d_get_format(&wined3d->adapters[adapter_idx].gl_info, format_id);
         UINT format_bits = format->byte_count * CHAR_BIT;
         unsigned int i = 0;
         unsigned int j = 0;
@@ -2667,34 +2640,36 @@ static UINT WINAPI IWineD3DImpl_GetAdapterModeCount(IWineD3D *iface, UINT Adapte
             }
         }
 
-        TRACE_(d3d_caps)("(%p}->(Adapter: %d) => %d (out of %d)\n", This, Adapter, i, j);
+        TRACE_(d3d_caps)("Returning %u matching modes (out of %u total) for adapter %u.\n", i, j, adapter_idx);
+
         return i;
-    } else {
-        FIXME_(d3d_caps)("Adapter not primary display\n");
     }
+    else
+    {
+        FIXME_(d3d_caps)("Adapter not primary display.\n");
+    }
+
     return 0;
 }
 
 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
-static HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapter,
-        enum wined3d_format_id format_id, UINT Mode, WINED3DDISPLAYMODE *pMode)
+HRESULT CDECL wined3d_enum_adapter_modes(const struct wined3d *wined3d, UINT adapter_idx,
+        enum wined3d_format_id format_id, UINT mode_idx, WINED3DDISPLAYMODE *mode)
 {
-    IWineD3DImpl *This = (IWineD3DImpl *)iface;
-
-    TRACE_(d3d_caps)("iface %p, adapter_idx %u, format %s, mode_idx %u, mode %p.\n",
-            iface, Adapter, debug_d3dformat(format_id), Mode, pMode);
+    TRACE_(d3d_caps)("wined3d %p, adapter_idx %u, format %s, mode_idx %u, mode %p.\n",
+            wined3d, adapter_idx, debug_d3dformat(format_id), mode_idx, mode);
 
     /* Validate the parameters as much as possible */
-    if (!pMode || Adapter >= IWineD3DImpl_GetAdapterCount(iface)
-            || Mode >= IWineD3DImpl_GetAdapterModeCount(iface, Adapter, format_id))
+    if (!mode || adapter_idx >= wined3d->adapter_count
+            || mode_idx >= wined3d_get_adapter_mode_count(wined3d, adapter_idx, format_id))
     {
         return WINED3DERR_INVALIDCALL;
     }
 
     /* TODO: Store modes per adapter and read it from the adapter structure */
-    if (Adapter == 0)
+    if (!adapter_idx)
     {
-        const struct wined3d_format *format = wined3d_get_format(&This->adapters[Adapter].gl_info, format_id);
+        const struct wined3d_format *format = wined3d_get_format(&wined3d->adapters[adapter_idx].gl_info, format_id);
         UINT format_bits = format->byte_count * CHAR_BIT;
         DEVMODEW DevModeW;
         int ModeIdx = 0;
@@ -2707,7 +2682,7 @@ static HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapte
         /* If we are filtering to a specific format (D3D9), then need to skip
            all unrelated modes, but if mode is irrelevant (D3D8), then we can
            just count through the ones with valid bit depths */
-        while ((i<=Mode) && EnumDisplaySettingsExW(NULL, j++, &DevModeW, 0))
+        while (i <= mode_idx && EnumDisplaySettingsExW(NULL, j++, &DevModeW, 0))
         {
             if (format_id == WINED3DFMT_UNKNOWN)
             {
@@ -2728,28 +2703,28 @@ static HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapte
         ModeIdx = j - 1;
 
         /* Now get the display mode via the calculated index */
-        if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0)) {
-            pMode->Width        = DevModeW.dmPelsWidth;
-            pMode->Height       = DevModeW.dmPelsHeight;
-            pMode->RefreshRate  = DEFAULT_REFRESH_RATE;
+        if (EnumDisplaySettingsExW(NULL, ModeIdx, &DevModeW, 0))
+        {
+            mode->Width = DevModeW.dmPelsWidth;
+            mode->Height = DevModeW.dmPelsHeight;
+            mode->RefreshRate = DEFAULT_REFRESH_RATE;
             if (DevModeW.dmFields & DM_DISPLAYFREQUENCY)
-                pMode->RefreshRate = DevModeW.dmDisplayFrequency;
+                mode->RefreshRate = DevModeW.dmDisplayFrequency;
 
             if (format_id == WINED3DFMT_UNKNOWN)
-                pMode->Format = pixelformat_for_depth(DevModeW.dmBitsPerPel);
+                mode->Format = pixelformat_for_depth(DevModeW.dmBitsPerPel);
             else
-                pMode->Format = format_id;
+                mode->Format = format_id;
         }
         else
         {
-            TRACE_(d3d_caps)("Requested mode out of range %d\n", Mode);
+            TRACE_(d3d_caps)("Requested mode %u out of range.\n", mode_idx);
             return WINED3DERR_INVALIDCALL;
         }
 
-        TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n", pMode->Width, pMode->Height,
-                pMode->RefreshRate, pMode->Format, debug_d3dformat(pMode->Format),
-                DevModeW.dmBitsPerPel);
-
+        TRACE_(d3d_caps)("W %d H %d rr %d fmt (%x - %s) bpp %u\n",
+                mode->Width, mode->Height, mode->RefreshRate, mode->Format,
+                debug_d3dformat(mode->Format), DevModeW.dmBitsPerPel);
     }
     else
     {
@@ -2759,102 +2734,102 @@ static HRESULT WINAPI IWineD3DImpl_EnumAdapterModes(IWineD3D *iface, UINT Adapte
     return WINED3D_OK;
 }
 
-static HRESULT WINAPI IWineD3DImpl_GetAdapterDisplayMode(IWineD3D *iface, UINT Adapter, WINED3DDISPLAYMODE *pMode)
+HRESULT CDECL wined3d_get_adapter_display_mode(const struct wined3d *wined3d, UINT adapter_idx,
+        WINED3DDISPLAYMODE *mode)
 {
-    TRACE("iface %p, adapter_idx %u, display_mode %p.\n", iface, Adapter, pMode);
+    TRACE("wined3d %p, adapter_idx %u, display_mode %p.\n", wined3d, adapter_idx, mode);
 
-    if (!pMode || Adapter >= IWineD3D_GetAdapterCount(iface))
+    if (!mode || adapter_idx >= wined3d->adapter_count)
         return WINED3DERR_INVALIDCALL;
 
-    if (Adapter == 0) { /* Display */
-        int bpp = 0;
+    if (!adapter_idx)
+    {
         DEVMODEW DevModeW;
+        unsigned int bpp;
 
         ZeroMemory(&DevModeW, sizeof(DevModeW));
         DevModeW.dmSize = sizeof(DevModeW);
 
         EnumDisplaySettingsExW(NULL, ENUM_CURRENT_SETTINGS, &DevModeW, 0);
-        pMode->Width        = DevModeW.dmPelsWidth;
-        pMode->Height       = DevModeW.dmPelsHeight;
-        bpp                 = DevModeW.dmBitsPerPel;
-        pMode->RefreshRate  = DEFAULT_REFRESH_RATE;
+        mode->Width = DevModeW.dmPelsWidth;
+        mode->Height = DevModeW.dmPelsHeight;
+        bpp = DevModeW.dmBitsPerPel;
+        mode->RefreshRate = DEFAULT_REFRESH_RATE;
         if (DevModeW.dmFields&DM_DISPLAYFREQUENCY)
-        {
-            pMode->RefreshRate = DevModeW.dmDisplayFrequency;
-        }
-
-        pMode->Format = pixelformat_for_depth(bpp);
-    } else {
+            mode->RefreshRate = DevModeW.dmDisplayFrequency;
+        mode->Format = pixelformat_for_depth(bpp);
+    }
+    else
+    {
         FIXME_(d3d_caps)("Adapter not primary display\n");
     }
 
-    TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", pMode->Width,
-          pMode->Height, pMode->RefreshRate, debug_d3dformat(pMode->Format));
+    TRACE_(d3d_caps)("returning w:%d, h:%d, ref:%d, fmt:%s\n", mode->Width,
+          mode->Height, mode->RefreshRate, debug_d3dformat(mode->Format));
     return WINED3D_OK;
 }
 
 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
    and fields being inserted in the middle, a new structure is used in place    */
-static HRESULT WINAPI IWineD3DImpl_GetAdapterIdentifier(IWineD3D *iface,
-        UINT Adapter, DWORD flags, WINED3DADAPTER_IDENTIFIER *pIdentifier)
+HRESULT CDECL wined3d_get_adapter_identifier(const struct wined3d *wined3d,
+        UINT adapter_idx, DWORD flags, WINED3DADAPTER_IDENTIFIER *identifier)
 {
-    IWineD3DImpl *This = (IWineD3DImpl *)iface;
-    struct wined3d_adapter *adapter;
+    const struct wined3d_adapter *adapter;
     size_t len;
 
-    TRACE_(d3d_caps)("(%p}->(Adapter: %d, flags: %x, pId=%p)\n", This, Adapter, flags, pIdentifier);
+    TRACE_(d3d_caps)("wined3d %p, adapter_idx %u, flags %#x, indentifier %p.\n",
+            wined3d, adapter_idx, flags, identifier);
 
-    if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
+    if (adapter_idx >= wined3d->adapter_count)
         return WINED3DERR_INVALIDCALL;
-    }
 
-    adapter = &This->adapters[Adapter];
+    adapter = &wined3d->adapters[adapter_idx];
 
     /* Return the information requested */
     TRACE_(d3d_caps)("device/Vendor Name and Version detection using FillGLCaps\n");
 
-    if (pIdentifier->driver_size)
+    if (identifier->driver_size)
     {
         const char *name = adapter->driver_info.name;
-        len = min(strlen(name), pIdentifier->driver_size - 1);
-        memcpy(pIdentifier->driver, name, len);
-        pIdentifier->driver[len] = '\0';
+        len = min(strlen(name), identifier->driver_size - 1);
+        memcpy(identifier->driver, name, len);
+        identifier->driver[len] = '\0';
     }
 
-    if (pIdentifier->description_size)
+    if (identifier->description_size)
     {
         const char *description = adapter->driver_info.description;
-        len = min(strlen(description), pIdentifier->description_size - 1);
-        memcpy(pIdentifier->description, description, len);
-        pIdentifier->description[len] = '\0';
+        len = min(strlen(description), identifier->description_size - 1);
+        memcpy(identifier->description, description, len);
+        identifier->description[len] = '\0';
     }
 
     /* Note that d3d8 doesn't supply a device name. */
-    if (pIdentifier->device_name_size)
+    if (identifier->device_name_size)
     {
         static const char *device_name = "\\\\.\\DISPLAY1"; /* FIXME: May depend on desktop? */
 
         len = strlen(device_name);
-        if (len >= pIdentifier->device_name_size)
+        if (len >= identifier->device_name_size)
         {
             ERR("Device name size too small.\n");
             return WINED3DERR_INVALIDCALL;
         }
 
-        memcpy(pIdentifier->device_name, device_name, len);
-        pIdentifier->device_name[len] = '\0';
+        memcpy(identifier->device_name, device_name, len);
+        identifier->device_name[len] = '\0';
     }
 
-    pIdentifier->driver_version.u.HighPart = adapter->driver_info.version_high;
-    pIdentifier->driver_version.u.LowPart = adapter->driver_info.version_low;
-    pIdentifier->vendor_id = adapter->driver_info.vendor;
-    pIdentifier->device_id = adapter->driver_info.device;
-    pIdentifier->subsystem_id = 0;
-    pIdentifier->revision = 0;
-    memcpy(&pIdentifier->device_identifier, &IID_D3DDEVICE_D3DUID, sizeof(pIdentifier->device_identifier));
-    pIdentifier->whql_level = (flags & WINED3DENUM_NO_WHQL_LEVEL) ? 0 : 1;
-    memcpy(&pIdentifier->adapter_luid, &adapter->luid, sizeof(pIdentifier->adapter_luid));
-    pIdentifier->video_memory = adapter->TextureRam;
+    identifier->driver_version.u.HighPart = adapter->driver_info.version_high;
+    identifier->driver_version.u.LowPart = adapter->driver_info.version_low;
+    identifier->vendor_id = adapter->driver_info.vendor;
+    identifier->device_id = adapter->driver_info.device;
+    identifier->subsystem_id = 0;
+    identifier->revision = 0;
+    memcpy(&identifier->device_identifier, &IID_D3DDEVICE_D3DUID, sizeof(identifier->device_identifier));
+    identifier->whql_level = (flags & WINED3DENUM_NO_WHQL_LEVEL) ? 0 : 1;
+    memcpy(&identifier->adapter_luid, &adapter->luid, sizeof(identifier->adapter_luid));
+    identifier->video_memory = adapter->TextureRam;
 
     return WINED3D_OK;
 }
@@ -2931,138 +2906,136 @@ static BOOL IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(const struct wined3
     return TRUE;
 }
 
-static HRESULT WINAPI IWineD3DImpl_CheckDepthStencilMatch(IWineD3D *iface,
-        UINT Adapter, WINED3DDEVTYPE DeviceType, enum wined3d_format_id AdapterFormat,
-        enum wined3d_format_id RenderTargetFormat, enum wined3d_format_id DepthStencilFormat)
+HRESULT CDECL wined3d_check_depth_stencil_match(const struct wined3d *wined3d,
+        UINT adapter_idx, WINED3DDEVTYPE device_type, enum wined3d_format_id adapter_format_id,
+        enum wined3d_format_id render_target_format_id, enum wined3d_format_id depth_stencil_format_id)
 {
-    IWineD3DImpl *This = (IWineD3DImpl *)iface;
-    int nCfgs;
-    const WineD3D_PixelFormat *cfgs;
-    const struct wined3d_adapter *adapter;
     const struct wined3d_format *rt_format;
     const struct wined3d_format *ds_format;
-    int it;
+    const struct wined3d_adapter *adapter;
 
-    WARN_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%x,%s), AdptFmt:(%x,%s), RendrTgtFmt:(%x,%s), DepthStencilFmt:(%x,%s))\n",
-           This, Adapter,
-           DeviceType, debug_d3ddevicetype(DeviceType),
-           AdapterFormat, debug_d3dformat(AdapterFormat),
-           RenderTargetFormat, debug_d3dformat(RenderTargetFormat),
-           DepthStencilFormat, debug_d3dformat(DepthStencilFormat));
+    TRACE_(d3d_caps)("wined3d %p, adapter_idx %u, device_type %s,\n"
+            "adapter_format %s, render_target_format %s, depth_stencil_format %s.\n",
+            wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(adapter_format_id),
+            debug_d3dformat(render_target_format_id), debug_d3dformat(depth_stencil_format_id));
 
-    if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
-        TRACE("(%p) Failed: Atapter (%u) higher than supported adapters (%u) returning WINED3DERR_INVALIDCALL\n", This, Adapter, IWineD3D_GetAdapterCount(iface));
+    if (adapter_idx >= wined3d->adapter_count)
         return WINED3DERR_INVALIDCALL;
-    }
 
-    adapter = &This->adapters[Adapter];
-    rt_format = wined3d_get_format(&adapter->gl_info, RenderTargetFormat);
-    ds_format = wined3d_get_format(&adapter->gl_info, DepthStencilFormat);
+    adapter = &wined3d->adapters[adapter_idx];
+    rt_format = wined3d_get_format(&adapter->gl_info, render_target_format_id);
+    ds_format = wined3d_get_format(&adapter->gl_info, depth_stencil_format_id);
     if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
     {
         if ((rt_format->flags & WINED3DFMT_FLAG_RENDERTARGET)
                 && (ds_format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)))
         {
-            TRACE_(d3d_caps)("(%p) : Formats matched\n", This);
+            TRACE_(d3d_caps)("Formats match.\n");
             return WINED3D_OK;
         }
     }
     else
     {
+        const WineD3D_PixelFormat *cfgs;
+        unsigned int cfg_count;
+        unsigned int i;
+
         cfgs = adapter->cfgs;
-        nCfgs = adapter->nCfgs;
-        for (it = 0; it < nCfgs; ++it)
+        cfg_count = adapter->nCfgs;
+        for (i = 0; i < cfg_count; ++i)
         {
-            if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info, &cfgs[it], rt_format))
+            if (IWineD3DImpl_IsPixelFormatCompatibleWithRenderFmt(&adapter->gl_info, &cfgs[i], rt_format))
             {
-                if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, &cfgs[it], ds_format))
+                if (IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, &cfgs[i], ds_format))
                 {
-                    TRACE_(d3d_caps)("(%p) : Formats matched\n", This);
+                    TRACE_(d3d_caps)("Formats match.\n");
                     return WINED3D_OK;
                 }
             }
         }
     }
-    WARN_(d3d_caps)("unsupported format pair: %s and %s\n", debug_d3dformat(RenderTargetFormat), debug_d3dformat(DepthStencilFormat));
+
+    TRACE_(d3d_caps)("Unsupported format pair: %s and %s.\n",
+            debug_d3dformat(render_target_format_id),
+            debug_d3dformat(depth_stencil_format_id));
 
     return WINED3DERR_NOTAVAILABLE;
 }
 
-static HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, UINT Adapter,
-        WINED3DDEVTYPE DeviceType, enum wined3d_format_id SurfaceFormat, BOOL Windowed,
-        WINED3DMULTISAMPLE_TYPE MultiSampleType, DWORD *pQualityLevels)
+HRESULT CDECL wined3d_check_device_multisample_type(const struct wined3d *wined3d, UINT adapter_idx,
+        WINED3DDEVTYPE device_type, enum wined3d_format_id surface_format_id, BOOL windowed,
+        WINED3DMULTISAMPLE_TYPE multisample_type, DWORD *quality_levels)
 {
-    IWineD3DImpl *This = (IWineD3DImpl *)iface;
     const struct wined3d_adapter *adapter;
     const struct wined3d_format *format;
 
-    TRACE_(d3d_caps)("(%p)-> (Adptr:%d, DevType:(%x,%s), SurfFmt:(%x,%s), Win?%d, MultiSamp:%x, pQual:%p)\n",
-          This,
-          Adapter,
-          DeviceType, debug_d3ddevicetype(DeviceType),
-          SurfaceFormat, debug_d3dformat(SurfaceFormat),
-          Windowed,
-          MultiSampleType,
-          pQualityLevels);
+    TRACE_(d3d_caps)("wined3d %p, adapter_idx %u, device_type %s, surface_format %s,\n"
+            "windowed %#x, multisample_type %#x, quality_levels %p.\n",
+            wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(surface_format_id),
+            windowed, multisample_type, quality_levels);
 
-    if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
+    if (adapter_idx >= wined3d->adapter_count)
         return WINED3DERR_INVALIDCALL;
-    }
 
-    /* TODO: handle Windowed, add more quality levels */
+    /* TODO: Handle windowed, add more quality levels. */
 
-    if (WINED3DMULTISAMPLE_NONE == MultiSampleType) {
-        if(pQualityLevels) *pQualityLevels = 1;
+    if (WINED3DMULTISAMPLE_NONE == multisample_type)
+    {
+        if (quality_levels) *quality_levels = 1;
         return WINED3D_OK;
     }
 
     /* By default multisampling is disabled right now as it causes issues
      * on some Nvidia driver versions and it doesn't work well in combination
      * with FBOs yet. */
-    if(!wined3d_settings.allow_multisampling)
+    if (!wined3d_settings.allow_multisampling)
         return WINED3DERR_NOTAVAILABLE;
 
-    adapter = &This->adapters[Adapter];
-    format = wined3d_get_format(&adapter->gl_info, SurfaceFormat);
+    adapter = &wined3d->adapters[adapter_idx];
+    format = wined3d_get_format(&adapter->gl_info, surface_format_id);
     if (!format) return WINED3DERR_INVALIDCALL;
 
     if (format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL))
     {
-        int i, nCfgs;
         const WineD3D_PixelFormat *cfgs;
+        unsigned int i, cfg_count;
 
         cfgs = adapter->cfgs;
-        nCfgs = adapter->nCfgs;
-        for(i=0; i<nCfgs; i++) {
-            if(cfgs[i].numSamples != MultiSampleType)
+        cfg_count = adapter->nCfgs;
+        for (i = 0; i < cfg_count; ++i)
+        {
+            if(cfgs[i].numSamples != multisample_type)
                 continue;
 
             if (!IWineD3DImpl_IsPixelFormatCompatibleWithDepthFmt(&adapter->gl_info, &cfgs[i], format))
                 continue;
 
-            TRACE("Found iPixelFormat=%d to support MultiSampleType=%d for format %s\n", cfgs[i].iPixelFormat, MultiSampleType, debug_d3dformat(SurfaceFormat));
+            TRACE("Found pixel format %u to support multisample_type %#x for format %s.\n",
+                    cfgs[i].iPixelFormat, multisample_type, debug_d3dformat(surface_format_id));
+
+            if (quality_levels) *quality_levels = 1;
 
-            if(pQualityLevels)
-                *pQualityLevels = 1; /* Guess at a value! */
             return WINED3D_OK;
         }
     }
     else if (format->flags & WINED3DFMT_FLAG_RENDERTARGET)
     {
         short redSize, greenSize, blueSize, alphaSize, colorBits;
-        int i, nCfgs;
         const WineD3D_PixelFormat *cfgs;
+        unsigned int i, cfg_count;
 
         if (!getColorBits(format, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits))
         {
-            ERR("Unable to color bits for format %#x, can't check multisampling capability!\n", SurfaceFormat);
+            ERR("Unable to get color bits for format %s, can't check multisampling capability.\n",
+                    debug_d3dformat(surface_format_id));
             return WINED3DERR_NOTAVAILABLE;
         }
 
         cfgs = adapter->cfgs;
-        nCfgs = adapter->nCfgs;
-        for(i=0; i<nCfgs; i++) {
-            if(cfgs[i].numSamples != MultiSampleType)
+        cfg_count = adapter->nCfgs;
+        for (i = 0; i < cfg_count; ++i)
+        {
+            if(cfgs[i].numSamples != multisample_type)
                 continue;
             if(cfgs[i].redSize != redSize)
                 continue;
@@ -3070,16 +3043,18 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceMultiSampleType(IWineD3D *iface, U
                 continue;
             if(cfgs[i].blueSize != blueSize)
                 continue;
-            /* Not all drivers report alpha-less formats since they use 32-bit anyway, so accept alpha even if we didn't ask for it. */
+            /* Not all drivers report alpha-less formats since they use 32-bit
+             * anyway, so accept alpha even if we didn't ask for it. */
             if(alphaSize && cfgs[i].alphaSize != alphaSize)
                 continue;
             if (cfgs[i].colorSize != (format->byte_count << 3))
                 continue;
 
-            TRACE("Found iPixelFormat=%d to support MultiSampleType=%d for format %s\n", cfgs[i].iPixelFormat, MultiSampleType, debug_d3dformat(SurfaceFormat));
+            TRACE("Found pixel format %u to support multisample_type %#x for format %s.\n",
+                    cfgs[i].iPixelFormat, multisample_type, debug_d3dformat(surface_format_id));
+
+            if (quality_levels) *quality_levels = 1;
 
-            if(pQualityLevels)
-                *pQualityLevels = 1; /* Guess at a value! */
             return WINED3D_OK;
         }
     }
@@ -3549,31 +3524,26 @@ static BOOL CheckVertexTextureCapability(const struct wined3d_adapter *adapter,
     return adapter->gl_info.limits.vertex_samplers && (format->flags & WINED3DFMT_FLAG_VTF);
 }
 
-static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType,
-        enum wined3d_format_id AdapterFormat, DWORD Usage, WINED3DRESOURCETYPE RType,
-        enum wined3d_format_id CheckFormat, WINED3DSURFTYPE SurfaceType)
+HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT adapter_idx,
+        WINED3DDEVTYPE device_type, enum wined3d_format_id adapter_format_id, DWORD usage,
+        WINED3DRESOURCETYPE resource_type, enum wined3d_format_id check_format_id, WINED3DSURFTYPE surface_type)
 {
-    IWineD3DImpl *This = (IWineD3DImpl *)iface;
-    const struct wined3d_adapter *adapter = &This->adapters[Adapter];
+    const struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx];
     const struct wined3d_gl_info *gl_info = &adapter->gl_info;
-    const struct wined3d_format *format = wined3d_get_format(gl_info, CheckFormat);
-    const struct wined3d_format *adapter_format = wined3d_get_format(gl_info, AdapterFormat);
-    DWORD UsageCaps = 0;
-
-    TRACE_(d3d_caps)("(%p)-> (STUB) (Adptr:%d, DevType:(%u,%s), AdptFmt:(%u,%s), Use:(%u,%s,%s), ResTyp:(%x,%s), CheckFmt:(%u,%s))\n",
-          This,
-          Adapter,
-          DeviceType, debug_d3ddevicetype(DeviceType),
-          AdapterFormat, debug_d3dformat(AdapterFormat),
-          Usage, debug_d3dusage(Usage), debug_d3dusagequery(Usage),
-          RType, debug_d3dresourcetype(RType),
-          CheckFormat, debug_d3dformat(CheckFormat));
-
-    if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
+    const struct wined3d_format *adapter_format = wined3d_get_format(gl_info, adapter_format_id);
+    const struct wined3d_format *format = wined3d_get_format(gl_info, check_format_id);
+    DWORD usage_caps = 0;
+
+    TRACE_(d3d_caps)("wined3d %p, adapter_idx %u, device_type %s, adapter_format %s, usage %s, %s,\n"
+            "resource_type %s, check_format %s, surface_type %#x.\n",
+            wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(adapter_format_id),
+            debug_d3dusage(usage), debug_d3dusagequery(usage), debug_d3dresourcetype(resource_type),
+            debug_d3dformat(check_format_id), surface_type);
+
+    if (adapter_idx >= wined3d->adapter_count)
         return WINED3DERR_INVALIDCALL;
-    }
 
-    switch (RType)
+    switch (resource_type)
     {
         case WINED3DRTYPE_CUBETEXTURE:
             /* Cubetexture allows:
@@ -3585,7 +3555,7 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapt
              *      - WINED3DUSAGE_SOFTWAREPROCESSING
              *      - WINED3DUSAGE_QUERY_WRAPANDMIP
              */
-            if (SurfaceType != SURFACE_OPENGL)
+            if (surface_type != SURFACE_OPENGL)
             {
                 TRACE_(d3d_caps)("[FAILED]\n");
                 return WINED3DERR_NOTAVAILABLE;
@@ -3603,92 +3573,92 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapt
                 return WINED3DERR_NOTAVAILABLE;
             }
 
-            if (Usage & WINED3DUSAGE_AUTOGENMIPMAP)
+            if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
             {
                 if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
                     /* When autogenmipmap isn't around continue and return
                      * WINED3DOK_NOAUTOGEN instead of D3D_OK. */
                     TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
                 else
-                    UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
+                    usage_caps |= WINED3DUSAGE_AUTOGENMIPMAP;
             }
 
             /* Always report dynamic locking. */
-            if (Usage & WINED3DUSAGE_DYNAMIC)
-                UsageCaps |= WINED3DUSAGE_DYNAMIC;
+            if (usage & WINED3DUSAGE_DYNAMIC)
+                usage_caps |= WINED3DUSAGE_DYNAMIC;
 
-            if (Usage & WINED3DUSAGE_RENDERTARGET)
+            if (usage & WINED3DUSAGE_RENDERTARGET)
             {
                 if (!CheckRenderTargetCapability(adapter, adapter_format, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_RENDERTARGET;
+                usage_caps |= WINED3DUSAGE_RENDERTARGET;
             }
 
             /* Always report software processing. */
-            if (Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
-                UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
+            if (usage & WINED3DUSAGE_SOFTWAREPROCESSING)
+                usage_caps |= WINED3DUSAGE_SOFTWAREPROCESSING;
 
-            if (Usage & WINED3DUSAGE_QUERY_FILTER)
+            if (usage & WINED3DUSAGE_QUERY_FILTER)
             {
                 if (!CheckFilterCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
+                usage_caps |= WINED3DUSAGE_QUERY_FILTER;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
+            if (usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
             {
                 if (!CheckPostPixelShaderBlendingCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
+                usage_caps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_SRGBREAD)
+            if (usage & WINED3DUSAGE_QUERY_SRGBREAD)
             {
                 if (!CheckSrgbReadCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
+                usage_caps |= WINED3DUSAGE_QUERY_SRGBREAD;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_SRGBWRITE)
+            if (usage & WINED3DUSAGE_QUERY_SRGBWRITE)
             {
                 if (!CheckSrgbWriteCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
+                usage_caps |= WINED3DUSAGE_QUERY_SRGBWRITE;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE)
+            if (usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE)
             {
                 if (!CheckVertexTextureCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
+                usage_caps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_WRAPANDMIP)
+            if (usage & WINED3DUSAGE_QUERY_WRAPANDMIP)
             {
                 if (!CheckWrapAndMipCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
+                usage_caps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
             }
             break;
 
@@ -3698,40 +3668,40 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapt
              *      - WINED3DUSAGE_NONSECURE (d3d9ex)
              *      - WINED3DUSAGE_RENDERTARGET
              */
-            if (!CheckSurfaceCapability(adapter, adapter_format, format, SurfaceType))
+            if (!CheckSurfaceCapability(adapter, adapter_format, format, surface_type))
             {
                 TRACE_(d3d_caps)("[FAILED] - Not supported for plain surfaces\n");
                 return WINED3DERR_NOTAVAILABLE;
             }
 
-            if (Usage & WINED3DUSAGE_DEPTHSTENCIL)
+            if (usage & WINED3DUSAGE_DEPTHSTENCIL)
             {
                 if (!CheckDepthStencilCapability(adapter, adapter_format, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No depthstencil support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
+                usage_caps |= WINED3DUSAGE_DEPTHSTENCIL;
             }
 
-            if (Usage & WINED3DUSAGE_RENDERTARGET)
+            if (usage & WINED3DUSAGE_RENDERTARGET)
             {
                 if (!CheckRenderTargetCapability(adapter, adapter_format, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_RENDERTARGET;
+                usage_caps |= WINED3DUSAGE_RENDERTARGET;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
+            if (usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
             {
                 if (!CheckPostPixelShaderBlendingCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
+                usage_caps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
             }
             break;
 
@@ -3747,7 +3717,7 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapt
              *      - WINED3DUSAGE_TEXTAPI (d3d9ex)
              *      - WINED3DUSAGE_QUERY_WRAPANDMIP
              */
-            if (SurfaceType != SURFACE_OPENGL)
+            if (surface_type != SURFACE_OPENGL)
             {
                 TRACE_(d3d_caps)("[FAILED]\n");
                 return WINED3DERR_NOTAVAILABLE;
@@ -3759,105 +3729,105 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapt
                 return WINED3DERR_NOTAVAILABLE;
             }
 
-            if (Usage & WINED3DUSAGE_AUTOGENMIPMAP)
+            if (usage & WINED3DUSAGE_AUTOGENMIPMAP)
             {
                 if (!gl_info->supported[SGIS_GENERATE_MIPMAP])
                     /* When autogenmipmap isn't around continue and return
                      * WINED3DOK_NOAUTOGEN instead of D3D_OK. */
                     TRACE_(d3d_caps)("[FAILED] - No autogenmipmap support, but continuing\n");
                 else
-                    UsageCaps |= WINED3DUSAGE_AUTOGENMIPMAP;
+                    usage_caps |= WINED3DUSAGE_AUTOGENMIPMAP;
             }
 
             /* Always report dynamic locking. */
-            if (Usage & WINED3DUSAGE_DYNAMIC)
-                UsageCaps |= WINED3DUSAGE_DYNAMIC;
+            if (usage & WINED3DUSAGE_DYNAMIC)
+                usage_caps |= WINED3DUSAGE_DYNAMIC;
 
-            if (Usage & WINED3DUSAGE_RENDERTARGET)
+            if (usage & WINED3DUSAGE_RENDERTARGET)
             {
                 if (!CheckRenderTargetCapability(adapter, adapter_format, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No rendertarget support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_RENDERTARGET;
+                usage_caps |= WINED3DUSAGE_RENDERTARGET;
             }
 
             /* Always report software processing. */
-            if (Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
-                UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
+            if (usage & WINED3DUSAGE_SOFTWAREPROCESSING)
+                usage_caps |= WINED3DUSAGE_SOFTWAREPROCESSING;
 
-            if (Usage & WINED3DUSAGE_QUERY_FILTER)
+            if (usage & WINED3DUSAGE_QUERY_FILTER)
             {
                 if (!CheckFilterCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
+                usage_caps |= WINED3DUSAGE_QUERY_FILTER;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP)
+            if (usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP)
             {
                 if (!CheckBumpMapCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No legacy bumpmap support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_LEGACYBUMPMAP;
+                usage_caps |= WINED3DUSAGE_QUERY_LEGACYBUMPMAP;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
+            if (usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
             {
                 if (!CheckPostPixelShaderBlendingCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
+                usage_caps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_SRGBREAD)
+            if (usage & WINED3DUSAGE_QUERY_SRGBREAD)
             {
                 if (!CheckSrgbReadCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
+                usage_caps |= WINED3DUSAGE_QUERY_SRGBREAD;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_SRGBWRITE)
+            if (usage & WINED3DUSAGE_QUERY_SRGBWRITE)
             {
                 if (!CheckSrgbWriteCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
+                usage_caps |= WINED3DUSAGE_QUERY_SRGBWRITE;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE)
+            if (usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE)
             {
                 if (!CheckVertexTextureCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
+                usage_caps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_WRAPANDMIP)
+            if (usage & WINED3DUSAGE_QUERY_WRAPANDMIP)
             {
                 if (!CheckWrapAndMipCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
+                usage_caps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
             }
 
-            if (Usage & WINED3DUSAGE_DEPTHSTENCIL)
+            if (usage & WINED3DUSAGE_DEPTHSTENCIL)
             {
                 if (!CheckDepthStencilCapability(adapter, adapter_format, format))
                 {
@@ -3869,7 +3839,7 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapt
                     TRACE_(d3d_caps)("[FAILED] - No shadow sampler support.\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_DEPTHSTENCIL;
+                usage_caps |= WINED3DUSAGE_DEPTHSTENCIL;
             }
             break;
 
@@ -3885,7 +3855,7 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapt
              *      - D3DUSAGE_SOFTWAREPROCESSING
              *      - D3DUSAGE_QUERY_WRAPANDMIP
              */
-            if (SurfaceType != SURFACE_OPENGL)
+            if (surface_type != SURFACE_OPENGL)
             {
                 TRACE_(d3d_caps)("[FAILED]\n");
                 return WINED3DERR_NOTAVAILABLE;
@@ -3910,7 +3880,7 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapt
              * leading applications into temptation. The windows drivers don't
              * support most of those formats on volumes anyway, except for
              * WINED3DFMT_R32_FLOAT. */
-            switch (CheckFormat)
+            switch (check_format_id)
             {
                 case WINED3DFMT_P8_UINT:
                 case WINED3DFMT_L4A4_UNORM:
@@ -3958,118 +3928,115 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormat(IWineD3D *iface, UINT Adapt
             }
 
             /* Always report dynamic locking. */
-            if (Usage & WINED3DUSAGE_DYNAMIC)
-                UsageCaps |= WINED3DUSAGE_DYNAMIC;
+            if (usage & WINED3DUSAGE_DYNAMIC)
+                usage_caps |= WINED3DUSAGE_DYNAMIC;
 
             /* Always report software processing. */
-            if (Usage & WINED3DUSAGE_SOFTWAREPROCESSING)
-                UsageCaps |= WINED3DUSAGE_SOFTWAREPROCESSING;
+            if (usage & WINED3DUSAGE_SOFTWAREPROCESSING)
+                usage_caps |= WINED3DUSAGE_SOFTWAREPROCESSING;
 
-            if (Usage & WINED3DUSAGE_QUERY_FILTER)
+            if (usage & WINED3DUSAGE_QUERY_FILTER)
             {
                 if (!CheckFilterCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No query filter support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_FILTER;
+                usage_caps |= WINED3DUSAGE_QUERY_FILTER;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
+            if (usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
             {
                 if (!CheckPostPixelShaderBlendingCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No query post pixelshader blending support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
+                usage_caps |= WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_SRGBREAD)
+            if (usage & WINED3DUSAGE_QUERY_SRGBREAD)
             {
                 if (!CheckSrgbReadCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No query srgbread support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_SRGBREAD;
+                usage_caps |= WINED3DUSAGE_QUERY_SRGBREAD;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_SRGBWRITE)
+            if (usage & WINED3DUSAGE_QUERY_SRGBWRITE)
             {
                 if (!CheckSrgbWriteCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No query srgbwrite support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_SRGBWRITE;
+                usage_caps |= WINED3DUSAGE_QUERY_SRGBWRITE;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE)
+            if (usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE)
             {
                 if (!CheckVertexTextureCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No query vertextexture support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
+                usage_caps |= WINED3DUSAGE_QUERY_VERTEXTEXTURE;
             }
 
-            if (Usage & WINED3DUSAGE_QUERY_WRAPANDMIP)
+            if (usage & WINED3DUSAGE_QUERY_WRAPANDMIP)
             {
                 if (!CheckWrapAndMipCapability(adapter, format))
                 {
                     TRACE_(d3d_caps)("[FAILED] - No wrapping and mipmapping support\n");
                     return WINED3DERR_NOTAVAILABLE;
                 }
-                UsageCaps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
+                usage_caps |= WINED3DUSAGE_QUERY_WRAPANDMIP;
             }
             break;
 
         default:
-            FIXME_(d3d_caps)("Unhandled resource type %s.\n", debug_d3dresourcetype(RType));
+            FIXME_(d3d_caps)("Unhandled resource type %s.\n", debug_d3dresourcetype(resource_type));
             return WINED3DERR_NOTAVAILABLE;
     }
 
-    /* When the UsageCaps exactly matches Usage return WINED3D_OK except for
+    /* When the usage_caps exactly matches usage return WINED3D_OK except for
      * the situation in which WINED3DUSAGE_AUTOGENMIPMAP isn't around, then
      * WINED3DOK_NOAUTOGEN is returned if all the other usage flags match. */
-    if (UsageCaps == Usage)
+    if (usage_caps == usage)
         return WINED3D_OK;
-    if (UsageCaps == (Usage & ~WINED3DUSAGE_AUTOGENMIPMAP))
+    if (usage_caps == (usage & ~WINED3DUSAGE_AUTOGENMIPMAP))
         return WINED3DOK_NOAUTOGEN;
 
-    TRACE_(d3d_caps)("[FAILED] - Usage %#x requested for CheckFormat %s and RType %s but only %#x is available\n",
-            Usage, debug_d3dformat(CheckFormat), debug_d3dresourcetype(RType), UsageCaps);
+    TRACE_(d3d_caps)("[FAILED] - Usage %#x requested for format %s and resource_type %s but only %#x is available.\n",
+            usage, debug_d3dformat(check_format_id), debug_d3dresourcetype(resource_type), usage_caps);
 
     return WINED3DERR_NOTAVAILABLE;
 }
 
-static HRESULT WINAPI IWineD3DImpl_CheckDeviceFormatConversion(IWineD3D *iface, UINT adapter_idx,
+HRESULT CDECL wined3d_check_device_format_conversion(const struct wined3d *wined3d, UINT adapter_idx,
         WINED3DDEVTYPE device_type, enum wined3d_format_id src_format, enum wined3d_format_id dst_format)
 {
-    FIXME("iface %p, adapter_idx %u, device_type %s, src_format %s, dst_format %s stub!\n",
-            iface, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(src_format),
+    FIXME("wined3d %p, adapter_idx %u, device_type %s, src_format %s, dst_format %s stub!\n",
+            wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(src_format),
             debug_d3dformat(dst_format));
 
     return WINED3D_OK;
 }
 
-static HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT adapter_idx, WINED3DDEVTYPE device_type,
+HRESULT CDECL wined3d_check_device_type(const struct wined3d *wined3d, UINT adapter_idx, WINED3DDEVTYPE device_type,
         enum wined3d_format_id display_format, enum wined3d_format_id backbuffer_format, BOOL windowed)
 {
     UINT mode_count;
     HRESULT hr;
 
-    TRACE("iface %p, adapter_idx %u, device_type %s, display_format %s, backbuffer_format %s, windowed %#x.\n",
-            iface, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(display_format),
+    TRACE("wined3d %p, adapter_idx %u, device_type %s, display_format %s, backbuffer_format %s, windowed %#x.\n",
+            wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(display_format),
             debug_d3dformat(backbuffer_format), windowed);
 
-    if (adapter_idx >= IWineD3D_GetAdapterCount(iface))
-    {
-        WARN_(d3d_caps)("adapter_idx >= IWineD3D_GetAdapterCount(iface), returning WINED3DERR_INVALIDCALL\n");
+    if (adapter_idx >= wined3d->adapter_count)
         return WINED3DERR_INVALIDCALL;
-    }
 
     /* The task of this function is to check whether a certain display / backbuffer format
      * combination is available on the given adapter. In fullscreen mode microsoft specified
@@ -4091,7 +4058,7 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT adapter
     }
 
     /* If the requested display format is not available, don't continue. */
-    mode_count = IWineD3DImpl_GetAdapterModeCount(iface, adapter_idx, display_format);
+    mode_count = wined3d_get_adapter_mode_count(wined3d, adapter_idx, display_format);
     if (!mode_count)
     {
         TRACE_(d3d_caps)("No available modes for display format %s.\n", debug_d3dformat(display_format));
@@ -4148,7 +4115,7 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT adapter
     }
 
     /* Use CheckDeviceFormat to see if the backbuffer_format is usable with the given display_format */
-    hr = IWineD3DImpl_CheckDeviceFormat(iface, adapter_idx, device_type, display_format,
+    hr = wined3d_check_device_format(wined3d, adapter_idx, device_type, display_format,
             WINED3DUSAGE_RENDERTARGET, WINED3DRTYPE_SURFACE, backbuffer_format, SURFACE_OPENGL);
     if (FAILED(hr))
         TRACE_(d3d_caps)("Unsupported display/backbuffer format combination %s / %s.\n",
@@ -4160,10 +4127,10 @@ static HRESULT WINAPI IWineD3DImpl_CheckDeviceType(IWineD3D *iface, UINT adapter
 /* Note: d3d8 passes in a pointer to a D3DCAPS8 structure, which is a true
       subset of a D3DCAPS9 structure. However, it has to come via a void *
       as the d3d8 interface cannot import the d3d9 header                  */
-static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter, WINED3DDEVTYPE DeviceType, WINED3DCAPS* pCaps) {
-
-    IWineD3DImpl    *This = (IWineD3DImpl *)iface;
-    struct wined3d_adapter *adapter = &This->adapters[Adapter];
+HRESULT CDECL wined3d_get_device_caps(const struct wined3d *wined3d, UINT adapter_idx,
+        WINED3DDEVTYPE device_type, WINED3DCAPS *caps)
+{
+    const struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx];
     const struct wined3d_gl_info *gl_info = &adapter->gl_info;
     int vs_selected_mode;
     int ps_selected_mode;
@@ -4171,40 +4138,39 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
     struct fragment_caps fragment_caps;
     DWORD ckey_caps, blit_caps, fx_caps, pal_caps;
 
-    TRACE_(d3d_caps)("(%p)->(Adptr:%d, DevType: %x, pCaps: %p)\n", This, Adapter, DeviceType, pCaps);
+    TRACE_(d3d_caps)("wined3d %p, adapter_idx %u, device_type %s, caps %p.\n",
+            wined3d, adapter_idx, debug_d3ddevicetype(device_type), caps);
 
-    if (Adapter >= IWineD3D_GetAdapterCount(iface)) {
+    if (adapter_idx >= wined3d->adapter_count)
         return WINED3DERR_INVALIDCALL;
-    }
 
     select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
 
     /* ------------------------------------------------
        The following fields apply to both d3d8 and d3d9
        ------------------------------------------------ */
-    pCaps->DeviceType              = (DeviceType == WINED3DDEVTYPE_HAL) ? WINED3DDEVTYPE_HAL : WINED3DDEVTYPE_REF;  /* Not quite true, but use h/w supported by opengl I suppose */
-    pCaps->AdapterOrdinal          = Adapter;
+    /* Not quite true, but use h/w supported by opengl I suppose */
+    caps->DeviceType               = (device_type == WINED3DDEVTYPE_HAL) ? WINED3DDEVTYPE_HAL : WINED3DDEVTYPE_REF;
+    caps->AdapterOrdinal           = adapter_idx;
 
-    pCaps->Caps                    = 0;
-    pCaps->Caps2                   = WINED3DCAPS2_CANRENDERWINDOWED |
+    caps->Caps                     = 0;
+    caps->Caps2                    = WINED3DCAPS2_CANRENDERWINDOWED |
                                      WINED3DCAPS2_FULLSCREENGAMMA |
                                      WINED3DCAPS2_DYNAMICTEXTURES;
     if (gl_info->supported[SGIS_GENERATE_MIPMAP])
-    {
-        pCaps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
-    }
+        caps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
 
-    pCaps->Caps3                   = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD |
+    caps->Caps3                    = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD |
                                      WINED3DCAPS3_COPY_TO_VIDMEM                   |
                                      WINED3DCAPS3_COPY_TO_SYSTEMMEM;
 
-    pCaps->PresentationIntervals   = WINED3DPRESENT_INTERVAL_IMMEDIATE  |
+    caps->PresentationIntervals    = WINED3DPRESENT_INTERVAL_IMMEDIATE  |
                                      WINED3DPRESENT_INTERVAL_ONE;
 
-    pCaps->CursorCaps              = WINED3DCURSORCAPS_COLOR            |
+    caps->CursorCaps               = WINED3DCURSORCAPS_COLOR            |
                                      WINED3DCURSORCAPS_LOWRES;
 
-    pCaps->DevCaps                 = WINED3DDEVCAPS_FLOATTLVERTEX       |
+    caps->DevCaps                  = WINED3DDEVCAPS_FLOATTLVERTEX       |
                                      WINED3DDEVCAPS_EXECUTESYSTEMMEMORY |
                                      WINED3DDEVCAPS_TLVERTEXSYSTEMMEMORY|
                                      WINED3DDEVCAPS_TLVERTEXVIDEOMEMORY |
@@ -4220,7 +4186,7 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
                                      WINED3DDEVCAPS_DRAWPRIMITIVES2EX   |
                                      WINED3DDEVCAPS_RTPATCHES;
 
-    pCaps->PrimitiveMiscCaps       = WINED3DPMISCCAPS_CULLNONE              |
+    caps->PrimitiveMiscCaps        = WINED3DPMISCCAPS_CULLNONE              |
                                      WINED3DPMISCCAPS_CULLCCW               |
                                      WINED3DPMISCCAPS_CULLCW                |
                                      WINED3DPMISCCAPS_COLORWRITEENABLE      |
@@ -4236,11 +4202,11 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
                                         WINED3DPMISCCAPS_FOGVERTEXCLAMPED */
 
     if (gl_info->supported[EXT_BLEND_EQUATION_SEPARATE] && gl_info->supported[EXT_BLEND_FUNC_SEPARATE])
-        pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
+        caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
     if (gl_info->supported[EXT_DRAW_BUFFERS2])
-        pCaps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS;
+        caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS;
 
-    pCaps->RasterCaps              = WINED3DPRASTERCAPS_DITHER    |
+    caps->RasterCaps               = WINED3DPRASTERCAPS_DITHER    |
                                      WINED3DPRASTERCAPS_PAT       |
                                      WINED3DPRASTERCAPS_WFOG      |
                                      WINED3DPRASTERCAPS_ZFOG      |
@@ -4255,13 +4221,13 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
 
     if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
     {
-        pCaps->RasterCaps |= WINED3DPRASTERCAPS_ANISOTROPY    |
+        caps->RasterCaps  |= WINED3DPRASTERCAPS_ANISOTROPY    |
                              WINED3DPRASTERCAPS_ZBIAS         |
                              WINED3DPRASTERCAPS_MIPMAPLODBIAS;
     }
     if (gl_info->supported[NV_FOG_DISTANCE])
     {
-        pCaps->RasterCaps         |= WINED3DPRASTERCAPS_FOGRANGE;
+        caps->RasterCaps          |= WINED3DPRASTERCAPS_FOGRANGE;
     }
                         /* FIXME Add:
                            WINED3DPRASTERCAPS_COLORPERSPECTIVE
@@ -4270,7 +4236,7 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
                            WINED3DPRASTERCAPS_ZBUFFERLESSHSR
                            WINED3DPRASTERCAPS_WBUFFER */
 
-    pCaps->ZCmpCaps = WINED3DPCMPCAPS_ALWAYS       |
+    caps->ZCmpCaps =  WINED3DPCMPCAPS_ALWAYS       |
                       WINED3DPCMPCAPS_EQUAL        |
                       WINED3DPCMPCAPS_GREATER      |
                       WINED3DPCMPCAPS_GREATEREQUAL |
@@ -4279,7 +4245,7 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
                       WINED3DPCMPCAPS_NEVER        |
                       WINED3DPCMPCAPS_NOTEQUAL;
 
-    pCaps->SrcBlendCaps  = WINED3DPBLENDCAPS_BOTHINVSRCALPHA |
+    caps->SrcBlendCaps  =  WINED3DPBLENDCAPS_BOTHINVSRCALPHA |
                            WINED3DPBLENDCAPS_BOTHSRCALPHA    |
                            WINED3DPBLENDCAPS_DESTALPHA       |
                            WINED3DPBLENDCAPS_DESTCOLOR       |
@@ -4293,7 +4259,7 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
                            WINED3DPBLENDCAPS_SRCCOLOR        |
                            WINED3DPBLENDCAPS_ZERO;
 
-    pCaps->DestBlendCaps = WINED3DPBLENDCAPS_DESTALPHA       |
+    caps->DestBlendCaps =  WINED3DPBLENDCAPS_DESTALPHA       |
                            WINED3DPBLENDCAPS_DESTCOLOR       |
                            WINED3DPBLENDCAPS_INVDESTALPHA    |
                            WINED3DPBLENDCAPS_INVDESTCOLOR    |
@@ -4312,12 +4278,12 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
 
     if (gl_info->supported[EXT_BLEND_COLOR])
     {
-        pCaps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
-        pCaps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
+        caps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
+        caps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
     }
 
 
-    pCaps->AlphaCmpCaps = WINED3DPCMPCAPS_ALWAYS       |
+    caps->AlphaCmpCaps  = WINED3DPCMPCAPS_ALWAYS       |
                           WINED3DPCMPCAPS_EQUAL        |
                           WINED3DPCMPCAPS_GREATER      |
                           WINED3DPCMPCAPS_GREATEREQUAL |
@@ -4326,7 +4292,7 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
                           WINED3DPCMPCAPS_NEVER        |
                           WINED3DPCMPCAPS_NOTEQUAL;
 
-    pCaps->ShadeCaps     = WINED3DPSHADECAPS_SPECULARGOURAUDRGB |
+    caps->ShadeCaps      = WINED3DPSHADECAPS_SPECULARGOURAUDRGB |
                            WINED3DPSHADECAPS_COLORGOURAUDRGB    |
                            WINED3DPSHADECAPS_ALPHAFLATBLEND     |
                            WINED3DPSHADECAPS_ALPHAGOURAUDBLEND  |
@@ -4335,7 +4301,7 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
                            WINED3DPSHADECAPS_FOGGOURAUD         |
                            WINED3DPSHADECAPS_SPECULARFLATRGB;
 
-    pCaps->TextureCaps =  WINED3DPTEXTURECAPS_ALPHA              |
+    caps->TextureCaps   = WINED3DPTEXTURECAPS_ALPHA              |
                           WINED3DPTEXTURECAPS_ALPHAPALETTE       |
                           WINED3DPTEXTURECAPS_TRANSPARENCY       |
                           WINED3DPTEXTURECAPS_BORDER             |
@@ -4345,31 +4311,31 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
 
     if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
     {
-        pCaps->TextureCaps |= WINED3DPTEXTURECAPS_POW2 |
+        caps->TextureCaps  |= WINED3DPTEXTURECAPS_POW2 |
                               WINED3DPTEXTURECAPS_NONPOW2CONDITIONAL;
     }
 
     if (gl_info->supported[EXT_TEXTURE3D])
     {
-        pCaps->TextureCaps |=  WINED3DPTEXTURECAPS_VOLUMEMAP      |
+        caps->TextureCaps  |=  WINED3DPTEXTURECAPS_VOLUMEMAP      |
                                WINED3DPTEXTURECAPS_MIPVOLUMEMAP;
         if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
         {
-            pCaps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP_POW2;
+            caps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP_POW2;
         }
     }
 
     if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
     {
-        pCaps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP     |
+        caps->TextureCaps  |= WINED3DPTEXTURECAPS_CUBEMAP     |
                               WINED3DPTEXTURECAPS_MIPCUBEMAP;
         if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
         {
-            pCaps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP_POW2;
+            caps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP_POW2;
         }
     }
 
-    pCaps->TextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR       |
+    caps->TextureFilterCaps =  WINED3DPTFILTERCAPS_MAGFLINEAR       |
                                WINED3DPTFILTERCAPS_MAGFPOINT        |
                                WINED3DPTFILTERCAPS_MINFLINEAR       |
                                WINED3DPTFILTERCAPS_MINFPOINT        |
@@ -4384,13 +4350,13 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
 
     if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
     {
-        pCaps->TextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
+        caps->TextureFilterCaps  |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
                                     WINED3DPTFILTERCAPS_MINFANISOTROPIC;
     }
 
     if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
     {
-        pCaps->CubeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR       |
+        caps->CubeTextureFilterCaps =  WINED3DPTFILTERCAPS_MAGFLINEAR       |
                                        WINED3DPTFILTERCAPS_MAGFPOINT        |
                                        WINED3DPTFILTERCAPS_MINFLINEAR       |
                                        WINED3DPTFILTERCAPS_MINFPOINT        |
@@ -4405,15 +4371,18 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
 
         if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
         {
-            pCaps->CubeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
+            caps->CubeTextureFilterCaps  |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
                                             WINED3DPTFILTERCAPS_MINFANISOTROPIC;
         }
-    } else
-        pCaps->CubeTextureFilterCaps = 0;
+    }
+    else
+    {
+        caps->CubeTextureFilterCaps = 0;
+    }
 
     if (gl_info->supported[EXT_TEXTURE3D])
     {
-        pCaps->VolumeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR       |
+        caps->VolumeTextureFilterCaps  = WINED3DPTFILTERCAPS_MAGFLINEAR       |
                                          WINED3DPTFILTERCAPS_MAGFPOINT        |
                                          WINED3DPTFILTERCAPS_MINFLINEAR       |
                                          WINED3DPTFILTERCAPS_MINFPOINT        |
@@ -4425,47 +4394,53 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
                                          WINED3DPTFILTERCAPS_MIPLINEAR        |
                                          WINED3DPTFILTERCAPS_MIPNEAREST       |
                                          WINED3DPTFILTERCAPS_NEAREST;
-    } else
-        pCaps->VolumeTextureFilterCaps = 0;
+    }
+    else
+    {
+        caps->VolumeTextureFilterCaps = 0;
+    }
 
-    pCaps->TextureAddressCaps =  WINED3DPTADDRESSCAPS_INDEPENDENTUV |
+    caps->TextureAddressCaps  =  WINED3DPTADDRESSCAPS_INDEPENDENTUV |
                                  WINED3DPTADDRESSCAPS_CLAMP  |
                                  WINED3DPTADDRESSCAPS_WRAP;
 
     if (gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
     {
-        pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
+        caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
     }
     if (gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT])
     {
-        pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
+        caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
     }
     if (gl_info->supported[ATI_TEXTURE_MIRROR_ONCE])
     {
-        pCaps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
+        caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
     }
 
     if (gl_info->supported[EXT_TEXTURE3D])
     {
-        pCaps->VolumeTextureAddressCaps =  WINED3DPTADDRESSCAPS_INDEPENDENTUV |
+        caps->VolumeTextureAddressCaps =   WINED3DPTADDRESSCAPS_INDEPENDENTUV |
                                            WINED3DPTADDRESSCAPS_CLAMP  |
                                            WINED3DPTADDRESSCAPS_WRAP;
         if (gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
         {
-            pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
+            caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
         }
         if (gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT])
         {
-            pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
+            caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
         }
         if (gl_info->supported[ATI_TEXTURE_MIRROR_ONCE])
         {
-            pCaps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
+            caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
         }
-    } else
-        pCaps->VolumeTextureAddressCaps = 0;
+    }
+    else
+    {
+        caps->VolumeTextureAddressCaps = 0;
+    }
 
-    pCaps->LineCaps = WINED3DLINECAPS_TEXTURE       |
+    caps->LineCaps  = WINED3DLINECAPS_TEXTURE       |
                       WINED3DLINECAPS_ZTEST         |
                       WINED3DLINECAPS_BLEND         |
                       WINED3DLINECAPS_ALPHACMP      |
@@ -4474,26 +4449,26 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
      * idea how generating the smoothing alpha values works; the result is different
      */
 
-    pCaps->MaxTextureWidth = gl_info->limits.texture_size;
-    pCaps->MaxTextureHeight = gl_info->limits.texture_size;
+    caps->MaxTextureWidth = gl_info->limits.texture_size;
+    caps->MaxTextureHeight = gl_info->limits.texture_size;
 
     if (gl_info->supported[EXT_TEXTURE3D])
-        pCaps->MaxVolumeExtent = gl_info->limits.texture3d_size;
+        caps->MaxVolumeExtent = gl_info->limits.texture3d_size;
     else
-        pCaps->MaxVolumeExtent = 0;
+        caps->MaxVolumeExtent = 0;
 
-    pCaps->MaxTextureRepeat = 32768;
-    pCaps->MaxTextureAspectRatio = gl_info->limits.texture_size;
-    pCaps->MaxVertexW = 1.0f;
+    caps->MaxTextureRepeat = 32768;
+    caps->MaxTextureAspectRatio = gl_info->limits.texture_size;
+    caps->MaxVertexW = 1.0f;
 
-    pCaps->GuardBandLeft = 0.0f;
-    pCaps->GuardBandTop = 0.0f;
-    pCaps->GuardBandRight = 0.0f;
-    pCaps->GuardBandBottom = 0.0f;
+    caps->GuardBandLeft = 0.0f;
+    caps->GuardBandTop = 0.0f;
+    caps->GuardBandRight = 0.0f;
+    caps->GuardBandBottom = 0.0f;
 
-    pCaps->ExtentsAdjust = 0.0f;
+    caps->ExtentsAdjust = 0.0f;
 
-    pCaps->StencilCaps =  WINED3DSTENCILCAPS_DECRSAT |
+    caps->StencilCaps   = WINED3DSTENCILCAPS_DECRSAT |
                           WINED3DSTENCILCAPS_INCRSAT |
                           WINED3DSTENCILCAPS_INVERT  |
                           WINED3DSTENCILCAPS_KEEP    |
@@ -4501,162 +4476,185 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
                           WINED3DSTENCILCAPS_ZERO;
     if (gl_info->supported[EXT_STENCIL_WRAP])
     {
-        pCaps->StencilCaps |= WINED3DSTENCILCAPS_DECR  |
+        caps->StencilCaps |= WINED3DSTENCILCAPS_DECR  |
                               WINED3DSTENCILCAPS_INCR;
     }
     if (gl_info->supported[EXT_STENCIL_TWO_SIDE] || gl_info->supported[ATI_SEPARATE_STENCIL])
     {
-        pCaps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
+        caps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
     }
 
-    pCaps->FVFCaps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
+    caps->FVFCaps = WINED3DFVFCAPS_PSIZE | 0x0008; /* 8 texture coords */
 
-    pCaps->MaxUserClipPlanes = gl_info->limits.clipplanes;
-    pCaps->MaxActiveLights = gl_info->limits.lights;
+    caps->MaxUserClipPlanes = gl_info->limits.clipplanes;
+    caps->MaxActiveLights = gl_info->limits.lights;
 
-    pCaps->MaxVertexBlendMatrices = gl_info->limits.blends;
-    pCaps->MaxVertexBlendMatrixIndex   = 0;
+    caps->MaxVertexBlendMatrices = gl_info->limits.blends;
+    caps->MaxVertexBlendMatrixIndex   = 0;
 
-    pCaps->MaxAnisotropy = gl_info->limits.anisotropy;
-    pCaps->MaxPointSize = gl_info->limits.pointsize_max;
+    caps->MaxAnisotropy = gl_info->limits.anisotropy;
+    caps->MaxPointSize = gl_info->limits.pointsize_max;
 
 
     /* FIXME: Add D3DVTXPCAPS_TWEENING, D3DVTXPCAPS_TEXGEN_SPHEREMAP */
-    pCaps->VertexProcessingCaps = WINED3DVTXPCAPS_DIRECTIONALLIGHTS |
+    caps->VertexProcessingCaps  = WINED3DVTXPCAPS_DIRECTIONALLIGHTS |
                                   WINED3DVTXPCAPS_MATERIALSOURCE7   |
                                   WINED3DVTXPCAPS_POSITIONALLIGHTS  |
                                   WINED3DVTXPCAPS_LOCALVIEWER       |
                                   WINED3DVTXPCAPS_VERTEXFOG         |
                                   WINED3DVTXPCAPS_TEXGEN;
 
-    pCaps->MaxPrimitiveCount   = 0xFFFFF; /* For now set 2^20-1 which is used by most >=Geforce3/Radeon8500 cards */
-    pCaps->MaxVertexIndex      = 0xFFFFF;
-    pCaps->MaxStreams          = MAX_STREAMS;
-    pCaps->MaxStreamStride     = 1024;
+    caps->MaxPrimitiveCount   = 0xFFFFF; /* For now set 2^20-1 which is used by most >=Geforce3/Radeon8500 cards */
+    caps->MaxVertexIndex      = 0xFFFFF;
+    caps->MaxStreams          = MAX_STREAMS;
+    caps->MaxStreamStride     = 1024;
 
     /* d3d9.dll sets D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES here because StretchRects is implemented in d3d9 */
-    pCaps->DevCaps2                          = WINED3DDEVCAPS2_STREAMOFFSET |
-                                               WINED3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
-    pCaps->MaxNpatchTessellationLevel        = 0;
-    pCaps->MasterAdapterOrdinal              = 0;
-    pCaps->AdapterOrdinalInGroup             = 0;
-    pCaps->NumberOfAdaptersInGroup           = 1;
+    caps->DevCaps2                          = WINED3DDEVCAPS2_STREAMOFFSET |
+                                              WINED3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
+    caps->MaxNpatchTessellationLevel        = 0;
+    caps->MasterAdapterOrdinal              = 0;
+    caps->AdapterOrdinalInGroup             = 0;
+    caps->NumberOfAdaptersInGroup           = 1;
 
-    pCaps->NumSimultaneousRTs = gl_info->limits.buffers;
+    caps->NumSimultaneousRTs = gl_info->limits.buffers;
 
-    pCaps->StretchRectFilterCaps             = WINED3DPTFILTERCAPS_MINFPOINT  |
+    caps->StretchRectFilterCaps               = WINED3DPTFILTERCAPS_MINFPOINT  |
                                                 WINED3DPTFILTERCAPS_MAGFPOINT  |
                                                 WINED3DPTFILTERCAPS_MINFLINEAR |
                                                 WINED3DPTFILTERCAPS_MAGFLINEAR;
-    pCaps->VertexTextureFilterCaps           = 0;
+    caps->VertexTextureFilterCaps             = 0;
 
     adapter->shader_backend->shader_get_caps(&adapter->gl_info, &shader_caps);
     adapter->fragment_pipe->get_caps(&adapter->gl_info, &fragment_caps);
 
     /* Add shader misc caps. Only some of them belong to the shader parts of the pipeline */
-    pCaps->PrimitiveMiscCaps |= fragment_caps.PrimitiveMiscCaps;
+    caps->PrimitiveMiscCaps |= fragment_caps.PrimitiveMiscCaps;
 
     /* This takes care for disabling vertex shader or pixel shader caps while leaving the other one enabled.
      * Ignore shader model capabilities if disabled in config
      */
-    if(vs_selected_mode == SHADER_NONE) {
+    if (vs_selected_mode == SHADER_NONE)
+    {
         TRACE_(d3d_caps)("Vertex shader disabled in config, reporting version 0.0\n");
-        pCaps->VertexShaderVersion          = WINED3DVS_VERSION(0,0);
-        pCaps->MaxVertexShaderConst         = 0;
-    } else {
-        pCaps->VertexShaderVersion          = shader_caps.VertexShaderVersion;
-        pCaps->MaxVertexShaderConst         = shader_caps.MaxVertexShaderConst;
+        caps->VertexShaderVersion          = WINED3DVS_VERSION(0,0);
+        caps->MaxVertexShaderConst         = 0;
+    }
+    else
+    {
+        caps->VertexShaderVersion          = shader_caps.VertexShaderVersion;
+        caps->MaxVertexShaderConst         = shader_caps.MaxVertexShaderConst;
     }
 
-    if(ps_selected_mode == SHADER_NONE) {
+    if (ps_selected_mode == SHADER_NONE)
+    {
         TRACE_(d3d_caps)("Pixel shader disabled in config, reporting version 0.0\n");
-        pCaps->PixelShaderVersion           = WINED3DPS_VERSION(0,0);
-        pCaps->PixelShader1xMaxValue        = 0.0f;
+        caps->PixelShaderVersion           = WINED3DPS_VERSION(0,0);
+        caps->PixelShader1xMaxValue        = 0.0f;
     } else {
-        pCaps->PixelShaderVersion           = shader_caps.PixelShaderVersion;
-        pCaps->PixelShader1xMaxValue        = shader_caps.PixelShader1xMaxValue;
+        caps->PixelShaderVersion           = shader_caps.PixelShaderVersion;
+        caps->PixelShader1xMaxValue        = shader_caps.PixelShader1xMaxValue;
     }
 
-    pCaps->TextureOpCaps                    = fragment_caps.TextureOpCaps;
-    pCaps->MaxTextureBlendStages            = fragment_caps.MaxTextureBlendStages;
-    pCaps->MaxSimultaneousTextures          = fragment_caps.MaxSimultaneousTextures;
+    caps->TextureOpCaps                    = fragment_caps.TextureOpCaps;
+    caps->MaxTextureBlendStages            = fragment_caps.MaxTextureBlendStages;
+    caps->MaxSimultaneousTextures          = fragment_caps.MaxSimultaneousTextures;
 
     /* The following caps are shader specific, but they are things we cannot detect, or which
      * are the same among all shader models. So to avoid code duplication set the shader version
      * specific, but otherwise constant caps here
      */
-    if(pCaps->VertexShaderVersion == WINED3DVS_VERSION(3,0)) {
-        /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
-        use the VS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum VS3.0 value. */
-        pCaps->VS20Caps.Caps                     = WINED3DVS20CAPS_PREDICATION;
-        pCaps->VS20Caps.DynamicFlowControlDepth  = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
-        pCaps->VS20Caps.NumTemps = max(32, adapter->gl_info.limits.arb_vs_temps);
-        pCaps->VS20Caps.StaticFlowControlDepth   = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH ; /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
-
-        pCaps->MaxVShaderInstructionsExecuted    = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
-        pCaps->MaxVertexShader30InstructionSlots = max(512, adapter->gl_info.limits.arb_vs_instructions);
-    }
-    else if (pCaps->VertexShaderVersion == WINED3DVS_VERSION(2,0))
-    {
-        pCaps->VS20Caps.Caps                     = 0;
-        pCaps->VS20Caps.DynamicFlowControlDepth  = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
-        pCaps->VS20Caps.NumTemps = max(12, adapter->gl_info.limits.arb_vs_temps);
-        pCaps->VS20Caps.StaticFlowControlDepth   = 1;
-
-        pCaps->MaxVShaderInstructionsExecuted    = 65535;
-        pCaps->MaxVertexShader30InstructionSlots = 0;
-    } else { /* VS 1.x */
-        pCaps->VS20Caps.Caps                     = 0;
-        pCaps->VS20Caps.DynamicFlowControlDepth  = 0;
-        pCaps->VS20Caps.NumTemps                 = 0;
-        pCaps->VS20Caps.StaticFlowControlDepth   = 0;
-
-        pCaps->MaxVShaderInstructionsExecuted    = 0;
-        pCaps->MaxVertexShader30InstructionSlots = 0;
-    }
-
-    if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(3,0)) {
-        /* Where possible set the caps based on OpenGL extensions and if they aren't set (in case of software rendering)
-        use the PS 3.0 from MSDN or else if there's OpenGL spec use a hardcoded value minimum PS 3.0 value. */
-
-        /* Caps is more or less undocumented on MSDN but it appears to be used for PS20Caps based on results from R9600/FX5900/Geforce6800 cards from Windows */
-        pCaps->PS20Caps.Caps                     = WINED3DPS20CAPS_ARBITRARYSWIZZLE     |
+    if (caps->VertexShaderVersion == WINED3DVS_VERSION(3,0))
+    {
+        /* Where possible set the caps based on OpenGL extensions and if they
+         * aren't set (in case of software rendering) use the VS 3.0 from
+         * MSDN or else if there's OpenGL spec use a hardcoded value minimum
+         * VS3.0 value. */
+        caps->VS20Caps.Caps                     = WINED3DVS20CAPS_PREDICATION;
+        /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
+        caps->VS20Caps.DynamicFlowControlDepth  = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH;
+        caps->VS20Caps.NumTemps = max(32, adapter->gl_info.limits.arb_vs_temps);
+        /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
+        caps->VS20Caps.StaticFlowControlDepth   = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH;
+
+        caps->MaxVShaderInstructionsExecuted    = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
+        caps->MaxVertexShader30InstructionSlots = max(512, adapter->gl_info.limits.arb_vs_instructions);
+    }
+    else if (caps->VertexShaderVersion == WINED3DVS_VERSION(2,0))
+    {
+        caps->VS20Caps.Caps                     = 0;
+        caps->VS20Caps.DynamicFlowControlDepth  = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
+        caps->VS20Caps.NumTemps = max(12, adapter->gl_info.limits.arb_vs_temps);
+        caps->VS20Caps.StaticFlowControlDepth   = 1;
+
+        caps->MaxVShaderInstructionsExecuted    = 65535;
+        caps->MaxVertexShader30InstructionSlots = 0;
+    }
+    else
+    { /* VS 1.x */
+        caps->VS20Caps.Caps                     = 0;
+        caps->VS20Caps.DynamicFlowControlDepth  = 0;
+        caps->VS20Caps.NumTemps                 = 0;
+        caps->VS20Caps.StaticFlowControlDepth   = 0;
+
+        caps->MaxVShaderInstructionsExecuted    = 0;
+        caps->MaxVertexShader30InstructionSlots = 0;
+    }
+
+    if (caps->PixelShaderVersion == WINED3DPS_VERSION(3,0))
+    {
+        /* Where possible set the caps based on OpenGL extensions and if they
+         * aren't set (in case of software rendering) use the PS 3.0 from
+         * MSDN or else if there's OpenGL spec use a hardcoded value minimum
+         * PS 3.0 value. */
+
+        /* Caps is more or less undocumented on MSDN but it appears to be
+         * used for PS20Caps based on results from R9600/FX5900/Geforce6800
+         * cards from Windows */
+        caps->PS20Caps.Caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE |
                 WINED3DPS20CAPS_GRADIENTINSTRUCTIONS |
                 WINED3DPS20CAPS_PREDICATION          |
                 WINED3DPS20CAPS_NODEPENDENTREADLIMIT |
                 WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
-        pCaps->PS20Caps.DynamicFlowControlDepth  = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
-        pCaps->PS20Caps.NumTemps = max(32, adapter->gl_info.limits.arb_ps_temps);
-        pCaps->PS20Caps.StaticFlowControlDepth   = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH; /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
-        pCaps->PS20Caps.NumInstructionSlots      = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS; /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
-
-        pCaps->MaxPShaderInstructionsExecuted    = 65535;
-        pCaps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS,
+        /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
+        caps->PS20Caps.DynamicFlowControlDepth  = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH;
+        caps->PS20Caps.NumTemps = max(32, adapter->gl_info.limits.arb_ps_temps);
+        /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
+        caps->PS20Caps.StaticFlowControlDepth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH;
+        /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
+        caps->PS20Caps.NumInstructionSlots = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS;
+
+        caps->MaxPShaderInstructionsExecuted = 65535;
+        caps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS,
                 adapter->gl_info.limits.arb_ps_instructions);
     }
-    else if(pCaps->PixelShaderVersion == WINED3DPS_VERSION(2,0))
+    else if(caps->PixelShaderVersion == WINED3DPS_VERSION(2,0))
     {
         /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */
-        pCaps->PS20Caps.Caps                     = 0;
-        pCaps->PS20Caps.DynamicFlowControlDepth  = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
-        pCaps->PS20Caps.NumTemps = max(12, adapter->gl_info.limits.arb_ps_temps);
-        pCaps->PS20Caps.StaticFlowControlDepth   = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
-        pCaps->PS20Caps.NumInstructionSlots      = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS; /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
-
-        pCaps->MaxPShaderInstructionsExecuted    = 512; /* Minimum value, a GeforceFX uses 1024 */
-        pCaps->MaxPixelShader30InstructionSlots  = 0;
-    } else { /* PS 1.x */
-        pCaps->PS20Caps.Caps                     = 0;
-        pCaps->PS20Caps.DynamicFlowControlDepth  = 0;
-        pCaps->PS20Caps.NumTemps                 = 0;
-        pCaps->PS20Caps.StaticFlowControlDepth   = 0;
-        pCaps->PS20Caps.NumInstructionSlots      = 0;
-
-        pCaps->MaxPShaderInstructionsExecuted    = 0;
-        pCaps->MaxPixelShader30InstructionSlots  = 0;
-    }
-
-    if(pCaps->VertexShaderVersion >= WINED3DVS_VERSION(2,0)) {
+        caps->PS20Caps.Caps                     = 0;
+        caps->PS20Caps.DynamicFlowControlDepth  = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
+        caps->PS20Caps.NumTemps = max(12, adapter->gl_info.limits.arb_ps_temps);
+        caps->PS20Caps.StaticFlowControlDepth   = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
+        /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
+        caps->PS20Caps.NumInstructionSlots      = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS;
+
+        caps->MaxPShaderInstructionsExecuted    = 512; /* Minimum value, a GeforceFX uses 1024 */
+        caps->MaxPixelShader30InstructionSlots  = 0;
+    }
+    else /* PS 1.x */
+    {
+        caps->PS20Caps.Caps                     = 0;
+        caps->PS20Caps.DynamicFlowControlDepth  = 0;
+        caps->PS20Caps.NumTemps                 = 0;
+        caps->PS20Caps.StaticFlowControlDepth   = 0;
+        caps->PS20Caps.NumInstructionSlots      = 0;
+
+        caps->MaxPShaderInstructionsExecuted    = 0;
+        caps->MaxPixelShader30InstructionSlots  = 0;
+    }
+
+    if (caps->VertexShaderVersion >= WINED3DVS_VERSION(2,0))
+    {
         /* OpenGL supports all the formats below, perhaps not always
          * without conversion, but it supports them.
          * Further GLSL doesn't seem to have an official unsigned type so
@@ -4664,17 +4662,20 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
          * We might need to add some clamping in the shader engine to
          * support it.
          * TODO: WINED3DDTCAPS_USHORT2N, WINED3DDTCAPS_USHORT4N, WINED3DDTCAPS_UDEC3, WINED3DDTCAPS_DEC3N */
-        pCaps->DeclTypes = WINED3DDTCAPS_UBYTE4    |
-                           WINED3DDTCAPS_UBYTE4N   |
-                           WINED3DDTCAPS_SHORT2N   |
-                           WINED3DDTCAPS_SHORT4N;
+        caps->DeclTypes = WINED3DDTCAPS_UBYTE4    |
+                          WINED3DDTCAPS_UBYTE4N   |
+                          WINED3DDTCAPS_SHORT2N   |
+                          WINED3DDTCAPS_SHORT4N;
         if (gl_info->supported[ARB_HALF_FLOAT_VERTEX])
         {
-            pCaps->DeclTypes |= WINED3DDTCAPS_FLOAT16_2 |
-                                WINED3DDTCAPS_FLOAT16_4;
+            caps->DeclTypes |= WINED3DDTCAPS_FLOAT16_2 |
+                               WINED3DDTCAPS_FLOAT16_4;
         }
-    } else
-        pCaps->DeclTypes                         = 0;
+    }
+    else
+    {
+        caps->DeclTypes = 0;
+    }
 
     /* Set DirectDraw helper Caps */
     ckey_caps =                         WINEDDCKEYCAPS_DESTBLT              |
@@ -4705,28 +4706,28 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
                                         WINEDDPCAPS_PRIMARYSURFACE;
 
     /* Fill the ddraw caps structure */
-    pCaps->DirectDrawCaps.Caps =        WINEDDCAPS_GDI                      |
+    caps->DirectDrawCaps.Caps =         WINEDDCAPS_GDI                      |
                                         WINEDDCAPS_PALETTE                  |
                                         blit_caps;
-    pCaps->DirectDrawCaps.Caps2 =       WINEDDCAPS2_CERTIFIED                |
+    caps->DirectDrawCaps.Caps2 =        WINEDDCAPS2_CERTIFIED                |
                                         WINEDDCAPS2_NOPAGELOCKREQUIRED       |
                                         WINEDDCAPS2_PRIMARYGAMMA             |
                                         WINEDDCAPS2_WIDESURFACES             |
                                         WINEDDCAPS2_CANRENDERWINDOWED;
-    pCaps->DirectDrawCaps.CKeyCaps =    ckey_caps;
-    pCaps->DirectDrawCaps.FXCaps =      fx_caps;
-    pCaps->DirectDrawCaps.PalCaps =     pal_caps;
-    pCaps->DirectDrawCaps.SVBCaps =     blit_caps;
-    pCaps->DirectDrawCaps.SVBCKeyCaps = ckey_caps;
-    pCaps->DirectDrawCaps.SVBFXCaps =   fx_caps;
-    pCaps->DirectDrawCaps.VSBCaps =     blit_caps;
-    pCaps->DirectDrawCaps.VSBCKeyCaps = ckey_caps;
-    pCaps->DirectDrawCaps.VSBFXCaps =   fx_caps;
-    pCaps->DirectDrawCaps.SSBCaps =     blit_caps;
-    pCaps->DirectDrawCaps.SSBCKeyCaps = ckey_caps;
-    pCaps->DirectDrawCaps.SSBFXCaps =   fx_caps;
-
-    pCaps->DirectDrawCaps.ddsCaps =     WINEDDSCAPS_ALPHA                   |
+    caps->DirectDrawCaps.CKeyCaps =     ckey_caps;
+    caps->DirectDrawCaps.FXCaps =       fx_caps;
+    caps->DirectDrawCaps.PalCaps =      pal_caps;
+    caps->DirectDrawCaps.SVBCaps =      blit_caps;
+    caps->DirectDrawCaps.SVBCKeyCaps =  ckey_caps;
+    caps->DirectDrawCaps.SVBFXCaps =    fx_caps;
+    caps->DirectDrawCaps.VSBCaps =      blit_caps;
+    caps->DirectDrawCaps.VSBCKeyCaps =  ckey_caps;
+    caps->DirectDrawCaps.VSBFXCaps =    fx_caps;
+    caps->DirectDrawCaps.SSBCaps =      blit_caps;
+    caps->DirectDrawCaps.SSBCKeyCaps =  ckey_caps;
+    caps->DirectDrawCaps.SSBFXCaps =    fx_caps;
+
+    caps->DirectDrawCaps.ddsCaps =      WINEDDSCAPS_ALPHA                   |
                                         WINEDDSCAPS_BACKBUFFER              |
                                         WINEDDSCAPS_FLIP                    |
                                         WINEDDSCAPS_FRONTBUFFER             |
@@ -4736,37 +4737,34 @@ static HRESULT WINAPI IWineD3DImpl_GetDeviceCaps(IWineD3D *iface, UINT Adapter,
                                         WINEDDSCAPS_SYSTEMMEMORY            |
                                         WINEDDSCAPS_VIDEOMEMORY             |
                                         WINEDDSCAPS_VISIBLE;
-    pCaps->DirectDrawCaps.StrideAlign = DDRAW_PITCH_ALIGNMENT;
+    caps->DirectDrawCaps.StrideAlign = DDRAW_PITCH_ALIGNMENT;
 
     /* Set D3D caps if OpenGL is available. */
     if (adapter->opengl)
     {
-        pCaps->DirectDrawCaps.ddsCaps |=WINEDDSCAPS_3DDEVICE                |
+        caps->DirectDrawCaps.ddsCaps |= WINEDDSCAPS_3DDEVICE                |
                                         WINEDDSCAPS_MIPMAP                  |
                                         WINEDDSCAPS_TEXTURE                 |
                                         WINEDDSCAPS_ZBUFFER;
-        pCaps->DirectDrawCaps.Caps |=   WINEDDCAPS_3D;
+        caps->DirectDrawCaps.Caps |=    WINEDDCAPS_3D;
     }
 
     return WINED3D_OK;
 }
 
-static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT adapter_idx, WINED3DDEVTYPE device_type,
+HRESULT CDECL wined3d_device_create(struct wined3d *wined3d, UINT adapter_idx, WINED3DDEVTYPE device_type,
         HWND focus_window, DWORD flags, IWineD3DDeviceParent *device_parent, IWineD3DDevice **device)
 {
-    IWineD3DImpl *This = (IWineD3DImpl *)iface;
     IWineD3DDeviceImpl *object;
     HRESULT hr;
 
-    TRACE("iface %p, adapter_idx %u, device_type %#x, focus_window %p, flags %#x, device_parent %p, device %p.\n",
-            iface, adapter_idx, device_type, focus_window, flags, device_parent, device);
+    TRACE("wined3d %p, adapter_idx %u, device_type %#x, focus_window %p, flags %#x, device_parent %p, device %p.\n",
+            wined3d, adapter_idx, device_type, focus_window, flags, device_parent, device);
 
     /* Validate the adapter number. If no adapters are available(no GL), ignore the adapter
      * number and create a device without a 3D adapter for 2D only operation. */
-    if (IWineD3D_GetAdapterCount(iface) && adapter_idx >= IWineD3D_GetAdapterCount(iface))
-    {
+    if (wined3d->adapter_count && adapter_idx >= wined3d->adapter_count)
         return WINED3DERR_INVALIDCALL;
-    }
 
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
     if (!object)
@@ -4775,7 +4773,7 @@ static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT adapter_id
         return E_OUTOFMEMORY;
     }
 
-    hr = device_init(object, This, adapter_idx, device_type, focus_window, flags, device_parent);
+    hr = device_init(object, wined3d, adapter_idx, device_type, focus_window, flags, device_parent);
     if (FAILED(hr))
     {
         WARN("Failed to initialize device, hr %#x.\n", hr);
@@ -4791,11 +4789,11 @@ static HRESULT WINAPI IWineD3DImpl_CreateDevice(IWineD3D *iface, UINT adapter_id
     return WINED3D_OK;
 }
 
-static void * WINAPI IWineD3DImpl_GetParent(IWineD3D *iface)
+void * CDECL wined3d_get_parent(const struct wined3d *wined3d)
 {
-    TRACE("iface %p.\n", iface);
+    TRACE("wined3d %p.\n", wined3d);
 
-    return ((IWineD3DImpl *)iface)->parent;
+    return wined3d->parent;
 }
 
 static void WINE_GLAPI invalid_func(const void *data)
@@ -5275,34 +5273,6 @@ nogl_adapter:
     return FALSE;
 }
 
-/**********************************************************
- * IWineD3D VTbl follows
- **********************************************************/
-
-static const struct IWineD3DVtbl IWineD3D_Vtbl =
-{
-    /* IUnknown */
-    IWineD3DImpl_QueryInterface,
-    IWineD3DImpl_AddRef,
-    IWineD3DImpl_Release,
-    /* IWineD3D */
-    IWineD3DImpl_GetParent,
-    IWineD3DImpl_GetAdapterCount,
-    IWineD3DImpl_RegisterSoftwareDevice,
-    IWineD3DImpl_GetAdapterMonitor,
-    IWineD3DImpl_GetAdapterModeCount,
-    IWineD3DImpl_EnumAdapterModes,
-    IWineD3DImpl_GetAdapterDisplayMode,
-    IWineD3DImpl_GetAdapterIdentifier,
-    IWineD3DImpl_CheckDeviceMultiSampleType,
-    IWineD3DImpl_CheckDepthStencilMatch,
-    IWineD3DImpl_CheckDeviceType,
-    IWineD3DImpl_CheckDeviceFormat,
-    IWineD3DImpl_CheckDeviceFormatConversion,
-    IWineD3DImpl_GetDeviceCaps,
-    IWineD3DImpl_CreateDevice
-};
-
 static void STDMETHODCALLTYPE wined3d_null_wined3d_object_destroyed(void *parent) {}
 
 const struct wined3d_parent_ops wined3d_null_parent_ops =
@@ -5313,7 +5283,6 @@ const struct wined3d_parent_ops wined3d_null_parent_ops =
 /* Do not call while under the GL lock. */
 HRESULT wined3d_init(IWineD3DImpl *wined3d, UINT version, void *parent)
 {
-    wined3d->lpVtbl = &IWineD3D_Vtbl;
     wined3d->dxVersion = version;
     wined3d->ref = 1;
     wined3d->parent = parent;
diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c
index f613dfe..2c186a2 100644
--- a/dlls/wined3d/swapchain.c
+++ b/dlls/wined3d/swapchain.c
@@ -540,7 +540,7 @@ HRESULT swapchain_init(IWineD3DSwapChainImpl *swapchain, WINED3DSURFTYPE surface
     swapchain->win_handle = window;
     swapchain->device_window = window;
 
-    IWineD3D_GetAdapterDisplayMode(device->wined3d, adapter->ordinal, &mode);
+    wined3d_get_adapter_display_mode(device->wined3d, adapter->ordinal, &mode);
     swapchain->orig_width = mode.Width;
     swapchain->orig_height = mode.Height;
     swapchain->orig_fmt = mode.Format;
diff --git a/dlls/wined3d/swapchain_base.c b/dlls/wined3d/swapchain_base.c
index a2903f6..79d1187 100644
--- a/dlls/wined3d/swapchain_base.c
+++ b/dlls/wined3d/swapchain_base.c
@@ -142,7 +142,7 @@ HRESULT WINAPI IWineD3DBaseSwapChainImpl_GetDisplayMode(IWineD3DSwapChain *iface
     HRESULT hr;
 
     TRACE("(%p)->(%p): Calling GetAdapterDisplayMode\n", This, pMode);
-    hr = IWineD3D_GetAdapterDisplayMode(This->device->wined3d, This->device->adapter->ordinal, pMode);
+    hr = wined3d_get_adapter_display_mode(This->device->wined3d, This->device->adapter->ordinal, pMode);
 
     TRACE("(%p) : returning w(%d) h(%d) rr(%d) fmt(%u,%s)\n", This, pMode->Width, pMode->Height, pMode->RefreshRate,
           pMode->Format, debug_d3dformat(pMode->Format));
diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec
index 2f20f2b..491aa97 100644
--- a/dlls/wined3d/wined3d.spec
+++ b/dlls/wined3d/wined3d.spec
@@ -1,8 +1,27 @@
-@ stdcall WineDirect3DCreate(long ptr)
 @ stdcall WineDirect3DCreateClipper()
 @ stdcall wined3d_mutex_lock()
 @ stdcall wined3d_mutex_unlock()
 
+@ cdecl wined3d_check_depth_stencil_match(ptr long long long long long)
+@ cdecl wined3d_check_device_format(ptr long long long long long long long)
+@ cdecl wined3d_check_device_format_conversion(ptr long long long long)
+@ cdecl wined3d_check_device_multisample_type(ptr long long long long long ptr)
+@ cdecl wined3d_check_device_type(ptr long long long long long)
+@ cdecl wined3d_create(long ptr)
+@ cdecl wined3d_decref(ptr)
+@ cdecl wined3d_enum_adapter_modes(ptr long long long ptr)
+@ cdecl wined3d_get_adapter_count(ptr)
+@ cdecl wined3d_get_adapter_display_mode(ptr long ptr)
+@ cdecl wined3d_get_adapter_identifier(ptr long long ptr)
+@ cdecl wined3d_get_adapter_mode_count(ptr long long)
+@ cdecl wined3d_get_adapter_monitor(ptr long)
+@ cdecl wined3d_get_device_caps(ptr long long ptr)
+@ cdecl wined3d_get_parent(ptr)
+@ cdecl wined3d_incref(ptr)
+@ cdecl wined3d_register_software_device(ptr ptr);
+
+@ cdecl wined3d_device_create(ptr long long ptr long ptr ptr);
+
 @ cdecl wined3d_stateblock_apply(ptr)
 @ cdecl wined3d_stateblock_capture(ptr)
 @ cdecl wined3d_stateblock_decref(ptr)
diff --git a/dlls/wined3d/wined3d_main.c b/dlls/wined3d/wined3d_main.c
index 8cc2828..c46ffe2 100644
--- a/dlls/wined3d/wined3d_main.c
+++ b/dlls/wined3d/wined3d_main.c
@@ -78,7 +78,7 @@ wined3d_settings_t wined3d_settings =
 };
 
 /* Do not call while under the GL lock. */
-IWineD3D * WINAPI WineDirect3DCreate(UINT version, void *parent)
+struct wined3d * CDECL wined3d_create(UINT version, void *parent)
 {
     IWineD3DImpl *object;
     HRESULT hr;
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 83aa0d4..5d4ad04 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -59,6 +59,8 @@ typedef struct IWineD3DSwapChainImpl  IWineD3DSwapChainImpl;
 struct IWineD3DBaseShaderImpl;
 struct IWineD3DBaseTextureImpl;
 struct IWineD3DResourceImpl;
+typedef struct wined3d IWineD3DImpl;
+typedef struct wined3d IWineD3D;
 
 /* Texture format fixups */
 
@@ -1611,22 +1613,14 @@ const struct ffp_frag_desc *find_ffp_frag_shader(const struct wine_rb_tree *frag
         const struct ffp_frag_settings *settings) DECLSPEC_HIDDEN;
 void add_ffp_frag_shader(struct wine_rb_tree *shaders, struct ffp_frag_desc *desc) DECLSPEC_HIDDEN;
 
-/*****************************************************************************
- * IWineD3D implementation structure
- */
-typedef struct IWineD3DImpl
+struct wined3d
 {
-    /* IUnknown fields */
-    const IWineD3DVtbl     *lpVtbl;
-    LONG                    ref;     /* Note: Ref counting not required */
-
-    /* WineD3D Information */
+    LONG ref;
     void *parent;
-    UINT                    dxVersion;
-
+    UINT dxVersion;
     UINT adapter_count;
     struct wined3d_adapter adapters[1];
-} IWineD3DImpl;
+};
 
 HRESULT wined3d_init(IWineD3DImpl *wined3d, UINT version, void *parent) DECLSPEC_HIDDEN;
 BOOL wined3d_register_window(HWND window, struct IWineD3DDeviceImpl *device) DECLSPEC_HIDDEN;
diff --git a/include/wine/wined3d.idl b/include/wine/wined3d.idl
index 6d20f89..b3b5238 100644
--- a/include/wine/wined3d.idl
+++ b/include/wine/wined3d.idl
@@ -2110,6 +2110,7 @@ interface IWineD3DSurface;
 interface IWineD3DVolume;
 interface IWineD3DSwapChain;
 interface IWineD3DDevice;
+struct wined3d;
 struct wined3d_stateblock;
 
 [
@@ -2189,92 +2190,6 @@ interface IWineD3DBase : IUnknown
 [
     object,
     local,
-    uuid(108f9c44-6f30-11d9-c687-00046142c14f)
-]
-interface IWineD3D : IWineD3DBase
-{
-    UINT GetAdapterCount(
-    );
-    HRESULT RegisterSoftwareDevice(
-        [in] void *pInitializeFunction
-    );
-    HMONITOR GetAdapterMonitor(
-        [in] UINT adapter_idx
-    );
-    UINT GetAdapterModeCount(
-        [in] UINT adapter_idx,
-        [in] enum wined3d_format_id format_id
-    );
-    HRESULT EnumAdapterModes(
-        [in] UINT adapter_idx,
-        [in] enum wined3d_format_id format_id,
-        [in] UINT mode_idx,
-        [out] WINED3DDISPLAYMODE *mode
-    );
-    HRESULT GetAdapterDisplayMode(
-        [in] UINT adapter_idx,
-        [out] WINED3DDISPLAYMODE *mode
-    );
-    HRESULT GetAdapterIdentifier(
-        [in] UINT adapter_idx,
-        [in] DWORD flags,
-        [out] WINED3DADAPTER_IDENTIFIER *identifier
-    );
-    HRESULT CheckDeviceMultiSampleType(
-        [in] UINT adapter_idx,
-        [in] WINED3DDEVTYPE device_type,
-        [in] enum wined3d_format_id surface_format_id,
-        [in] BOOL windowed,
-        [in] WINED3DMULTISAMPLE_TYPE multisample_type,
-        [out] DWORD *quality_levels
-    );
-    HRESULT CheckDepthStencilMatch(
-        [in] UINT adapter_idx,
-        [in] WINED3DDEVTYPE device_type,
-        [in] enum wined3d_format_id adapter_format_id,
-        [in] enum wined3d_format_id render_target_format_id,
-        [in] enum wined3d_format_id depth_stencil_format_id
-    );
-    HRESULT CheckDeviceType(
-        [in] UINT adapter_idx,
-        [in] WINED3DDEVTYPE device_type,
-        [in] enum wined3d_format_id display_format_id,
-        [in] enum wined3d_format_id backbuffer_format_id,
-        [in] BOOL windowed
-    );
-    HRESULT CheckDeviceFormat(
-        [in] UINT adaper_idx,
-        [in] WINED3DDEVTYPE device_type,
-        [in] enum wined3d_format_id adapter_format_id,
-        [in] DWORD usage,
-        [in] WINED3DRESOURCETYPE resource_type,
-        [in] enum wined3d_format_id check_format,
-        [in] WINED3DSURFTYPE surface_type
-    );
-    HRESULT CheckDeviceFormatConversion(
-        [in] UINT adapter_idx,
-        [in] WINED3DDEVTYPE device_type,
-        [in] enum wined3d_format_id source_format_id,
-        [in] enum wined3d_format_id target_format_id
-    );
-    HRESULT GetDeviceCaps(
-        [in] UINT adapter_idx,
-        [in] WINED3DDEVTYPE device_type,
-        [out] WINED3DCAPS *caps
-    );
-    HRESULT CreateDevice(
-        [in] UINT adapter_idx,
-        [in] WINED3DDEVTYPE device_type,
-        [in] HWND focus_window,
-        [in] DWORD behaviour_flags,
-        [in] IWineD3DDeviceParent *device_parent,
-        [out] IWineD3DDevice **device
-    );
-}
-
-[
-    object,
-    local,
     uuid(1f3bfb34-6f30-11d9-c687-00046142c14f)
 ]
 interface IWineD3DResource : IWineD3DBase
@@ -2926,7 +2841,7 @@ interface IWineD3DDevice : IUnknown
         [out] WINED3DCAPS *caps
     );
     HRESULT GetDirect3D(
-        [out] IWineD3D** d3d
+        [out] struct wined3d **d3d
     );
     HRESULT GetDisplayMode(
         [in] UINT swapchain_idx,
@@ -3349,11 +3264,48 @@ interface IWineD3DDevice : IUnknown
     );
 }
 
-IWineD3D * __stdcall WineDirect3DCreate(UINT dxVersion, void *parent);
 IWineD3DClipper * __stdcall WineDirect3DCreateClipper(void);
 void __stdcall wined3d_mutex_lock(void);
 void __stdcall wined3d_mutex_unlock(void);
 
+HRESULT __cdecl wined3d_check_depth_stencil_match(const struct wined3d *wined3d, UINT adapter_idx,
+        WINED3DDEVTYPE device_type, enum wined3d_format_id adapter_format_id,
+        enum wined3d_format_id render_target_format_id, enum wined3d_format_id depth_stencil_format_id);
+HRESULT __cdecl wined3d_check_device_format(const struct wined3d *wined3d, UINT adaper_idx,
+        WINED3DDEVTYPE device_type, enum wined3d_format_id adapter_format_id, DWORD usage,
+        WINED3DRESOURCETYPE resource_type, enum wined3d_format_id check_format_id,
+        WINED3DSURFTYPE surface_type);
+HRESULT __cdecl wined3d_check_device_format_conversion(const struct wined3d *wined3d, UINT adapter_idx,
+        WINED3DDEVTYPE device_type, enum wined3d_format_id source_format_id,
+        enum wined3d_format_id target_format_id);
+HRESULT __cdecl wined3d_check_device_multisample_type(const struct wined3d *wined3d, UINT adapter_idx,
+        WINED3DDEVTYPE device_type, enum wined3d_format_id surface_format_id, BOOL windowed,
+        WINED3DMULTISAMPLE_TYPE multisample_type, DWORD *quality_levels);
+HRESULT __cdecl wined3d_check_device_type(const struct wined3d *wined3d, UINT adapter_idx,
+        WINED3DDEVTYPE device_type, enum wined3d_format_id display_format_id,
+        enum wined3d_format_id backbuffer_format_id, BOOL windowed);
+struct wined3d * __cdecl wined3d_create(UINT dxVersion, void *parent);
+ULONG __cdecl wined3d_decref(struct wined3d *wined3d);
+HRESULT __cdecl wined3d_enum_adapter_modes(const struct wined3d *wined3d, UINT adapter_idx,
+        enum wined3d_format_id format_id, UINT mode_idx, WINED3DDISPLAYMODE *mode);
+UINT __cdecl wined3d_get_adapter_count(const struct wined3d *wined3d);
+HRESULT __cdecl wined3d_get_adapter_display_mode(const struct wined3d *wined3d, UINT adapter_idx,
+        WINED3DDISPLAYMODE *mode);
+HRESULT __cdecl wined3d_get_adapter_identifier(const struct wined3d *wined3d, UINT adapter_idx,
+        DWORD flags, WINED3DADAPTER_IDENTIFIER *identifier);
+UINT __cdecl wined3d_get_adapter_mode_count(const struct wined3d *wined3d,
+        UINT adapter_idx, enum wined3d_format_id format_id);
+HMONITOR __cdecl wined3d_get_adapter_monitor(const struct wined3d *wined3d, UINT adapter_idx);
+HRESULT __cdecl wined3d_get_device_caps(const struct wined3d *wined3d, UINT adapter_idx,
+        WINED3DDEVTYPE device_type, WINED3DCAPS *caps);
+void * __cdecl wined3d_get_parent(const struct wined3d *wined3d);
+ULONG __cdecl wined3d_incref(struct wined3d *wined3d);
+HRESULT __cdecl wined3d_register_software_device(struct wined3d *wined3d, void *init_function);
+
+HRESULT __cdecl wined3d_device_create(struct wined3d *wined3d, UINT adapter_idx,
+        WINED3DDEVTYPE device_type, HWND focus_window, DWORD behaviour_flags,
+        IWineD3DDeviceParent *device_parent, IWineD3DDevice **device);
+
 HRESULT __cdecl wined3d_stateblock_apply(const struct wined3d_stateblock *stateblock);
 HRESULT __cdecl wined3d_stateblock_capture(struct wined3d_stateblock *stateblock);
 ULONG __cdecl wined3d_stateblock_decref(struct wined3d_stateblock *stateblock);
diff --git a/include/wine/winedxgi.idl b/include/wine/winedxgi.idl
index e54ce73..e9b2e51 100644
--- a/include/wine/winedxgi.idl
+++ b/include/wine/winedxgi.idl
@@ -25,7 +25,7 @@ import "dxgi.idl";
 ]
 interface IWineDXGIFactory : IDXGIFactory
 {
-    struct IWineD3D *get_wined3d();
+    struct wined3d *get_wined3d();
 }
 
 [
-- 
1.7.3.4




More information about the wine-patches mailing list