| 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 "web/CompositorProxyClientImpl.h" | 5 #include "web/CompositorProxyClientImpl.h" |
| 6 | 6 |
| 7 #include "core/dom/CompositorProxy.h" | 7 #include "core/dom/CompositorProxy.h" |
| 8 #include "modules/compositorworker/CompositorWorkerGlobalScope.h" | 8 #include "modules/compositorworker/CompositorWorkerGlobalScope.h" |
| 9 #include "platform/TraceEvent.h" | 9 #include "platform/TraceEvent.h" |
| 10 #include "platform/graphics/CompositorMutableStateProvider.h" |
| 10 #include "web/CompositorMutatorImpl.h" | 11 #include "web/CompositorMutatorImpl.h" |
| 11 #include "wtf/CurrentTime.h" | 12 #include "wtf/CurrentTime.h" |
| 12 | 13 |
| 13 namespace blink { | 14 namespace blink { |
| 14 | 15 |
| 16 // A helper class that updates proxies mutable state on creation and reset it |
| 17 // on destruction. This can be used with rAF callback to ensure no mutation is |
| 18 // allowed outside rAF. |
| 19 class ScopedCompositorMutableState final { |
| 20 WTF_MAKE_NONCOPYABLE(ScopedCompositorMutableState); |
| 21 STACK_ALLOCATED(); |
| 22 public: |
| 23 ScopedCompositorMutableState(HeapHashSet<WeakMember<CompositorProxy>>& proxi
es, CompositorMutableStateProvider* stateProvider) |
| 24 : m_proxies(proxies) |
| 25 { |
| 26 for (CompositorProxy* proxy : m_proxies) |
| 27 proxy->takeCompositorMutableState(stateProvider->getMutableStateFor(
proxy->elementId())); |
| 28 |
| 29 } |
| 30 ~ScopedCompositorMutableState() |
| 31 { |
| 32 for (CompositorProxy* proxy : m_proxies) |
| 33 proxy->takeCompositorMutableState(nullptr); |
| 34 } |
| 35 private: |
| 36 HeapHashSet<WeakMember<CompositorProxy>>& m_proxies; |
| 37 }; |
| 38 |
| 15 CompositorProxyClientImpl::CompositorProxyClientImpl(CompositorMutatorImpl* muta
tor) | 39 CompositorProxyClientImpl::CompositorProxyClientImpl(CompositorMutatorImpl* muta
tor) |
| 16 : m_mutator(mutator) | 40 : m_mutator(mutator) |
| 17 , m_globalScope(nullptr) | 41 , m_globalScope(nullptr) |
| 18 { | 42 { |
| 19 } | 43 } |
| 20 | 44 |
| 21 DEFINE_TRACE(CompositorProxyClientImpl) | 45 DEFINE_TRACE(CompositorProxyClientImpl) |
| 22 { | 46 { |
| 23 CompositorProxyClient::trace(visitor); | 47 CompositorProxyClient::trace(visitor); |
| 24 visitor->trace(m_mutator); | 48 visitor->trace(m_mutator); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 35 m_mutator->registerProxyClient(this); | 59 m_mutator->registerProxyClient(this); |
| 36 } | 60 } |
| 37 | 61 |
| 38 void CompositorProxyClientImpl::requestAnimationFrame() | 62 void CompositorProxyClientImpl::requestAnimationFrame() |
| 39 { | 63 { |
| 40 TRACE_EVENT0("compositor-worker", "CompositorProxyClientImpl::requestAnimati
onFrame"); | 64 TRACE_EVENT0("compositor-worker", "CompositorProxyClientImpl::requestAnimati
onFrame"); |
| 41 m_requestedAnimationFrameCallbacks = true; | 65 m_requestedAnimationFrameCallbacks = true; |
| 42 m_mutator->setNeedsMutate(); | 66 m_mutator->setNeedsMutate(); |
| 43 } | 67 } |
| 44 | 68 |
| 45 bool CompositorProxyClientImpl::mutate(double monotonicTimeNow) | 69 bool CompositorProxyClientImpl::mutate(double monotonicTimeNow, CompositorMutabl
eStateProvider* stateProvider) |
| 46 { | 70 { |
| 47 if (!m_globalScope) | 71 if (!m_globalScope) |
| 48 return false; | 72 return false; |
| 49 | 73 |
| 50 TRACE_EVENT0("compositor-worker", "CompositorProxyClientImpl::mutate"); | 74 TRACE_EVENT0("compositor-worker", "CompositorProxyClientImpl::mutate"); |
| 51 if (!m_requestedAnimationFrameCallbacks) | 75 if (!m_requestedAnimationFrameCallbacks) |
| 52 return false; | 76 return false; |
| 53 | 77 |
| 54 m_requestedAnimationFrameCallbacks = executeAnimationFrameCallbacks(monotoni
cTimeNow); | 78 { |
| 79 ScopedCompositorMutableState mutableState(m_proxies, stateProvider); |
| 80 m_requestedAnimationFrameCallbacks = executeAnimationFrameCallbacks(mono
tonicTimeNow); |
| 81 } |
| 55 | 82 |
| 56 return m_requestedAnimationFrameCallbacks; | 83 return m_requestedAnimationFrameCallbacks; |
| 57 } | 84 } |
| 58 | 85 |
| 59 bool CompositorProxyClientImpl::executeAnimationFrameCallbacks(double monotonicT
imeNow) | 86 bool CompositorProxyClientImpl::executeAnimationFrameCallbacks(double monotonicT
imeNow) |
| 60 { | 87 { |
| 61 TRACE_EVENT0("compositor-worker", "CompositorProxyClientImpl::executeAnimati
onFrameCallbacks"); | 88 TRACE_EVENT0("compositor-worker", "CompositorProxyClientImpl::executeAnimati
onFrameCallbacks"); |
| 89 |
| 62 // Convert to zero based document time in milliseconds consistent with reque
stAnimationFrame. | 90 // Convert to zero based document time in milliseconds consistent with reque
stAnimationFrame. |
| 63 double highResTimeMs = 1000.0 * (monotonicTimeNow - m_globalScope->timeOrigi
n()); | 91 double highResTimeMs = 1000.0 * (monotonicTimeNow - m_globalScope->timeOrigi
n()); |
| 64 const bool shouldReinvoke = m_globalScope->executeAnimationFrameCallbacks(hi
ghResTimeMs); | 92 return m_globalScope->executeAnimationFrameCallbacks(highResTimeMs); |
| 65 return shouldReinvoke; | |
| 66 } | 93 } |
| 67 | 94 |
| 68 void CompositorProxyClientImpl::registerCompositorProxy(CompositorProxy* proxy) | 95 void CompositorProxyClientImpl::registerCompositorProxy(CompositorProxy* proxy) |
| 69 { | 96 { |
| 70 m_proxies.add(proxy); | 97 m_proxies.add(proxy); |
| 71 } | 98 } |
| 72 | 99 |
| 73 void CompositorProxyClientImpl::unregisterCompositorProxy(CompositorProxy* proxy
) | 100 void CompositorProxyClientImpl::unregisterCompositorProxy(CompositorProxy* proxy
) |
| 74 { | 101 { |
| 75 m_proxies.remove(proxy); | 102 m_proxies.remove(proxy); |
| 76 } | 103 } |
| 77 | 104 |
| 78 } // namespace blink | 105 } // namespace blink |
| OLD | NEW |