| 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..b95a3942b5cd5bcdd8afdce5745ed30e1a7bdb49 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 (GetGlobalScopeManager().GetNumberOfGlobalScopes() == 0)
|
| + return nullptr;
|
| +
|
| + PaintWorkletGlobalScopeProxy* proxy = PaintWorkletGlobalScopeProxy::From(
|
| + GetGlobalScopeManager().FindAvailableGlobalScope());
|
| + return proxy->FindDefinition(name);
|
| }
|
|
|
| void PaintWorklet::AddPendingGenerator(const String& name,
|
| CSSPaintImageGeneratorImpl* generator) {
|
| - return global_scope_proxy_->AddPendingGenerator(name, generator);
|
| + if (GetGlobalScopeManager().GetNumberOfGlobalScopes() == 0) {
|
| + pending_generator_registry_->AddPendingGenerator(name, generator);
|
| + return;
|
| + }
|
| +
|
| + PaintWorkletGlobalScopeProxy* proxy = PaintWorkletGlobalScopeProxy::From(
|
| + GetGlobalScopeManager().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 GetGlobalScopeManager().GetNumberOfGlobalScopes();
|
| +}
|
| +
|
| +std::unique_ptr<WorkletGlobalScopeProxy> PaintWorklet::CreateGlobalScope() {
|
| + LocalFrame* frame = ToDocument(GetExecutionContext())->GetFrame();
|
| + auto proxy = WTF::MakeUnique<PaintWorkletGlobalScopeProxy>(frame);
|
| + if (GetGlobalScopeManager().GetNumberOfGlobalScopes() == 0) {
|
| + proxy->global_scope()->SetPendingGeneratorRegistry(
|
| + pending_generator_registry_);
|
| + pending_generator_registry_ = nullptr;
|
| + }
|
| + return std::move(proxy);
|
| +}
|
| +
|
| } // namespace blink
|
|
|