From 47e12d832a8c97896bef6b00839a83d59266cd63 Mon Sep 17 00:00:00 2001 From: Chih-Wei Huang Date: Fri, 13 Mar 2020 19:33:56 +0800 Subject: [PATCH] Allow to force mode by a property The desired resolution could be set by property debug.drm.mode.force. --- drm_framebuffer.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drm_framebuffer.c b/drm_framebuffer.c index 4c9871f..2f53bd7 100644 --- a/drm_framebuffer.c +++ b/drm_framebuffer.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -90,10 +91,27 @@ static drmModeModeInfoPtr fb0_find_preferred_mode(drmModeConnectorPtr connector) { int i; drmModeModeInfoPtr mode = NULL; + char value[PROPERTY_VALUE_MAX]; + uint32_t xres = 0, yres = 0, rate = 0; + if (property_get("debug.drm.mode.force", value, NULL)) { + /* parse x[@] */ + if (sscanf(value, "%dx%d@%d", &xres, &yres, &rate) != 3) { + rate = 0; + if (sscanf(value, "%dx%d", &xres, &yres) != 2) { + xres = yres = 0; + } + } + ALOGI_IF(xres && yres, "force mode to %dx%d@%dHz", xres, yres, rate); + } for (i = 0; i < connector->count_modes; ++i) { mode = &connector->modes[i]; - if (mode->type & DRM_MODE_TYPE_PREFERRED) { + if (xres && yres) { + if (mode->hdisplay == xres && mode->vdisplay == yres && + (!rate || mode->vrefresh == rate)) { + break; + } + } else if (mode->type & DRM_MODE_TYPE_PREFERRED) { break; } } -- 2.11.0