Commit d5da3665 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

Add a generic Output::transformation method

Makes it possible to map any space into the output's coordinates system
parent 9a8b6f73
......@@ -19,6 +19,7 @@
// KF5
#include <KLocalizedString>
#include <QMatrix4x4>
#include <cmath>
namespace KWin
......@@ -310,4 +311,46 @@ AbstractWaylandOutput::Transform AbstractWaylandOutput::transform() const
return static_cast<Transform>(m_waylandOutputDevice->transform());
}
// TODO: Do we need to handle the flipped cases differently?
int transformToRotation(AbstractWaylandOutput::Transform transform)
{
switch (transform) {
case AbstractWaylandOutput::Transform::Normal:
case AbstractWaylandOutput::Transform::Flipped:
return 0;
case AbstractWaylandOutput::Transform::Rotated90:
case AbstractWaylandOutput::Transform::Flipped90:
return 90;
case AbstractWaylandOutput::Transform::Rotated180:
case AbstractWaylandOutput::Transform::Flipped180:
return 180;
case AbstractWaylandOutput::Transform::Rotated270:
case AbstractWaylandOutput::Transform::Flipped270:
return 270;
}
Q_UNREACHABLE();
return 0;
}
int AbstractWaylandOutput::rotation() const
{
return transformToRotation(transform());
}
QMatrix4x4 AbstractWaylandOutput::transformation() const
{
const QSize outputSize = modeSize();
const QSize logicalSize = pixelSize();
QMatrix4x4 matrix;
matrix.translate(outputSize.width()/2, outputSize.height()/2);
matrix.rotate(rotation(), 0, 0, 1);
matrix.translate(-logicalSize.width()/2, -logicalSize.height()/2);
matrix.scale(scale());
const QPoint topLeft = -globalPos();
matrix.translate(-topLeft.x(), -topLeft.y());
return matrix;
}
}
......@@ -112,6 +112,18 @@ public:
QString description() const;
/**
* The current rotation of the output
*
* @return rotation in degrees
*/
int rotation() const;
/**
* Returns a matrix that can translate into the display's coordinates system
*/
QMatrix4x4 transformation() const;
Q_SIGNALS:
void modeChanged();
void geometryChanged();
......
......@@ -129,31 +129,10 @@ bool DrmOutput::showCursor()
return ret;
}
// TODO: Do we need to handle the flipped cases differently?
int transformToRotation(DrmOutput::Transform transform)
{
switch (transform) {
case DrmOutput::Transform::Normal:
case DrmOutput::Transform::Flipped:
return 0;
case DrmOutput::Transform::Rotated90:
case DrmOutput::Transform::Flipped90:
return 90;
case DrmOutput::Transform::Rotated180:
case DrmOutput::Transform::Flipped180:
return 180;
case DrmOutput::Transform::Rotated270:
case DrmOutput::Transform::Flipped270:
return 270;
}
Q_UNREACHABLE();
return 0;
}
QMatrix4x4 DrmOutput::matrixDisplay(const QSize &s) const
{
QMatrix4x4 matrix;
const int angle = transformToRotation(transform());
const int angle = rotation();
if (angle) {
const QSize center = s / 2;
......@@ -680,11 +659,6 @@ bool DrmOutput::hardwareTransforms() const
return m_primaryPlane->transformation() == outputToPlaneTransform(transform());
}
int DrmOutput::rotation() const
{
return transformToRotation(transform());
}
void DrmOutput::updateTransform(Transform transform)
{
const auto planeTransform = outputToPlaneTransform(transform);
......
......@@ -92,13 +92,6 @@ public:
*/
bool hardwareTransforms() const;
/**
* The current rotation of the output
*
* @return rotation in degree
*/
int rotation() const;
private:
friend class DrmBackend;
friend class DrmCrtc; // TODO: For use of setModeLegacy. Remove later when we allow multiple connectors per crtc
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment