Package version up to 0.8.8
[platform/core/uifw/wayland-tbm.git] / test / tbm-client-test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4
5 #include <wayland-client.h>
6 #include <wayland-tbm-client.h>
7 #include <tbm_surface.h>
8 #include <wayland-tbm-client-protocol.h>
9
10 int
11 main(int argc, char *argv[])
12 {
13         struct wl_display *dpy = NULL;
14         const char *dpy_name = NULL;
15         struct wayland_tbm_client *tbm_client = NULL;
16         tbm_surface_h tbm_surf = NULL;
17         struct wl_buffer *buf = NULL;
18         int res = -1;
19
20         if (argc > 0) {
21                 dpy_name = argv[1];
22                 printf("[APP] Connect to %s\n", dpy_name);
23         }
24
25         dpy = wl_display_connect(dpy_name);
26         if (!dpy) {
27                 printf("[APP] failed to connect server\n");
28                 return -1;
29         }
30
31         tbm_client = wayland_tbm_client_init(dpy);
32         if (!tbm_client) {
33                 printf("[APP] failed to client init\n");
34                 goto finish;
35         }
36
37         tbm_surf = tbm_surface_create(100, 100, TBM_FORMAT_ABGR8888);
38         if (!tbm_surf) {
39                 printf("[APP] failed to tbm_surface_create\n");
40                 goto finish;
41         }
42
43         buf = wayland_tbm_client_create_buffer(tbm_client, tbm_surf);
44         if (!buf) {
45                 printf("[APP] failed to wayland_tbm_client_create_buffer\n");
46                 goto finish;
47         }
48         wl_display_flush(dpy);
49
50         tbm_surface_destroy(tbm_surf);
51         wayland_tbm_client_destroy_buffer(tbm_client, buf);
52
53         tbm_surf = NULL;
54         buf = NULL;
55
56         tbm_surf = tbm_surface_create(200, 200, TBM_FORMAT_NV12);
57         if (!tbm_surf) {
58                 printf("[APP] failed to tbm_surface_create\n");
59                 goto finish;
60         }
61
62         buf = wayland_tbm_client_create_buffer(tbm_client, tbm_surf);
63         if (!buf) {
64                 printf("[APP] failed to wayland_tbm_client_create_buffer\n");
65                 goto finish;
66         }
67         wl_display_flush(dpy);
68
69         while (1) {
70                 if (0 > wl_display_dispatch(dpy))
71                         break;
72         }
73
74         res = 0;
75
76 finish:
77         if (buf) wayland_tbm_client_destroy_buffer(tbm_client, buf);
78         if (tbm_surf) tbm_surface_destroy(tbm_surf);
79         if (tbm_client) wayland_tbm_client_deinit(tbm_client);
80         if (dpy) wl_display_disconnect(dpy);
81
82         return res;
83 }