Explicitly call deprecated AX name calculation API.
[chromium-blink-merge.git] / native_client_sdk / src / examples / demo / flock / frame_counter.cc
blobe9e4c5453411dbbc2d04a2634a72b0772ca45650
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 #include <time.h>
6 #include <limits>
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 +
14 start_time.tv_usec;
17 void FrameCounter::EndFrame() {
18 struct timeval end_time;
19 gettimeofday(&end_time, NULL);
20 double frame_end = end_time.tv_sec * kMicroSecondsPerSecond +
21 end_time.tv_usec;
22 double dt = frame_end - frame_start_;
23 if (dt < 0)
24 return;
25 frame_duration_accumulator_ += dt;
26 frame_count_++;
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;
35 frame_count_ = 0;
39 void FrameCounter::Reset() {
40 frames_per_second_ = 0;
41 frame_duration_accumulator_ = 0;
42 frame_count_ = 0;