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