From bef9c9c8c5893a6785eb86f72243c7ff67577033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 18 Oct 2016 16:33:20 +0200 Subject: [PATCH] Adjust blur and contrast for multi-output rendering on Wayland Summary: The glCopyTex(Sub)Image calls are adjusted to take the per output rendering into account. In addition contrast effect sets the model view projection matrix in each call to ensure it's on the correct screen. Blur probably needs more changes for the cached texture to work, but it's a start. Test Plan: Blur and Background contrast work on multi-screen wayland Reviewers: #kwin, #plasma_on_wayland Subscribers: plasma-devel, kwin Tags: #plasma_on_wayland, #kwin Differential Revision: https://phabricator.kde.org/D3101 --- effects/backgroundcontrast/contrast.cpp | 10 ++++++---- effects/backgroundcontrast/contrast.h | 2 +- effects/blur/blur.cpp | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/effects/backgroundcontrast/contrast.cpp b/effects/backgroundcontrast/contrast.cpp index 657ea6371c..65528f91f2 100644 --- a/effects/backgroundcontrast/contrast.cpp +++ b/effects/backgroundcontrast/contrast.cpp @@ -370,7 +370,7 @@ bool ContrastEffect::shouldContrast(const EffectWindow *w, int mask, const Windo void ContrastEffect::drawWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data) { - const QRect screen = effects->virtualScreenGeometry(); + const QRect screen = GLRenderTarget::virtualScreenGeometry(); if (shouldContrast(w, mask, data)) { QRegion shape = region & contrastRegion(w).translated(w->pos()) & screen; @@ -397,7 +397,7 @@ void ContrastEffect::drawWindow(EffectWindow *w, int mask, QRegion region, Windo } if (!shape.isEmpty()) { - doContrast(shape, screen, data.opacity()); + doContrast(shape, screen, data.opacity(), data.screenProjectionMatrix()); } } @@ -411,7 +411,7 @@ void ContrastEffect::paintEffectFrame(EffectFrame *frame, QRegion region, double effects->paintEffectFrame(frame, region, opacity, frameOpacity); } -void ContrastEffect::doContrast(const QRegion& shape, const QRect& screen, const float opacity) +void ContrastEffect::doContrast(const QRegion& shape, const QRect& screen, const float opacity, const QMatrix4x4 &screenProjection) { const QRegion actualShape = shape & screen; const QRect r = actualShape.boundingRect(); @@ -428,7 +428,8 @@ void ContrastEffect::doContrast(const QRegion& shape, const QRect& screen, const scratch.setWrapMode(GL_CLAMP_TO_EDGE); scratch.bind(); - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r.x(), effects->virtualScreenSize().height() - r.y() - r.height(), + const QRect sg = GLRenderTarget::virtualScreenGeometry(); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r.x() - sg.x(), sg.height() - sg.y() - r.y() - r.height(), r.width(), r.height()); // Draw the texture on the offscreen framebuffer object, while blurring it horizontally @@ -443,6 +444,7 @@ void ContrastEffect::doContrast(const QRegion& shape, const QRect& screen, const textureMatrix.scale(1.0 / scratch.width(), -1.0 / scratch.height(), 1); textureMatrix.translate(-r.x(), -scratch.height() - r.y(), 0); shader->setTextureMatrix(textureMatrix); + shader->setModelViewProjectionMatrix(screenProjection); vbo->draw(GL_TRIANGLES, 0, actualShape.rectCount() * 6); diff --git a/effects/backgroundcontrast/contrast.h b/effects/backgroundcontrast/contrast.h index 688fe2203d..20bf8bf605 100644 --- a/effects/backgroundcontrast/contrast.h +++ b/effects/backgroundcontrast/contrast.h @@ -74,7 +74,7 @@ private: QRegion contrastRegion(const EffectWindow *w) const; bool shouldContrast(const EffectWindow *w, int mask, const WindowPaintData &data) const; void updateContrastRegion(EffectWindow *w) const; - void doContrast(const QRegion &shape, const QRect &screen, const float opacity); + void doContrast(const QRegion &shape, const QRect &screen, const float opacity, const QMatrix4x4 &screenProjection); void uploadRegion(QVector2D *&map, const QRegion ®ion); void uploadGeometry(GLVertexBuffer *vbo, const QRegion ®ion); diff --git a/effects/blur/blur.cpp b/effects/blur/blur.cpp index 95debe435f..ea68fcba3b 100644 --- a/effects/blur/blur.cpp +++ b/effects/blur/blur.cpp @@ -434,7 +434,7 @@ bool BlurEffect::shouldBlur(const EffectWindow *w, int mask, const WindowPaintDa void BlurEffect::drawWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data) { - const QRect screen = effects->virtualScreenGeometry(); + const QRect screen = GLRenderTarget::virtualScreenGeometry(); if (shouldBlur(w, mask, data)) { QRegion shape = region & blurRegion(w).translated(w->pos()) & screen; @@ -529,7 +529,8 @@ void BlurEffect::doBlur(const QRegion& shape, const QRect& screen, const float o scratch.setWrapMode(GL_CLAMP_TO_EDGE); scratch.bind(); - glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r.x(), effects->virtualScreenSize().height() - r.y() - r.height(), + const QRect sg = GLRenderTarget::virtualScreenGeometry(); + glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, r.x() - sg.x(), sg.height() - sg.y() - r.y() - r.height(), r.width(), r.height()); // Draw the texture on the offscreen framebuffer object, while blurring it horizontally