//#define WL_TBM_CLIENT_DEBUG
-struct wayland_tbm_client
-{
- struct wl_display* dpy;
- struct wl_event_queue *wl_queue;
- struct wl_tbm* wl_tbm;
-
- tbm_bufmgr bufmgr;
- int32_t auth_fd;
- uint32_t capabilities;
- char *device;
-
- /* This authenticated information is for the client of the embedded server.
- */
- int32_t embedded_auth_fd;
- uint32_t embedded_capabilities;
- char *embedded_device;
+struct wayland_tbm_client {
+ struct wl_display *dpy;
+ struct wl_event_queue *wl_queue;
+ struct wl_tbm *wl_tbm;
+
+ tbm_bufmgr bufmgr;
+ int32_t auth_fd;
+ uint32_t capabilities;
+ char *device;
+
+ /* This authenticated information is for the client of the embedded server.
+ */
+ int32_t embedded_auth_fd;
+ uint32_t embedded_capabilities;
+ char *embedded_device;
};
static void
handle_tbm_monitor_client_tbm_bo(void *data,
- struct wl_tbm *wl_tbm,
- int32_t command,
- int32_t trace_command,
- int32_t target,
- int32_t pid)
+ struct wl_tbm *wl_tbm,
+ int32_t command,
+ int32_t trace_command,
+ int32_t target,
+ int32_t pid)
{
- struct wayland_tbm_client *tbm_client = (struct wayland_tbm_client *)data;
+ struct wayland_tbm_client *tbm_client = (struct wayland_tbm_client *)data;
#ifdef WL_TBM_CLIENT_DEBUG
- WL_TBM_LOG("[%s]: command=%d, trace_command=%d, pid=%d\n", __func__, command, trace_command, pid);
+ WL_TBM_LOG("[%s]: command=%d, trace_command=%d, pid=%d\n", __func__, command,
+ trace_command, pid);
#endif
- if (command == WL_TBM_MONITOR_COMMAND_SHOW) {
- if (target == WL_TBM_MONITOR_TARGET_CLIENT) {
- if (getpid() == pid)
- tbm_bufmgr_debug_show(tbm_client->bufmgr);
- } else if (target == WL_TBM_MONITOR_TARGET_ALL) {
- tbm_bufmgr_debug_show(tbm_client->bufmgr);
- } else {
- WL_TBM_LOG("[%s]: Error target is not available. target = %d\n", __func__, target);
- }
- } else if (command == WL_TBM_MONITOR_COMMAND_TRACE) {
+ if (command == WL_TBM_MONITOR_COMMAND_SHOW) {
+ if (target == WL_TBM_MONITOR_TARGET_CLIENT) {
+ if (getpid() == pid)
+ tbm_bufmgr_debug_show(tbm_client->bufmgr);
+ } else if (target == WL_TBM_MONITOR_TARGET_ALL) {
+ tbm_bufmgr_debug_show(tbm_client->bufmgr);
+ } else {
+ WL_TBM_LOG("[%s]: Error target is not available. target = %d\n", __func__,
+ target);
+ }
+ } else if (command == WL_TBM_MONITOR_COMMAND_TRACE) {
WL_TBM_LOG("[%s]: TRACE is not implemented.\n", __func__);
- } else {
- WL_TBM_LOG("[%s]: Error command is not available. command = %d\n", __func__, command);
- }
+ } else {
+ WL_TBM_LOG("[%s]: Error command is not available. command = %d\n", __func__,
+ command);
+ }
}
static void
handle_tbm_authentication_info(void *data,
- struct wl_tbm *wl_tbm,
- const char *device_name,
- uint32_t capabilities,
- int32_t auth_fd)
+ struct wl_tbm *wl_tbm,
+ const char *device_name,
+ uint32_t capabilities,
+ int32_t auth_fd)
{
- struct wayland_tbm_client *tbm_client = (struct wayland_tbm_client *)data;
+ struct wayland_tbm_client *tbm_client = (struct wayland_tbm_client *)data;
- if (tbm_client->auth_fd == -1 ) {
+ if (tbm_client->auth_fd == -1 ) {
#ifdef WL_TBM_CLIENT_DEBUG
- WL_TBM_LOG("[%s]: get the client auth info\n", __func__);
+ WL_TBM_LOG("[%s]: get the client auth info\n", __func__);
#endif
- /* client authentication infomation */
- tbm_client->auth_fd = auth_fd;
- tbm_client->capabilities = capabilities;
- if (device_name)
- tbm_client->device = strndup(device_name, 256);
- } else {
+ /* client authentication infomation */
+ tbm_client->auth_fd = auth_fd;
+ tbm_client->capabilities = capabilities;
+ if (device_name)
+ tbm_client->device = strndup(device_name, 256);
+ } else {
#ifdef WL_TBM_CLIENT_DEBUG
- WL_TBM_LOG("[%s]: get the embedded server client auth info\n", __func__);
+ WL_TBM_LOG("[%s]: get the embedded server client auth info\n", __func__);
#endif
- /* authentication information of embedded server client */
- tbm_client->embedded_auth_fd = auth_fd;
- tbm_client->embedded_capabilities = capabilities;
- tbm_client->embedded_device = strndup(device_name, 256);
- }
+ /* authentication information of embedded server client */
+ tbm_client->embedded_auth_fd = auth_fd;
+ tbm_client->embedded_capabilities = capabilities;
+ tbm_client->embedded_device = strndup(device_name, 256);
+ }
#ifdef WL_TBM_CLIENT_DEBUG
- WL_TBM_LOG("[%s]: tbm_client=%p, wl_tbm=%p, device_name=%s, capabilities=%d, auth_fd=%d\n",
- __func__, tbm_client, wl_tbm, device_name, capabilities, auth_fd);
+ WL_TBM_LOG("[%s]: tbm_client=%p, wl_tbm=%p, device_name=%s, capabilities=%d, auth_fd=%d\n",
+ __func__, tbm_client, wl_tbm, device_name, capabilities, auth_fd);
#endif
}
static const struct wl_tbm_listener wl_tbm_client_listener = {
- handle_tbm_authentication_info,
- handle_tbm_monitor_client_tbm_bo
+ handle_tbm_authentication_info,
+ handle_tbm_monitor_client_tbm_bo
};
static void
-_wayland_tbm_client_registry_handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
+_wayland_tbm_client_registry_handle_global(void *data,
+ struct wl_registry *registry, uint32_t name, const char *interface,
+ uint32_t version)
{
- struct wayland_tbm_client *tbm_client = (struct wayland_tbm_client *)data;
+ struct wayland_tbm_client *tbm_client = (struct wayland_tbm_client *)data;
- if (!strcmp(interface, "wl_tbm")) {
- tbm_client->wl_tbm = wl_registry_bind(registry, name, &wl_tbm_interface, version);
- WL_TBM_RETURN_IF_FAIL(tbm_client->wl_tbm != NULL);
+ if (!strcmp(interface, "wl_tbm")) {
+ tbm_client->wl_tbm = wl_registry_bind(registry, name, &wl_tbm_interface,
+ version);
+ WL_TBM_RETURN_IF_FAIL(tbm_client->wl_tbm != NULL);
- wl_tbm_add_listener(tbm_client->wl_tbm, &wl_tbm_client_listener, tbm_client);
- wl_proxy_set_queue((struct wl_proxy *)tbm_client->wl_tbm, tbm_client->wl_queue);
+ wl_tbm_add_listener(tbm_client->wl_tbm, &wl_tbm_client_listener, tbm_client);
+ wl_proxy_set_queue((struct wl_proxy *)tbm_client->wl_tbm, tbm_client->wl_queue);
- /* get the authentication from the display server */
- wl_tbm_get_authentication_info(tbm_client->wl_tbm);
- wl_display_roundtrip_queue(tbm_client->dpy, tbm_client->wl_queue);
+ /* get the authentication from the display server */
+ wl_tbm_get_authentication_info(tbm_client->wl_tbm);
+ wl_display_roundtrip_queue(tbm_client->dpy, tbm_client->wl_queue);
- // TODO: check the failure to get the auth information.
- // WL_TBM_LOG("failed to get auth_info\n");
- // tbm_client->wl_tbm = NULL;
- // return;
+ // TODO: check the failure to get the auth information.
+ // WL_TBM_LOG("failed to get auth_info\n");
+ // tbm_client->wl_tbm = NULL;
+ // return;
#ifdef WL_TBM_CLIENT_DEBUG
- WL_TBM_LOG("[%s]: tbm_client=%p, wl_tbm=%p, device_name=%s, capabilities=%d, auth_fd=%d\n",
- __func__, tbm_client, tbm_client->wl_tbm, tbm_client->device, tbm_client->capabilities, tbm_client->auth_fd);
+ WL_TBM_LOG("[%s]: tbm_client=%p, wl_tbm=%p, device_name=%s, capabilities=%d, auth_fd=%d\n",
+ __func__, tbm_client, tbm_client->wl_tbm, tbm_client->device,
+ tbm_client->capabilities, tbm_client->auth_fd);
#endif
- tbm_client->bufmgr = tbm_bufmgr_init(tbm_client->auth_fd);
- if (!tbm_client->bufmgr) {
- WL_TBM_LOG("failed to get auth_info\n");
+ tbm_client->bufmgr = tbm_bufmgr_init(tbm_client->auth_fd);
+ if (!tbm_client->bufmgr) {
+ WL_TBM_LOG("failed to get auth_info\n");
- tbm_client->wl_tbm = NULL;
- return;
- }
- }
+ tbm_client->wl_tbm = NULL;
+ return;
+ }
+ }
}
static const struct wl_registry_listener registry_listener = {
- _wayland_tbm_client_registry_handle_global,
- NULL
+ _wayland_tbm_client_registry_handle_global,
+ NULL
};
struct wayland_tbm_client *
-wayland_tbm_client_init(struct wl_display* display)
+wayland_tbm_client_init(struct wl_display *display)
{
- WL_TBM_RETURN_VAL_IF_FAIL(display != NULL, NULL);
+ WL_TBM_RETURN_VAL_IF_FAIL(display != NULL, NULL);
- struct wayland_tbm_client *tbm_client = NULL;
- struct wl_registry *wl_registry;
+ struct wayland_tbm_client *tbm_client = NULL;
+ struct wl_registry *wl_registry;
- tbm_client = calloc(1, sizeof(struct wayland_tbm_client));
- WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, NULL);
+ tbm_client = calloc(1, sizeof(struct wayland_tbm_client));
+ WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, NULL);
- tbm_client->dpy = display;
- tbm_client->auth_fd = -1; /* initialize */
- tbm_client->embedded_auth_fd = -1; /* for embedded server client */
+ tbm_client->dpy = display;
+ tbm_client->auth_fd = -1; /* initialize */
+ tbm_client->embedded_auth_fd = -1; /* for embedded server client */
- tbm_client->wl_queue = wl_display_create_queue(display);
- if (!tbm_client->wl_queue) {
- WL_TBM_LOG("Failed to create queue.\n");
+ tbm_client->wl_queue = wl_display_create_queue(display);
+ if (!tbm_client->wl_queue) {
+ WL_TBM_LOG("Failed to create queue.\n");
- free(tbm_client);
- return NULL;
- }
+ free(tbm_client);
+ return NULL;
+ }
- wl_registry = wl_display_get_registry(display);
- if (!wl_registry) {
- WL_TBM_LOG("Failed to get registry\n");
+ wl_registry = wl_display_get_registry(display);
+ if (!wl_registry) {
+ WL_TBM_LOG("Failed to get registry\n");
- wl_event_queue_destroy(tbm_client->wl_queue);
- free(tbm_client);
- return NULL;
- }
+ wl_event_queue_destroy(tbm_client->wl_queue);
+ free(tbm_client);
+ return NULL;
+ }
- wl_proxy_set_queue((struct wl_proxy *)wl_registry, tbm_client->wl_queue);
+ wl_proxy_set_queue((struct wl_proxy *)wl_registry, tbm_client->wl_queue);
#ifdef WL_TBM_CLIENT_DEBUG
- WL_TBM_LOG("[%s]: tbm_client=%p, display=%p\n", __func__, tbm_client, display);
+ WL_TBM_LOG("[%s]: tbm_client=%p, display=%p\n", __func__, tbm_client, display);
#endif
- wl_registry_add_listener(wl_registry, ®istry_listener, tbm_client);
- wl_display_roundtrip_queue(display, tbm_client->wl_queue);
+ wl_registry_add_listener(wl_registry, ®istry_listener, tbm_client);
+ wl_display_roundtrip_queue(display, tbm_client->wl_queue);
- wl_event_queue_destroy(tbm_client->wl_queue);
- wl_registry_destroy(wl_registry);
+ wl_event_queue_destroy(tbm_client->wl_queue);
+ wl_registry_destroy(wl_registry);
- /* check wl_tbm */
- if (!tbm_client->wl_tbm) {
- WL_TBM_LOG("failed to create wl_tbm\n");
- wayland_tbm_client_deinit(tbm_client);
- return NULL;
- }
+ /* check wl_tbm */
+ if (!tbm_client->wl_tbm) {
+ WL_TBM_LOG("failed to create wl_tbm\n");
+ wayland_tbm_client_deinit(tbm_client);
+ return NULL;
+ }
- /* wl_tbm's queue is destroyed above. We should make wl_tbm's queue to
- * display's default_queue.
- */
- wl_proxy_set_queue((struct wl_proxy *)tbm_client->wl_tbm, NULL);
+ /* wl_tbm's queue is destroyed above. We should make wl_tbm's queue to
+ * display's default_queue.
+ */
+ wl_proxy_set_queue((struct wl_proxy *)tbm_client->wl_tbm, NULL);
- return tbm_client;
+ return tbm_client;
}
void
wayland_tbm_client_deinit(struct wayland_tbm_client *tbm_client)
{
- if (!tbm_client)
- return;
+ if (!tbm_client)
+ return;
- /* clear the embedded server client auth information */
- _wayland_tbm_client_reset_embedded_auth_info(tbm_client);
+ /* clear the embedded server client auth information */
+ _wayland_tbm_client_reset_embedded_auth_info(tbm_client);
- if (tbm_client->wl_tbm) {
- wl_tbm_set_user_data(tbm_client->wl_tbm, NULL);
- wl_tbm_destroy(tbm_client->wl_tbm);
- }
+ if (tbm_client->wl_tbm) {
+ wl_tbm_set_user_data(tbm_client->wl_tbm, NULL);
+ wl_tbm_destroy(tbm_client->wl_tbm);
+ }
- if (tbm_client->bufmgr)
- tbm_bufmgr_deinit(tbm_client->bufmgr);
+ if (tbm_client->bufmgr)
+ tbm_bufmgr_deinit(tbm_client->bufmgr);
- if (tbm_client->device)
- free(tbm_client->device);
+ if (tbm_client->device)
+ free(tbm_client->device);
- if (tbm_client->auth_fd)
- close(tbm_client->auth_fd);
+ if (tbm_client->auth_fd)
+ close(tbm_client->auth_fd);
- free(tbm_client);
+ free(tbm_client);
}
struct wl_buffer *
-wayland_tbm_client_create_buffer(struct wayland_tbm_client *tbm_client, tbm_surface_h surface)
+wayland_tbm_client_create_buffer(struct wayland_tbm_client *tbm_client,
+ tbm_surface_h surface)
{
- WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, NULL);
- WL_TBM_RETURN_VAL_IF_FAIL(surface != NULL, NULL);
-
- int ret = -1;
- tbm_surface_info_s info;
- int num_buf;
- int bufs[TBM_SURF_PLANE_MAX] = {-1, -1, -1, -1};
- int is_fd = -1;
- struct wl_buffer* wl_buffer = NULL;
- int i;
-
- ret = tbm_surface_get_info(surface, &info);
- if (ret != TBM_SURFACE_ERROR_NONE) {
- WL_TBM_LOG("Failed to create buffer from surface\n");
- return NULL;
- }
-
- if (info.num_planes > 3) {
- WL_TBM_LOG("invalid num_planes(%d)\n", info.num_planes);
- return NULL;
- }
-
- num_buf = tbm_surface_internal_get_num_bos(surface);
- if (num_buf == 0) {
- WL_TBM_LOG("surface doesn't have any bo.\n");
- goto err;
- }
-
- for (i = 0; i < num_buf; i++) {
- tbm_bo bo = tbm_surface_internal_get_bo(surface, i);
- if (bo == NULL) {
- WL_TBM_LOG("Failed to get bo from surface\n");
- goto err;
- }
-
- /* try to get fd first */
- if (is_fd == -1 || is_fd == 1) {
- bufs[i] = tbm_bo_export_fd(bo);
- if (bufs[i] >= 0)
- is_fd = 1;
- }
-
- /* if fail to get fd, try to get name second */
- if (is_fd == -1 || is_fd == 0) {
- bufs[i] = tbm_bo_export(bo);
- if (bufs[i] > 0)
- is_fd = 0;
- }
-
- if (is_fd == -1 ||
- (is_fd == 1 && bufs[i] < 0) ||
- (is_fd == 0 && bufs[i] <= 0)) {
- WL_TBM_LOG("Failed to export(is_fd:%d, bufs:%d)\n", is_fd, bufs[i]);
- goto err;
- }
- }
-
- if (is_fd == 1)
- wl_buffer = wl_tbm_create_buffer_with_fd(tbm_client->wl_tbm,
- info.width, info.height, info.format, info.num_planes,
- tbm_surface_internal_get_plane_bo_idx(surface, 0),
- info.planes[0].offset, info.planes[0].stride,
- tbm_surface_internal_get_plane_bo_idx(surface, 1),
- info.planes[1].offset, info.planes[1].stride,
- tbm_surface_internal_get_plane_bo_idx(surface, 2),
- info.planes[2].offset, info.planes[2].stride,
- 0, num_buf, bufs[0],
- (bufs[1] == -1) ? bufs[0] : bufs[1],
- (bufs[2] == -1) ? bufs[0] : bufs[2]);
- else
- wl_buffer = wl_tbm_create_buffer(tbm_client->wl_tbm,
- info.width, info.height, info.format, info.num_planes,
- tbm_surface_internal_get_plane_bo_idx(surface, 0),
- info.planes[0].offset, info.planes[0].stride,
- tbm_surface_internal_get_plane_bo_idx(surface, 1),
- info.planes[1].offset, info.planes[1].stride,
- tbm_surface_internal_get_plane_bo_idx(surface, 2),
- info.planes[2].offset, info.planes[2].stride,
- 0,
- num_buf, bufs[0], bufs[1], bufs[2]);
-
- if (!wl_buffer) {
- WL_TBM_LOG("Failed to create wl_buffer\n");
- goto err;
- }
-
- for (i = 0; i < TBM_SURF_PLANE_MAX; i++) {
- if (is_fd == 1 && (bufs[i] >= 0))
- close(bufs[i]);
- }
-
- return wl_buffer;
+ WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, NULL);
+ WL_TBM_RETURN_VAL_IF_FAIL(surface != NULL, NULL);
+
+ int ret = -1;
+ tbm_surface_info_s info;
+ int num_buf;
+ int bufs[TBM_SURF_PLANE_MAX] = { -1, -1, -1, -1};
+ int is_fd = -1;
+ struct wl_buffer *wl_buffer = NULL;
+ int i;
+
+ ret = tbm_surface_get_info(surface, &info);
+ if (ret != TBM_SURFACE_ERROR_NONE) {
+ WL_TBM_LOG("Failed to create buffer from surface\n");
+ return NULL;
+ }
+
+ if (info.num_planes > 3) {
+ WL_TBM_LOG("invalid num_planes(%d)\n", info.num_planes);
+ return NULL;
+ }
+
+ num_buf = tbm_surface_internal_get_num_bos(surface);
+ if (num_buf == 0) {
+ WL_TBM_LOG("surface doesn't have any bo.\n");
+ goto err;
+ }
+
+ for (i = 0; i < num_buf; i++) {
+ tbm_bo bo = tbm_surface_internal_get_bo(surface, i);
+ if (bo == NULL) {
+ WL_TBM_LOG("Failed to get bo from surface\n");
+ goto err;
+ }
+
+ /* try to get fd first */
+ if (is_fd == -1 || is_fd == 1) {
+ bufs[i] = tbm_bo_export_fd(bo);
+ if (bufs[i] >= 0)
+ is_fd = 1;
+ }
+
+ /* if fail to get fd, try to get name second */
+ if (is_fd == -1 || is_fd == 0) {
+ bufs[i] = tbm_bo_export(bo);
+ if (bufs[i] > 0)
+ is_fd = 0;
+ }
+
+ if (is_fd == -1 ||
+ (is_fd == 1 && bufs[i] < 0) ||
+ (is_fd == 0 && bufs[i] <= 0)) {
+ WL_TBM_LOG("Failed to export(is_fd:%d, bufs:%d)\n", is_fd, bufs[i]);
+ goto err;
+ }
+ }
+
+ if (is_fd == 1)
+ wl_buffer = wl_tbm_create_buffer_with_fd(tbm_client->wl_tbm,
+ info.width, info.height, info.format, info.num_planes,
+ tbm_surface_internal_get_plane_bo_idx(surface, 0),
+ info.planes[0].offset, info.planes[0].stride,
+ tbm_surface_internal_get_plane_bo_idx(surface, 1),
+ info.planes[1].offset, info.planes[1].stride,
+ tbm_surface_internal_get_plane_bo_idx(surface, 2),
+ info.planes[2].offset, info.planes[2].stride,
+ 0, num_buf, bufs[0],
+ (bufs[1] == -1) ? bufs[0] : bufs[1],
+ (bufs[2] == -1) ? bufs[0] : bufs[2]);
+ else
+ wl_buffer = wl_tbm_create_buffer(tbm_client->wl_tbm,
+ info.width, info.height, info.format, info.num_planes,
+ tbm_surface_internal_get_plane_bo_idx(surface, 0),
+ info.planes[0].offset, info.planes[0].stride,
+ tbm_surface_internal_get_plane_bo_idx(surface, 1),
+ info.planes[1].offset, info.planes[1].stride,
+ tbm_surface_internal_get_plane_bo_idx(surface, 2),
+ info.planes[2].offset, info.planes[2].stride,
+ 0,
+ num_buf, bufs[0], bufs[1], bufs[2]);
+
+ if (!wl_buffer) {
+ WL_TBM_LOG("Failed to create wl_buffer\n");
+ goto err;
+ }
+
+ for (i = 0; i < TBM_SURF_PLANE_MAX; i++) {
+ if (is_fd == 1 && (bufs[i] >= 0))
+ close(bufs[i]);
+ }
+
+ return wl_buffer;
err:
- for (i = 0; i < TBM_SURF_PLANE_MAX; i++) {
- if (is_fd == 1 && (bufs[i] >= 0))
- close(bufs[i]);
- }
+ for (i = 0; i < TBM_SURF_PLANE_MAX; i++) {
+ if (is_fd == 1 && (bufs[i] >= 0))
+ close(bufs[i]);
+ }
- return NULL;
+ return NULL;
}
void
-wayland_tbm_client_destroy_buffer(struct wayland_tbm_client *tbm_client, struct wl_buffer* buffer)
+wayland_tbm_client_destroy_buffer(struct wayland_tbm_client *tbm_client,
+ struct wl_buffer *buffer)
{
- WL_TBM_RETURN_IF_FAIL(tbm_client != NULL);
- WL_TBM_RETURN_IF_FAIL(buffer != NULL);
+ WL_TBM_RETURN_IF_FAIL(tbm_client != NULL);
+ WL_TBM_RETURN_IF_FAIL(buffer != NULL);
- // TODO: valid check if the buffer is from this tbm_client???
+ // TODO: valid check if the buffer is from this tbm_client???
- wl_buffer_set_user_data(buffer, NULL);
- wl_buffer_destroy(buffer);
+ wl_buffer_set_user_data(buffer, NULL);
+ wl_buffer_destroy(buffer);
}
-const char*
+const char *
wayland_tbm_client_get_device_name(struct wayland_tbm_client *tbm_client)
{
- WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, NULL);
+ WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, NULL);
- return (const char *)tbm_client->device;
+ return (const char *)tbm_client->device;
}
uint32_t
wayland_tbm_client_get_capability(struct wayland_tbm_client *tbm_client)
{
- WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, 0);
+ WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, 0);
- return tbm_client->capabilities;
+ return tbm_client->capabilities;
}
void *
wayland_tbm_client_get_bufmgr(struct wayland_tbm_client *tbm_client)
{
- WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, NULL);
+ WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, NULL);
- return (void *)tbm_client->bufmgr;
+ return (void *)tbm_client->bufmgr;
}
int32_t
_wayland_tbm_client_get_auth_fd(struct wayland_tbm_client *tbm_client)
{
- WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, -1);
+ WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, -1);
- return tbm_client->auth_fd;
+ return tbm_client->auth_fd;
}
struct wl_tbm *
_wayland_tbm_client_get_wl_tbm(struct wayland_tbm_client *tbm_client)
{
- WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, NULL);
+ WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, NULL);
- return tbm_client->wl_tbm;
+ return tbm_client->wl_tbm;
}
void
-_wayland_tbm_client_reset_embedded_auth_info(struct wayland_tbm_client *tbm_client)
+_wayland_tbm_client_reset_embedded_auth_info(struct wayland_tbm_client
+ *tbm_client)
{
- WL_TBM_RETURN_IF_FAIL(tbm_client != NULL);
+ WL_TBM_RETURN_IF_FAIL(tbm_client != NULL);
- if (tbm_client->embedded_auth_fd > 0) {
- close(tbm_client->embedded_auth_fd);
- tbm_client->embedded_auth_fd = -1;
- }
+ if (tbm_client->embedded_auth_fd > 0) {
+ close(tbm_client->embedded_auth_fd);
+ tbm_client->embedded_auth_fd = -1;
+ }
- tbm_client->embedded_capabilities = 0;
+ tbm_client->embedded_capabilities = 0;
- if (tbm_client->embedded_device != NULL) {
- free(tbm_client->embedded_device);
- tbm_client->embedded_device = NULL;
- }
+ if (tbm_client->embedded_device != NULL) {
+ free(tbm_client->embedded_device);
+ tbm_client->embedded_device = NULL;
+ }
}
int32_t
_wayland_tbm_client_get_embedded_auth_fd(struct wayland_tbm_client *tbm_client)
{
- WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, -1);
+ WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, -1);
- return tbm_client->embedded_auth_fd;
+ return tbm_client->embedded_auth_fd;
}
uint32_t
-_wayland_tbm_client_get_embedded_capability(struct wayland_tbm_client *tbm_client)
+_wayland_tbm_client_get_embedded_capability(struct wayland_tbm_client
+ *tbm_client)
{
- WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, 0);
+ WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, 0);
- return tbm_client->embedded_capabilities;
+ return tbm_client->embedded_capabilities;
}
-const char*
-_wayland_tbm_client_get_embedded_device_name(struct wayland_tbm_client *tbm_client)
+const char *
+_wayland_tbm_client_get_embedded_device_name(struct wayland_tbm_client
+ *tbm_client)
{
- WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, NULL);
+ WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, NULL);
- return (const char *)tbm_client->embedded_device;
+ return (const char *)tbm_client->embedded_device;
}
struct wayland_tbm_client;
-struct wayland_tbm_client *wayland_tbm_client_init(struct wl_display* display);
-void wayland_tbm_client_deinit(struct wayland_tbm_client* tbm_client);
-
-struct wl_buffer *wayland_tbm_client_create_buffer(struct wayland_tbm_client* tbm_client, tbm_surface_h surface);
-void wayland_tbm_client_destroy_buffer(struct wayland_tbm_client *tbm_client, struct wl_buffer* buffer);
-
-const char *wayland_tbm_client_get_device_name(struct wayland_tbm_client* tbm_client);
-uint32_t wayland_tbm_client_get_capability(struct wayland_tbm_client* tbm_client);
-void *wayland_tbm_client_get_bufmgr(struct wayland_tbm_client* tbm_client);
+struct wayland_tbm_client *wayland_tbm_client_init(struct wl_display *display);
+void wayland_tbm_client_deinit(struct wayland_tbm_client
+ *tbm_client);
+
+struct wl_buffer *wayland_tbm_client_create_buffer(struct wayland_tbm_client
+ *tbm_client, tbm_surface_h surface);
+void wayland_tbm_client_destroy_buffer(struct wayland_tbm_client
+ *tbm_client, struct wl_buffer *buffer);
+
+const char *wayland_tbm_client_get_device_name(struct wayland_tbm_client
+ *tbm_client);
+uint32_t wayland_tbm_client_get_capability(struct wayland_tbm_client
+ *tbm_client);
+void *wayland_tbm_client_get_bufmgr(struct wayland_tbm_client
+ *tbm_client);
#ifdef __cplusplus
}
}\
}
-typedef enum
-{
+typedef enum {
WL_TBM_MONITOR_COMMAND_LIST,
- WL_TBM_MONITOR_COMMAND_SHOW,
- WL_TBM_MONITOR_COMMAND_TRACE,
+ WL_TBM_MONITOR_COMMAND_SHOW,
+ WL_TBM_MONITOR_COMMAND_TRACE,
} WL_TBM_MONITOR_COMMAND;
-typedef enum
-{
- WL_TBM_MONITOR_TRACE_COMMAND_ON,
- WL_TBM_MONITOR_TRACE_COMMAND_OFF,
- WL_TBM_MONITOR_TRACE_COMMAND_REGISTER,
- WL_TBM_MONITOR_TRACE_COMMAND_UNREGISTER,
- WL_TBM_MONITOR_TRACE_COMMAND_CHANGE,
+typedef enum {
+ WL_TBM_MONITOR_TRACE_COMMAND_ON,
+ WL_TBM_MONITOR_TRACE_COMMAND_OFF,
+ WL_TBM_MONITOR_TRACE_COMMAND_REGISTER,
+ WL_TBM_MONITOR_TRACE_COMMAND_UNREGISTER,
+ WL_TBM_MONITOR_TRACE_COMMAND_CHANGE,
WL_TBM_MONITOR_TRACE_COMMAND_INFO,
WL_TBM_MONITOR_TRACE_COMMAND_STATUS,
} WL_TBM_MONITOR_TRACE_COMMAND;
-typedef enum
-{
- WL_TBM_MONITOR_TARGET_CLIENT,
- WL_TBM_MONITOR_TARGET_SERVER,
- WL_TBM_MONITOR_TARGET_ALL,
+typedef enum {
+ WL_TBM_MONITOR_TARGET_CLIENT,
+ WL_TBM_MONITOR_TARGET_SERVER,
+ WL_TBM_MONITOR_TARGET_ALL,
} WL_TBM_MONITOR_TARGET;
/* internal functions */
-int32_t _wayland_tbm_client_get_auth_fd(struct wayland_tbm_client *tbm_client);
-struct wl_tbm *_wayland_tbm_client_get_wl_tbm(struct wayland_tbm_client *tbm_client);
-
-void _wayland_tbm_client_reset_embedded_auth_info(struct wayland_tbm_client *tbm_client);
-int32_t _wayland_tbm_client_get_embedded_auth_fd(struct wayland_tbm_client *tbm_client);
-uint32_t _wayland_tbm_client_get_embedded_capability(struct wayland_tbm_client *tbm_client);
-const char *_wayland_tbm_client_get_embedded_device_name(struct wayland_tbm_client *tbm_client);
+int32_t _wayland_tbm_client_get_auth_fd(struct wayland_tbm_client
+ *tbm_client);
+struct wl_tbm *_wayland_tbm_client_get_wl_tbm(struct wayland_tbm_client
+ *tbm_client);
+
+void _wayland_tbm_client_reset_embedded_auth_info(
+ struct wayland_tbm_client *tbm_client);
+int32_t _wayland_tbm_client_get_embedded_auth_fd(struct wayland_tbm_client
+ *tbm_client);
+uint32_t _wayland_tbm_client_get_embedded_capability(
+ struct wayland_tbm_client *tbm_client);
+const char *_wayland_tbm_client_get_embedded_device_name(
+ struct wayland_tbm_client *tbm_client);
void _wayland_tbm_util_get_appname_brief(char *brief);
void _wayland_tbm_util_get_appname_from_pid(long pid, char *str);
#define MIN(x,y) (((x)<(y))?(x):(y))
struct wayland_tbm_server {
- struct wl_display *display;
- struct wl_global *wl_tbm_global;
+ struct wl_display *display;
+ struct wl_global *wl_tbm_global;
struct wl_list client_resource_list;
- char *device_name;
- uint32_t fd;
- uint32_t flags;
- tbm_bufmgr bufmgr;
+ char *device_name;
+ uint32_t fd;
+ uint32_t flags;
+ tbm_bufmgr bufmgr;
- /* for embedded serverc client */
- struct wayland_tbm_client *tbm_client;
- struct wl_display *host_dpy;
- struct wl_tbm *wl_tbm;
+ /* for embedded serverc client */
+ struct wayland_tbm_client *tbm_client;
+ struct wl_display *host_dpy;
+ struct wl_tbm *wl_tbm;
};
struct wl_tbm_buffer {
- struct wl_resource *resource;
- tbm_surface_h tbm_surface;
- int flags;
+ struct wl_resource *resource;
+ tbm_surface_h tbm_surface;
+ int flags;
};
struct wayland_tbm_client_resource {
- struct wl_resource *resource;
+ struct wl_resource *resource;
pid_t pid;
- char *app_name;
+ char *app_name;
struct wl_list link;
};
-static void _buffer_destroy(struct wl_client *client, struct wl_resource *resource);
+static void _buffer_destroy(struct wl_client *client,
+ struct wl_resource *resource);
static const struct wl_buffer_interface _wayland_tbm_buffer_impementation = {
- _buffer_destroy
+ _buffer_destroy
};
static void
_destroy_buffer(struct wl_resource *resource)
{
- struct wl_tbm_buffer *buffer = wl_resource_get_user_data(resource);
+ struct wl_tbm_buffer *buffer = wl_resource_get_user_data(resource);
- tbm_surface_destroy(buffer->tbm_surface);
+ tbm_surface_destroy(buffer->tbm_surface);
- free(buffer);
+ free(buffer);
}
static void
_buffer_destroy(struct wl_client *client, struct wl_resource *resource)
{
- wl_resource_destroy(resource);
+ wl_resource_destroy(resource);
}
static void
_create_buffer(struct wl_client *client, struct wl_resource *resource,
- uint32_t id,
- tbm_surface_info_s *info,
- int32_t is_fd, int32_t *names, int32_t num_name, uint32_t flags)
+ uint32_t id,
+ tbm_surface_info_s *info,
+ int32_t is_fd, int32_t *names, int32_t num_name, uint32_t flags)
{
- struct wayland_tbm_server *tbm_srv = wl_resource_get_user_data(resource);
- struct wayland_tbm_client_resource *c_res = NULL, *tmp_res = NULL;
- struct wl_tbm_buffer *buffer;
- tbm_surface_h surface;
- tbm_bo bos[TBM_SURF_PLANE_MAX];
- int i;
-
- buffer = calloc(1, sizeof *buffer);
- if (buffer == NULL) {
- wl_resource_post_no_memory(resource);
- return;
- }
-
- for (i = 0; i < num_name; i++) {
- if(is_fd) {
- bos[i] = tbm_bo_import_fd(tbm_srv->bufmgr, names[i]);
- } else {
- bos[i] = tbm_bo_import(tbm_srv->bufmgr, names[i]);
- }
- }
-
- surface = tbm_surface_internal_create_with_bos(info, bos, num_name);
- for (i = 0; i < num_name; i++)
- tbm_bo_unref(bos[i]);
-
- buffer->flags = flags;
- buffer->tbm_surface = (void*)surface;
- if (buffer->tbm_surface == NULL) {
- wl_resource_post_error(resource,
- WL_TBM_ERROR_INVALID_NAME,
- "invalid name:is_fd(%d)", is_fd);
- free(buffer);
- return;
- }
-
- /* set the debug_pid to the surface for debugging */
- if (!wl_list_empty(&tbm_srv->client_resource_list)) {
- wl_list_for_each_safe(c_res, tmp_res, &tbm_srv->client_resource_list, link) {
- if (c_res->resource == resource) {
- tbm_surface_internal_set_debug_pid(surface, c_res->pid);
- break;
- }
- }
- }
-
- buffer->resource = wl_resource_create(client, &wl_buffer_interface, 1, id);
- if (!buffer->resource) {
- wl_resource_post_no_memory(resource);
- tbm_surface_destroy(buffer->tbm_surface);
- free(buffer);
- return;
- }
-
- wl_resource_set_implementation(buffer->resource,
- (void (**)(void)) &_wayland_tbm_buffer_impementation,
- buffer, _destroy_buffer);
+ struct wayland_tbm_server *tbm_srv = wl_resource_get_user_data(resource);
+ struct wayland_tbm_client_resource *c_res = NULL, *tmp_res = NULL;
+ struct wl_tbm_buffer *buffer;
+ tbm_surface_h surface;
+ tbm_bo bos[TBM_SURF_PLANE_MAX];
+ int i;
+
+ buffer = calloc(1, sizeof * buffer);
+ if (buffer == NULL) {
+ wl_resource_post_no_memory(resource);
+ return;
+ }
+
+ for (i = 0; i < num_name; i++) {
+ if (is_fd) {
+ bos[i] = tbm_bo_import_fd(tbm_srv->bufmgr, names[i]);
+ } else {
+ bos[i] = tbm_bo_import(tbm_srv->bufmgr, names[i]);
+ }
+ }
+
+ surface = tbm_surface_internal_create_with_bos(info, bos, num_name);
+ for (i = 0; i < num_name; i++)
+ tbm_bo_unref(bos[i]);
+
+ buffer->flags = flags;
+ buffer->tbm_surface = (void *)surface;
+ if (buffer->tbm_surface == NULL) {
+ wl_resource_post_error(resource,
+ WL_TBM_ERROR_INVALID_NAME,
+ "invalid name:is_fd(%d)", is_fd);
+ free(buffer);
+ return;
+ }
+
+ /* set the debug_pid to the surface for debugging */
+ if (!wl_list_empty(&tbm_srv->client_resource_list)) {
+ wl_list_for_each_safe(c_res, tmp_res, &tbm_srv->client_resource_list, link) {
+ if (c_res->resource == resource) {
+ tbm_surface_internal_set_debug_pid(surface, c_res->pid);
+ break;
+ }
+ }
+ }
+
+ buffer->resource = wl_resource_create(client, &wl_buffer_interface, 1, id);
+ if (!buffer->resource) {
+ wl_resource_post_no_memory(resource);
+ tbm_surface_destroy(buffer->tbm_surface);
+ free(buffer);
+ return;
+ }
+
+ wl_resource_set_implementation(buffer->resource,
+ (void (* *)(void)) &_wayland_tbm_buffer_impementation,
+ buffer, _destroy_buffer);
}
static void
-_send_embedded_server_auth_info(struct wayland_tbm_client *tbm_client, struct wl_resource *resource, struct wl_display *host_dpy)
+_send_embedded_server_auth_info(struct wayland_tbm_client *tbm_client,
+ struct wl_resource *resource, struct wl_display *host_dpy)
{
- struct wl_tbm *wl_tbm = NULL;
- int fd = -1;
- uint32_t capabilities;
- const char* device_name = NULL;
-
- wl_tbm = _wayland_tbm_client_get_wl_tbm(tbm_client);
- if (!wl_tbm) {
- WL_TBM_LOG("fail to send embedded server auth infor : no wl_tbm.\n");
- return;
- }
+ struct wl_tbm *wl_tbm = NULL;
+ int fd = -1;
+ uint32_t capabilities;
+ const char *device_name = NULL;
+
+ wl_tbm = _wayland_tbm_client_get_wl_tbm(tbm_client);
+ if (!wl_tbm) {
+ WL_TBM_LOG("fail to send embedded server auth infor : no wl_tbm.\n");
+ return;
+ }
- /* get the authentication from the display server */
- wl_tbm_get_authentication_info(wl_tbm);
- wl_display_roundtrip(host_dpy);
+ /* get the authentication from the display server */
+ wl_tbm_get_authentication_info(wl_tbm);
+ wl_display_roundtrip(host_dpy);
- fd = _wayland_tbm_client_get_embedded_auth_fd(tbm_client);
- capabilities = _wayland_tbm_client_get_embedded_capability(tbm_client);
- device_name = _wayland_tbm_client_get_embedded_device_name(tbm_client);
+ fd = _wayland_tbm_client_get_embedded_auth_fd(tbm_client);
+ capabilities = _wayland_tbm_client_get_embedded_capability(tbm_client);
+ device_name = _wayland_tbm_client_get_embedded_device_name(tbm_client);
#ifdef WL_TBM_SERVER_DEBUG
- WL_TBM_LOG("[%s]: send embedded auth: device_name=%p, capabilities=%d, fd=%d\n",
- __func__, device_name, capabilities, fd);
+ WL_TBM_LOG("[%s]: send embedded auth: device_name=%p, capabilities=%d, fd=%d\n",
+ __func__, device_name, capabilities, fd);
#endif
- /* send */
- wl_tbm_send_authentication_info(resource, device_name, capabilities, fd);
+ /* send */
+ wl_tbm_send_authentication_info(resource, device_name, capabilities, fd);
- /* reset the auth information */
- _wayland_tbm_client_reset_embedded_auth_info(tbm_client);
+ /* reset the auth information */
+ _wayland_tbm_client_reset_embedded_auth_info(tbm_client);
}
static void
-_send_server_auth_info(struct wayland_tbm_server *tbm_srv, struct wl_resource *resource)
+_send_server_auth_info(struct wayland_tbm_server *tbm_srv,
+ struct wl_resource *resource)
{
- int fd = -1;
- uint32_t capabilities;
- char* device_name = NULL;
- drm_magic_t magic = 0;
-
- fd = open(tbm_srv->device_name, O_RDWR | O_CLOEXEC);
- if (fd == -1 && errno == EINVAL) {
- fd = open(tbm_srv->device_name, O_RDWR);
- if (fd != -1)
- fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
- }
-
- if (fd < 0) {
- WL_TBM_LOG("failed to open drm : device_name, %s\n", tbm_srv->device_name);
-
- wl_resource_post_error(resource, WL_TBM_ERROR_AUTHENTICATE_FAIL,
- "authenicate failed::open_drm");
- goto fini;
- }
-
- if (drmGetMagic(fd, &magic) < 0) {
- if (errno != EACCES) {
- WL_TBM_LOG("failed to get magic\n");
-
- wl_resource_post_error(resource, WL_TBM_ERROR_AUTHENTICATE_FAIL,
- "authenicate failed::get_magic");
- goto fini;
- }
- }
-
- if (drmAuthMagic(tbm_srv->fd, magic) < 0) {
- WL_TBM_LOG("failed to authenticate magic\n");
-
- wl_resource_post_error(resource, WL_TBM_ERROR_AUTHENTICATE_FAIL,
- "authenicate failed::auth_magic");
- goto fini;
- }
-
- capabilities = tbm_srv->flags;
- device_name = tbm_srv->device_name;
+ int fd = -1;
+ uint32_t capabilities;
+ char *device_name = NULL;
+ drm_magic_t magic = 0;
+
+ fd = open(tbm_srv->device_name, O_RDWR | O_CLOEXEC);
+ if (fd == -1 && errno == EINVAL) {
+ fd = open(tbm_srv->device_name, O_RDWR);
+ if (fd != -1)
+ fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
+ }
+
+ if (fd < 0) {
+ WL_TBM_LOG("failed to open drm : device_name, %s\n", tbm_srv->device_name);
+
+ wl_resource_post_error(resource, WL_TBM_ERROR_AUTHENTICATE_FAIL,
+ "authenicate failed::open_drm");
+ goto fini;
+ }
+
+ if (drmGetMagic(fd, &magic) < 0) {
+ if (errno != EACCES) {
+ WL_TBM_LOG("failed to get magic\n");
+
+ wl_resource_post_error(resource, WL_TBM_ERROR_AUTHENTICATE_FAIL,
+ "authenicate failed::get_magic");
+ goto fini;
+ }
+ }
+
+ if (drmAuthMagic(tbm_srv->fd, magic) < 0) {
+ WL_TBM_LOG("failed to authenticate magic\n");
+
+ wl_resource_post_error(resource, WL_TBM_ERROR_AUTHENTICATE_FAIL,
+ "authenicate failed::auth_magic");
+ goto fini;
+ }
+
+ capabilities = tbm_srv->flags;
+ device_name = tbm_srv->device_name;
#ifdef WL_TBM_SERVER_DEBUG
- WL_TBM_LOG("[%s]: send auth: device_name=%p, capabilities=%d, fd=%d\n",
- __func__, device_name, capabilities, fd);
+ WL_TBM_LOG("[%s]: send auth: device_name=%p, capabilities=%d, fd=%d\n",
+ __func__, device_name, capabilities, fd);
#endif
- /* send */
- wl_tbm_send_authentication_info(resource, device_name, capabilities, fd);
+ /* send */
+ wl_tbm_send_authentication_info(resource, device_name, capabilities, fd);
fini:
- if (fd >= 0)
- close(fd);
+ if (fd >= 0)
+ close(fd);
- if (device_name && device_name != tbm_srv->device_name)
- free(device_name);
+ if (device_name && device_name != tbm_srv->device_name)
+ free(device_name);
}
static void
_wayland_tbm_server_impl_request_tbm_monitor(struct wl_client *client,
- struct wl_resource *resource,
- int32_t command,
- int32_t trace_command,
- int32_t target,
- int32_t pid)
+ struct wl_resource *resource,
+ int32_t command,
+ int32_t trace_command,
+ int32_t target,
+ int32_t pid)
{
- struct wayland_tbm_server *tbm_srv = wl_resource_get_user_data(resource);
+ struct wayland_tbm_server *tbm_srv = wl_resource_get_user_data(resource);
struct wayland_tbm_client_resource *c_res = NULL, *tmp_res = NULL;
- int i = 0;
+ int i = 0;
#ifdef WL_TBM_SERVER_DEBUG
- WL_TBM_LOG("[%s]: command=%d, trace_command=%d, target=%d, pid=%d.\n", __func__,
- command, trace_command, target, pid);
+ WL_TBM_LOG("[%s]: command=%d, trace_command=%d, target=%d, pid=%d.\n", __func__,
+ command, trace_command, target, pid);
#endif
if (command == WL_TBM_MONITOR_COMMAND_LIST) {
if (!wl_list_empty(&tbm_srv->client_resource_list)) {
wl_list_for_each_safe(c_res, tmp_res, &tbm_srv->client_resource_list, link) {
- /* skip the requestor (wayland-tbm-monitor */
- if (c_res->resource == resource)
- continue;
+ /* skip the requestor (wayland-tbm-monitor */
+ if (c_res->resource == resource)
+ continue;
- if (!c_res->app_name) {
- c_res->app_name = (char*) calloc(1, 255*sizeof(char));
+ if (!c_res->app_name) {
+ c_res->app_name = (char *) calloc(1, 255 * sizeof(char));
- _wayland_tbm_util_get_appname_from_pid(c_res->pid, c_res->app_name);
- _wayland_tbm_util_get_appname_brief(c_res->app_name);
- }
+ _wayland_tbm_util_get_appname_from_pid(c_res->pid, c_res->app_name);
+ _wayland_tbm_util_get_appname_brief(c_res->app_name);
+ }
- WL_TBM_DEBUG("%-3d%-5d%s\n", ++i, c_res->pid, c_res->app_name);
+ WL_TBM_DEBUG("%-3d%-5d%s\n", ++i, c_res->pid, c_res->app_name);
}
}
return;
}
- if (target == WL_TBM_MONITOR_TARGET_CLIENT) {
- if (pid < 1) {
+ if (target == WL_TBM_MONITOR_TARGET_CLIENT) {
+ if (pid < 1) {
wl_resource_post_error(resource, WL_TBM_ERROR_INVALID_FORMAT, "invalid format");
- return;
- }
+ return;
+ }
/* send the events to all client containing wl_tbm resource except for the wayland-tbm-monitor(requestor). */
if (!wl_list_empty(&tbm_srv->client_resource_list)) {
wl_list_for_each_safe(c_res, tmp_res, &tbm_srv->client_resource_list, link) {
- /* skip the requestor (wayland-tbm-monitor */
- if (c_res->resource == resource)
- continue;
+ /* skip the requestor (wayland-tbm-monitor */
+ if (c_res->resource == resource)
+ continue;
- wl_tbm_send_monitor_client_tbm_bo(c_res->resource, command, trace_command, target, pid);
+ wl_tbm_send_monitor_client_tbm_bo(c_res->resource, command, trace_command,
+ target, pid);
}
}
} else if (target == WL_TBM_MONITOR_TARGET_SERVER) {
- if (command == WL_TBM_MONITOR_COMMAND_SHOW) {
- tbm_bufmgr_debug_show(tbm_srv->bufmgr);
- } else if (command == WL_TBM_MONITOR_COMMAND_TRACE) {
- WL_TBM_LOG("[%s]: TRACE NOT IMPLEMENTED.\n", __func__);
- } else
+ if (command == WL_TBM_MONITOR_COMMAND_SHOW) {
+ tbm_bufmgr_debug_show(tbm_srv->bufmgr);
+ } else if (command == WL_TBM_MONITOR_COMMAND_TRACE) {
+ WL_TBM_LOG("[%s]: TRACE NOT IMPLEMENTED.\n", __func__);
+ } else
wl_resource_post_error(resource, WL_TBM_ERROR_INVALID_FORMAT,
- "invalid format");
+ "invalid format");
} else if (target == WL_TBM_MONITOR_TARGET_ALL) {
- if (command == WL_TBM_MONITOR_COMMAND_SHOW) {
- /* send the events to all client containing wl_tbm resource except for the wayland-tbm-monitor(requestor). */
+ if (command == WL_TBM_MONITOR_COMMAND_SHOW) {
+ /* send the events to all client containing wl_tbm resource except for the wayland-tbm-monitor(requestor). */
if (!wl_list_empty(&tbm_srv->client_resource_list)) {
wl_list_for_each_safe(c_res, tmp_res, &tbm_srv->client_resource_list, link) {
/* skip the requestor (wayland-tbm-monitor */
if (c_res->resource == resource)
continue;
- wl_tbm_send_monitor_client_tbm_bo(c_res->resource, command, trace_command, target, pid);
+ wl_tbm_send_monitor_client_tbm_bo(c_res->resource, command, trace_command,
+ target, pid);
}
}
tbm_bufmgr_debug_show(tbm_srv->bufmgr);
- }
- else if (command == WL_TBM_MONITOR_COMMAND_TRACE) {
- wl_tbm_send_monitor_client_tbm_bo(resource, command, trace_command, target, pid);
+ } else if (command == WL_TBM_MONITOR_COMMAND_TRACE) {
+ wl_tbm_send_monitor_client_tbm_bo(resource, command, trace_command, target,
+ pid);
WL_TBM_LOG("[%s]: TRACE NOT IMPLEMENTED.\n", __func__);
- }
- else
+ } else
wl_resource_post_error(resource, WL_TBM_ERROR_INVALID_FORMAT,
- "invalid format");
+ "invalid format");
} else
wl_resource_post_error(resource, WL_TBM_ERROR_INVALID_FORMAT,
- "invalid format");
+ "invalid format");
}
static void
_wayland_tbm_server_impl_get_authentication_info(struct wl_client *client,
- struct wl_resource *resource)
+ struct wl_resource *resource)
{
- struct wayland_tbm_server *tbm_srv = wl_resource_get_user_data(resource);
-
- /* if display server is the client of the host display server, for embedded server */
- if (tbm_srv->tbm_client) {
- _send_embedded_server_auth_info(tbm_srv->tbm_client, resource, tbm_srv->host_dpy);
- } else {
- _send_server_auth_info(tbm_srv, resource);
- }
+ struct wayland_tbm_server *tbm_srv = wl_resource_get_user_data(resource);
+
+ /* if display server is the client of the host display server, for embedded server */
+ if (tbm_srv->tbm_client) {
+ _send_embedded_server_auth_info(tbm_srv->tbm_client, resource,
+ tbm_srv->host_dpy);
+ } else {
+ _send_server_auth_info(tbm_srv, resource);
+ }
}
static void
_wayland_tbm_server_impl_create_buffer(struct wl_client *client,
- struct wl_resource *resource,
- uint32_t id,
- int32_t width, int32_t height, uint32_t format, int32_t num_plane,
- int32_t buf_idx0, int32_t offset0, int32_t stride0,
- int32_t buf_idx1, int32_t offset1, int32_t stride1,
- int32_t buf_idx2, int32_t offset2, int32_t stride2,
- uint32_t flags,
- int32_t num_buf, uint32_t buf0, uint32_t buf1, uint32_t buf2)
+ struct wl_resource *resource,
+ uint32_t id,
+ int32_t width, int32_t height, uint32_t format, int32_t num_plane,
+ int32_t buf_idx0, int32_t offset0, int32_t stride0,
+ int32_t buf_idx1, int32_t offset1, int32_t stride1,
+ int32_t buf_idx2, int32_t offset2, int32_t stride2,
+ uint32_t flags,
+ int32_t num_buf, uint32_t buf0, uint32_t buf1, uint32_t buf2)
{
- int32_t names[TBM_SURF_PLANE_MAX] = {-1, -1, -1, -1};
- tbm_surface_info_s info;
- int bpp;
- int numPlane, numName = 0;
+ int32_t names[TBM_SURF_PLANE_MAX] = { -1, -1, -1, -1};
+ tbm_surface_info_s info;
+ int bpp;
+ int numPlane, numName = 0;
#ifdef WL_TBM_SERVER_DEBUG
- WL_TBM_LOG("[%s]: trying.\n", __func__);
+ WL_TBM_LOG("[%s]: trying.\n", __func__);
#endif
- bpp = tbm_surface_internal_get_bpp(format);
- numPlane = tbm_surface_internal_get_num_planes(format);
- if (numPlane != num_plane) {
- wl_resource_post_error(resource, WL_TBM_ERROR_INVALID_FORMAT,
- "invalid format");
- return;
- }
+ bpp = tbm_surface_internal_get_bpp(format);
+ numPlane = tbm_surface_internal_get_num_planes(format);
+ if (numPlane != num_plane) {
+ wl_resource_post_error(resource, WL_TBM_ERROR_INVALID_FORMAT,
+ "invalid format");
+ return;
+ }
memset(&info, 0x0, sizeof(tbm_surface_info_s));
- info.width = width;
- info.height = height;
- info.format = format;
- info.bpp = bpp;
- info.num_planes = numPlane;
-
- /*Fill plane info*/
- if (numPlane > 0) {
- info.planes[0].offset = offset0;
- info.planes[0].stride = stride0;
- numPlane--;
- }
-
- if (numPlane > 0) {
- info.planes[1].offset = offset1;
- info.planes[1].stride = stride1;
- numPlane--;
- }
-
- if (numPlane > 0) {
- info.planes[2].offset = offset2;
- info.planes[2].stride = stride2;
- numPlane--;
- }
-
- /*Fill buffer*/
- numName = num_buf;
- names[0] = buf0;
- names[1] = buf1;
- names[2] = buf2;
-
- _create_buffer(client, resource, id, &info, 0, names, numName, flags);
+ info.width = width;
+ info.height = height;
+ info.format = format;
+ info.bpp = bpp;
+ info.num_planes = numPlane;
+
+ /*Fill plane info*/
+ if (numPlane > 0) {
+ info.planes[0].offset = offset0;
+ info.planes[0].stride = stride0;
+ numPlane--;
+ }
+
+ if (numPlane > 0) {
+ info.planes[1].offset = offset1;
+ info.planes[1].stride = stride1;
+ numPlane--;
+ }
+
+ if (numPlane > 0) {
+ info.planes[2].offset = offset2;
+ info.planes[2].stride = stride2;
+ numPlane--;
+ }
+
+ /*Fill buffer*/
+ numName = num_buf;
+ names[0] = buf0;
+ names[1] = buf1;
+ names[2] = buf2;
+
+ _create_buffer(client, resource, id, &info, 0, names, numName, flags);
}
static void
_wayland_tbm_server_impl_create_buffer_with_fd(struct wl_client *client,
- struct wl_resource *resource,
- uint32_t id,
- int32_t width, int32_t height, uint32_t format, int num_plane,
- int32_t buf_idx0, int32_t offset0, int32_t stride0,
- int32_t buf_idx1, int32_t offset1, int32_t stride1,
- int32_t buf_idx2, int32_t offset2, int32_t stride2,
- uint32_t flags,
- int32_t num_buf, int32_t buf0, int32_t buf1, int32_t buf2)
+ struct wl_resource *resource,
+ uint32_t id,
+ int32_t width, int32_t height, uint32_t format, int num_plane,
+ int32_t buf_idx0, int32_t offset0, int32_t stride0,
+ int32_t buf_idx1, int32_t offset1, int32_t stride1,
+ int32_t buf_idx2, int32_t offset2, int32_t stride2,
+ uint32_t flags,
+ int32_t num_buf, int32_t buf0, int32_t buf1, int32_t buf2)
{
- int32_t names[TBM_SURF_PLANE_MAX] = {0, 0, 0, 0};
- tbm_surface_info_s info;
- int bpp;
- int numPlane, numName = 0;
+ int32_t names[TBM_SURF_PLANE_MAX] = {0, 0, 0, 0};
+ tbm_surface_info_s info;
+ int bpp;
+ int numPlane, numName = 0;
#ifdef WL_TBM_SERVER_DEBUG
- WL_TBM_LOG("[%s]: trying.\n", __func__);
+ WL_TBM_LOG("[%s]: trying.\n", __func__);
#endif
- bpp = tbm_surface_internal_get_bpp(format);
- numPlane = tbm_surface_internal_get_num_planes(format);
- if (numPlane != num_plane) {
- wl_resource_post_error(resource, WL_TBM_ERROR_INVALID_FORMAT,
- "invalid format");
- return;
- }
+ bpp = tbm_surface_internal_get_bpp(format);
+ numPlane = tbm_surface_internal_get_num_planes(format);
+ if (numPlane != num_plane) {
+ wl_resource_post_error(resource, WL_TBM_ERROR_INVALID_FORMAT,
+ "invalid format");
+ return;
+ }
memset(&info, 0x0, sizeof(tbm_surface_info_s));
- info.width = width;
- info.height = height;
- info.format = format;
- info.bpp = bpp;
- info.num_planes = numPlane;
-
- /*Fill plane info*/
- if (numPlane > 0) {
- info.planes[0].offset = offset0;
- info.planes[0].stride = stride0;
- numPlane--;
- }
-
- if (numPlane > 0) {
- info.planes[1].offset = offset1;
- info.planes[1].stride = stride1;
- numPlane--;
- }
-
- if (numPlane > 0) {
- info.planes[2].offset = offset2;
- info.planes[2].stride = stride2;
- numPlane--;
- }
-
- /*Fill buffer*/
- numName = num_buf;
- names[0] = buf0;
- names[1] = buf1;
- names[2] = buf2;
-
- _create_buffer(client, resource, id, &info, 1, names, numName, flags);
-
- close(buf0);
- close(buf1);
- close(buf2);
+ info.width = width;
+ info.height = height;
+ info.format = format;
+ info.bpp = bpp;
+ info.num_planes = numPlane;
+
+ /*Fill plane info*/
+ if (numPlane > 0) {
+ info.planes[0].offset = offset0;
+ info.planes[0].stride = stride0;
+ numPlane--;
+ }
+
+ if (numPlane > 0) {
+ info.planes[1].offset = offset1;
+ info.planes[1].stride = stride1;
+ numPlane--;
+ }
+
+ if (numPlane > 0) {
+ info.planes[2].offset = offset2;
+ info.planes[2].stride = stride2;
+ numPlane--;
+ }
+
+ /*Fill buffer*/
+ numName = num_buf;
+ names[0] = buf0;
+ names[1] = buf1;
+ names[2] = buf2;
+
+ _create_buffer(client, resource, id, &info, 1, names, numName, flags);
+
+ close(buf0);
+ close(buf1);
+ close(buf2);
}
static const struct wl_tbm_interface _wayland_tbm_server_implementation = {
- _wayland_tbm_server_impl_create_buffer,
- _wayland_tbm_server_impl_create_buffer_with_fd,
- _wayland_tbm_server_impl_get_authentication_info,
- _wayland_tbm_server_impl_request_tbm_monitor,
+ _wayland_tbm_server_impl_create_buffer,
+ _wayland_tbm_server_impl_create_buffer_with_fd,
+ _wayland_tbm_server_impl_get_authentication_info,
+ _wayland_tbm_server_impl_request_tbm_monitor,
};
static void
_wayland_tbm_server_destroy_resource (struct wl_resource *resource)
{
- struct wayland_tbm_server *tbm_srv = NULL;
- struct wayland_tbm_client_resource *c_res = NULL, *tmp_res;
+ struct wayland_tbm_server *tbm_srv = NULL;
+ struct wayland_tbm_client_resource *c_res = NULL, *tmp_res;
- /* remove the client resources to the list */
- tbm_srv = wl_resource_get_user_data(resource);
+ /* remove the client resources to the list */
+ tbm_srv = wl_resource_get_user_data(resource);
if (!wl_list_empty(&tbm_srv->client_resource_list)) {
wl_list_for_each_safe(c_res, tmp_res, &tbm_srv->client_resource_list, link) {
if (c_res->resource == resource) {
#ifdef WL_TBM_SERVER_DEBUG
- WL_TBM_LOG("[%s]: resource,%p pid,%d \n", __func__, c_res->resource, c_res->pid);
+ WL_TBM_LOG("[%s]: resource,%p pid,%d \n", __func__, c_res->resource,
+ c_res->pid);
#endif
wl_list_remove(&c_res->link);
- if (c_res->app_name)
- free(c_res->app_name);
- free(c_res);
+ if (c_res->app_name)
+ free(c_res->app_name);
+ free(c_res);
break;
- }
+ }
}
}
}
static void
-_wayland_tbm_server_bind_cb(struct wl_client *client, void *data, uint32_t version,
- uint32_t id)
+_wayland_tbm_server_bind_cb(struct wl_client *client, void *data,
+ uint32_t version,
+ uint32_t id)
{
- struct wayland_tbm_server *tbm_srv = NULL;
+ struct wayland_tbm_server *tbm_srv = NULL;
struct wayland_tbm_client_resource *c_res = NULL;
- struct wl_resource *resource;
+ struct wl_resource *resource;
pid_t pid = 0;
- uid_t uid = 0;
- gid_t gid = 0;
+ uid_t uid = 0;
+ gid_t gid = 0;
- resource = wl_resource_create(client, &wl_tbm_interface, MIN(version, 1), id);
- if (!resource) {
- wl_client_post_no_memory(client);
- return;
- }
+ resource = wl_resource_create(client, &wl_tbm_interface, MIN(version, 1), id);
+ if (!resource) {
+ wl_client_post_no_memory(client);
+ return;
+ }
- wl_resource_set_implementation(resource,
- &_wayland_tbm_server_implementation,
- data,
- _wayland_tbm_server_destroy_resource);
+ wl_resource_set_implementation(resource,
+ &_wayland_tbm_server_implementation,
+ data,
+ _wayland_tbm_server_destroy_resource);
- /* add the client resources to the list */
- tbm_srv = wl_resource_get_user_data(resource);
+ /* add the client resources to the list */
+ tbm_srv = wl_resource_get_user_data(resource);
wl_client_get_credentials(client, &pid, &uid, &gid);
#ifdef WL_TBM_SERVER_DEBUG
- WL_TBM_LOG("[%s]: resource,%p pid,%d \n", __func__, resource, pid);
+ WL_TBM_LOG("[%s]: resource,%p pid,%d \n", __func__, resource, pid);
#endif
- c_res = calloc (1, sizeof(struct wayland_tbm_client_resource));
- c_res->pid = pid;
- c_res->resource = resource;
- wl_list_insert(&tbm_srv->client_resource_list, &c_res->link);
+ c_res = calloc (1, sizeof(struct wayland_tbm_client_resource));
+ c_res->pid = pid;
+ c_res->resource = resource;
+ wl_list_insert(&tbm_srv->client_resource_list, &c_res->link);
}
struct wayland_tbm_server *
-wayland_tbm_server_init(struct wl_display *display, const char *device_name, int fd,
- uint32_t flags)
+wayland_tbm_server_init(struct wl_display *display, const char *device_name,
+ int fd,
+ uint32_t flags)
{
- struct wayland_tbm_server *tbm_srv;
+ struct wayland_tbm_server *tbm_srv;
- tbm_srv = calloc(1, sizeof(struct wayland_tbm_server));
- WL_TBM_RETURN_VAL_IF_FAIL(tbm_srv != NULL, NULL);
+ tbm_srv = calloc(1, sizeof(struct wayland_tbm_server));
+ WL_TBM_RETURN_VAL_IF_FAIL(tbm_srv != NULL, NULL);
- tbm_srv->display = display;
- tbm_srv->device_name = strdup(device_name);
- tbm_srv->fd = fd;
- tbm_srv->flags = flags;
+ tbm_srv->display = display;
+ tbm_srv->device_name = strdup(device_name);
+ tbm_srv->fd = fd;
+ tbm_srv->flags = flags;
- /* init the client resource list */
+ /* init the client resource list */
wl_list_init(&tbm_srv->client_resource_list);
- //init bufmgr
- tbm_srv->bufmgr = tbm_bufmgr_init(tbm_srv->fd);
- if (!tbm_srv->bufmgr) {
- if (tbm_srv->device_name)
- free(tbm_srv->device_name);
- free(tbm_srv);
- return NULL;
- }
+ //init bufmgr
+ tbm_srv->bufmgr = tbm_bufmgr_init(tbm_srv->fd);
+ if (!tbm_srv->bufmgr) {
+ if (tbm_srv->device_name)
+ free(tbm_srv->device_name);
+ free(tbm_srv);
+ return NULL;
+ }
- tbm_srv->wl_tbm_global = wl_global_create(display, &wl_tbm_interface, 1,
- tbm_srv, _wayland_tbm_server_bind_cb);
+ tbm_srv->wl_tbm_global = wl_global_create(display, &wl_tbm_interface, 1,
+ tbm_srv, _wayland_tbm_server_bind_cb);
- return tbm_srv;
+ return tbm_srv;
}
struct wayland_tbm_server *
-wayland_tbm_server_embedded_init(struct wl_display *display, struct wl_display *host_display)
+wayland_tbm_server_embedded_init(struct wl_display *display,
+ struct wl_display *host_display)
{
- struct wayland_tbm_server *tbm_srv;
- struct wayland_tbm_client *tbm_client;
-
- tbm_client = wayland_tbm_client_init(host_display);
- WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, NULL);
-
- tbm_srv = calloc(1, sizeof *tbm_srv);
- if (!tbm_srv) {
- wayland_tbm_client_deinit(tbm_client);
- return NULL;
- }
-
- tbm_srv->display = display;
- tbm_srv->device_name = strdup(wayland_tbm_client_get_device_name(tbm_client));
- tbm_srv->fd = _wayland_tbm_client_get_auth_fd(tbm_client); // TODO: check dup or not????
- tbm_srv->flags = wayland_tbm_client_get_capability(tbm_client);
- tbm_srv->bufmgr = tbm_bufmgr_init(-1);
- tbm_srv->tbm_client = tbm_client;
- tbm_srv->host_dpy = host_display;
- tbm_srv->wl_tbm = _wayland_tbm_client_get_wl_tbm(tbm_client);
-
- tbm_srv->wl_tbm_global = wl_global_create(display, &wl_tbm_interface, 1,
- tbm_srv, _wayland_tbm_server_bind_cb);
-
- return tbm_srv;
+ struct wayland_tbm_server *tbm_srv;
+ struct wayland_tbm_client *tbm_client;
+
+ tbm_client = wayland_tbm_client_init(host_display);
+ WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, NULL);
+
+ tbm_srv = calloc(1, sizeof * tbm_srv);
+ if (!tbm_srv) {
+ wayland_tbm_client_deinit(tbm_client);
+ return NULL;
+ }
+
+ tbm_srv->display = display;
+ tbm_srv->device_name = strdup(wayland_tbm_client_get_device_name(tbm_client));
+ tbm_srv->fd = _wayland_tbm_client_get_auth_fd(
+ tbm_client); // TODO: check dup or not????
+ tbm_srv->flags = wayland_tbm_client_get_capability(tbm_client);
+ tbm_srv->bufmgr = tbm_bufmgr_init(-1);
+ tbm_srv->tbm_client = tbm_client;
+ tbm_srv->host_dpy = host_display;
+ tbm_srv->wl_tbm = _wayland_tbm_client_get_wl_tbm(tbm_client);
+
+ tbm_srv->wl_tbm_global = wl_global_create(display, &wl_tbm_interface, 1,
+ tbm_srv, _wayland_tbm_server_bind_cb);
+
+ return tbm_srv;
}
void
wayland_tbm_server_deinit(struct wayland_tbm_server *tbm_srv)
{
- if (tbm_srv->tbm_client)
- wayland_tbm_client_deinit(tbm_srv->tbm_client);
+ if (tbm_srv->tbm_client)
+ wayland_tbm_client_deinit(tbm_srv->tbm_client);
- wl_global_destroy(tbm_srv->wl_tbm_global);
+ wl_global_destroy(tbm_srv->wl_tbm_global);
- tbm_bufmgr_deinit(tbm_srv->bufmgr);
+ tbm_bufmgr_deinit(tbm_srv->bufmgr);
- if (tbm_srv->device_name)
- free(tbm_srv->device_name);
+ if (tbm_srv->device_name)
+ free(tbm_srv->device_name);
- free(tbm_srv);
+ free(tbm_srv);
}
tbm_surface_h
-wayland_tbm_server_get_surface(struct wayland_tbm_server *tbm_srv, struct wl_resource *resource)
+wayland_tbm_server_get_surface(struct wayland_tbm_server *tbm_srv,
+ struct wl_resource *resource)
{
- struct wl_tbm_buffer *wl_buffer;
+ struct wl_tbm_buffer *wl_buffer;
- if (resource == NULL)
- return NULL;
+ if (resource == NULL)
+ return NULL;
- if (wl_resource_instance_of(resource, &wl_buffer_interface,
- &_wayland_tbm_buffer_impementation)) {
- wl_buffer = wl_resource_get_user_data(resource);
- return wl_buffer->tbm_surface;
- }
+ if (wl_resource_instance_of(resource, &wl_buffer_interface,
+ &_wayland_tbm_buffer_impementation)) {
+ wl_buffer = wl_resource_get_user_data(resource);
+ return wl_buffer->tbm_surface;
+ }
- return NULL;
+ return NULL;
}
void *
wayland_tbm_server_get_bufmgr(struct wayland_tbm_server *tbm_srv)
{
- if (tbm_srv == NULL)
- return NULL;
+ if (tbm_srv == NULL)
+ return NULL;
- return (void *)tbm_srv->bufmgr;
+ return (void *)tbm_srv->bufmgr;
}
struct wayland_tbm_server;
-struct wayland_tbm_server *wayland_tbm_server_init(struct wl_display *display, const char *device_name, int fd, uint32_t flags);
-struct wayland_tbm_server *wayland_tbm_server_embedded_init(struct wl_display *embedded, struct wl_display *host);
-void wayland_tbm_server_deinit(struct wayland_tbm_server *tbm_srv);
-
-
-void *wayland_tbm_server_get_bufmgr(struct wayland_tbm_server *tbm_srv);
-tbm_surface_h wayland_tbm_server_get_surface(struct wayland_tbm_server *tbm_srv, struct wl_resource *resource);
+struct wayland_tbm_server *wayland_tbm_server_init(struct wl_display *display,
+ const char *device_name, int fd, uint32_t flags);
+struct wayland_tbm_server *wayland_tbm_server_embedded_init(
+ struct wl_display *embedded, struct wl_display *host);
+void wayland_tbm_server_deinit(struct wayland_tbm_server
+ *tbm_srv);
+
+
+void *wayland_tbm_server_get_bufmgr(struct wayland_tbm_server
+ *tbm_srv);
+tbm_surface_h wayland_tbm_server_get_surface(struct wayland_tbm_server
+ *tbm_srv, struct wl_resource *resource);
#ifdef __cplusplus
void
_wayland_tbm_util_get_appname_brief(char *brief)
{
- char delim[] = "/";
- char *token = NULL;
- char temp[255] = {0,};
- char *saveptr = NULL;
+ char delim[] = "/";
+ char *token = NULL;
+ char temp[255] = {0,};
+ char *saveptr = NULL;
- token = strtok_r(brief, delim, &saveptr);
+ token = strtok_r(brief, delim, &saveptr);
- while (token != NULL) {
- memset(temp, 0x00, 255*sizeof(char));
- strncpy(temp, token, 254*sizeof(char));
- token = strtok_r(NULL, delim, &saveptr);
- }
+ while (token != NULL) {
+ memset(temp, 0x00, 255 * sizeof(char));
+ strncpy(temp, token, 254 * sizeof(char));
+ token = strtok_r(NULL, delim, &saveptr);
+ }
- snprintf(brief, sizeof(temp), "%s", temp);
+ snprintf(brief, sizeof(temp), "%s", temp);
}
void
_wayland_tbm_util_get_appname_from_pid(long pid, char *str)
{
- FILE* fp;
- int len;
- long app_pid = pid;
- char fn_cmdline[255] = {0,};
- char cmdline[255] = {0,};
-
- snprintf(fn_cmdline, sizeof(fn_cmdline), "/proc/%ld/cmdline",app_pid);
-
- fp = fopen(fn_cmdline, "r");
- if(fp == 0) {
- fprintf(stderr,"cannot file open /proc/%ld/cmdline", app_pid);
- return;
- }
-
- if (!fgets(cmdline, 255, fp)) {
- fprintf(stderr, "fail to get appname for pid(%ld)\n", app_pid);
- fclose(fp);
- return;
- }
- fclose(fp);
-
- len = strlen(cmdline);
- if(len < 1)
- memset(cmdline, 0x00,255);
- else
- cmdline[len] = 0;
-
- snprintf(str, sizeof(cmdline), "%s", cmdline);
+ FILE *fp;
+ int len;
+ long app_pid = pid;
+ char fn_cmdline[255] = {0,};
+ char cmdline[255] = {0,};
+
+ snprintf(fn_cmdline, sizeof(fn_cmdline), "/proc/%ld/cmdline", app_pid);
+
+ fp = fopen(fn_cmdline, "r");
+ if (fp == 0) {
+ fprintf(stderr, "cannot file open /proc/%ld/cmdline", app_pid);
+ return;
+ }
+
+ if (!fgets(cmdline, 255, fp)) {
+ fprintf(stderr, "fail to get appname for pid(%ld)\n", app_pid);
+ fclose(fp);
+ return;
+ }
+ fclose(fp);
+
+ len = strlen(cmdline);
+ if (len < 1)
+ memset(cmdline, 0x00, 255);
+ else
+ cmdline[len] = 0;
+
+ snprintf(str, sizeof(cmdline), "%s", cmdline);
}
#include <wayland-tbm-client-protocol.h>
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
- struct wl_display *dpy = NULL;
- const char *dpy_name = NULL;
- struct wayland_tbm_client *tbm_client = NULL;
- tbm_surface_h tbm_surf = NULL;
- struct wl_buffer *buf = NULL;
- int res = -1;
+ struct wl_display *dpy = NULL;
+ const char *dpy_name = NULL;
+ struct wayland_tbm_client *tbm_client = NULL;
+ tbm_surface_h tbm_surf = NULL;
+ struct wl_buffer *buf = NULL;
+ int res = -1;
- if (argc > 0) {
- dpy_name = argv[1];
- printf("[APP] Connect to %s\n", dpy_name);
- }
+ if (argc > 0) {
+ dpy_name = argv[1];
+ printf("[APP] Connect to %s\n", dpy_name);
+ }
- dpy = wl_display_connect(dpy_name);
- if (!dpy) {
- printf("[APP] failed to connect server\n");
- return -1;
- }
+ dpy = wl_display_connect(dpy_name);
+ if (!dpy) {
+ printf("[APP] failed to connect server\n");
+ return -1;
+ }
- tbm_client = wayland_tbm_client_init(dpy);
- if (!tbm_client) {
- printf("[APP] failed to client init\n");
- goto finish;
- }
+ tbm_client = wayland_tbm_client_init(dpy);
+ if (!tbm_client) {
+ printf("[APP] failed to client init\n");
+ goto finish;
+ }
- tbm_surf = tbm_surface_create(100, 100, TBM_FORMAT_ABGR8888);
- if (!tbm_surf) {
- printf("[APP] failed to tbm_surface_create\n");
- goto finish;
- }
+ tbm_surf = tbm_surface_create(100, 100, TBM_FORMAT_ABGR8888);
+ if (!tbm_surf) {
+ printf("[APP] failed to tbm_surface_create\n");
+ goto finish;
+ }
- buf = wayland_tbm_client_create_buffer(tbm_client, tbm_surf);
- if (!buf) {
- printf("[APP] failed to wayland_tbm_client_create_buffer\n");
- goto finish;
- }
- wl_display_flush(dpy);
+ buf = wayland_tbm_client_create_buffer(tbm_client, tbm_surf);
+ if (!buf) {
+ printf("[APP] failed to wayland_tbm_client_create_buffer\n");
+ goto finish;
+ }
+ wl_display_flush(dpy);
- tbm_surface_destroy(tbm_surf);
- wayland_tbm_client_destroy_buffer(tbm_client, buf);
+ tbm_surface_destroy(tbm_surf);
+ wayland_tbm_client_destroy_buffer(tbm_client, buf);
- tbm_surf = NULL;
- buf = NULL;
+ tbm_surf = NULL;
+ buf = NULL;
- tbm_surf = tbm_surface_create(200, 200, TBM_FORMAT_NV12);
- if (!tbm_surf) {
- printf("[APP] failed to tbm_surface_create\n");
- goto finish;
- }
+ tbm_surf = tbm_surface_create(200, 200, TBM_FORMAT_NV12);
+ if (!tbm_surf) {
+ printf("[APP] failed to tbm_surface_create\n");
+ goto finish;
+ }
- buf = wayland_tbm_client_create_buffer(tbm_client, tbm_surf);
- if (!buf) {
- printf("[APP] failed to wayland_tbm_client_create_buffer\n");
- goto finish;
- }
- wl_display_flush(dpy);
+ buf = wayland_tbm_client_create_buffer(tbm_client, tbm_surf);
+ if (!buf) {
+ printf("[APP] failed to wayland_tbm_client_create_buffer\n");
+ goto finish;
+ }
+ wl_display_flush(dpy);
- while (1) {
- if (0 > wl_display_dispatch(dpy))
- break;
- }
+ while (1) {
+ if (0 > wl_display_dispatch(dpy))
+ break;
+ }
- res = 0;
+ res = 0;
finish:
- if (buf) wayland_tbm_client_destroy_buffer(tbm_client, buf);
- if (tbm_surf) tbm_surface_destroy(tbm_surf);
- if (tbm_client) wayland_tbm_client_deinit(tbm_client);
- if (dpy) wl_display_disconnect(dpy);
+ if (buf) wayland_tbm_client_destroy_buffer(tbm_client, buf);
+ if (tbm_surf) tbm_surface_destroy(tbm_surf);
+ if (tbm_client) wayland_tbm_client_deinit(tbm_client);
+ if (dpy) wl_display_disconnect(dpy);
- return res;
+ return res;
}
int
main(int argc, char *argv[])
{
- struct wl_display *dpy;
- struct wayland_tbm_server *tbm_server;
- int fd;
- const char *dev_name;
- const char *dpy_name;
-
- dpy = wl_display_create();
- if (!dpy) {
- printf("[SRV] failed to create display\n");
- return -1;
- }
-
- dpy_name = wl_display_add_socket_auto(dpy);
- printf("[SRV] wl_display : %s\n", dpy_name);
-
- fd = drmOpen("exynos", NULL);
- if (fd < 0) {
- printf("[SRV] failed to open drm\n");
- wl_display_destroy(dpy);
- return -1;
- }
-
- dev_name = drmGetDeviceNameFromFd(fd);
- printf("[SRV] drm_device: %s\n", dev_name);
-
- tbm_server = wayland_tbm_server_init(dpy, dev_name, fd, 0);
- if (!tbm_server) {
- printf("[SRV] failed to tbm_server init\n");
- wl_display_destroy(dpy);
- close(fd);
- return -1;
- }
-
- wl_display_run(dpy);
-
- return 0;
+ struct wl_display *dpy;
+ struct wayland_tbm_server *tbm_server;
+ int fd;
+ const char *dev_name;
+ const char *dpy_name;
+
+ dpy = wl_display_create();
+ if (!dpy) {
+ printf("[SRV] failed to create display\n");
+ return -1;
+ }
+
+ dpy_name = wl_display_add_socket_auto(dpy);
+ printf("[SRV] wl_display : %s\n", dpy_name);
+
+ fd = drmOpen("exynos", NULL);
+ if (fd < 0) {
+ printf("[SRV] failed to open drm\n");
+ wl_display_destroy(dpy);
+ return -1;
+ }
+
+ dev_name = drmGetDeviceNameFromFd(fd);
+ printf("[SRV] drm_device: %s\n", dev_name);
+
+ tbm_server = wayland_tbm_server_init(dpy, dev_name, fd, 0);
+ if (!tbm_server) {
+ printf("[SRV] failed to tbm_server init\n");
+ wl_display_destroy(dpy);
+ close(fd);
+ return -1;
+ }
+
+ wl_display_run(dpy);
+
+ return 0;
}
static struct wl_display *
_connect_remote(int argc, char *argv[])
{
- struct wl_display *dpy;
- const char *dpy_name = NULL;
+ struct wl_display *dpy;
+ const char *dpy_name = NULL;
- if (argc > 0) {
- dpy_name = argv[1];
- printf("[APP] Connect to %s\n", dpy_name);
- }
+ if (argc > 0) {
+ dpy_name = argv[1];
+ printf("[APP] Connect to %s\n", dpy_name);
+ }
- dpy = wl_display_connect(dpy_name);
- if (!dpy) {
- printf("[APP] failed to connect server\n");
- }
+ dpy = wl_display_connect(dpy_name);
+ if (!dpy) {
+ printf("[APP] failed to connect server\n");
+ }
- return dpy;
+ return dpy;
}
int
main(int argc, char *argv[])
{
- struct wl_display *dpy;
- struct wl_display *host;
- struct wayland_tbm_server *tbm_server;
- const char *dpy_name;
- void *bufmgr;
+ struct wl_display *dpy;
+ struct wl_display *host;
+ struct wayland_tbm_server *tbm_server;
+ const char *dpy_name;
+ void *bufmgr;
- dpy = wl_display_create();
- if (!dpy) {
- printf("[SRV] failed to create display\n");
- return -1;
- }
+ dpy = wl_display_create();
+ if (!dpy) {
+ printf("[SRV] failed to create display\n");
+ return -1;
+ }
- dpy_name = wl_display_add_socket_auto(dpy);
- printf("[SRV] wl_display : %s\n", dpy_name);
+ dpy_name = wl_display_add_socket_auto(dpy);
+ printf("[SRV] wl_display : %s\n", dpy_name);
- host = _connect_remote(argc, argv);
- if (!host) {
- printf("[SRV] failed to connect host\n");
- wl_display_destroy(dpy);
- return -1;
- }
+ host = _connect_remote(argc, argv);
+ if (!host) {
+ printf("[SRV] failed to connect host\n");
+ wl_display_destroy(dpy);
+ return -1;
+ }
- tbm_server = wayland_tbm_server_embedded_init(dpy, host);
- if (!tbm_server) {
- printf("[SRV] failed to initialize tbm embedded server\n");
- wl_display_destroy(dpy);
- return -1;
- }
+ tbm_server = wayland_tbm_server_embedded_init(dpy, host);
+ if (!tbm_server) {
+ printf("[SRV] failed to initialize tbm embedded server\n");
+ wl_display_destroy(dpy);
+ return -1;
+ }
- bufmgr = wayland_tbm_server_get_bufmgr(tbm_server);
- printf("[SRV] bufmgr:%p\n", bufmgr);
+ bufmgr = wayland_tbm_server_get_bufmgr(tbm_server);
+ printf("[SRV] bufmgr:%p\n", bufmgr);
- wl_display_run(dpy);
+ wl_display_run(dpy);
- return 0;
+ return 0;
}
//#define WL_TBM_MONITOR_DEBUG
-struct wayland_tbm_monitor
-{
- struct wl_display *dpy;
- struct wl_tbm *wl_tbm;
+struct wayland_tbm_monitor {
+ struct wl_display *dpy;
+ struct wl_tbm *wl_tbm;
- struct {
+ struct {
WL_TBM_MONITOR_COMMAND command;
WL_TBM_MONITOR_TRACE_COMMAND trace_command;
WL_TBM_MONITOR_TARGET target;
int pid;
- } options;
+ } options;
};
static const struct wl_tbm_listener wl_tbm_monitor_listener = {
- NULL, /* authentication_info */
+ NULL, /* authentication_info */
NULL, /* monitor_client_tbm_bo */
};
static void
_wayland_tbm_monitor_registry_handle_global(void *data,
- struct wl_registry *registry,
- uint32_t name,
- const char *interface,
- uint32_t version)
+ struct wl_registry *registry,
+ uint32_t name,
+ const char *interface,
+ uint32_t version)
{
- struct wayland_tbm_monitor *tbm_monitor = (struct wayland_tbm_monitor *)data;
+ struct wayland_tbm_monitor *tbm_monitor = (struct wayland_tbm_monitor *)data;
- if (!strcmp(interface, "wl_tbm")) {
- tbm_monitor->wl_tbm = wl_registry_bind(registry, name, &wl_tbm_interface, version);
- WL_TBM_RETURN_IF_FAIL(tbm_monitor->wl_tbm != NULL);
+ if (!strcmp(interface, "wl_tbm")) {
+ tbm_monitor->wl_tbm = wl_registry_bind(registry, name, &wl_tbm_interface,
+ version);
+ WL_TBM_RETURN_IF_FAIL(tbm_monitor->wl_tbm != NULL);
- wl_tbm_add_listener(tbm_monitor->wl_tbm, &wl_tbm_monitor_listener, tbm_monitor);
+ wl_tbm_add_listener(tbm_monitor->wl_tbm, &wl_tbm_monitor_listener, tbm_monitor);
- /* request the tbm monitor */
+ /* request the tbm monitor */
wl_tbm_request_tbm_monitor(tbm_monitor->wl_tbm,
- tbm_monitor->options.command,
- tbm_monitor->options.trace_command,
- tbm_monitor->options.target,
- tbm_monitor->options.pid);
- wl_display_roundtrip(tbm_monitor->dpy);
- }
+ tbm_monitor->options.command,
+ tbm_monitor->options.trace_command,
+ tbm_monitor->options.target,
+ tbm_monitor->options.pid);
+ wl_display_roundtrip(tbm_monitor->dpy);
+ }
}
static const struct wl_registry_listener registry_listener = {
- _wayland_tbm_monitor_registry_handle_global,
- NULL
+ _wayland_tbm_monitor_registry_handle_global,
+ NULL
};
static void
_wl_tbm_usage()
{
WL_TBM_LOG("wayland-tbm-monitor : show/trace the infomation of tbm_bo in clietns and in server.\n");
- _wl_tbm_list_usage();
- _wl_tbm_show_usage();
- _wl_tbm_trace_usage();
+ _wl_tbm_list_usage();
+ _wl_tbm_show_usage();
+ _wl_tbm_trace_usage();
WL_TBM_LOG("\n");
}
static int
-_wl_tbm_select_target_option(struct wayland_tbm_monitor *tbm_monitor, int argc, char *argv[], int arg_pos)
+_wl_tbm_select_target_option(struct wayland_tbm_monitor *tbm_monitor, int argc,
+ char *argv[], int arg_pos)
{
- if (!strncmp(argv[arg_pos], "client", strlen(argv[arg_pos])+1)) {
- if (argc < (arg_pos+2)) {
+ if (!strncmp(argv[arg_pos], "client", strlen(argv[arg_pos]) + 1)) {
+ if (argc < (arg_pos + 2)) {
WL_TBM_LOG("error: no pid. please type the pid.\n");
return 0;
}
tbm_monitor->options.target = WL_TBM_MONITOR_TARGET_CLIENT;
- tbm_monitor->options.pid = atoi(argv[arg_pos+1]);
+ tbm_monitor->options.pid = atoi(argv[arg_pos + 1]);
} else if (!strncmp(argv[arg_pos], "server", 6)) {
tbm_monitor->options.target = WL_TBM_MONITOR_TARGET_SERVER;
} else if (!strncmp(argv[arg_pos], "all", 3)) {
return 0;
}
- return 1;
+ return 1;
}
static int
-_wl_tbm_monitor_process_options(struct wayland_tbm_monitor *tbm_monitor, int argc, char* argv[])
+_wl_tbm_monitor_process_options(struct wayland_tbm_monitor *tbm_monitor,
+ int argc, char *argv[])
{
- if (argc < 2) {
- _wl_tbm_usage();
- return 0;
- }
-
- if (!strncmp(argv[1], "list", strlen(argv[1])+1)) {
- tbm_monitor->options.command = WL_TBM_MONITOR_COMMAND_LIST;
- } else if (!strncmp(argv[1], "show", strlen(argv[1])+1)) {
- if (argc < 3) {
+ if (argc < 2) {
+ _wl_tbm_usage();
+ return 0;
+ }
+
+ if (!strncmp(argv[1], "list", strlen(argv[1]) + 1)) {
+ tbm_monitor->options.command = WL_TBM_MONITOR_COMMAND_LIST;
+ } else if (!strncmp(argv[1], "show", strlen(argv[1]) + 1)) {
+ if (argc < 3) {
_wl_tbm_show_usage();
return 0;
- }
+ }
- tbm_monitor->options.command = WL_TBM_MONITOR_COMMAND_SHOW;
- if (!_wl_tbm_select_target_option(tbm_monitor, argc, argv, 2)){
+ tbm_monitor->options.command = WL_TBM_MONITOR_COMMAND_SHOW;
+ if (!_wl_tbm_select_target_option(tbm_monitor, argc, argv, 2)) {
_wl_tbm_show_usage();
return 0;
- }
- } else if (!strncmp(argv[1], "trace", strlen(argv[1])+1)) {
- if (argc < 3) {
+ }
+ } else if (!strncmp(argv[1], "trace", strlen(argv[1]) + 1)) {
+ if (argc < 3) {
_wl_tbm_trace_usage();
return 0;
- }
+ }
- tbm_monitor->options.command = WL_TBM_MONITOR_COMMAND_TRACE;
+ tbm_monitor->options.command = WL_TBM_MONITOR_COMMAND_TRACE;
- if (!strncmp(argv[2], "on", strlen(argv[2])+1)) {
+ if (!strncmp(argv[2], "on", strlen(argv[2]) + 1)) {
tbm_monitor->options.trace_command = WL_TBM_MONITOR_TRACE_COMMAND_ON;
- } else if (!strncmp(argv[2], "off", strlen(argv[2])+1)) {
+ } else if (!strncmp(argv[2], "off", strlen(argv[2]) + 1)) {
tbm_monitor->options.trace_command = WL_TBM_MONITOR_TRACE_COMMAND_OFF;
- } else if (!strncmp(argv[2], "register", strlen(argv[2])+1)) {
+ } else if (!strncmp(argv[2], "register", strlen(argv[2]) + 1)) {
if (argc < 4) {
WL_TBM_LOG("error: no pid. please type the target(client [pid]/server/all).\n");
_wl_tbm_trace_usage();
}
tbm_monitor->options.trace_command = WL_TBM_MONITOR_TRACE_COMMAND_REGISTER;
- if (_wl_tbm_select_target_option(tbm_monitor, argc, argv, 3)){
+ if (_wl_tbm_select_target_option(tbm_monitor, argc, argv, 3)) {
WL_TBM_LOG("error: no pid. please type the target(client [pid]/server/all).\n");
_wl_tbm_trace_usage();
return 0;
}
- } else if (!strncmp(argv[2], "unregister", strlen(argv[2])+1)) {
+ } else if (!strncmp(argv[2], "unregister", strlen(argv[2]) + 1)) {
if (argc < 4) {
WL_TBM_LOG("error: no pid. please type the target(client [pid]/server/all).\n");
_wl_tbm_trace_usage();
}
tbm_monitor->options.trace_command = WL_TBM_MONITOR_TRACE_COMMAND_UNREGISTER;
- if (_wl_tbm_select_target_option(tbm_monitor, argc, argv, 3)){
+ if (_wl_tbm_select_target_option(tbm_monitor, argc, argv, 3)) {
WL_TBM_LOG("error: no pid. please type the target(client [pid]/server/all).\n");
_wl_tbm_trace_usage();
return 0;
}
- } else if (!strncmp(argv[2], "status", strlen(argv[2])+1)) {
+ } else if (!strncmp(argv[2], "status", strlen(argv[2]) + 1)) {
tbm_monitor->options.trace_command = WL_TBM_MONITOR_TRACE_COMMAND_STATUS;
- } else {
+ } else {
_wl_tbm_trace_usage();
return 0;
- }
- } else {
- _wl_tbm_usage();
- return 0;
- }
+ }
+ } else {
+ _wl_tbm_usage();
+ return 0;
+ }
- return 1;
+ return 1;
}
int
-main(int argc, char* argv[])
+main(int argc, char *argv[])
{
- struct wayland_tbm_monitor *tbm_monitor = NULL;
- struct wl_registry *wl_registry;
- int ret = 0;
+ struct wayland_tbm_monitor *tbm_monitor = NULL;
+ struct wl_registry *wl_registry;
+ int ret = 0;
- tbm_monitor = calloc(1, sizeof(struct wayland_tbm_monitor));
- WL_TBM_RETURN_VAL_IF_FAIL(tbm_monitor != NULL, -1);
+ tbm_monitor = calloc(1, sizeof(struct wayland_tbm_monitor));
+ WL_TBM_RETURN_VAL_IF_FAIL(tbm_monitor != NULL, -1);
- ret = _wl_tbm_monitor_process_options(tbm_monitor, argc, argv);
- if (!ret) {
- goto finish;
- }
+ ret = _wl_tbm_monitor_process_options(tbm_monitor, argc, argv);
+ if (!ret) {
+ goto finish;
+ }
- tbm_monitor->dpy = wl_display_connect(NULL);
- WL_TBM_GOTO_IF_FAIL(tbm_monitor->dpy != NULL, finish);
+ tbm_monitor->dpy = wl_display_connect(NULL);
+ WL_TBM_GOTO_IF_FAIL(tbm_monitor->dpy != NULL, finish);
- wl_registry = wl_display_get_registry(tbm_monitor->dpy);
- WL_TBM_GOTO_IF_FAIL(wl_registry != NULL, finish);
+ wl_registry = wl_display_get_registry(tbm_monitor->dpy);
+ WL_TBM_GOTO_IF_FAIL(wl_registry != NULL, finish);
#ifdef WL_TBM_MONITOR_DEBUG
- WL_TBM_LOG("[%s]: tbm_monitor=%p, display=%p\n", __func__, tbm_monitor, tbm_monitor->dpy);
+ WL_TBM_LOG("[%s]: tbm_monitor=%p, display=%p\n", __func__, tbm_monitor,
+ tbm_monitor->dpy);
#endif
- wl_registry_add_listener(wl_registry, ®istry_listener, tbm_monitor);
- wl_display_dispatch(tbm_monitor->dpy);
- wl_display_roundtrip(tbm_monitor->dpy);
+ wl_registry_add_listener(wl_registry, ®istry_listener, tbm_monitor);
+ wl_display_dispatch(tbm_monitor->dpy);
+ wl_display_roundtrip(tbm_monitor->dpy);
- wl_registry_destroy(wl_registry);
+ wl_registry_destroy(wl_registry);
finish:
- if (tbm_monitor) {
- if (tbm_monitor->wl_tbm) {
- wl_tbm_set_user_data(tbm_monitor->wl_tbm, NULL);
- wl_tbm_destroy(tbm_monitor->wl_tbm);
- }
+ if (tbm_monitor) {
+ if (tbm_monitor->wl_tbm) {
+ wl_tbm_set_user_data(tbm_monitor->wl_tbm, NULL);
+ wl_tbm_destroy(tbm_monitor->wl_tbm);
+ }
- free(tbm_monitor);
- }
+ free(tbm_monitor);
+ }
- return 1;
+ return 1;
}