- add sources.
[platform/framework/web/crosswalk.git] / src / native_client_sdk / src / examples / demo / flock / frame_counter.h
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.
4
5 #ifndef FRAME_COUNTER_H_
6 #define FRAME_COUNTER_H_
7
8 class FrameCounter {
9  public:
10   FrameCounter()
11       : frame_duration_accumulator_(0),
12         frame_count_(0),
13         frames_per_second_(0) {}
14   ~FrameCounter() {}
15
16   // Record the current time, which is used to compute the frame duration
17   // when EndFrame() is called.
18   void BeginFrame();
19
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();
25
26   // Reset the frame counters back to 0.
27   void Reset();
28
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_;
34   }
35
36  private:
37   static const double kMicroSecondsPerSecond = 1000000.0;
38   static const int32_t kFrameRateRefreshCount = 100;
39
40   double frame_duration_accumulator_;  // Measured in microseconds.
41   int32_t frame_count_;
42   double frame_start_;
43   double frames_per_second_;
44 };
45
46 #endif  // FRAME_COUNTER_H_