Chromium Code Reviews| Index: third_party/WebKit/Source/modules/csspaint/PaintWorklet.cpp |
| diff --git a/third_party/WebKit/Source/modules/csspaint/PaintWorklet.cpp b/third_party/WebKit/Source/modules/csspaint/PaintWorklet.cpp |
| index 5631ede6909a80d6c746431a4abca10773172f2f..f29a95b5b8b1768ca63dbc56cd4c4f58f9fbcade 100644 |
| --- a/third_party/WebKit/Source/modules/csspaint/PaintWorklet.cpp |
| +++ b/third_party/WebKit/Source/modules/csspaint/PaintWorklet.cpp |
| @@ -18,26 +18,55 @@ PaintWorklet* PaintWorklet::Create(LocalFrame* frame) { |
| PaintWorklet::PaintWorklet(LocalFrame* frame) |
| : MainThreadWorklet(frame), |
| - global_scope_proxy_( |
| - WTF::MakeUnique<PaintWorkletGlobalScopeProxy>(frame)) {} |
| + pending_generator_registry_(new PaintWorkletPendingGeneratorRegistry) {} |
| PaintWorklet::~PaintWorklet() = default; |
| -WorkletGlobalScopeProxy* PaintWorklet::GetWorkletGlobalScopeProxy() const { |
| - return global_scope_proxy_.get(); |
| -} |
| - |
| CSSPaintDefinition* PaintWorklet::FindDefinition(const String& name) { |
| - return global_scope_proxy_->FindDefinition(name); |
| + if (GetNumberOfGlobalScopes() == 0) |
| + return nullptr; |
| + |
| + PaintWorkletGlobalScopeProxy* proxy = |
| + PaintWorkletGlobalScopeProxy::From(FindAvailableGlobalScope()); |
| + return proxy->FindDefinition(name); |
| } |
| void PaintWorklet::AddPendingGenerator(const String& name, |
| CSSPaintImageGeneratorImpl* generator) { |
| - return global_scope_proxy_->AddPendingGenerator(name, generator); |
| + if (GetNumberOfGlobalScopes() == 0) { |
| + pending_generator_registry_->AddPendingGenerator(name, generator); |
| + return; |
| + } |
| + |
| + PaintWorkletGlobalScopeProxy* proxy = |
| + PaintWorkletGlobalScopeProxy::From(FindAvailableGlobalScope()); |
| + proxy->AddPendingGenerator(name, generator); |
| } |
| DEFINE_TRACE(PaintWorklet) { |
| + visitor->Trace(pending_generator_registry_); |
| MainThreadWorklet::Trace(visitor); |
| } |
| +bool PaintWorklet::NeedsToCreateGlobalScope() { |
| + // "The user agent must have, and select from at least two |
| + // PaintWorkletGlobalScopes in the worklet's WorkletGlobalScopes list, unless |
| + // the user agent is under memory constraints." |
| + // https://drafts.css-houdini.org/css-paint-api-1/#drawing-an-image |
| + // TODO(nhiroki): In the current impl, we create only one global scope. We |
| + // should create at least two global scopes as the spec. |
| + return !GetNumberOfGlobalScopes(); |
| +} |
| + |
| +std::unique_ptr<WorkletGlobalScopeProxy> PaintWorklet::CreateGlobalScope() { |
| + LocalFrame* frame = ToDocument(GetExecutionContext())->GetFrame(); |
| + auto proxy = WTF::MakeUnique<PaintWorkletGlobalScopeProxy>(frame); |
| + if (GetNumberOfGlobalScopes() == 0) { |
|
kouhei (in TOK)
2017/05/24 14:31:13
DCHECK(pending_generator_registry_)
nhiroki
2017/05/24 14:42:09
Done.
|
| + proxy->global_scope()->SetPendingGeneratorRegistry( |
| + pending_generator_registry_); |
| + pending_generator_registry_ = nullptr; |
| + } |
|
kouhei (in TOK)
2017/05/24 14:31:13
else DCHECK(!pending_generator_registry_)
nhiroki
2017/05/24 14:42:09
Done (I omitted "else")
|
| + return std::move(proxy); |
| +} |
| + |
| } // namespace blink |