Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.cpp	(revision 46362)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.cpp	(revision 46364)
@@ -163,5 +163,4 @@
 }
 
-/* This method is called on EMT from under this object's lock! */
 STDMETHODIMP UIFrameBuffer::RequestResize(ULONG uScreenId, ULONG uPixelFormat,
                                           BYTE *pVRAM, ULONG uBitsPerPixel, ULONG uBytesPerLine,
@@ -220,15 +219,4 @@
 }
 
-/**
- * Returns whether we like the given video mode.
- * @note We always like a mode smaller than the current framebuffer
- *       size.
- *
- * @returns COM status code
- * @param   width     video mode width in pixels
- * @param   height    video mode height in pixels
- * @param   bpp       video mode bit depth in bits per pixel
- * @param   supported pointer to result variable
- */
 STDMETHODIMP UIFrameBuffer::VideoModeSupported(ULONG uWidth, ULONG uHeight, ULONG uBPP, BOOL *pbSupported)
 {
@@ -281,27 +269,42 @@
 STDMETHODIMP UIFrameBuffer::SetVisibleRegion(BYTE *pRectangles, ULONG uCount)
 {
+    /* Make sure frame-buffer is not yet scheduled for removal: */
+    if (m_fIsScheduledToDelete)
+        return E_FAIL;
+
+    /* Make sure rectangles were passed: */
     PRTRECT rects = (PRTRECT)pRectangles;
-
     if (!rects)
         return E_POINTER;
 
-    QRegion reg;
-    for (ULONG ind = 0; ind < uCount; ++ ind)
+    /* Compose region: */
+    QRegion region;
+    for (ULONG ind = 0; ind < uCount; ++ind)
     {
+        /* Get current rectangle: */
         QRect rect;
         rect.setLeft(rects->xLeft);
         rect.setTop(rects->yTop);
-        /* QRect are inclusive */
+        /* Which is inclusive: */
         rect.setRight(rects->xRight - 1);
         rect.setBottom(rects->yBottom - 1);
-        reg += rect;
-        ++ rects;
+        /* Append region: */
+        region += rect;
+        ++rects;
     }
-    lock(); /* See comment in setView(). */
-    m_syncVisibleRegion = reg;
-    if (m_pMachineView)
-        QApplication::postEvent(m_pMachineView, new UISetRegionEvent(reg));
-    unlock();
-
+
+    /* See comment in setView(): */
+    lock();
+
+    /* We are directly updating synchronous visible-region: */
+    m_syncVisibleRegion = region;
+    /* And send async signal to update asynchronous one: */
+    if (m_pMachineView)
+        emit sigSetVisibleRegion(region);
+
+    /* Unlock thread finally: */
+    unlock();
+
+    /* Confirm SetVisibleRegion: */
     return S_OK;
 }
@@ -369,4 +372,7 @@
             m_pMachineView, SLOT(sltHandleNotifyUpdate(int, int, int, int)),
             Qt::QueuedConnection);
+    connect(this, SIGNAL(sigSetVisibleRegion(QRegion)),
+            m_pMachineView, SLOT(sltHandleSetVisibleRegion(QRegion)),
+            Qt::QueuedConnection);
 }
 
@@ -377,4 +383,6 @@
     disconnect(this, SIGNAL(sigNotifyUpdate(int, int, int, int)),
                m_pMachineView, SLOT(sltHandleNotifyUpdate(int, int, int, int)));
-}
-
+    disconnect(this, SIGNAL(sigSetVisibleRegion(QRegion)),
+               m_pMachineView, SLOT(sltHandleSetVisibleRegion(QRegion)));
+}
+
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.h	(revision 46362)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.h	(revision 46364)
@@ -67,21 +67,4 @@
 
 /**
- *  Frame buffer set region event.
- */
-class UISetRegionEvent : public QEvent
-{
-public:
-
-    UISetRegionEvent(const QRegion &region)
-        : QEvent((QEvent::Type)SetRegionEventType)
-        , m_region(region) {}
-    QRegion region() { return m_region; }
-
-private:
-
-    QRegion m_region;
-};
-
-/**
  *  Common IFramebuffer implementation for all methods used by GUI to maintain
  *  the VM display video memory.
@@ -115,4 +98,5 @@
                           int iWidth, int iHeight);
     void sigNotifyUpdate(int iX, int iY, int iWidth, int iHeight);
+    void sigSetVisibleRegion(QRegion region);
 
 public:
@@ -206,5 +190,5 @@
     virtual void resizeEvent(UIResizeEvent *pEvent) = 0;
     virtual void paintEvent(QPaintEvent *pEvent) = 0;
-    virtual void applyVisibleRegionEvent(UISetRegionEvent *pEvent) = 0;
+    virtual void applyVisibleRegion(const QRegion &region) = 0;
 
 #ifdef VBOX_WITH_VIDEOHWACCEL
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQImage.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQImage.cpp	(revision 46362)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQImage.cpp	(revision 46364)
@@ -178,14 +178,14 @@
 }
 
-void UIFrameBufferQImage::applyVisibleRegionEvent(UISetRegionEvent *pEvent)
+void UIFrameBufferQImage::applyVisibleRegion(const QRegion &region)
 {
     /* Make sure async visible-region changed: */
