Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/drm/drm_output.cpp
Show All 17 Lines | |||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #include "drm_output.h" | 20 | #include "drm_output.h" | ||
21 | #include "drm_backend.h" | 21 | #include "drm_backend.h" | ||
22 | #include "drm_object_plane.h" | 22 | #include "drm_object_plane.h" | ||
23 | #include "drm_object_crtc.h" | 23 | #include "drm_object_crtc.h" | ||
24 | #include "drm_object_connector.h" | 24 | #include "drm_object_connector.h" | ||
25 | 25 | | |||
26 | #include <errno.h> | ||||
27 | #include <cmath> | ||||
28 | | ||||
26 | #include "composite.h" | 29 | #include "composite.h" | ||
27 | #include "logind.h" | 30 | #include "logind.h" | ||
28 | #include "logging.h" | 31 | #include "logging.h" | ||
29 | #include "main.h" | 32 | #include "main.h" | ||
30 | #include "orientation_sensor.h" | 33 | #include "orientation_sensor.h" | ||
31 | #include "screens_drm.h" | 34 | #include "screens_drm.h" | ||
32 | #include "wayland_server.h" | 35 | #include "wayland_server.h" | ||
33 | // KWayland | 36 | // KWayland | ||
▲ Show 20 Lines • Show All 283 Lines • ▼ Show 20 Line(s) | 319 | } else if (!m_edid.serialNumber().isEmpty()) { | |||
317 | modelName = QString::fromLatin1(m_edid.serialNumber()); | 320 | modelName = QString::fromLatin1(m_edid.serialNumber()); | ||
318 | } else { | 321 | } else { | ||
319 | modelName = i18n("unknown"); | 322 | modelName = i18n("unknown"); | ||
320 | } | 323 | } | ||
321 | 324 | | |||
322 | const QString model = connectorName + QStringLiteral("-") + QString::number(connector->connector_type_id) + QStringLiteral("-") + modelName; | 325 | const QString model = connectorName + QStringLiteral("-") + QString::number(connector->connector_type_id) + QStringLiteral("-") + modelName; | ||
323 | 326 | | |||
324 | // read in mode information | 327 | // read in mode information | ||
328 | m_preferredOrientation = Qt::LandscapeOrientation; | ||||
325 | QVector<KWayland::Server::OutputDeviceInterface::Mode> modes; | 329 | QVector<KWayland::Server::OutputDeviceInterface::Mode> modes; | ||
326 | for (int i = 0; i < connector->count_modes; ++i) { | 330 | for (int i = 0; i < connector->count_modes; ++i) { | ||
327 | // TODO: in AMS here we could read and store for later every mode's blob_id | 331 | // TODO: in AMS here we could read and store for later every mode's blob_id | ||
328 | // would simplify isCurrentMode(..) and presentAtomically(..) in case of mode set | 332 | // would simplify isCurrentMode(..) and presentAtomically(..) in case of mode set | ||
329 | auto *m = &connector->modes[i]; | 333 | auto *m = &connector->modes[i]; | ||
330 | KWayland::Server::OutputDeviceInterface::ModeFlags deviceflags; | 334 | KWayland::Server::OutputDeviceInterface::ModeFlags deviceflags; | ||
331 | if (isCurrentMode(m)) { | 335 | if (isCurrentMode(m)) { | ||
332 | deviceflags |= KWayland::Server::OutputDeviceInterface::ModeFlag::Current; | 336 | deviceflags |= KWayland::Server::OutputDeviceInterface::ModeFlag::Current; | ||
333 | } | 337 | } | ||
334 | if (m->type & DRM_MODE_TYPE_PREFERRED) { | 338 | if (m->type & DRM_MODE_TYPE_PREFERRED) { | ||
339 | m_preferredOrientation = m->hdisplay > m->vdisplay ? Qt::LandscapeOrientation : Qt::PortraitOrientation; | ||||
335 | deviceflags |= KWayland::Server::OutputDeviceInterface::ModeFlag::Preferred; | 340 | deviceflags |= KWayland::Server::OutputDeviceInterface::ModeFlag::Preferred; | ||
336 | } | 341 | } | ||
337 | 342 | | |||
338 | KWayland::Server::OutputDeviceInterface::Mode mode; | 343 | KWayland::Server::OutputDeviceInterface::Mode mode; | ||
339 | mode.id = i; | 344 | mode.id = i; | ||
340 | mode.size = QSize(m->hdisplay, m->vdisplay); | 345 | mode.size = QSize(m->hdisplay, m->vdisplay); | ||
341 | mode.flags = deviceflags; | 346 | mode.flags = deviceflags; | ||
342 | mode.refreshRate = refreshRateForMode(m); | 347 | mode.refreshRate = refreshRateForMode(m); | ||
▲ Show 20 Lines • Show All 238 Lines • ▼ Show 20 Line(s) | |||||
581 | } | 586 | } | ||
582 | 587 | | |||
583 | void DrmOutput::transform(KWayland::Server::OutputDeviceInterface::Transform transform) | 588 | void DrmOutput::transform(KWayland::Server::OutputDeviceInterface::Transform transform) | ||
584 | { | 589 | { | ||
585 | waylandOutputDevice()->setTransform(transform); | 590 | waylandOutputDevice()->setTransform(transform); | ||
586 | using KWayland::Server::OutputDeviceInterface; | 591 | using KWayland::Server::OutputDeviceInterface; | ||
587 | using KWayland::Server::OutputInterface; | 592 | using KWayland::Server::OutputInterface; | ||
588 | auto wlOutput = waylandOutput(); | 593 | auto wlOutput = waylandOutput(); | ||
594 | m_softwareRotationAngle = 0; | ||||
589 | 595 | | |||
590 | switch (transform) { | 596 | switch (transform) { | ||
591 | case OutputDeviceInterface::Transform::Normal: | 597 | case OutputDeviceInterface::Transform::Normal: | ||
592 | if (m_primaryPlane) { | 598 | if (m_primaryPlane) { | ||
593 | m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate0); | 599 | m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate0); | ||
594 | } | 600 | } | ||
595 | if (wlOutput) { | 601 | if (wlOutput) { | ||
596 | wlOutput->setTransform(OutputInterface::Transform::Normal); | 602 | wlOutput->setTransform(OutputInterface::Transform::Normal); | ||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Line(s) | 756 | { | |||
765 | } | 771 | } | ||
766 | m_nextPlanesFlipList.clear(); | 772 | m_nextPlanesFlipList.clear(); | ||
767 | dpmsOffHandler(); | 773 | dpmsOffHandler(); | ||
768 | 774 | | |||
769 | return true; | 775 | return true; | ||
770 | 776 | | |||
771 | } | 777 | } | ||
772 | 778 | | |||
779 | ///Copied from QPlatformScreen | ||||
780 | int DrmOutput::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b) const | ||||
781 | { | ||||
782 | if (a == Qt::PrimaryOrientation) a = m_preferredOrientation; | ||||
783 | if (b == Qt::PrimaryOrientation) b = m_preferredOrientation; | ||||
784 | | ||||
785 | if (a == b) | ||||
786 | return 0; | ||||
787 | | ||||
788 | int ia = std::log2(uint(a)); | ||||
789 | int ib = std::log2(uint(b)); | ||||
790 | | ||||
791 | int delta = ia - ib; | ||||
792 | | ||||
793 | if (delta < 0) | ||||
794 | delta = delta + 4; | ||||
795 | | ||||
796 | int angles[] = { 0, 90, 180, 270 }; | ||||
797 | return angles[delta]; | ||||
798 | } | ||||
zzag: I know that you copied this code, but could we maybe re-format it accordingly to the Frameworks… | |||||
apol: I would rather not. | |||||
799 | | ||||
773 | bool DrmOutput::presentAtomically(DrmBuffer *buffer) | 800 | bool DrmOutput::presentAtomically(DrmBuffer *buffer) | ||
774 | { | 801 | { | ||
775 | if (!LogindIntegration::self()->isActiveSession()) { | 802 | if (!LogindIntegration::self()->isActiveSession()) { | ||
776 | qCWarning(KWIN_DRM) << "Logind session not active."; | 803 | qCWarning(KWIN_DRM) << "Logind session not active."; | ||
777 | return false; | 804 | return false; | ||
778 | } | 805 | } | ||
779 | 806 | | |||
780 | if (m_pageFlipPending) { | 807 | if (m_pageFlipPending) { | ||
Show All 15 Lines | 819 | #endif | |||
796 | 823 | | |||
797 | if (!doAtomicCommit(AtomicCommitMode::Test)) { | 824 | if (!doAtomicCommit(AtomicCommitMode::Test)) { | ||
798 | //TODO: When we use planes for layered rendering, fallback to renderer instead. Also for direct scanout? | 825 | //TODO: When we use planes for layered rendering, fallback to renderer instead. Also for direct scanout? | ||
799 | //TODO: Probably should undo setNext and reset the flip list | 826 | //TODO: Probably should undo setNext and reset the flip list | ||
800 | qCDebug(KWIN_DRM) << "Atomic test commit failed. Aborting present."; | 827 | qCDebug(KWIN_DRM) << "Atomic test commit failed. Aborting present."; | ||
801 | // go back to previous state | 828 | // go back to previous state | ||
802 | if (m_lastWorkingState.valid) { | 829 | if (m_lastWorkingState.valid) { | ||
803 | m_mode = m_lastWorkingState.mode; | 830 | m_mode = m_lastWorkingState.mode; | ||
804 | setOrientation(m_lastWorkingState.orientation); | 831 | m_softwareRotationAngle = angleBetween(m_lastWorkingState.orientation, orientation()); | ||
832 | qCDebug(KWIN_DRM) << "software rotation to" << m_softwareRotationAngle; | ||||
805 | setGlobalPos(m_lastWorkingState.globalPos); | 833 | setGlobalPos(m_lastWorkingState.globalPos); | ||
806 | if (m_primaryPlane) { | 834 | if (m_primaryPlane) { | ||
807 | m_primaryPlane->setTransformation(m_lastWorkingState.planeTransformations); | 835 | m_primaryPlane->setTransformation(m_lastWorkingState.planeTransformations); | ||
808 | } | 836 | } | ||
809 | m_modesetRequested = true; | 837 | m_modesetRequested = true; | ||
810 | // the cursor might need to get rotated | 838 | // the cursor might need to get rotated | ||
811 | updateCursor(); | 839 | updateCursor(); | ||
812 | showCursor(); | 840 | showCursor(); | ||
▲ Show 20 Lines • Show All 265 Lines • Show Last 20 Lines |
I know that you copied this code, but could we maybe re-format it accordingly to the Frameworks coding style?
Also, it would be great to use more const.