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 "core/workers/WorkletThreadHolder.h" | 8 #include "core/workers/WorkletThreadHolder.h" |
9 #include "platform/CrossThreadFunctional.h" | 9 #include "platform/CrossThreadFunctional.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 template class WorkletThreadHolder<AbstractAnimationWorkletThread>; | 18 template class WorkletThreadHolder<AbstractAnimationWorkletThread>; |
19 | 19 |
20 AbstractAnimationWorkletThread::AbstractAnimationWorkletThread( | 20 AbstractAnimationWorkletThread::AbstractAnimationWorkletThread( |
21 PassRefPtr<WorkerLoaderProxy> workerLoaderProxy, | 21 PassRefPtr<WorkerLoaderProxy> workerLoaderProxy, |
22 WorkerReportingProxy& workerReportingProxy) | 22 WorkerReportingProxy& workerReportingProxy) |
23 : WorkerThread(std::move(workerLoaderProxy), workerReportingProxy) {} | 23 : WorkerThread(std::move(workerLoaderProxy), workerReportingProxy) {} |
24 | 24 |
25 AbstractAnimationWorkletThread::~AbstractAnimationWorkletThread() {} | 25 AbstractAnimationWorkletThread::~AbstractAnimationWorkletThread() {} |
26 | 26 |
27 WorkerBackingThread& AbstractAnimationWorkletThread::workerBackingThread() { | 27 WorkerBackingThread& AbstractAnimationWorkletThread::workerBackingThread() { |
28 return *WorkletThreadHolder< | 28 return *WorkletThreadHolder<AbstractAnimationWorkletThread>::getInstance() |
29 AbstractAnimationWorkletThread>::threadHolderInstance() | |
30 ->thread(); | 29 ->thread(); |
31 } | 30 } |
32 | 31 |
33 void collectAllGarbageOnThread(WaitableEvent* doneEvent) { | 32 void collectAllGarbageOnThread(WaitableEvent* doneEvent) { |
34 blink::ThreadState::current()->collectAllGarbage(); | 33 blink::ThreadState::current()->collectAllGarbage(); |
35 doneEvent->signal(); | 34 doneEvent->signal(); |
36 } | 35 } |
37 | 36 |
38 void AbstractAnimationWorkletThread::collectAllGarbage() { | 37 void AbstractAnimationWorkletThread::collectAllGarbage() { |
39 DCHECK(isMainThread()); | 38 DCHECK(isMainThread()); |
40 WaitableEvent doneEvent; | 39 WaitableEvent doneEvent; |
41 WorkletThreadHolder<AbstractAnimationWorkletThread>* threadHolderInstance = | 40 WorkletThreadHolder<AbstractAnimationWorkletThread>* workletThreadHolder = |
42 WorkletThreadHolder< | 41 WorkletThreadHolder<AbstractAnimationWorkletThread>::getInstance(); |
43 AbstractAnimationWorkletThread>::threadHolderInstance(); | 42 if (!workletThreadHolder) |
44 if (!threadHolderInstance) | |
45 return; | 43 return; |
46 threadHolderInstance->thread()->backingThread().postTask( | 44 workletThreadHolder->thread()->backingThread().postTask( |
47 BLINK_FROM_HERE, crossThreadBind(&collectAllGarbageOnThread, | 45 BLINK_FROM_HERE, crossThreadBind(&collectAllGarbageOnThread, |
48 crossThreadUnretained(&doneEvent))); | 46 crossThreadUnretained(&doneEvent))); |
49 doneEvent.wait(); | 47 doneEvent.wait(); |
50 } | 48 } |
51 | 49 |
52 void AbstractAnimationWorkletThread::ensureSharedBackingThread() { | 50 void AbstractAnimationWorkletThread::ensureSharedBackingThread() { |
53 DCHECK(isMainThread()); | 51 DCHECK(isMainThread()); |
54 WorkletThreadHolder<AbstractAnimationWorkletThread>::ensureInstance( | 52 WorkletThreadHolder<AbstractAnimationWorkletThread>::ensureInstance( |
55 Platform::current()->compositorThread()); | 53 Platform::current()->compositorThread()); |
56 } | 54 } |
57 | 55 |
58 void AbstractAnimationWorkletThread::clearSharedBackingThread() { | 56 void AbstractAnimationWorkletThread::clearSharedBackingThread() { |
59 DCHECK(isMainThread()); | 57 DCHECK(isMainThread()); |
60 WorkletThreadHolder<AbstractAnimationWorkletThread>::clearInstance(); | 58 WorkletThreadHolder<AbstractAnimationWorkletThread>::clearInstance(); |
61 } | 59 } |
62 | 60 |
63 void AbstractAnimationWorkletThread::createSharedBackingThreadForTest() { | 61 void AbstractAnimationWorkletThread::createSharedBackingThreadForTest() { |
64 WorkletThreadHolder<AbstractAnimationWorkletThread>::createForTest( | 62 WorkletThreadHolder<AbstractAnimationWorkletThread>::createForTest( |
65 Platform::current()->compositorThread()); | 63 Platform::current()->compositorThread()); |
66 } | 64 } |
67 | 65 |
68 } // namespace blink | 66 } // namespace blink |
OLD | NEW |