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

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: 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 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() : total_time_us_(0) {
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 total_time_us_ += delta.InMicroseconds();
33
34 if (frame_times_.size() + 1 < kNumFrameTimes) {
35 frame_times_.push_back(delta);
36 } else {
37 total_time_us_ -= frame_times_[current_index_].InMicroseconds();
38 frame_times_[current_index_] = delta;
39 }
40
41 current_index_++;
42 if (current_index_ >= kNumFrameTimes)
43 current_index_ = 0;
44 }
45
46 bool FPSMeter::CanComputeFPS() const {
47 return !frame_times_.empty();
48 }
49
50 // Simply takes the average time delta.
51 double FPSMeter::GetFPS() const {
52 if (!CanComputeFPS())
53 return 0.0;
54
55 return (frame_times_.size() * 1.0e6) / total_time_us_;
56 }
57
58 } // namespace vr_shell
OLDNEW
« 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