summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Widawsky <ben@bwidawsk.net>2016-12-01 10:24:47 -0800
committerBen Widawsky <ben@bwidawsk.net>2017-04-14 14:09:09 -0700
commit6ad9e67a729848a50f77c507de27c047c21f4c4d (patch)
treef1984519e03346e06276463a546784b3fd69c112
parent616128f4c21fe16eae02d1aee1597279cfb986e1 (diff)
common: Give cmdline parameter for forcing modifiersmod-prep
-rw-r--r--common.c18
-rw-r--r--common.h11
-rw-r--r--kmscube.c14
3 files changed, 33 insertions, 10 deletions
diff --git a/common.c b/common.c
index eda92b0..64c4f91 100644
--- a/common.c
+++ b/common.c
@@ -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
diff --git a/common.h b/common.h
index 2eceac7..0cddb66 100644
--- a/common.h
+++ b/common.h
@@ -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
@@ -53,9 +61,10 @@ struct gbm {
struct gbm_device *dev;
struct gbm_surface *surface;
int width, height;
+ uint64_t forced_modifier;
};
-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 {
diff --git a/kmscube.c b/kmscube.c
index 63a133b..6dcfd2f 100644
--- a/kmscube.c
+++ b/kmscube.c
@@ -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;