libkwineffects: Drop QtQuick dummy window hack

The dummy window hack was needed to ensure hidpi rendering on Wayland.
We introduced QQuickRenderTarget::setDevicePixelRatio() in Qt 6.3, so
the hack can be removed now.
This commit is contained in:
Vlad Zahorodnii 2023-02-27 23:54:28 +02:00
parent b93e01a724
commit 3aa16bd1ca
9 changed files with 10 additions and 109 deletions

View file

@ -74,13 +74,9 @@ void OutputLocatorEffect::show()
return;
}
// Needed until Qt6 https://codereview.qt-project.org/c/qt/qtdeclarative/+/361506
m_dummyWindow = std::make_unique<QWindow>();
m_dummyWindow->create();
const auto screens = effects->screens();
for (const auto screen : screens) {
auto scene = new OffscreenQuickScene(this, m_dummyWindow.get());
auto scene = new OffscreenQuickScene(this);
scene->setSource(m_qmlUrl, {{QStringLiteral("outputName"), outputName(screen)}, {QStringLiteral("resolution"), screen->geometry().size()}, {QStringLiteral("scale"), screen->devicePixelRatio()}});
QRectF geometry(0, 0, scene->rootItem()->implicitWidth(), scene->rootItem()->implicitHeight());
geometry.moveCenter(screen->geometry().center());

View file

@ -9,7 +9,6 @@
#include <kwineffects.h>
#include <QTimer>
#include <QWindow>
namespace KWin
{
@ -31,7 +30,6 @@ public Q_SLOTS:
private:
QUrl m_qmlUrl;
QTimer m_showTimer;
std::unique_ptr<QWindow> m_dummyWindow;
QMap<EffectScreen *, OffscreenQuickScene *> m_scenesByScreens;
};
}

View file

