aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Michael <cp.michael@samsung.com>2014-01-02 08:00:00 +0000
committerChris Michael <cp.michael@samsung.com>2014-01-29 15:27:22 +0000
commit9584b01c03c63db9b918b6493c9a3c41287ad99c (patch)
tree4f940cf86f4d657430aa089b7514168324340686
parentAdd code to setup drm outputs for hardware or software rendering (diff)
downloadefl-9584b01c03c63db9b918b6493c9a3c41287ad99c.tar.gz
Add ecore_drm_fb file for framebuffer functions
Signed-off-by: Chris Michael <cp.michael@samsung.com>
-rw-r--r--src/lib/ecore_drm/ecore_drm_fb.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/lib/ecore_drm/ecore_drm_fb.c b/src/lib/ecore_drm/ecore_drm_fb.c
new file mode 100644
index 0000000000..fb96c13767
--- /dev/null
+++ b/src/lib/ecore_drm/ecore_drm_fb.c
@@ -0,0 +1,83 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "ecore_drm_private.h"
+
+Ecore_Drm_Fb *
+_ecore_drm_fb_create(Ecore_Drm_Device *dev, int width, int height)
+{
+ Ecore_Drm_Fb *fb;
+ struct drm_mode_create_dumb carg;
+ struct drm_mode_destroy_dumb darg;
+ struct drm_mode_map_dumb marg;
+
+ if (!(fb = calloc(1, sizeof(Ecore_Drm_Fb)))) return NULL;
+
+ memset(&carg, 0, sizeof(struct drm_mode_create_dumb));
+
+ carg.bpp = 32; // FIXME: Hard-coded depth
+ carg.width = width;
+ carg.height = height;
+
+ if (drmIoctl(dev->drm.fd, DRM_IOCTL_MODE_CREATE_DUMB, &carg))
+ {
+ ERR("Could not create dumb framebuffer: %m");
+ goto create_err;
+ }
+
+ fb->hdl = carg.handle;
+ fb->stride = carg.pitch;
+ fb->size = carg.size;
+ fb->fd = dev->drm.fd;
+
+ if (drmModeAddFB(dev->drm.fd, width, height, 24, 32,
+ fb->stride, fb->hdl, &fb->id))
+ {
+ ERR("Could not add framebuffer: %m");
+ goto add_err;
+ }
+
+ memset(&marg, 0, sizeof(struct drm_mode_map_dumb));
+ marg.handle = fb->hdl;
+ if (drmIoctl(dev->drm.fd, DRM_IOCTL_MODE_MAP_DUMB, &marg))
+ {
+ ERR("Could not map framebuffer: %m");
+ goto map_err;
+ }
+
+ fb->mmap =
+ mmap(0, fb->size, PROT_WRITE, MAP_SHARED, dev->drm.fd, marg.offset);
+ if (fb->mmap == MAP_FAILED)
+ {
+ ERR("Could not mmap framebuffer space: %m");
+ goto map_err;
+ }
+
+ return fb;
+
+map_err:
+ drmModeRmFB(fb->fd, fb->id);
+add_err:
+ memset(&darg, 0, sizeof(struct drm_mode_destroy_dumb));
+ darg.handle = fb->hdl;
+ drmIoctl(dev->drm.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &darg);
+create_err:
+ free(fb);
+ return NULL;
+}
+
+void
+_ecore_drm_fb_destroy(Ecore_Drm_Fb *fb)
+{
+ struct drm_mode_destroy_dumb darg;
+
+ if ((!fb) || (!fb->mmap)) return;
+
+ if (fb->id) drmModeRmFB(fb->fd, fb->id);
+ munmap(fb->mmap, fb->size);
+ memset(&darg, 0, sizeof(struct drm_mode_destroy_dumb));
+ darg.handle = fb->hdl;
+ drmIoctl(fb->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &darg);
+ free(fb);
+}