Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/dd.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/dd.c	(revision 27838)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/dd.c	(revision 27839)
@@ -108,6 +108,4 @@
     {
 #ifdef VBOX_WITH_VIDEOHWACCEL
-        vboxVHWAInit();
-
         memset(pHalInfo, 0, sizeof(DD_HALINFO));
         pHalInfo->dwSize    = sizeof(DD_HALINFO);
@@ -659,5 +657,5 @@
             if (lpSurfaceLocal->ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)
             {
-                pBody->SurfInfo.offSurface = 0;
+                pBody->SurfInfo.offSurface = vboxVHWAVramOffsetFromPDEV(pDev, 0);
             }
             else
@@ -1082,5 +1080,5 @@
                 memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_LOCK));
 
-                pBody->u.in.offSurface = (uint64_t)lpSurfaceGlobal->fpVidMem;
+                pBody->u.in.offSurface = vboxVHWAVramOffsetFromPDEV(pDev, lpSurfaceGlobal->fpVidMem);
 
 //            if (lpLock->bHasRect)
@@ -1465,5 +1463,5 @@
         memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_COLORKEY_SET));
 
-        pBody->u.in.offSurface = (uint64_t)lpSurfaceGlobal->fpVidMem;
+        pBody->u.in.offSurface = vboxVHWAVramOffsetFromPDEV(pDev, lpSurfaceGlobal->fpVidMem);
         pBody->u.in.hSurf = pDesc->hHostHandle;
         pBody->u.in.flags = vboxVHWAFromDDCKEYs(lpSetColorKey->dwFlags);
@@ -1508,6 +1506,6 @@
             memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_BLT));
 
-            pBody->u.in.offSrcSurface = (uint64_t)lpSrcSurfaceGlobal->fpVidMem;
-            pBody->u.in.offDstSurface = (uint64_t)lpDestSurfaceGlobal->fpVidMem;
+            pBody->u.in.offSrcSurface = vboxVHWAVramOffsetFromPDEV(pDev, lpSrcSurfaceGlobal->fpVidMem);
+            pBody->u.in.offDstSurface = vboxVHWAVramOffsetFromPDEV(pDev, lpDestSurfaceGlobal->fpVidMem);
 
             pBody->u.in.hDstSurf = pDestDesc->hHostHandle;
@@ -1601,6 +1599,6 @@
         memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_FLIP));
 
-        pBody->u.in.offCurrSurface = (uint64_t)lpCurrSurfaceGlobal->fpVidMem;
-        pBody->u.in.offTargSurface = (uint64_t)lpTargSurfaceGlobal->fpVidMem;
+        pBody->u.in.offCurrSurface = vboxVHWAVramOffsetFromPDEV(pDev, lpCurrSurfaceGlobal->fpVidMem);
+        pBody->u.in.offTargSurface = vboxVHWAVramOffsetFromPDEV(pDev, lpTargSurfaceGlobal->fpVidMem);
 
         pBody->u.in.hTargSurf = pTargDesc->hHostHandle;
@@ -1770,6 +1768,6 @@
         memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_OVERLAY_SETPOSITION));
 
-        pBody->u.in.offSrcSurface = (uint64_t)lpSrcSurfaceGlobal->fpVidMem;
-        pBody->u.in.offDstSurface = (uint64_t)lpDestSurfaceGlobal->fpVidMem;
+        pBody->u.in.offSrcSurface = vboxVHWAVramOffsetFromPDEV(pDev, lpSrcSurfaceGlobal->fpVidMem);
+        pBody->u.in.offDstSurface = vboxVHWAVramOffsetFromPDEV(pDev, lpDestSurfaceGlobal->fpVidMem);
 
         pBody->u.in.hDstSurf = pDestDesc->hHostHandle;
@@ -1811,5 +1809,5 @@
         memset(pBody, 0, sizeof(VBOXVHWACMD_SURF_OVERLAY_UPDATE));
 
