return NULL;
}
-struct wl_buffer *
-wayland_tbm_client_create_buffer(struct wayland_tbm_client *tbm_client,
- tbm_surface_h surface)
+static struct wl_buffer *
+_wayland_tbm_client_create_wl_buffer(struct wayland_tbm_client *tbm_client, tbm_surface_h surface, int with_fd)
{
- WL_TBM_RETURN_VAL_IF_FAIL(tbm_client != NULL, NULL);
- WL_TBM_RETURN_VAL_IF_FAIL(surface != NULL, NULL);
-
int bufs[TBM_SURF_PLANE_MAX] = { -1, -1, -1, -1};
struct wl_buffer *wl_buffer = NULL;
- struct wayland_tbm_buffer *buffer = NULL;
- int num_buf, is_fd = -1, i;
- char debug_id[64] = {0, };
- tbm_surface_info_s info;
+ int num_buf, i;
+ tbm_surface_info_s info = {0, };
uint32_t flags = 0;
struct wl_array plane_buf_idx, plane_offset, plane_stride, plane_size;
int *p;
- /*
- * if the surface is the attached surface from display server,
- * return the wl_buffer of the attached surface
- */
-
- buffer = _wayland_tbm_client_find_tbm_buffer_surface(tbm_client, surface);
- if (buffer) {
- WL_TBM_TRACE("wl_buffer:%p tbm_surface:%p", buffer->wl_buffer, buffer->tbm_surface);
- buffer->exposed = 1;
- return buffer->wl_buffer;
- }
-
if (tbm_surface_get_info(surface, &info) != TBM_SURFACE_ERROR_NONE) {
WL_TBM_LOG_E("Failed to create buffer from surface");
return NULL;
goto err;
}
- /* try to get fd first */
- if (is_fd == -1 || is_fd == 1) {
+ if (with_fd)
bufs[i] = tbm_bo_export_fd(bo);
- if (is_fd == -1 && bufs[i] >= 0)
- is_fd = 1;
- }
-
- /* if fail to get fd, try to get name second */
- if (is_fd == -1 || is_fd == 0) {
+ else
bufs[i] = tbm_bo_export(bo);
- if (is_fd == -1 && 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_E("Failed to export(is_fd:%d, bufs:%d)", is_fd, bufs[i]);
+ if (((with_fd) && (bufs[i] < 0)) ||
+ ((!with_fd) && (bufs[i] <= 0))) {
+ WL_TBM_LOG_E("Failed to export(with_fd:%d, bufs:%d)", with_fd, bufs[i]);
goto err;
}
}
*p = info.planes[i].size;
}
- if (is_fd == 1)
+ if (with_fd)
wl_buffer = wl_tbm_create_buffer_with_fd(tbm_client->wl_tbm,
info.width, info.height, info.format, info.bpp, info.size, info.num_planes,
&plane_buf_idx, &plane_offset, &plane_stride, &plane_size,
wl_array_release(&plane_size);
if (!wl_buffer) {
- WL_TBM_LOG_E("Failed to create wl_buffer");
+ TBM_ERR("Failed to wl_tbm_create_buffer(with_fd:%d)", with_fd);
goto err;
}
+ WL_TBM_TRACE("wl_buffer:%p tbm_surface:%p (%dx%d) size:%d fmt:%c%c%c%c",
+ wl_buffer, surface, info.width, info.height, info.size, FOURCC_STR(info.format));
+
for (i = 0; i < TBM_SURF_PLANE_MAX; i++) {
- if (is_fd == 1 && (bufs[i] >= 0))
+ if ((with_fd) && (bufs[i] >= 0))
close(bufs[i]);
}
- wl_buffer_set_user_data(wl_buffer, surface);
-
- snprintf(debug_id, sizeof(debug_id), "%u",
- (unsigned int)wl_proxy_get_id((struct wl_proxy *)wl_buffer));
- tbm_surface_internal_set_debug_data(surface, "id", debug_id);
-
- WL_TBM_TRACE("wl_buffer:%p tbm_surface:%p (%dx%d) size:%d fmt:%c%c%c%c",
- wl_buffer, surface, info.width, info.height, info.size, FOURCC_STR(info.format));
-
return wl_buffer;
err:
for (i = 0; i < TBM_SURF_PLANE_MAX; i++) {
- if (is_fd == 1 && (bufs[i] >= 0))
+ if ((with_fd) && (bufs[i] >= 0))
close(bufs[i]);
}
return NULL;
}
+struct wl_buffer *
+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);
+
+ struct wayland_tbm_buffer *buffer = NULL;
+ struct wl_buffer *wl_buffer = NULL;
+ char debug_id[64] = {0, };
+
+ /*
+ * if the surface is the attached surface from display server,
+ * return the wl_buffer of the attached surface
+ */
+ buffer = _wayland_tbm_client_find_tbm_buffer_surface(tbm_client, surface);
+ if (buffer) {
+ WL_TBM_TRACE("wl_buffer:%p tbm_surface:%p", buffer->wl_buffer, buffer->tbm_surface);
+ buffer->exposed = 1;
+ return buffer->wl_buffer;
+ }
+
+ /* try create with fd */
+ wl_buffer = _wayland_tbm_client_create_wl_buffer(tbm_client, surface, 1);
+ if (!wl_buffer) {
+ WL_TBM_C_LOG("retry create wl_buffer with key");
+ /* retry creat with key */
+ wl_buffer = _wayland_tbm_client_create_wl_buffer(tbm_client, surface, 0);
+ }
+
+ if (!wl_buffer) {
+ WL_TBM_LOG_E("Failed to create wl_buffer");
+ return NULL;
+ }
+
+ wl_buffer_set_user_data(wl_buffer, surface);
+
+ snprintf(debug_id, sizeof(debug_id), "%u",
+ (unsigned int)wl_proxy_get_id((struct wl_proxy *)wl_buffer));
+ tbm_surface_internal_set_debug_data(surface, "id", debug_id);
+
+ return wl_buffer;
+}
+
void
wayland_tbm_client_destroy_buffer(struct wayland_tbm_client *tbm_client,
struct wl_buffer *wl_buffer)