plugins/contrast: fix: effect not clipped to region

Introduced in:
7732f0e56b
wilder/Plasma/6.2
Jin Liu 2 years ago
parent 0bd65de375
commit c2c19fe91f
  1. 20
      src/plugins/backgroundcontrast/contrast.cpp
  2. 2
      src/plugins/backgroundcontrast/contrast.h

@ -398,7 +398,7 @@ void ContrastEffect::drawWindow(const RenderTarget &renderTarget, const RenderVi
{ {
if (shouldContrast(w, mask, data)) { if (shouldContrast(w, mask, data)) {
const QRect screen = viewport.renderRect().toRect(); const QRect screen = viewport.renderRect().toRect();
QRegion shape = region & contrastRegion(w).translated(w->pos().toPoint()) & screen; QRegion shape = contrastRegion(w).translated(w->pos().toPoint());
// let's do the evil parts - someone wants to contrast behind a transformed window // let's do the evil parts - someone wants to contrast behind a transformed window
const bool translated = data.xTranslation() || data.yTranslation(); const bool translated = data.xTranslation() || data.yTranslation();
@ -413,15 +413,16 @@ void ContrastEffect::drawWindow(const RenderTarget &renderTarget, const RenderVi
std::floor(topLeft.y() + r.height() * data.yScale()) - 1); std::floor(topLeft.y() + r.height() * data.yScale()) - 1);
scaledShape += QRect(QPoint(std::floor(topLeft.x()), std::floor(topLeft.y())), bottomRight); scaledShape += QRect(QPoint(std::floor(topLeft.x()), std::floor(topLeft.y())), bottomRight);
} }
shape = scaledShape & region; shape = scaledShape;
// Only translated, not scaled // Only translated, not scaled
} else if (translated) { } else if (translated) {
shape.translate(std::round(data.xTranslation()), std::round(data.yTranslation())); shape.translate(std::round(data.xTranslation()), std::round(data.yTranslation()));
} }
if (!shape.isEmpty()) { const QRegion effectiveShape = shape & region & screen;
doContrast(renderTarget, viewport, w, shape, screen, w->opacity() * data.opacity(), data.projectionMatrix()); if (!effectiveShape.isEmpty()) {
doContrast(renderTarget, viewport, w, effectiveShape, w->opacity() * data.opacity(), data.projectionMatrix());
} }
} }
@ -429,16 +430,15 @@ void ContrastEffect::drawWindow(const RenderTarget &renderTarget, const RenderVi
effects->drawWindow(renderTarget, viewport, w, mask, region, data); effects->drawWindow(renderTarget, viewport, w, mask, region, data);
} }
void ContrastEffect::doContrast(const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *w, const QRegion &shape, const QRect &screen, const float opacity, const QMatrix4x4 &screenProjection) void ContrastEffect::doContrast(const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *w, const QRegion &shape, const float opacity, const QMatrix4x4 &screenProjection)
{ {
const qreal scale = viewport.scale(); const qreal scale = viewport.scale();
const QRegion actualShape = shape & screen; const QRectF r = viewport.mapToRenderTarget(shape.boundingRect());
const QRectF r = viewport.mapToRenderTarget(actualShape.boundingRect());
// Upload geometry for the horizontal and vertical passes // Upload geometry for the horizontal and vertical passes
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer(); GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
vbo->reset(); vbo->reset();
if (!uploadGeometry(vbo, actualShape, scale)) { if (!uploadGeometry(vbo, shape, scale)) {
return; return;
} }
vbo->bindArrays(); vbo->bindArrays();
@ -465,7 +465,7 @@ void ContrastEffect::doContrast(const RenderTarget &renderTarget, const RenderVi
m_shader->setOpacity(opacity); m_shader->setOpacity(opacity);
// Set up the texture matrix to transform from screen coordinates // Set up the texture matrix to transform from screen coordinates
// to texture coordinates. // to texture coordinates.
const QRectF boundingRect = actualShape.boundingRect(); const QRectF boundingRect = shape.boundingRect();
QMatrix4x4 textureMatrix; QMatrix4x4 textureMatrix;
textureMatrix.scale(1, -1); textureMatrix.scale(1, -1);
textureMatrix.translate(0, -1); textureMatrix.translate(0, -1);
@ -481,7 +481,7 @@ void ContrastEffect::doContrast(const RenderTarget &renderTarget, const RenderVi
m_shader->setTextureMatrix(textureMatrix); m_shader->setTextureMatrix(textureMatrix);
m_shader->setModelViewProjectionMatrix(screenProjection); m_shader->setModelViewProjectionMatrix(screenProjection);
vbo->draw(GL_TRIANGLES, 0, actualShape.rectCount() * 6); vbo->draw(GL_TRIANGLES, 0, shape.rectCount() * 6);
contrastTexture->unbind(); contrastTexture->unbind();

@ -56,7 +56,7 @@ private:
QRegion contrastRegion(const EffectWindow *w) const; QRegion contrastRegion(const EffectWindow *w) const;
bool shouldContrast(const EffectWindow *w, int mask, const WindowPaintData &data) const; bool shouldContrast(const EffectWindow *w, int mask, const WindowPaintData &data) const;
void updateContrastRegion(EffectWindow *w); void updateContrastRegion(EffectWindow *w);
void doContrast(const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *w, const QRegion &shape, const QRect &screen, const float opacity, const QMatrix4x4 &screenProjection); void doContrast(const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *w, const QRegion &shape, const float opacity, const QMatrix4x4 &screenProjection);
void uploadRegion(std::span<QVector2D> map, const QRegion &region, qreal scale); void uploadRegion(std::span<QVector2D> map, const QRegion &region, qreal scale);
Q_REQUIRED_RESULT bool uploadGeometry(GLVertexBuffer *vbo, const QRegion &region, qreal scale); Q_REQUIRED_RESULT bool uploadGeometry(GLVertexBuffer *vbo, const QRegion &region, qreal scale);

Loading…
Cancel
Save