Package version up to 0.8.8
[platform/core/uifw/wayland-tbm.git] / test / tbm-client-remote-consumer-test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <string.h>
5
6 #define WL_HIDE_DEPRECATED
7 #include <wayland-client.h>
8 #include <wayland-tbm-client.h>
9 #include <wayland-tbm-int.h>
10
11 #include <tbm_surface.h>
12
13 #include "wayland-tbm-test-client-protocol.h"
14
15 #define WL_APP_C_LOG(fmt, ...)   fprintf(stderr, "[CLIENT(%d):%s] " fmt, getpid(), __func__, ##__VA_ARGS__)
16
17 typedef struct {
18         struct wayland_tbm_client *tbm_client;
19         struct wl_tbm *wl_tbm;
20         struct wl_tbm_test *wl_tbm_test;
21         struct wl_test_remote *remote;
22
23         struct wl_buffer *bufs[3];
24         int cur_buf;
25
26         int exit;
27 } AppInfoClient;
28
29 AppInfoClient gApp;
30
31 static void
32 _wl_registry_global_cb(void *data,
33                        struct wl_registry *wl_registry,
34                        uint32_t name,
35                        const char *interface,
36                        uint32_t version)
37 {
38         AppInfoClient *app = (AppInfoClient *)data;
39
40         if (!strcmp(interface, "wl_tbm_test")) {
41                 WL_APP_C_LOG("bind %s", interface);
42                 app->wl_tbm_test = wl_registry_bind(wl_registry, name,
43                                                     &wl_tbm_test_interface, 1);
44         }
45 }
46
47 static void
48 _wl_registry_global_remove_cb(void *data,
49                               struct wl_registry *wl_registry,
50                               uint32_t name)
51 {
52 }
53
54 static const struct wl_registry_listener wl_registry_impl = {
55         _wl_registry_global_cb,
56         _wl_registry_global_remove_cb,
57 };
58
59 static void
60 _wl_test_remote_update_cb(void *data,
61                        struct wl_test_remote *wl_test_remote,
62                        struct wl_buffer *buffer)
63 {
64         WL_APP_C_LOG("wl_buffer:%p, tbm_surface:%p\n", buffer, wl_buffer_get_user_data(buffer));
65 }
66
67 static const struct wl_test_remote_listener wl_test_remote_impl = {
68         _wl_test_remote_update_cb
69 };
70
71 void create_consumer(AppInfoClient *app)
72 {
73         app->remote = wl_tbm_test_create_remote_surface(app->wl_tbm_test, "test");
74         wl_test_remote_add_listener(app->remote, &wl_test_remote_impl, NULL);
75         wl_test_remote_redirect(app->remote, app->wl_tbm);
76 }
77
78 int
79 main(int argc, char *argv[])
80 {
81         static const char *default_dpy_name = "tbm_remote";
82         struct wl_display *dpy = NULL;
83         struct wl_registry *registry;
84         const char *dpy_name = NULL;
85         int ret = 0;
86
87         if (argc > 1)
88                 dpy_name = argv[1];
89         else
90                 dpy_name = default_dpy_name;
91
92         dpy = wl_display_connect(dpy_name);
93         if (!dpy) {
94                 printf("[APP] failed to connect server\n");
95                 return -1;
96         }
97
98         registry = wl_display_get_registry(dpy);
99         wl_registry_add_listener(registry, &wl_registry_impl, &gApp);
100         wl_display_roundtrip(dpy);
101         if (gApp.wl_tbm_test == NULL) {
102                 WL_APP_C_LOG("fail to bind::wl_tbm_test");
103                 return 0;
104         }
105
106         gApp.tbm_client = wayland_tbm_client_init(dpy);
107         if (!gApp.tbm_client) {
108                 WL_APP_C_LOG("fail to wayland_tbm_client_init()\n");
109                 goto finish;
110         }
111         gApp.wl_tbm = wayland_tbm_client_get_wl_tbm(gApp.tbm_client);
112
113         create_consumer(&gApp);
114
115         while (ret >= 0 && gApp.exit == 0)
116                 ret = wl_display_dispatch(dpy);
117
118 finish:
119         return 1;
120 }
121