Changeset View
Changeset View
Standalone View
Standalone View
plugins/platforms/drm/drm_output.cpp
Show All 21 Lines | |||||
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 "composite.h" | 26 | #include "composite.h" | ||
27 | #include "logind.h" | 27 | #include "logind.h" | ||
28 | #include "logging.h" | 28 | #include "logging.h" | ||
29 | #include "main.h" | 29 | #include "main.h" | ||
30 | #include "orientation_sensor.h" | | |||
31 | #include "screens_drm.h" | 30 | #include "screens_drm.h" | ||
32 | #include "wayland_server.h" | 31 | #include "wayland_server.h" | ||
33 | // KWayland | 32 | // KWayland | ||
34 | #include <KWayland/Server/output_interface.h> | 33 | #include <KWayland/Server/output_interface.h> | ||
35 | // KF5 | 34 | // KF5 | ||
36 | #include <KConfigGroup> | 35 | #include <KConfigGroup> | ||
37 | #include <KLocalizedString> | 36 | #include <KLocalizedString> | ||
38 | #include <KSharedConfig> | 37 | #include <KSharedConfig> | ||
▲ Show 20 Lines • Show All 226 Lines • ▼ Show 20 Line(s) | 263 | if (m_backend->atomicModeSetting()) { | |||
265 | if (!initPrimaryPlane()) { | 264 | if (!initPrimaryPlane()) { | ||
266 | return false; | 265 | return false; | ||
267 | } | 266 | } | ||
268 | } | 267 | } | ||
269 | 268 | | |||
270 | setInternal(connector->connector_type == DRM_MODE_CONNECTOR_LVDS || connector->connector_type == DRM_MODE_CONNECTOR_eDP | 269 | setInternal(connector->connector_type == DRM_MODE_CONNECTOR_LVDS || connector->connector_type == DRM_MODE_CONNECTOR_eDP | ||
271 | || connector->connector_type == DRM_MODE_CONNECTOR_DSI); | 270 | || connector->connector_type == DRM_MODE_CONNECTOR_DSI); | ||
272 | setDpmsSupported(true); | 271 | setDpmsSupported(true); | ||
273 | | ||||
274 | if (isInternal()) { | | |||
275 | connect(kwinApp(), &Application::screensCreated, this, | | |||
276 | [this] { | | |||
277 | connect(screens()->orientationSensor(), &OrientationSensor::orientationChanged, this, &DrmOutput::automaticRotation); | | |||
278 | } | | |||
279 | ); | | |||
280 | } | | |||
281 | | ||||
282 | initOutputDevice(connector); | 272 | initOutputDevice(connector); | ||
283 | 273 | | |||
284 | if (!m_backend->atomicModeSetting() && !m_crtc->blank()) { | 274 | if (!m_backend->atomicModeSetting() && !m_crtc->blank()) { | ||
285 | // We use legacy mode and the initial output blank failed. | 275 | // We use legacy mode and the initial output blank failed. | ||
286 | return false; | 276 | return false; | ||
287 | } | 277 | } | ||
288 | 278 | | |||
289 | updateDpms(KWayland::Server::OutputInterface::DpmsMode::On); | 279 | updateDpms(KWayland::Server::OutputInterface::DpmsMode::On); | ||
▲ Show 20 Lines • Show All 792 Lines • ▼ Show 20 Line(s) | 1071 | if (!m_primaryPlane) { | |||
1082 | return false; | 1072 | return false; | ||
1083 | } | 1073 | } | ||
1084 | const auto transformations = m_primaryPlane->supportedTransformations(); | 1074 | const auto transformations = m_primaryPlane->supportedTransformations(); | ||
1085 | return transformations.testFlag(DrmPlane::Transformation::Rotate90) | 1075 | return transformations.testFlag(DrmPlane::Transformation::Rotate90) | ||
1086 | || transformations.testFlag(DrmPlane::Transformation::Rotate180) | 1076 | || transformations.testFlag(DrmPlane::Transformation::Rotate180) | ||
1087 | || transformations.testFlag(DrmPlane::Transformation::Rotate270); | 1077 | || transformations.testFlag(DrmPlane::Transformation::Rotate270); | ||
1088 | } | 1078 | } | ||
1089 | 1079 | | |||
1090 | void DrmOutput::automaticRotation() | | |||
1091 | { | | |||
1092 | if (!m_primaryPlane) { | | |||
1093 | return; | | |||
1094 | } | | |||
1095 | const auto supportedTransformations = m_primaryPlane->supportedTransformations(); | | |||
1096 | const auto requestedTransformation = screens()->orientationSensor()->orientation(); | | |||
1097 | | ||||
1098 | Transform newTransformation = Transform::Normal; | | |||
1099 | switch (requestedTransformation) { | | |||
1100 | case OrientationSensor::Orientation::TopUp: | | |||
1101 | newTransformation = Transform::Normal; | | |||
1102 | break; | | |||
1103 | case OrientationSensor::Orientation::TopDown: | | |||
1104 | if (!supportedTransformations.testFlag(DrmPlane::Transformation::Rotate180)) { | | |||
1105 | return; | | |||
1106 | } | | |||
1107 | newTransformation = Transform::Rotated180; | | |||
1108 | break; | | |||
1109 | case OrientationSensor::Orientation::LeftUp: | | |||
1110 | if (!supportedTransformations.testFlag(DrmPlane::Transformation::Rotate90)) { | | |||
1111 | return; | | |||
1112 | } | | |||
1113 | newTransformation = Transform::Rotated90; | | |||
1114 | break; | | |||
1115 | case OrientationSensor::Orientation::RightUp: | | |||
1116 | if (!supportedTransformations.testFlag(DrmPlane::Transformation::Rotate270)) { | | |||
1117 | return; | | |||
1118 | } | | |||
1119 | newTransformation = Transform::Rotated270; | | |||
1120 | break; | | |||
1121 | case OrientationSensor::Orientation::FaceUp: | | |||
1122 | case OrientationSensor::Orientation::FaceDown: | | |||
1123 | case OrientationSensor::Orientation::Undefined: | | |||
1124 | // unsupported | | |||
1125 | return; | | |||
1126 | } | | |||
1127 | setTransform(newTransformation); | | |||
1128 | emit screens()->changed(); | | |||
1129 | } | | |||
1130 | | ||||
1131 | int DrmOutput::gammaRampSize() const | 1080 | int DrmOutput::gammaRampSize() const | ||
1132 | { | 1081 | { | ||
1133 | return m_crtc->gammaRampSize(); | 1082 | return m_crtc->gammaRampSize(); | ||
1134 | } | 1083 | } | ||
1135 | 1084 | | |||
1136 | bool DrmOutput::setGammaRamp(const GammaRamp &gamma) | 1085 | bool DrmOutput::setGammaRamp(const GammaRamp &gamma) | ||
1137 | { | 1086 | { | ||
1138 | return m_crtc->setGammaRamp(gamma); | 1087 | return m_crtc->setGammaRamp(gamma); | ||
1139 | } | 1088 | } | ||
1140 | 1089 | | |||
1141 | } | 1090 | } |