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

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

Issue 2871513002: Worklet: Lazily create PaintWorkletGlobalScopes (Closed)
Patch Set: fix wrong dcheck 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/PaintWorkletGlobalScope.cpp
diff --git a/third_party/WebKit/Source/modules/csspaint/PaintWorkletGlobalScope.cpp b/third_party/WebKit/Source/modules/csspaint/PaintWorkletGlobalScope.cpp
index 20c8688b9b8949bd3a2610b857ddb814d70c7b69..253e21493dc82ae0687383daaf38fe8338d4c2fa 100644
--- a/third_party/WebKit/Source/modules/csspaint/PaintWorkletGlobalScope.cpp
+++ b/third_party/WebKit/Source/modules/csspaint/PaintWorkletGlobalScope.cpp
@@ -23,10 +23,12 @@ PaintWorkletGlobalScope* PaintWorkletGlobalScope::Create(
const KURL& url,
const String& user_agent,
PassRefPtr<SecurityOrigin> security_origin,
- v8::Isolate* isolate) {
+ v8::Isolate* isolate,
+ PaintWorkletPendingGeneratorRegistry* pending_generator_registry) {
PaintWorkletGlobalScope* paint_worklet_global_scope =
new PaintWorkletGlobalScope(frame, url, user_agent,
- std::move(security_origin), isolate);
+ std::move(security_origin), isolate,
+ pending_generator_registry);
paint_worklet_global_scope->ScriptController()->InitializeContextIfNeeded();
MainThreadDebugger::Instance()->ContextCreated(
paint_worklet_global_scope->ScriptController()->GetScriptState(),
@@ -40,22 +42,26 @@ PaintWorkletGlobalScope::PaintWorkletGlobalScope(
const KURL& url,
const String& user_agent,
PassRefPtr<SecurityOrigin> security_origin,
- v8::Isolate* isolate)
+ v8::Isolate* isolate,
+ PaintWorkletPendingGeneratorRegistry* pending_generator_registry)
: MainThreadWorkletGlobalScope(frame,
url,
user_agent,
std::move(security_origin),
- isolate) {}
+ isolate),
+ pending_generator_registry_(pending_generator_registry) {}
PaintWorkletGlobalScope::~PaintWorkletGlobalScope() {}
void PaintWorkletGlobalScope::Dispose() {
MainThreadDebugger::Instance()->ContextWillBeDestroyed(
ScriptController()->GetScriptState());
+
// Explicitly clear the paint defininitions to break a reference cycle
// between them and this global scope.
paint_definitions_.clear();
+ pending_generator_registry_ = nullptr;
WorkletGlobalScope::Dispose();
}
@@ -193,17 +199,7 @@ void PaintWorkletGlobalScope::registerPaint(const String& name,
native_invalidation_properties, custom_invalidation_properties,
input_argument_types, has_alpha);
paint_definitions_.Set(name, definition);
-
- // Set the definition on any pending generators.
- GeneratorHashSet* set = pending_generators_.at(name);
- if (set) {
- for (const auto& generator : *set) {
- if (generator) {
- generator->SetDefinition(definition);
- }
- }
- }
- pending_generators_.erase(name);
+ pending_generator_registry_->SetDefinition(name, definition);
}
CSSPaintDefinition* PaintWorkletGlobalScope::FindDefinition(
@@ -211,19 +207,9 @@ CSSPaintDefinition* PaintWorkletGlobalScope::FindDefinition(
return paint_definitions_.at(name);
}
-void PaintWorkletGlobalScope::AddPendingGenerator(
- const String& name,
- CSSPaintImageGeneratorImpl* generator) {
- Member<GeneratorHashSet>& set =
- pending_generators_.insert(name, nullptr).stored_value->value;
- if (!set)
- set = new GeneratorHashSet;
- set->insert(generator);
-}
-
DEFINE_TRACE(PaintWorkletGlobalScope) {
visitor->Trace(paint_definitions_);
- visitor->Trace(pending_generators_);
+ visitor->Trace(pending_generator_registry_);
MainThreadWorkletGlobalScope::Trace(visitor);
}

Powered by Google App Engine
This is Rietveld 408576698