wayland: Introduce logicalToNativeMatrix() helper

The new helper function computes the projection matrix from the logical
coordinate space to the display coordinate space.
icc-effect-5.20.5
Vlad Zahorodnii 2020-10-13 23:57:15 +03:00
parent 642be48bd2
commit e9b751d2c1
5 changed files with 14 additions and 54 deletions

View File

@ -311,14 +311,12 @@ AbstractWaylandOutput::Transform AbstractWaylandOutput::transform() const
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;
matrix.scale(scale());
matrix.scale(scale);
switch (transform()) {
switch (transform) {
case Transform::Normal:
case Transform::Flipped:
break;
@ -339,7 +337,7 @@ QMatrix4x4 AbstractWaylandOutput::transformation() const
break;
}
switch (transform()) {
switch (transform) {
case Transform::Flipped:
case Transform::Flipped90:
case Transform::Flipped180:

View File

@ -115,7 +115,7 @@ public:
/**
* 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:
void modeChanged();

View File

@ -129,48 +129,6 @@ bool DrmOutput::showCursor()
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()
{
if (m_deleted) {
@ -186,15 +144,15 @@ void DrmOutput::updateCursor()
QPainter p;
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.end();
}
void DrmOutput::moveCursor(Cursor* cursor, const QPoint &globalPos)
{
const QMatrix4x4 hotspotMatrix = matrixForTransform(cursor->image().rect(), scale(), transform());
const QMatrix4x4 monitorMatrix = transformation();
const QMatrix4x4 hotspotMatrix = logicalToNativeMatrix(cursor->image().rect(), scale(), transform());
const QMatrix4x4 monitorMatrix = logicalToNativeMatrix(geometry(), scale(), transform());
QPoint pos = monitorMatrix.map(globalPos);
pos -= hotspotMatrix.map(cursor->hotspot());

View File

@ -450,7 +450,9 @@ static QVector<EGLint> regionToRects(const QRegion &region, AbstractWaylandOutpu
{
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;
rects.reserve(region.rectCount() * 4);

View File

@ -289,7 +289,9 @@ void EglWaylandBackend::present()
static QVector<EGLint> regionToRects(const QRegion &region, AbstractWaylandOutput *output)
{
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;
rects.reserve(region.rectCount() * 4);