diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2017-09-11 08:10:07 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2017-09-11 08:10:07 +0200 |
commit | 069b8bca0dc60077eba891566f32aa91532e123c (patch) | |
tree | 73bcb58b4e0421e97de9316bd0faa2cbfc79ff2e | |
parent | e63f7620b6a8cb64a1d47adb789f51802163a8b7 (diff) | |
download | fbida-069b8bca0dc60077eba891566f32aa91532e123c.tar.gz |
mode switching for drm
-rw-r--r-- | drmtools-egl.c | 4 | ||||
-rw-r--r-- | drmtools.c | 27 | ||||
-rw-r--r-- | drmtools.h | 7 | ||||
-rw-r--r-- | fbi.c | 4 | ||||
-rw-r--r-- | fbpdf.c | 8 |
5 files changed, 34 insertions, 16 deletions
diff --git a/drmtools-egl.c b/drmtools-egl.c index 49932df..50a3408 100644 --- a/drmtools-egl.c +++ b/drmtools-egl.c @@ -163,7 +163,7 @@ static void drm_egl_flush_display(bool second) bo = newbo; } -gfxstate *drm_init_egl(const char *device, const char *output) +gfxstate *drm_init_egl(const char *device, const char *output, const char *mode) { gfxstate *gfx; char dev[64]; @@ -175,7 +175,7 @@ gfxstate *drm_init_egl(const char *device, const char *output) } fprintf(stderr, "trying drm/egl: %s ...\n", dev); - if (drm_init_dev(dev, output) < 0) + if (drm_init_dev(dev, output, mode) < 0) return NULL; if (drm_setup_egl() < 0) return NULL; @@ -75,10 +75,10 @@ void drm_cleanup_display(void) } } -int drm_init_dev(const char *dev, const char *output) +int drm_init_dev(const char *dev, const char *output, const char *mode) { drmModeRes *res; - char name[64]; + char name[64], m[64]; uint64_t has_dumb; int i, rc; @@ -127,7 +127,23 @@ int drm_init_dev(const char *dev, const char *output) } return -1; } - drm_mode = &drm_conn->modes[0]; + + if (mode) { + for (i = 0; i < drm_conn->count_modes; i++) { + snprintf(m, sizeof(m), "%dx%d", + drm_conn->modes[i].hdisplay, + drm_conn->modes[i].vdisplay); + if (strcmp(m, mode) == 0) { + fprintf(stderr, "Using mode %s\n", mode); + drm_mode = &drm_conn->modes[i]; + break; + } + } + } + if (!drm_mode) { + drm_mode = &drm_conn->modes[0]; + } + drm_enc = drmModeGetEncoder(drm_fd, drm_conn->encoder_id); if (drm_enc == NULL) { fprintf(stderr, "drm: drmModeGetEncoder() failed\n"); @@ -207,7 +223,8 @@ static void drm_flush_display(bool second) drmModeDirtyFB(drm_fd, fbc->id, 0, 0); } -gfxstate *drm_init(const char *device, const char *output, bool pageflip) +gfxstate *drm_init(const char *device, const char *output, + const char *mode, bool pageflip) { gfxstate *gfx; char dev[64]; @@ -219,7 +236,7 @@ gfxstate *drm_init(const char *device, const char *output, bool pageflip) } fprintf(stderr, "trying drm: %s ...\n", dev); - if (drm_init_dev(dev, output) < 0) + if (drm_init_dev(dev, output, mode) < 0) return NULL; if (drm_init_fb(&fb1) < 0) return NULL; @@ -7,11 +7,12 @@ extern drmModeEncoder *drm_enc; extern drmModeModeInfo *drm_mode; extern drmModeConnector *drm_conn; void drm_cleanup_display(void); -int drm_init_dev(const char *dev, const char *output); +int drm_init_dev(const char *dev, const char *output, const char *mode); /* drmtools.c */ -gfxstate *drm_init(const char *device, const char *output, bool pageflip); +gfxstate *drm_init(const char *device, const char *output, + const char *mode, bool pageflip); void drm_info(const char *device); /* drmtools-egl.c */ -gfxstate *drm_init_egl(const char *device, const char *output); +gfxstate *drm_init_egl(const char *device, const char *output, const char *mode); @@ -1405,14 +1405,14 @@ int main(int argc, char *argv[]) if (device) { /* device specified */ if (strncmp(device, "/dev/d", 6) == 0) { - gfx = drm_init(device, output, false); + gfx = drm_init(device, output, mode, false); } else { framebuffer = true; gfx = fb_init(device, mode, GET_VT()); } } else { /* try drm first, failing that fb */ - gfx = drm_init(NULL, output, false); + gfx = drm_init(NULL, output, mode, false); if (!gfx) { framebuffer = true; gfx = fb_init(NULL, mode, GET_VT()); @@ -317,10 +317,10 @@ int main(int argc, char *argv[]) /* device specified */ if (strncmp(device, "/dev/d", 6) == 0) { if (opengl) { - gfx = drm_init_egl(device, output); + gfx = drm_init_egl(device, output, mode); } if (!gfx) { - gfx = drm_init(device, output, pageflip); + gfx = drm_init(device, output, mode, pageflip); } } else { framebuffer = true; @@ -329,10 +329,10 @@ int main(int argc, char *argv[]) } else { /* try drm first, failing that fb */ if (opengl) { - gfx = drm_init_egl(NULL, output); + gfx = drm_init_egl(NULL, output, mode); } if (!gfx) { - gfx = drm_init(NULL, output, pageflip); + gfx = drm_init(NULL, output, mode, pageflip); } if (!gfx) { framebuffer = true; |