Codebase list kmscube / 5816934
common: Give cmdline parameter for forcing modifiers Signed-off-by: Ben Widawsky <ben@bwidawsk.net> Reviewed-by: Emil Velikov <emil.velikov@collabora.com> Ben Widawsky 7 years ago
3 changed file(s) with 32 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
3030
3131 static struct gbm gbm;
3232
33 #ifndef DRM_FORMAT_MOD_LINEAR
34 #define DRM_FORMAT_MOD_LINEAR 0
35 #endif
36
3733 #ifdef HAVE_GBM_MODIFIERS
3834 static int
3935 get_modifiers(uint64_t **mods)
4541 }
4642 #endif
4743
48 const struct gbm * init_gbm(int drm_fd, int w, int h)
44 const struct gbm * init_gbm(int drm_fd, int w, int h, uint64_t modifier)
4945 {
5046 gbm.dev = gbm_create_device(drm_fd);
5147
5248 #ifndef HAVE_GBM_MODIFIERS
49 if (modifier != DRM_FORMAT_MOD_INVALID) {
50 fprintf(stderr, "Modifiers requested but support isn't available\n");
51 return NULL;
52 }
5353 gbm.surface = gbm_surface_create(gbm.dev, w, h,
5454 GBM_FORMAT_XRGB8888,
5555 GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
5656 #else
5757 uint64_t *mods;
58 int count = get_modifiers(&mods);
58 int count;
59 if (modifier != DRM_FORMAT_MOD_INVALID) {
60 count = 1;
61 mods = &modifier;
62 } else {
63 count = get_modifiers(&mods);
64 }
5965 gbm.surface = gbm_surface_create_with_modifiers(gbm.dev, w, h,
6066 GBM_FORMAT_XRGB8888, mods, count);
6167 #endif
3131 #include <gbm.h>
3232 #include <drm_fourcc.h>
3333
34 #ifndef DRM_FORMAT_MOD_LINEAR
35 #define DRM_FORMAT_MOD_LINEAR 0
36 #endif
37
38 #ifndef DRM_FORMAT_MOD_INVALID
39 #define DRM_FORMAT_MOD_INVALID ((((__u64)0) << 56) | ((1ULL << 56) - 1))
40 #endif
41
3442 #ifndef EGL_KHR_platform_gbm
3543 #define EGL_KHR_platform_gbm 1
3644 #define EGL_PLATFORM_GBM_KHR 0x31D7
5462 int width, height;
5563 };
5664
57 const struct gbm * init_gbm(int drm_fd, int w, int h);
65 const struct gbm * init_gbm(int drm_fd, int w, int h, uint64_t modifier);
5866
5967
6068 struct egl {
2525
2626 #include <string.h>
2727 #include <stdio.h>
28 #include <stdlib.h>
2829 #include <getopt.h>
2930
3031 #include "common.h"
4041 static const struct gbm *gbm;
4142 static const struct drm *drm;
4243
43 static const char *shortopts = "AD:M:V:";
44 static const char *shortopts = "AD:M:m:V:";
4445
4546 static const struct option longopts[] = {
4647 {"atomic", no_argument, 0, 'A'},
4748 {"device", required_argument, 0, 'D'},
4849 {"mode", required_argument, 0, 'M'},
50 {"modifier", required_argument, 0, 'm'},
4951 {"video", required_argument, 0, 'V'},
5052 {0, 0, 0, 0}
5153 };
5254
5355 static void usage(const char *name)
5456 {
55 printf("Usage: %s [-ADMV]\n"
57 printf("Usage: %s [-ADMmV]\n"
5658 "\n"
5759 "options:\n"
5860 " -A, --atomic use atomic modesetting and fencing\n"
6264 " rgba - rgba textured cube\n"
6365 " nv12-2img - yuv textured (color conversion in shader)\n"
6466 " nv12-1img - yuv textured (single nv12 texture)\n"
67 " -m, --modifier=MODIFIER hardcode the selected modifier\n"
6568 " -V, --video=FILE video textured cube\n",
6669 name);
6770 }
7174 const char *device = "/dev/dri/card0";
7275 const char *video = NULL;
7376 enum mode mode = SMOOTH;
77 uint64_t modifier = DRM_FORMAT_MOD_INVALID;
7478 int atomic = 0;
7579 int opt;
7680
101105 return -1;
102106 }
103107 break;
108 case 'm':
109 modifier = strtoull(optarg, NULL, 0);
110 break;
104111 case 'V':
105112 mode = VIDEO;
106113 video = optarg;
120127 return -1;
121128 }
122129
123 gbm = init_gbm(drm->fd, drm->mode->hdisplay, drm->mode->vdisplay);
130 gbm = init_gbm(drm->fd, drm->mode->hdisplay, drm->mode->vdisplay,
131 modifier);
124132 if (!gbm) {
125133 printf("failed to initialize GBM\n");
126134 return -1;