Commit 168109f3 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii

[effects/blur] Clean up shader code

Summary:
* Drop abstract BlurShader class
* Delete evil "using namespace KWin"
* Fix includes
* Use smart pointers
* Turn BlurShader into a QObject
* Fix coding style
* Add missing default cases
* Use default member initialization
* Delete methods that are used only once
* Use more const
* Use QRect::{top,right,bottom,left} methods in the setBlurRect method

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D13110
parent 6b0d2fc0
......@@ -46,7 +46,7 @@ static const QByteArray s_blurAtomName = QByteArrayLiteral("_KDE_NET_WM_BLUR_BEH
BlurEffect::BlurEffect()
{
initConfig<BlurConfig>();
m_shader = BlurShader::create();
m_shader = new BlurShader(this);
initBlurStrengthValues();
reconfigure(ReconfigureAll);
......@@ -84,9 +84,6 @@ BlurEffect::BlurEffect()
BlurEffect::~BlurEffect()
{
deleteFBOs();
delete m_shader;
m_shader = nullptr;
}
void BlurEffect::slotScreenGeometryChanged()
......
This diff is collapsed.
......@@ -22,33 +22,25 @@
#define BLURSHADER_H
#include <kwinglutils.h>
#include <QMatrix4x4>
#include <QObject>
#include <QScopedPointer>
#include <QVector2D>
#include <QVector4D>
class QMatrix4x4;
namespace KWin
{
class BlurShader
class BlurShader : public QObject
{
public:
BlurShader();
virtual ~BlurShader();
static BlurShader *create();
Q_OBJECT
bool isValid() const {
return mValid;
}
public:
BlurShader(QObject *parent = nullptr);
~BlurShader() override;
virtual void setModelViewProjectionMatrix(const QMatrix4x4 &matrix) = 0;
virtual void setOffset(float offset) = 0;
virtual void setTargetTextureSize(QSize renderTextureSize) = 0;
virtual void setNoiseTextureSize(QSize noiseTextureSize) = 0;
virtual void setTexturePosition(QPoint texPos) = 0;
virtual void setBlurRect(QRect blurRect, QSize screenSize) = 0;
bool isValid() const;
enum SampleType {
DownSampleType,
......@@ -57,49 +49,21 @@ public:
NoiseSampleType
};
virtual void bind(SampleType sampleType) = 0;
virtual void unbind() = 0;
protected:
void setIsValid(bool value) {
mValid = value;
}
virtual void init() = 0;
virtual void reset() = 0;
private:
bool mValid;
};
// ----------------------------------------------------------------------------
void bind(SampleType sampleType);
void unbind();
class GLSLBlurShader : public BlurShader
{
public:
GLSLBlurShader();
~GLSLBlurShader();
void bind(SampleType sampleType) override final;
void unbind() override final;
void setModelViewProjectionMatrix(const QMatrix4x4 &matrix) override final;
void setOffset(float offset) override final;
void setTargetTextureSize(QSize renderTextureSize) override final;
void setNoiseTextureSize(QSize noiseTextureSize) override final;
void setTexturePosition(QPoint texPos) override final;
void setBlurRect(QRect blurRect, QSize screenSize) override final;
protected:
void init() override final;
void reset() override final;
void setModelViewProjectionMatrix(const QMatrix4x4 &matrix);
void setOffset(float offset);
void setTargetTextureSize(const QSize &renderTextureSize);
void setNoiseTextureSize(const QSize &noiseTextureSize);
void setTexturePosition(const QPoint &texPos);
void setBlurRect(const QRect &blurRect, const QSize &screenSize);
private:
GLShader *m_shaderDownsample = nullptr;
GLShader *m_shaderUpsample = nullptr;
GLShader *m_shaderCopysample = nullptr;
GLShader *m_shaderNoisesample = nullptr;
QScopedPointer<GLShader> m_shaderDownsample;
QScopedPointer<GLShader> m_shaderUpsample;
QScopedPointer<GLShader> m_shaderCopysample;
QScopedPointer<GLShader> m_shaderNoisesample;
int m_mvpMatrixLocationDownsample;
int m_offsetLocationDownsample;
......@@ -122,24 +86,31 @@ private:
int m_texStartPosLocationNoisesample;
int m_halfpixelLocationNoisesample;
//Caching uniform values to aviod unnecessary setUniform calls
int m_activeSampleType;
int m_activeSampleType = -1;
float m_offsetDownsample;
float m_offsetDownsample = 0.0;
QMatrix4x4 m_matrixDownsample;
float m_offsetUpsample;
float m_offsetUpsample = 0.0;
QMatrix4x4 m_matrixUpsample;
QMatrix4x4 m_matrixCopysample;
float m_offsetNoisesample;
float m_offsetNoisesample = 0.0;
QVector2D m_noiseTextureSizeNoisesample;
QMatrix4x4 m_matrixNoisesample;
bool m_valid = false;
Q_DISABLE_COPY(BlurShader);
};
inline bool BlurShader::isValid() const
{
return m_valid;
}
} // namespace KWin
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment