[server] Don't emit unmapped if the Surface wasn't mapped

Summary:
If a Surface doesn't have a buffer attached and a null buffer gets
attached the buffer state doesn't really change. Thus neither the
unmapped signal nor the damaged signal should not be emitted.

Reviewers: #plasma

Subscribers: plasma-devel

Projects: #plasma

Differential Revision: https://phabricator.kde.org/D1261
This commit is contained in:
Martin Gräßlin 2016-03-30 10:16:39 +02:00
parent e616ade18e
commit 7053e4fce6
2 changed files with 31 additions and 1 deletions

View file

@ -53,6 +53,7 @@ private Q_SLOTS:
void testInput();
void testScale();
void testDestroy();
void testUnmapOfNotMappedSurface();
private:
KWayland::Server::Display *m_display;
@ -706,5 +707,30 @@ void TestWaylandSurface::testDestroy()
s->destroy();
}
void TestWaylandSurface::testUnmapOfNotMappedSurface()
{
// this test verifies that a surface which doesn't have a buffer attached doesn't trigger the unmapped signal
using namespace KWayland::Client;
using namespace KWayland::Server;
// create surface
QSignalSpy serverSurfaceCreated(m_compositorInterface, &CompositorInterface::surfaceCreated);
QVERIFY(serverSurfaceCreated.isValid());
QScopedPointer<Surface> s(m_compositor->createSurface());
QVERIFY(serverSurfaceCreated.wait());
SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value<KWayland::Server::SurfaceInterface*>();
QSignalSpy unmappedSpy(serverSurface, &SurfaceInterface::unmapped);
QVERIFY(unmappedSpy.isValid());
QSignalSpy scaleChanged(serverSurface, &SurfaceInterface::scaleChanged);
// let's map a null buffer and change scale to trigger a signal we can wait for
s->attachBuffer(Buffer::Ptr());
s->setScale(2);
s->commit(Surface::CommitFlag::None);
QVERIFY(scaleChanged.wait());
QVERIFY(unmappedSpy.isEmpty());
}
QTEST_GUILESS_MAIN(TestWaylandSurface)
#include "test_wayland_surface.moc"

View file

@ -238,7 +238,7 @@ void SurfaceInterface::Private::destroy()
void SurfaceInterface::Private::swapStates(State *source, State *target, bool emitChanged)
{
Q_Q(SurfaceInterface);
const bool bufferChanged = source->bufferIsSet;
bool bufferChanged = source->bufferIsSet;
const bool opaqueRegionChanged = source->opaqueIsSet;
const bool inputRegionChanged = source->inputIsSet;
const bool scaleFactorChanged = source->scaleIsSet && (target->scale != source->scale);
@ -271,6 +271,10 @@ void SurfaceInterface::Private::swapStates(State *source, State *target, bool em
const QSize newSize = source->buffer->size();
sizeChanged = newSize.isValid() && newSize != oldSize;
}
if (!target->buffer && !source->buffer && emitChanged) {
// null buffer set on a not mapped surface, don't emit unmapped
bufferChanged = false;
}
buffer = source->buffer;
}
// copy values