[PATCH] compositor-drm: Add the aspect ratio parsing support
Nautiyal Ankit
ankit.k.nautiyal at intel.com
Wed Sep 6 12:20:02 UTC 2017
From: Ankit Nautiyal <ankit.k.nautiyal at intel.com>
DRM layer populates aspect ratio information for CEA video modes,
but we lose it while parsing modeline (Aspect ratio patch series
in drm layer: https://patchwork.freedesktop.org/series/10850).
The flag bits 19-22 of the connector modes, provide the aspect ratio info.
This information can be stored in flags bits of the weston mode structure,
so that it can used for setting a mode with a particular aspect ratio.
This patch:
- preserves aspect ratio flags from kernel video modes and accommodates it
in wayland mode flags (bits 02-05).
- Uses these aspect ratio flags to pick the appropriateĀ mode during
modeset.
- changes the mode format in configuration file weston.ini to accommodate
aspect ratio information as:
<width>x<height>@<RefreshRate> <aspect-ratio>.
The aspect ratio should be given as <length:breadth>.
Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal at intel.com>
---
libweston/compositor-drm.c | 103 +++++++++++++++++++++++++++++++++++++++------
man/weston.ini.man | 10 +++--
2 files changed, 96 insertions(+), 17 deletions(-)
diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index 1a96138..f18e2a8 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -83,6 +83,13 @@
#define GBM_BO_USE_CURSOR GBM_BO_USE_CURSOR_64X64
#endif
+#ifndef DRM_MODE_FLAG_PIC_AR_MASK
+#define DRM_MODE_PIC_AR_BITS_POS 19
+#define WL_MODE_PIC_AR_BITS_POS 2
+#define DRM_MODE_FLAG_PIC_AR_MASK (0xF << DRM_MODE_PIC_AR_BITS_POS)
+#endif
+
+
/**
* List of properties attached to DRM planes
*/
@@ -1962,24 +1969,41 @@ drm_assign_planes(struct weston_output *output_base, void *repaint_data)
static struct drm_mode *
choose_mode (struct drm_output *output, struct weston_mode *target_mode)
{
- struct drm_mode *tmp_mode = NULL, *mode;
+ struct drm_mode *tmp_mode = NULL, *mode_fall_back = NULL, *mode;
+ uint8_t src_aspect = 0;
+ uint8_t target_aspect = 0;
+ target_aspect =
+ target_mode->flags & WL_OUTPUT_MODE_ASPECT_RATIO_MASK;
if (output->base.current_mode->width == target_mode->width &&
output->base.current_mode->height == target_mode->height &&
(output->base.current_mode->refresh == target_mode->refresh ||
- target_mode->refresh == 0))
- return (struct drm_mode *)output->base.current_mode;
+ target_mode->refresh == 0)) {
+ src_aspect = mode->mode_info.flags &
+ WL_OUTPUT_MODE_ASPECT_RATIO_MASK;
+ if (target_aspect && src_aspect && src_aspect == target_aspect)
+ return (struct drm_mode *)output->base.current_mode;
+ }
wl_list_for_each(mode, &output->base.mode_list, base.link) {
if (mode->mode_info.hdisplay == target_mode->width &&
mode->mode_info.vdisplay == target_mode->height) {
if (mode->base.refresh == target_mode->refresh ||
- target_mode->refresh == 0) {
- return mode;
- } else if (!tmp_mode)
+ target_mode->refresh == 0) {
+ src_aspect = mode->mode_info.flags &
+ WL_OUTPUT_MODE_ASPECT_RATIO_MASK;
+ if (target_aspect && src_aspect &&
+ src_aspect == target_aspect)
+ return mode;
+ else if (!mode_fall_back)
+ mode_fall_back = mode;
+ } else if (!tmp_mode) {
tmp_mode = mode;
+ }
}
}
+ if (mode_fall_back)
+ return mode_fall_back;
return tmp_mode;
}
@@ -2025,7 +2049,7 @@ drm_output_switch_mode(struct weston_output *output_base, struct weston_mode *mo
output->base.current_mode->flags = 0;
output->base.current_mode = &drm_mode->base;
- output->base.current_mode->flags =
+ output->base.current_mode->flags |=
WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
/* XXX: This drops our current buffer too early, before we've started
@@ -2360,6 +2384,28 @@ destroy_sprites(struct drm_backend *b)
drm_plane_destroy(plane);
}
+
+/**
+ * Copy the aspect ratio bits from flag of drmModeModeInfo mode to the
+ * weston_mode structure.
+ *
+ * @param w_mode the weston mode to which aspect ratio bits are to be added.
+ * @param info the drmModeModeInfo mode from which has the aspect ratio info.
+ */
+static void
+drm_set_aspect_ratio(struct weston_mode *w_mode, const drmModeModeInfo *info)
+{
+ uint8_t aspect_ratio;
+
+ if (w_mode == NULL || info == NULL) {
+ weston_log("NULL value received. Unable to set aspect-ratio\n");
+ return;
+ }
+ aspect_ratio = (info->flags & DRM_MODE_FLAG_PIC_AR_MASK) >>
+ DRM_MODE_PIC_AR_BITS_POS;
+ w_mode->flags |= (aspect_ratio << WL_MODE_PIC_AR_BITS_POS);
+}
+
/**
* Add a mode to output's mode list
*
@@ -2400,7 +2446,7 @@ drm_output_add_mode(struct drm_output *output, const drmModeModeInfo *info)
if (info->type & DRM_MODE_TYPE_PREFERRED)
mode->base.flags |= WL_OUTPUT_MODE_PREFERRED;
-
+ drm_set_aspect_ratio(&mode->base, info);
wl_list_insert(output->base.mode_list.prev, &mode->base.link);
return mode;
@@ -2982,17 +3028,34 @@ drm_output_choose_initial_mode(struct drm_backend *backend,
struct drm_mode *preferred = NULL;
struct drm_mode *current = NULL;
struct drm_mode *configured = NULL;
+ struct drm_mode *config_fall_back = NULL;
struct drm_mode *best = NULL;
struct drm_mode *drm_mode;
drmModeModeInfo drm_modeline;
int32_t width = 0;
int32_t height = 0;
uint32_t refresh = 0;
+ uint32_t aspect_width = 0;
+ uint32_t aspect_height = 0;
+ uint8_t aspect_ratio = 0;
int n;
if (mode == WESTON_DRM_BACKEND_OUTPUT_PREFERRED && modeline) {
- n = sscanf(modeline, "%dx%d@%d", &width, &height, &refresh);
- if (n != 2 && n != 3) {
+ n = sscanf(modeline, "%dx%d@%d %u:%u", &width, &height, &refresh,
+ &aspect_width, &aspect_height);
+
+ if (aspect_width == 4 && aspect_height == 3)
+ aspect_ratio = WL_OUTPUT_MODE_PICTURE_ASPECT_4_3;
+ else if (aspect_width == 16 && aspect_height == 9)
+ aspect_ratio = WL_OUTPUT_MODE_PICTURE_ASPECT_16_9;
+ else if (aspect_width == 64 && aspect_height == 27)
+ aspect_ratio = WL_OUTPUT_MODE_PICTURE_ASPECT_64_27;
+ else if (aspect_width == 256 && aspect_height == 135)
+ aspect_ratio = WL_OUTPUT_MODE_PICTURE_ASPECT_256_135;
+ else
+ aspect_ratio = WL_OUTPUT_MODE_PICTURE_ASPECT_NONE;
+
+ if (n != 2 && n != 3 && n != 5) {
width = -1;
if (parse_modeline(modeline, &drm_modeline) == 0) {
@@ -3009,9 +3072,20 @@ drm_output_choose_initial_mode(struct drm_backend *backend,
wl_list_for_each_reverse(drm_mode, &output->base.mode_list, base.link) {
if (width == drm_mode->base.width &&
height == drm_mode->base.height &&
- (refresh == 0 || refresh == drm_mode->mode_info.vrefresh))
- configured = drm_mode;
-
+ (refresh == 0 || refresh == drm_mode->mode_info.vrefresh)) {
+ uint8_t src_ar;
+
+ src_ar = (drm_mode->base.flags &
+ WL_OUTPUT_MODE_ASPECT_RATIO_MASK) >>
+ WL_MODE_PIC_AR_BITS_POS;
+
+ if (aspect_ratio != WL_OUTPUT_MODE_PICTURE_ASPECT_NONE
+ && src_ar != WL_OUTPUT_MODE_PICTURE_ASPECT_NONE
+ && aspect_ratio == src_ar)
+ configured = drm_mode;
+ else
+ config_fall_back = drm_mode;
+ }
if (memcmp(current_mode, &drm_mode->mode_info,
sizeof *current_mode) == 0)
current = drm_mode;
@@ -3034,6 +3108,9 @@ drm_output_choose_initial_mode(struct drm_backend *backend,
if (configured)
return configured;
+ if (config_fall_back)
+ return config_fall_back;
+
if (preferred)
return preferred;
diff --git a/man/weston.ini.man b/man/weston.ini.man
index 4cfefc9..16965aa 100644
--- a/man/weston.ini.man
+++ b/man/weston.ini.man
@@ -363,10 +363,12 @@ The DRM backend accepts different modes:
.PP
.RS 10
.nf
-.BR "WIDTHxHEIGHT " "Resolution size width and height in pixels"
-.BR "preferred " "Uses the preferred mode"
-.BR "current " "Uses the current crt controller mode"
-.BR "off " "Disables the output"
+.BR "WIDTHxHEIGHT " "Resolution size width and height in pixels"
+.BR "WIDTHxHEIGHT at RR " "Resolution as above and refresh-rate in Hertz"
+.BR "WIDTHxHEIGHT at RR L:B " "Resolution as above and aspect-ratio as length:breadth"
+.BR "preferred " "Uses the preferred mode"
+.BR "current " "Uses the current crt controller mode"
+.BR "off " "Disables the output"
.fi
.RE
.RS
--
2.7.4
More information about the wayland-devel
mailing list