66
77#include " lib/fidl/cpp/optional.h"
88#include " lib/ui/scenic/fidl_helpers.h"
9+ #include " vsync_waiter.h"
910
1011namespace flutter {
1112
@@ -14,22 +15,27 @@ SessionConnection::SessionConnection(
1415 std::string debug_label,
1516 zx::eventpair import_token,
1617 OnMetricsUpdate session_metrics_did_change_callback,
17- fxl::Closure session_error_callback)
18+ fxl::Closure session_error_callback,
19+ zx_handle_t vsync_event_handle)
1820 : debug_label_(std::move(debug_label)),
1921 scenic_ (scenic_handle.Bind()),
2022 session_(scenic_.get()),
2123 root_node_(&session_),
2224 surface_producer_(std::make_unique<VulkanSurfaceProducer>(&session_)),
2325 scene_update_context_(&session_, surface_producer_.get()),
24- metrics_changed_callback_(
25- std::move (session_metrics_did_change_callback) ) {
26+ metrics_changed_callback_(std::move(session_metrics_did_change_callback)),
27+ vsync_event_handle_(vsync_event_handle ) {
2628 session_.set_error_handler (std::move (session_error_callback));
2729 session_.set_event_handler (std::bind (&SessionConnection::OnSessionEvents,
2830 this , std::placeholders::_1));
2931
3032 root_node_.Bind (std::move (import_token));
3133 root_node_.SetEventMask (gfx::kMetricsEventMask );
32- session_.Present (0 , [](auto ) {});
34+
35+ // Signal is initially high inidicating availability of the session.
36+ ToggleSignal (vsync_event_handle_, true );
37+
38+ PresentSession ();
3339}
3440
3541SessionConnection::~SessionConnection () = default ;
@@ -66,9 +72,7 @@ void SessionConnection::Present(flow::CompositorContext::ScopedFrame& frame) {
6672 // Flush all session ops. Paint tasks have not yet executed but those are
6773 // fenced. The compositor can start processing ops while we finalize paint
6874 // tasks.
69- session_.Present (0 , // presentation_time. (placeholder).
70- [](auto ) {} // callback
71- );
75+ PresentSession ();
7276
7377 // Execute paint tasks and signal fences.
7478 auto surfaces_to_submit = scene_update_context_.ExecutePaintTasks (frame);
@@ -88,4 +92,24 @@ void SessionConnection::EnqueueClearOps() {
8892 session_.Enqueue (scenic_lib::NewDetachChildrenCommand (root_node_.id ()));
8993}
9094
95+ void SessionConnection::PresentSession () {
96+ ToggleSignal (vsync_event_handle_, false );
97+ session_.Present (0 , // presentation_time. (placeholder).
98+ [handle = vsync_event_handle_](auto ) {
99+ ToggleSignal (handle, true );
100+ } // callback
101+ );
102+ }
103+
104+ void SessionConnection::ToggleSignal (zx_handle_t handle, bool set) {
105+ const auto signal = flutter::VsyncWaiter::SessionPresentSignal;
106+ auto status = zx_object_signal (handle, // handle
107+ set ? 0 : signal, // clear mask
108+ set ? signal : 0 // set mask
109+ );
110+ if (status != ZX_OK) {
111+ FXL_LOG (ERROR) << " Could not toggle vsync signal: " << set;
112+ }
113+ }
114+
91115} // namespace flutter
0 commit comments