2020-08-02 22:22:19 +00:00
|
|
|
/*
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
2016-03-21 14:11:17 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-FileCopyrightText: 2015 Martin Gräßlin <mgraesslin@kde.org>
|
2016-03-21 14:11:17 +00:00
|
|
|
|
2020-08-02 22:22:19 +00:00
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2016-03-21 14:11:17 +00:00
|
|
|
#include "drm_output.h"
|
|
|
|
#include "drm_backend.h"
|
2016-08-31 12:00:31 +00:00
|
|
|
#include "drm_object_crtc.h"
|
|
|
|
#include "drm_object_connector.h"
|
|
|
|
|
2016-03-21 14:11:17 +00:00
|
|
|
#include "composite.h"
|
2020-04-02 16:18:01 +00:00
|
|
|
#include "cursor.h"
|
2016-03-21 14:11:17 +00:00
|
|
|
#include "logging.h"
|
2016-04-13 12:08:38 +00:00
|
|
|
#include "main.h"
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
#include "renderloop.h"
|
2021-02-20 15:04:18 +00:00
|
|
|
#include "renderloop_p.h"
|
2021-01-30 13:22:07 +00:00
|
|
|
#include "screens.h"
|
|
|
|
#include "session.h"
|
2016-03-21 14:11:17 +00:00
|
|
|
// Qt
|
2017-11-02 17:13:17 +00:00
|
|
|
#include <QMatrix4x4>
|
2016-03-21 14:11:17 +00:00
|
|
|
#include <QCryptographicHash>
|
2017-11-05 10:59:24 +00:00
|
|
|
#include <QPainter>
|
2019-07-09 19:19:26 +00:00
|
|
|
// c++
|
|
|
|
#include <cerrno>
|
2016-03-21 14:11:17 +00:00
|
|
|
// drm
|
|
|
|
#include <xf86drm.h>
|
|
|
|
#include <libdrm/drm_mode.h>
|
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
#include "drm_gpu.h"
|
|
|
|
|
2016-03-21 14:11:17 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2020-10-05 21:05:55 +00:00
|
|
|
DrmOutput::DrmOutput(DrmBackend *backend, DrmGpu *gpu)
|
2019-06-13 09:36:07 +00:00
|
|
|
: AbstractWaylandOutput(backend)
|
2016-03-21 14:11:17 +00:00
|
|
|
, m_backend(backend)
|
2020-10-05 21:05:55 +00:00
|
|
|
, m_gpu(gpu)
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
, m_renderLoop(new RenderLoop(this))
|
2016-03-21 14:11:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
DrmOutput::~DrmOutput()
|
|
|
|
{
|
2018-07-18 14:13:38 +00:00
|
|
|
Q_ASSERT(!m_pageFlipPending);
|
2019-09-05 14:59:53 +00:00
|
|
|
teardown();
|
2018-07-18 14:13:38 +00:00
|
|
|
}
|
|
|
|
|
Introduce RenderLoop
At the moment, our frame scheduling infrastructure is still heavily
based on Xinerama-style rendering. Specifically, we assume that painting
is driven by a single timer, etc.
This change introduces a new type - RenderLoop. Its main purpose is to
drive compositing on a specific output, or in case of X11, on the
overlay window.
With RenderLoop, compositing is synchronized to vblank events. It
exposes the last and the next estimated presentation timestamp. The
expected presentation timestamp can be used by effects to ensure that
animations are synchronized with the upcoming vblank event.
On Wayland, every outputs has its own render loop. On X11, per screen
rendering is not possible, therefore the platform exposes the render
loop for the overlay window. Ideally, the Scene has to expose the
RenderLoop, but as the first step towards better compositing scheduling
it's good as is for the time being.
The RenderLoop tries to minimize the latency by delaying compositing as
close as possible to the next vblank event. One tricky thing about it is
that if compositing is too close to the next vblank event, animations
may become a little bit choppy. However, increasing the latency reduces
the choppiness.
Given that, there is no any "silver bullet" solution for the choppiness
issue, a new option has been added in the Compositing KCM to specify the
amount of latency. By default, it's "Medium," but if a user is not
satisfied with the upstream default, they can tweak it.
2020-11-19 08:52:29 +00:00
|
|
|
RenderLoop *DrmOutput::renderLoop() const
|
|
|
|
{
|
|
|
|
return m_renderLoop;
|
|
|
|
}
|
|
|
|
|
2018-07-18 14:13:38 +00:00
|
|
|
void DrmOutput::teardown()
|
|
|
|
{
|
2019-09-05 14:59:53 +00:00
|
|
|
if (m_deleted) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-18 14:13:38 +00:00
|
|
|
m_deleted = true;
|
2016-03-21 14:11:17 +00:00
|
|
|
hideCursor();
|
2021-04-20 10:53:02 +00:00
|
|
|
m_crtc->blank(this);
|
2017-05-09 19:29:10 +00:00
|
|
|
|
|
|
|
if (m_primaryPlane) {
|
|
|
|
// TODO: when having multiple planes, also clean up these
|
|
|
|
m_primaryPlane->setCurrent(nullptr);
|
|
|
|
}
|
|
|
|
|
2021-04-20 10:53:02 +00:00
|
|
|
m_cursor[0].reset(nullptr);
|
|
|
|
m_cursor[1].reset(nullptr);
|
2018-07-18 14:13:38 +00:00
|
|
|
if (!m_pageFlipPending) {
|
|
|
|
deleteLater();
|
|
|
|
} //else will be deleted in the page flip handler
|
|
|
|
//this is needed so that the pageflipcallback handle isn't deleted
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 20:38:36 +00:00
|
|
|
void DrmOutput::releaseGbm()
|
|
|
|
{
|
|
|
|
if (auto buffer = m_crtc->current()) {
|
|
|
|
buffer->releaseGbm();
|
|
|
|
}
|
|
|
|
if (auto buffer = m_crtc->next()) {
|
|
|
|
buffer->releaseGbm();
|
|
|
|
}
|
|
|
|
if (m_primaryPlane) {
|
|
|
|
if (auto buffer = m_primaryPlane->current()) {
|
|
|
|
buffer->releaseGbm();
|
|
|
|
}
|
|
|
|
if (auto buffer = m_primaryPlane->next()) {
|
|
|
|
buffer->releaseGbm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 10:53:02 +00:00
|
|
|
bool DrmOutput::hideCursor()
|
2016-03-21 14:11:17 +00:00
|
|
|
{
|
2021-02-20 15:04:18 +00:00
|
|
|
if (RenderLoopPrivate::get(m_renderLoop)->presentMode == RenderLoopPrivate::SyncMode::Adaptive
|
|
|
|
&& isCursorVisible()) {
|
|
|
|
m_renderLoop->scheduleRepaint();
|
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
return drmModeSetCursor(m_gpu->fd(), m_crtc->id(), 0, 0, 0) == 0;
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 10:53:02 +00:00
|
|
|
bool DrmOutput::showCursor(DrmDumbBuffer *c)
|
2016-03-21 14:11:17 +00:00
|
|
|
{
|
2021-04-20 10:53:02 +00:00
|
|
|
const QSize &s = c->size();
|
2021-02-20 15:04:18 +00:00
|
|
|
if (drmModeSetCursor(m_gpu->fd(), m_crtc->id(), c->handle(), s.width(), s.height()) == 0) {
|
|
|
|
if (RenderLoopPrivate::get(m_renderLoop)->presentMode == RenderLoopPrivate::SyncMode::Adaptive
|
|
|
|
&& isCursorVisible()) {
|
|
|
|
m_renderLoop->scheduleRepaint();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
|
2018-04-22 13:17:53 +00:00
|
|
|
bool DrmOutput::showCursor()
|
2017-11-05 10:59:24 +00:00
|
|
|
{
|
2021-04-20 10:53:02 +00:00
|
|
|
if (m_deleted) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool ret = showCursor(m_cursor[m_cursorIndex].data());
|
|
|
|
if (!ret) {
|
|
|
|
qCDebug(KWIN_DRM) << "DrmOutput::showCursor(DrmDumbBuffer) failed";
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-02-20 15:04:18 +00:00
|
|
|
bool visibleBefore = isCursorVisible();
|
2021-04-20 10:53:02 +00:00
|
|
|
if (m_hasNewCursor) {
|
|
|
|
m_cursorIndex = (m_cursorIndex + 1) % 2;
|
|
|
|
m_hasNewCursor = false;
|
|
|
|
}
|
2021-02-20 15:04:18 +00:00
|
|
|
if (RenderLoopPrivate::get(m_renderLoop)->presentMode == RenderLoopPrivate::SyncMode::Adaptive
|
|
|
|
&& !visibleBefore
|
|
|
|
&& isCursorVisible()) {
|
|
|
|
m_renderLoop->scheduleRepaint();
|
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
|
|
|
|
return ret;
|
2017-11-05 10:59:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-28 07:03:09 +00:00
|
|
|
static bool isCursorSpriteCompatible(const QImage *buffer, const QImage *sprite)
|
|
|
|
{
|
|
|
|
// Note that we need compare the rects in the device independent pixels because the
|
|
|
|
// buffer and the cursor sprite image may have different scale factors.
|
|
|
|
const QRect bufferRect(QPoint(0, 0), buffer->size() / buffer->devicePixelRatio());
|
|
|
|
const QRect spriteRect(QPoint(0, 0), sprite->size() / sprite->devicePixelRatio());
|
|
|
|
|
|
|
|
return bufferRect.contains(spriteRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::updateCursor()
|
2017-11-05 10:59:24 +00:00
|
|
|
{
|
2020-07-28 16:48:57 +00:00
|
|
|
if (m_deleted) {
|
2020-10-28 07:03:09 +00:00
|
|
|
return false;
|
2020-07-28 16:48:57 +00:00
|
|
|
}
|
2020-10-25 15:19:07 +00:00
|
|
|
const Cursor *cursor = Cursors::self()->currentCursor();
|
|
|
|
const QImage cursorImage = cursor->image();
|
2017-11-05 10:59:24 +00:00
|
|
|
if (cursorImage.isNull()) {
|
2021-04-20 10:53:02 +00:00
|
|
|
return false;
|
2017-11-05 10:59:24 +00:00
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
|
|
|
|
QImage *c = m_cursor[m_cursorIndex]->image();
|
2020-10-28 07:03:09 +00:00
|
|
|
c->setDevicePixelRatio(scale());
|
2021-04-20 10:53:02 +00:00
|
|
|
|
2020-10-28 07:03:09 +00:00
|
|
|
if (!isCursorSpriteCompatible(c, &cursorImage)) {
|
|
|
|
// If the cursor image is too big, fall back to rendering the software cursor.
|
|
|
|
return false;
|
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
|
|
|
|
m_hasNewCursor = true;
|
2017-11-05 10:59:24 +00:00
|
|
|
c->fill(Qt::transparent);
|
2021-04-20 10:53:02 +00:00
|
|
|
|
2017-11-05 10:59:24 +00:00
|
|
|
QPainter p;
|
|
|
|
p.begin(c);
|
2020-10-28 07:03:09 +00:00
|
|
|
p.setWorldTransform(logicalToNativeMatrix(cursor->rect(), 1, transform()).toTransform());
|
2017-11-05 10:59:24 +00:00
|
|
|
p.drawImage(QPoint(0, 0), cursorImage);
|
|
|
|
p.end();
|
2021-02-20 15:04:18 +00:00
|
|
|
if (RenderLoopPrivate::get(m_renderLoop)->presentMode == RenderLoopPrivate::SyncMode::Adaptive
|
|
|
|
&& isCursorVisible()) {
|
|
|
|
m_renderLoop->scheduleRepaint();
|
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
return true;
|
2017-11-05 10:59:24 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 10:53:02 +00:00
|
|
|
void DrmOutput::moveCursor()
|
2016-03-21 14:11:17 +00:00
|
|
|
{
|
2020-10-27 11:50:06 +00:00
|
|
|
Cursor *cursor = Cursors::self()->currentCursor();
|
2020-10-25 15:19:07 +00:00
|
|
|
const QMatrix4x4 hotspotMatrix = logicalToNativeMatrix(cursor->rect(), scale(), transform());
|
2020-10-13 20:57:15 +00:00
|
|
|
const QMatrix4x4 monitorMatrix = logicalToNativeMatrix(geometry(), scale(), transform());
|
2020-10-13 20:15:46 +00:00
|
|
|
|
2020-10-27 11:50:06 +00:00
|
|
|
QPoint pos = monitorMatrix.map(cursor->pos());
|
2020-04-02 16:18:01 +00:00
|
|
|
pos -= hotspotMatrix.map(cursor->hotspot());
|
2020-10-12 20:56:07 +00:00
|
|
|
|
2021-02-20 15:04:18 +00:00
|
|
|
if (pos != m_cursorPos) {
|
|
|
|
bool visible = isCursorVisible();
|
|
|
|
drmModeMoveCursor(m_gpu->fd(), m_crtc->id(), pos.x(), pos.y());
|
|
|
|
m_cursorPos = pos;
|
|
|
|
if (RenderLoopPrivate::get(m_renderLoop)->presentMode == RenderLoopPrivate::SyncMode::Adaptive
|
|
|
|
&& (visible || visible != isCursorVisible())) {
|
|
|
|
m_renderLoop->scheduleRepaint();
|
|
|
|
}
|
|
|
|
}
|
2021-04-07 13:31:04 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 10:53:02 +00:00
|
|
|
namespace {
|
|
|
|
quint64 refreshRateForMode(_drmModeModeInfo *m)
|
2016-03-21 14:11:17 +00:00
|
|
|
{
|
2021-04-20 10:53:02 +00:00
|
|
|
// Calculate higher precision (mHz) refresh rate
|
|
|
|
// logic based on Weston, see compositor-drm.c
|
|
|
|
quint64 refreshRate = (m->clock * 1000000LL / m->htotal + m->vtotal / 2) / m->vtotal;
|
|
|
|
if (m->flags & DRM_MODE_FLAG_INTERLACE) {
|
|
|
|
refreshRate *= 2;
|
|
|
|
}
|
|
|
|
if (m->flags & DRM_MODE_FLAG_DBLSCAN) {
|
|
|
|
refreshRate /= 2;
|
|
|
|
}
|
|
|
|
if (m->vscan > 1) {
|
|
|
|
refreshRate /= m->vscan;
|
|
|
|
}
|
|
|
|
return refreshRate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static AbstractWaylandOutput::SubPixel drmSubPixelToKWinSubPixel(drmModeSubPixel subpixel)
|
|
|
|
{
|
|
|
|
switch (subpixel) {
|
|
|
|
case DRM_MODE_SUBPIXEL_UNKNOWN:
|
|
|
|
return AbstractWaylandOutput::SubPixel::Unknown;
|
|
|
|
case DRM_MODE_SUBPIXEL_NONE:
|
|
|
|
return AbstractWaylandOutput::SubPixel::None;
|
|
|
|
case DRM_MODE_SUBPIXEL_HORIZONTAL_RGB:
|
|
|
|
return AbstractWaylandOutput::SubPixel::Horizontal_RGB;
|
|
|
|
case DRM_MODE_SUBPIXEL_HORIZONTAL_BGR:
|
|
|
|
return AbstractWaylandOutput::SubPixel::Horizontal_BGR;
|
|
|
|
case DRM_MODE_SUBPIXEL_VERTICAL_RGB:
|
|
|
|
return AbstractWaylandOutput::SubPixel::Vertical_RGB;
|
|
|
|
case DRM_MODE_SUBPIXEL_VERTICAL_BGR:
|
|
|
|
return AbstractWaylandOutput::SubPixel::Vertical_BGR;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::init(drmModeConnector *connector)
|
|
|
|
{
|
|
|
|
if (m_gpu->atomicModeSetting() && !m_primaryPlane) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
setSubPixelInternal(drmSubPixelToKWinSubPixel(connector->subpixel));
|
2021-03-31 11:22:23 +00:00
|
|
|
setInternal(m_conn->isInternal());
|
2021-04-20 10:53:02 +00:00
|
|
|
setCapabilityInternal(DrmOutput::Capability::Dpms);
|
2021-04-11 14:26:21 +00:00
|
|
|
if (m_conn->hasOverscan()) {
|
|
|
|
setCapabilityInternal(Capability::Overscan);
|
|
|
|
setOverscanInternal(m_conn->overscan());
|
|
|
|
}
|
2021-02-20 15:04:18 +00:00
|
|
|
if (m_conn->vrrCapable()) {
|
|
|
|
setCapabilityInternal(Capability::Vrr);
|
|
|
|
setVrrPolicy(RenderLoop::VrrPolicy::Automatic);
|
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
initOutputDevice(connector);
|
2019-10-21 12:56:33 +00:00
|
|
|
|
2021-04-20 10:53:02 +00:00
|
|
|
if (!m_gpu->atomicModeSetting() && !m_crtc->blank(this)) {
|
|
|
|
// We use legacy mode and the initial output blank failed.
|
|
|
|
return false;
|
|
|
|
}
|
2019-10-21 12:56:33 +00:00
|
|
|
|
2021-04-04 14:11:13 +00:00
|
|
|
setDpmsMode(DpmsMode::On);
|
2021-04-20 10:53:02 +00:00
|
|
|
return true;
|
2021-03-27 14:01:34 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 10:53:02 +00:00
|
|
|
void DrmOutput::initOutputDevice(drmModeConnector *connector)
|
2017-11-15 16:08:09 +00:00
|
|
|
{
|
2021-04-20 10:53:02 +00:00
|
|
|
// read in mode information
|
2021-04-04 14:11:13 +00:00
|
|
|
QVector<Mode> modes;
|
2021-04-20 10:53:02 +00:00
|
|
|
modes.reserve(connector->count_modes);
|
|
|
|
for (int i = 0; i < connector->count_modes; ++i) {
|
|
|
|
// TODO: in AMS here we could read and store for later every mode's blob_id
|
|
|
|
// would simplify isCurrentMode(..) and presentAtomically(..) in case of mode set
|
|
|
|
auto *m = &connector->modes[i];
|
2021-04-04 14:11:13 +00:00
|
|
|
|
|
|
|
Mode mode;
|
2021-04-20 10:53:02 +00:00
|
|
|
if (isCurrentMode(m)) {
|
2021-04-04 14:11:13 +00:00
|
|
|
mode.flags |= ModeFlag::Current;
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
if (m->type & DRM_MODE_TYPE_PREFERRED) {
|
2021-04-04 14:11:13 +00:00
|
|
|
mode.flags |= ModeFlag::Preferred;
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
|
2016-03-21 14:11:17 +00:00
|
|
|
mode.id = i;
|
2021-04-20 10:53:02 +00:00
|
|
|
mode.size = QSize(m->hdisplay, m->vdisplay);
|
|
|
|
mode.refreshRate = refreshRateForMode(m);
|
2018-11-09 20:13:56 +00:00
|
|
|
modes << mode;
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
2018-11-09 20:13:56 +00:00
|
|
|
|
2021-03-31 11:22:23 +00:00
|
|
|
setName(m_conn->connectorName());
|
2021-04-06 20:15:24 +00:00
|
|
|
initialize(m_conn->modelName(), m_conn->edid()->manufacturerString(),
|
|
|
|
m_conn->edid()->eisaId(), m_conn->edid()->serialNumber(),
|
2021-04-06 20:08:02 +00:00
|
|
|
m_conn->physicalSize(), modes, m_conn->edid()->raw());
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 10:53:02 +00:00
|
|
|
bool DrmOutput::isCurrentMode(const drmModeModeInfo *mode) const
|
2018-11-09 21:58:23 +00:00
|
|
|
{
|
2021-04-20 10:53:02 +00:00
|
|
|
return mode->clock == m_mode.clock
|
|
|
|
&& mode->hdisplay == m_mode.hdisplay
|
|
|
|
&& mode->hsync_start == m_mode.hsync_start
|
|
|
|
&& mode->hsync_end == m_mode.hsync_end
|
|
|
|
&& mode->htotal == m_mode.htotal
|
|
|
|
&& mode->hskew == m_mode.hskew
|
|
|
|
&& mode->vdisplay == m_mode.vdisplay
|
|
|
|
&& mode->vsync_start == m_mode.vsync_start
|
|
|
|
&& mode->vsync_end == m_mode.vsync_end
|
|
|
|
&& mode->vtotal == m_mode.vtotal
|
|
|
|
&& mode->vscan == m_mode.vscan
|
|
|
|
&& mode->vrefresh == m_mode.vrefresh
|
|
|
|
&& mode->flags == m_mode.flags
|
|
|
|
&& mode->type == m_mode.type
|
|
|
|
&& qstrcmp(mode->name, m_mode.name) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::initCursor(const QSize &cursorSize)
|
|
|
|
{
|
|
|
|
auto createCursor = [this, cursorSize] (int index) {
|
|
|
|
m_cursor[index].reset(new DrmDumbBuffer(m_gpu, cursorSize));
|
|
|
|
if (!m_cursor[index]->map(QImage::Format_ARGB32_Premultiplied)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
if (!createCursor(0) || !createCursor(1)) {
|
|
|
|
return false;
|
2018-11-09 21:58:23 +00:00
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-11-09 21:58:23 +00:00
|
|
|
|
2021-04-20 10:53:02 +00:00
|
|
|
void DrmOutput::updateEnablement(bool enable)
|
|
|
|
{
|
|
|
|
if (enable) {
|
|
|
|
m_dpmsModePending = DpmsMode::On;
|
|
|
|
if (m_gpu->atomicModeSetting()) {
|
|
|
|
atomicEnable();
|
2019-08-31 08:27:04 +00:00
|
|
|
} else {
|
2021-04-20 10:53:02 +00:00
|
|
|
if (dpmsLegacyApply()) {
|
|
|
|
m_backend->enableOutput(this, true);
|
|
|
|
}
|
2019-08-31 08:27:04 +00:00
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
|
2019-08-31 08:27:04 +00:00
|
|
|
} else {
|
2021-04-20 10:53:02 +00:00
|
|
|
m_dpmsModePending = DpmsMode::Off;
|
|
|
|
if (m_gpu->atomicModeSetting()) {
|
|
|
|
atomicDisable();
|
|
|
|
} else {
|
|
|
|
if (dpmsLegacyApply()) {
|
|
|
|
m_backend->enableOutput(this, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmOutput::atomicEnable()
|
|
|
|
{
|
|
|
|
m_modesetRequested = true;
|
|
|
|
|
|
|
|
if (m_atomicOffPending) {
|
|
|
|
Q_ASSERT(m_pageFlipPending);
|
|
|
|
m_atomicOffPending = false;
|
|
|
|
}
|
|
|
|
m_backend->enableOutput(this, true);
|
|
|
|
dpmsFinishOn();
|
|
|
|
|
|
|
|
if (Compositor *compositor = Compositor::self()) {
|
|
|
|
compositor->addRepaintFull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmOutput::atomicDisable()
|
|
|
|
{
|
|
|
|
m_modesetRequested = true;
|
|
|
|
|
|
|
|
m_backend->enableOutput(this, false);
|
|
|
|
m_atomicOffPending = true;
|
|
|
|
if (!m_pageFlipPending) {
|
|
|
|
dpmsAtomicOff();
|
2019-08-31 08:27:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-04 14:11:13 +00:00
|
|
|
void DrmOutput::setDpmsMode(DpmsMode mode)
|
2016-03-21 14:11:17 +00:00
|
|
|
{
|
2021-04-20 10:53:02 +00:00
|
|
|
if (!m_conn->dpms() || !isEnabled()) {
|
2016-03-21 14:11:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
|
|
|
|
if (mode == m_dpmsModePending) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_dpmsModePending = mode;
|
|
|
|
|
|
|
|
if (m_gpu->atomicModeSetting()) {
|
|
|
|
m_modesetRequested = true;
|
|
|
|
if (mode == DpmsMode::On) {
|
|
|
|
if (m_atomicOffPending) {
|
|
|
|
Q_ASSERT(m_pageFlipPending);
|
|
|
|
m_atomicOffPending = false;
|
2017-05-09 19:29:10 +00:00
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
dpmsFinishOn();
|
2016-08-31 12:00:31 +00:00
|
|
|
} else {
|
2021-04-20 10:53:02 +00:00
|
|
|
m_atomicOffPending = true;
|
|
|
|
if (!m_pageFlipPending) {
|
|
|
|
dpmsAtomicOff();
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-04-20 10:53:02 +00:00
|
|
|
dpmsLegacyApply();
|
2019-08-31 08:27:04 +00:00
|
|
|
}
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|
|
|
|
|
2021-04-20 10:53:02 +00:00
|
|
|
void DrmOutput::dpmsFinishOn()
|
|
|
|
{
|
|
|
|
qCDebug(KWIN_DRM) << "DPMS mode set for output" << m_crtc->id() << "to On.";
|
|
|
|
|
|
|
|
m_backend->checkOutputsAreOn();
|
|
|
|
m_crtc->blank(this);
|
|
|
|
m_renderLoop->uninhibit();
|
|
|
|
if (Compositor *compositor = Compositor::self()) {
|
|
|
|
compositor->addRepaintFull();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmOutput::dpmsFinishOff()
|
|
|
|
{
|
|
|
|
qCDebug(KWIN_DRM) << "DPMS mode set for output" << m_crtc->id() << "to Off.";
|
|
|
|
|
|
|
|
if (isEnabled()) {
|
|
|
|
m_backend->createDpmsFilter();
|
|
|
|
}
|
|
|
|
m_renderLoop->inhibit();
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t kwinDpmsModeToDrmDpmsMode(AbstractWaylandOutput::DpmsMode dpmsMode)
|
|
|
|
{
|
|
|
|
switch (dpmsMode) {
|
|
|
|
case AbstractWaylandOutput::DpmsMode::On:
|
|
|
|
return DRM_MODE_DPMS_ON;
|
|
|
|
case AbstractWaylandOutput::DpmsMode::Standby:
|
|
|
|
return DRM_MODE_DPMS_STANDBY;
|
|
|
|
case AbstractWaylandOutput::DpmsMode::Suspend:
|
|
|
|
return DRM_MODE_DPMS_SUSPEND;
|
|
|
|
case AbstractWaylandOutput::DpmsMode::Off:
|
|
|
|
return DRM_MODE_DPMS_OFF;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::dpmsLegacyApply()
|
|
|
|
{
|
|
|
|
if (drmModeConnectorSetProperty(m_gpu->fd(), m_conn->id(),
|
|
|
|
m_conn->dpms()->propId(),
|
|
|
|
kwinDpmsModeToDrmDpmsMode(m_dpmsModePending)) < 0) {
|
|
|
|
m_dpmsModePending = dpmsMode();
|
|
|
|
qCWarning(KWIN_DRM) << "Setting DPMS failed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_dpmsModePending == DpmsMode::On) {
|
|
|
|
dpmsFinishOn();
|
|
|
|
} else {
|
|
|
|
dpmsFinishOff();
|
|
|
|
}
|
|
|
|
setDpmsModeInternal(m_dpmsModePending);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-02 14:55:02 +00:00
|
|
|
DrmPlane::Transformations outputToPlaneTransform(DrmOutput::Transform transform)
|
|
|
|
{
|
|
|
|
using OutTrans = DrmOutput::Transform;
|
|
|
|
using PlaneTrans = DrmPlane::Transformation;
|
|
|
|
|
|
|
|
// TODO: Do we want to support reflections (flips)?
|
|
|
|
|
|
|
|
switch (transform) {
|
|
|
|
case OutTrans::Normal:
|
|
|
|
case OutTrans::Flipped:
|
|
|
|
return PlaneTrans::Rotate0;
|
|
|
|
case OutTrans::Rotated90:
|
|
|
|
case OutTrans::Flipped90:
|
|
|
|
return PlaneTrans::Rotate90;
|
|
|
|
case OutTrans::Rotated180:
|
|
|
|
case OutTrans::Flipped180:
|
|
|
|
return PlaneTrans::Rotate180;
|
|
|
|
case OutTrans::Rotated270:
|
|
|
|
case OutTrans::Flipped270:
|
|
|
|
return PlaneTrans::Rotate270;
|
|
|
|
default:
|
|
|
|
Q_UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::hardwareTransforms() const
|
|
|
|
{
|
|
|
|
if (!m_primaryPlane) {
|
|
|
|
return false;
|
2019-12-01 11:51:38 +00:00
|
|
|
}
|
2020-01-02 14:55:02 +00:00
|
|
|
return m_primaryPlane->transformation() == outputToPlaneTransform(transform());
|
|
|
|
}
|
2019-12-01 11:51:38 +00:00
|
|
|
|
2020-01-02 14:55:02 +00:00
|
|
|
void DrmOutput::updateTransform(Transform transform)
|
|
|
|
{
|
|
|
|
const auto planeTransform = outputToPlaneTransform(transform);
|
|
|
|
|
|
|
|
if (m_primaryPlane) {
|
|
|
|
// At the moment we have to exclude hardware transforms for vertical buffers.
|
|
|
|
// For that we need to support other buffers and graceful fallback from atomic tests.
|
|
|
|
// Reason is that standard linear buffers are not suitable.
|
|
|
|
const bool isPortrait = transform == Transform::Rotated90
|
|
|
|
|| transform == Transform::Flipped90
|
|
|
|
|| transform == Transform::Rotated270
|
|
|
|
|| transform == Transform::Flipped270;
|
2021-04-20 10:53:02 +00:00
|
|
|
|
2020-01-02 14:55:02 +00:00
|
|
|
if (!qEnvironmentVariableIsSet("KWIN_DRM_SW_ROTATIONS_ONLY") &&
|
|
|
|
(m_primaryPlane->supportedTransformations() & planeTransform) &&
|
|
|
|
!isPortrait) {
|
|
|
|
m_primaryPlane->setTransformation(planeTransform);
|
|
|
|
} else {
|
|
|
|
m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate0);
|
|
|
|
}
|
2017-11-06 16:00:15 +00:00
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
m_modesetRequested = true;
|
2019-12-01 11:51:38 +00:00
|
|
|
|
2020-05-20 14:26:15 +00:00
|
|
|
// show cursor only if is enabled, i.e if pointer device is presentP
|
2020-10-27 09:40:38 +00:00
|
|
|
if (!m_backend->isCursorHidden() && !m_backend->usesSoftwareCursor()) {
|
2020-05-20 14:26:15 +00:00
|
|
|
// the cursor might need to get rotated
|
2021-03-27 14:01:34 +00:00
|
|
|
updateCursor();
|
2021-04-20 10:53:02 +00:00
|
|
|
showCursor();
|
2020-05-20 14:26:15 +00:00
|
|
|
}
|
2017-11-06 16:00:15 +00:00
|
|
|
}
|
|
|
|
|
2020-12-15 20:20:10 +00:00
|
|
|
void DrmOutput::updateMode(uint32_t width, uint32_t height, uint32_t refreshRate)
|
|
|
|
{
|
2021-05-04 08:56:59 +00:00
|
|
|
if (m_mode.hdisplay == width && m_mode.vdisplay == height && refreshRateForMode(&m_mode) == refreshRate) {
|
2020-12-15 20:20:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// try to find a fitting mode
|
2021-04-20 10:53:02 +00:00
|
|
|
DrmScopedPointer<drmModeConnector> connector(drmModeGetConnectorCurrent(m_gpu->fd(), m_conn->id()));
|
|
|
|
for (int i = 0; i < connector->count_modes; i++) {
|
|
|
|
auto mode = connector->modes[i];
|
2021-05-04 08:56:59 +00:00
|
|
|
if (mode.hdisplay == width && mode.vdisplay == height && refreshRateForMode(&mode) == refreshRate) {
|
2020-12-15 20:20:10 +00:00
|
|
|
updateMode(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
qCWarning(KWIN_DRM, "Could not find a fitting mode with size=%dx%d and refresh rate %d for output %s",
|
2021-04-06 20:08:02 +00:00
|
|
|
width, height, refreshRate, qPrintable(name()));
|
2020-12-15 20:20:10 +00:00
|
|
|
}
|
|
|
|
|
2017-10-21 13:16:41 +00:00
|
|
|
void DrmOutput::updateMode(int modeIndex)
|
|
|
|
{
|
2021-04-20 10:53:02 +00:00
|
|
|
// get all modes on the connector
|
|
|
|
DrmScopedPointer<drmModeConnector> connector(drmModeGetConnector(m_gpu->fd(), m_conn->id()));
|
|
|
|
if (connector->count_modes <= modeIndex) {
|
|
|
|
// TODO: error?
|
2017-10-21 13:16:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
if (isCurrentMode(&connector->modes[modeIndex])) {
|
|
|
|
// nothing to do
|
|
|
|
return;
|
2017-10-21 13:16:41 +00:00
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
m_mode = connector->modes[modeIndex];
|
|
|
|
m_modesetRequested = true;
|
|
|
|
setCurrentModeInternal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrmOutput::setCurrentModeInternal()
|
|
|
|
{
|
|
|
|
AbstractWaylandOutput::setCurrentModeInternal(QSize(m_mode.hdisplay, m_mode.vdisplay),
|
|
|
|
refreshRateForMode(&m_mode));
|
2017-10-21 13:16:41 +00:00
|
|
|
}
|
|
|
|
|
2016-08-31 12:00:31 +00:00
|
|
|
void DrmOutput::pageFlipped()
|
|
|
|
{
|
2021-04-20 10:53:02 +00:00
|
|
|
// In legacy mode we might get a page flip through a blank.
|
|
|
|
Q_ASSERT(m_pageFlipPending || !m_gpu->atomicModeSetting());
|
2017-05-09 19:29:10 +00:00
|
|
|
m_pageFlipPending = false;
|
2021-04-20 10:53:02 +00:00
|
|
|
|
2018-07-18 14:13:38 +00:00
|
|
|
if (m_deleted) {
|
|
|
|
deleteLater();
|
|
|
|
return;
|
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
|
|
|
|
if (!m_crtc) {
|
|
|
|
return;
|
|
|
|
}
|
2021-03-20 18:18:52 +00:00
|
|
|
if (m_gpu->atomicModeSetting()) {
|
2021-05-13 16:41:39 +00:00
|
|
|
for (DrmPlane *p : qAsConst(m_nextPlanesFlipList)) {
|
2021-04-20 10:53:02 +00:00
|
|
|
p->flipBuffer();
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
m_nextPlanesFlipList.clear();
|
2016-08-31 12:00:31 +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
|
|
|
m_crtc->flipBuffer();
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
|
|
|
|
if (m_atomicOffPending) {
|
|
|
|
dpmsAtomicOff();
|
|
|
|
}
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
|
|
|
|
2021-03-22 14:46:09 +00:00
|
|
|
bool DrmOutput::present(const QSharedPointer<DrmBuffer> &buffer)
|
2021-04-20 10:53:02 +00:00
|
|
|
{
|
|
|
|
if (!buffer || buffer->bufferId() == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_dpmsModePending != DpmsMode::On) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-02-20 15:04:18 +00:00
|
|
|
RenderLoopPrivate *renderLoopPrivate = RenderLoopPrivate::get(m_renderLoop);
|
|
|
|
setVrr(renderLoopPrivate->presentMode == RenderLoopPrivate::SyncMode::Adaptive);
|
2021-04-20 10:53:02 +00:00
|
|
|
return m_gpu->atomicModeSetting() ? presentAtomically(buffer) : presentLegacy(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::dpmsAtomicOff()
|
|
|
|
{
|
|
|
|
m_atomicOffPending = false;
|
|
|
|
|
|
|
|
// TODO: With multiple planes: deactivate all of them here
|
2021-04-22 00:30:34 +00:00
|
|
|
hideCursor();
|
2021-04-20 10:53:02 +00:00
|
|
|
m_primaryPlane->setNext(nullptr);
|
|
|
|
m_nextPlanesFlipList << m_primaryPlane;
|
|
|
|
|
|
|
|
if (!doAtomicCommit(AtomicCommitMode::Test)) {
|
|
|
|
qCDebug(KWIN_DRM) << "Atomic test commit to Dpms Off failed. Aborting.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!doAtomicCommit(AtomicCommitMode::Real)) {
|
|
|
|
qCDebug(KWIN_DRM) << "Atomic commit to Dpms Off failed. This should have never happened! Aborting.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
m_nextPlanesFlipList.clear();
|
|
|
|
dpmsFinishOff();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::presentAtomically(const QSharedPointer<DrmBuffer> &buffer)
|
2017-05-09 19:29:10 +00:00
|
|
|
{
|
2021-01-30 13:22:07 +00:00
|
|
|
if (!m_backend->session()->isActive()) {
|
2021-04-20 10:53:02 +00:00
|
|
|
qCWarning(KWIN_DRM) << "Refusing to present output because session is inactive";
|
2017-05-09 19:29:10 +00:00
|
|
|
return false;
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
|
2017-05-09 19:29:10 +00:00
|
|
|
if (m_pageFlipPending) {
|
2021-04-20 10:53:02 +00:00
|
|
|
qCWarning(KWIN_DRM) << "Page not yet flipped.";
|
2017-05-09 19:29:10 +00:00
|
|
|
return false;
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
|
|
|
|
#if HAVE_EGL_STREAMS
|
|
|
|
if (m_gpu->useEglStreams() && !m_modesetRequested) {
|
|
|
|
// EglStreamBackend queues normal page flips through EGL,
|
|
|
|
// modesets are still performed through DRM-KMS
|
2021-02-22 18:17:23 +00:00
|
|
|
m_pageFlipPending = true;
|
2016-08-31 12:00:31 +00:00
|
|
|
return true;
|
2021-04-20 10:53:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
m_primaryPlane->setNext(buffer);
|
|
|
|
m_nextPlanesFlipList << m_primaryPlane;
|
|
|
|
|
|
|
|
if (!doAtomicCommit(AtomicCommitMode::Test)) {
|
|
|
|
//TODO: When we use planes for layered rendering, fallback to renderer instead. Also for direct scanout?
|
|
|
|
//TODO: Probably should undo setNext and reset the flip list
|
|
|
|
qCDebug(KWIN_DRM) << "Atomic test commit failed. Aborting present.";
|
|
|
|
// go back to previous state
|
|
|
|
if (m_lastWorkingState.valid) {
|
|
|
|
m_mode = m_lastWorkingState.mode;
|
|
|
|
setTransformInternal(m_lastWorkingState.transform);
|
|
|
|
setGlobalPos(m_lastWorkingState.globalPos);
|
|
|
|
if (m_primaryPlane) {
|
|
|
|
m_primaryPlane->setTransformation(m_lastWorkingState.planeTransformations);
|
|
|
|
}
|
|
|
|
m_modesetRequested = true;
|
|
|
|
if (!m_backend->isCursorHidden()) {
|
|
|
|
// the cursor might need to get rotated
|
|
|
|
updateCursor();
|
|
|
|
showCursor();
|
|
|
|
}
|
|
|
|
setCurrentModeInternal();
|
|
|
|
emit screens()->changed();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const bool wasModeset = m_modesetRequested;
|
|
|
|
if (!doAtomicCommit(AtomicCommitMode::Real)) {
|
|
|
|
qCDebug(KWIN_DRM) << "Atomic commit failed. This should have never happened! Aborting present.";
|
|
|
|
//TODO: Probably should undo setNext and reset the flip list
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (wasModeset) {
|
|
|
|
// store current mode set as new good state
|
|
|
|
m_lastWorkingState.mode = m_mode;
|
|
|
|
m_lastWorkingState.transform = transform();
|
|
|
|
m_lastWorkingState.globalPos = globalPos();
|
|
|
|
if (m_primaryPlane) {
|
|
|
|
m_lastWorkingState.planeTransformations = m_primaryPlane->transformation();
|
|
|
|
}
|
|
|
|
m_lastWorkingState.valid = true;
|
|
|
|
m_renderLoop->setRefreshRate(refreshRateForMode(&m_mode));
|
|
|
|
}
|
|
|
|
m_pageFlipPending = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::presentLegacy(const QSharedPointer<DrmBuffer> &buffer)
|
|
|
|
{
|
|
|
|
if (m_crtc->next()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!m_backend->session()->isActive()) {
|
|
|
|
m_crtc->setNext(buffer);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we need to set a new mode first?
|
|
|
|
if (!m_crtc->current() || m_crtc->current()->needsModeChange(buffer.get())) {
|
|
|
|
if (!setModeLegacy(buffer.get())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const bool ok = drmModePageFlip(m_gpu->fd(), m_crtc->id(), buffer->bufferId(), DRM_MODE_PAGE_FLIP_EVENT, this) == 0;
|
|
|
|
if (ok) {
|
|
|
|
m_crtc->setNext(buffer);
|
|
|
|
m_pageFlipPending = true;
|
2016-08-31 12:00:31 +00:00
|
|
|
} else {
|
2021-04-20 10:53:02 +00:00
|
|
|
qCWarning(KWIN_DRM) << "Page flip failed:" << strerror(errno);
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::setModeLegacy(DrmBuffer *buffer)
|
|
|
|
{
|
|
|
|
uint32_t connId = m_conn->id();
|
|
|
|
if (drmModeSetCrtc(m_gpu->fd(), m_crtc->id(), buffer->bufferId(), 0, 0, &connId, 1, &m_mode) == 0) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
qCWarning(KWIN_DRM) << "Mode setting failed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::doAtomicCommit(AtomicCommitMode mode)
|
|
|
|
{
|
|
|
|
drmModeAtomicReq *req = drmModeAtomicAlloc();
|
|
|
|
|
|
|
|
auto errorHandler = [this, mode, req] () {
|
|
|
|
if (mode == AtomicCommitMode::Test) {
|
|
|
|
// TODO: when we later test overlay planes, make sure we change only the right stuff back
|
|
|
|
}
|
|
|
|
if (req) {
|
|
|
|
drmModeAtomicFree(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dpmsMode() != m_dpmsModePending) {
|
|
|
|
qCWarning(KWIN_DRM) << "Setting DPMS failed";
|
|
|
|
m_dpmsModePending = dpmsMode();
|
|
|
|
if (dpmsMode() != DpmsMode::On) {
|
|
|
|
dpmsFinishOff();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: see above, rework later for overlay planes!
|
2021-05-13 16:41:39 +00:00
|
|
|
for (DrmPlane *p : qAsConst(m_nextPlanesFlipList)) {
|
2021-04-20 10:53:02 +00:00
|
|
|
p->setNext(nullptr);
|
|
|
|
}
|
|
|
|
m_nextPlanesFlipList.clear();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!req) {
|
|
|
|
qCWarning(KWIN_DRM) << "DRM: couldn't allocate atomic request";
|
|
|
|
errorHandler();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t flags = 0;
|
|
|
|
// Do we need to set a new mode?
|
|
|
|
if (m_modesetRequested) {
|
|
|
|
if (m_dpmsModePending == DpmsMode::On) {
|
|
|
|
if (drmModeCreatePropertyBlob(m_gpu->fd(), &m_mode, sizeof(m_mode), &m_blobId) != 0) {
|
|
|
|
qCWarning(KWIN_DRM) << "Failed to create property blob";
|
|
|
|
errorHandler();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!atomicReqModesetPopulate(req, m_dpmsModePending == DpmsMode::On)){
|
|
|
|
qCWarning(KWIN_DRM) << "Failed to populate Atomic Modeset";
|
|
|
|
errorHandler();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
flags |= DRM_MODE_ATOMIC_ALLOW_MODESET;
|
|
|
|
}
|
|
|
|
|
2021-02-20 15:04:18 +00:00
|
|
|
if (!m_crtc->atomicPopulate(req)) {
|
|
|
|
qCWarning(KWIN_DRM) << "Failed to populate crtc. Abort atomic commit!";
|
|
|
|
errorHandler();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-04-20 10:53:02 +00:00
|
|
|
if (mode == AtomicCommitMode::Real) {
|
|
|
|
if (m_dpmsModePending == DpmsMode::On) {
|
|
|
|
if (!(flags & DRM_MODE_ATOMIC_ALLOW_MODESET)) {
|
|
|
|
// TODO: Evaluating this condition should only be necessary, as long as we expect older kernels than 4.10.
|
|
|
|
flags |= DRM_MODE_ATOMIC_NONBLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if HAVE_EGL_STREAMS
|
|
|
|
if (!m_gpu->useEglStreams())
|
|
|
|
// EglStreamBackend uses the NV_output_drm_flip_event EGL extension
|
|
|
|
// to register the flip event through eglStreamConsumerAcquireAttribNV
|
|
|
|
#endif
|
|
|
|
flags |= DRM_MODE_PAGE_FLIP_EVENT;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
flags |= DRM_MODE_ATOMIC_TEST_ONLY;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ret = true;
|
|
|
|
// TODO: Make sure when we use more than one plane at a time, that we go through this list in the right order.
|
|
|
|
for (int i = m_nextPlanesFlipList.size() - 1; 0 <= i; i-- ) {
|
|
|
|
DrmPlane *p = m_nextPlanesFlipList[i];
|
|
|
|
ret &= p->atomicPopulate(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
qCWarning(KWIN_DRM) << "Failed to populate atomic planes. Abort atomic commit!";
|
|
|
|
errorHandler();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drmModeAtomicCommit(m_gpu->fd(), req, flags, this)) {
|
|
|
|
qCDebug(KWIN_DRM) << "Atomic request failed to commit: " << strerror(errno);
|
|
|
|
errorHandler();
|
2017-05-09 19:29:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-04-20 10:53:02 +00:00
|
|
|
|
|
|
|
if (mode == AtomicCommitMode::Real && (flags & DRM_MODE_ATOMIC_ALLOW_MODESET)) {
|
|
|
|
qCDebug(KWIN_DRM) << "Atomic Modeset successful.";
|
|
|
|
m_modesetRequested = false;
|
|
|
|
setDpmsModeInternal(m_dpmsModePending);
|
|
|
|
}
|
|
|
|
|
|
|
|
drmModeAtomicFree(req);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::atomicReqModesetPopulate(drmModeAtomicReq *req, bool enable)
|
|
|
|
{
|
|
|
|
if (enable) {
|
|
|
|
const QSize mSize = modeSize();
|
|
|
|
const QSize bufferSize = m_primaryPlane->next() ? m_primaryPlane->next()->size() : pixelSize();
|
|
|
|
const QSize sourceSize = hardwareTransforms() ? bufferSize : mSize;
|
|
|
|
QRect targetRect = QRect(QPoint(0, 0), mSize);
|
|
|
|
if (mSize != sourceSize) {
|
|
|
|
targetRect.setSize(sourceSize.scaled(mSize, Qt::AspectRatioMode::KeepAspectRatio));
|
|
|
|
targetRect.setX((mSize.width() - targetRect.width()) / 2);
|
|
|
|
targetRect.setY((mSize.height() - targetRect.height()) / 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::SrcX, 0);
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::SrcY, 0);
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::SrcW, sourceSize.width() << 16);
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::SrcH, sourceSize.height() << 16);
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::CrtcX, targetRect.x());
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::CrtcY, targetRect.y());
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::CrtcW, targetRect.width());
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::CrtcH, targetRect.height());
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::CrtcId, m_crtc->id());
|
|
|
|
} else {
|
|
|
|
m_primaryPlane->setCurrent(nullptr);
|
|
|
|
m_primaryPlane->setNext(nullptr);
|
|
|
|
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::SrcX, 0);
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::SrcY, 0);
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::SrcW, 0);
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::SrcH, 0);
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::CrtcX, 0);
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::CrtcY, 0);
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::CrtcW, 0);
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::CrtcH, 0);
|
|
|
|
m_primaryPlane->setValue(DrmPlane::PropertyIndex::CrtcId, 0);
|
|
|
|
}
|
|
|
|
m_conn->setValue(DrmConnector::PropertyIndex::CrtcId, enable ? m_crtc->id() : 0);
|
|
|
|
m_crtc->setValue(DrmCrtc::PropertyIndex::ModeId, enable ? m_blobId : 0);
|
|
|
|
m_crtc->setValue(DrmCrtc::PropertyIndex::Active, enable);
|
|
|
|
|
2021-02-20 15:04:18 +00:00
|
|
|
return m_conn->atomicPopulate(req);
|
2016-08-31 12:00:31 +00:00
|
|
|
}
|
2016-03-21 14:11:17 +00:00
|
|
|
|
Backport Night Color feature to X11
Summary:
The color correction manager doesn't make any specific assumptions about
underlying platform, e.g. whether it's x11, etc. The platform just
has to be capable of setting gamma ramps. Given that, there are no any
significant technical blockers for making this feature work on x.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, neobrain, GB_2, filipf, davidedmundson, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D21345
2019-06-17 09:07:19 +00:00
|
|
|
int DrmOutput::gammaRampSize() const
|
2018-03-30 13:03:37 +00:00
|
|
|
{
|
Backport Night Color feature to X11
Summary:
The color correction manager doesn't make any specific assumptions about
underlying platform, e.g. whether it's x11, etc. The platform just
has to be capable of setting gamma ramps. Given that, there are no any
significant technical blockers for making this feature work on x.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, neobrain, GB_2, filipf, davidedmundson, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D21345
2019-06-17 09:07:19 +00:00
|
|
|
return m_crtc->gammaRampSize();
|
2018-03-30 13:03:37 +00:00
|
|
|
}
|
|
|
|
|
Backport Night Color feature to X11
Summary:
The color correction manager doesn't make any specific assumptions about
underlying platform, e.g. whether it's x11, etc. The platform just
has to be capable of setting gamma ramps. Given that, there are no any
significant technical blockers for making this feature work on x.
Reviewers: #kwin, davidedmundson, romangg
Reviewed By: #kwin, davidedmundson, romangg
Subscribers: romangg, neobrain, GB_2, filipf, davidedmundson, ngraham, kwin
Tags: #kwin
Differential Revision: https://phabricator.kde.org/D21345
2019-06-17 09:07:19 +00:00
|
|
|
bool DrmOutput::setGammaRamp(const GammaRamp &gamma)
|
2018-03-30 13:03:37 +00:00
|
|
|
{
|
2021-04-20 10:53:02 +00:00
|
|
|
return m_crtc->setGammaRamp(gamma);
|
2018-03-30 13:03:37 +00:00
|
|
|
}
|
|
|
|
|
2021-04-11 14:26:21 +00:00
|
|
|
void DrmOutput::setOverscan(uint32_t overscan)
|
|
|
|
{
|
|
|
|
if (m_conn->hasOverscan() && overscan <= 100) {
|
|
|
|
m_conn->setOverscan(overscan);
|
|
|
|
setOverscanInternal(overscan);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-20 15:04:18 +00:00
|
|
|
void DrmOutput::setVrr(bool enable)
|
|
|
|
{
|
|
|
|
if (!m_conn->vrrCapable() || m_crtc->isVrrEnabled() == enable) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!m_crtc->setVrr(enable) || (m_gpu->atomicModeSetting() && !doAtomicCommit(AtomicCommitMode::Test))) {
|
|
|
|
qCWarning(KWIN_DRM) << "Failed to set vrr on" << this;
|
|
|
|
setVrrPolicy(RenderLoop::VrrPolicy::Never);
|
|
|
|
m_crtc->setVrr(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrmOutput::isCursorVisible()
|
|
|
|
{
|
|
|
|
return m_cursor[m_cursorIndex] && QRect(m_cursorPos, m_cursor[m_cursorIndex]->size()).intersects(QRect(0, 0, m_mode.vdisplay, m_mode.hdisplay));
|
|
|
|
}
|
|
|
|
|
2016-03-21 14:11:17 +00:00
|
|
|
}
|