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
This commit is contained in:
Martin Flöser 2017-10-17 18:46:20 +02:00
parent c2d4cb8846
commit 02d3daf28a
11 changed files with 47 additions and 3 deletions

View file

@ -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; qCWarning(KWIN_DRM) << "Overwriting monitor physical size for" << m_edid.eisaId << "/" << m_edid.monitorName << "/" << m_edid.serialNumber << " from " << physicalSize << "to " << overwriteSize;
physicalSize = overwriteSize; physicalSize = overwriteSize;
} }
m_physicalSize = physicalSize;
m_waylandOutput->setPhysicalSize(physicalSize); m_waylandOutput->setPhysicalSize(physicalSize);
m_waylandOutputDevice->setPhysicalSize(physicalSize); m_waylandOutputDevice->setPhysicalSize(physicalSize);

View file

@ -103,6 +103,10 @@ public:
return m_uuid; return m_uuid;
} }
QSize physicalSize() const {
return m_physicalSize;
}
Q_SIGNALS: Q_SIGNALS:
void dpmsChanged(); void dpmsChanged();
@ -159,6 +163,7 @@ private:
bool m_pageFlipPending = false; bool m_pageFlipPending = false;
bool m_dpmsAtomicOffPending = false; bool m_dpmsAtomicOffPending = false;
bool m_modesetRequested = true; bool m_modesetRequested = true;
QSize m_physicalSize;
}; };
} }

View file

@ -113,4 +113,13 @@ float DrmScreens::refreshRate(int screen) const
return outputs.at(screen)->currentRefreshRate() / 1000.0f; 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();
}
} }

View file

@ -40,6 +40,8 @@ public:
QString name(int screen) const override; QString name(int screen) const override;
float refreshRate(int screen) const override; float refreshRate(int screen) const override;
QSizeF physicalSize(int screen) const override;
private: private:
DrmBackend *m_backend; DrmBackend *m_backend;
}; };

View file

@ -194,8 +194,9 @@ static KWayland::Server::OutputInterface *createOutput(hwc_composer_device_1_t *
if (attr_values[2] != 0 && attr_values[3] != 0) { if (attr_values[2] != 0 && attr_values[3] != 0) {
static const qreal factor = 25.4; static const qreal factor = 25.4;
o->setPhysicalSize(QSizeF(qreal(pixel.width() * 1000) / qreal(attr_values[2]) * factor, m_physicalSize = QSizeF(qreal(pixel.width() * 1000) / qreal(attr_values[2]) * factor,
qreal(pixel.height() * 1000) / qreal(attr_values[3]) * factor).toSize()); qreal(pixel.height() * 1000) / qreal(attr_values[3]) * factor);
o->setPhysicalSize(m_physicalSize.toSize());
} else { } else {
// couldn't read physical size, assume 96 dpi // couldn't read physical size, assume 96 dpi
o->setPhysicalSize(pixel / 3.8); o->setPhysicalSize(pixel / 3.8);

View file

@ -85,6 +85,9 @@ public:
QVector<CompositingType> supportedCompositors() const override { QVector<CompositingType> supportedCompositors() const override {
return QVector<CompositingType>{OpenGLCompositing}; return QVector<CompositingType>{OpenGLCompositing};
} }
QSizeF physicalSize() const {
return m_physicalSize;
}
Q_SIGNALS: Q_SIGNALS:
void outputBlankChanged(); void outputBlankChanged();
@ -110,6 +113,7 @@ private:
QMutex m_vsyncMutex; QMutex m_vsyncMutex;
QWaitCondition m_vsyncWaitCondition; QWaitCondition m_vsyncWaitCondition;
QScopedPointer<BacklightInputEventFilter> m_filter; QScopedPointer<BacklightInputEventFilter> m_filter;
QSizeF m_physicalSize;
}; };
class HwcomposerWindow : public HWComposerNativeWindow class HwcomposerWindow : public HWComposerNativeWindow

View file

@ -37,4 +37,13 @@ float HwcomposerScreens::refreshRate(int screen) const
return m_backend->refreshRate() / 1000.0f; 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);
}
} }

View file

@ -32,6 +32,7 @@ public:
HwcomposerScreens(HwcomposerBackend *backend, QObject *parent = nullptr); HwcomposerScreens(HwcomposerBackend *backend, QObject *parent = nullptr);
virtual ~HwcomposerScreens(); virtual ~HwcomposerScreens();
float refreshRate(int screen) const override; float refreshRate(int screen) const override;
QSizeF physicalSize(int screen) const override;
private: private:
HwcomposerBackend *m_backend; HwcomposerBackend *m_backend;

View file

@ -190,6 +190,11 @@ QSize Screens::displaySize() const
return size(); return size();
} }
QSizeF Screens::physicalSize(int screen) const
{
return QSizeF(size(screen)) / 3.8;
}
BasicScreens::BasicScreens(Platform *backend, QObject *parent) BasicScreens::BasicScreens(Platform *backend, QObject *parent)
: Screens(parent) : Screens(parent)
, m_backend(backend) , m_backend(backend)

View file

@ -117,6 +117,13 @@ public:
**/ **/
virtual QSize displaySize() const; 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: public Q_SLOTS:
void reconfigure(); void reconfigure();

View file

@ -414,7 +414,7 @@ void WaylandServer::syncOutputsToWayland()
output->setScale(s->scale(i)); output->setScale(s->scale(i));
const QRect &geo = s->geometry(i); const QRect &geo = s->geometry(i);
output->setGlobalPosition(geo.topLeft()); output->setGlobalPosition(geo.topLeft());
output->setPhysicalSize(geo.size() / 3.8); output->setPhysicalSize(s->physicalSize(i).toSize());
output->addMode(geo.size()); output->addMode(geo.size());
output->create(); output->create();
} }