VirtualBox

Ignore:
Timestamp:
Feb 19, 2018 2:27:09 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
120920
Message:

FE/Qt: bugref:8694: Runtime UI: Framebuffer: Simplify HiDPI painting routine; that is a requirement for fractional device-pixel-ratio support.

File:
1 edited

Legend:

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

    r71056 r71057  
    294294    /** Erases corresponding @a rect with @a painter. */
    295295    static void eraseImageRect(QPainter &painter, const QRect &rect,
    296                                bool fUseUnscaledHiDPIOutput,
    297296                               double dDevicePixelRatio);
    298297    /** Draws corresponding @a rect of passed @a image with @a painter. */
    299298    static void drawImageRect(QPainter &painter, const QImage &image, const QRect &rect,
    300299                              int iContentsShiftX, int iContentsShiftY,
    301                               bool fUseUnscaledHiDPIOutput,
    302300                              double dDevicePixelRatio);
    303301
     
    13361334    QImage *pSourceImage = &m_image;
    13371335
    1338     /* But if scaled size is set: */
    1339     if (m_scaledSize.isValid())
    1340     {
     1336    /* But if we should scale image by some reason: */
     1337    if (   scaledSize().isValid()
     1338        || (!useUnscaledHiDPIOutput() && devicePixelRatio() != 1.0))
     1339    {
     1340        /* Calculate final scaled size: */
     1341        QSize effectiveSize = !scaledSize().isValid() ? pSourceImage->size() : scaledSize();
     1342        /* Take the device-pixel-ratio into account: */
     1343        if (!useUnscaledHiDPIOutput() && devicePixelRatio() != 1.0)
     1344            effectiveSize *= devicePixelRatio();
    13411345        /* We scale the image to requested size and retain it
    13421346         * by making heap shallow copy of that temporary object: */
     
    13441348        {
    13451349            case UIVisualStateType_Scale:
    1346                 pSourceImage = new QImage(pSourceImage->scaled(m_scaledSize, Qt::IgnoreAspectRatio,
     1350                pSourceImage = new QImage(pSourceImage->scaled(effectiveSize, Qt::IgnoreAspectRatio,
    13471351                                                               transformationMode(scalingOptimizationType())));
    13481352                break;
    13491353            default:
    1350                 pSourceImage = new QImage(pSourceImage->scaled(m_scaledSize, Qt::IgnoreAspectRatio,
     1354                pSourceImage = new QImage(pSourceImage->scaled(effectiveSize, Qt::IgnoreAspectRatio,
    13511355                                                               transformationMode(scalingOptimizationType(), m_dScaleFactor)));
    13521356                break;
     
    13541358    }
    13551359
     1360    /* Take the device-pixel-ratio into account: */
     1361    pSourceImage->setDevicePixelRatio(devicePixelRatio());
     1362
    13561363    /* Prepare the base and hidpi paint rectangles: */
    13571364    const QRect paintRect = pEvent->rect();
     
    13591366
    13601367    /* Take the device-pixel-ratio into account: */
    1361     if (useUnscaledHiDPIOutput() && devicePixelRatio() > 1.0)
    1362     {
    1363         paintRectHiDPI.moveTo(paintRectHiDPI.topLeft() * devicePixelRatio());
    1364         paintRectHiDPI.setSize(paintRectHiDPI.size() * devicePixelRatio());
    1365     }
     1368    paintRectHiDPI.moveTo(paintRectHiDPI.topLeft() * devicePixelRatio());
     1369    paintRectHiDPI.setSize(paintRectHiDPI.size() * devicePixelRatio());
    13661370
    13671371    /* Make sure hidpi paint rectangle is within the image boundary: */
     
    13831387    drawImageRect(painter, *pSourceImage, paintRectHiDPI,
    13841388                  m_pMachineView->contentsX(), m_pMachineView->contentsY(),
    1385                   useUnscaledHiDPIOutput(),
    13861389                  devicePixelRatio());
    13871390
    1388     /* If scaled size is set: */
    1389     if (m_scaledSize.isValid())
     1391    /* If we had to scale image for some reason: */
     1392    if (   scaledSize().isValid()
     1393        || (!useUnscaledHiDPIOutput() && devicePixelRatio() != 1.0))
    13901394    {
    13911395        /* Wipe out copied image: */
     
    14041408    QImage *pSourceImage = &m_image;
    14051409
    1406     /* But if scaled size is set: */
    1407     if (m_scaledSize.isValid())
    1408     {
     1410    /* But if we should scale image by some reason: */
     1411    if (   scaledSize().isValid()
     1412        || (!useUnscaledHiDPIOutput() && devicePixelRatio() != 1.0))
     1413    {
     1414        /* Calculate final scaled size: */
     1415        QSize effectiveSize = !scaledSize().isValid() ? pSourceImage->size() : scaledSize();
     1416        /* Take the device-pixel-ratio into account: */
     1417        if (!useUnscaledHiDPIOutput() && devicePixelRatio() != 1.0)
     1418            effectiveSize *= devicePixelRatio();
    14091419        /* We scale the image to requested size and retain it
    14101420         * by making heap shallow copy of that temporary object: */
     
    14121422        {
    14131423            case UIVisualStateType_Scale:
    1414                 pSourceImage = new QImage(pSourceImage->scaled(m_scaledSize, Qt::IgnoreAspectRatio,
     1424                pSourceImage = new QImage(pSourceImage->scaled(effectiveSize, Qt::IgnoreAspectRatio,
    14151425                                                               transformationMode(scalingOptimizationType())));
    14161426                break;
    14171427            default:
    1418                 pSourceImage = new QImage(pSourceImage->scaled(m_scaledSize, Qt::IgnoreAspectRatio,
     1428                pSourceImage = new QImage(pSourceImage->scaled(effectiveSize, Qt::IgnoreAspectRatio,
    14191429                                                               transformationMode(scalingOptimizationType(), m_dScaleFactor)));
    14201430                break;
     
    14221432    }
    14231433
     1434    /* Take the device-pixel-ratio into account: */
     1435    pSourceImage->setDevicePixelRatio(devicePixelRatio());
     1436
    14241437    /* Prepare the base and hidpi paint rectangles: */
    14251438    const QRect paintRect = pEvent->rect();
     
    14271440
    14281441    /* Take the device-pixel-ratio into account: */
    1429     if (useUnscaledHiDPIOutput() && devicePixelRatio() > 1.0)
    1430     {
    1431         paintRectHiDPI.moveTo(paintRectHiDPI.topLeft() * devicePixelRatio());
    1432         paintRectHiDPI.setSize(paintRectHiDPI.size() * devicePixelRatio());
    1433     }
     1442    paintRectHiDPI.moveTo(paintRectHiDPI.topLeft() * devicePixelRatio());
     1443    paintRectHiDPI.setSize(paintRectHiDPI.size() * devicePixelRatio());
    14341444
    14351445    /* Make sure hidpi paint rectangle is within the image boundary: */
     
    14491459    /* Erase hidpi rectangle: */
    14501460    eraseImageRect(painter, paintRectHiDPI,
    1451                    useUnscaledHiDPIOutput(),
    14521461                   devicePixelRatio());
    14531462
     
    14681477    drawImageRect(painter, *pSourceImage, paintRectHiDPI,
    14691478                  m_pMachineView->contentsX(), m_pMachineView->contentsY(),
    1470                   useUnscaledHiDPIOutput(),
    14711479                  devicePixelRatio());
    14721480
    1473     /* If scaled size is set: */
    1474     if (m_scaledSize.isValid())
     1481    /* If we had to scale image for some reason: */
     1482    if (   scaledSize().isValid()
     1483        || (!useUnscaledHiDPIOutput() && devicePixelRatio() != 1.0))
    14751484    {
    14761485        /* Wipe out copied image: */
     
    14951504/* static */
    14961505void UIFrameBufferPrivate::eraseImageRect(QPainter &painter, const QRect &rect,
    1497                                           bool fUseUnscaledHiDPIOutput,
    14981506                                          double dDevicePixelRatio)
    14991507{
    15001508    /* Prepare sub-pixmap: */
    15011509    QPixmap subPixmap = QPixmap(rect.width(), rect.height());
    1502 
    1503     /* If HiDPI 'device-pixel-ratio' defined: */
    1504     if (dDevicePixelRatio > 1.0)
    1505     {
    1506         /* In auto-scale mode: */
    1507         if (!fUseUnscaledHiDPIOutput)
    1508         {
    1509             /* Adjust sub-pixmap: */
    1510             subPixmap = QPixmap((int)(rect.width() * dDevicePixelRatio),
    1511                                 (int)(rect.height() * dDevicePixelRatio));
    1512         }
    1513 
    1514         /* Mark sub-pixmap HiDPI: */
    1515         subPixmap.setDevicePixelRatio(dDevicePixelRatio);
    1516     }
     1510    /* Take the device-pixel-ratio into account: */
     1511    subPixmap.setDevicePixelRatio(dDevicePixelRatio);
    15171512
    15181513    /* Which point we should draw corresponding sub-pixmap? */
    1519     QPointF paintPoint = rect.topLeft();
    1520 
     1514    QPoint paintPoint = rect.topLeft();
    15211515    /* Take the device-pixel-ratio into account: */
    1522     if (fUseUnscaledHiDPIOutput && dDevicePixelRatio > 1.0)
    1523         paintPoint /= dDevicePixelRatio;
     1516    paintPoint /= dDevicePixelRatio;
    15241517
    15251518    /* Draw sub-pixmap: */
     
    15301523void UIFrameBufferPrivate::drawImageRect(QPainter &painter, const QImage &image, const QRect &rect,
    15311524                                         int iContentsShiftX, int iContentsShiftY,
    1532                                          bool fUseUnscaledHiDPIOutput,
    15331525                                         double dDevicePixelRatio)
    15341526{
     
    15481540    /* Create sub-pixmap on the basis of sub-image above (1st copy involved): */
    15491541    QPixmap subPixmap = QPixmap::fromImage(subImage);
    1550 
    1551     /* If HiDPI 'device-pixel-ratio' defined: */
    1552     if (dDevicePixelRatio > 1.0)
    1553     {
    1554         /* In auto-scale mode: */
    1555         if (!fUseUnscaledHiDPIOutput)
    1556         {
    1557             /* Fast scale sub-pixmap (2nd copy involved): */
    1558             subPixmap = subPixmap.scaled(subPixmap.size() * dDevicePixelRatio,
    1559                                          Qt::IgnoreAspectRatio, Qt::FastTransformation);
    1560         }
    1561 
    1562         /* Mark sub-pixmap HiDPI: */
    1563         subPixmap.setDevicePixelRatio(dDevicePixelRatio);
    1564     }
     1542    /* Take the device-pixel-ratio into account: */
     1543    subPixmap.setDevicePixelRatio(dDevicePixelRatio);
    15651544
    15661545    /* Which point we should draw corresponding sub-pixmap? */
    1567     QPointF paintPoint = rect.topLeft();
    1568 
     1546    QPoint paintPoint = rect.topLeft();
    15691547    /* Take the device-pixel-ratio into account: */
    1570     if (fUseUnscaledHiDPIOutput && dDevicePixelRatio > 1.0)
    1571         paintPoint /= dDevicePixelRatio;
     1548    paintPoint /= dDevicePixelRatio;
    15721549
    15731550    /* Draw sub-pixmap: */
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