2010-03-05 20:42:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2010 Fredrik Höglund <fredrik@kde.org>
|
2011-12-10 10:28:38 +00:00
|
|
|
* Copyright © 2011 Philipp Knechtges <philipp-dev@knechtges.com>
|
2010-03-05 20:42:10 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. if not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "blur.h"
|
2015-08-31 13:47:01 +00:00
|
|
|
#include "effects.h"
|
2010-03-05 20:42:10 +00:00
|
|
|
#include "blurshader.h"
|
2012-09-14 12:28:30 +00:00
|
|
|
// KConfigSkeleton
|
|
|
|
#include "blurconfig.h"
|
2010-03-05 20:42:10 +00:00
|
|
|
|
2011-01-08 18:56:22 +00:00
|
|
|
#include <QMatrix4x4>
|
2011-05-01 21:17:28 +00:00
|
|
|
#include <QLinkedList>
|
2010-03-05 20:42:10 +00:00
|
|
|
|
2015-08-31 13:47:01 +00:00
|
|
|
#include <KWayland/Server/surface_interface.h>
|
|
|
|
#include <KWayland/Server/blur_interface.h>
|
|
|
|
#include <KWayland/Server/shadow_interface.h>
|
|
|
|
#include <KWayland/Server/display.h>
|
|
|
|
|
2010-03-05 20:42:10 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
2011-05-01 20:52:43 +00:00
|
|
|
|
2014-03-16 09:16:52 +00:00
|
|
|
static const QByteArray s_blurAtomName = QByteArrayLiteral("_KDE_NET_WM_BLUR_BEHIND_REGION");
|
|
|
|
|
2010-03-05 20:42:10 +00:00
|
|
|
BlurEffect::BlurEffect()
|
|
|
|
{
|
2016-12-02 19:27:43 +00:00
|
|
|
initConfig<BlurConfig>();
|
2010-03-08 20:45:58 +00:00
|
|
|
shader = BlurShader::create();
|
2016-01-27 13:15:32 +00:00
|
|
|
m_simpleShader = ShaderManager::instance()->generateShaderFromResources(ShaderTrait::MapTexture, QString(), QStringLiteral("logout-blur.frag"));
|
|
|
|
if (!m_simpleShader->isValid()) {
|
|
|
|
qCDebug(KWINEFFECTS) << "Simple blur shader failed to load";
|
|
|
|
}
|
2010-03-05 20:42:10 +00:00
|
|
|
|
2017-09-29 12:30:54 +00:00
|
|
|
updateTexture();
|
2010-09-25 00:11:06 +00:00
|
|
|
reconfigure(ReconfigureAll);
|
|
|
|
|
2010-03-06 16:14:25 +00:00
|
|
|
// ### Hackish way to announce support.
|
|
|
|
// Should be included in _NET_SUPPORTED instead.
|
2012-10-05 09:46:13 +00:00
|
|
|
if (shader && shader->isValid() && target->valid()) {
|
2014-03-16 09:16:52 +00:00
|
|
|
net_wm_blur_region = effects->announceSupportProperty(s_blurAtomName, this);
|
2015-09-29 08:21:24 +00:00
|
|
|
KWayland::Server::Display *display = effects->waylandDisplay();
|
|
|
|
if (display) {
|
|
|
|
m_blurManager = display->createBlurManager(this);
|
|
|
|
m_blurManager->create();
|
|
|
|
}
|
2010-09-25 00:11:06 +00:00
|
|
|
} else {
|
2012-12-13 23:09:47 +00:00
|
|
|
net_wm_blur_region = 0;
|
2010-09-25 00:11:06 +00:00
|
|
|
}
|
2013-03-16 10:34:14 +00:00
|
|
|
|
2012-01-29 11:29:24 +00:00
|
|
|
connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), this, SLOT(slotWindowAdded(KWin::EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(windowDeleted(KWin::EffectWindow*)), this, SLOT(slotWindowDeleted(KWin::EffectWindow*)));
|
|
|
|
connect(effects, SIGNAL(propertyNotify(KWin::EffectWindow*,long)), this, SLOT(slotPropertyNotify(KWin::EffectWindow*,long)));
|
2011-11-26 15:15:46 +00:00
|
|
|
connect(effects, SIGNAL(screenGeometryChanged(QSize)), this, SLOT(slotScreenGeometryChanged()));
|
2017-09-10 14:51:18 +00:00
|
|
|
connect(effects, &EffectsHandler::xcbConnectionChanged, this,
|
|
|
|
[this] {
|
|
|
|
if (shader && shader->isValid() && target->valid()) {
|
|
|
|
net_wm_blur_region = effects->announceSupportProperty(s_blurAtomName, this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2013-03-16 10:34:14 +00:00
|
|
|
|
|
|
|
// Fetch the blur regions for all windows
|
|
|
|
foreach (EffectWindow *window, effects->stackingOrder())
|
|
|
|
updateBlurRegion(window);
|
2010-03-05 20:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BlurEffect::~BlurEffect()
|
|
|
|
{
|
2011-07-17 15:57:30 +00:00
|
|
|
windows.clear();
|
|
|
|
|
2016-01-27 13:15:32 +00:00
|
|
|
delete m_simpleShader;
|
2010-03-05 20:42:10 +00:00
|
|
|
delete shader;
|
|
|
|
delete target;
|
|
|
|
}
|
|
|
|
|
2011-11-26 15:15:46 +00:00
|
|
|
void BlurEffect::slotScreenGeometryChanged()
|
|
|
|
{
|
2017-09-29 12:30:54 +00:00
|
|
|
effects->makeOpenGLContextCurrent();
|
|
|
|
updateTexture();
|
|
|
|
// Fetch the blur regions for all windows
|
|
|
|
foreach (EffectWindow *window, effects->stackingOrder())
|
|
|
|
updateBlurRegion(window);
|
|
|
|
effects->doneOpenGLContextCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlurEffect::updateTexture() {
|
|
|
|
delete target;
|
|
|
|
// Offscreen texture that's used as the target for the horizontal blur pass
|
|
|
|
// and the source for the vertical pass.
|
|
|
|
tex = GLTexture(GL_RGBA8, effects->virtualScreenSize());
|
|
|
|
tex.setFilter(GL_LINEAR);
|
|
|
|
tex.setWrapMode(GL_CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
target = new GLRenderTarget(tex);
|
2011-11-26 15:15:46 +00:00
|
|
|
}
|
|
|
|
|
2010-03-13 15:03:29 +00:00
|
|
|
void BlurEffect::reconfigure(ReconfigureFlags flags)
|
|
|
|
{
|
|
|
|
Q_UNUSED(flags)
|
|
|
|
|
2014-03-25 15:29:03 +00:00
|
|
|
BlurConfig::self()->read();
|
2012-09-14 12:28:30 +00:00
|
|
|
int radius = qBound(2, BlurConfig::blurRadius(), 14);
|
2012-10-05 09:46:13 +00:00
|
|
|
if (shader)
|
|
|
|
shader->setRadius(radius);
|
2010-09-25 00:11:06 +00:00
|
|
|
|
2012-09-14 12:28:30 +00:00
|
|
|
m_shouldCache = BlurConfig::cacheTexture();
|
2011-07-17 15:57:30 +00:00
|
|
|
|
|
|
|
windows.clear();
|
|
|
|
|
2015-09-29 08:21:24 +00:00
|
|
|
if (!shader || !shader->isValid()) {
|
2014-03-16 09:16:52 +00:00
|
|
|
effects->removeSupportProperty(s_blurAtomName, this);
|
2015-09-29 08:21:24 +00:00
|
|
|
delete m_blurManager;
|
|
|
|
m_blurManager = nullptr;
|
|
|
|
}
|
2010-03-13 15:03:29 +00:00
|
|
|
}
|
|
|
|
|
2010-03-06 16:14:25 +00:00
|
|
|
void BlurEffect::updateBlurRegion(EffectWindow *w) const
|
|
|
|
{
|
|
|
|
QRegion region;
|
2017-09-10 14:51:18 +00:00
|
|
|
QByteArray value;
|
|
|
|
|
|
|
|
if (net_wm_blur_region != XCB_ATOM_NONE) {
|
|
|
|
value = w->readProperty(net_wm_blur_region, XCB_ATOM_CARDINAL, 32);
|
|
|
|
if (value.size() > 0 && !(value.size() % (4 * sizeof(uint32_t)))) {
|
|
|
|
const uint32_t *cardinals = reinterpret_cast<const uint32_t*>(value.constData());
|
|
|
|
for (unsigned int i = 0; i < value.size() / sizeof(uint32_t);) {
|
|
|
|
int x = cardinals[i++];
|
|
|
|
int y = cardinals[i++];
|
|
|
|
int w = cardinals[i++];
|
|
|
|
int h = cardinals[i++];
|
|
|
|
region += QRect(x, y, w, h);
|
|
|
|
}
|
2010-03-06 16:14:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-31 13:47:01 +00:00
|
|
|
KWayland::Server::SurfaceInterface *surf = w->surface();
|
|
|
|
|
|
|
|
if (surf && surf->blur()) {
|
|
|
|
region = surf->blur()->region();
|
|
|
|
}
|
|
|
|
|
|
|
|
//!value.isNull() full window in X11 case, surf->blur()
|
|
|
|
//valid, full window in wayland case
|
|
|
|
if (region.isEmpty() && (!value.isNull() || (surf && surf->blur()))) {
|
2010-03-12 16:47:45 +00:00
|
|
|
// Set the data to a dummy value.
|
|
|
|
// This is needed to be able to distinguish between the value not
|
|
|
|
// being set, and being set to an empty region.
|
2010-07-23 19:52:20 +00:00
|
|
|
w->setData(WindowBlurBehindRole, 1);
|
2010-03-12 16:47:45 +00:00
|
|
|
} else
|
2010-07-23 19:52:20 +00:00
|
|
|
w->setData(WindowBlurBehindRole, region);
|
2010-03-06 16:14:25 +00:00
|
|
|
}
|
|
|
|
|
2011-02-25 21:06:02 +00:00
|
|
|
void BlurEffect::slotWindowAdded(EffectWindow *w)
|
2010-03-06 16:14:25 +00:00
|
|
|
{
|
2015-08-31 13:47:01 +00:00
|
|
|
KWayland::Server::SurfaceInterface *surf = w->surface();
|
|
|
|
|
|
|
|
if (surf) {
|
|
|
|
windows[w].blurChangedConnection = connect(surf, &KWayland::Server::SurfaceInterface::blurChanged, this, [this, w] () {
|
|
|
|
|
|
|
|
if (w) {
|
|
|
|
updateBlurRegion(w);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2010-03-06 16:14:25 +00:00
|
|
|
updateBlurRegion(w);
|
|
|
|
}
|
|
|
|
|
2011-07-17 15:57:30 +00:00
|
|
|
void BlurEffect::slotWindowDeleted(EffectWindow *w)
|
|
|
|
{
|
|
|
|
if (windows.contains(w)) {
|
2015-08-31 13:47:01 +00:00
|
|
|
disconnect(windows[w].blurChangedConnection);
|
2011-07-17 15:57:30 +00:00
|
|
|
windows.remove(w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-12 18:18:19 +00:00
|
|
|
void BlurEffect::slotPropertyNotify(EffectWindow *w, long atom)
|
2010-03-06 16:14:25 +00:00
|
|
|
{
|
2017-09-10 14:51:18 +00:00
|
|
|
if (w && atom == net_wm_blur_region && net_wm_blur_region != XCB_ATOM_NONE) {
|
2010-03-06 16:14:25 +00:00
|
|
|
updateBlurRegion(w);
|
2012-02-18 21:07:39 +00:00
|
|
|
CacheEntry it = windows.find(w);
|
|
|
|
if (it != windows.end()) {
|
2014-02-24 15:13:30 +00:00
|
|
|
const QRect screen = effects->virtualScreenGeometry();
|
2012-02-18 21:07:39 +00:00
|
|
|
it->damagedRegion = expand(blurRegion(w).translated(w->pos())) & screen;
|
2011-10-12 13:16:46 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-06 16:14:25 +00:00
|
|
|
}
|
|
|
|
|
2011-05-01 20:52:43 +00:00
|
|
|
bool BlurEffect::enabledByDefault()
|
|
|
|
{
|
|
|
|
GLPlatform *gl = GLPlatform::instance();
|
|
|
|
|
2012-02-04 10:23:04 +00:00
|
|
|
if (gl->isIntel() && gl->chipClass() < SandyBridge)
|
2011-05-01 20:52:43 +00:00
|
|
|
return false;
|
2016-08-09 12:52:14 +00:00
|
|
|
if (gl->isSoftwareEmulation()) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-05-01 20:52:43 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-05 20:42:10 +00:00
|
|
|
bool BlurEffect::supported()
|
|
|
|
{
|
2014-11-22 14:53:15 +00:00
|
|
|
bool supported = effects->isOpenGLCompositing() && GLRenderTarget::supported();
|
2010-09-25 00:11:06 +00:00
|
|
|
|
|
|
|
if (supported) {
|
|
|
|
int maxTexSize;
|
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
|
|
|
|
|
2014-02-24 15:13:30 +00:00
|
|
|
const QSize screenSize = effects->virtualScreenSize();
|
|
|
|
if (screenSize.width() > maxTexSize || screenSize.height() > maxTexSize)
|
2010-09-25 00:11:06 +00:00
|
|
|
supported = false;
|
|
|
|
}
|
2010-07-05 13:42:34 +00:00
|
|
|
return supported;
|
2010-03-05 20:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QRect BlurEffect::expand(const QRect &rect) const
|
|
|
|
{
|
2010-03-13 15:03:29 +00:00
|
|
|
const int radius = shader->radius();
|
2010-03-05 20:42:10 +00:00
|
|
|
return rect.adjusted(-radius, -radius, radius, radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
QRegion BlurEffect::expand(const QRegion ®ion) const
|
|
|
|
{
|
|
|
|
QRegion expanded;
|
|
|
|
|
2011-07-09 10:43:32 +00:00
|
|
|
foreach (const QRect & rect, region.rects()) {
|
2011-01-30 14:34:42 +00:00
|
|
|
expanded += expand(rect);
|
2011-07-09 10:43:32 +00:00
|
|
|
}
|
2010-03-05 20:42:10 +00:00
|
|
|
|
|
|
|
return expanded;
|
|
|
|
}
|
|
|
|
|
2010-03-06 16:14:25 +00:00
|
|
|
QRegion BlurEffect::blurRegion(const EffectWindow *w) const
|
|
|
|
{
|
|
|
|
QRegion region;
|
|
|
|
|
2010-07-23 19:52:20 +00:00
|
|
|
const QVariant value = w->data(WindowBlurBehindRole);
|
2010-03-06 16:14:25 +00:00
|
|
|
if (value.isValid()) {
|
|
|
|
const QRegion appRegion = qvariant_cast<QRegion>(value);
|
|
|
|
if (!appRegion.isEmpty()) {
|
2012-10-12 09:34:05 +00:00
|
|
|
if (w->decorationHasAlpha() && effects->decorationSupportsBlurBehind()) {
|
2010-03-06 16:14:25 +00:00
|
|
|
region = w->shape();
|
2010-03-12 16:47:45 +00:00
|
|
|
region -= w->decorationInnerRect();
|
2011-10-15 14:19:19 +00:00
|
|
|
}
|
|
|
|
region |= appRegion.translated(w->contentsRect().topLeft()) &
|
|
|
|
w->decorationInnerRect();
|
2010-03-12 16:47:45 +00:00
|
|
|
} else {
|
|
|
|
// An empty region means that the blur effect should be enabled
|
|
|
|
// for the whole window.
|
2010-03-06 16:14:25 +00:00
|
|
|
region = w->shape();
|
2010-03-12 16:47:45 +00:00
|
|
|
}
|
2012-10-12 09:34:05 +00:00
|
|
|
} else if (w->decorationHasAlpha() && effects->decorationSupportsBlurBehind()) {
|
2010-03-12 16:47:45 +00:00
|
|
|
// If the client hasn't specified a blur region, we'll only enable
|
|
|
|
// the effect behind the decoration.
|
2010-03-06 16:14:25 +00:00
|
|
|
region = w->shape();
|
2010-03-12 16:47:45 +00:00
|
|
|
region -= w->decorationInnerRect();
|
|
|
|
}
|
2010-03-06 16:14:25 +00:00
|
|
|
|
|
|
|
return region;
|
|
|
|
}
|
|
|
|
|
2013-03-24 16:00:11 +00:00
|
|
|
void BlurEffect::uploadRegion(QVector2D *&map, const QRegion ®ion)
|
2010-03-12 18:29:16 +00:00
|
|
|
{
|
2013-03-24 15:44:40 +00:00
|
|
|
foreach (const QRect &r, region.rects()) {
|
|
|
|
const QVector2D topLeft(r.x(), r.y());
|
|
|
|
const QVector2D topRight(r.x() + r.width(), r.y());
|
|
|
|
const QVector2D bottomLeft(r.x(), r.y() + r.height());
|
|
|
|
const QVector2D bottomRight(r.x() + r.width(), r.y() + r.height());
|
|
|
|
|
|
|
|
// First triangle
|
|
|
|
*(map++) = topRight;
|
|
|
|
*(map++) = topLeft;
|
|
|
|
*(map++) = bottomLeft;
|
|
|
|
|
|
|
|
// Second triangle
|
|
|
|
*(map++) = bottomLeft;
|
|
|
|
*(map++) = bottomRight;
|
|
|
|
*(map++) = topRight;
|
|
|
|
}
|
2013-03-24 16:00:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BlurEffect::uploadGeometry(GLVertexBuffer *vbo, const QRegion &horizontal, const QRegion &vertical)
|
|
|
|
{
|
|
|
|
const int vertexCount = (horizontal.rectCount() + vertical.rectCount()) * 6;
|
2015-05-19 12:35:12 +00:00
|
|
|
if (!vertexCount)
|
|
|
|
return;
|
2013-03-24 15:44:40 +00:00
|
|
|
|
2013-03-24 16:00:11 +00:00
|
|
|
QVector2D *map = (QVector2D *) vbo->map(vertexCount * sizeof(QVector2D));
|
|
|
|
uploadRegion(map, horizontal);
|
|
|
|
uploadRegion(map, vertical);
|
2013-03-24 15:44:40 +00:00
|
|
|
vbo->unmap();
|
|
|
|
|
|
|
|
const GLVertexAttrib layout[] = {
|
|
|
|
{ VA_Position, 2, GL_FLOAT, 0 },
|
|
|
|
{ VA_TexCoord, 2, GL_FLOAT, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
vbo->setAttribLayout(layout, 2, sizeof(QVector2D));
|
2010-03-12 18:29:16 +00:00
|
|
|
}
|
|
|
|
|
2011-05-01 21:17:28 +00:00
|
|
|
void BlurEffect::prePaintScreen(ScreenPrePaintData &data, int time)
|
2010-03-05 20:42:10 +00:00
|
|
|
{
|
2011-07-09 10:43:32 +00:00
|
|
|
m_damagedArea = QRegion();
|
2011-07-17 15:57:30 +00:00
|
|
|
m_paintedArea = QRegion();
|
2011-07-09 10:43:32 +00:00
|
|
|
m_currentBlur = QRegion();
|
2011-05-01 21:17:28 +00:00
|
|
|
|
|
|
|
effects->prePaintScreen(data, time);
|
2011-07-09 10:43:32 +00:00
|
|
|
}
|
2011-05-01 21:17:28 +00:00
|
|
|
|
2011-07-09 10:43:32 +00:00
|
|
|
void BlurEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
// this effect relies on prePaintWindow being called in the bottom to top order
|
2011-05-01 21:17:28 +00:00
|
|
|
|
2011-07-09 10:43:32 +00:00
|
|
|
effects->prePaintWindow(w, data, time);
|
2011-05-01 21:17:28 +00:00
|
|
|
|
2011-07-09 10:43:32 +00:00
|
|
|
if (!w->isPaintingEnabled()) {
|
2011-05-01 21:17:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-10-05 09:46:13 +00:00
|
|
|
if (!shader || !shader->isValid()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-05-01 21:17:28 +00:00
|
|
|
|
2011-07-09 10:43:32 +00:00
|
|
|
// to blur an area partially we have to shrink the opaque area of a window
|
|
|
|
QRegion newClip;
|
|
|
|
const QRegion oldClip = data.clip;
|
|
|
|
const int radius = shader->radius();
|
|
|
|
foreach (const QRect& rect, data.clip.rects()) {
|
|
|
|
newClip |= rect.adjusted(radius,radius,-radius,-radius);
|
|
|
|
}
|
|
|
|
data.clip = newClip;
|
|
|
|
|
2011-07-17 15:57:30 +00:00
|
|
|
const QRegion oldPaint = data.paint;
|
|
|
|
|
2011-08-03 06:16:12 +00:00
|
|
|
// we don't have to blur a region we don't see
|
2011-07-09 10:43:32 +00:00
|
|
|
m_currentBlur -= newClip;
|
|
|
|
// if we have to paint a non-opaque part of this window that intersects with the
|
2011-10-12 14:02:19 +00:00
|
|
|
// currently blurred region (which is not cached) we have to redraw the whole region
|
2011-07-09 10:43:32 +00:00
|
|
|
if ((data.paint-oldClip).intersects(m_currentBlur)) {
|
|
|
|
data.paint |= m_currentBlur;
|
|
|
|
}
|
|
|
|
|
|
|
|
// in case this window has regions to be blurred
|
2014-02-24 15:13:30 +00:00
|
|
|
const QRect screen = effects->virtualScreenGeometry();
|
2012-02-16 20:11:51 +00:00
|
|
|
const QRegion blurArea = blurRegion(w).translated(w->pos()) & screen;
|
|
|
|
const QRegion expandedBlur = expand(blurArea) & screen;
|
2011-07-17 15:57:30 +00:00
|
|
|
|
2015-01-08 07:44:47 +00:00
|
|
|
if (m_shouldCache && !w->isDeleted()) {
|
2011-07-17 15:57:30 +00:00
|
|
|
// we are caching the horizontally blurred background texture
|
|
|
|
|
|
|
|
// if a window underneath the blurred area is damaged we have to
|
2011-10-12 14:02:19 +00:00
|
|
|
// update the cached texture
|
2011-12-10 16:31:18 +00:00
|
|
|
QRegion damagedCache;
|
2012-02-18 21:07:39 +00:00
|
|
|
CacheEntry it = windows.find(w);
|
|
|
|
if (it != windows.end() && !it->dropCache &&
|
|
|
|
it->windowPos == w->pos() &&
|
|
|
|
it->blurredBackground.size() == expandedBlur.boundingRect().size()) {
|
2012-02-16 20:11:51 +00:00
|
|
|
damagedCache = (expand(expandedBlur & m_damagedArea) |
|
2012-02-18 21:07:39 +00:00
|
|
|
(it->damagedRegion & data.paint)) & expandedBlur;
|
2011-12-10 16:31:18 +00:00
|
|
|
} else {
|
|
|
|
damagedCache = expandedBlur;
|
|
|
|
}
|
2011-12-10 10:28:38 +00:00
|
|
|
if (!damagedCache.isEmpty()) {
|
2011-10-12 14:02:19 +00:00
|
|
|
// This is the area of the blurry window which really can change.
|
2011-12-10 10:28:38 +00:00
|
|
|
const QRegion damagedArea = damagedCache & blurArea;
|
2011-10-12 14:02:19 +00:00
|
|
|
// In order to be able to recalculate this area we have to make sure the
|
|
|
|
// background area is painted before.
|
2011-09-18 15:53:14 +00:00
|
|
|
data.paint |= expand(damagedArea);
|
2012-02-18 21:07:39 +00:00
|
|
|
if (it != windows.end()) {
|
2011-10-12 14:02:19 +00:00
|
|
|
// In case we already have a texture cache mark the dirty regions invalid.
|
2012-02-18 21:07:39 +00:00
|
|
|
it->damagedRegion &= expandedBlur;
|
|
|
|
it->damagedRegion |= damagedCache;
|
2012-02-19 00:19:32 +00:00
|
|
|
// The valid part of the cache can be considered as being opaque
|
|
|
|
// as long as we don't need to update a bordering part
|
|
|
|
data.clip |= blurArea - expand(it->damagedRegion);
|
2012-02-18 21:07:39 +00:00
|
|
|
it->dropCache = false;
|
2011-09-18 15:53:14 +00:00
|
|
|
}
|
2011-07-17 15:57:30 +00:00
|
|
|
// we keep track of the "damage propagation"
|
2011-09-18 15:53:14 +00:00
|
|
|
m_damagedArea |= damagedArea;
|
2011-07-17 15:57:30 +00:00
|
|
|
// we have to check again whether we do not damage a blurred area
|
|
|
|
// of a window we do not cache
|
|
|
|
if (expandedBlur.intersects(m_currentBlur)) {
|
|
|
|
data.paint |= m_currentBlur;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// we are not caching the window
|
|
|
|
|
|
|
|
// if this window or an window underneath the blurred area is painted again we have to
|
|
|
|
// blur everything
|
2011-12-10 10:28:38 +00:00
|
|
|
if (m_paintedArea.intersects(expandedBlur) || data.paint.intersects(blurArea)) {
|
2011-07-17 15:57:30 +00:00
|
|
|
data.paint |= expandedBlur;
|
|
|
|
// we keep track of the "damage propagation"
|
2011-12-10 10:28:38 +00:00
|
|
|
m_damagedArea |= expand(expandedBlur & m_damagedArea) & blurArea;
|
2011-07-17 15:57:30 +00:00
|
|
|
// we have to check again whether we do not damage a blurred area
|
|
|
|
// of a window we do not cache
|
|
|
|
if (expandedBlur.intersects(m_currentBlur)) {
|
|
|
|
data.paint |= m_currentBlur;
|
|
|
|
}
|
2011-05-01 21:17:28 +00:00
|
|
|
}
|
2011-07-17 15:57:30 +00:00
|
|
|
|
|
|
|
m_currentBlur |= expandedBlur;
|
2011-05-01 21:17:28 +00:00
|
|
|
}
|
|
|
|
|
2011-08-03 06:16:12 +00:00
|
|
|
// we don't consider damaged areas which are occluded and are not
|
2011-07-09 10:43:32 +00:00
|
|
|
// explicitly damaged by this window
|
|
|
|
m_damagedArea -= data.clip;
|
2011-07-17 15:57:30 +00:00
|
|
|
m_damagedArea |= oldPaint;
|
|
|
|
|
|
|
|
// in contrast to m_damagedArea does m_paintedArea keep track of all repainted areas
|
|
|
|
m_paintedArea -= data.clip;
|
|
|
|
m_paintedArea |= data.paint;
|
2010-03-05 20:42:10 +00:00
|
|
|
}
|
|
|
|
|
2011-05-14 16:22:38 +00:00
|
|
|
bool BlurEffect::shouldBlur(const EffectWindow *w, int mask, const WindowPaintData &data) const
|
2010-03-05 20:42:10 +00:00
|
|
|
{
|
2012-10-05 09:46:13 +00:00
|
|
|
if (!target->valid() || !shader || !shader->isValid())
|
2011-05-14 16:22:38 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (effects->activeFullScreenEffect() && !w->data(WindowForceBlurRole).toBool())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (w->isDesktop())
|
|
|
|
return false;
|
|
|
|
|
2012-05-28 10:00:31 +00:00
|
|
|
bool scaled = !qFuzzyCompare(data.xScale(), 1.0) && !qFuzzyCompare(data.yScale(), 1.0);
|
2012-05-28 12:45:46 +00:00
|
|
|
bool translated = data.xTranslation() || data.yTranslation();
|
2011-05-14 16:22:38 +00:00
|
|
|
|
2016-02-25 11:45:19 +00:00
|
|
|
if ((scaled || (translated || (mask & PAINT_WINDOW_TRANSFORMED))) && !w->data(WindowForceBlurRole).toBool())
|
2011-05-14 16:22:38 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
bool blurBehindDecos = effects->decorationsHaveAlpha() &&
|
|
|
|
effects->decorationSupportsBlurBehind();
|
|
|
|
|
2015-06-22 13:48:48 +00:00
|
|
|
if (!w->hasAlpha() && w->opacity() >= 1.0 && !(blurBehindDecos && w->hasDecoration()))
|
2011-05-14 16:22:38 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BlurEffect::drawWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data)
|
|
|
|
{
|
2016-10-18 14:33:20 +00:00
|
|
|
const QRect screen = GLRenderTarget::virtualScreenGeometry();
|
2011-05-14 16:22:38 +00:00
|
|
|
if (shouldBlur(w, mask, data)) {
|
2011-12-10 21:32:47 +00:00
|
|
|
QRegion shape = region & blurRegion(w).translated(w->pos()) & screen;
|
|
|
|
|
|
|
|
// let's do the evil parts - someone wants to blur behind a transformed window
|
2016-02-09 11:09:01 +00:00
|
|
|
const bool translated = data.xTranslation() || data.yTranslation();
|
|
|
|
const bool scaled = data.xScale() != 1 || data.yScale() != 1;
|
|
|
|
if (scaled) {
|
|
|
|
QPoint pt = shape.boundingRect().topLeft();
|
|
|
|
QVector<QRect> shapeRects = shape.rects();
|
|
|
|
shape = QRegion(); // clear
|
|
|
|
foreach (QRect r, shapeRects) {
|
|
|
|
r.moveTo(pt.x() + (r.x() - pt.x()) * data.xScale() + data.xTranslation(),
|
|
|
|
pt.y() + (r.y() - pt.y()) * data.yScale() + data.yTranslation());
|
|
|
|
r.setWidth(r.width() * data.xScale());
|
|
|
|
r.setHeight(r.height() * data.yScale());
|
|
|
|
shape |= r;
|
|
|
|
}
|
|
|
|
shape = shape & region;
|
|
|
|
|
|
|
|
//Only translated, not scaled
|
|
|
|
} else if (translated) {
|
2012-05-28 12:45:46 +00:00
|
|
|
shape = shape.translated(data.xTranslation(), data.yTranslation());
|
2011-12-10 21:32:47 +00:00
|
|
|
shape = shape & region;
|
|
|
|
}
|
2011-05-14 16:22:38 +00:00
|
|
|
|
2011-07-17 15:57:30 +00:00
|
|
|
if (!shape.isEmpty()) {
|
2016-02-02 11:14:55 +00:00
|
|
|
if (w->isFullScreen() && GLRenderTarget::blitSupported() && m_simpleShader->isValid()
|
|
|
|
&& !GLPlatform::instance()->supports(LimitedNPOT) && shape.boundingRect() == w->geometry()) {
|
2016-01-27 13:15:32 +00:00
|
|
|
doSimpleBlur(w, data.opacity(), data.screenProjectionMatrix());
|
|
|
|
} else if (m_shouldCache && !translated && !w->isDeleted()) {
|
2015-12-03 08:51:52 +00:00
|
|
|
doCachedBlur(w, region, data.opacity(), data.screenProjectionMatrix());
|
2011-07-17 15:57:30 +00:00
|
|
|
} else {
|
2015-12-03 08:51:52 +00:00
|
|
|
doBlur(shape, screen, data.opacity(), data.screenProjectionMatrix());
|
2011-07-17 15:57:30 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-05 20:42:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the window over the blurred area
|
|
|
|
effects->drawWindow(w, mask, region, data);
|
|
|
|
}
|
|
|
|
|
2010-07-24 20:48:19 +00:00
|
|
|
void BlurEffect::paintEffectFrame(EffectFrame *frame, QRegion region, double opacity, double frameOpacity)
|
|
|
|
{
|
2014-02-24 15:13:30 +00:00
|
|
|
const QRect screen = effects->virtualScreenGeometry();
|
2012-10-05 09:46:13 +00:00
|
|
|
bool valid = target->valid() && shader && shader->isValid();
|
2011-01-30 14:34:42 +00:00
|
|
|
QRegion shape = frame->geometry().adjusted(-5, -5, 5, 5) & screen;
|
2011-04-27 12:48:34 +00:00
|
|
|
if (valid && !shape.isEmpty() && region.intersects(shape.boundingRect()) && frame->style() != EffectFrameNone) {
|
2015-12-03 08:51:52 +00:00
|
|
|
doBlur(shape, screen, opacity * frameOpacity, frame->screenProjectionMatrix());
|
2010-07-24 20:48:19 +00:00
|
|
|
}
|
|
|
|
effects->paintEffectFrame(frame, region, opacity, frameOpacity);
|
|
|
|
}
|
|
|
|
|
2016-01-27 13:15:32 +00:00
|
|
|
void BlurEffect::doSimpleBlur(EffectWindow *w, const float opacity, const QMatrix4x4 &screenProjection)
|
|
|
|
{
|
|
|
|
// The fragment shader uses a LOD bias of 1.75, so we need 3 mipmap levels.
|
|
|
|
GLTexture blurTexture = GLTexture(GL_RGBA8, w->size(), 3);
|
|
|
|
blurTexture.setFilter(GL_LINEAR_MIPMAP_LINEAR);
|
|
|
|
blurTexture.setWrapMode(GL_CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
target->attachTexture(blurTexture);
|
|
|
|
target->blitFromFramebuffer(w->geometry(), QRect(QPoint(0, 0), w->size()));
|
|
|
|
|
|
|
|
// Unmodified base image
|
|
|
|
ShaderBinder binder(m_simpleShader);
|
|
|
|
QMatrix4x4 mvp = screenProjection;
|
|
|
|
mvp.translate(w->x(), w->y());
|
|
|
|
m_simpleShader->setUniform(GLShader::ModelViewProjectionMatrix, mvp);
|
|
|
|
m_simpleShader->setUniform("u_alphaProgress", opacity);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
blurTexture.bind();
|
|
|
|
blurTexture.generateMipmaps();
|
|
|
|
blurTexture.render(infiniteRegion(), w->geometry());
|
|
|
|
blurTexture.unbind();
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
2015-12-03 08:51:52 +00:00
|
|
|
void BlurEffect::doBlur(const QRegion& shape, const QRect& screen, const float opacity, const QMatrix4x4 &screenProjection)
|
2010-07-24 20:48:19 +00:00
|
|
|
{
|
|
|
|
const QRegion expanded = expand(shape) & screen;
|
|
|
|
const QRect r = expanded.boundingRect();
|
|
|
|
|
2013-03-24 16:00:11 +00:00
|
|
|
// Upload geometry for the horizontal and vertical passes
|
|
|
|
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
|
|
|
|
uploadGeometry(vbo, expanded, shape);
|
|
|
|
vbo->bindArrays();
|
|
|
|
|
2017-03-06 14:34:36 +00:00
|
|
|
const qreal scale = GLRenderTarget::virtualScreenScale();
|
|
|
|
|
2010-07-24 20:48:19 +00:00
|
|
|
// Create a scratch texture and copy the area in the back buffer that we're
|
|
|
|
// going to blur into it
|
2017-03-06 14:34:36 +00:00
|
|
|
// for HIGH DPI scratch is captured in native resolution, it is then implicitly downsampled
|
|
|
|
// when rendering into tex
|
|
|
|
GLTexture scratch(GL_RGBA8, r.width() * scale, r.height() * scale);
|
2010-07-24 20:48:19 +00:00
|
|
|
scratch.setFilter(GL_LINEAR);
|
|
|
|
scratch.setWrapMode(GL_CLAMP_TO_EDGE);
|
|
|
|
scratch.bind();
|
|
|
|
|
2016-10-18 14:33:20 +00:00
|
|
|
const QRect sg = GLRenderTarget::virtualScreenGeometry();
|
2017-03-06 14:34:36 +00:00
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, (r.x() - sg.x()) * scale, (sg.height() - sg.y() - r.y() - r.height()) * scale,
|
|
|
|
scratch.width(), scratch.height());
|
2010-07-24 20:48:19 +00:00
|
|
|
|
|
|
|
// Draw the texture on the offscreen framebuffer object, while blurring it horizontally
|
2011-07-17 15:57:30 +00:00
|
|
|
target->attachTexture(tex);
|
2011-03-13 13:34:30 +00:00
|
|
|
GLRenderTarget::pushRenderTarget(target);
|
2010-07-24 20:48:19 +00:00
|
|
|
|
|
|
|
shader->bind();
|
|
|
|
shader->setDirection(Qt::Horizontal);
|
|
|
|
shader->setPixelDistance(1.0 / r.width());
|
|
|
|
|
2015-12-03 08:51:52 +00:00
|
|
|
QMatrix4x4 modelViewProjectionMatrix;
|
|
|
|
modelViewProjectionMatrix.ortho(0, tex.width(), tex.height(), 0 , 0, 65535);
|
|
|
|
shader->setModelViewProjectionMatrix(modelViewProjectionMatrix);
|
|
|
|
|
2010-07-24 20:48:19 +00:00
|
|
|
// Set up the texture matrix to transform from screen coordinates
|
|
|
|
// to texture coordinates.
|
2011-01-08 18:56:22 +00:00
|
|
|
QMatrix4x4 textureMatrix;
|
2017-03-06 14:34:36 +00:00
|
|
|
textureMatrix.scale(1.0 / r.width(), -1.0 / r.height(), 1);
|
|
|
|
textureMatrix.translate(-r.x(), (-r.height() - r.y()), 0);
|
2011-01-08 18:56:22 +00:00
|
|
|
shader->setTextureMatrix(textureMatrix);
|
2010-07-24 20:48:19 +00:00
|
|
|
|
2013-03-24 16:00:11 +00:00
|
|
|
vbo->draw(GL_TRIANGLES, 0, expanded.rectCount() * 6);
|
2010-07-24 20:48:19 +00:00
|
|
|
|
2011-03-13 13:34:30 +00:00
|
|
|
GLRenderTarget::popRenderTarget();
|
2010-07-24 20:48:19 +00:00
|
|
|
scratch.unbind();
|
|
|
|
scratch.discard();
|
|
|
|
|
|
|
|
// Now draw the horizontally blurred area back to the backbuffer, while
|
|
|
|
// blurring it vertically and clipping it to the window shape.
|
2011-07-17 15:57:30 +00:00
|
|
|
tex.bind();
|
2010-07-24 20:48:19 +00:00
|
|
|
|
|
|
|
shader->setDirection(Qt::Vertical);
|
2011-07-17 15:57:30 +00:00
|
|
|
shader->setPixelDistance(1.0 / tex.height());
|
2010-07-24 20:48:19 +00:00
|
|
|
|
|
|
|
// Modulate the blurred texture with the window opacity if the window isn't opaque
|
|
|
|
if (opacity < 1.0) {
|
|
|
|
glEnable(GL_BLEND);
|
2015-06-22 13:48:48 +00:00
|
|
|
#if 1 // bow shape, always above y = x
|
|
|
|
float o = 1.0f-opacity;
|
|
|
|
o = 1.0f - o*o;
|
|
|
|
#else // sigmoid shape, above y = x for x > 0.5, below y = x for x < 0.5
|
|
|
|
float o = 2.0f*opacity - 1.0f;
|
|
|
|
o = 0.5f + o / (1.0f + qAbs(o));
|
|
|
|
#endif
|
|
|
|
glBlendColor(0, 0, 0, o);
|
2010-07-24 20:48:19 +00:00
|
|
|
glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the up the texture matrix to transform from screen coordinates
|
|
|
|
// to texture coordinates.
|
2011-01-08 18:56:22 +00:00
|
|
|
textureMatrix.setToIdentity();
|
2011-07-17 15:57:30 +00:00
|
|
|
textureMatrix.scale(1.0 / tex.width(), -1.0 / tex.height(), 1);
|
|
|
|
textureMatrix.translate(0, -tex.height(), 0);
|
2011-01-08 18:56:22 +00:00
|
|
|
shader->setTextureMatrix(textureMatrix);
|
2015-12-03 08:51:52 +00:00
|
|
|
shader->setModelViewProjectionMatrix(screenProjection);
|
2010-07-24 20:48:19 +00:00
|
|
|
|
2013-03-24 16:00:11 +00:00
|
|
|
vbo->draw(GL_TRIANGLES, expanded.rectCount() * 6, shape.rectCount() * 6);
|
|
|
|
vbo->unbindArrays();
|
2010-07-24 20:48:19 +00:00
|
|
|
|
2011-01-08 18:56:22 +00:00
|
|
|
if (opacity < 1.0) {
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
2010-07-24 20:48:19 +00:00
|
|
|
|
2011-07-17 15:57:30 +00:00
|
|
|
tex.unbind();
|
|
|
|
shader->unbind();
|
|
|
|
}
|
|
|
|
|
2015-12-03 08:51:52 +00:00
|
|
|
void BlurEffect::doCachedBlur(EffectWindow *w, const QRegion& region, const float opacity, const QMatrix4x4 &screenProjection)
|
2011-07-17 15:57:30 +00:00
|
|
|
{
|
2014-02-24 15:13:30 +00:00
|
|
|
const QRect screen = effects->virtualScreenGeometry();
|
2011-07-17 15:57:30 +00:00
|
|
|
const QRegion blurredRegion = blurRegion(w).translated(w->pos()) & screen;
|
|
|
|
const QRegion expanded = expand(blurredRegion) & screen;
|
|
|
|
const QRect r = expanded.boundingRect();
|
|
|
|
|
2011-10-12 14:02:19 +00:00
|
|
|
// The background texture we get is only partially valid.
|
2011-07-17 15:57:30 +00:00
|
|
|
|
2012-02-18 21:07:39 +00:00
|
|
|
CacheEntry it = windows.find(w);
|
|
|
|
if (it == windows.end()) {
|
2011-07-17 15:57:30 +00:00
|
|
|
BlurWindowInfo bwi;
|
2014-12-13 13:28:33 +00:00
|
|
|
bwi.blurredBackground = GLTexture(GL_RGBA8, r.width(),r.height());
|
2011-09-18 15:53:14 +00:00
|
|
|
bwi.damagedRegion = expanded;
|
2011-12-10 16:31:18 +00:00
|
|
|
bwi.dropCache = false;
|
2012-02-07 16:01:41 +00:00
|
|
|
bwi.windowPos = w->pos();
|
2012-02-18 21:07:39 +00:00
|
|
|
it = windows.insert(w, bwi);
|
|
|
|
} else if (it->blurredBackground.size() != r.size()) {
|
2014-12-13 13:28:33 +00:00
|
|
|
it->blurredBackground = GLTexture(GL_RGBA8, r.width(),r.height());
|
2012-02-18 21:07:39 +00:00
|
|
|
it->dropCache = false;
|
|
|
|
it->windowPos = w->pos();
|
|
|
|
} else if (it->windowPos != w->pos()) {
|
|
|
|
it->dropCache = false;
|
|
|
|
it->windowPos = w->pos();
|
2011-07-17 15:57:30 +00:00
|
|
|
}
|
|
|
|
|
2012-02-18 21:07:39 +00:00
|
|
|
GLTexture targetTexture = it->blurredBackground;
|
2011-07-17 15:57:30 +00:00
|
|
|
targetTexture.setFilter(GL_LINEAR);
|
|
|
|
targetTexture.setWrapMode(GL_CLAMP_TO_EDGE);
|
|
|
|
shader->bind();
|
|
|
|
QMatrix4x4 textureMatrix;
|
|
|
|
QMatrix4x4 modelViewProjectionMatrix;
|
|
|
|
|
2012-02-16 20:11:51 +00:00
|
|
|
/**
|
|
|
|
* Which part of the background texture can be updated ?
|
|
|
|
*
|
|
|
|
* Well this is a rather difficult question. We kind of rely on the fact, that
|
|
|
|
* we need a bigger background region being painted before, more precisely if we want to
|
|
|
|
* blur region A we need the background region expand(A). This business logic is basically
|
|
|
|
* done in prePaintWindow:
|
|
|
|
* data.paint |= expand(damagedArea);
|
|
|
|
*
|
|
|
|
* Now "data.paint" gets clipped and becomes what we receive as the "region" variable
|
|
|
|
* in this function. In theory there is now only one function that does this clipping
|
|
|
|
* and this is paintSimpleScreen. The clipping has the effect that "damagedRegion"
|
|
|
|
* is no longer a subset of "region" and we cannot fully validate the cache within one
|
|
|
|
* rendering pass. If we would now update the "damageRegion & region" part of the cache
|
|
|
|
* we would wrongly update the part of the cache that is next to the "region" border and
|
|
|
|
* which lies within "damagedRegion", just because we cannot assume that the framebuffer
|
|
|
|
* outside of "region" is valid. Therefore the maximal damaged region of the cache that can
|
|
|
|
* be repainted is given by:
|
|
|
|
* validUpdate = damagedRegion - expand(damagedRegion - region);
|
|
|
|
*
|
|
|
|
* Now you may ask what is with the rest of "damagedRegion & region" that is not part
|
|
|
|
* of "validUpdate" but also might end up on the screen. Well under the assumption
|
|
|
|
* that only the occlusion culling can shrink "data.paint", we can control this by reducing
|
|
|
|
* the opaque area of every window by a margin of the blurring radius (c.f. prePaintWindow).
|
|
|
|
* This way we are sure that this area is overpainted by a higher opaque window.
|
|
|
|
*
|
|
|
|
* Apparently paintSimpleScreen is not the only function that can influence "region".
|
|
|
|
* In fact every effect's paintWindow that is called before Blur::paintWindow
|
|
|
|
* can do so (e.g. SlidingPopups). Hence we have to make the compromise that we update
|
|
|
|
* "damagedRegion & region" of the cache but only mark "validUpdate" as valid.
|
|
|
|
**/
|
2012-02-18 21:07:39 +00:00
|
|
|
const QRegion damagedRegion = it->damagedRegion;
|
2012-02-16 20:11:51 +00:00
|
|
|
const QRegion updateBackground = damagedRegion & region;
|
|
|
|
const QRegion validUpdate = damagedRegion - expand(damagedRegion - region);
|
|
|
|
|
2013-03-24 16:00:11 +00:00
|
|
|
const QRegion horizontal = validUpdate.isEmpty() ? QRegion() : (updateBackground & screen);
|
|
|
|
const QRegion vertical = blurredRegion & region;
|
|
|
|
|
|
|
|
const int horizontalOffset = 0;
|
|
|
|
const int horizontalCount = horizontal.rectCount() * 6;
|
|
|
|
|
|
|
|
const int verticalOffset = horizontalCount;
|
|
|
|
const int verticalCount = vertical.rectCount() * 6;
|
|
|
|
|
|
|
|
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
|
|
|
|
uploadGeometry(vbo, horizontal, vertical);
|
|
|
|
|
|
|
|
vbo->bindArrays();
|
|
|
|
|
2012-02-16 20:11:51 +00:00
|
|
|
if (!validUpdate.isEmpty()) {
|
2011-09-18 15:53:14 +00:00
|
|
|
const QRect updateRect = (expand(updateBackground) & expanded).boundingRect();
|
2012-01-08 16:23:36 +00:00
|
|
|
// First we have to copy the background from the frontbuffer
|
|
|
|
// into a scratch texture (in this case "tex").
|
|
|
|
tex.bind();
|
2011-07-17 15:57:30 +00:00
|
|
|
|
2014-11-25 07:40:23 +00:00
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, updateRect.x(), effects->virtualScreenSize().height() - updateRect.y() - updateRect.height(),
|
2011-09-18 15:53:14 +00:00
|
|
|
updateRect.width(), updateRect.height());
|
2011-07-17 15:57:30 +00:00
|
|
|
|
|
|
|
// Draw the texture on the offscreen framebuffer object, while blurring it horizontally
|
|
|
|
target->attachTexture(targetTexture);
|
|
|
|
GLRenderTarget::pushRenderTarget(target);
|
|
|
|
|
|
|
|
shader->setDirection(Qt::Horizontal);
|
2012-01-08 16:23:36 +00:00
|
|
|
shader->setPixelDistance(1.0 / tex.width());
|
2011-07-17 15:57:30 +00:00
|
|
|
|
|
|
|
modelViewProjectionMatrix.ortho(0, r.width(), r.height(), 0 , 0, 65535);
|
|
|
|
modelViewProjectionMatrix.translate(-r.x(), -r.y(), 0);
|
|
|
|
shader->setModelViewProjectionMatrix(modelViewProjectionMatrix);
|
|
|
|
|
|
|
|
// Set up the texture matrix to transform from screen coordinates
|
|
|
|
// to texture coordinates.
|
2012-01-08 16:23:36 +00:00
|
|
|
textureMatrix.scale(1.0 / tex.width(), -1.0 / tex.height(), 1);
|
|
|
|
textureMatrix.translate(-updateRect.x(), -updateRect.height() - updateRect.y(), 0);
|
2011-07-17 15:57:30 +00:00
|
|
|
shader->setTextureMatrix(textureMatrix);
|
|
|
|
|
2013-03-24 16:00:11 +00:00
|
|
|
vbo->draw(GL_TRIANGLES, horizontalOffset, horizontalCount);
|
2011-07-17 15:57:30 +00:00
|
|
|
|
|
|
|
GLRenderTarget::popRenderTarget();
|
2012-01-08 16:23:36 +00:00
|
|
|
tex.unbind();
|
2011-10-12 14:02:19 +00:00
|
|
|
// mark the updated region as valid
|
2012-02-18 21:07:39 +00:00
|
|
|
it->damagedRegion -= validUpdate;
|
2011-07-17 15:57:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now draw the horizontally blurred area back to the backbuffer, while
|
|
|
|
// blurring it vertically and clipping it to the window shape.
|
|
|
|
targetTexture.bind();
|
|
|
|
|
|
|
|
shader->setDirection(Qt::Vertical);
|
|
|
|
shader->setPixelDistance(1.0 / targetTexture.height());
|
|
|
|
|
|
|
|
// Modulate the blurred texture with the window opacity if the window isn't opaque
|
|
|
|
if (opacity < 1.0) {
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glBlendColor(0, 0, 0, opacity);
|
|
|
|
glBlendFunc(GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA);
|
|
|
|
}
|
|
|
|
|
2015-12-03 08:51:52 +00:00
|
|
|
shader->setModelViewProjectionMatrix(screenProjection);
|
2011-07-17 15:57:30 +00:00
|
|
|
|
|
|
|
// Set the up the texture matrix to transform from screen coordinates
|
|
|
|
// to texture coordinates.
|
|
|
|
textureMatrix.setToIdentity();
|
|
|
|
textureMatrix.scale(1.0 / targetTexture.width(), -1.0 / targetTexture.height(), 1);
|
|
|
|
textureMatrix.translate(-r.x(), -targetTexture.height() - r.y(), 0);
|
|
|
|
shader->setTextureMatrix(textureMatrix);
|
|
|
|
|
2013-03-24 16:00:11 +00:00
|
|
|
vbo->draw(GL_TRIANGLES, verticalOffset, verticalCount);
|
|
|
|
vbo->unbindArrays();
|
2011-07-17 15:57:30 +00:00
|
|
|
|
|
|
|
if (opacity < 1.0) {
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
|
|
|
targetTexture.unbind();
|
2010-07-24 20:48:19 +00:00
|
|
|
shader->unbind();
|
|
|
|
}
|
|
|
|
|
2012-08-11 09:24:37 +00:00
|
|
|
int BlurEffect::blurRadius() const
|
|
|
|
{
|
2012-10-05 09:46:13 +00:00
|
|
|
if (!shader) {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-08-11 09:24:37 +00:00
|
|
|
return shader->radius();
|
|
|
|
}
|
|
|
|
|
2010-03-05 20:42:10 +00:00
|
|
|
} // namespace KWin
|
|
|
|
|