Warning, /sdk/licensedigger/autotests/testdata_conversionexamples/blur.h.spdx is written in an unsupported language. File is not indexed.

0001 /*
0002  *   Copyright © 2010 Fredrik Höglund <fredrik@kde.org>
0003  *
0004  *   SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef BLUR_H
0008 #define BLUR_H
0009 
0010 #include <kwineffects.h>
0011 #include <kwinglplatform.h>
0012 #include <kwinglutils.h>
0013 
0014 #include <QVector>
0015 #include <QVector2D>
0016 
0017 namespace KWin
0018 {
0019 
0020 class BlurShader;
0021 
0022 class BlurEffect : public KWin::Effect
0023 {
0024     Q_OBJECT
0025     Q_PROPERTY(int blurRadius READ blurRadius)
0026     Q_PROPERTY(bool cacheTexture READ isCacheTexture)
0027 public:
0028     BlurEffect();
0029     ~BlurEffect();
0030 
0031     static bool supported();
0032     static bool enabledByDefault();
0033 
0034     void reconfigure(ReconfigureFlags flags);
0035     void prePaintScreen(ScreenPrePaintData &data, int time);
0036     void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time);
0037     void drawWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data);
0038     void paintEffectFrame(EffectFrame *frame, QRegion region, double opacity, double frameOpacity);
0039 
0040     // for dynamic setting extraction
0041     int blurRadius() const;
0042     bool isCacheTexture() const {
0043         return m_shouldCache;
0044     }
0045     virtual bool provides(Feature feature);
0046 
0047     int requestedEffectChainPosition() const override {
0048         return 75;
0049     }
0050 
0051 public Q_SLOTS:
0052     void slotWindowAdded(KWin::EffectWindow *w);
0053     void slotWindowDeleted(KWin::EffectWindow *w);
0054     void slotPropertyNotify(KWin::EffectWindow *w, long atom);
0055     void slotScreenGeometryChanged();
0056 
0057 private:
0058     QRect expand(const QRect &rect) const;
0059     QRegion expand(const QRegion &region) const;
0060     QRegion blurRegion(const EffectWindow *w) const;
0061     bool shouldBlur(const EffectWindow *w, int mask, const WindowPaintData &data) const;
0062     void updateBlurRegion(EffectWindow *w) const;
0063     void doBlur(const QRegion &shape, const QRect &screen, const float opacity);
0064     void doCachedBlur(EffectWindow *w, const QRegion& region, const float opacity);
0065     void uploadRegion(QVector2D *&map, const QRegion &region);
0066     void uploadGeometry(GLVertexBuffer *vbo, const QRegion &horizontal, const QRegion &vertical);
0067 
0068 private:
0069     BlurShader *shader;
0070     GLRenderTarget *target;
0071     GLTexture tex;
0072     long net_wm_blur_region;
0073     QRegion m_damagedArea; // keeps track of the area which has been damaged (from bottom to top)
0074     QRegion m_paintedArea; // actually painted area which is greater than m_damagedArea
0075     QRegion m_currentBlur; // keeps track of the currently blured area of non-caching windows(from bottom to top)
0076     bool m_shouldCache;
0077 
0078     struct BlurWindowInfo {
0079         GLTexture blurredBackground; // keeps the horizontally blurred background
0080         QRegion damagedRegion;
0081         QPoint windowPos;
0082         bool dropCache;
0083     };
0084 
0085     QHash< const EffectWindow*, BlurWindowInfo > windows;
0086     typedef QHash<const EffectWindow*, BlurWindowInfo>::iterator CacheEntry;
0087 };
0088 
0089 inline
0090 bool BlurEffect::provides(Effect::Feature feature)
0091 {
0092     if (feature == Blur) {
0093         return true;
0094     }
0095     return KWin::Effect::provides(feature);
0096 }
0097 
0098 
0099 } // namespace KWin
0100 
0101 #endif
0102