Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp	(revision 34938)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/wddm/VBoxDispD3D.cpp	(revision 34939)
@@ -2137,15 +2137,10 @@
                     if (pvSwapchain != pSwapchain->pSwapChainIf)
                     {
+#ifdef DEBUG_misha
+                        /* @todo: we can not generally update the render target directly, implement */
                         Assert(iBb != (~0));
-//                        Assert(0);
-#if 0 //def DEBUG_misha
-                        vboxVDbgDumpAllocSurfData((pDevice, "Synch Src:\n", pAlloc, pD3D9OldSurf, NULL, "\n"));
-                        vboxVDbgDumpAllocData((pDevice, "Synch ALLOC:\n", pAlloc, NULL, "\n"));
 #endif
                         hr = pDevice->pDevice9If->StretchRect(pD3D9OldSurf, NULL, pD3D9Surf, NULL, D3DTEXF_NONE);
                         Assert(hr == S_OK);
-#if 0 //def DEBUG_misha
-                        vboxVDbgDumpAllocSurfData((pDevice, "Synch Dst:\n", pAlloc, pD3D9Surf, NULL, "\n"));
-#endif
                         if (pSwapchain->cRTs == 1)
                         {
@@ -2210,5 +2205,8 @@
 {
     Assert(pSwapchain->cRTs);
+#ifdef DEBUG_misha
+    /* not supported by wine properly, need to use offscreen render targets and blit their data to swapchain RTs*/
     Assert(pSwapchain->cRTs <= 2);
+#endif
     memset(pParams, 0, sizeof (D3DPRESENT_PARAMETERS));
     PVBOXWDDMDISP_RENDERTGT pRt = vboxWddmSwapchainGetBb(pSwapchain);
@@ -2312,5 +2310,4 @@
                 if (pOldIf)
                 {
-                    Assert(0);
                     /* copy current rt data to offscreen render targets */
                     IDirect3DSurface9* pD3D9OldFb = NULL;
@@ -3365,7 +3362,11 @@
 //    VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
     vboxVDbgPrintF(("<== "__FUNCTION__", hDevice(0x%p)\n", hDevice));
+#ifdef DEBUG_misha
+    /* @todo: check if it's ok to always return success */
+    vboxVDbgPrint((__FUNCTION__": @todo: check if it's ok to always return success\n"));
     Assert(0);
-    vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
-    return E_FAIL;
+#endif
+    vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
+    return S_OK;
 }
 
@@ -4406,5 +4407,6 @@
 
         if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE
-            || pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_CUBE_TEXTURE)
+            || pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_CUBE_TEXTURE
+            || pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE)
         {
             PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];
@@ -4413,4 +4415,5 @@
             IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pTexAlloc->pD3DIf;
             IDirect3DCubeTexture9 *pD3DIfCubeTex = (IDirect3DCubeTexture9*)pTexAlloc->pD3DIf;
+            IDirect3DSurface9 *pD3DIfSurface = (IDirect3DSurface9*)pTexAlloc->pD3DIf;
             Assert(pTexAlloc->pD3DIf);
             RECT *pRect = NULL;
@@ -4425,27 +4428,33 @@
             /* else - we lock the entire texture, pRect == NULL */
 
-//            Assert(!pLockAlloc->LockInfo.cLocks);
             if (!pLockAlloc->LockInfo.cLocks)
             {
-                if (pTexAlloc->enmD3DIfType==VBOXDISP_D3DIFTYPE_TEXTURE)
-                {
-                    hr = pD3DIfTex->LockRect(pData->SubResourceIndex,
-                            &pLockAlloc->LockInfo.LockedRect,
-                            pRect,
-                            vboxDDI2D3DLockFlags(pData->Flags));
-                }
-                else /*VBOXDISP_D3DIFTYPE_CUBE_TEXTURE*/
-                {
-                    hr = pD3DIfCubeTex->LockRect(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, pData->SubResourceIndex),
-                            VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, pData->SubResourceIndex),
-                            &pLockAlloc->LockInfo.LockedRect,
-                            pRect,
-                            vboxDDI2D3DLockFlags(pData->Flags));
+                switch (pTexAlloc->enmD3DIfType)
+                {
+                    case VBOXDISP_D3DIFTYPE_TEXTURE:
+                        hr = pD3DIfTex->LockRect(pData->SubResourceIndex,
+                                &pLockAlloc->LockInfo.LockedRect,
+                                pRect,
+                                vboxDDI2D3DLockFlags(pData->Flags));
+                        break;
+                    case VBOXDISP_D3DIFTYPE_CUBE_TEXTURE:
+                        hr = pD3DIfCubeTex->LockRect(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, pData->SubResourceIndex),
+                                VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, pData->SubResourceIndex),
+                                &pLockAlloc->LockInfo.LockedRect,
+                                pRect,
+                                vboxDDI2D3DLockFlags(pData->Flags));
+                        break;
+                    case VBOXDISP_D3DIFTYPE_SURFACE:
+                        hr = pD3DIfSurface->LockRect(&pLockAlloc->LockInfo.LockedRect,
+                                pRect,
+                                vboxDDI2D3DLockFlags(pData->Flags));
+                        break;
+                    default:
+                        Assert(0);
+                        break;
                 }
                 Assert(hr == S_OK);
                 if (hr == S_OK)
                 {
-
-//                    Assert(pLockAlloc->LockInfo.fFlags.Value == 0);
                     pLockAlloc->LockInfo.fFlags = pData->Flags;
                     if (pRect)
@@ -4453,10 +4462,8 @@
                         pLockAlloc->LockInfo.Area = *pRect;
                         Assert(pLockAlloc->LockInfo.fFlags.AreaValid == 1);
-//                        pLockAlloc->LockInfo.fFlags.AreaValid = 1;
                     }
                     else
                     {
                         Assert(pLockAlloc->LockInfo.fFlags.AreaValid == 0);
-//                        pLockAlloc->LockInfo.fFlags.AreaValid = 0;
                     }
 
