Index: /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp	(revision 30916)
@@ -1889,9 +1889,9 @@
     HRESULT hr = S_OK;
 
-#ifdef DEBUG_misha
-    uint32_t iBackBuf = (pDevice->iRenderTargetFrontBuf + 1) % pDevice->pRenderTargetRc->cAllocations;
-    vboxVDbgDumpSurfData((pDevice, ">>>DrawPrimitive:\n", pDevice->pRenderTargetRc, iBackBuf,
-            NULL, (IDirect3DSurface9*)pDevice->pRenderTargetRc->aAllocations[iBackBuf].pD3DIf, "\n"));
-#endif
+//#ifdef DEBUG_misha
+//    uint32_t iBackBuf = (pDevice->iRenderTargetFrontBuf + 1) % pDevice->pRenderTargetRc->cAllocations;
+//    vboxVDbgDumpSurfData((pDevice, ">>>DrawPrimitive:\n", pDevice->pRenderTargetRc, iBackBuf,
+//            NULL, (IDirect3DSurface9*)pDevice->pRenderTargetRc->aAllocations[iBackBuf].pD3DIf, "\n"));
+//#endif
 
     if (!pDevice->cStreamSources)
@@ -1911,5 +1911,5 @@
             Assert(hr == S_OK);
 
-            vboxVDbgMpPrint((pDevice, __FUNCTION__": DrawPrimitiveUP\n"));
+//            vboxVDbgMpPrint((pDevice, __FUNCTION__": DrawPrimitiveUP\n"));
         }
         else
@@ -1946,5 +1946,5 @@
         Assert(hr == S_OK);
 
-        vboxVDbgMpPrint((pDevice, __FUNCTION__": DrawPrimitive\n"));
+//        vboxVDbgMpPrint((pDevice, __FUNCTION__": DrawPrimitive\n"));
 #if 0
         IDirect3DVertexDeclaration9* pDecl;
@@ -2156,9 +2156,9 @@
     }
 
-#ifdef DEBUG_misha
-    iBackBuf = (pDevice->iRenderTargetFrontBuf + 1) % pDevice->pRenderTargetRc->cAllocations;
-    vboxVDbgDumpSurfData((pDevice, "<<<DrawPrimitive:\n", pDevice->pRenderTargetRc, iBackBuf,
-            NULL, (IDirect3DSurface9*)pDevice->pRenderTargetRc->aAllocations[iBackBuf].pD3DIf, "\n"));
-#endif
+//#ifdef DEBUG_misha
+//    iBackBuf = (pDevice->iRenderTargetFrontBuf + 1) % pDevice->pRenderTargetRc->cAllocations;
+//    vboxVDbgDumpSurfData((pDevice, "<<<DrawPrimitive:\n", pDevice->pRenderTargetRc, iBackBuf,
+//            NULL, (IDirect3DSurface9*)pDevice->pRenderTargetRc->aAllocations[iBackBuf].pD3DIf, "\n"));
+//#endif
 
     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p), hr(0x%x)\n", hDevice, hr));
@@ -2172,9 +2172,9 @@
     Assert(pDevice);
     Assert(pDevice->pDevice9If);
-#ifdef DEBUG_misha
-    uint32_t iBackBuf = (pDevice->iRenderTargetFrontBuf + 1) % pDevice->pRenderTargetRc->cAllocations;
-    vboxVDbgDumpSurfData((pDevice, ">>>DrawIndexedPrimitive:\n", pDevice->pRenderTargetRc, iBackBuf,
-            NULL, (IDirect3DSurface9*)pDevice->pRenderTargetRc->aAllocations[iBackBuf].pD3DIf, "\n"));
-#endif
+//#ifdef DEBUG_misha
+//    uint32_t iBackBuf = (pDevice->iRenderTargetFrontBuf + 1) % pDevice->pRenderTargetRc->cAllocations;
+//    vboxVDbgDumpSurfData((pDevice, ">>>DrawIndexedPrimitive:\n", pDevice->pRenderTargetRc, iBackBuf,
+//            NULL, (IDirect3DSurface9*)pDevice->pRenderTargetRc->aAllocations[iBackBuf].pD3DIf, "\n"));
+//#endif
 
 #ifdef DEBUG
@@ -2210,9 +2210,9 @@
     Assert(hr == S_OK);
 
-#ifdef DEBUG_misha
-    iBackBuf = (pDevice->iRenderTargetFrontBuf + 1) % pDevice->pRenderTargetRc->cAllocations;
-    vboxVDbgDumpSurfData((pDevice, "<<<DrawIndexedPrimitive:\n", pDevice->pRenderTargetRc, iBackBuf,
-            NULL, (IDirect3DSurface9*)pDevice->pRenderTargetRc->aAllocations[iBackBuf].pD3DIf, "\n"));
-#endif
+//#ifdef DEBUG_misha
+//    iBackBuf = (pDevice->iRenderTargetFrontBuf + 1) % pDevice->pRenderTargetRc->cAllocations;
+//    vboxVDbgDumpSurfData((pDevice, "<<<DrawIndexedPrimitive:\n", pDevice->pRenderTargetRc, iBackBuf,
+//            NULL, (IDirect3DSurface9*)pDevice->pRenderTargetRc->aAllocations[iBackBuf].pD3DIf, "\n"));
+//#endif
 
 
@@ -2274,9 +2274,9 @@
     hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType, pData->FirstVertexOffset, pData->PrimitiveCount);
 #else
