summaryrefslogtreecommitdiff
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:05:52 -0700
commit616128f4c21fe16eae02d1aee1597279cfb986e1 (patch)
tree56a64facff390175391ba8bad8df7da2c7c7374a
parent431417736173d16b7dbd097ba10cd97033860155 (diff)
common: use drmModeAddFB2* API over the legacy drmModeAddFB one
Note: nothing happens here yet since LINEAR == 0.
-rw-r--r--common.c10
-rw-r--r--configure.ac2
-rw-r--r--drm-common.c40
3 files changed, 41 insertions, 11 deletions
diff --git a/common.c b/common.c
index 6b8849d..eda92b0 100644
--- a/common.c
+++ b/common.c
@@ -54,10 +54,6 @@ const struct gbm * init_gbm(int drm_fd, int w, int h)
gbm.surface = gbm_surface_create(gbm.dev, w, h,
GBM_FORMAT_XRGB8888,
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
- if (!gbm.surface) {
- printf("failed to create gbm surface\n");
- return NULL;
- }
#else
uint64_t *mods;
int count = get_modifiers(&mods);
@@ -65,13 +61,17 @@ const struct gbm * init_gbm(int drm_fd, int w, int h)
GBM_FORMAT_XRGB8888, mods, count);
#endif
+ if (!gbm.surface) {
+ printf("failed to create gbm surface\n");
+ return NULL;
+ }
+
gbm.width = w;
gbm.height = h;
return &gbm;
}
-
int init_egl(struct egl *egl, const struct gbm *gbm)
{
EGLint major, minor, n;
diff --git a/configure.ac b/configure.ac
index 33167e4..f564ef3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -35,7 +35,7 @@ AC_PROG_CC
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
# Obtain compiler/linker options for depedencies
-PKG_CHECK_MODULES(DRM, libdrm)
+PKG_CHECK_MODULES(DRM, [libdrm >= 2.4.71])
PKG_CHECK_MODULES(GBM, gbm >= 13.0)
PKG_CHECK_MODULES(EGL, egl)
PKG_CHECK_MODULES(GLES2, glesv2)
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);