summaryrefslogtreecommitdiff
path: root/src/lib/ecore_drm/ecore_drm_fb.c
diff options
context:
space:
mode:
authorChris Michael <cp.michael@samsung.com>2014-03-06 09:43:48 +0000
committerChris Michael <cp.michael@samsung.com>2014-03-06 10:57:26 +0000
commit3762e85c3967a7a7574c83bf6d550d58e58d90fc (patch)
tree48e695cf560924cf0b800f682371dfe1eb74de7e /src/lib/ecore_drm/ecore_drm_fb.c
parent0f1883df9a978d686971bba9f1450b7eb7a3fd84 (diff)
ecore-drm: Add Ecore_Drm code
@feature: Add Ecore_Drm library code for setting up drm card, outputs, virtual terminals, framebuffers, and input for use with ecore_evas drm code. Signed-off-by: Chris Michael <cp.michael@samsung.com>
Diffstat (limited to 'src/lib/ecore_drm/ecore_drm_fb.c')
-rw-r--r--src/lib/ecore_drm/ecore_drm_fb.c151
1 files changed, 151 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..40dd473ed9
--- /dev/null
+++ b/src/lib/ecore_drm/ecore_drm_fb.c
@@ -0,0 +1,151 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "ecore_drm_private.h"
6
7/**
8 * @defgroup Ecore_Drm_Fb_Group
9 *
10 */
11
12/* TODO: DOXY !! */
13
14EAPI Ecore_Drm_Fb *
15ecore_drm_fb_create(Ecore_Drm_Device *dev, int width, int height)
16{
17 Ecore_Drm_Fb *fb;
18 struct drm_mode_create_dumb carg;
19 struct drm_mode_destroy_dumb darg;
20 struct drm_mode_map_dumb marg;
21
22 if (!(fb = calloc(1, sizeof(Ecore_Drm_Fb)))) return NULL;
23
24 memset(&carg, 0, sizeof(struct drm_mode_create_dumb));
25
26 carg.bpp = 32; // FIXME: Hard-coded depth
27 carg.width = width;
28 carg.height = height;
29
30 if (drmIoctl(dev->drm.fd, DRM_IOCTL_MODE_CREATE_DUMB, &carg))
31 {
32 ERR("Could not create dumb framebuffer: %m");
33 goto create_err;
34 }
35
36 fb->from_client = EINA_TRUE;
37 fb->hdl = carg.handle;
38 fb->stride = carg.pitch;
39 fb->size = carg.size;
40 fb->fd = dev->drm.fd;
41
42 if (drmModeAddFB(dev->drm.fd, width, height, 24, 32,
43 fb->stride, fb->hdl, &fb->id))
44 {
45 ERR("Could not add framebuffer: %m");
46 goto add_err;
47 }
48
49 memset(&marg, 0, sizeof(struct drm_mode_map_dumb));
50 marg.handle = fb->hdl;
51 if (drmIoctl(dev->drm.fd, DRM_IOCTL_MODE_MAP_DUMB, &marg))
52 {
53 ERR("Could not map framebuffer: %m");
54 goto map_err;
55 }
56
57 fb->mmap =
58 mmap(0, fb->size, PROT_WRITE | PROT_READ, MAP_SHARED,
59 dev->drm.fd, marg.offset);
60 if (fb->mmap == MAP_FAILED)
61 {
62 ERR("Could not mmap framebuffer space: %m");
63 goto map_err;
64 }
65
66 memset(fb->mmap, 0, fb->size);
67
68 return fb;
69
70map_err:
71 drmModeRmFB(fb->fd, fb->id);
72add_err:
73 memset(&darg, 0, sizeof(struct drm_mode_destroy_dumb));
74 darg.handle = fb->hdl;
75 drmIoctl(dev->drm.fd, DRM_IOCTL_MODE_DESTROY_DUMB, &darg);
76create_err:
77 free(fb);
78 return NULL;
79}
80
81EAPI void
82ecore_drm_fb_destroy(Ecore_Drm_Fb *fb)
83{
84 struct drm_mode_destroy_dumb darg;
85
86 if ((!fb) || (!fb->mmap)) return;
87
88 if (fb->id) drmModeRmFB(fb->fd, fb->id);
89 munmap(fb->mmap, fb->size);
90 memset(&darg, 0, sizeof(struct drm_mode_destroy_dumb));
91 darg.handle = fb->hdl;
92 drmIoctl(fb->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &darg);
93 free(fb);
94}
95
96/* #ifdef HAVE_GBM */
97/* static void */
98/* _ecore_drm_fb_user_data_destroy(struct gbm_bo *bo EINA_UNUSED, void *data) */
99/* { */
100/* Ecore_Drm_Fb *fb; */
101
102/* if (!(fb = data)) return; */
103/* ecore_drm_fb_destroy(fb); */
104/* } */
105
106/* Ecore_Drm_Fb * */
107/* _ecore_drm_fb_bo_get(Ecore_Drm_Device *dev, struct gbm_bo *bo) */
108/* { */
109/* Ecore_Drm_Fb *fb; */
110/* unsigned int width, height; */
111/* unsigned int h[4], p[4], o[4]; */
112/* int ret = -1; */
113
114/* if ((fb = gbm_bo_get_user_data(bo))) return fb; */
115
116/* if (!(fb = calloc(1, sizeof(Ecore_Drm_Fb)))) return NULL; */
117
118/* fb->bo = bo; */
119
120/* width = gbm_bo_get_width(bo); */
121/* height = gbm_bo_get_height(bo); */
122/* fb->stride = gbm_bo_get_stride(bo); */
123/* fb->hdl = gbm_bo_get_handle(bo).u32; */
124/* fb->size = (fb->stride * height); */
125/* fb->fd = dev->drm.fd; */
126
127/* h[0] = fb->hdl; */
128/* p[0] = fb->stride; */
129/* o[0] = 0; */
130
131/* ret = drmModeAddFB2(dev->drm.fd, width, height, dev->format, h, p, o, */
132/* &fb->id, 0); */
133/* if (ret) */
134/* { */
135/* ret = drmModeAddFB(dev->drm.fd, width, height, 24, 32, */
136/* fb->stride, fb->hdl, &fb->id); */
137
138/* } */
139
140/* if (ret) */
141/* { */
142/* ERR("Error during ModeAddFb"); */
143/* free(fb); */
144/* return NULL; */
145/* } */
146
147/* gbm_bo_set_user_data(bo, fb, _ecore_drm_fb_user_data_destroy); */
148
149/* return fb; */
150/* } */
151/* #endif */