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 282 Lines • ▼ Show 20 Line(s) | 317 | } else if (!m_edid.serialNumber.isEmpty()) { | |||
317 | modelName = QString::fromLatin1(m_edid.serialNumber); | 318 | modelName = QString::fromLatin1(m_edid.serialNumber); | ||
318 | } else { | 319 | } else { | ||
319 | modelName = i18n("unknown"); | 320 | modelName = i18n("unknown"); | ||
320 | } | 321 | } | ||
321 | 322 | | |||
322 | const QString model = connectorName + QStringLiteral("-") + QString::number(connector->connector_type_id) + QStringLiteral("-") + modelName; | 323 | const QString model = connectorName + QStringLiteral("-") + QString::number(connector->connector_type_id) + QStringLiteral("-") + modelName; | ||
323 | 324 | | |||
324 | // read in mode information | 325 | // read in mode information | ||
326 | m_preferredOrientation = Qt::LandscapeOrientation; | ||||
325 | QVector<KWayland::Server::OutputDeviceInterface::Mode> modes; | 327 | QVector<KWayland::Server::OutputDeviceInterface::Mode> modes; | ||
326 | for (int i = 0; i < connector->count_modes; ++i) { | 328 | 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 | 329 | // 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 | 330 | // would simplify isCurrentMode(..) and presentAtomically(..) in case of mode set | ||
329 | auto *m = &connector->modes[i]; | 331 | auto *m = &connector->modes[i]; | ||
330 | KWayland::Server::OutputDeviceInterface::ModeFlags deviceflags; | 332 | KWayland::Server::OutputDeviceInterface::ModeFlags deviceflags; | ||
331 | if (isCurrentMode(m)) { | 333 | if (isCurrentMode(m)) { | ||
332 | deviceflags |= KWayland::Server::OutputDeviceInterface::ModeFlag::Current; | 334 | deviceflags |= KWayland::Server::OutputDeviceInterface::ModeFlag::Current; | ||
333 | } | 335 | } | ||
334 | if (m->type & DRM_MODE_TYPE_PREFERRED) { | 336 | if (m->type & DRM_MODE_TYPE_PREFERRED) { | ||
337 | m_preferredOrientation = m->hdisplay > m->vdisplay ? Qt::LandscapeOrientation : Qt::PortraitOrientation; | ||||
335 | deviceflags |= KWayland::Server::OutputDeviceInterface::ModeFlag::Preferred; | 338 | deviceflags |= KWayland::Server::OutputDeviceInterface::ModeFlag::Preferred; | ||
336 | } | 339 | } | ||
337 | 340 | | |||
338 | KWayland::Server::OutputDeviceInterface::Mode mode; | 341 | KWayland::Server::OutputDeviceInterface::Mode mode; | ||
339 | mode.id = i; | 342 | mode.id = i; | ||
340 | mode.size = QSize(m->hdisplay, m->vdisplay); | 343 | mode.size = QSize(m->hdisplay, m->vdisplay); | ||
341 | mode.flags = deviceflags; | 344 | mode.flags = deviceflags; | ||
342 | mode.refreshRate = refreshRateForMode(m); | 345 | mode.refreshRate = refreshRateForMode(m); | ||
▲ Show 20 Lines • Show All 375 Lines • ▼ Show 20 Line(s) | |||||
718 | } | 721 | } | ||
719 | 722 | | |||
720 | void DrmOutput::transform(KWayland::Server::OutputDeviceInterface::Transform transform) | 723 | void DrmOutput::transform(KWayland::Server::OutputDeviceInterface::Transform transform) | ||
721 | { | 724 | { | ||
722 | waylandOutputDevice()->setTransform(transform); | 725 | waylandOutputDevice()->setTransform(transform); | ||
723 | using KWayland::Server::OutputDeviceInterface; | 726 | using KWayland::Server::OutputDeviceInterface; | ||
724 | using KWayland::Server::OutputInterface; | 727 | using KWayland::Server::OutputInterface; | ||
725 | auto wlOutput = waylandOutput(); | 728 | auto wlOutput = waylandOutput(); | ||
729 | m_softwareRotationAngle = 0; | ||||
726 | 730 | | |||
727 | switch (transform) { | 731 | switch (transform) { | ||
728 | case OutputDeviceInterface::Transform::Normal: | 732 | case OutputDeviceInterface::Transform::Normal: | ||
729 | if (m_primaryPlane) { | 733 | if (m_primaryPlane) { | ||
730 | m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate0); | 734 | m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate0); | ||
731 | } | 735 | } | ||
732 | if (wlOutput) { | 736 | if (wlOutput) { | ||
733 | wlOutput->setTransform(OutputInterface::Transform::Normal); | 737 | wlOutput->setTransform(OutputInterface::Transform::Normal); | ||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | 803 | { | |||
809 | } | 813 | } | ||
810 | m_mode = connector->modes[modeIndex]; | 814 | m_mode = connector->modes[modeIndex]; | ||
811 | m_modesetRequested = true; | 815 | m_modesetRequested = true; | ||
812 | setWaylandMode(); | 816 | setWaylandMode(); | ||
813 | } | 817 | } | ||
814 | 818 | | |||
815 | QSize DrmOutput::pixelSize() const | 819 | QSize DrmOutput::pixelSize() const | ||
816 | { | 820 | { | ||
817 | return orientateSize(QSize(m_mode.hdisplay, m_mode.vdisplay)); | 821 | return QSize(m_mode.hdisplay, m_mode.vdisplay); | ||
818 | } | 822 | } | ||
819 | 823 | | |||
820 | void DrmOutput::setWaylandMode() | 824 | void DrmOutput::setWaylandMode() | ||
821 | { | 825 | { | ||
822 | AbstractWaylandOutput::setWaylandMode(QSize(m_mode.hdisplay, m_mode.vdisplay), | 826 | AbstractWaylandOutput::setWaylandMode(QSize(m_mode.hdisplay, m_mode.vdisplay), | ||
823 | refreshRateForMode(&m_mode)); | 827 | refreshRateForMode(&m_mode)); | ||
824 | } | 828 | } | ||
825 | 829 | | |||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | 891 | { | |||
902 | } | 906 | } | ||
903 | m_nextPlanesFlipList.clear(); | 907 | m_nextPlanesFlipList.clear(); | ||
904 | dpmsOffHandler(); | 908 | dpmsOffHandler(); | ||
905 | 909 | | |||
906 | return true; | 910 | return true; | ||
907 | 911 | | |||
908 | } | 912 | } | ||
909 | 913 | | |||
914 | ///Copied from QPlatformScreen | ||||
915 | int DrmOutput::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b) const | ||||
916 | { | ||||
917 | if (a == Qt::PrimaryOrientation) a = m_preferredOrientation; | ||||
918 | if (b == Qt::PrimaryOrientation) b = m_preferredOrientation; | ||||
919 | | ||||
920 | if (a == b) | ||||
921 | return 0; | ||||
922 | | ||||
923 | int ia = std::log2(uint(a)); | ||||
924 | int ib = std::log2(uint(b)); | ||||
925 | | ||||
926 | int delta = ia - ib; | ||||
927 | | ||||
928 | if (delta < 0) | ||||
929 | delta = delta + 4; | ||||
930 | | ||||
931 | int angles[] = { 0, 90, 180, 270 }; | ||||
932 | return angles[delta]; | ||||
933 | } | ||||
zzag: I know that you copied this code, but could we maybe re-format it accordingly to the Frameworks… | |||||
apol: I would rather not. | |||||
934 | | ||||
910 | bool DrmOutput::presentAtomically(DrmBuffer *buffer) | 935 | bool DrmOutput::presentAtomically(DrmBuffer *buffer) | ||
911 | { | 936 | { | ||
912 | if (!LogindIntegration::self()->isActiveSession()) { | 937 | if (!LogindIntegration::self()->isActiveSession()) { | ||
913 | qCWarning(KWIN_DRM) << "Logind session not active."; | 938 | qCWarning(KWIN_DRM) << "Logind session not active."; | ||
914 | return false; | 939 | return false; | ||
915 | } | 940 | } | ||
916 | 941 | | |||
917 | if (m_pageFlipPending) { | 942 | if (m_pageFlipPending) { | ||
Show All 15 Lines | 954 | #endif | |||
933 | 958 | | |||
934 | if (!doAtomicCommit(AtomicCommitMode::Test)) { | 959 | if (!doAtomicCommit(AtomicCommitMode::Test)) { | ||
935 | //TODO: When we use planes for layered rendering, fallback to renderer instead. Also for direct scanout? | 960 | //TODO: When we use planes for layered rendering, fallback to renderer instead. Also for direct scanout? | ||
936 | //TODO: Probably should undo setNext and reset the flip list | 961 | //TODO: Probably should undo setNext and reset the flip list | ||
937 | qCDebug(KWIN_DRM) << "Atomic test commit failed. Aborting present."; | 962 | qCDebug(KWIN_DRM) << "Atomic test commit failed. Aborting present."; | ||
938 | // go back to previous state | 963 | // go back to previous state | ||
939 | if (m_lastWorkingState.valid) { | 964 | if (m_lastWorkingState.valid) { | ||
940 | m_mode = m_lastWorkingState.mode; | 965 | m_mode = m_lastWorkingState.mode; | ||
941 | setOrientation(m_lastWorkingState.orientation); | 966 | m_softwareRotationAngle = angleBetween(m_lastWorkingState.orientation, orientation()); | ||
967 | qCDebug(KWIN_DRM) << "software rotation to" << m_softwareRotationAngle; | ||||
942 | setGlobalPos(m_lastWorkingState.globalPos); | 968 | setGlobalPos(m_lastWorkingState.globalPos); | ||
943 | if (m_primaryPlane) { | 969 | if (m_primaryPlane) { | ||
944 | m_primaryPlane->setTransformation(m_lastWorkingState.planeTransformations); | 970 | m_primaryPlane->setTransformation(m_lastWorkingState.planeTransformations); | ||
945 | } | 971 | } | ||
946 | m_modesetRequested = true; | 972 | m_modesetRequested = true; | ||
947 | // the cursor might need to get rotated | 973 | // the cursor might need to get rotated | ||
948 | updateCursor(); | 974 | updateCursor(); | ||
949 | showCursor(); | 975 | 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.