From 6d20b977abfb577bf50e19c1f3f540e5cd2c019b Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 17 Feb 2022 11:58:44 +0200 Subject: [PATCH] effects/screenshot: Capture screenshot in paintScreen() It's not guaranteed that there will be current render target in postPaintScreen() as all painting have been completed. Furthermore, even the docs of the postPaintScreen() function indicate that no painting should be done there, you can do only cleanup things, e.g. schedule a repaint, etc. paintScreen() is a much safer place to capture screenshot. --- src/effects/screenshot/screenshot.cpp | 41 ++++++++++++--------------- src/effects/screenshot/screenshot.h | 1 - 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/effects/screenshot/screenshot.cpp b/src/effects/screenshot/screenshot.cpp index 92d2bfbc4b..a20c7a01c4 100644 --- a/src/effects/screenshot/screenshot.cpp +++ b/src/effects/screenshot/screenshot.cpp @@ -200,6 +200,23 @@ void ScreenShotEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintD { m_paintedScreen = data.screen(); effects->paintScreen(mask, region, data); + + while (!m_windowScreenShots.isEmpty()) { + ScreenShotWindowData screenshot = m_windowScreenShots.takeLast(); + takeScreenShot(&screenshot); + } + + for (int i = m_areaScreenShots.count() - 1; i >= 0; --i) { + if (takeScreenShot(&m_areaScreenShots[i])) { + m_areaScreenShots.removeAt(i); + } + } + + for (int i = m_screenScreenShots.count() - 1; i >= 0; --i) { + if (takeScreenShot(&m_screenScreenShots[i])) { + m_screenScreenShots.removeAt(i); + } + } } void ScreenShotEffect::takeScreenShot(ScreenShotWindowData *screenshot) @@ -331,28 +348,6 @@ bool ScreenShotEffect::takeScreenShot(ScreenShotScreenData *screenshot) return screenshot->promise.isFinished(); } -void ScreenShotEffect::postPaintScreen() -{ - effects->postPaintScreen(); - - while (!m_windowScreenShots.isEmpty()) { - ScreenShotWindowData screenshot = m_windowScreenShots.takeLast(); - takeScreenShot(&screenshot); - } - - for (int i = m_areaScreenShots.count() - 1; i >= 0; --i) { - if (takeScreenShot(&m_areaScreenShots[i])) { - m_areaScreenShots.removeAt(i); - } - } - - for (int i = m_screenScreenShots.count() - 1; i >= 0; --i) { - if (takeScreenShot(&m_screenScreenShots[i])) { - m_screenScreenShots.removeAt(i); - } - } -} - QImage ScreenShotEffect::blitScreenshot(const QRect &geometry, qreal devicePixelRatio) const { QImage image; @@ -402,7 +397,7 @@ bool ScreenShotEffect::isActive() const int ScreenShotEffect::requestedEffectChainPosition() const { - return 50; + return 0; } void ScreenShotEffect::handleScreenAdded() diff --git a/src/effects/screenshot/screenshot.h b/src/effects/screenshot/screenshot.h index 7ab8169b24..42d850ef40 100644 --- a/src/effects/screenshot/screenshot.h +++ b/src/effects/screenshot/screenshot.h @@ -73,7 +73,6 @@ public: QFuture scheduleScreenShot(EffectWindow *window, ScreenShotFlags flags = {}); void paintScreen(int mask, const QRegion ®ion, ScreenPaintData &data) override; - void postPaintScreen() override; bool isActive() const override; int requestedEffectChainPosition() const override;