summaryrefslogtreecommitdiff
path: root/drm-common.c
diff options
context:
space:
mode:
authorBen Widawsky <ben@bwidawsk.net>2016-07-29 14:41:45 -0700
committerBen Widawsky <ben@bwidawsk.net>2017-04-14 14:14:10 -0700
commit13bd303d3ea8eb10f107dbd82be0259c5e5bd765 (patch)
tree56a64facff390175391ba8bad8df7da2c7c7374a /drm-common.c
parente5fb5659ebe11ad6c4e965495d8baced83c667f2 (diff)
downloadkmscube-13bd303d3ea8eb10f107dbd82be0259c5e5bd765.tar.gz
common: use drmModeAddFB2* API over the legacy drmModeAddFB one
Note: nothing happens here yet since LINEAR == 0. Signed-off-by: Ben Widawsky <ben@bwidawsk.net> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Diffstat (limited to 'drm-common.c')
-rw-r--r--drm-common.c40
1 files changed, 35 insertions, 5 deletions
diff --git a/drm-common.c b/drm-common.c
index b69ed70..2f2c918 100644
--- a/drm-common.c
+++ b/drm-common.c
@@ -46,8 +46,10 @@ struct drm_fb * drm_fb_get_from_bo(struct gbm_bo *bo)
{
int drm_fd = gbm_device_get_fd(gbm_bo_get_device(bo));
struct drm_fb *fb = gbm_bo_get_user_data(bo);
- uint32_t width, height, stride, handle;
- int ret;
+ uint32_t width, height,
+ strides[4] = {0}, handles[4] = {0},
+ offsets[4] = {0}, flags = 0;
+ int ret = -1;
if (fb)
return fb;
@@ -57,10 +59,38 @@ struct drm_fb * drm_fb_get_from_bo(struct gbm_bo *bo)
width = gbm_bo_get_width(bo);
height = gbm_bo_get_height(bo);
- stride = gbm_bo_get_stride(bo);
- handle = gbm_bo_get_handle(bo).u32;
- ret = drmModeAddFB(drm_fd, width, height, 24, 32, stride, handle, &fb->fb_id);
+#ifdef HAVE_GBM_MODIFIERS
+ uint64_t modifiers[4] = {0};
+ modifiers[0] = gbm_bo_get_modifier(bo);
+ const int num_planes = gbm_bo_get_plane_count(bo);
+ for (int i = 0; i < num_planes; i++) {
+ strides[i] = gbm_bo_get_stride_for_plane(bo, i);
+ handles[i] = gbm_bo_get_handle(bo).u32;
+ offsets[i] = gbm_bo_get_offset(bo, i);
+ modifiers[i] = modifiers[0];
+ }
+
+ if (modifiers[0]) {
+ flags = DRM_MODE_FB_MODIFIERS;
+ printf("Using modifier %lx\n", modifiers[0]);
+ }
+
+ ret = drmModeAddFB2WithModifiers(drm_fd, width, height,
+ DRM_FORMAT_XRGB8888, handles, strides, offsets,
+ modifiers, &fb->fb_id, flags);
+#endif
+ if (ret) {
+ if (flags)
+ fprintf(stderr, "Modifiers failed!\n");
+
+ memcpy(handles, (uint32_t [4]){gbm_bo_get_handle(bo).u32,0,0,0}, 16);
+ memcpy(strides, (uint32_t [4]){gbm_bo_get_stride(bo),0,0,0}, 16);
+ memset(offsets, 0, 16);
+ ret = drmModeAddFB2(drm_fd, width, height, DRM_FORMAT_XRGB8888,
+ handles, strides, offsets, &fb->fb_id, 0);
+ }
+
if (ret) {
printf("failed to create fb: %s\n", strerror(errno));
free(fb);