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

Unified Diff: third_party/WebKit/Source/modules/csspaint/PaintWorklet.cpp

Issue 2871513002: Worklet: Lazily create PaintWorkletGlobalScopes (Closed)
Patch Set: add class-level comments Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
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..cb2db5c013fc4d01e9ed4a69b142d1ac44ba84fa 100644
--- a/third_party/WebKit/Source/modules/csspaint/PaintWorklet.cpp
+++ b/third_party/WebKit/Source/modules/csspaint/PaintWorklet.cpp
@@ -18,26 +18,58 @@ 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 (GetProxies().IsEmpty())
+ return nullptr;
+
+ // TODO(nhiroki): Support the case where there are multiple global scopes.
ikilpatrick 2017/05/10 03:47:44 so what we'll want to do for paint is basically sw
nhiroki 2017/05/10 09:01:32 I'm a bit confused. Does it mean to remove PaintWo
ikilpatrick 2017/05/24 03:47:07 Ah sorry, we'll have to work on this a bit more, t
nhiroki 2017/05/24 05:12:21 Acknowledged. Thank you for the clarification.
+ DCHECK_EQ(1u, GetProxies().size());
+ PaintWorkletGlobalScopeProxy* proxy =
+ PaintWorkletGlobalScopeProxy::From(GetProxies().begin()->get());
+ return proxy->FindDefinition(name);
}
void PaintWorklet::AddPendingGenerator(const String& name,
CSSPaintImageGeneratorImpl* generator) {
- return global_scope_proxy_->AddPendingGenerator(name, generator);
+ if (GetProxies().IsEmpty()) {
+ pending_generator_registry_->AddPendingGenerator(name, generator);
+ return;
+ }
+
+ // TODO(nhiroki): Support the case where there are multiple global scopes.
+ DCHECK_EQ(1u, GetProxies().size());
+ PaintWorkletGlobalScopeProxy* proxy =
+ PaintWorkletGlobalScopeProxy::From(GetProxies().begin()->get());
+ return 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 GetProxies().IsEmpty();
+}
+
+std::unique_ptr<WorkletGlobalScopeProxy> PaintWorklet::CreateGlobalScope() {
+ auto proxy = WTF::MakeUnique<PaintWorkletGlobalScopeProxy>(frame_);
+ if (GetProxies().IsEmpty()) {
+ proxy->global_scope()->SetPendingGeneratorRegistry(
+ pending_generator_registry_);
+ pending_generator_registry_ = nullptr;
+ }
+ return proxy;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698