File: test_overlay.c

package info (click to toggle)
gxr-openvr 0.15.1-2
  • links: PTS, VCS
  • area: contrib
  • in suites: bookworm, bullseye
  • size: 1,724 kB
  • sloc: ansic: 15,256; sh: 72; xml: 71; awk: 35; makefile: 19
file content (74 lines) | stat: -rw-r--r-- 1,739 bytes parent folder | download | duplicates (5)
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
68
69
70
71
72
73
74
/*
 * gxr
 * Copyright 2018 Collabora Ltd.
 * Author: Lubosz Sarnecki <lubosz.sarnecki@collabora.com>
 * SPDX-License-Identifier: MIT
 */

#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdk.h>

#include "gxr.h"

static GdkPixbuf *
load_gdk_pixbuf ()
{
  GError *error = NULL;
  GdkPixbuf * pixbuf_rgb =
    gdk_pixbuf_new_from_resource ("/res/cat.jpg", &error);

  if (error != NULL)
    {
      g_printerr ("Unable to read file: %s\n", error->message);
      g_error_free (error);
      return NULL;
    }
  else
    {
      GdkPixbuf *pixbuf = gdk_pixbuf_add_alpha (pixbuf_rgb, FALSE, 0, 0, 0);
      g_object_unref (pixbuf_rgb);
      return pixbuf;
    }
}

static void
test_overlay_pixbuf ()
{
  GError *error = NULL;
  GdkPixbuf * pixbuf = load_gdk_pixbuf ();
  g_assert (error == NULL);
  g_assert_nonnull (pixbuf);

  GxrContext *context = gxr_context_new (GXR_APP_OVERLAY, "Test Overlay", 1);
  g_assert_nonnull (context);

  GulkanClient *gc = gxr_context_get_gulkan (context);
  g_assert_nonnull (gc);

  GulkanTexture *texture =
    gulkan_texture_new_from_pixbuf (gc, pixbuf,
                                    VK_FORMAT_R8G8B8A8_UNORM,
                                    VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
                                    FALSE);
  g_assert_nonnull (texture);

  GxrOverlay *overlay = gxr_overlay_new (context, "test.pixbuf");
  g_assert_nonnull (overlay);

  gxr_overlay_set_mouse_scale (overlay,
                               (float) (gdk_pixbuf_get_width (pixbuf)),
                               (float) (gdk_pixbuf_get_height (pixbuf)));

  gxr_overlay_submit_texture (overlay, texture);

  g_object_unref (pixbuf);
}

int
main ()
{
  test_overlay_pixbuf ();

  return 0;
}