Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 45 additions & 23 deletions src/VBox/Frontends/VirtualBox/src/runtime/UIFrameBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,9 @@ void UIFrameBufferPrivate::performRescale()
switch (m_pMachineView->machineLogic()->visualStateType())
{
case UIVisualStateType_Scale:
#ifdef VBOX_WS_MAC
case UIVisualStateType_Fullscreen:
#endif
m_scaledSize = scaledSize().width() == m_iWidth && scaledSize().height() == m_iHeight ? QSize() : scaledSize();
break;
default:
Expand Down Expand Up @@ -1314,14 +1317,32 @@ void UIFrameBufferPrivate::paintDefault(QPaintEvent *pEvent)
/* Take the device-pixel-ratio into account: */
paintRectHiDPI.moveTo(paintRectHiDPI.topLeft() * devicePixelRatio());
paintRectHiDPI.setSize(paintRectHiDPI.size() * devicePixelRatio());

/* Make sure hidpi paint rectangle is within the image boundary: */
paintRectHiDPI &= pSourceImage->rect();
if (paintRectHiDPI.isEmpty())
{
#ifdef VBOX_WS_MAC
switch (m_pMachineView->visualStateType())
{
case UIVisualStateType_Normal:
case UIVisualStateType_Fullscreen:
case UIVisualStateType_Scale:
{
QPainter painter(m_pMachineView->viewport());
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect(paintRect, QColor(Qt::black));
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
break;
}
default:
break;
}
#endif /* VBOX_WS_MAC */
return;

}
/* Create painter: */
QPainter painter(m_pMachineView->viewport());
bool fRestoreSourceOverComposition = false;

/* Depending on visual-state type: */
switch (m_pMachineView->visualStateType())
Expand All @@ -1331,12 +1352,17 @@ void UIFrameBufferPrivate::paintDefault(QPaintEvent *pEvent)
case UIVisualStateType_Scale:
{
#ifdef VBOX_WS_MAC
/* On OSX for Qt5 we need to fill the backing store first: */
/* On macOS, make the destination explicitly opaque before drawing the guest image.
* The guest RGB32 backing buffer may carry transparent/undefined alpha bits for
* black pixels; drawing it with Source can copy those bits into the window backing
* store and make the boot framebuffer appear gray or washed out. */
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect(paintRect, QColor(Qt::black));
painter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
fRestoreSourceOverComposition = true;
#else
/* Nothing to do. */
#endif /* VBOX_WS_MAC */

break;
}
case UIVisualStateType_Seamless:
Expand All @@ -1357,12 +1383,12 @@ void UIFrameBufferPrivate::paintDefault(QPaintEvent *pEvent)
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
unlock();

#ifdef VBOX_WITH_TRANSLUCENT_SEAMLESS
#if defined(VBOX_WITH_TRANSLUCENT_SEAMLESS) && QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
/* In case of translucent seamless for Qt5 we need to fill the backing store first: */
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect(paintRect, QColor(Qt::black));
painter.setCompositionMode(QPainter::CompositionMode_SourceAtop);
#endif /* VBOX_WITH_TRANSLUCENT_SEAMLESS */
#endif /* VBOX_WITH_TRANSLUCENT_SEAMLESS && Qt < 6 */

break;
}
Expand All @@ -1374,6 +1400,8 @@ void UIFrameBufferPrivate::paintDefault(QPaintEvent *pEvent)
drawImageRect(painter, *pSourceImage, paintRectHiDPI,
m_pMachineView->contentsX(), m_pMachineView->contentsY(),
devicePixelRatio());
if (fRestoreSourceOverComposition)
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);

