Paste P358

Masterwork From Distant Lands
ActivePublic

Authored by apol on Mar 27 2019, 2:23 PM.
diff --git a/plugins/platforms/drm/drm_output.cpp b/plugins/platforms/drm/drm_output.cpp
index cb243871f..c53f62b53 100644
--- a/plugins/platforms/drm/drm_output.cpp
+++ b/plugins/platforms/drm/drm_output.cpp
@@ -51,6 +51,27 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
namespace KWin
{
+///Copied from QPlatformScreen
+static int angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b)
+{
+ if (a == Qt::PrimaryOrientation) a = Qt::LandscapeOrientation;
+ if (b == Qt::PrimaryOrientation) b = Qt::LandscapeOrientation;
+
+ if (a == b)
+ return 0;
+
+ int ia = std::log2(uint(a));
+ int ib = std::log2(uint(b));
+
+ int delta = ia - ib;
+
+ if (delta < 0)
+ delta = delta + 4;
+
+ int angles[] = { 0, 90, 180, 270 };
+ return angles[delta];
+}
+
DrmOutput::DrmOutput(DrmBackend *backend)
: AbstractOutput(backend)
, m_backend(backend)
@@ -716,6 +737,7 @@ void DrmOutput::transform(KWayland::Server::OutputDeviceInterface::Transform tra
auto wlOutput = waylandOutput();
m_softwareRotationAngle = 0;
+ const auto supportedTransformations = m_primaryPlane->supportedTransformations();
switch (transform) {
case OutputDeviceInterface::Transform::Normal:
if (m_primaryPlane) {
@@ -724,11 +746,15 @@ void DrmOutput::transform(KWayland::Server::OutputDeviceInterface::Transform tra
if (wlOutput) {
wlOutput->setTransform(OutputInterface::Transform::Normal);
}
+
setOrientation(Qt::PrimaryOrientation);
break;
case OutputDeviceInterface::Transform::Rotated90:
+ if (!supportedTransformations.testFlag(DrmPlane::Transformation::Rotate90)) {
+ m_softwareRotationAngle = angleBetween(Qt::PrimaryOrientation, Qt::PortraitOrientation);
+ }
if (m_primaryPlane) {
- m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate90);
+ m_primaryPlane->setTransformation(m_softwareRotationAngle ? DrmPlane::Transformation::Rotate0 : DrmPlane::Transformation::Rotate90);
}
if (wlOutput) {
wlOutput->setTransform(OutputInterface::Transform::Rotated90);
@@ -736,8 +762,11 @@ void DrmOutput::transform(KWayland::Server::OutputDeviceInterface::Transform tra
setOrientation(Qt::PortraitOrientation);
break;
case OutputDeviceInterface::Transform::Rotated180:
+ if (!supportedTransformations.testFlag(DrmPlane::Transformation::Rotate270)) {
+ m_softwareRotationAngle = angleBetween(Qt::PrimaryOrientation, Qt::PortraitOrientation);
+ }
if (m_primaryPlane) {
- m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate180);
+ m_primaryPlane->setTransformation(m_softwareRotationAngle ? DrmPlane::Transformation::Rotate0 : DrmPlane::Transformation::Rotate180);
}
if (wlOutput) {
wlOutput->setTransform(OutputInterface::Transform::Rotated180);
@@ -745,8 +774,11 @@ void DrmOutput::transform(KWayland::Server::OutputDeviceInterface::Transform tra
setOrientation(Qt::InvertedLandscapeOrientation);
break;
case OutputDeviceInterface::Transform::Rotated270:
+ if (!supportedTransformations.testFlag(DrmPlane::Transformation::Rotate270)) {
+ m_softwareRotationAngle = angleBetween(Qt::PrimaryOrientation, Qt::PortraitOrientation);
+ }
if (m_primaryPlane) {
- m_primaryPlane->setTransformation(DrmPlane::Transformation::Rotate270);
+ m_primaryPlane->setTransformation(m_softwareRotationAngle ? DrmPlane::Transformation::Rotate0 : DrmPlane::Transformation::Rotate270);
}
if (wlOutput) {
wlOutput->setTransform(OutputInterface::Transform::Rotated270);
@@ -899,27 +931,6 @@ bool DrmOutput::dpmsAtomicOff()
}
-///Copied from QPlatformScreen
-static int angleBetween(Qt::ScreenOrientation a, Qt::ScreenOrientation b)
-{
- if (a == Qt::PrimaryOrientation) a = Qt::LandscapeOrientation;
- if (b == Qt::PrimaryOrientation) b = Qt::LandscapeOrientation;
-
- if (a == b)
- return 0;
-
- int ia = std::log2(uint(a));
- int ib = std::log2(uint(b));
-
- int delta = ia - ib;
-
- if (delta < 0)
- delta = delta + 4;
-
- int angles[] = { 0, 90, 180, 270 };
- return angles[delta];
-}
-
bool DrmOutput::presentAtomically(DrmBuffer *buffer)
{
if (!LogindIntegration::self()->isActiveSession()) {
@@ -1164,7 +1175,7 @@ void DrmOutput::automaticRotation()
if (!m_primaryPlane) {
return;
}
- const auto supportedTransformations = m_primaryPlane->supportedTransformations();
+
const auto requestedTransformation = screens()->orientationSensor()->orientation();
using KWayland::Server::OutputDeviceInterface;
OutputDeviceInterface::Transform newTransformation = OutputDeviceInterface::Transform::Normal;
@@ -1173,21 +1184,12 @@ void DrmOutput::automaticRotation()
newTransformation = OutputDeviceInterface::Transform::Normal;
break;
case OrientationSensor::Orientation::TopDown:
- if (!supportedTransformations.testFlag(DrmPlane::Transformation::Rotate180)) {
- return;
- }
newTransformation = OutputDeviceInterface::Transform::Rotated180;
break;
case OrientationSensor::Orientation::LeftUp:
- if (!supportedTransformations.testFlag(DrmPlane::Transformation::Rotate90)) {
- return;
- }
newTransformation = OutputDeviceInterface::Transform::Rotated90;
break;
case OrientationSensor::Orientation::RightUp:
- if (!supportedTransformations.testFlag(DrmPlane::Transformation::Rotate270)) {
- return;
- }
newTransformation = OutputDeviceInterface::Transform::Rotated270;
break;
case OrientationSensor::Orientation::FaceUp:
apol edited the content of this paste. (Show Details)Mar 27 2019, 2:23 PM
apol changed the title of this paste from untitled to Masterwork From Distant Lands.