VirtualBox

Changeset 26781 in vbox


Ignore:
Timestamp:
Feb 25, 2010 11:11:32 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
58046
Message:

FE/Qt4: new core: Quartz2D up again

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r26737 r26781  
    490490        src/runtime/UIIndicatorsPool.cpp \
    491491        src/runtime/UIFrameBuffer.cpp \
     492        src/runtime/UIFrameBufferQuartz2D.cpp \
    492493        src/runtime/UIMachine.cpp \
    493494        src/runtime/UIMachineLogic.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.h

    r26709 r26781  
    431431
    432432#endif
    433 #if defined (Q_WS_MAC) && defined (VBOX_GUI_USE_QUARTZ2D)
    434 #include <Carbon/Carbon.h>
    435 
    436 class UIFrameBufferQuartz2D : public UIFrameBuffer
    437 {
    438 public:
    439 
    440     UIFrameBufferQuartz2D(UIMachineView *pMachineView);
    441     virtual ~UIFrameBufferQuartz2D();
    442 
    443     STDMETHOD (NotifyUpdate) (ULONG uX, ULONG uY, ULONG uW, ULONG uH);
    444     STDMETHOD (SetVisibleRegion) (BYTE *pRectangles, ULONG uCount);
    445 
    446     uchar* address() { return m_pDataAddress; }
    447     ulong bitsPerPixel() { return CGImageGetBitsPerPixel(m_image); }
    448     ulong bytesPerLine() { return CGImageGetBytesPerRow(m_image); }
    449     ulong pixelFormat() { return m_uPixelFormat; };
    450     bool usesGuestVRAM() { return m_pBitmapData == NULL; }
    451 
    452     const CGImageRef imageRef() const { return m_image; }
    453 
    454     void paintEvent(QPaintEvent *pEvent);
    455     void resizeEvent(UIResizeEvent *pEvent);
    456 
    457 #ifndef QT_MAC_USE_COCOA
    458     void testAndSetSNCarbonFix();
    459 #endif /* QT_MAC_USE_COCOA */
    460 
    461 private:
    462 
    463     void clean();
    464 
    465     uchar *m_pDataAddress;
    466     void *m_pBitmapData;
    467     ulong m_uPixelFormat;
    468     CGImageRef m_image;
    469     typedef struct
    470     {
    471         /** The size of this structure expressed in rcts entries. */
    472         ULONG allocated;
    473         /** The number of entries in the rcts array. */
    474         ULONG used;
    475         /** Variable sized array of the rectangle that makes up the region. */
    476         CGRect rcts[1];
    477     } RegionRects;
    478     /** The current valid region, all access is by atomic cmpxchg or atomic xchg.
    479      *
    480      * The protocol for updating and using this has to take into account that
    481      * the producer (SetVisibleRegion) and consumer (paintEvent) are running
    482      * on different threads. Therefore the producer will create a new RegionRects
    483      * structure before atomically replace the existing one. While the consumer
    484      * will read the value by atomically replace it by NULL, and then when its
    485      * done try restore it by cmpxchg. If the producer has already put a new
    486      * region there, it will be discarded (see mRegionUnused).
    487      */
    488     RegionRects volatile *mRegion;
    489     /** For keeping the unused region and thus avoid some RTMemAlloc/RTMemFree calls.
    490      * This is operated with atomic cmpxchg and atomic xchg. */
    491     RegionRects volatile *mRegionUnused;
    492 
    493 #ifndef QT_MAC_USE_COCOA
    494     bool mSnowLeoCarbonFix;
    495     EventHandlerRef mDarwinSNWindowHandlerRef;
    496 #endif /* QT_MAC_USE_COCOA */
    497 };
    498 #endif /* Q_WS_MAC && VBOX_GUI_USE_QUARTZ2D */
    499433
    500434#endif // !___UIFrameBuffer_h___
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQuartz2D.cpp

    r26777 r26781  
    11/* $Id$ */
    22/** @file
    3  * Qt GUI (aka VirtualBox) - Quartz2D framebuffer implementation.
     3 *
     4 * VBox frontends: Qt GUI ("VirtualBox"):
     5 * UIFrameBufferQuartz2D class implementation
    46 */
    57
    68/*
    7  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     9 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
    810 *
    911 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2527# include "precomp.h"
    2628#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
     29/* Global includes */
     30#include <QApplication>
     31
    2732#include <iprt/asm.h>
    2833
    29 /* VBox includes */
    30 #include "VBoxFrameBuffer.h"
    31 #include "VBoxConsoleView.h"
    32 #include "VBoxProblemReporter.h"
    33 #include "VBoxGlobal.h"
     34/* Local includes */
     35#include "UIFrameBufferQuartz2D.h"
     36#include "UIMachineView.h"
    3437#include "VBoxUtils.h"
    35 /* Needed for checking against seamless mode */
    36 #include "VBoxConsoleWnd.h"
    37 #include "VBoxIChatTheaterWrapper.h"
    38 
    39 #include <QDesktopWidget>
    40 
    41 #include "iprt/system.h"
     38
     39///* Needed for checking against seamless mode */
     40//#include "VBoxConsoleWnd.h"
     41//#include "VBoxIChatTheaterWrapper.h"
     42
    4243#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4344
     
    4546//#define OVERLAY_CLIPRECTS
    4647
    47 /** @class VBoxQuartz2DFrameBuffer
     48/** @class UIFrameBufferQuartz2D
    4849 *
    49  *  The VBoxQuartz2dFrameBuffer class is a class that implements the IFrameBuffer
     50 *  The UIFrameBufferQuartz2D class is a class that implements the IFrameBuffer
    5051 *  interface and uses Apples Quartz2D to store and render VM display data.
    5152 */
     
    5758        && ::GetEventClass (aInEvent) == kEventClassWindow
    5859        && ::GetEventKind (aInEvent) == kEventWindowBoundsChanged)
    59         static_cast<VBoxQuartz2DFrameBuffer *> (aInUserData)->testAndSetSNCarbonFix();
     60        static_cast<UIFrameBufferQuartz2D *> (aInUserData)->testAndSetSNCarbonFix();
    6061
    6162    return ::CallNextEventHandler (aInHandlerCallRef, aInEvent);
     
    6364#endif /* QT_MAC_USE_COCOA */
    6465
    65 VBoxQuartz2DFrameBuffer::VBoxQuartz2DFrameBuffer (VBoxConsoleView *aView)
    66     : VBoxFrameBuffer(aView)
    67     , mDataAddress(NULL)
    68     , mBitmapData(NULL)
    69     , mPixelFormat(FramebufferPixelFormat_FOURCC_RGB)
    70     , mImage(NULL)
     66UIFrameBufferQuartz2D::UIFrameBufferQuartz2D(UIMachineView *pMachineView)
     67    : UIFrameBuffer(pMachineView)
     68    , m_pDataAddress(NULL)
     69    , m_pBitmapData(NULL)
     70    , m_uPixelFormat(FramebufferPixelFormat_FOURCC_RGB)
     71    , m_image(NULL)
    7172    , mRegion (NULL)
    7273    , mRegionUnused (NULL)
     
    9798            { kEventClassWindow, kEventWindowBoundsChanged }
    9899        };
    99         ::InstallWindowEventHandler (::darwinToNativeWindow (mView->viewport()), darwinSNWindowHandler, RT_ELEMENTS (eventTypes), &eventTypes[0],
     100        ::InstallWindowEventHandler (::darwinToNativeWindow (m_pMachineView->viewport()), darwinSNWindowHandler, RT_ELEMENTS (eventTypes), &eventTypes[0],
    100101                                     this, &mDarwinSNWindowHandlerRef);
    101102        /* Initialize it now */
     
    104105#endif /* QT_MAC_USE_COCOA */
    105106
    106     VBoxResizeEvent event(FramebufferPixelFormat_Opaque,
    107                           NULL, 0, 0, 640, 480);
     107    UIResizeEvent event(FramebufferPixelFormat_Opaque,
     108                        NULL, 0, 0, 640, 480);
    108109    resizeEvent (&event);
    109110}
    110111
    111 VBoxQuartz2DFrameBuffer::~VBoxQuartz2DFrameBuffer()
     112UIFrameBufferQuartz2D::~UIFrameBufferQuartz2D()
    112113{
    113114    Log (("Quartz2D: Deleting\n"));
     
    123124
    124125/** @note This method is called on EMT from under this object's lock */
    125 STDMETHODIMP VBoxQuartz2DFrameBuffer::NotifyUpdate (ULONG aX, ULONG aY,
     126STDMETHODIMP UIFrameBufferQuartz2D::NotifyUpdate (ULONG aX, ULONG aY,
    126127                                                 ULONG aW, ULONG aH)
    127128{
    128129/*    Log (("Quartz2D: NotifyUpdate %d,%d %dx%d\n", aX, aY, aW, aH));*/
    129130
    130     QApplication::postEvent (mView,
    131                              new VBoxRepaintEvent (aX, aY, aW, aH));
     131    QApplication::postEvent (m_pMachineView,
     132                             new UIRepaintEvent (aX, aY, aW, aH));
    132133    return S_OK;
    133134}
    134135
    135 STDMETHODIMP VBoxQuartz2DFrameBuffer::SetVisibleRegion (BYTE *aRectangles, ULONG aCount)
     136STDMETHODIMP UIFrameBufferQuartz2D::SetVisibleRegion (BYTE *aRectangles, ULONG aCount)
    136137{
    137138    PRTRECT rects = (PRTRECT)aRectangles;
     
    202203        RTMemFree (pvOld);
    203204
    204     QApplication::postEvent (mView, new VBoxSetRegionEvent (reg));
     205    QApplication::postEvent (m_pMachineView, new UISetRegionEvent (reg));
    205206
    206207    return S_OK;
    207208}
    208209
    209 void VBoxQuartz2DFrameBuffer::paintEvent (QPaintEvent *aEvent)
     210void UIFrameBufferQuartz2D::paintEvent (QPaintEvent *aEvent)
    210211{
    211212    /* For debugging /Developer/Applications/Performance Tools/Quartz
     
    213214     * updated.*/
    214215
    215     Assert (mImage);
    216 
    217     VBoxConsoleWnd *main = qobject_cast <VBoxConsoleWnd *> (vboxGlobal().mainWindow());
    218     Assert (VALID_PTR (main));
    219     QWidget* viewport = mView->viewport();
     216    Assert (m_image);
     217
     218//    VBoxConsoleWnd *main = qobject_cast <VBoxConsoleWnd *> (vboxGlobal().mainWindow());
     219//    Assert (VALID_PTR (main));
     220    QWidget* viewport = m_pMachineView->viewport();
    220221    Assert (VALID_PTR (viewport));
    221222    /* Get the dimensions of the viewport */
     
    230231
    231232    /* We handle the seamless mode as a special case. */
    232     if (main->isTrueSeamless())
     233//    if (main->isTrueSeamless())
     234    if (0)
    233235    {
    234236        /* Here we paint the windows without any wallpaper.
     
    238240         * Currently this subimage is the whole screen. */
    239241        CGImageRef subImage;
    240         if (!mView->pauseShot().isNull())
    241         {
    242             CGImageRef pauseImg = ::darwinToCGImageRef (&mView->pauseShot());
    243             subImage = CGImageCreateWithImageInRect (pauseImg, CGRectMake (mView->contentsX(), mView->contentsY(), mView->visibleWidth(), mView->visibleHeight()));
     242        if (!m_pMachineView->pauseShot().isNull())
     243        {
     244            CGImageRef pauseImg = ::darwinToCGImageRef (&m_pMachineView->pauseShot());
     245            subImage = CGImageCreateWithImageInRect (pauseImg, CGRectMake (m_pMachineView->contentsX(), m_pMachineView->contentsY(), m_pMachineView->visibleWidth(), m_pMachineView->visibleHeight()));
    244246            CGImageRelease (pauseImg);
    245247        }
     
    251253            if (mSnowLeoCarbonFix)
    252254            {
    253                 CGImageRef copy = CGImageCreateCopy (mImage);
    254                 subImage = CGImageCreateWithImageInRect (copy, CGRectMake (mView->contentsX(), mView->contentsY(), mView->visibleWidth(), mView->visibleHeight()));
     255                CGImageRef copy = CGImageCreateCopy (m_image);
     256                subImage = CGImageCreateWithImageInRect (copy, CGRectMake (m_pMachineView->contentsX(), m_pMachineView->contentsY(), m_pMachineView->visibleWidth(), m_pMachineView->visibleHeight()));
    255257                CGImageRelease (copy);
    256258            }else
    257259#endif /* QT_MAC_USE_COCOA */
    258                 subImage = CGImageCreateWithImageInRect (mImage, CGRectMake (mView->contentsX(), mView->contentsY(), mView->visibleWidth(), mView->visibleHeight()));
     260                subImage = CGImageCreateWithImageInRect (m_image, CGRectMake (m_pMachineView->contentsX(), m_pMachineView->contentsY(), m_pMachineView->visibleWidth(), m_pMachineView->visibleHeight()));
    259261        }
    260262        Assert (VALID_PTR (subImage));
     
    315317         * of the bounding box of the current paint event */
    316318        QRect ir = aEvent->rect();
    317         QRect is = QRect (ir.x() + mView->contentsX(), ir.y() + mView->contentsY(), ir.width(), ir.height());
     319        QRect is = QRect (ir.x() + m_pMachineView->contentsX(), ir.y() + m_pMachineView->contentsY(), ir.width(), ir.height());
    318320        CGImageRef subImage;
    319         if (!mView->pauseShot().isNull())
    320         {
    321             CGImageRef pauseImg = ::darwinToCGImageRef (&mView->pauseShot());
     321        if (!m_pMachineView->pauseShot().isNull())
     322        {
     323            CGImageRef pauseImg = ::darwinToCGImageRef (&m_pMachineView->pauseShot());
    322324            subImage = CGImageCreateWithImageInRect (pauseImg, ::darwinToCGRect (is));
    323325            CGImageRelease (pauseImg);
     
    329331            if (mSnowLeoCarbonFix)
    330332            {
    331                 CGImageRef copy = CGImageCreateCopy (mImage);
     333                CGImageRef copy = CGImageCreateCopy (m_image);
    332334                subImage = CGImageCreateWithImageInRect (copy, ::darwinToCGRect (is));
    333335                CGImageRelease (copy);
    334336            }else
    335337#endif /* QT_MAC_USE_COCOA */
    336                 subImage = CGImageCreateWithImageInRect (mImage, ::darwinToCGRect (is));
     338                subImage = CGImageCreateWithImageInRect (m_image, ::darwinToCGRect (is));
    337339        }
    338340        Assert (VALID_PTR (subImage));
     
    359361}
    360362
    361 void VBoxQuartz2DFrameBuffer::resizeEvent (VBoxResizeEvent *aEvent)
     363void UIFrameBufferQuartz2D::resizeEvent (UIResizeEvent *aEvent)
    362364{
    363365#if 0
     
    371373    clean();
    372374
    373     mWdt = aEvent->width();
    374     mHgt = aEvent->height();
     375    m_width = aEvent->width();
     376    m_height = aEvent->height();
    375377
    376378    bool remind = false;
     
    386388//        printf ("VRAM\n");
    387389        /* Create the image copy of the framebuffer */
    388         CGDataProviderRef dp = CGDataProviderCreateWithData (NULL, aEvent->VRAM(), aEvent->bitsPerPixel() / 8 * mWdt * mHgt, NULL);
    389         mImage = CGImageCreate (mWdt, mHgt, 8, aEvent->bitsPerPixel(), aEvent->bytesPerLine(), cs,
     390        CGDataProviderRef dp = CGDataProviderCreateWithData (NULL, aEvent->VRAM(), aEvent->bitsPerPixel() / 8 * m_width * m_height, NULL);
     391        m_image = CGImageCreate (m_width, m_height, 8, aEvent->bitsPerPixel(), aEvent->bytesPerLine(), cs,
    390392                                kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little, dp, 0, false,
    391393                                kCGRenderingIntentDefault);
    392         mDataAddress = aEvent->VRAM();
     394        m_pDataAddress = aEvent->VRAM();
    393395        CGDataProviderRelease (dp);
    394396    }
     
    400402         * Read somewhere that an alignment of 16 is
    401403         * best for optimal performance. So why not. */
    402 //        int bitmapBytesPerRow = RT_ALIGN (mWdt * 4, 16);
    403         int bitmapBytesPerRow = mWdt * 4;
    404         int bitmapByteCount = (bitmapBytesPerRow * mHgt);
    405         mBitmapData = RTMemAlloc (bitmapByteCount);
    406         CGDataProviderRef dp = CGDataProviderCreateWithData (NULL, mBitmapData, bitmapByteCount, NULL);
    407         mImage = CGImageCreate (mWdt, mHgt, 8, 32, bitmapBytesPerRow, cs,
     404//        int bitmapBytesPerRow = RT_ALIGN (m_width * 4, 16);
     405        int bitmapBytesPerRow = m_width * 4;
     406        int bitmapByteCount = (bitmapBytesPerRow * m_height);
     407        m_pBitmapData = RTMemAlloc (bitmapByteCount);
     408        CGDataProviderRef dp = CGDataProviderCreateWithData (NULL, m_pBitmapData, bitmapByteCount, NULL);
     409        m_image = CGImageCreate (m_width, m_height, 8, 32, bitmapBytesPerRow, cs,
    408410                               kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little, dp, 0, false,
    409411                               kCGRenderingIntentDefault);
    410         mDataAddress = static_cast <uchar*> (mBitmapData);
     412        m_pDataAddress = static_cast <uchar*> (m_pBitmapData);
    411413        CGDataProviderRelease (dp);
    412414    }
    413415    CGColorSpaceRelease (cs);
    414416#ifdef VBOX_WITH_ICHAT_THEATER
    415     setImageRef (mImage);
     417    setImageRef (m_image);
    416418#endif
    417419
     
    433435}
    434436
    435 void VBoxQuartz2DFrameBuffer::clean()
    436 {
    437     if (mImage)
    438     {
    439         CGImageRelease (mImage);
    440         mImage = NULL;
    441     }
    442     if (mBitmapData)
    443     {
    444         RTMemFree (mBitmapData);
    445         mBitmapData = NULL;
     437void UIFrameBufferQuartz2D::clean()
     438{
     439    if (m_image)
     440    {
     441        CGImageRelease (m_image);
     442        m_image = NULL;
     443    }
     444    if (m_pBitmapData)
     445    {
     446        RTMemFree (m_pBitmapData);
     447        m_pBitmapData = NULL;
    446448    }
    447449    if (mRegion)
     
    458460
    459461#ifndef QT_MAC_USE_COCOA
    460 void VBoxQuartz2DFrameBuffer::testAndSetSNCarbonFix()
    461 {
    462     QWidget* viewport = mView->viewport();
     462void UIFrameBufferQuartz2D::testAndSetSNCarbonFix()
     463{
     464    QWidget* viewport = m_pMachineView->viewport();
    463465    Assert (VALID_PTR (viewport));
    464466    QDesktopWidget dw;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQuartz2D.h

    r26777 r26781  
    22 *
    33 * VBox frontends: Qt GUI ("VirtualBox"):
    4  * UIFrameBuffer class and subclasses declarations
     4 * UIFrameBufferQuartz2D class declarations
    55 */
    66
     
    2121 */
    2222
    23 #ifndef ___UIFrameBuffer_h___
    24 #define ___UIFrameBuffer_h___
     23#ifndef ___UIFrameBufferQuartz2D_h___
     24#define ___UIFrameBufferQuartz2D_h___
    2525
    26 /* Global includes */
    27 //#include <QImage>
    28 #include <QPixmap>
    29 //#include <QMutex>
    30 #include <QPaintEvent>
    31 //#include <QMoveEvent>
    32 //#if defined (VBOX_GUI_USE_QGL)
    33 //#include "VBoxFBOverlay.h"
    34 //#endif
     26#include <QtGlobal>
    3527
    36 /* Local includes */
    37 #include "COMDefs.h"
    38 #include <iprt/critsect.h>
     28#if defined (Q_WS_MAC) && defined (VBOX_GUI_USE_QUARTZ2D)
    3929
    40 //#if defined (VBOX_GUI_USE_SDL)
    41 //#include <SDL.h>
    42 //#include <signal.h>
    43 //#endif
     30#include "UIFrameBuffer.h"
    4431
    45 //#if defined (Q_WS_WIN) && defined (VBOX_GUI_USE_DDRAW)
    46 // VBox/cdefs.h defines these:
    47 //#undef LOWORD
    48 //#undef HIWORD
    49 //#undef LOBYTE
    50 //#undef HIBYTE
    51 //#include <ddraw.h>
    52 //#endif
    53 
    54 class UIMachineView;
    55 
    56 /**
    57  *  Frame buffer resize event.
    58  */
    59 class UIResizeEvent : public QEvent
    60 {
    61 public:
    62 
    63     UIResizeEvent(ulong uPixelFormat, uchar *pVRAM,
    64                   ulong uBitsPerPixel, ulong uBytesPerLine,
    65                   ulong uWidth, ulong uHeight)
    66         : QEvent((QEvent::Type)VBoxDefs::ResizeEventType)
    67         , m_uPixelFormat(uPixelFormat), m_pVRAM(pVRAM), m_uBitsPerPixel(uBitsPerPixel)
    68         , m_uBytesPerLine(uBytesPerLine), m_uWidth(uWidth), m_uHeight(uHeight) {}
    69     ulong pixelFormat() { return m_uPixelFormat; }
    70     uchar *VRAM() { return m_pVRAM; }
    71     ulong bitsPerPixel() { return m_uBitsPerPixel; }
    72     ulong bytesPerLine() { return m_uBytesPerLine; }
    73     ulong width() { return m_uWidth; }
    74     ulong height() { return m_uHeight; }
    75 
    76 private:
    77 
    78     ulong m_uPixelFormat;
    79     uchar *m_pVRAM;
    80     ulong m_uBitsPerPixel;
    81     ulong m_uBytesPerLine;
    82     ulong m_uWidth;
    83     ulong m_uHeight;
    84 };
    85 
    86 /**
    87  *  Frame buffer repaint event.
    88  */
    89 class UIRepaintEvent : public QEvent
    90 {
    91 public:
    92 
    93     UIRepaintEvent(int iX, int iY, int iW, int iH)
    94         : QEvent((QEvent::Type)VBoxDefs::RepaintEventType)
    95         , m_iX(iX), m_iY(iY), m_iW(iW), m_iH(iH) {}
    96     int x() { return m_iX; }
    97     int y() { return m_iY; }
    98     int width() { return m_iW; }
    99     int height() { return m_iH; }
    100 
    101 private:
    102 
    103     int m_iX, m_iY, m_iW, m_iH;
    104 };
    105 
    106 /**
    107  *  Frame buffer set region event.
    108  */
    109 class UISetRegionEvent : public QEvent
    110 {
    111 public:
    112 
    113     UISetRegionEvent(const QRegion &region)
    114         : QEvent((QEvent::Type)VBoxDefs::SetRegionEventType)
    115         , m_region(region) {}
    116     QRegion region() { return m_region; }
    117 
    118 private:
    119 
    120     QRegion m_region;
    121 };
    122 
    123 /**
    124  *  Common IFramebuffer implementation for all methods used by GUI to maintain
    125  *  the VM display video memory.
    126  *
    127  *  Note that although this class can be called from multiple threads
    128  *  (in particular, the GUI thread and EMT) it doesn't protect access to every
    129  *  data field using its mutex lock. This is because all synchronization between
    130  *  the GUI and the EMT thread is supposed to be done using the
    131  *  IFramebuffer::NotifyUpdate() and IFramebuffer::RequestResize() methods
    132  *  (in particular, the \a aFinished parameter of these methods is responsible
    133  *  for the synchronization). These methods are always called on EMT and
    134  *  therefore always follow one another but never in parallel.
    135  *
    136  *  Using this object's mutex lock (exposed also in IFramebuffer::Lock() and
    137  *  IFramebuffer::Unlock() implementations) usually makes sense only if some
    138  *  third-party thread (i.e. other than GUI or EMT) needs to make sure that
    139  *  *no* VM display update or resize event can occur while it is accessing
    140  *  IFramebuffer properties or the underlying display memory storage area.
    141  *
    142  *  See IFramebuffer documentation for more info.
    143  */
    144 class UIFrameBuffer : VBOX_SCRIPTABLE_IMPL(IFramebuffer)
    145 {
    146 public:
    147 
    148     UIFrameBuffer(UIMachineView *aView);
    149     virtual ~UIFrameBuffer();
    150 
    151     NS_DECL_ISUPPORTS
    152 
    153 #if defined (Q_OS_WIN32)
    154     STDMETHOD_(ULONG, AddRef)()
    155     {
    156         return ::InterlockedIncrement(&m_iRefCnt);
    157     }
    158 
    159     STDMETHOD_(ULONG, Release)()
    160     {
    161         long cnt = ::InterlockedDecrement(&m_iRefCnt);
    162         if (cnt == 0)
    163             delete this;
    164         return cnt;
    165     }
    166 #endif
    167 
    168     VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
    169 
    170     /* IFramebuffer COM methods */
    171     STDMETHOD(COMGETTER(Address)) (BYTE **ppAddress);
    172     STDMETHOD(COMGETTER(Width)) (ULONG *puWidth);
    173     STDMETHOD(COMGETTER(Height)) (ULONG *puHeight);
    174     STDMETHOD(COMGETTER(BitsPerPixel)) (ULONG *puBitsPerPixel);
    175     STDMETHOD(COMGETTER(BytesPerLine)) (ULONG *puBytesPerLine);
    176     STDMETHOD(COMGETTER(PixelFormat)) (ULONG *puPixelFormat);
    177     STDMETHOD(COMGETTER(UsesGuestVRAM)) (BOOL *pbUsesGuestVRAM);
    178     STDMETHOD(COMGETTER(HeightReduction)) (ULONG *puHeightReduction);
    179     STDMETHOD(COMGETTER(Overlay)) (IFramebufferOverlay **ppOverlay);
    180     STDMETHOD(COMGETTER(WinId)) (ULONG64 *pWinId);
    181 
    182     STDMETHOD(Lock)();
    183     STDMETHOD(Unlock)();
    184 
    185     STDMETHOD(RequestResize) (ULONG uScreenId, ULONG uPixelFormat,
    186                               BYTE *pVRAM, ULONG uBitsPerPixel, ULONG uBytesPerLine,
    187                               ULONG uWidth, ULONG uHeight,
    188                               BOOL *pbFinished);
    189 
    190     STDMETHOD(VideoModeSupported) (ULONG uWidth, ULONG uHeight, ULONG uBPP,
    191                                    BOOL *pbSupported);
    192 
    193     STDMETHOD(GetVisibleRegion)(BYTE *pRectangles, ULONG uCount, ULONG *puCountCopied);
    194     STDMETHOD(SetVisibleRegion)(BYTE *pRectangles, ULONG uCount);
    195 
    196     STDMETHOD(ProcessVHWACommand)(BYTE *pCommand);
    197 
    198     ulong width() { return m_width; }
    199     ulong height() { return m_height; }
    200 
    201     virtual ulong pixelFormat()
    202     {
    203         return FramebufferPixelFormat_FOURCC_RGB;
    204     }
    205 
    206     virtual bool usesGuestVRAM()
    207     {
    208         return false;
    209     }
    210 
    211     void lock() { RTCritSectEnter(&m_critSect); }
    212     void unlock() { RTCritSectLeave(&m_critSect); }
    213 
    214     virtual uchar *address() = 0;
    215     virtual ulong bitsPerPixel() = 0;
    216     virtual ulong bytesPerLine() = 0;
    217 
    218     /**
    219      *  Called on the GUI thread (from VBoxConsoleView) when some part of the
    220      *  VM display viewport needs to be repainted on the host screen.
    221      */
    222     virtual void paintEvent(QPaintEvent *pEvent) = 0;
    223 
    224     /**
    225      *  Called on the GUI thread (from VBoxConsoleView) after it gets a
    226      *  UIResizeEvent posted from the RequestResize() method implementation.
    227      */
    228     virtual void resizeEvent(UIResizeEvent *pEvent)
    229     {
    230         m_width = pEvent->width();
    231         m_height = pEvent->height();
    232     }
    233 
    234     /**
    235      *  Called on the GUI thread (from VBoxConsoleView) when the VM console
    236      *  window is moved.
    237      */
    238     virtual void moveEvent(QMoveEvent * /* pEvent */) {}
    239 
    240 #ifdef VBOX_WITH_VIDEOHWACCEL
    241     /* this method is called from the GUI thread
    242      * to perform the actual Video HW Acceleration command processing
    243      * the event is framebuffer implementation specific */
    244     virtual void doProcessVHWACommand(QEvent * pEvent);
    245 
    246     virtual void viewportResized(QResizeEvent * /* pEvent */) {}
    247 
    248     virtual void viewportScrolled(int /* iX */, int /* iY */) {}
    249 #endif
    250 
    251 protected:
    252 
    253     UIMachineView *m_pMachineView;
    254     RTCRITSECT m_critSect;
    255     int m_width;
    256     int m_height;
    257     uint64_t m_uWinId;
    258 
    259 #if defined (Q_OS_WIN32)
    260 private:
    261 
    262     long m_iRefCnt;
    263 #endif
    264 };
    265 
    266 #if defined (VBOX_GUI_USE_QIMAGE)
    267 class UIFrameBufferQImage : public UIFrameBuffer
    268 {
    269 public:
    270 
    271     UIFrameBufferQImage(UIMachineView *pMachineView);
    272 
    273     STDMETHOD(NotifyUpdate) (ULONG uX, ULONG uY, ULONG uW, ULONG uH);
    274 
    275     ulong pixelFormat() { return m_uPixelFormat; }
    276     bool usesGuestVRAM() { return m_bUsesGuestVRAM; }
    277 
    278     uchar *address() { return m_img.bits(); }
    279     ulong bitsPerPixel() { return m_img.depth(); }
    280     ulong bytesPerLine() { return m_img.bytesPerLine(); }
    281 
    282     void paintEvent (QPaintEvent *pEvent);
    283     void resizeEvent (UIResizeEvent *pEvent);
    284 
    285 private:
    286 
    287     QPixmap m_PM;
    288     QImage m_img;
    289     ulong m_uPixelFormat;
    290     bool m_bUsesGuestVRAM;
    291 };
    292 #endif
    293 
    294 #if 0
    295 #if defined (VBOX_GUI_USE_QGL)
    296 class UIFrameBufferQGL : public UIFrameBuffer
    297 {
    298 public:
    299 
    300     UIFrameBufferQGL(UIMachineView *pMachineView);
    301 
    302     STDMETHOD(NotifyUpdate) (ULONG uX, ULONG uY, ULONG uW, ULONG uH);
    303 #ifdef VBOXQGL_PROF_BASE
    304     STDMETHOD(RequestResize) (ULONG uScreenId, ULONG uPixelFormat,
    305                               BYTE *pVRAM, ULONG uBitsPerPixel, ULONG uBytesPerLine,
    306                               ULONG uWidth, ULONG uHeight, BOOL *pbFinished);
    307 #endif
    308 
    309 #ifdef VBOX_WITH_VIDEOHWACCEL
    310     STDMETHOD(ProcessVHWACommand)(BYTE *pbCommand);
    311 #endif
    312 
    313     ulong pixelFormat() { return vboxWidget()->vboxPixelFormat(); }
    314     bool usesGuestVRAM() { return vboxWidget()->vboxUsesGuestVRAM(); }
    315 
    316     uchar *address() { return vboxWidget()->vboxAddress(); }
    317     ulong bitsPerPixel() { return vboxWidget()->vboxBitsPerPixel(); }
    318     ulong bytesPerLine() { return vboxWidget()->vboxBytesPerLine(); }
    319 
    320     void paintEvent (QPaintEvent *pEvent);
    321     void resizeEvent (UIResizeEvent *pEvent);
    322     void doProcessVHWACommand(QEvent *pEvent);
    323 
    324 private:
    325 
    326     class VBoxGLWidget* vboxWidget();
    327 
    328     class VBoxVHWACommandElementProcessor m_cmdPipe;
    329 };
    330 #endif
    331 
    332 #if defined (VBOX_GUI_USE_SDL)
    333 class UIFrameBufferSDL : public UIFrameBuffer
    334 {
    335 public:
    336 
    337     UIFrameBufferSDL (VBoxConsoleView *pMachineView);
    338     virtual ~UIFrameBufferSDL();
    339 
    340     STDMETHOD(NotifyUpdate) (ULONG aX, ULONG aY, ULONG aW, ULONG aH);
    341 
    342     uchar* address()
    343     {
    344         SDL_Surface *surf = m_pSurfVRAM ? m_pSurfVRAM : m_pScreen;
    345         return surf ? (uchar*) (uintptr_t) surf->pixels : 0;
    346     }
    347 
    348     ulong bitsPerPixel()
    349     {
    350         SDL_Surface *surf = m_pSurfVRAM ? m_pSurfVRAM : m_pScreen;
    351         return surf ? surf->format->BitsPerPixel : 0;
    352     }
    353 
    354     ulong bytesPerLine()
    355     {
    356         SDL_Surface *surf = m_pSurfVRAM ? m_pSurfVRAM : m_pScreen;
    357         return surf ? surf->pitch : 0;
    358     }
    359 
    360     ulong pixelFormat()
    361     {
    362         return m_uPixelFormat;
    363     }
    364 
    365     bool usesGuestVRAM()
    366     {
    367         return m_pSurfVRAM != NULL;
    368     }
    369 
    370     void paintEvent(QPaintEvent *pEvent);
    371     void resizeEvent(UIResizeEvent *pEvent);
    372 
    373 private:
    374 
    375     SDL_Surface *m_pScreen;
    376     SDL_Surface *m_pSurfVRAM;
    377 
    378     ulong m_uPixelFormat;
    379 };
    380 #endif
    381 
    382 #if defined (VBOX_GUI_USE_DDRAW)
    383 class UIFrameBufferDDRAW : public UIFrameBuffer
    384 {
    385 public:
    386 
    387     UIFrameBufferDDRAW(UIMachineView *pMachineView);
    388     virtual ~UIFrameBufferDDRAW();
    389 
    390     STDMETHOD(NotifyUpdate) (ULONG uX, ULONG uY, ULONG uW, ULONG uH);
    391 
    392     uchar* address() { return (uchar*) m_surfaceDesc.lpSurface; }
    393     ulong bitsPerPixel() { return m_surfaceDesc.ddpfPixelFormat.dwRGBBitCount; }
    394     ulong bytesPerLine() { return (ulong) m_surfaceDesc.lPitch; }
    395 
    396     ulong pixelFormat() { return m_uPixelFormat; };
    397 
    398     bool usesGuestVRAM() { return m_bUsesGuestVRAM; }
    399 
    400     void paintEvent(QPaintEvent *pEvent);
    401     void resizeEvent(UIResizeEvent *pEvent);
    402     void moveEvent(QMoveEvent *pEvent);
    403 
    404 private:
    405 
    406     void releaseObjects();
    407 
    408     bool createSurface(ULONG uPixelFormat, uchar *pvVRAM,
    409                        ULONG uBitsPerPixel, ULONG uBytesPerLine,
    410                        ULONG uWidth, ULONG uHeight);
    411     void deleteSurface();
    412     void drawRect(ULONG uX, ULONG uY, ULONG uW, ULONG uH);
    413     void getWindowPosition(void);
    414 
    415     LPDIRECTDRAW7        m_DDRAW;
    416     LPDIRECTDRAWCLIPPER  m_clipper;
    417     LPDIRECTDRAWSURFACE7 m_surface;
    418     DDSURFACEDESC2       m_surfaceDesc;
    419     LPDIRECTDRAWSURFACE7 m_primarySurface;
    420 
    421     ulong m_uPixelFormat;
    422 
    423     bool m_bUsesGuestVRAM;
    424 
    425     int m_iWndX;
    426     int m_iWndY;
    427 
    428     bool m_bSynchronousUpdates;
    429 };
    430 #endif
    431 
    432 #endif
    433 #if defined (Q_WS_MAC) && defined (VBOX_GUI_USE_QUARTZ2D)
    43432#include <Carbon/Carbon.h>
    43533
     
    44139    virtual ~UIFrameBufferQuartz2D();
    44240
    443     STDMETHOD (NotifyUpdate) (ULONG uX, ULONG uY, ULONG uW, ULONG uH);
    444     STDMETHOD (SetVisibleRegion) (BYTE *pRectangles, ULONG uCount);
     41    STDMETHOD(NotifyUpdate)(ULONG uX, ULONG uY, ULONG uW, ULONG uH);
     42    STDMETHOD(SetVisibleRegion)(BYTE *pRectangles, ULONG uCount);
    44543
    44644    uchar* address() { return m_pDataAddress; }
     
    49896#endif /* Q_WS_MAC && VBOX_GUI_USE_QUARTZ2D */
    49997
    500 #endif // !___UIFrameBuffer_h___
     98#endif // !___UIFrameBufferQuartz2D_h___
    50199
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r26773 r26781  
    10171017
    10181018    // TODO: Call for singleton information dialog for this machine!
    1019     //VBoxVMInformationDlg::createInformationDlg(session(), machineWindowWrapper()->machineWindow());
     1019//    VBoxVMInformationDlg::createInformationDlg(session(), machineWindowWrapper()->machineWindow());
    10201020}
    10211021
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp

    r26773 r26781  
    3333#include "VBoxProblemReporter.h"
    3434#include "UIFrameBuffer.h"
     35#include "UIFrameBufferQuartz2D.h"
    3536#include "UISession.h"
    3637#include "UIActionsPool.h"
     
    459460#endif
    460461#endif
    461 #if 0 // TODO: Enable Quartz2D frame buffer!
    462462#if defined (VBOX_GUI_USE_QUARTZ2D)
    463463        case VBoxDefs::Quartz2DMode:
    464464            /* Indicate that we are doing all drawing stuff ourself: */
    465             pViewport->setAttribute(Qt::WA_PaintOnScreen);
    466 # ifdef VBOX_WITH_VIDEOHWACCEL
    467             m_pFrameBuffer = m_fAccelerate2DVideo ? new VBoxOverlayFrameBuffer<VBoxQuartz2DFrameBuffer>(this, &machineWindowWrapper()->session()) : new UIFrameBufferQuartz2D(this);
    468 # else
     465//            pViewport->setAttribute(Qt::WA_PaintOnScreen);
     466//# ifdef VBOX_WITH_VIDEOHWACCEL
     467//            m_pFrameBuffer = m_fAccelerate2DVideo ? new VBoxOverlayFrameBuffer<VBoxQuartz2DFrameBuffer>(this, &machineWindowWrapper()->session()) : new UIFrameBufferQuartz2D(this);
     468//# else
    469469            m_pFrameBuffer = new UIFrameBufferQuartz2D(this);
    470 # endif
     470//# endif
    471471            break;
    472 #endif
    473472#endif
    474473        default:
     
    720719    }
    721720# endif
    722     delete mDockIconPreview;
     721    // TODO_NEW_CORE
     722//    delete mDockIconPreview;
    723723    mDockIconPreview = NULL;
    724724#endif
     
    10111011
    10121012#ifdef Q_WS_MAC
    1013             mDockIconPreview->setOriginalSize(pResizeEvent->width(), pResizeEvent->height());
     1013            // TODO_NEW_CORE
     1014//            mDockIconPreview->setOriginalSize(pResizeEvent->width(), pResizeEvent->height());
    10141015#endif /* Q_WS_MAC */
    10151016
     
    20532054#ifdef Q_WS_MAC
    20542055        /* Update the dock icon if we are in the running state */
    2055         if (isRunning())
    2056             updateDockIcon();
     2056            // TODO_NEW_CORE
     2057//        if (isRunning())
     2058//            updateDockIcon();
    20572059#endif
    20582060        return;
     
    20602062
    20612063#ifdef VBOX_GUI_USE_QUARTZ2D
    2062     if (mode() == VBoxDefs::Quartz2DMode && m_pFrameBuffer)
    2063     {
    2064         m_pFrameBuffer->paintEvent(pPaintEvent);
    2065         updateDockIcon();
    2066     }
    2067     else
    2068 #endif
    2069     {
    2070         /* We have a snapshot for the paused state: */
    2071         QRect r = pPaintEvent->rect().intersect (viewport()->rect());
    2072         /* We have to disable paint on screen if we are using the regular painter */
    2073         bool paintOnScreen = viewport()->testAttribute(Qt::WA_PaintOnScreen);
    2074         viewport()->setAttribute(Qt::WA_PaintOnScreen, false);
    2075         QPainter pnt(viewport());
    2076         pnt.drawPixmap(r.x(), r.y(), m_pauseShot, r.x() + contentsX(), r.y() + contentsY(), r.width(), r.height());
    2077         /* Restore the attribute to its previous state */
    2078         viewport()->setAttribute(Qt::WA_PaintOnScreen, paintOnScreen);
     2064            // TODO_NEW_CORE
     2065//    if (mode() == VBoxDefs::Quartz2DMode && m_pFrameBuffer)
     2066//    {
     2067//        m_pFrameBuffer->paintEvent(pPaintEvent);
     2068//        updateDockIcon();
     2069//    }
     2070//    else
     2071#endif
     2072//    {
     2073//        /* We have a snapshot for the paused state: */
     2074//        QRect r = pPaintEvent->rect().intersect (viewport()->rect());
     2075//        /* We have to disable paint on screen if we are using the regular painter */
     2076//        bool paintOnScreen = viewport()->testAttribute(Qt::WA_PaintOnScreen);
     2077//        viewport()->setAttribute(Qt::WA_PaintOnScreen, false);
     2078//        QPainter pnt(viewport());
     2079//        pnt.drawPixmap(r.x(), r.y(), m_pauseShot, r.x() + contentsX(), r.y() + contentsY(), r.width(), r.height());
     2080//        /* Restore the attribute to its previous state */
     2081//        viewport()->setAttribute(Qt::WA_PaintOnScreen, paintOnScreen);
    20792082#ifdef Q_WS_MAC
    2080         updateDockIcon();
    2081 #endif
    2082     }
     2083//        updateDockIcon();
     2084#endif
     2085//    }
    20832086}
    20842087
     
    32453248void UIMachineView::updateDockIcon()
    32463249{
    3247     if (mDockIconEnabled)
    3248     {
    3249         if (!m_pauseShot.isNull())
    3250         {
    3251             CGImageRef pauseImg = ::darwinToCGImageRef (&m_pauseShot);
    3252             /* Use the pause image as background */
    3253             mDockIconPreview->updateDockPreview (pauseImg);
    3254             CGImageRelease (pauseImg);
    3255         }
    3256         else
    3257         {
    3258 # if defined (VBOX_GUI_USE_QUARTZ2D)
    3259                 // TODO_NEW_CORE
     3250    // TODO_NEW_CORE
     3251//    if (mDockIconEnabled)
     3252//    {
     3253//        if (!m_pauseShot.isNull())
     3254//        {
     3255//            CGImageRef pauseImg = ::darwinToCGImageRef (&m_pauseShot);
     3256//            /* Use the pause image as background */
     3257//            mDockIconPreview->updateDockPreview (pauseImg);
     3258//            CGImageRelease (pauseImg);
     3259//        }
     3260//        else
     3261//        {
     3262//# if defined (VBOX_GUI_USE_QUARTZ2D)
    32603263//            if (mode() == VBoxDefs::Quartz2DMode)
    32613264//            {
    3262                 /* If the render mode is Quartz2D we could use the CGImageRef
    3263                  * of the framebuffer for the dock icon creation. This saves
    3264                  * some conversion time. */
    3265 //                mDockIconPreview->updateDockPreview (static_cast <VBoxQuartz2DFrameBuffer *> (m_pFrameBuffer)->imageRef());
     3265//                /* If the render mode is Quartz2D we could use the CGImageRef
     3266//                 * of the framebuffer for the dock icon creation. This saves
     3267//                 * some conversion time. */
     3268//                mDockIconPreview->updateDockPreview(static_cast<UIFrameBufferQuartz2D*>(m_pFrameBuffer)->imageRef());
    32663269//            }
    32673270//            else
    3268 # endif
    3269                 /* In image mode we have to create the image ref out of the
    3270                  * framebuffer */
    3271                 // TODO_NEW_CORE
    3272 //                mDockIconPreview->updateDockPreview (m_pFrameBuffer);
    3273         }
    3274     }
     3271//# endif
     3272//                /* In image mode we have to create the image ref out of the
     3273//                 * framebuffer */
     3274//                mDockIconPreview->updateDockPreview(m_pFrameBuffer);
     3275//        }
     3276//    }
    32753277}
    32763278
     
    32803282     * & we are in an state where the framebuffer is likely valid. Otherwise to
    32813283     * the overlay stuff only. */
    3282     if (mDockIconEnabled &&
    3283         (machineState() == KMachineState_Running ||
    3284          machineState() == KMachineState_Paused ||
    3285          machineState() == KMachineState_Teleporting ||
    3286          machineState() == KMachineState_LiveSnapshotting ||
    3287          machineState() == KMachineState_Restoring ||
    3288          machineState() == KMachineState_TeleportingPausedVM ||
    3289          machineState() == KMachineState_TeleportingIn ||
    3290          machineState() == KMachineState_Saving))
    3291         updateDockIcon();
    3292     else
    3293         mDockIconPreview->updateDockOverlay();
     3284    // TODO_NEW_CORE
     3285//    if (mDockIconEnabled &&
     3286//        (machineState() == KMachineState_Running ||
     3287//         machineState() == KMachineState_Paused ||
     3288//         machineState() == KMachineState_Teleporting ||
     3289//         machineState() == KMachineState_LiveSnapshotting ||
     3290//         machineState() == KMachineState_Restoring ||
     3291//         machineState() == KMachineState_TeleportingPausedVM ||
     3292//         machineState() == KMachineState_TeleportingIn ||
     3293//         machineState() == KMachineState_Saving))
     3294//        updateDockIcon();
     3295//    else
     3296//        mDockIconPreview->updateDockOverlay();
    32943297}
    32953298
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