[Mesa-dev] [PATCH kmscube 6/6] common: Give cmdline parameter for forcing modifiers

Ben Widawsky ben at bwidawsk.net
Thu Apr 13 18:22:17 UTC 2017


---
 common.c  | 13 ++++++++-----
 common.h  | 11 ++++++++++-
 kmscube.c | 14 +++++++++++---
 3 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/common.c b/common.c
index e63bb39..eaaa9a4 100644
--- a/common.c
+++ b/common.c
@@ -31,9 +31,6 @@
 
 static struct gbm gbm;
 
-#ifndef DRM_FORMAT_MOD_LINEAR
-#define DRM_FORMAT_MOD_LINEAR 0
-#endif
 static int
 get_modifiers(uint64_t **mods)
 {
@@ -43,7 +40,7 @@ get_modifiers(uint64_t **mods)
 	return 1;
 }
 
-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);
 
@@ -57,7 +54,13 @@ const struct gbm * init_gbm(int drm_fd, int w, int h)
 	}
 #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 f3d9d32..03634cc 100644
--- a/common.h
+++ b/common.h
@@ -36,6 +36,14 @@
   #include "config.h"
 #endif
 
+#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
@@ -57,9 +65,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;
-- 
2.12.2



More information about the mesa-dev mailing list