Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Unified Diff: chrome/browser/android/vr_shell/fps_meter.cc

Issue 2901213002: Add SlidingAverage to FPSMeter, use for WebVR prediction time (Closed)
Patch Set: Fix "Complex destructor has an inline body" for = default. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/android/vr_shell/fps_meter.h ('k') | chrome/browser/android/vr_shell/fps_meter_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/android/vr_shell/fps_meter.cc
diff --git a/chrome/browser/android/vr_shell/fps_meter.cc b/chrome/browser/android/vr_shell/fps_meter.cc
index 9065fd4350373435e2b0225e07c81db5999719a1..c6d03126d68eb83834ccf278de51a16d4591ae92 100644
--- a/chrome/browser/android/vr_shell/fps_meter.cc
+++ b/chrome/browser/android/vr_shell/fps_meter.cc
@@ -10,18 +10,40 @@ namespace vr_shell {
namespace {
-static constexpr size_t kNumFrameTimes = 10;
+static constexpr size_t kDefaultNumFrameTimes = 10;
-} // namepsace
+} // namespace
-FPSMeter::FPSMeter() : total_time_us_(0) {
- frame_times_.reserve(kNumFrameTimes);
+SampleQueue::SampleQueue(size_t window_size) : window_size_(window_size) {
+ samples_.reserve(window_size);
}
-FPSMeter::~FPSMeter() {}
+SampleQueue::~SampleQueue() = default;
+
+void SampleQueue::AddSample(int64_t value) {
+ sum_ += value;
+
+ if (samples_.size() < window_size_) {
+ samples_.push_back(value);
+ } else {
+ sum_ -= samples_[current_index_];
+ samples_[current_index_] = value;
+ }
+
+ ++current_index_;
+ if (current_index_ >= window_size_) {
+ current_index_ = 0;
+ }
+}
+
+FPSMeter::FPSMeter() : frame_times_(kDefaultNumFrameTimes) {}
+
+FPSMeter::FPSMeter(size_t window_size) : frame_times_(window_size) {}
+
+FPSMeter::~FPSMeter() = default;
size_t FPSMeter::GetNumFrameTimes() {
- return kNumFrameTimes;
+ return frame_times_.GetWindowSize();
}
void FPSMeter::AddFrame(const base::TimeTicks& time_stamp) {
@@ -30,25 +52,14 @@ void FPSMeter::AddFrame(const base::TimeTicks& time_stamp) {
return;
}
- base::TimeDelta delta = time_stamp - last_time_stamp_;
+ int64_t delta = (time_stamp - last_time_stamp_).InMicroseconds();
last_time_stamp_ = time_stamp;
- total_time_us_ += delta.InMicroseconds();
-
- if (frame_times_.size() < kNumFrameTimes) {
- frame_times_.push_back(delta);
- } else {
- total_time_us_ -= frame_times_[current_index_].InMicroseconds();
- frame_times_[current_index_] = delta;
- }
-
- current_index_++;
- if (current_index_ >= kNumFrameTimes)
- current_index_ = 0;
+ frame_times_.AddSample(delta);
}
bool FPSMeter::CanComputeFPS() const {
- return !frame_times_.empty();
+ return frame_times_.GetCount() > 0;
}
// Simply takes the average time delta.
@@ -56,7 +67,21 @@ double FPSMeter::GetFPS() const {
if (!CanComputeFPS())
return 0.0;
- return (frame_times_.size() * 1.0e6) / total_time_us_;
+ return (frame_times_.GetCount() * 1.0e6) / frame_times_.GetSum();
+}
+
+SlidingAverage::SlidingAverage(size_t window_size) : values_(window_size) {}
+
+SlidingAverage::~SlidingAverage() = default;
+
+void SlidingAverage::AddSample(int64_t value) {
+ values_.AddSample(value);
+}
+
+int64_t SlidingAverage::GetAverageOrDefault(int64_t default_value) const {
+ if (values_.GetCount() == 0)
+ return default_value;
+ return values_.GetSum() / values_.GetCount();
}
} // namespace vr_shell
« no previous file with comments | « chrome/browser/android/vr_shell/fps_meter.h ('k') | chrome/browser/android/vr_shell/fps_meter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698