45 | 45 |
{
|
46 | 46 |
int drm_fd = gbm_device_get_fd(gbm_bo_get_device(bo));
|
47 | 47 |
struct drm_fb *fb = gbm_bo_get_user_data(bo);
|
48 | |
uint32_t width, height, stride, handle;
|
49 | |
int ret;
|
|
48 |
uint32_t width, height,
|
|
49 |
strides[4] = {0}, handles[4] = {0},
|
|
50 |
offsets[4] = {0}, flags = 0;
|
|
51 |
int ret = -1;
|
50 | 52 |
|
51 | 53 |
if (fb)
|
52 | 54 |
return fb;
|
|
56 | 58 |
|
57 | 59 |
width = gbm_bo_get_width(bo);
|
58 | 60 |
height = gbm_bo_get_height(bo);
|
59 | |
stride = gbm_bo_get_stride(bo);
|
60 | |
handle = gbm_bo_get_handle(bo).u32;
|
61 | |
|
62 | |
ret = drmModeAddFB(drm_fd, width, height, 24, 32, stride, handle, &fb->fb_id);
|
|
61 |
|
|
62 |
#ifdef HAVE_GBM_MODIFIERS
|
|
63 |
uint64_t modifiers[4] = {0};
|
|
64 |
modifiers[0] = gbm_bo_get_modifier(bo);
|
|
65 |
const int num_planes = gbm_bo_get_plane_count(bo);
|
|
66 |
for (int i = 0; i < num_planes; i++) {
|
|
67 |
strides[i] = gbm_bo_get_stride_for_plane(bo, i);
|
|
68 |
handles[i] = gbm_bo_get_handle(bo).u32;
|
|
69 |
offsets[i] = gbm_bo_get_offset(bo, i);
|
|
70 |
modifiers[i] = modifiers[0];
|
|
71 |
}
|
|
72 |
|
|
73 |
if (modifiers[0]) {
|
|
74 |
flags = DRM_MODE_FB_MODIFIERS;
|
|
75 |
printf("Using modifier %lx\n", modifiers[0]);
|
|
76 |
}
|
|
77 |
|
|
78 |
ret = drmModeAddFB2WithModifiers(drm_fd, width, height,
|
|
79 |
DRM_FORMAT_XRGB8888, handles, strides, offsets,
|
|
80 |
modifiers, &fb->fb_id, flags);
|
|
81 |
#endif
|
|
82 |
if (ret) {
|
|
83 |
if (flags)
|
|
84 |
fprintf(stderr, "Modifiers failed!\n");
|
|
85 |
|
|
86 |
memcpy(handles, (uint32_t [4]){gbm_bo_get_handle(bo).u32,0,0,0}, 16);
|
|
87 |
memcpy(strides, (uint32_t [4]){gbm_bo_get_stride(bo),0,0,0}, 16);
|
|
88 |
memset(offsets, 0, 16);
|
|
89 |
ret = drmModeAddFB2(drm_fd, width, height, DRM_FORMAT_XRGB8888,
|
|
90 |
handles, strides, offsets, &fb->fb_id, 0);
|
|
91 |
}
|
|
92 |
|
63 | 93 |
if (ret) {
|
64 | 94 |
printf("failed to create fb: %s\n", strerror(errno));
|
65 | 95 |
free(fb);
|