Codebase list kmscube / a0a4c02
kmscube: add command-line selection of video mode The mode of type "DRM_MODE_TYPE_PREFERED" can be miss-configured, making kmscube not working. Plus, user could need to test the other available video modes at the connector. Add a command line flag to specify the video mode. If the mode is not present, print an informative message and fall-back to the default behaviour (preferred mode or highest resolution mode). Signed-off-by: Antonio Borneo <antonio.borneo@st.com> Reviewed-by: Emil Velikov <emil.velikov@collabora.com> Antonio Borneo authored 5 years ago Antonio Borneo committed 4 years ago
6 changed file(s) with 64 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
336336 return ret;
337337 }
338338
339 const struct drm * init_drm_atomic(const char *device)
339 const struct drm * init_drm_atomic(const char *device, const char *mode_str, unsigned int vrefresh)
340340 {
341341 uint32_t plane_id;
342342 int ret;
343343
344 ret = init_drm(&drm, device);
344 ret = init_drm(&drm, device, mode_str, vrefresh);
345345 if (ret)
346346 return NULL;
347347
159159 return -1;
160160 }
161161
162 int init_drm(struct drm *drm, const char *device)
162 int init_drm(struct drm *drm, const char *device, const char *mode_str, unsigned int vrefresh)
163163 {
164164 drmModeRes *resources;
165165 drmModeConnector *connector = NULL;
198198 return -1;
199199 }
200200
201 /* find user requested mode: */
202 if (mode_str && *mode_str) {
203 for (i = 0; i < connector->count_modes; i++) {
204 drmModeModeInfo *current_mode = &connector->modes[i];
205
206 if (strcmp(current_mode->name, mode_str) == 0) {
207 if (vrefresh == 0 || current_mode->vrefresh == vrefresh) {
208 drm->mode = current_mode;
209 break;
210 }
211 }
212 }
213 if (!drm->mode)
214 printf("requested mode not found, using default mode!\n");
215 }
216
201217 /* find preferred mode or the highest resolution mode: */
202 for (i = 0, area = 0; i < connector->count_modes; i++) {
203 drmModeModeInfo *current_mode = &connector->modes[i];
204
205 if (current_mode->type & DRM_MODE_TYPE_PREFERRED) {
206 drm->mode = current_mode;
207 break;
208 }
209
210 int current_area = current_mode->hdisplay * current_mode->vdisplay;
211 if (current_area > area) {
212 drm->mode = current_mode;
213 area = current_area;
218 if (!drm->mode) {
219 for (i = 0, area = 0; i < connector->count_modes; i++) {
220 drmModeModeInfo *current_mode = &connector->modes[i];
221
222 if (current_mode->type & DRM_MODE_TYPE_PREFERRED) {
223 drm->mode = current_mode;
224 break;
225 }
226
227 int current_area = current_mode->hdisplay * current_mode->vdisplay;
228 if (current_area > area) {
229 drm->mode = current_mode;
230 area = current_area;
231 }
214232 }
215233 }
216234
7272
7373 struct drm_fb * drm_fb_get_from_bo(struct gbm_bo *bo);
7474
75 int init_drm(struct drm *drm, const char *device);
76 const struct drm * init_drm_legacy(const char *device);
77 const struct drm * init_drm_atomic(const char *device);
75 int init_drm(struct drm *drm, const char *device, const char *mode_str, unsigned int vrefresh);
76 const struct drm * init_drm_legacy(const char *device, const char *mode_str, unsigned int vrefresh);
77 const struct drm * init_drm_atomic(const char *device, const char *mode_str, unsigned int vrefresh);
7878
7979 #endif /* _DRM_COMMON_H */
121121 return 0;
122122 }
123123
124 const struct drm * init_drm_legacy(const char *device)
124 const struct drm * init_drm_legacy(const char *device, const char *mode_str, unsigned int vrefresh)
125125 {
126126 int ret;
127127
128 ret = init_drm(&drm, device);
128 ret = init_drm(&drm, device, mode_str, vrefresh);
129129 if (ret)
130130 return NULL;
131131
4040 static const struct gbm *gbm;
4141 static const struct drm *drm;
4242
43 static const char *shortopts = "AD:M:m:V:";
43 static const char *shortopts = "AD:M:m:V:v:";
4444
4545 static const struct option longopts[] = {
4646 {"atomic", no_argument, 0, 'A'},
4949 {"modifier", required_argument, 0, 'm'},
5050 {"samples", required_argument, 0, 's'},
5151 {"video", required_argument, 0, 'V'},
52 {"vmode", required_argument, 0, 'v'},
5253 {0, 0, 0, 0}
5354 };
5455
5556 static void usage(const char *name)
5657 {
57 printf("Usage: %s [-ADMmV]\n"
58 printf("Usage: %s [-ADMmVv]\n"
5859 "\n"
5960 "options:\n"
6061 " -A, --atomic use atomic modesetting and fencing\n"
6667 " nv12-1img - yuv textured (single nv12 texture)\n"
6768 " -m, --modifier=MODIFIER hardcode the selected modifier\n"
6869 " -s, --samples=N use MSAA\n"
69 " -V, --video=FILE video textured cube\n",
70 " -V, --video=FILE video textured cube\n"
71 " -v, --vmode=VMODE specify the video mode in the format\n"
72 " <mode>[-<vrefresh>]\n",
7073 name);
7174 }
7275
7477 {
7578 const char *device = "/dev/dri/card0";
7679 const char *video = NULL;
80 char mode_str[DRM_DISPLAY_MODE_LEN] = "";
81 char *p;
7782 enum mode mode = SMOOTH;
7883 uint64_t modifier = DRM_FORMAT_MOD_LINEAR;
7984 int samples = 0;
8085 int atomic = 0;
8186 int opt;
87 unsigned int len;
88 unsigned int vrefresh = 0;
8289
8390 #ifdef HAVE_GST
8491 gst_init(&argc, &argv);
118125 mode = VIDEO;
119126 video = optarg;
120127 break;
128 case 'v':
129 p = strchr(optarg, '-');
130 if (p == NULL) {
131 len = strlen(optarg);
132 } else {
133 vrefresh = strtoul(p + 1, NULL, 0);
134 len = p - optarg;
135 }
136 if (len > sizeof(mode_str) - 1)
137 len = sizeof(mode_str) - 1;
138 strncpy(mode_str, optarg, len);
139 mode_str[len] = '\0';
140 break;
121141 default:
122142 usage(argv[0]);
123143 return -1;
125145 }
126146
127147 if (atomic)
128 drm = init_drm_atomic(device);
148 drm = init_drm_atomic(device, mode_str, vrefresh);
129149 else
130 drm = init_drm_legacy(device);
150 drm = init_drm_legacy(device, mode_str, vrefresh);
131151 if (!drm) {
132152 printf("failed to initialize %s DRM\n", atomic ? "atomic" : "legacy");
133153 return -1;
927927 print_summary();
928928
929929 /* no real need for atomic here: */
930 drm = init_drm_legacy(device);
930 drm = init_drm_legacy(device, NULL, 0);
931931 if (!drm) {
932932 printf("failed to initialize DRM\n");
933933 return -1;