VirtualBox

Changeset 51131 in vbox


Ignore:
Timestamp:
Apr 24, 2014 11:05:02 AM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: Runtime UI: QImage frame-buffer: Optimizing paintEvent.

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

Legend:

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

    r50557 r51131  
    208208    QPainter painter(m_pMachineView->viewport());
    209209
    210     /* Draw image rectangle depending on rectangle width: */
    211     if ((ulong)paintRect.width() < m_width * 2 / 3)
    212         drawImageRectNarrow(painter, m_img,
    213                             paintRect, m_pMachineView->contentsX(), m_pMachineView->contentsY());
    214     else
    215         drawImageRectWide(painter, m_img,
    216                           paintRect, m_pMachineView->contentsX(), m_pMachineView->contentsY());
     210    /* Draw image rectangle: */
     211    drawImageRect(painter, m_img, paintRect,
     212                  m_pMachineView->contentsX(), m_pMachineView->contentsY());
    217213}
    218214
     
    259255#endif /* VBOX_WITH_TRANSLUCENT_SEAMLESS && Q_WS_WIN */
    260256
    261             /* Draw image rectangle depending on rectangle width: */
    262             if ((ulong)rect.width() < m_width * 2 / 3)
    263                 drawImageRectNarrow(painter, m_img,
    264                                     rect, m_pMachineView->contentsX(), m_pMachineView->contentsY());
    265             else
    266                 drawImageRectWide(painter, m_img,
    267                                   rect, m_pMachineView->contentsX(), m_pMachineView->contentsY());
     257            /* Draw image rectangle: */
     258            drawImageRect(painter, m_img, rect,
     259                          m_pMachineView->contentsX(), m_pMachineView->contentsY());
    268260        }
    269261    }
     
    294286    QPainter painter(m_pMachineView->viewport());
    295287
    296     /* Draw image rectangle depending on rectangle width: */
    297     if ((ulong)paintRect.width() < m_width * 2 / 3)
    298         drawImageRectNarrow(painter, sourceImage,
    299                             paintRect, m_pMachineView->contentsX(), m_pMachineView->contentsY());
    300     else
    301         drawImageRectWide(painter, sourceImage,
    302                           paintRect, m_pMachineView->contentsX(), m_pMachineView->contentsY());
     288    /* Draw image rectangle: */
     289    drawImageRect(painter, sourceImage, paintRect,
     290                  m_pMachineView->contentsX(), m_pMachineView->contentsY());
    303291}
    304292
    305293/* static */
    306 void UIFrameBufferQImage::drawImageRectNarrow(QPainter &painter, const QImage &image,
    307                                               const QRect &rect, int iContentsShiftX, int iContentsShiftY)
    308 {
    309     /* This method is faster for narrow updates: */
    310     QPixmap pm = QPixmap::fromImage(image.copy(rect.x() + iContentsShiftX,
    311                                                rect.y() + iContentsShiftY,
    312                                                rect.width(), rect.height()));
    313     painter.drawPixmap(rect.x(), rect.y(), pm);
    314 }
    315 
    316 /* static */
    317 void UIFrameBufferQImage::drawImageRectWide(QPainter &painter, const QImage &image,
    318                                             const QRect &rect, int iContentsShiftX, int iContentsShiftY)
    319 {
    320     /* This method is faster for wide updates: */
    321     QPixmap pm = QPixmap::fromImage(QImage(image.scanLine(rect.y() + iContentsShiftY),
    322                                            image.width(), rect.height(), image.bytesPerLine(),
    323                                            QImage::Format_RGB32));
    324     painter.drawPixmap(rect.x(), rect.y(), pm, rect.x() + iContentsShiftX, 0, 0, 0);
     294void UIFrameBufferQImage::drawImageRect(QPainter &painter, const QImage &image, const QRect &rect,
     295                                        int iContentsShiftX, int iContentsShiftY)
     296{
     297    /* Calculate offset: */
     298    size_t offset = (rect.x() + iContentsShiftX) * image.depth() / 8 +
     299                    (rect.y() + iContentsShiftY) * image.bytesPerLine();
     300
     301    /* Create sub-image (no copy involved): */
     302    QImage subImage = QImage(image.bits() + offset,
     303                             rect.width(), rect.height(),
     304                             image.bytesPerLine(), image.format());
     305
     306#ifndef QIMAGE_FRAMEBUFFER_WITH_DIRECT_OUTPUT
     307    /* Create sub-pixmap on the basis of sub-image above (1st copy involved): */
     308    QPixmap subPixmap = QPixmap::fromImage(subImage);
     309
     310    /* Draw sub-pixmap: */
     311    painter.drawPixmap(rect.x(), rect.y(), subPixmap);
     312#else /* QIMAGE_FRAMEBUFFER_WITH_DIRECT_OUTPUT */
     313    /* Directly draw sub-image (no copy involved): */
     314    painter.drawImage(rect.x(), rect.y(), subImage);
     315#endif /* QIMAGE_FRAMEBUFFER_WITH_DIRECT_OUTPUT */
    325316}
    326317
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBufferQImage.h

    r47067 r51131  
    5555    void paintScale(QPaintEvent *pEvent);
    5656
    57     /* Static helpers: Drawing stuff: */
    58     static void drawImageRectNarrow(QPainter &painter, const QImage &image,
    59                                     const QRect &rect, int iContentsShiftX, int iContentsShiftY);
    60     static void drawImageRectWide(QPainter &painter, const QImage &image,
    61                                   const QRect &rect, int iContentsShiftX, int iContentsShiftY);
     57    /** Draws corresponding @a rect of passed @a image with @a painter. */
     58    static void drawImageRect(QPainter &painter, const QImage &image, const QRect &rect,
     59                              int iContentsShiftX, int iContentsShiftY);
    6260
    6361    /* Helper: Fallback stuff: */
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