From 7053e4fce665ad139ae88d48a5aab54eb85b6dbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 30 Mar 2016 10:16:39 +0200 Subject: [PATCH] [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 --- .../autotests/client/test_wayland_surface.cpp | 26 +++++++++++++++++++ src/wayland/surface_interface.cpp | 6 ++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/wayland/autotests/client/test_wayland_surface.cpp b/src/wayland/autotests/client/test_wayland_surface.cpp index 1860f45179..a808272cbe 100644 --- a/src/wayland/autotests/client/test_wayland_surface.cpp +++ b/src/wayland/autotests/client/test_wayland_surface.cpp @@ -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 s(m_compositor->createSurface()); + QVERIFY(serverSurfaceCreated.wait()); + SurfaceInterface *serverSurface = serverSurfaceCreated.first().first().value(); + + 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" diff --git a/src/wayland/surface_interface.cpp b/src/wayland/surface_interface.cpp index bc34af6bba..56fc18fe72 100644 --- a/src/wayland/surface_interface.cpp +++ b/src/wayland/surface_interface.cpp @@ -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