kwineffects: Allow disabling automatic frame scheduling in EffectQuickView

This commit is contained in:
Vlad Zahorodnii 2021-07-22 12:17:26 +03:00
parent 212090d990
commit b32592f54e
2 changed files with 49 additions and 6 deletions

View file

@ -38,12 +38,14 @@ public:
QScopedPointer<QOffscreenSurface> m_offscreenSurface; QScopedPointer<QOffscreenSurface> m_offscreenSurface;
QScopedPointer<QOpenGLFramebufferObject> m_fbo; QScopedPointer<QOpenGLFramebufferObject> m_fbo;
QTimer *m_repaintTimer;
QImage m_image; QImage m_image;
QScopedPointer<GLTexture> m_textureExport; QScopedPointer<GLTexture> m_textureExport;
// if we should capture a QImage after rendering into our BO. // if we should capture a QImage after rendering into our BO.
// Used for either software QtQuick rendering and nonGL kwin rendering // Used for either software QtQuick rendering and nonGL kwin rendering
bool m_useBlit = false; bool m_useBlit = false;
bool m_visible = true; bool m_visible = true;
bool m_automaticRepaint = true;
void releaseResources(); 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::widthChanged, this, updateSize);
connect(d->m_view, &QWindow::heightChanged, this, updateSize); connect(d->m_view, &QWindow::heightChanged, this, updateSize);
QTimer *t = new QTimer(this); d->m_repaintTimer = new QTimer(this);
t->setSingleShot(true); d->m_repaintTimer->setSingleShot(true);
t->setInterval(10); d->m_repaintTimer->setInterval(10);
connect(t, &QTimer::timeout, this, &EffectQuickView::update); connect(d->m_repaintTimer, &QTimer::timeout, this, &EffectQuickView::update);
connect(d->m_renderControl, &QQuickRenderControl::renderRequested, t, [t]() { t->start(); }); connect(d->m_renderControl, &QQuickRenderControl::renderRequested, this, &EffectQuickView::handleRenderRequested);
connect(d->m_renderControl, &QQuickRenderControl::sceneChanged, t, [t]() { t->start(); }); connect(d->m_renderControl, &QQuickRenderControl::sceneChanged, this, &EffectQuickView::handleSceneChanged);
} }
EffectQuickView::~EffectQuickView() 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() void EffectQuickView::update()
{ {
if (!d->m_visible) { if (!d->m_visible) {

View file

@ -104,6 +104,9 @@ public:
void show(); void show();
void hide(); void hide();
bool automaticRepaint() const;
void setAutomaticRepaint(bool set);
/** /**
* Returns the current output of the scene graph * Returns the current output of the scene graph
* @note The render context must valid at the time of calling * @note The render context must valid at the time of calling
@ -133,8 +136,13 @@ Q_SIGNALS:
*/ */
void repaintNeeded(); void repaintNeeded();
void geometryChanged(const QRect &oldGeometry, const QRect &newGeometry); void geometryChanged(const QRect &oldGeometry, const QRect &newGeometry);
void renderRequested();
void sceneChanged();
private: private:
void handleRenderRequested();
void handleSceneChanged();
class Private; class Private;
QScopedPointer<Private> d; QScopedPointer<Private> d;
}; };