Flutter Engine
session_connection.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_SESSION_CONNECTION_H_
6 #define FLUTTER_SHELL_PLATFORM_FUCHSIA_SESSION_CONNECTION_H_
7 
8 #include <fuchsia/scenic/scheduling/cpp/fidl.h>
9 #include <fuchsia/ui/scenic/cpp/fidl.h>
10 #include <lib/fidl/cpp/interface_handle.h>
11 #include <lib/ui/scenic/cpp/session.h>
12 
13 #include "flutter/flow/scene_update_context.h"
14 #include "flutter/fml/closure.h"
15 #include "flutter/fml/macros.h"
16 
17 namespace flutter_runner {
18 
20  std::function<void(fuchsia::scenic::scheduling::FramePresentedInfo)>;
21 
22 // The component residing on the raster thread that is responsible for
23 // maintaining the Scenic session connection and presenting node updates.
25  public:
26  SessionConnection(std::string debug_label,
27  fidl::InterfaceHandle<fuchsia::ui::scenic::Session> session,
28  fml::closure session_error_callback,
29  on_frame_presented_event on_frame_presented_callback,
30  zx_handle_t vsync_event_handle,
31  uint64_t max_frames_in_flight);
32 
34 
35  scenic::Session* get() override { return &session_wrapper_; }
36  void Present() override;
37 
39  fml::TimePoint present_requested_time,
40  fml::TimePoint now,
41  fml::TimePoint last_latch_point_targeted,
42  fml::TimeDelta flutter_frame_build_time,
43  fml::TimeDelta vsync_interval,
44  std::deque<std::pair<fml::TimePoint, fml::TimePoint>>&
45  future_presentation_infos);
46 
47  private:
48  scenic::Session session_wrapper_;
49 
50  on_frame_presented_event on_frame_presented_callback_;
51 
52  zx_handle_t vsync_event_handle_;
53 
54  fml::TimePoint last_latch_point_targeted_ =
56  fml::TimePoint present_requested_time_ =
58 
59  std::deque<std::pair<fml::TimePoint, fml::TimePoint>>
60  future_presentation_infos_ = {};
61 
62  bool initialized_ = false;
63 
64  // A flow event trace id for following |Session::Present| calls into
65  // Scenic. This will be incremented each |Session::Present| call. By
66  // convention, the Scenic side will also contain its own trace id that
67  // begins at 0, and is incremented each |Session::Present| call.
68  uint64_t next_present_trace_id_ = 0;
69  uint64_t next_present_session_trace_id_ = 0;
70  uint64_t processed_present_session_trace_id_ = 0;
71 
72  // The maximum number of frames Flutter sent to Scenic that it can have
73  // outstanding at any time. This is equivalent to how many times it has
74  // called Present2() before receiving an OnFramePresented() event.
75  const int kMaxFramesInFlight;
76  int frames_in_flight_ = 0;
77 
78  int frames_in_flight_allowed_ = 0;
79 
80  bool present_session_pending_ = false;
81 
82  void PresentSession();
83 
84  static void ToggleSignal(zx_handle_t handle, bool raise);
85 
86  FML_DISALLOW_COPY_AND_ASSIGN(SessionConnection);
87 };
88 
89 } // namespace flutter_runner
90 
91 #endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_SESSION_CONNECTION_H_
static constexpr TimeDelta Zero()
Definition: time_delta.h:33
static constexpr TimePoint FromEpochDelta(TimeDelta ticks)
Definition: time_point.h:36
std::function< void()> closure
Definition: closure.h:14
static fml::TimePoint CalculateNextLatchPoint(fml::TimePoint present_requested_time, fml::TimePoint now, fml::TimePoint last_latch_point_targeted, fml::TimeDelta flutter_frame_build_time, fml::TimeDelta vsync_interval, std::deque< std::pair< fml::TimePoint, fml::TimePoint >> &future_presentation_infos)
SessionConnection(std::string debug_label, fidl::InterfaceHandle< fuchsia::ui::scenic::Session > session, fml::closure session_error_callback, on_frame_presented_event on_frame_presented_callback, zx_handle_t vsync_event_handle, uint64_t max_frames_in_flight)
std::function< void(fuchsia::scenic::scheduling::FramePresentedInfo)> on_frame_presented_event