Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: third_party/WebKit/Source/web/CompositorWorkerProxyClientImpl.cpp

Issue 2515363002: Introduce AnimationWorkletProxyClient and necessary plumbing to get it in worklet messaging proxy. (Closed)
Patch Set: Remove unnecessary PLATFORM_EXPORT Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/CompositorWorkerProxyClientImpl.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/graphics/CompositorMutableStateProvider.h" 9 #include "platform/graphics/CompositorMutableStateProvider.h"
10 #include "platform/instrumentation/tracing/TraceEvent.h" 10 #include "platform/instrumentation/tracing/TraceEvent.h"
11 #include "web/CompositorMutatorImpl.h" 11 #include "web/CompositorMutatorImpl.h"
12 #include "wtf/CurrentTime.h" 12 #include "wtf/CurrentTime.h"
13 13
14 namespace blink { 14 namespace blink {
15 15
16 // A helper class that updates proxies mutable state on creation and reset it 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 17 // on destruction. This can be used with rAF callback to ensure no mutation is
18 // allowed outside rAF. 18 // allowed outside rAF.
19 class ScopedCompositorMutableState final { 19 class ScopedCompositorMutableState final {
20 WTF_MAKE_NONCOPYABLE(ScopedCompositorMutableState); 20 WTF_MAKE_NONCOPYABLE(ScopedCompositorMutableState);
21 STACK_ALLOCATED(); 21 STACK_ALLOCATED();
22 22
23 public: 23 public:
24 ScopedCompositorMutableState( 24 ScopedCompositorMutableState(
25 HeapHashSet<WeakMember<CompositorProxy>>& proxies, 25 HeapHashSet<WeakMember<CompositorProxy>>& proxies,
26 CompositorMutableStateProvider* stateProvider) 26 CompositorMutableStateProvider* stateProvider)
27 : m_proxies(proxies) { 27 : m_proxies(proxies) {
28 for (CompositorProxy* proxy : m_proxies) 28 for (CompositorProxy* proxy : m_proxies) {
29 proxy->takeCompositorMutableState( 29 proxy->takeCompositorMutableState(
30 stateProvider->getMutableStateFor(proxy->elementId())); 30 stateProvider->getMutableStateFor(proxy->elementId()));
31 }
31 } 32 }
32 ~ScopedCompositorMutableState() { 33 ~ScopedCompositorMutableState() {
33 for (CompositorProxy* proxy : m_proxies) 34 for (CompositorProxy* proxy : m_proxies)
34 proxy->takeCompositorMutableState(nullptr); 35 proxy->takeCompositorMutableState(nullptr);
35 } 36 }
36 37
37 private: 38 private:
38 HeapHashSet<WeakMember<CompositorProxy>>& m_proxies; 39 HeapHashSet<WeakMember<CompositorProxy>>& m_proxies;
39 }; 40 };
40 41
41 CompositorProxyClientImpl::CompositorProxyClientImpl( 42 CompositorWorkerProxyClientImpl::CompositorWorkerProxyClientImpl(
42 CompositorMutatorImpl* mutator) 43 CompositorMutatorImpl* mutator)
43 : m_mutator(mutator), m_globalScope(nullptr) { 44 : m_mutator(mutator), m_globalScope(nullptr) {
44 DCHECK(isMainThread()); 45 DCHECK(isMainThread());
45 } 46 }
46 47
47 DEFINE_TRACE(CompositorProxyClientImpl) { 48 DEFINE_TRACE(CompositorWorkerProxyClientImpl) {
48 CompositorProxyClient::trace(visitor);
49 visitor->trace(m_proxies); 49 visitor->trace(m_proxies);
50 CompositorAnimator::trace(visitor);
51 CompositorWorkerProxyClient::trace(visitor);
50 } 52 }
51 53
52 void CompositorProxyClientImpl::setGlobalScope(WorkerGlobalScope* scope) { 54 void CompositorWorkerProxyClientImpl::setGlobalScope(WorkerGlobalScope* scope) {
53 TRACE_EVENT0("compositor-worker", 55 TRACE_EVENT0("compositor-worker",
54 "CompositorProxyClientImpl::setGlobalScope"); 56 "CompositorWorkerProxyClientImpl::setGlobalScope");
55 DCHECK(!m_globalScope); 57 DCHECK(!m_globalScope);
56 DCHECK(scope); 58 DCHECK(scope);
57 m_globalScope = static_cast<CompositorWorkerGlobalScope*>(scope); 59 m_globalScope = static_cast<CompositorWorkerGlobalScope*>(scope);
58 m_mutator->registerProxyClient(this); 60 m_mutator->registerCompositorAnimator(this);
59 } 61 }
60 62
61 void CompositorProxyClientImpl::dispose() { 63 void CompositorWorkerProxyClientImpl::dispose() {
62 // CompositorProxyClientImpl and CompositorMutatorImpl form a reference 64 // CompositorWorkerProxyClientImpl and CompositorMutatorImpl form a reference
63 // cycle. CompositorWorkerGlobalScope and CompositorProxyClientImpl 65 // cycle. CompositorWorkerGlobalScope and CompositorWorkerProxyClientImpl
64 // also form another big reference cycle. So dispose needs to be called on 66 // also form another big reference cycle. So dispose needs to be called on
65 // Worker termination to break these cycles. If not, layout test leak 67 // Worker termination to break these cycles. If not, layout test leak
66 // detection will report a WorkerGlobalScope leak. 68 // detection will report a WorkerGlobalScope leak.
67 m_mutator->unregisterProxyClient(this); 69 m_mutator->unregisterCompositorAnimator(this);
68 m_globalScope = nullptr; 70 m_globalScope = nullptr;
69 } 71 }
70 72
71 void CompositorProxyClientImpl::requestAnimationFrame() { 73 void CompositorWorkerProxyClientImpl::requestAnimationFrame() {
72 TRACE_EVENT0("compositor-worker", 74 TRACE_EVENT0("compositor-worker",
73 "CompositorProxyClientImpl::requestAnimationFrame"); 75 "CompositorWorkerProxyClientImpl::requestAnimationFrame");
74 m_requestedAnimationFrameCallbacks = true; 76 m_requestedAnimationFrameCallbacks = true;
75 m_mutator->setNeedsMutate(); 77 m_mutator->setNeedsMutate();
76 } 78 }
77 79
78 bool CompositorProxyClientImpl::mutate( 80 bool CompositorWorkerProxyClientImpl::mutate(
79 double monotonicTimeNow, 81 double monotonicTimeNow,
80 CompositorMutableStateProvider* stateProvider) { 82 CompositorMutableStateProvider* stateProvider) {
81 if (!m_globalScope) 83 if (!m_globalScope)
82 return false; 84 return false;
83 85
84 TRACE_EVENT0("compositor-worker", "CompositorProxyClientImpl::mutate"); 86 TRACE_EVENT0("compositor-worker", "CompositorWorkerProxyClientImpl::mutate");
85 if (!m_requestedAnimationFrameCallbacks) 87 if (!m_requestedAnimationFrameCallbacks)
86 return false; 88 return false;
87 89
88 { 90 {
89 ScopedCompositorMutableState mutableState(m_proxies, stateProvider); 91 ScopedCompositorMutableState mutableState(m_proxies, stateProvider);
90 m_requestedAnimationFrameCallbacks = 92 m_requestedAnimationFrameCallbacks =
91 executeAnimationFrameCallbacks(monotonicTimeNow); 93 executeAnimationFrameCallbacks(monotonicTimeNow);
92 } 94 }
93 95
94 return m_requestedAnimationFrameCallbacks; 96 return m_requestedAnimationFrameCallbacks;
95 } 97 }
96 98
97 bool CompositorProxyClientImpl::executeAnimationFrameCallbacks( 99 bool CompositorWorkerProxyClientImpl::executeAnimationFrameCallbacks(
98 double monotonicTimeNow) { 100 double monotonicTimeNow) {
99 TRACE_EVENT0("compositor-worker", 101 TRACE_EVENT0(
100 "CompositorProxyClientImpl::executeAnimationFrameCallbacks"); 102 "compositor-worker",
103 "CompositorWorkerProxyClientImpl::executeAnimationFrameCallbacks");
101 104
102 DCHECK(m_globalScope); 105 DCHECK(m_globalScope);
103 // Convert to zero based document time in milliseconds consistent with 106 // Convert to zero based document time in milliseconds consistent with
104 // requestAnimationFrame. 107 // requestAnimationFrame.
105 double highResTimeMs = 108 double highResTimeMs =
106 1000.0 * (monotonicTimeNow - m_globalScope->timeOrigin()); 109 1000.0 * (monotonicTimeNow - m_globalScope->timeOrigin());
107 return m_globalScope->executeAnimationFrameCallbacks(highResTimeMs); 110 return m_globalScope->executeAnimationFrameCallbacks(highResTimeMs);
108 } 111 }
109 112
110 void CompositorProxyClientImpl::registerCompositorProxy( 113 void CompositorWorkerProxyClientImpl::registerCompositorProxy(
111 CompositorProxy* proxy) { 114 CompositorProxy* proxy) {
112 m_proxies.insert(proxy); 115 m_proxies.insert(proxy);
113 } 116 }
114 117
115 void CompositorProxyClientImpl::unregisterCompositorProxy( 118 void CompositorWorkerProxyClientImpl::unregisterCompositorProxy(
116 CompositorProxy* proxy) { 119 CompositorProxy* proxy) {
117 m_proxies.remove(proxy); 120 m_proxies.remove(proxy);
118 } 121 }
119 122
120 } // namespace blink 123 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/CompositorWorkerProxyClientImpl.h ('k') | third_party/WebKit/Source/web/WebFrameWidgetBase.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698