[flutter] Update type of presentation info to std::optional
Change |VsyncRecorder|'s |last_presentation_info_| to a std::optional,
rather than a value and a bool. This is how I wanted to write it in the
first place, however we did not have C++17 support at the time.
Test: CQ
Change-Id: Ic6b2c6608455dc9f097bba6d892753cd02757c63
diff --git a/runtime/flutter_runner/vsync_recorder.cc b/runtime/flutter_runner/vsync_recorder.cc
index 7593476..9f76b0e 100644
--- a/runtime/flutter_runner/vsync_recorder.cc
+++ b/runtime/flutter_runner/vsync_recorder.cc
@@ -20,18 +20,18 @@
} // namespace
VsyncRecorder& VsyncRecorder::GetInstance() {
- static VsyncRecorder vsync_manager;
- return vsync_manager;
+ static VsyncRecorder vsync_recorder;
+ return vsync_recorder;
}
VsyncInfo VsyncRecorder::GetCurrentVsyncInfo() const {
{
std::unique_lock<std::mutex> lock(g_mutex);
- if (last_presentation_info_set_) {
+ if (last_presentation_info_) {
return {fml::TimePoint::FromEpochDelta(fml::TimeDelta::FromNanoseconds(
- last_presentation_info_.presentation_time)),
+ last_presentation_info_->presentation_time)),
fml::TimeDelta::FromNanoseconds(
- last_presentation_info_.presentation_interval)};
+ last_presentation_info_->presentation_interval)};
}
}
return {fml::TimePoint::Now(), kDefaultPresentationInterval};
@@ -40,13 +40,12 @@
void VsyncRecorder::UpdateVsyncInfo(
fuchsia::images::PresentationInfo presentation_info) {
std::unique_lock<std::mutex> lock(g_mutex);
- if (last_presentation_info_set_ &&
+ if (last_presentation_info_ &&
presentation_info.presentation_time >
- last_presentation_info_.presentation_time) {
+ last_presentation_info_->presentation_time) {
last_presentation_info_ = presentation_info;
- } else if (!last_presentation_info_set_) {
+ } else if (!last_presentation_info_) {
last_presentation_info_ = presentation_info;
- last_presentation_info_set_ = true;
}
}
diff --git a/runtime/flutter_runner/vsync_recorder.h b/runtime/flutter_runner/vsync_recorder.h
index 60c788d..87d501c 100644
--- a/runtime/flutter_runner/vsync_recorder.h
+++ b/runtime/flutter_runner/vsync_recorder.h
@@ -5,6 +5,8 @@
#ifndef TOPAZ_RUNTIME_FLUTTER_RUNNER_VSYNC_RECORDER_H_
#define TOPAZ_RUNTIME_FLUTTER_RUNNER_VSYNC_RECORDER_H_
+#include <optional>
+
#include "flutter/fml/time/time_delta.h"
#include "flutter/fml/time/time_point.h"
#include "lib/fxl/macros.h"
@@ -36,8 +38,7 @@
private:
VsyncRecorder() = default;
- fuchsia::images::PresentationInfo last_presentation_info_ = {};
- bool last_presentation_info_set_ = false;
+ std::optional<fuchsia::images::PresentationInfo> last_presentation_info_;
FXL_DISALLOW_COPY_ASSIGN_AND_MOVE(VsyncRecorder);
};