From 88e64000528b300743e81c67399cb0af021cea29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Sat, 10 Oct 2020 11:10:47 +0200 Subject: [PATCH] monitor-manager/kms: Turn on DPMS together with mode set We cannot switch DPMS state to 'on' first, then mode set later, when using atomic KMS. So when we're turning it on, just let the eventual mode set handle DPMS too. When switching DPMS to 'off', do it directly, synchronously, both by setting the DPMS state and switching off CRTCs. Part-of: --- src/backends/native/meta-crtc-kms.c | 20 ++++++++ src/backends/native/meta-gpu-kms.c | 17 +++---- .../native/meta-monitor-manager-kms.c | 50 +++++++++++++------ .../native/meta-monitor-manager-kms.h | 2 + 4 files changed, 64 insertions(+), 25 deletions(-) diff --git a/src/backends/native/meta-crtc-kms.c b/src/backends/native/meta-crtc-kms.c index 59570e60b..3a72c46d1 100644 --- a/src/backends/native/meta-crtc-kms.c +++ b/src/backends/native/meta-crtc-kms.c @@ -33,6 +33,7 @@ #include "backends/native/meta-kms-mode.h" #include "backends/native/meta-kms-plane.h" #include "backends/native/meta-kms-update.h" +#include "backends/native/meta-monitor-manager-kms.h" #define ALL_TRANSFORMS_MASK ((1 << META_MONITOR_N_TRANSFORMS) - 1) @@ -190,11 +191,30 @@ meta_crtc_kms_set_mode (MetaCrtcKms *crtc_kms, { const MetaCrtcConfig *crtc_config = meta_crtc_get_config (crtc); MetaCrtcModeKms *crtc_mode_kms = META_CRTC_MODE_KMS (crtc_config->mode); + MetaBackend *backend = meta_gpu_get_backend (gpu); + MetaMonitorManager *monitor_manager = + meta_backend_get_monitor_manager (backend); + MetaPowerSave power_save; + uint64_t dpms_state; + GList *l; kms_mode = meta_crtc_mode_kms_get_kms_mode (crtc_mode_kms); g_debug ("Setting CRTC (%" G_GUINT64_FORMAT ") mode to %s", meta_crtc_get_id (crtc), meta_kms_mode_get_name (kms_mode)); + + power_save = meta_monitor_manager_get_power_save_mode (monitor_manager); + g_warn_if_fail (power_save == META_POWER_SAVE_ON); + + dpms_state = meta_power_save_to_dpms_state (power_save); + for (l = connectors; l; l = l->next) + { + MetaKmsConnector *kms_connector = l->data; + + meta_kms_update_set_dpms_state (kms_update, + kms_connector, + dpms_state); + } } else { diff --git a/src/backends/native/meta-gpu-kms.c b/src/backends/native/meta-gpu-kms.c index dbf76abed..3df26ff3e 100644 --- a/src/backends/native/meta-gpu-kms.c +++ b/src/backends/native/meta-gpu-kms.c @@ -151,6 +151,8 @@ meta_gpu_kms_set_power_save_mode (MetaGpuKms *gpu_kms, MetaGpu *gpu = META_GPU (gpu_kms); GList *l; + g_return_if_fail (state != DRM_MODE_DPMS_ON); + for (l = meta_gpu_get_outputs (gpu); l; l = l->next) { MetaOutput *output = l->data; @@ -159,17 +161,14 @@ meta_gpu_kms_set_power_save_mode (MetaGpuKms *gpu_kms, state, kms_update); } - if (state != META_POWER_SAVE_ON) + /* Turn off CRTCs for DPMS */ + for (l = meta_gpu_get_crtcs (gpu); l; l = l->next) { - /* Turn off CRTCs for DPMS */ - for (l = meta_gpu_get_crtcs (gpu); l; l = l->next) - { - MetaCrtcKms *crtc_kms = META_CRTC_KMS (l->data); + MetaCrtcKms *crtc_kms = META_CRTC_KMS (l->data); - meta_kms_update_mode_set (kms_update, - meta_crtc_kms_get_kms_crtc (crtc_kms), - NULL, NULL); - } + meta_kms_update_mode_set (kms_update, + meta_crtc_kms_get_kms_crtc (crtc_kms), + NULL, NULL); } } diff --git a/src/backends/native/meta-monitor-manager-kms.c b/src/backends/native/meta-monitor-manager-kms.c index f3881862f..19b3faaf0 100644 --- a/src/backends/native/meta-monitor-manager-kms.c +++ b/src/backends/native/meta-monitor-manager-kms.c @@ -113,6 +113,27 @@ meta_monitor_manager_kms_read_current_state (MetaMonitorManager *manager) parent_class->read_current_state (manager); } +uint64_t +meta_power_save_to_dpms_state (MetaPowerSave power_save) +{ + switch (power_save) + { + case META_POWER_SAVE_ON: + return DRM_MODE_DPMS_ON; + case META_POWER_SAVE_STANDBY: + return DRM_MODE_DPMS_STANDBY; + case META_POWER_SAVE_SUSPEND: + return DRM_MODE_DPMS_SUSPEND; + case META_POWER_SAVE_OFF: + return DRM_MODE_DPMS_OFF; + case META_POWER_SAVE_UNSUPPORTED: + return DRM_MODE_DPMS_ON; + } + + g_warn_if_reached (); + return DRM_MODE_DPMS_ON; +} + static void meta_monitor_manager_kms_set_power_save_mode (MetaMonitorManager *manager, MetaPowerSave mode) @@ -123,22 +144,19 @@ meta_monitor_manager_kms_set_power_save_mode (MetaMonitorManager *manager, uint64_t state; GList *l; - switch (mode) { - case META_POWER_SAVE_ON: - state = DRM_MODE_DPMS_ON; - break; - case META_POWER_SAVE_STANDBY: - state = DRM_MODE_DPMS_STANDBY; - break; - case META_POWER_SAVE_SUSPEND: - state = DRM_MODE_DPMS_SUSPEND; - break; - case META_POWER_SAVE_OFF: - state = DRM_MODE_DPMS_OFF; - break; - default: - return; - } + switch (mode) + { + case META_POWER_SAVE_ON: + case META_POWER_SAVE_UNSUPPORTED: + /* This will be handled on mode set. */ + return; + case META_POWER_SAVE_STANDBY: + case META_POWER_SAVE_SUSPEND: + case META_POWER_SAVE_OFF: + break; + } + + state = meta_power_save_to_dpms_state (mode); for (l = meta_backend_get_gpus (backend); l; l = l->next) { diff --git a/src/backends/native/meta-monitor-manager-kms.h b/src/backends/native/meta-monitor-manager-kms.h index b7287bc9a..84499397c 100644 --- a/src/backends/native/meta-monitor-manager-kms.h +++ b/src/backends/native/meta-monitor-manager-kms.h @@ -39,4 +39,6 @@ void meta_monitor_manager_kms_pause (MetaMonitorManagerKms *manager_kms); void meta_monitor_manager_kms_resume (MetaMonitorManagerKms *manager_kms); +uint64_t meta_power_save_to_dpms_state (MetaPowerSave power_save); + #endif /* META_MONITOR_MANAGER_KMS_H */