Index: trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.cpp	(revision 27695)
+++ trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.cpp	(revision 27697)
@@ -4184,4 +4184,18 @@
 }
 
+void VBoxQGLOverlay::updateAttachment(QWidget *pViewport, QObject *pPostEventObject)
+{
+    mCmdPipe.updatePostEventObject(pPostEventObject);
+    if (mpViewport != pViewport)
+    {
+        mpViewport = pViewport;
+        mpOverlayWgt = NULL;
+        mOverlayWidgetVisible = false;
+        initGl();
+        vboxDoCheckUpdateViewport();
+        mGlCurrent = false;
+    }
+}
+
 int VBoxQGLOverlay::reset()
 {
Index: trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.h	(revision 27695)
+++ trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.h	(revision 27697)
@@ -1303,4 +1303,5 @@
     class VBoxVHWACommandElement * detachCmdList(class VBoxVHWACommandElement * pFirst2Free, VBoxVHWACommandElement * pLast2Free);
     void reset(class VBoxVHWACommandElement ** ppHead, class VBoxVHWACommandElement ** ppTail);
+    void updatePostEventObject(QObject *m_pObject) { m_pParent = m_pObject; }
 private:
     RTCRITSECT mCritSect;
@@ -1677,5 +1678,5 @@
     }
 
-    void updateViewport(QWidget *pViewport);
+    void updateAttachment(QWidget *pViewport, QObject *pPostEventObject);
 
     int onVHWACommand (struct _VBOXVHWACMD * pCommand);
@@ -1822,7 +1823,13 @@
 {
 public:
+    VBoxOverlayFrameBuffer (V *pView, VBoxQGLOverlay *pOverlay, CSession * aSession)
+        : T (pView),
+          mpOverlay (pOverlay),
+          mpView (pView)
+    {}
+
     VBoxOverlayFrameBuffer (V *pView, QWidget *pWidget, CSession * aSession)
         : T (pView),
-          mOverlay (pWidget, pView, aSession),
+          mpOverlay (new VBoxQGLOverlay(pWidget, pView, aSession)),
           mpView (pView)
     {}
@@ -1831,10 +1838,10 @@
     STDMETHOD(ProcessVHWACommand)(BYTE *pCommand)
     {
-        return mOverlay.onVHWACommand ((struct _VBOXVHWACMD*)pCommand);
+        return mpOverlay->onVHWACommand ((struct _VBOXVHWACMD*)pCommand);
     }
 
     void doProcessVHWACommand (QEvent * pEvent)
     {
-        mOverlay.onVHWACommandEvent (pEvent);
+        mpOverlay->onVHWACommandEvent (pEvent);
     }
 
@@ -1844,5 +1851,5 @@
                               BOOL *aFinished)
    {
-        if (mOverlay.onRequestResize (aScreenId, aPixelFormat,
+        if (mpOverlay->onRequestResize (aScreenId, aPixelFormat,
                 aVRAM, aBitsPerPixel, aBytesPerLine,
                 aWidth, aHeight,
@@ -1860,5 +1867,5 @@
                              ULONG aW, ULONG aH)
     {
-        if (mOverlay.onNotifyUpdate (aX, aY, aW, aH))
+        if (mpOverlay->onNotifyUpdate (aX, aY, aW, aH))
             return S_OK;
         return T::NotifyUpdate (aX, aY, aW, aH);
@@ -1868,5 +1875,5 @@
     {
         T::resizeEvent (re);
-        mOverlay.onResizeEventPostprocess (VBoxFBSizeInfo(re),
+        mpOverlay->onResizeEventPostprocess (VBoxFBSizeInfo(re),
                 QPoint(mpView->contentsX(), mpView->contentsY()));
     }
@@ -1874,5 +1881,5 @@
     void viewportResized (QResizeEvent * re)
     {
-        mOverlay.onViewportResized (re);
+        mpOverlay->onViewportResized (re);
         T::viewportResized (re);
     }
@@ -1880,9 +1887,9 @@
     void viewportScrolled (int dx, int dy)
     {
-        mOverlay.onViewportScrolled (QPoint(mpView->contentsX(), mpView->contentsY()));
+        mpOverlay->onViewportScrolled (QPoint(mpView->contentsX(), mpView->contentsY()));
         T::viewportScrolled (dx, dy);
     }
 private:
-    VBoxQGLOverlay mOverlay;
+    VBoxQGLOverlay *mpOverlay;
     V *mpView;
 };
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp	(revision 27695)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp	(revision 27697)
@@ -488,7 +488,14 @@
         case VBoxDefs::QImageMode:
 # ifdef VBOX_WITH_VIDEOHWACCEL
-            /* these two additional template args is a workaround to this [VBox|UI] duplication
-             * @todo: they are to be removed once VBox stuff is gone */
-            m_pFrameBuffer = m_fAccelerate2DVideo ? new VBoxOverlayFrameBuffer<UIFrameBufferQImage, UIMachineView, UIResizeEvent>(this, viewport(), &machineWindowWrapper()->session()) : new UIFrameBufferQImage(this);
+            if (m_fAccelerate2DVideo)
+            {
+                class VBoxQGLOverlay* pOverlay = uisession()->overlayForScreen(screenId());
+                pOverlay->updateAttachment(viewport(), this);
+                /* these two additional template args is a workaround to this [VBox|UI] duplication
+                 * @todo: they are to be removed once VBox stuff is gone */
+                m_pFrameBuffer = new VBoxOverlayFrameBuffer<UIFrameBufferQImage, UIMachineView, UIResizeEvent>(this, pOverlay, &machineWindowWrapper()->session());
+            }
+            else
+                m_pFrameBuffer = new UIFrameBufferQImage(this);
 # else
             m_pFrameBuffer = new UIFrameBufferQImage(this);
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp	(revision 27695)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp	(revision 27697)
@@ -36,4 +36,7 @@
 #include "VBoxProblemReporter.h"
 #include "UIFirstRunWzd.h"
+#ifdef VBOX_WITH_VIDEOHWACCEL
+# include "VBoxFBOverlay.h"
+#endif
 
 #ifdef Q_WS_X11
@@ -1488,2 +1491,15 @@
 }
 
+#ifdef VBOX_WITH_VIDEOHWACCEL
+/* 2D video overlay state + API */
+class VBoxQGLOverlay* UISession::overlayForScreen(ulong screenId)
+{
+    /* durty hack to fill the list as needed */
+    if (m_OverlaysList.size() <= (int)screenId)
+    {
+        for (int i = m_OverlaysList.size(); i <= (int)screenId; ++i)
+            m_OverlaysList.append(new VBoxQGLOverlay((QWidget *)NULL, (QObject *)NULL, &m_session));
+    }
+    return m_OverlaysList.at((int)screenId);
+}
+#endif
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h	(revision 27695)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h	(revision 27697)
@@ -140,4 +140,9 @@
     void setMouseIntegrated(bool fIsMouseIntegrated) { m_fIsMouseIntegrated = fIsMouseIntegrated; }
 
+#ifdef VBOX_WITH_VIDEOHWACCEL
+    /* 2D video overlay state + API */
+    class VBoxQGLOverlay* overlayForScreen(ulong screenId);
+#endif
+
 signals:
 
@@ -203,4 +208,11 @@
     UIMachineMenuBar *m_pMenuPool;
 
+#ifdef VBOX_WITH_VIDEOHWACCEL
+    /* 2D video overlay state + API
+     * this does not get re-created on mode change
+     * Each screen has its own Overlay state */
+    QList<class VBoxQGLOverlay*> m_OverlaysList;
+#endif
+
     /* Common variables: */
     KMachineState m_machineState;
