Index: /trunk/src/VBox/Frontends/VirtualBox/include/VBoxFrameBuffer.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/include/VBoxFrameBuffer.h	(revision 23898)
+++ /trunk/src/VBox/Frontends/VirtualBox/include/VBoxFrameBuffer.h	(revision 23899)
@@ -475,4 +475,8 @@
     void resizeEvent (VBoxResizeEvent *re);
 
+#ifndef QT_MAC_USE_COCOA
+    void testAndSetSNCarbonFix();
+#endif /* QT_MAC_USE_COCOA */
+
 private:
 
@@ -506,4 +510,9 @@
      * This is operated with atomic cmpxchg and atomic xchg. */
     RegionRects volatile *mRegionUnused;
+
+#ifndef QT_MAC_USE_COCOA
+    bool mSnowLeoCarbonFix;
+    EventHandlerRef mDarwinSNWindowHandlerRef;
+#endif /* QT_MAC_USE_COCOA */
 };
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBQuartz2D.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBQuartz2D.cpp	(revision 23898)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBQuartz2D.cpp	(revision 23899)
@@ -34,5 +34,10 @@
 #include "VBoxIChatTheaterWrapper.h"
 
+#include <QDesktopWidget>
+
+#include "iprt/system.h"
+
 //#define COMP_WITH_SHADOW
+//#define OVERLAY_CLIPRECTS
 
 /** @class VBoxQuartz2DFrameBuffer
@@ -42,14 +47,56 @@
  */
 
-VBoxQuartz2DFrameBuffer::VBoxQuartz2DFrameBuffer (VBoxConsoleView *aView) :
-    VBoxFrameBuffer(aView),
-    mDataAddress(NULL),
-    mBitmapData(NULL),
-    mPixelFormat(FramebufferPixelFormat_FOURCC_RGB),
-    mImage(NULL),
-    mRegion (NULL),
-    mRegionUnused (NULL)
+#ifndef QT_MAC_USE_COCOA
+static OSStatus darwinSNWindowHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData)
+{
+    if (     aInUserData
+        && ::GetEventClass (aInEvent) == kEventClassWindow
+        && ::GetEventKind (aInEvent) == kEventWindowBoundsChanged)
+        static_cast<VBoxQuartz2DFrameBuffer *> (aInUserData)->testAndSetSNCarbonFix();
+
+    return ::CallNextEventHandler (aInHandlerCallRef, aInEvent);
+}
+#endif /* QT_MAC_USE_COCOA */
+
+VBoxQuartz2DFrameBuffer::VBoxQuartz2DFrameBuffer (VBoxConsoleView *aView)
+    : VBoxFrameBuffer(aView)
+    , mDataAddress(NULL)
+    , mBitmapData(NULL)
+    , mPixelFormat(FramebufferPixelFormat_FOURCC_RGB)
+    , mImage(NULL)
+    , mRegion (NULL)
+    , mRegionUnused (NULL)
+#ifndef QT_MAC_USE_COCOA
+    , mSnowLeoCarbonFix (false)
+    , mDarwinSNWindowHandlerRef (NULL)
+#endif /* QT_MAC_USE_COCOA */
 {
     Log (("Quartz2D: Creating\n"));
+
+#ifndef QT_MAC_USE_COCOA
+    /* There seems to be a big bug on Snow Leopard regarding hardware
+     * accelerated image handling in Carbon. If our VM image is used on a
+     * second monitor it seems not really to be valid. (maybe the OpenGL
+     * texture is not properly shared between the two contexts). As a
+     * workaround we make a deep copy on every paint event. This workaround
+     * should only be in place if we are firstly on Snow Leopard and secondly
+     * on any screen beside the primary one. To track the current screen, we
+     * install a event handler for the window move event. Whenever the user
+     * drag the window around we recheck the current screen of the window. */
+    char szInfo[64];
+    int rc = RTSystemQueryOSInfo (RTSYSOSINFO_RELEASE, szInfo, sizeof(szInfo));
+    if (RT_SUCCESS (rc) &&
+        szInfo[0] == '1') /* higher than 1x.x.x */
+    {
+        EventTypeSpec eventTypes[] =
+        {
+            { kEventClassWindow, kEventWindowBoundsChanged }
+        };
+        ::InstallWindowEventHandler (::darwinToNativeWindow (mView->viewport()), darwinSNWindowHandler, RT_ELEMENTS (eventTypes), &eventTypes[0],
+                                     this, &mDarwinSNWindowHandlerRef);
+        /* Initialize it now */
+        testAndSetSNCarbonFix();
+    }
+#endif /* QT_MAC_USE_COCOA */
 
     VBoxResizeEvent event(FramebufferPixelFormat_Opaque,
@@ -62,4 +109,11 @@
     Log (("Quartz2D: Deleting\n"));
     clean();
+#ifndef QT_MAC_USE_COCOA
+    if (mDarwinSNWindowHandlerRef)
+    {
+       ::RemoveEventHandler (mDarwinSNWindowHandlerRef);
+       mDarwinSNWindowHandlerRef = NULL;
+    }
+#endif /* QT_MAC_USE_COCOA */
 }
 
@@ -187,8 +241,24 @@
         }
         else
