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
+ auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now () - time_start);
48
+
49
+ return duration.count ()/1000.0 ;
50
+ }
51
+
52
+ std::chrono::time_point<std::chrono::high_resolution_clock> time_start;
53
+ };
54
+ #elif defined(LIBFREENECT2_WITH_OPENGL_SUPPORT)
55
+ class TimerImpl {
56
+ public:
57
+ void start () {
58
+ time_start = glfwGetTime ();
59
+ }
60
+
61
+ double stop () {
62
+ return glfwGetTime () - time_start;
63
+ }
64
+
65
+ double time_start;
66
+ };
67
+ #else
68
+ class TimerImpl {
69
+ public:
70
+ void start () {
71
+ }
72
+
73
+ double stop () {
74
+ return 0 ;
75
+ }
76
+ };
77
+ #endif
78
+
79
+ Timer::Timer () :
80
+ impl_ (new TimerImpl()) {
81
+ }
82
+
83
+ Timer::~Timer () {
84
+ delete impl_;
85
+ }
86
+
87
+ void Timer::start () {
88
+ impl_->start ();
89
+ }
90
+
91
+ double Timer::stop () {
92
+ return impl_->stop ();
93
+ }
94
+
95
+ } /* namespace libfreenect2 */
0 commit comments