| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2011 Google 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 * | 23 * |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "ScriptedAnimationController.h" | 27 #include "ScriptedAnimationController.h" |
| 28 | 28 |
| 29 #if ENABLE(REQUEST_ANIMATION_FRAME) | 29 #if ENABLE(REQUEST_ANIMATION_FRAME) |
| 30 | 30 |
| 31 #include "Document.h" | 31 #include "Document.h" |
| 32 #include "DocumentLoader.h" | |
| 33 #include "FrameView.h" | 32 #include "FrameView.h" |
| 34 #include "InspectorInstrumentation.h" | 33 #include "InspectorInstrumentation.h" |
| 35 #include "RequestAnimationFrameCallback.h" | 34 #include "RequestAnimationFrameCallback.h" |
| 36 | 35 |
| 37 #if USE(REQUEST_ANIMATION_FRAME_TIMER) | 36 #if USE(REQUEST_ANIMATION_FRAME_TIMER) |
| 38 #include <algorithm> | 37 #include <algorithm> |
| 39 #include <wtf/CurrentTime.h> | 38 #include <wtf/CurrentTime.h> |
| 40 | 39 |
| 41 using namespace std; | 40 using namespace std; |
| 42 | 41 |
| 43 // Allow a little more than 60fps to make sure we can at least hit that frame ra
te. | 42 // Allow a little more than 60fps to make sure we can at least hit that frame ra
te. |
| 44 #define MinimumAnimationInterval 0.015 | 43 #define MinimumAnimationInterval 0.015 |
| 45 #endif | 44 #endif |
| 46 | 45 |
| 47 namespace WebCore { | 46 namespace WebCore { |
| 48 | 47 |
| 49 ScriptedAnimationController::ScriptedAnimationController(Document* document, Pla
tformDisplayID displayID) | 48 ScriptedAnimationController::ScriptedAnimationController(Document* document, Pla
tformDisplayID displayID) |
| 50 : m_document(document) | 49 : m_document(document) |
| 51 , m_nextCallbackId(0) | 50 , m_nextCallbackId(0) |
| 52 , m_suspendCount(0) | 51 , m_suspendCount(0) |
| 53 #if USE(REQUEST_ANIMATION_FRAME_TIMER) | 52 #if USE(REQUEST_ANIMATION_FRAME_TIMER) |
| 54 , m_animationTimer(this, &ScriptedAnimationController::animationTimerFired) | 53 , m_animationTimer(this, &ScriptedAnimationController::animationTimerFired) |
| 55 , m_lastAnimationFrameTimeMonotonic(0) | 54 , m_lastAnimationFrameTime(0) |
| 56 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) | 55 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) |
| 57 , m_useTimer(false) | 56 , m_useTimer(false) |
| 58 #endif | 57 #endif |
| 59 #endif | 58 #endif |
| 60 { | 59 { |
| 61 windowScreenDidChange(displayID); | 60 windowScreenDidChange(displayID); |
| 62 } | 61 } |
| 63 | 62 |
| 64 ScriptedAnimationController::~ScriptedAnimationController() | 63 ScriptedAnimationController::~ScriptedAnimationController() |
| 65 { | 64 { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 for (size_t i = 0; i < m_callbacks.size(); ++i) { | 99 for (size_t i = 0; i < m_callbacks.size(); ++i) { |
| 101 if (m_callbacks[i]->m_id == id) { | 100 if (m_callbacks[i]->m_id == id) { |
| 102 m_callbacks[i]->m_firedOrCancelled = true; | 101 m_callbacks[i]->m_firedOrCancelled = true; |
| 103 InspectorInstrumentation::didCancelAnimationFrame(m_document, id); | 102 InspectorInstrumentation::didCancelAnimationFrame(m_document, id); |
| 104 m_callbacks.remove(i); | 103 m_callbacks.remove(i); |
| 105 return; | 104 return; |
| 106 } | 105 } |
| 107 } | 106 } |
| 108 } | 107 } |
| 109 | 108 |
| 110 void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTime
Now) | 109 void ScriptedAnimationController::serviceScriptedAnimations(DOMTimeStamp time) |
| 111 { | 110 { |
| 112 if (!m_callbacks.size() || m_suspendCount) | 111 if (!m_callbacks.size() || m_suspendCount) |
| 113 return; | 112 return; |
| 114 | 113 |
| 115 double highResNowMs = 1000.0 * m_document->loader()->timing()->convertMonoto
nicTimeToZeroBasedDocumentTime(monotonicTimeNow); | |
| 116 | |
| 117 // First, generate a list of callbacks to consider. Callbacks registered fr
om this point | 114 // First, generate a list of callbacks to consider. Callbacks registered fr
om this point |
| 118 // on are considered only for the "next" frame, not this one. | 115 // on are considered only for the "next" frame, not this one. |
| 119 CallbackList callbacks(m_callbacks); | 116 CallbackList callbacks(m_callbacks); |
| 120 | 117 |
| 121 // Invoking callbacks may detach elements from our document, which clear's t
he document's | 118 // Invoking callbacks may detach elements from our document, which clear's t
he document's |
| 122 // reference to us, so take a defensive reference. | 119 // reference to us, so take a defensive reference. |
| 123 RefPtr<ScriptedAnimationController> protector(this); | 120 RefPtr<ScriptedAnimationController> protector(this); |
| 124 | 121 |
| 125 for (size_t i = 0; i < callbacks.size(); ++i) { | 122 for (size_t i = 0; i < callbacks.size(); ++i) { |
| 126 RequestAnimationFrameCallback* callback = callbacks[i].get(); | 123 RequestAnimationFrameCallback* callback = callbacks[i].get(); |
| 127 if (!callback->m_firedOrCancelled) { | 124 if (!callback->m_firedOrCancelled) { |
| 128 callback->m_firedOrCancelled = true; | 125 callback->m_firedOrCancelled = true; |
| 129 InspectorInstrumentationCookie cookie = InspectorInstrumentation::wi
llFireAnimationFrame(m_document, callback->m_id); | 126 InspectorInstrumentationCookie cookie = InspectorInstrumentation::wi
llFireAnimationFrame(m_document, callback->m_id); |
| 130 callback->handleEvent(highResNowMs); | 127 callback->handleEvent(time); |
| 131 InspectorInstrumentation::didFireAnimationFrame(cookie); | 128 InspectorInstrumentation::didFireAnimationFrame(cookie); |
| 132 } | 129 } |
| 133 } | 130 } |
| 134 | 131 |
| 135 // Remove any callbacks we fired from the list of pending callbacks. | 132 // Remove any callbacks we fired from the list of pending callbacks. |
| 136 for (size_t i = 0; i < m_callbacks.size();) { | 133 for (size_t i = 0; i < m_callbacks.size();) { |
| 137 if (m_callbacks[i]->m_firedOrCancelled) | 134 if (m_callbacks[i]->m_firedOrCancelled) |
| 138 m_callbacks.remove(i); | 135 m_callbacks.remove(i); |
| 139 else | 136 else |
| 140 ++i; | 137 ++i; |
| 141 } | 138 } |
| 142 | 139 |
| 143 if (m_callbacks.size()) | 140 if (m_callbacks.size()) |
| 144 scheduleAnimation(); | 141 scheduleAnimation(); |
| 145 } | 142 } |
| 146 | 143 |
| 147 void ScriptedAnimationController::windowScreenDidChange(PlatformDisplayID displa
yID) | 144 void ScriptedAnimationController::windowScreenDidChange(PlatformDisplayID displa
yID) |
| 148 { | 145 { |
| 149 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) | 146 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) |
| 150 DisplayRefreshMonitorManager::sharedManager()->windowScreenDidChange(display
ID, this); | 147 DisplayRefreshMonitorManager::sharedManager()->windowScreenDidChange(display
ID, this); |
| 151 #else | 148 #else |
| 152 UNUSED_PARAM(displayID); | 149 UNUSED_PARAM(displayID); |
| 153 #endif | 150 #endif |
| 154 } | 151 } |
| 155 | 152 |
| 156 void ScriptedAnimationController::scheduleAnimation() | 153 void ScriptedAnimationController::scheduleAnimation() |
| 157 { | 154 { |
| 158 if (!m_document) | 155 if (!m_document) |
| 159 return; | 156 return; |
| 160 | 157 |
| 161 #if USE(REQUEST_ANIMATION_FRAME_TIMER) | 158 #if USE(REQUEST_ANIMATION_FRAME_TIMER) |
| 162 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) | 159 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) |
| 163 if (!m_useTimer) { | 160 if (!m_useTimer) { |
| 164 if (DisplayRefreshMonitorManager::sharedManager()->scheduleAnimation(thi
s)) | 161 if (DisplayRefreshMonitorManager::sharedManager()->scheduleAnimation(thi
s)) |
| 165 return; | 162 return; |
| 166 | 163 |
| 167 m_useTimer = true; | 164 m_useTimer = true; |
| 168 } | 165 } |
| 169 #endif | 166 #endif |
| 170 if (m_animationTimer.isActive()) | 167 if (m_animationTimer.isActive()) |
| 171 return; | 168 return; |
| 172 | 169 |
| 173 double scheduleDelay = max<double>(MinimumAnimationInterval - (monotonically
IncreasingTime() - m_lastAnimationFrameTimeMonotonic), 0); | 170 double scheduleDelay = max<double>(MinimumAnimationInterval - (currentTime()
- m_lastAnimationFrameTime), 0); |
| 174 m_animationTimer.startOneShot(scheduleDelay); | 171 m_animationTimer.startOneShot(scheduleDelay); |
| 175 #else | 172 #else |
| 176 if (FrameView* frameView = m_document->view()) | 173 if (FrameView* frameView = m_document->view()) |
| 177 frameView->scheduleAnimation(); | 174 frameView->scheduleAnimation(); |
| 178 #endif | 175 #endif |
| 179 } | 176 } |
| 180 | 177 |
| 181 #if USE(REQUEST_ANIMATION_FRAME_TIMER) | 178 #if USE(REQUEST_ANIMATION_FRAME_TIMER) |
| 182 void ScriptedAnimationController::animationTimerFired(Timer<ScriptedAnimationCon
troller>*) | 179 void ScriptedAnimationController::animationTimerFired(Timer<ScriptedAnimationCon
troller>*) |
| 183 { | 180 { |
| 184 m_lastAnimationFrameTimeMonotonic = monotonicallyIncreasingTime(); | 181 m_lastAnimationFrameTime = currentTime(); |
| 185 serviceScriptedAnimations(m_lastAnimationFrameTimeMonotonic); | 182 serviceScriptedAnimations(convertSecondsToDOMTimeStamp(m_lastAnimationFrameT
ime)); |
| 186 } | |
| 187 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) | |
| 188 void ScriptedAnimationController::displayRefreshFired(double monotonicTimeNow) | |
| 189 { | |
| 190 serviceScriptedAnimations(monotonicTimeNow); | |
| 191 } | 183 } |
| 192 #endif | 184 #endif |
| 193 #endif | |
| 194 | |
| 195 | |
| 196 | 185 |
| 197 } | 186 } |
| 198 | 187 |
| 199 #endif | 188 #endif |
| 189 |
| OLD | NEW |