OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2011 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "ClockGeneric.h" | 27 #include "ClockGeneric.h" |
28 | 28 |
29 #include "FloatConversion.h" | |
30 #include <wtf/CurrentTime.h> | 29 #include <wtf/CurrentTime.h> |
31 | 30 |
32 using namespace WebCore; | 31 using namespace WebCore; |
33 | 32 |
34 ClockGeneric::ClockGeneric() | 33 ClockGeneric::ClockGeneric() |
35 : m_running(false) | 34 : m_running(false) |
36 , m_rate(1) | 35 , m_rate(1) |
37 , m_offset(0) | 36 , m_offset(0) |
38 { | 37 { |
39 m_startTime = m_lastTime = now(); | 38 m_startTime = m_lastTime = now(); |
40 } | 39 } |
41 | 40 |
42 void ClockGeneric::setCurrentTime(float time) | 41 void ClockGeneric::setCurrentTime(double time) |
43 { | 42 { |
44 m_startTime = m_lastTime = now(); | 43 m_startTime = m_lastTime = now(); |
45 m_offset = time; | 44 m_offset = time; |
46 } | 45 } |
47 | 46 |
48 float ClockGeneric::currentTime() const | 47 double ClockGeneric::currentTime() const |
49 { | 48 { |
50 if (m_running) | 49 if (m_running) |
51 m_lastTime = now(); | 50 m_lastTime = now(); |
52 float time = narrowPrecisionToFloat(((m_lastTime - m_startTime) * m_rate) +
m_offset); | 51 return ((m_lastTime - m_startTime) * m_rate) + m_offset; |
53 return time; | |
54 } | 52 } |
55 | 53 |
56 void ClockGeneric::setPlayRate(float rate) | 54 void ClockGeneric::setPlayRate(double rate) |
57 { | 55 { |
58 m_offset = now(); | 56 m_offset = now(); |
59 m_lastTime = m_startTime = now(); | 57 m_lastTime = m_startTime = now(); |
60 m_rate = rate; | 58 m_rate = rate; |
61 } | 59 } |
62 | 60 |
63 void ClockGeneric::start() | 61 void ClockGeneric::start() |
64 { | 62 { |
65 if (m_running) | 63 if (m_running) |
66 return; | 64 return; |
67 | 65 |
68 m_lastTime = m_startTime = now(); | 66 m_lastTime = m_startTime = now(); |
69 m_running = true; | 67 m_running = true; |
70 } | 68 } |
71 | 69 |
72 void ClockGeneric::stop() | 70 void ClockGeneric::stop() |
73 { | 71 { |
74 if (!m_running) | 72 if (!m_running) |
75 return; | 73 return; |
76 | 74 |
77 m_offset = now(); | 75 m_offset = now(); |
78 m_lastTime = m_startTime = now(); | 76 m_lastTime = m_startTime = now(); |
79 m_running = false; | 77 m_running = false; |
80 } | 78 } |
81 | 79 |
82 double ClockGeneric::now() const | 80 double ClockGeneric::now() const |
83 { | 81 { |
84 return WTF::currentTime(); | 82 return WTF::currentTime(); |
85 } | 83 } |
86 | |
OLD | NEW |