Index: trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_presenter.cpp
===================================================================
--- trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_presenter.cpp	(revision 51423)
+++ trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_presenter.cpp	(revision 51432)
@@ -2905,11 +2905,78 @@
         }
 
-        if (CrFbIsEnabled(getFramebuffer()))
+        int rc = windowDimensionsSync();
+        if (!RT_SUCCESS(rc))
+        {
+            WARN(("windowDimensionsSync failed rc %d", rc));
+            return rc;
+        }
+
+        return VINF_SUCCESS;
+    }
+
+    virtual int windowSetCompositor(bool fSet)
+    {
+        if (fSet)
+        {
+            const struct VBOXVR_SCR_COMPOSITOR* pCompositor = CrFbGetCompositor(getFramebuffer());
+            return mpWindow->SetCompositor(pCompositor);
+        }
+        return mpWindow->SetCompositor(NULL);
+    }
+
+    virtual int windowCleanup()
+    {
+        int rc = mpWindow->UpdateBegin();
+        if (!RT_SUCCESS(rc))
+        {
+            WARN(("err"));
+            return rc;
+        }
+
+        rc = windowDimensionsSync(true);
+        if (!RT_SUCCESS(rc))
+        {
+            WARN(("err"));
+            mpWindow->UpdateEnd();
+            return rc;
+        }
+
+        rc = windowSetCompositor(false);
+        if (!RT_SUCCESS(rc))
+        {
+            WARN(("err"));
+            mpWindow->UpdateEnd();
+            return rc;
+        }
+
+        mpWindow->UpdateEnd();
+
+        return VINF_SUCCESS;
+    }
+
+    virtual int fbCleanup()
+    {
+        int rc = windowCleanup();
+        if (!RT_SUCCESS(rc))
+        {
+            WARN(("windowCleanup failed"));
+            return rc;
+        }
+        return CrFbDisplayBase::fbCleanup();
+    }
+
+    int windowDimensionsSync(bool fForceCleanup = false)
+    {
+        int rc = VINF_SUCCESS;
+
+        HCR_FRAMEBUFFER hFb = getFramebuffer();
+        if (!fForceCleanup && hFb && CrFbIsEnabled(hFb))
         {
             const RTRECT* pRect = getRect();
-            int rc = mpWindow->SetPosition(pRect->xLeft - mViewportRect.xLeft, pRect->yTop - mViewportRect.yTop);
+
+            rc = mpWindow->SetPosition(pRect->xLeft - mViewportRect.xLeft, pRect->yTop - mViewportRect.yTop);
             if (!RT_SUCCESS(rc))
             {
-                WARN(("SetComposition failed rc %d", rc));
+                WARN(("err"));
                 return rc;
             }
@@ -2920,5 +2987,5 @@
             if (!RT_SUCCESS(rc))
             {
-                WARN(("SetSize failed rc %d", rc));
+                WARN(("err"));
                 return rc;
             }
@@ -2927,25 +2994,22 @@
             if (!RT_SUCCESS(rc))
             {
-                WARN(("SetVisible failed rc %d", rc));
+                WARN(("err"));
                 return rc;
             }
-
-            return VINF_SUCCESS;
-        }
-
-        return mpWindow->SetVisible(false);
-    }
-
-    virtual int windowSetCompositor(bool fSet)
-    {
-        if (fSet)
-        {
-            const struct VBOXVR_SCR_COMPOSITOR* pCompositor = CrFbGetCompositor(getFramebuffer());
-            return mpWindow->SetCompositor(pCompositor);
-        }
-        return mpWindow->SetCompositor(NULL);
-    }
-
-    virtual int windowCleanup()
+        }
+        else
+        {
+            rc = mpWindow->SetVisible(false);
+            if (!RT_SUCCESS(rc))
+            {
+                WARN(("err"));
+                return rc;
+            }
+        }
+
+        return rc;
+    }
+
+    virtual int windowSync()
     {
         int rc = mpWindow->UpdateBegin();
@@ -2956,5 +3020,5 @@
         }
 
-        rc = mpWindow->SetVisible(false);
+        rc = windowSetCompositor(true);
         if (!RT_SUCCESS(rc))
         {
@@ -2964,65 +3028,5 @@
         }
 
