KWin
Loading...
Searching...
No Matches
output.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: 2019 Roman Gilg <subdiff@gmail.com>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#pragma once
10
11#include <kwin_export.h>
12
13#include "renderloop.h"
14#include "utils/edid.h"
15
16#include <QDebug>
17#include <QList>
18#include <QMatrix4x4>
19#include <QObject>
20#include <QRect>
21#include <QSize>
22#include <QUuid>
23
24namespace KWin
25{
26
27class RenderLoop;
28class OutputConfiguration;
29class ColorTransformation;
30class IccProfile;
31class OutputChangeSet;
32
36class KWIN_EXPORT OutputTransform
37{
38public:
39 enum Kind {
40 Normal = 0, // no rotation
41 Rotate90 = 1, // rotate 90 degrees counterclockwise
42 Rotate180 = 2, // rotate 180 degrees counterclockwise
43 Rotate270 = 3, // rotate 270 degrees counterclockwise
44 FlipX = 4, // mirror horizontally
45 FlipX90 = 5, // mirror horizontally, then rotate 90 degrees counterclockwise
46 FlipX180 = 6, // mirror horizontally, then rotate 180 degrees counterclockwise
47 FlipX270 = 7, // mirror horizontally, then rotate 270 degrees counterclockwise
48 FlipY = FlipX180, // mirror vertically
49 FlipY90 = FlipX270, // mirror vertically, then rotate 90 degrees counterclockwise
50 FlipY180 = FlipX, // mirror vertically, then rotate 180 degrees counterclockwise
51 FlipY270 = FlipX90, // mirror vertically, then rotate 270 degrees counterclockwise
52 };
53
54 OutputTransform() = default;
56 : m_kind(kind)
57 {
58 }
59
60 bool operator<=>(const OutputTransform &other) const = default;
61
65 Kind kind() const;
66
71 OutputTransform inverted() const;
72
76 QSizeF map(const QSizeF &size) const;
77 QSize map(const QSize &size) const;
78
82 QRectF map(const QRectF &rect, const QSizeF &bounds) const;
83 QRect map(const QRect &rect, const QSize &bounds) const;
84
88 QPointF map(const QPointF &point, const QSizeF &bounds) const;
89 QPoint map(const QPoint &point, const QSize &bounds) const;
90
95 OutputTransform combine(OutputTransform other) const;
96
100 QMatrix4x4 toMatrix() const;
101
102private:
103 Kind m_kind = Kind::Normal;
104};
105
106class KWIN_EXPORT OutputMode
107{
108public:
109 enum class Flag : uint {
110 Preferred = 0x1,
111 Generated = 0x2,
112 };
113 Q_DECLARE_FLAGS(Flags, Flag)
114
115 OutputMode(const QSize &size, uint32_t refreshRate, Flags flags = {});
116 virtual ~OutputMode() = default;
117
118 QSize size() const;
119 uint32_t refreshRate() const;
120 Flags flags() const;
121
122private:
123 const QSize m_size;
124 const uint32_t m_refreshRate;
125 const Flags m_flags;
126};
127
131class KWIN_EXPORT Output : public QObject
132{
133 Q_OBJECT
134 Q_PROPERTY(QRect geometry READ geometry NOTIFY geometryChanged)
135 Q_PROPERTY(qreal devicePixelRatio READ scale NOTIFY scaleChanged)
136 Q_PROPERTY(QString name READ name CONSTANT)
137 Q_PROPERTY(QString manufacturer READ manufacturer CONSTANT)
138 Q_PROPERTY(QString model READ model CONSTANT)
139 Q_PROPERTY(QString serialNumber READ serialNumber CONSTANT)
140
141public:
142 enum class DpmsMode {
143 On,
144 Standby,
145 Suspend,
146 Off,
147 };
148 Q_ENUM(DpmsMode)
149
150 enum class Capability : uint {
151 Dpms = 1,
152 Overscan = 1 << 1,
153 Vrr = 1 << 2,
154 RgbRange = 1 << 3,
155 HighDynamicRange = 1 << 4,
156 WideColorGamut = 1 << 5,
157 AutoRotation = 1 << 6,
158 IccProfile = 1 << 7,
159 Tearing = 1 << 8,
160 };
161 Q_DECLARE_FLAGS(Capabilities, Capability)
162
163 enum class SubPixel {
164 Unknown,
165 None,
166 Horizontal_RGB,
167 Horizontal_BGR,
168 Vertical_RGB,
169 Vertical_BGR,
170 };
171 Q_ENUM(SubPixel)
172
173 enum class RgbRange {
174 Automatic = 0,
175 Full = 1,
176 Limited = 2,
177 };
178 Q_ENUM(RgbRange)
179
181 Never = 0,
182 InTabletMode,
183 Always
184 };
186
187 explicit Output(QObject *parent = nullptr);
188 ~Output() override;
189
190 void ref();
191 void unref();
192
196 QRect mapFromGlobal(const QRect &rect) const;
197
201 QRectF mapFromGlobal(const QRectF &rect) const;
202
206 QRectF mapToGlobal(const QRectF &rect) const;
207
208 Q_INVOKABLE QPointF mapToGlobal(const QPointF &pos) const;
209 Q_INVOKABLE QPointF mapFromGlobal(const QPointF &pos) const;
210
214 QString name() const;
215
219 QUuid uuid() const;
220
224 bool isEnabled() const;
225
229 QRect geometry() const;
230
234 QRectF geometryF() const;
235
239 QRect rect() const;
240
244 QRectF rectF() const;
245
249 uint32_t refreshRate() const;
250
255 bool isInternal() const;
256
260 qreal scale() const;
261
265 QSize physicalSize() const;
266
268 QSize pixelSize() const;
269 QSize modeSize() const;
270
271 QString eisaId() const;
272
276 QString manufacturer() const;
280 QString model() const;
284 QString serialNumber() const;
285
291 virtual RenderLoop *renderLoop() const = 0;
292
293 void inhibitDirectScanout();
294 void uninhibitDirectScanout();
295
296 bool directScanoutInhibited() const;
297
306 static std::chrono::milliseconds dimAnimationTime();
307
308 OutputTransform transform() const;
313 OutputTransform manualTransform() const;
314 QSize orientateSize(const QSize &size) const;
315
316 void applyChanges(const OutputConfiguration &config);
317
318 SubPixel subPixel() const;
319 QString description() const;
320 Capabilities capabilities() const;
321 const Edid &edid() const;
322 QList<std::shared_ptr<OutputMode>> modes() const;
323 std::shared_ptr<OutputMode> currentMode() const;
324 DpmsMode dpmsMode() const;
325 virtual void setDpmsMode(DpmsMode mode);
326
327 uint32_t overscan() const;
328
329 VrrPolicy vrrPolicy() const;
330 RgbRange rgbRange() const;
331
332 bool isPlaceholder() const;
333 bool isNonDesktop() const;
334 OutputTransform panelOrientation() const;
335 bool wideColorGamut() const;
336 bool highDynamicRange() const;
337 uint32_t sdrBrightness() const;
338 AutoRotationPolicy autoRotationPolicy() const;
339 std::shared_ptr<IccProfile> iccProfile() const;
340 QString iccProfilePath() const;
344 QByteArray mstPath() const;
345
346 virtual bool setGammaRamp(const std::shared_ptr<ColorTransformation> &transformation);
347 virtual bool setChannelFactors(const QVector3D &rgb);
348
349 virtual bool updateCursorLayer();
350
351 std::optional<double> maxPeakBrightness() const;
352 std::optional<double> maxAverageBrightness() const;
353 double minBrightness() const;
354 std::optional<double> maxPeakBrightnessOverride() const;
355 std::optional<double> maxAverageBrightnessOverride() const;
356 std::optional<double> minBrightnessOverride() const;
357
358 double sdrGamutWideness() const;
359
360 const ColorDescription &colorDescription() const;
361
362Q_SIGNALS:
375
380 void aboutToTurnOff(std::chrono::milliseconds time);
381
385 void wakeUp();
386
396
404 void changed();
405
408 void outputChange(const QRegion &damagedRegion);
424
425protected:
427 {
428 QString name;
430 QString model;
432 QString eisaId;
435 SubPixel subPixel = SubPixel::Unknown;
436 Capabilities capabilities;
437 OutputTransform panelOrientation = OutputTransform::Normal;
438 bool internal = false;
439 bool placeholder = false;
440 bool nonDesktop = false;
441 QByteArray mstPath;
442 std::optional<double> maxPeakBrightness;
443 std::optional<double> maxAverageBrightness;
444 double minBrightness = 0;
445 };
446
447 struct State
448 {
449 QPoint position;
450 qreal scale = 1;
451 OutputTransform transform = OutputTransform::Normal;
452 OutputTransform manualTransform = OutputTransform::Normal;
453 QList<std::shared_ptr<OutputMode>> modes;
454 std::shared_ptr<OutputMode> currentMode;
455 DpmsMode dpmsMode = DpmsMode::On;
456 SubPixel subPixel = SubPixel::Unknown;
457 bool enabled = false;
458 uint32_t overscan = 0;
459 RgbRange rgbRange = RgbRange::Automatic;
460 bool wideColorGamut = false;
461 bool highDynamicRange = false;
462 uint32_t sdrBrightness = 200;
463 AutoRotationPolicy autoRotatePolicy = AutoRotationPolicy::InTabletMode;
465 std::shared_ptr<IccProfile> iccProfile;
466 ColorDescription colorDescription = ColorDescription::sRGB;
467 std::optional<double> maxPeakBrightnessOverride;
468 std::optional<double> maxAverageBrightnessOverride;
469 std::optional<double> minBrightnessOverride;
470 double sdrGamutWideness = 0;
471 VrrPolicy vrrPolicy = VrrPolicy::Automatic;
472 };
473
474 void setInformation(const Information &information);
475 void setState(const State &state);
476
479 QUuid m_uuid;
480 int m_directScanoutCount = 0;
481 int m_refCount = 1;
482};
483
484inline QRect Output::rect() const
485{
486 return QRect(QPoint(0, 0), geometry().size());
487}
488
489inline QRectF Output::rectF() const
490{
491 return QRectF(QPointF(0, 0), geometryF().size());
492}
493
494KWIN_EXPORT QDebug operator<<(QDebug debug, const Output *output);
495
496} // namespace KWin
497
498Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::Output::Capabilities)
void enabledChanged()
QRect rect() const
Definition output.h:484
void rgbRangeChanged()
void outputChange(const QRegion &damagedRegion)
void colorDescriptionChanged()
QRectF geometryF() const
Definition output.cpp:465
Q_ENUM(AutoRotationPolicy)
void overscanChanged()
void currentModeChanged()
void highDynamicRangeChanged()
void geometryChanged()
void autoRotationPolicyChanged()
void sdrBrightnessChanged()
void scaleChanged()
virtual RenderLoop * renderLoop() const =0
void capabilitiesChanged()
void modesChanged()
void iccProfilePathChanged()
void vrrPolicyChanged()
void aboutToChange(OutputChangeSet *changeSet)
QRectF rectF() const
Definition output.h:489
void iccProfileChanged()
void sdrGamutWidenessChanged()
void brightnessMetadataChanged()
State m_state
Definition output.h:477
void transformChanged()
void changed()
void aboutToTurnOff(std::chrono::milliseconds time)
void wideColorGamutChanged()
QRect geometry
Definition output.h:134
Information m_information
Definition output.h:478
void dpmsModeChanged()
QUuid m_uuid
Definition output.h:479
virtual ~OutputMode()=default
bool operator<=>(const OutputTransform &other) const =default
OutputTransform(Kind kind)
Definition output.h:55
VrrPolicy
Definition globals.h:292
QDebug & operator<<(QDebug &s, const KWin::DrmConnector *obj)
Capabilities capabilities
Definition output.h:436
std::optional< double > maxAverageBrightness
Definition output.h:443
std::optional< double > maxPeakBrightness
Definition output.h:442
std::shared_ptr< OutputMode > currentMode
Definition output.h:454
QList< std::shared_ptr< OutputMode > > modes
Definition output.h:453
QString iccProfilePath
Definition output.h:464
std::shared_ptr< IccProfile > iccProfile
Definition output.h:465
std::optional< double > maxAverageBrightnessOverride
Definition output.h:468
std::optional< double > minBrightnessOverride
Definition output.h:469
std::optional< double > maxPeakBrightnessOverride
Definition output.h:467