-#ifdef DEBUG_misha
-    uint32_t iBackBuf = (pDevice->iRenderTargetFrontBuf + 1) % pDevice->pRenderTargetRc->cAllocations;
-    vboxVDbgDumpSurfData((pDevice, ">>>DrawPrimitive2:\n", pDevice->pRenderTargetRc, iBackBuf,
-            NULL, (IDirect3DSurface9*)pDevice->pRenderTargetRc->aAllocations[iBackBuf].pD3DIf, "\n"));
-#endif
+//#ifdef DEBUG_misha
+//    uint32_t iBackBuf = (pDevice->iRenderTargetFrontBuf + 1) % pDevice->pRenderTargetRc->cAllocations;
+//    vboxVDbgDumpSurfData((pDevice, ">>>DrawPrimitive2:\n", pDevice->pRenderTargetRc, iBackBuf,
+//            NULL, (IDirect3DSurface9*)pDevice->pRenderTargetRc->aAllocations[iBackBuf].pD3DIf, "\n"));
+//#endif
 
 #ifdef DEBUG
@@ -2298,5 +2298,5 @@
             if (pDevice->aStreamSource[stream]->LockInfo.cLocks)
             {
-                vboxVDbgMpPrint((pDevice, __FUNCTION__": DrawPrimitiveUP\n"));
+//                vboxVDbgMpPrint((pDevice, __FUNCTION__": DrawPrimitiveUP\n"));
 
                 Assert(pLock->fFlags.MightDrawFromLocked && (pLock->fFlags.Discard || pLock->fFlags.NoOverwrite));
@@ -2310,5 +2310,5 @@
             else
             {
-                vboxVDbgMpPrint((pDevice, __FUNCTION__": DrawPrimitive\n"));
+//                vboxVDbgMpPrint((pDevice, __FUNCTION__": DrawPrimitive\n"));
 
                 hr = pDevice->pDevice9If->DrawPrimitive(pData->PrimitiveType, pData->FirstVertexOffset/pDevice->StreamSourceInfo[stream].uiStride, pData->PrimitiveCount);
@@ -2324,9 +2324,9 @@
 #endif
 
-#ifdef DEBUG_misha
-    iBackBuf = (pDevice->iRenderTargetFrontBuf + 1) % pDevice->pRenderTargetRc->cAllocations;
-    vboxVDbgDumpSurfData((pDevice, "<<<DrawPrimitive2:\n", pDevice->pRenderTargetRc, iBackBuf,
-            NULL, (IDirect3DSurface9*)pDevice->pRenderTargetRc->aAllocations[iBackBuf].pD3DIf, "\n"));
-#endif
+//#ifdef DEBUG_misha
+//    iBackBuf = (pDevice->iRenderTargetFrontBuf + 1) % pDevice->pRenderTargetRc->cAllocations;
+//    vboxVDbgDumpSurfData((pDevice, "<<<DrawPrimitive2:\n", pDevice->pRenderTargetRc, iBackBuf,
+//            NULL, (IDirect3DSurface9*)pDevice->pRenderTargetRc->aAllocations[iBackBuf].pD3DIf, "\n"));
+//#endif
 
     Assert(hr == S_OK);
@@ -2679,7 +2679,8 @@
                     Assert(pLockAlloc->pvMem);
                     Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);
-
+#if 0
                     if (bNeedResynch)
                         vboxWddmLockUnlockMemSynch(pLockAlloc, &pLockAlloc->LockInfo.LockedRect, pRect, false /*bool bToLockInfo*/);
+#endif
                 }
             }
@@ -2983,4 +2984,5 @@
                 Assert(pD3DIfTex);
                 /* this is a sysmem texture, update  */
+#if 0
                 if (pLockAlloc->pvMem && !pLockAlloc->LockInfo.fFlags.ReadOnly)
                 {
@@ -2989,4 +2991,5 @@
                             true /*bool bToLockInfo*/);
                 }
+#endif
                 hr = pD3DIfTex->UnlockRect(pData->SubResourceIndex);
                 Assert(hr == S_OK);
@@ -3407,4 +3410,5 @@
                 CONST D3DDDI_SURFACEINFO* pSurf = &pResource->pSurfList[0];
                 IDirect3DTexture9 *pD3DIfTex;
+#if 0
                 hr = pDevice->pDevice9If->CreateTexture(pSurf->Width,
                                             pSurf->Height,
@@ -3416,4 +3420,16 @@
                                             NULL /* HANDLE* pSharedHandle */
                                             );
+#else
+                hr = pDevice->pAdapter->D3D.pfnVBoxWineExD3DDev9CreateTexture((IDirect3DDevice9Ex *)pDevice->pDevice9If,
+                                            pSurf->Width,
+                                            pSurf->Height,
+                                            pResource->SurfCount,
+                                            vboxDDI2D3DUsage(pResource->Flags),
+                                            vboxDDI2D3DFormat(pResource->Format),
+                                            vboxDDI2D3DPool(pResource->Pool),
+                                            &pD3DIfTex,
+                                            NULL /* HANDLE* pSharedHandle */,
+                                            pResource->Pool == D3DDDIPOOL_SYSTEMMEM ? pRc->aAllocations[0].pvMem : NULL);
+#endif
                 Assert(hr == S_OK);
                 if (hr == S_OK)
@@ -3422,4 +3438,5 @@
                     pAllocation->enmD3DIfType = VBOXDISP_D3DIFTYPE_TEXTURE;
                     pAllocation->pD3DIf = pD3DIfTex;
+#if 0
                     if (pResource->Pool == D3DDDIPOOL_SYSTEMMEM)
                     {
@@ -3444,4 +3461,5 @@
                         }
                     }
+#endif
                 }
 #ifdef DEBUG
@@ -4209,7 +4227,4 @@
     Assert(pDstRc->cAllocations > pData->DstSubResourceIndex);
     Assert(pSrcRc->cAllocations > pData->SrcSubResourceIndex);
-//    Assert(pSrcRc->RcDesc.enmPool != D3DDDIPOOL_SYSTEMMEM);
-    /* @todo: use UpdateRect in case of Src is a D3DDDIPOOL_SYSTEMMEM */
-    Assert(pDstRc->RcDesc.enmPool != D3DDDIPOOL_SYSTEMMEM);
     Assert(pDstRc != pDevice->pRenderTargetRc || pDevice->iRenderTargetFrontBuf != pData->DstSubResourceIndex);
     HRESULT hr = S_OK;
