| OLD | NEW |
| 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" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 PaintWorkletGlobalScope::PaintWorkletGlobalScope( | 38 PaintWorkletGlobalScope::PaintWorkletGlobalScope( |
| 39 LocalFrame* frame, | 39 LocalFrame* frame, |
| 40 const KURL& url, | 40 const KURL& url, |
| 41 const String& user_agent, | 41 const String& user_agent, |
| 42 PassRefPtr<SecurityOrigin> security_origin, | 42 PassRefPtr<SecurityOrigin> security_origin, |
| 43 v8::Isolate* isolate) | 43 v8::Isolate* isolate) |
| 44 : MainThreadWorkletGlobalScope(frame, | 44 : MainThreadWorkletGlobalScope(frame, |
| 45 url, | 45 url, |
| 46 user_agent, | 46 user_agent, |
| 47 std::move(security_origin), | 47 std::move(security_origin), |
| 48 isolate) {} | 48 isolate), |
| 49 pending_generator_registry_(new PaintWorkletPendingGeneratorRegistry) {} |
| 49 | 50 |
| 50 PaintWorkletGlobalScope::~PaintWorkletGlobalScope() {} | 51 PaintWorkletGlobalScope::~PaintWorkletGlobalScope() {} |
| 51 | 52 |
| 52 void PaintWorkletGlobalScope::Dispose() { | 53 void PaintWorkletGlobalScope::Dispose() { |
| 53 MainThreadDebugger::Instance()->ContextWillBeDestroyed( | 54 MainThreadDebugger::Instance()->ContextWillBeDestroyed( |
| 54 ScriptController()->GetScriptState()); | 55 ScriptController()->GetScriptState()); |
| 55 // Explicitly clear the paint defininitions to break a reference cycle | 56 // Explicitly clear the paint defininitions to break a reference cycle |
| 56 // between them and this global scope. | 57 // between them and this global scope. |
| 57 paint_definitions_.clear(); | 58 paint_definitions_.clear(); |
| 58 | 59 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 return; | 187 return; |
| 187 } | 188 } |
| 188 | 189 |
| 189 v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paint_value); | 190 v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paint_value); |
| 190 | 191 |
| 191 CSSPaintDefinition* definition = CSSPaintDefinition::Create( | 192 CSSPaintDefinition* definition = CSSPaintDefinition::Create( |
| 192 ScriptController()->GetScriptState(), constructor, paint, | 193 ScriptController()->GetScriptState(), constructor, paint, |
| 193 native_invalidation_properties, custom_invalidation_properties, | 194 native_invalidation_properties, custom_invalidation_properties, |
| 194 input_argument_types, has_alpha); | 195 input_argument_types, has_alpha); |
| 195 paint_definitions_.Set(name, definition); | 196 paint_definitions_.Set(name, definition); |
| 196 | 197 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 } | 198 } |
| 208 | 199 |
| 209 CSSPaintDefinition* PaintWorkletGlobalScope::FindDefinition( | 200 CSSPaintDefinition* PaintWorkletGlobalScope::FindDefinition( |
| 210 const String& name) { | 201 const String& name) { |
| 211 return paint_definitions_.at(name); | 202 return paint_definitions_.at(name); |
| 212 } | 203 } |
| 213 | 204 |
| 214 void PaintWorkletGlobalScope::AddPendingGenerator( | 205 void PaintWorkletGlobalScope::AddPendingGenerator( |
| 215 const String& name, | 206 const String& name, |
| 216 CSSPaintImageGeneratorImpl* generator) { | 207 CSSPaintImageGeneratorImpl* generator) { |
| 217 Member<GeneratorHashSet>& set = | 208 pending_generator_registry_->AddPendingGenerator(name, generator); |
| 218 pending_generators_.insert(name, nullptr).stored_value->value; | |
| 219 if (!set) | |
| 220 set = new GeneratorHashSet; | |
| 221 set->insert(generator); | |
| 222 } | 209 } |
| 223 | 210 |
| 224 DEFINE_TRACE(PaintWorkletGlobalScope) { | 211 DEFINE_TRACE(PaintWorkletGlobalScope) { |
| 225 visitor->Trace(paint_definitions_); | 212 visitor->Trace(paint_definitions_); |
| 226 visitor->Trace(pending_generators_); | 213 visitor->Trace(pending_generator_registry_); |
| 227 MainThreadWorkletGlobalScope::Trace(visitor); | 214 MainThreadWorkletGlobalScope::Trace(visitor); |
| 228 } | 215 } |
| 229 | 216 |
| 230 } // namespace blink | 217 } // namespace blink |
| OLD | NEW |