From e5e5c4a020d77047884b2944684663ddcac47994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Sun, 13 Mar 2011 14:34:30 +0100 Subject: [PATCH] Move push/popRenderTarget to kwingluitls (De)Activating a FBO is OpenGL specific and does not belong into EffectsHandler. --- effects.cpp | 30 --------------------------- effects.h | 5 ----- effects/blur/blur.cpp | 4 ++-- effects/logout/logout.cpp | 4 ++-- effects/lookingglass/lookingglass.cpp | 4 ++-- effects/screenshot/screenshot.cpp | 4 ++-- lanczosfilter.cpp | 4 ++-- libkwineffects/kwineffects.cpp | 6 +++--- libkwineffects/kwineffects.h | 4 ---- libkwineffects/kwinglutils.cpp | 21 +++++++++++++++++++ libkwineffects/kwinglutils.h | 4 ++++ 11 files changed, 38 insertions(+), 52 deletions(-) diff --git a/effects.cpp b/effects.cpp index 0cc7577e92..6dd84efc9f 100644 --- a/effects.cpp +++ b/effects.cpp @@ -784,36 +784,6 @@ EffectWindow* EffectsHandlerImpl::currentTabBoxWindow() const return NULL; } -void EffectsHandlerImpl::pushRenderTarget(GLRenderTarget* target) -{ -#ifdef KWIN_HAVE_OPENGL_COMPOSITING - target->enable(); - render_targets.push(target); -#endif -} - -GLRenderTarget* EffectsHandlerImpl::popRenderTarget() -{ -#ifdef KWIN_HAVE_OPENGL_COMPOSITING - GLRenderTarget* ret = render_targets.pop(); - ret->disable(); - if (!render_targets.isEmpty()) - render_targets.top()->enable(); - return ret; -#else - return 0; -#endif -} - -bool EffectsHandlerImpl::isRenderTargetBound() -{ -#ifdef KWIN_HAVE_OPENGL_COMPOSITING - return !render_targets.isEmpty(); -#else - return false; -#endif -} - void EffectsHandlerImpl::addRepaintFull() { Workspace::self()->addRepaintFull(); diff --git a/effects.h b/effects.h index 5857ebc059..85cc75fd03 100644 --- a/effects.h +++ b/effects.h @@ -111,10 +111,6 @@ public: virtual void setActiveFullScreenEffect(Effect* e); virtual Effect* activeFullScreenEffect() const; - virtual void pushRenderTarget(GLRenderTarget* target); - virtual GLRenderTarget* popRenderTarget(); - virtual bool isRenderTargetBound(); - virtual void addRepaintFull(); virtual void addRepaint(const QRect& r); virtual void addRepaint(const QRegion& r); @@ -202,7 +198,6 @@ protected: void setupUnmanagedConnections(KWin::Unmanaged *u); Effect* keyboard_grab_effect; - QStack render_targets; Effect* fullscreen_effect; QList elevated_windows; QMultiMap< int, EffectPair > effect_order; diff --git a/effects/blur/blur.cpp b/effects/blur/blur.cpp index 3a2afe8537..ea8e299d02 100644 --- a/effects/blur/blur.cpp +++ b/effects/blur/blur.cpp @@ -273,7 +273,7 @@ void BlurEffect::doBlur(const QRegion& shape, const QRect& screen, const float o r.width(), r.height()); // Draw the texture on the offscreen framebuffer object, while blurring it horizontally - effects->pushRenderTarget(target); + GLRenderTarget::pushRenderTarget(target); shader->bind(); shader->setDirection(Qt::Horizontal); @@ -293,7 +293,7 @@ void BlurEffect::doBlur(const QRegion& shape, const QRect& screen, const float o drawRegion(expanded); - effects->popRenderTarget(); + GLRenderTarget::popRenderTarget(); scratch.unbind(); scratch.discard(); diff --git a/effects/logout/logout.cpp b/effects/logout/logout.cpp index 02dde1caa0..92cbb8e55f 100644 --- a/effects/logout/logout.cpp +++ b/effects/logout/logout.cpp @@ -195,7 +195,7 @@ void LogoutEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data) { #ifdef KWIN_HAVE_OPENGL_COMPOSITING if (blurSupported && progress > 0.0) - effects->pushRenderTarget(blurTarget); + GLRenderTarget::pushRenderTarget(blurTarget); #endif effects->paintScreen(mask, region, data); @@ -208,7 +208,7 @@ void LogoutEffect::paintScreen(int mask, QRegion region, ScreenPaintData& data) // is set as it may still be even if it wasn't rendered. renderVignetting(); } else { - GLRenderTarget* target = effects->popRenderTarget(); + GLRenderTarget* target = GLRenderTarget::popRenderTarget(); assert(target == blurTarget); Q_UNUSED(target); diff --git a/effects/lookingglass/lookingglass.cpp b/effects/lookingglass/lookingglass.cpp index 458dd20396..783823efdf 100644 --- a/effects/lookingglass/lookingglass.cpp +++ b/effects/lookingglass/lookingglass.cpp @@ -210,7 +210,7 @@ void LookingGlassEffect::prePaintScreen(ScreenPrePaintData& data, int time) if (m_valid && m_enabled) { data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS; // Start rendering to texture - effects->pushRenderTarget(m_fbo); + GLRenderTarget::pushRenderTarget(m_fbo); } effects->prePaintScreen(data, time); @@ -231,7 +231,7 @@ void LookingGlassEffect::postPaintScreen() effects->postPaintScreen(); if (m_valid && m_enabled) { // Disable render texture - GLRenderTarget* target = effects->popRenderTarget(); + GLRenderTarget* target = GLRenderTarget::popRenderTarget(); assert(target == m_fbo); Q_UNUSED(target); m_texture->bind(); diff --git a/effects/screenshot/screenshot.cpp b/effects/screenshot/screenshot.cpp index 5fc09ec44f..2925f3ccd9 100644 --- a/effects/screenshot/screenshot.cpp +++ b/effects/screenshot/screenshot.cpp @@ -102,7 +102,7 @@ void ScreenShotEffect::postPaintScreen() d.yTranslate = -m_scheduledScreenshot->y() - top; // render window into offscreen texture int mask = PAINT_WINDOW_TRANSFORMED | PAINT_WINDOW_TRANSLUCENT; - effects->pushRenderTarget(target); + GLRenderTarget::pushRenderTarget(target); glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glClearColor(0.0, 0.0, 0.0, 1.0); @@ -110,7 +110,7 @@ void ScreenShotEffect::postPaintScreen() // copy content from framebuffer into image QImage img(QSize(width, height), QImage::Format_ARGB32); glReadPixels(0, offscreenTexture->height() - height, width, height, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)img.bits()); - effects->popRenderTarget(); + GLRenderTarget::popRenderTarget(); ScreenShotEffect::convertFromGLImage(img, width, height); if (m_type & INCLUDE_CURSOR) { grabPointerImage(img, m_scheduledScreenshot->x() + left, m_scheduledScreenshot->y() + top); diff --git a/lanczosfilter.cpp b/lanczosfilter.cpp index 879695e7af..0d22e24a8b 100644 --- a/lanczosfilter.cpp +++ b/lanczosfilter.cpp @@ -256,7 +256,7 @@ void LanczosFilter::performPaint(EffectWindowImpl* w, int mask, QRegion region, // Bind the offscreen FBO and draw the window on it unscaled updateOffscreenSurfaces(); - effects->pushRenderTarget(m_offscreenTarget); + GLRenderTarget::pushRenderTarget(m_offscreenTarget); glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); @@ -341,7 +341,7 @@ void LanczosFilter::performPaint(EffectWindowImpl* w, int mask, QRegion region, cache->setWrapMode(GL_CLAMP_TO_EDGE); cache->bind(); glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, m_offscreenTex->height() - th, tw, th); - effects->popRenderTarget(); + GLRenderTarget::popRenderTarget(); if (ShaderManager::instance()->isValid()) { glEnable(GL_BLEND); diff --git a/libkwineffects/kwineffects.cpp b/libkwineffects/kwineffects.cpp index 5a076080b7..ff8ee07eb5 100644 --- a/libkwineffects/kwineffects.cpp +++ b/libkwineffects/kwineffects.cpp @@ -744,7 +744,7 @@ PaintClipper::Iterator::Iterator() #ifndef KWIN_HAVE_OPENGLES glPushAttrib(GL_SCISSOR_BIT); #endif - if (!effects->isRenderTargetBound()) + if (!GLRenderTarget::isRenderTargetBound()) glEnable(GL_SCISSOR_TEST); data->rects = paintArea().rects(); data->index = -1; @@ -764,7 +764,7 @@ PaintClipper::Iterator::~Iterator() { #ifdef KWIN_HAVE_OPENGL_COMPOSITING if (clip() && effects->compositingType() == OpenGLCompositing) { - if (!effects->isRenderTargetBound()) + if (!GLRenderTarget::isRenderTargetBound()) glDisable(GL_SCISSOR_TEST); #ifndef KWIN_HAVE_OPENGLES glPopAttrib(); @@ -797,7 +797,7 @@ void PaintClipper::Iterator::next() { data->index++; #ifdef KWIN_HAVE_OPENGL_COMPOSITING - if (clip() && effects->compositingType() == OpenGLCompositing && !effects->isRenderTargetBound() && data->index < data->rects.count()) { + if (clip() && effects->compositingType() == OpenGLCompositing && !GLRenderTarget::isRenderTargetBound() && data->index < data->rects.count()) { const QRect& r = data->rects[ data->index ]; // Scissor rect has to be given in OpenGL coords glScissor(r.x(), displayHeight() - r.y() - r.height(), r.width(), r.height()); diff --git a/libkwineffects/kwineffects.h b/libkwineffects/kwineffects.h index 89c2be7eed..e78ae452ae 100644 --- a/libkwineffects/kwineffects.h +++ b/libkwineffects/kwineffects.h @@ -700,10 +700,6 @@ public: virtual void setActiveFullScreenEffect(Effect* e) = 0; virtual Effect* activeFullScreenEffect() const = 0; - virtual void pushRenderTarget(GLRenderTarget* target) = 0; - virtual GLRenderTarget* popRenderTarget() = 0; - virtual bool isRenderTargetBound() = 0; - /** * Schedules the entire workspace to be repainted next time. * If you call it during painting (including prepaint) then it does not diff --git a/libkwineffects/kwinglutils.cpp b/libkwineffects/kwinglutils.cpp index f8ddb693ff..a8e40c34a3 100644 --- a/libkwineffects/kwinglutils.cpp +++ b/libkwineffects/kwinglutils.cpp @@ -1326,6 +1326,7 @@ void ShaderManager::resetShader(ShaderType type) /*** GLRenderTarget ***/ bool GLRenderTarget::sSupported = false; +QStack GLRenderTarget::s_renderTargets = QStack(); void GLRenderTarget::initStatic() { @@ -1336,6 +1337,26 @@ void GLRenderTarget::initStatic() #endif } +bool GLRenderTarget::isRenderTargetBound() +{ + return !s_renderTargets.isEmpty(); +} + +void GLRenderTarget::pushRenderTarget(GLRenderTarget* target) +{ + target->enable(); + s_renderTargets.push(target); +} + +GLRenderTarget* GLRenderTarget::popRenderTarget() +{ + GLRenderTarget* ret = s_renderTargets.pop(); + ret->disable(); + if (!s_renderTargets.isEmpty()) + s_renderTargets.top()->enable(); + return ret; +} + GLRenderTarget::GLRenderTarget(GLTexture* color) { // Reset variables diff --git a/libkwineffects/kwinglutils.h b/libkwineffects/kwinglutils.h index 135b02eae9..2857f43a2b 100644 --- a/libkwineffects/kwinglutils.h +++ b/libkwineffects/kwinglutils.h @@ -523,6 +523,9 @@ public: static bool supported() { return sSupported; } + static void pushRenderTarget(GLRenderTarget *target); + static GLRenderTarget *popRenderTarget(); + static bool isRenderTargetBound(); protected: @@ -531,6 +534,7 @@ protected: private: static bool sSupported; + static QStack s_renderTargets; GLTexture* mTexture; bool mValid;