2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-03-21 14:11:17 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
|
2016-03-21 14:11:17 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-03-21 14:11:17 +00:00
|
|
|
#include "drm_output.h"
|
|
|
|
#include "drm_backend.h"
|
2016-08-31 12:00:31 +00:00
|
|
|
#include "drm_object_crtc.h"
|
|
|
|
#include "drm_object_connector.h"
|
|
|
|
|
2016-03-21 14:11:17 +00:00
|
|
|
#include "composite.h"
|
2020-04-02 16:18:01 +00:00
|
|
|
#include "cursor.h"
|
2016-04-19 07:46:16 +00:00
|
|
|
#include "logind.h"
|
2016-03-21 14:11:17 +00:00
|
|
|
#include "logging.h"
|
2016-04-13 12:08:38 +00:00
|
|
|
#include "main.h"
|
2020-12-20 13:15:57 +00:00
|
|
|
#include "screens.h"
|
2016-03-21 14:11:17 +00:00
|
|
|
#include "wayland_server.h"
|
|
|
|
// KWayland
|
2020-04-29 15:18:41 +00:00
|
|
|
#include <KWaylandServer/output_interface.h>
|
2016-03-21 14:11:17 +00:00
|
|
|
// KF5
|
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <KSharedConfig>
|
|
|
|
// Qt
|
2017-11-02 17:13:17 +00:00
|
|
|
#include <QMatrix4x4>
|
2016-03-21 14:11:17 +00:00
|
|
|
#include <QCryptographicHash>
|
2017-11-05 10:59:24 +00:00
|
|
|
#include <QPainter>
|
2019-07-09 19:19:26 +00:00
|
|
|
// c++
|
|
|
|
#include <cerrno>
|
2016-03-21 14:11:17 +00:00
|
|
|
// drm
|
|
|
|
#include <xf86drm.h>
|
|
|
|
#include <libdrm/drm_mode.h>
|
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
#include "drm_gpu.h"
|
|
|
|
|
2016-03-21 14:11:17 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
DrmOutput::DrmOutput(DrmBackend *backend, DrmGpu *gpu)
|
2019-06-13 09:36:07 +00:00
|
|
|
: AbstractWaylandOutput(backend)
|
2016-03-21 14:11:17 +00:00
|
|
|
, m_backend(backend)
|
2020-10-05 21:05:55 +00:00
|
|
|
, m_gpu(gpu)
|
2016-03-21 14:11:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmOutput::~DrmOutput()
|
|
|
|
{
|
2018-07-18 14:13:38 +00:00
|
|
|
Q_ASSERT(!m_pageFlipPending);
|
2019-09-05 14:59:53 +00:00
|
|
|
teardown();
|
2018-07-18 14:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrmOutput::teardown()
|
|
|
|
{
|
2019-09-05 14:59:53 +00:00
|
|
|
if (m_deleted) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-18 14:13:38 +00:00
|
|
|
m_deleted = true;
|
2016-03-21 14:11:17 +00:00
|
|
|
hideCursor();
|
[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
|
|
|
m_crtc->blank();
|
2017-05-09 19:29:10 +00:00
|
|
|
|
|
|
|
if (m_primaryPlane) {
|
|
|
|
// TODO: when having multiple planes, also clean up these
|
|
|
|
m_primaryPlane->setOutput(nullptr);
|
|
|
|
|
2020-10-25 17:47:58 +00:00
|
|
|
if (m_gpu->deleteBufferAfterPageFlip()) {
|
2017-05-09 19:29:10 +00:00
|
|
|
delete m_primaryPlane->current();
|
|
|
|
}
|
|
|
|
m_primaryPlane->setCurrent(nullptr);
|
|
|
|
}
|
Avoid crash in KWin::DrmOutput::updateCursor
Summary:
BUG: 420077
Sample stack traces :
From bug:
#2 QImage::copy (this=this@entry=0x558117775e20, r=...) at image/qimage.cpp:1172
#3 0x00007f22d0a24cdf in QImage::detach (this=this@entry=0x558117775e20) at image/qimage.cpp:1091
#4 0x00007f22d0a25ae0 in QImage::fill (this=0x558117775e20, color=...) at image/qimage.cpp:1806
#5 0x00007f22d0a25f5f in QImage::fill (this=this@entry=0x558117775e20, color=color@entry=Qt::transparent) at image/qimage.cpp:1780
#6 0x00007f22bf3bdffd in KWin::DrmOutput::updateCursor (this=0x5581176fb780) at ./plugins/platforms/drm/drm_output.cpp:175
#7 0x00007f22bf3b0e55 in KWin::DrmBackend::updateCursor (this=0x558117669b60) at ./plugins/platforms/drm/drm_backend.cpp:701
Locally reproduced:
#0 0x00007f360611e159 in KWayland::Server::OutputDeviceInterface::transform() const (this=<optimized out>)
at /home/meven/kde/src/kwayland/src/server/outputdevice_interface.cpp:590
#1 0x00007f3607438059 in KWin::AbstractWaylandOutput::transform() const (this=this@entry=0x5645bed10f90) at /home/meven/kde/src/kwin/abstract_wayland_output.cpp:317
#2 0x00007f35ecd8acd3 in KWin::DrmOutput::matrixDisplay(QSize const&) const (this=0x5645bed10f90, s=...)
at /home/meven/kde/src/kwin/plugins/platforms/drm/drm_output.cpp:155
#3 0x00007f35ecd8efa9 in KWin::DrmOutput::updateCursor() (this=<optimized out>) at /home/meven/kde/src/kwin/plugins/platforms/drm/drm_output.cpp:179
#4 0x00007f35ecd81db5 in KWin::DrmBackend::updateCursor() (this=0x5645bec743a0) at /home/meven/kde/src/kwin/plugins/platforms/drm/drm_backend.cpp:701
#5 0x00007f36049e7fe7 in () at /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#6 0x00007f36075ee43f in KWin::Cursors::currentCursorChanged(KWin::Cursor*) (this=<optimized out>, _t1=<optimized out>)
at /home/meven/kde/build/kwin/kwin_autogen/EWIEGA46WW/moc_cursor.cpp:385
Test Plan: Could not reproduce
Reviewers: #kwin, zzag, davidedmundson
Reviewed By: #kwin, davidedmundson
Subscribers: ngraham, apol, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D28889
2020-04-17 08:10:45 +00:00
|
|
|
if (m_cursorPlane) {
|
|
|
|
m_cursorPlane->setOutput(nullptr);
|
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
|
|
|
|
m_crtc->setOutput(nullptr);
|
|
|
|
m_conn->setOutput(nullptr);
|
|
|
|
|
2020-07-26 18:44:45 +00:00
|
|
|
m_cursor[0].reset(nullptr);
|
|
|
|
m_cursor[1].reset(nullptr);
|
2018-07-18 14:13:38 +00:00
|
|
|
if (!m_pageFlipPending) {
|
|
|
|
deleteLater();
|
|
|
|
} //else will be deleted in the page flip handler
|
|
|
|
//this is needed so that the pageflipcallback handle isn't deleted
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
|
[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
|
|
|
void DrmOutput::releaseGbm()
|
2017-03-17 19:31:06 +00:00
|
|
|
{
|
[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
|
|
|
if (DrmBuffer *b = m_crtc->current()) {
|
|
|
|
b->releaseGbm();
|
2017-03-17 19:31:06 +00:00
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
if (m_primaryPlane && m_primaryPlane->current()) {
|
|
|
|
m_primaryPlane->current()->releaseGbm();
|
2017-03-17 19:31:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-22 13:17:53 +00:00
|
|
|
bool DrmOutput::hideCursor()
|
2016-03-21 14:11:17 +00:00
|
|
|
{
|
2020-10-05 21:05:55 +00:00
|
|
|
return drmModeSetCursor(m_gpu->fd(), m_crtc->id(), 0, 0, 0) == 0;
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
|
2018-04-22 13:17:53 +00:00
|
|
|
bool DrmOutput::showCursor(DrmDumbBuffer *c)
|
2016-03-21 14:11:17 +00:00
|
|
|
{
|
|
|
|
const QSize &s = c->size();
|
2020-10-05 21:05:55 +00:00
|
|
|
return drmModeSetCursor(m_gpu->fd(), m_crtc->id(), c->handle(), s.width(), s.height()) == 0;
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
|
2018-04-22 13:17:53 +00:00
|
|
|
bool DrmOutput::showCursor()
|
2017-11-05 10:59:24 +00:00
|
|
|
{
|
2020-07-28 16:48:57 +00:00
|
|
|
if (m_deleted) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-07-26 18:44:45 +00:00
|
|
|
const bool ret = showCursor(m_cursor[m_cursorIndex].data());
|
2018-04-22 13:17:53 +00:00
|
|
|
if (!ret) {
|
2020-10-05 21:05:55 +00:00
|
|
|
qCDebug(KWIN_DRM) << "DrmOutput::showCursor(DrmDumbBuffer) failed";
|
2018-04-22 13:17:53 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-11-05 10:59:24 +00:00
|
|
|
if (m_hasNewCursor) {
|
|
|
|
m_cursorIndex = (m_cursorIndex + 1) % 2;
|
|
|
|
m_hasNewCursor = false;
|
|
|
|
}
|
2018-04-22 13:17:53 +00:00
|
|
|
|
|
|
|
return ret;
|
2017-11-05 10:59:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 07:03:09 +00:00
|
|
|
static bool isCursorSpriteCompatible(const QImage *buffer, const QImage *sprite)
|
|
|
|
{
|
|
|
|
// Note that we need compare the rects in the device independent pixels because the
|
|
|
|
// buffer and the cursor sprite image may have different scale factors.
|
|
|
|
const QRect bufferRect(QPoint(0, 0), buffer->size() / buffer->devicePixelRatio());
|
|
|
|
const QRect spriteRect(QPoint(0, 0), sprite->size() / sprite->devicePixelRatio());
|
|
|
|
|
|
|
|
return bufferRect.contains(spriteRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::updateCursor()
|
2017-11-05 10:59:24 +00:00
|
|
|
{
|
2020-07-28 16:48:57 +00:00
|
|
|
if (m_deleted) {
|
2020-10-28 07:03:09 +00:00
|
|
|
return false;
|
2020-07-28 16:48:57 +00:00
|
|
|
}
|
2020-10-25 15:19:07 +00:00
|
|
|
const Cursor *cursor = Cursors::self()->currentCursor();
|
|
|
|
const QImage cursorImage = cursor->image();
|
2017-11-05 10:59:24 +00:00
|
|
|
if (cursorImage.isNull()) {
|
2020-10-28 07:03:09 +00:00
|
|
|
return false;
|
2017-11-05 10:59:24 +00:00
|
|
|
}
|
2020-10-28 07:03:09 +00:00
|
|
|
|
2017-11-05 10:59:24 +00:00
|
|
|
QImage *c = m_cursor[m_cursorIndex]->image();
|
2020-10-28 07:03:09 +00:00
|
|
|
c->setDevicePixelRatio(scale());
|
|
|
|
|
|
|
|
if (!isCursorSpriteCompatible(c, &cursorImage)) {
|
|
|
|
// If the cursor image is too big, fall back to rendering the software cursor.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_hasNewCursor = true;
|
2017-11-05 10:59:24 +00:00
|
|
|
c->fill(Qt::transparent);
|
2018-06-23 17:14:50 +00:00
|
|
|
|
2017-11-05 10:59:24 +00:00
|
|
|
QPainter p;
|
|
|
|
p.begin(c);
|
2020-10-28 07:03:09 +00:00
|
|
|
p.setWorldTransform(logicalToNativeMatrix(cursor->rect(), 1, transform()).toTransform());
|
2017-11-05 10:59:24 +00:00
|
|
|
p.drawImage(QPoint(0, 0), cursorImage);
|
|
|
|
p.end();
|
2020-10-28 07:03:09 +00:00
|
|
|
|
|
|
|
return true;
|
2017-11-05 10:59:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 11:50:06 +00:00
|
|
|
void DrmOutput::moveCursor()
|
2016-03-21 14:11:17 +00:00
|
|
|
{
|
2020-10-27 11:50:06 +00:00
|
|
|
Cursor *cursor = Cursors::self()->currentCursor();
|
2020-10-25 15:19:07 +00:00
|
|
|
const QMatrix4x4 hotspotMatrix = logicalToNativeMatrix(cursor->rect(), scale(), transform());
|
2020-10-13 20:57:15 +00:00
|
|
|
const QMatrix4x4 monitorMatrix = logicalToNativeMatrix(geometry(), scale(), transform());
|
2020-10-13 20:15:46 +00:00
|
|
|
|
2020-10-27 11:50:06 +00:00
|
|
|
QPoint pos = monitorMatrix.map(cursor->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
pos -= hotspotMatrix.map(cursor->hotspot());
|
2020-10-12 20:56:07 +00:00
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
drmModeMoveCursor(m_gpu->fd(), m_crtc->id(), pos.x(), pos.y());
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
|
2016-11-15 15:01:28 +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")},
|
2019-03-15 11:08:31 +00:00
|
|
|
{DRM_MODE_CONNECTOR_DSI, QByteArrayLiteral("DSI")},
|
|
|
|
#ifdef DRM_MODE_CONNECTOR_DPI
|
|
|
|
{DRM_MODE_CONNECTOR_DPI, QByteArrayLiteral("DPI")},
|
|
|
|
#endif
|
2016-11-15 15:01:28 +00:00
|
|
|
};
|
|
|
|
|
2017-10-31 16:12:12 +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;
|
|
|
|
}
|
|
|
|
}
|
2016-11-15 15:01:28 +00:00
|
|
|
|
2016-07-11 09:26:03 +00:00
|
|
|
bool DrmOutput::init(drmModeConnector *connector)
|
2016-03-21 14:11:17 +00:00
|
|
|
{
|
|
|
|
initEdid(connector);
|
|
|
|
initDpms(connector);
|
|
|
|
initUuid();
|
2020-10-05 21:05:55 +00:00
|
|
|
if (m_gpu->atomicModeSetting()) {
|
2016-08-31 12:00:31 +00:00
|
|
|
if (!initPrimaryPlane()) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-11 09:26:03 +00:00
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
|
2019-09-25 06:32:03 +00:00
|
|
|
setInternal(connector->connector_type == DRM_MODE_CONNECTOR_LVDS || connector->connector_type == DRM_MODE_CONNECTOR_eDP
|
|
|
|
|| connector->connector_type == DRM_MODE_CONNECTOR_DSI);
|
2018-11-09 19:28:57 +00:00
|
|
|
setDpmsSupported(true);
|
2017-11-15 16:08:09 +00:00
|
|
|
initOutputDevice(connector);
|
2019-10-21 12:56:33 +00:00
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
if (!m_gpu->atomicModeSetting() && !m_crtc->blank()) {
|
2019-10-21 12:56:33 +00:00
|
|
|
// We use legacy mode and the initial output blank failed.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
updateDpms(KWaylandServer::OutputInterface::DpmsMode::On);
|
2017-11-15 16:08:09 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmOutput::initUuid()
|
|
|
|
{
|
|
|
|
QCryptographicHash hash(QCryptographicHash::Md5);
|
|
|
|
hash.addData(QByteArray::number(m_conn->id()));
|
2019-07-02 10:01:37 +00:00
|
|
|
hash.addData(m_edid.eisaId());
|
|
|
|
hash.addData(m_edid.monitorName());
|
|
|
|
hash.addData(m_edid.serialNumber());
|
2017-11-15 16:08:09 +00:00
|
|
|
m_uuid = hash.result().toHex().left(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmOutput::initOutputDevice(drmModeConnector *connector)
|
|
|
|
{
|
2018-11-09 20:13:56 +00:00
|
|
|
QString manufacturer;
|
Decode full monitor vendor name from EDID using hwdata
Test Plan:
KScreen now shows "Dell Inc." instead of DEL and
"Eizo Nano Corporation" instead of ENC in output names, which
matches closer to what's written on my monitors.
Reviewers: graesslin, davidedmundson, #plasma
Reviewed By: davidedmundson, #plasma
Subscribers: apol, feverfew, ngraham, davidedmundson, mart, kwin, sebas
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D10041
2020-02-26 11:37:01 +00:00
|
|
|
if (!m_edid.vendor().isEmpty()) {
|
|
|
|
manufacturer = QString::fromLatin1(m_edid.vendor());
|
|
|
|
} else if (!m_edid.eisaId().isEmpty()) {
|
2019-07-02 10:01:37 +00:00
|
|
|
manufacturer = QString::fromLatin1(m_edid.eisaId());
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 09:38:41 +00:00
|
|
|
QString connectorName = s_connectorNames.value(connector->connector_type, QByteArrayLiteral("Unknown")) + QStringLiteral("-") + QString::number(connector->connector_type_id);
|
2016-11-15 15:01:28 +00:00
|
|
|
QString modelName;
|
|
|
|
|
2019-07-02 10:01:37 +00:00
|
|
|
if (!m_edid.monitorName().isEmpty()) {
|
|
|
|
QString m = QString::fromLatin1(m_edid.monitorName());
|
|
|
|
if (!m_edid.serialNumber().isEmpty()) {
|
2018-11-09 20:13:56 +00:00
|
|
|
m.append('/');
|
2019-07-02 10:01:37 +00:00
|
|
|
m.append(QString::fromLatin1(m_edid.serialNumber()));
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
2018-11-09 20:13:56 +00:00
|
|
|
modelName = m;
|
2019-07-02 10:01:37 +00:00
|
|
|
} else if (!m_edid.serialNumber().isEmpty()) {
|
|
|
|
modelName = QString::fromLatin1(m_edid.serialNumber());
|
2016-03-21 14:11:17 +00:00
|
|
|
} else {
|
2016-11-15 15:01:28 +00:00
|
|
|
modelName = i18n("unknown");
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 09:38:41 +00:00
|
|
|
const QString model = connectorName + QStringLiteral("-") + modelName;
|
2016-03-21 14:11:17 +00:00
|
|
|
|
|
|
|
// read in mode information
|
2020-04-29 15:18:41 +00:00
|
|
|
QVector<KWaylandServer::OutputDeviceInterface::Mode> modes;
|
2016-03-21 14:11:17 +00:00
|
|
|
for (int i = 0; i < connector->count_modes; ++i) {
|
2016-08-31 12:00:31 +00:00
|
|
|
// TODO: in AMS here we could read and store for later every mode's blob_id
|
|
|
|
// would simplify isCurrentMode(..) and presentAtomically(..) in case of mode set
|
2016-03-21 14:11:17 +00:00
|
|
|
auto *m = &connector->modes[i];
|
2020-04-29 15:18:41 +00:00
|
|
|
KWaylandServer::OutputDeviceInterface::ModeFlags deviceflags;
|
2016-03-21 14:11:17 +00:00
|
|
|
if (isCurrentMode(m)) {
|
2020-04-29 15:18:41 +00:00
|
|
|
deviceflags |= KWaylandServer::OutputDeviceInterface::ModeFlag::Current;
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
if (m->type & DRM_MODE_TYPE_PREFERRED) {
|
2020-04-29 15:18:41 +00:00
|
|
|
deviceflags |= KWaylandServer::OutputDeviceInterface::ModeFlag::Preferred;
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
KWaylandServer::OutputDeviceInterface::Mode mode;
|
2016-03-21 14:11:17 +00:00
|
|
|
mode.id = i;
|
|
|
|
mode.size = QSize(m->hdisplay, m->vdisplay);
|
|
|
|
mode.flags = deviceflags;
|
2018-11-09 20:13:56 +00:00
|
|
|
mode.refreshRate = refreshRateForMode(m);
|
|
|
|
modes << mode;
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
2018-11-09 20:13:56 +00:00
|
|
|
|
2019-08-27 14:52:39 +00:00
|
|
|
QSize physicalSize = !m_edid.physicalSize().isEmpty() ? m_edid.physicalSize() : QSize(connector->mmWidth, connector->mmHeight);
|
|
|
|
// 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");
|
|
|
|
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());
|
|
|
|
if (group.hasKey("PhysicalSize")) {
|
|
|
|
const QSize overwriteSize = group.readEntry("PhysicalSize", physicalSize);
|
|
|
|
qCWarning(KWIN_DRM) << "Overwriting monitor physical size for" << m_edid.eisaId() << "/" << m_edid.monitorName() << "/" << m_edid.serialNumber() << " from " << physicalSize << "to " << overwriteSize;
|
|
|
|
physicalSize = overwriteSize;
|
|
|
|
}
|
2020-04-08 09:38:41 +00:00
|
|
|
setName(connectorName);
|
2020-10-26 17:29:33 +00:00
|
|
|
initInterfaces(model, manufacturer, m_uuid, physicalSize, modes, m_edid.raw());
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::isCurrentMode(const drmModeModeInfo *mode) const
|
|
|
|
{
|
|
|
|
return mode->clock == m_mode.clock
|
|
|
|
&& mode->hdisplay == m_mode.hdisplay
|
|
|
|
&& mode->hsync_start == m_mode.hsync_start
|
|
|
|
&& mode->hsync_end == m_mode.hsync_end
|
|
|
|
&& mode->htotal == m_mode.htotal
|
|
|
|
&& mode->hskew == m_mode.hskew
|
|
|
|
&& mode->vdisplay == m_mode.vdisplay
|
|
|
|
&& mode->vsync_start == m_mode.vsync_start
|
|
|
|
&& mode->vsync_end == m_mode.vsync_end
|
|
|
|
&& mode->vtotal == m_mode.vtotal
|
|
|
|
&& mode->vscan == m_mode.vscan
|
|
|
|
&& mode->vrefresh == m_mode.vrefresh
|
|
|
|
&& mode->flags == m_mode.flags
|
|
|
|
&& mode->type == m_mode.type
|
|
|
|
&& qstrcmp(mode->name, m_mode.name) == 0;
|
|
|
|
}
|
|
|
|
void DrmOutput::initEdid(drmModeConnector *connector)
|
|
|
|
{
|
2019-03-20 08:32:26 +00:00
|
|
|
DrmScopedPointer<drmModePropertyBlobRes> edid;
|
2016-03-21 14:11:17 +00:00
|
|
|
for (int i = 0; i < connector->count_props; ++i) {
|
2020-10-05 21:05:55 +00:00
|
|
|
DrmScopedPointer<drmModePropertyRes> property(drmModeGetProperty(m_gpu->fd(), connector->props[i]));
|
2016-03-21 14:11:17 +00:00
|
|
|
if (!property) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((property->flags & DRM_MODE_PROP_BLOB) && qstrcmp(property->name, "EDID") == 0) {
|
2020-10-05 21:05:55 +00:00
|
|
|
edid.reset(drmModeGetPropertyBlob(m_gpu->fd(), connector->prop_values[i]));
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!edid) {
|
2020-10-26 17:35:58 +00:00
|
|
|
qCWarning(KWIN_DRM) << "Could not find edid for connector" << connector << connector->connector_id;
|
2016-03-21 14:11:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-02 10:01:37 +00:00
|
|
|
m_edid = Edid(edid->data, edid->length);
|
|
|
|
if (!m_edid.isValid()) {
|
|
|
|
qCWarning(KWIN_DRM, "Couldn't parse EDID for connector with id %d", m_conn->id());
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-31 12:00:31 +00:00
|
|
|
bool DrmOutput::initPrimaryPlane()
|
|
|
|
{
|
2020-10-05 21:05:55 +00:00
|
|
|
for (int i = 0; i < m_gpu->planes().size(); ++i) {
|
|
|
|
DrmPlane *p = m_gpu->planes()[i];
|
2016-08-31 12:00:31 +00:00
|
|
|
if (!p) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (p->type() != DrmPlane::TypeIndex::Primary) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (p->output()) { // Plane already has an output
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (m_primaryPlane) { // Output already has a primary plane
|
|
|
|
continue;
|
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
if (!p->isCrtcSupported(m_crtc->resIndex())) {
|
2016-08-31 12:00:31 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
p->setOutput(this);
|
|
|
|
m_primaryPlane = p;
|
[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
|
|
|
qCDebug(KWIN_DRM) << "Initialized primary plane" << p->id() << "on CRTC" << m_crtc->id();
|
2016-08-31 12:00:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
qCCritical(KWIN_DRM) << "Failed to initialize primary plane.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::initCursorPlane() // TODO: Add call in init (but needs layer support in general first)
|
|
|
|
{
|
2020-10-05 21:05:55 +00:00
|
|
|
for (int i = 0; i < m_gpu->planes().size(); ++i) {
|
|
|
|
DrmPlane *p = m_gpu->planes()[i];
|
2016-08-31 12:00:31 +00:00
|
|
|
if (!p) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (p->type() != DrmPlane::TypeIndex::Cursor) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (p->output()) { // Plane already has an output
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (m_cursorPlane) { // Output already has a cursor plane
|
|
|
|
continue;
|
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
if (!p->isCrtcSupported(m_crtc->resIndex())) {
|
2016-08-31 12:00:31 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
p->setOutput(this);
|
|
|
|
m_cursorPlane = p;
|
[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
|
|
|
qCDebug(KWIN_DRM) << "Initialized cursor plane" << p->id() << "on CRTC" << m_crtc->id();
|
2016-08-31 12:00:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-09 21:58:23 +00:00
|
|
|
bool DrmOutput::initCursor(const QSize &cursorSize)
|
|
|
|
{
|
|
|
|
auto createCursor = [this, cursorSize] (int index) {
|
2020-10-05 21:05:55 +00:00
|
|
|
m_cursor[index].reset(m_gpu->createBuffer(cursorSize));
|
2018-11-09 21:58:23 +00:00
|
|
|
if (!m_cursor[index]->map(QImage::Format_ARGB32_Premultiplied)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
if (!createCursor(0) || !createCursor(1)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-21 14:11:17 +00:00
|
|
|
void DrmOutput::initDpms(drmModeConnector *connector)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < connector->count_props; ++i) {
|
2020-10-05 21:05:55 +00:00
|
|
|
DrmScopedPointer<drmModePropertyRes> property(drmModeGetProperty(m_gpu->fd(), connector->props[i]));
|
2016-03-21 14:11:17 +00:00
|
|
|
if (!property) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (qstrcmp(property->name, "DPMS") == 0) {
|
|
|
|
m_dpms.swap(property);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-31 08:27:04 +00:00
|
|
|
void DrmOutput::updateEnablement(bool enable)
|
|
|
|
{
|
|
|
|
if (enable) {
|
|
|
|
m_dpmsModePending = DpmsMode::On;
|
2020-10-05 21:05:55 +00:00
|
|
|
if (m_gpu->atomicModeSetting()) {
|
2019-08-31 08:27:04 +00:00
|
|
|
atomicEnable();
|
|
|
|
} else {
|
|
|
|
if (dpmsLegacyApply()) {
|
|
|
|
m_backend->enableOutput(this, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
m_dpmsModePending = DpmsMode::Off;
|
2020-10-05 21:05:55 +00:00
|
|
|
if (m_gpu->atomicModeSetting()) {
|
2019-08-31 08:27:04 +00:00
|
|
|
atomicDisable();
|
|
|
|
} else {
|
|
|
|
if (dpmsLegacyApply()) {
|
|
|
|
m_backend->enableOutput(this, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmOutput::atomicEnable()
|
|
|
|
{
|
|
|
|
m_modesetRequested = true;
|
|
|
|
|
|
|
|
if (m_atomicOffPending) {
|
|
|
|
Q_ASSERT(m_pageFlipPending);
|
|
|
|
m_atomicOffPending = false;
|
|
|
|
}
|
|
|
|
m_backend->enableOutput(this, true);
|
|
|
|
|
|
|
|
if (Compositor *compositor = Compositor::self()) {
|
|
|
|
compositor->addRepaintFull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmOutput::atomicDisable()
|
|
|
|
{
|
|
|
|
m_modesetRequested = true;
|
|
|
|
|
|
|
|
m_backend->enableOutput(this, false);
|
|
|
|
m_atomicOffPending = true;
|
|
|
|
if (!m_pageFlipPending) {
|
|
|
|
dpmsAtomicOff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
static DrmOutput::DpmsMode fromWaylandDpmsMode(KWaylandServer::OutputInterface::DpmsMode wlMode)
|
2018-11-09 21:58:23 +00:00
|
|
|
{
|
2020-04-29 15:18:41 +00:00
|
|
|
using namespace KWaylandServer;
|
2018-11-09 21:58:23 +00:00
|
|
|
switch (wlMode) {
|
|
|
|
case OutputInterface::DpmsMode::On:
|
|
|
|
return DrmOutput::DpmsMode::On;
|
|
|
|
case OutputInterface::DpmsMode::Standby:
|
|
|
|
return DrmOutput::DpmsMode::Standby;
|
|
|
|
case OutputInterface::DpmsMode::Suspend:
|
|
|
|
return DrmOutput::DpmsMode::Suspend;
|
|
|
|
case OutputInterface::DpmsMode::Off:
|
|
|
|
return DrmOutput::DpmsMode::Off;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
static KWaylandServer::OutputInterface::DpmsMode toWaylandDpmsMode(DrmOutput::DpmsMode mode)
|
2018-11-09 21:58:23 +00:00
|
|
|
{
|
2020-04-29 15:18:41 +00:00
|
|
|
using namespace KWaylandServer;
|
2018-11-09 21:58:23 +00:00
|
|
|
switch (mode) {
|
|
|
|
case DrmOutput::DpmsMode::On:
|
|
|
|
return OutputInterface::DpmsMode::On;
|
|
|
|
case DrmOutput::DpmsMode::Standby:
|
|
|
|
return OutputInterface::DpmsMode::Standby;
|
|
|
|
case DrmOutput::DpmsMode::Suspend:
|
|
|
|
return OutputInterface::DpmsMode::Suspend;
|
|
|
|
case DrmOutput::DpmsMode::Off:
|
|
|
|
return OutputInterface::DpmsMode::Off;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-29 15:18:41 +00:00
|
|
|
void DrmOutput::updateDpms(KWaylandServer::OutputInterface::DpmsMode mode)
|
2016-03-21 14:11:17 +00:00
|
|
|
{
|
2019-08-31 08:27:04 +00:00
|
|
|
if (m_dpms.isNull() || !isEnabled()) {
|
2016-03-21 14:11:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-11-09 19:28:57 +00:00
|
|
|
|
|
|
|
const auto drmMode = fromWaylandDpmsMode(mode);
|
2019-08-31 08:27:04 +00:00
|
|
|
|
2018-11-09 19:28:57 +00:00
|
|
|
if (drmMode == m_dpmsModePending) {
|
2016-08-31 12:00:31 +00:00
|
|
|
qCDebug(KWIN_DRM) << "New DPMS mode equals old mode. DPMS unchanged.";
|
2020-05-27 08:07:36 +00:00
|
|
|
waylandOutput()->setDpmsMode(mode);
|
2016-03-21 14:11:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2018-11-09 19:28:57 +00:00
|
|
|
m_dpmsModePending = drmMode;
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
if (m_gpu->atomicModeSetting()) {
|
2017-05-09 19:29:10 +00:00
|
|
|
m_modesetRequested = true;
|
2018-11-09 19:28:57 +00:00
|
|
|
if (drmMode == DpmsMode::On) {
|
2019-08-31 08:27:04 +00:00
|
|
|
if (m_atomicOffPending) {
|
|
|
|
Q_ASSERT(m_pageFlipPending);
|
|
|
|
m_atomicOffPending = false;
|
2017-05-09 19:29:10 +00:00
|
|
|
}
|
2019-08-31 08:27:04 +00:00
|
|
|
dpmsFinishOn();
|
2016-08-31 12:00:31 +00:00
|
|
|
} else {
|
2019-08-31 08:27:04 +00:00
|
|
|
m_atomicOffPending = true;
|
2017-05-09 19:29:10 +00:00
|
|
|
if (!m_pageFlipPending) {
|
|
|
|
dpmsAtomicOff();
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-08-31 08:27:04 +00:00
|
|
|
dpmsLegacyApply();
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
}
|
|
|
|
|
2019-08-31 08:27:04 +00:00
|
|
|
void DrmOutput::dpmsFinishOn()
|
2017-05-09 19:29:10 +00:00
|
|
|
{
|
|
|
|
qCDebug(KWIN_DRM) << "DPMS mode set for output" << m_crtc->id() << "to On.";
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2020-05-27 08:07:36 +00:00
|
|
|
waylandOutput()->setDpmsMode(toWaylandDpmsMode(DpmsMode::On));
|
2017-05-09 19:29:10 +00:00
|
|
|
|
|
|
|
m_backend->checkOutputsAreOn();
|
2020-10-05 21:05:55 +00:00
|
|
|
if (!m_gpu->atomicModeSetting()) {
|
[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
|
|
|
m_crtc->blank();
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
if (Compositor *compositor = Compositor::self()) {
|
|
|
|
compositor->addRepaintFull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-31 08:27:04 +00:00
|
|
|
void DrmOutput::dpmsFinishOff()
|
2017-05-09 19:29:10 +00:00
|
|
|
{
|
|
|
|
qCDebug(KWIN_DRM) << "DPMS mode set for output" << m_crtc->id() << "to Off.";
|
|
|
|
|
2019-08-31 08:27:04 +00:00
|
|
|
if (isEnabled()) {
|
|
|
|
waylandOutput()->setDpmsMode(toWaylandDpmsMode(m_dpmsModePending));
|
|
|
|
m_backend->createDpmsFilter();
|
2020-05-26 15:14:13 +00:00
|
|
|
} else {
|
|
|
|
waylandOutput()->setDpmsMode(toWaylandDpmsMode(DpmsMode::Off));
|
2017-05-09 19:29:10 +00:00
|
|
|
}
|
2019-08-31 08:27:04 +00:00
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
|
2019-08-31 08:27:04 +00:00
|
|
|
bool DrmOutput::dpmsLegacyApply()
|
|
|
|
{
|
2020-10-05 21:05:55 +00:00
|
|
|
if (drmModeConnectorSetProperty(m_gpu->fd(), m_conn->id(),
|
2019-08-31 08:27:04 +00:00
|
|
|
m_dpms->prop_id, uint64_t(m_dpmsModePending)) < 0) {
|
|
|
|
m_dpmsModePending = m_dpmsMode;
|
|
|
|
qCWarning(KWIN_DRM) << "Setting DPMS failed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_dpmsModePending == DpmsMode::On) {
|
|
|
|
dpmsFinishOn();
|
|
|
|
} else {
|
|
|
|
dpmsFinishOff();
|
|
|
|
}
|
|
|
|
m_dpmsMode = m_dpmsModePending;
|
|
|
|
return true;
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
|
2020-01-02 14:55:02 +00:00
|
|
|
DrmPlane::Transformations outputToPlaneTransform(DrmOutput::Transform transform)
|
|
|
|
{
|
|
|
|
using OutTrans = DrmOutput::Transform;
|
|
|
|
using PlaneTrans = DrmPlane::Transformation;
|
|
|
|
|
|
|
|
// TODO: Do we want to support reflections (flips)?
|
|
|
|
|
|
|
|
switch (transform) {
|
|
|
|
case OutTrans::Normal:
|
|
|
|
case OutTrans::Flipped:
|
|
|
|
return PlaneTrans::Rotate0;
|
|
|
|
case OutTrans::Rotated90:
|
|
|
|
case OutTrans::Flipped90:
|
|
|
|
return PlaneTrans::Rotate90;
|
|
|
|
case OutTrans::Rotated180:
|
|
|
|
case OutTrans::Flipped180:
|
|
|
|
return PlaneTrans::Rotate180;
|
|
|
|
case OutTrans::Rotated270:
|
|
|
|
case OutTrans::Flipped270:
|
|
|
|
return PlaneTrans::Rotate270;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::hardwareTransforms() const
|
|
|
|
{
|
|
|
|
if (!m_primaryPlane) {
|
|
|
|
return false;
|
2019-12-01 11:51:38 +00:00
|
|
|
}
|
2020-01-02 14:55:02 +00:00
|
|
|
return m_primaryPlane->transformation() == outputToPlaneTransform(transform());
|
|
|
|
}
|
2019-12-01 11:51:38 +00:00
|
|
|
|
2020-01-02 14:55:02 +00:00
|
|
|
void DrmOutput::updateTransform(Transform transform)
|
|
|
|
{
|
|
|
|
const auto planeTransform = outputToPlaneTransform(transform);
|
|
|
|
|
|
|
|
if (m_primaryPlane) {
|
|
|
|
// At the moment we have to exclude hardware transforms for vertical buffers.
|
|
|
|
// For that we need to support other buffers and graceful fallback from atomic tests.
|
|
|
|
// Reason is that standard linear buffers are not suitable.
|
|
|
|
const bool isPortrait = transform == Transform::Rotated90
|
|
|
|
|| transform == Transform::Flipped90
|
|
|
|
|| transform == Transform::Rotated270
|
|
|
|
|| transform == Transform::Flipped270;
|
|
|
|
|
|
|
|
if (!qEnvironmentVariableIsSet("KWIN_DRM_SW_ROTATIONS_ONLY") &&
|
|
|
|
(m_primaryPlane->supportedTransformations() & planeTransform) &&
|
|
|
|
!isPortrait) {
|
|
|
|
m_primaryPlane->setTransformation(planeTransform);
|
|
|
|
} else {
|
|
|
|
m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate0);
|
|
|
|
}
|
2017-11-06 16:00:15 +00:00
|
|
|
}
|
|
|
|
m_modesetRequested = true;
|
2019-12-01 11:51:38 +00:00
|
|
|
|
2020-05-20 14:26:15 +00:00
|
|
|
// show cursor only if is enabled, i.e if pointer device is presentP
|
2020-10-27 09:40:38 +00:00
|
|
|
if (!m_backend->isCursorHidden() && !m_backend->usesSoftwareCursor()) {
|
2020-05-20 14:26:15 +00:00
|
|
|
// the cursor might need to get rotated
|
|
|
|
updateCursor();
|
|
|
|
showCursor();
|
|
|
|
}
|
2017-11-06 16:00:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-15 20:20:10 +00:00
|
|
|
void DrmOutput::updateMode(uint32_t width, uint32_t height, uint32_t refreshRate)
|
|
|
|
{
|
|
|
|
if (m_mode.hdisplay == width && m_mode.vdisplay == height && m_mode.vrefresh == refreshRate) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// try to find a fitting mode
|
|
|
|
DrmScopedPointer<drmModeConnector> connector(drmModeGetConnectorCurrent(m_gpu->fd(), m_conn->id()));
|
|
|
|
for (int i = 0; i < connector->count_modes; i++) {
|
|
|
|
auto mode = connector->modes[i];
|
|
|
|
if (mode.hdisplay == width && mode.vdisplay == height && mode.vrefresh == refreshRate) {
|
|
|
|
updateMode(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qCWarning(KWIN_DRM, "Could not find a fitting mode with size=%dx%d and refresh rate %d for output %s",
|
|
|
|
width, height, refreshRate, uuid().constData());
|
|
|
|
}
|
|
|
|
|
2017-10-21 13:16:41 +00:00
|
|
|
void DrmOutput::updateMode(int modeIndex)
|
|
|
|
{
|
|
|
|
// get all modes on the connector
|
2020-10-05 21:05:55 +00:00
|
|
|
DrmScopedPointer<drmModeConnector> connector(drmModeGetConnector(m_gpu->fd(), m_conn->id()));
|
2017-10-21 13:16:41 +00:00
|
|
|
if (connector->count_modes <= modeIndex) {
|
|
|
|
// TODO: error?
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isCurrentMode(&connector->modes[modeIndex])) {
|
|
|
|
// nothing to do
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_mode = connector->modes[modeIndex];
|
|
|
|
m_modesetRequested = true;
|
2018-11-09 19:08:21 +00:00
|
|
|
setWaylandMode();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmOutput::setWaylandMode()
|
|
|
|
{
|
2019-06-13 09:36:07 +00:00
|
|
|
AbstractWaylandOutput::setWaylandMode(QSize(m_mode.hdisplay, m_mode.vdisplay),
|
|
|
|
refreshRateForMode(&m_mode));
|
2017-10-21 13:16:41 +00:00
|
|
|
}
|
|
|
|
|
2016-08-31 12:00:31 +00:00
|
|
|
void DrmOutput::pageFlipped()
|
|
|
|
{
|
2019-10-21 12:56:33 +00:00
|
|
|
// In legacy mode we might get a page flip through a blank.
|
2020-10-05 21:05:55 +00:00
|
|
|
Q_ASSERT(m_pageFlipPending || !m_gpu->atomicModeSetting());
|
2017-05-09 19:29:10 +00:00
|
|
|
m_pageFlipPending = false;
|
2019-10-21 12:56:33 +00:00
|
|
|
|
2018-07-18 14:13:38 +00:00
|
|
|
if (m_deleted) {
|
|
|
|
deleteLater();
|
|
|
|
return;
|
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
|
[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
|
|
|
if (!m_crtc) {
|
|
|
|
return;
|
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
// Egl based surface buffers get destroyed, QPainter based dumb buffers not
|
|
|
|
// TODO: split up DrmOutput in two for dumb and egl/gbm surface buffer compatible subclasses completely?
|
2020-10-25 17:47:58 +00:00
|
|
|
if (m_gpu->deleteBufferAfterPageFlip()) {
|
2020-10-05 21:05:55 +00:00
|
|
|
if (m_gpu->atomicModeSetting()) {
|
2017-05-09 19:29:10 +00:00
|
|
|
if (!m_primaryPlane->next()) {
|
|
|
|
// on manual vt switch
|
|
|
|
// TODO: when we later use overlay planes it might happen, that we have a page flip with only
|
|
|
|
// damage on one of these, and therefore the primary plane has no next buffer
|
|
|
|
// -> Then we don't want to return here!
|
|
|
|
if (m_primaryPlane->current()) {
|
|
|
|
m_primaryPlane->current()->releaseGbm();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (DrmPlane *p : m_nextPlanesFlipList) {
|
|
|
|
p->flipBufferWithDelete();
|
|
|
|
}
|
|
|
|
m_nextPlanesFlipList.clear();
|
|
|
|
} else {
|
|
|
|
if (!m_crtc->next()) {
|
|
|
|
// on manual vt switch
|
|
|
|
if (DrmBuffer *b = m_crtc->current()) {
|
|
|
|
b->releaseGbm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_crtc->flipBuffer();
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-10-05 21:05:55 +00:00
|
|
|
if (m_gpu->atomicModeSetting()){
|
2017-05-09 19:29:10 +00:00
|
|
|
for (DrmPlane *p : m_nextPlanesFlipList) {
|
|
|
|
p->flipBuffer();
|
2017-03-17 19:31:06 +00:00
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
m_nextPlanesFlipList.clear();
|
|
|
|
} else {
|
|
|
|
m_crtc->flipBuffer();
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
[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
|
|
|
m_crtc->flipBuffer();
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
2019-08-31 08:27:04 +00:00
|
|
|
|
|
|
|
if (m_atomicOffPending) {
|
|
|
|
dpmsAtomicOff();
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::present(DrmBuffer *buffer)
|
|
|
|
{
|
2019-08-31 08:27:04 +00:00
|
|
|
if (m_dpmsModePending != DpmsMode::On) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-10-05 21:05:55 +00:00
|
|
|
if (m_gpu->atomicModeSetting()) {
|
2016-08-31 12:00:31 +00:00
|
|
|
return presentAtomically(buffer);
|
|
|
|
} else {
|
|
|
|
return presentLegacy(buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
bool DrmOutput::dpmsAtomicOff()
|
2016-08-31 12:00:31 +00:00
|
|
|
{
|
2019-08-31 08:27:04 +00:00
|
|
|
m_atomicOffPending = false;
|
2017-05-09 19:29:10 +00:00
|
|
|
|
|
|
|
// TODO: With multiple planes: deactivate all of them here
|
|
|
|
delete m_primaryPlane->next();
|
|
|
|
m_primaryPlane->setNext(nullptr);
|
|
|
|
m_nextPlanesFlipList << m_primaryPlane;
|
|
|
|
|
|
|
|
if (!doAtomicCommit(AtomicCommitMode::Test)) {
|
|
|
|
qCDebug(KWIN_DRM) << "Atomic test commit to Dpms Off failed. Aborting.";
|
2016-08-31 12:00:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
if (!doAtomicCommit(AtomicCommitMode::Real)) {
|
|
|
|
qCDebug(KWIN_DRM) << "Atomic commit to Dpms Off failed. This should have never happened! Aborting.";
|
2016-08-31 12:00:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
m_nextPlanesFlipList.clear();
|
2019-08-31 08:27:04 +00:00
|
|
|
dpmsFinishOff();
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
bool DrmOutput::presentAtomically(DrmBuffer *buffer)
|
|
|
|
{
|
|
|
|
if (!LogindIntegration::self()->isActiveSession()) {
|
|
|
|
qCWarning(KWIN_DRM) << "Logind session not active.";
|
|
|
|
return false;
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
if (m_pageFlipPending) {
|
|
|
|
qCWarning(KWIN_DRM) << "Page not yet flipped.";
|
|
|
|
return false;
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
|
[platforms/drm] EGLStream DRM Backend Initial Implementation
Summary:
This is the initial implementation of a DRM backend based on the EGLDevice,
EGLOutput, and EGLStream extensions, supporting NVIDIA graphics hardware using
their proprietary driver. The new backend will be used if the environment
variable KWIN_DRM_USE_EGL_STREAMS is set. On initialization, it will attempt to
create an EGLDevice based on the DRM device currently in use and create
EGLOutputs and EGLStreams for any attached displays. These are used to control
presentation of the final composited frame. Additionally, it will register the
wl_eglstream_controller Wayland interface so that native EGL windows created by
clients can be attached to an EGLStream allowing buffer contents to be shared
with the compositor as a GL texture.
At this time there are two known bugs in the NVIDIA driver's EGL implementation
affecting desktop functionality. The first can result in tooltip windows drawn
by plasmashell to contain incorrect contents. The second prevents KWayland from
being able to query the format of EGLStream-backed buffers which interferes
with the blur effect. Fixes for both of these are currently in development and
should appear in an upcoming NVIDIA driver release.
Additionally, hardware cursors are currently not supported with this backend.
Enabling them causes the desktop to intermittently hang for several seconds.
This is also likely a bug in the NVIDIA DRM-KMS implementation but the root
cause is still under investigation.
Test Plan:
On a system with an NVIDIA graphics card running a recent release of their
proprietary driver
* Ensure the nvidia_drm kernel module is loaded with the option "modeset=1"
("# cat /sys/module/nvidia_drm/parameters/modeset" should print "Y")
* Ensure EGL external platform support is installed
https://github.com/NVIDIA/eglexternalplatform
* Ensure KWin was build with the CMake option
KWIN_BUILD_EGL_STREAM_BACKEND=ON (this is the default)
* Start a plasma wayland session with the environment variable
KWIN_DRM_USE_EGL_STREAMS set
* Ensure output from KWin OpenGL initialization indicates the NVIDIA EGL
driver is in use (as opposed to Mesa / llvmpipe).
* Desktop should be fully functional and perform smoothly.
Reviewers: #kwin, romangg, davidedmundson
Reviewed By: #kwin, romangg, davidedmundson
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D18570
2019-04-15 14:26:22 +00:00
|
|
|
#if HAVE_EGL_STREAMS
|
2020-10-25 17:47:58 +00:00
|
|
|
if (m_gpu->useEglStreams() && !m_modesetRequested) {
|
[platforms/drm] EGLStream DRM Backend Initial Implementation
Summary:
This is the initial implementation of a DRM backend based on the EGLDevice,
EGLOutput, and EGLStream extensions, supporting NVIDIA graphics hardware using
their proprietary driver. The new backend will be used if the environment
variable KWIN_DRM_USE_EGL_STREAMS is set. On initialization, it will attempt to
create an EGLDevice based on the DRM device currently in use and create
EGLOutputs and EGLStreams for any attached displays. These are used to control
presentation of the final composited frame. Additionally, it will register the
wl_eglstream_controller Wayland interface so that native EGL windows created by
clients can be attached to an EGLStream allowing buffer contents to be shared
with the compositor as a GL texture.
At this time there are two known bugs in the NVIDIA driver's EGL implementation
affecting desktop functionality. The first can result in tooltip windows drawn
by plasmashell to contain incorrect contents. The second prevents KWayland from
being able to query the format of EGLStream-backed buffers which interferes
with the blur effect. Fixes for both of these are currently in development and
should appear in an upcoming NVIDIA driver release.
Additionally, hardware cursors are currently not supported with this backend.
Enabling them causes the desktop to intermittently hang for several seconds.
This is also likely a bug in the NVIDIA DRM-KMS implementation but the root
cause is still under investigation.
Test Plan:
On a system with an NVIDIA graphics card running a recent release of their
proprietary driver
* Ensure the nvidia_drm kernel module is loaded with the option "modeset=1"
("# cat /sys/module/nvidia_drm/parameters/modeset" should print "Y")
* Ensure EGL external platform support is installed
https://github.com/NVIDIA/eglexternalplatform
* Ensure KWin was build with the CMake option
KWIN_BUILD_EGL_STREAM_BACKEND=ON (this is the default)
* Start a plasma wayland session with the environment variable
KWIN_DRM_USE_EGL_STREAMS set
* Ensure output from KWin OpenGL initialization indicates the NVIDIA EGL
driver is in use (as opposed to Mesa / llvmpipe).
* Desktop should be fully functional and perform smoothly.
Reviewers: #kwin, romangg, davidedmundson
Reviewed By: #kwin, romangg, davidedmundson
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D18570
2019-04-15 14:26:22 +00:00
|
|
|
// EglStreamBackend queues normal page flips through EGL,
|
|
|
|
// modesets are still performed through DRM-KMS
|
|
|
|
m_pageFlipPending = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
2020-11-27 19:57:24 +00:00
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
m_primaryPlane->setNext(buffer);
|
|
|
|
m_nextPlanesFlipList << m_primaryPlane;
|
|
|
|
|
|
|
|
if (!doAtomicCommit(AtomicCommitMode::Test)) {
|
|
|
|
//TODO: When we use planes for layered rendering, fallback to renderer instead. Also for direct scanout?
|
2017-07-14 11:42:52 +00:00
|
|
|
//TODO: Probably should undo setNext and reset the flip list
|
2017-05-09 19:29:10 +00:00
|
|
|
qCDebug(KWIN_DRM) << "Atomic test commit failed. Aborting present.";
|
2017-11-01 18:21:08 +00:00
|
|
|
// go back to previous state
|
|
|
|
if (m_lastWorkingState.valid) {
|
|
|
|
m_mode = m_lastWorkingState.mode;
|
2019-11-26 22:53:17 +00:00
|
|
|
setTransform(m_lastWorkingState.transform);
|
2017-11-01 18:21:08 +00:00
|
|
|
setGlobalPos(m_lastWorkingState.globalPos);
|
|
|
|
if (m_primaryPlane) {
|
|
|
|
m_primaryPlane->setTransformation(m_lastWorkingState.planeTransformations);
|
|
|
|
}
|
|
|
|
m_modesetRequested = true;
|
2020-10-27 09:40:38 +00:00
|
|
|
if (!m_backend->isCursorHidden()) {
|
2020-05-20 14:26:15 +00:00
|
|
|
// the cursor might need to get rotated
|
|
|
|
updateCursor();
|
|
|
|
showCursor();
|
|
|
|
}
|
2018-11-09 19:08:21 +00:00
|
|
|
setWaylandMode();
|
2017-11-01 18:21:08 +00:00
|
|
|
emit screens()->changed();
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-11-01 18:21:08 +00:00
|
|
|
const bool wasModeset = m_modesetRequested;
|
2017-05-09 19:29:10 +00:00
|
|
|
if (!doAtomicCommit(AtomicCommitMode::Real)) {
|
|
|
|
qCDebug(KWIN_DRM) << "Atomic commit failed. This should have never happened! Aborting present.";
|
2017-07-14 11:42:52 +00:00
|
|
|
//TODO: Probably should undo setNext and reset the flip list
|
2017-05-09 19:29:10 +00:00
|
|
|
return false;
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
2017-11-01 18:21:08 +00:00
|
|
|
if (wasModeset) {
|
|
|
|
// store current mode set as new good state
|
|
|
|
m_lastWorkingState.mode = m_mode;
|
2019-11-26 22:53:17 +00:00
|
|
|
m_lastWorkingState.transform = transform();
|
2018-03-28 23:27:21 +00:00
|
|
|
m_lastWorkingState.globalPos = globalPos();
|
2017-11-01 18:21:08 +00:00
|
|
|
if (m_primaryPlane) {
|
|
|
|
m_lastWorkingState.planeTransformations = m_primaryPlane->transformation();
|
|
|
|
}
|
|
|
|
m_lastWorkingState.valid = true;
|
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
m_pageFlipPending = true;
|
2016-08-31 12:00:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::presentLegacy(DrmBuffer *buffer)
|
|
|
|
{
|
[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
|
|
|
if (m_crtc->next()) {
|
2016-08-31 12:00:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!LogindIntegration::self()->isActiveSession()) {
|
[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
|
|
|
m_crtc->setNext(buffer);
|
2016-08-31 12:00:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we need to set a new mode first?
|
2017-05-09 19:00:33 +00:00
|
|
|
if (!m_crtc->current() || m_crtc->current()->needsModeChange(buffer)) {
|
|
|
|
if (!setModeLegacy(buffer)) {
|
2016-08-31 12:00:31 +00:00
|
|
|
return false;
|
2017-05-09 19:00:33 +00:00
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
2020-10-05 21:05:55 +00:00
|
|
|
const bool ok = drmModePageFlip(m_gpu->fd(), m_crtc->id(), buffer->bufferId(), DRM_MODE_PAGE_FLIP_EVENT, this) == 0;
|
2016-08-31 12:00:31 +00:00
|
|
|
if (ok) {
|
[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
|
|
|
m_crtc->setNext(buffer);
|
2016-08-31 12:00:31 +00:00
|
|
|
} else {
|
|
|
|
qCWarning(KWIN_DRM) << "Page flip failed:" << strerror(errno);
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::setModeLegacy(DrmBuffer *buffer)
|
|
|
|
{
|
[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
|
|
|
uint32_t connId = m_conn->id();
|
2020-10-05 21:05:55 +00:00
|
|
|
if (drmModeSetCrtc(m_gpu->fd(), m_crtc->id(), buffer->bufferId(), 0, 0, &connId, 1, &m_mode) == 0) {
|
2016-08-31 12:00:31 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
qCWarning(KWIN_DRM) << "Mode setting failed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
bool DrmOutput::doAtomicCommit(AtomicCommitMode mode)
|
2016-08-31 12:00:31 +00:00
|
|
|
{
|
2017-05-09 19:29:10 +00:00
|
|
|
drmModeAtomicReq *req = drmModeAtomicAlloc();
|
|
|
|
|
|
|
|
auto errorHandler = [this, mode, req] () {
|
|
|
|
if (mode == AtomicCommitMode::Test) {
|
|
|
|
// TODO: when we later test overlay planes, make sure we change only the right stuff back
|
|
|
|
}
|
|
|
|
if (req) {
|
|
|
|
drmModeAtomicFree(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_dpmsMode != m_dpmsModePending) {
|
|
|
|
qCWarning(KWIN_DRM) << "Setting DPMS failed";
|
|
|
|
m_dpmsModePending = m_dpmsMode;
|
|
|
|
if (m_dpmsMode != DpmsMode::On) {
|
2019-08-31 08:27:04 +00:00
|
|
|
dpmsFinishOff();
|
2017-05-09 19:29:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: see above, rework later for overlay planes!
|
|
|
|
for (DrmPlane *p : m_nextPlanesFlipList) {
|
|
|
|
p->setNext(nullptr);
|
|
|
|
}
|
|
|
|
m_nextPlanesFlipList.clear();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!req) {
|
2020-10-05 21:05:55 +00:00
|
|
|
qCWarning(KWIN_DRM) << "DRM: couldn't allocate atomic request";
|
|
|
|
errorHandler();
|
|
|
|
return false;
|
2017-05-09 19:29:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t flags = 0;
|
|
|
|
// Do we need to set a new mode?
|
|
|
|
if (m_modesetRequested) {
|
|
|
|
if (m_dpmsModePending == DpmsMode::On) {
|
2020-10-05 21:05:55 +00:00
|
|
|
if (drmModeCreatePropertyBlob(m_gpu->fd(), &m_mode, sizeof(m_mode), &m_blobId) != 0) {
|
2017-05-09 19:29:10 +00:00
|
|
|
qCWarning(KWIN_DRM) << "Failed to create property blob";
|
|
|
|
errorHandler();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!atomicReqModesetPopulate(req, m_dpmsModePending == DpmsMode::On)){
|
|
|
|
qCWarning(KWIN_DRM) << "Failed to populate Atomic Modeset";
|
|
|
|
errorHandler();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode == AtomicCommitMode::Real) {
|
|
|
|
if (m_dpmsModePending == DpmsMode::On) {
|
|
|
|
if (!(flags & DRM_MODE_ATOMIC_ALLOW_MODESET)) {
|
|
|
|
// TODO: Evaluating this condition should only be necessary, as long as we expect older kernels than 4.10.
|
|
|
|
flags |= DRM_MODE_ATOMIC_NONBLOCK;
|
|
|
|
}
|
[platforms/drm] EGLStream DRM Backend Initial Implementation
Summary:
This is the initial implementation of a DRM backend based on the EGLDevice,
EGLOutput, and EGLStream extensions, supporting NVIDIA graphics hardware using
their proprietary driver. The new backend will be used if the environment
variable KWIN_DRM_USE_EGL_STREAMS is set. On initialization, it will attempt to
create an EGLDevice based on the DRM device currently in use and create
EGLOutputs and EGLStreams for any attached displays. These are used to control
presentation of the final composited frame. Additionally, it will register the
wl_eglstream_controller Wayland interface so that native EGL windows created by
clients can be attached to an EGLStream allowing buffer contents to be shared
with the compositor as a GL texture.
At this time there are two known bugs in the NVIDIA driver's EGL implementation
affecting desktop functionality. The first can result in tooltip windows drawn
by plasmashell to contain incorrect contents. The second prevents KWayland from
being able to query the format of EGLStream-backed buffers which interferes
with the blur effect. Fixes for both of these are currently in development and
should appear in an upcoming NVIDIA driver release.
Additionally, hardware cursors are currently not supported with this backend.
Enabling them causes the desktop to intermittently hang for several seconds.
This is also likely a bug in the NVIDIA DRM-KMS implementation but the root
cause is still under investigation.
Test Plan:
On a system with an NVIDIA graphics card running a recent release of their
proprietary driver
* Ensure the nvidia_drm kernel module is loaded with the option "modeset=1"
("# cat /sys/module/nvidia_drm/parameters/modeset" should print "Y")
* Ensure EGL external platform support is installed
https://github.com/NVIDIA/eglexternalplatform
* Ensure KWin was build with the CMake option
KWIN_BUILD_EGL_STREAM_BACKEND=ON (this is the default)
* Start a plasma wayland session with the environment variable
KWIN_DRM_USE_EGL_STREAMS set
* Ensure output from KWin OpenGL initialization indicates the NVIDIA EGL
driver is in use (as opposed to Mesa / llvmpipe).
* Desktop should be fully functional and perform smoothly.
Reviewers: #kwin, romangg, davidedmundson
Reviewed By: #kwin, romangg, davidedmundson
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D18570
2019-04-15 14:26:22 +00:00
|
|
|
|
|
|
|
#if HAVE_EGL_STREAMS
|
2020-10-25 17:47:58 +00:00
|
|
|
if (!m_gpu->useEglStreams())
|
[platforms/drm] EGLStream DRM Backend Initial Implementation
Summary:
This is the initial implementation of a DRM backend based on the EGLDevice,
EGLOutput, and EGLStream extensions, supporting NVIDIA graphics hardware using
their proprietary driver. The new backend will be used if the environment
variable KWIN_DRM_USE_EGL_STREAMS is set. On initialization, it will attempt to
create an EGLDevice based on the DRM device currently in use and create
EGLOutputs and EGLStreams for any attached displays. These are used to control
presentation of the final composited frame. Additionally, it will register the
wl_eglstream_controller Wayland interface so that native EGL windows created by
clients can be attached to an EGLStream allowing buffer contents to be shared
with the compositor as a GL texture.
At this time there are two known bugs in the NVIDIA driver's EGL implementation
affecting desktop functionality. The first can result in tooltip windows drawn
by plasmashell to contain incorrect contents. The second prevents KWayland from
being able to query the format of EGLStream-backed buffers which interferes
with the blur effect. Fixes for both of these are currently in development and
should appear in an upcoming NVIDIA driver release.
Additionally, hardware cursors are currently not supported with this backend.
Enabling them causes the desktop to intermittently hang for several seconds.
This is also likely a bug in the NVIDIA DRM-KMS implementation but the root
cause is still under investigation.
Test Plan:
On a system with an NVIDIA graphics card running a recent release of their
proprietary driver
* Ensure the nvidia_drm kernel module is loaded with the option "modeset=1"
("# cat /sys/module/nvidia_drm/parameters/modeset" should print "Y")
* Ensure EGL external platform support is installed
https://github.com/NVIDIA/eglexternalplatform
* Ensure KWin was build with the CMake option
KWIN_BUILD_EGL_STREAM_BACKEND=ON (this is the default)
* Start a plasma wayland session with the environment variable
KWIN_DRM_USE_EGL_STREAMS set
* Ensure output from KWin OpenGL initialization indicates the NVIDIA EGL
driver is in use (as opposed to Mesa / llvmpipe).
* Desktop should be fully functional and perform smoothly.
Reviewers: #kwin, romangg, davidedmundson
Reviewed By: #kwin, romangg, davidedmundson
Subscribers: kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D18570
2019-04-15 14:26:22 +00:00
|
|
|
// EglStreamBackend uses the NV_output_drm_flip_event EGL extension
|
|
|
|
// to register the flip event through eglStreamConsumerAcquireAttribNV
|
|
|
|
#endif
|
|
|
|
flags |= DRM_MODE_PAGE_FLIP_EVENT;
|
2017-05-09 19:29:10 +00:00
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
} else {
|
2017-05-09 19:29:10 +00:00
|
|
|
flags |= DRM_MODE_ATOMIC_TEST_ONLY;
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ret = true;
|
2017-05-09 19:29:10 +00:00
|
|
|
// TODO: Make sure when we use more than one plane at a time, that we go through this list in the right order.
|
|
|
|
for (int i = m_nextPlanesFlipList.size() - 1; 0 <= i; i-- ) {
|
|
|
|
DrmPlane *p = m_nextPlanesFlipList[i];
|
|
|
|
ret &= p->atomicPopulate(req);
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
if (!ret) {
|
|
|
|
qCWarning(KWIN_DRM) << "Failed to populate atomic planes. Abort atomic commit!";
|
|
|
|
errorHandler();
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
if (drmModeAtomicCommit(m_gpu->fd(), req, flags, this)) {
|
|
|
|
qCDebug(KWIN_DRM) << "Atomic request failed to commit: " << strerror(errno);
|
2017-05-09 19:29:10 +00:00
|
|
|
errorHandler();
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
if (mode == AtomicCommitMode::Real && (flags & DRM_MODE_ATOMIC_ALLOW_MODESET)) {
|
|
|
|
qCDebug(KWIN_DRM) << "Atomic Modeset successful.";
|
|
|
|
m_modesetRequested = false;
|
|
|
|
m_dpmsMode = m_dpmsModePending;
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
|
|
|
|
drmModeAtomicFree(req);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::atomicReqModesetPopulate(drmModeAtomicReq *req, bool enable)
|
|
|
|
{
|
|
|
|
if (enable) {
|
2020-01-02 14:55:09 +00:00
|
|
|
const QSize mSize = modeSize();
|
|
|
|
const QSize sourceSize = hardwareTransforms() ? pixelSize() : mSize;
|
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::SrcX), 0);
|
|
|
|
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::SrcY), 0);
|
2020-01-02 14:55:09 +00:00
|
|
|
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::SrcW), sourceSize.width() << 16);
|
|
|
|
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::SrcH), sourceSize.height() << 16);
|
|
|
|
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::CrtcW), mSize.width());
|
|
|
|
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::CrtcH), mSize.height());
|
2017-05-09 19:29:10 +00:00
|
|
|
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::CrtcId), m_crtc->id());
|
|
|
|
} else {
|
2020-10-25 17:47:58 +00:00
|
|
|
if (m_gpu->deleteBufferAfterPageFlip()) {
|
2017-05-09 19:29:10 +00:00
|
|
|
delete m_primaryPlane->current();
|
|
|
|
delete m_primaryPlane->next();
|
|
|
|
}
|
|
|
|
m_primaryPlane->setCurrent(nullptr);
|
|
|
|
m_primaryPlane->setNext(nullptr);
|
|
|
|
|
|
|
|
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::SrcX), 0);
|
|
|
|
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::SrcY), 0);
|
|
|
|
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::SrcW), 0);
|
|
|
|
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::SrcH), 0);
|
|
|
|
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::CrtcW), 0);
|
|
|
|
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::CrtcH), 0);
|
|
|
|
m_primaryPlane->setValue(int(DrmPlane::PropertyIndex::CrtcId), 0);
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
2017-05-09 19:29:10 +00:00
|
|
|
m_conn->setValue(int(DrmConnector::PropertyIndex::CrtcId), enable ? m_crtc->id() : 0);
|
|
|
|
m_crtc->setValue(int(DrmCrtc::PropertyIndex::ModeId), enable ? m_blobId : 0);
|
|
|
|
m_crtc->setValue(int(DrmCrtc::PropertyIndex::Active), enable);
|
|
|
|
|
|
|
|
bool ret = true;
|
|
|
|
ret &= m_conn->atomicPopulate(req);
|
|
|
|
ret &= m_crtc->atomicPopulate(req);
|
|
|
|
|
|
|
|
return ret;
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
2016-03-21 14:11:17 +00:00
|
|
|
|
Backport Night Color feature to X11
Summary:
The color correction manager doesn't make any specific assumptions about
underlying platform, e.g. whether it's x11, etc. The platform just
has to be capable of setting gamma ramps. Given that, there are no any
significant technical blockers for making this feature work on x.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, neobrain, GB_2, filipf, davidedmundson, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D21345
2019-06-17 09:07:19 +00:00
|
|
|
int DrmOutput::gammaRampSize() const
|
2018-03-30 13:03:37 +00:00
|
|
|
{
|
Backport Night Color feature to X11
Summary:
The color correction manager doesn't make any specific assumptions about
underlying platform, e.g. whether it's x11, etc. The platform just
has to be capable of setting gamma ramps. Given that, there are no any
significant technical blockers for making this feature work on x.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, neobrain, GB_2, filipf, davidedmundson, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D21345
2019-06-17 09:07:19 +00:00
|
|
|
return m_crtc->gammaRampSize();
|
2018-03-30 13:03:37 +00:00
|
|
|
}
|
|
|
|
|
Backport Night Color feature to X11
Summary:
The color correction manager doesn't make any specific assumptions about
underlying platform, e.g. whether it's x11, etc. The platform just
has to be capable of setting gamma ramps. Given that, there are no any
significant technical blockers for making this feature work on x.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, neobrain, GB_2, filipf, davidedmundson, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D21345
2019-06-17 09:07:19 +00:00
|
|
|
bool DrmOutput::setGammaRamp(const GammaRamp &gamma)
|
2018-03-30 13:03:37 +00:00
|
|
|
{
|
|
|
|
return m_crtc->setGammaRamp(gamma);
|
|
|
|
}
|
|
|
|
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
2020-04-08 14:07:36 +00:00
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
QDebug& operator<<(QDebug& s, const KWin::DrmOutput *output)
|
2020-04-08 14:07:36 +00:00
|
|
|
{
|
|
|
|
if (!output)
|
|
|
|
return s.nospace() << "DrmOutput()";
|
|
|
|
return s.nospace() << "DrmOutput(" << output->name() << ", crtc:" << output->crtc() << ", connector:" << output->connector() << ", geometry:" << output->geometry() << ')';
|
|
|
|
}
|