contrast.h 2.77 KB
Newer Older
1
/*
Vlad Zahorodnii's avatar
Vlad Zahorodnii committed
2
3
4
5
6
    SPDX-FileCopyrightText: 2010 Fredrik Höglund <fredrik@kde.org>
    SPDX-FileCopyrightText: 2014 Marco Martin <mart@kde.org>

    SPDX-License-Identifier: GPL-2.0-or-later
*/
7
8
9
10
11
12
13
14
15
16
17

#ifndef CONTRAST_H
#define CONTRAST_H

#include <kwineffects.h>
#include <kwinglplatform.h>
#include <kwinglutils.h>

#include <QVector>
#include <QVector2D>

18
namespace KWaylandServer
19
20
21
22
{
class ContrastManagerInterface;
}

23
24
25
26
27
28
29
30
31
32
namespace KWin
{

class ContrastShader;

class ContrastEffect : public KWin::Effect
{
    Q_OBJECT
public:
    ContrastEffect();
33
    ~ContrastEffect() override;
34
35
36
37

    static bool supported();
    static bool enabledByDefault();

Marco Martin's avatar
Marco Martin committed
38
    static QMatrix4x4 colorMatrix(qreal contrast, qreal intensity, qreal saturation);
39
40
41
    void reconfigure(ReconfigureFlags flags) override;
    void prePaintScreen(ScreenPrePaintData &data, int time) override;
    void prePaintWindow(EffectWindow *w, WindowPrePaintData &data, int time) override;
Albert Astals Cid's avatar
Albert Astals Cid committed
42
43
    void drawWindow(EffectWindow *w, int mask, const QRegion &region, WindowPaintData &data) override;
    void paintEffectFrame(EffectFrame *frame, const QRegion &region, double opacity, double frameOpacity) override;
44

45
    bool provides(Feature feature) override;
46
    bool isActive() const override;
47

48
49
50
51
    int requestedEffectChainPosition() const override {
        return 76;
    }

52
53
    bool eventFilter(QObject *watched, QEvent *event) override;

54
55
public Q_SLOTS:
    void slotWindowAdded(KWin::EffectWindow *w);
56
    void slotWindowDeleted(KWin::EffectWindow *w);
Marco Martin's avatar
Marco Martin committed
57
    void slotPropertyNotify(KWin::EffectWindow *w, long atom);
58
59
60
61
62
    void slotScreenGeometryChanged();

private:
    QRegion contrastRegion(const EffectWindow *w) const;
    bool shouldContrast(const EffectWindow *w, int mask, const WindowPaintData &data) const;
63
64
    void updateContrastRegion(EffectWindow *w);
    void doContrast(EffectWindow *w, const QRegion &shape, const QRect &screen, const float opacity, const QMatrix4x4 &screenProjection);
65
    void uploadRegion(QVector2D *&map, const QRegion &region);
66
    void uploadGeometry(GLVertexBuffer *vbo, const QRegion &region);
67
68
69

private:
    ContrastShader *shader;
70
    long net_wm_contrast_region;
Marco Martin's avatar
Marco Martin committed
71
72
    QRegion m_paintedArea; // actually painted area which is greater than m_damagedArea
    QRegion m_currentContrast; // keeps track of the currently contrasted area of non-caching windows(from bottom to top)
73
    QHash< const EffectWindow*, QMatrix4x4> m_colorMatrices;
74
    QHash< const EffectWindow*, QMetaObject::Connection > m_contrastChangedConnections; // used only in Wayland to keep track of effect changed
75
    KWaylandServer::ContrastManagerInterface *m_contrastManager = nullptr;
76
77
78
79
80
};

inline
bool ContrastEffect::provides(Effect::Feature feature)
{
81
    if (feature == Contrast) {
82
83
84
85
86
87
88
89
90
91
        return true;
    }
    return KWin::Effect::provides(feature);
}


} // namespace KWin

#endif