summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSooChan Lim <sc1.lim@samsung.com>2018-03-19 20:45:32 +0900
committerSooChan Lim <sc1.lim@samsung.com>2018-03-19 20:45:32 +0900
commit670862a646efd5a6ce5888fb09de696b9079254b (patch)
treeaf1c4d900cd05406033b5c6cff0046909a952e54
parentfaad5059a110d6bd2064ef23b2e2afa66d5b3842 (diff)
downloadlibtbm-dumb-670862a646efd5a6ce5888fb09de696b9079254b.tar.gz
libtbm-dumb-670862a646efd5a6ce5888fb09de696b9079254b.tar.bz2
libtbm-dumb-670862a646efd5a6ce5888fb09de696b9079254b.zip
re-arrange the static functions.
Change-Id: I775bc21a2445eaebcca7ba22fb54f2b2fdd4d816
-rw-r--r--src/tbm_bufmgr_dumb.c975
1 files changed, 487 insertions, 488 deletions
diff --git a/src/tbm_bufmgr_dumb.c b/src/tbm_bufmgr_dumb.c
index c8b8b13..16ebf09 100644
--- a/src/tbm_bufmgr_dumb.c
+++ b/src/tbm_bufmgr_dumb.c
@@ -408,21 +408,298 @@ _dumb_cache_flush(int fd, tbm_bo_dumb bo_dumb, int flags)
}
#endif
-static int
-tbm_dumb_bo_get_size(tbm_backend_bo_data *bo_data, tbm_error_e *error)
+static tbm_bufmgr_capability
+tbm_dumb_bufmgr_get_capabilities(tbm_backend_bufmgr_data *bufmgr_data, tbm_error_e *error)
{
- tbm_bo_dumb bo_dumb = (tbm_bo_dumb)bo_data;
+ tbm_bufmgr_capability capabilities = TBM_BUFMGR_CAPABILITY_NONE;
- if (!bo_dumb) {
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return 0;
- }
+ capabilities = TBM_BUFMGR_CAPABILITY_SHARE_KEY|TBM_BUFMGR_CAPABILITY_SHARE_FD;
if (error)
*error = TBM_ERROR_NONE;
- return bo_dumb->size;
+ return capabilities;
+}
+
+static tbm_error_e
+tbm_dumb_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display)
+{
+ tbm_bufmgr_dumb bufmgr_dumb = (tbm_bufmgr_dumb)bufmgr_data;
+ DUMB_RETURN_VAL_IF_FAIL(bufmgr_dumb != NULL, TBM_ERROR_INVALID_PARAMETER);
+
+ if (!tbm_drm_helper_wl_auth_server_init(native_display, bufmgr_dumb->fd,
+ bufmgr_dumb->device_name, 0)) {
+ TBM_DUMB_ERROR("fail to tbm_drm_helper_wl_server_init\n");
+ return TBM_ERROR_OPERATION_FAILED;
+ }
+
+ bufmgr_dumb->bind_display = native_display;
+
+ return TBM_ERROR_NONE;
+}
+
+static tbm_error_e
+tbm_dumb_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data,
+ uint32_t **formats, uint32_t *num)
+{
+ tbm_bufmgr_dumb bufmgr_dumb = (tbm_bufmgr_dumb)bufmgr_data;
+ uint32_t *color_formats;
+
+ DUMB_RETURN_VAL_IF_FAIL(bufmgr_dumb != NULL, TBM_ERROR_INVALID_PARAMETER);
+
+ color_formats = (uint32_t *)calloc(1, sizeof(uint32_t) * TBM_COLOR_FORMAT_COUNT);
+ if (color_formats == NULL)
+ return TBM_ERROR_OUT_OF_MEMORY;
+
+ memcpy(color_formats, tbm_dumb_color_format_list, sizeof(uint32_t)*TBM_COLOR_FORMAT_COUNT);
+
+ *formats = color_formats;
+ *num = TBM_COLOR_FORMAT_COUNT;
+
+ TBM_DUMB_DEBUG("supported format count = %d\n", *num);
+
+ return TBM_ERROR_NONE;
+}
+
+static tbm_error_e
+tbm_dumb_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data,
+ tbm_format format, int plane_idx, int width,
+ int height, uint32_t *size, uint32_t *offset,
+ uint32_t *pitch, int *bo_idx)
+{
+ tbm_bufmgr_dumb bufmgr_dumb = (tbm_bufmgr_dumb)bufmgr_data;
+ int bpp;
+ int _offset = 0;
+ int _pitch = 0;
+ int _size = 0;
+ int _bo_idx = 0;
+
+ DUMB_RETURN_VAL_IF_FAIL(bufmgr_dumb != NULL, TBM_ERROR_INVALID_PARAMETER);
+
+ switch (format) {
+ /* 16 bpp RGB */
+ case TBM_FORMAT_XRGB4444:
+ case TBM_FORMAT_XBGR4444:
+ case TBM_FORMAT_RGBX4444:
+ case TBM_FORMAT_BGRX4444:
+ case TBM_FORMAT_ARGB4444:
+ case TBM_FORMAT_ABGR4444:
+ case TBM_FORMAT_RGBA4444:
+ case TBM_FORMAT_BGRA4444:
+ case TBM_FORMAT_XRGB1555:
+ case TBM_FORMAT_XBGR1555:
+ case TBM_FORMAT_RGBX5551:
+ case TBM_FORMAT_BGRX5551:
+ case TBM_FORMAT_ARGB1555:
+ case TBM_FORMAT_ABGR1555:
+ case TBM_FORMAT_RGBA5551:
+ case TBM_FORMAT_BGRA5551:
+ case TBM_FORMAT_RGB565:
+ bpp = 16;
+ _offset = 0;
+ _pitch = SIZE_ALIGN((width * bpp)>>3, TBM_SURFACE_ALIGNMENT_PITCH_RGB);
+ _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ break;
+ /* 24 bpp RGB */
+ case TBM_FORMAT_RGB888:
+ case TBM_FORMAT_BGR888:
+ bpp = 24;
+ _offset = 0;
+ _pitch = SIZE_ALIGN((width * bpp)>>3, TBM_SURFACE_ALIGNMENT_PITCH_RGB);
+ _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ break;
+ /* 32 bpp RGB */
+ case TBM_FORMAT_XRGB8888:
+ case TBM_FORMAT_XBGR8888:
+ case TBM_FORMAT_RGBX8888:
+ case TBM_FORMAT_BGRX8888:
+ case TBM_FORMAT_ARGB8888:
+ case TBM_FORMAT_ABGR8888:
+ case TBM_FORMAT_RGBA8888:
+ case TBM_FORMAT_BGRA8888:
+ bpp = 32;
+ _offset = 0;
+ _pitch = SIZE_ALIGN((width * bpp)>>3, TBM_SURFACE_ALIGNMENT_PITCH_RGB);
+ _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ break;
+
+ /* packed YCbCr */
+ case TBM_FORMAT_YUYV:
+ case TBM_FORMAT_YVYU:
+ case TBM_FORMAT_UYVY:
+ case TBM_FORMAT_VYUY:
+ case TBM_FORMAT_AYUV:
+ bpp = 32;
+ _offset = 0;
+ _pitch = SIZE_ALIGN((width * bpp)>>3, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
+ _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ break;
+
+ /*
+ * 2 plane YCbCr
+ * index 0 = Y plane, [7:0] Y
+ * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
+ * or
+ * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
+ */
+ case TBM_FORMAT_NV12:
+ case TBM_FORMAT_NV21:
+ bpp = 12;
+ if (plane_idx == 0) {
+ _offset = 0;
+ _pitch = SIZE_ALIGN(width , TBM_SURFACE_ALIGNMENT_PITCH_YUV);
+ _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ } else if (plane_idx == 1) {
+ _offset = width*height;
+ _pitch = SIZE_ALIGN(width , TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
+ _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ }
+ break;
+
+ case TBM_FORMAT_NV16:
+ case TBM_FORMAT_NV61:
+ bpp = 16;
+ //if (plane_idx == 0)
+ {
+ _offset = 0;
+ _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
+ _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ if (plane_idx == 0)
+ break;
+ }
+ //else if (plane_idx == 1)
+ {
+ _offset += _size;
+ _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
+ _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ }
+ break;
+
+ /*
+ * 3 plane YCbCr
+ * index 0: Y plane, [7:0] Y
+ * index 1: Cb plane, [7:0] Cb
+ * index 2: Cr plane, [7:0] Cr
+ * or
+ * index 1: Cr plane, [7:0] Cr
+ * index 2: Cb plane, [7:0] Cb
+ */
+ /*
+ NATIVE_BUFFER_FORMAT_YV12
+ NATIVE_BUFFER_FORMAT_I420
+ */
+ case TBM_FORMAT_YUV410:
+ case TBM_FORMAT_YVU410:
+ bpp = 9;
+ break;
+ case TBM_FORMAT_YUV411:
+ case TBM_FORMAT_YVU411:
+ case TBM_FORMAT_YUV420:
+ case TBM_FORMAT_YVU420:
+ bpp = 12;
+ //if (plane_idx == 0)
+ {
+ _offset = 0;
+ _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
+ _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ if (plane_idx == 0)
+ break;
+ }
+ //else if (plane_idx == 1)
+ {
+ _offset += _size;
+ _pitch = SIZE_ALIGN(width/2, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
+ _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ if (plane_idx == 1)
+ break;
+ }
+ //else if (plane_idx == 2)
+ {
+ _offset += _size;
+ _pitch = SIZE_ALIGN(width/2, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
+ _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ }
+ break;
+ case TBM_FORMAT_YUV422:
+ case TBM_FORMAT_YVU422:
+ bpp = 16;
+ //if (plane_idx == 0)
+ {
+ _offset = 0;
+ _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
+ _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ if (plane_idx == 0)
+ break;
+ }
+ //else if (plane_idx == 1)
+ {
+ _offset += _size;
+ _pitch = SIZE_ALIGN(width/2, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
+ _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ if (plane_idx == 1)
+ break;
+ }
+ //else if (plane_idx == 2)
+ {
+ _offset += _size;
+ _pitch = SIZE_ALIGN(width/2, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
+ _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ }
+ break;
+ case TBM_FORMAT_YUV444:
+ case TBM_FORMAT_YVU444:
+ bpp = 24;
+ //if (plane_idx == 0)
+ {
+ _offset = 0;
+ _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
+ _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ if (plane_idx == 0)
+ break;
+ }
+ //else if (plane_idx == 1)
+ {
+ _offset += _size;
+ _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
+ _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ if (plane_idx == 1)
+ break;
+ }
+ //else if (plane_idx == 2)
+ {
+ _offset += _size;
+ _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
+ _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
+ _bo_idx = 0;
+ }
+ break;
+ default:
+ bpp = 0;
+ break;
+ }
+
+ *size = _size;
+ *offset = _offset;
+ *pitch = _pitch;
+ *bo_idx = _bo_idx;
+
+ return TBM_ERROR_NONE;
}
static tbm_backend_bo_data *
@@ -505,140 +782,6 @@ tbm_dumb_bufmgr_alloc_bo(tbm_backend_bufmgr_data *bufmgr_data, int size, tbm_bo_
return (tbm_backend_bo_data *)bo_dumb;
}
-static void
-tbm_dumb_bo_free(tbm_backend_bo_data *bo_data)
-{
- tbm_bo_dumb bo_dumb = (tbm_bo_dumb)bo_data;
- tbm_bo_dumb temp;
- tbm_bufmgr_dumb bufmgr_dumb;
- char buf[STRERR_BUFSIZE];
- int ret;
-
- if (!bo_data)
- return;
-
- bufmgr_dumb = bo_dumb->bufmgr_dumb;
- if (!bufmgr_dumb)
- return;
-
- TBM_DUMB_DEBUG(" bo_dumb:%p, gem:%d(%d), fd:%d, size:%d\n",
- bo_dumb,
- bo_dumb->gem, bo_dumb->name,
- bo_dumb->dmabuf,
- bo_dumb->size);
-
- if (bo_dumb->pBase) {
- if (munmap(bo_dumb->pBase, bo_dumb->size) == -1) {
- TBM_DUMB_ERROR("bo_dumb:%p fail to munmap(%s)\n",
- bo_dumb, strerror_r(errno, buf, STRERR_BUFSIZE));
- }
- }
-
- /* close dmabuf */
- if (bo_dumb->dmabuf) {
- close(bo_dumb->dmabuf);
- bo_dumb->dmabuf = 0;
- }
-
- /* delete bo from hash */
- ret = drmHashLookup(bufmgr_dumb->hashBos, bo_dumb->name, (void**)&temp);
- if (ret == 0)
- drmHashDelete(bufmgr_dumb->hashBos, bo_dumb->name);
- else
- TBM_DUMB_ERROR("Cannot find bo_dumb to Hash(%d), ret=%d\n", bo_dumb->name, ret);
-
- if (temp != bo_dumb)
- TBM_DUMB_ERROR("hashBos probably has several BOs with same name!!!\n");
-
- /* Free gem handle */
- struct drm_gem_close arg = {0, };
-
- memset(&arg, 0, sizeof(arg));
- arg.handle = bo_dumb->gem;
- if (drmIoctl(bo_dumb->fd, DRM_IOCTL_GEM_CLOSE, &arg))
- TBM_DUMB_ERROR("bo_dumb:%p fail to gem close.(%s)\n",
- bo_dumb, strerror_r(errno, buf, STRERR_BUFSIZE));
-
- free(bo_dumb);
-}
-
-static tbm_backend_bo_data *
-tbm_dumb_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_error_e *error)
-{
- tbm_bufmgr_dumb bufmgr_dumb = (tbm_bufmgr_dumb)bufmgr_data;
- tbm_bo_dumb bo_dumb;
- int ret;
-
- if (bufmgr_dumb == NULL) {
- TBM_DUMB_ERROR("bufmgr_data is null\n");
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return NULL;
- }
-
- ret = drmHashLookup(bufmgr_dumb->hashBos, key, (void **)&bo_dumb);
- if (ret == 0) {
- if (error)
- *error = TBM_ERROR_NONE;
- return (tbm_backend_bo_data *)bo_dumb;
- }
-
- struct drm_gem_open arg = {0, };
-
- arg.name = key;
- if (drmIoctl(bufmgr_dumb->fd, DRM_IOCTL_GEM_OPEN, &arg)) {
- TBM_DUMB_ERROR("Cannot open gem name=%d\n", key);
- if (error)
- *error = TBM_ERROR_OPERATION_FAILED;
- return NULL;
- }
-
- bo_dumb = calloc(1, sizeof(struct _tbm_bo_dumb));
- if (!bo_dumb) {
- TBM_DUMB_ERROR("fail to allocate the bo_dumb private\n");
- if (error)
- *error = TBM_ERROR_OUT_OF_MEMORY;
- return NULL;
- }
-
- bo_dumb->fd = bufmgr_dumb->fd;
- bo_dumb->gem = arg.handle;
- bo_dumb->size = arg.size;
- bo_dumb->flags_dumb = 0;
- bo_dumb->name = key;
- bo_dumb->flags_tbm = _get_tbm_flag_from_dumb(bo_dumb->flags_dumb);
-
- if (!bo_dumb->dmabuf) {
- struct drm_prime_handle arg = {0, };
-
- arg.handle = bo_dumb->gem;
- if (drmIoctl(bo_dumb->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) {
- TBM_DUMB_ERROR("fail to DRM_IOCTL_PRIME_HANDLE_TO_FD gem=%d\n", bo_dumb->gem);
- if (error)
- *error = TBM_ERROR_OPERATION_FAILED;
- free(bo_dumb);
- return NULL;
- }
- bo_dumb->dmabuf = arg.fd;
- }
-
- /* add bo to hash */
- if (drmHashInsert(bufmgr_dumb->hashBos, bo_dumb->name, (void *)bo_dumb) < 0)
- TBM_DUMB_ERROR("Cannot insert bo_dumb to Hash(%d)\n", bo_dumb->name);
-
- TBM_DUMB_DEBUG(" bo_dumb:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n",
- bo_dumb,
- bo_dumb->gem, bo_dumb->name,
- bo_dumb->dmabuf,
- bo_dumb->flags_tbm,
- bo_dumb->size);
-
- if (error)
- *error = TBM_ERROR_NONE;
-
- return (tbm_backend_bo_data *)bo_dumb;
-}
-
static tbm_backend_bo_data *
tbm_dumb_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_error_e *error)
{
@@ -758,28 +901,71 @@ tbm_dumb_bufmgr_import_fd(tbm_backend_bufmgr_data *bufmgr_data, tbm_fd key, tbm_
return (tbm_backend_bo_data *)bo_dumb;
}
-static tbm_key
-tbm_dumb_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error)
+static tbm_backend_bo_data *
+tbm_dumb_bufmgr_import_key(tbm_backend_bufmgr_data *bufmgr_data, tbm_key key, tbm_error_e *error)
{
- tbm_bo_dumb bo_dumb = (tbm_bo_dumb)bo_data;
+ tbm_bufmgr_dumb bufmgr_dumb = (tbm_bufmgr_dumb)bufmgr_data;
+ tbm_bo_dumb bo_dumb;
+ int ret;
- if (!bo_dumb) {
+ if (bufmgr_dumb == NULL) {
+ TBM_DUMB_ERROR("bufmgr_data is null\n");
if (error)
*error = TBM_ERROR_INVALID_PARAMETER;
- return 0;
+ return NULL;
}
- if (!bo_dumb->name) {
- bo_dumb->name = _get_name(bo_dumb->fd, bo_dumb->gem);
- if (!bo_dumb->name) {
- TBM_DUMB_ERROR("error Cannot get name\n");
+ ret = drmHashLookup(bufmgr_dumb->hashBos, key, (void **)&bo_dumb);
+ if (ret == 0) {
+ if (error)
+ *error = TBM_ERROR_NONE;
+ return (tbm_backend_bo_data *)bo_dumb;
+ }
+
+ struct drm_gem_open arg = {0, };
+
+ arg.name = key;
+ if (drmIoctl(bufmgr_dumb->fd, DRM_IOCTL_GEM_OPEN, &arg)) {
+ TBM_DUMB_ERROR("Cannot open gem name=%d\n", key);
+ if (error)
+ *error = TBM_ERROR_OPERATION_FAILED;
+ return NULL;
+ }
+
+ bo_dumb = calloc(1, sizeof(struct _tbm_bo_dumb));
+ if (!bo_dumb) {
+ TBM_DUMB_ERROR("fail to allocate the bo_dumb private\n");
+ if (error)
+ *error = TBM_ERROR_OUT_OF_MEMORY;
+ return NULL;
+ }
+
+ bo_dumb->fd = bufmgr_dumb->fd;
+ bo_dumb->gem = arg.handle;
+ bo_dumb->size = arg.size;
+ bo_dumb->flags_dumb = 0;
+ bo_dumb->name = key;
+ bo_dumb->flags_tbm = _get_tbm_flag_from_dumb(bo_dumb->flags_dumb);
+
+ if (!bo_dumb->dmabuf) {
+ struct drm_prime_handle arg = {0, };
+
+ arg.handle = bo_dumb->gem;
+ if (drmIoctl(bo_dumb->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg)) {
+ TBM_DUMB_ERROR("fail to DRM_IOCTL_PRIME_HANDLE_TO_FD gem=%d\n", bo_dumb->gem);
if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return 0;
+ *error = TBM_ERROR_OPERATION_FAILED;
+ free(bo_dumb);
+ return NULL;
}
+ bo_dumb->dmabuf = arg.fd;
}
- TBM_DUMB_DEBUG(" bo_dumb:%p, gem:%d(%d), fd:%d, flags:%d, size:%d\n",
+ /* add bo to hash */
+ if (drmHashInsert(bufmgr_dumb->hashBos, bo_dumb->name, (void *)bo_dumb) < 0)
+ TBM_DUMB_ERROR("Cannot insert bo_dumb to Hash(%d)\n", bo_dumb->name);
+
+ TBM_DUMB_DEBUG(" bo_dumb:%p, gem:%d(%d), fd:%d, flags:%d(%d), size:%d\n",
bo_dumb,
bo_dumb->gem, bo_dumb->name,
bo_dumb->dmabuf,
@@ -789,43 +975,98 @@ tbm_dumb_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error)
if (error)
*error = TBM_ERROR_NONE;
- return (tbm_key)bo_dumb->name;
+ return (tbm_backend_bo_data *)bo_dumb;
}
-tbm_fd
-tbm_dumb_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error)
+static void
+tbm_dumb_bo_free(tbm_backend_bo_data *bo_data)
{
tbm_bo_dumb bo_dumb = (tbm_bo_dumb)bo_data;
- int ret;
+ tbm_bo_dumb temp;
+ tbm_bufmgr_dumb bufmgr_dumb;
char buf[STRERR_BUFSIZE];
+ int ret;
+
+ if (!bo_data)
+ return;
+
+ bufmgr_dumb = bo_dumb->bufmgr_dumb;
+ if (!bufmgr_dumb)
+ return;
+
+ TBM_DUMB_DEBUG(" bo_dumb:%p, gem:%d(%d), fd:%d, size:%d\n",
+ bo_dumb,
+ bo_dumb->gem, bo_dumb->name,
+ bo_dumb->dmabuf,
+ bo_dumb->size);
+
+ if (bo_dumb->pBase) {
+ if (munmap(bo_dumb->pBase, bo_dumb->size) == -1) {
+ TBM_DUMB_ERROR("bo_dumb:%p fail to munmap(%s)\n",
+ bo_dumb, strerror_r(errno, buf, STRERR_BUFSIZE));
+ }
+ }
+
+ /* close dmabuf */
+ if (bo_dumb->dmabuf) {
+ close(bo_dumb->dmabuf);
+ bo_dumb->dmabuf = 0;
+ }
+
+ /* delete bo from hash */
+ ret = drmHashLookup(bufmgr_dumb->hashBos, bo_dumb->name, (void**)&temp);
+ if (ret == 0)
+ drmHashDelete(bufmgr_dumb->hashBos, bo_dumb->name);
+ else
+ TBM_DUMB_ERROR("Cannot find bo_dumb to Hash(%d), ret=%d\n", bo_dumb->name, ret);
+
+ if (temp != bo_dumb)
+ TBM_DUMB_ERROR("hashBos probably has several BOs with same name!!!\n");
+
+ /* Free gem handle */
+ struct drm_gem_close arg = {0, };
+
+ memset(&arg, 0, sizeof(arg));
+ arg.handle = bo_dumb->gem;
+ if (drmIoctl(bo_dumb->fd, DRM_IOCTL_GEM_CLOSE, &arg))
+ TBM_DUMB_ERROR("bo_dumb:%p fail to gem close.(%s)\n",
+ bo_dumb, strerror_r(errno, buf, STRERR_BUFSIZE));
+
+ free(bo_dumb);
+}
+
+static int
+tbm_dumb_bo_get_size(tbm_backend_bo_data *bo_data, tbm_error_e *error)
+{
+ tbm_bo_dumb bo_dumb = (tbm_bo_dumb)bo_data;
if (!bo_dumb) {
if (error)
*error = TBM_ERROR_INVALID_PARAMETER;
- return -1;
+ return 0;
}
- struct drm_prime_handle arg = {0, };
+ if (error)
+ *error = TBM_ERROR_NONE;
- arg.handle = bo_dumb->gem;
- ret = drmIoctl(bo_dumb->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg);
- if (ret) {
- TBM_DUMB_ERROR("bo_dumb:%p Cannot dmabuf=%d (%s)\n",
- bo_dumb, bo_dumb->gem, strerror_r(errno, buf, STRERR_BUFSIZE));
+ return bo_dumb->size;
+}
+
+static tbm_bo_memory_type
+tbm_dumb_bo_get_memory_type(tbm_backend_bo_data *bo_data, tbm_error_e *error)
+{
+ tbm_bo_dumb bo_dumb = (tbm_bo_dumb)bo_data;
+
+ if (!bo_dumb) {
if (error)
- *error = TBM_ERROR_OPERATION_FAILED;
- return (tbm_fd) ret;
+ *error = TBM_ERROR_INVALID_PARAMETER;
+ return TBM_BO_DEFAULT;
}
- TBM_DUMB_DEBUG(" bo_dumb:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d, size:%d\n",
- bo_dumb,
- bo_dumb->gem, bo_dumb->name,
- bo_dumb->dmabuf,
- arg.fd,
- bo_dumb->flags_tbm,
- bo_dumb->size);
+ if (error)
+ *error = TBM_ERROR_NONE;
- return (tbm_fd)arg.fd;
+ return bo_dumb->flags_tbm;
}
static tbm_bo_handle
@@ -1114,6 +1355,76 @@ tbm_dumb_bo_unlock(tbm_backend_bo_data *bo_data)
return TBM_ERROR_NONE;
}
+tbm_fd
+tbm_dumb_bo_export_fd(tbm_backend_bo_data *bo_data, tbm_error_e *error)
+{
+ tbm_bo_dumb bo_dumb = (tbm_bo_dumb)bo_data;
+ int ret;
+ char buf[STRERR_BUFSIZE];
+
+ if (!bo_dumb) {
+ if (error)
+ *error = TBM_ERROR_INVALID_PARAMETER;
+ return -1;
+ }
+
+ struct drm_prime_handle arg = {0, };
+
+ arg.handle = bo_dumb->gem;
+ ret = drmIoctl(bo_dumb->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &arg);
+ if (ret) {
+ TBM_DUMB_ERROR("bo_dumb:%p Cannot dmabuf=%d (%s)\n",
+ bo_dumb, bo_dumb->gem, strerror_r(errno, buf, STRERR_BUFSIZE));
+ if (error)
+ *error = TBM_ERROR_OPERATION_FAILED;
+ return (tbm_fd) ret;
+ }
+
+ TBM_DUMB_DEBUG(" bo_dumb:%p, gem:%d(%d), fd:%d, key_fd:%d, flags:%d, size:%d\n",
+ bo_dumb,
+ bo_dumb->gem, bo_dumb->name,
+ bo_dumb->dmabuf,
+ arg.fd,
+ bo_dumb->flags_tbm,
+ bo_dumb->size);
+
+ return (tbm_fd)arg.fd;
+}
+
+static tbm_key
+tbm_dumb_bo_export_key(tbm_backend_bo_data *bo_data, tbm_error_e *error)
+{
+ tbm_bo_dumb bo_dumb = (tbm_bo_dumb)bo_data;
+
+ if (!bo_dumb) {
+ if (error)
+ *error = TBM_ERROR_INVALID_PARAMETER;
+ return 0;
+ }
+
+ if (!bo_dumb->name) {
+ bo_dumb->name = _get_name(bo_dumb->fd, bo_dumb->gem);
+ if (!bo_dumb->name) {
+ TBM_DUMB_ERROR("error Cannot get name\n");
+ if (error)
+ *error = TBM_ERROR_INVALID_PARAMETER;
+ return 0;
+ }
+ }
+
+ TBM_DUMB_DEBUG(" bo_dumb:%p, gem:%d(%d), fd:%d, flags:%d, size:%d\n",
+ bo_dumb,
+ bo_dumb->gem, bo_dumb->name,
+ bo_dumb->dmabuf,
+ bo_dumb->flags_tbm,
+ bo_dumb->size);
+
+ if (error)
+ *error = TBM_ERROR_NONE;
+
+ return (tbm_key)bo_dumb->name;
+}
+
static void
tbm_dumb_deinit(tbm_backend_bufmgr_data *bufmgr_data)
{
@@ -1156,318 +1467,6 @@ tbm_dumb_deinit(tbm_backend_bufmgr_data *bufmgr_data)
free(bufmgr_dumb);
}
-static tbm_error_e
-tbm_dumb_bufmgr_get_supported_formats(tbm_backend_bufmgr_data *bufmgr_data,
- uint32_t **formats, uint32_t *num)
-{
- tbm_bufmgr_dumb bufmgr_dumb = (tbm_bufmgr_dumb)bufmgr_data;
- uint32_t *color_formats;
-
- DUMB_RETURN_VAL_IF_FAIL(bufmgr_dumb != NULL, TBM_ERROR_INVALID_PARAMETER);
-
- color_formats = (uint32_t *)calloc(1, sizeof(uint32_t) * TBM_COLOR_FORMAT_COUNT);
- if (color_formats == NULL)
- return TBM_ERROR_OUT_OF_MEMORY;
-
- memcpy(color_formats, tbm_dumb_color_format_list, sizeof(uint32_t)*TBM_COLOR_FORMAT_COUNT);
-
- *formats = color_formats;
- *num = TBM_COLOR_FORMAT_COUNT;
-
- TBM_DUMB_DEBUG("supported format count = %d\n", *num);
-
- return TBM_ERROR_NONE;
-}
-
-
-static tbm_error_e
-tbm_dumb_bufmgr_get_plane_data(tbm_backend_bufmgr_data *bufmgr_data,
- tbm_format format, int plane_idx, int width,
- int height, uint32_t *size, uint32_t *offset,
- uint32_t *pitch, int *bo_idx)
-{
- tbm_bufmgr_dumb bufmgr_dumb = (tbm_bufmgr_dumb)bufmgr_data;
- int bpp;
- int _offset = 0;
- int _pitch = 0;
- int _size = 0;
- int _bo_idx = 0;
-
- DUMB_RETURN_VAL_IF_FAIL(bufmgr_dumb != NULL, TBM_ERROR_INVALID_PARAMETER);
-
- switch (format) {
- /* 16 bpp RGB */
- case TBM_FORMAT_XRGB4444:
- case TBM_FORMAT_XBGR4444:
- case TBM_FORMAT_RGBX4444:
- case TBM_FORMAT_BGRX4444:
- case TBM_FORMAT_ARGB4444:
- case TBM_FORMAT_ABGR4444:
- case TBM_FORMAT_RGBA4444:
- case TBM_FORMAT_BGRA4444:
- case TBM_FORMAT_XRGB1555:
- case TBM_FORMAT_XBGR1555:
- case TBM_FORMAT_RGBX5551:
- case TBM_FORMAT_BGRX5551:
- case TBM_FORMAT_ARGB1555:
- case TBM_FORMAT_ABGR1555:
- case TBM_FORMAT_RGBA5551:
- case TBM_FORMAT_BGRA5551:
- case TBM_FORMAT_RGB565:
- bpp = 16;
- _offset = 0;
- _pitch = SIZE_ALIGN((width * bpp)>>3, TBM_SURFACE_ALIGNMENT_PITCH_RGB);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- break;
- /* 24 bpp RGB */
- case TBM_FORMAT_RGB888:
- case TBM_FORMAT_BGR888:
- bpp = 24;
- _offset = 0;
- _pitch = SIZE_ALIGN((width * bpp)>>3, TBM_SURFACE_ALIGNMENT_PITCH_RGB);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- break;
- /* 32 bpp RGB */
- case TBM_FORMAT_XRGB8888:
- case TBM_FORMAT_XBGR8888:
- case TBM_FORMAT_RGBX8888:
- case TBM_FORMAT_BGRX8888:
- case TBM_FORMAT_ARGB8888:
- case TBM_FORMAT_ABGR8888:
- case TBM_FORMAT_RGBA8888:
- case TBM_FORMAT_BGRA8888:
- bpp = 32;
- _offset = 0;
- _pitch = SIZE_ALIGN((width * bpp)>>3, TBM_SURFACE_ALIGNMENT_PITCH_RGB);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- break;
-
- /* packed YCbCr */
- case TBM_FORMAT_YUYV:
- case TBM_FORMAT_YVYU:
- case TBM_FORMAT_UYVY:
- case TBM_FORMAT_VYUY:
- case TBM_FORMAT_AYUV:
- bpp = 32;
- _offset = 0;
- _pitch = SIZE_ALIGN((width * bpp)>>3, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- break;
-
- /*
- * 2 plane YCbCr
- * index 0 = Y plane, [7:0] Y
- * index 1 = Cr:Cb plane, [15:0] Cr:Cb little endian
- * or
- * index 1 = Cb:Cr plane, [15:0] Cb:Cr little endian
- */
- case TBM_FORMAT_NV12:
- case TBM_FORMAT_NV21:
- bpp = 12;
- if (plane_idx == 0) {
- _offset = 0;
- _pitch = SIZE_ALIGN(width , TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- } else if (plane_idx == 1) {
- _offset = width*height;
- _pitch = SIZE_ALIGN(width , TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
- _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- }
- break;
-
- case TBM_FORMAT_NV16:
- case TBM_FORMAT_NV61:
- bpp = 16;
- //if (plane_idx == 0)
- {
- _offset = 0;
- _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- if (plane_idx == 0)
- break;
- }
- //else if (plane_idx == 1)
- {
- _offset += _size;
- _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- }
- break;
-
- /*
- * 3 plane YCbCr
- * index 0: Y plane, [7:0] Y
- * index 1: Cb plane, [7:0] Cb
- * index 2: Cr plane, [7:0] Cr
- * or
- * index 1: Cr plane, [7:0] Cr
- * index 2: Cb plane, [7:0] Cb
- */
- /*
- NATIVE_BUFFER_FORMAT_YV12
- NATIVE_BUFFER_FORMAT_I420
- */
- case TBM_FORMAT_YUV410:
- case TBM_FORMAT_YVU410:
- bpp = 9;
- break;
- case TBM_FORMAT_YUV411:
- case TBM_FORMAT_YVU411:
- case TBM_FORMAT_YUV420:
- case TBM_FORMAT_YVU420:
- bpp = 12;
- //if (plane_idx == 0)
- {
- _offset = 0;
- _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- if (plane_idx == 0)
- break;
- }
- //else if (plane_idx == 1)
- {
- _offset += _size;
- _pitch = SIZE_ALIGN(width/2, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
- _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- if (plane_idx == 1)
- break;
- }
- //else if (plane_idx == 2)
- {
- _offset += _size;
- _pitch = SIZE_ALIGN(width/2, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
- _size = SIZE_ALIGN(_pitch * (height / 2), TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- }
- break;
- case TBM_FORMAT_YUV422:
- case TBM_FORMAT_YVU422:
- bpp = 16;
- //if (plane_idx == 0)
- {
- _offset = 0;
- _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- if (plane_idx == 0)
- break;
- }
- //else if (plane_idx == 1)
- {
- _offset += _size;
- _pitch = SIZE_ALIGN(width/2, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- if (plane_idx == 1)
- break;
- }
- //else if (plane_idx == 2)
- {
- _offset += _size;
- _pitch = SIZE_ALIGN(width/2, TBM_SURFACE_ALIGNMENT_PITCH_YUV/2);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- }
- break;
- case TBM_FORMAT_YUV444:
- case TBM_FORMAT_YVU444:
- bpp = 24;
- //if (plane_idx == 0)
- {
- _offset = 0;
- _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- if (plane_idx == 0)
- break;
- }
- //else if (plane_idx == 1)
- {
- _offset += _size;
- _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- if (plane_idx == 1)
- break;
- }
- //else if (plane_idx == 2)
- {
- _offset += _size;
- _pitch = SIZE_ALIGN(width, TBM_SURFACE_ALIGNMENT_PITCH_YUV);
- _size = SIZE_ALIGN(_pitch * height, TBM_SURFACE_ALIGNMENT_PLANE);
- _bo_idx = 0;
- }
- break;
- default:
- bpp = 0;
- break;
- }
-
- *size = _size;
- *offset = _offset;
- *pitch = _pitch;
- *bo_idx = _bo_idx;
-
- return TBM_ERROR_NONE;
-}
-
-static tbm_bo_memory_type
-tbm_dumb_bo_get_memory_type(tbm_backend_bo_data *bo_data, tbm_error_e *error)
-{
- tbm_bo_dumb bo_dumb = (tbm_bo_dumb)bo_data;
-
- if (!bo_dumb) {
- if (error)
- *error = TBM_ERROR_INVALID_PARAMETER;
- return TBM_BO_DEFAULT;
- }
-
- if (error)
- *error = TBM_ERROR_NONE;
-
- return bo_dumb->flags_tbm;
-}
-
-static tbm_bufmgr_capability
-tbm_dumb_bufmgr_get_capabilities(tbm_backend_bufmgr_data *bufmgr_data, tbm_error_e *error)
-{
- tbm_bufmgr_capability capabilities = TBM_BUFMGR_CAPABILITY_NONE;
-
- capabilities = TBM_BUFMGR_CAPABILITY_SHARE_KEY|TBM_BUFMGR_CAPABILITY_SHARE_FD;
-
- if (error)
- *error = TBM_ERROR_NONE;
-
- return capabilities;
-}
-
-static tbm_error_e
-tbm_dumb_bufmgr_bind_native_display(tbm_backend_bufmgr_data *bufmgr_data, tbm_native_display *native_display)
-{
- tbm_bufmgr_dumb bufmgr_dumb = (tbm_bufmgr_dumb)bufmgr_data;
- DUMB_RETURN_VAL_IF_FAIL(bufmgr_dumb != NULL, TBM_ERROR_INVALID_PARAMETER);
-
- if (!tbm_drm_helper_wl_auth_server_init(native_display, bufmgr_dumb->fd,
- bufmgr_dumb->device_name, 0)) {
- TBM_DUMB_ERROR("fail to tbm_drm_helper_wl_server_init\n");
- return TBM_ERROR_OPERATION_FAILED;
- }
-
- bufmgr_dumb->bind_display = native_display;
-
- return TBM_ERROR_NONE;
-}
-
static tbm_backend_bufmgr_data *
tbm_dumb_init(tbm_bufmgr bufmgr, tbm_error_e *error)
{