Instead of changing the code each time, allow the fourcc to be passed in as an argument.
Signed-off-by: Ilia Mirkin <imir...@alum.mit.edu> --- common.c | 4 ++-- common.h | 2 +- kmscube.c | 20 +++++++++++++++++++- texturator.c | 2 +- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/common.c b/common.c index b6f3e9b..b60b833 100644 --- a/common.c +++ b/common.c @@ -40,10 +40,10 @@ gbm_surface_create_with_modifiers(struct gbm_device *gbm, const uint64_t *modifiers, const unsigned int count); -const struct gbm * init_gbm(int drm_fd, int w, int h, uint64_t modifier) +const struct gbm * init_gbm(int drm_fd, int w, int h, uint32_t format, uint64_t modifier) { gbm.dev = gbm_create_device(drm_fd); - gbm.format = GBM_FORMAT_XRGB8888; + gbm.format = format; gbm.surface = NULL; if (gbm_surface_create_with_modifiers) { diff --git a/common.h b/common.h index d461262..6540763 100644 --- a/common.h +++ b/common.h @@ -99,7 +99,7 @@ struct gbm { int width, height; }; -const struct gbm * init_gbm(int drm_fd, int w, int h, uint64_t modifier); +const struct gbm * init_gbm(int drm_fd, int w, int h, uint32_t format, uint64_t modifier); struct egl { diff --git a/kmscube.c b/kmscube.c index 90de638..6a1c2af 100644 --- a/kmscube.c +++ b/kmscube.c @@ -46,6 +46,7 @@ static const char *shortopts = "AD:M:m:V:v:"; static const struct option longopts[] = { {"atomic", no_argument, 0, 'A'}, {"device", required_argument, 0, 'D'}, + {"format", required_argument, 0, 'f'}, {"mode", required_argument, 0, 'M'}, {"modifier", required_argument, 0, 'm'}, {"samples", required_argument, 0, 's'}, @@ -66,6 +67,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" + " -f, --format=FOURCC framebuffer format\n" " -m, --modifier=MODIFIER hardcode the selected modifier\n" " -s, --samples=N use MSAA\n" " -V, --video=FILE video textured cube\n" @@ -81,6 +83,7 @@ int main(int argc, char *argv[]) char mode_str[DRM_DISPLAY_MODE_LEN] = ""; char *p; enum mode mode = SMOOTH; + uint32_t format = DRM_FORMAT_XRGB8888; uint64_t modifier = DRM_FORMAT_MOD_LINEAR; int samples = 0; int atomic = 0; @@ -101,6 +104,21 @@ int main(int argc, char *argv[]) case 'D': device = optarg; break; + case 'f': { + char fourcc[4] = " "; + int length = strlen(optarg); + if (length > 0) + fourcc[0] = optarg[0]; + if (length > 1) + fourcc[1] = optarg[1]; + if (length > 2) + fourcc[2] = optarg[2]; + if (length > 3) + fourcc[3] = optarg[3]; + format = fourcc_code(fourcc[0], fourcc[1], + fourcc[2], fourcc[3]); + break; + } case 'M': if (strcmp(optarg, "smooth") == 0) { mode = SMOOTH; @@ -155,7 +173,7 @@ int main(int argc, char *argv[]) } gbm = init_gbm(drm->fd, drm->mode->hdisplay, drm->mode->vdisplay, - modifier); + format, modifier); if (!gbm) { printf("failed to initialize GBM\n"); return -1; diff --git a/texturator.c b/texturator.c index ddd8014..555f81f 100644 --- a/texturator.c +++ b/texturator.c @@ -955,7 +955,7 @@ int main(int argc, char *argv[]) } gbm = init_gbm(drm->fd, drm->mode->hdisplay, drm->mode->vdisplay, - DRM_FORMAT_MOD_LINEAR); + DRM_FORMAT_XRGB8888, DRM_FORMAT_MOD_LINEAR); if (!gbm) { printf("failed to initialize GBM\n"); return -1; -- 2.21.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev