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/csspaint/PaintWorklet.h" | 5 #include "modules/csspaint/PaintWorklet.h" |
6 | 6 |
7 #include "bindings/core/v8/V8BindingForCore.h" | 7 #include "bindings/core/v8/V8BindingForCore.h" |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "core/frame/LocalFrame.h" | 9 #include "core/frame/LocalFrame.h" |
10 #include "modules/csspaint/PaintWorkletGlobalScope.h" | 10 #include "modules/csspaint/PaintWorkletGlobalScope.h" |
11 #include "modules/csspaint/PaintWorkletGlobalScopeProxy.h" | |
11 | 12 |
12 namespace blink { | 13 namespace blink { |
13 | 14 |
14 // static | 15 // static |
15 PaintWorklet* PaintWorklet::Create(LocalFrame* frame) { | 16 PaintWorklet* PaintWorklet::Create(LocalFrame* frame) { |
16 return new PaintWorklet(frame); | 17 return new PaintWorklet(frame); |
17 } | 18 } |
18 | 19 |
19 PaintWorklet::PaintWorklet(LocalFrame* frame) | 20 PaintWorklet::PaintWorklet(LocalFrame* frame) : MainThreadWorklet(frame) {} |
20 : MainThreadWorklet(frame), | |
21 paint_worklet_global_scope_(PaintWorkletGlobalScope::Create( | |
22 frame, | |
23 frame->GetDocument()->Url(), | |
24 frame->GetDocument()->UserAgent(), | |
25 frame->GetDocument()->GetSecurityOrigin(), | |
26 ToIsolate(frame->GetDocument()), | |
27 this)) {} | |
28 | 21 |
29 PaintWorklet::~PaintWorklet() {} | 22 PaintWorklet::~PaintWorklet() {} |
30 | 23 |
31 PaintWorkletGlobalScope* PaintWorklet::GetWorkletGlobalScopeProxy() const { | |
32 return paint_worklet_global_scope_.Get(); | |
33 } | |
34 | |
35 CSSPaintDefinition* PaintWorklet::FindDefinition(const String& name) { | 24 CSSPaintDefinition* PaintWorklet::FindDefinition(const String& name) { |
36 return paint_worklet_global_scope_->FindDefinition(name); | 25 for (const auto& proxy : global_scope_proxies_) { |
26 PaintWorkletGlobalScope* global_scope = | |
27 PaintWorkletGlobalScopeProxy::From(proxy.get())->global_scope(); | |
28 CSSPaintDefinition* definition = global_scope->FindDefinition(name); | |
29 if (definition) | |
30 return definition; | |
nhiroki
2017/04/25 09:31:32
ikilpatrick@: I'm not sure how FindDefinition() sh
| |
31 } | |
32 return nullptr; | |
37 } | 33 } |
38 | 34 |
39 void PaintWorklet::AddPendingGenerator(const String& name, | 35 void PaintWorklet::AddPendingGenerator(const String& name, |
40 CSSPaintImageGeneratorImpl* generator) { | 36 CSSPaintImageGeneratorImpl* generator) { |
41 return paint_worklet_global_scope_->AddPendingGenerator(name, generator); | 37 for (const auto& proxy : global_scope_proxies_) { |
38 PaintWorkletGlobalScope* global_scope = | |
39 PaintWorkletGlobalScopeProxy::From(proxy.get())->global_scope(); | |
40 global_scope->AddPendingGenerator(name, generator); | |
nhiroki
2017/04/25 09:31:32
ikilpatrick@: ditto. Is it right to call this func
| |
41 } | |
42 } | 42 } |
43 | 43 |
44 DEFINE_TRACE(PaintWorklet) { | 44 DEFINE_TRACE(PaintWorklet) { |
45 visitor->Trace(paint_worklet_global_scope_); | |
46 MainThreadWorklet::Trace(visitor); | 45 MainThreadWorklet::Trace(visitor); |
47 } | 46 } |
48 | 47 |
48 void PaintWorklet::CreateWorkletGlobalScope() { | |
49 MainThreadWorklet::CreateWorkletGlobalScope(); | |
50 | |
51 // Step 12: "Let workletGlobalScope be a PaintWorkletGlobalScope from the list | |
52 // of worklet' s WorkletGlobalScopes from the paint Worklet." | |
53 // | |
54 // "The user agent must have, and select from at least two | |
55 // PaintWorkletGlobalScopes in the worklet's WorkletGlobalScopes list, unless | |
56 // the user agent is under memory constraints." | |
57 // | |
58 // https://drafts.css-houdini.org/css-paint-api-1/#drawing-an-image | |
59 // | |
60 // TODO(nhiroki): Create at least two global scopes. | |
61 std::unique_ptr<WorkletGlobalScopeProxy> proxy = | |
62 PaintWorkletGlobalScopeProxy::Create(frame_, this); | |
63 global_scope_proxies_.insert(std::move(proxy)); | |
64 } | |
65 | |
49 } // namespace blink | 66 } // namespace blink |
OLD | NEW |