2010-06-03 00:04:54 +04: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 16:17:53 +04:00
|
|
|
Copyright (C) 2010 Martin Gräßlin <mgraesslin@kde.org>
|
2010-06-03 00:04:54 +04: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 11:17:58 +04:00
|
|
|
#include "client.h"
|
|
|
|
#include "deleted.h"
|
2010-06-03 00:04:54 +04:00
|
|
|
#include "effects.h"
|
2013-04-11 11:17:58 +04:00
|
|
|
#include "unmanaged.h"
|
2012-03-16 11:43:52 +04:00
|
|
|
#include "options.h"
|
2013-04-26 13:52:15 +04:00
|
|
|
#include "workspace.h"
|
2010-06-03 00:04:54 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
#include <kwinglutils.h>
|
|
|
|
#include <kwinglplatform.h>
|
2010-06-03 00:04:54 +04:00
|
|
|
|
|
|
|
#include <kwineffects.h>
|
|
|
|
#include <KDE/KGlobalSettings>
|
|
|
|
|
|
|
|
#include <qmath.h>
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
LanczosFilter::LanczosFilter(QObject* parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_offscreenTex(0)
|
|
|
|
, m_offscreenTarget(0)
|
|
|
|
, m_inited(false)
|
2013-02-08 16:39:55 +04:00
|
|
|
, m_shader(0)
|
|
|
|
, m_uTexUnit(0)
|
|
|
|
, m_uOffsets(0)
|
|
|
|
, m_uKernel(0)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
}
|
2010-06-03 00:04:54 +04:00
|
|
|
|
|
|
|
LanczosFilter::~LanczosFilter()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2010-06-03 00:04:54 +04:00
|
|
|
delete m_offscreenTarget;
|
|
|
|
delete m_offscreenTex;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2010-06-03 00:04:54 +04:00
|
|
|
|
|
|
|
void LanczosFilter::init()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2010-06-03 00:04:54 +04:00
|
|
|
if (m_inited)
|
|
|
|
return;
|
|
|
|
m_inited = true;
|
2011-07-21 00:41:58 +04:00
|
|
|
const bool force = (qstrcmp(qgetenv("KWIN_FORCE_LANCZOS"), "1") == 0);
|
|
|
|
if (force) {
|
|
|
|
kWarning(1212) << "Lanczos Filter forced on by environment variable";
|
|
|
|
}
|
2010-11-11 22:53:19 +03:00
|
|
|
|
2012-03-16 11:43:52 +04:00
|
|
|
if (!force && options->glSmoothScale() != 2)
|
2010-11-11 22:53:19 +03:00
|
|
|
return; // disabled by config
|
2013-04-11 11:01:01 +04:00
|
|
|
if (!GLRenderTarget::supported())
|
2013-02-08 16:39:55 +04:00
|
|
|
return;
|
2010-11-11 22:53:19 +03:00
|
|
|
|
2011-01-19 01:36:58 +03:00
|
|
|
GLPlatform *gl = GLPlatform::instance();
|
2013-02-08 16:39:55 +04: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;
|
|
|
|
// Broken on IvyBridge with Mesa 9.1 - BUG 313613
|
|
|
|
if (gl->driver() == Driver_Intel && gl->chipClass() == IvyBridge && gl->mesaVersion() >= kVersionNumber(9, 1))
|
|
|
|
return;
|
|
|
|
// also radeon before R600 has trouble
|
|
|
|
if (gl->isRadeon() && gl->chipClass() < R600)
|
|
|
|
return;
|
2011-12-31 11:54:15 +04:00
|
|
|
}
|
2013-02-08 16:39:55 +04:00
|
|
|
m_shader.reset(ShaderManager::instance()->loadFragmentShader(ShaderManager::SimpleShader, ":/resources/lanczos-fragment.glsl"));
|
|
|
|
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 {
|
|
|
|
kDebug(1212) << "Shader is not valid";
|
|
|
|
m_shader.reset();
|
2010-06-03 00:04:54 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2010-06-03 00:04:54 +04:00
|
|
|
|
|
|
|
|
|
|
|
void LanczosFilter::updateOffscreenSurfaces()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2010-06-03 00:04:54 +04:00
|
|
|
int w = displayWidth();
|
|
|
|
int h = displayHeight();
|
2011-01-30 17:34:42 +03: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-03 00:04:54 +04:00
|
|
|
delete m_offscreenTex;
|
|
|
|
delete m_offscreenTarget;
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
m_offscreenTex = new GLTexture(w, h);
|
|
|
|
m_offscreenTex->setFilter(GL_LINEAR);
|
|
|
|
m_offscreenTex->setWrapMode(GL_CLAMP_TO_EDGE);
|
2011-07-17 19:57:30 +04:00
|
|
|
m_offscreenTarget = new GLRenderTarget(*m_offscreenTex);
|
2010-06-03 00:04:54 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2010-06-03 00:04:54 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
static float sinc(float x)
|
|
|
|
{
|
|
|
|
return std::sin(x * M_PI) / (x * M_PI);
|
|
|
|
}
|
2010-06-03 00:04:54 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
static float lanczos(float x, float a)
|
|
|
|
{
|
|
|
|
if (qFuzzyCompare(x + 1.0, 1.0))
|
2010-06-03 00:04:54 +04:00
|
|
|
return 1.0;
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
if (qAbs(x) >= a)
|
2010-06-03 00:04:54 +04:00
|
|
|
return 0.0;
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
return sinc(x) * sinc(x / a);
|
|
|
|
}
|
2010-06-03 00:04:54 +04:00
|
|
|
|
2013-02-08 16:39:55 +04:00
|
|
|
void LanczosFilter::createKernel(float delta, int *size)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2010-06-03 00:04:54 +04: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 17:34:42 +03:00
|
|
|
const int sampleCount = qBound(3, qCeil(delta * a) * 2 + 1 - 2, 29);
|
2010-06-03 00:04:54 +04:00
|
|
|
const int center = sampleCount / 2;
|
|
|
|
const int kernelSize = center + 1;
|
|
|
|
const float factor = 1.0 / delta;
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
QVector<float> values(kernelSize);
|
2010-06-03 00:04:54 +04:00
|
|
|
float sum = 0;
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
for (int i = 0; i < kernelSize; i++) {
|
|
|
|
const float val = lanczos(i * factor, a);
|
2010-06-03 00:04:54 +04:00
|
|
|
sum += i > 0 ? val * 2 : val;
|
|
|
|
values[i] = val;
|
|
|
|
}
|
|
|
|
|
2011-01-19 01:43:08 +03:00
|
|
|
memset(m_kernel, 0, 16 * sizeof(QVector4D));
|
2010-09-14 02:03:21 +04:00
|
|
|
|
2010-06-03 00:04:54 +04:00
|
|
|
// Normalize the kernel
|
2011-01-30 17:34:42 +03:00
|
|
|
for (int i = 0; i < kernelSize; i++) {
|
2010-06-03 00:04:54 +04:00
|
|
|
const float val = values[i] / sum;
|
2011-01-30 17:34:42 +03:00
|
|
|
m_kernel[i] = QVector4D(val, val, val, val);
|
2010-06-03 00:04:54 +04:00
|
|
|
}
|
|
|
|
|
2010-09-14 02:03:21 +04:00
|
|
|
*size = kernelSize;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2010-06-03 00:04:54 +04:00
|
|
|
|
2013-02-08 16:39:55 +04:00
|
|
|
void LanczosFilter::createOffsets(int count, float width, Qt::Orientation direction)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2011-01-19 01:43:08 +03:00
|
|
|
memset(m_offsets, 0, 16 * sizeof(QVector2D));
|
2011-01-30 17:34:42 +03:00
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
m_offsets[i] = (direction == Qt::Horizontal) ?
|
|
|
|
QVector2D(i / width, 0) : QVector2D(0, i / width);
|
2010-06-03 00:04:54 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2010-06-03 00:04:54 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void LanczosFilter::performPaint(EffectWindowImpl* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
2013-04-11 11:01:01 +04:00
|
|
|
if ((data.xScale() < 0.9 || data.yScale() < 0.9) &&
|
2011-01-30 17:34:42 +03:00
|
|
|
KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects) {
|
2010-06-03 00:04:54 +04:00
|
|
|
if (!m_inited)
|
|
|
|
init();
|
2011-01-30 17:34:42 +03:00
|
|
|
const QRect screenRect = Workspace::self()->clientArea(ScreenArea, w->screen(), w->desktop());
|
2010-08-29 15:27:57 +04:00
|
|
|
// window geometry may not be bigger than screen geometry to fit into the FBO
|
2011-01-30 17:34:42 +03:00
|
|
|
if (m_shader && w->width() <= screenRect.width() && w->height() <= screenRect.height()) {
|
2010-08-08 13:59:03 +04:00
|
|
|
double left = 0;
|
|
|
|
double top = 0;
|
|
|
|
double right = w->width();
|
|
|
|
double bottom = w->height();
|
2011-01-30 17:34:42 +03:00
|
|
|
foreach (const WindowQuad & quad, data.quads) {
|
2010-08-08 13:59:03 +04:00
|
|
|
// we need this loop to include the decoration padding
|
|
|
|
left = qMin(left, quad.left());
|
|
|
|
top = qMin(top, quad.top());
|
|
|
|
right = qMax(right, quad.right());
|
|
|
|
bottom = qMax(bottom, quad.bottom());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2010-08-08 13:59:03 +04:00
|
|
|
double width = right - left;
|
|
|
|
double height = bottom - top;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (width > screenRect.width() || height > screenRect.height()) {
|
2010-08-29 15:27:57 +04:00
|
|
|
// window with padding does not fit into the framebuffer
|
|
|
|
// so cut of the shadow
|
|
|
|
left = 0;
|
|
|
|
top = 0;
|
|
|
|
width = w->width();
|
|
|
|
height = w->height();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2012-05-28 16:45:46 +04:00
|
|
|
int tx = data.xTranslation() + w->x() + left * data.xScale();
|
|
|
|
int ty = data.yTranslation() + w->y() + top * data.yScale();
|
2012-05-28 14:00:31 +04:00
|
|
|
int tw = width * data.xScale();
|
|
|
|
int th = height * data.yScale();
|
2010-11-01 13:46:11 +03:00
|
|
|
const QRect textureRect(tx, ty, tw, th);
|
2012-03-24 15:44:35 +04:00
|
|
|
const bool hardwareClipping = !(QRegion(textureRect)-region).isEmpty();
|
2010-08-08 13:59:03 +04:00
|
|
|
|
|
|
|
int sw = width;
|
|
|
|
int sh = height;
|
2011-02-12 03:36:21 +03:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
GLTexture *cachedTexture = static_cast< GLTexture*>(w->data(LanczosCacheRole).value<void*>());
|
|
|
|
if (cachedTexture) {
|
|
|
|
if (cachedTexture->width() == tw && cachedTexture->height() == th) {
|
2010-11-01 13:46:11 +03:00
|
|
|
cachedTexture->bind();
|
2012-03-24 15:44:35 +04:00
|
|
|
if (hardwareClipping) {
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
}
|
2013-03-21 20:13:34 +04:00
|
|
|
|
2013-02-08 16:39:55 +04:00
|
|
|
glEnable(GL_BLEND);
|
2013-03-21 20:13:34 +04:00
|
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
2013-02-08 16:39:55 +04: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 15:44:35 +04:00
|
|
|
if (hardwareClipping) {
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
}
|
2010-11-01 13:46:11 +03:00
|
|
|
cachedTexture->unbind();
|
2011-01-30 17:34:42 +03:00
|
|
|
m_timer.start(5000, this);
|
2010-11-01 13:46:11 +03:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
} else {
|
2010-11-01 13:46:11 +03:00
|
|
|
// offscreen texture not matching - delete
|
|
|
|
delete cachedTexture;
|
|
|
|
cachedTexture = 0;
|
2011-01-30 17:34:42 +03:00
|
|
|
w->setData(LanczosCacheRole, QVariant());
|
2010-11-01 13:46:11 +03:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2010-06-03 00:04:54 +04:00
|
|
|
|
|
|
|
WindowPaintData thumbData = data;
|
2012-05-28 14:00:31 +04:00
|
|
|
thumbData.setXScale(1.0);
|
|
|
|
thumbData.setYScale(1.0);
|
2012-05-28 16:45:46 +04:00
|
|
|
thumbData.setXTranslation(-w->x() - left);
|
|
|
|
thumbData.setYTranslation(-w->y() - top);
|
2012-07-12 19:20:17 +04:00
|
|
|
thumbData.setBrightness(1.0);
|
|
|
|
thumbData.setOpacity(1.0);
|
|
|
|
thumbData.setSaturation(1.0);
|
2010-06-03 00:04:54 +04:00
|
|
|
|
|
|
|
// Bind the offscreen FBO and draw the window on it unscaled
|
|
|
|
updateOffscreenSurfaces();
|
2011-03-13 16:34:30 +03:00
|
|
|
GLRenderTarget::pushRenderTarget(m_offscreenTarget);
|
2010-06-03 00:04:54 +04:00
|
|
|
|
2011-01-02 23:28:07 +03:00
|
|
|
glClearColor(0.0, 0.0, 0.0, 0.0);
|
2011-01-30 17:34:42 +03:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
w->sceneWindow()->performPaint(mask, infiniteRegion(), thumbData);
|
2010-06-03 00:04:54 +04:00
|
|
|
|
|
|
|
// Create a scratch texture and copy the rendered window into it
|
2011-01-30 17:34:42 +03:00
|
|
|
GLTexture tex(sw, sh);
|
|
|
|
tex.setFilter(GL_LINEAR);
|
|
|
|
tex.setWrapMode(GL_CLAMP_TO_EDGE);
|
2010-06-03 00:04:54 +04:00
|
|
|
tex.bind();
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, m_offscreenTex->height() - sh, sw, sh);
|
2010-06-03 00:04:54 +04:00
|
|
|
|
|
|
|
// Set up the shader for horizontal scaling
|
|
|
|
float dx = sw / float(tw);
|
2010-09-14 02:03:21 +04:00
|
|
|
int kernelSize;
|
2013-02-08 16:39:55 +04:00
|
|
|
createKernel(dx, &kernelSize);
|
|
|
|
createOffsets(kernelSize, sw, Qt::Horizontal);
|
2010-06-03 00:04:54 +04:00
|
|
|
|
2013-02-08 16:39:55 +04:00
|
|
|
ShaderManager::instance()->pushShader(m_shader.data());
|
|
|
|
setUniforms();
|
2010-06-03 00:04:54 +04:00
|
|
|
|
|
|
|
// Draw the window back into the FBO, this time scaled horizontally
|
2011-01-30 17:34:42 +03:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2011-01-02 23:28:07 +03: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-03 00:04:54 +04:00
|
|
|
|
|
|
|
// At this point we don't need the scratch texture anymore
|
|
|
|
tex.unbind();
|
|
|
|
tex.discard();
|
|
|
|
|
2010-11-01 13:46:11 +03:00
|
|
|
// create scratch texture for second rendering pass
|
2011-01-30 17:34:42 +03:00
|
|
|
GLTexture tex2(tw, sh);
|
|
|
|
tex2.setFilter(GL_LINEAR);
|
|
|
|
tex2.setWrapMode(GL_CLAMP_TO_EDGE);
|
2010-11-01 13:46:11 +03:00
|
|
|
tex2.bind();
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, m_offscreenTex->height() - sh, tw, sh);
|
2010-06-03 00:04:54 +04:00
|
|
|
|
|
|
|
// Set up the shader for vertical scaling
|
|
|
|
float dy = sh / float(th);
|
2013-02-08 16:39:55 +04:00
|
|
|
createKernel(dy, &kernelSize);
|
|
|
|
createOffsets(kernelSize, m_offscreenTex->height(), Qt::Vertical);
|
|
|
|
setUniforms();
|
2010-06-03 00:04:54 +04: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 17:34:42 +03:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2010-06-03 00:04:54 +04:00
|
|
|
|
2011-01-02 23:28:07 +03: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-03 00:04:54 +04:00
|
|
|
|
2010-11-01 13:46:11 +03:00
|
|
|
tex2.unbind();
|
|
|
|
tex2.discard();
|
2013-02-08 16:39:55 +04:00
|
|
|
ShaderManager::instance()->popShader();
|
2010-06-03 00:04:54 +04:00
|
|
|
|
2010-11-01 13:46:11 +03:00
|
|
|
// create cache texture
|
2011-01-30 17:34:42 +03:00
|
|
|
GLTexture *cache = new GLTexture(tw, th);
|
2010-11-01 13:46:11 +03:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
cache->setFilter(GL_LINEAR);
|
|
|
|
cache->setWrapMode(GL_CLAMP_TO_EDGE);
|
2010-11-01 13:46:11 +03:00
|
|
|
cache->bind();
|
2011-01-30 17:34:42 +03:00
|
|
|
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, m_offscreenTex->height() - th, tw, th);
|
2011-03-13 16:34:30 +03:00
|
|
|
GLRenderTarget::popRenderTarget();
|
2011-02-12 03:36:21 +03:00
|
|
|
|
2012-03-24 15:44:35 +04:00
|
|
|
if (hardwareClipping) {
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
}
|
2013-03-21 20:13:34 +04:00
|
|
|
|
2013-02-08 16:39:55 +04:00
|
|
|
glEnable(GL_BLEND);
|
2013-03-21 20:13:34 +04:00
|
|
|
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
2013-02-08 16:39:55 +04: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 20:13:34 +04:00
|
|
|
|
2012-03-24 15:44:35 +04:00
|
|
|
if (hardwareClipping) {
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
}
|
2011-02-12 03:36:21 +03:00
|
|
|
|
2010-11-01 13:46:11 +03:00
|
|
|
cache->unbind();
|
2011-01-30 17:34:42 +03:00
|
|
|
w->setData(LanczosCacheRole, QVariant::fromValue(static_cast<void*>(cache)));
|
2010-11-01 13:46:11 +03:00
|
|
|
|
2010-06-03 00:04:54 +04:00
|
|
|
// Delete the offscreen surface after 5 seconds
|
2011-01-30 17:34:42 +03:00
|
|
|
m_timer.start(5000, this);
|
2010-06-03 00:04:54 +04:00
|
|
|
return;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
|
|
|
} // if ( effects->compositingType() == KWin::OpenGLCompositing )
|
|
|
|
w->sceneWindow()->performPaint(mask, region, data);
|
|
|
|
} // End of function
|
2010-06-03 00:04:54 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
void LanczosFilter::timerEvent(QTimerEvent *event)
|
|
|
|
{
|
|
|
|
if (event->timerId() == m_timer.timerId()) {
|
2010-06-03 00:04:54 +04:00
|
|
|
m_timer.stop();
|
|
|
|
|
|
|
|
delete m_offscreenTarget;
|
|
|
|
delete m_offscreenTex;
|
|
|
|
m_offscreenTarget = 0;
|
|
|
|
m_offscreenTex = 0;
|
2013-04-11 11:17:58 +04: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-03 00:04:54 +04:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2010-06-03 00:04:54 +04:00
|
|
|
|
2013-04-11 11:17:58 +04: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 16:39:55 +04:00
|
|
|
void LanczosFilter::setUniforms()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2013-02-08 16:39:55 +04:00
|
|
|
glUniform1i(m_uTexUnit, 0);
|
|
|
|
glUniform2fv(m_uOffsets, 16, (const GLfloat*)m_offsets);
|
|
|
|
glUniform4fv(m_uKernel, 16, (const GLfloat*)m_kernel);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2010-11-10 21:25:40 +03:00
|
|
|
|
2010-06-03 00:04:54 +04:00
|
|
|
} // namespace
|
|
|
|
|