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

Side by Side Diff: Source/core/dom/FrameRequestCallbackCollection.cpp

Issue 1043903003: rAF: Introduce FrameRequestCallbackCollection for managing rAF callbacks. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: . Created 5 years, 8 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/dom/FrameRequestCallbackCollection.h"
7
8 #include "core/dom/FrameRequestCallback.h"
9 #include "core/inspector/InspectorInstrumentation.h"
10 #include "core/inspector/InspectorTraceEvents.h"
11
12 namespace blink {
13
14 FrameRequestCallbackCollection::FrameRequestCallbackCollection(ExecutionContext* context)
15 : m_context(context)
16 {
17 }
18
19 FrameRequestCallbackCollection::CallbackId FrameRequestCallbackCollection::regis terCallback(FrameRequestCallback* callback)
20 {
21 FrameRequestCallbackCollection::CallbackId id = ++m_nextCallbackId;
22 callback->m_cancelled = false;
23 callback->m_id = id;
24 m_callbacks.append(callback);
25
26 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "Reques tAnimationFrame", "data", InspectorAnimationFrameEvent::data(m_context, id));
27 InspectorInstrumentation::didRequestAnimationFrame(m_context, id);
28
29 return id;
30 }
31
32 void FrameRequestCallbackCollection::cancelCallback(CallbackId id)
33 {
34 for (size_t i = 0; i < m_callbacks.size(); ++i) {
35 if (m_callbacks[i]->m_id == id) {
36 m_callbacks.remove(i);
37 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "CancelAnimationFrame", "data", InspectorAnimationFrameEvent::data(m_context, i d));
38 InspectorInstrumentation::didCancelAnimationFrame(m_context, id);
39 return;
40 }
41 }
42 for (size_t i = 0; i < m_callbacksToInvoke.size(); ++i) {
43 if (m_callbacksToInvoke[i]->m_id == id) {
44 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "CancelAnimationFrame", "data", InspectorAnimationFrameEvent::data(m_context, i d));
45 InspectorInstrumentation::didCancelAnimationFrame(m_context, id);
46 m_callbacksToInvoke[i]->m_cancelled = true;
47 // will be removed at the end of executeCallbacks()
48 return;
49 }
50 }
51 }
52
53 void FrameRequestCallbackCollection::executeCallbacks(double highResNowMs, doubl e highResNowMsLegacy)
54 {
55 // First, generate a list of callbacks to consider. Callbacks registered fr om this point
56 // on are considered only for the "next" frame, not this one.
57 ASSERT(m_callbacksToInvoke.isEmpty());
58 m_callbacksToInvoke.swap(m_callbacks);
59
60 for (size_t i = 0; i < m_callbacksToInvoke.size(); ++i) {
61 FrameRequestCallback* callback = m_callbacksToInvoke[i].get();
62 if (!callback->m_cancelled) {
63 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "FireAn imationFrame", "data", InspectorAnimationFrameEvent::data(m_context, callback->m _id));
64 InspectorInstrumentationCookie cookie = InspectorInstrumentation::wi llFireAnimationFrame(m_context, callback->m_id);
65 if (callback->m_useLegacyTimeBase)
66 callback->handleEvent(highResNowMsLegacy);
67 else
68 callback->handleEvent(highResNowMs);
69 InspectorInstrumentation::didFireAnimationFrame(cookie);
70 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "UpdateCounters", "data", InspectorUpdateCountersEvent::data());
71 }
72 }
73
74 m_callbacksToInvoke.clear();
75 }
76
77 DEFINE_TRACE(FrameRequestCallbackCollection)
78 {
79 #if ENABLE(OILPAN)
80 visitor->trace(m_callbacks);
81 visitor->trace(m_callbacksToInvoke);
82 #endif
83 }
84
85 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/dom/FrameRequestCallbackCollection.h ('k') | Source/core/dom/RequestAnimationFrameCallback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698