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
30 | 30 | |
31 | 31 | static struct gbm gbm; |
32 | 32 | |
33 | #ifndef DRM_FORMAT_MOD_LINEAR | |
34 | #define DRM_FORMAT_MOD_LINEAR 0 | |
35 | #endif | |
36 | ||
37 | 33 | #ifdef HAVE_GBM_MODIFIERS |
38 | 34 | static int |
39 | 35 | get_modifiers(uint64_t **mods) |
45 | 41 | } |
46 | 42 | #endif |
47 | 43 | |
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) | |
49 | 45 | { |
50 | 46 | gbm.dev = gbm_create_device(drm_fd); |
51 | 47 | |
52 | 48 | #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 | } | |
53 | 53 | gbm.surface = gbm_surface_create(gbm.dev, w, h, |
54 | 54 | GBM_FORMAT_XRGB8888, |
55 | 55 | GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING); |
56 | 56 | #else |
57 | 57 | 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 | } | |
59 | 65 | gbm.surface = gbm_surface_create_with_modifiers(gbm.dev, w, h, |
60 | 66 | GBM_FORMAT_XRGB8888, mods, count); |
61 | 67 | #endif |
31 | 31 | #include <gbm.h> |
32 | 32 | #include <drm_fourcc.h> |
33 | 33 | |
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 | ||
34 | 42 | #ifndef EGL_KHR_platform_gbm |
35 | 43 | #define EGL_KHR_platform_gbm 1 |
36 | 44 | #define EGL_PLATFORM_GBM_KHR 0x31D7 |
54 | 62 | int width, height; |
55 | 63 | }; |
56 | 64 | |
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); | |
58 | 66 | |
59 | 67 | |
60 | 68 | struct egl { |
25 | 25 | |
26 | 26 | #include <string.h> |
27 | 27 | #include <stdio.h> |
28 | #include <stdlib.h> | |
28 | 29 | #include <getopt.h> |
29 | 30 | |
30 | 31 | #include "common.h" |
40 | 41 | static const struct gbm *gbm; |
41 | 42 | static const struct drm *drm; |
42 | 43 | |
43 | static const char *shortopts = "AD:M:V:"; | |
44 | static const char *shortopts = "AD:M:m:V:"; | |
44 | 45 | |
45 | 46 | static const struct option longopts[] = { |
46 | 47 | {"atomic", no_argument, 0, 'A'}, |
47 | 48 | {"device", required_argument, 0, 'D'}, |
48 | 49 | {"mode", required_argument, 0, 'M'}, |
50 | {"modifier", required_argument, 0, 'm'}, | |
49 | 51 | {"video", required_argument, 0, 'V'}, |
50 | 52 | {0, 0, 0, 0} |
51 | 53 | }; |
52 | 54 | |
53 | 55 | static void usage(const char *name) |
54 | 56 | { |
55 | printf("Usage: %s [-ADMV]\n" | |
57 | printf("Usage: %s [-ADMmV]\n" | |
56 | 58 | "\n" |
57 | 59 | "options:\n" |
58 | 60 | " -A, --atomic use atomic modesetting and fencing\n" |
62 | 64 | " rgba - rgba textured cube\n" |
63 | 65 | " nv12-2img - yuv textured (color conversion in shader)\n" |
64 | 66 | " nv12-1img - yuv textured (single nv12 texture)\n" |
67 | " -m, --modifier=MODIFIER hardcode the selected modifier\n" | |
65 | 68 | " -V, --video=FILE video textured cube\n", |
66 | 69 | name); |
67 | 70 | } |
71 | 74 | const char *device = "/dev/dri/card0"; |
72 | 75 | const char *video = NULL; |
73 | 76 | enum mode mode = SMOOTH; |
77 | uint64_t modifier = DRM_FORMAT_MOD_INVALID; | |
74 | 78 | int atomic = 0; |
75 | 79 | int opt; |
76 | 80 | |
101 | 105 | return -1; |
102 | 106 | } |
103 | 107 | break; |
108 | case 'm': | |
109 | modifier = strtoull(optarg, NULL, 0); | |
110 | break; | |
104 | 111 | case 'V': |
105 | 112 | mode = VIDEO; |
106 | 113 | video = optarg; |
120 | 127 | return -1; |
121 | 128 | } |
122 | 129 | |
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); | |
124 | 132 | if (!gbm) { |
125 | 133 | printf("failed to initialize GBM\n"); |
126 | 134 | return -1; |