From 0c3a8e6f29077a1b5fcec3453783a1ee782fc95f Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 15 Feb 2022 17:31:23 +0200 Subject: [PATCH] scene: Make paintScreen() clip the damage region paintScreen() already tries to ensure that the damage region doesn't go outside the scene geometry. With this change, it will try to clip the damage region to the render target rect, which saves us an extra region intersection and simplifies code that calls paintScreen(). --- src/scene.cpp | 9 ++++----- src/scenes/opengl/scene_opengl.cpp | 2 +- src/scenes/qpainter/scene_qpainter.cpp | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/scene.cpp b/src/scene.cpp index d1f50bf076..bcfaae8339 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -269,8 +269,6 @@ void Scene::paintScreen(AbstractOutput *output, const QList &topleve void Scene::paintScreen(const QRegion &damage, const QRegion &repaint, QRegion *updateRegion, QRegion *validRegion) { - const QRegion displayRegion(geometry()); - const RenderLoop *renderLoop = painted_screen->renderLoop(); const std::chrono::milliseconds presentTime = std::chrono::duration_cast(renderLoop->nextPresentationTimestamp()); @@ -288,6 +286,7 @@ void Scene::paintScreen(const QRegion &damage, const QRegion &repaint, auto effectsImpl = static_cast(effects); effectsImpl->startPaint(); + const QRegion displayRegion(renderTargetRect()); QRegion region = damage; auto screen = EffectScreenImpl::get(painted_screen); @@ -382,7 +381,7 @@ void Scene::paintGenericScreen(int orig_mask, const ScreenPaintData &) phase2.append({w, infiniteRegion(), data.clip, data.mask,}); } - damaged_region = geometry(); + damaged_region = renderTargetRect(); if (m_paintScreenCount == 1) { aboutToStartPainting(painted_screen, damaged_region); @@ -480,7 +479,7 @@ void Scene::paintSimpleScreen(int orig_mask, const QRegion ®ion) const QRegion repaintClip = repaint_region - dirtyArea; dirtyArea |= repaint_region; - const QRegion displayRegion(geometry()); + const QRegion displayRegion(renderTargetRect()); bool fullRepaint(dirtyArea == displayRegion); // spare some expensive region operations if (!fullRepaint) { extendPaintRegion(dirtyArea, opaqueFullscreen); @@ -607,7 +606,7 @@ void Scene::clearStackingOrder() void Scene::paintWindow(Window* w, int mask, const QRegion &_region) { // no painting outside visible screen (and no transformations) - const QRegion region = _region & geometry(); + const QRegion region = _region & renderTargetRect(); if (region.isEmpty()) // completely clipped return; diff --git a/src/scenes/opengl/scene_opengl.cpp b/src/scenes/opengl/scene_opengl.cpp index 48352cdce2..0361022e33 100644 --- a/src/scenes/opengl/scene_opengl.cpp +++ b/src/scenes/opengl/scene_opengl.cpp @@ -248,7 +248,7 @@ void SceneOpenGL::paint(AbstractOutput *output, const QRegion &damage, const QLi repaint = m_backend->beginFrame(output); GLVertexBuffer::streamingBuffer()->beginFrame(); - paintScreen(damage.intersected(renderTargetRect()), repaint, &update, &valid); + paintScreen(damage, repaint, &update, &valid); paintCursor(output, valid); renderLoop->endFrame(); diff --git a/src/scenes/qpainter/scene_qpainter.cpp b/src/scenes/qpainter/scene_qpainter.cpp index 2ea7e12b7f..3751b7a56a 100644 --- a/src/scenes/qpainter/scene_qpainter.cpp +++ b/src/scenes/qpainter/scene_qpainter.cpp @@ -86,7 +86,7 @@ void SceneQPainter::paint(AbstractOutput *output, const QRegion &damage, const Q m_painter->setWindow(geometry); QRegion updateRegion, validRegion; - paintScreen(damage.intersected(geometry), repaint, &updateRegion, &validRegion); + paintScreen(damage, repaint, &updateRegion, &validRegion); paintCursor(output, updateRegion); m_painter->end();