Explicitly call deprecated AX name calculation API.
[chromium-blink-merge.git] / native_client_sdk / src / examples / demo / flock / frame_counter.h
blob26a1b6628847c6e4b5449101c5a2b678a0d8eee3
1 // Copyright 2013 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.
5 #ifndef FRAME_COUNTER_H_
6 #define FRAME_COUNTER_H_
8 class FrameCounter {
9 public:
10 FrameCounter()
11 : frame_duration_accumulator_(0),
12 frame_count_(0),
13 frames_per_second_(0) {}
14 ~FrameCounter() {}
16 // Record the current time, which is used to compute the frame duration
17 // when EndFrame() is called.
18 void BeginFrame();
20 // Compute the delta since the last call to BeginFrame() and increment the
21 // frame count. Update the frame rate whenever the prescribed number of
22 // frames have been counted, or at least one second of simulator time has
23 // passed, whichever is less.
24 void EndFrame();
26 // Reset the frame counters back to 0.
27 void Reset();
29 // The current frame rate. Note that this is 0 for the first second in
30 // the accumulator, and is updated every 100 frames (and at least once
31 // every second of simulation time or so).
32 double frames_per_second() const {
33 return frames_per_second_;
36 private:
37 static const double kMicroSecondsPerSecond = 1000000.0;
38 static const int32_t kFrameRateRefreshCount = 100;
40 double frame_duration_accumulator_; // Measured in microseconds.
41 int32_t frame_count_;
42 double frame_start_;
43 double frames_per_second_;
46 #endif // FRAME_COUNTER_H_