Commit 49cbe7b2 authored by David Edmundson's avatar David Edmundson

Return SurfaceInterface::size in global compositor space

REVIEW: 129358
parent 3ab5d134
......@@ -671,6 +671,10 @@ void TestWaylandSurface::testScale()
// let's change the scale factor
QSignalSpy scaleChangedSpy(serverSurface, &SurfaceInterface::scaleChanged);
//changing the scale implicitly changes the size
QSignalSpy sizeChangedSpy(serverSurface, &SurfaceInterface::sizeChanged);
QVERIFY(scaleChangedSpy.isValid());
s->setScale(2);
QCOMPARE(s->scale(), 2);
......@@ -682,6 +686,11 @@ void TestWaylandSurface::testScale()
QCOMPARE(scaleChangedSpy.first().first().toInt(), 2);
QCOMPARE(serverSurface->scale(), 2);
//even though we've changed the scale, if we don't have a buffer we
//don't have a size. If we don't have a size it can't have changed
QCOMPARE(sizeChangedSpy.count(), 0);
QVERIFY(!serverSurface->size().isValid());
// let's try changing to same factor, should not emit changed on server
s->setScale(2);
s->commit(Surface::CommitFlag::None);
......@@ -695,6 +704,44 @@ void TestWaylandSurface::testScale()
QCOMPARE(scaleChangedSpy.first().first().toInt(), 2);
QCOMPARE(scaleChangedSpy.last().first().toInt(), 4);
QCOMPARE(serverSurface->scale(), 4);
scaleChangedSpy.clear();
//attach a buffer of 100x100, our scale is 4, so this should be a size of 25x25
QImage red(100, 100, QImage::Format_ARGB32);
red.fill(QColor(255, 0, 0, 128));
auto redBuffer = m_shm->createBuffer(red);
s->attachBuffer(redBuffer.data());
s->damage(QRect(0,0, 25,25));
s->commit(Surface::CommitFlag::None);
QVERIFY(sizeChangedSpy.wait());
QCOMPARE(sizeChangedSpy.count(), 1);
QCOMPARE(serverSurface->size(), QSize(25,25));
sizeChangedSpy.clear();
scaleChangedSpy.clear();
//set the scale to 1, buffer is still 100x100 so size should change to 100x100
s->setScale(1);
s->commit(Surface::CommitFlag::None);
QVERIFY(sizeChangedSpy.wait());
QCOMPARE(sizeChangedSpy.count(), 1);
QCOMPARE(scaleChangedSpy.count(), 1);
QCOMPARE(serverSurface->scale(), 1);
QCOMPARE(serverSurface->size(), QSize(100,100));
sizeChangedSpy.clear();
scaleChangedSpy.clear();
//set scale and size in one commit, buffer is 50x50 at scale 2 so size should be 25x25
QImage blue(50, 50, QImage::Format_ARGB32);
red.fill(QColor(255, 0, 0, 128));
auto blueBuffer = m_shm->createBuffer(blue);
s->attachBuffer(blueBuffer.data());
s->setScale(2);
s->commit(Surface::CommitFlag::None);
QVERIFY(sizeChangedSpy.wait());
QCOMPARE(sizeChangedSpy.count(), 1);
QCOMPARE(scaleChangedSpy.count(), 1);
QCOMPARE(serverSurface->scale(), 2);
QCOMPARE(serverSurface->size(), QSize(25,25));
}
void TestWaylandSurface::testDestroy()
......
......@@ -335,6 +335,9 @@ void SurfaceInterface::Private::swapStates(State *source, State *target, bool em
}
if (scaleFactorChanged) {
emit q->scaleChanged(target->scale);
if (buffer && !sizeChanged) {
emit q->sizeChanged();
}
}
if (transformChanged) {
emit q->transformChanged(target->transform);
......@@ -634,9 +637,9 @@ QPointer< SubSurfaceInterface > SurfaceInterface::subSurface() const
QSize SurfaceInterface::size() const
{
Q_D();
// TODO: apply transform and scale to the buffer size
// TODO: apply transform to the buffer size
if (d->current.buffer) {
return d->current.buffer->size();
return d->current.buffer->size() / scale();
}
return QSize();
}
......
......@@ -114,7 +114,9 @@ public:
BufferInterface *buffer();
QPoint offset() const;
/**
* The size of the Surface.
* The size of the Surface in global compositor space.
* @see For buffer size use BufferInterface::size
* from SurfaceInterface::buffer
* @since 5.3
**/
QSize size() const;
......
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