-        rc = windowSetCompositor(false);
-        if (!RT_SUCCESS(rc))
-        {
-            WARN(("err"));
-            mpWindow->UpdateEnd();
-            return rc;
-        }
-
-        mpWindow->UpdateEnd();
-
-        return VINF_SUCCESS;
-    }
-
-    virtual int fbCleanup()
-    {
-        int rc = windowCleanup();
-        if (!RT_SUCCESS(rc))
-        {
-            WARN(("windowCleanup failed"));
-            return rc;
-        }
-        return CrFbDisplayBase::fbCleanup();
-    }
-
-    virtual int windowSync()
-    {
-        const RTRECT* pRect = getRect();
-
-        int rc = mpWindow->UpdateBegin();
-        if (!RT_SUCCESS(rc))
-        {
-            WARN(("err"));
-            return rc;
-        }
-
-        rc = windowSetCompositor(true);
-        if (!RT_SUCCESS(rc))
-        {
-            WARN(("err"));
-            mpWindow->UpdateEnd();
-            return rc;
-        }
-
-        rc = mpWindow->SetPosition(pRect->xLeft - mViewportRect.xLeft, pRect->yTop - mViewportRect.yTop);
-        if (!RT_SUCCESS(rc))
-        {
-            WARN(("err"));
-            mpWindow->UpdateEnd();
-            return rc;
-        }
-
-        rc = mpWindow->SetSize((uint32_t)(pRect->xRight - pRect->xLeft), (uint32_t)(pRect->yBottom - pRect->yTop));
-        if (!RT_SUCCESS(rc))
-        {
-            WARN(("err"));
-            mpWindow->UpdateEnd();
-            return rc;
-        }
-
-        HCR_FRAMEBUFFER hFb = getFramebuffer();
-        rc = mpWindow->SetVisible(hFb && CrFbIsEnabled(hFb) && !g_CrPresenter.fWindowsForceHidden);
+        rc = windowDimensionsSync();
         if (!RT_SUCCESS(rc))
         {
@@ -4610,7 +4614,8 @@
     g_CrPresenter.u32DisplayMode = u32DisplayMode;
 
-    for (HCR_FRAMEBUFFER hFb = CrPMgrFbGetFirstEnabled();
+    /* disabled framebuffers may still have displays attached */
+    for (HCR_FRAMEBUFFER hFb = CrPMgrFbGetFirstInitialized();
             hFb;
-            hFb = CrPMgrFbGetNextEnabled(hFb))
+            hFb = CrPMgrFbGetNextInitialized(hFb))
     {
         crPMgrModeModify(hFb, u32ModeAdd, u32ModeRemove);
@@ -4794,22 +4799,41 @@
 
     VBOXCMDVBVA_SCREENMAP_DECL(uint32_t, aRemovedTargetMap);
+    VBOXCMDVBVA_SCREENMAP_DECL(uint32_t, aAddedTargetMap);
+
     bool fDisplaysAdded = false, fDisplaysRemoved = false;
 
     memcpy(aRemovedTargetMap, pFbInfo->aTargetMap, sizeof (aRemovedTargetMap));
-    for (int i = 0; i < RT_ELEMENTS(aRemovedTargetMap); ++i)
-    {
-        aRemovedTargetMap[i] = (aRemovedTargetMap[i] & ~pTargetMap[i]);
-        if (aRemovedTargetMap[i])
-            fDisplaysRemoved = true;
-    }
-
-    VBOXCMDVBVA_SCREENMAP_DECL(uint32_t, aAddedTargetMap);
-
-    memcpy(aAddedTargetMap, pFbInfo->aTargetMap, sizeof (aAddedTargetMap));
-    for (int i = 0; i < RT_ELEMENTS(aAddedTargetMap); ++i)
-    {
-        aAddedTargetMap[i] = (pTargetMap[i] & ~aAddedTargetMap[i]);
-        if (aAddedTargetMap[i])
-            fDisplaysAdded = true;
+
+    if (pScreen->u16Flags & VBVA_SCREEN_F_DISABLED)
+    {
+        /* so far there is no need in keeping displays attached to disabled Framebffer,
+         * just disconnect everything */
+        for (int i = 0; i < RT_ELEMENTS(aRemovedTargetMap); ++i)
+        {
+            if (aRemovedTargetMap[i])
+            {
+                fDisplaysRemoved = true;
+                break;
+            }
+        }
+
+        memset(aAddedTargetMap, 0, sizeof (aAddedTargetMap));
+    }
+    else
+    {
+        for (int i = 0; i < RT_ELEMENTS(aRemovedTargetMap); ++i)
+        {
+            aRemovedTargetMap[i] = (aRemovedTargetMap[i] & ~pTargetMap[i]);
+            if (aRemovedTargetMap[i])
+                fDisplaysRemoved = true;
+        }
+
+        memcpy(aAddedTargetMap, pFbInfo->aTargetMap, sizeof (aAddedTargetMap));
+        for (int i = 0; i < RT_ELEMENTS(aAddedTargetMap); ++i)
+        {
+            aAddedTargetMap[i] = (pTargetMap[i] & ~aAddedTargetMap[i]);
+            if (aAddedTargetMap[i])
+                fDisplaysAdded = true;
+        }
     }
 
