From e567cb972d2eb3c69a015b78886e94e5949707ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Mon, 29 Mar 2021 11:56:49 +0200 Subject: [PATCH] renderer/native: Get 'uses-monotonic' state from MetaKmsDevice It's better suited to be handled by the MetaKmsDevice abstraction. This eliminates the last caller of drmGetCaps() from outside MetaKmsImplDevice. Part-of: --- src/backends/native/meta-gpu-kms.c | 20 -------------------- src/backends/native/meta-gpu-kms.h | 2 -- src/backends/native/meta-kms-device.c | 6 ++++++ src/backends/native/meta-kms-device.h | 2 ++ src/backends/native/meta-kms-impl-device.c | 6 ++++++ src/backends/native/meta-kms-impl-device.h | 1 + src/backends/native/meta-onscreen-native.c | 9 ++++----- 7 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/backends/native/meta-gpu-kms.c b/src/backends/native/meta-gpu-kms.c index e81c90a02..6c0342113 100644 --- a/src/backends/native/meta-gpu-kms.c +++ b/src/backends/native/meta-gpu-kms.c @@ -57,8 +57,6 @@ struct _MetaGpuKms uint32_t id; int fd; - clockid_t clock_id; - gboolean resources_init_failed_before; }; @@ -124,12 +122,6 @@ meta_gpu_kms_get_file_path (MetaGpuKms *gpu_kms) return meta_kms_device_get_path (gpu_kms->kms_device); } -gboolean -meta_gpu_kms_is_clock_monotonic (MetaGpuKms *gpu_kms) -{ - return gpu_kms->clock_id == CLOCK_MONOTONIC; -} - gboolean meta_gpu_kms_is_boot_vga (MetaGpuKms *gpu_kms) { @@ -316,17 +308,6 @@ init_crtcs (MetaGpuKms *gpu_kms) meta_gpu_take_crtcs (gpu, crtcs); } -static void -init_frame_clock (MetaGpuKms *gpu_kms) -{ - uint64_t uses_monotonic; - - if (drmGetCap (gpu_kms->fd, DRM_CAP_TIMESTAMP_MONOTONIC, &uses_monotonic) != 0) - uses_monotonic = 0; - - gpu_kms->clock_id = uses_monotonic ? CLOCK_MONOTONIC : CLOCK_REALTIME; -} - static void init_outputs (MetaGpuKms *gpu_kms) { @@ -391,7 +372,6 @@ meta_gpu_kms_read_current (MetaGpu *gpu, init_modes (gpu_kms); init_crtcs (gpu_kms); init_outputs (gpu_kms); - init_frame_clock (gpu_kms); return TRUE; } diff --git a/src/backends/native/meta-gpu-kms.h b/src/backends/native/meta-gpu-kms.h index f13a141f4..051ea374a 100644 --- a/src/backends/native/meta-gpu-kms.h +++ b/src/backends/native/meta-gpu-kms.h @@ -57,8 +57,6 @@ uint32_t meta_gpu_kms_get_id (MetaGpuKms *gpu_kms); const char * meta_gpu_kms_get_file_path (MetaGpuKms *gpu_kms); -gboolean meta_gpu_kms_is_clock_monotonic (MetaGpuKms *gpu_kms); - void meta_gpu_kms_set_power_save_mode (MetaGpuKms *gpu_kms, uint64_t state, MetaKmsUpdate *kms_update); diff --git a/src/backends/native/meta-kms-device.c b/src/backends/native/meta-kms-device.c index 49516bde6..d958e0be6 100644 --- a/src/backends/native/meta-kms-device.c +++ b/src/backends/native/meta-kms-device.c @@ -127,6 +127,12 @@ meta_kms_device_prefers_shadow_buffer (MetaKmsDevice *device) return device->caps.prefers_shadow_buffer; } +gboolean +meta_kms_device_uses_monotonic_clock (MetaKmsDevice *device) +{ + return device->caps.uses_monotonic_clock; +} + GList * meta_kms_device_get_connectors (MetaKmsDevice *device) { diff --git a/src/backends/native/meta-kms-device.h b/src/backends/native/meta-kms-device.h index c8bf94843..c5e734a4c 100644 --- a/src/backends/native/meta-kms-device.h +++ b/src/backends/native/meta-kms-device.h @@ -47,6 +47,8 @@ gboolean meta_kms_device_get_cursor_size (MetaKmsDevice *device, gboolean meta_kms_device_prefers_shadow_buffer (MetaKmsDevice *device); +gboolean meta_kms_device_uses_monotonic_clock (MetaKmsDevice *device); + GList * meta_kms_device_get_connectors (MetaKmsDevice *device); GList * meta_kms_device_get_crtcs (MetaKmsDevice *device); diff --git a/src/backends/native/meta-kms-impl-device.c b/src/backends/native/meta-kms-impl-device.c index 4194b9ffa..dbc6c57de 100644 --- a/src/backends/native/meta-kms-impl-device.c +++ b/src/backends/native/meta-kms-impl-device.c @@ -301,6 +301,7 @@ init_caps (MetaKmsImplDevice *impl_device) int fd; uint64_t cursor_width, cursor_height; uint64_t prefer_shadow; + uint64_t uses_monotonic_clock; fd = meta_device_file_get_fd (priv->device_file); if (drmGetCap (fd, DRM_CAP_CURSOR_WIDTH, &cursor_width) == 0 && @@ -318,6 +319,11 @@ init_caps (MetaKmsImplDevice *impl_device) priv->caps.prefers_shadow_buffer = prefer_shadow; } + + if (drmGetCap (fd, DRM_CAP_TIMESTAMP_MONOTONIC, &uses_monotonic_clock) == 0) + { + priv->caps.uses_monotonic_clock = uses_monotonic_clock; + } } static void diff --git a/src/backends/native/meta-kms-impl-device.h b/src/backends/native/meta-kms-impl-device.h index 9e2070527..4256cc20b 100644 --- a/src/backends/native/meta-kms-impl-device.h +++ b/src/backends/native/meta-kms-impl-device.h @@ -39,6 +39,7 @@ typedef struct _MetaKmsDeviceCaps uint64_t cursor_height; gboolean prefers_shadow_buffer; + gboolean uses_monotonic_clock; } MetaKmsDeviceCaps; typedef struct _MetaKmsProp MetaKmsProp; diff --git a/src/backends/native/meta-onscreen-native.c b/src/backends/native/meta-onscreen-native.c index 02cd5da2e..016533df7 100644 --- a/src/backends/native/meta-onscreen-native.c +++ b/src/backends/native/meta-onscreen-native.c @@ -38,6 +38,7 @@ #include "backends/native/meta-drm-buffer-gbm.h" #include "backends/native/meta-drm-buffer-import.h" #include "backends/native/meta-drm-buffer.h" +#include "backends/native/meta-kms-device.h" #include "backends/native/meta-kms-utils.h" #include "backends/native/meta-kms.h" #include "backends/native/meta-output-kms.h" @@ -246,8 +247,7 @@ page_flip_feedback_flipped (MetaKmsCrtc *kms_crtc, { MetaRendererView *view = user_data; struct timeval page_flip_time; - MetaCrtc *crtc; - MetaGpuKms *gpu_kms; + MetaKmsDevice *kms_device; int64_t presentation_time_us; CoglFrameInfoFlag flags = COGL_FRAME_INFO_FLAG_VSYNC; @@ -256,9 +256,8 @@ page_flip_feedback_flipped (MetaKmsCrtc *kms_crtc, .tv_usec = tv_usec, }; - crtc = META_CRTC (meta_crtc_kms_from_kms_crtc (kms_crtc)); - gpu_kms = META_GPU_KMS (meta_crtc_get_gpu (crtc)); - if (meta_gpu_kms_is_clock_monotonic (gpu_kms)) + kms_device = meta_kms_crtc_get_device (kms_crtc); + if (meta_kms_device_uses_monotonic_clock (kms_device)) { presentation_time_us = timeval_to_microseconds (&page_flip_time); flags |= COGL_FRAME_INFO_FLAG_HW_CLOCK;