2010-06-02 20:04:54 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2010 by Fredrik Höglund <fredrik@kde.org>
|
2013-03-12 12:17:53 +00:00
|
|
|
Copyright (C) 2010 Martin Gräßlin <mgraesslin@kde.org>
|
2010-06-02 20:04:54 +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. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#include "lanczosfilter.h"
|
2013-04-11 07:17:58 +00:00
|
|
|
#include "client.h"
|
|
|
|
#include "deleted.h"
|
2010-06-02 20:04:54 +00:00
|
|
|
#include "effects.h"
|
2013-04-11 07:17:58 +00:00
|
|
|
#include "unmanaged.h"
|
2012-03-16 07:43:52 +00:00
|
|
|
#include "options.h"
|
2013-04-26 09:52:15 +00:00
|
|
|
#include "workspace.h"
|
2010-06-02 20:04:54 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
#include <kwinglutils.h>
|
|
|
|
#include <kwinglplatform.h>
|
2010-06-02 20:04:54 +00:00
|
|
|
|
|
|
|
#include <kwineffects.h>
|
|
|
|
|
|
|
|
#include <qmath.h>
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
LanczosFilter::LanczosFilter(QObject* parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_offscreenTex(0)
|
|
|
|
, m_offscreenTarget(0)
|
|
|
|
, m_inited(false)
|
2013-02-08 12:39:55 +00:00
|
|
|
, m_shader(0)
|
|
|
|
, m_uTexUnit(0)
|
|
|
|
, m_uOffsets(0)
|
|
|
|
, m_uKernel(0)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
}
|
2010-06-02 20:04:54 +00:00
|
|
|
|
|
|
|
LanczosFilter::~LanczosFilter()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-06-02 20:04:54 +00:00
|
|
|
delete m_offscreenTarget;
|
|
|
|
delete m_offscreenTex;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-06-02 20:04:54 +00:00
|
|
|
|
|
|
|
void LanczosFilter::init()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-06-02 20:04:54 +00:00
|
|
|
if (m_inited)
|
|
|
|
return;
|
|
|
|
m_inited = true;
|
2011-07-20 20:41:58 +00:00
|
|
|
const bool force = (qstrcmp(qgetenv("KWIN_FORCE_LANCZOS"), "1") == 0);
|
|
|
|
if (force) {
|
2013-09-02 11:14:39 +00:00
|
|
|
qWarning() << "Lanczos Filter forced on by environment variable";
|
2011-07-20 20:41:58 +00:00
|
|
|
}
|
2010-11-11 19:53:19 +00:00
|
|
|
|
2012-03-16 07:43:52 +00:00
|
|
|
if (!force && options->glSmoothScale() != 2)
|
2010-11-11 19:53:19 +00:00
|
|
|
return; // disabled by config
|
2013-04-11 07:01:01 +00:00
|
|
|
if (!GLRenderTarget::supported())
|
2013-02-08 12:39:55 +00:00
|
|
|
return;
|
2010-11-11 19:53:19 +00:00
|
|
|
|
2011-01-18 22:36:58 +00:00
|
|
|
GLPlatform *gl = GLPlatform::instance();
|
2013-02-08 12:39:55 +00:00
|
|
|
if (!force) {
|
|
|
|
// The lanczos filter is reported to be broken with the Intel driver prior SandyBridge
|
|
|
|
if (gl->driver() == Driver_Intel && gl->chipClass() < SandyBridge)
|
|
|
|
return;
|
2013-07-18 09:03:23 +00:00
|
|
|
// Broken on Intel chips with Mesa 9.1 - BUG 313613
|
|
|
|
if (gl->driver() == Driver_Intel && gl->mesaVersion() >= kVersionNumber(9, 1) && gl->mesaVersion() < kVersionNumber(9, 2))
|
2013-02-08 12:39:55 +00:00
|
|
|
return;
|
|
|
|
// also radeon before R600 has trouble
|
|
|
|
if (gl->isRadeon() && gl->chipClass() < R600)
|
|
|
|
return;
|
2011-12-31 07:54:15 +00:00
|
|
|
}
|
2013-03-13 16:29:41 +00:00
|
|
|
m_shader.reset(ShaderManager::instance()->loadFragmentShader(ShaderManager::SimpleShader,
|
|
|
|
gl->glslVersion() >= kVersionNumber(1, 40) ?
|
2013-07-23 05:02:52 +00:00
|
|
|
QStringLiteral(":/resources/shaders/1.40/lanczos-fragment.glsl") :
|
|
|
|
QStringLiteral(":/resources/shaders/1.10/lanczos-fragment.glsl")));
|
2013-02-08 12:39:55 +00:00
|
|
|
if (m_shader->isValid()) {
|
|
|
|
ShaderBinder binder(m_shader.data());
|
|
|
|
m_uTexUnit = m_shader->uniformLocation("texUnit");
|
|
|
|
m_uKernel = m_shader->uniformLocation("kernel");
|
|
|
|
m_uOffsets = m_shader->uniformLocation("offsets");
|
|
|
|
} else {
|
2013-09-02 11:14:39 +00:00
|
|
|
qDebug() << "Shader is not valid";
|
2013-02-08 12:39:55 +00:00
|
|
|
m_shader.reset();
|
2010-06-02 20:04:54 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-06-02 20:04:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
void LanczosFilter::updateOffscreenSurfaces()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-06-02 20:04:54 +00:00
|
|
|
int w = displayWidth();
|
|
|
|
int h = displayHeight();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!GLTexture::NPOTTextureSupported()) {
|
|
|
|
w = nearestPowerOfTwo(w);
|
|
|
|
h = nearestPowerOfTwo(h);
|
|
|
|
}
|
|
|
|
if (!m_offscreenTex || m_offscreenTex->width() != w || m_offscreenTex->height() != h) {
|
|
|
|
if (m_offscreenTex) {
|
2010-06-02 20:04:54 +00:00
|
|
|
delete m_offscreenTex;
|
|
|
|
delete m_offscreenTarget;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
m_offscreenTex = new GLTexture(w, h);
|
|
|
|
m_offscreenTex->setFilter(GL_LINEAR);
|
|
|
|
m_offscreenTex->setWrapMode(GL_CLAMP_TO_EDGE);
|
2011-07-17 15:57:30 +00:00
|
|
|
m_offscreenTarget = new GLRenderTarget(*m_offscreenTex);
|
2010-06-02 20:04:54 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-06-02 20:04:54 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static float sinc(float x)
|
|
|
|
{
|
|
|
|
return std::sin(x * M_PI) / (x * M_PI);
|
|
|
|
}
|
2010-06-02 20:04:54 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
static float lanczos(float x, float a)
|
|
|
|
{
|
|
|
|
if (qFuzzyCompare(x + 1.0, 1.0))
|
2010-06-02 20:04:54 +00:00
|
|
|
return 1.0;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (qAbs(x) >= a)
|
2010-06-02 20:04:54 +00:00
|
|
|
return 0.0;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
return sinc(x) * sinc(x / a);
|
|
|
|
}
|
2010-06-02 20:04:54 +00:00
|
|
|
|
2013-02-08 12:39:55 +00:00
|
|
|
void LanczosFilter::createKernel(float delta, int *size)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2010-06-02 20:04:54 +00:00
|
|
|
const float a = 2.0;
|
|
|
|
|
|
|
|
// The two outermost samples always fall at points where the lanczos
|
|
|
|
// function returns 0, so we'll skip them.
|
2011-01-30 14:34:42 +00:00
|
|
|
const int sampleCount = qBound(3, qCeil(delta * a) * 2 + 1 - 2, 29);
|
2010-06-02 20:04:54 +00:00
|
|
|
const int center = sampleCount / 2;
|
|
|
|
const int kernelSize = center + 1;
|
|
|
|
const float factor = 1.0 / delta;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QVector<float> values(kernelSize);
|
2010-06-02 20:04:54 +00:00
|
|
|
float sum = 0;
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0; i < kernelSize; i++) {
|
|
|
|
const float val = lanczos(i * factor, a);
|
2010-06-02 20:04:54 +00:00
|
|
|
sum += i > 0 ? val * 2 : val;
|
|
|
|
values[i] = val;
|
|
|
|
}
|
|
|
|
|
2011-01-18 22:43:08 +00:00
|
|
|
memset(m_kernel, 0, 16 * sizeof(QVector4D));
|
2010-09-13 22:03:21 +00:00
|
|
|
|
2010-06-02 20:04:54 +00:00
|
|
|
// Normalize the kernel
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0; i < kernelSize; i++) {
|
2010-06-02 20:04:54 +00:00
|
|
|
const float val = values[i] / sum;
|
2011-01-30 14:34:42 +00:00
|
|
|
m_kernel[i] = QVector4D(val, val, val, val);
|
2010-06-02 20:04:54 +00:00
|
|
|
}
|
|
|
|
|
2010-09-13 22:03:21 +00:00
|
|
|
*size = kernelSize;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-06-02 20:04:54 +00:00
|
|
|
|
2013-02-08 12:39:55 +00:00
|
|
|
void LanczosFilter::createOffsets(int count, float width, Qt::Orientation direction)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-01-18 22:43:08 +00:00
|
|
|
memset(m_offsets, 0, 16 * sizeof(QVector2D));
|
2011-01-30 14:34:42 +00:00
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
m_offsets[i] = (direction == Qt::Horizontal) ?
|
|
|
|
QVector2D(i / width, 0) : QVector2D(0, i / width);
|
2010-06-02 20:04:54 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-06-02 20:04:54 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void LanczosFilter::performPaint(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
2013-09-06 07:47:12 +00:00
|
|
|
if (data.xScale() < 0.9 || data.yScale() < 0.9) {
|
2010-06-02 20:04:54 +00:00
|
|
|
if (!m_inited)
|
|
|
|
init();
|
2011-01-30 14:34:42 +00:00
|
|
|
const QRect screenRect = Workspace::self()->clientArea(ScreenArea, w->screen(), w->desktop());
|
2010-08-29 11:27:57 +00:00
|
|
|
// window geometry may not be bigger than screen geometry to fit into the FBO
|
2013-07-07 11:57:00 +00:00
|
|
|
QRect winGeo(w->expandedGeometry());
|
|
|
|
if (m_shader && winGeo.width() <= screenRect.width() && winGeo.height() <= screenRect.height()) {
|
|
|
|
winGeo.translate(-w->geometry().topLeft());
|
|
|
|
double left = winGeo.left();
|
|
|
|
double top = winGeo.top();
|
|
|
|
double width = winGeo.right() - left;
|
|
|
|
double height = winGeo.bottom() - top;
|
|
|
|
|
2012-05-28 12:45:46 +00:00
|
|
|
int tx = data.xTranslation() + w->x() + left * data.xScale();
|
|
|
|
int ty = data.yTranslation() + w->y() + top * data.yScale();
|
2012-05-28 10:00:31 +00:00
|
|
|
int tw = width * data.xScale();
|
|
|
|
int th = height * data.yScale();
|
2010-11-01 10:46:11 +00:00
|
|
|
const QRect textureRect(tx, ty, tw, th);
|
2012-03-24 11:44:35 +00:00
|
|
|
const bool hardwareClipping = !(QRegion(textureRect)-region).isEmpty();
|
2010-08-08 09:59:03 +00:00
|
|
|
|
|
|
|
int sw = width;
|
|
|
|
int sh = height;
|
2011-02-12 00:36:21 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
GLTexture *cachedTexture = static_cast< GLTexture*>(w->data(LanczosCacheRole).value<void*>());
|
|
|
|
if (cachedTexture) {
|
|
|
|
if (cachedTexture->width() == tw && cachedTexture->height() == th) {
|
2010-11-01 10:46:11 +00:00
|
|
|
cachedTexture->bind();
|
2012-03-24 11:44:35 +00:00
|
|
|
if (hardwareClipping) {
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
}
|
2013-03-21 16:13:34 +00:00
|
|
|
|
2013-02-08 12:39:55 +00:00
|
|
|
glEnable(GL_BLEND);
|
2013-03-21 16:13:34 +00:00
|
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
2013-02-08 12:39:55 +00:00
|
|
|
|
|
|
|
const qreal rgb = data.brightness() * data.opacity();
|
|
|
|
const qreal a = data.opacity();
|
|
|
|
|
|
|
|
ShaderBinder binder(ShaderManager::SimpleShader);
|
|
|
|
GLShader *shader = binder.shader();
|
|
|
|
shader->setUniform(GLShader::Offset, QVector2D(0, 0));
|
|
|
|
shader->setUniform(GLShader::ModulationConstant, QVector4D(rgb, rgb, rgb, a));
|
|
|
|
shader->setUniform(GLShader::Saturation, data.saturation());
|
|
|
|
|
|
|
|
cachedTexture->render(region, textureRect, hardwareClipping);
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
2012-03-24 11:44:35 +00:00
|
|
|
if (hardwareClipping) {
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
}
|
2010-11-01 10:46:11 +00:00
|
|
|
cachedTexture->unbind();
|
2011-01-30 14:34:42 +00:00
|
|
|
m_timer.start(5000, this);
|
2010-11-01 10:46:11 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2010-11-01 10:46:11 +00:00
|
|
|
// offscreen texture not matching - delete
|
|
|
|
delete cachedTexture;
|
|
|
|
cachedTexture = 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
w->setData(LanczosCacheRole, QVariant());
|
2010-11-01 10:46:11 +00:00
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-06-02 20:04:54 +00:00
|
|
|
|
|
|
|
WindowPaintData thumbData = data;
|
2012-05-28 10:00:31 +00:00
|
|
|
thumbData.setXScale(1.0);
|
|
|
|
thumbData.setYScale(1.0);
|
2012-05-28 12:45:46 +00:00
|
|
|
thumbData.setXTranslation(-w->x() - left);
|
|
|
|
thumbData.setYTranslation(-w->y() - top);
|
2012-07-12 15:20:17 +00:00
|
|
|
thumbData.setBrightness(1.0);
|
|
|
|
thumbData.setOpacity(1.0);
|
|
|
|
thumbData.setSaturation(1.0);
|
2010-06-02 20:04:54 +00:00
|
|
|
|
|
|
|
// Bind the offscreen FBO and draw the window on it unscaled
|
|
|
|
updateOffscreenSurfaces();
|
2011-03-13 13:34:30 +00:00
|
|
|
GLRenderTarget::pushRenderTarget(m_offscreenTarget);
|
2010-06-02 20:04:54 +00:00
|
|
|
|
2011-01-02 20:28:07 +00:00
|
|
|
glClearColor(0.0, 0.0, 0.0, 0.0);
|
2011-01-30 14:34:42 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
w->sceneWindow()->performPaint(mask, infiniteRegion(), thumbData);
|
2010-06-02 20:04:54 +00:00
|
|
|
|
|
|
|
// Create a scratch texture and copy the rendered window into it
|
2011-01-30 14:34:42 +00:00
|
|
|
GLTexture tex(sw, sh);
|
|
|
|
tex.setFilter(GL_LINEAR);
|
|
|
|
tex.setWrapMode(GL_CLAMP_TO_EDGE);
|
2010-06-02 20:04:54 +00:00
|
|
|
tex.bind();
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, m_offscreenTex->height() - sh, sw, sh);
|
2010-06-02 20:04:54 +00:00
|
|
|
|
|
|
|
// Set up the shader for horizontal scaling
|
|
|
|
float dx = sw / float(tw);
|
2010-09-13 22:03:21 +00:00
|
|
|
int kernelSize;
|
2013-02-08 12:39:55 +00:00
|
|
|
createKernel(dx, &kernelSize);
|
|
|
|
createOffsets(kernelSize, sw, Qt::Horizontal);
|
2010-06-02 20:04:54 +00:00
|
|
|
|
2013-02-08 12:39:55 +00:00
|
|
|
ShaderManager::instance()->pushShader(m_shader.data());
|
|
|
|
setUniforms();
|
2010-06-02 20:04:54 +00:00
|
|
|
|
|
|
|
// Draw the window back into the FBO, this time scaled horizontally
|
2011-01-30 14:34:42 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2011-01-02 20:28:07 +00:00
|
|
|
QVector<float> verts;
|
|
|
|
QVector<float> texCoords;
|
|
|
|
verts.reserve(12);
|
|
|
|
texCoords.reserve(12);
|
|
|
|
|
|
|
|
texCoords << 1.0 << 0.0; verts << tw << 0.0; // Top right
|
|
|
|
texCoords << 0.0 << 0.0; verts << 0.0 << 0.0; // Top left
|
|
|
|
texCoords << 0.0 << 1.0; verts << 0.0 << sh; // Bottom left
|
|
|
|
texCoords << 0.0 << 1.0; verts << 0.0 << sh; // Bottom left
|
|
|
|
texCoords << 1.0 << 1.0; verts << tw << sh; // Bottom right
|
|
|
|
texCoords << 1.0 << 0.0; verts << tw << 0.0; // Top right
|
|
|
|
GLVertexBuffer *vbo = GLVertexBuffer::streamingBuffer();
|
|
|
|
vbo->reset();
|
|
|
|
vbo->setData(6, 2, verts.constData(), texCoords.constData());
|
|
|
|
vbo->render(GL_TRIANGLES);
|
2010-06-02 20:04:54 +00:00
|
|
|
|
|
|
|
// At this point we don't need the scratch texture anymore
|
|
|
|
tex.unbind();
|
|
|
|
tex.discard();
|
|
|
|
|
2010-11-01 10:46:11 +00:00
|
|
|
// create scratch texture for second rendering pass
|
2011-01-30 14:34:42 +00:00
|
|
|
GLTexture tex2(tw, sh);
|
|
|
|
tex2.setFilter(GL_LINEAR);
|
|
|
|
tex2.setWrapMode(GL_CLAMP_TO_EDGE);
|
2010-11-01 10:46:11 +00:00
|
|
|
tex2.bind();
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, m_offscreenTex->height() - sh, tw, sh);
|
2010-06-02 20:04:54 +00:00
|
|
|
|
|
|
|
// Set up the shader for vertical scaling
|
|
|
|
float dy = sh / float(th);
|
2013-02-08 12:39:55 +00:00
|
|
|
createKernel(dy, &kernelSize);
|
|
|
|
createOffsets(kernelSize, m_offscreenTex->height(), Qt::Vertical);
|
|
|
|
setUniforms();
|
2010-06-02 20:04:54 +00:00
|
|
|
|
|
|
|
// Now draw the horizontally scaled window in the FBO at the right
|
|
|
|
// coordinates on the screen, while scaling it vertically and blending it.
|
2011-01-30 14:34:42 +00:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2010-06-02 20:04:54 +00:00
|
|
|
|
2011-01-02 20:28:07 +00:00
|
|
|
verts.clear();
|
|
|
|
|
|
|
|
verts << tw << 0.0; // Top right
|
|
|
|
verts << 0.0 << 0.0; // Top left
|
|
|
|
verts << 0.0 << th; // Bottom left
|
|
|
|
verts << 0.0 << th; // Bottom left
|
|
|
|
verts << tw << th; // Bottom right
|
|
|
|
verts << tw << 0.0; // Top right
|
|
|
|
vbo->setData(6, 2, verts.constData(), texCoords.constData());
|
|
|
|
vbo->render(GL_TRIANGLES);
|
2010-06-02 20:04:54 +00:00
|
|
|
|
2010-11-01 10:46:11 +00:00
|
|
|
tex2.unbind();
|
|
|
|
tex2.discard();
|
2013-02-08 12:39:55 +00:00
|
|
|
ShaderManager::instance()->popShader();
|
2010-06-02 20:04:54 +00:00
|
|
|
|
2010-11-01 10:46:11 +00:00
|
|
|
// create cache texture
|
2011-01-30 14:34:42 +00:00
|
|
|
GLTexture *cache = new GLTexture(tw, th);
|
2010-11-01 10:46:11 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
cache->setFilter(GL_LINEAR);
|
|
|
|
cache->setWrapMode(GL_CLAMP_TO_EDGE);
|
2010-11-01 10:46:11 +00:00
|
|
|
cache->bind();
|
2011-01-30 14:34:42 +00:00
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, m_offscreenTex->height() - th, tw, th);
|
2011-03-13 13:34:30 +00:00
|
|
|
GLRenderTarget::popRenderTarget();
|
2011-02-12 00:36:21 +00:00
|
|
|
|
2012-03-24 11:44:35 +00:00
|
|
|
if (hardwareClipping) {
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
}
|
2013-03-21 16:13:34 +00:00
|
|
|
|
2013-02-08 12:39:55 +00:00
|
|
|
glEnable(GL_BLEND);
|
2013-03-21 16:13:34 +00:00
|
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
2013-02-08 12:39:55 +00:00
|
|
|
|
|
|
|
const qreal rgb = data.brightness() * data.opacity();
|
|
|
|
const qreal a = data.opacity();
|
|
|
|
|
|
|
|
ShaderBinder binder(ShaderManager::SimpleShader);
|
|
|
|
GLShader *shader = binder.shader();
|
|
|
|
shader->setUniform(GLShader::Offset, QVector2D(0, 0));
|
|
|
|
shader->setUniform(GLShader::ModulationConstant, QVector4D(rgb, rgb, rgb, a));
|
|
|
|
shader->setUniform(GLShader::Saturation, data.saturation());
|
|
|
|
|
|
|
|
cache->render(region, textureRect, hardwareClipping);
|
|
|
|
|
|
|
|
glDisable(GL_BLEND);
|
2013-03-21 16:13:34 +00:00
|
|
|
|
2012-03-24 11:44:35 +00:00
|
|
|
if (hardwareClipping) {
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
}
|
2011-02-12 00:36:21 +00:00
|
|
|
|
2010-11-01 10:46:11 +00:00
|
|
|
cache->unbind();
|
2011-01-30 14:34:42 +00:00
|
|
|
w->setData(LanczosCacheRole, QVariant::fromValue(static_cast<void*>(cache)));
|
2010-11-01 10:46:11 +00:00
|
|
|
|
2010-06-02 20:04:54 +00:00
|
|
|
// Delete the offscreen surface after 5 seconds
|
2011-01-30 14:34:42 +00:00
|
|
|
m_timer.start(5000, this);
|
2010-06-02 20:04:54 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
} // if ( effects->compositingType() == KWin::OpenGLCompositing )
|
|
|
|
w->sceneWindow()->performPaint(mask, region, data);
|
|
|
|
} // End of function
|
2010-06-02 20:04:54 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void LanczosFilter::timerEvent(QTimerEvent *event)
|
|
|
|
{
|
|
|
|
if (event->timerId() == m_timer.timerId()) {
|
2010-06-02 20:04:54 +00:00
|
|
|
m_timer.stop();
|
|
|
|
|
|
|
|
delete m_offscreenTarget;
|
|
|
|
delete m_offscreenTex;
|
|
|
|
m_offscreenTarget = 0;
|
|
|
|
m_offscreenTex = 0;
|
2013-04-11 07:17:58 +00:00
|
|
|
foreach (Client *c, Workspace::self()->clientList()) {
|
|
|
|
discardCacheTexture(c->effectWindow());
|
|
|
|
}
|
|
|
|
foreach (Client *c, Workspace::self()->desktopList()) {
|
|
|
|
discardCacheTexture(c->effectWindow());
|
|
|
|
}
|
|
|
|
foreach (Unmanaged *u, Workspace::self()->unmanagedList()) {
|
|
|
|
discardCacheTexture(u->effectWindow());
|
|
|
|
}
|
|
|
|
foreach (Deleted *d, Workspace::self()->deletedList()) {
|
|
|
|
discardCacheTexture(d->effectWindow());
|
2010-06-02 20:04:54 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-06-02 20:04:54 +00:00
|
|
|
|
2013-04-11 07:17:58 +00:00
|
|
|
void LanczosFilter::discardCacheTexture(EffectWindow *w)
|
|
|
|
{
|
|
|
|
QVariant cachedTextureVariant = w->data(LanczosCacheRole);
|
|
|
|
if (cachedTextureVariant.isValid()) {
|
|
|
|
delete static_cast< GLTexture*>(cachedTextureVariant.value<void*>());
|
|
|
|
w->setData(LanczosCacheRole, QVariant());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-08 12:39:55 +00:00
|
|
|
void LanczosFilter::setUniforms()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2013-02-08 12:39:55 +00:00
|
|
|
glUniform1i(m_uTexUnit, 0);
|
|
|
|
glUniform2fv(m_uOffsets, 16, (const GLfloat*)m_offsets);
|
|
|
|
glUniform4fv(m_uKernel, 16, (const GLfloat*)m_kernel);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2010-11-10 18:25:40 +00:00
|
|
|
|
2010-06-02 20:04:54 +00:00
|
|
|
} // namespace
|
|
|
|
|