drm_output.h 4.35 KB
Newer Older
Vlad Zahorodnii's avatar
Vlad Zahorodnii committed
1
2
3
/*
    KWin - the KDE window manager
    This file is part of the KDE project.
4

Vlad Zahorodnii's avatar
Vlad Zahorodnii committed
5
    SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
6

Vlad Zahorodnii's avatar
Vlad Zahorodnii committed
7
8
    SPDX-License-Identifier: GPL-2.0-or-later
*/
9
10
11
#ifndef KWIN_DRM_OUTPUT_H
#define KWIN_DRM_OUTPUT_H

12
#include "abstract_wayland_output.h"
13
#include "drm_pointer.h"
14
#include "drm_object.h"
15
#include "drm_object_plane.h"
16
17
18
19

#include <QObject>
#include <QPoint>
#include <QSize>
20
#include <QVector>
Xaver Hugl's avatar
Xaver Hugl committed
21
#include <QSharedPointer>
22
23
24
25
26
27
28
#include <xf86drmMode.h>

namespace KWin
{

class DrmBackend;
class DrmBuffer;
Roman Gilg's avatar
Roman Gilg committed
29
class DrmDumbBuffer;
30
31
32
class DrmPlane;
class DrmConnector;
class DrmCrtc;
33
class Cursor;
34
class DrmGpu;
35

36
class KWIN_EXPORT DrmOutput : public AbstractWaylandOutput
37
38
39
{
    Q_OBJECT
public:
40
41
    ///deletes the output, calling this whilst a page flip is pending will result in an error
    ~DrmOutput() override;
Vlad Zahorodnii's avatar
Vlad Zahorodnii committed
42
43
44

    RenderLoop *renderLoop() const override;

45
46
    ///queues deleting the output after a page flip has completed.
    void teardown();
47
    void releaseBuffers();
48
    bool showCursor(DrmDumbBuffer *buffer);
49
50
    bool showCursor();
    bool hideCursor();
51
52
53
54
55
    bool updateCursor();
    void moveCursor();
    bool init(drmModeConnector *connector);
    bool present(const QSharedPointer<DrmBuffer> &buffer);
    void pageFlipped();
56

57
    bool isDpmsEnabled() const {
58
59
60
61
62
63
        // We care for current as well as pending mode in order to allow first present in AMS.
        return m_dpmsModePending == DpmsMode::On;
    }

    DpmsMode dpmsModePending() const {
        return m_dpmsModePending;
64
65
    }

66
67
68
    const DrmCrtc *crtc() const {
        return m_crtc;
    }
69
70
71
    const DrmConnector *connector() const {
        return m_conn;
    }
72
73
74
75
    const DrmPlane *primaryPlane() const {
        return m_primaryPlane;
    }

76
77
    bool initCursor(const QSize &cursorSize);

78
79
80
81
82
83
84
    /**
     * Drm planes might be capable of realizing the current output transform without usage
     * of compositing. This is a getter to query the current state of that
     *
     * @return true if the hardware realizes the transform without further assistance
     */
    bool hardwareTransforms() const;
Vlad Zahorodnii's avatar
Vlad Zahorodnii committed
85

86
87
88
    DrmGpu *gpu() {
        return m_gpu;
    }
89

90
private:
91
    friend class DrmGpu;
92
    friend class DrmBackend;
93
94
    friend class DrmCrtc;   // TODO: For use of setModeLegacy. Remove later when we allow multiple connectors per crtc
                            //       and save the connector ids in the DrmCrtc instance.
95
    DrmOutput(DrmBackend *backend, DrmGpu* gpu);
96

97
98
99
100
101
102
103
    bool presentAtomically(const QSharedPointer<DrmBuffer> &buffer);

    enum class AtomicCommitMode {
        Test,
        Real
    };
    bool doAtomicCommit(AtomicCommitMode mode);
104

105
106
107
108
109
110
111
112
    bool presentLegacy(const QSharedPointer<DrmBuffer> &buffer);
    bool setModeLegacy(DrmBuffer *buffer);
    void initOutputDevice(drmModeConnector *connector);

    bool isCurrentMode(const drmModeModeInfo *mode) const;

    void atomicEnable();
    void atomicDisable();
113
    void updateEnablement(bool enable) override;
114
115
116
117
118
119
120
121

    bool dpmsAtomicOff();
    bool dpmsLegacyApply();

    void dpmsFinishOn();
    void dpmsFinishOff();

    bool atomicReqModesetPopulate(drmModeAtomicReq *req, bool enable);
122
    void setDpmsMode(DpmsMode mode) override;
123
    void updateMode(int modeIndex) override;
Xaver Hugl's avatar
Xaver Hugl committed
124
    void updateMode(uint32_t width, uint32_t height, uint32_t refreshRate);
125
126
    void setCurrentModeInternal();

Roman Gilg's avatar
Roman Gilg committed
127
    void updateTransform(Transform transform) override;
128

129
130
    int gammaRampSize() const override;
    bool setGammaRamp(const GammaRamp &gamma) override;
131
    void setOverscan(uint32_t overscan) override;
132

133
    DrmBackend *m_backend;
134
    DrmGpu *m_gpu;
135
136
    DrmConnector *m_conn = nullptr;
    DrmCrtc *m_crtc = nullptr;
137
138
139
    bool m_lastGbm = false;
    drmModeModeInfo m_mode;
    DpmsMode m_dpmsModePending = DpmsMode::On;
Vlad Zahorodnii's avatar
Vlad Zahorodnii committed
140
    RenderLoop *m_renderLoop;
141

142
143
144
    uint32_t m_blobId = 0;
    DrmPlane *m_primaryPlane = nullptr;
    QVector<DrmPlane*> m_nextPlanesFlipList;
145
    bool m_pageFlipPending = false;
146
147
148
149
150
151
152
153
154
155
156
157
158
    bool m_atomicOffPending = false;
    bool m_modesetRequested = true;

    struct {
        Transform transform;
        drmModeModeInfo mode;
        DrmPlane::Transformations planeTransformations;
        QPoint globalPos;
        bool valid = false;
    } m_lastWorkingState;
    QScopedPointer<DrmDumbBuffer> m_cursor[2];
    int m_cursorIndex = 0;
    bool m_hasNewCursor = false;
159
    bool m_deleted = false;
160
};
161
162
163
164
165
166

}

Q_DECLARE_METATYPE(KWin::DrmOutput*)

#endif