-    if (m_asyncVisibleRegion == pEvent->region())
+    if (m_asyncVisibleRegion == region)
         return;
 
     /* We are accounting async visible-regions one-by-one
      * to keep corresponding viewport area always updated! */
-    m_pMachineView->viewport()->update(pEvent->region() + m_asyncVisibleRegion);
-    m_asyncVisibleRegion = pEvent->region();
+    m_pMachineView->viewport()->update(region + m_asyncVisibleRegion);
+    m_asyncVisibleRegion = region;
 
 #ifdef Q_WS_X11
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQImage.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQImage.h	(revision 46362)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQImage.h	(revision 46364)
@@ -47,5 +47,5 @@
     void resizeEvent(UIResizeEvent *pEvent);
     void paintEvent(QPaintEvent *pEvent);
-    void applyVisibleRegionEvent(UISetRegionEvent *pEvent);
+    void applyVisibleRegion(const QRegion &region);
 
 private:
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQuartz2D.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQuartz2D.cpp	(revision 46362)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQuartz2D.cpp	(revision 46364)
@@ -73,8 +73,12 @@
 }
 
-STDMETHODIMP UIFrameBufferQuartz2D::SetVisibleRegion(BYTE *aRectangles, ULONG aCount)
-{
-    PRTRECT rects = (PRTRECT)aRectangles;
-
+STDMETHODIMP UIFrameBufferQuartz2D::SetVisibleRegion(BYTE *pRectangles, ULONG aCount)
+{
+    /* Make sure frame-buffer is not yet scheduled for removal: */
+    if (m_fIsScheduledToDelete)
+        return E_FAIL;
+
+    /* Make sure rectangles were passed: */
+    PRTRECT rects = (PRTRECT)pRectangles;
     if (!rects)
         return E_POINTER;
@@ -103,13 +107,14 @@
     rgnRcts->used = 0;
 
+    /* Compose region: */
     QRegion reg;
-//    printf ("Region rects follow...\n");
-    QRect vmScreenRect (0, 0, width(), height());
+    QRect vmScreenRect(0, 0, width(), height());
     for (ULONG ind = 0; ind < aCount; ++ ind)
     {
+        /* Get current rectangle: */
         QRect rect;
         rect.setLeft(rects->xLeft);
         rect.setTop(rects->yTop);
-        /* QRect are inclusive */
+        /* Which is inclusive: */
         rect.setRight(rects->xRight - 1);
         rect.setBottom(rects->yBottom - 1);
@@ -117,8 +122,6 @@
         /* The rect should intersect with the vm screen. */
         rect = vmScreenRect.intersect(rect);
-        ++ rects;
-        /* Make sure only valid rects are distributed */
-        /* todo: Test if the other framebuffer implementation have the same
-         * problem with invalid rects (In Linux/Windows) */
+        ++rects;
+        /* Make sure only valid rects are distributed: */
         if (rect.isValid() &&
            rect.width() > 0 && rect.height() > 0)
@@ -127,4 +130,5 @@
             continue;
 
+        /* That is some *magic* added by Knut in r27807: */
         CGRect *cgRct = &rgnRcts->rcts[rgnRcts->used];
         cgRct->origin.x = rect.x();
@@ -132,8 +136,6 @@
         cgRct->size.width = rect.width();
         cgRct->size.height = rect.height();
-//        printf ("Region rect[%d - %d]: %d %d %d %d\n", rgnRcts->used, aCount, rect.x(), rect.y(), rect.height(), rect.width());
         rgnRcts->used++;
     }
-//    printf ("..................................\n");
 
     RegionRects *pOld = ASMAtomicXchgPtrT(&mRegion, rgnRcts, RegionRects *);
@@ -142,6 +144,9 @@
         RTMemFree(pOld);
 
-    QApplication::postEvent(m_pMachineView, new UISetRegionEvent (reg));
-
+    /* Send async signal to update asynchronous visible-region: */
+    if (m_pMachineView)
+        emit sigSetVisibleRegion(region);
+
+    /* Confirm SetVisibleRegion: */
     return S_OK;
 }
@@ -463,8 +468,8 @@
 }
 
