#include <stdio.h>
#include <stdlib.h>
#include <wayland-client.h>
+#include <wayland-tbm-client.h>
#include "wayland-egl/wayland-egl-priv.h"
#include "tpl_wayland_egl_thread.h"
+#include "tpl_utils.h"
typedef struct _twe_wl_disp_source twe_wl_disp_source;
typedef struct _twe_wl_surf_source twe_wl_surf_source;
struct _twe_thread {
twe_thread_context *ctx;
+ struct wayland_tbm_client *wl_tbm_client;
};
struct _twe_wl_disp_source {
.finalize = _twe_thread_wl_disp_finalize,
};
+static struct wayland_tbm_client*
+_twe_thread_init_wl_tbm_client(struct wl_display *display,
+ struct wl_event_queue *ev_queue)
+{
+ struct wl_proxy *wl_tbm = NULL;
+ struct wayland_tbm_client *wl_tbm_client = NULL;
+
+ wl_tbm_client = wayland_tbm_client_init(display);
+ if (!wl_tbm_client) {
+ TPL_ERR("Failed to initialize wl_tbm_client.");
+ return NULL;
+ }
+
+ wl_tbm = (struct wl_proxy *)wayland_tbm_client_get_wl_tbm(wl_tbm_client);
+ if (!wl_tbm) {
+ TPL_ERR("Failed to get wl_tbm from wl_tbm_client(%p)", wl_tbm_client);
+ wayland_tbm_client_deinit(wl_tbm_client);
+ return NULL;
+ }
+
+ wl_proxy_set_queue(wl_tbm, ev_queue);
+
+ return wl_tbm_client;
+}
+
+static void
+_twe_thread_fini_wl_tbm_client(struct wayland_tbm_client *wl_tbm_client)
+{
+ struct wl_proxy *wl_tbm = NULL;
+
+ wl_tbm = (struct wl_proxy *)wayland_tbm_client_get_wl_tbm(wl_tbm_client);
+ if (wl_tbm) {
+ wl_proxy_set_queue(wl_tbm, NULL);
+ }
+
+ wayland_tbm_client_deinit(wl_tbm_client);
+}
+
+
void
twe_thread_add_wl_display(twe_thread* thread,
struct wl_display *display)
{
twe_thread_context *ctx = thread->ctx;
twe_wl_disp_source *source;
+ struct wayland_tbm_client *wl_tbm_client = NULL;
+ struct wl_event_queue *ev_queue = NULL;
+
+ ev_queue = wl_display_create_queue(display);
+ if (!ev_queue) {
+ TPL_ERR("Failed to create wl_event_queue.");
+ return;
+ }
+
+ wl_tbm_client = _twe_thread_init_wl_tbm_client(display, ev_queue);
+ if (!wl_tbm_client) {
+ TPL_ERR("Failed to create wl_tbm_client.");
+ return;
+ }
+
+ thread->wl_tbm_client = wl_tbm_client;
source = (twe_wl_disp_source *)g_source_new(&_twe_wl_disp_funcs,
sizeof(twe_wl_disp_source));
source->disp = display;
- source->ev_queue = wl_display_create_queue(display);
+ source->ev_queue = ev_queue;
source->gfd.fd = wl_display_get_fd(display);
source->gfd.events = G_IO_IN | G_IO_ERR;
source->gfd.revents = 0;
return;
}
+ _twe_thread_fini_wl_tbm_client(thread->wl_tbm_client);
+ thread->wl_tbm_client = NULL;
+
g_source_remove_poll(&source->gsource, &source->gfd);
g_source_destroy(&source->gsource);
g_source_unref(&source->gsource);