diff options
-rw-r--r-- | common.c | 18 | ||||
-rw-r--r-- | common.h | 10 | ||||
-rw-r--r-- | kmscube.c | 14 |
3 files changed, 32 insertions, 10 deletions
@@ -31,10 +31,6 @@ static struct gbm gbm; -#ifndef DRM_FORMAT_MOD_LINEAR -#define DRM_FORMAT_MOD_LINEAR 0 -#endif - #ifdef HAVE_GBM_MODIFIERS static int get_modifiers(uint64_t **mods) @@ -46,17 +42,27 @@ get_modifiers(uint64_t **mods) } #endif -const struct gbm * init_gbm(int drm_fd, int w, int h) +const struct gbm * init_gbm(int drm_fd, int w, int h, uint64_t modifier) { gbm.dev = gbm_create_device(drm_fd); #ifndef HAVE_GBM_MODIFIERS + if (modifier != DRM_FORMAT_MOD_INVALID) { + fprintf(stderr, "Modifiers requested but support isn't available\n"); + return NULL; + } gbm.surface = gbm_surface_create(gbm.dev, w, h, GBM_FORMAT_XRGB8888, GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); #else uint64_t *mods; - int count = get_modifiers(&mods); + int count; + if (modifier != DRM_FORMAT_MOD_INVALID) { + count = 1; + mods = &modifier; + } else { + count = get_modifiers(&mods); + } gbm.surface = gbm_surface_create_with_modifiers(gbm.dev, w, h, GBM_FORMAT_XRGB8888, mods, count); #endif @@ -32,6 +32,14 @@ #include <gbm.h> #include <drm_fourcc.h> +#ifndef DRM_FORMAT_MOD_LINEAR +#define DRM_FORMAT_MOD_LINEAR 0 +#endif + +#ifndef DRM_FORMAT_MOD_INVALID +#define DRM_FORMAT_MOD_INVALID ((((__u64)0) << 56) | ((1ULL << 56) - 1)) +#endif + #ifndef EGL_KHR_platform_gbm #define EGL_KHR_platform_gbm 1 #define EGL_PLATFORM_GBM_KHR 0x31D7 @@ -55,7 +63,7 @@ struct gbm { int width, height; }; -const struct gbm * init_gbm(int drm_fd, int w, int h); +const struct gbm * init_gbm(int drm_fd, int w, int h, uint64_t modifier); struct egl { @@ -26,6 +26,7 @@ #include <string.h> #include <stdio.h> +#include <stdlib.h> #include <getopt.h> #include "common.h" @@ -41,19 +42,20 @@ static const struct egl *egl; static const struct gbm *gbm; static const struct drm *drm; -static const char *shortopts = "AD:M:V:"; +static const char *shortopts = "AD:M:m:V:"; static const struct option longopts[] = { {"atomic", no_argument, 0, 'A'}, {"device", required_argument, 0, 'D'}, {"mode", required_argument, 0, 'M'}, + {"modifier", required_argument, 0, 'm'}, {"video", required_argument, 0, 'V'}, {0, 0, 0, 0} }; static void usage(const char *name) { - printf("Usage: %s [-ADMV]\n" + printf("Usage: %s [-ADMmV]\n" "\n" "options:\n" " -A, --atomic use atomic modesetting and fencing\n" @@ -63,6 +65,7 @@ static void usage(const char *name) " rgba - rgba textured cube\n" " nv12-2img - yuv textured (color conversion in shader)\n" " nv12-1img - yuv textured (single nv12 texture)\n" + " -m, --modifier=MODIFIER hardcode the selected modifier\n" " -V, --video=FILE video textured cube\n", name); } @@ -72,6 +75,7 @@ int main(int argc, char *argv[]) const char *device = "/dev/dri/card0"; const char *video = NULL; enum mode mode = SMOOTH; + uint64_t modifier = DRM_FORMAT_MOD_INVALID; int atomic = 0; int opt; @@ -102,6 +106,9 @@ int main(int argc, char *argv[]) return -1; } break; + case 'm': + modifier = strtoull(optarg, NULL, 0); + break; case 'V': mode = VIDEO; video = optarg; @@ -121,7 +128,8 @@ int main(int argc, char *argv[]) return -1; } - gbm = init_gbm(drm->fd, drm->mode->hdisplay, drm->mode->vdisplay); + gbm = init_gbm(drm->fd, drm->mode->hdisplay, drm->mode->vdisplay, + modifier); if (!gbm) { printf("failed to initialize GBM\n"); return -1; |