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: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1488>
This commit is contained in:
Jonas Ådahl 2020-10-10 11:10:47 +02:00 committed by Marge Bot
parent d8279ba474
commit 88e6400052
4 changed files with 64 additions and 25 deletions

View File

@ -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
{

View File

@ -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);
}
}

View File

@ -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)
{

View File

@ -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 */