2010-03-05 20:42:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2010 Fredrik Höglund <fredrik@kde.org>
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
* Copyright © 2018 Alex Nemeth <alex.nemeth329@gmail.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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BLUR_H
|
2011-01-30 14:34:42 +00:00
|
|
|
#define BLUR_H
|
2010-03-05 20:42:10 +00:00
|
|
|
|
|
|
|
#include <kwineffects.h>
|
2011-05-01 20:52:43 +00:00
|
|
|
#include <kwinglplatform.h>
|
2010-03-05 20:42:10 +00:00
|
|
|
#include <kwinglutils.h>
|
|
|
|
|
|
|
|
#include <QVector>
|
|
|
|
#include <QVector2D>
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
#include <QStack>
|
2010-03-05 20:42:10 +00:00
|
|
|
|
2015-09-29 08:21:24 +00:00
|
|
|
namespace KWayland
|
|
|
|
{
|
|
|
|
namespace Server
|
|
|
|
{
|
|
|
|
class BlurManagerInterface;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-05 20:42:10 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
static const int borderSize = 5;
|
|
|
|
|
2010-03-05 20:42:10 +00:00
|
|
|
class BlurShader;
|
|
|
|
|
|
|
|
class BlurEffect : public KWin::Effect
|
|
|
|
{
|
2011-02-25 21:06:02 +00:00
|
|
|
Q_OBJECT
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
|
2010-03-05 20:42:10 +00:00
|
|
|
public:
|
|
|
|
BlurEffect();
|
|
|
|
~BlurEffect();
|
|
|
|
|
|
|
|
static bool supported();
|
2011-05-01 20:52:43 +00:00
|
|
|
static bool enabledByDefault();
|
2010-03-05 20:42:10 +00:00
|
|
|
|
2010-03-13 15:03:29 +00:00
|
|
|
void reconfigure(ReconfigureFlags flags);
|
2011-05-01 21:17:28 +00:00
|
|
|
void prePaintScreen(ScreenPrePaintData &data, int time);
|
2011-07-09 10:43:32 +00:00
|
|
|
void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time);
|
2010-03-05 20:42:10 +00:00
|
|
|
void drawWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data);
|
2010-07-24 20:48:19 +00:00
|
|
|
void paintEffectFrame(EffectFrame *frame, QRegion region, double opacity, double frameOpacity);
|
2010-03-05 20:42:10 +00:00
|
|
|
|
2013-01-16 13:50:43 +00:00
|
|
|
virtual bool provides(Feature feature);
|
2012-08-11 09:24:37 +00:00
|
|
|
|
2014-03-24 10:50:09 +00:00
|
|
|
int requestedEffectChainPosition() const override {
|
|
|
|
return 75;
|
|
|
|
}
|
|
|
|
|
2011-02-25 21:06:02 +00:00
|
|
|
public Q_SLOTS:
|
2012-01-29 11:29:24 +00:00
|
|
|
void slotWindowAdded(KWin::EffectWindow *w);
|
|
|
|
void slotWindowDeleted(KWin::EffectWindow *w);
|
|
|
|
void slotPropertyNotify(KWin::EffectWindow *w, long atom);
|
2011-11-26 15:15:46 +00:00
|
|
|
void slotScreenGeometryChanged();
|
2011-02-25 21:06:02 +00:00
|
|
|
|
2010-03-05 20:42:10 +00:00
|
|
|
private:
|
|
|
|
QRect expand(const QRect &rect) const;
|
|
|
|
QRegion expand(const QRegion ®ion) const;
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
bool renderTargetsValid() const;
|
|
|
|
void deleteFBOs();
|
|
|
|
void initBlurStrengthValues();
|
|
|
|
void updateTexture();
|
2010-03-06 16:14:25 +00:00
|
|
|
QRegion blurRegion(const EffectWindow *w) const;
|
2011-05-14 16:22:38 +00:00
|
|
|
bool shouldBlur(const EffectWindow *w, int mask, const WindowPaintData &data) const;
|
2010-03-06 16:14:25 +00:00
|
|
|
void updateBlurRegion(EffectWindow *w) const;
|
2016-01-27 13:15:32 +00:00
|
|
|
void doSimpleBlur(EffectWindow *w, const float opacity, const QMatrix4x4 &screenProjection);
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
void doBlur(const QRegion &shape, const QRect &screen, const float opacity, const QMatrix4x4 &screenProjection, bool isDock);
|
|
|
|
void uploadRegion(QVector2D *&map, const QRegion ®ion, const int downSampleIterations);
|
|
|
|
void uploadGeometry(GLVertexBuffer *vbo, const QRegion &blurRegion, const QRegion &windowRegion);
|
|
|
|
|
|
|
|
void downSampleTexture(GLVertexBuffer *vbo, int blurRectCount);
|
|
|
|
void upSampleTexture(GLVertexBuffer *vbo, int blurRectCount);
|
|
|
|
void copyScreenSampleTexture(GLVertexBuffer *vbo, int blurRectCount, QRegion blurShape, QSize screenSize, QMatrix4x4 screenProjection);
|
2010-03-05 20:42:10 +00:00
|
|
|
|
|
|
|
private:
|
2016-01-27 13:15:32 +00:00
|
|
|
GLShader *m_simpleShader;
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
GLRenderTarget *m_simpleTarget;
|
|
|
|
|
|
|
|
BlurShader *m_shader;
|
|
|
|
QVector <GLRenderTarget*> m_renderTargets;
|
|
|
|
QVector <GLTexture> m_renderTextures;
|
|
|
|
QStack <GLRenderTarget*> m_renderTargetStack;
|
|
|
|
bool m_renderTargetsValid;
|
2010-03-06 16:14:25 +00:00
|
|
|
long net_wm_blur_region;
|
2011-07-09 10:43:32 +00:00
|
|
|
QRegion m_damagedArea; // keeps track of the area which has been damaged (from bottom to top)
|
2011-07-17 15:57:30 +00:00
|
|
|
QRegion m_paintedArea; // actually painted area which is greater than m_damagedArea
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
QRegion m_currentBlur; // keeps track of the currently blured area of the windows(from bottom to top)
|
|
|
|
bool m_useSimpleBlur;
|
|
|
|
|
|
|
|
int m_downSampleIterations; // number of times the texture will be downsized to half size
|
|
|
|
int m_offset;
|
|
|
|
int m_expandSize;
|
|
|
|
|
|
|
|
struct OffsetStruct {
|
|
|
|
float minOffset;
|
|
|
|
float maxOffset;
|
|
|
|
int expandSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
QVector <OffsetStruct> blurOffsets;
|
|
|
|
|
|
|
|
struct BlurValuesStruct {
|
|
|
|
int iteration;
|
|
|
|
float offset;
|
2011-07-17 15:57:30 +00:00
|
|
|
};
|
|
|
|
|
Updated the blur method to use the more efficient dual kawase blur algorithm.
Summary:
Updated the old and outdated blur method to use the much more efficient dual kawase blur method.
Now with this we can do virtually infinite blur with very very little performance cost.
The dual kawase blur method is basically downscaling and upscaling an image, but combined with the kawase blur shader.
Comparison: https://i.imgur.com/mh6Cw61.png
Left is old, right is new.
Comparison was done with the strongest blur setting in a VM running on an Intel i7-4790 and a GTX980
We can see here that the performance is even better with this new method.
Reviewers: #plasma, #kwin, graesslin, fredrik
Reviewed By: fredrik
Subscribers: hein, dos, luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D9848
2018-01-25 17:31:11 +00:00
|
|
|
QVector <BlurValuesStruct> blurStrengthValues;
|
|
|
|
|
|
|
|
QMap <EffectWindow*, QMetaObject::Connection> windowBlurChangedConnections;
|
2015-09-29 08:21:24 +00:00
|
|
|
KWayland::Server::BlurManagerInterface *m_blurManager = nullptr;
|
2010-03-05 20:42:10 +00:00
|
|
|
};
|
|
|
|
|
2013-01-16 13:50:43 +00:00
|
|
|
inline
|
|
|
|
bool BlurEffect::provides(Effect::Feature feature)
|
|
|
|
{
|
|
|
|
if (feature == Blur) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return KWin::Effect::provides(feature);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-05 20:42:10 +00:00
|
|
|
} // namespace KWin
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|