File: dmabuf-support.c

package info (click to toggle)
gtk4 4.20.3%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 187,060 kB
  • sloc: ansic: 779,084; xml: 3,093; javascript: 3,054; python: 1,911; java: 752; sh: 682; makefile: 315; perl: 162; cpp: 21
file content (67 lines) | stat: -rw-r--r-- 1,642 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "config.h"

#include <gtk/gtk.h>
#include "gdk/gdkdmabuffourccprivate.h"
#include "udmabuf.h"

static void
test_dmabuf_no_gpu (void)
{
  guchar buffer[UDMABUF_STRIDE_ALIGN];
  GdkTexture *texture;
  GError *error = NULL;
  GdkTextureDownloader *downloader;
  gsize stride;
  GBytes *bytes;
  const guchar *data;

  if (!udmabuf_initialize (&error))
    {
      g_test_fail_printf ("%s", error->message);
      g_error_free (error);
      return;
    }

  buffer[0] = 255;
  buffer[1] = 0;
  buffer[2] = 0;
  buffer[3] = 255;

  bytes = g_bytes_new_static (buffer, G_N_ELEMENTS(buffer));

  texture = udmabuf_texture_new (1, 1,
                                 DRM_FORMAT_RGBA8888,
                                 gdk_color_state_get_srgb (),
                                 FALSE,
                                 bytes,
                                 UDMABUF_STRIDE_ALIGN,
                                 &error);
  g_assert_no_error (error);

  g_bytes_unref (bytes);

  downloader = gdk_texture_downloader_new (texture);
  gdk_texture_downloader_set_format (downloader, gdk_texture_get_format (texture));
  gdk_texture_downloader_set_color_state (downloader, gdk_texture_get_color_state (texture));

  bytes = gdk_texture_downloader_download_bytes (downloader, &stride);

  gdk_texture_downloader_free (downloader);

  data = g_bytes_get_data (bytes, NULL);
  g_assert_true (memcmp (data, buffer, 4) == 0);

  g_bytes_unref (bytes);

  g_object_unref (texture);
}

int
main (int argc, char *argv[])
{
  gtk_test_init (&argc, &argv, NULL);

  g_test_add_func ("/dmabuf/no-gpu", test_dmabuf_no_gpu);

  return g_test_run ();
}