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 | 21 |
28 PaintWorklet::~PaintWorklet() {} | 22 PaintWorklet::~PaintWorklet() {} |
29 | 23 |
30 PaintWorkletGlobalScope* PaintWorklet::GetWorkletGlobalScopeProxy() const { | |
31 return paint_worklet_global_scope_.Get(); | |
32 } | |
33 | |
34 CSSPaintDefinition* PaintWorklet::FindDefinition(const String& name) { | 24 CSSPaintDefinition* PaintWorklet::FindDefinition(const String& name) { |
35 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; |
| 31 } |
| 32 return nullptr; |
36 } | 33 } |
37 | 34 |
38 void PaintWorklet::AddPendingGenerator(const String& name, | 35 void PaintWorklet::AddPendingGenerator(const String& name, |
39 CSSPaintImageGeneratorImpl* generator) { | 36 CSSPaintImageGeneratorImpl* generator) { |
40 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); |
| 41 } |
41 } | 42 } |
42 | 43 |
43 DEFINE_TRACE(PaintWorklet) { | 44 DEFINE_TRACE(PaintWorklet) { |
44 visitor->Trace(paint_worklet_global_scope_); | |
45 MainThreadWorklet::Trace(visitor); | 45 MainThreadWorklet::Trace(visitor); |
46 } | 46 } |
47 | 47 |
| 48 void PaintWorklet::MayAddWorkletGlobalScopes() { |
| 49 // "The user agent must have, and select from at least two |
| 50 // PaintWorkletGlobalScopes in the worklet's WorkletGlobalScopes list, unless |
| 51 // the user agent is under memory constraints." |
| 52 // https://drafts.css-houdini.org/css-paint-api-1/#drawing-an-image |
| 53 // |
| 54 // TODO(nhiroki): Create at least two global scopes. |
| 55 if (!global_scope_proxies_.IsEmpty()) |
| 56 return; |
| 57 std::unique_ptr<WorkletGlobalScopeProxy> proxy = |
| 58 PaintWorkletGlobalScopeProxy::Create(frame_); |
| 59 global_scope_proxies_.insert(std::move(proxy)); |
| 60 } |
| 61 |
48 } // namespace blink | 62 } // namespace blink |
OLD | NEW |