diff options
author | Vasiliy Ulyanov <v.ulyanov@samsung.com> | 2015-02-25 17:42:59 +0300 |
---|---|---|
committer | Joonyoung Shim <jy0922.shim@samsung.com> | 2017-02-15 13:37:33 +0900 |
commit | 16205359731c351c8ad21678489705ff82eb031f (patch) | |
tree | d286e148b6778a4bd33da99c7988d31a08c7cfde | |
parent | a7719998cfcf0764a114eda2ec0da6f60de71254 (diff) | |
download | libdrm-16205359731c351c8ad21678489705ff82eb031f.tar.gz libdrm-16205359731c351c8ad21678489705ff82eb031f.tar.bz2 libdrm-16205359731c351c8ad21678489705ff82eb031f.zip |
VIGS: add PRIME functions
Change-Id: I488c4529c1fb1f52aec9081cb6eb82c40d256dc3
Signed-off-by: Vasiliy Ulyanov <v.ulyanov@samsung.com>
-rw-r--r-- | vigs/Makefile.am | 2 | ||||
-rw-r--r-- | vigs/vigs.c | 83 | ||||
-rw-r--r-- | vigs/vigs.h | 17 |
3 files changed, 101 insertions, 1 deletions
diff --git a/vigs/Makefile.am b/vigs/Makefile.am index fdc77400..06014707 100644 --- a/vigs/Makefile.am +++ b/vigs/Makefile.am @@ -12,7 +12,7 @@ AM_CFLAGS = \ libdrm_vigs_la_LTLIBRARIES = libdrm_vigs.la libdrm_vigs_ladir = $(libdir) -libdrm_vigs_la_LDFLAGS = -version-number 9:0:0 -no-undefined +libdrm_vigs_la_LDFLAGS = -version-number 10:0:0 -no-undefined libdrm_vigs_la_LIBADD = ../libdrm.la @PTHREADSTUBS_LIBS@ libdrm_vigs_la_SOURCES = vigs.c diff --git a/vigs/vigs.c b/vigs/vigs.c index 33a59d7a..bbab72fb 100644 --- a/vigs/vigs.c +++ b/vigs/vigs.c @@ -33,6 +33,7 @@ #include <stdio.h> #include <string.h> #include <errno.h> +#include <fcntl.h> #include <sys/mman.h> #include <linux/stddef.h> @@ -821,3 +822,85 @@ fail1: return ret; } + +int vigs_drm_prime_export_fd(struct vigs_drm_device *dev, + struct vigs_drm_surface *sfc, + int *prime_fd) +{ + struct drm_prime_handle req = { + .handle = sfc->gem.handle, + .flags = DRM_CLOEXEC, + }; + int ret; + + ret = drmIoctl(dev->fd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &req); + + if (ret) { + ret = -errno; + goto fail; + } + + *prime_fd = req.fd; + +fail: + return ret; +} + +int vigs_drm_prime_import_fd(struct vigs_drm_device *dev, + int prime_fd, + struct vigs_drm_surface **sfc) +{ + struct vigs_drm_surface_impl *sfc_impl; + struct drm_vigs_surface_info info_req; + struct drm_prime_handle req = { + .fd = prime_fd, + }; + int ret; + + ret = drmIoctl(dev->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &req); + + if (ret) { + ret = -errno; + goto err; + } + + sfc_impl = calloc(sizeof(*sfc_impl), 1); + + if (!sfc_impl) { + ret = -ENOMEM; + goto err; + } + + memset(&info_req, 0, sizeof(info_req)); + info_req.handle = req.handle; + + ret = drmIoctl(dev->fd, DRM_IOCTL_VIGS_SURFACE_INFO, &info_req); + + if (ret) { + ret = -errno; + goto err_free_sfc_impl; + } + + vigs_drm_gem_impl_init((struct vigs_drm_gem_impl*)sfc_impl, + dev, + req.handle, + info_req.size, + 0 /* name */); + + sfc_impl->base.width = info_req.width; + sfc_impl->base.height = info_req.height; + sfc_impl->base.stride = info_req.stride; + sfc_impl->base.format = info_req.format; + sfc_impl->base.scanout = info_req.scanout; + sfc_impl->base.id = info_req.id; + + *sfc = &sfc_impl->base; + + return 0; + +err_free_sfc_impl: + free(sfc_impl); + +err: + return ret; +} diff --git a/vigs/vigs.h b/vigs/vigs.h index 7453431b..a225fe3b 100644 --- a/vigs/vigs.h +++ b/vigs/vigs.h @@ -286,6 +286,23 @@ int vigs_drm_dp_surface_open(struct vigs_drm_device *dev, * @} */ +/* + * PRIME functions. + * @{ + */ + +int vigs_drm_prime_export_fd(struct vigs_drm_device *dev, + struct vigs_drm_surface *sfc, + int *prime_fd); + +int vigs_drm_prime_import_fd(struct vigs_drm_device *dev, + int prime_fd, + struct vigs_drm_surface **sfc); + +/* + * @} + */ + #ifdef __cplusplus }; #endif /* __cplusplus */ |