Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.cpp	(revision 71056)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.cpp	(revision 71057)
@@ -294,10 +294,8 @@
     /** Erases corresponding @a rect with @a painter. */
     static void eraseImageRect(QPainter &painter, const QRect &rect,
-                               bool fUseUnscaledHiDPIOutput,
                                double dDevicePixelRatio);
     /** Draws corresponding @a rect of passed @a image with @a painter. */
     static void drawImageRect(QPainter &painter, const QImage &image, const QRect &rect,
                               int iContentsShiftX, int iContentsShiftY,
-                              bool fUseUnscaledHiDPIOutput,
                               double dDevicePixelRatio);
 
@@ -1336,7 +1334,13 @@
     QImage *pSourceImage = &m_image;
 
-    /* But if scaled size is set: */
-    if (m_scaledSize.isValid())
-    {
+    /* But if we should scale image by some reason: */
+    if (   scaledSize().isValid()
+        || (!useUnscaledHiDPIOutput() && devicePixelRatio() != 1.0))
+    {
+        /* Calculate final scaled size: */
+        QSize effectiveSize = !scaledSize().isValid() ? pSourceImage->size() : scaledSize();
+        /* Take the device-pixel-ratio into account: */
+        if (!useUnscaledHiDPIOutput() && devicePixelRatio() != 1.0)
+            effectiveSize *= devicePixelRatio();
         /* We scale the image to requested size and retain it
          * by making heap shallow copy of that temporary object: */
@@ -1344,9 +1348,9 @@
         {
             case UIVisualStateType_Scale:
-                pSourceImage = new QImage(pSourceImage->scaled(m_scaledSize, Qt::IgnoreAspectRatio,
+                pSourceImage = new QImage(pSourceImage->scaled(effectiveSize, Qt::IgnoreAspectRatio,
                                                                transformationMode(scalingOptimizationType())));
                 break;
             default:
-                pSourceImage = new QImage(pSourceImage->scaled(m_scaledSize, Qt::IgnoreAspectRatio,
+                pSourceImage = new QImage(pSourceImage->scaled(effectiveSize, Qt::IgnoreAspectRatio,
                                                                transformationMode(scalingOptimizationType(), m_dScaleFactor)));
                 break;
@@ -1354,4 +1358,7 @@
     }
 
+    /* Take the device-pixel-ratio into account: */
+    pSourceImage->setDevicePixelRatio(devicePixelRatio());
+
     /* Prepare the base and hidpi paint rectangles: */
     const QRect paintRect = pEvent->rect();
@@ -1359,9 +1366,6 @@
 
     /* Take the device-pixel-ratio into account: */
-    if (useUnscaledHiDPIOutput() && devicePixelRatio() > 1.0)
-    {
-        paintRectHiDPI.moveTo(paintRectHiDPI.topLeft() * devicePixelRatio());
-        paintRectHiDPI.setSize(paintRectHiDPI.size() * devicePixelRatio());
-    }
+    paintRectHiDPI.moveTo(paintRectHiDPI.topLeft() * devicePixelRatio());
+    paintRectHiDPI.setSize(paintRectHiDPI.size() * devicePixelRatio());
 
     /* Make sure hidpi paint rectangle is within the image boundary: */
@@ -1383,9 +1387,9 @@
     drawImageRect(painter, *pSourceImage, paintRectHiDPI,
                   m_pMachineView->contentsX(), m_pMachineView->contentsY(),
-                  useUnscaledHiDPIOutput(),
                   devicePixelRatio());
 
-    /* If scaled size is set: */
-    if (m_scaledSize.isValid())
+    /* If we had to scale image for some reason: */
+    if (   scaledSize().isValid()
+        || (!useUnscaledHiDPIOutput() && devicePixelRatio() != 1.0))
     {
         /* Wipe out copied image: */
@@ -1404,7 +1408,13 @@
     QImage *pSourceImage = &m_image;
 
-    /* But if scaled size is set: */
-    if (m_scaledSize.isValid())
-    {
+    /* But if we should scale image by some reason: */
+    if (   scaledSize().isValid()
+        || (!useUnscaledHiDPIOutput() && devicePixelRatio() != 1.0))
+    {
+        /* Calculate final scaled size: */
+        QSize effectiveSize = !scaledSize().isValid() ? pSourceImage->size() : scaledSize();
+        /* Take the device-pixel-ratio into account: */
+        if (!useUnscaledHiDPIOutput() && devicePixelRatio() != 1.0)
+            effectiveSize *= devicePixelRatio();
         /* We scale the image to requested size and retain it
          * by making heap shallow copy of that temporary object: */
@@ -1412,9 +1422,9 @@
         {
             case UIVisualStateType_Scale:
-                pSourceImage = new QImage(pSourceImage->scaled(m_scaledSize, Qt::IgnoreAspectRatio,
+                pSourceImage = new QImage(pSourceImage->scaled(effectiveSize, Qt::IgnoreAspectRatio,
                                                                transformationMode(scalingOptimizationType())));
                 break;
             default:
-                pSourceImage = new QImage(pSourceImage->scaled(m_scaledSize, Qt::IgnoreAspectRatio,
+                pSourceImage = new QImage(pSourceImage->scaled(effectiveSize, Qt::IgnoreAspectRatio,
                                                                transformationMode(scalingOptimizationType(), m_dScaleFactor)));
                 break;
@@ -1422,4 +1432,7 @@
     }
 
+    /* Take the device-pixel-ratio into account: */
+    pSourceImage->setDevicePixelRatio(devicePixelRatio());
+
     /* Prepare the base and hidpi paint rectangles: */
     const QRect paintRect = pEvent->rect();
@@ -1427,9 +1440,6 @@
 
     /* Take the device-pixel-ratio into account: */
-    if (useUnscaledHiDPIOutput() && devicePixelRatio() > 1.0)
-    {
-        paintRectHiDPI.moveTo(paintRectHiDPI.topLeft() * devicePixelRatio());
-        paintRectHiDPI.setSize(paintRectHiDPI.size() * devicePixelRatio());
-    }
+    paintRectHiDPI.moveTo(paintRectHiDPI.topLeft() * devicePixelRatio());
+    paintRectHiDPI.setSize(paintRectHiDPI.size() * devicePixelRatio());
 
     /* Make sure hidpi paint rectangle is within the image boundary: */
@@ -1449,5 +1459,4 @@
     /* Erase hidpi rectangle: */
     eraseImageRect(painter, paintRectHiDPI,
-                   useUnscaledHiDPIOutput(),
                    devicePixelRatio());
 
@@ -1468,9 +1477,9 @@
     drawImageRect(painter, *pSourceImage, paintRectHiDPI,
                   m_pMachineView->contentsX(), m_pMachineView->contentsY(),
-                  useUnscaledHiDPIOutput(),
                   devicePixelRatio());
 
-    /* If scaled size is set: */
-    if (m_scaledSize.isValid())
+    /* If we had to scale image for some reason: */
+    if (   scaledSize().isValid()
+        || (!useUnscaledHiDPIOutput() && devicePixelRatio() != 1.0))
     {
         /* Wipe out copied image: */
@@ -1495,31 +1504,15 @@
 /* static */
 void UIFrameBufferPrivate::eraseImageRect(QPainter &painter, const QRect &rect,
-                                          bool fUseUnscaledHiDPIOutput,
                                           double dDevicePixelRatio)
 {
     /* Prepare sub-pixmap: */
     QPixmap subPixmap = QPixmap(rect.width(), rect.height());
-
-    /* If HiDPI 'device-pixel-ratio' defined: */
-    if (dDevicePixelRatio > 1.0)
-    {
-        /* In auto-scale mode: */
-        if (!fUseUnscaledHiDPIOutput)
-        {
-            /* Adjust sub-pixmap: */
-            subPixmap = QPixmap((int)(rect.width() * dDevicePixelRatio),
-                                (int)(rect.height() * dDevicePixelRatio));
-        }
-
-        /* Mark sub-pixmap HiDPI: */
-        subPixmap.setDevicePixelRatio(dDevicePixelRatio);
-    }
+    /* Take the device-pixel-ratio into account: */
+    subPixmap.setDevicePixelRatio(dDevicePixelRatio);
 
     /* Which point we should draw corresponding sub-pixmap? */
-    QPointF paintPoint = rect.topLeft();
-
+    QPoint paintPoint = rect.topLeft();
     /* Take the device-pixel-ratio into account: */
-    if (fUseUnscaledHiDPIOutput && dDevicePixelRatio > 1.0)
-        paintPoint /= dDevicePixelRatio;
+    paintPoint /= dDevicePixelRatio;
 
     /* Draw sub-pixmap: */
@@ -1530,5 +1523,4 @@
 void UIFrameBufferPrivate::drawImageRect(QPainter &painter, const QImage &image, const QRect &rect,
                                          int iContentsShiftX, int iContentsShiftY,
-                                         bool fUseUnscaledHiDPIOutput,
                                          double dDevicePixelRatio)
 {
@@ -1548,26 +1540,11 @@
     /* Create sub-pixmap on the basis of sub-image above (1st copy involved): */
     QPixmap subPixmap = QPixmap::fromImage(subImage);
-
-    /* If HiDPI 'device-pixel-ratio' defined: */
-    if (dDevicePixelRatio > 1.0)
-    {
-        /* In auto-scale mode: */
-        if (!fUseUnscaledHiDPIOutput)
-        {
-            /* Fast scale sub-pixmap (2nd copy involved): */
-            subPixmap = subPixmap.scaled(subPixmap.size() * dDevicePixelRatio,
-                                         Qt::IgnoreAspectRatio, Qt::FastTransformation);
-        }
-
-        /* Mark sub-pixmap HiDPI: */
-        subPixmap.setDevicePixelRatio(dDevicePixelRatio);
-    }
+    /* Take the device-pixel-ratio into account: */
+    subPixmap.setDevicePixelRatio(dDevicePixelRatio);
 
     /* Which point we should draw corresponding sub-pixmap? */
-    QPointF paintPoint = rect.topLeft();
-
+    QPoint paintPoint = rect.topLeft();
     /* Take the device-pixel-ratio into account: */
-    if (fUseUnscaledHiDPIOutput && dDevicePixelRatio > 1.0)
-        paintPoint /= dDevicePixelRatio;
+    paintPoint /= dDevicePixelRatio;
 
     /* Draw sub-pixmap: */
