From 852d3b12a9548e7e517d782a51e13f7507a72642 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 20 Jul 2021 17:31:57 +0200 Subject: [PATCH] drm: embed drm_t.mode This will allow us to store a custom mode there, instead of a mode that comes from the EDID. --- src/drm.cpp | 25 ++++++++++++++----------- src/drm.hpp | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/drm.cpp b/src/drm.cpp index 14cb6de..950bee5 100644 --- a/src/drm.cpp +++ b/src/drm.cpp @@ -430,23 +430,26 @@ int init_drm(struct drm_t *drm, const char *device) * highest refresh rate */ std::stable_sort(connector->modes, connector->modes + connector->count_modes, compare_modes); + const drmModeModeInfo *mode = nullptr; if ( g_nOutputWidth != 0 || g_nOutputHeight != 0 || g_nNestedRefresh != 0 ) { - drm->mode = get_matching_mode(connector, g_nOutputWidth, g_nOutputHeight, g_nNestedRefresh); + mode = get_matching_mode(connector, g_nOutputWidth, g_nOutputHeight, g_nNestedRefresh); } - if (!drm->mode) { - drm->mode = get_matching_mode(connector, 0, 0, 0); + if (!mode) { + mode = get_matching_mode(connector, 0, 0, 0); } - if (!drm->mode) { + if (!mode) { fprintf(stderr, "could not find mode!\n"); return -1; } - fprintf( stderr, "drm: selected mode %dx%d@%uHz\n", drm->mode->hdisplay, drm->mode->vdisplay, drm->mode->vrefresh ); + fprintf( stderr, "drm: selected mode %dx%d@%uHz\n", mode->hdisplay, mode->vdisplay, mode->vrefresh ); - if (drmModeCreatePropertyBlob(drm->fd, drm->mode, sizeof(*drm->mode), &drm->mode_id) != 0) + drm->mode = *mode; + + if (drmModeCreatePropertyBlob(drm->fd, &drm->mode, sizeof(drm->mode), &drm->mode_id) != 0) return -1; /* find encoder: */ @@ -546,9 +549,9 @@ int init_drm(struct drm_t *drm, const char *device) std::thread flip_handler_thread( flip_handler_thread_run ); flip_handler_thread.detach(); - g_nOutputWidth = drm->mode->hdisplay; - g_nOutputHeight = drm->mode->vdisplay; - g_nOutputRefresh = drm->mode->vrefresh; + g_nOutputWidth = drm->mode.hdisplay; + g_nOutputHeight = drm->mode.vdisplay; + g_nOutputRefresh = drm->mode.vrefresh; if ( g_nOutputWidth < g_nOutputHeight ) { @@ -558,8 +561,8 @@ int init_drm(struct drm_t *drm, const char *device) if ( g_bRotated ) { - g_nOutputWidth = drm->mode->vdisplay; - g_nOutputHeight = drm->mode->hdisplay; + g_nOutputWidth = drm->mode.vdisplay; + g_nOutputHeight = drm->mode.hdisplay; } if (g_bUseLayers) { diff --git a/src/drm.hpp b/src/drm.hpp index 2c2b31f..1f59567 100644 --- a/src/drm.hpp +++ b/src/drm.hpp @@ -63,7 +63,7 @@ struct drm_t { int kms_in_fence_fd; int kms_out_fence_fd; - const drmModeModeInfo *mode; + drmModeModeInfo mode; uint32_t mode_id; uint32_t crtc_id; uint32_t connector_id;