| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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::asyncTaskScheduled( | 29 InspectorInstrumentation::asyncTaskScheduled( |
| 30 m_context, "requestAnimationFrame", callback); | 30 m_context, "requestAnimationFrame", callback); |
| 31 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( | 31 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( |
| 32 m_context, "requestAnimationFrame", true); | 32 m_context, "DOMWindow.requestAnimationFrame", true); |
| 33 return id; | 33 return id; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void FrameRequestCallbackCollection::cancelCallback(CallbackId id) { | 36 void FrameRequestCallbackCollection::cancelCallback(CallbackId id) { |
| 37 for (size_t i = 0; i < m_callbacks.size(); ++i) { | 37 for (size_t i = 0; i < m_callbacks.size(); ++i) { |
| 38 if (m_callbacks[i]->m_id == id) { | 38 if (m_callbacks[i]->m_id == id) { |
| 39 InspectorInstrumentation::asyncTaskCanceled(m_context, m_callbacks[i]); | 39 InspectorInstrumentation::asyncTaskCanceled(m_context, m_callbacks[i]); |
| 40 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( | 40 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( |
| 41 m_context, "cancelAnimationFrame", true); | 41 m_context, "DOMWindow.cancelAnimationFrame", true); |
| 42 m_callbacks.remove(i); | 42 m_callbacks.remove(i); |
| 43 TRACE_EVENT_INSTANT1("devtools.timeline", "CancelAnimationFrame", | 43 TRACE_EVENT_INSTANT1("devtools.timeline", "CancelAnimationFrame", |
| 44 TRACE_EVENT_SCOPE_THREAD, "data", | 44 TRACE_EVENT_SCOPE_THREAD, "data", |
| 45 InspectorAnimationFrameEvent::data(m_context, id)); | 45 InspectorAnimationFrameEvent::data(m_context, id)); |
| 46 return; | 46 return; |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 for (const auto& callback : m_callbacksToInvoke) { | 49 for (const auto& callback : m_callbacksToInvoke) { |
| 50 if (callback->m_id == id) { | 50 if (callback->m_id == id) { |
| 51 InspectorInstrumentation::asyncTaskCanceled(m_context, callback); | 51 InspectorInstrumentation::asyncTaskCanceled(m_context, callback); |
| 52 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( | 52 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( |
| 53 m_context, "cancelAnimationFrame", true); | 53 m_context, "DOMWindow.cancelAnimationFrame", true); |
| 54 TRACE_EVENT_INSTANT1("devtools.timeline", "CancelAnimationFrame", | 54 TRACE_EVENT_INSTANT1("devtools.timeline", "CancelAnimationFrame", |
| 55 TRACE_EVENT_SCOPE_THREAD, "data", | 55 TRACE_EVENT_SCOPE_THREAD, "data", |
| 56 InspectorAnimationFrameEvent::data(m_context, id)); | 56 InspectorAnimationFrameEvent::data(m_context, id)); |
| 57 callback->m_cancelled = true; | 57 callback->m_cancelled = true; |
| 58 // will be removed at the end of executeCallbacks() | 58 // will be removed at the end of executeCallbacks() |
| 59 return; | 59 return; |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 | 63 |
| 64 void FrameRequestCallbackCollection::executeCallbacks( | 64 void FrameRequestCallbackCollection::executeCallbacks( |
| 65 double highResNowMs, | 65 double highResNowMs, |
| 66 double highResNowMsLegacy) { | 66 double highResNowMsLegacy) { |
| 67 // First, generate a list of callbacks to consider. Callbacks registered from | 67 // First, generate a list of callbacks to consider. Callbacks registered from |
| 68 // 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. |
| 69 DCHECK(m_callbacksToInvoke.isEmpty()); | 69 DCHECK(m_callbacksToInvoke.isEmpty()); |
| 70 m_callbacksToInvoke.swap(m_callbacks); | 70 m_callbacksToInvoke.swap(m_callbacks); |
| 71 | 71 |
| 72 for (const auto& callback : m_callbacksToInvoke) { | 72 for (const auto& callback : m_callbacksToInvoke) { |
| 73 if (!callback->m_cancelled) { | 73 if (!callback->m_cancelled) { |
| 74 TRACE_EVENT1( | 74 TRACE_EVENT1( |
| 75 "devtools.timeline", "FireAnimationFrame", "data", | 75 "devtools.timeline", "FireAnimationFrame", "data", |
| 76 InspectorAnimationFrameEvent::data(m_context, callback->m_id)); | 76 InspectorAnimationFrameEvent::data(m_context, callback->m_id)); |
| 77 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( | 77 InspectorInstrumentation::NativeBreakpoint nativeBreakpoint( |
| 78 m_context, "animationFrameFired", false); | 78 m_context, "DOMWindow.requestAnimationFrame.callback", false); |
| 79 InspectorInstrumentation::AsyncTask asyncTask(m_context, callback); | 79 InspectorInstrumentation::AsyncTask asyncTask(m_context, callback); |
| 80 PerformanceMonitor::HandlerCall handlerCall( | 80 PerformanceMonitor::HandlerCall handlerCall( |
| 81 m_context, "requestAnimationFrame", true); | 81 m_context, "requestAnimationFrame", true); |
| 82 if (callback->m_useLegacyTimeBase) | 82 if (callback->m_useLegacyTimeBase) |
| 83 callback->handleEvent(highResNowMsLegacy); | 83 callback->handleEvent(highResNowMsLegacy); |
| 84 else | 84 else |
| 85 callback->handleEvent(highResNowMs); | 85 callback->handleEvent(highResNowMs); |
| 86 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), | 86 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), |
| 87 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", | 87 "UpdateCounters", TRACE_EVENT_SCOPE_THREAD, "data", |
| 88 InspectorUpdateCountersEvent::data()); | 88 InspectorUpdateCountersEvent::data()); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 | 91 |
| 92 m_callbacksToInvoke.clear(); | 92 m_callbacksToInvoke.clear(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 DEFINE_TRACE(FrameRequestCallbackCollection) { | 95 DEFINE_TRACE(FrameRequestCallbackCollection) { |
| 96 visitor->trace(m_callbacks); | 96 visitor->trace(m_callbacks); |
| 97 visitor->trace(m_callbacksToInvoke); | 97 visitor->trace(m_callbacksToInvoke); |
| 98 visitor->trace(m_context); | 98 visitor->trace(m_context); |
| 99 } | 99 } |
| 100 | 100 |
| 101 } // namespace blink | 101 } // namespace blink |
| OLD | NEW |