-        pBody->u.in.offSrcSurface = (uint64_t)lpSrcSurfaceGlobal->fpVidMem;
+        pBody->u.in.offSrcSurface = vboxVHWAVramOffsetFromPDEV(pDev, lpSrcSurfaceGlobal->fpVidMem);
 
         pBody->u.in.hSrcSurf = pSrcDesc->hHostHandle;
@@ -1841,5 +1839,5 @@
             PVBOXVHWASURFDESC pDestDesc = (PVBOXVHWASURFDESC)lpDestSurfaceGlobal->dwReserved1;
             pBody->u.in.hDstSurf = pDestDesc->hHostHandle;
-            pBody->u.in.offDstSurface = (uint64_t)lpDestSurfaceGlobal->fpVidMem;
+            pBody->u.in.offDstSurface = vboxVHWAVramOffsetFromPDEV(pDev, lpDestSurfaceGlobal->fpVidMem);
         }
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/driver.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/driver.h	(revision 27838)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/driver.h	(revision 27839)
@@ -131,5 +131,7 @@
     uint32_t numFourCC;
     HGSMIOFFSET FourCC;
+    ULONG_PTR offVramBase;
     BOOLEAN bVHWAEnabled;
+    BOOLEAN bVHWAInited;
 } VBOXVHWAINFO;
 #endif
@@ -297,4 +299,9 @@
 
  #ifdef VBOX_WITH_VIDEOHWACCEL
+
+DECLINLINE(uint64_t) vboxVHWAVramOffsetFromPDEV(PPDEV pDev, ULONG_PTR offPdev)
+{
+    return (uint64_t)(pDev->vhwaInfo.offVramBase + offPdev);
+}
 
 #define VBOXDD_CHECKFLAG(_v, _f) ((_v) & (_f)) == (_f)
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/screen.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/screen.c	(revision 27838)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/screen.c	(revision 27839)
@@ -154,4 +154,10 @@
                 Assert(!err);
 #endif
+
+#ifdef VBOX_WITH_VIDEOHWACCEL
+                if (!err)
+                    vboxVHWAInit(ppdev);
+#endif
+
                 /* this is not fatal, just means Video 2D acceleration will not be supported */
                 err = 0;
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/vbox.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/vbox.c	(revision 27838)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/vbox.c	(revision 27839)
@@ -1065,4 +1065,29 @@
 }
 
+void vboxVHWAInit(PPDEV ppdev)
+{
+    VHWAQUERYINFO info;
+    DWORD returnedDataLength;
+    DWORD err;
+
+    memset(&info, 0, sizeof (info));
+
+    err = EngDeviceIoControl(ppdev->hDriver,
+            IOCTL_VIDEO_VHWA_QUERY_INFO,
+            NULL,
+            0,
+            &info,
+            sizeof(info),
+            &returnedDataLength);
+    Assert(!err);
+    if(!err)
+    {
+        ppdev->vhwaInfo.offVramBase = info.offVramBase;
+        ppdev->vhwaInfo.bVHWAInited = TRUE;
+    }
+    else
+        ppdev->vhwaInfo.bVHWAInited = FALSE;
+}
+
 # endif
 
Index: trunk/src/VBox/Additions/WINNT/Graphics/Display/vhwa.c
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Display/vhwa.c	(revision 27838)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Display/vhwa.c	(revision 27839)
@@ -139,12 +139,4 @@
         )
 
-void vboxVHWAInit()
-{
-}
-
-void vboxVHWATerm()
-{
-}
-
 uint32_t vboxVHWAUnsupportedDDCAPS(uint32_t caps)
 {
Index: trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp	(revision 27838)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Miniport/VBoxVideo.cpp	(revision 27839)
@@ -2687,6 +2687,29 @@
             break;
         }
