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

Unified Diff: runtime/embedders/openglui/common/timer.cc

Issue 11883013: Refactored OpenGL embedder that works on Android, Mac or Linux. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/embedders/openglui/common/timer.h ('k') | runtime/embedders/openglui/common/types.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/embedders/openglui/common/timer.cc
===================================================================
--- runtime/embedders/openglui/common/timer.cc (revision 0)
+++ runtime/embedders/openglui/common/timer.cc (revision 0)
@@ -0,0 +1,66 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#include "embedders/openglui/common/timer.h"
+
+#define NANO (+1.0E-9)
+
+#ifdef __MACH__
+#include <mach/mach.h>
+#include <mach/mach_time.h>
+#include <sys/time.h>
+
+#define GIGA UINT64_C(1000000000)
+
+#define CLOCK_REALTIME 0
+#define CLOCK_MONOTONIC 1
+
+double timebase = 0.0;
+uint64_t timestart = 0;
+
+void clock_gettime(int type, timespec* t) {
+ if (!timestart) {
+ mach_timebase_info_data_t tb = { 0, 1 };
+ mach_timebase_info(&tb);
+ timebase = tb.numer;
+ timebase /= tb.denom;
+ timestart = mach_absolute_time();
+ }
+ if (type == CLOCK_MONOTONIC) {
+ double diff = (mach_absolute_time() - timestart) * timebase;
+ t->tv_sec = diff * NANO;
+ t->tv_nsec = diff - (t->tv_sec * GIGA);
+ } else { // type == CLOCK_REALTIME
+ struct timeval now;
+ gettimeofday(&now, NULL);
+ t->tv_sec = now.tv_sec;
+ t->tv_nsec = now.tv_usec * 1000;
+ }
+}
+#endif
+
+Timer::Timer() : elapsed_(0.0f), last_time_(0.0) {
+}
+
+void Timer::reset() {
+ elapsed_ = 0.0f;
+ last_time_ = now();
+}
+
+void Timer::update() {
+ double current = now();
+ elapsed_ = (current - last_time_);
+ last_time_ = current;
+}
+
+double Timer::now() {
+ timespec timeval;
+ clock_gettime(CLOCK_MONOTONIC, &timeval);
+ return timeval.tv_sec + (timeval.tv_nsec * NANO);
+}
+
+float Timer::elapsed() {
+ return elapsed_;
+}
+
« no previous file with comments | « runtime/embedders/openglui/common/timer.h ('k') | runtime/embedders/openglui/common/types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698