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
|
2015-04-24 10:01:39 +00:00
|
|
|
// KWayland
|
2016-05-25 09:24:45 +00:00
|
|
|
#include <KWayland/Server/seat_interface.h>
|
2016-03-10 18:57:07 +00:00
|
|
|
#include <KWayland/Server/outputconfiguration_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
|
|
|
|
#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
|
|
|
{
|
2015-04-24 10:01:39 +00:00
|
|
|
handleOutputs();
|
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);
|
|
|
|
}
|
|
|
|
qDeleteAll(m_outputs);
|
[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
|
|
|
}
|
|
|
|
|
2016-02-15 14:40:25 +00:00
|
|
|
void DrmBackend::outputWentOff()
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
for (auto it = m_outputs.constBegin(), end = m_outputs.constEnd(); it != end; it++) {
|
|
|
|
(*it)->setDpms(DrmOutput::DpmsMode::On);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmBackend::checkOutputsAreOn()
|
|
|
|
{
|
|
|
|
if (m_dpmsFilter.isNull()) {
|
|
|
|
// already disabled, all outputs are on
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (auto it = m_outputs.constBegin(), end = m_outputs.constEnd(); it != end; it++) {
|
|
|
|
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;
|
|
|
|
o->pageFlipped(); // TODO: Do we really need this?
|
[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);
|
|
|
|
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
|
|
|
|
|
|
|
if (output->m_dpmsAtomicOffPending) {
|
|
|
|
output->m_modesetRequested = true;
|
|
|
|
output->dpmsAtomicOff();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
int fd = LogindIntegration::self()->takeDevice(device->devNode());
|
|
|
|
if (fd < 0) {
|
2015-05-05 15:27:03 +00:00
|
|
|
qCWarning(KWIN_DRM) << "failed to open drm device at" << device->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;
|
|
|
|
|
|
|
|
ScopedDrmPointer<drmModePlaneRes, &drmModeFreePlaneResources> planeResources(drmModeGetPlaneResources(m_fd));
|
|
|
|
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-05-09 19:29:10 +00:00
|
|
|
DrmPlane *p = new DrmPlane(kplane->plane_id, this);
|
|
|
|
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.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
[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
|
|
|
ScopedDrmPointer<_drmModeRes, &drmModeFreeResources> resources(drmModeGetResources(m_fd));
|
|
|
|
drmModeRes *res = resources.data();
|
|
|
|
if (!resources) {
|
|
|
|
qCWarning(KWIN_DRM) << "drmModeGetResources failed";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < res->count_connectors; ++i) {
|
2017-05-09 19:29:10 +00:00
|
|
|
m_connectors << new DrmConnector(res->connectors[i], this);
|
[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
|
|
|
|
2015-04-09 12:49:32 +00:00
|
|
|
ScopedDrmPointer<_drmModeRes, &drmModeFreeResources> resources(drmModeGetResources(m_fd));
|
|
|
|
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);
|
|
|
|
emit outputRemoved(removed);
|
|
|
|
delete removed;
|
|
|
|
}
|
[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)) {
|
|
|
|
ScopedDrmPointer<_drmModeConnector, &drmModeFreeConnector> connector(drmModeGetConnector(m_fd, con->id()));
|
|
|
|
if (!connector) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (connector->count_modes == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bool outputDone = false;
|
|
|
|
|
|
|
|
QVector<uint32_t> encoders = con->encoders();
|
|
|
|
for (auto encId : qAsConst(encoders)) {
|
|
|
|
ScopedDrmPointer<_drmModeEncoder, &drmModeFreeEncoder> encoder(drmModeGetEncoder(m_fd, encId));
|
|
|
|
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
|
|
|
|
ScopedDrmPointer<_drmModeCrtc, &drmModeFreeCrtc> modeCrtc(drmModeGetCrtc(m_fd, crtc->id()));
|
|
|
|
if (!modeCrtc) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmOutput *output = new DrmOutput(this);
|
|
|
|
con->setOutput(output);
|
|
|
|
output->m_conn = con;
|
|
|
|
crtc->setOutput(output);
|
|
|
|
output->m_crtc = crtc;
|
|
|
|
connect(output, &DrmOutput::dpmsChanged, this, &DrmBackend::outputDpmsChanged);
|
|
|
|
|
|
|
|
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();
|
|
|
|
con->setOutput(nullptr);
|
|
|
|
crtc->setOutput(nullptr);
|
|
|
|
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;
|
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
|
2016-11-14 18:30:29 +00:00
|
|
|
(*it)->setScale(outputConfig.readEntry("Scale", 1.0));
|
|
|
|
pos.setX(pos.x() + (*it)->geometry().width());
|
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
|
|
|
}
|
|
|
|
|
2016-03-10 18:57:07 +00:00
|
|
|
void DrmBackend::configurationChangeRequested(KWayland::Server::OutputConfigurationInterface *config)
|
|
|
|
{
|
|
|
|
const auto changes = config->changes();
|
|
|
|
for (auto it = changes.begin(); it != changes.end(); it++) {
|
|
|
|
|
|
|
|
KWayland::Server::OutputChangeSet *changeset = it.value();
|
|
|
|
|
|
|
|
auto drmoutput = findOutput(it.key()->uuid());
|
|
|
|
if (drmoutput == nullptr) {
|
|
|
|
qCWarning(KWIN_DRM) << "Could NOT find DrmOutput matching " << it.key()->uuid();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
drmoutput->setChanges(changeset);
|
|
|
|
}
|
2016-06-14 08:53:46 +00:00
|
|
|
emit screens()->changed();
|
2017-09-21 12:52:46 +00:00
|
|
|
// KCoreAddons needs kwayland's 2b3f9509ac1 to not crash
|
|
|
|
if (KCoreAddons::version() >= QT_VERSION_CHECK(5, 39, 0)) {
|
|
|
|
config->setApplied();
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2016-03-10 18:57:07 +00:00
|
|
|
DrmOutput *DrmBackend::findOutput(const QByteArray &uuid)
|
|
|
|
{
|
|
|
|
auto it = std::find_if(m_outputs.constBegin(), m_outputs.constEnd(), [uuid] (DrmOutput *o) {
|
|
|
|
return o->m_uuid == uuid;
|
|
|
|
});
|
|
|
|
if (it != m_outputs.constEnd()) {
|
|
|
|
return *it;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-04-17 09:16:00 +00:00
|
|
|
void DrmBackend::present(DrmBuffer *buffer, DrmOutput *output)
|
|
|
|
{
|
2017-07-14 11:42:52 +00:00
|
|
|
if (!buffer || buffer->bufferId() == 0) {
|
|
|
|
if (m_deleteBufferAfterPageFlip) {
|
|
|
|
delete buffer;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
2017-07-14 11:42:52 +00:00
|
|
|
} else if (m_deleteBufferAfterPageFlip) {
|
|
|
|
delete buffer;
|
2015-04-13 07:23:03 +00:00
|
|
|
}
|
2015-04-09 12:49:32 +00:00
|
|
|
}
|
|
|
|
|
2015-04-13 14:25:34 +00:00
|
|
|
void DrmBackend::initCursor()
|
|
|
|
{
|
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) {
|
2017-11-05 10:59:24 +00:00
|
|
|
(*it)->showCursor();
|
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) {
|
2017-11-05 10:59:24 +00:00
|
|
|
(*it)->showCursor();
|
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
|
|
|
{
|
2016-05-25 09:24:45 +00:00
|
|
|
if (!m_cursorEnabled) {
|
|
|
|
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()
|
|
|
|
{
|
2016-10-20 08:21:54 +00:00
|
|
|
if (!m_cursorEnabled || isCursorHidden()) {
|
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()
|
|
|
|
{
|
|
|
|
#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-05-09 19:00:33 +00:00
|
|
|
DrmDumbBuffer *b = new DrmDumbBuffer(this, 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-05-09 19:00:33 +00:00
|
|
|
DrmSurfaceBuffer *b = new DrmSurfaceBuffer(this, 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
|
|
|
|
2015-08-31 09:41:19 +00:00
|
|
|
void DrmBackend::outputDpmsChanged()
|
|
|
|
{
|
|
|
|
if (m_outputs.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool enabled = false;
|
|
|
|
for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) {
|
|
|
|
enabled = enabled || (*it)->isDpmsEnabled();
|
|
|
|
}
|
|
|
|
setOutputsEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
2017-10-15 20:24:49 +00:00
|
|
|
QVector<CompositingType> DrmBackend::supportedCompositors() const
|
|
|
|
{
|
|
|
|
#if HAVE_GBM
|
|
|
|
return QVector<CompositingType>{OpenGLCompositing, QPainterCompositing};
|
|
|
|
#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;
|
|
|
|
return supportInfo;
|
|
|
|
}
|
|
|
|
|
2015-04-09 12:49:32 +00:00
|
|
|
}
|