2010-03-05 20:42:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2010 Fredrik Höglund <fredrik@kde.org>
|
|
|
|
*
|
|
|
|
* 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>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
class BlurShader;
|
|
|
|
|
|
|
|
class BlurEffect : public KWin::Effect
|
|
|
|
{
|
2011-02-25 21:06:02 +00:00
|
|
|
Q_OBJECT
|
2012-08-11 09:24:37 +00:00
|
|
|
Q_PROPERTY(int blurRadius READ blurRadius)
|
|
|
|
Q_PROPERTY(bool cacheTexture READ isCacheTexture)
|
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
|
|
|
|
2012-08-11 09:24:37 +00:00
|
|
|
// for dynamic setting extraction
|
|
|
|
int blurRadius() const;
|
|
|
|
bool isCacheTexture() const {
|
|
|
|
return m_shouldCache;
|
|
|
|
}
|
2013-01-16 13:50:43 +00:00
|
|
|
virtual bool provides(Feature feature);
|
2012-08-11 09:24:37 +00:00
|
|
|
|
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;
|
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;
|
2010-03-12 18:29:16 +00:00
|
|
|
void drawRegion(const QRegion ®ion);
|
2010-07-24 20:48:19 +00:00
|
|
|
void doBlur(const QRegion &shape, const QRect &screen, const float opacity);
|
2011-07-17 15:57:30 +00:00
|
|
|
void doCachedBlur(EffectWindow *w, const QRegion& region, const float opacity);
|
2010-03-05 20:42:10 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
BlurShader *shader;
|
|
|
|
QVector<QVector2D> vertices;
|
|
|
|
GLRenderTarget *target;
|
2011-07-17 15:57:30 +00:00
|
|
|
GLTexture tex;
|
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
|
2011-10-12 14:02:19 +00:00
|
|
|
QRegion m_currentBlur; // keeps track of the currently blured area of non-caching windows(from bottom to top)
|
2011-07-17 15:57:30 +00:00
|
|
|
bool m_shouldCache;
|
|
|
|
|
|
|
|
struct BlurWindowInfo {
|
|
|
|
GLTexture blurredBackground; // keeps the horizontally blurred background
|
2011-09-18 15:53:14 +00:00
|
|
|
QRegion damagedRegion;
|
2012-02-07 16:01:41 +00:00
|
|
|
QPoint windowPos;
|
2011-12-10 16:31:18 +00:00
|
|
|
bool dropCache;
|
2011-07-17 15:57:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
QHash< const EffectWindow*, BlurWindowInfo > windows;
|
2012-02-18 21:07:39 +00:00
|
|
|
typedef QHash<const EffectWindow*, BlurWindowInfo>::iterator CacheEntry;
|
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
|
|
|
|
|