From 62f904b6988942b3e4e03ca99e5d2cbc27a1bae0 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 21 Nov 2023 17:17:17 +0200 Subject: [PATCH] Drop EffectsHandler::renderScreen() It's no longer relevant after merging libkwin and libkwineffects. By dropping EffectsHandler::renderScreen() and making the screen transform use the Scene API directly, we can clean up some OpenGL context handling code. --- src/effect/effecthandler.cpp | 17 --------- src/effect/effecthandler.h | 5 --- .../screentransform/screentransform.cpp | 38 ++++++++++++------- 3 files changed, 24 insertions(+), 36 deletions(-) diff --git a/src/effect/effecthandler.cpp b/src/effect/effecthandler.cpp index 53e8ee5bf5..a81ca0f284 100644 --- a/src/effect/effecthandler.cpp +++ b/src/effect/effecthandler.cpp @@ -1569,23 +1569,6 @@ Output *EffectsHandler::findScreen(int screenId) const return Workspace::self()->outputs().value(screenId); } -void EffectsHandler::renderScreen(Output *output) -{ - Q_ASSERT(effects->isOpenGLCompositing()); - - RenderLayer layer(output->renderLoop()); - SceneDelegate delegate(m_scene, output); - delegate.setLayer(&layer); - - m_scene->prePaint(&delegate); - - effects->makeOpenGLContextCurrent(); // TODO: doesn't belong here, but there's no better place atm either - RenderTarget renderTarget(GLFramebuffer::currentFramebuffer()); - m_scene->paint(renderTarget, output->geometry()); - - m_scene->postPaint(); -} - bool EffectsHandler::isCursorHidden() const { return Cursors::self()->isCursorHidden(); diff --git a/src/effect/effecthandler.h b/src/effect/effecthandler.h index be95540897..76ac1b697e 100644 --- a/src/effect/effecthandler.h +++ b/src/effect/effecthandler.h @@ -718,11 +718,6 @@ public: Output *findScreen(const QString &name) const; Output *findScreen(int screenId) const; - /** - * Renders @p screen in the current render target - */ - void renderScreen(Output *screen); - KWin::EffectWindow *inputPanel() const; bool isInputPanelOverlay() const; diff --git a/src/plugins/screentransform/screentransform.cpp b/src/plugins/screentransform/screentransform.cpp index 51516e4619..067edf4c00 100644 --- a/src/plugins/screentransform/screentransform.cpp +++ b/src/plugins/screentransform/screentransform.cpp @@ -8,10 +8,12 @@ */ // own #include "screentransform.h" +#include "core/renderlayer.h" #include "core/rendertarget.h" #include "core/renderviewport.h" #include "effect/effecthandler.h" #include "opengl/glutils.h" +#include "scene/workspacescene.h" #include @@ -81,24 +83,32 @@ void ScreenTransformEffect::addScreen(Output *screen) effects->addRepaintFull(); }); connect(screen, &Output::aboutToChange, this, [this, screen] { + Scene *scene = effects->scene(); + + RenderLayer layer(screen->renderLoop()); + SceneDelegate delegate(scene, screen); + delegate.setLayer(&layer); + + scene->prePaint(&delegate); + effects->makeOpenGLContextCurrent(); - auto &state = m_states[screen]; - state.m_oldTransform = screen->transform(); - state.m_oldGeometry = screen->geometry(); - state.m_prev.texture = GLTexture::allocate(GL_RGBA8, screen->geometry().size() * screen->scale()); - if (!state.m_prev.texture) { + if (auto texture = GLTexture::allocate(GL_RGBA8, screen->geometry().size() * screen->scale())) { + auto &state = m_states[screen]; + state.m_oldTransform = screen->transform(); + state.m_oldGeometry = screen->geometry(); + state.m_prev.texture = std::move(texture); + state.m_prev.framebuffer = std::make_unique(state.m_prev.texture.get()); + + RenderTarget renderTarget(state.m_prev.framebuffer.get()); + scene->paint(renderTarget, screen->geometry()); + + // Now, the effect can cross-fade between current and previous state. + state.m_captured = true; + } else { m_states.remove(screen); - return; } - state.m_prev.framebuffer = std::make_unique(state.m_prev.texture.get()); - // Rendering the current scene into a texture - GLFramebuffer::pushFramebuffer(state.m_prev.framebuffer.get()); - effects->renderScreen(screen); - GLFramebuffer::popFramebuffer(); - - // Now, the effect can cross-fade between current and previous state. - state.m_captured = true; + scene->postPaint(); }); }