-
Notifications
You must be signed in to change notification settings - Fork 12
/
gbm.c
47 lines (37 loc) · 1.01 KB
/
gbm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <gbm.h>
#include <assert.h>
#include <stdio.h>
static struct gbm_device *gbm;
void gbm_init(int drm_fd) {
gbm = gbm_create_device(drm_fd);
assert(gbm);
}
struct gbm_device *gbm_get_device() {
return gbm;
}
struct gbm_bo *gbm_import_from_dmabuf(int num_fds, int32_t *dmabuf_fds,
uint32_t width, uint32_t height, uint32_t format, uint32_t *strides, uint32_t
*offsets, uint64_t modifier) {
struct gbm_import_fd_modifier_data data = {
.width = width,
.height = height,
.format = format,
.num_fds = 1,
.fds[0] = dmabuf_fds[0],
.strides[0] = strides[0],
.offsets[0] = offsets[0],
.modifier = modifier
};
struct gbm_bo *gbm_bo = gbm_bo_import(gbm,
GBM_BO_IMPORT_FD_MODIFIER, &data, GBM_BO_USE_SCANOUT);
if (!gbm_bo) {
fprintf(stderr, "gbm_bo_import failed\n");
return 0;
}
return gbm_bo;
}
void gbm_destroy(struct gbm_bo *gbm_bo) { gbm_bo_destroy(gbm_bo); }
uint32_t gbm_get_handle(struct gbm_bo *gbm_bo) { return gbm_bo_get_handle(gbm_bo).u32; }
void gbm_fini() {
gbm_device_destroy(gbm);
}