Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 99166f2

Browse files
committed
remove vsync_recorder
1 parent d3f740e commit 99166f2

File tree

6 files changed

+60
-134
lines changed

6 files changed

+60
-134
lines changed

shell/platform/fuchsia/flutter/BUILD.gn

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ template("runner_sources") {
8383
"thread.cc",
8484
"thread.h",
8585
"unique_fdio_ns.h",
86-
"vsync_recorder.cc",
87-
"vsync_recorder.h",
8886
"vsync_waiter.cc",
8987
"vsync_waiter.h",
9088
"vulkan_surface.cc",
@@ -455,7 +453,6 @@ executable("flutter_runner_unittests") {
455453
"runner_unittest.cc",
456454
"tests/engine_unittests.cc",
457455
"tests/flutter_runner_product_configuration_unittests.cc",
458-
"tests/vsync_recorder_unittests.cc",
459456
]
460457

461458
# This is needed for //third_party/googletest for linking zircon symbols.

shell/platform/fuchsia/flutter/default_session_connection.cc

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "flutter/fml/make_copyable.h"
88
#include "flutter/fml/trace_event.h"
99

10-
#include "vsync_recorder.h"
1110
#include "vsync_waiter.h"
1211

1312
namespace flutter_runner {
@@ -200,8 +199,8 @@ DefaultSessionConnection::DefaultSessionConnection(
200199
num_presents_handled);
201200
FML_DCHECK(frames_in_flight_ >= 0);
202201

203-
VsyncRecorder::GetInstance().UpdateFramePresentedInfo(
204-
zx::time(info.actual_presentation_time));
202+
last_presentation_time_ = fml::TimePoint::FromEpochDelta(
203+
fml::TimeDelta::FromNanoseconds(info.actual_presentation_time));
205204

206205
// Call the client-provided callback once we are done using |info|.
207206
on_frame_presented_callback_(std::move(info));
@@ -230,8 +229,7 @@ DefaultSessionConnection::DefaultSessionConnection(
230229
// If Scenic alloted us 0 frames to begin with, we should fail here.
231230
FML_CHECK(frames_in_flight_allowed_ > 0);
232231

233-
VsyncRecorder::GetInstance().UpdateNextPresentationInfo(
234-
std::move(info));
232+
UpdateNextPresentationInfo(std::move(info));
235233

236234
initialized_ = true;
237235

@@ -314,7 +312,7 @@ void DefaultSessionConnection::PresentSession() {
314312
// tasks.
315313

316314
fml::TimeDelta presentation_interval =
317-
VsyncRecorder::GetInstance().GetCurrentVsyncInfo().presentation_interval;
315+
GetCurrentVsyncInfo().presentation_interval;
318316

319317
fml::TimePoint next_latch_point = CalculateNextLatchPoint(
320318
fml::TimePoint::Now(), present_requested_time_,
@@ -344,8 +342,7 @@ void DefaultSessionConnection::PresentSession() {
344342
}
345343

346344
frames_in_flight_allowed_ = info.remaining_presents_in_flight_allowed;
347-
VsyncRecorder::GetInstance().UpdateNextPresentationInfo(
348-
std::move(info));
345+
UpdateNextPresentationInfo(std::move(info));
349346
});
350347
}
351348

@@ -373,13 +370,11 @@ void DefaultSessionConnection::FireCallbackMaybe() {
373370
FlutterFrameTimes DefaultSessionConnection::GetTargetTimesHelper(
374371
bool secondary_callback) {
375372
fml::TimeDelta presentation_interval =
376-
VsyncRecorder::GetInstance().GetCurrentVsyncInfo().presentation_interval;
373+
GetCurrentVsyncInfo().presentation_interval;
377374

378-
fml::TimePoint next_vsync =
379-
VsyncRecorder::GetInstance().GetCurrentVsyncInfo().presentation_time;
375+
fml::TimePoint next_vsync = GetCurrentVsyncInfo().presentation_time;
380376
fml::TimePoint now = fml::TimePoint::Now();
381-
fml::TimePoint last_presentation_time =
382-
VsyncRecorder::GetInstance().GetLastPresentationTime();
377+
fml::TimePoint last_presentation_time = last_presentation_time_;
383378
if (next_vsync <= now) {
384379
next_vsync =
385380
SnapToNextPhase(now, last_presentation_time, presentation_interval);
@@ -391,4 +386,24 @@ FlutterFrameTimes DefaultSessionConnection::GetTargetTimesHelper(
391386
last_targetted_vsync, now, next_vsync);
392387
}
393388

389+
void DefaultSessionConnection::UpdateNextPresentationInfo(
390+
fuchsia::scenic::scheduling::FuturePresentationTimes info) {
391+
auto next_time = next_presentation_info_.presentation_time();
392+
// Get the earliest vsync time that is after our recorded |presentation_time|.
393+
for (auto& presentation_info : info.future_presentations) {
394+
auto current_time = presentation_info.presentation_time();
395+
396+
if (current_time > next_time) {
397+
next_presentation_info_.set_presentation_time(current_time);
398+
return;
399+
}
400+
}
401+
}
402+
403+
VsyncInfo DefaultSessionConnection::GetCurrentVsyncInfo() const {
404+
return {fml::TimePoint::FromEpochDelta(fml::TimeDelta::FromNanoseconds(
405+
next_presentation_info_.presentation_time())),
406+
kDefaultPresentationInterval};
407+
}
408+
394409
} // namespace flutter_runner

shell/platform/fuchsia/flutter/default_session_connection.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ struct FlutterFrameTimes {
2828
fml::TimePoint frame_target;
2929
};
3030

31+
struct VsyncInfo {
32+
fml::TimePoint presentation_time;
33+
fml::TimeDelta presentation_interval;
34+
};
35+
36+
// Assume a 60hz refresh rate before we have enough past
37+
// |fuchsia::scenic::scheduling::PresentationInfo|s to calculate it ourselves.
38+
static constexpr fml::TimeDelta kDefaultPresentationInterval =
39+
fml::TimeDelta::FromSecondsF(1.0 / 60.0);
40+
3141
// The component residing on the raster thread that is responsible for
3242
// maintaining the Scenic session connection and presenting node updates.
3343
class DefaultSessionConnection final : public flutter::SessionWrapper {
@@ -111,8 +121,11 @@ class DefaultSessionConnection final : public flutter::SessionWrapper {
111121
int frames_in_flight_allowed_ = 0;
112122
bool present_session_pending_ = false;
113123

114-
////// Flutter Animator logic.
124+
// Flutter framework pipeline logic.
115125

126+
// The following fields can be accessed from both the raster and UI threads,
127+
// so guard them with this mutex. If performance dictates, this could probably
128+
// be made lock-free, but it's much easier to reason about with this mutex.
116129
std::mutex mutex_;
117130

118131
// This is the last Vsync we submitted as the frame_target_time to
@@ -124,8 +137,26 @@ class DefaultSessionConnection final : public flutter::SessionWrapper {
124137
// This is true iff AwaitVSync() was called but we could not schedule a frame.
125138
bool fire_callback_request_pending_ = false;
126139

140+
// The callback passed in from VsyncWaiter which eventually runs on the UI
141+
// thread.
127142
FireCallbackCallback fire_callback_;
128143

144+
// VsyncRecorder logic.
145+
146+
// Update the next Vsync info to |next_presentation_info_|. This is expected
147+
// to be called in |scenic::Session::Present2| immedaite callbacks with the
148+
// presentation info provided by Scenic. Only the next vsync
149+
// information will be saved (in order to handle edge cases involving
150+
// multiple Scenic sessions in the same process). This function is safe to
151+
// call from any thread.
152+
void UpdateNextPresentationInfo(
153+
fuchsia::scenic::scheduling::FuturePresentationTimes info);
154+
155+
VsyncInfo GetCurrentVsyncInfo() const;
156+
157+
fuchsia::scenic::scheduling::PresentationInfo next_presentation_info_;
158+
fml::TimePoint last_presentation_time_ = fml::TimePoint::Now();
159+
129160
FML_DISALLOW_COPY_AND_ASSIGN(DefaultSessionConnection);
130161
};
131162

shell/platform/fuchsia/flutter/vsync_recorder.cc

Lines changed: 0 additions & 61 deletions
This file was deleted.

shell/platform/fuchsia/flutter/vsync_recorder.h

Lines changed: 0 additions & 55 deletions
This file was deleted.

shell/platform/fuchsia/flutter/vsync_waiter.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "flutter/fml/trace_event.h"
1616

1717
#include "flutter_runner_product_configuration.h"
18-
#include "vsync_recorder.h"
1918

2019
namespace flutter_runner {
2120

0 commit comments

Comments
 (0)