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

Side by Side Diff: chrome/browser/android/vr_shell/fps_meter.cc

Issue 2804943003: [vr] Add a frame rate counter for the vr UI (Closed)
Patch Set: Actually implement CanComputeFPS 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/android/vr_shell/fps_meter.h"
6
7 #include <algorithm>
8
9 namespace vr_shell {
10
11 namespace {
12
13 static constexpr size_t kNumFrameTimes = 200;
14
15 } // namepsace
16
17 FPSMeter::FPSMeter() {
18 frame_times_.reserve(kNumFrameTimes);
19 }
20
21 FPSMeter::~FPSMeter() {}
22
23 void FPSMeter::AddFrame(const base::TimeTicks& time_stamp) {
24 if (last_time_stamp_.is_null()) {
25 last_time_stamp_ = time_stamp;
26 return;
27 }
28
29 base::TimeDelta delta = time_stamp - last_time_stamp_;
30 last_time_stamp_ = time_stamp;
31
32 if (frame_times_.size() + 1 < kNumFrameTimes)
33 frame_times_.push_back(delta);
34 else
35 frame_times_[current_index_] = delta;
36
37 current_index_++;
38 if (current_index_ >= kNumFrameTimes)
39 current_index_ = 0;
40 }
41
42 bool FPSMeter::CanComputeFPS() const {
43 return !frame_times_.empty();
44 }
45
46 // Simply takes the average time delta.
47 double FPSMeter::GetFPS() const {
48 if (!CanComputeFPS())
49 return 0.0;
50
51 double total_duration = 0.0;
52 for (const auto& delta : frame_times_)
mthiesse 2017/04/11 19:14:36 Instead of recomputing the sum each time you read,
billorr 2017/04/12 00:40:03 floating point error will accumulate
53 total_duration += delta.InSecondsF();
54
55 return frame_times_.size() / total_duration;
56 }
57
58 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698