mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 18:05:37 +00:00
tests/glmemory: add simple transfer test
tests transferring to/from the GL with a 1x1 RGBA pixel.
This commit is contained in:
parent
7b0a30343a
commit
ce7226da06
1 changed files with 143 additions and 2 deletions
|
@ -64,8 +64,7 @@ GST_START_TEST (test_basic)
|
||||||
fail_if (gl_allocator == NULL);
|
fail_if (gl_allocator == NULL);
|
||||||
|
|
||||||
/* test allocator creation */
|
/* test allocator creation */
|
||||||
ASSERT_WARNING (mem = gst_allocator_alloc (gl_allocator, 0, NULL);
|
ASSERT_WARNING (mem = gst_allocator_alloc (gl_allocator, 0, NULL));
|
||||||
);
|
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (formats); i++) {
|
for (i = 0; i < G_N_ELEMENTS (formats); i++) {
|
||||||
GstVideoInfo v_info;
|
GstVideoInfo v_info;
|
||||||
|
@ -107,6 +106,147 @@ GST_START_TEST (test_basic)
|
||||||
|
|
||||||
GST_END_TEST;
|
GST_END_TEST;
|
||||||
|
|
||||||
|
/* one red rgba pixel */
|
||||||
|
static gchar rgba_pixel[] = {
|
||||||
|
0xff, 0x00, 0x00, 0xff,
|
||||||
|
};
|
||||||
|
|
||||||
|
GST_START_TEST (test_transfer)
|
||||||
|
{
|
||||||
|
GstAllocator *gl_allocator;
|
||||||
|
GstVideoInfo v_info;
|
||||||
|
GstMemory *mem, *mem2, *mem3;
|
||||||
|
GstMapInfo map_info;
|
||||||
|
|
||||||
|
gl_allocator = gst_allocator_find (GST_GL_MEMORY_ALLOCATOR);
|
||||||
|
fail_if (gl_allocator == NULL);
|
||||||
|
|
||||||
|
gst_video_info_set_format (&v_info, GST_VIDEO_FORMAT_RGBA, 1, 1);
|
||||||
|
|
||||||
|
/* texture creation */
|
||||||
|
mem = (GstMemory *) gst_gl_memory_alloc (context, &v_info, 0);
|
||||||
|
fail_unless (!GST_GL_MEMORY_FLAG_IS_SET (mem,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_UPLOAD));
|
||||||
|
fail_unless (!GST_GL_MEMORY_FLAG_IS_SET (mem,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_DOWNLOAD));
|
||||||
|
|
||||||
|
/* test wrapping raw data */
|
||||||
|
mem2 =
|
||||||
|
(GstMemory *) gst_gl_memory_wrapped (context, &v_info, 0, rgba_pixel,
|
||||||
|
NULL, NULL);
|
||||||
|
fail_if (mem == NULL);
|
||||||
|
|
||||||
|
fail_unless (GST_GL_MEMORY_FLAG_IS_SET (mem2,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_UPLOAD));
|
||||||
|
fail_unless (!GST_GL_MEMORY_FLAG_IS_SET (mem2,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_DOWNLOAD));
|
||||||
|
|
||||||
|
/* wrapped texture creation */
|
||||||
|
mem3 = (GstMemory *) gst_gl_memory_wrapped_texture (context,
|
||||||
|
((GstGLMemory *) mem)->tex_id, &v_info, 0, NULL, NULL);
|
||||||
|
fail_unless (!GST_GL_MEMORY_FLAG_IS_SET (mem3,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_UPLOAD));
|
||||||
|
fail_unless (GST_GL_MEMORY_FLAG_IS_SET (mem3,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_DOWNLOAD));
|
||||||
|
|
||||||
|
/* check data/flags are correct */
|
||||||
|
fail_unless (gst_memory_map (mem2, &map_info, GST_MAP_READ));
|
||||||
|
|
||||||
|
fail_unless (GST_GL_MEMORY_FLAG_IS_SET (mem2,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_UPLOAD));
|
||||||
|
fail_unless (!GST_GL_MEMORY_FLAG_IS_SET (mem2,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_DOWNLOAD));
|
||||||
|
|
||||||
|
fail_unless (((gchar *) map_info.data)[0] == rgba_pixel[0]);
|
||||||
|
fail_unless (((gchar *) map_info.data)[1] == rgba_pixel[1]);
|
||||||
|
fail_unless (((gchar *) map_info.data)[2] == rgba_pixel[2]);
|
||||||
|
fail_unless (((gchar *) map_info.data)[3] == rgba_pixel[3]);
|
||||||
|
|
||||||
|
gst_memory_unmap (mem2, &map_info);
|
||||||
|
|
||||||
|
fail_unless (GST_GL_MEMORY_FLAG_IS_SET (mem2,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_UPLOAD));
|
||||||
|
fail_unless (!GST_GL_MEMORY_FLAG_IS_SET (mem2,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_DOWNLOAD));
|
||||||
|
|
||||||
|
fail_unless (gst_memory_map (mem2, &map_info, GST_MAP_READ | GST_MAP_GL));
|
||||||
|
|
||||||
|
fail_unless (!GST_GL_MEMORY_FLAG_IS_SET (mem2,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_UPLOAD));
|
||||||
|
fail_unless (!GST_GL_MEMORY_FLAG_IS_SET (mem2,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_DOWNLOAD));
|
||||||
|
|
||||||
|
/* test texture copy */
|
||||||
|
fail_unless (gst_gl_memory_copy_into_texture ((GstGLMemory *) mem2,
|
||||||
|
((GstGLMemory *) mem)->tex_id, GST_VIDEO_GL_TEXTURE_TYPE_RGBA, 1, 1,
|
||||||
|
4, FALSE));
|
||||||
|
GST_GL_MEMORY_FLAG_SET (mem, GST_GL_MEMORY_FLAG_NEED_DOWNLOAD);
|
||||||
|
|
||||||
|
fail_unless (!GST_GL_MEMORY_FLAG_IS_SET (mem2,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_UPLOAD));
|
||||||
|
fail_unless (!GST_GL_MEMORY_FLAG_IS_SET (mem2,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_DOWNLOAD));
|
||||||
|
fail_unless (!GST_GL_MEMORY_FLAG_IS_SET (mem,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_UPLOAD));
|
||||||
|
fail_unless (GST_GL_MEMORY_FLAG_IS_SET (mem,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_DOWNLOAD));
|
||||||
|
|
||||||
|
gst_memory_unmap (mem2, &map_info);
|
||||||
|
|
||||||
|
/* test download of copied texture */
|
||||||
|
fail_unless (gst_memory_map (mem, &map_info, GST_MAP_READ));
|
||||||
|
|
||||||
|
fail_unless (((gchar *) map_info.data)[0] == rgba_pixel[0]);
|
||||||
|
fail_unless (((gchar *) map_info.data)[1] == rgba_pixel[1]);
|
||||||
|
fail_unless (((gchar *) map_info.data)[2] == rgba_pixel[2]);
|
||||||
|
fail_unless (((gchar *) map_info.data)[3] == rgba_pixel[3]);
|
||||||
|
|
||||||
|
gst_memory_unmap (mem, &map_info);
|
||||||
|
|
||||||
|
/* test download of wrapped copied texture */
|
||||||
|
fail_unless (gst_memory_map (mem3, &map_info, GST_MAP_READ));
|
||||||
|
|
||||||
|
fail_unless (!GST_GL_MEMORY_FLAG_IS_SET (mem,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_UPLOAD));
|
||||||
|
fail_unless (!GST_GL_MEMORY_FLAG_IS_SET (mem,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_DOWNLOAD));
|
||||||
|
|
||||||
|
fail_unless (((gchar *) map_info.data)[0] == rgba_pixel[0]);
|
||||||
|
fail_unless (((gchar *) map_info.data)[1] == rgba_pixel[1]);
|
||||||
|
fail_unless (((gchar *) map_info.data)[2] == rgba_pixel[2]);
|
||||||
|
fail_unless (((gchar *) map_info.data)[3] == rgba_pixel[3]);
|
||||||
|
|
||||||
|
gst_memory_unmap (mem3, &map_info);
|
||||||
|
|
||||||
|
/* test upload flag */
|
||||||
|
fail_unless (gst_memory_map (mem3, &map_info, GST_MAP_WRITE));
|
||||||
|
gst_memory_unmap (mem3, &map_info);
|
||||||
|
|
||||||
|
fail_unless (GST_GL_MEMORY_FLAG_IS_SET (mem3,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_UPLOAD));
|
||||||
|
fail_unless (!GST_GL_MEMORY_FLAG_IS_SET (mem3,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_DOWNLOAD));
|
||||||
|
|
||||||
|
/* test download flag */
|
||||||
|
fail_unless (gst_memory_map (mem3, &map_info, GST_MAP_WRITE | GST_MAP_GL));
|
||||||
|
gst_memory_unmap (mem3, &map_info);
|
||||||
|
|
||||||
|
fail_unless (!GST_GL_MEMORY_FLAG_IS_SET (mem3,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_UPLOAD));
|
||||||
|
fail_unless (GST_GL_MEMORY_FLAG_IS_SET (mem3,
|
||||||
|
GST_GL_MEMORY_FLAG_NEED_DOWNLOAD));
|
||||||
|
|
||||||
|
if (gst_gl_context_get_error ())
|
||||||
|
printf ("%s\n", gst_gl_context_get_error ());
|
||||||
|
fail_if (gst_gl_context_get_error () != NULL);
|
||||||
|
|
||||||
|
gst_memory_unref (mem);
|
||||||
|
gst_memory_unref (mem2);
|
||||||
|
gst_memory_unref (mem3);
|
||||||
|
gst_object_unref (gl_allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_END_TEST;
|
||||||
|
|
||||||
static Suite *
|
static Suite *
|
||||||
gst_gl_memory_suite (void)
|
gst_gl_memory_suite (void)
|
||||||
|
@ -117,6 +257,7 @@ gst_gl_memory_suite (void)
|
||||||
suite_add_tcase (s, tc_chain);
|
suite_add_tcase (s, tc_chain);
|
||||||
tcase_add_checked_fixture (tc_chain, setup, teardown);
|
tcase_add_checked_fixture (tc_chain, setup, teardown);
|
||||||
tcase_add_test (tc_chain, test_basic);
|
tcase_add_test (tc_chain, test_basic);
|
||||||
|
tcase_add_test (tc_chain, test_transfer);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue