Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1781)

Side by Side Diff: third_party/WebKit/Source/modules/compositorworker/AnimationWorklet.cpp

Issue 2912743002: [WIP] Worklet: Merge MainThreadWorklet and ThreadedWorklet into Worklet
Patch Set: WIP Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/AnimationWorklet.h" 5 #include "modules/compositorworker/AnimationWorklet.h"
6 6
7 #include "bindings/core/v8/V8BindingForCore.h" 7 #include "bindings/core/v8/V8BindingForCore.h"
8 #include "core/dom/AnimationWorkletProxyClient.h" 8 #include "core/dom/AnimationWorkletProxyClient.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/frame/LocalFrame.h" 10 #include "core/frame/LocalFrame.h"
11 #include "core/page/ChromeClient.h" 11 #include "core/page/ChromeClient.h"
12 #include "modules/compositorworker/AnimationWorkletMessagingProxy.h" 12 #include "modules/compositorworker/AnimationWorkletMessagingProxy.h"
13 #include "modules/compositorworker/AnimationWorkletThread.h" 13 #include "modules/compositorworker/AnimationWorkletThread.h"
14 14
15 namespace blink { 15 namespace blink {
16 16
17 // static 17 // static
18 AnimationWorklet* AnimationWorklet::Create(LocalFrame* frame) { 18 AnimationWorklet* AnimationWorklet::Create(LocalFrame* frame) {
19 return new AnimationWorklet(frame); 19 return new AnimationWorklet(frame);
20 } 20 }
21 21
22 AnimationWorklet::AnimationWorklet(LocalFrame* frame) 22 AnimationWorklet::AnimationWorklet(LocalFrame* frame) : Worklet(frame) {}
23 : ThreadedWorklet(frame), worklet_messaging_proxy_(nullptr) {}
24 23
25 AnimationWorklet::~AnimationWorklet() { 24 AnimationWorklet::~AnimationWorklet() {
26 if (worklet_messaging_proxy_) 25 // The proxy outlives the worklet as it is used to perform thread shutdown,
27 worklet_messaging_proxy_->ParentObjectDestroyed(); 26 // it deletes itself once this has occurred.
27 // TODO(nhiroki):
28 } 28 }
29 29
30 void AnimationWorklet::Initialize() { 30 bool AnimationWorklet::NeedsToCreateGlobalScope() {
31 // In the current impl, we create only one global scope.
32 return !GetNumberOfGlobalScopes();
33 }
34
35 std::unique_ptr<WorkletGlobalScopeProxy> AnimationWorklet::CreateGlobalScope() {
31 AnimationWorkletThread::EnsureSharedBackingThread(); 36 AnimationWorkletThread::EnsureSharedBackingThread();
32
33 DCHECK(!worklet_messaging_proxy_);
34 DCHECK(GetExecutionContext());
35 Document* document = ToDocument(GetExecutionContext()); 37 Document* document = ToDocument(GetExecutionContext());
36 AnimationWorkletProxyClient* proxy_client = 38 AnimationWorkletProxyClient* proxy_client =
37 document->GetFrame()->GetChromeClient().CreateAnimationWorkletProxyClient( 39 document->GetFrame()->GetChromeClient().CreateAnimationWorkletProxyClient(
38 document->GetFrame()); 40 document->GetFrame());
39 41 return WTF::MakeUnique<AnimationWorkletMessagingProxy>(GetExecutionContext(),
40 worklet_messaging_proxy_ = 42 proxy_client);
41 new AnimationWorkletMessagingProxy(GetExecutionContext(), proxy_client);
42 worklet_messaging_proxy_->Initialize();
43 }
44
45 bool AnimationWorklet::IsInitialized() const {
46 return worklet_messaging_proxy_;
47 }
48
49 WorkletGlobalScopeProxy* AnimationWorklet::GetWorkletGlobalScopeProxy() const {
50 DCHECK(worklet_messaging_proxy_);
51 return worklet_messaging_proxy_;
52 } 43 }
53 44
54 DEFINE_TRACE(AnimationWorklet) { 45 DEFINE_TRACE(AnimationWorklet) {
55 ThreadedWorklet::Trace(visitor); 46 Worklet::Trace(visitor);
56 } 47 }
57 48
58 } // namespace blink 49 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698