Changeset View
Changeset View
Standalone View
Standalone View
autotests/client/test_wayland_subsurface.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 44 | private Q_SLOTS: | |||
---|---|---|---|---|---|
51 | void testPlaceAbove(); | 51 | void testPlaceAbove(); | ||
52 | void testPlaceBelow(); | 52 | void testPlaceBelow(); | ||
53 | void testDestroy(); | 53 | void testDestroy(); | ||
54 | void testCast(); | 54 | void testCast(); | ||
55 | void testSyncMode(); | 55 | void testSyncMode(); | ||
56 | void testDeSyncMode(); | 56 | void testDeSyncMode(); | ||
57 | void testMainSurfaceFromTree(); | 57 | void testMainSurfaceFromTree(); | ||
58 | void testRemoveSurface(); | 58 | void testRemoveSurface(); | ||
59 | void testMappingOfSurfaceTree(); | ||||
59 | 60 | | |||
60 | private: | 61 | private: | ||
61 | KWayland::Server::Display *m_display; | 62 | KWayland::Server::Display *m_display; | ||
62 | KWayland::Server::CompositorInterface *m_compositorInterface; | 63 | KWayland::Server::CompositorInterface *m_compositorInterface; | ||
63 | KWayland::Server::SubCompositorInterface *m_subcompositorInterface; | 64 | KWayland::Server::SubCompositorInterface *m_subcompositorInterface; | ||
64 | KWayland::Client::ConnectionThread *m_connection; | 65 | KWayland::Client::ConnectionThread *m_connection; | ||
65 | KWayland::Client::Compositor *m_compositor; | 66 | KWayland::Client::Compositor *m_compositor; | ||
66 | KWayland::Client::ShmPool *m_shm; | 67 | KWayland::Client::ShmPool *m_shm; | ||
▲ Show 20 Lines • Show All 719 Lines • ▼ Show 20 Line(s) | 763 | { | |||
786 | QCOMPARE(parentServerSurface->childSubSurfaces().count(), 1); | 787 | QCOMPARE(parentServerSurface->childSubSurfaces().count(), 1); | ||
787 | 788 | | |||
788 | // destroy surface, takes place immediately | 789 | // destroy surface, takes place immediately | ||
789 | childSurface.reset(); | 790 | childSurface.reset(); | ||
790 | QVERIFY(subSurfaceTreeChangedSpy.wait()); | 791 | QVERIFY(subSurfaceTreeChangedSpy.wait()); | ||
791 | QCOMPARE(parentServerSurface->childSubSurfaces().count(), 0); | 792 | QCOMPARE(parentServerSurface->childSubSurfaces().count(), 0); | ||
792 | } | 793 | } | ||
793 | 794 | | |||
795 | void TestSubSurface::testMappingOfSurfaceTree() | ||||
796 | { | ||||
797 | // this test verifies mapping and unmapping of a sub-surface tree | ||||
798 | using namespace KWayland::Client; | ||||
799 | using namespace KWayland::Server; | ||||
800 | QSignalSpy surfaceCreatedSpy(m_compositorInterface, &CompositorInterface::surfaceCreated); | ||||
801 | QVERIFY(surfaceCreatedSpy.isValid()); | ||||
802 | | ||||
803 | QScopedPointer<Surface> parentSurface(m_compositor->createSurface()); | ||||
804 | QVERIFY(surfaceCreatedSpy.wait()); | ||||
805 | auto parentServerSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface*>(); | ||||
806 | QVERIFY(parentServerSurface); | ||||
807 | QScopedPointer<Surface> childLevel1Surface(m_compositor->createSurface()); | ||||
808 | QVERIFY(surfaceCreatedSpy.wait()); | ||||
809 | auto childLevel1ServerSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface*>(); | ||||
810 | QVERIFY(childLevel1ServerSurface); | ||||
811 | QScopedPointer<Surface> childLevel2Surface(m_compositor->createSurface()); | ||||
812 | QVERIFY(surfaceCreatedSpy.wait()); | ||||
813 | auto childLevel2ServerSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface*>(); | ||||
814 | QVERIFY(childLevel2ServerSurface); | ||||
815 | QScopedPointer<Surface> childLevel3Surface(m_compositor->createSurface()); | ||||
816 | QVERIFY(surfaceCreatedSpy.wait()); | ||||
817 | auto childLevel3ServerSurface = surfaceCreatedSpy.last().first().value<SurfaceInterface*>(); | ||||
818 | QVERIFY(childLevel3ServerSurface); | ||||
819 | | ||||
820 | QSignalSpy subSurfaceTreeChangedSpy(parentServerSurface, &SurfaceInterface::subSurfaceTreeChanged); | ||||
821 | QVERIFY(subSurfaceTreeChangedSpy.isValid()); | ||||
822 | | ||||
823 | auto subSurfaceLevel1 = m_subCompositor->createSubSurface(childLevel1Surface.data(), parentSurface.data()); | ||||
824 | auto subSurfaceLevel2 = m_subCompositor->createSubSurface(childLevel2Surface.data(), childLevel1Surface.data()); | ||||
825 | auto subSurfaceLevel3 = m_subCompositor->createSubSurface(childLevel3Surface.data(), childLevel2Surface.data()); | ||||
826 | | ||||
827 | parentSurface->commit(Surface::CommitFlag::None); | ||||
828 | QVERIFY(subSurfaceTreeChangedSpy.wait()); | ||||
829 | | ||||
830 | QCOMPARE(parentServerSurface->childSubSurfaces().count(), 1); | ||||
831 | auto child = parentServerSurface->childSubSurfaces().first(); | ||||
832 | QCOMPARE(child->surface()->childSubSurfaces().count(), 1); | ||||
833 | auto child2 = child->surface()->childSubSurfaces().first(); | ||||
834 | QCOMPARE(child2->surface()->childSubSurfaces().count(), 1); | ||||
835 | auto child3 = child2->surface()->childSubSurfaces().first(); | ||||
836 | QCOMPARE(child3->parentSurface().data(), child2->surface().data()); | ||||
837 | QCOMPARE(child3->mainSurface().data(), parentServerSurface); | ||||
838 | QCOMPARE(child3->surface()->childSubSurfaces().count(), 0); | ||||
839 | | ||||
840 | // so far no surface is mapped | ||||
841 | QVERIFY(!parentServerSurface->isMapped()); | ||||
842 | QVERIFY(!child->surface()->isMapped()); | ||||
843 | QVERIFY(!child2->surface()->isMapped()); | ||||
844 | QVERIFY(!child3->surface()->isMapped()); | ||||
845 | | ||||
846 | // first set all subsurfaces to desync, to simplify | ||||
847 | subSurfaceLevel1->setMode(SubSurface::Mode::Desynchronized); | ||||
848 | subSurfaceLevel2->setMode(SubSurface::Mode::Desynchronized); | ||||
849 | subSurfaceLevel3->setMode(SubSurface::Mode::Desynchronized); | ||||
850 | | ||||
851 | // first map the child, should not map it | ||||
852 | QSignalSpy child3DamageSpy(child3->surface().data(), &SurfaceInterface::damaged); | ||||
853 | QVERIFY(child3DamageSpy.isValid()); | ||||
854 | QImage image(QSize(200, 200), QImage::Format_ARGB32); | ||||
855 | image.fill(Qt::black); | ||||
856 | childLevel3Surface->attachBuffer(m_shm->createBuffer(image)); | ||||
857 | childLevel3Surface->damage(QRect(0, 0, 200, 200)); | ||||
858 | childLevel3Surface->commit(Surface::CommitFlag::None); | ||||
859 | QVERIFY(child3DamageSpy.wait()); | ||||
860 | QVERIFY(child3->surface()->buffer()); | ||||
861 | QVERIFY(!child3->surface()->isMapped()); | ||||
862 | | ||||
863 | // let's map the top level | ||||
864 | QSignalSpy parentSpy(parentServerSurface, &SurfaceInterface::damaged); | ||||
865 | QVERIFY(parentSpy.isValid()); | ||||
866 | parentSurface->attachBuffer(m_shm->createBuffer(image)); | ||||
867 | parentSurface->damage(QRect(0, 0, 200, 200)); | ||||
868 | parentSurface->commit(Surface::CommitFlag::None); | ||||
869 | QVERIFY(parentSpy.wait()); | ||||
870 | QVERIFY(parentServerSurface->isMapped()); | ||||
871 | // children should not yet be mapped | ||||
872 | QVERIFY(!child->surface()->isMapped()); | ||||
873 | QVERIFY(!child2->surface()->isMapped()); | ||||
874 | QVERIFY(!child3->surface()->isMapped()); | ||||
875 | | ||||
876 | // next level | ||||
877 | QSignalSpy child2DamageSpy(child2->surface().data(), &SurfaceInterface::damaged); | ||||
878 | QVERIFY(child2DamageSpy.isValid()); | ||||
879 | childLevel2Surface->attachBuffer(m_shm->createBuffer(image)); | ||||
880 | childLevel2Surface->damage(QRect(0, 0, 200, 200)); | ||||
881 | childLevel2Surface->commit(Surface::CommitFlag::None); | ||||
882 | QVERIFY(child2DamageSpy.wait()); | ||||
883 | QVERIFY(parentServerSurface->isMapped()); | ||||
884 | // children should not yet be mapped | ||||
885 | QVERIFY(!child->surface()->isMapped()); | ||||
886 | QVERIFY(!child2->surface()->isMapped()); | ||||
887 | QVERIFY(!child3->surface()->isMapped()); | ||||
888 | | ||||
889 | // last but not least the first child level, which should map all our subsurfaces | ||||
890 | QSignalSpy child1DamageSpy(child->surface().data(), &SurfaceInterface::damaged); | ||||
891 | QVERIFY(child1DamageSpy.isValid()); | ||||
892 | childLevel1Surface->attachBuffer(m_shm->createBuffer(image)); | ||||
893 | childLevel1Surface->damage(QRect(0, 0, 200, 200)); | ||||
894 | childLevel1Surface->commit(Surface::CommitFlag::None); | ||||
895 | QVERIFY(child1DamageSpy.wait()); | ||||
896 | | ||||
897 | // everything is mapped | ||||
898 | QVERIFY(parentServerSurface->isMapped()); | ||||
899 | QVERIFY(child->surface()->isMapped()); | ||||
900 | QVERIFY(child2->surface()->isMapped()); | ||||
901 | QVERIFY(child3->surface()->isMapped()); | ||||
902 | | ||||
903 | // unmapping a parent should unmap the complete tree | ||||
904 | QSignalSpy unmappedSpy(child->surface().data(), &SurfaceInterface::unmapped); | ||||
905 | QVERIFY(unmappedSpy.isValid()); | ||||
906 | childLevel1Surface->attachBuffer(Buffer::Ptr()); | ||||
907 | childLevel1Surface->damage(QRect(0, 0, 200, 200)); | ||||
908 | childLevel1Surface->commit(Surface::CommitFlag::None); | ||||
909 | QVERIFY(unmappedSpy.wait()); | ||||
910 | | ||||
911 | QVERIFY(parentServerSurface->isMapped()); | ||||
912 | QVERIFY(!child->surface()->isMapped()); | ||||
913 | QVERIFY(!child2->surface()->isMapped()); | ||||
914 | QVERIFY(!child3->surface()->isMapped()); | ||||
915 | } | ||||
916 | | ||||
794 | QTEST_GUILESS_MAIN(TestSubSurface) | 917 | QTEST_GUILESS_MAIN(TestSubSurface) | ||
795 | #include "test_wayland_subsurface.moc" | 918 | #include "test_wayland_subsurface.moc" |