+# ifdef VBOX_WITH_VIDEOHWACCEL
+        case IOCTL_VIDEO_VHWA_QUERY_INFO:
+        {
+            if (RequestPacket->OutputBufferLength < sizeof (VHWAQUERYINFO))
+            {
+                dprintf(("VBoxVideo::VBoxVideoStartIO: Output buffer too small: %d needed: %d!!!\n",
+                         RequestPacket->OutputBufferLength, sizeof(VHWAQUERYINFO)));
+                RequestPacket->StatusBlock->Status = ERROR_INSUFFICIENT_BUFFER;
+                return FALSE;
+            }
+
+            if (!pDevExt->pPrimary->u.primary.bHGSMI)
+            {
+                RequestPacket->StatusBlock->Status = ERROR_INVALID_FUNCTION;
+                return FALSE;
+            }
+
+            VHWAQUERYINFO *pInfo = (VHWAQUERYINFO *)RequestPacket->OutputBuffer;
+            pInfo->offVramBase = (ULONG_PTR)pDevExt->ulFrameBufferOffset;
+            RequestPacket->StatusBlock->Information = sizeof (VHWAQUERYINFO);
+            Result = TRUE;
+            break;
+        }
+# endif
 #endif /* VBOX_WITH_HGSMI */
-
         default:
             dprintf(("VBoxVideo::VBoxVideoStartIO: Unsupported %p, fn %d(0x%x)\n",
Index: trunk/src/VBox/Additions/WINNT/Graphics/Miniport/vboxioctl.h
===================================================================
--- trunk/src/VBox/Additions/WINNT/Graphics/Miniport/vboxioctl.h	(revision 27838)
+++ trunk/src/VBox/Additions/WINNT/Graphics/Miniport/vboxioctl.h	(revision 27839)
@@ -63,4 +63,7 @@
 #define IOCTL_VIDEO_HGSMI_QUERY_PORTPROCS \
     CTL_CODE(FILE_DEVICE_VIDEO, 0x434, METHOD_BUFFERED, FILE_ANY_ACCESS)
+
+#define IOCTL_VIDEO_VHWA_QUERY_INFO \
+    CTL_CODE(FILE_DEVICE_VIDEO, 0x435, METHOD_BUFFERED, FILE_ANY_ACCESS)
 
 #endif /* VBOX_WITH_HGSMI */
@@ -167,4 +170,11 @@
 } HGSMIHANDLERDISABLE;
 
+# ifdef VBOX_WITH_VIDEOHWACCEL
+typedef struct _VHWAQUERYINFO
+{
+    ULONG_PTR offVramBase;
+} VHWAQUERYINFO;
+# endif
+
 #endif /* VBOX_WITH_HGSMI */
 #pragma pack()
Index: trunk/src/VBox/Devices/Graphics/DevVGA_VBVA.cpp
===================================================================
--- trunk/src/VBox/Devices/Graphics/DevVGA_VBVA.cpp	(revision 27838)
+++ trunk/src/VBox/Devices/Graphics/DevVGA_VBVA.cpp	(revision 27839)
@@ -1001,16 +1001,20 @@
 
 #ifdef VBOX_WITH_VIDEOHWACCEL
-static VBOXVHWACMD* vbvaVHWAHHCommandCreate (PVGASTATE pVGAState, VBOXVHWACMD_TYPE enmCmd, VBOXVHWACMD_LENGTH cbCmd)
+static void vbvaVHWAHHCommandReinit(VBOXVHWACMD* pHdr, VBOXVHWACMD_TYPE enmCmd, int32_t iDisplay)
+{
+    memset(pHdr, 0, VBOXVHWACMD_HEADSIZE());
+    pHdr->cRefs = 1;
+    pHdr->iDisplay = iDisplay;
+    pHdr->rc = VERR_NOT_IMPLEMENTED;
+    pHdr->enmCmd = enmCmd;
+    pHdr->Flags = VBOXVHWACMD_FLAG_HH_CMD;
+}
+
+static VBOXVHWACMD* vbvaVHWAHHCommandCreate (PVGASTATE pVGAState, VBOXVHWACMD_TYPE enmCmd, int32_t iDisplay, VBOXVHWACMD_LENGTH cbCmd)
 {
     VBOXVHWACMD* pHdr = (VBOXVHWACMD*)RTMemAlloc(cbCmd + VBOXVHWACMD_HEADSIZE());
     Assert(pHdr);
     if (pHdr)
-    {
-        memset(pHdr, 0, VBOXVHWACMD_HEADSIZE());
-        pHdr->cRefs = 1;
-        pHdr->rc = VERR_NOT_IMPLEMENTED;
-        pHdr->enmCmd = enmCmd;
-        pHdr->Flags = VBOXVHWACMD_FLAG_HH_CMD;
-    }
+        vbvaVHWAHHCommandReinit(pHdr, enmCmd, iDisplay);
 
     return pHdr;
@@ -1079,31 +1083,47 @@
 int vbvaVHWAConstruct (PVGASTATE pVGAState)
 {
-    VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_HH_CONSTRUCT, sizeof(VBOXVHWACMD_HH_CONSTRUCT));
+    VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_HH_CONSTRUCT, 0, sizeof(VBOXVHWACMD_HH_CONSTRUCT));
     Assert(pCmd);
     if(pCmd)
     {
+        uint32_t iDisplay = 0;
+        int rc = VINF_SUCCESS;
         VBOXVHWACMD_HH_CONSTRUCT * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_HH_CONSTRUCT);
-        memset(pBody, 0, sizeof(VBOXVHWACMD_HH_CONSTRUCT));
-
-        PPDMDEVINS pDevIns = pVGAState->pDevInsR3;
-        PVM pVM = PDMDevHlpGetVM(pDevIns);
-
-        pBody->pVM = pVM;
-        pBody->pvVRAM = pVGAState->vram_ptrR3;
-        pBody->cbVRAM = pVGAState->vram_size;
-
-        int rc = vbvaVHWAHHCommandPost(pVGAState, pCmd);
-        AssertRC(rc);
-        if(RT_SUCCESS(rc))
-        {
-            rc = pCmd->rc;
-            AssertMsg(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED, ("%Rrc\n", rc));
-            if(rc == VERR_NOT_IMPLEMENTED)
-            {
-                /* @todo: set some flag in pVGAState indicating VHWA is not supported */
-                /* VERR_NOT_IMPLEMENTED is not a failure, we just do not support it */
-                rc = VINF_SUCCESS;
-            }
-        }
+
+        do
+        {
+            memset(pBody, 0, sizeof(VBOXVHWACMD_HH_CONSTRUCT));
+
+            PPDMDEVINS pDevIns = pVGAState->pDevInsR3;
+            PVM pVM = PDMDevHlpGetVM(pDevIns);
+
+            pBody->pVM = pVM;
+            pBody->pvVRAM = pVGAState->vram_ptrR3;
+            pBody->cbVRAM = pVGAState->vram_size;
+
+            rc = vbvaVHWAHHCommandPost(pVGAState, pCmd);
+            AssertRC(rc);
+            if(RT_SUCCESS(rc))
+            {
+                rc = pCmd->rc;
+                AssertMsg(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED, ("%Rrc\n", rc));
+                if(rc == VERR_NOT_IMPLEMENTED)
+                {
+                    /* @todo: set some flag in pVGAState indicating VHWA is not supported */
+                    /* VERR_NOT_IMPLEMENTED is not a failure, we just do not support it */
+                    rc = VINF_SUCCESS;
+                }
+
+                if (!RT_SUCCESS(rc))
+                    break;
+            }
+            else
+                break;
+
+            ++iDisplay;
+            if (iDisplay >= pVGAState->cMonitors)
+                break;
+            vbvaVHWAHHCommandReinit(pCmd, VBOXVHWACMD_TYPE_HH_CONSTRUCT, (int32_t)iDisplay);
+        } while (true);
 
         vbvaVHWAHHCommandRelease(pCmd);
@@ -1117,17 +1137,32 @@
 {
     /* ensure we have all pending cmds processed and h->g cmds disabled */
-    VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_HH_RESET, 0);
+    VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_HH_RESET, 0, 0);
     Assert(pCmd);
     if(pCmd)
     {
-        int rc = vbvaVHWAHHCommandPost(pVGAState, pCmd);
-        AssertRC(rc);
-        if(RT_SUCCESS(rc))
-        {
-            rc = pCmd->rc;
-            AssertMsg(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED, ("%Rrc\n", rc));
-            if (rc == VERR_NOT_IMPLEMENTED)
-                rc = VINF_SUCCESS;
-        }
+        int rc = VINF_SUCCESS;
+        uint32_t iDisplay = 0;
+
+        do
+        {
+            rc =vbvaVHWAHHCommandPost(pVGAState, pCmd);
+            AssertRC(rc);
+            if(RT_SUCCESS(rc))
+            {
+                rc = pCmd->rc;
+                AssertMsg(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED, ("%Rrc\n", rc));
+                if (rc == VERR_NOT_IMPLEMENTED)
+                    rc = VINF_SUCCESS;
+            }
+
+            if (!RT_SUCCESS(rc))
+                break;
+
+            ++iDisplay;
+            if (iDisplay >= pVGAState->cMonitors)
+                break;
+            vbvaVHWAHHCommandReinit(pCmd, VBOXVHWACMD_TYPE_HH_RESET, (int32_t)iDisplay);
+
+        } while (true);
 
         vbvaVHWAHHCommandRelease(pCmd);
@@ -1141,19 +1176,34 @@
 int vbvaVHWADisable (PVGASTATE pVGAState)
 {
-    VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_DISABLE, 0);
+    VBOXVHWACMD *pCmd = vbvaVHWAHHCommandCreate(pVGAState, VBOXVHWACMD_TYPE_DISABLE, 0, 0);
     Assert(pCmd);
     if(pCmd)
     {
-        int rc = vbvaVHWAHHCommandPost(pVGAState, pCmd);
-        AssertRC(rc);
-        if(RT_SUCCESS(rc))
-        {
-            rc = pCmd->rc;
-            AssertMsg(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED, ("%Rrc\n", rc));
-            if(rc == VERR_NOT_IMPLEMENTED)
-            {
-                rc = VINF_SUCCESS;
-            }
-        }
+        int rc = VINF_SUCCESS;
+        uint32_t iDisplay = 0;
+
+        do
+        {
+            rc = vbvaVHWAHHCommandPost(pVGAState, pCmd);
+            AssertRC(rc);
+            if(RT_SUCCESS(rc))
+            {
+                rc = pCmd->rc;
+                AssertMsg(RT_SUCCESS(rc) || rc == VERR_NOT_IMPLEMENTED, ("%Rrc\n", rc));
+                if(rc == VERR_NOT_IMPLEMENTED)
+                {
+                    rc = VINF_SUCCESS;
+                }
+            }
+
+            if (!RT_SUCCESS(rc))
+                break;
+
+            ++iDisplay;
+            if (iDisplay >= pVGAState->cMonitors)
+                break;
+            vbvaVHWAHHCommandReinit(pCmd, VBOXVHWACMD_TYPE_DISABLE, (int32_t)iDisplay);
+
+        } while (true);
 
         vbvaVHWAHHCommandRelease(pCmd);
Index: trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp	(revision 27838)
+++ trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp	(revision 27839)
@@ -820,5 +820,5 @@
                     /* these two additional template args is a workaround to this [VBox|UI] duplication
                      * @todo: they are to be removed once VBox stuff is gone */
-                    mAccelerate2DVideo ? new VBoxOverlayFrameBuffer<VBoxQImageFrameBuffer, VBoxConsoleView, VBoxResizeEvent> (this, &mainWnd->session()) :
+                    mAccelerate2DVideo ? new VBoxOverlayFrameBuffer<VBoxQImageFrameBuffer, VBoxConsoleView, VBoxResizeEvent> (this, &mainWnd->session(), 0) :
 #endif
                     new VBoxQImageFrameBuffer (this);
@@ -839,5 +839,5 @@
                     /* these two additional template args is a workaround to this [VBox|UI] duplication
                      * @todo: they are to be removed once VBox stuff is gone */
-                    mAccelerate2DVideo ? new VBoxOverlayFrameBuffer<VBoxSDLFrameBuffer, VBoxConsoleView, VBoxResizeEvent> (this, &mainWnd->session()) :
+                    mAccelerate2DVideo ? new VBoxOverlayFrameBuffer<VBoxSDLFrameBuffer, VBoxConsoleView, VBoxResizeEvent> (this, &mainWnd->session(), 0) :
 #endif
                     new VBoxSDLFrameBuffer (this);
@@ -864,5 +864,5 @@
                     /* these two additional template args is a workaround to this [VBox|UI] duplication
                      * @todo: they are to be removed once VBox stuff is gone */
-                    mAccelerate2DVideo ? new VBoxOverlayFrameBuffer<VBoxQuartz2DFrameBuffer, VBoxConsoleView, VBoxResizeEvent> (this, &mainWnd->session()) :
+                    mAccelerate2DVideo ? new VBoxOverlayFrameBuffer<VBoxQuartz2DFrameBuffer, VBoxConsoleView, VBoxResizeEvent> (this, &mainWnd->session(), 0) :
 #endif
                     new VBoxQuartz2DFrameBuffer (this);
Index: trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.cpp	(revision 27838)
+++ trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.cpp	(revision 27839)
@@ -2204,5 +2204,9 @@
 
     VBoxVHWASurfaceBase *surf = NULL;
-    const VBoxVHWASurfaceBase *existingSurf = NULL;
+    /* in case the Framebuffer is working in "not using VRAM" mode,
+     * we need to report the pitch, etc. info of the form guest expects from us*/
+    VBoxVHWAColorFormat reportedFormat;
+    /* paranoya to ensure the VBoxVHWAColorFormat API works properly */
+    Assert(!reportedFormat.isValid());
     bool bNoPBO = false;
     bool bPrimary = false;
@@ -2233,5 +2237,5 @@
     }
 
-    if(pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_PRIMARYSURFACE)
+    if (pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_PRIMARYSURFACE)
     {
         bNoPBO = true;
@@ -2240,5 +2244,5 @@
 
         Assert((pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_OFFSCREENPLAIN) == 0);
-        if(pVga->handle() == VBOXVHWA_SURFHANDLE_INVALID
+        if (pVga->handle() == VBOXVHWA_SURFHANDLE_INVALID
                 && (pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_OFFSCREENPLAIN) == 0)
         {
@@ -2251,12 +2255,12 @@
 //                        && pCmd->SurfInfo.height == pVga->height())
                 {
-                    VBoxVHWAColorFormat format(pCmd->SurfInfo.PixelFormat.c.rgbBitCount,
+                    reportedFormat = VBoxVHWAColorFormat(pCmd->SurfInfo.PixelFormat.c.rgbBitCount,
                                                 pCmd->SurfInfo.PixelFormat.m1.rgbRBitMask,
                                                 pCmd->SurfInfo.PixelFormat.m2.rgbGBitMask,
                                                 pCmd->SurfInfo.PixelFormat.m3.rgbBBitMask);
-                    Assert(pVga->pixelFormat().equals(format));
+                    // the assert below is incorrect in case the Framebuffer is working in "not using VRAM" mode
+//                    Assert(pVga->pixelFormat().equals(format));
 //                    if(pVga->pixelFormat().equals(format))
                     {
-                        existingSurf = pVga;
                         surf = pVga;
 
@@ -2282,4 +2286,5 @@
     if(!surf)
     {
+        Assert(!(pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_PRIMARYSURFACE));
         VBOXVHWAIMG_TYPE fFlags = 0;
         if(!bNoPBO)
@@ -2336,6 +2341,5 @@
 
         uchar * addr = vboxVRAMAddressFromOffset(pCmd->SurfInfo.offSurface);
-        if (!existingSurf)
-            surf->init(mDisplay.getPrimary(), addr);
+        surf->init(mDisplay.getPrimary(), addr);
 
         if(pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_OVERLAY)
@@ -2376,4 +2380,8 @@
         }
     }
+    else
+    {
+        Assert(pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_PRIMARYSURFACE);
+    }
 
     Assert(mDisplay.getVGA() == mDisplay.getPrimary());
@@ -2382,7 +2390,21 @@
     VBOXQGLLOG(("bps: %d\n", surf->bitsPerPixel()));
 
-    pCmd->SurfInfo.pitch        = surf->bitsPerPixel() * surf->width() / 8;
-    pCmd->SurfInfo.sizeX = surf->memSize();
-    pCmd->SurfInfo.sizeY = 1;
+    if (!reportedFormat.isValid())
+    {
+        pCmd->SurfInfo.pitch = surf->bitsPerPixel() * surf->width() / 8;
+        pCmd->SurfInfo.sizeX = surf->memSize();
+        pCmd->SurfInfo.sizeY = 1;
+    }
+    else
+    {
+        /* this is the case of Framebuffer not using Gueat VRAM */
+        /* can happen for primary surface creation only */
+        Assert(pCmd->SurfInfo.surfCaps & VBOXVHWA_SCAPS_PRIMARYSURFACE);
+        pCmd->SurfInfo.pitch = (reportedFormat.bitsPerPixel() * surf->width() + 7) / 8;
+        /* we support only RGB case now, otherwise we would need more complicated mechanism of memsize calculation */
+        Assert(!reportedFormat.fourcc());
+        pCmd->SurfInfo.sizeX = (reportedFormat.bitsPerPixel() * surf->width() + 7) / 8 * surf->height();
+        pCmd->SurfInfo.sizeY = 1;
+    }
 
     if(handle != VBOXVHWA_SURFHANDLE_INVALID)
@@ -2495,5 +2517,5 @@
     VBOXQGLLOG_ENTER(("pSurf (0x%x)\n",pSurf));
     vboxCheckUpdateAddress (pSurf, pCmd->u.in.offSurface);
-    if(pCmd->u.in.rectValid)
+    if (pCmd->u.in.rectValid)
     {
         QRect r = VBOXVHWA_CONSTRUCT_QRECT_FROM_RECTL_WH(&pCmd->u.in.rect);
@@ -3665,4 +3687,5 @@
             Assert ((size.bytesPerLine() & 3) == 0);
             fallback = ((size.bytesPerLine() & 3) != 0);
+            Assert(!fallback);
         }
         if (!fallback)
@@ -3671,4 +3694,5 @@
             Assert ((bitsPerLine & (size.bitsPerPixel() - 1)) == 0);
             fallback = ((bitsPerLine & (size.bitsPerPixel() - 1)) != 0);
+            Assert(!fallback);
         }
         if (!fallback)
@@ -3681,4 +3705,5 @@
     else
     {
+        AssertBreakpoint();
         fallback = true;
     }
@@ -3686,4 +3711,6 @@
     if (fallback)
     {
+        /* we should never come to fallback more now */
+        AssertBreakpoint();
         /* we don't support either the pixel format or the color depth,
          * fallback to a self-provided 32bpp RGB buffer */
@@ -3998,5 +4025,5 @@
 }
 
-VBoxQGLOverlay::VBoxQGLOverlay (QWidget *pViewport,QObject *pPostEventObject,  CSession * aSession)
+VBoxQGLOverlay::VBoxQGLOverlay (QWidget *pViewport,QObject *pPostEventObject,  CSession * aSession, uint32_t id)
     : mpOverlayWgt (NULL),
       mpViewport (pViewport),
@@ -4010,5 +4037,6 @@
       mCmdPipe (pPostEventObject),
       mSettings (*aSession),
-      mpSession(aSession)
+      mpSession(aSession),
+      m_id(id)
 {
     /* postpone the gl widget initialization to avoid conflict with 3D on Mac */
@@ -4062,5 +4090,5 @@
         if (mOverlayImage.hasSurfaces())
         {
-            Assert(!mOverlayVisible);
+//            Assert(!mOverlayVisible);
             if (pViewport)
             {
@@ -4068,5 +4096,5 @@
 //            vboxDoCheckUpdateViewport();
             }
-            Assert(!mOverlayVisible);
+//            Assert(!mOverlayVisible);
         }
         mGlCurrent = false;
@@ -4604,5 +4632,5 @@
 {
     PVM pVM = (PVM)pCmd->pVM;
-    uint32_t intsId = 0; /* @todo: set the proper id */
+    uint32_t intsId = m_id;
 
     char nameFuf[sizeof(VBOXQGL_STATE_NAMEBASE) + 8];
Index: trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.h	(revision 27838)
+++ trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.h	(revision 27839)
@@ -226,5 +226,7 @@
     VBoxVHWAColorFormat(uint32_t bitsPerPixel, uint32_t r, uint32_t g, uint32_t b);
     VBoxVHWAColorFormat(uint32_t fourcc);
-    VBoxVHWAColorFormat(){}
+    VBoxVHWAColorFormat() :
+        mBitsPerPixel(0) /* needed for isValid() to work */
+    {}
     GLint internalFormat() const {return mInternalFormat; }
     GLenum format() const {return mFormat; }
@@ -1575,10 +1577,11 @@
 #ifdef VBOX_WITH_VIDEOHWACCEL
 
-    void vboxCheckUpdateAddress (VBoxVHWASurfaceBase * pSurface, uint64_t offset)
+    void vboxCheckUpdateAddress(VBoxVHWASurfaceBase * pSurface, uint64_t offset)
     {
         if (pSurface->addressAlocated())
         {
+            Assert(!mDisplay.isPrimary(pSurface));
             uchar * addr = vboxVRAMAddressFromOffset(offset);
-            if(addr)
+            if (addr)
             {
                 pSurface->setAddress(addr);
@@ -1761,5 +1764,5 @@
 {
 public:
-    VBoxQGLOverlay (QWidget *pViewport, QObject *pPostEventObject, CSession * aSession);
+    VBoxQGLOverlay(QWidget *pViewport, QObject *pPostEventObject, CSession * aSession, uint32_t id);
     ~VBoxQGLOverlay()
     {
@@ -1912,4 +1915,6 @@
 
     QGLWidget *mpShareWgt;
+
+    uint32_t m_id;
 };
 
@@ -1920,7 +1925,7 @@
 {
 public:
-    VBoxOverlayFrameBuffer (V *pView, CSession * aSession)
+    VBoxOverlayFrameBuffer (V *pView, CSession * aSession, uint32_t id)
         : T (pView),
-          mOverlay(pView->viewport(), pView, aSession),
+          mOverlay(pView->viewport(), pView, aSession, id),
           mpView (pView)
     {
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp	(revision 27838)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp	(revision 27839)
@@ -497,5 +497,5 @@
                     /* these two additional template args is a workaround to this [VBox|UI] duplication
                      * @todo: they are to be removed once VBox stuff is gone */
-                    pFramebuffer = new VBoxOverlayFrameBuffer<UIFrameBufferQImage, UIMachineView, UIResizeEvent>(this, &machineWindowWrapper()->session());
+                    pFramebuffer = new VBoxOverlayFrameBuffer<UIFrameBufferQImage, UIMachineView, UIResizeEvent>(this, &machineWindowWrapper()->session(), (uint32_t)screenId());
                     uisession()->setFrameBuffer(screenId(), pFramebuffer);
                 }
@@ -536,5 +536,5 @@
                     /* these two additional template args is a workaround to this [VBox|UI] duplication
                      * @todo: they are to be removed once VBox stuff is gone */
-                    pFramebuffer = new VBoxOverlayFrameBuffer<UIFrameBufferSDL, UIMachineView, UIResizeEvent>(this, &machineWindowWrapper()->session());
+                    pFramebuffer = new VBoxOverlayFrameBuffer<UIFrameBufferSDL, UIMachineView, UIResizeEvent>(this, &machineWindowWrapper()->session(), (uint32_t)screenId());
                     uisession()->setFrameBuffer(screenId(), pFramebuffer);
                 }
@@ -579,5 +579,5 @@
                     /* these two additional template args is a workaround to this [VBox|UI] duplication
                      * @todo: they are to be removed once VBox stuff is gone */
-                    pFramebuffer = new VBoxOverlayFrameBuffer<UIFrameBufferQuartz2D, UIMachineView, UIResizeEvent>(this, &machineWindowWrapper()->session());
+                    pFramebuffer = new VBoxOverlayFrameBuffer<UIFrameBufferQuartz2D, UIMachineView, UIResizeEvent>(this, &machineWindowWrapper()->session(), (uint32_t)screenId());
                     uisession()->setFrameBuffer(screenId(), pFramebuffer);
                 }
