From b32592f54e5c229c1656e735a2f21a31302242fc Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 22 Jul 2021 12:17:26 +0300 Subject: [PATCH] kwineffects: Allow disabling automatic frame scheduling in EffectQuickView --- src/libkwineffects/kwineffectquickview.cpp | 47 +++++++++++++++++++--- src/libkwineffects/kwineffectquickview.h | 8 ++++ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/libkwineffects/kwineffectquickview.cpp b/src/libkwineffects/kwineffectquickview.cpp index ed5cef3987..15830f17c2 100644 --- a/src/libkwineffects/kwineffectquickview.cpp +++ b/src/libkwineffects/kwineffectquickview.cpp @@ -38,12 +38,14 @@ public: QScopedPointer m_offscreenSurface; QScopedPointer m_fbo; + QTimer *m_repaintTimer; QImage m_image; QScopedPointer m_textureExport; // if we should capture a QImage after rendering into our BO. // Used for either software QtQuick rendering and nonGL kwin rendering bool m_useBlit = false; bool m_visible = true; + bool m_automaticRepaint = true; void releaseResources(); }; @@ -111,13 +113,13 @@ EffectQuickView::EffectQuickView(QObject *parent, ExportMode exportMode) connect(d->m_view, &QWindow::widthChanged, this, updateSize); connect(d->m_view, &QWindow::heightChanged, this, updateSize); - QTimer *t = new QTimer(this); - t->setSingleShot(true); - t->setInterval(10); + d->m_repaintTimer = new QTimer(this); + d->m_repaintTimer->setSingleShot(true); + d->m_repaintTimer->setInterval(10); - connect(t, &QTimer::timeout, this, &EffectQuickView::update); - connect(d->m_renderControl, &QQuickRenderControl::renderRequested, t, [t]() { t->start(); }); - connect(d->m_renderControl, &QQuickRenderControl::sceneChanged, t, [t]() { t->start(); }); + connect(d->m_repaintTimer, &QTimer::timeout, this, &EffectQuickView::update); + connect(d->m_renderControl, &QQuickRenderControl::renderRequested, this, &EffectQuickView::handleRenderRequested); + connect(d->m_renderControl, &QQuickRenderControl::sceneChanged, this, &EffectQuickView::handleSceneChanged); } EffectQuickView::~EffectQuickView() @@ -132,6 +134,39 @@ EffectQuickView::~EffectQuickView() } } +bool EffectQuickView::automaticRepaint() const +{ + return d->m_automaticRepaint; +} + +void EffectQuickView::setAutomaticRepaint(bool set) +{ + if (d->m_automaticRepaint != set) { + d->m_automaticRepaint = set; + + // If there's an in-flight update, disable it. + if (!d->m_automaticRepaint) { + d->m_repaintTimer->stop(); + } + } +} + +void EffectQuickView::handleSceneChanged() +{ + if (d->m_automaticRepaint) { + d->m_repaintTimer->start(); + } + Q_EMIT sceneChanged(); +} + +void EffectQuickView::handleRenderRequested() +{ + if (d->m_automaticRepaint) { + d->m_repaintTimer->start(); + } + Q_EMIT renderRequested(); +} + void EffectQuickView::update() { if (!d->m_visible) { diff --git a/src/libkwineffects/kwineffectquickview.h b/src/libkwineffects/kwineffectquickview.h index 9335b69028..f7da758e4e 100644 --- a/src/libkwineffects/kwineffectquickview.h +++ b/src/libkwineffects/kwineffectquickview.h @@ -104,6 +104,9 @@ public: void show(); void hide(); + bool automaticRepaint() const; + void setAutomaticRepaint(bool set); + /** * Returns the current output of the scene graph * @note The render context must valid at the time of calling @@ -133,8 +136,13 @@ Q_SIGNALS: */ void repaintNeeded(); void geometryChanged(const QRect &oldGeometry, const QRect &newGeometry); + void renderRequested(); + void sceneChanged(); private: + void handleRenderRequested(); + void handleSceneChanged(); + class Private; QScopedPointer d; };