2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2016 Roman Gilg <subdiff@gmail.com>
|
2021-05-25 21:08:31 +00:00
|
|
|
SPDX-FileCopyrightText: 2021 Xaver Hugl <xaver.hugl@gmail.com>
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-08-31 12:00:31 +00:00
|
|
|
#include "drm_object_connector.h"
|
2021-04-01 11:15:42 +00:00
|
|
|
#include "drm_gpu.h"
|
[DRM plugin] Remember static kernel objects, amplify use of DrmCrtc
To get an image from KWin to the screen in the DRM pipeline we combine a CRTC,
an encoder and a connector. These objects are static in the sense, that they
represent real hardware on the graphics card, which doesn't change in a
session. See here for more details:
https://01.org/linuxgraphics/gfx-docs/drm/gpu/drm-kms.html
Until now we used DrmOutput as the main representation for such an active
rendering pipeline. I.e. it gets created and destroyed on hot plug events of
displays. On the other side we had no fixed representation of the static kernel
objects throughout the lifetime of KWin. This has several disadvantages:
* We always need to query all available static objects on an hot plug event.
* We can't manipulate the frame buffer of a CRTC after an output has been
disconnected
* Adding functionality for driving multiple displays on a single CRTC (i.e.
cloning) would be difficult
* We can't destroy the last frame buffer on display disconnect because the CRTC
still accesses it and have therefore a memory leak on every display disconnect
This patch solves these issues by storing representations of all available CRTC
and Connector objects in DrmBackend on init via DrmCrtc and DrmConnector
instances. On an hotplug event these vectors are looped for a fitting CRTC and
Connector combinations. Buffer handling is moved to the respective CRTC
instance. All changes in overview:
* Query all available CRTCs and Connectors and save for subsequent hotplug
events
* Fix logic errors in `queryResources()`
* Move framebuffers, buffer flip and blank logic in DrmCrtc
* Remove `restoreSaved()`. It isn't necessary and is dangerous if the old
framebuffer was deleted in the meantime. Also could reveal sensitive user
info from old session.
Test Plan:
Login, logout, VT switching, connect and disconnect external monitor, energy
saving mode.
Reviewers: #kwin
Subscribers: kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D5118
2017-05-09 18:02:49 +00:00
|
|
|
#include "drm_pointer.h"
|
2016-08-31 12:00:31 +00:00
|
|
|
#include "logging.h"
|
2021-03-31 11:22:23 +00:00
|
|
|
|
|
|
|
#include <main.h>
|
|
|
|
// frameworks
|
|
|
|
#include <KConfigGroup>
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2021-06-29 08:32:06 +00:00
|
|
|
#include <cerrno>
|
|
|
|
|
2016-08-31 12:00:31 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2021-04-01 11:21:37 +00:00
|
|
|
DrmConnector::DrmConnector(DrmGpu *gpu, uint32_t connectorId)
|
2021-06-03 13:50:37 +00:00
|
|
|
: DrmObject(gpu, connectorId, {
|
2021-08-27 16:56:05 +00:00
|
|
|
PropertyDefinition(QByteArrayLiteral("CRTC_ID"), Requirement::Required),
|
|
|
|
PropertyDefinition(QByteArrayLiteral("non-desktop"), Requirement::Optional),
|
2021-09-16 12:03:10 +00:00
|
|
|
PropertyDefinition(QByteArrayLiteral("DPMS"), Requirement::RequiredForLegacy),
|
2021-08-27 16:56:05 +00:00
|
|
|
PropertyDefinition(QByteArrayLiteral("EDID"), Requirement::Optional),
|
|
|
|
PropertyDefinition(QByteArrayLiteral("overscan"), Requirement::Optional),
|
|
|
|
PropertyDefinition(QByteArrayLiteral("vrr_capable"), Requirement::Optional),
|
|
|
|
PropertyDefinition(QByteArrayLiteral("underscan"), Requirement::Optional, {
|
2021-06-03 13:50:37 +00:00
|
|
|
QByteArrayLiteral("off"),
|
|
|
|
QByteArrayLiteral("on"),
|
|
|
|
QByteArrayLiteral("auto")
|
|
|
|
}),
|
2021-08-27 16:56:05 +00:00
|
|
|
PropertyDefinition(QByteArrayLiteral("underscan vborder"), Requirement::Optional),
|
|
|
|
PropertyDefinition(QByteArrayLiteral("underscan hborder"), Requirement::Optional),
|
2021-08-31 14:59:06 +00:00
|
|
|
PropertyDefinition(QByteArrayLiteral("Broadcast RGB"), Requirement::Optional, {
|
|
|
|
QByteArrayLiteral("Automatic"),
|
|
|
|
QByteArrayLiteral("Full"),
|
|
|
|
QByteArrayLiteral("Limited 16:235")
|
|
|
|
}),
|
2021-06-03 13:50:37 +00:00
|
|
|
}, DRM_MODE_OBJECT_CONNECTOR)
|
2021-04-01 11:21:37 +00:00
|
|
|
, m_conn(drmModeGetConnector(gpu->fd(), connectorId))
|
2016-08-31 12:00:31 +00:00
|
|
|
{
|
2021-06-28 14:40:12 +00:00
|
|
|
if (m_conn) {
|
|
|
|
for (int i = 0; i < m_conn->count_encoders; ++i) {
|
|
|
|
m_encoders << m_conn->encoders[i];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qCWarning(KWIN_DRM) << "drmModeGetConnector failed!" << strerror(errno);
|
[DRM plugin] Remember static kernel objects, amplify use of DrmCrtc
To get an image from KWin to the screen in the DRM pipeline we combine a CRTC,
an encoder and a connector. These objects are static in the sense, that they
represent real hardware on the graphics card, which doesn't change in a
session. See here for more details:
https://01.org/linuxgraphics/gfx-docs/drm/gpu/drm-kms.html
Until now we used DrmOutput as the main representation for such an active
rendering pipeline. I.e. it gets created and destroyed on hot plug events of
displays. On the other side we had no fixed representation of the static kernel
objects throughout the lifetime of KWin. This has several disadvantages:
* We always need to query all available static objects on an hot plug event.
* We can't manipulate the frame buffer of a CRTC after an output has been
disconnected
* Adding functionality for driving multiple displays on a single CRTC (i.e.
cloning) would be difficult
* We can't destroy the last frame buffer on display disconnect because the CRTC
still accesses it and have therefore a memory leak on every display disconnect
This patch solves these issues by storing representations of all available CRTC
and Connector objects in DrmBackend on init via DrmCrtc and DrmConnector
instances. On an hotplug event these vectors are looped for a fitting CRTC and
Connector combinations. Buffer handling is moved to the respective CRTC
instance. All changes in overview:
* Query all available CRTCs and Connectors and save for subsequent hotplug
events
* Fix logic errors in `queryResources()`
* Move framebuffers, buffer flip and blank logic in DrmCrtc
* Remove `restoreSaved()`. It isn't necessary and is dangerous if the old
framebuffer was deleted in the meantime. Also could reveal sensitive user
info from old session.
Test Plan:
Login, logout, VT switching, connect and disconnect external monitor, energy
saving mode.
Reviewers: #kwin
Subscribers: kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D5118
2017-05-09 18:02:49 +00:00
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DrmConnector::~DrmConnector() = default;
|
|
|
|
|
2021-05-25 21:08:31 +00:00
|
|
|
namespace {
|
|
|
|
quint64 refreshRateForMode(_drmModeModeInfo *m)
|
|
|
|
{
|
|
|
|
// Calculate higher precision (mHz) refresh rate
|
|
|
|
// logic based on Weston, see compositor-drm.c
|
|
|
|
quint64 refreshRate = (m->clock * 1000000LL / m->htotal + m->vtotal / 2) / m->vtotal;
|
|
|
|
if (m->flags & DRM_MODE_FLAG_INTERLACE) {
|
|
|
|
refreshRate *= 2;
|
|
|
|
}
|
|
|
|
if (m->flags & DRM_MODE_FLAG_DBLSCAN) {
|
|
|
|
refreshRate /= 2;
|
|
|
|
}
|
|
|
|
if (m->vscan > 1) {
|
|
|
|
refreshRate /= m->vscan;
|
|
|
|
}
|
|
|
|
return refreshRate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-26 20:23:44 +00:00
|
|
|
bool DrmConnector::init()
|
2016-08-31 12:00:31 +00:00
|
|
|
{
|
2021-06-28 14:40:12 +00:00
|
|
|
if (!m_conn || !m_conn->count_modes) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2021-06-03 13:50:37 +00:00
|
|
|
if (!initProps()) {
|
2021-03-31 11:22:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-09-16 12:03:10 +00:00
|
|
|
if (const auto &dpms = getProp(PropertyIndex::Dpms)) {
|
|
|
|
dpms->setLegacy();
|
2021-04-19 22:42:37 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 21:28:08 +00:00
|
|
|
auto underscan = m_props[static_cast<uint32_t>(PropertyIndex::Underscan)];
|
|
|
|
auto vborder = m_props[static_cast<uint32_t>(PropertyIndex::Underscan_vborder)];
|
|
|
|
auto hborder = m_props[static_cast<uint32_t>(PropertyIndex::Underscan_hborder)];
|
|
|
|
if (underscan && vborder && hborder) {
|
2021-05-25 22:05:17 +00:00
|
|
|
underscan->setEnum(vborder->current() > 0 ? UnderscanOptions::On : UnderscanOptions::Off);
|
2021-06-22 21:28:08 +00:00
|
|
|
} else {
|
|
|
|
deleteProp(PropertyIndex::Underscan);
|
|
|
|
deleteProp(PropertyIndex::Underscan_vborder);
|
|
|
|
deleteProp(PropertyIndex::Underscan_hborder);
|
|
|
|
}
|
|
|
|
|
2021-03-31 11:22:23 +00:00
|
|
|
// parse edid
|
2021-05-25 22:05:17 +00:00
|
|
|
auto edidProp = getProp(PropertyIndex::Edid);
|
2021-09-27 18:43:26 +00:00
|
|
|
if (edidProp) {
|
|
|
|
DrmScopedPointer<drmModePropertyBlobRes> blob(drmModeGetPropertyBlob(gpu()->fd(), edidProp->current()));
|
|
|
|
if (blob && blob->data) {
|
|
|
|
m_edid = Edid(blob->data, blob->length);
|
|
|
|
if (!m_edid.isValid()) {
|
2021-10-04 16:21:56 +00:00
|
|
|
qCWarning(KWIN_DRM) << "Couldn't parse EDID for connector" << this;
|
2021-09-27 18:43:26 +00:00
|
|
|
}
|
2021-03-31 11:22:23 +00:00
|
|
|
}
|
2021-09-27 18:43:26 +00:00
|
|
|
deleteProp(PropertyIndex::Edid);
|
2021-03-31 11:22:23 +00:00
|
|
|
} else {
|
2021-04-01 10:20:15 +00:00
|
|
|
qCDebug(KWIN_DRM) << "Could not find edid for connector" << this;
|
2021-03-31 11:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// check the physical size
|
2021-04-01 10:09:37 +00:00
|
|
|
if (m_edid.physicalSize().isEmpty()) {
|
2021-03-31 11:22:23 +00:00
|
|
|
m_physicalSize = QSize(m_conn->mmWidth, m_conn->mmHeight);
|
|
|
|
} else {
|
2021-04-01 10:09:37 +00:00
|
|
|
m_physicalSize = m_edid.physicalSize();
|
2021-03-31 11:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// the size might be completely borked. E.g. Samsung SyncMaster 2494HS reports 160x90 while in truth it's 520x292
|
|
|
|
// as this information is used to calculate DPI info, it's going to result in everything being huge
|
|
|
|
const QByteArray unknown = QByteArrayLiteral("unknown");
|
2021-04-01 10:09:37 +00:00
|
|
|
KConfigGroup group = kwinApp()->config()->group("EdidOverwrite").group(m_edid.eisaId().isEmpty() ? unknown : m_edid.eisaId())
|
|
|
|
.group(m_edid.monitorName().isEmpty() ? unknown : m_edid.monitorName())
|
|
|
|
.group(m_edid.serialNumber().isEmpty() ? unknown : m_edid.serialNumber());
|
2021-03-31 11:22:23 +00:00
|
|
|
if (group.hasKey("PhysicalSize")) {
|
|
|
|
const QSize overwriteSize = group.readEntry("PhysicalSize", m_physicalSize);
|
2021-04-01 10:09:37 +00:00
|
|
|
qCWarning(KWIN_DRM) << "Overwriting monitor physical size for" << m_edid.eisaId() << "/" << m_edid.monitorName() << "/" << m_edid.serialNumber() << " from " << m_physicalSize << "to " << overwriteSize;
|
2021-03-31 11:22:23 +00:00
|
|
|
m_physicalSize = overwriteSize;
|
|
|
|
}
|
|
|
|
|
2021-05-25 21:08:31 +00:00
|
|
|
// init modes
|
2021-07-21 10:11:21 +00:00
|
|
|
updateModes();
|
2021-05-25 21:08:31 +00:00
|
|
|
|
2021-03-31 11:22:23 +00:00
|
|
|
return true;
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
|
2021-09-02 13:21:57 +00:00
|
|
|
bool DrmConnector::isConnected() const
|
[DRM plugin] Remember static kernel objects, amplify use of DrmCrtc
To get an image from KWin to the screen in the DRM pipeline we combine a CRTC,
an encoder and a connector. These objects are static in the sense, that they
represent real hardware on the graphics card, which doesn't change in a
session. See here for more details:
https://01.org/linuxgraphics/gfx-docs/drm/gpu/drm-kms.html
Until now we used DrmOutput as the main representation for such an active
rendering pipeline. I.e. it gets created and destroyed on hot plug events of
displays. On the other side we had no fixed representation of the static kernel
objects throughout the lifetime of KWin. This has several disadvantages:
* We always need to query all available static objects on an hot plug event.
* We can't manipulate the frame buffer of a CRTC after an output has been
disconnected
* Adding functionality for driving multiple displays on a single CRTC (i.e.
cloning) would be difficult
* We can't destroy the last frame buffer on display disconnect because the CRTC
still accesses it and have therefore a memory leak on every display disconnect
This patch solves these issues by storing representations of all available CRTC
and Connector objects in DrmBackend on init via DrmCrtc and DrmConnector
instances. On an hotplug event these vectors are looped for a fitting CRTC and
Connector combinations. Buffer handling is moved to the respective CRTC
instance. All changes in overview:
* Query all available CRTCs and Connectors and save for subsequent hotplug
events
* Fix logic errors in `queryResources()`
* Move framebuffers, buffer flip and blank logic in DrmCrtc
* Remove `restoreSaved()`. It isn't necessary and is dangerous if the old
framebuffer was deleted in the meantime. Also could reveal sensitive user
info from old session.
Test Plan:
Login, logout, VT switching, connect and disconnect external monitor, energy
saving mode.
Reviewers: #kwin
Subscribers: kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D5118
2017-05-09 18:02:49 +00:00
|
|
|
{
|
2021-05-25 21:08:31 +00:00
|
|
|
if (!m_conn) {
|
[DRM plugin] Remember static kernel objects, amplify use of DrmCrtc
To get an image from KWin to the screen in the DRM pipeline we combine a CRTC,
an encoder and a connector. These objects are static in the sense, that they
represent real hardware on the graphics card, which doesn't change in a
session. See here for more details:
https://01.org/linuxgraphics/gfx-docs/drm/gpu/drm-kms.html
Until now we used DrmOutput as the main representation for such an active
rendering pipeline. I.e. it gets created and destroyed on hot plug events of
displays. On the other side we had no fixed representation of the static kernel
objects throughout the lifetime of KWin. This has several disadvantages:
* We always need to query all available static objects on an hot plug event.
* We can't manipulate the frame buffer of a CRTC after an output has been
disconnected
* Adding functionality for driving multiple displays on a single CRTC (i.e.
cloning) would be difficult
* We can't destroy the last frame buffer on display disconnect because the CRTC
still accesses it and have therefore a memory leak on every display disconnect
This patch solves these issues by storing representations of all available CRTC
and Connector objects in DrmBackend on init via DrmCrtc and DrmConnector
instances. On an hotplug event these vectors are looped for a fitting CRTC and
Connector combinations. Buffer handling is moved to the respective CRTC
instance. All changes in overview:
* Query all available CRTCs and Connectors and save for subsequent hotplug
events
* Fix logic errors in `queryResources()`
* Move framebuffers, buffer flip and blank logic in DrmCrtc
* Remove `restoreSaved()`. It isn't necessary and is dangerous if the old
framebuffer was deleted in the meantime. Also could reveal sensitive user
info from old session.
Test Plan:
Login, logout, VT switching, connect and disconnect external monitor, energy
saving mode.
Reviewers: #kwin
Subscribers: kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D5118
2017-05-09 18:02:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-05-25 21:08:31 +00:00
|
|
|
return m_conn->connection == DRM_MODE_CONNECTED;
|
[DRM plugin] Remember static kernel objects, amplify use of DrmCrtc
To get an image from KWin to the screen in the DRM pipeline we combine a CRTC,
an encoder and a connector. These objects are static in the sense, that they
represent real hardware on the graphics card, which doesn't change in a
session. See here for more details:
https://01.org/linuxgraphics/gfx-docs/drm/gpu/drm-kms.html
Until now we used DrmOutput as the main representation for such an active
rendering pipeline. I.e. it gets created and destroyed on hot plug events of
displays. On the other side we had no fixed representation of the static kernel
objects throughout the lifetime of KWin. This has several disadvantages:
* We always need to query all available static objects on an hot plug event.
* We can't manipulate the frame buffer of a CRTC after an output has been
disconnected
* Adding functionality for driving multiple displays on a single CRTC (i.e.
cloning) would be difficult
* We can't destroy the last frame buffer on display disconnect because the CRTC
still accesses it and have therefore a memory leak on every display disconnect
This patch solves these issues by storing representations of all available CRTC
and Connector objects in DrmBackend on init via DrmCrtc and DrmConnector
instances. On an hotplug event these vectors are looped for a fitting CRTC and
Connector combinations. Buffer handling is moved to the respective CRTC
instance. All changes in overview:
* Query all available CRTCs and Connectors and save for subsequent hotplug
events
* Fix logic errors in `queryResources()`
* Move framebuffers, buffer flip and blank logic in DrmCrtc
* Remove `restoreSaved()`. It isn't necessary and is dangerous if the old
framebuffer was deleted in the meantime. Also could reveal sensitive user
info from old session.
Test Plan:
Login, logout, VT switching, connect and disconnect external monitor, energy
saving mode.
Reviewers: #kwin
Subscribers: kwin, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D5118
2017-05-09 18:02:49 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 11:22:23 +00:00
|
|
|
static QHash<int, QByteArray> s_connectorNames = {
|
|
|
|
{DRM_MODE_CONNECTOR_Unknown, QByteArrayLiteral("Unknown")},
|
|
|
|
{DRM_MODE_CONNECTOR_VGA, QByteArrayLiteral("VGA")},
|
|
|
|
{DRM_MODE_CONNECTOR_DVII, QByteArrayLiteral("DVI-I")},
|
|
|
|
{DRM_MODE_CONNECTOR_DVID, QByteArrayLiteral("DVI-D")},
|
|
|
|
{DRM_MODE_CONNECTOR_DVIA, QByteArrayLiteral("DVI-A")},
|
|
|
|
{DRM_MODE_CONNECTOR_Composite, QByteArrayLiteral("Composite")},
|
|
|
|
{DRM_MODE_CONNECTOR_SVIDEO, QByteArrayLiteral("SVIDEO")},
|
|
|
|
{DRM_MODE_CONNECTOR_LVDS, QByteArrayLiteral("LVDS")},
|
|
|
|
{DRM_MODE_CONNECTOR_Component, QByteArrayLiteral("Component")},
|
|
|
|
{DRM_MODE_CONNECTOR_9PinDIN, QByteArrayLiteral("DIN")},
|
|
|
|
{DRM_MODE_CONNECTOR_DisplayPort, QByteArrayLiteral("DP")},
|
|
|
|
{DRM_MODE_CONNECTOR_HDMIA, QByteArrayLiteral("HDMI-A")},
|
|
|
|
{DRM_MODE_CONNECTOR_HDMIB, QByteArrayLiteral("HDMI-B")},
|
|
|
|
{DRM_MODE_CONNECTOR_TV, QByteArrayLiteral("TV")},
|
|
|
|
{DRM_MODE_CONNECTOR_eDP, QByteArrayLiteral("eDP")},
|
|
|
|
{DRM_MODE_CONNECTOR_VIRTUAL, QByteArrayLiteral("Virtual")},
|
|
|
|
{DRM_MODE_CONNECTOR_DSI, QByteArrayLiteral("DSI")},
|
|
|
|
#ifdef DRM_MODE_CONNECTOR_DPI
|
|
|
|
{DRM_MODE_CONNECTOR_DPI, QByteArrayLiteral("DPI")},
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
QString DrmConnector::connectorName() const
|
|
|
|
{
|
|
|
|
return s_connectorNames.value(m_conn->connector_type, QByteArrayLiteral("Unknown")) + QStringLiteral("-") + QString::number(m_conn->connector_type_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DrmConnector::modelName() const
|
|
|
|
{
|
2021-04-04 23:45:02 +00:00
|
|
|
if (m_edid.serialNumber().isEmpty()) {
|
|
|
|
return connectorName() + QLatin1Char('-') + m_edid.nameString();
|
|
|
|
} else {
|
|
|
|
return m_edid.nameString();
|
|
|
|
}
|
2021-03-31 11:22:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmConnector::isInternal() const
|
|
|
|
{
|
|
|
|
return m_conn->connector_type == DRM_MODE_CONNECTOR_LVDS || m_conn->connector_type == DRM_MODE_CONNECTOR_eDP
|
|
|
|
|| m_conn->connector_type == DRM_MODE_CONNECTOR_DSI;
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize DrmConnector::physicalSize() const
|
|
|
|
{
|
|
|
|
return m_physicalSize;
|
|
|
|
}
|
|
|
|
|
2021-05-25 21:08:31 +00:00
|
|
|
const DrmConnector::Mode &DrmConnector::currentMode() const
|
|
|
|
{
|
|
|
|
return m_modes[m_modeIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
int DrmConnector::currentModeIndex() const
|
|
|
|
{
|
|
|
|
return m_modeIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QVector<DrmConnector::Mode> &DrmConnector::modes()
|
|
|
|
{
|
|
|
|
return m_modes;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmConnector::setModeIndex(int index)
|
|
|
|
{
|
|
|
|
m_modeIndex = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool checkIfEqual(drmModeModeInfo one, drmModeModeInfo two)
|
|
|
|
{
|
|
|
|
return one.clock == two.clock
|
|
|
|
&& one.hdisplay == two.hdisplay
|
|
|
|
&& one.hsync_start == two.hsync_start
|
|
|
|
&& one.hsync_end == two.hsync_end
|
|
|
|
&& one.htotal == two.htotal
|
|
|
|
&& one.hskew == two.hskew
|
|
|
|
&& one.vdisplay == two.vdisplay
|
|
|
|
&& one.vsync_start == two.vsync_start
|
|
|
|
&& one.vsync_end == two.vsync_end
|
|
|
|
&& one.vtotal == two.vtotal
|
|
|
|
&& one.vscan == two.vscan
|
|
|
|
&& one.vrefresh == two.vrefresh;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmConnector::findCurrentMode(drmModeModeInfo currentMode)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < m_modes.count(); i++) {
|
|
|
|
if (checkIfEqual(m_modes[i].mode, currentMode)) {
|
|
|
|
m_modeIndex = i;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_modeIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractWaylandOutput::SubPixel DrmConnector::subpixel() const
|
|
|
|
{
|
|
|
|
switch (m_conn->subpixel) {
|
|
|
|
case DRM_MODE_SUBPIXEL_UNKNOWN:
|
|
|
|
return AbstractWaylandOutput::SubPixel::Unknown;
|
|
|
|
case DRM_MODE_SUBPIXEL_NONE:
|
|
|
|
return AbstractWaylandOutput::SubPixel::None;
|
|
|
|
case DRM_MODE_SUBPIXEL_HORIZONTAL_RGB:
|
|
|
|
return AbstractWaylandOutput::SubPixel::Horizontal_RGB;
|
|
|
|
case DRM_MODE_SUBPIXEL_HORIZONTAL_BGR:
|
|
|
|
return AbstractWaylandOutput::SubPixel::Horizontal_BGR;
|
|
|
|
case DRM_MODE_SUBPIXEL_VERTICAL_RGB:
|
|
|
|
return AbstractWaylandOutput::SubPixel::Vertical_RGB;
|
|
|
|
case DRM_MODE_SUBPIXEL_VERTICAL_BGR:
|
|
|
|
return AbstractWaylandOutput::SubPixel::Vertical_BGR;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 14:26:21 +00:00
|
|
|
bool DrmConnector::hasOverscan() const
|
|
|
|
{
|
2021-05-25 22:05:17 +00:00
|
|
|
return getProp(PropertyIndex::Overscan) || getProp(PropertyIndex::Underscan);
|
2021-04-11 14:26:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t DrmConnector::overscan() const
|
|
|
|
{
|
2021-05-25 22:05:17 +00:00
|
|
|
if (const auto &prop = getProp(PropertyIndex::Overscan)) {
|
|
|
|
return prop->pending();
|
|
|
|
} else if (const auto &prop = getProp(PropertyIndex::Underscan_vborder)) {
|
|
|
|
return prop->pending();
|
2021-04-11 14:26:21 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2021-03-27 14:01:34 +00:00
|
|
|
|
2021-06-22 21:28:08 +00:00
|
|
|
void DrmConnector::setOverscan(uint32_t overscan, const QSize &modeSize)
|
2021-04-11 14:26:21 +00:00
|
|
|
{
|
2021-06-22 21:28:08 +00:00
|
|
|
if (auto prop = m_props[static_cast<uint32_t>(PropertyIndex::Overscan)]) {
|
2021-05-25 22:05:17 +00:00
|
|
|
prop->setPending(overscan);
|
2021-06-22 21:28:08 +00:00
|
|
|
} else if (auto prop = m_props[static_cast<uint32_t>(PropertyIndex::Underscan)]) {
|
|
|
|
float aspectRatio = modeSize.width() / static_cast<float>(modeSize.height());
|
|
|
|
prop->setEnum(overscan > 0 ? UnderscanOptions::On : UnderscanOptions::Off);
|
2021-07-07 16:56:33 +00:00
|
|
|
uint32_t hborder = overscan * aspectRatio;
|
2021-06-22 21:28:08 +00:00
|
|
|
if (hborder > 128) {
|
|
|
|
hborder = 128;
|
2021-07-07 16:56:33 +00:00
|
|
|
overscan = 128 / aspectRatio;
|
2021-06-22 21:28:08 +00:00
|
|
|
}
|
|
|
|
// overscan only goes from 0-100 so we cut off the 101-128 value range of underscan_vborder
|
2021-05-25 22:05:17 +00:00
|
|
|
setPending(PropertyIndex::Underscan_vborder, overscan);
|
|
|
|
setPending(PropertyIndex::Underscan_hborder, hborder);
|
2021-06-22 21:28:08 +00:00
|
|
|
}
|
2021-04-11 14:26:21 +00:00
|
|
|
}
|
2021-03-31 11:22:23 +00:00
|
|
|
|
2021-02-20 15:04:18 +00:00
|
|
|
bool DrmConnector::vrrCapable() const
|
|
|
|
{
|
2021-05-25 22:05:17 +00:00
|
|
|
if (const auto &prop = getProp(PropertyIndex::VrrCapable)) {
|
|
|
|
return prop->pending();
|
2021-02-20 15:04:18 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-05-25 22:05:17 +00:00
|
|
|
bool DrmConnector::needsModeset() const
|
|
|
|
{
|
2021-09-16 22:40:41 +00:00
|
|
|
if (getProp(PropertyIndex::CrtcId)->needsCommit()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const auto &rgb = getProp(PropertyIndex::Broadcast_RGB);
|
|
|
|
return rgb && rgb->needsCommit();
|
2021-05-25 22:05:17 +00:00
|
|
|
}
|
|
|
|
|
2021-07-21 10:11:21 +00:00
|
|
|
void DrmConnector::updateModes()
|
|
|
|
{
|
|
|
|
m_modes.clear();
|
|
|
|
|
|
|
|
// reload modes
|
|
|
|
for (int i = 0; i < m_conn->count_modes; i++) {
|
|
|
|
auto mode = m_conn->modes[i];
|
|
|
|
Mode m;
|
|
|
|
m.mode = mode;
|
|
|
|
m.size = QSize(mode.hdisplay, mode.vdisplay);
|
|
|
|
m.refreshRate = refreshRateForMode(&mode);
|
|
|
|
m_modes << m;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-31 14:59:06 +00:00
|
|
|
bool DrmConnector::hasRgbRange() const
|
|
|
|
{
|
|
|
|
const auto &rgb = getProp(PropertyIndex::Broadcast_RGB);
|
|
|
|
return rgb && rgb->hasAllEnums();
|
|
|
|
}
|
|
|
|
|
|
|
|
AbstractWaylandOutput::RgbRange DrmConnector::rgbRange() const
|
|
|
|
{
|
|
|
|
const auto &rgb = getProp(PropertyIndex::Broadcast_RGB);
|
|
|
|
return rgb->enumForValue<AbstractWaylandOutput::RgbRange>(rgb->pending());
|
|
|
|
}
|
2021-07-21 10:11:21 +00:00
|
|
|
|
2021-09-02 13:21:57 +00:00
|
|
|
bool DrmConnector::updateProperties()
|
|
|
|
{
|
|
|
|
if (!DrmObject::updateProperties()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
m_conn.reset(drmModeGetConnector(gpu()->fd(), id()));
|
|
|
|
return m_conn != nullptr;
|
|
|
|
}
|
|
|
|
|
2021-09-22 11:26:19 +00:00
|
|
|
QVector<uint32_t> DrmConnector::encoders() const
|
|
|
|
{
|
|
|
|
return m_encoders;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmConnector::isNonDesktop() const
|
|
|
|
{
|
|
|
|
const auto &prop = getProp(PropertyIndex::NonDesktop);
|
|
|
|
return prop && prop->current();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Edid *DrmConnector::edid() const
|
|
|
|
{
|
|
|
|
return &m_edid;
|
|
|
|
}
|
|
|
|
|
2021-10-04 16:21:56 +00:00
|
|
|
QDebug& operator<<(QDebug& s, const KWin::DrmConnector *obj)
|
|
|
|
{
|
|
|
|
QDebugStateSaver saver(s);
|
|
|
|
if (obj) {
|
|
|
|
|
|
|
|
QString connState = QStringLiteral("Disconnected");
|
|
|
|
if (!obj->m_conn || obj->m_conn->connection == DRM_MODE_UNKNOWNCONNECTION) {
|
|
|
|
connState = QStringLiteral("Unknown Connection");
|
|
|
|
} else if (obj->m_conn->connection == DRM_MODE_CONNECTED) {
|
|
|
|
connState = QStringLiteral("Connected");
|
|
|
|
}
|
|
|
|
|
|
|
|
s.nospace() << "DrmConnector(id=" << obj->id() <<
|
|
|
|
", gpu="<< obj->gpu() <<
|
|
|
|
", name="<< obj->modelName() <<
|
|
|
|
", connection=" << connState <<
|
|
|
|
", countMode=" << (obj->m_conn ? obj->m_conn->count_modes : 0)
|
|
|
|
<< ')';
|
|
|
|
} else {
|
|
|
|
s << "DrmConnector(0x0)";
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|