Flutter Engine
flutter_runner::SessionConnection Class Referencefinal

#include <session_connection.h>

Inheritance diagram for flutter_runner::SessionConnection:
flutter::SessionWrapper

Public Member Functions

 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)
 
 ~SessionConnection ()
 
scenic::Session * get () override
 
void Present () override
 
- Public Member Functions inherited from flutter::SessionWrapper
virtual ~SessionWrapper ()
 

Static Public Member Functions

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)
 

Detailed Description

Definition at line 24 of file session_connection.h.

Constructor & Destructor Documentation

◆ SessionConnection()

flutter_runner::SessionConnection::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 
)

Definition at line 15 of file session_connection.cc.

References FML_CHECK, FML_DCHECK, flutter_runner::VsyncRecorder::GetInstance(), TRACE_EVENT2, flutter_runner::VsyncRecorder::UpdateFramePresentedInfo(), flutter_runner::VsyncRecorder::UpdateNextPresentationInfo(), and ~SessionConnection().

22  : session_wrapper_(session.Bind(), nullptr),
23  on_frame_presented_callback_(std::move(on_frame_presented_callback)),
24  vsync_event_handle_(vsync_event_handle),
25  kMaxFramesInFlight(max_frames_in_flight) {
26  session_wrapper_.set_error_handler(
27  [callback = session_error_callback](zx_status_t status) { callback(); });
28 
29  // Set the |fuchsia::ui::scenic::OnFramePresented()| event handler that will
30  // fire every time a set of one or more frames is presented.
31  session_wrapper_.set_on_frame_presented_handler(
32  [this, handle = vsync_event_handle_](
33  fuchsia::scenic::scheduling::FramePresentedInfo info) {
34  // Update Scenic's limit for our remaining frames in flight allowed.
35  size_t num_presents_handled = info.presentation_infos.size();
36  frames_in_flight_allowed_ = info.num_presents_allowed;
37 
38  // A frame was presented: Update our |frames_in_flight| to match the
39  // updated unfinalized present requests.
40  frames_in_flight_ -= num_presents_handled;
41  TRACE_EVENT2("gfx", "OnFramePresented", "frames_in_flight",
42  frames_in_flight_, "max_frames_in_flight",
43  kMaxFramesInFlight);
44  FML_DCHECK(frames_in_flight_ >= 0);
45 
47  zx::time(info.actual_presentation_time));
48 
49  // Call the client-provided callback once we are done using |info|.
50  on_frame_presented_callback_(std::move(info));
51 
52  if (present_session_pending_) {
53  PresentSession();
54  }
55  ToggleSignal(handle, true);
56  } // callback
57  );
58 
59  session_wrapper_.SetDebugName(debug_label);
60 
61  // Get information to finish initialization and only then allow Present()s.
62  session_wrapper_.RequestPresentationTimes(
63  /*requested_prediction_span=*/0,
64  [this](fuchsia::scenic::scheduling::FuturePresentationTimes info) {
65  frames_in_flight_allowed_ = info.remaining_presents_in_flight_allowed;
66 
67  // If Scenic alloted us 0 frames to begin with, we should fail here.
68  FML_CHECK(frames_in_flight_allowed_ > 0);
69 
71  std::move(info));
72 
73  // Signal is initially high indicating availability of the session.
74  ToggleSignal(vsync_event_handle_, true);
75  initialized_ = true;
76 
77  PresentSession();
78  });
79 }
#define FML_DCHECK(condition)
Definition: logging.h:86
void UpdateNextPresentationInfo(fuchsia::scenic::scheduling::FuturePresentationTimes info)
void UpdateFramePresentedInfo(zx::time presentation_time)
static VsyncRecorder & GetInstance()
#define FML_CHECK(condition)
Definition: logging.h:68
#define TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val)
Definition: trace_event.h:83

◆ ~SessionConnection()

flutter_runner::SessionConnection::~SessionConnection ( )
default

Referenced by SessionConnection().

