scripting: Provide hidpi window thumbnails

This commit is contained in:
Vlad Zahorodnii 2021-07-16 19:29:31 +03:00
parent 97f8bfac5c
commit 9e5cb836a3
2 changed files with 12 additions and 3 deletions

View file

@ -211,7 +211,9 @@ QSGNode *ThumbnailItemBase::updatePaintNode(QSGNode *oldNode, QQuickItem::Update
if (m_offscreenTexture) {
m_provider->setTexture(m_offscreenTexture);
} else {
m_provider->setTexture(window()->createTextureFromImage(fallbackImage()));
const QImage placeholderImage = fallbackImage();
m_provider->setTexture(window()->createTextureFromImage(placeholderImage));
m_devicePixelRatio = placeholderImage.devicePixelRatio();
}
QSGImageNode *node = static_cast<QSGImageNode *>(oldNode);
@ -226,7 +228,7 @@ QSGNode *ThumbnailItemBase::updatePaintNode(QSGNode *oldNode, QQuickItem::Update
node->setTextureCoordinatesTransform(QSGImageNode::NoTransform);
}
const QSizeF size = QSizeF(node->texture()->textureSize())
const QSizeF size = QSizeF(node->texture()->textureSize() / m_devicePixelRatio)
.scaled(boundingRect().size(), Qt::KeepAspectRatio);
const qreal x = boundingRect().x() + (boundingRect().width() - size.width()) / 2;
const qreal y = boundingRect().y() + (boundingRect().height() - size.height()) / 2;
@ -311,7 +313,7 @@ void WindowThumbnailItem::setClient(AbstractClient *client)
QImage WindowThumbnailItem::fallbackImage() const
{
if (m_client) {
return m_client->icon().pixmap(boundingRect().size().toSize()).toImage();
return m_client->icon().pixmap(window(), boundingRect().size().toSize()).toImage();
}
return QImage();
}
@ -337,6 +339,9 @@ void WindowThumbnailItem::updateOffscreenTexture()
textureSize.setHeight(sourceSize().height());
}
m_devicePixelRatio = window()->devicePixelRatio();
textureSize *= m_devicePixelRatio;
if (!m_offscreenTexture || m_offscreenTexture->size() != textureSize) {
m_offscreenTexture.reset(new GLTexture(GL_RGBA8, textureSize));
m_offscreenTexture->setFilter(GL_LINEAR);
@ -417,6 +422,9 @@ void DesktopThumbnailItem::updateOffscreenTexture()
textureSize.setHeight(sourceSize().height());
}
m_devicePixelRatio = window()->devicePixelRatio();
textureSize *= m_devicePixelRatio;
if (!m_offscreenTexture || m_offscreenTexture->size() != textureSize) {
m_offscreenTexture.reset(new GLTexture(GL_RGBA8, textureSize));
m_offscreenTexture->setFilter(GL_LINEAR);

View file

@ -77,6 +77,7 @@ protected:
QSharedPointer<GLTexture> m_offscreenTexture;
QScopedPointer<GLRenderTarget> m_offscreenTarget;
GLsync m_acquireFence = 0;
qreal m_devicePixelRatio = 1;
private:
void handleCompositingToggled();