@@ -4284,9 +4299,41 @@
             {
                 Assert(pSrcSurfIf);
-
-//#ifdef DEBUG_misha
-//                vboxVDbgDumpSurfData((pDevice, "Blt-pre Src:\n", pSrcRc, pData->SrcSubResourceIndex, &pData->SrcRect, pSrcSurfIf, "\n"));
-//                vboxVDbgDumpSurfData((pDevice, "Blt-pre Dst:\n", pDstRc, pData->DstSubResourceIndex, &pData->DstRect, pDstSurfIf, "\n"));
-//#endif
+#ifdef DEBUG_misha
+                bool bDo = false;
+
+                if (g_VDbgTstDumpEnable)
+                {
+                    if (g_VDbgTstDumpOnSys2VidSameSizeEnable)
+                    {
+                        if (pDstRc->RcDesc.enmPool != D3DDDIPOOL_SYSTEMMEM
+                                && pSrcRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM)
+                        {
+                            D3DSURFACE_DESC SrcDesc;
+                            HRESULT hr = pSrcSurfIf->GetDesc(&SrcDesc);
+                            Assert(hr == S_OK);
+                            if (hr == S_OK)
+                            {
+                                D3DSURFACE_DESC DstDesc;
+                                hr = pDstSurfIf->GetDesc(&DstDesc);
+                                Assert(hr == S_OK);
+                                if (hr == S_OK)
+                                {
+                                    if (SrcDesc.Width == DstDesc.Width
+                                            && SrcDesc.Height == DstDesc.Height)
+                                    {
+                                        bDo = true;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+
+                if (bDo)
+                {
+                    vboxVDbgDumpSurfData((pDevice, "Blt-pre Src:\n", pSrcRc, pData->SrcSubResourceIndex, &pData->SrcRect, pSrcSurfIf, "\n"));
+                    vboxVDbgDumpSurfData((pDevice, "Blt-pre Dst:\n", pDstRc, pData->DstSubResourceIndex, &pData->DstRect, pDstSurfIf, "\n"));
+                }
+#endif
                 /* we support only Point & Linear, we ignore [Begin|Continue|End]PresentToDwm */
                 Assert((pData->Flags.Value & (~(0x00000100 | 0x00000200 | 0x00000400 | 0x00000001  | 0x00000002))) == 0);
@@ -4298,8 +4345,11 @@
                 Assert(hr == S_OK);
 
-//#ifdef DEBUG_misha
-//                vboxVDbgDumpSurfData((pDevice, "Blt-post Src:\n", pSrcRc, pData->SrcSubResourceIndex, &pData->SrcRect, pSrcSurfIf, "\n"));
-//                vboxVDbgDumpSurfData((pDevice, "Blt-post Dst:\n", pDstRc, pData->DstSubResourceIndex, &pData->DstRect, pDstSurfIf, "\n"));
-//#endif
+#ifdef DEBUG_misha
+                if (bDo)
+                {
+                    vboxVDbgDumpSurfData((pDevice, "Blt-post Src:\n", pSrcRc, pData->SrcSubResourceIndex, &pData->SrcRect, pSrcSurfIf, "\n"));
+                    vboxVDbgDumpSurfData((pDevice, "Blt-post Dst:\n", pDstRc, pData->DstSubResourceIndex, &pData->DstRect, pDstSurfIf, "\n"));
+                }
+#endif
                 pSrcSurfIf->Release();
             }
@@ -5369,4 +5419,8 @@
 
 #ifdef VBOXWDDMDISP_DEBUG
+
+bool g_VDbgTstDumpEnable = false;
+bool g_VDbgTstDumpOnSys2VidSameSizeEnable = false;
+
 VOID vboxVDbgDoDumpSurfData(const PVBOXWDDMDISP_DEVICE pDevice, const char * pPrefix, const PVBOXWDDMDISP_RESOURCE pRc, uint32_t iAlloc, const RECT *pRect, IDirect3DSurface9 *pSurf, const char* pSuffix)
 {
@@ -5411,4 +5465,28 @@
     {
         vboxVDbgMpPrint((pDevice, "%s\n", pSuffix));
+    }
+}
+
+VOID vboxVDbgDoDumpSurfDataBySurf(const PVBOXWDDMDISP_DEVICE pDevice, IDirect3DSurface9 *pSurf)
+{
+    D3DSURFACE_DESC Desc;
+    HRESULT hr = pSurf->GetDesc(&Desc);
+    Assert(hr == S_OK);
+    if (hr == S_OK)
+    {
+        D3DLOCKED_RECT Lr;
+        hr = pSurf->LockRect(&Lr, NULL, D3DLOCK_READONLY);
+        Assert(hr == S_OK);
+        if (hr == S_OK)
+        {
+            UINT bpp = vboxWddmCalcBitsPerPixel((D3DDDIFORMAT)Desc.Format);
+            vboxVDbgMpPrint((pDevice, "<?dml?><exec cmd=\"!vbvdbg.ms 0x%p 0n%d 0n%d 0n%d 0n%d\">surface info</exec>\n",
+                    Lr.pBits, Desc.Width, Desc.Height, bpp, Lr.Pitch));
+
+            Assert(0);
+
+            hr = pSurf->UnlockRect();
+            Assert(hr == S_OK);
+        }
     }
 }
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DCmn.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DCmn.h	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DCmn.h	(revision 30916)
@@ -38,5 +38,5 @@
 # define VBOXWDDMDISP_DEBUG
 # define VBOXWDDMDISP_DEBUG_FLOW
-//# define VBOXWDDMDISP_DEBUG_DUMPSURFDATA
+# define VBOXWDDMDISP_DEBUG_DUMPSURFDATA
 #endif
 
@@ -57,4 +57,7 @@
 
 #ifdef VBOXWDDMDISP_DEBUG
+extern bool g_VDbgTstDumpEnable;
+extern bool g_VDbgTstDumpOnSys2VidSameSizeEnable;
+
 VOID vboxVDbgDoDumpSurfData(const PVBOXWDDMDISP_DEVICE pDevice, const char * pPrefix, const PVBOXWDDMDISP_RESOURCE pRc, uint32_t iAlloc, const RECT *pRect, IDirect3DSurface9 *pSurf, const char* pSuffix);
 void vboxVDbgDoMpPrintRect(const PVBOXWDDMDISP_DEVICE pDevice, const char * pPrefix, const RECT *pRect, const char * pSuffix);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DIf.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DIf.cpp	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DIf.cpp	(revision 30916)
@@ -34,5 +34,12 @@
         Assert(pD3D->pfnDirect3DCreate9Ex);
         if (pD3D->pfnDirect3DCreate9Ex)
-            return S_OK;
+        {
+            pD3D->pfnVBoxWineExD3DDev9CreateTexture = (PFNVBOXWINEEXD3DDEV9_CREATETEXTURE)GetProcAddress(pD3D->hD3DLib, "VBoxWineExD3DDev9CreateTexture");
+            Assert(pD3D->pfnVBoxWineExD3DDev9CreateTexture);
+            if (pD3D->pfnVBoxWineExD3DDev9CreateTexture)
+            {
+                return S_OK;
+            }
+        }
         else
         {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DIf.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DIf.h	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3DIf.h	(revision 30916)
@@ -22,4 +22,6 @@
 #include <D3D9.h>
 
+#include "../../Wine/vbox/VBoxWineEx.h"
+
 /* D3D functionality the VBOXDISPD3D provides */
 typedef HRESULT WINAPI FNVBOXDISPD3DCREATE9EX(UINT SDKVersion, IDirect3D9Ex **ppD3D);
@@ -30,4 +32,6 @@
     /* D3D functionality the VBOXDISPD3D provides */
     PFNVBOXDISPD3DCREATE9EX pfnDirect3DCreate9Ex;
+
+    PFNVBOXWINEEXD3DDEV9_CREATETEXTURE pfnVBoxWineExD3DDev9CreateTexture;
 
     /* module handle */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/Makefile.kmk	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/Makefile.kmk	(revision 30916)
@@ -186,4 +186,7 @@
  VBoxD3D8_DEFS       += WINE_NO_DEBUG_MSGS
 endif
+#ifdef VBOXWDDM
+# VBoxD3D8_DEFS        += VBOXWDDM IN_VBOXWINEEX 
+#endif
 VBoxD3D8_INCS         := $(PATH_SUB_CURRENT)/include
 VBoxD3D8_SOURCES      := \
@@ -206,5 +209,4 @@
     $(PATH_LIB)/libWine$(VBOX_SUFF_LIB) \
     $(PATH_LIB)/wined3d$(VBOX_SUFF_LIB)
-
 DLLS += VBoxD3D9
 
@@ -220,4 +222,7 @@
 ifneq ($(KBUILD_TYPE),debug)
  VBoxD3D9_DEFS       += WINE_NO_DEBUG_MSGS
+endif
+ifdef VBOXWDDM
+ VBoxD3D9_DEFS        += VBOXWDDM IN_VBOXWINEEX 
 endif
 VBoxD3D9_INCS         := $(PATH_SUB_CURRENT)/include
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9.def
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9.def	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9.def	(revision 30916)
@@ -15,2 +15,3 @@
   Direct3DCreate9@4=Direct3DCreate9
   Direct3DCreate9Ex@8=Direct3DCreate9Ex
+  VBoxWineExD3DDev9CreateTexture
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_private.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_private.h	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/d3d9_private.h	(revision 30916)
@@ -47,4 +47,8 @@
 #include "d3d9.h"
 #include "wine/wined3d.h"
+
+#ifdef VBOXWDDM
+#include "../vbox/VBoxWineEx.h"
+#endif
 
 /* ===========================================================================
@@ -316,5 +320,10 @@
 HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *device,
         UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
-        DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality) DECLSPEC_HIDDEN;
+        DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        ) DECLSPEC_HIDDEN;
 
 /* ---------------------- */
@@ -428,5 +437,10 @@
 
 HRESULT texture_init(IDirect3DTexture9Impl *texture, IDirect3DDevice9Impl *device,
-        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool) DECLSPEC_HIDDEN;
+        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        ) DECLSPEC_HIDDEN;
 
 /* ----------------------- */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/device.c	(revision 30916)
@@ -713,8 +713,53 @@
 }
 
+#ifdef VBOXWDDM
+VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9CreateTexture(IDirect3DDevice9Ex *iface,
+        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
+        D3DPOOL pool, IDirect3DTexture9 **texture, HANDLE *shared_handle,
+        void *pvClientMem) /* <- extension arg to pass in the client memory buffer,
+                            *    applicable ONLY for SYSMEM textures */
+{
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IDirect3DTexture9Impl *object;
+    HRESULT hr;
+
+    TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
+            iface, width, height, levels, usage, format, pool, texture, shared_handle);
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
+    if (!object)
+    {
+        ERR("Failed to allocate texture memory.\n");
+        return D3DERR_OUTOFVIDEOMEMORY;
+    }
+
+    hr = texture_init(object, This, width, height, levels, usage, format, pool
+#ifdef VBOXWDDM
+        , shared_handle
+        , pvClientMem
+#endif
+            );
+    if (FAILED(hr))
+    {
+        WARN("Failed to initialize texture, hr %#x.\n", hr);
+        HeapFree(GetProcessHeap(), 0, object);
+        return hr;
+    }
+
+    TRACE("Created texture %p.\n", object);
+    *texture = (IDirect3DTexture9 *)object;
+
+    return D3D_OK;
+}
+#endif
+
 static HRESULT WINAPI IDirect3DDevice9Impl_CreateTexture(IDirect3DDevice9Ex *iface,
         UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
         D3DPOOL pool, IDirect3DTexture9 **texture, HANDLE *shared_handle)
 {
+#ifdef VBOXWDDM
+    return VBoxWineExD3DDev9CreateTexture(iface, width, height, levels, usage, format,
+            pool, texture, shared_handle, NULL);
+#else
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
     IDirect3DTexture9Impl *object;
@@ -743,4 +788,5 @@
 
     return D3D_OK;
+#endif
 }
 
@@ -873,7 +919,11 @@
 }
 
-static HRESULT IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
+#ifdef VBOXWDDM
+HRESULT VBoxWineExD3DDev9CreateSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
         D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface9 **ppSurface,
-        UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
+        UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality
+        , HANDLE *shared_handle
+        , void *pvClientMem
+        )
 {
     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
@@ -894,5 +944,6 @@
 
     hr = surface_init(object, This, Width, Height, Format, Lockable, Discard,
-            Level, Usage, Pool, MultiSample, MultisampleQuality);
+            Level, Usage, Pool, MultiSample, MultisampleQuality,
+            shared_handle, pvClientMem);
     if (FAILED(hr))
     {
@@ -906,4 +957,44 @@
 
     return D3D_OK;
+}
+#endif
+static HRESULT IDirect3DDevice9Impl_CreateSurface(LPDIRECT3DDEVICE9EX iface, UINT Width, UINT Height,
+        D3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IDirect3DSurface9 **ppSurface,
+        UINT Usage, D3DPOOL Pool, D3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality)
+{
+#ifdef VBOXWDDM
+    return VBoxWineExD3DDev9CreateSurface(iface, Width, Height, Format, Lockable, Discard, Level, ppSurface,
+            Usage, Pool, MultiSample, MultisampleQuality, NULL, NULL);
+#else
+    IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
+    IDirect3DSurface9Impl *object;
+    HRESULT hr;
+
+    TRACE("iface %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p.\n"
+            "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
+            iface, Width, Height, Format, Lockable, Discard, Level, ppSurface,
+            Usage, Pool, MultiSample, MultisampleQuality);
+
+    object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DSurface9Impl));
+    if (!object)
+    {
+        FIXME("Failed to allocate surface memory.\n");
+        return D3DERR_OUTOFVIDEOMEMORY;
+    }
+
+    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);
+        return hr;
+    }
+
+    TRACE("Created surface %p.\n", object);
+    *ppSurface = (IDirect3DSurface9 *)object;
+
+    return D3D_OK;
+#endif
 }
 