Member Function Documentation

◆ CalculateNextLatchPoint()

fml::TimePoint flutter_runner::SessionConnection::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 
)
static

Definition at line 108 of file session_connection.cc.

References FML_CHECK, FML_LOG, fml::TimePoint::FromEpochDelta(), fml::TimeDelta::FromMicroseconds(), fml::TimeDelta::FromNanoseconds(), flutter_runner::VsyncRecorder::GetCurrentVsyncInfo(), flutter_runner::VsyncRecorder::GetInstance(), fml::TimePoint::Now(), flutter_runner::VsyncInfo::presentation_interval, flutter_runner::VsyncWaiter::SessionPresentSignal, fml::swap(), fml::TimePoint::ToEpochDelta(), fml::TimeDelta::ToNanoseconds(), TRACE_EVENT0, TRACE_FLOW_BEGIN, TRACE_FLOW_END, and flutter_runner::VsyncRecorder::UpdateNextPresentationInfo().

Referenced by get(), and flutter_runner_test::TEST().

115  {
116  // The minimum latch point is the largest of:
117  // Now
118  // When we expect the Flutter work for the frame to be completed
119  // The last latch point targeted
120  fml::TimePoint minimum_latch_point_to_target =
121  std::max(std::max(now, present_requested_time + flutter_frame_build_time),
122  last_latch_point_targeted);
123 
124  for (auto& info : future_presentation_infos) {
125  fml::TimePoint latch_point = info.first;
126 
127  if (latch_point >= minimum_latch_point_to_target) {
128  return latch_point;
129  }
130  }
131 
132  // We could not find a suitable latch point in the list given to us from
133  // Scenic, so aim for the smallest safe value.
134  return minimum_latch_point_to_target;
135 }

◆ get()

◆ Present()

void flutter_runner::SessionConnection::Present ( )
overridevirtual

Implements flutter::SessionWrapper.

Definition at line 83 of file session_connection.cc.

References FML_CHECK, fml::TimePoint::Now(), TRACE_EVENT2, and TRACE_FLOW_BEGIN.

Referenced by flutter_runner::FuchsiaExternalViewEmbedder::EnableWireframe(), flutter_runner::FuchsiaExternalViewEmbedder::FuchsiaExternalViewEmbedder(), get(), flutter_runner::ScopedFrame::ScopedFrame(), flutter_runner::FuchsiaExternalViewEmbedder::SubmitFrame(), and flutter_runner_test::TEST_F().

83  {
84  TRACE_EVENT2("gfx", "SessionConnection::Present", "frames_in_flight",
85  frames_in_flight_, "max_frames_in_flight", kMaxFramesInFlight);
86 
87  TRACE_FLOW_BEGIN("gfx", "SessionConnection::PresentSession",
88  next_present_session_trace_id_);
89  next_present_session_trace_id_++;
90 
91  present_requested_time_ = fml::TimePoint::Now();
92 
93  // Throttle frame submission to Scenic if we already have the maximum amount
94  // of frames in flight. This allows the paint tasks for this frame to execute
95  // in parallel with the presentation of previous frame but still provides
96  // back-pressure to prevent us from enqueuing even more work.
97  if (initialized_ && frames_in_flight_ < kMaxFramesInFlight) {
98  PresentSession();
99  } else {
100  // We should never exceed the max frames in flight.
101  FML_CHECK(frames_in_flight_ <= kMaxFramesInFlight);
102 
103  present_session_pending_ = true;
104  ToggleSignal(vsync_event_handle_, false);
105  }
106 }
#define TRACE_FLOW_BEGIN(category, name, id)
Definition: trace_event.h:115
#define FML_CHECK(condition)
Definition: logging.h:68
#define TRACE_EVENT2(category_group, name, arg1_name, arg1_val, arg2_name, arg2_val)
Definition: trace_event.h:83
static TimePoint Now()
Definition: time_point.cc:26

The documentation for this class was generated from the following files: