diff options
author | Mateusz Krawczuk <m.krawczuk@samsung.com> | 2015-06-12 20:17:26 +0200 |
---|---|---|
committer | Sylwester Nawrocki <s.nawrocki@samsung.com> | 2015-07-09 15:55:04 +0200 |
commit | e0679a35cb7d216948ddd4cd8c17940fdb872a9e (patch) | |
tree | 461356432e5331ef6e2330ca57660cded3b81bdc /v4l2-mfc-example | |
parent | 2915635a0a4d03fe442399a679a42a92b33c8b99 (diff) |
v4l2-mfc-example: Adding DRM IPP code and refactoring old DRM
Signed-off-by: Mateusz Krawczuk <m.krawczuk@samsung.com>
Diffstat (limited to 'v4l2-mfc-example')
-rw-r--r-- | v4l2-mfc-example/drm.c | 82 | ||||
-rw-r--r-- | v4l2-mfc-example/drm.h | 7 |
2 files changed, 57 insertions, 32 deletions
diff --git a/v4l2-mfc-example/drm.c b/v4l2-mfc-example/drm.c index 16d9ee5..1b408b5 100644 --- a/v4l2-mfc-example/drm.c +++ b/v4l2-mfc-example/drm.c @@ -1,6 +1,7 @@ /* * V4L2 Codec decoding example application * Kamil Debski <k.debski@samsung.com> + * Mateusz Krawczuk <m.krawczuk@samsung.com> * * DRM operations * @@ -31,6 +32,7 @@ #include "drm.h" #include <string.h> #include <errno.h> +#include <drm/drm_fourcc.h> #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) @@ -53,7 +55,8 @@ char * res##_str(int type) { \ #include <xf86drm.h> #include <xf86drmMode.h> -#include <exynos_drm.h> +#include <drm/exynos_drm.h> +#include "gem.h" struct type_name encoder_type_names[] = { { DRM_MODE_ENCODER_NONE, "none" }, @@ -93,12 +96,15 @@ struct type_name connector_type_names[] = { type_name_fn(connector_type) - int dump_encoders(struct instance *i); int dump_connectors(struct instance *i); int dump_crtcs(struct instance *i); int dump_framebuffers(struct instance *i); + +/* + * drm_open calls functions to detect DRM parameters and setup gem and display. + */ int drm_open(struct instance *i) { char mode[32]; @@ -110,23 +116,31 @@ int drm_open(struct instance *i) unsigned int fb_id; int ret; int n; - struct drm_mode_map_dumb arg; void *map = NULL; - +/* + *Open drm file descriptor + */ i->drm.fd =drmOpen(name, NULL); if (i->drm.fd < 0) { err("Failed to open drm module \"%s\"", name); return -1; - } + } i->drm.resources = drmModeGetResources(i->drm.fd); +/* + *Auto detect Crtc and Connectors + */ - i->drm.resources = drmModeGetResources(i->drm.fd); if(i->drm.autodetect) { i->drm.crtc_id = dump_crtcs(i); - i->drm.conn_id=dump_connectors(i); + i->drm.conn_id = dump_connectors(i); } printf("Conn_id:%i \n",i->drm.conn_id); printf("Crtc_id:%i \n",i->drm.crtc_id); + +/* + *Detect screen width and height + */ + crtc = drmModeGetCrtc(i->drm.fd, i->drm.crtc_id); if (!crtc) { err("Failed to get crtc: %d", i->drm.crtc_id); @@ -136,41 +150,28 @@ int drm_open(struct instance *i) i->drm.width = crtc->width; i->drm.height = crtc->height; - dbg("DRM crtc (%d) resolution: %dx%d @", i->drm.crtc_id, i->drm.width, + printf("DRM crtc (%d) resolution: %dx%d @", i->drm.crtc_id, i->drm.width, i->drm.height); drmModeFreeCrtc(crtc); - for (n = 0; n < (i->fimc.double_buf?2:1); n++) { + for (n = 0; n < 3; n++) { i->drm.gem[n].size = i->drm.width * i->drm.height * 4; ret = ioctl(i->drm.fd, DRM_IOCTL_EXYNOS_GEM_CREATE, &i->drm.gem[n]); if (ret < 0) { - err("Failed to create gem"); + fprintf(stderr, + "Failed to Create Gem %s\n", strerror(errno)); return -1; } args.handle = i->drm.gem[n].handle; - if (i->fimc.dmabuf) { + if (i->fimc.dmabuf) ret = drmPrimeHandleToFD(i->drm.fd, i->drm.gem[n].handle, DRM_CLOEXEC, &i->fimc.dbuf[n]); if (ret < 0) { ioctl(i->drm.fd, DRM_IOCTL_GEM_CLOSE, &args); err("Failed to expbuf a gem object"); return -1; } - } else { - memset(&arg, 0, sizeof(&arg)); - arg.handle = i->drm.gem[n].handle; - ret = ioctl(i->drm.fd, DRM_IOCTL_MODE_MAP_DUMB, &arg); - if (ret < 0) { - ioctl(i->drm.fd, DRM_IOCTL_GEM_CLOSE, &args); - err("Failed to mmap gem"); - return -1; - } - i->drm.mmap[n].offset = arg.offset; - i->drm.p[n] = (char *)(unsigned int)map; - i->fimc.p[n] = (char *)(unsigned int)map; - map = mmap(0, i->drm.gem[n].size, PROT_READ | PROT_WRITE, MAP_SHARED,i->drm.fd, i->drm.mmap[n].offset); - } ret = drmModeAddFB(i->drm.fd, i->drm.width, i->drm.height, 32, 32, 4 * i->drm.width, i->drm.gem[n].handle, &fb_id); if (ret) { @@ -183,8 +184,9 @@ int drm_open(struct instance *i) } snprintf(mode, 32, "%dx%d", crtc->width, crtc->height); - - +/* + * Use detected Connector + */ connector = drmModeGetConnector(i->drm.fd, i->drm.conn_id); if (!connector || connector->connector_id != i->drm.conn_id) { err("Couldn't find the connector"); @@ -206,7 +208,9 @@ int drm_open(struct instance *i) drmModeFreeConnector(connector); return -1; } - +/* + * Use detected Crtc + */ ret = drmModeSetCrtc(i->drm.fd, i->drm.crtc_id, i->drm.fb[0], 0, 0, &i->drm.conn_id, 1, mode_drm); if (ret) { @@ -214,25 +218,39 @@ int drm_open(struct instance *i) drmModeFreeConnector(connector); return -1; } - +/* + * Setup fimc if DRM IPP is not enabled + */ + if(i->fimc.enabled) { i->fimc.width = i->drm.width; i->fimc.height = i->drm.height; i->fimc.stride = i->drm.width * 4; i->fimc.bpp = 32; i->fimc.buffers = (i->fimc.double_buf?2:1); i->fimc.size = i->drm.width * i->drm.height * 4; - + } i->drm.crtc[0] = i->drm.crtc_id; i->drm.crtc[1] = i->drm.crtc_id; + if(i->ipp.enabled) { + exynos_drm_ipp_setup(i); + + } + return 0; } +/* + * Closing DRM and IPP + */ void drm_close(struct instance *i) { drmClose(i->drm.fd); + exynos_drm_ipp_close(i); } - +/* + * Requise instance to get drm file descriptor and put data to struct + */ int dump_encoders(struct instance *i) { drmModeEncoder *encoder; @@ -360,7 +378,7 @@ int dump_framebuffers(struct instance *i) return 0; } -#else /* DRM */ +#else /*if DRM is Disabled*/ int drm_open(struct instance *i) { diff --git a/v4l2-mfc-example/drm.h b/v4l2-mfc-example/drm.h index ab2e4f0..5a6725c 100644 --- a/v4l2-mfc-example/drm.h +++ b/v4l2-mfc-example/drm.h @@ -23,12 +23,17 @@ #ifndef INCLUDE_DRM_H #define INCLUDE_DRM_H +#include <drm/drm_fourcc.h> +#include <linux/videodev2.h> + #ifdef DRM /* Open and mmap DRM buffer. Also read its properties */ int drm_open(struct instance *i); /* Unmap and close the buffer */ void drm_close(struct instance *i); +extern int exynos_drm_ipp_init(struct instance *i); +void exynos_drm_ipp_close(struct instance *inst); struct connector { uint32_t id; @@ -42,6 +47,8 @@ struct connector { int swap_count; }; + + #endif /* DRM */ #endif /* INCLUDE_DRM_H */ |