@@ -2630,5 +2721,10 @@
 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
         IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
-        WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
+        WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        )
 {
     struct IDirect3DDevice9Impl *This = device_from_device_parent(iface);
@@ -2644,7 +2740,18 @@
         lockable = FALSE;
 
+#ifdef VBOXWDDM
+    hr = VBoxWineExD3DDev9CreateSurface((IDirect3DDevice9Ex *)This, width, height,
+            d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
+            (IDirect3DSurface9 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */
+            , shared_handle
+            , pvClientMem
+            );
+
+#else
     hr = IDirect3DDevice9Impl_CreateSurface((IDirect3DDevice9Ex *)This, width, height,
             d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
-            (IDirect3DSurface9 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
+            (IDirect3DSurface9 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */
+            );
+#endif
     if (FAILED(hr))
     {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/surface.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/surface.c	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/surface.c	(revision 30916)
@@ -381,5 +381,10 @@
 HRESULT surface_init(IDirect3DSurface9Impl *surface, IDirect3DDevice9Impl *device,
         UINT width, UINT height, D3DFORMAT format, BOOL lockable, BOOL discard, UINT level,
-        DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality)
+        DWORD usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        )
 {
     HRESULT hr;
@@ -412,8 +417,18 @@
 
     wined3d_mutex_lock();
+#ifdef VBOXWDDM
+    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,
+            &d3d9_surface_wined3d_parent_ops
+            , shared_handle
+            , pvClientMem
+            );
+#else
     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,
             &d3d9_surface_wined3d_parent_ops);
+#endif
     wined3d_mutex_unlock();
     if (FAILED(hr))
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/texture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/texture.c	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/d3d9/texture.c	(revision 30916)
@@ -398,5 +398,10 @@
 
 HRESULT texture_init(IDirect3DTexture9Impl *texture, IDirect3DDevice9Impl *device,
-        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool)
+        UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        )
 {
     HRESULT hr;
@@ -406,7 +411,16 @@
 
     wined3d_mutex_lock();
+#ifdef VBOXWDDM
+    hr = IWineD3DDevice_CreateTexture(device->WineD3DDevice, width, height, levels,
+            usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
+            &texture->wineD3DTexture, (IUnknown *)texture, &d3d9_texture_wined3d_parent_ops
+            , shared_handle
+            , pvClientMem);
+#else
     hr = IWineD3DDevice_CreateTexture(device->WineD3DDevice, width, height, levels,
             usage & WINED3DUSAGE_MASK, wined3dformat_from_d3dformat(format), pool,
             &texture->wineD3DTexture, (IUnknown *)texture, &d3d9_texture_wined3d_parent_ops);
+#endif
+
     wined3d_mutex_unlock();
     if (FAILED(hr))
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.h	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/include/wine/wined3d.h	(revision 30916)
@@ -2689,5 +2689,10 @@
         UINT level,
         WINED3DCUBEMAP_FACES face,
-        IWineD3DSurface **surface);
+        IWineD3DSurface **surface
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        );
 
     HRESULT (STDMETHODCALLTYPE *CreateRenderTarget)(
@@ -2742,5 +2747,9 @@
 /*** IWineD3DDeviceParent methods ***/
 #define IWineD3DDeviceParent_WineD3DDeviceCreated(This,device) (This)->lpVtbl->WineD3DDeviceCreated(This,device)
+#ifdef VBOXWDDM
+#define IWineD3DDeviceParent_CreateSurface(This,superior,width,height,format,usage,pool,level,face,surface,shared_handle,pvClientMem) (This)->lpVtbl->CreateSurface(This,superior,width,height,format,usage,pool,level,face,surface,shared_handle,pvClientMem)
+#else
 #define IWineD3DDeviceParent_CreateSurface(This,superior,width,height,format,usage,pool,level,face,surface) (This)->lpVtbl->CreateSurface(This,superior,width,height,format,usage,pool,level,face,surface)
+#endif
 #define IWineD3DDeviceParent_CreateRenderTarget(This,superior,width,height,format,multisample_type,multisample_quality,lockable,surface) (This)->lpVtbl->CreateRenderTarget(This,superior,width,height,format,multisample_type,multisample_quality,lockable,surface)
 #define IWineD3DDeviceParent_CreateDepthStencilSurface(This,superior,width,height,format,multisample_type,multisample_quality,discard,surface) (This)->lpVtbl->CreateDepthStencilSurface(This,superior,width,height,format,multisample_type,multisample_quality,discard,surface)
@@ -7356,5 +7365,10 @@
         WINED3DSURFTYPE surface_type,
         IUnknown *parent,
-        const struct wined3d_parent_ops *parent_ops);
+        const struct wined3d_parent_ops *parent_ops
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        );
 
     HRESULT (STDMETHODCALLTYPE *CreateRendertargetView)(
@@ -7374,5 +7388,10 @@
         IWineD3DTexture **texture,
         IUnknown *parent,
-        const struct wined3d_parent_ops *parent_ops);
+        const struct wined3d_parent_ops *parent_ops
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        );
 
     HRESULT (STDMETHODCALLTYPE *CreateVolumeTexture)(
@@ -8054,7 +8073,15 @@
 #define IWineD3DDevice_CreateIndexBuffer(This,length,usage,pool,index_buffer,parent,parent_ops) (This)->lpVtbl->CreateIndexBuffer(This,length,usage,pool,index_buffer,parent,parent_ops)
 #define IWineD3DDevice_CreateStateBlock(This,type,stateblock,parent) (This)->lpVtbl->CreateStateBlock(This,type,stateblock,parent)
+#ifdef VBOXWDDM
+#define IWineD3DDevice_CreateSurface(This,width,height,format,lockable,discard,level,surface,usage,pool,multisample_type,multisample_quality,surface_type,parent,parent_ops,shared_handle,pvClientMem) (This)->lpVtbl->CreateSurface(This,width,height,format,lockable,discard,level,surface,usage,pool,multisample_type,multisample_quality,surface_type,parent,parent_ops,shared_handle,pvClientMem)
+#else
 #define IWineD3DDevice_CreateSurface(This,width,height,format,lockable,discard,level,surface,usage,pool,multisample_type,multisample_quality,surface_type,parent,parent_ops) (This)->lpVtbl->CreateSurface(This,width,height,format,lockable,discard,level,surface,usage,pool,multisample_type,multisample_quality,surface_type,parent,parent_ops)
+#endif
 #define IWineD3DDevice_CreateRendertargetView(This,resource,parent,rendertarget_view) (This)->lpVtbl->CreateRendertargetView(This,resource,parent,rendertarget_view)
+#ifdef VBOXWDDM
+#define IWineD3DDevice_CreateTexture(This,width,height,levels,usage,format,pool,texture,parent,parent_ops,shared_handle,pvClientMem) (This)->lpVtbl->CreateTexture(This,width,height,levels,usage,format,pool,texture,parent,parent_ops,shared_handle,pvClientMem)
+#else
 #define IWineD3DDevice_CreateTexture(This,width,height,levels,usage,format,pool,texture,parent,parent_ops) (This)->lpVtbl->CreateTexture(This,width,height,levels,usage,format,pool,texture,parent,parent_ops)
+#endif
 #define IWineD3DDevice_CreateVolumeTexture(This,width,height,depth,levels,usage,format,pool,texture,parent,parent_ops) (This)->lpVtbl->CreateVolumeTexture(This,width,height,depth,levels,usage,format,pool,texture,parent,parent_ops)
 #define IWineD3DDevice_CreateVolume(This,width,height,depth,usage,format,pool,volume,parent,parent_ops) (This)->lpVtbl->CreateVolume(This,width,height,depth,usage,format,pool,volume,parent,parent_ops)
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/basetexture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/basetexture.c	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/basetexture.c	(revision 30916)
@@ -44,5 +44,9 @@
 
     hr = resource_init((IWineD3DResource *)texture, resource_type, device,
-            size, usage, format_desc, pool, parent, parent_ops);
+            size, usage, format_desc, pool, parent, parent_ops
+#ifdef VBOXWDDM
+            , NULL, NULL /* <- no need this info here */
+#endif
+            );
     if (FAILED(hr))
     {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/buffer.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/buffer.c	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/buffer.c	(revision 30916)
@@ -1473,5 +1473,9 @@
 
     hr = resource_init((IWineD3DResource *)buffer, WINED3DRTYPE_BUFFER,
-            device, size, usage, format_desc, pool, parent, parent_ops);
+            device, size, usage, format_desc, pool, parent, parent_ops
+#ifdef VBOXWDDM
+            , NULL, NULL /* <- no need this info here so far */
+#endif
+            );
     if (FAILED(hr))
     {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/cubetexture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/cubetexture.c	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/cubetexture.c	(revision 30916)
@@ -535,6 +535,14 @@
             };
 
