Commit 7eccfdc5 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

wayland: Introduce logicalToNativeMatrix() helper

The new helper function computes the projection matrix from the logical
coordinate space to the display coordinate space.
parent f1741317
...@@ -311,14 +311,12 @@ AbstractWaylandOutput::Transform AbstractWaylandOutput::transform() const ...@@ -311,14 +311,12 @@ AbstractWaylandOutput::Transform AbstractWaylandOutput::transform() const
return static_cast<Transform>(m_waylandOutputDevice->transform()); return static_cast<Transform>(m_waylandOutputDevice->transform());
} }
QMatrix4x4 AbstractWaylandOutput::transformation() const QMatrix4x4 AbstractWaylandOutput::logicalToNativeMatrix(const QRect &rect, qreal scale, Transform transform)
{ {
const QRect rect = geometry();
QMatrix4x4 matrix; QMatrix4x4 matrix;
matrix.scale(scale()); matrix.scale(scale);
switch (transform()) { switch (transform) {
case Transform::Normal: case Transform::Normal:
case Transform::Flipped: case Transform::Flipped:
break; break;
...@@ -339,7 +337,7 @@ QMatrix4x4 AbstractWaylandOutput::transformation() const ...@@ -339,7 +337,7 @@ QMatrix4x4 AbstractWaylandOutput::transformation() const
break; break;
} }
switch (transform()) { switch (transform) {
case Transform::Flipped: case Transform::Flipped:
case Transform::Flipped90: case Transform::Flipped90:
case Transform::Flipped180: case Transform::Flipped180:
......
...@@ -115,7 +115,7 @@ public: ...@@ -115,7 +115,7 @@ public:
/** /**
* Returns a matrix that can translate into the display's coordinates system * Returns a matrix that can translate into the display's coordinates system
*/ */
QMatrix4x4 transformation() const; static QMatrix4x4 logicalToNativeMatrix(const QRect &rect, qreal scale, Transform transform);
Q_SIGNALS: Q_SIGNALS:
void modeChanged(); void modeChanged();
......
...@@ -133,48 +133,6 @@ bool DrmOutput::showCursor() ...@@ -133,48 +133,6 @@ bool DrmOutput::showCursor()
return ret; return ret;
} }
static QMatrix4x4 matrixForTransform(const QRectF &rect, qreal scale, DrmOutput::Transform transform)
{
QMatrix4x4 matrix;
matrix.scale(scale);
switch (transform) {
case DrmOutput::Transform::Normal:
case DrmOutput::Transform::Flipped:
break;
case DrmOutput::Transform::Rotated90:
case DrmOutput::Transform::Flipped90:
matrix.translate(0, rect.width());
matrix.rotate(-90, 0, 0, 1);
break;
case DrmOutput::Transform::Rotated180:
case DrmOutput::Transform::Flipped180:
matrix.translate(rect.width(), rect.height());
matrix.rotate(-180, 0, 0, 1);
break;
case DrmOutput::Transform::Rotated270:
case DrmOutput::Transform::Flipped270:
matrix.translate(rect.height(), 0);
matrix.rotate(-270, 0, 0, 1);
break;
}
switch (transform) {
case DrmOutput::Transform::Flipped:
case DrmOutput::Transform::Flipped180:
case DrmOutput::Transform::Flipped90:
case DrmOutput::Transform::Flipped270:
matrix.translate(rect.width(), 0);
matrix.scale(-1, 1);
break;
default:
break;
}
return matrix;
}
void DrmOutput::updateCursor() void DrmOutput::updateCursor()
{ {
if (m_deleted) { if (m_deleted) {
...@@ -190,15 +148,15 @@ void DrmOutput::updateCursor() ...@@ -190,15 +148,15 @@ void DrmOutput::updateCursor()
QPainter p; QPainter p;
p.begin(c); p.begin(c);
p.setWorldTransform(matrixForTransform(cursorImage.rect(), scale(), transform()).toTransform()); p.setWorldTransform(logicalToNativeMatrix(cursorImage.rect(), scale(), transform()).toTransform());
p.drawImage(QPoint(0, 0), cursorImage); p.drawImage(QPoint(0, 0), cursorImage);
p.end(); p.end();
} }
void DrmOutput::moveCursor(Cursor *cursor, const QPoint &globalPos) void DrmOutput::moveCursor(Cursor *cursor, const QPoint &globalPos)
{ {
const QMatrix4x4 hotspotMatrix = matrixForTransform(cursor->image().rect(), scale(), transform()); const QMatrix4x4 hotspotMatrix = logicalToNativeMatrix(cursor->image().rect(), scale(), transform());
const QMatrix4x4 monitorMatrix = transformation(); const QMatrix4x4 monitorMatrix = logicalToNativeMatrix(geometry(), scale(), transform());
QPoint pos = monitorMatrix.map(globalPos); QPoint pos = monitorMatrix.map(globalPos);
pos -= hotspotMatrix.map(cursor->hotspot()); pos -= hotspotMatrix.map(cursor->hotspot());
......
...@@ -448,7 +448,9 @@ static QVector<EGLint> regionToRects(const QRegion &region, AbstractWaylandOutpu ...@@ -448,7 +448,9 @@ static QVector<EGLint> regionToRects(const QRegion &region, AbstractWaylandOutpu
{ {
const int height = output->modeSize().height(); const int height = output->modeSize().height();
const QMatrix4x4 matrix = output->transformation(); const QMatrix4x4 matrix = DrmOutput::logicalToNativeMatrix(output->geometry(),
output->scale(),
output->transform());
QVector<EGLint> rects; QVector<EGLint> rects;
rects.reserve(region.rectCount() * 4); rects.reserve(region.rectCount() * 4);
......
...@@ -289,7 +289,9 @@ void EglWaylandBackend::present() ...@@ -289,7 +289,9 @@ void EglWaylandBackend::present()
static QVector<EGLint> regionToRects(const QRegion &region, AbstractWaylandOutput *output) static QVector<EGLint> regionToRects(const QRegion &region, AbstractWaylandOutput *output)
{ {
const int height = output->modeSize().height(); const int height = output->modeSize().height();
const QMatrix4x4 matrix = output->transformation(); const QMatrix4x4 matrix = WaylandOutput::logicalToNativeMatrix(output->geometry(),
output->scale(),
output->transform());
QVector<EGLint> rects; QVector<EGLint> rects;
rects.reserve(region.rectCount() * 4); rects.reserve(region.rectCount() * 4);
......
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