VirtualBox

Changeset 23899 in vbox


Ignore:
Timestamp:
Oct 20, 2009 11:42:26 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
53690
Message:

FE/Qt4-OSX: fix redraw problem on Snow Leopard/Carbon in a dual screen setup (public bug #4942)

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxFrameBuffer.h

    r23346 r23899  
    475475    void resizeEvent (VBoxResizeEvent *re);
    476476
     477#ifndef QT_MAC_USE_COCOA
     478    void testAndSetSNCarbonFix();
     479#endif /* QT_MAC_USE_COCOA */
     480
    477481private:
    478482
     
    506510     * This is operated with atomic cmpxchg and atomic xchg. */
    507511    RegionRects volatile *mRegionUnused;
     512
     513#ifndef QT_MAC_USE_COCOA
     514    bool mSnowLeoCarbonFix;
     515    EventHandlerRef mDarwinSNWindowHandlerRef;
     516#endif /* QT_MAC_USE_COCOA */
    508517};
    509518
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBQuartz2D.cpp

    r23796 r23899  
    3434#include "VBoxIChatTheaterWrapper.h"
    3535
     36#include <QDesktopWidget>
     37
     38#include "iprt/system.h"
     39
    3640//#define COMP_WITH_SHADOW
     41//#define OVERLAY_CLIPRECTS
    3742
    3843/** @class VBoxQuartz2DFrameBuffer
     
    4247 */
    4348
    44 VBoxQuartz2DFrameBuffer::VBoxQuartz2DFrameBuffer (VBoxConsoleView *aView) :
    45     VBoxFrameBuffer(aView),
    46     mDataAddress(NULL),
    47     mBitmapData(NULL),
    48     mPixelFormat(FramebufferPixelFormat_FOURCC_RGB),
    49     mImage(NULL),
    50     mRegion (NULL),
    51     mRegionUnused (NULL)
     49#ifndef QT_MAC_USE_COCOA
     50static OSStatus darwinSNWindowHandler (EventHandlerCallRef aInHandlerCallRef, EventRef aInEvent, void *aInUserData)
     51{
     52    if (     aInUserData
     53        && ::GetEventClass (aInEvent) == kEventClassWindow
     54        && ::GetEventKind (aInEvent) == kEventWindowBoundsChanged)
     55        static_cast<VBoxQuartz2DFrameBuffer *> (aInUserData)->testAndSetSNCarbonFix();
     56
     57    return ::CallNextEventHandler (aInHandlerCallRef, aInEvent);
     58}
     59#endif /* QT_MAC_USE_COCOA */
     60
     61VBoxQuartz2DFrameBuffer::VBoxQuartz2DFrameBuffer (VBoxConsoleView *aView)
     62    : VBoxFrameBuffer(aView)
     63    , mDataAddress(NULL)
     64    , mBitmapData(NULL)
     65    , mPixelFormat(FramebufferPixelFormat_FOURCC_RGB)
     66    , mImage(NULL)
     67    , mRegion (NULL)
     68    , mRegionUnused (NULL)
     69#ifndef QT_MAC_USE_COCOA
     70    , mSnowLeoCarbonFix (false)
     71    , mDarwinSNWindowHandlerRef (NULL)
     72#endif /* QT_MAC_USE_COCOA */
    5273{
    5374    Log (("Quartz2D: Creating\n"));
     75
     76#ifndef QT_MAC_USE_COCOA
     77    /* There seems to be a big bug on Snow Leopard regarding hardware
     78     * accelerated image handling in Carbon. If our VM image is used on a
     79     * second monitor it seems not really to be valid. (maybe the OpenGL
     80     * texture is not properly shared between the two contexts). As a
     81     * workaround we make a deep copy on every paint event. This workaround
     82     * should only be in place if we are firstly on Snow Leopard and secondly
     83     * on any screen beside the primary one. To track the current screen, we
     84     * install a event handler for the window move event. Whenever the user
     85     * drag the window around we recheck the current screen of the window. */
     86    char szInfo[64];
     87    int rc = RTSystemQueryOSInfo (RTSYSOSINFO_RELEASE, szInfo, sizeof(szInfo));
     88    if (RT_SUCCESS (rc) &&
     89        szInfo[0] == '1') /* higher than 1x.x.x */
     90    {
     91        EventTypeSpec eventTypes[] =
     92        {
     93            { kEventClassWindow, kEventWindowBoundsChanged }
     94        };
     95        ::InstallWindowEventHandler (::darwinToNativeWindow (mView->viewport()), darwinSNWindowHandler, RT_ELEMENTS (eventTypes), &eventTypes[0],
     96                                     this, &mDarwinSNWindowHandlerRef);
     97        /* Initialize it now */
     98        testAndSetSNCarbonFix();
     99    }
     100#endif /* QT_MAC_USE_COCOA */
    54101
    55102    VBoxResizeEvent event(FramebufferPixelFormat_Opaque,
     
    62109    Log (("Quartz2D: Deleting\n"));
    63110    clean();
     111#ifndef QT_MAC_USE_COCOA
     112    if (mDarwinSNWindowHandlerRef)
     113    {
     114       ::RemoveEventHandler (mDarwinSNWindowHandlerRef);
     115       mDarwinSNWindowHandlerRef = NULL;
     116    }
     117#endif /* QT_MAC_USE_COCOA */
    64118}
    65119
     
    187241        }
    188242        else
    189             subImage = CGImageCreateWithImageInRect (mImage, CGRectMake (mView->contentsX(), mView->contentsY(), mView->visibleWidth(), mView->visibleHeight()));
     243        {
     244
     245#ifndef QT_MAC_USE_COCOA
     246            /* For the reason of this see the constructor. */
     247            if (mSnowLeoCarbonFix)
     248            {
     249                CGImageRef copy = CGImageCreateCopy (mImage);
     250                subImage = CGImageCreateWithImageInRect (copy, CGRectMake (mView->contentsX(), mView->contentsY(), mView->visibleWidth(), mView->visibleHeight()));
     251                CGImageRelease (copy);
     252            }else
     253#endif /* QT_MAC_USE_COCOA */
     254                subImage = CGImageCreateWithImageInRect (mImage, CGRectMake (mView->contentsX(), mView->contentsY(), mView->visibleWidth(), mView->visibleHeight()));
     255        }
    190256        Assert (VALID_PTR (subImage));
    191257        /* Clear the background (Make the rect fully transparent) */
    192258        CGContextClearRect (ctx, viewRect);
     259#ifdef OVERLAY_CLIPRECTS
     260        CGContextSetRGBFillColor (ctx, 0.0, 0.0, 5.0, 0.7);
     261        CGContextFillRect (ctx, viewRect);
     262#endif
    193263#ifdef COMP_WITH_SHADOW
    194264        /* Enable shadows */
     
    222292#endif
    223293        CGImageRelease (subImage);
     294#ifdef OVERLAY_CLIPRECTS
     295        if (rgnRcts && rgnRcts->used > 0)
     296        {
     297            CGContextBeginPath (ctx);
     298            CGContextAddRects (ctx, rgnRcts->rcts, rgnRcts->used);
     299            CGContextSetRGBStrokeColor (ctx, 1.0, 0.0, 0.0, 0.7);
     300            CGContextDrawPath (ctx, kCGPathStroke);
     301        }
     302        CGContextSetRGBStrokeColor (ctx, 0.0, 1.0, 0.0, 0.7);
     303        CGContextStrokeRect (ctx, viewRect);
     304#endif
    224305    }
    225306    else
     
    239320        }
    240321        else
    241             subImage = CGImageCreateWithImageInRect (mImage, ::darwinToCGRect (is));
     322        {
     323#ifndef QT_MAC_USE_COCOA
     324            /* For the reason of this see the constructor. */
     325            if (mSnowLeoCarbonFix)
     326            {
     327                CGImageRef copy = CGImageCreateCopy (mImage);
     328                subImage = CGImageCreateWithImageInRect (copy, ::darwinToCGRect (is));
     329                CGImageRelease (copy);
     330            }else
     331#endif /* QT_MAC_USE_COCOA */
     332                subImage = CGImageCreateWithImageInRect (mImage, ::darwinToCGRect (is));
     333        }
    242334        Assert (VALID_PTR (subImage));
    243335        /* Ok, for more performance we set a clipping path of the
     
    361453}
    362454
     455#ifndef QT_MAC_USE_COCOA
     456void VBoxQuartz2DFrameBuffer::testAndSetSNCarbonFix()
     457{
     458    QWidget* viewport = mView->viewport();
     459    Assert (VALID_PTR (viewport));
     460    QDesktopWidget dw;
     461    mSnowLeoCarbonFix = dw.primaryScreen() != dw.screenNumber (viewport);
     462}
     463#endif /* QT_MAC_USE_COCOA */
     464
    363465#endif /* defined (VBOX_GUI_USE_QUARTZ2D) */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette