diff options
author | Emil Velikov <emil.velikov@collabora.com> | 2018-03-30 15:17:11 +0100 |
---|---|---|
committer | Christian Gmeiner <christian.gmeiner@gmail.com> | 2018-04-02 13:55:57 +0200 |
commit | 4f7cec00b6e2ccf8ee3b8575b77303e65c1acea9 (patch) | |
tree | 518eccd9576b0529c166721cdf335e87e51e2a90 /drm-common.c | |
parent | aac3788d2844872a0b66eb2994f773e13326d642 (diff) | |
download | kmscube-4f7cec00b6e2ccf8ee3b8575b77303e65c1acea9.tar.gz |
Use weak functions to handle lack of gbm modifiers
Add weak function declaration and check if they're valid prior
to calling the functions.
This allows us to remove conditional compilation, yet allowing the
modifiers codepath to work if API is available.
Cc: Christian Gmeiner <christian.gmeiner@gmail.com>
Cc: Rob Clark <robdclark@gmail.com>
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Reviewed-by: Rob Clark <robdclark@gmail.com>
Diffstat (limited to 'drm-common.c')
-rw-r--r-- | drm-common.c | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/drm-common.c b/drm-common.c index 1ec2820..136fe69 100644 --- a/drm-common.c +++ b/drm-common.c @@ -31,6 +31,18 @@ #include "common.h" #include "drm-common.h" +WEAK uint64_t +gbm_bo_get_modifier(struct gbm_bo *bo); + +WEAK int +gbm_bo_get_plane_count(struct gbm_bo *bo); + +WEAK uint32_t +gbm_bo_get_stride_for_plane(struct gbm_bo *bo, int plane); + +WEAK uint32_t +gbm_bo_get_offset(struct gbm_bo *bo, int plane); + static void drm_fb_destroy_callback(struct gbm_bo *bo, void *data) { @@ -62,26 +74,29 @@ struct drm_fb * drm_fb_get_from_bo(struct gbm_bo *bo) height = gbm_bo_get_height(bo); format = gbm_bo_get_format(bo); -#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 (gbm_bo_get_modifier && gbm_bo_get_plane_count && + gbm_bo_get_stride_for_plane && gbm_bo_get_offset) { + + 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 %" PRIx64 "\n", modifiers[0]); + } - if (modifiers[0]) { - flags = DRM_MODE_FB_MODIFIERS; - printf("Using modifier %" PRIx64 "\n", modifiers[0]); + ret = drmModeAddFB2WithModifiers(drm_fd, width, height, + format, handles, strides, offsets, + modifiers, &fb->fb_id, flags); } - ret = drmModeAddFB2WithModifiers(drm_fd, width, height, - format, handles, strides, offsets, - modifiers, &fb->fb_id, flags); -#endif if (ret) { if (flags) fprintf(stderr, "Modifiers failed!\n"); |