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

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

Issue 2804943003: [vr] Add a frame rate counter for the vr UI (Closed)
Patch Set: dcheck is on Created 3 years, 8 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
new file mode 100644
index 0000000000000000000000000000000000000000..09319b1815ce47fb228e3e519c49a340c3aadf92
--- /dev/null
+++ b/chrome/browser/android/vr_shell/fps_meter.cc
@@ -0,0 +1,58 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/vr_shell/fps_meter.h"
+
+#include <algorithm>
+
+namespace vr_shell {
+
+namespace {
+
+static constexpr size_t kNumFrameTimes = 200;
+
+} // namepsace
+
+FPSMeter::FPSMeter() : total_time_us_(0) {
+ frame_times_.reserve(kNumFrameTimes);
+}
+
+FPSMeter::~FPSMeter() {}
+
+void FPSMeter::AddFrame(const base::TimeTicks& time_stamp) {
+ if (last_time_stamp_.is_null()) {
+ last_time_stamp_ = time_stamp;
+ return;
+ }
+
+ base::TimeDelta delta = time_stamp - last_time_stamp_;
+ last_time_stamp_ = time_stamp;
+
+ total_time_us_ += delta.InMicroseconds();
+
+ if (frame_times_.size() + 1 < 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;
+}
+
+bool FPSMeter::CanComputeFPS() const {
+ return !frame_times_.empty();
+}
+
+// Simply takes the average time delta.
+double FPSMeter::GetFPS() const {
+ if (!CanComputeFPS())
+ return 0.0;
+
+ return (frame_times_.size() * 1.0e6) / total_time_us_;
+}
+
+} // 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