| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/CompositorMutatorImpl.h" | 5 #include "web/CompositorMutatorImpl.h" |
| 6 | 6 |
| 7 #include "core/animation/CustomCompositorAnimationManager.h" | 7 #include "core/animation/CustomCompositorAnimationManager.h" |
| 8 #include "core/dom/CompositorProxy.h" | 8 #include "core/dom/CompositorProxy.h" |
| 9 #include "platform/CrossThreadFunctional.h" | 9 #include "platform/CrossThreadFunctional.h" |
| 10 #include "platform/WaitableEvent.h" | 10 #include "platform/WaitableEvent.h" |
| 11 #include "platform/graphics/CompositorMutationsTarget.h" | 11 #include "platform/graphics/CompositorMutationsTarget.h" |
| 12 #include "platform/graphics/CompositorMutatorClient.h" | 12 #include "platform/graphics/CompositorMutatorClient.h" |
| 13 #include "platform/heap/Handle.h" | 13 #include "platform/heap/Handle.h" |
| 14 #include "platform/instrumentation/tracing/TraceEvent.h" | 14 #include "platform/instrumentation/tracing/TraceEvent.h" |
| 15 #include "public/platform/Platform.h" | 15 #include "public/platform/Platform.h" |
| 16 #include "web/CompositorProxyClientImpl.h" | 16 #include "web/CompositorAnimator.h" |
| 17 #include "wtf/PtrUtil.h" | 17 #include "wtf/PtrUtil.h" |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 void createCompositorMutatorClient( | 23 void createCompositorMutatorClient( |
| 24 std::unique_ptr<CompositorMutatorClient>* ptr, | 24 std::unique_ptr<CompositorMutatorClient>* ptr, |
| 25 WaitableEvent* doneEvent) { | 25 WaitableEvent* doneEvent) { |
| 26 CompositorMutatorImpl* mutator = CompositorMutatorImpl::create(); | 26 CompositorMutatorImpl* mutator = CompositorMutatorImpl::create(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 40 WaitableEvent doneEvent; | 40 WaitableEvent doneEvent; |
| 41 if (WebThread* compositorThread = Platform::current()->compositorThread()) { | 41 if (WebThread* compositorThread = Platform::current()->compositorThread()) { |
| 42 compositorThread->getWebTaskRunner()->postTask( | 42 compositorThread->getWebTaskRunner()->postTask( |
| 43 BLINK_FROM_HERE, crossThreadBind(&createCompositorMutatorClient, | 43 BLINK_FROM_HERE, crossThreadBind(&createCompositorMutatorClient, |
| 44 crossThreadUnretained(&mutatorClient), | 44 crossThreadUnretained(&mutatorClient), |
| 45 crossThreadUnretained(&doneEvent))); | 45 crossThreadUnretained(&doneEvent))); |
| 46 } else { | 46 } else { |
| 47 createCompositorMutatorClient(&mutatorClient, &doneEvent); | 47 createCompositorMutatorClient(&mutatorClient, &doneEvent); |
| 48 } | 48 } |
| 49 // TODO(flackr): Instead of waiting for this event, we may be able to just set | 49 // TODO(flackr): Instead of waiting for this event, we may be able to just set |
| 50 // the mutator on the CompositorProxyClient directly from the compositor | 50 // the mutator on the CompositorWorkerProxyClient directly from the compositor |
| 51 // thread before it gets used there. We still need to make sure we only | 51 // thread before it gets used there. We still need to make sure we only |
| 52 // create one mutator though. | 52 // create one mutator though. |
| 53 doneEvent.wait(); | 53 doneEvent.wait(); |
| 54 return mutatorClient; | 54 return mutatorClient; |
| 55 } | 55 } |
| 56 | 56 |
| 57 CompositorMutatorImpl* CompositorMutatorImpl::create() { | 57 CompositorMutatorImpl* CompositorMutatorImpl::create() { |
| 58 return new CompositorMutatorImpl(); | 58 return new CompositorMutatorImpl(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool CompositorMutatorImpl::mutate( | 61 bool CompositorMutatorImpl::mutate( |
| 62 double monotonicTimeNow, | 62 double monotonicTimeNow, |
| 63 CompositorMutableStateProvider* stateProvider) { | 63 CompositorMutableStateProvider* stateProvider) { |
| 64 TRACE_EVENT0("compositor-worker", "CompositorMutatorImpl::mutate"); | 64 TRACE_EVENT0("compositor-worker", "CompositorMutatorImpl::mutate"); |
| 65 bool needToReinvoke = false; | 65 bool needToReinvoke = false; |
| 66 // TODO(vollick): we should avoid executing the animation frame | 66 // TODO(vollick): we should avoid executing the animation frame |
| 67 // callbacks if none of the proxies in the global scope are affected by | 67 // callbacks if none of the proxies in the global scope are affected by |
| 68 // m_mutations. | 68 // m_mutations. |
| 69 for (CompositorProxyClientImpl* client : m_proxyClients) { | 69 for (CompositorAnimator* animator : m_animators) { |
| 70 if (client->mutate(monotonicTimeNow, stateProvider)) | 70 if (animator->mutate(monotonicTimeNow, stateProvider)) |
| 71 needToReinvoke = true; | 71 needToReinvoke = true; |
| 72 } | 72 } |
| 73 | 73 |
| 74 return needToReinvoke; | 74 return needToReinvoke; |
| 75 } | 75 } |
| 76 | 76 |
| 77 void CompositorMutatorImpl::registerProxyClient( | 77 void CompositorMutatorImpl::registerCompositorAnimator( |
| 78 CompositorProxyClientImpl* client) { | 78 CompositorAnimator* animator) { |
| 79 TRACE_EVENT0("compositor-worker", "CompositorMutatorImpl::registerClient"); | 79 TRACE_EVENT0("compositor-worker", |
| 80 DCHECK(!m_proxyClients.contains(client)); | 80 "CompositorMutatorImpl::registerCompositorAnimator"); |
| 81 m_proxyClients.insert(client); | 81 DCHECK(!m_animators.contains(animator)); |
| 82 m_animators.add(animator); |
| 82 setNeedsMutate(); | 83 setNeedsMutate(); |
| 83 } | 84 } |
| 84 | 85 |
| 85 void CompositorMutatorImpl::unregisterProxyClient( | 86 void CompositorMutatorImpl::unregisterCompositorAnimator( |
| 86 CompositorProxyClientImpl* client) { | 87 CompositorAnimator* animator) { |
| 87 DCHECK(m_proxyClients.contains(client)); | 88 DCHECK(m_animators.contains(animator)); |
| 88 m_proxyClients.remove(client); | 89 m_animators.remove(animator); |
| 89 } | 90 } |
| 90 | 91 |
| 91 void CompositorMutatorImpl::setNeedsMutate() { | 92 void CompositorMutatorImpl::setNeedsMutate() { |
| 92 TRACE_EVENT0("compositor-worker", "CompositorMutatorImpl::setNeedsMutate"); | 93 TRACE_EVENT0("compositor-worker", "CompositorMutatorImpl::setNeedsMutate"); |
| 93 m_client->setNeedsMutate(); | 94 m_client->setNeedsMutate(); |
| 94 } | 95 } |
| 95 | 96 |
| 96 } // namespace blink | 97 } // namespace blink |
| OLD | NEW |