Changeset View
Changeset View
Standalone View
Standalone View
effects/blur/blur.h
| 1 | /* | 1 | /* | ||
|---|---|---|---|---|---|
| 2 | * Copyright © 2010 Fredrik Höglund <fredrik@kde.org> | 2 | * Copyright © 2010 Fredrik Höglund <fredrik@kde.org> | ||
| 3 | * Copyright © 2018 Alex Nemeth <alex.nemeth329@gmail.com> | ||||
| 3 | * | 4 | * | ||
| 4 | * This program is free software; you can redistribute it and/or modify | 5 | * This program is free software; you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | 6 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation; either version 2 of the License, or | 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 7 | * (at your option) any later version. | 8 | * (at your option) any later version. | ||
| 8 | * | 9 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | 10 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| Show All 10 Lines | |||||
| 21 | #define BLUR_H | 22 | #define BLUR_H | ||
| 22 | 23 | | |||
| 23 | #include <kwineffects.h> | 24 | #include <kwineffects.h> | ||
| 24 | #include <kwinglplatform.h> | 25 | #include <kwinglplatform.h> | ||
| 25 | #include <kwinglutils.h> | 26 | #include <kwinglutils.h> | ||
| 26 | 27 | | |||
| 27 | #include <QVector> | 28 | #include <QVector> | ||
| 28 | #include <QVector2D> | 29 | #include <QVector2D> | ||
| 30 | #include <QStack> | ||||
romangg: Put this into the cpp. | |||||
anemeth: Why? | |||||
You only need it in the cpp and not in the header, right? Then you should also only include it in the cpp and not in the header. romangg: You only need it in the cpp and not in the header, right? Then you should also only include it… | |||||
| 29 | 31 | | |||
| 30 | namespace KWayland | 32 | namespace KWayland | ||
| 31 | { | 33 | { | ||
| 32 | namespace Server | 34 | namespace Server | ||
| 33 | { | 35 | { | ||
| 34 | class BlurManagerInterface; | 36 | class BlurManagerInterface; | ||
| 35 | } | 37 | } | ||
| 36 | } | 38 | } | ||
| 37 | 39 | | |||
| 38 | namespace KWin | 40 | namespace KWin | ||
| 39 | { | 41 | { | ||
| 40 | 42 | | |||
| 43 | static const int borderSize = 5; | ||||
fredrik: This number could use an explanation. | |||||
I don't know why it's 5 anemeth: I don't know why it's 5
This was in the old blur too: https://github. | |||||
It looks like that was added by Martin in 111db93e05a55496e7f13788207ead008bac80db. fredrik: It looks like that was added by Martin in 111db93e05a55496e7f13788207ead008bac80db. | |||||
| 44 | | ||||
| 41 | class BlurShader; | 45 | class BlurShader; | ||
| 42 | 46 | | |||
| 43 | class BlurEffect : public KWin::Effect | 47 | class BlurEffect : public KWin::Effect | ||
| 44 | { | 48 | { | ||
| 45 | Q_OBJECT | 49 | Q_OBJECT | ||
| 46 | Q_PROPERTY(int blurRadius READ blurRadius) | 50 | | ||
| 47 | Q_PROPERTY(bool cacheTexture READ isCacheTexture) | | |||
| 48 | public: | 51 | public: | ||
| 49 | BlurEffect(); | 52 | BlurEffect(); | ||
| 50 | ~BlurEffect(); | 53 | ~BlurEffect(); | ||
| 51 | 54 | | |||
| 52 | static bool supported(); | 55 | static bool supported(); | ||
| 53 | static bool enabledByDefault(); | 56 | static bool enabledByDefault(); | ||
| 54 | 57 | | |||
| 55 | void reconfigure(ReconfigureFlags flags); | 58 | void reconfigure(ReconfigureFlags flags); | ||
| 56 | void prePaintScreen(ScreenPrePaintData &data, int time); | 59 | void prePaintScreen(ScreenPrePaintData &data, int time); | ||
| 57 | void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time); | 60 | void prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time); | ||
| 58 | void drawWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data); | 61 | void drawWindow(EffectWindow *w, int mask, QRegion region, WindowPaintData &data); | ||
| 59 | void paintEffectFrame(EffectFrame *frame, QRegion region, double opacity, double frameOpacity); | 62 | void paintEffectFrame(EffectFrame *frame, QRegion region, double opacity, double frameOpacity); | ||
| 60 | 63 | | |||
| 61 | // for dynamic setting extraction | | |||
| 62 | int blurRadius() const; | | |||
| 63 | bool isCacheTexture() const { | | |||
| 64 | return m_shouldCache; | | |||
| 65 | } | | |||
| 66 | virtual bool provides(Feature feature); | 64 | virtual bool provides(Feature feature); | ||
| 67 | 65 | | |||
| 68 | int requestedEffectChainPosition() const override { | 66 | int requestedEffectChainPosition() const override { | ||
| 69 | return 75; | 67 | return 75; | ||
| 70 | } | 68 | } | ||
| 71 | 69 | | |||
| 72 | public Q_SLOTS: | 70 | public Q_SLOTS: | ||
| 73 | void slotWindowAdded(KWin::EffectWindow *w); | 71 | void slotWindowAdded(KWin::EffectWindow *w); | ||
| 74 | void slotWindowDeleted(KWin::EffectWindow *w); | 72 | void slotWindowDeleted(KWin::EffectWindow *w); | ||
| 75 | void slotPropertyNotify(KWin::EffectWindow *w, long atom); | 73 | void slotPropertyNotify(KWin::EffectWindow *w, long atom); | ||
| 76 | void slotScreenGeometryChanged(); | 74 | void slotScreenGeometryChanged(); | ||
| 77 | 75 | | |||
| 78 | private: | 76 | private: | ||
| 79 | void updateTexture(); | | |||
| 80 | QRect expand(const QRect &rect) const; | 77 | QRect expand(const QRect &rect) const; | ||
| 81 | QRegion expand(const QRegion ®ion) const; | 78 | QRegion expand(const QRegion ®ion) const; | ||
| 79 | bool renderTargetsValid() const; | ||||
| 80 | void deleteFBOs(); | ||||
| 81 | void initBlurStrengthValues(); | ||||
| 82 | void updateTexture(); | ||||
| 82 | QRegion blurRegion(const EffectWindow *w) const; | 83 | QRegion blurRegion(const EffectWindow *w) const; | ||
| 83 | bool shouldBlur(const EffectWindow *w, int mask, const WindowPaintData &data) const; | 84 | bool shouldBlur(const EffectWindow *w, int mask, const WindowPaintData &data) const; | ||
anthonyfieroni: Still can be const. | |||||
| 84 | void updateBlurRegion(EffectWindow *w) const; | 85 | void updateBlurRegion(EffectWindow *w) const; | ||
| 85 | void doSimpleBlur(EffectWindow *w, const float opacity, const QMatrix4x4 &screenProjection); | 86 | void doSimpleBlur(EffectWindow *w, const float opacity, const QMatrix4x4 &screenProjection); | ||
| 86 | void doBlur(const QRegion &shape, const QRect &screen, const float opacity, const QMatrix4x4 &screenProjection); | 87 | void doBlur(const QRegion &shape, const QRect &screen, const float opacity, const QMatrix4x4 &screenProjection, bool isDock); | ||
| 87 | void doCachedBlur(EffectWindow *w, const QRegion& region, const float opacity, const QMatrix4x4 &screenProjection); | 88 | void uploadRegion(QVector2D *&map, const QRegion ®ion, const int downSampleIterations); | ||
| 88 | void uploadRegion(QVector2D *&map, const QRegion ®ion); | 89 | void uploadGeometry(GLVertexBuffer *vbo, const QRegion &blurRegion, const QRegion &windowRegion); | ||
There are many whitespace errors. If you're using KDevelop or Kate make sure that you have activated to automatically remove whitespace at the end of a line. romangg: There are many whitespace errors. If you're using KDevelop or Kate make sure that you have… | |||||
| 89 | void uploadGeometry(GLVertexBuffer *vbo, const QRegion &horizontal, const QRegion &vertical); | 90 | | ||
| 91 | void downSampleTexture(GLVertexBuffer *vbo, int blurRectCount); | ||||
| 92 | void upSampleTexture(GLVertexBuffer *vbo, int blurRectCount); | ||||
| 93 | void copyScreenSampleTexture(GLVertexBuffer *vbo, int blurRectCount, QRegion blurShape, QSize screenSize, QMatrix4x4 screenProjection); | ||||
| 90 | 94 | | |||
| 91 | private: | 95 | private: | ||
| 92 | BlurShader *shader; | | |||
| 93 | GLShader *m_simpleShader; | 96 | GLShader *m_simpleShader; | ||
| 94 | GLRenderTarget *target = nullptr; | 97 | GLRenderTarget *m_simpleTarget; | ||
| 95 | GLTexture tex; | 98 | | ||
| 99 | BlurShader *m_shader; | ||||
| 100 | QVector <GLRenderTarget*> m_renderTargets; | ||||
| 101 | QVector <GLTexture> m_renderTextures; | ||||
Coding style(prefix fields with m_) + consistency: BlurShader *m_shader; QVector <GLRenderTarget*> m_renderTargets; QVector <GLTexture> m_renderTextures; zzag: Coding style(prefix fields with `m_`) + consistency:
```
BlurShader *m_shader… | |||||
| 102 | QStack <GLRenderTarget*> m_renderTargetStack; | ||||
| 103 | bool m_renderTargetsValid; | ||||
| 96 | long net_wm_blur_region; | 104 | long net_wm_blur_region; | ||
| 97 | QRegion m_damagedArea; // keeps track of the area which has been damaged (from bottom to top) | 105 | QRegion m_damagedArea; // keeps track of the area which has been damaged (from bottom to top) | ||
| 98 | QRegion m_paintedArea; // actually painted area which is greater than m_damagedArea | 106 | QRegion m_paintedArea; // actually painted area which is greater than m_damagedArea | ||
| 99 | QRegion m_currentBlur; // keeps track of the currently blured area of non-caching windows(from bottom to top) | 107 | QRegion m_currentBlur; // keeps track of the currently blured area of the windows(from bottom to top) | ||
| 100 | bool m_shouldCache; | 108 | bool m_useSimpleBlur; | ||
| 101 | 109 | | |||
| 102 | struct BlurWindowInfo { | 110 | int m_downSampleIterations; // number of times the texture will be downsized to half size | ||
| 103 | GLTexture blurredBackground; // keeps the horizontally blurred background | 111 | int m_offset; | ||
| 104 | QRegion damagedRegion; | 112 | int m_expandSize; | ||
| 105 | QPoint windowPos; | 113 | | ||
| 106 | bool dropCache; | 114 | struct OffsetStruct { | ||
| 107 | QMetaObject::Connection blurChangedConnection; | 115 | float minOffset; | ||
| 116 | float maxOffset; | ||||
| 117 | int expandSize; | ||||
| 108 | }; | 118 | }; | ||
| 109 | 119 | | |||
| 110 | QHash< const EffectWindow*, BlurWindowInfo > windows; | 120 | QVector <OffsetStruct> blurOffsets; | ||
| 111 | typedef QHash<const EffectWindow*, BlurWindowInfo>::iterator CacheEntry; | 121 | | ||
| 122 | struct BlurValuesStruct { | ||||
| 123 | int iteration; | ||||
| 124 | float offset; | ||||
| 125 | }; | ||||
| 126 | | ||||
| 127 | QVector <BlurValuesStruct> blurStrengthValues; | ||||
zzag: strength | |||||
| 128 | | ||||
| 129 | QMap <EffectWindow*, QMetaObject::Connection> windowBlurChangedConnections; | ||||
| 112 | KWayland::Server::BlurManagerInterface *m_blurManager = nullptr; | 130 | KWayland::Server::BlurManagerInterface *m_blurManager = nullptr; | ||
| 113 | }; | 131 | }; | ||
| 114 | 132 | | |||
| 115 | inline | 133 | inline | ||
| 116 | bool BlurEffect::provides(Effect::Feature feature) | 134 | bool BlurEffect::provides(Effect::Feature feature) | ||
| 117 | { | 135 | { | ||
| 118 | if (feature == Blur) { | 136 | if (feature == Blur) { | ||
| 119 | return true; | 137 | return true; | ||
| Show All 9 Lines | |||||
Put this into the cpp.