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.
8 #include "nacl_app/flock.h"
10 void FrameCounter::BeginFrame() {
11 struct timeval start_time
;
12 gettimeofday(&start_time
, NULL
);
13 frame_start_
= start_time
.tv_sec
* kMicroSecondsPerSecond
+
17 void FrameCounter::EndFrame() {
18 struct timeval end_time
;
19 gettimeofday(&end_time
, NULL
);
20 double frame_end
= end_time
.tv_sec
* kMicroSecondsPerSecond
+
22 double dt
= frame_end
- frame_start_
;
25 frame_duration_accumulator_
+= dt
;
27 if (frame_count_
> kFrameRateRefreshCount
||
28 frame_duration_accumulator_
>= kMicroSecondsPerSecond
) {
29 double elapsed_time
= frame_duration_accumulator_
/
30 kMicroSecondsPerSecond
;
31 if (fabs(elapsed_time
) > std::numeric_limits
<double>::epsilon()) {
32 frames_per_second_
= frame_count_
/ elapsed_time
;
34 frame_duration_accumulator_
= 0;
39 void FrameCounter::Reset() {
40 frames_per_second_
= 0;
41 frame_duration_accumulator_
= 0;