From 906661d40bdca048162b097b76bf197f82e6ce9f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 7 Feb 2024 17:41:07 -0500 Subject: [PATCH] gdk: Add some subsurface tests Test that the stacking order is properly maintained. --- testsuite/gdk/meson.build | 1 + testsuite/gdk/subsurface.c | 104 +++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 testsuite/gdk/subsurface.c diff --git a/testsuite/gdk/meson.build b/testsuite/gdk/meson.build index c410196a03..927d084ba4 100644 --- a/testsuite/gdk/meson.build +++ b/testsuite/gdk/meson.build @@ -60,6 +60,7 @@ internal_tests = [ { 'name': 'image' }, { 'name': 'texture' }, { 'name': 'gltexture' }, + { 'name': 'subsurface' }, ] if host_machine.system() != 'windows' diff --git a/testsuite/gdk/subsurface.c b/testsuite/gdk/subsurface.c new file mode 100644 index 0000000000..c38d99ecdd --- /dev/null +++ b/testsuite/gdk/subsurface.c @@ -0,0 +1,104 @@ +#include +#include "gdk/gdksurfaceprivate.h" +#include "gdk/gdksubsurfaceprivate.h" + +#ifdef GDK_WINDOWING_WAYLAND +#include "gdk/wayland/gdkwayland.h" +#endif + +static void +test_subsurface_stacking (void) +{ + GdkSurface *surface; + GdkSubsurface *sub0, *sub1, *sub2; + GdkTexture *texture; + +#ifdef GDK_WINDOWING_WAYLAND + if (!GDK_IS_WAYLAND_DISPLAY (gdk_display_get_default ())) +#endif + { + g_test_skip ("No subsurface support"); + return; + } + + surface = gdk_surface_new_toplevel (gdk_display_get_default ()); + + g_assert_true (surface->subsurfaces_below == NULL); + g_assert_true (surface->subsurfaces_above == NULL); + + sub0 = gdk_surface_create_subsurface (surface); + sub1 = gdk_surface_create_subsurface (surface); + sub2 = gdk_surface_create_subsurface (surface); + + g_assert_true (gdk_surface_get_n_subsurfaces (surface) == 3); + g_assert_true (gdk_surface_get_subsurface (surface, 0) == sub0); + g_assert_true (gdk_surface_get_subsurface (surface, 1) == sub1); + g_assert_true (gdk_surface_get_subsurface (surface, 2) == sub2); + + texture = gdk_texture_new_from_resource ("/org/gtk/libgtk/icons/16x16/actions/media-eject.png"); + + gdk_subsurface_attach (sub0, texture, &GRAPHENE_RECT_INIT (0, 0, 10, 10), TRUE, NULL); + gdk_subsurface_attach (sub1, texture, &GRAPHENE_RECT_INIT (0, 0, 10, 10), TRUE, NULL); + gdk_subsurface_attach (sub2, texture, &GRAPHENE_RECT_INIT (0, 0, 10, 10), TRUE, NULL); + + g_assert_true (surface->subsurfaces_above == sub2); + g_assert_true (sub2->sibling_below == NULL); + g_assert_true (sub2->sibling_above == sub1); + g_assert_true (sub2->above_parent); + g_assert_true (sub1->sibling_below == sub2); + g_assert_true (sub1->sibling_above == sub0); + g_assert_true (sub1->above_parent); + g_assert_true (sub0->sibling_below == sub1); + g_assert_true (sub0->sibling_above == NULL); + g_assert_true (sub0->above_parent); + + gdk_subsurface_detach (sub1); + + g_assert_true (surface->subsurfaces_above == sub2); + g_assert_true (sub2->sibling_below == NULL); + g_assert_true (sub2->sibling_above == sub0); + g_assert_true (sub2->above_parent); + g_assert_true (sub0->sibling_below == sub2); + g_assert_true (sub0->sibling_above == NULL); + g_assert_true (sub0->above_parent); + + gdk_subsurface_attach (sub2, texture, &GRAPHENE_RECT_INIT (0, 0, 10, 10), FALSE, NULL); + + g_assert_true (surface->subsurfaces_above == sub0); + g_assert_true (sub0->sibling_below == NULL); + g_assert_true (sub0->sibling_above == NULL); + g_assert_true (sub0->above_parent); + + g_assert_true (surface->subsurfaces_below == sub2); + g_assert_true (sub2->sibling_below == NULL); + g_assert_true (sub2->sibling_above == NULL); + g_assert_false (sub2->above_parent); + + gdk_subsurface_attach (sub1, texture, &GRAPHENE_RECT_INIT (0, 0, 10, 10), TRUE, sub2); + + g_assert_true (surface->subsurfaces_below == sub1); + g_assert_true (sub1->sibling_above == NULL); + g_assert_true (sub1->sibling_below == sub2); + g_assert_false (sub1->above_parent); + g_assert_true (sub2->sibling_above == sub1); + g_assert_true (sub2->sibling_below == NULL); + g_assert_false (sub2->above_parent); + + g_object_unref (sub0); + g_object_unref (sub1); + g_object_unref (sub2); + + g_object_unref (texture); + + gdk_surface_destroy (surface); +} + +int +main (int argc, char *argv[]) +{ + gtk_test_init (&argc, &argv, NULL); + + g_test_add_func ("/subsurface/stacking", test_subsurface_stacking); + + return g_test_run (); +}