From c96fb181abd3234784e6a77a87d46cef17699874 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sat, 30 Jan 2021 23:27:50 +0300 Subject: [PATCH] cogl/frame-info: Add sequence It will be used for the presentation-time Wayland protocol. Part-of: --- cogl/cogl/cogl-frame-info-private.h | 2 ++ cogl/cogl/cogl-frame-info.c | 8 ++++++++ cogl/cogl/cogl-frame-info.h | 3 +++ cogl/cogl/winsys/cogl-onscreen-glx.c | 12 +++++++++--- src/backends/native/meta-onscreen-native.c | 18 ++++++++++++------ 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/cogl/cogl/cogl-frame-info-private.h b/cogl/cogl/cogl-frame-info-private.h index debeb5dff..cd6bea004 100644 --- a/cogl/cogl/cogl-frame-info-private.h +++ b/cogl/cogl/cogl-frame-info-private.h @@ -53,6 +53,8 @@ struct _CoglFrameInfo int64_t global_frame_counter; CoglFrameInfoFlag flags; + + unsigned int sequence; }; COGL_EXPORT diff --git a/cogl/cogl/cogl-frame-info.c b/cogl/cogl/cogl-frame-info.c index 473a570c9..642bf298e 100644 --- a/cogl/cogl/cogl-frame-info.c +++ b/cogl/cogl/cogl-frame-info.c @@ -94,3 +94,11 @@ cogl_frame_info_is_hw_clock (CoglFrameInfo *info) { return !!(info->flags & COGL_FRAME_INFO_FLAG_HW_CLOCK); } + +unsigned int +cogl_frame_info_get_sequence (CoglFrameInfo *info) +{ + g_warn_if_fail (!(info->flags & COGL_FRAME_INFO_FLAG_SYMBOLIC)); + + return info->sequence; +} diff --git a/cogl/cogl/cogl-frame-info.h b/cogl/cogl/cogl-frame-info.h index c128bf820..6dfc6f296 100644 --- a/cogl/cogl/cogl-frame-info.h +++ b/cogl/cogl/cogl-frame-info.h @@ -141,6 +141,9 @@ gboolean cogl_frame_info_get_is_symbolic (CoglFrameInfo *info); COGL_EXPORT gboolean cogl_frame_info_is_hw_clock (CoglFrameInfo *info); +COGL_EXPORT +unsigned int cogl_frame_info_get_sequence (CoglFrameInfo *info); + G_END_DECLS #endif /* __COGL_FRAME_INFO_H */ diff --git a/cogl/cogl/winsys/cogl-onscreen-glx.c b/cogl/cogl/winsys/cogl-onscreen-glx.c index 65c8312c2..df8922b5d 100644 --- a/cogl/cogl/winsys/cogl-onscreen-glx.c +++ b/cogl/cogl/winsys/cogl-onscreen-glx.c @@ -497,6 +497,9 @@ _cogl_winsys_wait_for_vblank (CoglOnscreen *onscreen) { info->presentation_time_us = g_get_monotonic_time (); } + + /* Intentionally truncating to lower 32 bits, same as DRM. */ + info->sequence = msc; } else { @@ -976,20 +979,20 @@ cogl_onscreen_glx_notify_swap_buffers (CoglOnscreen *onscreen, CoglFramebuffer *framebuffer = COGL_FRAMEBUFFER (onscreen); CoglContext *context = cogl_framebuffer_get_context (framebuffer); gboolean ust_is_monotonic; + CoglFrameInfo *info; /* We only want to notify that the swap is complete when the application calls cogl_context_dispatch so instead of immediately notifying we'll set a flag to remember to notify later */ set_sync_pending (onscreen); + info = cogl_onscreen_peek_head_frame_info (onscreen); + ust_is_monotonic = is_ust_monotonic (context->display->renderer, onscreen_glx->glxwin); if (swap_event->ust != 0 && ust_is_monotonic) { - CoglFrameInfo *info; - - info = cogl_onscreen_peek_head_frame_info (onscreen); info->presentation_time_us = ust_to_microseconds (context->display->renderer, onscreen_glx->glxwin, @@ -997,6 +1000,9 @@ cogl_onscreen_glx_notify_swap_buffers (CoglOnscreen *onscreen, info->flags |= COGL_FRAME_INFO_FLAG_HW_CLOCK; } + /* Intentionally truncating to lower 32 bits, same as DRM. */ + info->sequence = swap_event->msc; + set_complete_pending (onscreen); } diff --git a/src/backends/native/meta-onscreen-native.c b/src/backends/native/meta-onscreen-native.c index 3c81c9601..a69f31c73 100644 --- a/src/backends/native/meta-onscreen-native.c +++ b/src/backends/native/meta-onscreen-native.c @@ -170,7 +170,8 @@ static void maybe_update_frame_info (MetaCrtc *crtc, CoglFrameInfo *frame_info, int64_t time_us, - CoglFrameInfoFlag flags) + CoglFrameInfoFlag flags, + unsigned int sequence) { const MetaCrtcConfig *crtc_config; const MetaCrtcModeInfo *crtc_mode_info; @@ -189,6 +190,7 @@ maybe_update_frame_info (MetaCrtc *crtc, frame_info->presentation_time_us = time_us; frame_info->refresh_rate = refresh_rate; frame_info->flags |= flags; + frame_info->sequence = sequence; } } @@ -210,7 +212,8 @@ static void notify_view_crtc_presented (MetaRendererView *view, MetaKmsCrtc *kms_crtc, int64_t time_us, - CoglFrameInfoFlag flags) + CoglFrameInfoFlag flags, + unsigned int sequence) { ClutterStageView *stage_view = CLUTTER_STAGE_VIEW (view); CoglFramebuffer *framebuffer = @@ -225,7 +228,7 @@ notify_view_crtc_presented (MetaRendererView *view, frame_info = cogl_onscreen_peek_head_frame_info (onscreen); crtc = META_CRTC (meta_crtc_kms_from_kms_crtc (kms_crtc)); - maybe_update_frame_info (crtc, frame_info, time_us, flags); + maybe_update_frame_info (crtc, frame_info, time_us, flags, sequence); meta_onscreen_native_notify_frame_complete (onscreen); @@ -287,7 +290,8 @@ page_flip_feedback_flipped (MetaKmsCrtc *kms_crtc, notify_view_crtc_presented (view, kms_crtc, presentation_time_us, - flags); + flags, + sequence); } static void @@ -323,7 +327,8 @@ page_flip_feedback_mode_set_fallback (MetaKmsCrtc *kms_crtc, notify_view_crtc_presented (view, kms_crtc, now_us, - COGL_FRAME_INFO_FLAG_NONE); + COGL_FRAME_INFO_FLAG_NONE, + 0); } static void @@ -350,7 +355,8 @@ page_flip_feedback_discarded (MetaKmsCrtc *kms_crtc, notify_view_crtc_presented (view, kms_crtc, now_us, - COGL_FRAME_INFO_FLAG_NONE); + COGL_FRAME_INFO_FLAG_NONE, + 0); } static const MetaKmsPageFlipListenerVtable page_flip_listener_vtable = {