@ -9,7 +9,6 @@
#include "showfpseffect.h"
#include <QQmlContext>
#include <QWindow>
namespace KWin
{
@ -69,9 +68,7 @@ void ShowFpsEffect::prePaintScreen(ScreenPrePaintData &data, std::chrono::millis
}
if (!m_scene) {
m_window = std::make_unique<QWindow>();
m_window->create();
m_scene = std::make_unique<OffscreenQuickScene>(nullptr, m_window.get());
m_scene = std::make_unique<OffscreenQuickScene>(nullptr);
const auto url = QUrl::fromLocalFile(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kwin/effects/showfps/qml/main.qml")));
m_scene->setSource(url, {{QStringLiteral("effect"), QVariant::fromValue(this)}});
}

View file

@ -48,7 +48,6 @@ Q_SIGNALS:
void paintChanged();
private:
std::unique_ptr<QWindow> m_window;
std::unique_ptr<OffscreenQuickScene> m_scene;
int m_maximumFps = 0;

View file

@ -34,35 +34,6 @@
namespace KWin
{
class EffectQuickRenderControl : public QQuickRenderControl
{
Q_OBJECT
public:
explicit EffectQuickRenderControl(OffscreenQuickView *view, QWindow *renderWindow)
: QQuickRenderControl(view)
, m_view(view)
, m_renderWindow(renderWindow)
{
}
QWindow *renderWindow(QPoint *offset) override
{
if (offset) {
if (m_renderWindow) {
*offset = m_renderWindow->mapFromGlobal(m_view->geometry().topLeft());
} else {
*offset = QPoint(0, 0);
}
}
return m_renderWindow;
}
private:
OffscreenQuickView *m_view;
QPointer<QWindow> m_renderWindow;
};
class Q_DECL_HIDDEN OffscreenQuickView::Private
{
public:
@ -111,20 +82,10 @@ OffscreenQuickView::OffscreenQuickView(QObject *parent)
}
OffscreenQuickView::OffscreenQuickView(QObject *parent, ExportMode exportMode)
: OffscreenQuickView(parent, nullptr, exportMode)
{
}
OffscreenQuickView::OffscreenQuickView(QObject *parent, QWindow *renderWindow)
: OffscreenQuickView(parent, renderWindow, effects ? ExportMode::Texture : ExportMode::Image)
{
}
OffscreenQuickView::OffscreenQuickView(QObject *parent, QWindow *renderWindow, ExportMode exportMode)
: QObject(parent)
, d(new OffscreenQuickView::Private)
{
d->m_renderControl = std::make_unique<EffectQuickRenderControl>(this, renderWindow);
d->m_renderControl = std::make_unique<QQuickRenderControl>();
d->m_view = std::make_unique<QQuickWindow>(d->m_renderControl.get());
d->m_view->setFlags(Qt::FramelessWindowHint);
@ -263,7 +224,11 @@ void OffscreenQuickView::update()
return;
}
}
d->m_view->setRenderTarget(QQuickRenderTarget::fromOpenGLTexture(d->m_fbo->texture(), d->m_fbo->size()));
QQuickRenderTarget renderTarget = QQuickRenderTarget::fromOpenGLTexture(d->m_fbo->texture(), d->m_fbo->size());
renderTarget.setDevicePixelRatio(d->m_view->devicePixelRatio());
d->m_view->setRenderTarget(renderTarget);
}
d->m_renderControl->polishItems();
@ -559,18 +524,6 @@ OffscreenQuickScene::OffscreenQuickScene(QObject *parent)
{
}
OffscreenQuickScene::OffscreenQuickScene(QObject *parent, QWindow *renderWindow)
: OffscreenQuickView(parent, renderWindow)
, d(new OffscreenQuickScene::Private)
{
}
OffscreenQuickScene::OffscreenQuickScene(QObject *parent, QWindow *renderWindow, ExportMode exportMode)
: OffscreenQuickView(parent, renderWindow, exportMode)
, d(new OffscreenQuickScene::Private)
{
}
OffscreenQuickScene::OffscreenQuickScene(QObject *parent, OffscreenQuickView::ExportMode exportMode)
: OffscreenQuickView(parent, exportMode)
, d(new OffscreenQuickScene::Private)

View file

@ -62,20 +62,6 @@ public:
*/
OffscreenQuickView(QObject *parent);
/**
* Construct a new OffscreenQuickView with the specified @a parent and the
* render window @a renderWindow. The render window can be used by QtQuick
* to compute the scale factor.
*/
OffscreenQuickView(QObject *parent, QWindow *renderWindow);
/**
* Construct a new OffscreenQuickView with the specified @a parent and the
* render window @a renderWindow. The render window can be used by QtQuick
* to compute the scale factor.
*/
OffscreenQuickView(QObject *parent, QWindow *renderWindow, ExportMode exportMode);
/**
* Construct a new KWinQuickView explicitly stating an export mode
*/
@ -180,8 +166,6 @@ class KWINEFFECTS_EXPORT OffscreenQuickScene : public OffscreenQuickView
public:
OffscreenQuickScene(QObject *parent);
OffscreenQuickScene(QObject *parent, ExportMode exportMode);
OffscreenQuickScene(QObject *parent, QWindow *renderWindow);
OffscreenQuickScene(QObject *parent, QWindow *renderWindow, ExportMode exportMode);
~OffscreenQuickScene();
QQmlContext *rootContext() const;

View file

@ -13,7 +13,6 @@
#include <QQmlIncubator>
#include <QQuickItem>
#include <QQuickWindow>
#include <QWindow>
namespace KWin
{
@ -71,7 +70,6 @@ public:
std::map<EffectScreen *, std::unique_ptr<QuickSceneView>> views;
QPointer<QuickSceneView> mouseImplicitGrab;
bool running = false;
std::unique_ptr<QWindow> dummyWindow;
};
bool QuickSceneEffectPrivate::isItemOnScreen(QQuickItem *item, EffectScreen *screen) const
@ -85,7 +83,7 @@ bool QuickSceneEffectPrivate::isItemOnScreen(QQuickItem *item, EffectScreen *scr
}
QuickSceneView::QuickSceneView(QuickSceneEffect *effect, EffectScreen *screen)
: OffscreenQuickView(effect, QuickSceneEffectPrivate::get(effect)->dummyWindow.get())
: OffscreenQuickView(effect)
, m_effect(effect)
, m_screen(screen)
{
@ -460,17 +458,6 @@ void QuickSceneEffect::startInternal()
// Install an event filter to monitor cursor shape changes.
qApp->installEventFilter(this);
// This is an ugly hack to make hidpi rendering work as expected on wayland until we switch
// to Qt 6.3 or newer. See https://codereview.qt-project.org/c/qt/qtdeclarative/+/361506
if (effects->waylandDisplay()) {
d->dummyWindow.reset(new QWindow());
d->dummyWindow->setOpacity(0);
d->dummyWindow->resize(1, 1);
d->dummyWindow->setFlag(Qt::FramelessWindowHint);
d->dummyWindow->setVisible(true);
d->dummyWindow->requestActivate();
}
const QList<EffectScreen *> screens = effects->screens();
for (EffectScreen *screen : screens) {
addScreen(screen);
@ -493,7 +480,6 @@ void QuickSceneEffect::stopInternal()
d->incubators.clear();
d->views.clear();
d->dummyWindow.reset();
d->running = false;
qApp->removeEventFilter(this);
effects->ungrabKeyboard();

View file

@ -313,18 +313,7 @@ void Decoration::init()
m_item->setParentItem(visualParent.value<QQuickItem *>());
visualParent.value<QQuickItem *>()->setProperty("drawBackground", false);
} else {
// This is an ugly hack to make hidpi rendering work as expected on wayland until we switch
// to Qt 6.3 or newer. See https://codereview.qt-project.org/c/qt/qtdeclarative/+/361506
if (KWin::effects && KWin::effects->waylandDisplay()) {
m_dummyWindow.reset(new QWindow());
m_dummyWindow->setOpacity(0);
m_dummyWindow->resize(1, 1);
m_dummyWindow->setFlag(Qt::FramelessWindowHint);
m_dummyWindow->setVisible(true);
}
m_view = std::make_unique<KWin::OffscreenQuickView>(this, m_dummyWindow.get(), KWin::OffscreenQuickView::ExportMode::Image);
m_view = std::make_unique<KWin::OffscreenQuickView>(this, KWin::OffscreenQuickView::ExportMode::Image);
m_item->setParentItem(m_view->contentItem());
auto updateSize = [this]() {
m_item->setSize(m_view->contentItem()->size());

View file

@ -80,7 +80,6 @@ private:
KWin::Borders *m_padding;
QString m_themeName;
std::unique_ptr<QWindow> m_dummyWindow;
std::unique_ptr<KWin::OffscreenQuickView> m_view;
};