Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Unified Diff: Source/core/dom/ScriptedAnimationController.cpp

Issue 92913002: Manage RequestAnimationFrameCallbacks with OwnPtrs instead of RefPtrs (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/ScriptedAnimationController.h ('k') | Source/core/frame/DOMWindow.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/dom/ScriptedAnimationController.cpp
diff --git a/Source/core/dom/ScriptedAnimationController.cpp b/Source/core/dom/ScriptedAnimationController.cpp
index 33446c8e85835e2137a614e139e4ec09dc0a5ec1..27a7f6b463f173ab8259b7a6e08c639cfad47de5 100644
--- a/Source/core/dom/ScriptedAnimationController.cpp
+++ b/Source/core/dom/ScriptedAnimationController.cpp
@@ -66,10 +66,10 @@ void ScriptedAnimationController::resume()
scheduleAnimationIfNeeded();
}
-ScriptedAnimationController::CallbackId ScriptedAnimationController::registerCallback(PassRefPtr<RequestAnimationFrameCallback> callback)
+ScriptedAnimationController::CallbackId ScriptedAnimationController::registerCallback(PassOwnPtr<RequestAnimationFrameCallback> callback)
{
ScriptedAnimationController::CallbackId id = ++m_nextCallbackId;
- callback->m_firedOrCancelled = false;
+ callback->m_cancelled = false;
callback->m_id = id;
m_callbacks.append(callback);
scheduleAnimationIfNeeded();
@@ -83,12 +83,19 @@ void ScriptedAnimationController::cancelCallback(CallbackId id)
{
for (size_t i = 0; i < m_callbacks.size(); ++i) {
if (m_callbacks[i]->m_id == id) {
- m_callbacks[i]->m_firedOrCancelled = true;
InspectorInstrumentation::didCancelAnimationFrame(m_document, id);
m_callbacks.remove(i);
return;
}
}
+ for (size_t i = 0; i < m_callbacksToInvoke.size(); ++i) {
+ if (m_callbacksToInvoke[i]->m_id == id) {
+ InspectorInstrumentation::didCancelAnimationFrame(m_document, id);
+ m_callbacksToInvoke[i]->m_cancelled = true;
+ // will be removed at the end of executeCallbacks()
+ return;
+ }
+ }
}
void ScriptedAnimationController::dispatchEvents()
@@ -120,12 +127,12 @@ void ScriptedAnimationController::executeCallbacks(double 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);
+ ASSERT(m_callbacksToInvoke.isEmpty());
+ m_callbacksToInvoke.swap(m_callbacks);
- for (size_t i = 0; i < callbacks.size(); ++i) {
- RequestAnimationFrameCallback* callback = callbacks[i].get();
- if (!callback->m_firedOrCancelled) {
- callback->m_firedOrCancelled = true;
+ for (size_t i = 0; i < m_callbacksToInvoke.size(); ++i) {
+ RequestAnimationFrameCallback* callback = m_callbacksToInvoke[i].get();
+ if (!callback->m_cancelled) {
InspectorInstrumentationCookie cookie = InspectorInstrumentation::willFireAnimationFrame(m_document, callback->m_id);
if (callback->m_useLegacyTimeBase)
callback->handleEvent(legacyHighResNowMs);
@@ -135,13 +142,7 @@ void ScriptedAnimationController::executeCallbacks(double monotonicTimeNow)
}
}
- // Remove any callbacks we fired from the list of pending callbacks.
- for (size_t i = 0; i < m_callbacks.size();) {
- if (m_callbacks[i]->m_firedOrCancelled)
- m_callbacks.remove(i);
- else
- ++i;
- }
+ m_callbacksToInvoke.clear();
}
void ScriptedAnimationController::serviceScriptedAnimations(double monotonicTimeNow)
« no previous file with comments | « Source/core/dom/ScriptedAnimationController.h ('k') | Source/core/frame/DOMWindow.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698