OLD | NEW |
(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 "web/CompositorProxyClientImpl.h" |
| 6 |
| 7 #include "core/dom/CompositorProxy.h" |
| 8 #include "modules/compositorworker/CompositorWorkerGlobalScope.h" |
| 9 #include "platform/TraceEvent.h" |
| 10 #include "public/platform/WebCompositorMutableState.h" |
| 11 #include "public/platform/WebCompositorMutableStateProvider.h" |
| 12 #include "web/WebMutatorImpl.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 CompositorProxyClientImpl::CompositorProxyClientImpl(WebMutatorImpl* proxy) |
| 17 : m_mutator(proxy) |
| 18 , m_globalScope(nullptr) |
| 19 , m_executingAnimationFrameCallbacks(false) |
| 20 { |
| 21 } |
| 22 |
| 23 CompositorProxyClientImpl::~CompositorProxyClientImpl() |
| 24 { |
| 25 m_mutator->unregisterClient(this); |
| 26 for (auto& iter : m_proxies) { |
| 27 for (CompositorProxy* proxy : iter.second) |
| 28 proxy->clearClient(); |
| 29 } |
| 30 } |
| 31 |
| 32 void CompositorProxyClientImpl::registerCompositorProxy(CompositorProxy* proxy) |
| 33 { |
| 34 uint64_t elementId = proxy->elementId(); |
| 35 |
| 36 TRACE_EVENT2("compositor-worker,compositor-proxy", |
| 37 "CompositorProxyClientImpl::registerCompositorProxy", |
| 38 "elementId", static_cast<int>(elementId), |
| 39 "proxy", proxy); |
| 40 |
| 41 if (!m_proxies.count(elementId)) { |
| 42 m_proxies[elementId] = ProxyVector(); |
| 43 } |
| 44 m_proxies[elementId].push_back(proxy); |
| 45 } |
| 46 |
| 47 void CompositorProxyClientImpl::unregisterCompositorProxy(CompositorProxy* proxy
) |
| 48 { |
| 49 uint64_t elementId = proxy->elementId(); |
| 50 if (!m_proxies.count(elementId)) |
| 51 return; |
| 52 |
| 53 TRACE_EVENT2("compositor-worker,compositor-proxy", |
| 54 "CompositorProxyClientImpl::unregisterCompositorProxy", |
| 55 "elementId", static_cast<int>(elementId), |
| 56 "proxy", proxy); |
| 57 |
| 58 ProxyVector& proxies = m_proxies[elementId]; |
| 59 proxies.erase(std::find(proxies.begin(), proxies.end(), proxy)); |
| 60 if (proxies.size() == 0) |
| 61 m_proxies.erase(elementId); |
| 62 } |
| 63 |
| 64 void CompositorProxyClientImpl::requestSync(CompositorProxy* proxy) |
| 65 { |
| 66 TRACE_EVENT0("compositor-worker", "CompositorProxyClientImpl::requestSync"); |
| 67 ASSERT(m_executingAnimationFrameCallbacks); |
| 68 m_requiresSync.add(proxy->elementId()); |
| 69 } |
| 70 |
| 71 void CompositorProxyClientImpl::setGlobalScope(WorkerGlobalScope* scope) |
| 72 { |
| 73 TRACE_EVENT0("compositor-worker", "CompositorProxyClientImpl::setGlobalScope
"); |
| 74 m_globalScope = static_cast<CompositorWorkerGlobalScope*>(scope); |
| 75 m_mutator->registerClient(this); |
| 76 } |
| 77 |
| 78 void CompositorProxyClientImpl::requestMutation() |
| 79 { |
| 80 TRACE_EVENT0("compositor-worker", "CompositorProxyClientImpl::requestMutatio
n"); |
| 81 m_requestedAnimationFrameCallbacks = true; |
| 82 m_mutator->setNeedsMutate(); |
| 83 } |
| 84 |
| 85 bool CompositorProxyClientImpl::mutate(double timeNow, WebCompositorMutableState
Provider* stateProvider) |
| 86 { |
| 87 if (!m_globalScope) |
| 88 return false; |
| 89 |
| 90 TRACE_EVENT0("compositor-worker", "CompositorProxyClientImpl::getMutations")
; |
| 91 willStartCompositorFrameCallbacks(stateProvider); |
| 92 |
| 93 if (!m_requestedAnimationFrameCallbacks) |
| 94 return false; |
| 95 |
| 96 m_requestedAnimationFrameCallbacks = false; |
| 97 { |
| 98 TemporaryChange<bool> temporary(m_executingAnimationFrameCallbacks, true
); |
| 99 m_requestedAnimationFrameCallbacks = executeAnimationFrameCallbacks(time
Now); |
| 100 } |
| 101 |
| 102 return m_requestedAnimationFrameCallbacks; |
| 103 } |
| 104 |
| 105 void CompositorProxyClientImpl::willStartCompositorFrameCallbacks(WebCompositorM
utableStateProvider* stateProvider) |
| 106 { |
| 107 TRACE_EVENT0("compositor-worker", "CompositorProxyClientImpl::willStartCompo
sitorFrameCallbacks"); |
| 108 ASSERT(m_requiresSync.isEmpty()); |
| 109 for (auto iter : m_proxies) { |
| 110 for (CompositorProxy* proxy : iter.second) |
| 111 proxy->takeCompositorMutableState(stateProvider->getCompositorMutabl
eStateFor(iter.first)); |
| 112 } |
| 113 } |
| 114 |
| 115 bool CompositorProxyClientImpl::executeAnimationFrameCallbacks(double time) |
| 116 { |
| 117 TRACE_EVENT0("compositor-worker", "CompositorProxyClientImpl::executeAnimati
onFrameCallbacks"); |
| 118 const bool reinvoke = m_globalScope->executeAnimationFrameCallbacks(time); |
| 119 for (auto iter : m_proxies) { |
| 120 for (CompositorProxy* proxy : iter.second) |
| 121 proxy->takeCompositorMutableState(nullptr); |
| 122 } |
| 123 return reinvoke; |
| 124 } |
| 125 |
| 126 } // namespace blink |
OLD | NEW |