From 9675da6325365ca51456e1fe5d4d86bac7513c6c Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Fri, 23 Jul 2021 09:30:23 +0300 Subject: [PATCH] kwineffects: Allow specifying render window for EffectQuickView QtQuick can use the render window to compute the device pixel ratio for the managed QQuickWindow. --- src/libkwineffects/kwineffectquickview.cpp | 51 +++++++++++++++++++++- src/libkwineffects/kwineffectquickview.h | 16 +++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/src/libkwineffects/kwineffectquickview.cpp b/src/libkwineffects/kwineffectquickview.cpp index 6fc19d71a2..23005d58af 100644 --- a/src/libkwineffects/kwineffectquickview.cpp +++ b/src/libkwineffects/kwineffectquickview.cpp @@ -29,6 +29,29 @@ namespace KWin { +class EffectQuickRenderControl : public QQuickRenderControl +{ + Q_OBJECT + +public: + explicit EffectQuickRenderControl(QWindow *renderWindow, QObject *parent = nullptr) + : QQuickRenderControl(parent) + , m_renderWindow(renderWindow) + { + } + + QWindow *renderWindow(QPoint *offset) override + { + if (offset) { + *offset = QPoint(0, 0); + } + return m_renderWindow; + } + +private: + QPointer m_renderWindow; +}; + class Q_DECL_HIDDEN EffectQuickView::Private { public: @@ -62,10 +85,20 @@ EffectQuickView::EffectQuickView(QObject *parent) } EffectQuickView::EffectQuickView(QObject *parent, ExportMode exportMode) + : EffectQuickView(parent, nullptr, exportMode) +{ +} + +EffectQuickView::EffectQuickView(QObject *parent, QWindow *renderWindow) + : EffectQuickView(parent, renderWindow, effects->isOpenGLCompositing() ? ExportMode::Texture : ExportMode::Image) +{ +} + +EffectQuickView::EffectQuickView(QObject *parent, QWindow *renderWindow, ExportMode exportMode) : QObject(parent) , d(new EffectQuickView::Private) { - d->m_renderControl = new QQuickRenderControl(this); + d->m_renderControl = new EffectQuickRenderControl(renderWindow, this); d->m_view = new QQuickWindow(d->m_renderControl); d->m_view->setFlags(Qt::FramelessWindowHint); @@ -365,6 +398,20 @@ EffectQuickScene::EffectQuickScene(QObject *parent) d->qmlObject = new KDeclarative::QmlObjectSharedEngine(this); } +EffectQuickScene::EffectQuickScene(QObject *parent, QWindow *renderWindow) + : EffectQuickView(parent, renderWindow) + , d(new EffectQuickScene::Private) +{ + d->qmlObject = new KDeclarative::QmlObjectSharedEngine(this); +} + +EffectQuickScene::EffectQuickScene(QObject *parent, QWindow *renderWindow, ExportMode exportMode) + : EffectQuickView(parent, renderWindow, exportMode) + , d(new EffectQuickScene::Private) +{ + d->qmlObject = new KDeclarative::QmlObjectSharedEngine(this); +} + EffectQuickScene::EffectQuickScene(QObject *parent, EffectQuickView::ExportMode exportMode) : EffectQuickView(parent, exportMode) , d(new EffectQuickScene::Private) @@ -405,3 +452,5 @@ QQuickItem *EffectQuickScene::rootItem() const } } // namespace KWin + +#include "kwineffectquickview.moc" diff --git a/src/libkwineffects/kwineffectquickview.h b/src/libkwineffects/kwineffectquickview.h index f7da758e4e..dac9d244f6 100644 --- a/src/libkwineffects/kwineffectquickview.h +++ b/src/libkwineffects/kwineffectquickview.h @@ -61,6 +61,20 @@ public: */ EffectQuickView(QObject *parent); + /** + * Construct a new EffectQuickView with the specified @a parent and the + * render window @a renderWindow. The render window can be used by QtQuick + * to compute the scale factor. + */ + EffectQuickView(QObject *parent, QWindow *renderWindow); + + /** + * Construct a new EffectQuickView with the specified @a parent and the + * render window @a renderWindow. The render window can be used by QtQuick + * to compute the scale factor. + */ + EffectQuickView(QObject *parent, QWindow *renderWindow, ExportMode exportMode); + /** * Construct a new KWinQuickView explicitly stating an export mode */ @@ -157,6 +171,8 @@ class KWINEFFECTS_EXPORT EffectQuickScene : public EffectQuickView public: EffectQuickScene(QObject *parent); EffectQuickScene(QObject *parent, ExportMode exportMode); + EffectQuickScene(QObject *parent, QWindow *renderWindow); + EffectQuickScene(QObject *parent, QWindow *renderWindow, ExportMode exportMode); ~EffectQuickScene(); QQmlContext *rootContext() const;