Commit 71dcb273 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

wayland: Remove OutputChangeSetV2

This allows us to properly map modes with same resolution and refresh
rate but different flags.
parent d78379da
Pipeline #219364 failed with stage
in 45 minutes and 13 seconds
......@@ -211,7 +211,6 @@ target_sources(kwin PRIVATE
output_interface.cpp
outputdevice_v2_interface.cpp
outputmanagement_v2_interface.cpp
outputchangeset_v2.cpp
plasmashell_interface.cpp
plasmavirtualdesktop_interface.cpp
plasmawindowmanagement_interface.cpp
......
/*
SPDX-FileCopyrightText: 2015 Sebastian Kügler <sebas@kde.org>
SPDX-FileCopyrightText: 2021 Méven Car <meven.car@enioka.com>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#include "outputchangeset_v2.h"
#include "outputchangeset_v2_p.h"
namespace KWaylandServer
{
OutputChangeSetV2Private::OutputChangeSetV2Private(OutputDeviceV2Interface *outputdevice, OutputChangeSetV2 *parent)
: q(parent)
, outputDevice(outputdevice)
, enabled(outputDevice->enabled())
, size(outputDevice->pixelSize())
, refreshRate(outputDevice->refreshRate())
, transform(outputDevice->transform())
, position(outputDevice->globalPosition())
, scale(outputDevice->scale())
, overscan(outputDevice->overscan())
, vrrPolicy(outputDevice->vrrPolicy())
, rgbRange(outputDevice->rgbRange())
{
}
OutputChangeSetV2::OutputChangeSetV2(OutputDeviceV2Interface *outputdevice)
: d(new OutputChangeSetV2Private(outputdevice, this))
{
}
OutputChangeSetV2::~OutputChangeSetV2() = default;
bool OutputChangeSetV2::enabledChanged() const
{
return d->enabled != d->outputDevice->enabled();
}
bool OutputChangeSetV2::enabled() const
{
return d->enabled;
}
QSize OutputChangeSetV2::size() const
{
return d->size;
}
bool OutputChangeSetV2::sizeChanged() const
{
return d->size != d->outputDevice->pixelSize();
}
int OutputChangeSetV2::refreshRate() const
{
return d->refreshRate;
}
bool OutputChangeSetV2::refreshRateChanged() const
{
return d->refreshRate != d->outputDevice->refreshRate();
}
bool OutputChangeSetV2::transformChanged() const
{
return d->transform != d->outputDevice->transform();
}
OutputDeviceV2Interface::Transform OutputChangeSetV2::transform() const
{
return d->transform;
}
bool OutputChangeSetV2::positionChanged() const
{
return d->position != d->outputDevice->globalPosition();
}
QPoint OutputChangeSetV2::position() const
{
return d->position;
}
bool OutputChangeSetV2::scaleChanged() const
{
return !qFuzzyCompare(d->scale, d->outputDevice->scale());
}
qreal OutputChangeSetV2::scale() const
{
return d->scale;
}
bool OutputChangeSetV2::overscanChanged() const
{
return d->overscan != d->outputDevice->overscan();
}
uint32_t OutputChangeSetV2::overscan() const
{
return d->overscan;
}
bool OutputChangeSetV2::vrrPolicyChanged() const
{
return d->vrrPolicy != d->outputDevice->vrrPolicy();
}
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;
}
}
/*
SPDX-FileCopyrightText: 2015 Sebastian Kügler <sebas@kde.org>
SPDX-FileCopyrightText: 2021 Méven Car <meven.car@enioka.com>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#pragma once
#include <QObject>
#include "outputdevice_v2_interface.h"
namespace KWaylandServer
{
class OutputChangeSetV2Private;
/**
* @brief Holds a set of changes to an OutputInterface or OutputDeviceInterface.
*
* This class implements a set of changes that the compositor can apply to an
* OutputInterface after OutputConfiguration::apply has been called on the client
* side. The changes are per-configuration.
*
* @see OutputConfiguration
*/
class KWIN_EXPORT OutputChangeSetV2 : public QObject
{
Q_OBJECT
public:
~OutputChangeSetV2() override;
/** Whether the enabled() property of the outputdevice changed.
* @returns @c true if the enabled property of the outputdevice has changed.
*/
bool enabledChanged() const;
/** Whether the transform() property of the outputdevice changed.
* @returns @c true if the enabled property of the outputdevice has changed.
* bool modeChanged() const;
*/
/** Whether the transform() property of the outputdevice changed. */
bool transformChanged() const;
/** Whether the size property of the outputdevice changed.
*/
bool sizeChanged() const;
/** Whether the refreshRate property of the outputdevice changed.
*/
bool refreshRateChanged() const;
/** Whether the globalPosition() property of the outputdevice changed.
* @returns @c true if the globalPosition() property of the outputdevice has changed.
*/
bool positionChanged() const;
/** Whether the scale() property of the outputdevice changed.
* @returns @c true if the scale() property of the outputdevice has changed.
*/
bool scaleChanged() const;
/** Whether the overscan() property of the outputdevice changed.
* @returns @c true if the overscan() property of the outputdevice has changed
*/
bool overscanChanged() const;
/**
* Whether the vrrPolicy() property of the outputdevice changed.
* @returns @c true if the vrrPolicy() property of the outputdevice has changed.
*/
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;
/** The new size */
QSize size() const;
/** The new refresh rate */
int refreshRate() const;
/** The new value for transform. */
OutputDeviceV2Interface::Transform transform() const;
/** The new value for globalPosition. */
QPoint position() const;
/** The new value for scale.
*/
qreal scale() const;
/** the overscan value in % */
uint32_t overscan() const;
/** The new value for vrrPolicy */
OutputDeviceV2Interface::VrrPolicy vrrPolicy() const;
/** The new value for rgbRange */
OutputDeviceV2Interface::RgbRange rgbRange() const;
private:
friend class OutputConfigurationV2Interface;
explicit OutputChangeSetV2(OutputDeviceV2Interface *outputdevice);
std::unique_ptr<OutputChangeSetV2Private> d;
};
}
/*
SPDX-FileCopyrightText: 2015 Sebastian Kügler <sebas@kde.org>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
#pragma once
#include "outputchangeset_v2.h"
namespace KWaylandServer
{
class OutputChangeSetV2Private
{
public:
OutputChangeSetV2Private(OutputDeviceV2Interface *outputdevice, OutputChangeSetV2 *parent);
OutputChangeSetV2 *q;
OutputDeviceV2Interface *outputDevice;
bool enabled;
QSize size;
int refreshRate;
OutputDeviceV2Interface::Transform transform;
QPoint position;
qreal scale;
uint32_t overscan;
OutputDeviceV2Interface::VrrPolicy vrrPolicy = OutputDeviceV2Interface::VrrPolicy::Automatic;
OutputDeviceV2Interface::RgbRange rgbRange = OutputDeviceV2Interface::RgbRange::Automatic;
};
}
......@@ -26,7 +26,7 @@ static const quint32 s_version = 2;
class OutputDeviceV2InterfacePrivate : public QtWaylandServer::kde_output_device_v2
{
public:
OutputDeviceV2InterfacePrivate(OutputDeviceV2Interface *q, Display *display);
OutputDeviceV2InterfacePrivate(OutputDeviceV2Interface *q, Display *display, KWin::Output *handle);
~OutputDeviceV2InterfacePrivate() override;
void updateGeometry();
......@@ -47,6 +47,9 @@ public:
void sendVrrPolicy(Resource *resource);
void sendRgbRange(Resource *resource);
OutputDeviceV2Interface *q;
QPointer<Display> display;
KWin::Output *handle;
QSize physicalSize;
QPoint globalPosition;
QString manufacturer = QStringLiteral("org.kde.kwin");
......@@ -69,9 +72,6 @@ public:
OutputDeviceV2Interface::VrrPolicy vrrPolicy = OutputDeviceV2Interface::VrrPolicy::Automatic;
OutputDeviceV2Interface::RgbRange rgbRange = OutputDeviceV2Interface::RgbRange::Automatic;
QPointer<Display> display;
OutputDeviceV2Interface *q;
private:
int32_t toTransform() const;
int32_t toSubPixel() const;
......@@ -89,7 +89,7 @@ public:
OutputDeviceV2InterfacePrivate::Resource *output;
};
OutputDeviceModeV2InterfacePrivate(OutputDeviceModeV2Interface *q, const QSize &size, int refreshRate, OutputDeviceModeV2Interface::ModeFlags flags);
OutputDeviceModeV2InterfacePrivate(OutputDeviceModeV2Interface *q, std::weak_ptr<KWin::OutputMode> handle, const QSize &size, int refreshRate, OutputDeviceModeV2Interface::ModeFlags flags);
~OutputDeviceModeV2InterfacePrivate() override;
Resource *createResource(OutputDeviceV2InterfacePrivate::Resource *output);
......@@ -103,7 +103,7 @@ public:
}
OutputDeviceModeV2Interface *q;
std::weak_ptr<KWin::OutputMode> m_handle;
QSize m_size;
int m_refreshRate = 60000;
OutputDeviceModeV2Interface::ModeFlags m_flags;
......@@ -112,10 +112,11 @@ protected:
Resource *kde_output_device_mode_v2_allocate() override;
};
OutputDeviceV2InterfacePrivate::OutputDeviceV2InterfacePrivate(OutputDeviceV2Interface *q, Display *display)
OutputDeviceV2InterfacePrivate::OutputDeviceV2InterfacePrivate(OutputDeviceV2Interface *q, Display *display, KWin::Output *handle)
: QtWaylandServer::kde_output_device_v2(*display, s_version)
, display(display)
, q(q)
, display(display)
, handle(handle)
{
DisplayPrivate *displayPrivate = DisplayPrivate::get(display);
displayPrivate->outputdevicesV2.append(q);
......@@ -129,9 +130,9 @@ OutputDeviceV2InterfacePrivate::~OutputDeviceV2InterfacePrivate()
}
}
OutputDeviceV2Interface::OutputDeviceV2Interface(Display *display, QObject *parent)
OutputDeviceV2Interface::OutputDeviceV2Interface(Display *display, KWin::Output *handle, QObject *parent)
: QObject(parent)
, d(new OutputDeviceV2InterfacePrivate(this, display))
, d(new OutputDeviceV2InterfacePrivate(this, display, handle))
{
}
......@@ -154,6 +155,11 @@ void OutputDeviceV2Interface::remove()
d->globalRemove();
}
KWin::Output *OutputDeviceV2Interface::handle() const
{
return d->handle;
}
QSize OutputDeviceV2Interface::pixelSize() const
{
if (d->currentMode == nullptr) {
......@@ -688,18 +694,19 @@ OutputDeviceV2Interface *OutputDeviceV2Interface::get(wl_resource *native)
return nullptr;
}
OutputDeviceModeV2InterfacePrivate::OutputDeviceModeV2InterfacePrivate(OutputDeviceModeV2Interface *q, const QSize &size, int refreshRate, OutputDeviceModeV2Interface::ModeFlags flags)
OutputDeviceModeV2InterfacePrivate::OutputDeviceModeV2InterfacePrivate(OutputDeviceModeV2Interface *q, std::weak_ptr<KWin::OutputMode> handle, const QSize &size, int refreshRate, OutputDeviceModeV2Interface::ModeFlags flags)
: QtWaylandServer::kde_output_device_mode_v2()
, q(q)
, m_handle(handle)
, m_size(size)
, m_refreshRate(refreshRate)
, m_flags(flags)
{
}
OutputDeviceModeV2Interface::OutputDeviceModeV2Interface(const QSize &size, int refreshRate, ModeFlags flags, QObject *parent)
OutputDeviceModeV2Interface::OutputDeviceModeV2Interface(std::weak_ptr<KWin::OutputMode> handle, const QSize &size, int refreshRate, ModeFlags flags, QObject *parent)
: QObject(parent)
, d(new OutputDeviceModeV2InterfacePrivate(this, size, refreshRate, flags))
, d(new OutputDeviceModeV2InterfacePrivate(this, handle, size, refreshRate, flags))
{
}
......@@ -737,6 +744,11 @@ OutputDeviceModeV2InterfacePrivate::Resource *OutputDeviceModeV2InterfacePrivate
return new ModeResource;
}
std::weak_ptr<KWin::OutputMode> OutputDeviceModeV2Interface::handle() const
{
return d->m_handle;
}
QSize OutputDeviceModeV2Interface::size() const
{
return d->m_size;
......
......@@ -17,6 +17,12 @@
struct wl_resource;
namespace KWin
{
class Output;
class OutputMode;
}
namespace KWaylandServer
{
......@@ -76,11 +82,12 @@ public:
};
Q_ENUM(RgbRange)
explicit OutputDeviceV2Interface(Display *display, QObject *parent = nullptr);
explicit OutputDeviceV2Interface(Display *display, KWin::Output *handle, QObject *parent = nullptr);
~OutputDeviceV2Interface() override;
void remove();
KWin::Output *handle() const;
QSize physicalSize() const;
QPoint globalPosition() const;
QString manufacturer() const;
......@@ -159,9 +166,10 @@ public:
Q_ENUM(ModeFlag)
Q_DECLARE_FLAGS(ModeFlags, ModeFlag)
OutputDeviceModeV2Interface(const QSize &size, int refreshRate, ModeFlags flags, QObject *parent = nullptr);
OutputDeviceModeV2Interface(std::weak_ptr<KWin::OutputMode> handle, const QSize &size, int refreshRate, ModeFlags flags, QObject *parent = nullptr);
~OutputDeviceModeV2Interface() override;
std::weak_ptr<KWin::OutputMode> handle() const;
QSize size() const;
int refreshRate() const;
OutputDeviceModeV2Interface::ModeFlags flags() const;
......
......@@ -6,8 +6,6 @@
*/
#include "outputmanagement_v2_interface.h"
#include "display.h"
#include "outputchangeset_v2.h"
#include "outputchangeset_v2_p.h"
#include "outputdevice_v2_interface.h"
#include "outputmanagement_v2_interface.h"
#include "utils/common.h"
......@@ -42,12 +40,9 @@ class OutputConfigurationV2Interface : public QtWaylandServer::kde_output_config
{
public:
explicit OutputConfigurationV2Interface(wl_resource *resource);
~OutputConfigurationV2Interface() override;
OutputChangeSetV2 *pendingChanges(OutputDeviceV2Interface *outputdevice);
bool applied = false;
QHash<OutputDeviceV2Interface *, OutputChangeSetV2 *> changes;
OutputConfiguration config;
std::optional<OutputDeviceV2Interface *> primaryOutput;
protected:
......@@ -93,26 +88,12 @@ OutputConfigurationV2Interface::OutputConfigurationV2Interface(wl_resource *reso
{
}
OutputConfigurationV2Interface::~OutputConfigurationV2Interface()
{
qDeleteAll(changes.begin(), changes.end());
}
OutputChangeSetV2 *OutputConfigurationV2Interface::pendingChanges(OutputDeviceV2Interface *outputdevice)
{
auto &change = changes[outputdevice];
if (!change) {
change = new OutputChangeSetV2(outputdevice);
}
return change;
}
void OutputConfigurationV2Interface::kde_output_configuration_v2_enable(Resource *resource, wl_resource *outputdevice, int32_t enable)
{
Q_UNUSED(resource)
OutputDeviceV2Interface *output = OutputDeviceV2Interface::get(outputdevice);
pendingChanges(output)->d->enabled = enable == 1;
config.changeSet(output->handle())->enabled = enable;
}
void OutputConfigurationV2Interface::kde_output_configuration_v2_mode(Resource *resource, wl_resource *outputdevice, wl_resource *modeResource)
......@@ -124,8 +105,7 @@ void OutputConfigurationV2Interface::kde_output_configuration_v2_mode(Resource *
return;
}
pendingChanges(output)->d->size = mode->size();
pendingChanges(output)->d->refreshRate = mode->refreshRate();
config.changeSet(output->handle())->mode = mode->handle().lock();
}
void OutputConfigurationV2Interface::kde_output_configuration_v2_transform(Resource *resource, wl_resource *outputdevice, int32_t transform)
......@@ -134,35 +114,34 @@ void OutputConfigurationV2Interface::kde_output_configuration_v2_transform(Resou
auto toTransform = [transform]() {
switch (transform) {
case WL_OUTPUT_TRANSFORM_90:
return OutputDeviceV2Interface::Transform::Rotated90;
return Output::Transform::Rotated90;
case WL_OUTPUT_TRANSFORM_180:
return OutputDeviceV2Interface::Transform::Rotated180;
return Output::Transform::Rotated180;
case WL_OUTPUT_TRANSFORM_270:
return OutputDeviceV2Interface::Transform::Rotated270;
return Output::Transform::Rotated270;
case WL_OUTPUT_TRANSFORM_FLIPPED:
return OutputDeviceV2Interface::Transform::Flipped;
return Output::Transform::Flipped;
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
return OutputDeviceV2Interface::Transform::Flipped90;
return Output::Transform::Flipped90;
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
return OutputDeviceV2Interface::Transform::Flipped180;
return Output::Transform::Flipped180;
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
return OutputDeviceV2Interface::Transform::Flipped270;
return Output::Transform::Flipped270;
case WL_OUTPUT_TRANSFORM_NORMAL:
default:
return OutputDeviceV2Interface::Transform::Normal;
return Output::Transform::Normal;
}
};
auto _transform = toTransform();
OutputDeviceV2Interface *output = OutputDeviceV2Interface::get(outputdevice);
pendingChanges(output)->d->transform = _transform;
config.changeSet(output->handle())->transform = _transform;
}
void OutputConfigurationV2Interface::kde_output_configuration_v2_position(Resource *resource, wl_resource *outputdevice, int32_t x, int32_t y)
{
Q_UNUSED(resource)
auto _pos = QPoint(x, y);
OutputDeviceV2Interface *output = OutputDeviceV2Interface::get(outputdevice);
pendingChanges(output)->d->position = _pos;
config.changeSet(output->handle())->pos = QPoint(x, y);
}
void OutputConfigurationV2Interface::kde_output_configuration_v2_scale(Resource *resource, wl_resource *outputdevice, wl_fixed_t scale)
......@@ -174,9 +153,9 @@ void OutputConfigurationV2Interface::kde_output_configuration_v2_scale(Resource
qCWarning(KWIN_CORE) << "Requested to scale output device to" << doubleScale << ", but I can't do that.";
return;
}
OutputDeviceV2Interface *output = OutputDeviceV2Interface::get(outputdevice);
pendingChanges(output)->d->scale = doubleScale;
OutputDeviceV2Interface *output = OutputDeviceV2Interface::get(outputdevice);
config.changeSet(output->handle())->scale = doubleScale;
}
void OutputConfigurationV2Interface::kde_output_configuration_v2_overscan(Resource *resource, wl_resource *outputdevice, uint32_t overscan)
......@@ -187,29 +166,29 @@ void OutputConfigurationV2Interface::kde_output_configuration_v2_overscan(Resour
return;
}
OutputDeviceV2Interface *output = OutputDeviceV2Interface::get(outputdevice);
pendingChanges(output)->d->overscan = overscan;
config.changeSet(output->handle())->overscan = overscan;
}
void OutputConfigurationV2Interface::kde_output_configuration_v2_set_vrr_policy(Resource *resource, wl_resource *outputdevice, uint32_t policy)
{
Q_UNUSED(resource)
if (policy > static_cast<uint32_t>(OutputDeviceV2Interface::VrrPolicy::Automatic)) {
if (policy > static_cast<uint32_t>(RenderLoop::VrrPolicy::Automatic)) {
qCWarning(KWIN_CORE) << "Invalid Vrr Policy requested:" << policy;
return;
}
OutputDeviceV2Interface *output = OutputDeviceV2Interface::get(outputdevice);
pendingChanges(output)->d->vrrPolicy = static_cast<OutputDeviceV2Interface::VrrPolicy>(policy);
config.changeSet(output->handle())->vrrPolicy = static_cast<RenderLoop::VrrPolicy>(policy);
}
void OutputConfigurationV2Interface::kde_output_configuration_v2_set_rgb_range(Resource *resource, wl_resource *outputdevice, uint32_t rgbRange)
{
Q_UNUSED(resource)
if (rgbRange > static_cast<uint32_t>(OutputDeviceV2Interface::RgbRange::Limited)) {
if (rgbRange > static_cast<uint32_t>(Output::RgbRange::Limited)) {
qCWarning(KWIN_CORE) << "Invalid Rgb Range requested:" << rgbRange;
return;
}
OutputDeviceV2Interface *output = OutputDeviceV2Interface::get(outputdevice);
pendingChanges(output)->d->rgbRange = static_cast<OutputDeviceV2Interface::RgbRange>(rgbRange);
config.changeSet(output->handle())->rgbRange = static_cast<Output::RgbRange>(rgbRange);
}
void OutputConfigurationV2Interface::kde_output_configuration_v2_set_primary_output(Resource *resource, struct ::wl_resource *output)
......@@ -238,39 +217,9 @@ void OutputConfigurationV2Interface::kde_output_configuration_v2_apply(Resource
applied = true;
OutputConfiguration cfg;
for (auto it = changes.constBegin(); it != changes.constEnd(); ++it) {
const KWaylandServer::OutputChangeSetV2 *changeset = it.value();
auto output = kwinApp()->platform()->findOutput(it.key()->uuid());
if (!output) {
qCWarning(KWIN_CORE) << "Could NOT find output matching " << it.key()->uuid();
continue;
}
const auto modes = output->modes();
const auto modeIt = std::find_if(modes.begin(), modes.end(), [&changeset](const auto &mode) {
return mode->size() == changeset->size() && mode->refreshRate() == changeset->refreshRate();
});