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 270 Lines • ▼ Show 20 Line(s) | 306 | } else if (!m_edid.serialNumber().isEmpty()) { | |||
304 | modelName = QString::fromLatin1(m_edid.serialNumber()); | 307 | modelName = QString::fromLatin1(m_edid.serialNumber()); | ||
305 | } else { | 308 | } else { | ||
306 | modelName = i18n("unknown"); | 309 | modelName = i18n("unknown"); | ||
307 | } | 310 | } | ||
308 | 311 | | |||
309 | const QString model = connectorName + QStringLiteral("-") + QString::number(connector->connector_type_id) + QStringLiteral("-") + modelName; | 312 | const QString model = connectorName + QStringLiteral("-") + QString::number(connector->connector_type_id) + QStringLiteral("-") + modelName; | ||
310 | 313 | | |||
311 | // read in mode information | 314 | // read in mode information | ||
315 | m_preferredOrientation = Qt::LandscapeOrientation; | ||||
312 | QVector<KWayland::Server::OutputDeviceInterface::Mode> modes; | 316 | QVector<KWayland::Server::OutputDeviceInterface::Mode> modes; | ||
313 | for (int i = 0; i < connector->count_modes; ++i) { | 317 | for (int i = 0; i < connector->count_modes; ++i) { | ||
314 | // TODO: in AMS here we could read and store for later every mode's blob_id | 318 | // TODO: in AMS here we could read and store for later every mode's blob_id | ||
315 | // would simplify isCurrentMode(..) and presentAtomically(..) in case of mode set | 319 | // would simplify isCurrentMode(..) and presentAtomically(..) in case of mode set | ||
316 | auto *m = &connector->modes[i]; | 320 | auto *m = &connector->modes[i]; | ||
317 | KWayland::Server::OutputDeviceInterface::ModeFlags deviceflags; | 321 | KWayland::Server::OutputDeviceInterface::ModeFlags deviceflags; | ||
318 | if (isCurrentMode(m)) { | 322 | if (isCurrentMode(m)) { | ||
319 | deviceflags |= KWayland::Server::OutputDeviceInterface::ModeFlag::Current; | 323 | deviceflags |= KWayland::Server::OutputDeviceInterface::ModeFlag::Current; | ||
320 | } | 324 | } | ||
321 | if (m->type & DRM_MODE_TYPE_PREFERRED) { | 325 | if (m->type & DRM_MODE_TYPE_PREFERRED) { | ||
326 | m_preferredOrientation = m->hdisplay > m->vdisplay ? Qt::LandscapeOrientation : Qt::PortraitOrientation; | ||||
322 | deviceflags |= KWayland::Server::OutputDeviceInterface::ModeFlag::Preferred; | 327 | deviceflags |= KWayland::Server::OutputDeviceInterface::ModeFlag::Preferred; | ||
323 | } | 328 | } | ||
324 | 329 | | |||
325 | KWayland::Server::OutputDeviceInterface::Mode mode; | 330 | KWayland::Server::OutputDeviceInterface::Mode mode; | ||
326 | mode.id = i; | 331 | mode.id = i; | ||
327 | mode.size = QSize(m->hdisplay, m->vdisplay); | 332 | mode.size = QSize(m->hdisplay, m->vdisplay); | ||
328 | mode.flags = deviceflags; | 333 | mode.flags = deviceflags; | ||
329 | mode.refreshRate = refreshRateForMode(m); | 334 | mode.refreshRate = refreshRateForMode(m); | ||
▲ Show 20 Lines • Show All 305 Lines • ▼ Show 20 Line(s) | |||||
635 | } | 640 | } | ||
636 | 641 | | |||
637 | void DrmOutput::transform(KWayland::Server::OutputDeviceInterface::Transform transform) | 642 | void DrmOutput::transform(KWayland::Server::OutputDeviceInterface::Transform transform) | ||
638 | { | 643 | { | ||
639 | waylandOutputDevice()->setTransform(transform); | 644 | waylandOutputDevice()->setTransform(transform); | ||
640 | using KWayland::Server::OutputDeviceInterface; | 645 | using KWayland::Server::OutputDeviceInterface; | ||
641 | using KWayland::Server::OutputInterface; | 646 | using KWayland::Server::OutputInterface; | ||
642 | auto wlOutput = waylandOutput(); | 647 | auto wlOutput = waylandOutput(); | ||
648 | m_softwareRotationAngle = 0; | ||||
643 | 649 | | |||
644 | switch (transform) { | 650 | switch (transform) { | ||
645 | case OutputDeviceInterface::Transform::Normal: | 651 | case OutputDeviceInterface::Transform::Normal: | ||
646 | if (m_primaryPlane) { | 652 | if (m_primaryPlane) { | ||
647 | m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate0); | 653 | m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate0); | ||
648 | } | 654 | } | ||
649 | if (wlOutput) { | 655 | if (wlOutput) { | ||
650 | wlOutput->setTransform(OutputInterface::Transform::Normal); | 656 | wlOutput->setTransform(OutputInterface::Transform::Normal); | ||
▲ Show 20 Lines • Show All 170 Lines • ▼ Show 20 Line(s) | 825 | if (!doAtomicCommit(AtomicCommitMode::Real)) { | |||
821 | return false; | 827 | return false; | ||
822 | } | 828 | } | ||
823 | m_nextPlanesFlipList.clear(); | 829 | m_nextPlanesFlipList.clear(); | ||
824 | dpmsFinishOff(); | 830 | dpmsFinishOff(); | ||
825 | 831 | | |||
826 | return true; | 832 | return true; | ||
827 | } | 833 | } | ||
828 | 834 | | |||
835 | ///Copied from QPlatformScreen | ||||
836 | int DrmOutput::angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b) const | ||||
837 | { | ||||
838 | if (a == Qt::PrimaryOrientation) a = m_preferredOrientation; | ||||
839 | if (b == Qt::PrimaryOrientation) b = m_preferredOrientation; | ||||
840 | | ||||
841 | if (a == b) | ||||
842 | return 0; | ||||
843 | | ||||
844 | int ia = std::log2(uint(a)); | ||||
845 | int ib = std::log2(uint(b)); | ||||
846 | | ||||
847 | int delta = ia - ib; | ||||
848 | | ||||
849 | if (delta < 0) | ||||
850 | delta = delta + 4; | ||||
851 | | ||||
852 | int angles[] = { 0, 90, 180, 270 }; | ||||
853 | return angles[delta]; | ||||
854 | } | ||||
zzag: I know that you copied this code, but could we maybe re-format it accordingly to the Frameworks… | |||||
apol: I would rather not. | |||||
855 | | ||||
829 | bool DrmOutput::presentAtomically(DrmBuffer *buffer) | 856 | bool DrmOutput::presentAtomically(DrmBuffer *buffer) | ||
830 | { | 857 | { | ||
831 | if (!LogindIntegration::self()->isActiveSession()) { | 858 | if (!LogindIntegration::self()->isActiveSession()) { | ||
832 | qCWarning(KWIN_DRM) << "Logind session not active."; | 859 | qCWarning(KWIN_DRM) << "Logind session not active."; | ||
833 | return false; | 860 | return false; | ||
834 | } | 861 | } | ||
835 | 862 | | |||
836 | if (m_pageFlipPending) { | 863 | if (m_pageFlipPending) { | ||
Show All 15 Lines | 875 | #endif | |||
852 | 879 | | |||
853 | if (!doAtomicCommit(AtomicCommitMode::Test)) { | 880 | if (!doAtomicCommit(AtomicCommitMode::Test)) { | ||
854 | //TODO: When we use planes for layered rendering, fallback to renderer instead. Also for direct scanout? | 881 | //TODO: When we use planes for layered rendering, fallback to renderer instead. Also for direct scanout? | ||
855 | //TODO: Probably should undo setNext and reset the flip list | 882 | //TODO: Probably should undo setNext and reset the flip list | ||
856 | qCDebug(KWIN_DRM) << "Atomic test commit failed. Aborting present."; | 883 | qCDebug(KWIN_DRM) << "Atomic test commit failed. Aborting present."; | ||
857 | // go back to previous state | 884 | // go back to previous state | ||
858 | if (m_lastWorkingState.valid) { | 885 | if (m_lastWorkingState.valid) { | ||
859 | m_mode = m_lastWorkingState.mode; | 886 | m_mode = m_lastWorkingState.mode; | ||
860 | setOrientation(m_lastWorkingState.orientation); | 887 | m_softwareRotationAngle = angleBetween(m_lastWorkingState.orientation, orientation()); | ||
888 | qCDebug(KWIN_DRM) << "software rotation to" << m_softwareRotationAngle; | ||||
861 | setGlobalPos(m_lastWorkingState.globalPos); | 889 | setGlobalPos(m_lastWorkingState.globalPos); | ||
862 | if (m_primaryPlane) { | 890 | if (m_primaryPlane) { | ||
863 | m_primaryPlane->setTransformation(m_lastWorkingState.planeTransformations); | 891 | m_primaryPlane->setTransformation(m_lastWorkingState.planeTransformations); | ||
864 | } | 892 | } | ||
865 | m_modesetRequested = true; | 893 | m_modesetRequested = true; | ||
866 | // the cursor might need to get rotated | 894 | // the cursor might need to get rotated | ||
867 | updateCursor(); | 895 | updateCursor(); | ||
868 | showCursor(); | 896 | showCursor(); | ||
▲ Show 20 Lines • Show All 262 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.