VirtualBox

Ignore:
Timestamp:
Jun 2, 2014 4:30:27 PM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: Runtime UI: Merge QImage frame-buffer code into frame-buffer interface code.

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

Legend:

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

    r51484 r51493  
    561561        src/runtime/UIConsoleEventHandler.cpp \
    562562        src/runtime/UIFrameBuffer.cpp \
    563         src/runtime/UIFrameBufferQImage.cpp \
    564563        src/runtime/UIIndicatorsPool.cpp \
    565564        src/runtime/UIKeyboardHandler.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxFBOverlay.h

    r51487 r51493  
    18191819};
    18201820
    1821 /* these two additional class V, class R are to workaround the [VBox|UI] duplication,
    1822  * @todo: remove them once VBox stuff is removed */
    1823 template <class T, class V, class R>
     1821/* this additional class V is to workaround the [VBox|UI] duplication,
     1822 * @todo: remove it once VBox stuff is removed */
     1823template <class T, class V>
    18241824class VBoxOverlayFrameBuffer : public T
    18251825{
     
    18861886    }
    18871887
    1888     void resizeEvent (R *re)
    1889     {
    1890         T::resizeEvent (re);
    1891         mOverlay.onResizeEventPostprocess (VBoxFBSizeInfo(this),
     1888    void resizeEvent(int iWidth, int iHeight)
     1889    {
     1890        T::resizeEvent(iWidth, iHeight);
     1891        mOverlay.onResizeEventPostprocess(VBoxFBSizeInfo(this),
    18921892                QPoint(mpView->contentsX(), mpView->contentsY()));
    18931893    }
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.cpp

    r51487 r51493  
    1919# include "precomp.h"
    2020#else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
     21/* Qt includes: */
     22# include <QPainter>
    2123/* GUI includes: */
    2224# include "UIFrameBuffer.h"
     25# include "UISession.h"
     26# include "UIMachineLogic.h"
     27# include "UIMachineWindow.h"
    2328# include "UIMachineView.h"
    24 # include "UIMessageCenter.h"
     29# include "UIPopupCenter.h"
    2530# include "VBoxGlobal.h"
    2631# ifndef VBOX_WITH_TRANSLUCENT_SEAMLESS
     
    4348
    4449UIFrameBuffer::UIFrameBuffer(UIMachineView *pMachineView)
    45     : m_pMachineView(pMachineView)
    46     , m_width(0), m_height(0)
     50    : m_iWidth(0), m_iHeight(0)
     51    , m_pMachineView(pMachineView)
     52    , m_iWinId(0)
     53    , m_fUpdatesAllowed(true)
    4754    , m_fUnused(false)
    4855    , m_fAutoEnabled(false)
    49     , m_fIsUpdatesAllowed(true)
    5056#ifdef Q_OS_WIN
    5157    , m_iRefCnt(0)
     
    5763    AssertMsg(m_pMachineView, ("UIMachineView must not be NULL\n"));
    5864    /* Cache window ID: */
    59     m_winId = (m_pMachineView && m_pMachineView->viewport()) ? (LONG64)m_pMachineView->viewport()->winId() : 0;
     65    m_iWinId = (m_pMachineView && m_pMachineView->viewport()) ? (LONG64)m_pMachineView->viewport()->winId() : 0;
    6066
    6167    /* Initialize critical-section: */
     
    6672    if (m_pMachineView)
    6773        prepareConnections();
     74
     75    /* Resize frame-buffer to default size: */
     76    resizeEvent(640, 480);
    6877}
    6978
     
    8796    m_pMachineView = pMachineView;
    8897    /* Recache window ID: */
    89     m_winId = (m_pMachineView && m_pMachineView->viewport()) ? (LONG64)m_pMachineView->viewport()->winId() : 0;
     98    m_iWinId = (m_pMachineView && m_pMachineView->viewport()) ? (LONG64)m_pMachineView->viewport()->winId() : 0;
    9099
    91100    /* Connect new handlers: */
     
    177186    if (!pWinId)
    178187        return E_POINTER;
    179     *pWinId = m_winId;
     188    *pWinId = m_iWinId;
    180189    return S_OK;
    181190}
     
    223232            (unsigned long)uX, (unsigned long)uY,
    224233            (unsigned long)uWidth, (unsigned long)uHeight));
    225     emit sigNotifyChange(uScreenId, uWidth, uHeight);
     234    emit sigNotifyChange(uWidth, uHeight);
    226235
    227236    /* Unlock access to frame-buffer: */
     
    242251    uX = qMax(0, (int)uX - 1);
    243252    uY = qMax(0, (int)uY - 1);
    244     uWidth = qMin((int)m_width, (int)uWidth + 2);
    245     uHeight = qMin((int)m_height, (int)uHeight + 2);
     253    uWidth = qMin(m_iWidth, (int)uWidth + 2);
     254    uHeight = qMin(m_iHeight, (int)uHeight + 2);
    246255
    247256    /* Lock access to frame-buffer: */
     
    455464}
    456465
    457 void UIFrameBuffer::notifyChange()
    458 {
     466void UIFrameBuffer::notifyChange(int iWidth, int iHeight)
     467{
     468    LogRel(("UIFrameBuffer::notifyChange: Size=%dx%d\n", iWidth, iHeight));
     469
     470    /* Make sure machine-view is assigned: */
     471    AssertPtrReturnVoid(m_pMachineView);
     472
    459473    /* Lock access to frame-buffer: */
    460474    lock();
    461475
    462     /* If there is NO pending source bitmap: */
     476    /* If there is NO pending source-bitmap: */
    463477    if (m_pendingSourceBitmap.isNull())
    464478    {
    465479        /* Do nothing, change-event already processed: */
    466         LogRelFlow(("UIFrameBuffer::notifyChange: Already processed.\n"));
     480        LogRel2(("UIFrameBuffer::notifyChange: Already processed.\n"));
    467481        /* Unlock access to frame-buffer: */
    468482        unlock();
     
    472486
    473487    /* Disable screen updates: */
    474     m_fIsUpdatesAllowed = false;
     488    m_fUpdatesAllowed = false;
    475489
    476490    /* Release the current bitmap and keep the pending one: */
     
    481495    unlock();
    482496
    483     /* Acquire source bitmap: */
    484     BYTE *pAddress = NULL;
    485     ULONG ulWidth = 0;
    486     ULONG ulHeight = 0;
    487     ULONG ulBitsPerPixel = 0;
    488     ULONG ulBytesPerLine = 0;
    489     ULONG ulPixelFormat = 0;
    490     m_sourceBitmap.QueryBitmapInfo(pAddress,
    491                                    ulWidth,
    492                                    ulHeight,
    493                                    ulBitsPerPixel,
    494                                    ulBytesPerLine,
    495                                    ulPixelFormat);
    496 
    497497    /* Perform frame-buffer resize: */
    498     UIResizeEvent e(FramebufferPixelFormat_Opaque, pAddress,
    499                     ulBitsPerPixel, ulBytesPerLine, ulWidth, ulHeight);
    500     resizeEvent(&e);
     498    resizeEvent(iWidth, iHeight);
     499}
     500
     501void UIFrameBuffer::resizeEvent(int iWidth, int iHeight)
     502{
     503    LogRel(("UIFrameBuffer::resizeEvent: Size=%dx%d\n", iWidth, iHeight));
     504
     505    /* Make sure machine-view is assigned: */
     506    AssertPtrReturnVoid(m_pMachineView);
     507
     508    /* Invalidate visible-region (if necessary): */
     509    if (m_pMachineView->machineLogic()->visualStateType() == UIVisualStateType_Seamless &&
     510        (m_iWidth != iWidth || m_iHeight != iHeight))
     511    {
     512        lock();
     513        m_syncVisibleRegion = QRegion();
     514        m_asyncVisibleRegion = QRegion();
     515        unlock();
     516    }
     517
     518    /* If source-bitmap invalid: */
     519    if (m_sourceBitmap.isNull())
     520    {
     521        LogRel(("UIFrameBuffer::resizeEvent: "
     522                "Using FALLBACK buffer due to source-bitmap is not provided..\n"));
     523
     524        /* Remember new size came from hint: */
     525        m_iWidth = iWidth;
     526        m_iHeight = iHeight;
     527
     528        /* And go fallback: */
     529        goFallback();
     530    }
     531    /* If source-bitmap valid: */
     532    else
     533    {
     534        LogRel(("UIFrameBuffer::resizeEvent: "
     535                "Directly using source-bitmap content..\n"));
     536
     537        /* Acquire source-bitmap attributes: */
     538        BYTE *pAddress = NULL;
     539        ULONG ulWidth = 0;
     540        ULONG ulHeight = 0;
     541        ULONG ulBitsPerPixel = 0;
     542        ULONG ulBytesPerLine = 0;
     543        ULONG ulPixelFormat = 0;
     544        m_sourceBitmap.QueryBitmapInfo(pAddress,
     545                                       ulWidth,
     546                                       ulHeight,
     547                                       ulBitsPerPixel,
     548                                       ulBytesPerLine,
     549                                       ulPixelFormat);
     550        Assert(ulBitsPerPixel == 32);
     551
     552        /* Remember new actual size: */
     553        m_iWidth = (int)ulWidth;
     554        m_iHeight = (int)ulHeight;
     555
     556        /* Recreate QImage on the basis of source-bitmap content: */
     557        m_image = QImage(pAddress, m_iWidth, m_iHeight, ulBytesPerLine, QImage::Format_RGB32);
     558
     559        /* Check whether guest color depth differs from the bitmap color depth: */
     560        ULONG ulGuestBitsPerPixel = 0;
     561        LONG xOrigin = 0;
     562        LONG yOrigin = 0;
     563        CDisplay display = m_pMachineView->uisession()->session().GetConsole().GetDisplay();
     564        display.GetScreenResolution(m_pMachineView->screenId(),
     565                                    ulWidth, ulHeight, ulGuestBitsPerPixel, xOrigin, yOrigin);
     566
     567        /* Remind user if necessary: */
     568        if (   ulGuestBitsPerPixel != ulBitsPerPixel
     569            && m_pMachineView->uisession()->isGuestAdditionsActive())
     570            popupCenter().remindAboutWrongColorDepth(m_pMachineView->machineWindow(),
     571                                                     ulGuestBitsPerPixel, ulBitsPerPixel);
     572        else
     573            popupCenter().forgetAboutWrongColorDepth(m_pMachineView->machineWindow());
     574    }
     575
     576    /* Enable screen updates: */
     577    lock();
     578    m_fUpdatesAllowed = true;
     579    unlock();
     580}
     581
     582void UIFrameBuffer::paintEvent(QPaintEvent *pEvent)
     583{
     584    LogRel2(("UIFrameBuffer::paintEvent: Origin=%lux%lu, Size=%dx%d\n",
     585             pEvent->rect().x(), pEvent->rect().y(),
     586             pEvent->rect().width(), pEvent->rect().height()));
     587
     588    /* On mode switch the enqueued paint-event may still come
     589     * while the machine-view is already null (before the new machine-view set),
     590     * ignore paint-event in that case. */
     591    if (!m_pMachineView)
     592        return;
     593
     594    /* Lock access to frame-buffer: */
     595    lock();
     596
     597    /* But if updates disabled: */
     598    if (!m_fUpdatesAllowed)
     599    {
     600        /* Unlock access to frame-buffer: */
     601        unlock();
     602        /* And return immediately: */
     603        return;
     604    }
     605
     606    /* If the machine is NOT in 'running', 'paused' or 'saving' state,
     607     * the link between the framebuffer and the video memory is broken.
     608     * We should go fallback in that case.
     609     * We should acquire actual machine-state to exclude
     610     * situations when the state was changed already but
     611     * GUI didn't received event about that or didn't processed it yet. */
     612    KMachineState machineState = m_pMachineView->uisession()->session().GetConsole().GetState();
     613    if (/* running */
     614           machineState != KMachineState_Running
     615        && machineState != KMachineState_Teleporting
     616        && machineState != KMachineState_LiveSnapshotting
     617        && machineState != KMachineState_DeletingSnapshotOnline
     618        /* paused */
     619        && machineState != KMachineState_Paused
     620        && machineState != KMachineState_TeleportingPausedVM
     621        /* saving */
     622        && machineState != KMachineState_Saving
     623        /* guru */
     624        && machineState != KMachineState_Stuck
     625        )
     626    {
     627        LogRel(("UIFrameBuffer::paintEvent: "
     628                "Using FALLBACK buffer due to machine-state become invalid: "
     629                "%d.\n", (int)machineState));
     630
     631        /* Go fallback: */
     632        goFallback();
     633    }
     634
     635    /* Depending on visual-state type: */
     636    switch (m_pMachineView->machineLogic()->visualStateType())
     637    {
     638        case UIVisualStateType_Seamless:
     639            paintSeamless(pEvent);
     640            break;
     641        case UIVisualStateType_Scale:
     642            paintScaled(pEvent);
     643            break;
     644        default:
     645            paintDefault(pEvent);
     646            break;
     647    }
     648
     649    /* Unlock access to frame-buffer: */
     650    unlock();
    501651}
    502652
     
    533683void UIFrameBuffer::prepareConnections()
    534684{
    535     connect(this, SIGNAL(sigNotifyChange(ulong, int, int)),
    536             m_pMachineView, SLOT(sltHandleNotifyChange(ulong, int, int)),
     685    connect(this, SIGNAL(sigNotifyChange(int, int)),
     686            m_pMachineView, SLOT(sltHandleNotifyChange(int, int)),
    537687            Qt::QueuedConnection);
    538688    connect(this, SIGNAL(sigNotifyUpdate(int, int, int, int)),
     
    549699void UIFrameBuffer::cleanupConnections()
    550700{
    551     disconnect(this, SIGNAL(sigNotifyChange(ulong, int, int)),
    552                m_pMachineView, SLOT(sltHandleNotifyChange(ulong, int, int)));
     701    disconnect(this, SIGNAL(sigNotifyChange(int, int)),
     702               m_pMachineView, SLOT(sltHandleNotifyChange(int, int)));
    553703    disconnect(this, SIGNAL(sigNotifyUpdate(int, int, int, int)),
    554704               m_pMachineView, SLOT(sltHandleNotifyUpdate(int, int, int, int)));
     
    559709}
    560710
     711void UIFrameBuffer::paintDefault(QPaintEvent *pEvent)
     712{
     713    /* Get rectangle to paint: */
     714    QRect paintRect = pEvent->rect().intersected(m_image.rect()).intersected(m_pMachineView->viewport()->geometry());
     715    if (paintRect.isEmpty())
     716        return;
     717
     718    /* Create painter: */
     719    QPainter painter(m_pMachineView->viewport());
     720
     721    /* Draw image rectangle: */
     722    drawImageRect(painter, m_image, paintRect,
     723                  m_pMachineView->contentsX(), m_pMachineView->contentsY(),
     724                  hiDPIOptimizationType(), backingScaleFactor());
     725}
     726
     727void UIFrameBuffer::paintSeamless(QPaintEvent *pEvent)
     728{
     729    /* Get rectangle to paint: */
     730    QRect paintRect = pEvent->rect().intersected(m_image.rect()).intersected(m_pMachineView->viewport()->geometry());
     731    if (paintRect.isEmpty())
     732        return;
     733
     734    /* Create painter: */
     735    QPainter painter(m_pMachineView->viewport());
     736
     737    /* Determine the region to erase: */
     738    lock();
     739    QRegion regionToErase = (QRegion)paintRect - m_syncVisibleRegion;
     740    unlock();
     741    if (!regionToErase.isEmpty())
     742    {
     743        /* Optimize composition-mode: */
     744        painter.setCompositionMode(QPainter::CompositionMode_Clear);
     745        /* Erase required region, slowly, rectangle-by-rectangle: */
     746        foreach (const QRect &rect, regionToErase.rects())
     747            painter.eraseRect(rect);
     748        /* Restore composition-mode: */
     749        painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
     750    }
     751
     752    /* Determine the region to paint: */
     753    lock();
     754    QRegion regionToPaint = (QRegion)paintRect & m_syncVisibleRegion;
     755    unlock();
     756    if (!regionToPaint.isEmpty())
     757    {
     758        /* Paint required region, slowly, rectangle-by-rectangle: */
     759        foreach (const QRect &rect, regionToPaint.rects())
     760        {
     761#if defined(VBOX_WITH_TRANSLUCENT_SEAMLESS) && defined(Q_WS_WIN)
     762            /* Replace translucent background with black one,
     763             * that is necessary for window with Qt::WA_TranslucentBackground: */
     764            painter.setCompositionMode(QPainter::CompositionMode_Source);
     765            painter.fillRect(rect, QColor(Qt::black));
     766            painter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
     767#endif /* VBOX_WITH_TRANSLUCENT_SEAMLESS && Q_WS_WIN */
     768
     769            /* Draw image rectangle: */
     770            drawImageRect(painter, m_image, rect,
     771                          m_pMachineView->contentsX(), m_pMachineView->contentsY(),
     772                          hiDPIOptimizationType(), backingScaleFactor());
     773        }
     774    }
     775}
     776
     777void UIFrameBuffer::paintScaled(QPaintEvent *pEvent)
     778{
     779    /* Scaled image is NULL by default: */
     780    QImage scaledImage;
     781    /* But if scaled-factor is set and current image is NOT null: */
     782    if (m_scaledSize.isValid() && !m_image.isNull())
     783    {
     784        /* We are doing a deep copy of the image to make sure it will not be
     785         * detached during scale process, otherwise we can get a frozen frame-buffer. */
     786        scaledImage = m_image.copy();
     787        /* And scaling the image to predefined scaled-factor: */
     788        scaledImage = scaledImage.scaled(m_scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
     789    }
     790    /* Finally we are choosing image to paint from: */
     791    QImage &sourceImage = scaledImage.isNull() ? m_image : scaledImage;
     792
     793    /* Get rectangle to paint: */
     794    QRect paintRect = pEvent->rect().intersected(sourceImage.rect()).intersected(m_pMachineView->viewport()->geometry());
     795    if (paintRect.isEmpty())
     796        return;
     797
     798    /* Create painter: */
     799    QPainter painter(m_pMachineView->viewport());
     800
     801    /* Draw image rectangle: */
     802    drawImageRect(painter, sourceImage, paintRect,
     803                  m_pMachineView->contentsX(), m_pMachineView->contentsY(),
     804                  hiDPIOptimizationType(), backingScaleFactor());
     805}
     806
     807/* static */
     808void UIFrameBuffer::drawImageRect(QPainter &painter, const QImage &image, const QRect &rect,
     809                                  int iContentsShiftX, int iContentsShiftY,
     810                                  HiDPIOptimizationType hiDPIOptimizationType,
     811                                  double dBackingScaleFactor)
     812{
     813    /* Calculate offset: */
     814    size_t offset = (rect.x() + iContentsShiftX) * image.depth() / 8 +
     815                    (rect.y() + iContentsShiftY) * image.bytesPerLine();
     816
     817    /* Restrain boundaries: */
     818    int iSubImageWidth = qMin(rect.width(), image.width() - rect.x() - iContentsShiftX);
     819    int iSubImageHeight = qMin(rect.height(), image.height() - rect.y() - iContentsShiftY);
     820
     821    /* Create sub-image (no copy involved): */
     822    QImage subImage = QImage(image.bits() + offset,
     823                             iSubImageWidth, iSubImageHeight,
     824                             image.bytesPerLine(), image.format());
     825
     826#ifndef QIMAGE_FRAMEBUFFER_WITH_DIRECT_OUTPUT
     827    /* Create sub-pixmap on the basis of sub-image above (1st copy involved): */
     828    QPixmap subPixmap = QPixmap::fromImage(subImage);
     829
     830    /* If HiDPI 'backing scale factor' defined: */
     831    if (dBackingScaleFactor > 1.0)
     832    {
     833        /* Should we optimize HiDPI output for performance? */
     834        if (hiDPIOptimizationType == HiDPIOptimizationType_Performance)
     835        {
     836            /* Fast scale sub-pixmap (2nd copy involved): */
     837            subPixmap = subPixmap.scaled(subPixmap.size() * dBackingScaleFactor,
     838                                         Qt::IgnoreAspectRatio, Qt::FastTransformation);
     839# ifdef Q_WS_MAC
     840#  ifdef VBOX_GUI_WITH_HIDPI
     841            /* Mark sub-pixmap as HiDPI: */
     842            subPixmap.setDevicePixelRatio(dBackingScaleFactor);
     843#  endif /* VBOX_GUI_WITH_HIDPI */
     844# endif /* Q_WS_MAC */
     845        }
     846    }
     847
     848    /* Draw sub-pixmap: */
     849    painter.drawPixmap(rect.x(), rect.y(), subPixmap);
     850#else /* QIMAGE_FRAMEBUFFER_WITH_DIRECT_OUTPUT */
     851    /* If HiDPI 'backing scale factor' defined: */
     852    if (dBackingScaleFactor > 1.0)
     853    {
     854        /* Should we optimize HiDPI output for performance? */
     855        if (hiDPIOptimizationType == HiDPIOptimizationType_Performance)
     856        {
     857            /* Create fast-scaled-sub-image (1st copy involved): */
     858            QImage scaledSubImage = subImage.scaled(subImage.size() * dBackingScaleFactor,
     859                                                    Qt::IgnoreAspectRatio, Qt::FastTransformation);
     860# ifdef Q_WS_MAC
     861#  ifdef VBOX_GUI_WITH_HIDPI
     862            /* Mark sub-pixmap as HiDPI: */
     863            scaledSubImage.setDevicePixelRatio(dBackingScaleFactor);
     864#  endif /* VBOX_GUI_WITH_HIDPI */
     865# endif /* Q_WS_MAC */
     866            /* Directly draw scaled-sub-image: */
     867            painter.drawImage(rect.x(), rect.y(), scaledSubImage);
     868            return;
     869        }
     870    }
     871    /* Directly draw sub-image: */
     872    painter.drawImage(rect.x(), rect.y(), subImage);
     873#endif /* QIMAGE_FRAMEBUFFER_WITH_DIRECT_OUTPUT */
     874}
     875
     876void UIFrameBuffer::goFallback()
     877{
     878    /* We are going for FALLBACK buffer when:
     879     * 1. Display did not provide the source-bitmap;
     880     * 2. or the machine is in the state which breaks link between
     881     *    the framebuffer and the actual video-memory: */
     882    m_image = QImage(m_iWidth, m_iHeight, QImage::Format_RGB32);
     883    m_image.fill(0);
     884}
     885
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.h

    r51487 r51493  
    2020/* Qt includes: */
    2121#include <QRegion>
     22#include <QImage>
    2223
    2324/* GUI includes: */
     
    3738class UIMachineView;
    3839
    39 /** Frame-buffer resize-event. */
    40 class UIResizeEvent : public QEvent
    41 {
    42 public:
    43 
    44     UIResizeEvent(ulong uPixelFormat, uchar *pVRAM,
    45                   ulong uBitsPerPixel, ulong uBytesPerLine,
    46                   ulong uWidth, ulong uHeight)
    47         : QEvent((QEvent::Type)ResizeEventType)
    48         , m_uPixelFormat(uPixelFormat), m_pVRAM(pVRAM), m_uBitsPerPixel(uBitsPerPixel)
    49         , m_uBytesPerLine(uBytesPerLine), m_uWidth(uWidth), m_uHeight(uHeight) {}
    50     ulong pixelFormat() { return m_uPixelFormat; }
    51     uchar *VRAM() { return m_pVRAM; }
    52     ulong bitsPerPixel() { return m_uBitsPerPixel; }
    53     ulong bytesPerLine() { return m_uBytesPerLine; }
    54     ulong width() { return m_uWidth; }
    55     ulong height() { return m_uHeight; }
    56 
    57 private:
    58 
    59     ulong m_uPixelFormat;
    60     uchar *m_pVRAM;
    61     ulong m_uBitsPerPixel;
    62     ulong m_uBytesPerLine;
    63     ulong m_uWidth;
    64     ulong m_uHeight;
    65 };
    66 
    6740/** Common IFramebuffer implementation used to maintain VM display video memory. */
    6841class UIFrameBuffer : public QObject, VBOX_SCRIPTABLE_IMPL(IFramebuffer)
     
    7346
    7447    /** Notifies listener about guest-screen resolution changes. */
    75     void sigNotifyChange(ulong uScreenId, int iWidth, int iHeight);
     48    void sigNotifyChange(int iWidth, int iHeight);
    7649    /** Notifies listener about guest-screen updates. */
    7750    void sigNotifyUpdate(int iX, int iY, int iWidth, int iHeight);
     
    190163
    191164    /** Returns frame-buffer data address. */
    192     virtual uchar *address() = 0;
     165    uchar *address() { return m_image.bits(); }
    193166    /** Returns frame-buffer width. */
    194     ulong width() { return m_width; }
     167    ulong width() { return m_iWidth; }
    195168    /** Returns frame-buffer height. */
    196     ulong height() { return m_height; }
     169    ulong height() { return m_iHeight; }
    197170    /** Returns frame-buffer bits-per-pixel value. */
    198     virtual ulong bitsPerPixel() = 0;
     171    ulong bitsPerPixel() { return m_image.depth(); }
    199172    /** Returns frame-buffer bytes-per-line value. */
    200     virtual ulong bytesPerLine() = 0;
     173    ulong bytesPerLine() { return m_image.bytesPerLine(); }
    201174    /** Returns default frame-buffer pixel-format. */
    202     virtual ulong pixelFormat() { return FramebufferPixelFormat_FOURCC_RGB; }
     175    ulong pixelFormat() { return FramebufferPixelFormat_FOURCC_RGB; }
    203176
    204177    /** Locks frame-buffer access. */
     
    212185    void setScaledSize(const QSize &size = QSize()) { m_scaledSize = size; }
    213186    /** Returns x-origin of the host (scaled) content corresponding to x-origin of guest (actual) content. */
    214     inline int convertGuestXTo(int x) const { return m_scaledSize.isValid() ? qRound((double)m_scaledSize.width() / m_width * x) : x; }
     187    inline int convertGuestXTo(int x) const { return m_scaledSize.isValid() ? qRound((double)m_scaledSize.width() / m_iWidth * x) : x; }
    215188    /** Returns y-origin of the host (scaled) content corresponding to y-origin of guest (actual) content. */
    216     inline int convertGuestYTo(int y) const { return m_scaledSize.isValid() ? qRound((double)m_scaledSize.height() / m_height * y) : y; }
     189    inline int convertGuestYTo(int y) const { return m_scaledSize.isValid() ? qRound((double)m_scaledSize.height() / m_iHeight * y) : y; }
    217190    /** Returns x-origin of the guest (actual) content corresponding to x-origin of host (scaled) content. */
    218     inline int convertHostXTo(int x) const  { return m_scaledSize.isValid() ? qRound((double)m_width / m_scaledSize.width() * x) : x; }
     191    inline int convertHostXTo(int x) const  { return m_scaledSize.isValid() ? qRound((double)m_iWidth / m_scaledSize.width() * x) : x; }
    219192    /** Returns y-origin of the guest (actual) content corresponding to y-origin of host (scaled) content. */
    220     inline int convertHostYTo(int y) const  { return m_scaledSize.isValid() ? qRound((double)m_height / m_scaledSize.height() * y) : y; }
     193    inline int convertHostYTo(int y) const  { return m_scaledSize.isValid() ? qRound((double)m_iHeight / m_scaledSize.height() * y) : y; }
    221194
    222195    /** Handles frame-buffer notify-change-event. */
    223     void notifyChange();
     196    virtual void notifyChange(int iWidth, int iHeight);
    224197    /** Handles frame-buffer resize-event. */
    225     virtual void resizeEvent(UIResizeEvent *pEvent) = 0;
     198    virtual void resizeEvent(int iWidth, int iHeight);
    226199    /** Handles frame-buffer paint-event. */
    227     virtual void paintEvent(QPaintEvent *pEvent) = 0;
     200    virtual void paintEvent(QPaintEvent *pEvent);
    228201    /** Handles frame-buffer apply-visible-region-event. */
    229     void applyVisibleRegion(const QRegion &region);
     202    virtual void applyVisibleRegion(const QRegion &region);
    230203
    231204#ifdef VBOX_WITH_VIDEOHWACCEL
     
    250223protected:
    251224
    252     /** Machine-view this frame-buffer is bounded to. */
     225    /** Prepare connections routine. */
     226    void prepareConnections();
     227    /** Cleanup connections routine. */
     228    void cleanupConnections();
     229
     230    /** Default paint routine. */
     231    void paintDefault(QPaintEvent *pEvent);
     232    /** Paint routine for seamless mode. */
     233    void paintSeamless(QPaintEvent *pEvent);
     234    /** Paint routine for scaled mode. */
     235    void paintScaled(QPaintEvent *pEvent);
     236
     237    /** Draws corresponding @a rect of passed @a image with @a painter. */
     238    static void drawImageRect(QPainter &painter, const QImage &image, const QRect &rect,
     239                              int iContentsShiftX, int iContentsShiftY,
     240                              HiDPIOptimizationType hiDPIOptimizationType,
     241                              double dBackingScaleFactor);
     242
     243    /** Recreates own clean QImage buffer. */
     244    void goFallback();
     245
     246    /** Holds the QImage buffer. */
     247    QImage m_image;
     248    /** Holds frame-buffer width. */
     249    int m_iWidth;
     250    /** Holds frame-buffer height. */
     251    int m_iHeight;
     252
     253    /** Source bitmap from IDisplay. */
     254    CDisplaySourceBitmap m_sourceBitmap;
     255    /** Source bitmap from IDisplay (acquired but not yet applied). */
     256    CDisplaySourceBitmap m_pendingSourceBitmap;
     257
     258    /** Holds machine-view this frame-buffer is bounded to. */
    253259    UIMachineView *m_pMachineView;
    254     /** Cached window ID. */
    255     int64_t m_winId;
    256     /** RTCRITSECT object to protect frame-buffer access. */
    257     mutable RTCRITSECT m_critSect;
    258     /** Frame-buffer width. */
    259     ulong m_width;
    260     /** Frame-buffer height. */
    261     ulong m_height;
    262     /** Frame-buffer scaled size. */
    263     QSize m_scaledSize;
     260    /** Holds window ID this frame-buffer referring to. */
     261    int64_t m_iWinId;
     262
     263    /** Reflects whether screen-updates are allowed. */
     264    bool m_fUpdatesAllowed;
     265
    264266    /** Defines whether frame-buffer is <b>unused</b>.
    265267      * <b>Unused</b> status determines whether frame-buffer should ignore EMT events or not. */
    266268    bool m_fUnused;
     269
    267270    /** Defines whether frame-buffer is <b>auto-enabled</b>.
    268271      * <b>Auto-enabled</b> status means that guest-screen corresponding to this frame-buffer
     
    272275    bool m_fAutoEnabled;
    273276
    274     /** Source bitmap from IDisplay. */
    275     CDisplaySourceBitmap m_sourceBitmap;
    276     /** Source bitmap from IDisplay (acquired but not yet applied). */
    277     CDisplaySourceBitmap m_pendingSourceBitmap;
    278     /** Reflects whether screen-updates are allowed. */
    279     bool m_fIsUpdatesAllowed;
    280 
     277    /** RTCRITSECT object to protect frame-buffer access. */
     278    mutable RTCRITSECT m_critSect;
     279
     280#ifdef Q_OS_WIN
     281    /** Windows: Holds the reference counter. */
     282    long m_iRefCnt;
     283#endif /* Q_OS_WIN */
     284
     285    /** @name Scaled mode related variables.
     286     * @{ */
     287    /** Holds frame-buffer scaled size. */
     288    QSize m_scaledSize;
     289    /** @} */
     290
     291    /** @name Seamless mode related variables.
     292     * @{ */
    281293    /* To avoid a seamless flicker which caused by the latency between
    282294     * the initial visible-region arriving from EMT thread
     
    290302      * because NotifyUpdate doesn't take into account these changes. */
    291303    QRegion m_asyncVisibleRegion;
    292 
    293 private:
    294 
    295     /** Prepare connections routine. */
    296     void prepareConnections();
    297     /** Cleanup connections routine. */
    298     void cleanupConnections();
    299 
    300 #ifdef Q_OS_WIN
    301     /** Windows: Holds the reference counter. */
    302     long m_iRefCnt;
    303 #endif /* Q_OS_WIN */
    304 
     304    /** @} */
     305
     306    /** @name HiDPI screens related variables.
     307     * @{ */
    305308    /** Holds HiDPI frame-buffer optimization type. */
    306309    HiDPIOptimizationType m_hiDPIOptimizationType;
    307 
    308310    /** Holds backing scale factor used by HiDPI frame-buffer. */
    309311    double m_dBackingScaleFactor;
     312    /** @} */
    310313};
    311314
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp

    r51487 r51493  
    3535#include "UIMessageCenter.h"
    3636#include "UIFrameBuffer.h"
    37 #include "UIFrameBufferQImage.h"
    3837#include "VBoxFBOverlay.h"
    3938#include "UISession.h"
     
    217216}
    218217
    219 void UIMachineView::sltHandleNotifyChange(ulong uScreenId, int iWidth, int iHeight)
     218void UIMachineView::sltHandleNotifyChange(int iWidth, int iHeight)
    220219{
    221220    LogRelFlow(("UIMachineView::HandleNotifyChange: Screen=%d, Size=%dx%d.\n",
     
    237236
    238237        /* Perform frame-buffer mode-change: */
    239         frameBuffer()->notifyChange();
     238        frameBuffer()->notifyChange(iWidth, iHeight);
    240239
    241240        /* Scale-mode doesn't need this.. */
     
    410409             * this [VBox|UI] duplication
    411410             * @todo: they are to be removed once VBox stuff is gone */
    412             pFrameBuffer = new VBoxOverlayFrameBuffer<UIFrameBufferQImage, UIMachineView, UIResizeEvent>(this, &session(), (uint32_t)screenId());
     411            pFrameBuffer = new VBoxOverlayFrameBuffer<UIFrameBuffer, UIMachineView>(this, &session(), (uint32_t)screenId());
    413412        }
    414413        else
    415             pFrameBuffer = new UIFrameBufferQImage(this);
     414            pFrameBuffer = new UIFrameBuffer(this);
    416415# else /* VBOX_WITH_VIDEOHWACCEL */
    417         pFrameBuffer = new UIFrameBufferQImage(this);
     416        pFrameBuffer = new UIFrameBuffer(this);
    418417# endif /* !VBOX_WITH_VIDEOHWACCEL */
    419418        pFrameBuffer->setHiDPIOptimizationType(uisession()->hiDPIOptimizationType());
     
    468467    }
    469468    /* If we have a valid size, resize the framebuffer. */
    470     if (   size.width() > 0
    471         && size.height() > 0)
    472     {
    473         UIResizeEvent event(FramebufferPixelFormat_Opaque, NULL, 0, 0, size.width(), size.height());
    474         frameBuffer()->resizeEvent(&event);
    475     }
     469    if (size.width() > 0 && size.height() > 0)
     470        frameBuffer()->resizeEvent(size.width(), size.height());
    476471}
    477472
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h

    r51487 r51493  
    9797
    9898    /* Handler: Frame-buffer NotifyChange stuff: */
    99     virtual void sltHandleNotifyChange(ulong uScreenId, int iWidth, int iHeight);
     99    virtual void sltHandleNotifyChange(int iWidth, int iHeight);
    100100
    101101    /* Handler: Frame-buffer NotifyUpdate stuff: */
     
    263263    friend class UIMachineLogic;
    264264    friend class UIFrameBuffer;
    265     friend class UIFrameBufferQImage;
    266     template<class, class, class> friend class VBoxOverlayFrameBuffer;
     265    template<class, class> friend class VBoxOverlayFrameBuffer;
    267266};
    268267
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.cpp

    r51484 r51493  
    3030#include "UIMachineViewScale.h"
    3131#include "UIFrameBuffer.h"
    32 #include "UIFrameBufferQImage.h"
    3332
    3433/* COM includes: */
Note: See TracChangeset for help on using the changeset viewer.

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