From e31d10c18df1baf8d3274ce84b1ce38077de58e7 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Tue, 31 Aug 2021 03:05:18 +0200 Subject: [PATCH] output protocols: add rgb range setting --- src/wayland/outputchangeset_v2.cpp | 9 ++++++ src/wayland/outputchangeset_v2.h | 9 ++++++ src/wayland/outputchangeset_v2_p.h | 1 + .../outputconfiguration_v2_interface.cpp | 12 ++++++++ src/wayland/outputdevice_v2_interface.cpp | 30 +++++++++++++++++++ src/wayland/outputdevice_v2_interface.h | 11 +++++++ 6 files changed, 72 insertions(+) diff --git a/src/wayland/outputchangeset_v2.cpp b/src/wayland/outputchangeset_v2.cpp index 5050b91139..faf4d3d2f0 100644 --- a/src/wayland/outputchangeset_v2.cpp +++ b/src/wayland/outputchangeset_v2.cpp @@ -111,4 +111,13 @@ OutputDeviceV2Interface::VrrPolicy OutputChangeSetV2::vrrPolicy() const return d->vrrPolicy; } +bool OutputChangeSetV2::rgbRangeChanged() const +{ + return d->rgbRange != d->outputDevice->rgbRange(); +} + +OutputDeviceV2Interface::RgbRange OutputChangeSetV2::rgbRange() const +{ + return d->rgbRange; +} } diff --git a/src/wayland/outputchangeset_v2.h b/src/wayland/outputchangeset_v2.h index 57276668d3..07292e0828 100644 --- a/src/wayland/outputchangeset_v2.h +++ b/src/wayland/outputchangeset_v2.h @@ -72,6 +72,12 @@ public: */ bool vrrPolicyChanged() const; + /** + * Whether the rgbRange() property of the outputdevice changed. + * @returns @c true if the rgbRange() property of the outputdevice has changed. + */ + bool rgbRangeChanged() const; + /** The new value for enabled. */ bool enabled() const; @@ -97,6 +103,9 @@ public: /** The new value for vrrPolicy */ OutputDeviceV2Interface::VrrPolicy vrrPolicy() const; + /** The new value for rgbRange */ + OutputDeviceV2Interface::RgbRange rgbRange() const; + private: friend class OutputConfigurationV2InterfacePrivate; explicit OutputChangeSetV2(OutputDeviceV2Interface *outputdevice, QObject *parent = nullptr); diff --git a/src/wayland/outputchangeset_v2_p.h b/src/wayland/outputchangeset_v2_p.h index 9802744c99..e282ab9ef9 100644 --- a/src/wayland/outputchangeset_v2_p.h +++ b/src/wayland/outputchangeset_v2_p.h @@ -26,6 +26,7 @@ public: qreal scale; uint32_t overscan; OutputDeviceV2Interface::VrrPolicy vrrPolicy = OutputDeviceV2Interface::VrrPolicy::Automatic; + OutputDeviceV2Interface::RgbRange rgbRange = OutputDeviceV2Interface::RgbRange::Automatic; }; } diff --git a/src/wayland/outputconfiguration_v2_interface.cpp b/src/wayland/outputconfiguration_v2_interface.cpp index db3520115b..96a7cb04ed 100644 --- a/src/wayland/outputconfiguration_v2_interface.cpp +++ b/src/wayland/outputconfiguration_v2_interface.cpp @@ -44,6 +44,7 @@ protected: void kde_output_configuration_v2_destroy_resource(Resource *resource) override; void kde_output_configuration_v2_overscan(Resource *resource, wl_resource *outputdevice, uint32_t overscan) override; void kde_output_configuration_v2_set_vrr_policy(Resource *resource, struct ::wl_resource *outputdevice, uint32_t policy) override; + void kde_output_configuration_v2_set_rgb_range(Resource *resource, wl_resource *outputdevice, uint32_t rgbRange) override; }; void OutputConfigurationV2InterfacePrivate::kde_output_configuration_v2_enable(Resource *resource, wl_resource *outputdevice, int32_t enable) @@ -143,6 +144,17 @@ void OutputConfigurationV2InterfacePrivate::kde_output_configuration_v2_set_vrr_ pendingChanges(output)->d->vrrPolicy = static_cast(policy); } +void OutputConfigurationV2InterfacePrivate::kde_output_configuration_v2_set_rgb_range(Resource *resource, wl_resource *outputdevice, uint32_t rgbRange) +{ + Q_UNUSED(resource) + if (rgbRange > static_cast(OutputDeviceV2Interface::RgbRange::Limited)) { + qCWarning(KWAYLAND_SERVER) << "Invalid Rgb Range requested:" << rgbRange; + return; + } + OutputDeviceV2Interface *output = OutputDeviceV2Interface::get(outputdevice); + pendingChanges(output)->d->rgbRange = static_cast(rgbRange); +} + void OutputConfigurationV2InterfacePrivate::kde_output_configuration_v2_destroy(Resource *resource) { wl_resource_destroy(resource->handle); diff --git a/src/wayland/outputdevice_v2_interface.cpp b/src/wayland/outputdevice_v2_interface.cpp index 12222cbc6c..9b189c7a76 100644 --- a/src/wayland/outputdevice_v2_interface.cpp +++ b/src/wayland/outputdevice_v2_interface.cpp @@ -38,6 +38,7 @@ public: void updateCapabilities(); void updateOverscan(); void updateVrrPolicy(); + void updateRgbRange(); void sendGeometry(Resource *resource); wl_resource *sendNewMode(Resource *resource, OutputDeviceModeV2Interface *mode); @@ -52,6 +53,7 @@ public: void sendCapabilities(Resource *resource); void sendOverscan(Resource *resource); void sendVrrPolicy(Resource *resource); + void sendRgbRange(Resource *resource); QSize physicalSize; QPoint globalPosition; @@ -72,6 +74,7 @@ public: OutputDeviceV2Interface::Capabilities capabilities; uint32_t overscan = 0; OutputDeviceV2Interface::VrrPolicy vrrPolicy = OutputDeviceV2Interface::VrrPolicy::Automatic; + OutputDeviceV2Interface::RgbRange rgbRange = OutputDeviceV2Interface::RgbRange::Automatic; QPointer display; OutputDeviceV2Interface *q; @@ -701,6 +704,33 @@ void OutputDeviceV2InterfacePrivate::updateVrrPolicy() } } +OutputDeviceV2Interface::RgbRange OutputDeviceV2Interface::rgbRange() const +{ + return d->rgbRange; +} + +void OutputDeviceV2Interface::setRgbRange(RgbRange rgbRange) +{ + if (d->rgbRange != rgbRange) { + d->rgbRange = rgbRange; + d->updateRgbRange(); + Q_EMIT rgbRangeChanged(); + } +} + +void OutputDeviceV2InterfacePrivate::sendRgbRange(Resource *resource) +{ + send_rgb_range(resource->handle, static_cast(rgbRange)); +} + +void OutputDeviceV2InterfacePrivate::updateRgbRange() +{ + const auto clientResources = resourceMap(); + for (const auto &resource : clientResources) { + sendRgbRange(resource); + } +} + OutputDeviceV2Interface *OutputDeviceV2Interface::get(wl_resource *native) { if (auto devicePrivate = resource_cast(native)) { diff --git a/src/wayland/outputdevice_v2_interface.h b/src/wayland/outputdevice_v2_interface.h index 8996ce85a0..680d993114 100644 --- a/src/wayland/outputdevice_v2_interface.h +++ b/src/wayland/outputdevice_v2_interface.h @@ -48,6 +48,7 @@ class KWAYLANDSERVER_EXPORT OutputDeviceV2Interface : public QObject Q_PROPERTY(Capabilities capabilities READ capabilities WRITE setCapabilities NOTIFY capabilitiesChanged) Q_PROPERTY(uint32_t overscan READ overscan WRITE setOverscan NOTIFY overscanChanged) Q_PROPERTY(VrrPolicy vrrPolicy READ vrrPolicy WRITE setVrrPolicy NOTIFY vrrPolicyChanged) + Q_PROPERTY(RgbRange rgbRange READ rgbRange WRITE setRgbRange NOTIFY rgbRangeChanged) public: enum class SubPixel { Unknown, @@ -72,6 +73,7 @@ public: enum class Capability { Overscan = 0x1, Vrr = 0x2, + RgbRange = 0x4, }; Q_ENUM(Capability) Q_DECLARE_FLAGS(Capabilities, Capability) @@ -81,6 +83,12 @@ public: Automatic = 2 }; Q_ENUM(VrrPolicy) + enum class RgbRange { + Automatic = 0, + Full = 1, + Limited = 2, + }; + Q_ENUM(RgbRange) explicit OutputDeviceV2Interface(Display *display, QObject *parent = nullptr); ~OutputDeviceV2Interface() override; @@ -107,6 +115,7 @@ public: Capabilities capabilities() const; uint32_t overscan() const; VrrPolicy vrrPolicy() const; + RgbRange rgbRange() const; void setPhysicalSize(const QSize &size); void setGlobalPosition(const QPoint &pos); @@ -135,6 +144,7 @@ public: void setCapabilities(Capabilities cap); void setOverscan(uint32_t overscan); void setVrrPolicy(VrrPolicy policy); + void setRgbRange(RgbRange rgbRange); static OutputDeviceV2Interface *get(wl_resource *native); @@ -158,6 +168,7 @@ Q_SIGNALS: void capabilitiesChanged(); void overscanChanged(); void vrrPolicyChanged(); + void rgbRangeChanged(); private: QScopedPointer d;