VirtualBox

Changeset 108075 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Feb 5, 2025 3:25:19 PM (3 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
167368
Message:

FE/Qt: Quick hack for the HiDIP update rounding issue which sometimes causes partial screen updates to be off by 1-2 pixels depending on your host scaling factor. Only an issue with non-integer factors.

File:
1 edited

Legend:

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

    r107411 r108075  
    277277    void updateCoordinateSystem();
    278278
     279    /** Applies alignment hack to HiDPI rectangle to avoid rounding problem.
     280     * @todo Temporary hack, please redo.  */
     281    static void alignHackForHiDPIRect(QRect &rectHiDPI, double rdPixelRatio);
     282
    279283    /** Default paint routine. */
    280284    void paintDefault(QPaintEvent *pEvent);
     
    12501254        m_transform = m_transform.scale(devicePixelRatioActual(), devicePixelRatioActual());
    12511255    m_transform = m_transform.scale(1.0 / devicePixelRatio(), 1.0 / devicePixelRatio());
     1256}
     1257
     1258/*static*/ void UIFrameBufferPrivate::alignHackForHiDPIRect(QRect &rectHiDPI, double rdPixelRatio)
     1259{
     1260    /* HACK ALERT! Extend the rectangle to avoid rounding issues related to devicePixelRatio(). */
     1261    if (rdPixelRatio != 1.0)
     1262    {
     1263        int iAlign;
     1264        switch (unsigned(rdPixelRatio * 8.0) & 7) /* ASSUMES scaling granularity  */
     1265        {
     1266            case 1: /* x.125 */
     1267            case 3: /* x.375 */
     1268            case 5: /* x.625 */
     1269            case 7: /* x.875 */
     1270                iAlign = 8;
     1271                break;
     1272            case 2: /* x.25 */
     1273            case 6: /* x.75 */
     1274                iAlign = 4;
     1275                break;
     1276            case 4: /* x.5 */
     1277                iAlign = 2;
     1278                break;
     1279            default:
     1280                return;
     1281        }
     1282        rectHiDPI.setTop(rectHiDPI.top() & ~iAlign);
     1283        rectHiDPI.setBottom((rectHiDPI.bottom() + iAlign - 1) & ~iAlign);
     1284        rectHiDPI.setLeft(rectHiDPI.left() & ~iAlign);
     1285        rectHiDPI.setRight((rectHiDPI.right() + iAlign - 1) & ~iAlign);
     1286    }
    12521287}
    12531288
     
    12951330    paintRectHiDPI.moveTo(paintRectHiDPI.topLeft() * devicePixelRatio());
    12961331    paintRectHiDPI.setSize(paintRectHiDPI.size() * devicePixelRatio());
     1332    alignHackForHiDPIRect(paintRectHiDPI, devicePixelRatio());
    12971333
    12981334    /* Make sure hidpi paint rectangle is within the image boundary: */
     
    13891425    paintRectHiDPI.moveTo(paintRectHiDPI.topLeft() * devicePixelRatio());
    13901426    paintRectHiDPI.setSize(paintRectHiDPI.size() * devicePixelRatio());
     1427    alignHackForHiDPIRect(paintRectHiDPI, devicePixelRatio());
    13911428
    13921429    /* Make sure hidpi paint rectangle is within the image boundary: */
     
    15121549    /* Which point we should draw corresponding sub-pixmap? */
    15131550    QPoint paintPoint = rect.topLeft();
    1514     /* Take the device-pixel-ratio into account: */
     1551    /* Take the device-pixel-ratio into account.
     1552       Note! I (bird) suspect this is the culprit for the off by one issues
     1553             during stuff like XP text mode installer and a bunch of other
     1554             situations (some involving XP desktop).  alignHackForHiDPIRect()
     1555             attempts to work around this by avoiding any rounding by making
     1556             sure the update rectangle is a multiple of the scaling factor.
     1557             Unfortuantely, due to clipping concerns, we have to apply the
     1558             hack in the calling code. */
    15151559    paintPoint /= dDevicePixelRatio;
    15161560
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