-            subImage = CGImageCreateWithImageInRect (mImage, CGRectMake (mView->contentsX(), mView->contentsY(), mView->visibleWidth(), mView->visibleHeight()));
+        {
+
+#ifndef QT_MAC_USE_COCOA
+            /* For the reason of this see the constructor. */
+            if (mSnowLeoCarbonFix)
+            {
+                CGImageRef copy = CGImageCreateCopy (mImage);
+                subImage = CGImageCreateWithImageInRect (copy, CGRectMake (mView->contentsX(), mView->contentsY(), mView->visibleWidth(), mView->visibleHeight()));
+                CGImageRelease (copy);
+            }else
+#endif /* QT_MAC_USE_COCOA */
+                subImage = CGImageCreateWithImageInRect (mImage, CGRectMake (mView->contentsX(), mView->contentsY(), mView->visibleWidth(), mView->visibleHeight()));
+        }
         Assert (VALID_PTR (subImage));
         /* Clear the background (Make the rect fully transparent) */
         CGContextClearRect (ctx, viewRect);
+#ifdef OVERLAY_CLIPRECTS
+        CGContextSetRGBFillColor (ctx, 0.0, 0.0, 5.0, 0.7);
+        CGContextFillRect (ctx, viewRect);
+#endif
 #ifdef COMP_WITH_SHADOW
         /* Enable shadows */
@@ -222,4 +292,15 @@
 #endif
         CGImageRelease (subImage);
+#ifdef OVERLAY_CLIPRECTS
+        if (rgnRcts && rgnRcts->used > 0)
+        {
+            CGContextBeginPath (ctx);
+            CGContextAddRects (ctx, rgnRcts->rcts, rgnRcts->used);
+            CGContextSetRGBStrokeColor (ctx, 1.0, 0.0, 0.0, 0.7);
+            CGContextDrawPath (ctx, kCGPathStroke);
+        }
+        CGContextSetRGBStrokeColor (ctx, 0.0, 1.0, 0.0, 0.7);
+        CGContextStrokeRect (ctx, viewRect);
+#endif
     }
     else
@@ -239,5 +320,16 @@
         }
         else
-            subImage = CGImageCreateWithImageInRect (mImage, ::darwinToCGRect (is));
+        {
+#ifndef QT_MAC_USE_COCOA
+            /* For the reason of this see the constructor. */
+            if (mSnowLeoCarbonFix)
+            {
+                CGImageRef copy = CGImageCreateCopy (mImage);
+                subImage = CGImageCreateWithImageInRect (copy, ::darwinToCGRect (is));
+                CGImageRelease (copy);
+            }else
+#endif /* QT_MAC_USE_COCOA */
+                subImage = CGImageCreateWithImageInRect (mImage, ::darwinToCGRect (is));
+        }
         Assert (VALID_PTR (subImage));
         /* Ok, for more performance we set a clipping path of the
@@ -361,3 +453,13 @@
 }
 
+#ifndef QT_MAC_USE_COCOA
+void VBoxQuartz2DFrameBuffer::testAndSetSNCarbonFix()
+{
+    QWidget* viewport = mView->viewport();
+    Assert (VALID_PTR (viewport));
+    QDesktopWidget dw;
+    mSnowLeoCarbonFix = dw.primaryScreen() != dw.screenNumber (viewport);
+}
+#endif /* QT_MAC_USE_COCOA */
+
 #endif /* defined (VBOX_GUI_USE_QUARTZ2D) */