+#ifdef VBOXWDDM
             hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_w,
-                    format, usage, pool, i /* Level */, j, &texture->surfaces[j][i]);
+                    format, usage, pool, i /* Level */, j, &texture->surfaces[j][i]
+                    , NULL, NULL /* <- no need this info here */
+                );
+#else
+            hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_w,
+                    format, usage, pool, i /* Level */, j, &texture->surfaces[j][i]
+                );
+#endif
             if (FAILED(hr))
             {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/device.c	(revision 30916)
@@ -802,5 +802,10 @@
         WINED3DFORMAT Format, BOOL Lockable, BOOL Discard, UINT Level, IWineD3DSurface **ppSurface,
         DWORD Usage, WINED3DPOOL Pool, WINED3DMULTISAMPLE_TYPE MultiSample, DWORD MultisampleQuality,
-        WINED3DSURFTYPE Impl, IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+        WINED3DSURFTYPE Impl, IUnknown *parent, const struct wined3d_parent_ops *parent_ops
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        )
 {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
@@ -828,5 +833,10 @@
 
     hr = surface_init(object, Impl, This->surface_alignment, Width, Height, Level, Lockable,
-            Discard, MultiSample, MultisampleQuality, This, Usage, Format, Pool, parent, parent_ops);
+            Discard, MultiSample, MultisampleQuality, This, Usage, Format, Pool, parent, parent_ops
+#ifdef VBOXWDDM
+            , shared_handle
+            , pvClientMem
+#endif
+            );
     if (FAILED(hr))
     {
@@ -868,5 +878,10 @@
 static HRESULT WINAPI IWineD3DDeviceImpl_CreateTexture(IWineD3DDevice *iface,
         UINT Width, UINT Height, UINT Levels, DWORD Usage, WINED3DFORMAT Format, WINED3DPOOL Pool,
-        IWineD3DTexture **ppTexture, IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+        IWineD3DTexture **ppTexture, IUnknown *parent, const struct wined3d_parent_ops *parent_ops
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        )
 {
     IWineD3DDeviceImpl *This = (IWineD3DDeviceImpl *)iface;
@@ -886,5 +901,10 @@
     }
 
-    hr = texture_init(object, Width, Height, Levels, This, Usage, Format, Pool, parent, parent_ops);
+    hr = texture_init(object, Width, Height, Levels, This, Usage, Format, Pool, parent, parent_ops
+#ifdef VBOXWDDM
+            , shared_handle
+            , pvClientMem
+#endif
+            );
     if (FAILED(hr))
     {
@@ -1420,7 +1440,13 @@
     }
 
+#ifdef VBOXWDDM
+    hr = IWineD3DDevice_CreateSurface((IWineD3DDevice *)This, bm.bmWidth, bm.bmHeight, WINED3DFMT_B5G6R5_UNORM, TRUE,
+            FALSE, 0, &This->logo_surface, 0, WINED3DPOOL_DEFAULT, WINED3DMULTISAMPLE_NONE, 0, SURFACE_OPENGL,
+            NULL, &wined3d_null_parent_ops, NULL, NULL);
+#else
     hr = IWineD3DDevice_CreateSurface((IWineD3DDevice *)This, bm.bmWidth, bm.bmHeight, WINED3DFMT_B5G6R5_UNORM, TRUE,
             FALSE, 0, &This->logo_surface, 0, WINED3DPOOL_DEFAULT, WINED3DMULTISAMPLE_NONE, 0, SURFACE_OPENGL,
             NULL, &wined3d_null_parent_ops);
+#endif
     if(FAILED(hr)) {
         ERR("Wine logo requested, but failed to create surface\n");
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/resource.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/resource.c	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/resource.c	(revision 30916)
@@ -39,5 +39,10 @@
 HRESULT resource_init(IWineD3DResource *iface, WINED3DRESOURCETYPE resource_type,
         IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct wined3d_format_desc *format_desc,
-        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        )
 {
     struct IWineD3DResourceClass *resource = &((IWineD3DResourceImpl *)iface)->resource;
@@ -55,18 +60,28 @@
     list_init(&resource->privateData);
 
-    if (size)
-    {
-        resource->heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + RESOURCE_ALIGNMENT);
-        if (!resource->heapMemory)
-        {
-            ERR("Out of memory!\n");
-            return WINED3DERR_OUTOFVIDEOMEMORY;
-        }
+#ifdef VBOXWDDM
+    if (pool == WINED3DPOOL_SYSTEMMEM && pvClientMem)
+    {
+        resource->allocatedMemory = pvClientMem;
+        resource->heapMemory = NULL;
     }
     else
-    {
-        resource->heapMemory = NULL;
-    }
-    resource->allocatedMemory = (BYTE *)(((ULONG_PTR)resource->heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
+#endif
+    {
+        if (size)
+        {
+            resource->heapMemory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + RESOURCE_ALIGNMENT);
+            if (!resource->heapMemory)
+            {
+                ERR("Out of memory!\n");
+                return WINED3DERR_OUTOFVIDEOMEMORY;
+            }
+        }
+        else
+        {
+            resource->heapMemory = NULL;
+        }
+        resource->allocatedMemory = (BYTE *)(((ULONG_PTR)resource->heapMemory + (RESOURCE_ALIGNMENT - 1)) & ~(RESOURCE_ALIGNMENT - 1));
+    }
 
     /* Check that we have enough video ram left */
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface.c	(revision 30916)
@@ -356,5 +356,10 @@
         UINT width, UINT height, UINT level, BOOL lockable, BOOL discard, WINED3DMULTISAMPLE_TYPE multisample_type,
         UINT multisample_quality, IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format,
-        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        )
 {
     const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
@@ -393,5 +398,10 @@
 
     hr = resource_init((IWineD3DResource *)surface, WINED3DRTYPE_SURFACE,
-            device, resource_size, usage, format_desc, pool, parent, parent_ops);
+            device, resource_size, usage, format_desc, pool, parent, parent_ops
+#ifdef VBOXWDDM
+            , shared_handle
+            , pvClientMem
+#endif
+            );
     if (FAILED(hr))
     {
@@ -412,4 +422,7 @@
     /* Flags */
     surface->Flags = SFLAG_NORMCOORD; /* Default to normalized coords. */
+#ifdef VBOXWDDM
+    if (pool == WINED3DPOOL_SYSTEMMEM && pvClientMem)  surface->Flags |= SFLAG_CLIENTMEM;
+#endif
     if (discard) surface->Flags |= SFLAG_DISCARD;
     if (lockable || format == WINED3DFMT_D16_LOCKABLE) surface->Flags |= SFLAG_LOCKABLE;
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_base.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_base.c	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/surface_base.c	(revision 30916)
@@ -849,4 +849,11 @@
     }
 
+#ifdef VBOXWDDM
+    IWineD3DDevice_CreateSurface((IWineD3DDevice *)source->resource.device, source->currentDesc.Width,
+            source->currentDesc.Height, to_fmt, TRUE /* lockable */, TRUE /* discard  */, 0 /* level */, &ret,
+            0 /* usage */, WINED3DPOOL_SCRATCH, WINED3DMULTISAMPLE_NONE /* TODO: Multisampled conversion */,
+            0 /* MultiSampleQuality */, IWineD3DSurface_GetImplType((IWineD3DSurface *) source),
+            NULL /* parent */, &wined3d_null_parent_ops, NULL, NULL);
+#else
     IWineD3DDevice_CreateSurface((IWineD3DDevice *)source->resource.device, source->currentDesc.Width,
             source->currentDesc.Height, to_fmt, TRUE /* lockable */, TRUE /* discard  */, 0 /* level */, &ret,
@@ -854,4 +861,6 @@
             0 /* MultiSampleQuality */, IWineD3DSurface_GetImplType((IWineD3DSurface *) source),
             NULL /* parent */, &wined3d_null_parent_ops);
+#endif
+
     if(!ret) {
         ERR("Failed to create a destination surface for conversion\n");
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/texture.c	(revision 30916)
@@ -441,5 +441,10 @@
 HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
         IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
-        IUnknown *parent, const struct wined3d_parent_ops *parent_ops)
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        )
 {
     const struct wined3d_gl_info *gl_info = &device->adapter->gl_info;
@@ -577,7 +582,17 @@
     for (i = 0; i < texture->baseTexture.levels; ++i)
     {
+#ifdef VBOXWDDM
+        /* Use the callback to create the texture surface. */
+        hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format,
+                usage, pool, i, WINED3DCUBEMAP_FACE_POSITIVE_X, &texture->surfaces[i]
+                , shared_handle
+                , pvClientMem);
+
+#else
         /* Use the callback to create the texture surface. */
         hr = IWineD3DDeviceParent_CreateSurface(device->device_parent, parent, tmp_w, tmp_h, format_desc->format,
                 usage, pool, i, WINED3DCUBEMAP_FACE_POSITIVE_X, &texture->surfaces[i]);
+#endif
+
         if (FAILED(hr))
         {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volume.c
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volume.c	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/volume.c	(revision 30916)
@@ -408,5 +408,9 @@
 
     hr = resource_init((IWineD3DResource *)volume, WINED3DRTYPE_VOLUME, device,
-            width * height * depth * format_desc->byte_count, usage, format_desc, pool, parent, parent_ops);
+            width * height * depth * format_desc->byte_count, usage, format_desc, pool, parent, parent_ops
+#ifdef VBOXWDDM
+            , NULL, NULL
+#endif
+            );
     if (FAILED(hr))
     {
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h	(revision 30915)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Wine/wined3d/wined3d_private.h	(revision 30916)
@@ -1824,5 +1824,10 @@
 HRESULT resource_init(IWineD3DResource *iface, WINED3DRESOURCETYPE resource_type,
         IWineD3DDeviceImpl *device, UINT size, DWORD usage, const struct wined3d_format_desc *format_desc,
-        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
+        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        ) DECLSPEC_HIDDEN;
 WINED3DRESOURCETYPE resource_get_type(IWineD3DResource *iface) DECLSPEC_HIDDEN;
 DWORD resource_set_priority(IWineD3DResource *iface, DWORD new_priority) DECLSPEC_HIDDEN;
@@ -1942,5 +1947,10 @@
 HRESULT texture_init(IWineD3DTextureImpl *texture, UINT width, UINT height, UINT levels,
         IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format, WINED3DPOOL pool,
-        IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
+        IUnknown *parent, const struct wined3d_parent_ops *parent_ops
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        ) DECLSPEC_HIDDEN;
 
 /*****************************************************************************
@@ -2131,5 +2141,10 @@
         UINT width, UINT height, UINT level, BOOL lockable, BOOL discard, WINED3DMULTISAMPLE_TYPE multisample_type,
         UINT multisample_quality, IWineD3DDeviceImpl *device, DWORD usage, WINED3DFORMAT format,
-        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops) DECLSPEC_HIDDEN;
+        WINED3DPOOL pool, IUnknown *parent, const struct wined3d_parent_ops *parent_ops
+#ifdef VBOXWDDM
+        , HANDLE *shared_handle
+        , void *pvClientMem
+#endif
+        ) DECLSPEC_HIDDEN;
 
 /* Predeclare the shared Surface functions */
@@ -2213,4 +2228,12 @@
 #define SFLAG_SWAPCHAIN     0x01000000 /* The surface is part of a swapchain */
 
+#ifdef VBOXWDDM
+# define SFLAG_CLIENTMEM     0x10000000 /* SYSMEM surface using client-supplied memory buffer */
+
+# define SFLAG_DONOTFREE_VBOXWDDM SFLAG_CLIENTMEM
+#else
+# define SFLAG_DONOTFREE_VBOXWDDM 0
+#endif
+
 /* In some conditions the surface memory must not be freed:
  * SFLAG_CONVERTED: Converting the data back would take too long
@@ -2227,5 +2250,7 @@
                              SFLAG_USERPTR    | \
                              SFLAG_PBO        | \
-                             SFLAG_CLIENT)
+                             SFLAG_CLIENT     | \
+                             SFLAG_DONOTFREE_VBOXWDDM \
+                             )
 
 #define SFLAG_LOCATIONS     (SFLAG_INSYSMEM   | \
