external/gbm_gralloc
Revision | c8de380a3c3ba2737702bceb4741cba8663fea4a (tree) |
---|---|
Zeit | 2018-11-01 07:01:46 |
Autor | lambdadroid <lambdadroid@gmai...> |
Commiter | lambdadroid |
Add simple framebuffer HAL implementation using drm_framebuffer
@@ -32,6 +32,8 @@ LOCAL_SHARED_LIBRARIES := \ | ||
32 | 32 | liblog \ |
33 | 33 | libcutils |
34 | 34 | |
35 | +LOCAL_STATIC_LIBRARIES := libdrm_framebuffer | |
36 | + | |
35 | 37 | LOCAL_EXPORT_C_INCLUDE_DIRS := \ |
36 | 38 | $(LOCAL_PATH) |
37 | 39 |
@@ -35,6 +35,7 @@ | ||
35 | 35 | #include <system/graphics.h> |
36 | 36 | |
37 | 37 | #include <gbm.h> |
38 | +#include <drm_framebuffer.h> | |
38 | 39 | |
39 | 40 | #include "gralloc_drm.h" |
40 | 41 | #include "gralloc_gbm_priv.h" |
@@ -44,18 +45,19 @@ struct gbm_module_t { | ||
44 | 45 | |
45 | 46 | pthread_mutex_t mutex; |
46 | 47 | struct gbm_device *gbm; |
48 | + struct drm_framebuffer *fb; | |
47 | 49 | }; |
48 | 50 | |
49 | 51 | /* |
50 | 52 | * Initialize the DRM device object |
51 | 53 | */ |
52 | -static int gbm_init(struct gbm_module_t *dmod) | |
54 | +static int gbm_init(struct gbm_module_t *dmod, bool master = false) | |
53 | 55 | { |
54 | 56 | int err = 0; |
55 | 57 | |
56 | 58 | pthread_mutex_lock(&dmod->mutex); |
57 | 59 | if (!dmod->gbm) { |
58 | - dmod->gbm = gbm_dev_create(); | |
60 | + dmod->gbm = gbm_dev_create(master); | |
59 | 61 | if (!dmod->gbm) |
60 | 62 | err = -EINVAL; |
61 | 63 | } |
@@ -105,6 +107,8 @@ static int gbm_mod_register_buffer(const gralloc_module_t *mod, | ||
105 | 107 | |
106 | 108 | pthread_mutex_lock(&dmod->mutex); |
107 | 109 | err = gralloc_gbm_handle_register(handle, dmod->gbm); |
110 | + if (err == 0 && dmod->fb) | |
111 | + drm_framebuffer_import(dmod->fb, handle); | |
108 | 112 | pthread_mutex_unlock(&dmod->mutex); |
109 | 113 | |
110 | 114 | return err; |
@@ -218,6 +222,19 @@ static int gbm_mod_open_gpu0(struct gbm_module_t *dmod, hw_device_t **dev) | ||
218 | 222 | return 0; |
219 | 223 | } |
220 | 224 | |
225 | +static int gbm_mod_open_fb0(struct gbm_module_t *dmod, hw_device_t **dev) | |
226 | +{ | |
227 | + int err = gbm_init(dmod, true); | |
228 | + if (err) | |
229 | + return err; | |
230 | + | |
231 | + pthread_mutex_lock(&dmod->mutex); | |
232 | + err = drm_framebuffer_open(gbm_device_get_fd(dmod->gbm), &dmod->fb, dev); | |
233 | + pthread_mutex_unlock(&dmod->mutex); | |
234 | + | |
235 | + return err; | |
236 | +} | |
237 | + | |
221 | 238 | static int gbm_mod_open(const struct hw_module_t *mod, |
222 | 239 | const char *name, struct hw_device_t **dev) |
223 | 240 | { |
@@ -226,6 +243,8 @@ static int gbm_mod_open(const struct hw_module_t *mod, | ||
226 | 243 | |
227 | 244 | if (strcmp(name, GRALLOC_HARDWARE_GPU0) == 0) |
228 | 245 | err = gbm_mod_open_gpu0(dmod, dev); |
246 | + else if (strcmp(name, GRALLOC_HARDWARE_FB0) == 0) | |
247 | + err = gbm_mod_open_fb0(dmod, dev); | |
229 | 248 | else |
230 | 249 | err = -EINVAL; |
231 | 250 |
@@ -306,13 +306,13 @@ void gbm_dev_destroy(struct gbm_device *gbm) | ||
306 | 306 | close(fd); |
307 | 307 | } |
308 | 308 | |
309 | -struct gbm_device *gbm_dev_create(void) | |
309 | +struct gbm_device *gbm_dev_create(bool master) | |
310 | 310 | { |
311 | 311 | struct gbm_device *gbm; |
312 | 312 | char path[PROPERTY_VALUE_MAX]; |
313 | 313 | int fd; |
314 | 314 | |
315 | - property_get("gralloc.gbm.device", path, "/dev/dri/renderD128"); | |
315 | + property_get("gralloc.gbm.device", path, master ? "/dev/dri/card0" : "/dev/dri/renderD128"); | |
316 | 316 | fd = open(path, O_RDWR | O_CLOEXEC); |
317 | 317 | if (fd < 0) { |
318 | 318 | ALOGE("failed to open %s", path); |
@@ -46,7 +46,7 @@ int gralloc_gbm_get_gem_handle(buffer_handle_t handle); | ||
46 | 46 | int gralloc_gbm_bo_lock(buffer_handle_t handle, int x, int y, int w, int h, int enable_write, void **addr); |
47 | 47 | int gralloc_gbm_bo_unlock(buffer_handle_t handle); |
48 | 48 | |
49 | -struct gbm_device *gbm_dev_create(void); | |
49 | +struct gbm_device *gbm_dev_create(bool master); | |
50 | 50 | void gbm_dev_destroy(struct gbm_device *gbm); |
51 | 51 | |
52 | 52 | #ifdef __cplusplus |