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

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

Issue 2840523002: [DONT COMMIT] Worklet: Implement "addModule()" algorithm for main thread worklets (Closed)
Patch Set: rebase Created 3 years, 8 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 d4ba23475c976898a79d9812442c75c369609f3a..dd0d9278140fb302e5d2ac57f3e1687ea69cf2dd 100644
--- a/third_party/WebKit/Source/modules/csspaint/PaintWorklet.cpp
+++ b/third_party/WebKit/Source/modules/csspaint/PaintWorklet.cpp
@@ -8,6 +8,7 @@
#include "core/dom/Document.h"
#include "core/frame/LocalFrame.h"
#include "modules/csspaint/PaintWorkletGlobalScope.h"
+#include "modules/csspaint/PaintWorkletGlobalScopeProxy.h"
namespace blink {
@@ -16,33 +17,46 @@ PaintWorklet* PaintWorklet::Create(LocalFrame* frame) {
return new PaintWorklet(frame);
}
-PaintWorklet::PaintWorklet(LocalFrame* frame)
- : MainThreadWorklet(frame),
- paint_worklet_global_scope_(PaintWorkletGlobalScope::Create(
- frame,
- frame->GetDocument()->Url(),
- frame->GetDocument()->UserAgent(),
- frame->GetDocument()->GetSecurityOrigin(),
- ToIsolate(frame->GetDocument()))) {}
+PaintWorklet::PaintWorklet(LocalFrame* frame) : MainThreadWorklet(frame) {}
PaintWorklet::~PaintWorklet() {}
-PaintWorkletGlobalScope* PaintWorklet::GetWorkletGlobalScopeProxy() const {
- return paint_worklet_global_scope_.Get();
-}
-
CSSPaintDefinition* PaintWorklet::FindDefinition(const String& name) {
- return paint_worklet_global_scope_->FindDefinition(name);
+ for (const auto& proxy : global_scope_proxies_) {
+ PaintWorkletGlobalScope* global_scope =
+ PaintWorkletGlobalScopeProxy::From(proxy.get())->global_scope();
+ CSSPaintDefinition* definition = global_scope->FindDefinition(name);
+ if (definition)
+ return definition;
+ }
+ return nullptr;
}
void PaintWorklet::AddPendingGenerator(const String& name,
CSSPaintImageGeneratorImpl* generator) {
- return paint_worklet_global_scope_->AddPendingGenerator(name, generator);
+ for (const auto& proxy : global_scope_proxies_) {
+ PaintWorkletGlobalScope* global_scope =
+ PaintWorkletGlobalScopeProxy::From(proxy.get())->global_scope();
+ global_scope->AddPendingGenerator(name, generator);
+ }
}
DEFINE_TRACE(PaintWorklet) {
- visitor->Trace(paint_worklet_global_scope_);
MainThreadWorklet::Trace(visitor);
}
+void PaintWorklet::MayAddWorkletGlobalScopes() {
+ // "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): Create at least two global scopes.
+ if (!global_scope_proxies_.IsEmpty())
+ return;
+ std::unique_ptr<WorkletGlobalScopeProxy> proxy =
+ PaintWorkletGlobalScopeProxy::Create(frame_);
+ global_scope_proxies_.insert(std::move(proxy));
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698