2015-04-09 12:49:32 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2015 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "drm_backend.h"
|
2016-03-21 14:11:17 +00:00
|
|
|
#include "drm_output.h"
|
2016-08-31 12:00:31 +00:00
|
|
|
#include "drm_object_connector.h"
|
|
|
|
#include "drm_object_crtc.h"
|
|
|
|
#include "drm_object_plane.h"
|
2015-04-13 07:23:03 +00:00
|
|
|
#include "composite.h"
|
2015-04-13 14:25:34 +00:00
|
|
|
#include "cursor.h"
|
2015-05-05 15:27:03 +00:00
|
|
|
#include "logging.h"
|
2015-04-09 12:49:32 +00:00
|
|
|
#include "logind.h"
|
2016-04-13 12:08:38 +00:00
|
|
|
#include "main.h"
|
2015-05-05 11:32:33 +00:00
|
|
|
#include "scene_qpainter_drm_backend.h"
|
2015-04-09 12:49:32 +00:00
|
|
|
#include "screens_drm.h"
|
|
|
|
#include "udev.h"
|
2015-04-24 10:01:39 +00:00
|
|
|
#include "wayland_server.h"
|
2015-04-10 08:44:07 +00:00
|
|
|
#if HAVE_GBM
|
|
|
|
#include "egl_gbm_backend.h"
|
2016-08-19 14:09:18 +00:00
|
|
|
#include <gbm.h>
|
2015-04-10 08:44:07 +00:00
|
|
|
#endif
|
[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
|
|
|
|
#include "egl_stream_backend.h"
|
|
|
|
#endif
|
2015-04-24 10:01:39 +00:00
|
|
|
// KWayland
|
2016-05-25 09:24:45 +00:00
|
|
|
#include <KWayland/Server/seat_interface.h>
|
2015-04-27 09:06:04 +00:00
|
|
|
// KF5
|
|
|
|
#include <KConfigGroup>
|
2017-09-21 12:52:46 +00:00
|
|
|
#include <KCoreAddons>
|
2015-04-27 09:06:04 +00:00
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <KSharedConfig>
|
2015-04-13 07:23:03 +00:00
|
|
|
// Qt
|
2015-11-02 08:34:32 +00:00
|
|
|
#include <QCryptographicHash>
|
2015-04-13 07:23:03 +00:00
|
|
|
#include <QSocketNotifier>
|
2015-04-13 14:25:34 +00:00
|
|
|
#include <QPainter>
|
2015-04-09 12:49:32 +00:00
|
|
|
// system
|
2018-03-28 23:27:21 +00:00
|
|
|
#include <algorithm>
|
2015-04-09 12:49:32 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
// drm
|
|
|
|
#include <xf86drm.h>
|
|
|
|
#include <xf86drmMode.h>
|
|
|
|
#include <libdrm/drm_mode.h>
|
|
|
|
|
2015-04-13 14:25:34 +00:00
|
|
|
#ifndef DRM_CAP_CURSOR_WIDTH
|
|
|
|
#define DRM_CAP_CURSOR_WIDTH 0x8
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef DRM_CAP_CURSOR_HEIGHT
|
|
|
|
#define DRM_CAP_CURSOR_HEIGHT 0x9
|
|
|
|
#endif
|
|
|
|
|
2017-04-10 04:52:44 +00:00
|
|
|
#define KWIN_DRM_EVENT_CONTEXT_VERSION 2
|
|
|
|
|
2015-04-09 12:49:32 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
DrmBackend::DrmBackend(QObject *parent)
|
2016-04-07 07:18:10 +00:00
|
|
|
: Platform(parent)
|
2015-04-09 12:49:32 +00:00
|
|
|
, m_udev(new Udev)
|
2015-04-24 06:15:55 +00:00
|
|
|
, m_udevMonitor(m_udev->monitor())
|
2016-02-15 14:40:25 +00:00
|
|
|
, m_dpmsFilter()
|
2015-04-09 12:49:32 +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
|
|
|
|
if (qEnvironmentVariableIsSet("KWIN_DRM_USE_EGL_STREAMS")) {
|
|
|
|
m_useEglStreams = true;
|
|
|
|
}
|
|
|
|
#endif
|
[colorcorrection] Night Color - blue light filter at nighttime
With Wayland KWin needs to provide certain services, which were provided
before that by the Xserver. One of these is gamma correction, which includes
the - by many people beloved - functionality to reduce the blue light at
nighttime. This patch provides the KWin part of that. It is self contained,
but in the end will work in tandem with a lib in Plasma Workspace and a KCM
in Plasma Desktop, which can be used to configure Night Color.
* Three modi:
** Automatic: The location and sun timings are determined automatically
(location data updates will be provided by the workspace)
** Location: The sun timings are determined by fixed location data
** Timings: The sun timings are set manually by the user
* Color temperature value changes are smoothly applied:
** Configuration changes, which lead to other current values are changed
in a quick way over a few seconds
** Changes on sunrise and sunset are applied slowly over the course of few
minutes till several hours depending on the configuration
* The current color value is set immediately at startup or after suspend
phases and VT switches. There is no flickering.
* All configuration is done via a DBus interface, changed values are tested
on correctness and applied atomically
* Self contained mechanism, speaks directly to the hardware by setting the
gamma ramps on the CRTC
* Currently working on DRM backend, extensible to other platform backends in
the future
* The code is written in a way to make the classes later easily extendable to
also provide normal color correction, as it's currently done by KGamma on X
Test Plan:
Manually with the workspace parts and added integration tests in KWin using
the virtual backend.
BUG:371494
Reviewers: #kwin, graesslin
Subscribers: kwin, plasma-devel, #kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D5928
2017-12-11 09:43:12 +00:00
|
|
|
setSupportsGammaControl(true);
|
2019-08-28 18:54:37 +00:00
|
|
|
supportsOutputChanges();
|
2015-04-09 12:49:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DrmBackend::~DrmBackend()
|
|
|
|
{
|
2016-08-19 14:09:18 +00:00
|
|
|
#if HAVE_GBM
|
|
|
|
if (m_gbmDevice) {
|
|
|
|
gbm_device_destroy(m_gbmDevice);
|
|
|
|
}
|
|
|
|
#endif
|
2015-04-09 12:49:32 +00:00
|
|
|
if (m_fd >= 0) {
|
2015-04-14 09:25:16 +00:00
|
|
|
// wait for pageflips
|
|
|
|
while (m_pageFlipsPending != 0) {
|
|
|
|
QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents);
|
|
|
|
}
|
2018-03-28 23:27:21 +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
|
|
|
qDeleteAll(m_planes);
|
|
|
|
qDeleteAll(m_crtcs);
|
|
|
|
qDeleteAll(m_connectors);
|
2015-04-09 12:49:32 +00:00
|
|
|
close(m_fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmBackend::init()
|
|
|
|
{
|
|
|
|
LogindIntegration *logind = LogindIntegration::self();
|
|
|
|
auto takeControl = [logind, this]() {
|
|
|
|
if (logind->hasSessionControl()) {
|
|
|
|
openDrm();
|
|
|
|
} else {
|
|
|
|
logind->takeControl();
|
|
|
|
connect(logind, &LogindIntegration::hasSessionControlChanged, this, &DrmBackend::openDrm);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (logind->isConnected()) {
|
|
|
|
takeControl();
|
|
|
|
} else {
|
|
|
|
connect(logind, &LogindIntegration::connectedChanged, this, takeControl);
|
|
|
|
}
|
2015-04-15 16:26:25 +00:00
|
|
|
}
|
|
|
|
|
2019-09-05 14:59:53 +00:00
|
|
|
void DrmBackend::prepareShutdown()
|
|
|
|
{
|
|
|
|
writeOutputsConfiguration();
|
|
|
|
for (DrmOutput *output : m_outputs) {
|
|
|
|
output->teardown();
|
|
|
|
}
|
|
|
|
Platform::prepareShutdown();
|
|
|
|
}
|
|
|
|
|
2018-03-28 23:27:21 +00:00
|
|
|
Outputs DrmBackend::outputs() const
|
|
|
|
{
|
|
|
|
return m_outputs;
|
|
|
|
}
|
|
|
|
|
|
|
|
Outputs DrmBackend::enabledOutputs() const
|
|
|
|
{
|
|
|
|
return m_enabledOutputs;
|
|
|
|
}
|
|
|
|
|
2019-08-31 08:27:04 +00:00
|
|
|
void DrmBackend::createDpmsFilter()
|
2016-02-15 14:40:25 +00:00
|
|
|
{
|
|
|
|
if (!m_dpmsFilter.isNull()) {
|
|
|
|
// already another output is off
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_dpmsFilter.reset(new DpmsInputEventFilter(this));
|
2017-01-02 19:13:30 +00:00
|
|
|
input()->prependInputEventFilter(m_dpmsFilter.data());
|
2016-02-15 14:40:25 +00:00
|
|
|
}
|
|
|
|
|
2016-02-15 15:30:22 +00:00
|
|
|
void DrmBackend::turnOutputsOn()
|
2016-02-15 14:40:25 +00:00
|
|
|
{
|
|
|
|
m_dpmsFilter.reset();
|
2017-11-21 12:04:30 +00:00
|
|
|
for (auto it = m_enabledOutputs.constBegin(), end = m_enabledOutputs.constEnd(); it != end; it++) {
|
2018-11-09 19:28:57 +00:00
|
|
|
(*it)->updateDpms(KWayland::Server::OutputInterface::DpmsMode::On);
|
2016-02-15 14:40:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmBackend::checkOutputsAreOn()
|
|
|
|
{
|
|
|
|
if (m_dpmsFilter.isNull()) {
|
|
|
|
// already disabled, all outputs are on
|
|
|
|
return;
|
|
|
|
}
|
2017-11-21 12:04:30 +00:00
|
|
|
for (auto it = m_enabledOutputs.constBegin(), end = m_enabledOutputs.constEnd(); it != end; it++) {
|
2016-02-15 14:40:25 +00:00
|
|
|
if (!(*it)->isDpmsEnabled()) {
|
|
|
|
// dpms still disabled, need to keep the filter
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// all outputs are on, disable the filter
|
|
|
|
m_dpmsFilter.reset();
|
|
|
|
}
|
|
|
|
|
2015-04-15 16:26:25 +00:00
|
|
|
void DrmBackend::activate(bool active)
|
|
|
|
{
|
|
|
|
if (active) {
|
2017-05-09 19:29:10 +00:00
|
|
|
qCDebug(KWIN_DRM) << "Activating session.";
|
2015-04-15 16:26:25 +00:00
|
|
|
reactivate();
|
|
|
|
} else {
|
2017-05-09 19:29:10 +00:00
|
|
|
qCDebug(KWIN_DRM) << "Deactivating session.";
|
2015-04-15 16:26:25 +00:00
|
|
|
deactivate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmBackend::reactivate()
|
|
|
|
{
|
|
|
|
if (m_active) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_active = true;
|
2016-06-28 08:20:27 +00:00
|
|
|
if (!usesSoftwareCursor()) {
|
|
|
|
const QPoint cp = Cursor::pos() - softwareCursorHotspot();
|
|
|
|
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
|
|
|
|
DrmOutput *o = *it;
|
2017-05-09 19:29:10 +00:00
|
|
|
// only relevant in atomic mode
|
|
|
|
o->m_modesetRequested = true;
|
[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
|
|
|
o->m_crtc->blank();
|
2017-11-05 10:59:24 +00:00
|
|
|
o->showCursor();
|
2016-06-28 08:20:27 +00:00
|
|
|
o->moveCursor(cp);
|
|
|
|
}
|
2015-04-15 16:26:25 +00:00
|
|
|
}
|
|
|
|
// restart compositor
|
|
|
|
m_pageFlipsPending = 0;
|
|
|
|
if (Compositor *compositor = Compositor::self()) {
|
|
|
|
compositor->bufferSwapComplete();
|
|
|
|
compositor->addRepaintFull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmBackend::deactivate()
|
|
|
|
{
|
|
|
|
if (!m_active) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// block compositor
|
|
|
|
if (m_pageFlipsPending == 0 && Compositor::self()) {
|
|
|
|
Compositor::self()->aboutToSwapBuffers();
|
|
|
|
}
|
|
|
|
// hide cursor and disable
|
|
|
|
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
|
|
|
|
DrmOutput *o = *it;
|
|
|
|
o->hideCursor();
|
|
|
|
}
|
|
|
|
m_active = false;
|
2015-04-09 12:49:32 +00:00
|
|
|
}
|
|
|
|
|
2015-04-13 07:23:03 +00:00
|
|
|
void DrmBackend::pageFlipHandler(int fd, unsigned int frame, unsigned int sec, unsigned int usec, void *data)
|
|
|
|
{
|
|
|
|
Q_UNUSED(fd)
|
|
|
|
Q_UNUSED(frame)
|
|
|
|
Q_UNUSED(sec)
|
|
|
|
Q_UNUSED(usec)
|
2015-04-14 09:25:16 +00:00
|
|
|
auto output = reinterpret_cast<DrmOutput*>(data);
|
2019-08-31 08:27:04 +00:00
|
|
|
|
2015-04-14 09:25:16 +00:00
|
|
|
output->pageFlipped();
|
|
|
|
output->m_backend->m_pageFlipsPending--;
|
|
|
|
if (output->m_backend->m_pageFlipsPending == 0) {
|
|
|
|
// TODO: improve, this currently means we wait for all page flips or all outputs.
|
|
|
|
// It would be better to driver the repaint per output
|
2017-05-09 19:29:10 +00:00
|
|
|
|
2015-04-14 09:25:16 +00:00
|
|
|
if (Compositor::self()) {
|
|
|
|
Compositor::self()->bufferSwapComplete();
|
|
|
|
}
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
2015-04-13 07:23:03 +00:00
|
|
|
}
|
|
|
|
|
2015-04-09 12:49:32 +00:00
|
|
|
void DrmBackend::openDrm()
|
|
|
|
{
|
2015-04-15 16:26:25 +00:00
|
|
|
connect(LogindIntegration::self(), &LogindIntegration::sessionActiveChanged, this, &DrmBackend::activate);
|
2015-04-09 12:49:32 +00:00
|
|
|
UdevDevice::Ptr device = m_udev->primaryGpu();
|
|
|
|
if (!device) {
|
2015-05-05 15:27:03 +00:00
|
|
|
qCWarning(KWIN_DRM) << "Did not find a GPU";
|
2015-04-09 12:49:32 +00:00
|
|
|
return;
|
|
|
|
}
|
[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
|
|
|
m_devNode = device->devNode();
|
|
|
|
int fd = LogindIntegration::self()->takeDevice(m_devNode.constData());
|
2015-04-09 12:49:32 +00:00
|
|
|
if (fd < 0) {
|
[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
|
|
|
qCWarning(KWIN_DRM) << "failed to open drm device at" << m_devNode;
|
2015-04-09 12:49:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_fd = fd;
|
2015-04-15 16:26:25 +00:00
|
|
|
m_active = true;
|
2015-04-13 07:23:03 +00:00
|
|
|
QSocketNotifier *notifier = new QSocketNotifier(m_fd, QSocketNotifier::Read, this);
|
|
|
|
connect(notifier, &QSocketNotifier::activated, this,
|
|
|
|
[this] {
|
2016-04-19 07:46:16 +00:00
|
|
|
if (!LogindIntegration::self()->isActiveSession()) {
|
2015-04-15 16:26:25 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-04-13 07:23:03 +00:00
|
|
|
drmEventContext e;
|
|
|
|
memset(&e, 0, sizeof e);
|
2017-04-10 04:52:44 +00:00
|
|
|
e.version = KWIN_DRM_EVENT_CONTEXT_VERSION;
|
2015-04-13 07:23:03 +00:00
|
|
|
e.page_flip_handler = pageFlipHandler;
|
|
|
|
drmHandleEvent(m_fd, &e);
|
|
|
|
}
|
|
|
|
);
|
2015-04-09 12:49:32 +00:00
|
|
|
m_drmId = device->sysNum();
|
2016-08-31 12:00:31 +00:00
|
|
|
|
|
|
|
// trying to activate Atomic Mode Setting (this means also Universal Planes)
|
2017-05-22 09:59:01 +00:00
|
|
|
if (!qEnvironmentVariableIsSet("KWIN_DRM_NO_AMS")) {
|
2016-08-31 12:00:31 +00:00
|
|
|
if (drmSetClientCap(m_fd, DRM_CLIENT_CAP_ATOMIC, 1) == 0) {
|
|
|
|
qCDebug(KWIN_DRM) << "Using Atomic Mode Setting.";
|
|
|
|
m_atomicModeSetting = true;
|
|
|
|
|
2019-03-20 08:32:26 +00:00
|
|
|
DrmScopedPointer<drmModePlaneRes> planeResources(drmModeGetPlaneResources(m_fd));
|
2016-08-31 12:00:31 +00:00
|
|
|
if (!planeResources) {
|
|
|
|
qCWarning(KWIN_DRM) << "Failed to get plane resources. Falling back to legacy mode";
|
|
|
|
m_atomicModeSetting = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_atomicModeSetting) {
|
|
|
|
qCDebug(KWIN_DRM) << "Number of planes:" << planeResources->count_planes;
|
|
|
|
|
|
|
|
// create the plane objects
|
|
|
|
for (unsigned int i = 0; i < planeResources->count_planes; ++i) {
|
|
|
|
drmModePlane *kplane = drmModeGetPlane(m_fd, planeResources->planes[i]);
|
2017-11-12 20:00:02 +00:00
|
|
|
DrmPlane *p = new DrmPlane(kplane->plane_id, m_fd);
|
2017-05-09 19:29:10 +00:00
|
|
|
if (p->atomicInit()) {
|
2016-08-31 12:00:31 +00:00
|
|
|
m_planes << p;
|
2017-05-09 19:29:10 +00:00
|
|
|
if (p->type() == DrmPlane::TypeIndex::Overlay) {
|
|
|
|
m_overlayPlanes << p;
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
} else {
|
|
|
|
delete p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_planes.isEmpty()) {
|
|
|
|
qCWarning(KWIN_DRM) << "Failed to create any plane. Falling back to legacy mode";
|
|
|
|
m_atomicModeSetting = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qCWarning(KWIN_DRM) << "drmSetClientCap for Atomic Mode Setting failed. Using legacy mode.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-20 08:32:26 +00:00
|
|
|
DrmScopedPointer<drmModeRes> resources(drmModeGetResources(m_fd));
|
[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
|
|
|
drmModeRes *res = resources.data();
|
|
|
|
if (!resources) {
|
|
|
|
qCWarning(KWIN_DRM) << "drmModeGetResources failed";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < res->count_connectors; ++i) {
|
2017-11-12 20:00:02 +00:00
|
|
|
m_connectors << new DrmConnector(res->connectors[i], m_fd);
|
[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
|
|
|
}
|
|
|
|
for (int i = 0; i < res->count_crtcs; ++i) {
|
2017-05-09 19:29:10 +00:00
|
|
|
m_crtcs << new DrmCrtc(res->crtcs[i], this, i);
|
[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_atomicModeSetting) {
|
2017-05-09 19:29:10 +00:00
|
|
|
auto tryAtomicInit = [] (DrmObject *obj) -> bool {
|
|
|
|
if (obj->atomicInit()) {
|
[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;
|
|
|
|
} else {
|
2017-05-09 19:29:10 +00:00
|
|
|
delete obj;
|
[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 true;
|
|
|
|
}
|
|
|
|
};
|
2017-05-09 19:29:10 +00:00
|
|
|
m_connectors.erase(std::remove_if(m_connectors.begin(), m_connectors.end(), tryAtomicInit), m_connectors.end());
|
|
|
|
m_crtcs.erase(std::remove_if(m_crtcs.begin(), m_crtcs.end(), tryAtomicInit), m_crtcs.end());
|
[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
|
|
|
}
|
|
|
|
|
2017-11-05 10:59:24 +00:00
|
|
|
initCursor();
|
2017-05-09 19:29:10 +00:00
|
|
|
updateOutputs();
|
[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-07-11 09:26:03 +00:00
|
|
|
if (m_outputs.isEmpty()) {
|
|
|
|
qCWarning(KWIN_DRM) << "No outputs, cannot render, will terminate now";
|
|
|
|
emit initFailed();
|
|
|
|
return;
|
|
|
|
}
|
2015-04-24 06:15:55 +00:00
|
|
|
|
|
|
|
// setup udevMonitor
|
|
|
|
if (m_udevMonitor) {
|
|
|
|
m_udevMonitor->filterSubsystemDevType("drm");
|
|
|
|
const int fd = m_udevMonitor->fd();
|
|
|
|
if (fd != -1) {
|
|
|
|
QSocketNotifier *notifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
|
|
|
|
connect(notifier, &QSocketNotifier::activated, this,
|
|
|
|
[this] {
|
|
|
|
auto device = m_udevMonitor->getDevice();
|
|
|
|
if (!device) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (device->sysNum() != m_drmId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (device->hasProperty("HOTPLUG", "1")) {
|
2015-05-05 15:27:03 +00:00
|
|
|
qCDebug(KWIN_DRM) << "Received hot plug event for monitored drm device";
|
2017-05-09 19:29:10 +00:00
|
|
|
updateOutputs();
|
2015-04-24 06:15:55 +00:00
|
|
|
updateCursor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
m_udevMonitor->enable();
|
|
|
|
}
|
|
|
|
}
|
2015-05-05 17:02:52 +00:00
|
|
|
setReady(true);
|
2015-04-09 12:49:32 +00:00
|
|
|
}
|
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
void DrmBackend::updateOutputs()
|
2015-04-09 12:49:32 +00:00
|
|
|
{
|
|
|
|
if (m_fd < 0) {
|
|
|
|
return;
|
|
|
|
}
|
[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
|
|
|
|
2019-03-20 08:32:26 +00:00
|
|
|
DrmScopedPointer<drmModeRes> resources(drmModeGetResources(m_fd));
|
2015-04-09 12:49:32 +00:00
|
|
|
if (!resources) {
|
2015-05-05 15:27:03 +00:00
|
|
|
qCWarning(KWIN_DRM) << "drmModeGetResources failed";
|
2015-04-09 12:49:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-04-24 06:15:55 +00:00
|
|
|
|
|
|
|
QVector<DrmOutput*> connectedOutputs;
|
[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
|
|
|
QVector<DrmConnector*> pendingConnectors;
|
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
|
|
|
// split up connected connectors in already or not yet assigned ones
|
|
|
|
for (DrmConnector *con : qAsConst(m_connectors)) {
|
|
|
|
if (!con->isConnected()) {
|
|
|
|
continue;
|
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
|
|
|
if (DrmOutput *o = findOutput(con->id())) {
|
|
|
|
connectedOutputs << o;
|
2015-04-24 06:15:55 +00:00
|
|
|
} else {
|
[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
|
|
|
pendingConnectors << con;
|
2016-07-11 09:26:03 +00:00
|
|
|
}
|
2015-04-24 06:15:55 +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
|
|
|
|
2015-04-24 06:15:55 +00:00
|
|
|
// check for outputs which got removed
|
|
|
|
auto it = m_outputs.begin();
|
|
|
|
while (it != m_outputs.end()) {
|
|
|
|
if (connectedOutputs.contains(*it)) {
|
|
|
|
it++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
DrmOutput *removed = *it;
|
|
|
|
it = m_outputs.erase(it);
|
2017-11-21 12:04:30 +00:00
|
|
|
m_enabledOutputs.removeOne(removed);
|
2015-04-24 06:15:55 +00:00
|
|
|
emit outputRemoved(removed);
|
2018-07-18 14:13:38 +00:00
|
|
|
removed->teardown();
|
2015-04-24 06:15:55 +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
|
|
|
|
|
|
|
// now check new connections
|
|
|
|
for (DrmConnector *con : qAsConst(pendingConnectors)) {
|
2019-03-20 08:32:26 +00:00
|
|
|
DrmScopedPointer<drmModeConnector> connector(drmModeGetConnector(m_fd, con->id()));
|
[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 (!connector) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (connector->count_modes == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bool outputDone = false;
|
|
|
|
|
|
|
|
QVector<uint32_t> encoders = con->encoders();
|
|
|
|
for (auto encId : qAsConst(encoders)) {
|
2019-03-20 08:32:26 +00:00
|
|
|
DrmScopedPointer<drmModeEncoder> encoder(drmModeGetEncoder(m_fd, encId));
|
[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 (!encoder) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (DrmCrtc *crtc : qAsConst(m_crtcs)) {
|
|
|
|
if (!(encoder->possible_crtcs & (1 << crtc->resIndex()))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if crtc isn't used yet -- currently we don't allow multiple outputs on one crtc (cloned mode)
|
|
|
|
auto it = std::find_if(connectedOutputs.constBegin(), connectedOutputs.constEnd(),
|
|
|
|
[crtc] (DrmOutput *o) {
|
|
|
|
return o->m_crtc == crtc;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
if (it != connectedOutputs.constEnd()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// we found a suitable encoder+crtc
|
|
|
|
// TODO: we could avoid these lib drm calls if we store all struct data in DrmCrtc and DrmConnector in the beginning
|
2019-03-20 08:32:26 +00:00
|
|
|
DrmScopedPointer<drmModeCrtc> modeCrtc(drmModeGetCrtc(m_fd, crtc->id()));
|
[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 (!modeCrtc) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmOutput *output = new DrmOutput(this);
|
|
|
|
con->setOutput(output);
|
|
|
|
output->m_conn = con;
|
|
|
|
crtc->setOutput(output);
|
|
|
|
output->m_crtc = crtc;
|
|
|
|
|
|
|
|
if (modeCrtc->mode_valid) {
|
|
|
|
output->m_mode = modeCrtc->mode;
|
|
|
|
} else {
|
|
|
|
output->m_mode = connector->modes[0];
|
|
|
|
}
|
|
|
|
qCDebug(KWIN_DRM) << "For new output use mode " << output->m_mode.name;
|
|
|
|
|
|
|
|
if (!output->init(connector.data())) {
|
|
|
|
qCWarning(KWIN_DRM) << "Failed to create output for connector " << con->id();
|
|
|
|
delete output;
|
|
|
|
continue;
|
|
|
|
}
|
2017-11-05 10:59:24 +00:00
|
|
|
if (!output->initCursor(m_cursorSize)) {
|
|
|
|
setSoftWareCursor(true);
|
|
|
|
}
|
[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) << "Found new output with uuid" << output->uuid();
|
|
|
|
|
|
|
|
connectedOutputs << output;
|
|
|
|
emit outputAdded(output);
|
|
|
|
outputDone = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (outputDone) {
|
|
|
|
break;
|
|
|
|
}
|
2015-04-24 06:15:55 +00:00
|
|
|
}
|
2015-04-09 12:49:32 +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
|
|
|
std::sort(connectedOutputs.begin(), connectedOutputs.end(), [] (DrmOutput *a, DrmOutput *b) { return a->m_conn->id() < b->m_conn->id(); });
|
2015-04-24 06:15:55 +00:00
|
|
|
m_outputs = connectedOutputs;
|
2017-11-21 12:04:30 +00:00
|
|
|
m_enabledOutputs = connectedOutputs;
|
2015-11-02 08:34:32 +00:00
|
|
|
readOutputsConfiguration();
|
2016-07-11 09:26:03 +00:00
|
|
|
if (!m_outputs.isEmpty()) {
|
|
|
|
emit screensQueried();
|
|
|
|
}
|
2015-11-02 08:34:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrmBackend::readOutputsConfiguration()
|
|
|
|
{
|
|
|
|
if (m_outputs.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const QByteArray uuid = generateOutputConfigurationUuid();
|
2016-01-29 10:24:18 +00:00
|
|
|
const auto outputGroup = kwinApp()->config()->group("DrmOutputs");
|
2015-11-02 08:34:32 +00:00
|
|
|
const auto configGroup = outputGroup.group(uuid);
|
|
|
|
// default position goes from left to right
|
|
|
|
QPoint pos(0, 0);
|
|
|
|
for (auto it = m_outputs.begin(); it != m_outputs.end(); ++it) {
|
2017-05-11 10:08:03 +00:00
|
|
|
qCDebug(KWIN_DRM) << "Reading output configuration for [" << uuid << "] ["<< (*it)->uuid() << "]";
|
2015-11-02 08:34:32 +00:00
|
|
|
const auto outputConfig = configGroup.group((*it)->uuid());
|
|
|
|
(*it)->setGlobalPos(outputConfig.readEntry<QPoint>("Position", pos));
|
|
|
|
// TODO: add mode
|
2019-04-24 23:45:14 +00:00
|
|
|
if (outputConfig.hasKey("Scale"))
|
|
|
|
(*it)->setScale(outputConfig.readEntry("Scale", 1.0));
|
2016-11-14 18:30:29 +00:00
|
|
|
pos.setX(pos.x() + (*it)->geometry().width());
|
2015-11-02 08:34:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-05 17:38:32 +00:00
|
|
|
void DrmBackend::writeOutputsConfiguration()
|
|
|
|
{
|
|
|
|
if (m_outputs.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const QByteArray uuid = generateOutputConfigurationUuid();
|
|
|
|
auto configGroup = KSharedConfig::openConfig()->group("DrmOutputs").group(uuid);
|
|
|
|
// default position goes from left to right
|
|
|
|
for (auto it = m_outputs.cbegin(); it != m_outputs.cend(); ++it) {
|
|
|
|
qCDebug(KWIN_DRM) << "Writing output configuration for [" << uuid << "] ["<< (*it)->uuid() << "]";
|
|
|
|
auto outputConfig = configGroup.group((*it)->uuid());
|
|
|
|
outputConfig.writeEntry("Scale", (*it)->scale());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-02 08:34:32 +00:00
|
|
|
QByteArray DrmBackend::generateOutputConfigurationUuid() const
|
|
|
|
{
|
|
|
|
auto it = m_outputs.constBegin();
|
|
|
|
if (m_outputs.size() == 1) {
|
|
|
|
// special case: one output
|
|
|
|
return (*it)->uuid();
|
|
|
|
}
|
|
|
|
QCryptographicHash hash(QCryptographicHash::Md5);
|
|
|
|
for (; it != m_outputs.constEnd(); ++it) {
|
|
|
|
hash.addData((*it)->uuid());
|
|
|
|
}
|
|
|
|
return hash.result().toHex().left(10);
|
2015-04-09 12:49:32 +00:00
|
|
|
}
|
|
|
|
|
2019-08-31 08:27:04 +00:00
|
|
|
void DrmBackend::enableOutput(DrmOutput *output, bool enable)
|
2016-03-10 18:57:07 +00:00
|
|
|
{
|
2019-08-28 18:54:37 +00:00
|
|
|
if (enable) {
|
2019-08-31 08:27:04 +00:00
|
|
|
Q_ASSERT(!m_enabledOutputs.contains(output));
|
|
|
|
m_enabledOutputs << output;
|
|
|
|
emit outputAdded(output);
|
2017-11-21 12:04:30 +00:00
|
|
|
} else {
|
2019-08-31 08:27:04 +00:00
|
|
|
Q_ASSERT(m_enabledOutputs.contains(output));
|
|
|
|
m_enabledOutputs.removeOne(output);
|
|
|
|
Q_ASSERT(!m_enabledOutputs.contains(output));
|
|
|
|
emit outputRemoved(output);
|
2017-11-21 12:04:30 +00:00
|
|
|
}
|
2019-08-31 08:27:04 +00:00
|
|
|
updateOutputsEnabled();
|
|
|
|
checkOutputsAreOn();
|
|
|
|
emit screensQueried();
|
2016-03-10 18:57:07 +00:00
|
|
|
}
|
|
|
|
|
2015-04-24 06:15:55 +00:00
|
|
|
DrmOutput *DrmBackend::findOutput(quint32 connector)
|
|
|
|
{
|
|
|
|
auto it = std::find_if(m_outputs.constBegin(), m_outputs.constEnd(), [connector] (DrmOutput *o) {
|
[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 o->m_conn->id() == connector;
|
2015-04-24 06:15:55 +00:00
|
|
|
});
|
|
|
|
if (it != m_outputs.constEnd()) {
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
[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
|
|
|
bool DrmBackend::present(DrmBuffer *buffer, DrmOutput *output)
|
2015-04-17 09:16:00 +00:00
|
|
|
{
|
2017-07-14 11:42:52 +00:00
|
|
|
if (!buffer || buffer->bufferId() == 0) {
|
|
|
|
if (m_deleteBufferAfterPageFlip) {
|
|
|
|
delete buffer;
|
|
|
|
}
|
[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
|
|
|
return false;
|
2017-07-14 11:42:52 +00:00
|
|
|
}
|
|
|
|
|
2015-04-17 09:16:00 +00:00
|
|
|
if (output->present(buffer)) {
|
2015-04-14 09:25:16 +00:00
|
|
|
m_pageFlipsPending++;
|
|
|
|
if (m_pageFlipsPending == 1 && Compositor::self()) {
|
|
|
|
Compositor::self()->aboutToSwapBuffers();
|
|
|
|
}
|
[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
|
|
|
return true;
|
2017-07-14 11:42:52 +00:00
|
|
|
} else if (m_deleteBufferAfterPageFlip) {
|
|
|
|
delete buffer;
|
2015-04-13 07:23:03 +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
|
|
|
return false;
|
2015-04-09 12:49:32 +00:00
|
|
|
}
|
|
|
|
|
2015-04-13 14:25:34 +00:00
|
|
|
void DrmBackend::initCursor()
|
|
|
|
{
|
[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
|
|
|
|
// Hardware cursors aren't currently supported with EGLStream backend,
|
|
|
|
// possibly an NVIDIA driver bug
|
|
|
|
if (m_useEglStreams) {
|
|
|
|
setSoftWareCursor(true);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-05-25 09:24:45 +00:00
|
|
|
m_cursorEnabled = waylandServer()->seat()->hasPointer();
|
|
|
|
connect(waylandServer()->seat(), &KWayland::Server::SeatInterface::hasPointerChanged, this,
|
|
|
|
[this] {
|
|
|
|
m_cursorEnabled = waylandServer()->seat()->hasPointer();
|
2016-06-28 08:20:27 +00:00
|
|
|
if (usesSoftwareCursor()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-05-25 09:24:45 +00:00
|
|
|
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
|
|
|
|
if (m_cursorEnabled) {
|
2018-04-22 13:17:53 +00:00
|
|
|
if (!(*it)->showCursor()) {
|
|
|
|
setSoftWareCursor(true);
|
|
|
|
}
|
2016-05-25 09:24:45 +00:00
|
|
|
} else {
|
|
|
|
(*it)->hideCursor();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2015-04-13 14:25:34 +00:00
|
|
|
uint64_t capability = 0;
|
|
|
|
QSize cursorSize;
|
|
|
|
if (drmGetCap(m_fd, DRM_CAP_CURSOR_WIDTH, &capability) == 0) {
|
|
|
|
cursorSize.setWidth(capability);
|
|
|
|
} else {
|
|
|
|
cursorSize.setWidth(64);
|
|
|
|
}
|
|
|
|
if (drmGetCap(m_fd, DRM_CAP_CURSOR_HEIGHT, &capability) == 0) {
|
|
|
|
cursorSize.setHeight(capability);
|
|
|
|
} else {
|
|
|
|
cursorSize.setHeight(64);
|
|
|
|
}
|
2017-11-05 10:59:24 +00:00
|
|
|
m_cursorSize = cursorSize;
|
2015-04-13 14:25:34 +00:00
|
|
|
// now we have screens and can set cursors, so start tracking
|
|
|
|
connect(this, &DrmBackend::cursorChanged, this, &DrmBackend::updateCursor);
|
|
|
|
connect(Cursor::self(), &Cursor::posChanged, this, &DrmBackend::moveCursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmBackend::setCursor()
|
|
|
|
{
|
2016-05-25 09:24:45 +00:00
|
|
|
if (m_cursorEnabled) {
|
|
|
|
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
|
2018-04-22 13:17:53 +00:00
|
|
|
if (!(*it)->showCursor()) {
|
|
|
|
setSoftWareCursor(true);
|
|
|
|
}
|
2016-05-25 09:24:45 +00:00
|
|
|
}
|
2015-04-14 09:25:16 +00:00
|
|
|
}
|
2016-02-23 11:29:05 +00:00
|
|
|
markCursorAsRendered();
|
2015-04-13 14:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrmBackend::updateCursor()
|
|
|
|
{
|
2016-06-28 08:20:27 +00:00
|
|
|
if (usesSoftwareCursor()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-20 08:21:54 +00:00
|
|
|
if (isCursorHidden()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-13 14:25:34 +00:00
|
|
|
const QImage &cursorImage = softwareCursor();
|
|
|
|
if (cursorImage.isNull()) {
|
2016-10-20 08:21:54 +00:00
|
|
|
doHideCursor();
|
2015-04-13 14:25:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-11-05 10:59:24 +00:00
|
|
|
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
|
|
|
|
(*it)->updateCursor();
|
|
|
|
}
|
2015-04-13 14:25:34 +00:00
|
|
|
|
|
|
|
setCursor();
|
|
|
|
moveCursor();
|
|
|
|
}
|
|
|
|
|
2016-10-20 08:21:54 +00:00
|
|
|
void DrmBackend::doShowCursor()
|
|
|
|
{
|
|
|
|
updateCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmBackend::doHideCursor()
|
2015-04-13 14:25:34 +00:00
|
|
|
{
|
2019-03-19 19:46:16 +00:00
|
|
|
if (!m_cursorEnabled || usesSoftwareCursor()) {
|
2016-05-25 09:24:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-04-14 09:25:16 +00:00
|
|
|
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
|
|
|
|
(*it)->hideCursor();
|
|
|
|
}
|
2015-04-13 14:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrmBackend::moveCursor()
|
|
|
|
{
|
2019-03-19 19:46:16 +00:00
|
|
|
if (!m_cursorEnabled || isCursorHidden() || usesSoftwareCursor()) {
|
2016-05-25 09:24:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-04-14 09:25:16 +00:00
|
|
|
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
|
2017-09-18 15:40:21 +00:00
|
|
|
(*it)->moveCursor(Cursor::pos());
|
2015-04-14 09:25:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-09 12:49:32 +00:00
|
|
|
Screens *DrmBackend::createScreens(QObject *parent)
|
|
|
|
{
|
|
|
|
return new DrmScreens(this, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPainterBackend *DrmBackend::createQPainterBackend()
|
|
|
|
{
|
2017-05-09 19:00:33 +00:00
|
|
|
m_deleteBufferAfterPageFlip = false;
|
2015-04-09 12:49:32 +00:00
|
|
|
return new DrmQPainterBackend(this);
|
|
|
|
}
|
|
|
|
|
2015-04-10 08:44:07 +00:00
|
|
|
OpenGLBackend *DrmBackend::createOpenGLBackend()
|
|
|
|
{
|
[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
|
|
|
|
if (m_useEglStreams) {
|
|
|
|
m_deleteBufferAfterPageFlip = false;
|
|
|
|
return new EglStreamBackend(this);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-04-10 08:44:07 +00:00
|
|
|
#if HAVE_GBM
|
2017-05-09 19:00:33 +00:00
|
|
|
m_deleteBufferAfterPageFlip = true;
|
2015-04-10 08:44:07 +00:00
|
|
|
return new EglGbmBackend(this);
|
2015-04-24 13:14:53 +00:00
|
|
|
#else
|
2016-04-07 07:18:10 +00:00
|
|
|
return Platform::createOpenGLBackend();
|
2015-04-24 13:14:53 +00:00
|
|
|
#endif
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
|
|
|
|
2017-05-09 19:00:33 +00:00
|
|
|
DrmDumbBuffer *DrmBackend::createBuffer(const QSize &size)
|
2015-04-09 12:49:32 +00:00
|
|
|
{
|
2017-11-12 20:00:02 +00:00
|
|
|
DrmDumbBuffer *b = new DrmDumbBuffer(m_fd, size);
|
2015-04-24 08:23:06 +00:00
|
|
|
return b;
|
2015-04-09 12:49:32 +00:00
|
|
|
}
|
|
|
|
|
2017-05-11 21:47:27 +00:00
|
|
|
#if HAVE_GBM
|
2017-10-05 16:58:57 +00:00
|
|
|
DrmSurfaceBuffer *DrmBackend::createBuffer(const std::shared_ptr<GbmSurface> &surface)
|
2015-04-10 08:44:07 +00:00
|
|
|
{
|
2017-11-12 20:00:02 +00:00
|
|
|
DrmSurfaceBuffer *b = new DrmSurfaceBuffer(m_fd, surface);
|
2015-04-24 08:23:06 +00:00
|
|
|
return b;
|
2015-04-10 08:44:07 +00:00
|
|
|
}
|
2017-05-11 21:47:27 +00:00
|
|
|
#endif
|
2015-04-10 08:44:07 +00:00
|
|
|
|
2019-08-31 08:27:04 +00:00
|
|
|
void DrmBackend::updateOutputsEnabled()
|
2015-08-31 09:41:19 +00:00
|
|
|
{
|
2017-11-21 12:04:30 +00:00
|
|
|
if (m_enabledOutputs.isEmpty()) {
|
2015-08-31 09:41:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool enabled = false;
|
2017-11-21 12:04:30 +00:00
|
|
|
for (auto it = m_enabledOutputs.constBegin(); it != m_enabledOutputs.constEnd(); ++it) {
|
2015-08-31 09:41:19 +00:00
|
|
|
enabled = enabled || (*it)->isDpmsEnabled();
|
|
|
|
}
|
|
|
|
setOutputsEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
2017-10-15 20:24:49 +00:00
|
|
|
QVector<CompositingType> DrmBackend::supportedCompositors() const
|
|
|
|
{
|
2019-02-16 19:50:46 +00:00
|
|
|
if (selectedCompositor() != NoCompositing) {
|
|
|
|
return {selectedCompositor()};
|
|
|
|
}
|
2017-10-15 20:24:49 +00:00
|
|
|
#if HAVE_GBM
|
|
|
|
return QVector<CompositingType>{OpenGLCompositing, QPainterCompositing};
|
[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
|
|
|
#elif HAVE_EGL_STREAMS
|
|
|
|
return m_useEglStreams ?
|
|
|
|
QVector<CompositingType>{OpenGLCompositing, QPainterCompositing} :
|
|
|
|
QVector<CompositingType>{QPainterCompositing};
|
2017-10-15 20:24:49 +00:00
|
|
|
#else
|
|
|
|
return QVector<CompositingType>{QPainterCompositing};
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-11-07 19:12:51 +00:00
|
|
|
QString DrmBackend::supportInformation() const
|
|
|
|
{
|
|
|
|
QString supportInfo;
|
|
|
|
QDebug s(&supportInfo);
|
|
|
|
s.nospace();
|
|
|
|
s << "Name: " << "DRM" << endl;
|
|
|
|
s << "Active: " << m_active << endl;
|
|
|
|
s << "Atomic Mode Setting: " << m_atomicModeSetting << endl;
|
[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
|
|
|
|
s << "Using EGL Streams: " << m_useEglStreams << endl;
|
|
|
|
#endif
|
2017-11-07 19:12:51 +00:00
|
|
|
return supportInfo;
|
|
|
|
}
|
|
|
|
|
2015-04-09 12:49:32 +00:00
|
|
|
}
|