From 14bb104ef0f5bc276ce108668cf5259ccd87d859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Tue, 12 Nov 2019 18:37:05 +0100 Subject: [PATCH] tests/clutter: Replace ClutterTexture from image with custom helper ClutterTexture is deprecated, lets remove the trivial usage with a simple gdk-pixbuf using constructor putting pixel contents into a ClutterImage then putting said image in a plain ClutterActor. Tested partially, as the interactive tests cannot be properly run at the moment. https://gitlab.gnome.org/GNOME/mutter/merge_requests/932 --- src/tests/clutter/interactive/meson.build | 1 + src/tests/clutter/interactive/test-actors.c | 4 ++- src/tests/clutter/interactive/test-devices.c | 18 ++++++----- src/tests/clutter/interactive/test-layout.c | 9 +++--- .../clutter/interactive/test-paint-wrapper.c | 10 ++++--- .../clutter/interactive/test-shader-effects.c | 3 +- src/tests/clutter/interactive/test-state.c | 3 +- .../clutter/interactive/test-table-layout.c | 3 +- src/tests/clutter/meson.build | 2 ++ src/tests/clutter/performance/meson.build | 5 +++- .../performance/test-state-interactive.c | 3 +- .../clutter/performance/test-state-mini.c | 3 +- .../clutter/performance/test-state-pick.c | 3 +- src/tests/clutter/performance/test-state.c | 3 +- src/tests/clutter/test-utils.h | 30 +++++++++++++++++++ 15 files changed, 75 insertions(+), 25 deletions(-) create mode 100644 src/tests/clutter/test-utils.h diff --git a/src/tests/clutter/interactive/meson.build b/src/tests/clutter/interactive/meson.build index 4d8d07b02..d09045b0d 100644 --- a/src/tests/clutter/interactive/meson.build +++ b/src/tests/clutter/interactive/meson.build @@ -76,6 +76,7 @@ executable('test-interactive', sources: clutter_tests_interactive_sources, include_directories: [ clutter_includes, + clutter_tests_includepath, clutter_tests_interactive_includepath, ], c_args: clutter_tests_interactive_c_args, diff --git a/src/tests/clutter/interactive/test-actors.c b/src/tests/clutter/interactive/test-actors.c index 4bb0b8636..20edc8517 100644 --- a/src/tests/clutter/interactive/test-actors.c +++ b/src/tests/clutter/interactive/test-actors.c @@ -6,6 +6,8 @@ #include #include +#include "test-utils.h" + #define NHANDS 6 typedef struct SuperOH @@ -195,7 +197,7 @@ test_actors_main (int argc, char *argv[]) g_signal_connect (oh->timeline, "new-frame", G_CALLBACK (frame_cb), oh); file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); - real_hand = clutter_texture_new_from_file (file, &error); + real_hand = clutter_test_utils_create_texture_from_file (file, &error); if (real_hand == NULL) g_error ("image load failed: %s", error->message); diff --git a/src/tests/clutter/interactive/test-devices.c b/src/tests/clutter/interactive/test-devices.c index c9644eb25..28e978992 100644 --- a/src/tests/clutter/interactive/test-devices.c +++ b/src/tests/clutter/interactive/test-devices.c @@ -6,6 +6,8 @@ #include #endif +#include "test-utils.h" + typedef struct { ClutterActor *stage; @@ -172,10 +174,10 @@ manager_device_added_cb (ClutterDeviceManager *manager, clutter_input_device_set_enabled (device, TRUE); - hand = clutter_texture_new_from_file (TESTS_DATADIR - G_DIR_SEPARATOR_S - "redhand.png", - NULL); + hand = clutter_test_utils_create_texture_from_file (TESTS_DATADIR + G_DIR_SEPARATOR_S + "redhand.png", + NULL); g_hash_table_insert (app->devices, device, hand); clutter_container_add_actor (CLUTTER_CONTAINER (app->stage), hand); @@ -273,10 +275,10 @@ test_devices_main (int argc, char **argv) clutter_input_device_set_enabled (device, TRUE); - hand = clutter_texture_new_from_file (TESTS_DATADIR - G_DIR_SEPARATOR_S - "redhand.png", - NULL); + hand = clutter_test_utils_create_texture_from_file (TESTS_DATADIR + G_DIR_SEPARATOR_S + "redhand.png", + NULL); g_hash_table_insert (app->devices, device, hand); clutter_container_add_actor (CLUTTER_CONTAINER (stage), hand); diff --git a/src/tests/clutter/interactive/test-layout.c b/src/tests/clutter/interactive/test-layout.c index 4c73c0de2..9666f15df 100644 --- a/src/tests/clutter/interactive/test-layout.c +++ b/src/tests/clutter/interactive/test-layout.c @@ -5,6 +5,7 @@ #include #include +#include "test-utils.h" /* layout actor, by Lucas Rocha */ @@ -629,10 +630,10 @@ test_layout_main (int argc, char *argv[]) clutter_actor_set_position (box, 20, 20); clutter_actor_set_size (box, 350, -1); - icon = clutter_texture_new_from_file (TESTS_DATADIR - G_DIR_SEPARATOR_S - "redhand.png", - &error); + icon = clutter_test_utils_create_texture_from_file (TESTS_DATADIR + G_DIR_SEPARATOR_S + "redhand.png", + &error); if (error) g_error ("Unable to load 'redhand.png': %s", error->message); diff --git a/src/tests/clutter/interactive/test-paint-wrapper.c b/src/tests/clutter/interactive/test-paint-wrapper.c index 0c64ce6fc..ccf199fb7 100644 --- a/src/tests/clutter/interactive/test-paint-wrapper.c +++ b/src/tests/clutter/interactive/test-paint-wrapper.c @@ -15,6 +15,8 @@ #include "clutter/x11/clutter-x11.h" #endif +#include "test-utils.h" + #define NHANDS 6 typedef struct SuperOH @@ -247,10 +249,10 @@ test_paint_wrapper_main (int argc, char *argv[]) oh->frame_id = g_signal_connect (oh->timeline, "new-frame", G_CALLBACK (frame_cb), oh); - real_hand = clutter_texture_new_from_file (TESTS_DATADIR - G_DIR_SEPARATOR_S - "redhand.png", - &error); + real_hand = clutter_test_utils_create_texture_from_file (TESTS_DATADIR + G_DIR_SEPARATOR_S + "redhand.png", + &error); if (real_hand == NULL) { g_error ("image load failed: %s", error->message); diff --git a/src/tests/clutter/interactive/test-shader-effects.c b/src/tests/clutter/interactive/test-shader-effects.c index a64a0ba29..1fb7cefda 100644 --- a/src/tests/clutter/interactive/test-shader-effects.c +++ b/src/tests/clutter/interactive/test-shader-effects.c @@ -6,6 +6,7 @@ #include #include +#include "test-utils.h" int test_shader_effects_main (int argc, char *argv[]); @@ -31,7 +32,7 @@ test_shader_effects_main (int argc, char *argv[]) /* Make a hand */ file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); - hand = clutter_texture_new_from_file (file, NULL); + hand = clutter_test_utils_create_texture_from_file (file, NULL); if (!hand) g_error("Unable to load '%s'", file); diff --git a/src/tests/clutter/interactive/test-state.c b/src/tests/clutter/interactive/test-state.c index b6894eac5..799ec980d 100644 --- a/src/tests/clutter/interactive/test-state.c +++ b/src/tests/clutter/interactive/test-state.c @@ -2,6 +2,7 @@ #include #include #include +#include "test-utils.h" #define STAGE_WIDTH 1024 #define STAGE_HEIGHT 768 @@ -82,7 +83,7 @@ static ClutterActor *new_rect (gint r, gchar *file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); - hand = clutter_texture_new_from_file (file, &error); + hand = clutter_test_utils_create_texture_from_file (file, &error); if (rectangle == NULL) g_error ("image load failed: %s", error->message); g_free (file); diff --git a/src/tests/clutter/interactive/test-table-layout.c b/src/tests/clutter/interactive/test-table-layout.c index 355944b06..4a8bbcac8 100644 --- a/src/tests/clutter/interactive/test-table-layout.c +++ b/src/tests/clutter/interactive/test-table-layout.c @@ -6,6 +6,7 @@ #include #include #include +#include "test-utils.h" #define FONT "Sans 12" @@ -155,7 +156,7 @@ create_image (const gchar *file, const gchar *color) ClutterActor *texture; ClutterActor *result; - texture = clutter_texture_new_from_file (file, NULL); + texture = clutter_test_utils_create_texture_from_file (file, NULL); g_object_set (G_OBJECT (texture), "keep-aspect-ratio", TRUE, NULL); clutter_actor_show (texture); diff --git a/src/tests/clutter/meson.build b/src/tests/clutter/meson.build index 125d81e97..e09b7f94e 100644 --- a/src/tests/clutter/meson.build +++ b/src/tests/clutter/meson.build @@ -1,3 +1,5 @@ +clutter_tests_includepath = include_directories('.') + subdir('accessibility') subdir('conform') subdir('interactive') diff --git a/src/tests/clutter/performance/meson.build b/src/tests/clutter/performance/meson.build index 1a6009bd4..ee092bb04 100644 --- a/src/tests/clutter/performance/meson.build +++ b/src/tests/clutter/performance/meson.build @@ -24,7 +24,10 @@ foreach test : clutter_tests_performance_tests '@0@.c'.format(test), 'test-common.h', ], - include_directories: clutter_includes, + include_directories: [ + clutter_includes, + clutter_tests_includepath, + ], c_args: clutter_tests_performance_c_args, dependencies: [ clutter_deps, diff --git a/src/tests/clutter/performance/test-state-interactive.c b/src/tests/clutter/performance/test-state-interactive.c index 375783541..e0cfe0671 100644 --- a/src/tests/clutter/performance/test-state-interactive.c +++ b/src/tests/clutter/performance/test-state-interactive.c @@ -3,6 +3,7 @@ #include #include #include "test-common.h" +#include "test-utils.h" #define STAGE_WIDTH 800 #define STAGE_HEIGHT 600 @@ -77,7 +78,7 @@ static ClutterActor *new_rect (gint r, gchar *file = g_build_filename (TESTS_DATA_DIR, "redhand.png", NULL); - hand = clutter_texture_new_from_file (file, &error); + hand = clutter_test_utils_create_texture_from_file (file, &error); if (rectangle == NULL) g_error ("image load failed: %s", error->message); g_free (file); diff --git a/src/tests/clutter/performance/test-state-mini.c b/src/tests/clutter/performance/test-state-mini.c index 773b9d061..5bd8fb282 100644 --- a/src/tests/clutter/performance/test-state-mini.c +++ b/src/tests/clutter/performance/test-state-mini.c @@ -3,6 +3,7 @@ #include #include #include "test-common.h" +#include "test-utils.h" #define STAGE_WIDTH 160 #define STAGE_HEIGHT 120 @@ -44,7 +45,7 @@ static ClutterActor *new_rect (gint r, gchar *file = g_build_filename (TESTS_DATA_DIR, "redhand.png", NULL); - hand = clutter_texture_new_from_file (file, &error); + hand = clutter_test_utils_create_texture_from_file (file, &error); if (rectangle == NULL) g_error ("image load failed: %s", error->message); g_free (file); diff --git a/src/tests/clutter/performance/test-state-pick.c b/src/tests/clutter/performance/test-state-pick.c index 0dc450a64..bf0d68c2b 100644 --- a/src/tests/clutter/performance/test-state-pick.c +++ b/src/tests/clutter/performance/test-state-pick.c @@ -3,6 +3,7 @@ #include #include #include "test-common.h" +#include "test-utils.h" static gint times = 16; @@ -49,7 +50,7 @@ static ClutterActor *new_rect (gint r, gchar *file = g_build_filename (TESTS_DATA_DIR, "redhand.png", NULL); - hand = clutter_texture_new_from_file (file, &error); + hand = clutter_test_utils_create_texture_from_file (file, &error); if (rectangle == NULL) g_error ("image load failed: %s", error->message); g_free (file); diff --git a/src/tests/clutter/performance/test-state.c b/src/tests/clutter/performance/test-state.c index 7b0778cb4..7a6303b58 100644 --- a/src/tests/clutter/performance/test-state.c +++ b/src/tests/clutter/performance/test-state.c @@ -3,6 +3,7 @@ #include #include #include "test-common.h" +#include "test-utils.h" static gint times = 16; @@ -49,7 +50,7 @@ static ClutterActor *new_rect (gint r, gchar *file = g_build_filename (TESTS_DATA_DIR, "redhand.png", NULL); - hand = clutter_texture_new_from_file (file, &error); + hand = clutter_test_utils_create_texture_from_file (file, &error); if (rectangle == NULL) g_error ("image load failed: %s", error->message); g_free (file); diff --git a/src/tests/clutter/test-utils.h b/src/tests/clutter/test-utils.h new file mode 100644 index 000000000..6ed1a938b --- /dev/null +++ b/src/tests/clutter/test-utils.h @@ -0,0 +1,30 @@ +#include +#include + +static inline ClutterActor * +clutter_test_utils_create_texture_from_file (const char *filename, + GError **error) +{ + g_autoptr (ClutterContent) image = NULL; + g_autoptr (GdkPixbuf) pixbuf = NULL; + + pixbuf = gdk_pixbuf_new_from_file (filename, error); + if (!pixbuf) + return NULL; + + image = clutter_image_new (); + if (!clutter_image_set_data (CLUTTER_IMAGE (image), + gdk_pixbuf_get_pixels (pixbuf), + gdk_pixbuf_get_has_alpha (pixbuf) + ? COGL_PIXEL_FORMAT_RGBA_8888 + : COGL_PIXEL_FORMAT_RGB_888, + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf), + gdk_pixbuf_get_rowstride (pixbuf), + error)) + return NULL; + + return g_object_new (CLUTTER_TYPE_ACTOR, + "content", image, + NULL); +}