KWin
Loading...
Searching...
No Matches
drm_pipeline.h
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2021 Xaver Hugl <xaver.hugl@gmail.com>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#pragma once
11
12#include <QList>
13#include <QPoint>
14#include <QSize>
15
16#include <chrono>
17#include <xf86drmMode.h>
18
19#include "core/colorlut.h"
20#include "core/colorspace.h"
21#include "core/output.h"
22#include "core/renderloop_p.h"
23#include "drm_blob.h"
24#include "drm_connector.h"
25#include "drm_plane.h"
26
27namespace KWin
28{
29
30class DrmGpu;
31class DrmConnector;
32class DrmCrtc;
33class GammaRamp;
34class DrmConnectorMode;
35class DrmPipelineLayer;
36class DrmCommitThread;
37
39{
40public:
41 DrmGammaRamp(DrmCrtc *crtc, const std::shared_ptr<ColorTransformation> &transformation);
42
43 const ColorLUT &lut() const;
44 std::shared_ptr<DrmBlob> blob() const;
45
46private:
47 const ColorLUT m_lut;
48 std::shared_ptr<DrmBlob> m_blob;
49};
50
52{
53public:
56
66 Q_ENUM(Error)
67
68
72 Error present();
73 bool testScanout();
74 bool maybeModeset();
75 void forceLegacyModeset();
76
77 bool needsModeset() const;
80
81 bool updateCursor();
82
83 DrmConnector *connector() const;
84 DrmGpu *gpu() const;
85
86 enum class PageflipType {
87 Normal,
89 Modeset,
90 };
91 void pageFlipped(std::chrono::nanoseconds timestamp, PageflipType type, PresentationMode mode);
92 bool pageflipsPending() const;
93 bool modesetPresentPending() const;
95
96 QMap<uint32_t, QList<uint64_t>> formats() const;
97 QMap<uint32_t, QList<uint64_t>> cursorFormats() const;
98 bool hasCTM() const;
99 bool hasGammaRamp() const;
100 bool pruneModifier();
101
103 DrmOutput *output() const;
104
105 void setLayers(const std::shared_ptr<DrmPipelineLayer> &primaryLayer, const std::shared_ptr<DrmPipelineLayer> &cursorLayer);
108 std::chrono::nanoseconds presentationDeadline() const;
109
110 DrmCrtc *crtc() const;
111 std::shared_ptr<DrmConnectorMode> mode() const;
112 bool active() const;
113 bool activePending() const;
114 bool enabled() const;
115 DrmPlane::Transformations renderOrientation() const;
117 uint32_t overscan() const;
120 const ColorDescription &colorDescription() const;
121 const std::shared_ptr<IccProfile> &iccProfile() const;
122
123 void setCrtc(DrmCrtc *crtc);
124 void setMode(const std::shared_ptr<DrmConnectorMode> &mode);
125 void setActive(bool active);
126 void setEnable(bool enable);
127 void setRenderOrientation(DrmPlane::Transformations orientation);
129 void setOverscan(uint32_t overscan);
130 void setRgbRange(Output::RgbRange range);
131 void setGammaRamp(const std::shared_ptr<ColorTransformation> &transformation);
132 void setCTM(const QMatrix3x3 &ctm);
134 void setColorDescription(const ColorDescription &description);
135 void setIccProfile(const std::shared_ptr<IccProfile> &profile);
136
137 enum class CommitMode {
138 Test,
141 };
142 Q_ENUM(CommitMode)
143 static Error commitPipelines(const QList<DrmPipeline *> &pipelines, CommitMode mode, const QList<DrmObject *> &unusedObjects = {});
144
145private:
146 bool isBufferForDirectScanout() const;
147 uint32_t calculateUnderscan();
148 static Error errnoToError();
149 std::shared_ptr<DrmBlob> createHdrMetadata(NamedTransferFunction transferFunction) const;
150
151 // legacy only
152 Error presentLegacy();
153 Error legacyModeset();
154 Error applyPendingChangesLegacy();
155 bool setCursorLegacy();
156 static Error commitPipelinesLegacy(const QList<DrmPipeline *> &pipelines, CommitMode mode, const QList<DrmObject *> &unusedObjects);
157
158 // atomic modesetting only
159 Error prepareAtomicCommit(DrmAtomicCommit *commit, CommitMode mode);
160 bool prepareAtomicModeset(DrmAtomicCommit *commit);
161 Error prepareAtomicPresentation(DrmAtomicCommit *commit);
162 void prepareAtomicCursor(DrmAtomicCommit *commit);
163 void prepareAtomicDisable(DrmAtomicCommit *commit);
164 static Error commitPipelinesAtomic(const QList<DrmPipeline *> &pipelines, CommitMode mode, const QList<DrmObject *> &unusedObjects);
165
166 DrmOutput *m_output = nullptr;
167 DrmConnector *m_connector = nullptr;
168
169 bool m_modesetPresentPending = false;
170
171 struct State
172 {
173 DrmCrtc *crtc = nullptr;
174 QMap<uint32_t, QList<uint64_t>> formats;
175 bool active = true; // whether or not the pipeline should be currently used
176 bool enabled = true; // whether or not the pipeline needs a crtc
177 bool needsModeset = false;
178 bool needsModesetProperties = false;
179 std::shared_ptr<DrmConnectorMode> mode;
180 uint32_t overscan = 0;
182 PresentationMode presentationMode = PresentationMode::VSync;
183 std::shared_ptr<ColorTransformation> colorTransformation;
184 std::shared_ptr<DrmGammaRamp> gamma;
185 std::shared_ptr<DrmBlob> ctm;
187
188 std::shared_ptr<IccProfile> iccProfile;
189 ColorDescription colorDescription = ColorDescription::sRGB;
190
191 // the transformation that buffers submitted to the pipeline should have
192 DrmPlane::Transformations renderOrientation = DrmPlane::Transformation::Rotate0;
193 };
194 // the state that is to be tested next
195 State m_pending;
196 // the state that will be applied at the next real atomic commit
197 State m_next;
198
199 std::unique_ptr<DrmCommitThread> m_commitThread;
200 std::shared_ptr<DrmPipelineLayer> m_primaryLayer;
201 std::shared_ptr<DrmPipelineLayer> m_cursorLayer;
202};
203
204}
static const ColorDescription sRGB
Definition colorspace.h:132
std::shared_ptr< DrmBlob > blob() const
const ColorLUT & lut() const
DrmGammaRamp(DrmCrtc *crtc, const std::shared_ptr< ColorTransformation > &transformation)
Output::RgbRange rgbRange() const
DrmPipelineLayer * cursorLayer() const
DrmConnector * connector() const
bool hasGammaRamp() const
uint32_t overscan() const
void setOutput(DrmOutput *output)
QMap< uint32_t, QList< uint64_t > > cursorFormats() const
DrmOutput * output() const
void setContentType(DrmConnector::DrmContentType type)
PresentationMode presentationMode() const
void setMode(const std::shared_ptr< DrmConnectorMode > &mode)
bool needsModeset() const
bool hasCTM() const
const std::shared_ptr< IccProfile > & iccProfile() const
bool active() const
void setLayers(const std::shared_ptr< DrmPipelineLayer > &primaryLayer, const std::shared_ptr< DrmPipelineLayer > &cursorLayer)
void setRgbRange(Output::RgbRange range)
QMap< uint32_t, QList< uint64_t > > formats() const
DrmGpu * gpu() const
const ColorDescription & colorDescription() const
std::chrono::nanoseconds presentationDeadline() const
void setEnable(bool enable)
void setCTM(const QMatrix3x3 &ctm)
bool pageflipsPending() const
void setActive(bool active)
void setCrtc(DrmCrtc *crtc)
bool modesetPresentPending() const
void pageFlipped(std::chrono::nanoseconds timestamp, PageflipType type, PresentationMode mode)
bool enabled() const
DrmPlane::Transformations renderOrientation() const
static Error commitPipelines(const QList< DrmPipeline * > &pipelines, CommitMode mode, const QList< DrmObject * > &unusedObjects={})
void setColorDescription(const ColorDescription &description)
DrmPipeline(DrmConnector *conn)
DrmCrtc * crtc() const
void setRenderOrientation(DrmPlane::Transformations orientation)
void setPresentationMode(PresentationMode mode)
std::shared_ptr< DrmConnectorMode > mode() const
void setIccProfile(const std::shared_ptr< IccProfile > &profile)
DrmPipelineLayer * primaryLayer() const
void setOverscan(uint32_t overscan)
DrmConnector::DrmContentType contentType() const
void resetModesetPresentPending()
bool activePending() const
void setGammaRamp(const std::shared_ptr< ColorTransformation > &transformation)
Session::Type type
Definition session.cpp:17
PresentationMode
Definition globals.h:276
NamedTransferFunction
Definition colorspace.h:90