Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/drm/drm_output.cpp
Show First 20 Lines • Show All 180 Lines • ▼ Show 20 Line(s) | |||||
181 | { | 181 | { | ||
182 | auto orient = orientation(); | 182 | auto orient = orientation(); | ||
183 | if (orient == Qt::PortraitOrientation || orient == Qt::InvertedPortraitOrientation) { | 183 | if (orient == Qt::PortraitOrientation || orient == Qt::InvertedPortraitOrientation) { | ||
184 | return QSize(m_mode.vdisplay, m_mode.hdisplay); | 184 | return QSize(m_mode.vdisplay, m_mode.hdisplay); | ||
185 | } | 185 | } | ||
186 | return QSize(m_mode.hdisplay, m_mode.vdisplay); | 186 | return QSize(m_mode.hdisplay, m_mode.vdisplay); | ||
187 | } | 187 | } | ||
188 | 188 | | |||
189 | void DrmOutput::setEnabled(bool enabled) | 189 | void DrmOutput::setEnabled(bool enabled) | ||
davidedmundson: I think this needs to become a virtual on AbstractOutput, it'll tidy a lot | |||||
davidedmundson: Heh. It is in a future patch. | |||||
190 | { | 190 | { | ||
191 | if (enabled == isEnabled()) { | 191 | if (enabled == isEnabled()) { | ||
192 | return; | 192 | return; | ||
193 | } | 193 | } | ||
194 | if (enabled) { | 194 | if (enabled) { | ||
195 | setDpms(DpmsMode::On); | 195 | updateDpms(KWayland::Server::OutputInterface::DpmsMode::On); | ||
196 | initWaylandOutput(); | 196 | initWaylandOutput(); | ||
197 | initDrmWaylandOutput(); | | |||
198 | } else { | 197 | } else { | ||
199 | setDpms(DpmsMode::Off); | 198 | updateDpms(KWayland::Server::OutputInterface::DpmsMode::Off); | ||
200 | delete waylandOutput().data(); | 199 | delete waylandOutput().data(); | ||
201 | } | 200 | } | ||
202 | waylandOutputDevice()->setEnabled(enabled ? | 201 | waylandOutputDevice()->setEnabled(enabled ? | ||
203 | KWayland::Server::OutputDeviceInterface::Enablement::Enabled : KWayland::Server::OutputDeviceInterface::Enablement::Disabled); | 202 | KWayland::Server::OutputDeviceInterface::Enablement::Enabled : KWayland::Server::OutputDeviceInterface::Enablement::Disabled); | ||
204 | } | 203 | } | ||
205 | 204 | | |||
206 | static KWayland::Server::OutputInterface::DpmsMode toWaylandDpmsMode(DrmOutput::DpmsMode mode) | 205 | static KWayland::Server::OutputInterface::DpmsMode toWaylandDpmsMode(DrmOutput::DpmsMode mode) | ||
207 | { | 206 | { | ||
▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Line(s) | 283 | if (m_backend->atomicModeSetting()) { | |||
285 | if (!initPrimaryPlane()) { | 284 | if (!initPrimaryPlane()) { | ||
286 | return false; | 285 | return false; | ||
287 | } | 286 | } | ||
288 | } else if (!m_crtc->blank()) { | 287 | } else if (!m_crtc->blank()) { | ||
289 | return false; | 288 | return false; | ||
290 | } | 289 | } | ||
291 | 290 | | |||
292 | setInternal(connector->connector_type == DRM_MODE_CONNECTOR_LVDS || connector->connector_type == DRM_MODE_CONNECTOR_eDP); | 291 | setInternal(connector->connector_type == DRM_MODE_CONNECTOR_LVDS || connector->connector_type == DRM_MODE_CONNECTOR_eDP); | ||
292 | setDpmsSupported(true); | ||||
293 | 293 | | |||
294 | if (internal()) { | 294 | if (internal()) { | ||
295 | connect(kwinApp(), &Application::screensCreated, this, | 295 | connect(kwinApp(), &Application::screensCreated, this, | ||
296 | [this] { | 296 | [this] { | ||
297 | connect(screens()->orientationSensor(), &OrientationSensor::orientationChanged, this, &DrmOutput::automaticRotation); | 297 | connect(screens()->orientationSensor(), &OrientationSensor::orientationChanged, this, &DrmOutput::automaticRotation); | ||
298 | } | 298 | } | ||
299 | ); | 299 | ); | ||
300 | } | 300 | } | ||
Show All 23 Lines | 323 | { | |||
324 | QCryptographicHash hash(QCryptographicHash::Md5); | 324 | QCryptographicHash hash(QCryptographicHash::Md5); | ||
325 | hash.addData(QByteArray::number(m_conn->id())); | 325 | hash.addData(QByteArray::number(m_conn->id())); | ||
326 | hash.addData(m_edid.eisaId); | 326 | hash.addData(m_edid.eisaId); | ||
327 | hash.addData(m_edid.monitorName); | 327 | hash.addData(m_edid.monitorName); | ||
328 | hash.addData(m_edid.serialNumber); | 328 | hash.addData(m_edid.serialNumber); | ||
329 | m_uuid = hash.result().toHex().left(10); | 329 | m_uuid = hash.result().toHex().left(10); | ||
330 | } | 330 | } | ||
331 | 331 | | |||
332 | void DrmOutput::initDrmWaylandOutput() | | |||
333 | { | | |||
334 | auto wlOutput = waylandOutput(); | | |||
335 | // set dpms | | |||
336 | if (!m_dpms.isNull()) { | | |||
337 | wlOutput->setDpmsSupported(true); | | |||
338 | wlOutput->setDpmsMode(toWaylandDpmsMode(m_dpmsMode)); | | |||
339 | connect(wlOutput.data(), &KWayland::Server::OutputInterface::dpmsModeRequested, this, | | |||
340 | [this] (KWayland::Server::OutputInterface::DpmsMode mode) { | | |||
341 | setDpms(fromWaylandDpmsMode(mode)); | | |||
342 | }, Qt::QueuedConnection | | |||
343 | ); | | |||
344 | } | | |||
345 | } | | |||
346 | | ||||
347 | void DrmOutput::initOutputDevice(drmModeConnector *connector) | 332 | void DrmOutput::initOutputDevice(drmModeConnector *connector) | ||
348 | { | 333 | { | ||
349 | auto wlOutputDevice = waylandOutputDevice(); | 334 | auto wlOutputDevice = waylandOutputDevice(); | ||
350 | if (!wlOutputDevice.isNull()) { | 335 | if (!wlOutputDevice.isNull()) { | ||
351 | delete wlOutputDevice.data(); | 336 | delete wlOutputDevice.data(); | ||
352 | wlOutputDevice.clear(); | 337 | wlOutputDevice.clear(); | ||
353 | } | 338 | } | ||
354 | wlOutputDevice = waylandServer()->display()->createOutputDevice(); | 339 | wlOutputDevice = waylandServer()->display()->createOutputDevice(); | ||
▲ Show 20 Lines • Show All 294 Lines • ▼ Show 20 Line(s) | 630 | for (int i = 0; i < connector->count_props; ++i) { | |||
649 | } | 634 | } | ||
650 | if (qstrcmp(property->name, "DPMS") == 0) { | 635 | if (qstrcmp(property->name, "DPMS") == 0) { | ||
651 | m_dpms.swap(property); | 636 | m_dpms.swap(property); | ||
652 | break; | 637 | break; | ||
653 | } | 638 | } | ||
654 | } | 639 | } | ||
655 | } | 640 | } | ||
656 | 641 | | |||
657 | void DrmOutput::setDpms(DrmOutput::DpmsMode mode) | 642 | void DrmOutput::updateDpms(KWayland::Server::OutputInterface::DpmsMode mode) | ||
658 | { | 643 | { | ||
659 | if (m_dpms.isNull()) { | 644 | if (m_dpms.isNull()) { | ||
660 | return; | 645 | return; | ||
661 | } | 646 | } | ||
662 | if (mode == m_dpmsModePending) { | 647 | | ||
648 | const auto drmMode = fromWaylandDpmsMode(mode); | ||||
649 | if (drmMode == m_dpmsModePending) { | ||||
663 | qCDebug(KWIN_DRM) << "New DPMS mode equals old mode. DPMS unchanged."; | 650 | qCDebug(KWIN_DRM) << "New DPMS mode equals old mode. DPMS unchanged."; | ||
664 | return; | 651 | return; | ||
665 | } | 652 | } | ||
666 | 653 | | |||
667 | m_dpmsModePending = mode; | 654 | m_dpmsModePending = drmMode; | ||
668 | 655 | | |||
669 | if (m_backend->atomicModeSetting()) { | 656 | if (m_backend->atomicModeSetting()) { | ||
670 | m_modesetRequested = true; | 657 | m_modesetRequested = true; | ||
671 | if (mode == DpmsMode::On) { | 658 | if (drmMode == DpmsMode::On) { | ||
672 | if (m_pageFlipPending) { | 659 | if (m_pageFlipPending) { | ||
673 | m_pageFlipPending = false; | 660 | m_pageFlipPending = false; | ||
674 | Compositor::self()->bufferSwapComplete(); | 661 | Compositor::self()->bufferSwapComplete(); | ||
675 | } | 662 | } | ||
676 | dpmsOnHandler(); | 663 | dpmsOnHandler(); | ||
677 | } else { | 664 | } else { | ||
678 | m_dpmsAtomicOffPending = true; | 665 | m_dpmsAtomicOffPending = true; | ||
679 | if (!m_pageFlipPending) { | 666 | if (!m_pageFlipPending) { | ||
680 | dpmsAtomicOff(); | 667 | dpmsAtomicOff(); | ||
681 | } | 668 | } | ||
682 | } | 669 | } | ||
683 | } else { | 670 | } else { | ||
684 | if (drmModeConnectorSetProperty(m_backend->fd(), m_conn->id(), m_dpms->prop_id, uint64_t(mode)) < 0) { | 671 | if (drmModeConnectorSetProperty(m_backend->fd(), m_conn->id(), m_dpms->prop_id, uint64_t(drmMode)) < 0) { | ||
685 | m_dpmsModePending = m_dpmsMode; | 672 | m_dpmsModePending = m_dpmsMode; | ||
686 | qCWarning(KWIN_DRM) << "Setting DPMS failed"; | 673 | qCWarning(KWIN_DRM) << "Setting DPMS failed"; | ||
687 | return; | 674 | return; | ||
688 | } | 675 | } | ||
689 | if (mode == DpmsMode::On) { | 676 | if (drmMode == DpmsMode::On) { | ||
690 | dpmsOnHandler(); | 677 | dpmsOnHandler(); | ||
691 | } else { | 678 | } else { | ||
692 | dpmsOffHandler(); | 679 | dpmsOffHandler(); | ||
693 | } | 680 | } | ||
694 | m_dpmsMode = m_dpmsModePending; | 681 | m_dpmsMode = m_dpmsModePending; | ||
695 | } | 682 | } | ||
696 | } | 683 | } | ||
697 | 684 | | |||
▲ Show 20 Lines • Show All 531 Lines • Show Last 20 Lines |
I think this needs to become a virtual on AbstractOutput, it'll tidy a lot