[PATCH 4/6] d3d8: Add a separate function for surface initialization.

Henri Verbeet hverbeet at codeweavers.com
Fri Sep 11 12:01:17 CDT 2009


---
 dlls/d3d8/d3d8_private.h |    9 +++----
 dlls/d3d8/device.c       |   53 ++++++++++++++-------------------------------
 dlls/d3d8/surface.c      |   35 +++++++++++++++++++++++++++++-
 3 files changed, 55 insertions(+), 42 deletions(-)

diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h
index 52abb84..ba58cc3 100644
--- a/dlls/d3d8/d3d8_private.h
+++ b/dlls/d3d8/d3d8_private.h
@@ -265,11 +265,6 @@ struct IDirect3DSwapChain8Impl
 /* ----------------- */
 
 /*****************************************************************************
- * Predeclare the interface implementation structures
- */
-extern const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl;
-
-/*****************************************************************************
  * IDirect3DSurface8 implementation structure
  */
 struct IDirect3DSurface8Impl
@@ -294,6 +289,10 @@ struct IDirect3DSurface8Impl
     BOOL                        isImplicit;
 };
 
+HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *device,
+        UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
+        DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality);
+
 /* ------------------ */
 /* IDirect3DResource8 */
 /* ------------------ */
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index 30195c6..76cfe88 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -858,51 +858,32 @@ static HRESULT IDirect3DDevice8Impl_CreateSurface(LPDIRECT3DDEVICE8 iface, UINT
         D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface8 **ppSurface,
         UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
 {
-    HRESULT hrc;
+    IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
     IDirect3DSurface8Impl *object;
-    IDirect3DDevice8Impl  *This = (IDirect3DDevice8Impl *)iface;
-    TRACE("(%p) Relay\n", This);
+    HRESULT hr;
 
-    if(MultisampleQuality > 0){
-        FIXME("MultisampleQuality set to %d, substituting 0\n" , MultisampleQuality);
-        /*
-        MultisampleQuality
-        [in] Quality level. The valid range is between zero and one less than the level returned by pQualityLevels used by IDirect3D8::CheckDeviceMultiSampleType. Passing a larger value returns the error D3DERR_INVALIDCALL. The MultisampleQuality values of paired render targets, depth stencil surfaces, and the MultiSample type must all match.
-        */
-        MultisampleQuality=0;
-    }
-    /*FIXME: Check MAX bounds of MultisampleQuality*/
+    TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
 
-    /* Allocate the storage for the device */
     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface8Impl));
-    if (NULL == object) {
-        FIXME("Allocation of memory failed\n");
-        *ppSurface = NULL;
+    if (!object)
+    {
+        FIXME("Failed to allocate surface memory.\n");
         return D3DERR_OUTOFVIDEOMEMORY;
     }
 
-    object->lpVtbl = &Direct3DSurface8_Vtbl;
-    object->ref = 1;
-
-    TRACE("(%p) : w(%d) h(%d) fmt(%d) surf@%p\n", This, Width, Height, Format, *ppSurface);
-
-    wined3d_mutex_lock();
-    hrc = IWineD3DDevice_CreateSurface(This->WineD3DDevice, Width, Height, wined3dformat_from_d3dformat(Format),
-            Lockable, Discard, Level, &object->wineD3DSurface, Usage & WINED3DUSAGE_MASK, (WINED3DPOOL)Pool,
-            MultiSample, MultisampleQuality, SURFACE_OPENGL, (IUnknown *)object);
-    wined3d_mutex_unlock();
-
-    if (hrc != D3D_OK || NULL == object->wineD3DSurface) {
-       /* free up object */
-        FIXME("(%p) call to IWineD3DDevice_CreateSurface failed\n", This);
+    hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
+            Level, Usage, Pool, MultiSample, MultisampleQuality);
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize surface, hr %#x.\n", hr);
         HeapFree(GetProcessHeap(), 0, object);
-        *ppSurface = NULL;
-    } else {
-        IUnknown_AddRef(iface);
-        object->parentDevice = iface;
-        *ppSurface = (LPDIRECT3DSURFACE8) object;
+        return hr;
     }
-    return hrc;
+
+    TRACE("Created surface %p.\n", object);
+    *ppSurface = (IDirect3DSurface8 *)object;
+
+    return D3D_OK;
 }
 
 static HRESULT WINAPI IDirect3DDevice8Impl_CreateRenderTarget(LPDIRECT3DDEVICE8 iface, UINT Width, UINT Height, D3DFORMAT Format, D3DMULTISAMPLE_TYPE MultiSample, BOOL Lockable, IDirect3DSurface8** ppSurface) {
diff --git a/dlls/d3d8/surface.c b/dlls/d3d8/surface.c
index 3185a1f..4cbe1c6 100644
--- a/dlls/d3d8/surface.c
+++ b/dlls/d3d8/surface.c
@@ -229,7 +229,7 @@ static HRESULT WINAPI IDirect3DSurface8Impl_UnlockRect(LPDIRECT3DSURFACE8 iface)
     }
 }
 
-const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl =
+static const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl =
 {
     /* IUnknown */
     IDirect3DSurface8Impl_QueryInterface,
@@ -246,3 +246,36 @@ const IDirect3DSurface8Vtbl Direct3DSurface8_Vtbl =
     IDirect3DSurface8Impl_LockRect,
     IDirect3DSurface8Impl_UnlockRect
 };
+
+HRESULT surface_init(IDirect3DSurface8Impl *surface, IDirect3DDevice8Impl *device,
+        UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
+        DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality)
+{
+    HRESULT hr;
+
+    surface->lpVtbl = &Direct3DSurface8_Vtbl;
+    surface->ref = 1;
+
+    /* FIXME: Check MAX bounds of MultisampleQuality. */
+    if (multisample_quality > 0)
+    {
+        FIXME("Multisample quality set to %u, substituting 0.\n", multisample_quality);
+        multisample_quality = 0;
+    }
+
+    wined3d_mutex_lock();
+    hr = IWineD3DDevice_CreateSurface(device->WineD3DDevice, width, height, wined3dformat_from_d3dformat(format),
+            lockable, discard, level, &surface->wineD3DSurface, usage & WINED3DUSAGE_MASK, (WINED3DPOOL)pool,
+            multisample_type, multisample_quality, SURFACE_OPENGL, (IUnknown *)surface);
+    wined3d_mutex_unlock();
+    if (FAILED(hr))
+    {
+        WARN("Failed to create wined3d surface, hr %#x.\n", hr);
+        return hr;
+    }
+
+    surface->parentDevice = (IDirect3DDevice8 *)device;
+    IUnknown_AddRef(surface->parentDevice);
+
+    return D3D_OK;
+}
-- 
1.6.0.6




More information about the wine-patches mailing list