| 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/Assertions.h" | 18 #include "wtf/Assertions.h" |
| 19 #include "wtf/PtrUtil.h" | |
| 20 #include <memory> | |
| 21 | 19 |
| 22 namespace blink { | 20 namespace blink { |
| 23 | 21 |
| 24 namespace { | 22 namespace { |
| 25 | 23 |
| 26 // This is a singleton class holding the compositor worker thread in this | 24 // This is a singleton class holding the compositor worker thread in this |
| 27 // renderer process. BackingThreadHolder::m_thread is cleared by | 25 // renderer process. BackingThreadHolder::m_thread is cleared by |
| 28 // ModulesInitializer::shutdown. | 26 // ModulesInitializer::shutdown. |
| 29 // See WorkerThread::terminateAndWaitForAllWorkers for the process shutdown | 27 // See WorkerThread::terminateAndWaitForAllWorkers for the process shutdown |
| 30 // case. | 28 // case. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 55 static void createForTest() | 53 static void createForTest() |
| 56 { | 54 { |
| 57 MutexLocker locker(holderInstanceMutex()); | 55 MutexLocker locker(holderInstanceMutex()); |
| 58 DCHECK_EQ(nullptr, s_instance); | 56 DCHECK_EQ(nullptr, s_instance); |
| 59 s_instance = new BackingThreadHolder(WorkerBackingThread::createForTest(
Platform::current()->compositorThread())); | 57 s_instance = new BackingThreadHolder(WorkerBackingThread::createForTest(
Platform::current()->compositorThread())); |
| 60 } | 58 } |
| 61 | 59 |
| 62 WorkerBackingThread* thread() { return m_thread.get(); } | 60 WorkerBackingThread* thread() { return m_thread.get(); } |
| 63 | 61 |
| 64 private: | 62 private: |
| 65 BackingThreadHolder(std::unique_ptr<WorkerBackingThread> useBackingThread =
nullptr) | 63 BackingThreadHolder(PassOwnPtr<WorkerBackingThread> useBackingThread = nullp
tr) |
| 66 : m_thread(useBackingThread ? std::move(useBackingThread) : WorkerBackin
gThread::create(Platform::current()->compositorThread())) | 64 : m_thread(useBackingThread ? std::move(useBackingThread) : WorkerBackin
gThread::create(Platform::current()->compositorThread())) |
| 67 { | 65 { |
| 68 DCHECK(isMainThread()); | 66 DCHECK(isMainThread()); |
| 69 m_thread->backingThread().postTask(BLINK_FROM_HERE, threadSafeBind(&Back
ingThreadHolder::initializeOnThread, AllowCrossThreadAccess(this))); | 67 m_thread->backingThread().postTask(BLINK_FROM_HERE, threadSafeBind(&Back
ingThreadHolder::initializeOnThread, AllowCrossThreadAccess(this))); |
| 70 } | 68 } |
| 71 | 69 |
| 72 static Mutex& holderInstanceMutex() | 70 static Mutex& holderInstanceMutex() |
| 73 { | 71 { |
| 74 DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, holderMutex, new Mutex); | 72 DEFINE_THREAD_SAFE_STATIC_LOCAL(Mutex, holderMutex, new Mutex); |
| 75 return holderMutex; | 73 return holderMutex; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 90 m_thread->backingThread().postTask(BLINK_FROM_HERE, threadSafeBind(&Back
ingThreadHolder::shutdownOnThread, AllowCrossThreadAccess(this), AllowCrossThrea
dAccess(&doneEvent))); | 88 m_thread->backingThread().postTask(BLINK_FROM_HERE, threadSafeBind(&Back
ingThreadHolder::shutdownOnThread, AllowCrossThreadAccess(this), AllowCrossThrea
dAccess(&doneEvent))); |
| 91 doneEvent.wait(); | 89 doneEvent.wait(); |
| 92 } | 90 } |
| 93 | 91 |
| 94 void shutdownOnThread(WaitableEvent* doneEvent) | 92 void shutdownOnThread(WaitableEvent* doneEvent) |
| 95 { | 93 { |
| 96 m_thread->shutdown(); | 94 m_thread->shutdown(); |
| 97 doneEvent->signal(); | 95 doneEvent->signal(); |
| 98 } | 96 } |
| 99 | 97 |
| 100 std::unique_ptr<WorkerBackingThread> m_thread; | 98 OwnPtr<WorkerBackingThread> m_thread; |
| 101 bool m_initialized = false; | 99 bool m_initialized = false; |
| 102 | 100 |
| 103 static BackingThreadHolder* s_instance; | 101 static BackingThreadHolder* s_instance; |
| 104 }; | 102 }; |
| 105 | 103 |
| 106 BackingThreadHolder* BackingThreadHolder::s_instance = nullptr; | 104 BackingThreadHolder* BackingThreadHolder::s_instance = nullptr; |
| 107 | 105 |
| 108 } // namespace | 106 } // namespace |
| 109 | 107 |
| 110 std::unique_ptr<CompositorWorkerThread> CompositorWorkerThread::create(PassRefPt
r<WorkerLoaderProxy> workerLoaderProxy, InProcessWorkerObjectProxy& workerObject
Proxy, double timeOrigin) | 108 PassOwnPtr<CompositorWorkerThread> CompositorWorkerThread::create(PassRefPtr<Wor
kerLoaderProxy> workerLoaderProxy, InProcessWorkerObjectProxy& workerObjectProxy
, double timeOrigin) |
| 111 { | 109 { |
| 112 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erThread::create"); | 110 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erThread::create"); |
| 113 ASSERT(isMainThread()); | 111 ASSERT(isMainThread()); |
| 114 return wrapUnique(new CompositorWorkerThread(workerLoaderProxy, workerObject
Proxy, timeOrigin)); | 112 return adoptPtr(new CompositorWorkerThread(workerLoaderProxy, workerObjectPr
oxy, timeOrigin)); |
| 115 } | 113 } |
| 116 | 114 |
| 117 CompositorWorkerThread::CompositorWorkerThread(PassRefPtr<WorkerLoaderProxy> wor
kerLoaderProxy, InProcessWorkerObjectProxy& workerObjectProxy, double timeOrigin
) | 115 CompositorWorkerThread::CompositorWorkerThread(PassRefPtr<WorkerLoaderProxy> wor
kerLoaderProxy, InProcessWorkerObjectProxy& workerObjectProxy, double timeOrigin
) |
| 118 : WorkerThread(workerLoaderProxy, workerObjectProxy) | 116 : WorkerThread(workerLoaderProxy, workerObjectProxy) |
| 119 , m_workerObjectProxy(workerObjectProxy) | 117 , m_workerObjectProxy(workerObjectProxy) |
| 120 , m_timeOrigin(timeOrigin) | 118 , m_timeOrigin(timeOrigin) |
| 121 { | 119 { |
| 122 } | 120 } |
| 123 | 121 |
| 124 CompositorWorkerThread::~CompositorWorkerThread() | 122 CompositorWorkerThread::~CompositorWorkerThread() |
| 125 { | 123 { |
| 126 } | 124 } |
| 127 | 125 |
| 128 WorkerBackingThread& CompositorWorkerThread::workerBackingThread() | 126 WorkerBackingThread& CompositorWorkerThread::workerBackingThread() |
| 129 { | 127 { |
| 130 return *BackingThreadHolder::instance().thread(); | 128 return *BackingThreadHolder::instance().thread(); |
| 131 } | 129 } |
| 132 | 130 |
| 133 WorkerGlobalScope*CompositorWorkerThread::createWorkerGlobalScope(std::unique_pt
r<WorkerThreadStartupData> startupData) | 131 WorkerGlobalScope*CompositorWorkerThread::createWorkerGlobalScope(PassOwnPtr<Wor
kerThreadStartupData> startupData) |
| 134 { | 132 { |
| 135 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erThread::createWorkerGlobalScope"); | 133 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("compositor-worker"), "CompositorWork
erThread::createWorkerGlobalScope"); |
| 136 return CompositorWorkerGlobalScope::create(this, std::move(startupData), m_t
imeOrigin); | 134 return CompositorWorkerGlobalScope::create(this, std::move(startupData), m_t
imeOrigin); |
| 137 } | 135 } |
| 138 | 136 |
| 139 void CompositorWorkerThread::ensureSharedBackingThread() | 137 void CompositorWorkerThread::ensureSharedBackingThread() |
| 140 { | 138 { |
| 141 DCHECK(isMainThread()); | 139 DCHECK(isMainThread()); |
| 142 BackingThreadHolder::ensureInstance(); | 140 BackingThreadHolder::ensureInstance(); |
| 143 } | 141 } |
| 144 | 142 |
| 145 void CompositorWorkerThread::clearSharedBackingThread() | 143 void CompositorWorkerThread::clearSharedBackingThread() |
| 146 { | 144 { |
| 147 DCHECK(isMainThread()); | 145 DCHECK(isMainThread()); |
| 148 BackingThreadHolder::clear(); | 146 BackingThreadHolder::clear(); |
| 149 } | 147 } |
| 150 | 148 |
| 151 void CompositorWorkerThread::createSharedBackingThreadForTest() | 149 void CompositorWorkerThread::createSharedBackingThreadForTest() |
| 152 { | 150 { |
| 153 BackingThreadHolder::createForTest(); | 151 BackingThreadHolder::createForTest(); |
| 154 } | 152 } |
| 155 | 153 |
| 156 } // namespace blink | 154 } // namespace blink |
| OLD | NEW |