Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/drm/drm_output.cpp
Show All 18 Lines | |||||
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> | 26 | #include <errno.h> | ||
27 | #include <cmath> | ||||
27 | 28 | | |||
28 | #include "composite.h" | 29 | #include "composite.h" | ||
29 | #include "logind.h" | 30 | #include "logind.h" | ||
30 | #include "logging.h" | 31 | #include "logging.h" | ||
31 | #include "main.h" | 32 | #include "main.h" | ||
32 | #include "orientation_sensor.h" | 33 | #include "orientation_sensor.h" | ||
33 | #include "screens_drm.h" | 34 | #include "screens_drm.h" | ||
34 | #include "wayland_server.h" | 35 | #include "wayland_server.h" | ||
▲ Show 20 Lines • Show All 272 Lines • ▼ Show 20 Line(s) | 307 | } else if (!m_edid.serialNumber.isEmpty()) { | |||
307 | modelName = QString::fromLatin1(m_edid.serialNumber); | 308 | modelName = QString::fromLatin1(m_edid.serialNumber); | ||
308 | } else { | 309 | } else { | ||
309 | modelName = i18n("unknown"); | 310 | modelName = i18n("unknown"); | ||
310 | } | 311 | } | ||
311 | 312 | | |||
312 | const QString model = connectorName + QStringLiteral("-") + QString::number(connector->connector_type_id) + QStringLiteral("-") + modelName; | 313 | const QString model = connectorName + QStringLiteral("-") + QString::number(connector->connector_type_id) + QStringLiteral("-") + modelName; | ||
313 | 314 | | |||
314 | // read in mode information | 315 | // read in mode information | ||
316 | m_preferredOrientation = Qt::LandscapeOrientation; | ||||
315 | QVector<KWayland::Server::OutputDeviceInterface::Mode> modes; | 317 | QVector<KWayland::Server::OutputDeviceInterface::Mode> modes; | ||
316 | for (int i = 0; i < connector->count_modes; ++i) { | 318 | for (int i = 0; i < connector->count_modes; ++i) { | ||
317 | // TODO: in AMS here we could read and store for later every mode's blob_id | 319 | // TODO: in AMS here we could read and store for later every mode's blob_id | ||
318 | // would simplify isCurrentMode(..) and presentAtomically(..) in case of mode set | 320 | // would simplify isCurrentMode(..) and presentAtomically(..) in case of mode set | ||
319 | auto *m = &connector->modes[i]; | 321 | auto *m = &connector->modes[i]; | ||
320 | KWayland::Server::OutputDeviceInterface::ModeFlags deviceflags; | 322 | KWayland::Server::OutputDeviceInterface::ModeFlags deviceflags; | ||
321 | if (isCurrentMode(m)) { | 323 | if (isCurrentMode(m)) { | ||
322 | deviceflags |= KWayland::Server::OutputDeviceInterface::ModeFlag::Current; | 324 | deviceflags |= KWayland::Server::OutputDeviceInterface::ModeFlag::Current; | ||
323 | } | 325 | } | ||
324 | if (m->type & DRM_MODE_TYPE_PREFERRED) { | 326 | if (m->type & DRM_MODE_TYPE_PREFERRED) { | ||
327 | m_preferredOrientation = m->hdisplay > m->vdisplay ? Qt::LandscapeOrientation : Qt::PortraitOrientation; | ||||
325 | deviceflags |= KWayland::Server::OutputDeviceInterface::ModeFlag::Preferred; | 328 | deviceflags |= KWayland::Server::OutputDeviceInterface::ModeFlag::Preferred; | ||
326 | } | 329 | } | ||
327 | 330 | | |||
328 | KWayland::Server::OutputDeviceInterface::Mode mode; | 331 | KWayland::Server::OutputDeviceInterface::Mode mode; | ||
329 | mode.id = i; | 332 | mode.id = i; | ||
330 | mode.size = QSize(m->hdisplay, m->vdisplay); | 333 | mode.size = QSize(m->hdisplay, m->vdisplay); | ||
331 | mode.flags = deviceflags; | 334 | mode.flags = deviceflags; | ||
332 | mode.refreshRate = refreshRateForMode(m); | 335 | mode.refreshRate = refreshRateForMode(m); | ||
▲ Show 20 Lines • Show All 375 Lines • ▼ Show 20 Line(s) | |||||
708 | } | 711 | } | ||
709 | 712 | | |||
710 | void DrmOutput::transform(KWayland::Server::OutputDeviceInterface::Transform transform) | 713 | void DrmOutput::transform(KWayland::Server::OutputDeviceInterface::Transform transform) | ||
711 | { | 714 | { | ||
712 | waylandOutputDevice()->setTransform(transform); | 715 | waylandOutputDevice()->setTransform(transform); | ||
713 | using KWayland::Server::OutputDeviceInterface; | 716 | using KWayland::Server::OutputDeviceInterface; | ||
714 | using KWayland::Server::OutputInterface; | 717 | using KWayland::Server::OutputInterface; | ||
715 | auto wlOutput = waylandOutput(); | 718 | auto wlOutput = waylandOutput(); | ||
719 | m_softwareRotationAngle = 0; | ||||
716 | 720 | | |||
717 | switch (transform) { | 721 | switch (transform) { | ||
718 | case OutputDeviceInterface::Transform::Normal: | 722 | case OutputDeviceInterface::Transform::Normal: | ||
719 | if (m_primaryPlane) { | 723 | if (m_primaryPlane) { | ||
720 | m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate0); | 724 | m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate0); | ||
721 | } | 725 | } | ||
722 | if (wlOutput) { | 726 | if (wlOutput) { | ||
723 | wlOutput->setTransform(OutputInterface::Transform::Normal); | 727 | wlOutput->setTransform(OutputInterface::Transform::Normal); | ||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | 793 | { | |||
799 | } | 803 | } | ||
800 | m_mode = connector->modes[modeIndex]; | 804 | m_mode = connector->modes[modeIndex]; | ||
801 | m_modesetRequested = true; | 805 | m_modesetRequested = true; | ||
802 | setWaylandMode(); | 806 | setWaylandMode(); | ||
803 | } | 807 | } | ||
804 | 808 | | |||
805 | QSize DrmOutput::pixelSize() const | 809 | QSize DrmOutput::pixelSize() const | ||
806 | { | 810 | { | ||
807 | return orientateSize(QSize(m_mode.hdisplay, m_mode.vdisplay)); | 811 | return QSize(m_mode.hdisplay, m_mode.vdisplay); | ||
808 | } | 812 | } | ||
809 | 813 | | |||
810 | void DrmOutput::setWaylandMode() | 814 | void DrmOutput::setWaylandMode() | ||
811 | { | 815 | { | ||
812 | AbstractOutput::setWaylandMode(QSize(m_mode.hdisplay, m_mode.vdisplay), | 816 | AbstractOutput::setWaylandMode(QSize(m_mode.hdisplay, m_mode.vdisplay), | ||
813 | refreshRateForMode(&m_mode)); | 817 | refreshRateForMode(&m_mode)); | ||
814 | } | 818 | } | ||
815 | 819 | | |||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | 881 | { | |||
892 | } | 896 | } | ||
893 | m_nextPlanesFlipList.clear(); | 897 | m_nextPlanesFlipList.clear(); | ||
894 | dpmsOffHandler(); | 898 | dpmsOffHandler(); | ||
895 | 899 | | |||
896 | return true; | 900 | return true; | ||
897 | 901 | | |||
898 | } | 902 | } | ||
899 | 903 | | |||
904 | ///Copied from QPlatformScreen | ||||
905 | int DrmOutput::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b) const | ||||
906 | { | ||||
907 | if (a == Qt::PrimaryOrientation) a = m_preferredOrientation; | ||||
908 | if (b == Qt::PrimaryOrientation) b = m_preferredOrientation; | ||||
909 | | ||||
910 | if (a == b) | ||||
911 | return 0; | ||||
912 | | ||||
913 | int ia = std::log2(uint(a)); | ||||
914 | int ib = std::log2(uint(b)); | ||||
915 | | ||||
916 | int delta = ia - ib; | ||||
917 | | ||||
918 | if (delta < 0) | ||||
919 | delta = delta + 4; | ||||
920 | | ||||
921 | int angles[] = { 0, 90, 180, 270 }; | ||||
922 | return angles[delta]; | ||||
923 | } | ||||
zzag: I know that you copied this code, but could we maybe re-format it accordingly to the Frameworks… | |||||
apol: I would rather not. | |||||
924 | | ||||
900 | bool DrmOutput::presentAtomically(DrmBuffer *buffer) | 925 | bool DrmOutput::presentAtomically(DrmBuffer *buffer) | ||
901 | { | 926 | { | ||
902 | if (!LogindIntegration::self()->isActiveSession()) { | 927 | if (!LogindIntegration::self()->isActiveSession()) { | ||
903 | qCWarning(KWIN_DRM) << "Logind session not active."; | 928 | qCWarning(KWIN_DRM) << "Logind session not active."; | ||
904 | return false; | 929 | return false; | ||
905 | } | 930 | } | ||
906 | 931 | | |||
907 | if (m_pageFlipPending) { | 932 | if (m_pageFlipPending) { | ||
908 | qCWarning(KWIN_DRM) << "Page not yet flipped."; | 933 | qCWarning(KWIN_DRM) << "Page not yet flipped."; | ||
909 | return false; | 934 | return false; | ||
910 | } | 935 | } | ||
911 | 936 | | |||
912 | m_primaryPlane->setNext(buffer); | 937 | m_primaryPlane->setNext(buffer); | ||
913 | m_nextPlanesFlipList << m_primaryPlane; | 938 | m_nextPlanesFlipList << m_primaryPlane; | ||
914 | 939 | | |||
915 | if (!doAtomicCommit(AtomicCommitMode::Test)) { | 940 | if (!doAtomicCommit(AtomicCommitMode::Test)) { | ||
916 | //TODO: When we use planes for layered rendering, fallback to renderer instead. Also for direct scanout? | 941 | //TODO: When we use planes for layered rendering, fallback to renderer instead. Also for direct scanout? | ||
917 | //TODO: Probably should undo setNext and reset the flip list | 942 | //TODO: Probably should undo setNext and reset the flip list | ||
918 | qCDebug(KWIN_DRM) << "Atomic test commit failed. Aborting present."; | 943 | qCDebug(KWIN_DRM) << "Atomic test commit failed. Aborting present."; | ||
919 | // go back to previous state | 944 | // go back to previous state | ||
920 | if (m_lastWorkingState.valid) { | 945 | if (m_lastWorkingState.valid) { | ||
921 | m_mode = m_lastWorkingState.mode; | 946 | m_mode = m_lastWorkingState.mode; | ||
922 | setOrientation(m_lastWorkingState.orientation); | 947 | m_softwareRotationAngle = angleBetween(m_lastWorkingState.orientation, orientation()); | ||
948 | qCDebug(KWIN_DRM) << "software rotation to" << m_softwareRotationAngle; | ||||
923 | setGlobalPos(m_lastWorkingState.globalPos); | 949 | setGlobalPos(m_lastWorkingState.globalPos); | ||
924 | if (m_primaryPlane) { | 950 | if (m_primaryPlane) { | ||
925 | m_primaryPlane->setTransformation(m_lastWorkingState.planeTransformations); | 951 | m_primaryPlane->setTransformation(m_lastWorkingState.planeTransformations); | ||
926 | } | 952 | } | ||
927 | m_modesetRequested = true; | 953 | m_modesetRequested = true; | ||
928 | // the cursor might need to get rotated | 954 | // the cursor might need to get rotated | ||
929 | updateCursor(); | 955 | updateCursor(); | ||
930 | showCursor(); | 956 | showCursor(); | ||
▲ Show 20 Lines • Show All 259 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.