From 02d3daf28a474d7d7a30af9afcd73e41fcd960f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Fl=C3=B6ser?= Date: Tue, 17 Oct 2017 18:46:20 +0200 Subject: [PATCH] Add physicalSize to the Screens API Summary: Allows to share the implementation in a better way and is a requirement to get the Screen implementation in the QPA plugin to be based on KWin::Screens instead of KWayland::Output. Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D8344 --- plugins/platforms/drm/drm_output.cpp | 1 + plugins/platforms/drm/drm_output.h | 5 +++++ plugins/platforms/drm/screens_drm.cpp | 9 +++++++++ plugins/platforms/drm/screens_drm.h | 2 ++ plugins/platforms/hwcomposer/hwcomposer_backend.cpp | 5 +++-- plugins/platforms/hwcomposer/hwcomposer_backend.h | 4 ++++ plugins/platforms/hwcomposer/screens_hwcomposer.cpp | 9 +++++++++ plugins/platforms/hwcomposer/screens_hwcomposer.h | 1 + screens.cpp | 5 +++++ screens.h | 7 +++++++ wayland_server.cpp | 2 +- 11 files changed, 47 insertions(+), 3 deletions(-) diff --git a/plugins/platforms/drm/drm_output.cpp b/plugins/platforms/drm/drm_output.cpp index efefecbcaa..cf6ef8a011 100644 --- a/plugins/platforms/drm/drm_output.cpp +++ b/plugins/platforms/drm/drm_output.cpp @@ -243,6 +243,7 @@ bool DrmOutput::init(drmModeConnector *connector) qCWarning(KWIN_DRM) << "Overwriting monitor physical size for" << m_edid.eisaId << "/" << m_edid.monitorName << "/" << m_edid.serialNumber << " from " << physicalSize << "to " << overwriteSize; physicalSize = overwriteSize; } + m_physicalSize = physicalSize; m_waylandOutput->setPhysicalSize(physicalSize); m_waylandOutputDevice->setPhysicalSize(physicalSize); diff --git a/plugins/platforms/drm/drm_output.h b/plugins/platforms/drm/drm_output.h index 6f358de1bd..30493c4685 100644 --- a/plugins/platforms/drm/drm_output.h +++ b/plugins/platforms/drm/drm_output.h @@ -103,6 +103,10 @@ public: return m_uuid; } + QSize physicalSize() const { + return m_physicalSize; + } + Q_SIGNALS: void dpmsChanged(); @@ -159,6 +163,7 @@ private: bool m_pageFlipPending = false; bool m_dpmsAtomicOffPending = false; bool m_modesetRequested = true; + QSize m_physicalSize; }; } diff --git a/plugins/platforms/drm/screens_drm.cpp b/plugins/platforms/drm/screens_drm.cpp index 17c6155066..e87d844238 100644 --- a/plugins/platforms/drm/screens_drm.cpp +++ b/plugins/platforms/drm/screens_drm.cpp @@ -113,4 +113,13 @@ float DrmScreens::refreshRate(int screen) const return outputs.at(screen)->currentRefreshRate() / 1000.0f; } +QSizeF DrmScreens::physicalSize(int screen) const +{ + const auto outputs = m_backend->outputs(); + if (screen >= outputs.size()) { + return Screens::physicalSize(screen); + } + return outputs.at(screen)->physicalSize(); +} + } diff --git a/plugins/platforms/drm/screens_drm.h b/plugins/platforms/drm/screens_drm.h index 9418e7426e..e7f8d961e1 100644 --- a/plugins/platforms/drm/screens_drm.h +++ b/plugins/platforms/drm/screens_drm.h @@ -40,6 +40,8 @@ public: QString name(int screen) const override; float refreshRate(int screen) const override; + QSizeF physicalSize(int screen) const override; + private: DrmBackend *m_backend; }; diff --git a/plugins/platforms/hwcomposer/hwcomposer_backend.cpp b/plugins/platforms/hwcomposer/hwcomposer_backend.cpp index 66b8d11e16..e72e9458de 100644 --- a/plugins/platforms/hwcomposer/hwcomposer_backend.cpp +++ b/plugins/platforms/hwcomposer/hwcomposer_backend.cpp @@ -194,8 +194,9 @@ static KWayland::Server::OutputInterface *createOutput(hwc_composer_device_1_t * if (attr_values[2] != 0 && attr_values[3] != 0) { static const qreal factor = 25.4; - o->setPhysicalSize(QSizeF(qreal(pixel.width() * 1000) / qreal(attr_values[2]) * factor, - qreal(pixel.height() * 1000) / qreal(attr_values[3]) * factor).toSize()); + m_physicalSize = QSizeF(qreal(pixel.width() * 1000) / qreal(attr_values[2]) * factor, + qreal(pixel.height() * 1000) / qreal(attr_values[3]) * factor); + o->setPhysicalSize(m_physicalSize.toSize()); } else { // couldn't read physical size, assume 96 dpi o->setPhysicalSize(pixel / 3.8); diff --git a/plugins/platforms/hwcomposer/hwcomposer_backend.h b/plugins/platforms/hwcomposer/hwcomposer_backend.h index e4b2aa6723..f7012e843e 100644 --- a/plugins/platforms/hwcomposer/hwcomposer_backend.h +++ b/plugins/platforms/hwcomposer/hwcomposer_backend.h @@ -85,6 +85,9 @@ public: QVector supportedCompositors() const override { return QVector{OpenGLCompositing}; } + QSizeF physicalSize() const { + return m_physicalSize; + } Q_SIGNALS: void outputBlankChanged(); @@ -110,6 +113,7 @@ private: QMutex m_vsyncMutex; QWaitCondition m_vsyncWaitCondition; QScopedPointer m_filter; + QSizeF m_physicalSize; }; class HwcomposerWindow : public HWComposerNativeWindow diff --git a/plugins/platforms/hwcomposer/screens_hwcomposer.cpp b/plugins/platforms/hwcomposer/screens_hwcomposer.cpp index b1e2c5ac01..be14e7d31c 100644 --- a/plugins/platforms/hwcomposer/screens_hwcomposer.cpp +++ b/plugins/platforms/hwcomposer/screens_hwcomposer.cpp @@ -37,4 +37,13 @@ float HwcomposerScreens::refreshRate(int screen) const return m_backend->refreshRate() / 1000.0f; } +QSizeF HwcomposerScreens::physicalSize(int screen) const +{ + const QSizeF size = m_backend->physicalSize(); + if (size.isValid()) { + return size; + } + return Screens::physicalSize(screen); +} + } diff --git a/plugins/platforms/hwcomposer/screens_hwcomposer.h b/plugins/platforms/hwcomposer/screens_hwcomposer.h index 4c7c213dcb..b4de1cbe3b 100644 --- a/plugins/platforms/hwcomposer/screens_hwcomposer.h +++ b/plugins/platforms/hwcomposer/screens_hwcomposer.h @@ -32,6 +32,7 @@ public: HwcomposerScreens(HwcomposerBackend *backend, QObject *parent = nullptr); virtual ~HwcomposerScreens(); float refreshRate(int screen) const override; + QSizeF physicalSize(int screen) const override; private: HwcomposerBackend *m_backend; diff --git a/screens.cpp b/screens.cpp index 078bc9c57a..5bf3b9939c 100644 --- a/screens.cpp +++ b/screens.cpp @@ -190,6 +190,11 @@ QSize Screens::displaySize() const return size(); } +QSizeF Screens::physicalSize(int screen) const +{ + return QSizeF(size(screen)) / 3.8; +} + BasicScreens::BasicScreens(Platform *backend, QObject *parent) : Screens(parent) , m_backend(backend) diff --git a/screens.h b/screens.h index 3dda15f2b0..1fbc2e6f3c 100644 --- a/screens.h +++ b/screens.h @@ -117,6 +117,13 @@ public: **/ virtual QSize displaySize() const; + + /** + * The physical size of @p screen in mm. + * Default implementation returns a size derived from 96 DPI. + **/ + virtual QSizeF physicalSize(int screen) const; + public Q_SLOTS: void reconfigure(); diff --git a/wayland_server.cpp b/wayland_server.cpp index 03e1d6ae22..5a5851a520 100644 --- a/wayland_server.cpp +++ b/wayland_server.cpp @@ -414,7 +414,7 @@ void WaylandServer::syncOutputsToWayland() output->setScale(s->scale(i)); const QRect &geo = s->geometry(i); output->setGlobalPosition(geo.topLeft()); - output->setPhysicalSize(geo.size() / 3.8); + output->setPhysicalSize(s->physicalSize(i).toSize()); output->addMode(geo.size()); output->create(); }