VirtualBox

Ignore:
Timestamp:
Aug 3, 2010 2:38:11 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
64380
Message:

FE/Qt4: make the VM view resizable when the VM is paused and in scale mode

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

Legend:

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

    r31283 r31341  
    150150        case KMachineState_TeleportingPausedVM:
    151151        {
    152             if (vboxGlobal().vmRenderMode() != VBoxDefs::TimerMode &&  m_pFrameBuffer &&
    153                 (state != KMachineState_TeleportingPausedVM || m_previousState != KMachineState_Teleporting))
    154             {
    155                 /* Take a screen snapshot. Note that TakeScreenShot() always needs a 32bpp image: */
    156                 QImage shot = QImage(m_pFrameBuffer->width(), m_pFrameBuffer->height(), QImage::Format_RGB32);
    157                 /* If TakeScreenShot fails or returns no image, just show a black image. */
    158                 shot.fill(0);
    159                 CDisplay dsp = session().GetConsole().GetDisplay();
    160                 dsp.TakeScreenShot(screenId(), shot.bits(), shot.width(), shot.height());
    161                 /* TakeScreenShot() may fail if, e.g. the Paused notification was delivered
    162                  * after the machine execution was resumed. It's not fatal: */
    163                 if (dsp.isOk())
    164                 {
    165                     dimImage(shot);
    166                 }
    167                 m_pauseShot = QPixmap::fromImage(shot);
     152            if (   vboxGlobal().vmRenderMode() != VBoxDefs::TimerMode
     153                && m_pFrameBuffer
     154                &&
     155                (   state           != KMachineState_TeleportingPausedVM
     156                 || m_previousState != KMachineState_Teleporting))
     157            {
     158                takePauseShotLive();
    168159                /* Fully repaint to pick up m_pauseShot: */
    169160                viewport()->update();
     
    171162            break;
    172163        }
     164#ifdef VBOX_TEST_IMAGE_ON_RESTORE
     165        case KMachineState_Restoring:
     166        {
     167            /* Only works with the primary screen currently. */
     168            if (screenId() == 0)
     169            {
     170                takePauseShotSnapshot();
     171                /* Fully repaint to pick up m_pauseShot: */
     172                viewport()->update();
     173            }
     174            break;
     175        }
     176#endif
    173177        case KMachineState_Running:
    174178        {
     
    180184                {
    181185                    /* Reset the pixmap to free memory: */
    182                     m_pauseShot = QPixmap();
     186                    resetPauseShot();
    183187                    /* Ask for full guest display update (it will also update
    184188                     * the viewport through IFramebuffer::NotifyUpdate): */
     
    192196            break;
    193197    }
     198
    194199    m_previousState = state;
    195200}
     
    379384    }
    380385
     386#ifdef VBOX_TEST_IMAGE_ON_RESTORE
     387    QSize size;
     388#ifdef Q_WS_X11
     389    /* Processing pseudo resize-event to synchronize frame-buffer with stored
     390     * framebuffer size. On X11 this will be additional done when the machine
     391     * state was 'saved'. */
     392    if (session().GetMachine().GetState() == KMachineState_Saved)
     393        QSize size = guestSizeHint();
     394#endif /* Q_WS_X11 */
     395    /* If there is a preview image saved, we will resize the framebuffer to the
     396     * size of that image. */
     397    ULONG buffer = 0, width = 0, height = 0;
     398    CMachine machine = session().GetMachine();
     399    machine.QuerySavedScreenshotPNGSize(0, buffer, width, height);
     400    if (buffer > 0)
     401        size = guestSizeHint();
     402    /* If we have a valid size, resize the framebuffer. */
     403    if (   size.width() > 0
     404        && size.height() > 0)
     405    {
     406        UIResizeEvent event(FramebufferPixelFormat_Opaque, NULL, 0, 0, size.width(), size.height());
     407        frameBuffer()->resizeEvent(&event);
     408    }
     409#else
    381410#ifdef Q_WS_X11
    382411    /* Processing pseudo resize-event to synchronize frame-buffer
     
    389418    }
    390419#endif /* Q_WS_X11 */
     420#endif
    391421}
    392422
     
    630660    QString strValue = QString("%1,%2").arg(sizeHint.width()).arg(sizeHint.height());
    631661    machine.SetExtraData(strKey, strValue);
     662}
     663
     664void UIMachineView::takePauseShotLive()
     665{
     666    /* Take a screen snapshot. Note that TakeScreenShot() always needs a 32bpp image: */
     667    QImage shot = QImage(m_pFrameBuffer->width(), m_pFrameBuffer->height(), QImage::Format_RGB32);
     668    /* If TakeScreenShot fails or returns no image, just show a black image. */
     669    shot.fill(0);
     670    CDisplay dsp = session().GetConsole().GetDisplay();
     671    dsp.TakeScreenShot(screenId(), shot.bits(), shot.width(), shot.height());
     672    /* TakeScreenShot() may fail if, e.g. the Paused notification was delivered
     673     * after the machine execution was resumed. It's not fatal: */
     674    if (dsp.isOk())
     675        dimImage(shot);
     676    m_pauseShot = QPixmap::fromImage(shot);
     677}
     678
     679void UIMachineView::takePauseShotSnapshot()
     680{
     681    CMachine machine = session().GetMachine();
     682    ULONG width = 0, height = 0;
     683    QVector<BYTE> screenData = machine.ReadSavedScreenshotPNGToArray(0, width, height);
     684    if (screenData.size() != 0)
     685    {
     686        QImage shot = QImage::fromData(screenData.data(), screenData.size(), "PNG").scaled(guestSizeHint());
     687        dimImage(shot);
     688        m_pauseShot = QPixmap::fromImage(shot);
     689    }
    632690}
    633691
     
    885943        viewport()->setAttribute(Qt::WA_PaintOnScreen, false);
    886944        QPainter pnt(viewport());
    887         pnt.drawPixmap(r.x(), r.y(), m_pauseShot, r.x() + contentsX(), r.y() + contentsY(), r.width(), r.height());
     945        pnt.drawPixmap(r, m_pauseShot, QRect(r.x() + contentsX(), r.y() + contentsY(), r.width(), r.height()));
    888946        /* Restore the attribute to its previous state: */
    889947        viewport()->setAttribute(Qt::WA_PaintOnScreen, paintOnScreen);
     
    9531011
    9541012#endif
    955 
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h

    r30752 r31341  
    130130
    131131    /* Protected helpers: */
     132    virtual void takePauseShotLive();
     133    virtual void takePauseShotSnapshot();
     134    virtual void resetPauseShot() { m_pauseShot = QPixmap(); }
    132135    virtual QRect workingArea() = 0;
    133136    virtual void calculateDesktopGeometry() = 0;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.cpp

    r31318 r31341  
    4747#endif
    4848                    )
    49     , m_fShouldWeDoScale(false)
     49    , m_pPauseImage(0)
    5050{
    5151    /* Load machine view settings: */
     
    8383}
    8484
    85 void UIMachineViewScale::sltMachineStateChanged()
    86 {
    87     /* Base-class processing: */
    88     UIMachineView::sltMachineStateChanged();
    89 
    90     /* Get machine state: */
    91     KMachineState state = uisession()->machineState();
    92     switch (state)
    93     {
    94         case KMachineState_Paused:
    95         case KMachineState_TeleportingPausedVM:
     85void UIMachineViewScale::takePauseShotLive()
     86{
     87    /* Take a screen snapshot. Note that TakeScreenShot() always needs a 32bpp image: */
     88    QImage shot = QImage(m_pFrameBuffer->width(), m_pFrameBuffer->height(), QImage::Format_RGB32);
     89    /* If TakeScreenShot fails or returns no image, just show a black image. */
     90    shot.fill(0);
     91    CDisplay dsp = session().GetConsole().GetDisplay();
     92    dsp.TakeScreenShot(screenId(), shot.bits(), shot.width(), shot.height());
     93    m_pPauseImage = new QImage(shot);
     94    scalePauseShot();
     95}
     96
     97void UIMachineViewScale::takePauseShotSnapshot()
     98{
     99    CMachine machine = session().GetMachine();
     100    ULONG width = 0, height = 0;
     101    QVector<BYTE> screenData = machine.ReadSavedScreenshotPNGToArray(0, width, height);
     102    if (screenData.size() != 0)
     103    {
     104        QImage shot = QImage::fromData(screenData.data(), screenData.size(), "PNG").scaled(guestSizeHint());
     105        m_pPauseImage = new QImage(shot);
     106        scalePauseShot();
     107    }
     108}
     109
     110void UIMachineViewScale::resetPauseShot()
     111{
     112    /* Call the base class */
     113    UIMachineView::resetPauseShot();
     114
     115    if (m_pPauseImage)
     116    {
     117        delete m_pPauseImage;
     118        m_pPauseImage = 0;
     119    }
     120}
     121
     122void UIMachineViewScale::scalePauseShot()
     123{
     124    if (m_pPauseImage)
     125    {
     126        QSize scaledSize = frameBuffer()->scaledSize();
     127        if (scaledSize.isValid())
    96128        {
    97             /* Scale stored pause-shot, it will be repainted on the next event-processing step: */
    98             m_pauseShot = m_pauseShot.scaled(frameBuffer()->scaledSize(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    99             break;
     129            QImage bla1 = m_pPauseImage->scaled(frameBuffer()->scaledSize(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
     130            dimImage(bla1);
     131            m_pauseShot = QPixmap::fromImage(bla1);
    100132        }
    101         default:
    102             break;
    103133    }
    104134}
     
    110140    frameBuffer()->setScaledSize(viewport()->size());
    111141
     142    /* Scale the pause image if necessary */
     143    scalePauseShot();
     144
    112145    /* Update viewport: */
    113146    viewport()->repaint();
     
    115148    /* Update machine-view sliders: */
    116149    updateSliders();
    117 
    118     /* Set request reflector to 'false' after scaling is done: */
    119     m_fShouldWeDoScale = false;
    120150}
    121151
     
    285315        display.SetFramebuffer(m_uScreenId, CFramebuffer(m_pFrameBuffer));
    286316    }
     317
     318#ifdef VBOX_TEST_IMAGE_ON_RESTORE
     319    QSize size;
     320#ifdef Q_WS_X11
     321    /* Processing pseudo resize-event to synchronize frame-buffer with stored
     322     * framebuffer size. On X11 this will be additional done when the machine
     323     * state was 'saved'. */
     324    if (session().GetMachine().GetState() == KMachineState_Saved)
     325        QSize size = guestSizeHint();
     326#endif /* Q_WS_X11 */
     327    /* If there is a preview image saved, we will resize the framebuffer to the
     328     * size of that image. */
     329    ULONG buffer = 0, width = 0, height = 0;
     330    CMachine machine = session().GetMachine();
     331    machine.QuerySavedScreenshotPNGSize(0, buffer, width, height);
     332    if (buffer > 0)
     333        size = guestSizeHint();
     334    /* If we have a valid size, resize the framebuffer. */
     335    if (   size.width() > 0
     336        && size.height() > 0)
     337    {
     338        UIResizeEvent event(FramebufferPixelFormat_Opaque, NULL, 0, 0, size.width(), size.height());
     339        frameBuffer()->resizeEvent(&event);
     340        QTimer::singleShot(0, this, SLOT(sltPerformGuestScale()));
     341    }
     342#endif
    287343}
    288344
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineViewScale.h

    r30848 r31341  
    3939    virtual ~UIMachineViewScale();
    4040
     41    virtual void takePauseShotLive();
     42    virtual void takePauseShotSnapshot();
     43    virtual void resetPauseShot();
     44    void scalePauseShot();
     45
    4146private slots:
    42 
    43     /* Console callback handlers: */
    44     void sltMachineStateChanged();
    4547
    4648    /* Slot to perform guest resize: */
     
    7577
    7678    /* Private members: */
    77     bool m_fShouldWeDoScale : 1;
     79    QImage *m_pPauseImage;
    7880
    7981    /* Friend classes: */
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