diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-07 11:21:11 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-07 11:21:11 +0200 |
commit | 2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47 (patch) | |
tree | 988e8c5b116dd0466244ae2fe5af8ee9be926d76 /Source/WebCore/dom/ScriptedAnimationController.cpp | |
parent | dd91e772430dc294e3bf478c119ef8d43c0a3358 (diff) | |
download | qtwebkit-2cf6c8816a73e0132bd8fa3b509d62d7c51b6e47.tar.gz |
Imported WebKit commit 7e538425aa020340619e927792f3d895061fb54b (http://svn.webkit.org/repository/webkit/trunk@116286)
Diffstat (limited to 'Source/WebCore/dom/ScriptedAnimationController.cpp')
-rw-r--r-- | Source/WebCore/dom/ScriptedAnimationController.cpp | 89 |
1 files changed, 40 insertions, 49 deletions
diff --git a/Source/WebCore/dom/ScriptedAnimationController.cpp b/Source/WebCore/dom/ScriptedAnimationController.cpp index 099bc5cbd..a0b0c9d61 100644 --- a/Source/WebCore/dom/ScriptedAnimationController.cpp +++ b/Source/WebCore/dom/ScriptedAnimationController.cpp @@ -29,10 +29,11 @@ #if ENABLE(REQUEST_ANIMATION_FRAME) #include "Document.h" -#include "Element.h" +#include "DocumentLoader.h" #include "FrameView.h" #include "InspectorInstrumentation.h" #include "RequestAnimationFrameCallback.h" +#include "Settings.h" #if USE(REQUEST_ANIMATION_FRAME_TIMER) #include <algorithm> @@ -52,7 +53,7 @@ ScriptedAnimationController::ScriptedAnimationController(Document* document, Pla , m_suspendCount(0) #if USE(REQUEST_ANIMATION_FRAME_TIMER) , m_animationTimer(this, &ScriptedAnimationController::animationTimerFired) - , m_lastAnimationFrameTime(0) + , m_lastAnimationFrameTimeMonotonic(0) #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) , m_useTimer(false) #endif @@ -72,17 +73,20 @@ void ScriptedAnimationController::suspend() void ScriptedAnimationController::resume() { - --m_suspendCount; + // It would be nice to put an ASSERT(m_suspendCount > 0) here, but in WK1 resume() can be called + // even when suspend hasn't (if a tab was created in the background). + if (m_suspendCount > 0) + --m_suspendCount; + if (!m_suspendCount && m_callbacks.size()) scheduleAnimation(); } -ScriptedAnimationController::CallbackId ScriptedAnimationController::registerCallback(PassRefPtr<RequestAnimationFrameCallback> callback, Element* animationElement) +ScriptedAnimationController::CallbackId ScriptedAnimationController::registerCallback(PassRefPtr<RequestAnimationFrameCallback> callback) { ScriptedAnimationController::CallbackId id = m_nextCallbackId++; callback->m_firedOrCancelled = false; callback->m_id = id; - callback->m_element = animationElement; m_callbacks.append(callback); InspectorInstrumentation::didRequestAnimationFrame(m_document, id); @@ -104,52 +108,30 @@ void ScriptedAnimationController::cancelCallback(CallbackId id) } } -void ScriptedAnimationController::serviceScriptedAnimations(DOMTimeStamp time) +void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTimeNow) { - if (!m_callbacks.size() || m_suspendCount) + if (!m_callbacks.size() || m_suspendCount || (m_document->settings() && !m_document->settings()->requestAnimationFrameEnabled())) return; - // We want to run the callback for all elements in the document that have registered - // for a callback and that are visible. Running the callbacks can cause new callbacks - // to be registered, existing callbacks to be cancelled, and elements to gain or lose - // visibility so this code has to iterate carefully. - // FIXME: Currently, this code doesn't do any visibility tests beyond checking display: + double highResNowMs = 1000.0 * m_document->loader()->timing()->convertMonotonicTimeToZeroBasedDocumentTime(monotonicTimeNow); // First, generate a list of callbacks to consider. Callbacks registered from this point // on are considered only for the "next" frame, not this one. CallbackList callbacks(m_callbacks); - // Firing the callback may cause the visibility of other elements to change. To avoid - // missing any callbacks, we keep iterating through the list of candiate callbacks and firing - // them until nothing new becomes visible. - bool firedCallback; - - // Invoking callbacks may detach elements from our document, which clear's the document's + // Invoking callbacks may detach elements from our document, which clears the document's // reference to us, so take a defensive reference. RefPtr<ScriptedAnimationController> protector(this); - do { - firedCallback = false; - // A previous iteration may have detached this Document from the DOM tree. - // If so, then we do not need to process any more callbacks. - if (!m_document) - continue; - - // A previous iteration may have invalidated style (or layout). Update styles for each iteration - // for now since all we check is the existence of a renderer. - m_document->updateStyleIfNeeded(); - for (size_t i = 0; i < callbacks.size(); ++i) { - RequestAnimationFrameCallback* callback = callbacks[i].get(); - if (!callback->m_firedOrCancelled && (!callback->m_element || callback->m_element->renderer())) { - callback->m_firedOrCancelled = true; - InspectorInstrumentationCookie cookie = InspectorInstrumentation::willFireAnimationFrame(m_document, callback->m_id); - callback->handleEvent(time); - InspectorInstrumentation::didFireAnimationFrame(cookie); - firedCallback = true; - callbacks.remove(i); - break; - } + + for (size_t i = 0; i < callbacks.size(); ++i) { + RequestAnimationFrameCallback* callback = callbacks[i].get(); + if (!callback->m_firedOrCancelled) { + callback->m_firedOrCancelled = true; + InspectorInstrumentationCookie cookie = InspectorInstrumentation::willFireAnimationFrame(m_document, callback->m_id); + callback->handleEvent(highResNowMs); + InspectorInstrumentation::didFireAnimationFrame(cookie); } - } while (firedCallback); + } // Remove any callbacks we fired from the list of pending callbacks. for (size_t i = 0; i < m_callbacks.size();) { @@ -162,19 +144,21 @@ void ScriptedAnimationController::serviceScriptedAnimations(DOMTimeStamp time) if (m_callbacks.size()) scheduleAnimation(); } - + void ScriptedAnimationController::windowScreenDidChange(PlatformDisplayID displayID) { + if (m_document->settings() && !m_document->settings()->requestAnimationFrameEnabled()) + return; #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) DisplayRefreshMonitorManager::sharedManager()->windowScreenDidChange(displayID, this); #else UNUSED_PARAM(displayID); -#endif +#endif } void ScriptedAnimationController::scheduleAnimation() { - if (!m_document) + if (!m_document || (m_document->settings() && !m_document->settings()->requestAnimationFrameEnabled())) return; #if USE(REQUEST_ANIMATION_FRAME_TIMER) @@ -182,14 +166,14 @@ void ScriptedAnimationController::scheduleAnimation() if (!m_useTimer) { if (DisplayRefreshMonitorManager::sharedManager()->scheduleAnimation(this)) return; - + m_useTimer = true; } #endif if (m_animationTimer.isActive()) return; - - double scheduleDelay = max<double>(MinimumAnimationInterval - (currentTime() - m_lastAnimationFrameTime), 0); + + double scheduleDelay = max<double>(MinimumAnimationInterval - (monotonicallyIncreasingTime() - m_lastAnimationFrameTimeMonotonic), 0); m_animationTimer.startOneShot(scheduleDelay); #else if (FrameView* frameView = m_document->view()) @@ -200,12 +184,19 @@ void ScriptedAnimationController::scheduleAnimation() #if USE(REQUEST_ANIMATION_FRAME_TIMER) void ScriptedAnimationController::animationTimerFired(Timer<ScriptedAnimationController>*) { - m_lastAnimationFrameTime = currentTime(); - serviceScriptedAnimations(convertSecondsToDOMTimeStamp(m_lastAnimationFrameTime)); + m_lastAnimationFrameTimeMonotonic = monotonicallyIncreasingTime(); + serviceScriptedAnimations(m_lastAnimationFrameTimeMonotonic); +} +#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) +void ScriptedAnimationController::displayRefreshFired(double monotonicTimeNow) +{ + serviceScriptedAnimations(monotonicTimeNow); } #endif +#endif + + } #endif - |