VirtualBox

Changeset 108390 in vbox


Ignore:
Timestamp:
Feb 26, 2025 10:49:10 AM (2 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
167754
Message:

FE/Qt: bugref:10450: Runtime UI: Merging paintDefault and paintSeamless UIFrameBuffer stuff, currently they are different just in few bits.

File:
1 edited

Legend:

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

    r108385 r108390  
    275275    /** Default paint routine. */
    276276    void paintDefault(QPaintEvent *pEvent);
    277     /** Paint routine for seamless mode. */
    278     void paintSeamless(QPaintEvent *pEvent);
    279277
    280278    /** Returns the transformation mode corresponding to the passed @a dScaleFactor and ScalingOptimizationType. */
     
    982980    }
    983981
    984     /* Depending on visual-state type: */
    985     switch (m_pMachineView->machineLogic()->visualStateType())
    986     {
    987         case UIVisualStateType_Seamless:
    988             paintSeamless(pEvent);
    989             break;
    990         default:
    991             paintDefault(pEvent);
    992             break;
    993     }
     982    /* Handle paint-event: */
     983    paintDefault(pEvent);
    994984
    995985    /* Unlock access to frame-buffer: */
     
    13071297    QPainter painter(m_pMachineView->viewport());
    13081298
     1299    /* Depending on visual-state type: */
     1300    switch (m_pMachineView->visualStateType())
     1301    {
     1302        case UIVisualStateType_Normal:
     1303        case UIVisualStateType_Fullscreen:
     1304        case UIVisualStateType_Scale:
     1305        {
    13091306#ifdef VBOX_WS_MAC
    1310     /* On OSX for Qt5 we need to fill the backing store first: */
    1311     painter.setCompositionMode(QPainter::CompositionMode_Source);
    1312     painter.fillRect(paintRect, QColor(Qt::black));
    1313     painter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
     1307            /* On OSX for Qt5 we need to fill the backing store first: */
     1308            painter.setCompositionMode(QPainter::CompositionMode_Source);
     1309            painter.fillRect(paintRect, QColor(Qt::black));
     1310            painter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
    13141311#endif /* VBOX_WS_MAC */
     1312
     1313            break;
     1314        }
     1315        case UIVisualStateType_Seamless:
     1316        {
     1317            /* Adjust painter for erasing: */
     1318            lock();
     1319            painter.setClipRegion(QRegion(paintRect) - m_syncVisibleRegion);
     1320            painter.setCompositionMode(QPainter::CompositionMode_Clear);
     1321            unlock();
     1322
     1323            /* Erase hidpi rectangle: */
     1324            eraseImageRect(painter, paintRectHiDPI,
     1325                           devicePixelRatio());
     1326
     1327            /* Adjust painter for painting: */
     1328            lock();
     1329            painter.setClipRegion(QRegion(paintRect) & m_syncVisibleRegion);
     1330            painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
     1331            unlock();
     1332
     1333#ifdef VBOX_WITH_TRANSLUCENT_SEAMLESS
     1334            /* In case of translucent seamless for Qt5 we need to fill the backing store first: */
     1335            painter.setCompositionMode(QPainter::CompositionMode_Source);
     1336            painter.fillRect(paintRect, QColor(Qt::black));
     1337            painter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
     1338#endif /* VBOX_WITH_TRANSLUCENT_SEAMLESS */
     1339
     1340            break;
     1341        }
     1342        default:
     1343            break;
     1344    }
    13151345
    13161346    /* Draw hidpi image rectangle: */
     
    13491379}
    13501380
    1351 void UIFrameBufferPrivate::paintSeamless(QPaintEvent *pEvent)
    1352 {
    1353     /* Make sure cached image is valid: */
    1354     if (m_image.isNull())
    1355         return;
    1356 
    1357     /* First we take the cached image as the source: */
    1358     QImage *pSourceImage = &m_image;
    1359 
    1360     /* But if we should scale image by some reason: */
    1361     if (   scaledSize().isValid()
    1362         || (!useUnscaledHiDPIOutput() && devicePixelRatio() != 1.0))
    1363     {
    1364         /* Calculate final scaled size: */
    1365         QSize effectiveSize = !scaledSize().isValid() ? pSourceImage->size() : scaledSize();
    1366         /* Take the device-pixel-ratio into account: */
    1367         if (!useUnscaledHiDPIOutput() && devicePixelRatio() != 1.0)
    1368             effectiveSize *= devicePixelRatio();
    1369         /* We scale the image to requested size and retain it
    1370          * by making heap shallow copy of that temporary object: */
    1371         switch (m_pMachineView->visualStateType())
    1372         {
    1373             case UIVisualStateType_Scale:
    1374                 pSourceImage = new QImage(pSourceImage->scaled(effectiveSize, Qt::IgnoreAspectRatio,
    1375                                                                transformationMode(scalingOptimizationType())));
    1376                 break;
    1377             default:
    1378                 pSourceImage = new QImage(pSourceImage->scaled(effectiveSize, Qt::IgnoreAspectRatio,
    1379                                                                transformationMode(scalingOptimizationType(), m_dScaleFactor)));
    1380                 break;
    1381         }
    1382     }
    1383 
    1384     /* Take the device-pixel-ratio into account: */
    1385     pSourceImage->setDevicePixelRatio(devicePixelRatio());
    1386 
    1387     /* Prepare the base and hidpi paint rectangles: */
    1388     QRect paintRect = pEvent->rect();
    1389     /* Adjust original rectangle the way that it can be fractionally upscaled to int values: */
    1390     if (devicePixelRatio() != 1.0)
    1391     {
    1392         paintRect.setLeft(findMultipleOfScaleFactor(devicePixelRatio(), paintRect.left(), false));
    1393         paintRect.setTop(findMultipleOfScaleFactor(devicePixelRatio(), paintRect.top(), false));
    1394         paintRect.setRight(findMultipleOfScaleFactor(devicePixelRatio(), paintRect.right(), true));
    1395         paintRect.setBottom(findMultipleOfScaleFactor(devicePixelRatio(), paintRect.bottom(), true));
    1396     }
    1397     QRect paintRectHiDPI = paintRect;
    1398 
    1399     /* Take the device-pixel-ratio into account: */
    1400     paintRectHiDPI.moveTo(paintRectHiDPI.topLeft() * devicePixelRatio());
    1401     paintRectHiDPI.setSize(paintRectHiDPI.size() * devicePixelRatio());
    1402 
    1403     /* Make sure hidpi paint rectangle is within the image boundary: */
    1404     paintRectHiDPI = paintRectHiDPI.intersected(pSourceImage->rect());
    1405     if (paintRectHiDPI.isEmpty())
    1406         return;
    1407 
    1408     /* Create painter: */
    1409     QPainter painter(m_pMachineView->viewport());
    1410 
    1411     /* Adjust painter for erasing: */
    1412     lock();
    1413     painter.setClipRegion(QRegion(paintRect) - m_syncVisibleRegion);
    1414     painter.setCompositionMode(QPainter::CompositionMode_Clear);
    1415     unlock();
    1416 
    1417     /* Erase hidpi rectangle: */
    1418     eraseImageRect(painter, paintRectHiDPI,
    1419                    devicePixelRatio());
    1420 
    1421     /* Adjust painter for painting: */
    1422     lock();
    1423     painter.setClipRegion(QRegion(paintRect) & m_syncVisibleRegion);
    1424     painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
    1425     unlock();
    1426 
    1427 #ifdef VBOX_WITH_TRANSLUCENT_SEAMLESS
    1428     /* In case of translucent seamless for Qt5 we need to fill the backing store first: */
    1429     painter.setCompositionMode(QPainter::CompositionMode_Source);
    1430     painter.fillRect(paintRect, QColor(Qt::black));
    1431     painter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
    1432 #endif /* VBOX_WITH_TRANSLUCENT_SEAMLESS */
    1433 
    1434     /* Draw hidpi image rectangle: */
    1435     drawImageRect(painter, *pSourceImage, paintRectHiDPI,
    1436                   m_pMachineView->contentsX(), m_pMachineView->contentsY(),
    1437                   devicePixelRatio());
    1438 
    1439     /* If we had to scale image for some reason: */
    1440     if (   scaledSize().isValid()
    1441         || (!useUnscaledHiDPIOutput() && devicePixelRatio() != 1.0))
    1442     {
    1443         /* Wipe out copied image: */
    1444         delete pSourceImage;
    1445         pSourceImage = 0;
    1446     }
    1447 
    1448     /* Paint cursor if it has valid shape and position.
    1449      * Also, please take into account, we are not currently painting
    1450      * framebuffer cursor if mouse integration is supported and enabled. */
    1451     if (   !m_cursorRectangle.isNull()
    1452         && !m_pMachineView->uimachine()->isHidingHostPointer()
    1453         && m_pMachineView->uimachine()->isValidPointerShapePresent()
    1454         && m_pMachineView->uimachine()->isValidCursorPositionPresent()
    1455         && (   !m_pMachineView->uimachine()->isMouseIntegrated()
    1456             || !m_pMachineView->uimachine()->isMouseSupportsAbsolute()))
    1457     {
    1458         /* Acquire session cursor shape pixmap: */
    1459         QPixmap cursorPixmap = m_pMachineView->uimachine()->cursorShapePixmap();
    1460 
    1461         /* Take the device-pixel-ratio into account: */
    1462         cursorPixmap.setDevicePixelRatio(devicePixelRatio());
    1463 
    1464         /* Draw sub-pixmap: */
    1465         painter.drawPixmap(m_cursorRectangle.topLeft(), cursorPixmap);
    1466     }
    1467 }
    1468 
    14691381/* static */
    14701382Qt::TransformationMode UIFrameBufferPrivate::transformationMode(ScalingOptimizationType type, double dScaleFactor /* = 0 */)
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