/* If we had to scale image for some reason: */
if ( scaledSize().isValid()
Expand Down Expand Up @@ -1441,31 +1469,25 @@ void UIFrameBufferPrivate::drawImageRect(QPainter &painter, const QImage &image,
int iContentsShiftX, int iContentsShiftY,
double dDevicePixelRatio)
{
/* Calculate offset: */
const size_t offset = (rect.x() + iContentsShiftX) * image.depth() / 8 +
(rect.y() + iContentsShiftY) * image.bytesPerLine();

/* Restrain boundaries: */
const int iSubImageWidth = qMin(rect.width(), image.width() - rect.x() - iContentsShiftX);
const int iSubImageHeight = qMin(rect.height(), image.height() - rect.y() - iContentsShiftY);
if ( iSubImageWidth <= 0
|| iSubImageHeight <= 0)
return;

/* Create sub-image (no copy involved): */
QImage subImage = QImage(image.bits() + offset,
iSubImageWidth, iSubImageHeight,
image.bytesPerLine(), image.format());

/* Create sub-pixmap on the basis of sub-image above (1st copy involved): */
QPixmap subPixmap = QPixmap::fromImage(subImage);
/* Take the device-pixel-ratio into account: */
subPixmap.setDevicePixelRatio(dDevicePixelRatio);

/* Which point we should draw corresponding sub-pixmap? */
/* Which point we should draw the image at? */
QPoint paintPoint = rect.topLeft();
/* Take the device-pixel-ratio into account: */
paintPoint /= dDevicePixelRatio;

/* Draw sub-pixmap: */
painter.drawPixmap(paintPoint, subPixmap);
/* Draw directly from the source image to avoid materializing a temporary pixmap for every update rectangle. */
const QRect sourceRect(rect.x() + iContentsShiftX, rect.y() + iContentsShiftY,
iSubImageWidth, iSubImageHeight);
const QRectF targetRect(QPointF(paintPoint),
QSizeF((double)iSubImageWidth / dDevicePixelRatio,
(double)iSubImageHeight / dDevicePixelRatio));
painter.drawImage(targetRect, image, sourceRect);
}

/* static */
Expand Down
29 changes: 21 additions & 8 deletions src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@

/* Other VBox includes: */
#include <iprt/path.h>
#include <iprt/time.h>

/* VirtualBox interface declarations: */
#include <VBox/com/VirtualBox.h>
Expand Down Expand Up @@ -332,19 +333,30 @@ void UIMachineLogic::openNetworkSettingsDialogTheModalWay()
}

#ifdef VBOX_WS_MAC
/** Minimum interval between live Dock preview frame updates. */
static const uint64_t s_u64DockIconUpdateIntervalMs = 250;

void UIMachineLogic::updateDockIcon()
{
if (!isMachineWindowsCreated())
return;

if ( m_fIsDockIconEnabled
&& m_pDockIconPreview)
if(UIMachineView *pView = machineWindows().at(m_DockIconPreviewMonitor)->machineView())
if (CGImageRef image = pView->vmContentImage())
{
m_pDockIconPreview->updateDockPreview(image);
CGImageRelease(image);
}
if ( !m_fIsDockIconEnabled
|| !m_pDockIconPreview)
return;

const uint64_t u64NowMs = RTTimeMilliTS();
if ( m_u64LastDockIconUpdateMs
&& u64NowMs - m_u64LastDockIconUpdateMs < s_u64DockIconUpdateIntervalMs)
return;

if (UIMachineView *pView = machineWindows().at(m_DockIconPreviewMonitor)->machineView())
if (CGImageRef image = pView->vmContentImage())
{
m_u64LastDockIconUpdateMs = u64NowMs;
m_pDockIconPreview->updateDockPreview(image);
CGImageRelease(image);
}
}

void UIMachineLogic::updateDockIconSize(int screenId, int width, int height)
Expand Down Expand Up @@ -790,6 +802,7 @@ UIMachineLogic::UIMachineLogic(UIMachine *pMachine)
, m_pDockPreviewSelectMonitorGroup(0)
, m_pDockSettingsMenuSeparator(0)
, m_DockIconPreviewMonitor(0)
, m_u64LastDockIconUpdateMs(0)
, m_pDockSettingMenuAction(0)
#endif /* VBOX_WS_MAC */
, m_pHostLedsState(NULL)
Expand Down
1 change: 1 addition & 0 deletions src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ private slots:
QActionGroup *m_pDockPreviewSelectMonitorGroup;
QAction *m_pDockSettingsMenuSeparator;
int m_DockIconPreviewMonitor;
uint64_t m_u64LastDockIconUpdateMs;
QAction *m_pDockSettingMenuAction;
/* Keeps a list of machine menu actions that we add to dock menu. */
QList<QAction*> m_dockMachineMenuActions;
Expand Down