| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/AbstractAnimationWorkletThread.h" | 5 #include "modules/compositorworker/AbstractAnimationWorkletThread.h" |
| 6 | 6 |
| 7 #include "core/workers/WorkerBackingThread.h" | 7 #include "core/workers/WorkerBackingThread.h" |
| 8 #include "platform/CrossThreadFunctional.h" | 8 #include "platform/CrossThreadFunctional.h" |
| 9 #include "platform/WaitableEvent.h" | 9 #include "platform/WaitableEvent.h" |
| 10 #include "platform/WebThreadSupportingGC.h" | 10 #include "platform/WebThreadSupportingGC.h" |
| 11 #include "public/platform/Platform.h" | 11 #include "public/platform/Platform.h" |
| 12 #include "wtf/Assertions.h" | 12 #include "wtf/Assertions.h" |
| 13 #include "wtf/PtrUtil.h" | 13 #include "wtf/PtrUtil.h" |
| 14 #include <memory> | 14 #include <memory> |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // This is a singleton class holding the animation worklet thread in this | 20 // This is a singleton class holding the animation worklet thread in this |
| 21 // renderer process. BackingThreadHolder::m_thread is cleared by | 21 // renderer process. BackingThreadHolder::m_thread is cleared by |
| 22 // ModulesInitializer::shutdown. | 22 // ModulesInitializer::shutdown. |
| 23 // See WorkerThread::terminateAndWaitForAllWorkers for the process shutdown | 23 // See WorkerThread::terminateAndWaitForAllWorkers for the process shutdown |
| 24 // case. | 24 // case. |
| 25 class BackingThreadHolder { | 25 class BackingThreadHolder { |
| 26 public: | 26 public: |
| 27 static BackingThreadHolder& instance() | 27 static BackingThreadHolder* instance() |
| 28 { | 28 { |
| 29 MutexLocker locker(holderInstanceMutex()); | 29 MutexLocker locker(holderInstanceMutex()); |
| 30 return *s_instance; | 30 return s_instance; |
| 31 } | 31 } |
| 32 | 32 |
| 33 static void ensureInstance() | 33 static void ensureInstance() |
| 34 { | 34 { |
| 35 if (!s_instance) | 35 if (!s_instance) |
| 36 s_instance = new BackingThreadHolder; | 36 s_instance = new BackingThreadHolder; |
| 37 } | 37 } |
| 38 | 38 |
| 39 static void clear() | 39 static void clear() |
| 40 { | 40 { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 : WorkerThread(std::move(workerLoaderProxy), workerReportingProxy) | 105 : WorkerThread(std::move(workerLoaderProxy), workerReportingProxy) |
| 106 { | 106 { |
| 107 } | 107 } |
| 108 | 108 |
| 109 AbstractAnimationWorkletThread::~AbstractAnimationWorkletThread() | 109 AbstractAnimationWorkletThread::~AbstractAnimationWorkletThread() |
| 110 { | 110 { |
| 111 } | 111 } |
| 112 | 112 |
| 113 WorkerBackingThread& AbstractAnimationWorkletThread::workerBackingThread() | 113 WorkerBackingThread& AbstractAnimationWorkletThread::workerBackingThread() |
| 114 { | 114 { |
| 115 return *BackingThreadHolder::instance().thread(); | 115 return *BackingThreadHolder::instance()->thread(); |
| 116 } |
| 117 |
| 118 void collectAllGarbageOnThread(WaitableEvent* doneEvent) |
| 119 { |
| 120 blink::ThreadState::current()->collectAllGarbage(); |
| 121 doneEvent->signal(); |
| 122 } |
| 123 |
| 124 void AbstractAnimationWorkletThread::collectAllGarbage() |
| 125 { |
| 126 DCHECK(isMainThread()); |
| 127 WaitableEvent doneEvent; |
| 128 BackingThreadHolder* instance = BackingThreadHolder::instance(); |
| 129 if (!instance) |
| 130 return; |
| 131 instance->thread()->backingThread().postTask(BLINK_FROM_HERE, crossThreadBin
d(&collectAllGarbageOnThread, crossThreadUnretained(&doneEvent))); |
| 132 doneEvent.wait(); |
| 116 } | 133 } |
| 117 | 134 |
| 118 void AbstractAnimationWorkletThread::ensureSharedBackingThread() | 135 void AbstractAnimationWorkletThread::ensureSharedBackingThread() |
| 119 { | 136 { |
| 120 DCHECK(isMainThread()); | 137 DCHECK(isMainThread()); |
| 121 BackingThreadHolder::ensureInstance(); | 138 BackingThreadHolder::ensureInstance(); |
| 122 } | 139 } |
| 123 | 140 |
| 124 void AbstractAnimationWorkletThread::clearSharedBackingThread() | 141 void AbstractAnimationWorkletThread::clearSharedBackingThread() |
| 125 { | 142 { |
| 126 DCHECK(isMainThread()); | 143 DCHECK(isMainThread()); |
| 127 BackingThreadHolder::clear(); | 144 BackingThreadHolder::clear(); |
| 128 } | 145 } |
| 129 | 146 |
| 130 void AbstractAnimationWorkletThread::createSharedBackingThreadForTest() | 147 void AbstractAnimationWorkletThread::createSharedBackingThreadForTest() |
| 131 { | 148 { |
| 132 BackingThreadHolder::createForTest(); | 149 BackingThreadHolder::createForTest(); |
| 133 } | 150 } |
| 134 | 151 |
| 135 } // namespace blink | 152 } // namespace blink |
| OLD | NEW |