@@ -4466,8 +4473,4 @@
             else
             {
-//                Assert(pLockAlloc->LockInfo.fFlags.Value == pData->Flags.Value);
-//                if (pLockAlloc->LockInfo.fFlags.Value != pData->Flags.Value)
-//                {
-//                }
                 Assert(pLockAlloc->LockInfo.fFlags.AreaValid == pData->Flags.AreaValid);
                 if (pLockAlloc->LockInfo.fFlags.AreaValid && pData->Flags.AreaValid)
@@ -4484,34 +4487,48 @@
                 Assert(!bNeedResynch);
 
-                if (/*(pLockAlloc->LockInfo.fFlags.Discard && !pData->Flags.Discard)
-                        || */
-                        (pLockAlloc->LockInfo.fFlags.ReadOnly && !pData->Flags.ReadOnly))
-                {
-                    if (pTexAlloc->enmD3DIfType==VBOXDISP_D3DIFTYPE_TEXTURE)
+                if (pLockAlloc->LockInfo.fFlags.ReadOnly && !pData->Flags.ReadOnly)
+                {
+                    switch (pTexAlloc->enmD3DIfType)
                     {
-                        hr = pD3DIfTex->UnlockRect(pData->SubResourceIndex);
-                    }
-                    else /*VBOXDISP_D3DIFTYPE_CUBE_TEXTURE*/
-                    {
-                        hr = pD3DIfCubeTex->UnlockRect(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, pData->SubResourceIndex),
-                                VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, pData->SubResourceIndex));
+                        case VBOXDISP_D3DIFTYPE_TEXTURE:
+                            hr = pD3DIfTex->UnlockRect(pData->SubResourceIndex);
+                            break;
+                        case VBOXDISP_D3DIFTYPE_CUBE_TEXTURE:
+                            hr = pD3DIfCubeTex->UnlockRect(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, pData->SubResourceIndex),
+                                    VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, pData->SubResourceIndex));
+                            break;
+                        case VBOXDISP_D3DIFTYPE_SURFACE:
+                            hr = pD3DIfSurface->UnlockRect();
+                            break;
+                        default:
+                            Assert(0);
+                            break;
                     }
                     Assert(hr == S_OK);
                     if (hr == S_OK)
                     {
-                        if (pTexAlloc->enmD3DIfType==VBOXDISP_D3DIFTYPE_TEXTURE)
+                        switch (pTexAlloc->enmD3DIfType)
                         {
-                            hr = pD3DIfTex->LockRect(pData->SubResourceIndex,
-                                    &pLockAlloc->LockInfo.LockedRect,
-                                    pRect,
-                                    vboxDDI2D3DLockFlags(pData->Flags));
-                        }
-                        else /*VBOXDISP_D3DIFTYPE_CUBE_TEXTURE*/
-                        {
-                            hr = pD3DIfCubeTex->LockRect(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, pData->SubResourceIndex),
-                                    VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, pData->SubResourceIndex),
-                                    &pLockAlloc->LockInfo.LockedRect,
-                                    pRect,
-                                    vboxDDI2D3DLockFlags(pData->Flags));
+                            case VBOXDISP_D3DIFTYPE_TEXTURE:
+                                hr = pD3DIfTex->LockRect(pData->SubResourceIndex,
+                                        &pLockAlloc->LockInfo.LockedRect,
+                                        pRect,
+                                        vboxDDI2D3DLockFlags(pData->Flags));
+                                break;
+                            case VBOXDISP_D3DIFTYPE_CUBE_TEXTURE:
+                                hr = pD3DIfCubeTex->LockRect(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, pData->SubResourceIndex),
+                                        VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, pData->SubResourceIndex),
+                                        &pLockAlloc->LockInfo.LockedRect,
+                                        pRect,
+                                        vboxDDI2D3DLockFlags(pData->Flags));
+                                break;
+                            case VBOXDISP_D3DIFTYPE_SURFACE:
+                                hr = pD3DIfSurface->LockRect(&pLockAlloc->LockInfo.LockedRect,
+                                        pRect,
+                                        vboxDDI2D3DLockFlags(pData->Flags));
+                                break;
+                            default:
+                                Assert(0);
+                                break;
                         }
                         Assert(hr == S_OK);
