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

Side by Side Diff: third_party/WebKit/Source/modules/csspaint/PaintWorkletGlobalScope.cpp

Issue 2871513002: Worklet: Lazily create PaintWorkletGlobalScopes (Closed)
Patch Set: fix wrong dcheck Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/csspaint/PaintWorkletGlobalScope.h" 5 #include "modules/csspaint/PaintWorkletGlobalScope.h"
6 6
7 #include "bindings/core/v8/IDLTypes.h" 7 #include "bindings/core/v8/IDLTypes.h"
8 #include "bindings/core/v8/NativeValueTraitsImpl.h" 8 #include "bindings/core/v8/NativeValueTraitsImpl.h"
9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" 9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h"
10 #include "core/CSSPropertyNames.h" 10 #include "core/CSSPropertyNames.h"
11 #include "core/css/CSSSyntaxDescriptor.h" 11 #include "core/css/CSSSyntaxDescriptor.h"
12 #include "core/dom/ExceptionCode.h" 12 #include "core/dom/ExceptionCode.h"
13 #include "core/inspector/MainThreadDebugger.h" 13 #include "core/inspector/MainThreadDebugger.h"
14 #include "modules/csspaint/CSSPaintDefinition.h" 14 #include "modules/csspaint/CSSPaintDefinition.h"
15 #include "modules/csspaint/CSSPaintImageGeneratorImpl.h" 15 #include "modules/csspaint/CSSPaintImageGeneratorImpl.h"
16 #include "platform/bindings/V8BindingMacros.h" 16 #include "platform/bindings/V8BindingMacros.h"
17 17
18 namespace blink { 18 namespace blink {
19 19
20 // static 20 // static
21 PaintWorkletGlobalScope* PaintWorkletGlobalScope::Create( 21 PaintWorkletGlobalScope* PaintWorkletGlobalScope::Create(
22 LocalFrame* frame, 22 LocalFrame* frame,
23 const KURL& url, 23 const KURL& url,
24 const String& user_agent, 24 const String& user_agent,
25 PassRefPtr<SecurityOrigin> security_origin, 25 PassRefPtr<SecurityOrigin> security_origin,
26 v8::Isolate* isolate) { 26 v8::Isolate* isolate,
27 PaintWorkletPendingGeneratorRegistry* pending_generator_registry) {
27 PaintWorkletGlobalScope* paint_worklet_global_scope = 28 PaintWorkletGlobalScope* paint_worklet_global_scope =
28 new PaintWorkletGlobalScope(frame, url, user_agent, 29 new PaintWorkletGlobalScope(frame, url, user_agent,
29 std::move(security_origin), isolate); 30 std::move(security_origin), isolate,
31 pending_generator_registry);
30 paint_worklet_global_scope->ScriptController()->InitializeContextIfNeeded(); 32 paint_worklet_global_scope->ScriptController()->InitializeContextIfNeeded();
31 MainThreadDebugger::Instance()->ContextCreated( 33 MainThreadDebugger::Instance()->ContextCreated(
32 paint_worklet_global_scope->ScriptController()->GetScriptState(), 34 paint_worklet_global_scope->ScriptController()->GetScriptState(),
33 paint_worklet_global_scope->GetFrame(), 35 paint_worklet_global_scope->GetFrame(),
34 paint_worklet_global_scope->GetSecurityOrigin()); 36 paint_worklet_global_scope->GetSecurityOrigin());
35 return paint_worklet_global_scope; 37 return paint_worklet_global_scope;
36 } 38 }
37 39
38 PaintWorkletGlobalScope::PaintWorkletGlobalScope( 40 PaintWorkletGlobalScope::PaintWorkletGlobalScope(
39 LocalFrame* frame, 41 LocalFrame* frame,
40 const KURL& url, 42 const KURL& url,
41 const String& user_agent, 43 const String& user_agent,
42 PassRefPtr<SecurityOrigin> security_origin, 44 PassRefPtr<SecurityOrigin> security_origin,
43 v8::Isolate* isolate) 45 v8::Isolate* isolate,
46 PaintWorkletPendingGeneratorRegistry* pending_generator_registry)
44 : MainThreadWorkletGlobalScope(frame, 47 : MainThreadWorkletGlobalScope(frame,
45 url, 48 url,
46 user_agent, 49 user_agent,
47 std::move(security_origin), 50 std::move(security_origin),
48 isolate) {} 51 isolate),
52 pending_generator_registry_(pending_generator_registry) {}
49 53
50 PaintWorkletGlobalScope::~PaintWorkletGlobalScope() {} 54 PaintWorkletGlobalScope::~PaintWorkletGlobalScope() {}
51 55
52 void PaintWorkletGlobalScope::Dispose() { 56 void PaintWorkletGlobalScope::Dispose() {
53 MainThreadDebugger::Instance()->ContextWillBeDestroyed( 57 MainThreadDebugger::Instance()->ContextWillBeDestroyed(
54 ScriptController()->GetScriptState()); 58 ScriptController()->GetScriptState());
59
55 // Explicitly clear the paint defininitions to break a reference cycle 60 // Explicitly clear the paint defininitions to break a reference cycle
56 // between them and this global scope. 61 // between them and this global scope.
57 paint_definitions_.clear(); 62 paint_definitions_.clear();
58 63
64 pending_generator_registry_ = nullptr;
59 WorkletGlobalScope::Dispose(); 65 WorkletGlobalScope::Dispose();
60 } 66 }
61 67
62 void PaintWorkletGlobalScope::registerPaint(const String& name, 68 void PaintWorkletGlobalScope::registerPaint(const String& name,
63 const ScriptValue& ctor_value, 69 const ScriptValue& ctor_value,
64 ExceptionState& exception_state) { 70 ExceptionState& exception_state) {
65 if (paint_definitions_.Contains(name)) { 71 if (paint_definitions_.Contains(name)) {
66 exception_state.ThrowDOMException( 72 exception_state.ThrowDOMException(
67 kNotSupportedError, 73 kNotSupportedError,
68 "A class with name:'" + name + "' is already registered."); 74 "A class with name:'" + name + "' is already registered.");
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 return; 192 return;
187 } 193 }
188 194
189 v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paint_value); 195 v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paint_value);
190 196
191 CSSPaintDefinition* definition = CSSPaintDefinition::Create( 197 CSSPaintDefinition* definition = CSSPaintDefinition::Create(
192 ScriptController()->GetScriptState(), constructor, paint, 198 ScriptController()->GetScriptState(), constructor, paint,
193 native_invalidation_properties, custom_invalidation_properties, 199 native_invalidation_properties, custom_invalidation_properties,
194 input_argument_types, has_alpha); 200 input_argument_types, has_alpha);
195 paint_definitions_.Set(name, definition); 201 paint_definitions_.Set(name, definition);
196 202 pending_generator_registry_->SetDefinition(name, definition);
197 // Set the definition on any pending generators.
198 GeneratorHashSet* set = pending_generators_.at(name);
199 if (set) {
200 for (const auto& generator : *set) {
201 if (generator) {
202 generator->SetDefinition(definition);
203 }
204 }
205 }
206 pending_generators_.erase(name);
207 } 203 }
208 204
209 CSSPaintDefinition* PaintWorkletGlobalScope::FindDefinition( 205 CSSPaintDefinition* PaintWorkletGlobalScope::FindDefinition(
210 const String& name) { 206 const String& name) {
211 return paint_definitions_.at(name); 207 return paint_definitions_.at(name);
212 } 208 }
213 209
214 void PaintWorkletGlobalScope::AddPendingGenerator(
215 const String& name,
216 CSSPaintImageGeneratorImpl* generator) {
217 Member<GeneratorHashSet>& set =
218 pending_generators_.insert(name, nullptr).stored_value->value;
219 if (!set)
220 set = new GeneratorHashSet;
221 set->insert(generator);
222 }
223
224 DEFINE_TRACE(PaintWorkletGlobalScope) { 210 DEFINE_TRACE(PaintWorkletGlobalScope) {
225 visitor->Trace(paint_definitions_); 211 visitor->Trace(paint_definitions_);
226 visitor->Trace(pending_generators_); 212 visitor->Trace(pending_generator_registry_);
227 MainThreadWorkletGlobalScope::Trace(visitor); 213 MainThreadWorkletGlobalScope::Trace(visitor);
228 } 214 }
229 215
230 } // namespace blink 216 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698