From 0af57d6366e6ccceac4c991283d4ddd2a0fa24ba Mon Sep 17 00:00:00 2001 From: Roman Gilg Date: Fri, 9 Nov 2018 22:58:23 +0100 Subject: [PATCH] [drm] Code cleanup in DrmOutput class Summary: Removes unneeded includes and reorders the code in a sensible way. Reviewers: #kwin Subscribers: davidedmundson, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D16792 --- plugins/platforms/drm/drm_output.cpp | 139 +++++++++++++-------------- 1 file changed, 67 insertions(+), 72 deletions(-) diff --git a/plugins/platforms/drm/drm_output.cpp b/plugins/platforms/drm/drm_output.cpp index 798ea98ed6..d7f948eb3c 100644 --- a/plugins/platforms/drm/drm_output.cpp +++ b/plugins/platforms/drm/drm_output.cpp @@ -33,12 +33,7 @@ along with this program. If not, see . #include "screens_drm.h" #include "wayland_server.h" // KWayland -#include #include -#include -#include -#include -#include // KF5 #include #include @@ -177,49 +172,6 @@ void DrmOutput::moveCursor(const QPoint &globalPos) drmModeMoveCursor(m_backend->fd(), m_crtc->id(), p.x(), p.y()); } -QSize DrmOutput::pixelSize() const -{ - auto orient = orientation(); - if (orient == Qt::PortraitOrientation || orient == Qt::InvertedPortraitOrientation) { - return QSize(m_mode.vdisplay, m_mode.hdisplay); - } - return QSize(m_mode.hdisplay, m_mode.vdisplay); -} - -static KWayland::Server::OutputInterface::DpmsMode toWaylandDpmsMode(DrmOutput::DpmsMode mode) -{ - using namespace KWayland::Server; - switch (mode) { - case DrmOutput::DpmsMode::On: - return OutputInterface::DpmsMode::On; - case DrmOutput::DpmsMode::Standby: - return OutputInterface::DpmsMode::Standby; - case DrmOutput::DpmsMode::Suspend: - return OutputInterface::DpmsMode::Suspend; - case DrmOutput::DpmsMode::Off: - return OutputInterface::DpmsMode::Off; - default: - Q_UNREACHABLE(); - } -} - -static DrmOutput::DpmsMode fromWaylandDpmsMode(KWayland::Server::OutputInterface::DpmsMode wlMode) -{ - using namespace KWayland::Server; - switch (wlMode) { - case OutputInterface::DpmsMode::On: - return DrmOutput::DpmsMode::On; - case OutputInterface::DpmsMode::Standby: - return DrmOutput::DpmsMode::Standby; - case OutputInterface::DpmsMode::Suspend: - return DrmOutput::DpmsMode::Suspend; - case OutputInterface::DpmsMode::Off: - return DrmOutput::DpmsMode::Off; - default: - Q_UNREACHABLE(); - } -} - static QHash s_connectorNames = { {DRM_MODE_CONNECTOR_Unknown, QByteArrayLiteral("Unknown")}, {DRM_MODE_CONNECTOR_VGA, QByteArrayLiteral("VGA")}, @@ -596,6 +548,21 @@ bool DrmOutput::initCursorPlane() // TODO: Add call in init (but needs lay return false; } +bool DrmOutput::initCursor(const QSize &cursorSize) +{ + auto createCursor = [this, cursorSize] (int index) { + m_cursor[index] = m_backend->createBuffer(cursorSize); + if (!m_cursor[index]->map(QImage::Format_ARGB32_Premultiplied)) { + return false; + } + return true; + }; + if (!createCursor(0) || !createCursor(1)) { + return false; + } + return true; +} + void DrmOutput::initDpms(drmModeConnector *connector) { for (int i = 0; i < connector->count_props; ++i) { @@ -610,6 +577,40 @@ void DrmOutput::initDpms(drmModeConnector *connector) } } +static DrmOutput::DpmsMode fromWaylandDpmsMode(KWayland::Server::OutputInterface::DpmsMode wlMode) +{ + using namespace KWayland::Server; + switch (wlMode) { + case OutputInterface::DpmsMode::On: + return DrmOutput::DpmsMode::On; + case OutputInterface::DpmsMode::Standby: + return DrmOutput::DpmsMode::Standby; + case OutputInterface::DpmsMode::Suspend: + return DrmOutput::DpmsMode::Suspend; + case OutputInterface::DpmsMode::Off: + return DrmOutput::DpmsMode::Off; + default: + Q_UNREACHABLE(); + } +} + +static KWayland::Server::OutputInterface::DpmsMode toWaylandDpmsMode(DrmOutput::DpmsMode mode) +{ + using namespace KWayland::Server; + switch (mode) { + case DrmOutput::DpmsMode::On: + return OutputInterface::DpmsMode::On; + case DrmOutput::DpmsMode::Standby: + return OutputInterface::DpmsMode::Standby; + case DrmOutput::DpmsMode::Suspend: + return OutputInterface::DpmsMode::Suspend; + case DrmOutput::DpmsMode::Off: + return OutputInterface::DpmsMode::Off; + default: + Q_UNREACHABLE(); + } +} + void DrmOutput::updateDpms(KWayland::Server::OutputInterface::DpmsMode mode) { if (m_dpms.isNull()) { @@ -685,15 +686,6 @@ void DrmOutput::dpmsOffHandler() m_backend->outputWentOff(); } -int DrmOutput::currentRefreshRate() const -{ - auto wlOutput = waylandOutput(); - if (!wlOutput) { - return 60000; - } - return wlOutput->refreshRate(); -} - void DrmOutput::transform(KWayland::Server::OutputDeviceInterface::Transform transform) { waylandOutputDevice()->setTransform(transform); @@ -789,6 +781,24 @@ void DrmOutput::updateMode(int modeIndex) setWaylandMode(); } +int DrmOutput::currentRefreshRate() const +{ + auto wlOutput = waylandOutput(); + if (!wlOutput) { + return 60000; + } + return wlOutput->refreshRate(); +} + +QSize DrmOutput::pixelSize() const +{ + auto orient = orientation(); + if (orient == Qt::PortraitOrientation || orient == Qt::InvertedPortraitOrientation) { + return QSize(m_mode.vdisplay, m_mode.hdisplay); + } + return QSize(m_mode.hdisplay, m_mode.vdisplay); +} + void DrmOutput::setWaylandMode() { AbstractOutput::setWaylandMode(QSize(m_mode.hdisplay, m_mode.vdisplay), @@ -1106,21 +1116,6 @@ bool DrmOutput::atomicReqModesetPopulate(drmModeAtomicReq *req, bool enable) return ret; } -bool DrmOutput::initCursor(const QSize &cursorSize) -{ - auto createCursor = [this, cursorSize] (int index) { - m_cursor[index] = m_backend->createBuffer(cursorSize); - if (!m_cursor[index]->map(QImage::Format_ARGB32_Premultiplied)) { - return false; - } - return true; - }; - if (!createCursor(0) || !createCursor(1)) { - return false; - } - return true; -} - bool DrmOutput::supportsTransformations() const { if (!m_primaryPlane) {