@@ -4537,8 +4554,4 @@
                     Assert(pLockAlloc->pvMem);
                     Assert(pRc->RcDesc.enmPool == D3DDDIPOOL_SYSTEMMEM);
-#if 0
-                    if (bNeedResynch)
-                        vboxWddmLockUnlockMemSynch(pLockAlloc, &pLockAlloc->LockInfo.LockedRect, pRect, false /*bool bToLockInfo*/);
-#endif
                 }
             }
@@ -4561,5 +4574,4 @@
             /* else - we lock the entire vertex buffer, pRect == NULL */
 
-            Assert(!pAlloc->LockInfo.cLocks);
             if (!pAlloc->LockInfo.cLocks)
             {
@@ -4594,8 +4606,4 @@
             else
             {
-//                Assert(pAlloc->LockInfo.fFlags.Value == pData->Flags.Value);
-//                if (pAlloc->LockInfo.fFlags.Value != pData->Flags.Value)
-//                {
-//                }
                 Assert(pAlloc->LockInfo.fFlags.RangeValid == pData->Flags.RangeValid);
                 if (pAlloc->LockInfo.fFlags.RangeValid && pData->Flags.RangeValid)
@@ -4658,5 +4666,4 @@
             /* else - we lock the entire vertex buffer, pRect == NULL */
 
-            Assert(!pAlloc->LockInfo.cLocks);
             if (!pAlloc->LockInfo.cLocks)
             {
@@ -4691,8 +4698,4 @@
             else
             {
-//                Assert(pAlloc->LockInfo.fFlags.Value == pData->Flags.Value);
-//                if (pAlloc->LockInfo.fFlags.Value != pData->Flags.Value)
-//                {
-//                }
                 Assert(pAlloc->LockInfo.fFlags.RangeValid == pData->Flags.RangeValid);
                 if (pAlloc->LockInfo.fFlags.RangeValid && pData->Flags.RangeValid)
@@ -4831,5 +4834,6 @@
     {
         if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE
-            || pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_CUBE_TEXTURE)
+            || pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_CUBE_TEXTURE
+            || pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_SURFACE)
         {
             Assert(pData->SubResourceIndex < pRc->cAllocations);
@@ -4838,29 +4842,32 @@
             --pLockAlloc->LockInfo.cLocks;
             Assert(pLockAlloc->LockInfo.cLocks < UINT32_MAX);
-//            pLockAlloc->LockInfo.cLocks = 0;
             if (!pLockAlloc->LockInfo.cLocks)
             {
                 PVBOXWDDMDISP_ALLOCATION pTexAlloc = &pRc->aAllocations[0];
-//                Assert(!pLockAlloc->LockInfo.cLocks);
                 Assert(pTexAlloc->pD3DIf);
-                /* this is a sysmem texture, update  */
-#if 0
-                if (pLockAlloc->pvMem && !pLockAlloc->LockInfo.fFlags.ReadOnly)
-                {
-                    vboxWddmLockUnlockMemSynch(pLockAlloc, &pLockAlloc->LockInfo.LockedRect,
-                            pLockAlloc->LockInfo.fFlags.AreaValid ? &pLockAlloc->LockInfo.Area : NULL,
-                            true /*bool bToLockInfo*/);
-                }
-#endif
-                if (pRc->aAllocations[0].enmD3DIfType == VBOXDISP_D3DIFTYPE_TEXTURE)
-                {
-                    IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pTexAlloc->pD3DIf;
-                    hr = pD3DIfTex->UnlockRect(pData->SubResourceIndex);
-                }
-                else
-                {
-                    IDirect3DCubeTexture9 *pD3DIfCubeTex = (IDirect3DCubeTexture9*)pTexAlloc->pD3DIf;
-                    hr = pD3DIfCubeTex->UnlockRect(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, pData->SubResourceIndex),
-                            VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, pData->SubResourceIndex));
+                switch (pRc->aAllocations[0].enmD3DIfType)
+                {
+                    case VBOXDISP_D3DIFTYPE_TEXTURE:
+                    {
+                        IDirect3DTexture9 *pD3DIfTex = (IDirect3DTexture9*)pTexAlloc->pD3DIf;
+                        hr = pD3DIfTex->UnlockRect(pData->SubResourceIndex);
+                        break;
+                    }
+                    case VBOXDISP_D3DIFTYPE_CUBE_TEXTURE:
+                    {
+                        IDirect3DCubeTexture9 *pD3DIfCubeTex = (IDirect3DCubeTexture9*)pTexAlloc->pD3DIf;
+                        hr = pD3DIfCubeTex->UnlockRect(VBOXDISP_CUBEMAP_INDEX_TO_FACE(pRc, pData->SubResourceIndex),
+                                VBOXDISP_CUBEMAP_INDEX_TO_LEVEL(pRc, pData->SubResourceIndex));
+                        break;
+                    }
+                    case VBOXDISP_D3DIFTYPE_SURFACE:
+                    {
+                        IDirect3DSurface9 *pD3DIfSurf = (IDirect3DSurface9*)pTexAlloc->pD3DIf;
+                        hr = pD3DIfSurf->UnlockRect();
+                        break;
+                    }
+                    default:
+                        Assert(0);
+                        break;
                 }
                 Assert(hr == S_OK);
@@ -7348,9 +7355,7 @@
     vboxVDbgPrintF(("==> "__FUNCTION__", hDevice(0x%p)\n", hDevice));
     PVBOXWDDMDISP_DEVICE pDevice = (PVBOXWDDMDISP_DEVICE)hDevice;
-//    Assert(pDevice);
-//    VBOXDISPCRHGSMI_SCOPE_SET_DEV(pDevice);
-
-    Assert(0);
+
     HRESULT hr = S_OK;
+    /* @todo check residency for the "real" allocations */
 #if 0
     for (UINT i = 0; i < pData->NumResources; ++i)
