KWin
Loading...
Searching...
No Matches
contrast.h
Go to the documentation of this file.
1/*
2 SPDX-FileCopyrightText: 2010 Fredrik Höglund <fredrik@kde.org>
3 SPDX-FileCopyrightText: 2014 Marco Martin <mart@kde.org>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8#pragma once
9
10#include "effect/effect.h"
11#include "opengl/glplatform.h"
12#include "opengl/glutils.h"
13
14#include <QList>
15#include <QVector2D>
16#include <unordered_map>
17
18namespace KWin
19{
20
21class ContrastManagerInterface;
22class ContrastShader;
23
25{
26 Q_OBJECT
27public:
29 ~ContrastEffect() override;
30
31 static bool supported();
32 static bool enabledByDefault();
33
34 static QMatrix4x4 colorMatrix(qreal contrast, qreal intensity, qreal saturation);
35 void drawWindow(const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *w, int mask, const QRegion &region, WindowPaintData &data) override;
36
37 bool provides(Feature feature) override;
38 bool isActive() const override;
39
40 int requestedEffectChainPosition() const override
41 {
42 return 21;
43 }
44
45 bool eventFilter(QObject *watched, QEvent *event) override;
46
47 bool blocksDirectScanout() const override;
48
49public Q_SLOTS:
52 void slotPropertyNotify(KWin::EffectWindow *w, long atom);
54
55private:
56 QRegion contrastRegion(const EffectWindow *w) const;
57 bool shouldContrast(const EffectWindow *w, int mask, const WindowPaintData &data) const;
58 void updateContrastRegion(EffectWindow *w);
59 void doContrast(const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *w, const QRegion &shape, const QRect &screen, const float opacity, const QMatrix4x4 &screenProjection);
60 void uploadRegion(std::span<QVector2D> map, const QRegion &region, qreal scale);
61 Q_REQUIRED_RESULT bool uploadGeometry(GLVertexBuffer *vbo, const QRegion &region, qreal scale);
62
63private:
64 std::unique_ptr<ContrastShader> m_shader;
65 long m_net_wm_contrast_region = 0;
66 QHash<const EffectWindow *, QMetaObject::Connection> m_contrastChangedConnections; // used only in Wayland to keep track of effect changed
67 struct Data
68 {
69 QMatrix4x4 colorMatrix;
70 QRegion contrastRegion;
71 std::unique_ptr<GLTexture> texture;
72 std::unique_ptr<GLFramebuffer> fbo;
73 };
74 std::unordered_map<const EffectWindow *, Data> m_windowData;
75 static ContrastManagerInterface *s_contrastManager;
76 static QTimer *s_contrastManagerRemoveTimer;
77};
78
80{
81 if (feature == Contrast) {
82 return true;
83 }
84 return KWin::Effect::provides(feature);
85}
86
87} // namespace KWin
void slotPropertyNotify(KWin::EffectWindow *w, long atom)
Definition contrast.cpp:220
bool eventFilter(QObject *watched, QEvent *event) override
Definition contrast.cpp:194
void drawWindow(const RenderTarget &renderTarget, const RenderViewport &viewport, EffectWindow *w, int mask, const QRegion &region, WindowPaintData &data) override
Definition contrast.cpp:397
bool blocksDirectScanout() const override
Definition contrast.cpp:509
void slotWindowAdded(KWin::EffectWindow *w)
Definition contrast.cpp:175
static bool supported()
Definition contrast.cpp:286
void slotScreenGeometryChanged()
Definition contrast.cpp:87
bool isActive() const override
Definition contrast.cpp:504
static bool enabledByDefault()
Definition contrast.cpp:266
static QMatrix4x4 colorMatrix(qreal contrast, qreal intensity, qreal saturation)
Definition contrast.cpp:227
int requestedEffectChainPosition() const override
Definition contrast.h:40
bool provides(Feature feature) override
Definition contrast.h:79
~ContrastEffect() override
Definition contrast.cpp:79
void slotWindowDeleted(KWin::EffectWindow *w)
Definition contrast.cpp:208
Base class for all KWin effects.
Definition effect.h:535
Representation of a window used by/for Effect classes.
Vertex Buffer Object.
virtual bool provides(Feature)
Definition effect.cpp:442