| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/dom/FrameRequestCallbackCollection.h" | 5 #include "core/dom/FrameRequestCallbackCollection.h" |
| 6 | 6 |
| 7 #include "core/dom/FrameRequestCallback.h" | 7 #include "core/dom/FrameRequestCallback.h" |
| 8 #include "core/frame/PerformanceMonitor.h" | 8 #include "core/frame/PerformanceMonitor.h" |
| 9 #include "core/inspector/InspectorInstrumentation.h" | 9 #include "core/inspector/InspectorInstrumentation.h" |
| 10 #include "core/inspector/InspectorTraceEvents.h" | 10 #include "core/inspector/InspectorTraceEvents.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 FrameRequestCallbackCollection::FrameRequestCallbackCollection( | 14 FrameRequestCallbackCollection::FrameRequestCallbackCollection( |
| 15 ExecutionContext* context) | 15 ExecutionContext* context) |
| 16 : m_context(context) {} | 16 : m_context(context) {} |
| 17 | 17 |
| 18 FrameRequestCallbackCollection::CallbackId | 18 FrameRequestCallbackCollection::CallbackId |
| 19 FrameRequestCallbackCollection::registerCallback( | 19 FrameRequestCallbackCollection::registerCallback( |
| 20 FrameRequestCallback* callback) { | 20 FrameRequestCallback* callback) { |
| 21 FrameRequestCallbackCollection::CallbackId id = ++m_nextCallbackId; | 21 FrameRequestCallbackCollection::CallbackId id = ++m_nextCallbackId; |
| 22 callback->m_cancelled = false; | 22 callback->m_cancelled = false; |
| 23 callback->m_id = id; | 23 callback->m_id = id; |
| 24 m_callbacks.push_back(callback); | 24 m_callbacks.push_back(callback); |
| 25 | 25 |
| 26 TRACE_EVENT_INSTANT1("devtools.timeline", "RequestAnimationFrame", | 26 TRACE_EVENT_INSTANT1("devtools.timeline", "RequestAnimationFrame", |
| 27 TRACE_EVENT_SCOPE_THREAD, "data", | 27 TRACE_EVENT_SCOPE_THREAD, "data", |
| 28 InspectorAnimationFrameEvent::data(m_context, id)); | 28 InspectorAnimationFrameEvent::data(m_context, id)); |
| 29 InspectorInstrumentation::asyncTaskScheduledBreakable( | 29 InspectorInstrumentation::asyncTaskScheduled( |
| 30 m_context, "requestAnimationFrame", callback); | 30 m_context, "requestAnimationFrame", callback); |
| 31 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( |
| 32 m_context, "DOMWindow.requestAnimationFrame", true); |
| 31 return id; | 33 return id; |
| 32 } | 34 } |
| 33 | 35 |
| 34 void FrameRequestCallbackCollection::cancelCallback(CallbackId id) { | 36 void FrameRequestCallbackCollection::cancelCallback(CallbackId id) { |
| 35 for (size_t i = 0; i < m_callbacks.size(); ++i) { | 37 for (size_t i = 0; i < m_callbacks.size(); ++i) { |
| 36 if (m_callbacks[i]->m_id == id) { | 38 if (m_callbacks[i]->m_id == id) { |
| 37 InspectorInstrumentation::asyncTaskCanceledBreakable( | 39 InspectorInstrumentation::asyncTaskCanceled(m_context, m_callbacks[i]); |
| 38 m_context, "cancelAnimationFrame", m_callbacks[i]); | 40 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( |
| 41 m_context, "DOMWindow.cancelAnimationFrame", true); |
| 39 m_callbacks.remove(i); | 42 m_callbacks.remove(i); |
| 40 TRACE_EVENT_INSTANT1("devtools.timeline", "CancelAnimationFrame", | 43 TRACE_EVENT_INSTANT1("devtools.timeline", "CancelAnimationFrame", |
| 41 TRACE_EVENT_SCOPE_THREAD, "data", | 44 TRACE_EVENT_SCOPE_THREAD, "data", |
| 42 InspectorAnimationFrameEvent::data(m_context, id)); | 45 InspectorAnimationFrameEvent::data(m_context, id)); |
| 43 return; | 46 return; |
| 44 } | 47 } |
| 45 } | 48 } |
| 46 for (const auto& callback : m_callbacksToInvoke) { | 49 for (const auto& callback : m_callbacksToInvoke) { |
| 47 if (callback->m_id == id) { | 50 if (callback->m_id == id) { |
| 48 InspectorInstrumentation::asyncTaskCanceledBreakable( | 51 InspectorInstrumentation::asyncTaskCanceled(m_context, callback); |
| 49 m_context, "cancelAnimationFrame", callback); | 52 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( |
| 53 m_context, "DOMWindow.cancelAnimationFrame", true); |
| 50 TRACE_EVENT_INSTANT1("devtools.timeline", "CancelAnimationFrame", | 54 TRACE_EVENT_INSTANT1("devtools.timeline", "CancelAnimationFrame", |
| 51 TRACE_EVENT_SCOPE_THREAD, "data", | 55 TRACE_EVENT_SCOPE_THREAD, "data", |
| 52 InspectorAnimationFrameEvent::data(m_context, id)); | 56 InspectorAnimationFrameEvent::data(m_context, id)); |
| 53 callback->m_cancelled = true; | 57 callback->m_cancelled = true; |
| 54 // will be removed at the end of executeCallbacks() | 58 // will be removed at the end of executeCallbacks() |
| 55 return; | 59 return; |
| 56 } | 60 } |
| 57 } | 61 } |
| 58 } | 62 } |
| 59 | 63 |
| 60 void FrameRequestCallbackCollection::executeCallbacks( | 64 void FrameRequestCallbackCollection::executeCallbacks( |
| 61 double highResNowMs, | 65 double highResNowMs, |
| 62 double highResNowMsLegacy) { | 66 double highResNowMsLegacy) { |
| 63 // First, generate a list of callbacks to consider. Callbacks registered from | 67 // First, generate a list of callbacks to consider. Callbacks registered from |
| 64 // this point on are considered only for the "next" frame, not this one. | 68 // this point on are considered only for the "next" frame, not this one. |
| 65 DCHECK(m_callbacksToInvoke.isEmpty()); | 69 DCHECK(m_callbacksToInvoke.isEmpty()); |
| 66 m_callbacksToInvoke.swap(m_callbacks); | 70 m_callbacksToInvoke.swap(m_callbacks); |
| 67 | 71 |
| 68 for (const auto& callback : m_callbacksToInvoke) { | 72 for (const auto& callback : m_callbacksToInvoke) { |
| 69 if (!callback->m_cancelled) { | 73 if (!callback->m_cancelled) { |
| 70 TRACE_EVENT1( | 74 TRACE_EVENT1( |
| 71 "devtools.timeline", "FireAnimationFrame", "data", | 75 "devtools.timeline", "FireAnimationFrame", "data", |
| 72 InspectorAnimationFrameEvent::data(m_context, callback->m_id)); | 76 InspectorAnimationFrameEvent::data(m_context, callback->m_id)); |
| 73 InspectorInstrumentation::AsyncTask asyncTask( | 77 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( |
| 74 m_context, callback, "requestAnimationFrame.callback"); | 78 m_context, "DOMWindow.requestAnimationFrame.callback", false); |
| 79 InspectorInstrumentation::AsyncTask asyncTask(m_context, callback); |
| 75 PerformanceMonitor::HandlerCall handlerCall( | 80 PerformanceMonitor::HandlerCall handlerCall( |
| 76 m_context, "requestAnimationFrame", true); | 81 m_context, "requestAnimationFrame", true); |
| 77 if (callback->m_useLegacyTimeBase) | 82 if (callback->m_useLegacyTimeBase) |
| 78 callback->handleEvent(highResNowMsLegacy); | 83 callback->handleEvent(highResNowMsLegacy); |
| 79 else | 84 else |
| 80 callback->handleEvent(highResNowMs); | 85 callback->handleEvent(highResNowMs); |
| 81 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), | 86 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| 82 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", | 87 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", |
| 83 InspectorUpdateCountersEvent::data()); | 88 InspectorUpdateCountersEvent::data()); |
| 84 } | 89 } |
| 85 } | 90 } |
| 86 | 91 |
| 87 m_callbacksToInvoke.clear(); | 92 m_callbacksToInvoke.clear(); |
| 88 } | 93 } |
| 89 | 94 |
| 90 DEFINE_TRACE(FrameRequestCallbackCollection) { | 95 DEFINE_TRACE(FrameRequestCallbackCollection) { |
| 91 visitor->trace(m_callbacks); | 96 visitor->trace(m_callbacks); |
| 92 visitor->trace(m_callbacksToInvoke); | 97 visitor->trace(m_callbacksToInvoke); |
| 93 visitor->trace(m_context); | 98 visitor->trace(m_context); |
| 94 } | 99 } |
| 95 | 100 |
| 96 } // namespace blink | 101 } // namespace blink |
| OLD | NEW |