tests/interactive: Replace cogl_texture_new_from_file

The interactive tests are the last users use this deprecated API, so
port them to the appropriate alternatives - either CoglTexture2D or
CoglTexture2DSliced.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2355>
This commit is contained in:
Georges Basile Stavracas Neto 2022-03-31 12:32:07 -03:00
parent ca0e467a3b
commit 8f6469f6cb
5 changed files with 23 additions and 41 deletions

View File

@ -124,6 +124,7 @@ test_cogl_multitexture_main (int argc, char *argv[])
0, 0, 1, 1, 0, 0, 1, 1,
0, 0, 1, 1 0, 0, 1, 1
}; };
CoglContext *ctx;
clutter_test_init (&argc, &argv); clutter_test_init (&argc, &argv);
@ -150,35 +151,20 @@ test_cogl_multitexture_main (int argc, char *argv[])
files[2] = g_build_filename (TESTS_DATADIR, "light0.png", NULL); files[2] = g_build_filename (TESTS_DATADIR, "light0.png", NULL);
files[3] = NULL; files[3] = NULL;
state->alpha_tex = ctx = clutter_backend_get_cogl_context (clutter_get_default_backend ());
cogl_texture_new_from_file (files[0], state->alpha_tex = cogl_texture_2d_new_from_file (ctx, files[0], &error);
COGL_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_ANY,
&error);
if (!state->alpha_tex) if (!state->alpha_tex)
g_critical ("Failed to load redhand_alpha.png: %s", error->message); g_critical ("Failed to load redhand_alpha.png: %s", error->message);
state->redhand_tex = state->redhand_tex = cogl_texture_2d_new_from_file (ctx, files[1], &error);
cogl_texture_new_from_file (files[1],
COGL_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_ANY,
&error);
if (!state->redhand_tex) if (!state->redhand_tex)
g_critical ("Failed to load redhand.png: %s", error->message); g_critical ("Failed to load redhand.png: %s", error->message);
state->light_tex0 = state->light_tex0 = cogl_texture_2d_new_from_file (ctx, files[2], &error);
cogl_texture_new_from_file (files[2],
COGL_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_ANY,
&error);
if (!state->light_tex0) if (!state->light_tex0)
g_critical ("Failed to load light0.png: %s", error->message); g_critical ("Failed to load light0.png: %s", error->message);
state->light_tex1 = state->light_tex1 = cogl_texture_2d_new_from_file (ctx, files[2], &error);
cogl_texture_new_from_file (files[2],
COGL_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_ANY,
&error);
if (!state->light_tex1) if (!state->light_tex1)
g_critical ("Failed to load light0.png: %s", error->message); g_critical ("Failed to load light0.png: %s", error->message);

View File

@ -226,16 +226,16 @@ test_coglbox_map (ClutterActor *actor)
static void static void
test_coglbox_init (TestCoglbox *self) test_coglbox_init (TestCoglbox *self)
{ {
g_autoptr (GError) error = NULL;
CoglContext *ctx = CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_get_default_backend ()); clutter_backend_get_cogl_context (clutter_get_default_backend ());
gchar *file; gchar *file;
printf ("Loading redhand.png\n"); printf ("Loading redhand.png\n");
file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
self->texhand_id = cogl_texture_new_from_file (file, self->texhand_id = cogl_texture_2d_new_from_file (ctx, file, &error);
COGL_TEXTURE_NONE, if (error)
COGL_PIXEL_FORMAT_ANY, g_warning ("Error loading redhand.png: %s", error->message);
NULL);
g_free (file); g_free (file);
printf ("Creating texture with size\n"); printf ("Creating texture with size\n");

View File

@ -323,10 +323,7 @@ test_cogl_shader_glsl_main (int argc, char *argv[])
file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
error = NULL; error = NULL;
redhand = cogl_texture_new_from_file (file, redhand = cogl_texture_2d_new_from_file (ctx, file, &error);
COGL_TEXTURE_NO_ATLAS,
COGL_PIXEL_FORMAT_ANY,
&error);
if (redhand == NULL) if (redhand == NULL)
g_error ("image load failed: %s", error->message); g_error ("image load failed: %s", error->message);

View File

@ -227,6 +227,8 @@ test_coglbox_dispose (GObject *object)
static void static void
test_coglbox_init (TestCoglbox *self) test_coglbox_init (TestCoglbox *self)
{ {
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_get_default_backend ());
GError *error = NULL; GError *error = NULL;
gchar *file; gchar *file;
@ -235,9 +237,8 @@ test_coglbox_init (TestCoglbox *self)
file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
self->sliced_tex = self->sliced_tex =
cogl_texture_new_from_file (file, cogl_texture_2d_sliced_new_from_file (ctx, file,
COGL_TEXTURE_NONE, COGL_TEXTURE_MAX_WASTE,
COGL_PIXEL_FORMAT_ANY,
&error); &error);
if (self->sliced_tex == NULL) if (self->sliced_tex == NULL)
{ {
@ -251,11 +252,7 @@ test_coglbox_init (TestCoglbox *self)
g_warning ("Texture loading failed: <unknown>"); g_warning ("Texture loading failed: <unknown>");
} }
self->not_sliced_tex = self->not_sliced_tex = cogl_texture_2d_new_from_file (ctx, file, &error);
cogl_texture_new_from_file (file,
COGL_TEXTURE_NO_SLICING,
COGL_PIXEL_FORMAT_ANY,
&error);
if (self->not_sliced_tex == NULL) if (self->not_sliced_tex == NULL)
{ {
if (error) if (error)

View File

@ -100,13 +100,15 @@ test_coglbox_dispose (GObject *object)
static void static void
test_coglbox_init (TestCoglbox *self) test_coglbox_init (TestCoglbox *self)
{ {
g_autoptr (GError) error = NULL;
CoglContext *ctx =
clutter_backend_get_cogl_context (clutter_get_default_backend ());
gchar *file; gchar *file;
file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL); file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
self->cogl_tex_id = cogl_texture_new_from_file (file, self->cogl_tex_id = cogl_texture_2d_new_from_file (ctx, file, &error);
COGL_TEXTURE_NONE, if (error)
COGL_PIXEL_FORMAT_ANY, g_warning ("Error loading redhand.png: %s", error->message);
NULL);
g_free (file); g_free (file);
} }