compositor-drm: get current mode on head discovery
authorPekka Paalanen <pekka.paalanen@collabora.co.uk>
Mon, 11 Sep 2017 11:06:11 +0000 (14:06 +0300)
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>
Wed, 18 Apr 2018 08:53:54 +0000 (11:53 +0300)
The inherited mode is the video mode on the connector when we have not
yet reconfigured the connector, if set.

Get the inherited mode the moment we create a drm_head, not when we
determine the mode for a drm_output. This way we are sure to read all
inherited modes before we reconfigure a single CRTC. Enabling one output
may grab the CRTC from another connector, overwriting whatever mode that
connector might have had.

The inherited mode is stored in drm_head, where we can keep it for the
lifetime of the head, rather than relying on re-loading it from the
kernel at set_mode() time.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Acked-by: Derek Foreman <derekf@osg.samsung.com>
libweston/compositor-drm.c

index 65f4378..f54257c 100644 (file)
@@ -416,6 +416,8 @@ struct drm_head {
        struct drm_property_info props_conn[WDRM_CONNECTOR__COUNT];
 
        struct backlight *backlight;
+
+       drmModeModeInfo inherited_mode; /**< Original mode on the connector */
 };
 
 struct drm_output {
@@ -4560,12 +4562,9 @@ drm_output_set_mode(struct weston_output *base,
        struct drm_head *head = to_drm_head(weston_output_get_first_head(base));
 
        struct drm_mode *current;
-       drmModeModeInfo crtc_mode;
-
-       if (connector_get_current_mode(head->connector, b->drm.fd, &crtc_mode) < 0)
-               return -1;
 
-       current = drm_output_choose_initial_mode(b, output, mode, modeline, &crtc_mode);
+       current = drm_output_choose_initial_mode(b, output, mode, modeline,
+                                                &head->inherited_mode);
        if (!current)
                return -1;
 
@@ -5079,6 +5078,13 @@ drm_head_create(struct drm_backend *backend, uint32_t connector_id,
            head->connector->connector_type == DRM_MODE_CONNECTOR_eDP)
                weston_head_set_internal(&head->base);
 
+       if (connector_get_current_mode(head->connector, backend->drm.fd,
+                                      &head->inherited_mode) < 0) {
+               weston_log("Failed to retrieve current mode from connector %d.\n",
+                          head->connector_id);
+               /* Continue, inherited_mode was memset to zero. */
+       }
+
        weston_compositor_add_head(backend->compositor, &head->base);
 
        weston_log("DRM: found head '%s', connector %d %s.\n",