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 "modules/compositorworker/CompositorWorkerThread.h" | 5 #include "modules/compositorworker/CompositorWorkerScript.h" |
6 | 6 |
7 #include "bindings/core/v8/V8GCController.h" | 7 #include "bindings/core/v8/V8GCController.h" |
8 #include "bindings/core/v8/V8Initializer.h" | 8 #include "bindings/core/v8/V8Initializer.h" |
9 #include "core/workers/WorkerObjectProxy.h" | 9 #include "core/workers/WorkerObjectProxy.h" |
10 #include "core/workers/WorkerThreadStartupData.h" | 10 #include "core/workers/WorkerScriptStartupData.h" |
11 #include "modules/compositorworker/CompositorWorkerGlobalScope.h" | 11 #include "modules/compositorworker/CompositorWorkerGlobalScope.h" |
12 #include "platform/ThreadSafeFunctional.h" | 12 #include "platform/ThreadSafeFunctional.h" |
13 #include "platform/TraceEvent.h" | 13 #include "platform/TraceEvent.h" |
14 #include "public/platform/Platform.h" | 14 #include "public/platform/Platform.h" |
15 | 15 |
16 namespace blink { | 16 namespace blink { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 void destroyThread(WebThreadSupportingGC* thread) | 20 void destroyThread(WebThreadSupportingGC* thread) |
21 { | 21 { |
22 ASSERT(isMainThread()); | 22 ASSERT(isMainThread()); |
23 // The destructor for |thread| will block until all tasks have completed. | 23 // The destructor for |thread| will block until all tasks have completed. |
24 // This guarantees that shutdown will finish before the thread is destroyed. | 24 // This guarantees that shutdown will finish before the thread is destroyed. |
25 delete thread; | 25 delete thread; |
26 } | 26 } |
27 | 27 |
28 class CompositorWorkerSharedState { | 28 class CompositorWorkerSharedState { |
29 public: | 29 public: |
30 static CompositorWorkerSharedState& instance() | 30 static CompositorWorkerSharedState& instance() |
31 { | 31 { |
32 DEFINE_THREAD_SAFE_STATIC_LOCAL(CompositorWorkerSharedState, compositorW
orkerSharedState, (new CompositorWorkerSharedState())); | 32 DEFINE_THREAD_SAFE_STATIC_LOCAL(CompositorWorkerSharedState, compositorW
orkerSharedState, (new CompositorWorkerSharedState())); |
33 return compositorWorkerSharedState; | 33 return compositorWorkerSharedState; |
34 } | 34 } |
35 | 35 |
36 WebThreadSupportingGC* compositorWorkerThread() | 36 WebThreadSupportingGC* compositorWorkerScript() |
37 { | 37 { |
38 MutexLocker lock(m_mutex); | 38 MutexLocker lock(m_mutex); |
39 if (!m_thread && isMainThread()) { | 39 if (!m_thread && isMainThread()) { |
40 ASSERT(!m_workerCount); | 40 ASSERT(!m_workerCount); |
41 WebThread* platformThread = Platform::current()->compositorThread(); | 41 WebThread* platformThread = Platform::current()->compositorThread(); |
42 m_thread = WebThreadSupportingGC::createForThread(platformThread); | 42 m_thread = WebThreadSupportingGC::createForThread(platformThread); |
43 } | 43 } |
44 return m_thread.get(); | 44 return m_thread.get(); |
45 } | 45 } |
46 | 46 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 ~CompositorWorkerSharedState() {} | 130 ~CompositorWorkerSharedState() {} |
131 | 131 |
132 Mutex m_mutex; | 132 Mutex m_mutex; |
133 OwnPtr<WebThreadSupportingGC> m_thread; | 133 OwnPtr<WebThreadSupportingGC> m_thread; |
134 int m_workerCount = 0; | 134 int m_workerCount = 0; |
135 v8::Isolate* m_isolate = nullptr; | 135 v8::Isolate* m_isolate = nullptr; |
136 }; | 136 }; |
137 | 137 |
138 } // namespace | 138 } // namespace |
139 | 139 |
140 PassRefPtr<CompositorWorkerThread> CompositorWorkerThread::create(PassRefPtr<Wor
kerLoaderProxy> workerLoaderProxy, WorkerObjectProxy& workerObjectProxy, double
timeOrigin) | 140 PassRefPtr<CompositorWorkerScript> CompositorWorkerScript::create(PassRefPtr<Wor
kerLoaderProxy> workerLoaderProxy, WorkerObjectProxy& workerObjectProxy, double
timeOrigin) |
141 { | 141 { |
142 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erThread::create"); | 142 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erScript::create"); |
143 ASSERT(isMainThread()); | 143 ASSERT(isMainThread()); |
144 return adoptRef(new CompositorWorkerThread(workerLoaderProxy, workerObjectPr
oxy, timeOrigin)); | 144 return adoptRef(new CompositorWorkerScript(workerLoaderProxy, workerObjectPr
oxy, timeOrigin)); |
145 } | 145 } |
146 | 146 |
147 CompositorWorkerThread::CompositorWorkerThread(PassRefPtr<WorkerLoaderProxy> wor
kerLoaderProxy, WorkerObjectProxy& workerObjectProxy, double timeOrigin) | 147 CompositorWorkerScript::CompositorWorkerScript(PassRefPtr<WorkerLoaderProxy> wor
kerLoaderProxy, WorkerObjectProxy& workerObjectProxy, double timeOrigin) |
148 : WorkerThread(workerLoaderProxy, workerObjectProxy) | 148 : WorkerScript(workerLoaderProxy, workerObjectProxy) |
149 , m_workerObjectProxy(workerObjectProxy) | 149 , m_workerObjectProxy(workerObjectProxy) |
150 , m_timeOrigin(timeOrigin) | 150 , m_timeOrigin(timeOrigin) |
151 { | 151 { |
152 } | 152 } |
153 | 153 |
154 CompositorWorkerThread::~CompositorWorkerThread() | 154 CompositorWorkerScript::~CompositorWorkerScript() |
155 { | 155 { |
156 } | 156 } |
157 | 157 |
158 WebThreadSupportingGC* CompositorWorkerThread::sharedBackingThread() | 158 WebThreadSupportingGC* CompositorWorkerScript::sharedBackingThread() |
159 { | 159 { |
160 return CompositorWorkerSharedState::instance().compositorWorkerThread(); | 160 return CompositorWorkerSharedState::instance().compositorWorkerScript(); |
161 } | 161 } |
162 | 162 |
163 PassRefPtrWillBeRawPtr<WorkerGlobalScope> CompositorWorkerThread::createWorkerGl
obalScope(PassOwnPtr<WorkerThreadStartupData> startupData) | 163 PassRefPtrWillBeRawPtr<WorkerGlobalScope> CompositorWorkerScript::createWorkerGl
obalScope(PassOwnPtr<WorkerScriptStartupData> startupData) |
164 { | 164 { |
165 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erThread::createWorkerGlobalScope"); | 165 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erScript::createWorkerGlobalScope"); |
166 return CompositorWorkerGlobalScope::create(this, startupData, m_timeOrigin); | 166 return CompositorWorkerGlobalScope::create(this, startupData, m_timeOrigin); |
167 } | 167 } |
168 | 168 |
169 WebThreadSupportingGC& CompositorWorkerThread::backingThread() | 169 WebThreadSupportingGC& CompositorWorkerScript::backingThread() |
170 { | 170 { |
171 return *CompositorWorkerSharedState::instance().compositorWorkerThread(); | 171 return *CompositorWorkerSharedState::instance().compositorWorkerScript(); |
172 } | 172 } |
173 | 173 |
174 void CompositorWorkerThread::initializeBackingThread() | 174 void CompositorWorkerScript::initializeBackingThread() |
175 { | 175 { |
176 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erThread::initializeBackingThread"); | 176 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erScript::initializeBackingThread"); |
177 CompositorWorkerSharedState::instance().initializeBackingThread(); | 177 CompositorWorkerSharedState::instance().initializeBackingThread(); |
178 } | 178 } |
179 | 179 |
180 void CompositorWorkerThread::shutdownBackingThread() | 180 void CompositorWorkerScript::shutdownBackingThread() |
181 { | 181 { |
182 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erThread::shutdownBackingThread"); | 182 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erScript::shutdownBackingThread"); |
183 CompositorWorkerSharedState::instance().shutdownBackingThread(); | 183 CompositorWorkerSharedState::instance().shutdownBackingThread(); |
184 } | 184 } |
185 | 185 |
186 v8::Isolate* CompositorWorkerThread::initializeIsolate() | 186 v8::Isolate* CompositorWorkerScript::initializeIsolate() |
187 { | 187 { |
188 return CompositorWorkerSharedState::instance().initializeIsolate(); | 188 return CompositorWorkerSharedState::instance().initializeIsolate(); |
189 } | 189 } |
190 | 190 |
191 void CompositorWorkerThread::willDestroyIsolate() | 191 void CompositorWorkerScript::willDestroyIsolate() |
192 { | 192 { |
193 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erThread::willDestroyIsolate"); | 193 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erScript::willDestroyIsolate"); |
194 CompositorWorkerSharedState::instance().willDestroyIsolate(); | 194 CompositorWorkerSharedState::instance().willDestroyIsolate(); |
195 } | 195 } |
196 | 196 |
197 void CompositorWorkerThread::destroyIsolate() | 197 void CompositorWorkerScript::destroyIsolate() |
198 { | 198 { |
199 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erThread::destroyIsolate"); | 199 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erScript::destroyIsolate"); |
200 CompositorWorkerSharedState::instance().destroyIsolate(); | 200 CompositorWorkerSharedState::instance().destroyIsolate(); |
201 } | 201 } |
202 | 202 |
203 void CompositorWorkerThread::terminateV8Execution() | 203 void CompositorWorkerScript::terminateV8Execution() |
204 { | 204 { |
205 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erThread::terminateV8Execution"); | 205 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erScript::terminateV8Execution"); |
206 CompositorWorkerSharedState::instance().terminateV8Execution(); | 206 CompositorWorkerSharedState::instance().terminateV8Execution(); |
207 } | 207 } |
208 | 208 |
209 bool CompositorWorkerThread::hasThreadForTest() | 209 bool CompositorWorkerScript::hasThreadForTest() |
210 { | 210 { |
211 return CompositorWorkerSharedState::instance().hasThreadForTest(); | 211 return CompositorWorkerSharedState::instance().hasThreadForTest(); |
212 } | 212 } |
213 | 213 |
214 bool CompositorWorkerThread::hasIsolateForTest() | 214 bool CompositorWorkerScript::hasIsolateForTest() |
215 { | 215 { |
216 return CompositorWorkerSharedState::instance().hasIsolateForTest(); | 216 return CompositorWorkerSharedState::instance().hasIsolateForTest(); |
217 } | 217 } |
218 | 218 |
219 } // namespace blink | 219 } // namespace blink |
OLD | NEW |