| 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/CompositorWorkerThread.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/InProcessWorkerObjectProxy.h" | 9 #include "core/workers/InProcessWorkerObjectProxy.h" |
| 10 #include "core/workers/WorkerBackingThread.h" | 10 #include "core/workers/WorkerBackingThread.h" |
| 11 #include "core/workers/WorkerThreadStartupData.h" | 11 #include "core/workers/WorkerThreadStartupData.h" |
| 12 #include "modules/compositorworker/CompositorWorkerGlobalScope.h" | 12 #include "modules/compositorworker/CompositorWorkerGlobalScope.h" |
| 13 #include "platform/ThreadSafeFunctional.h" | 13 #include "platform/ThreadSafeFunctional.h" |
| 14 #include "platform/TraceEvent.h" | 14 #include "platform/TraceEvent.h" |
| 15 #include "platform/WaitableEvent.h" | 15 #include "platform/WaitableEvent.h" |
| 16 #include "platform/WebThreadSupportingGC.h" | 16 #include "platform/WebThreadSupportingGC.h" |
| 17 #include "public/platform/Platform.h" | 17 #include "public/platform/Platform.h" |
| 18 #include "wtf/PtrUtil.h" |
| 19 #include <memory> |
| 18 | 20 |
| 19 namespace blink { | 21 namespace blink { |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 // This is a singleton class holding the compositor worker thread in this | 25 // This is a singleton class holding the compositor worker thread in this |
| 24 // renderer process. BackingThreadHolder::m_thread is cleared by | 26 // renderer process. BackingThreadHolder::m_thread is cleared by |
| 25 // ModulesInitializer::shutdown. | 27 // ModulesInitializer::shutdown. |
| 26 // See WorkerThread::terminateAndWaitForAllWorkers for the process shutdown | 28 // See WorkerThread::terminateAndWaitForAllWorkers for the process shutdown |
| 27 // case. | 29 // case. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 static void createForTest() | 64 static void createForTest() |
| 63 { | 65 { |
| 64 MutexLocker locker(holderInstanceMutex()); | 66 MutexLocker locker(holderInstanceMutex()); |
| 65 DCHECK_EQ(nullptr, s_instance); | 67 DCHECK_EQ(nullptr, s_instance); |
| 66 s_instance = new BackingThreadHolder(WorkerBackingThread::createForTest(
Platform::current()->compositorThread())); | 68 s_instance = new BackingThreadHolder(WorkerBackingThread::createForTest(
Platform::current()->compositorThread())); |
| 67 } | 69 } |
| 68 | 70 |
| 69 WorkerBackingThread* thread() { return m_thread.get(); } | 71 WorkerBackingThread* thread() { return m_thread.get(); } |
| 70 | 72 |
| 71 private: | 73 private: |
| 72 BackingThreadHolder(PassOwnPtr<WorkerBackingThread> useBackingThread = nullp
tr) | 74 BackingThreadHolder(std::unique_ptr<WorkerBackingThread> useBackingThread =
nullptr) |
| 73 : m_thread(useBackingThread ? std::move(useBackingThread) : WorkerBackin
gThread::create(Platform::current()->compositorThread())) | 75 : m_thread(useBackingThread ? std::move(useBackingThread) : WorkerBackin
gThread::create(Platform::current()->compositorThread())) |
| 74 { | 76 { |
| 75 DCHECK(isMainThread()); | 77 DCHECK(isMainThread()); |
| 76 m_thread->backingThread().postTask(BLINK_FROM_HERE, threadSafeBind(&Back
ingThreadHolder::initializeOnThread, AllowCrossThreadAccess(this))); | 78 m_thread->backingThread().postTask(BLINK_FROM_HERE, threadSafeBind(&Back
ingThreadHolder::initializeOnThread, AllowCrossThreadAccess(this))); |
| 77 } | 79 } |
| 78 | 80 |
| 79 static Mutex& holderInstanceMutex() | 81 static Mutex& holderInstanceMutex() |
| 80 { | 82 { |
| 81 DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, holderMutex, new Mutex); | 83 DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, holderMutex, new Mutex); |
| 82 return holderMutex; | 84 return holderMutex; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 98 doneEvent.wait(); | 100 doneEvent.wait(); |
| 99 } | 101 } |
| 100 | 102 |
| 101 void shutdownOnThread(WaitableEvent* doneEvent) | 103 void shutdownOnThread(WaitableEvent* doneEvent) |
| 102 { | 104 { |
| 103 DCHECK_EQ(1u, m_thread->workerScriptCount()) << "BackingThreadHolder sho
uld be the last to detach from WorkerBackingThread"; | 105 DCHECK_EQ(1u, m_thread->workerScriptCount()) << "BackingThreadHolder sho
uld be the last to detach from WorkerBackingThread"; |
| 104 m_thread->detach(); | 106 m_thread->detach(); |
| 105 doneEvent->signal(); | 107 doneEvent->signal(); |
| 106 } | 108 } |
| 107 | 109 |
| 108 OwnPtr<WorkerBackingThread> m_thread; | 110 std::unique_ptr<WorkerBackingThread> m_thread; |
| 109 bool m_terminatingExecution = false; | 111 bool m_terminatingExecution = false; |
| 110 bool m_initialized = false; | 112 bool m_initialized = false; |
| 111 | 113 |
| 112 static BackingThreadHolder* s_instance; | 114 static BackingThreadHolder* s_instance; |
| 113 }; | 115 }; |
| 114 | 116 |
| 115 BackingThreadHolder* BackingThreadHolder::s_instance = nullptr; | 117 BackingThreadHolder* BackingThreadHolder::s_instance = nullptr; |
| 116 | 118 |
| 117 } // namespace | 119 } // namespace |
| 118 | 120 |
| 119 PassOwnPtr<CompositorWorkerThread> CompositorWorkerThread::create(PassRefPtr<Wor
kerLoaderProxy> workerLoaderProxy, InProcessWorkerObjectProxy& workerObjectProxy
, double timeOrigin) | 121 std::unique_ptr<CompositorWorkerThread> CompositorWorkerThread::create(PassRefPt
r<WorkerLoaderProxy> workerLoaderProxy, InProcessWorkerObjectProxy& workerObject
Proxy, double timeOrigin) |
| 120 { | 122 { |
| 121 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erThread::create"); | 123 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erThread::create"); |
| 122 ASSERT(isMainThread()); | 124 ASSERT(isMainThread()); |
| 123 return adoptPtr(new CompositorWorkerThread(workerLoaderProxy, workerObjectPr
oxy, timeOrigin)); | 125 return wrapUnique(new CompositorWorkerThread(workerLoaderProxy, workerObject
Proxy, timeOrigin)); |
| 124 } | 126 } |
| 125 | 127 |
| 126 CompositorWorkerThread::CompositorWorkerThread(PassRefPtr<WorkerLoaderProxy> wor
kerLoaderProxy, InProcessWorkerObjectProxy& workerObjectProxy, double timeOrigin
) | 128 CompositorWorkerThread::CompositorWorkerThread(PassRefPtr<WorkerLoaderProxy> wor
kerLoaderProxy, InProcessWorkerObjectProxy& workerObjectProxy, double timeOrigin
) |
| 127 : WorkerThread(workerLoaderProxy, workerObjectProxy) | 129 : WorkerThread(workerLoaderProxy, workerObjectProxy) |
| 128 , m_workerObjectProxy(workerObjectProxy) | 130 , m_workerObjectProxy(workerObjectProxy) |
| 129 , m_timeOrigin(timeOrigin) | 131 , m_timeOrigin(timeOrigin) |
| 130 { | 132 { |
| 131 } | 133 } |
| 132 | 134 |
| 133 CompositorWorkerThread::~CompositorWorkerThread() | 135 CompositorWorkerThread::~CompositorWorkerThread() |
| 134 { | 136 { |
| 135 } | 137 } |
| 136 | 138 |
| 137 WorkerBackingThread& CompositorWorkerThread::workerBackingThread() | 139 WorkerBackingThread& CompositorWorkerThread::workerBackingThread() |
| 138 { | 140 { |
| 139 return *BackingThreadHolder::instance().thread(); | 141 return *BackingThreadHolder::instance().thread(); |
| 140 } | 142 } |
| 141 | 143 |
| 142 WorkerGlobalScope*CompositorWorkerThread::createWorkerGlobalScope(PassOwnPtr<Wor
kerThreadStartupData> startupData) | 144 WorkerGlobalScope*CompositorWorkerThread::createWorkerGlobalScope(std::unique_pt
r<WorkerThreadStartupData> startupData) |
| 143 { | 145 { |
| 144 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erThread::createWorkerGlobalScope"); | 146 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erThread::createWorkerGlobalScope"); |
| 145 return CompositorWorkerGlobalScope::create(this, std::move(startupData), m_t
imeOrigin); | 147 return CompositorWorkerGlobalScope::create(this, std::move(startupData), m_t
imeOrigin); |
| 146 } | 148 } |
| 147 | 149 |
| 148 void CompositorWorkerThread::ensureSharedBackingThread() | 150 void CompositorWorkerThread::ensureSharedBackingThread() |
| 149 { | 151 { |
| 150 DCHECK(isMainThread()); | 152 DCHECK(isMainThread()); |
| 151 BackingThreadHolder::ensureInstance(); | 153 BackingThreadHolder::ensureInstance(); |
| 152 } | 154 } |
| 153 | 155 |
| 154 void CompositorWorkerThread::terminateExecution() | 156 void CompositorWorkerThread::terminateExecution() |
| 155 { | 157 { |
| 156 DCHECK(isMainThread()); | 158 DCHECK(isMainThread()); |
| 157 BackingThreadHolder::terminateExecution(); | 159 BackingThreadHolder::terminateExecution(); |
| 158 } | 160 } |
| 159 | 161 |
| 160 void CompositorWorkerThread::clearSharedBackingThread() | 162 void CompositorWorkerThread::clearSharedBackingThread() |
| 161 { | 163 { |
| 162 DCHECK(isMainThread()); | 164 DCHECK(isMainThread()); |
| 163 BackingThreadHolder::clear(); | 165 BackingThreadHolder::clear(); |
| 164 } | 166 } |
| 165 | 167 |
| 166 void CompositorWorkerThread::createSharedBackingThreadForTest() | 168 void CompositorWorkerThread::createSharedBackingThreadForTest() |
| 167 { | 169 { |
| 168 BackingThreadHolder::createForTest(); | 170 BackingThreadHolder::createForTest(); |
| 169 } | 171 } |
| 170 | 172 |
| 171 } // namespace blink | 173 } // namespace blink |
| OLD | NEW |