1+ /*
2+ * This file is part of the OpenKinect Project. http://www.openkinect.org
3+ *
4+ * Copyright (c) 2015 individual OpenKinect contributors. See the CONTRIB file
5+ * for details.
6+ *
7+ * This code is licensed to you under the terms of the Apache License, version
8+ * 2.0, or, at your option, the terms of the GNU General Public License,
9+ * version 2.0. See the APACHE20 and GPL2 files for the text of the licenses,
10+ * or the following URLs:
11+ * http://www.apache.org/licenses/LICENSE-2.0
12+ * http://www.gnu.org/licenses/gpl-2.0.txt
13+ *
14+ * If you redistribute this file in source form, modified or unmodified, you
15+ * may:
16+ * 1) Leave this header intact and distribute it under the same terms,
17+ * accompanying it with the APACHE20 and GPL20 files, or
18+ * 2) Delete the Apache 2.0 clause and accompany it with the GPL2 file, or
19+ * 3) Delete the GPL v2 clause and accompany it with the APACHE20 file
20+ * In all cases you must keep the copyright notice intact and include a copy
21+ * of the CONTRIB file.
22+ *
23+ * Binary distributions must follow the binary distribution requirements of
24+ * either License.
25+ */
26+
27+ #include < libfreenect2/timer.h>
28+
29+ #ifdef LIBFREENECT2_WITH_CXX11_SUPPORT
30+ #include < chrono>
31+ #endif
32+
33+ #ifdef LIBFREENECT2_WITH_OPENGL_SUPPORT
34+ #include < GLFW/glfw3.h>
35+ #endif
36+
37+ namespace libfreenect2 {
38+
39+ #ifdef LIBFREENECT2_WITH_CXX11_SUPPORT
40+ class TimerImpl {
41+ public:
42+ void start () {
43+ time_start = std::chrono::high_resolution_clock::now ();
44+ }
45+
46+ double stop () {
47+ return std::chrono::duration_cast<std::chrono::duration<double >>(std::chrono::high_resolution_clock::now () - time_start).count ();
48+ }
49+
50+ std::chrono::time_point<std::chrono::high_resolution_clock> time_start;
51+ };
52+ #elif defined(LIBFREENECT2_WITH_OPENGL_SUPPORT)
53+ class TimerImpl {
54+ public:
55+ void start () {
56+ time_start = glfwGetTime ();
57+ }
58+
59+ double stop () {
60+ return glfwGetTime () - time_start;
61+ }
62+
63+ double time_start;
64+ };
65+ #else
66+ class TimerImpl {
67+ public:
68+ void start () {
69+ }
70+
71+ double stop () {
72+ return 0 ;
73+ }
74+ };
75+ #endif
76+
77+ Timer::Timer () :
78+ impl_ (new TimerImpl()) {
79+ }
80+
81+ Timer::~Timer () {
82+ delete impl_;
83+ }
84+
85+ void Timer::start () {
86+ impl_->start ();
87+ }
88+
89+ double Timer::stop () {
90+ return impl_->stop ();
91+ }
92+
93+ } /* namespace libfreenect2 */
0 commit comments