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.
This commit is contained in:
Vlad Zahorodnii 2022-02-17 11:58:44 +02:00
parent 24eee2df7c
commit 6d20b977ab
2 changed files with 18 additions and 24 deletions

View file

@ -200,6 +200,23 @@ void ScreenShotEffect::paintScreen(int mask, const QRegion &region, 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()

View file

@ -73,7 +73,6 @@ public:
QFuture<QImage> scheduleScreenShot(EffectWindow *window, ScreenShotFlags flags = {});
void paintScreen(int mask, const QRegion &region, ScreenPaintData &data) override;
void postPaintScreen() override;
bool isActive() const override;
int requestedEffectChainPosition() const override;