-void UIFrameBufferQuartz2D::applyVisibleRegionEvent(UISetRegionEvent *pEvent)
+void UIFrameBufferQuartz2D::applyVisibleRegion(const QRegion &region)
 {
     /* Make sure async visible-region changed: */
-    if (m_asyncVisibleRegion == pEvent->region())
+    if (m_asyncVisibleRegion == region)
         return;
 
@@ -472,5 +477,5 @@
      * to invalidate whole the viewport area! */
     ::darwinWindowInvalidateShape(m_pMachineView->viewport());
-    m_asyncVisibleRegion = pEvent->region();
+    m_asyncVisibleRegion = region;
 }
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQuartz2D.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQuartz2D.h	(revision 46362)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQuartz2D.h	(revision 46364)
@@ -50,5 +50,5 @@
     void resizeEvent(UIResizeEvent *pEvent);
     void paintEvent(QPaintEvent *pEvent);
-    void applyVisibleRegionEvent(UISetRegionEvent *pEvent);
+    void applyVisibleRegion(const QRegion &region);
 
 #ifdef VBOX_WITH_VIDEOHWACCEL
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp	(revision 46362)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp	(revision 46364)
@@ -283,4 +283,10 @@
     /* Update corresponding viewport part: */
     viewport()->update(iX - contentsX(), iY - contentsY(), iWidth, iHeight);
+}
+
+void UIMachineView::sltHandleSetVisibleRegion(QRegion region)
+{
+    /* Used only in seamless-mode. */
+    Q_UNUSED(region);
 }
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h	(revision 46362)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h	(revision 46364)
@@ -93,10 +93,13 @@
 
     /* Handler: Frame-buffer RequestResize stuff: */
-    void sltHandleRequestResize(int iPixelFormat, uchar *pVRAM,
+    virtual void sltHandleRequestResize(int iPixelFormat, uchar *pVRAM,
                                 int iBitsPerPixel, int iBytesPerLine,
                                 int iWidth, int iHeight);
 
     /* Handler: Frame-buffer NotifyUpdate stuff: */
-    void sltHandleNotifyUpdate(int iX, int iY, int iWidth, int iHeight);
+    virtual void sltHandleNotifyUpdate(int iX, int iY, int iWidth, int iHeight);
+
+    /* Handler: Frame-buffer SetVisibleRegion stuff: */
+    virtual void sltHandleSetVisibleRegion(QRegion region);
 
     /* Watch dog for desktop resizes: */
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.cpp	(revision 46362)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.cpp	(revision 46364)
@@ -70,19 +70,8 @@
 }
 
-bool UIMachineViewSeamless::event(QEvent *pEvent)
+void UIMachineViewSeamless::sltHandleSetVisibleRegion(QRegion region)
 {
-    switch (pEvent->type())
-    {
-        case SetRegionEventType:
-        {
-            /* Apply new seamless-region: */
-            m_pFrameBuffer->applyVisibleRegionEvent(static_cast<UISetRegionEvent*>(pEvent));
-            return true;
-        }
-
-        default:
-            break;
-    }
-    return UIMachineView::event(pEvent);
+    /* Apply new seamless-region: */
+    m_pFrameBuffer->applyVisibleRegion(region);
 }
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.h	(revision 46362)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.h	(revision 46364)
@@ -39,8 +39,12 @@
     virtual ~UIMachineViewSeamless();
 
+private slots:
+
+    /* Handler: Frame-buffer SetVisibleRegion stuff: */
+    virtual void sltHandleSetVisibleRegion(QRegion region);
+
 private:
 
     /* Event handlers: */
-    bool event(QEvent *pEvent);
     bool eventFilter(QObject *pWatched, QEvent *pEvent);
 
