VirtualBox

Changeset 39023 in vbox


Ignore:
Timestamp:
Oct 18, 2011 9:01:00 PM (13 years ago)
Author:
vboxsync
Message:

FE/Qt: cleaned up the maximum guest size code

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.cpp

    r39021 r39023  
    169169/**
    170170 * Returns whether we like the given video mode.
     171 * @note We always like a mode smaller than the current framebuffer
     172 *       size.
    171173 *
    172174 * @returns COM status code
     
    185187    *pbSupported = TRUE;
    186188    QSize screen = m_pMachineView->maxGuestSize();
    187     if ((screen.width() != 0) && (uWidth > (ULONG)screen.width()))
     189    if (   (screen.width() != 0)
     190        && (uWidth > (ULONG)screen.width())
     191        && (uWidth > (ULONG)width()))
    188192        *pbSupported = FALSE;
    189     if ((screen.height() != 0) && (uHeight > (ULONG)screen.height()))
     193    if (   (screen.height() != 0)
     194        && (uHeight > (ULONG)screen.height())
     195        && (uHeight > (ULONG)height()))
    190196        *pbSupported = FALSE;
    191197    LogFlowThisFunc(("screenW=%lu, screenH=%lu -> aSupported=%s\n",
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp

    r39022 r39023  
    2525#include <QScrollBar>
    2626#include <VBox/VBoxVideo.h>
     27#include <iprt/asm.h>
    2728
    2829/* Local includes */
     
    160161    AssertMsg(newSize.isValid(), ("Size should be valid!\n"));
    161162
    162     /* Store the new hint */
    163     storeHintForGuestSizePolicy(newSize.width(), newSize.height());
    164163    /* Send new size-hint to the guest: */
    165164    session().GetConsole().GetDisplay().SetVideoModeHint(newSize.width(), newSize.height(), 0, screenId());
     
    240239    , m_previousState(KMachineState_Null)
    241240    , m_maxGuestSizePolicy(MaxGuestSizePolicy_Invalid)
     241    , m_u64MaxGuestSize(0)
    242242#ifdef VBOX_WITH_VIDEOHWACCEL
    243243    , m_fAccelerate2DVideo(bAccelerate2DVideo)
     
    485485        QString maxGuestSize = vboxGlobal().settings().publicProperty("GUI/MaxGuestResolution");
    486486        if ((maxGuestSize == QString::null) || (maxGuestSize == "auto"))
    487             setMaxGuestSizePolicy(MaxGuestSizePolicy_Automatic, 0, 0);
     487            m_maxGuestSizePolicy = MaxGuestSizePolicy_Automatic;
    488488        else if (maxGuestSize == "any")
    489             setMaxGuestSizePolicy(MaxGuestSizePolicy_Any, 0, 0);
     489            m_maxGuestSizePolicy = MaxGuestSizePolicy_Any;
    490490        else  /** @todo Mea culpa, but what about error checking? */
    491491        {
    492492            int width  = maxGuestSize.section(',', 0, 0).toInt();
    493493            int height = maxGuestSize.section(',', 1, 1).toInt();
    494             setMaxGuestSizePolicy(MaxGuestSizePolicy_Fixed, width, height);
     494            m_maxGuestSizePolicy = MaxGuestSizePolicy_Fixed;
     495            m_fixedMaxGuestSize = QSize(width, height);
    495496        }
    496497    }
     
    597598}
    598599
    599 QSize UIMachineView::maxGuestSize() const
     600void UIMachineView::setMaxGuestSize()
    600601{
    601602    QSize maxSize;
     
    603604    {
    604605        case MaxGuestSizePolicy_Fixed:
     606            maxSize = m_fixedMaxGuestSize;
     607            break;
    605608        case MaxGuestSizePolicy_Automatic:
    606             maxSize = QSize(qMax(m_fixedMaxGuestSize.width(), m_storedGuestHintSize.width()),
    607                              qMax(m_fixedMaxGuestSize.height(), m_storedGuestHintSize.height()));
     609            maxSize = calculateMaxGuestSize();
    608610            break;
    609611        case MaxGuestSizePolicy_Any:
     612        default:
     613            AssertMsg(m_maxGuestSizePolicy == MaxGuestSizePolicy_Any,
     614                      ("Invalid maximum guest size policy %d!\n",
     615                       m_maxGuestSizePolicy));
     616            /* (0, 0) means any of course. */
    610617            maxSize = QSize(0, 0);
    611             break;
    612         default:
    613             AssertMsgFailed(("Invalid maximum guest size policy %d!\n",
    614                              m_maxGuestSizePolicy));
    615     }
    616     return maxSize;
     618    }
     619    ASMAtomicWriteU64(&m_u64MaxGuestSize,
     620                      RT_MAKE_U64(maxSize.width(), maxSize.height()));
     621}
     622
     623QSize UIMachineView::maxGuestSize()
     624{
     625    uint64_t u64Size = ASMAtomicReadU64(&m_u64MaxGuestSize);
     626    return QSize(int(RT_HI_U32(u64Size)), int(RT_LO_U32(u64Size)));
    617627}
    618628
     
    650660    /* Return result: */
    651661    return sizeHint;
    652 }
    653 
    654 void UIMachineView::setMaxGuestSizePolicy(MaxGuestSizePolicy policy, int cwMax,
    655                                           int chMax)
    656 {
    657     switch (policy)
    658     {
    659         case MaxGuestSizePolicy_Fixed:
    660             m_maxGuestSizePolicy = MaxGuestSizePolicy_Fixed;
    661             if (cwMax != 0 && chMax != 0)
    662                 m_fixedMaxGuestSize = QSize(cwMax, chMax);
    663             else
    664                 m_fixedMaxGuestSize = QSize(0, 0);
    665             storeHintForGuestSizePolicy(0, 0);
    666             break;
    667         case MaxGuestSizePolicy_Automatic:
    668             m_maxGuestSizePolicy = MaxGuestSizePolicy_Automatic;
    669             m_fixedMaxGuestSize = QSize(0, 0);
    670             storeHintForGuestSizePolicy(0, 0);
    671             break;
    672         case MaxGuestSizePolicy_Any:
    673             m_maxGuestSizePolicy = MaxGuestSizePolicy_Any;
    674             m_fixedMaxGuestSize = QSize(0, 0);
    675             break;
    676         default:
    677             AssertMsgFailed(("Invalid maximum guest size policy %d\n",
    678                              policy));
    679             m_maxGuestSizePolicy = MaxGuestSizePolicy_Invalid;
    680     }
    681 }
    682 
    683 void UIMachineView::storeHintForGuestSizePolicy(int cWidth, int cHeight)
    684 {
    685     if (m_maxGuestSizePolicy == MaxGuestSizePolicy_Automatic)
    686         m_storedGuestHintSize = QSize(cWidth, cHeight);
    687662}
    688663
     
    892867    /* Report to the VM thread that we finished resizing: */
    893868    session().GetConsole().GetDisplay().ResizeCompleted(screenId());
    894 
    895     /* We also recalculate the maximum guest size if necessary.  In fact we
    896      * only need this on the first resize, but it is done every time to keep
    897      * the code simpler. */
    898     calculateMaxGuestSize();
    899869
    900870    /* Emit a signal about guest was resized: */
     
    1009979{
    1010980    updateSliders();
     981    /* We call this on every resize as on X11 it sets information which becomes
     982     * available asynchronously at an unknown time after window creation.  As
     983     * long as the information is not available we make a best guess. */
     984    setMaxGuestSize();
    1011985    return QAbstractScrollArea::resizeEvent(pEvent);
    1012986}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h

    r39022 r39023  
    135135    UIFrameBuffer* frameBuffer() const { return m_pFrameBuffer; }
    136136    const QPixmap& pauseShot() const { return m_pauseShot; }
    137     /** Helper to retrieve the last non-fullscreen guest size hint
    138      * sent.  @note Currently unused. */
    139     QSize storedGuestHintSize() const { return m_storedGuestHintSize; }
    140     /** What policy are we currently applying for limiting guest
    141      * resolutions? */
    142     MaxGuestSizePolicy maxGuestSizePolicy() const
    143     { return m_maxGuestSizePolicy; }
    144     /** The maximum guest resolution which we currently wish to handle.
    145      * @note This must be safely called from another thread.
    146      * @todo So make it atomic.
    147      */
    148     QSize maxGuestSize() const;
     137    /** Atomically store the maximum guest resolution which we currently wish
     138     * to handle for @a maxGuestSize() to read. */
     139    void setMaxGuestSize();
     140    /** Atomically read the maximum guest resolution which we currently wish to
     141     * handle.  This may safely be called from another thread (called by
     142     * UIFramebuffer on EMT). */
     143    QSize maxGuestSize();
    149144    /** Retrieve the last non-fullscreen guest size hint (from extra data).
    150145     */
     
    152147
    153148    /* Protected setters: */
    154     void setMaxGuestSizePolicy(MaxGuestSizePolicy policy, int cwMax,
    155                                int chMax);
    156     void storeHintForGuestSizePolicy(int cWidth, int cHeight);
     149    /** Store a guest size hint value to extra data, called on switching to
     150     * fullscreen. */
    157151    void storeGuestSizeHint(const QSize &sizeHint);
    158152
     
    165159    /** Calculate how big the guest desktop can be while still fitting on one
    166160     * host screen. */
    167     virtual void calculateMaxGuestSize() = 0;
     161    virtual QSize calculateMaxGuestSize() const = 0;
    168162    virtual void maybeRestrictMinimumSize() = 0;
    169163    virtual void updateSliders();
     
    204198    KMachineState m_previousState;
    205199
    206     /** The policy for calculating the maximum guest resolution we wish to
    207      * support. */
     200    /** The policy for calculating the maximum guest resolution which we wish
     201     * to handle. */
    208202    MaxGuestSizePolicy m_maxGuestSizePolicy;
    209203    /** The maximum guest size for fixed size policy. */
    210204    QSize m_fixedMaxGuestSize;
    211     /** The last guest size hint sent out, used for calculating the maximum
    212      * supported guest resolution. */
    213     QSize m_storedGuestHintSize;
     205    /** Maximum guest resolution which we wish to handle.  Must be accessed
     206     * atomically. */
     207    /** @todo This should be private. */
     208    volatile uint64_t m_u64MaxGuestSize;
    214209
    215210#ifdef VBOX_WITH_VIDEOHWACCEL
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineViewFullscreen.cpp

    r39021 r39023  
    9595void UIMachineViewFullscreen::sltDesktopResized()
    9696{
    97     /* Recalculate the maximum guest size if necessary. */
    98     calculateMaxGuestSize();
     97
    9998}
    10099
     
    205204}
    206205
    207 void UIMachineViewFullscreen::calculateMaxGuestSize()
    208 {
    209     /* This method should not get called until we have initially set up the desktop geometry type: */
    210     Assert((maxGuestSizePolicy() != MaxGuestSizePolicy_Invalid));
    211     /* If we are not doing automatic adjustment then there is nothing to do. */
    212     if (maxGuestSizePolicy() == MaxGuestSizePolicy_Automatic)
    213         m_fixedMaxGuestSize = workingArea().size();
     206QSize UIMachineViewFullscreen::calculateMaxGuestSize() const
     207{
     208    return workingArea().size();
    214209}
    215210
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineViewFullscreen.h

    r39021 r39023  
    7171    void normalizeGeometry(bool /* fAdjustPosition */) {}
    7272    QRect workingArea() const;
    73     void calculateMaxGuestSize();
     73    QSize calculateMaxGuestSize() const;
    7474    void maybeRestrictMinimumSize();
    7575
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.cpp

    r39022 r39023  
    9898void UIMachineViewNormal::sltDesktopResized()
    9999{
    100     /* Recalculate the maximum guest size if necessary. */
    101     calculateMaxGuestSize();
     100
    102101}
    103102
     
    304303}
    305304
    306 void UIMachineViewNormal::calculateMaxGuestSize()
    307 {
    308     /* This method should not get called until we have initially set up the
    309      * maximum guest size policy. */
    310     Assert((maxGuestSizePolicy() != MaxGuestSizePolicy_Invalid));
    311     /* If we are not doing automatic adjustment then there is nothing to do. */
    312     if (maxGuestSizePolicy() == MaxGuestSizePolicy_Automatic)
    313     {
    314         /* The area taken up by the machine window on the desktop,
    315          * including window frame, title, menu bar and status bar: */
    316         QRect windowGeo = machineWindowWrapper()->machineWindow()->frameGeometry();
    317         /* The area taken up by the machine central widget, so excluding all decorations: */
    318         QRect centralWidgetGeo = static_cast<QMainWindow*>(machineWindowWrapper()->machineWindow())->centralWidget()->geometry();
    319         /* To work out how big we can make the console window while still fitting on the desktop,
    320          * we calculate workingArea() - (windowGeo - centralWidgetGeo).
    321          * This works because the difference between machine window and machine central widget
    322          * (or at least its width and height) is a constant. */
    323         m_fixedMaxGuestSize = QSize(  workingArea().width()
    324                                     - (windowGeo.width()
    325                                     - centralWidgetGeo.width()),
    326                                       workingArea().height()
    327                                     - (windowGeo.height()
    328                                     - centralWidgetGeo.height()));
    329     }
     305QSize UIMachineViewNormal::calculateMaxGuestSize() const
     306{
     307    /* The area taken up by the machine window on the desktop,
     308     * including window frame, title, menu bar and status bar: */
     309    QRect windowGeo = machineWindowWrapper()->machineWindow()->frameGeometry();
     310    /* The area taken up by the machine central widget, so excluding all decorations: */
     311    QRect centralWidgetGeo = static_cast<QMainWindow*>(machineWindowWrapper()->machineWindow())->centralWidget()->geometry();
     312    /* To work out how big we can make the console window while still fitting on the desktop,
     313     * we calculate workingArea() - (windowGeo - centralWidgetGeo).
     314     * This works because the difference between machine window and machine central widget
     315     * (or at least its width and height) is a constant. */
     316    return QSize(  workingArea().width()
     317                 - (windowGeo.width() - centralWidgetGeo.width()),
     318                   workingArea().height()
     319                 - (windowGeo.height() - centralWidgetGeo.height()));
    330320}
    331321
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.h

    r39021 r39023  
    8080    void normalizeGeometry(bool fAdjustPosition);
    8181    QRect workingArea() const;
    82     void calculateMaxGuestSize();
     82    QSize calculateMaxGuestSize() const;
    8383    void maybeRestrictMinimumSize();
    8484
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.cpp

    r39021 r39023  
    154154void UIMachineViewScale::sltDesktopResized()
    155155{
    156     /* Recalculate the maximum guest size if necessary. */
    157     calculateMaxGuestSize();
     156
    158157}
    159158
     
    185184            /* Report to the VM thread that we finished resizing: */
    186185            session().GetConsole().GetDisplay().ResizeCompleted(screenId());
    187 
    188             /* We also recalculate the maximum guest size if necessary.  In
    189              * fact we only need this on the first resize, but it is done
    190              * every time to keep the code simpler. */
    191             calculateMaxGuestSize();
    192186
    193187            /* Emit a signal about guest was resized: */
     
    368362}
    369363
    370 void UIMachineViewScale::calculateMaxGuestSize()
    371 {
    372     /* This method should not get called until we have initially set up the
    373      * maximum guest size policy. */
    374     Assert((maxGuestSizePolicy() != MaxGuestSizePolicy_Invalid));
    375     /* If we are not doing automatic adjustment then there is nothing to do. */
    376     if (maxGuestSizePolicy() == MaxGuestSizePolicy_Automatic)
    377     {
    378         /* The area taken up by the machine window on the desktop,
    379          * including window frame, title, menu bar and status bar: */
    380         QRect windowGeo = machineWindowWrapper()->machineWindow()->frameGeometry();
    381         /* The area taken up by the machine central widget, so excluding all decorations: */
    382         QRect centralWidgetGeo = static_cast<QMainWindow*>(machineWindowWrapper()->machineWindow())->centralWidget()->geometry();
    383         /* To work out how big we can make the console window while still fitting on the desktop,
    384          * we calculate workingArea() - (windowGeo - centralWidgetGeo).
    385          * This works because the difference between machine window and machine central widget
    386          * (or at least its width and height) is a constant. */
    387         m_fixedMaxGuestSize = QSize(  workingArea().width()
    388                                     - (windowGeo.width()
    389                                     - centralWidgetGeo.width()),
    390                                       workingArea().height()
    391                                     - (windowGeo.height()
    392                                     - centralWidgetGeo.height()));
    393     }
     364QSize UIMachineViewScale::calculateMaxGuestSize() const
     365{
     366    /* The area taken up by the machine window on the desktop,
     367     * including window frame, title, menu bar and status bar: */
     368    QRect windowGeo = machineWindowWrapper()->machineWindow()->frameGeometry();
     369    /* The area taken up by the machine central widget, so excluding all decorations: */
     370    QRect centralWidgetGeo = static_cast<QMainWindow*>(machineWindowWrapper()->machineWindow())->centralWidget()->geometry();
     371    /* To work out how big we can make the console window while still fitting on the desktop,
     372     * we calculate workingArea() - (windowGeo - centralWidgetGeo).
     373     * This works because the difference between machine window and machine central widget
     374     * (or at least its width and height) is a constant. */
     375    return QSize(  workingArea().width()
     376                 - (windowGeo.width() - centralWidgetGeo.width()),
     377                   workingArea().height()
     378                 - (windowGeo.height() - centralWidgetGeo.height()));
    394379}
    395380
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.h

    r39021 r39023  
    7272    void normalizeGeometry(bool /* fAdjustPosition */) {}
    7373    QRect workingArea() const;
    74     void calculateMaxGuestSize();
     74    QSize calculateMaxGuestSize() const;
    7575    void maybeRestrictMinimumSize() {}
    7676    void updateSliders();
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.cpp

    r39021 r39023  
    101101     *        I don't think that it is the GUI's job to check that
    102102     *        the resize succeeded though. */
    103 
    104     /* Recalculate the maximum guest size if necessary. */
    105     calculateMaxGuestSize();
    106103}
    107104
     
    227224}
    228225
    229 void UIMachineViewSeamless::calculateMaxGuestSize()
    230 {
    231     /* This method should not get called until we have initially set up the desktop geometry type: */
    232     Assert((maxGuestSizePolicy() != MaxGuestSizePolicy_Invalid));
    233     /* If we are not doing automatic adjustment then there is nothing to do. */
    234     if (maxGuestSizePolicy() == MaxGuestSizePolicy_Automatic)
    235         m_fixedMaxGuestSize = workingArea().size();
    236 }
    237 
     226QSize UIMachineViewSeamless::calculateMaxGuestSize() const
     227{
     228    return workingArea().size();
     229}
     230
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.h

    r39021 r39023  
    7575    void normalizeGeometry(bool /* fAdjustPosition */) {}
    7676    QRect workingArea() const;
    77     void calculateMaxGuestSize();
     77    QSize calculateMaxGuestSize() const;
    7878    void maybeRestrictMinimumSize() {}
    7979
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