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/ScopedPersistent.h" | 7 #include "bindings/core/v8/ScopedPersistent.h" |
8 #include "bindings/core/v8/V8BindingMacros.h" | 8 #include "bindings/core/v8/V8BindingMacros.h" |
9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" | 9 #include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
10 #include "core/dom/ExceptionCode.h" | 10 #include "core/dom/ExceptionCode.h" |
11 #include "core/inspector/MainThreadDebugger.h" | 11 #include "core/inspector/MainThreadDebugger.h" |
12 #include "modules/csspaint/CSSPaintDefinition.h" | 12 #include "modules/csspaint/CSSPaintDefinition.h" |
| 13 #include "modules/csspaint/CSSPaintImageGeneratorImpl.h" |
| 14 #include "platform/graphics/ImageBuffer.h" |
| 15 #include "platform/graphics/ImageBufferSurface.h" |
| 16 #include "platform/graphics/RecordingImageBufferSurface.h" |
13 | 17 |
14 namespace blink { | 18 namespace blink { |
15 | 19 |
16 // static | 20 // static |
17 RawPtr<PaintWorkletGlobalScope> PaintWorkletGlobalScope::create(LocalFrame* fram
e, const KURL& url, const String& userAgent, PassRefPtr<SecurityOrigin> security
Origin, v8::Isolate* isolate) | 21 RawPtr<PaintWorkletGlobalScope> PaintWorkletGlobalScope::create(LocalFrame* fram
e, const KURL& url, const String& userAgent, PassRefPtr<SecurityOrigin> security
Origin, v8::Isolate* isolate) |
18 { | 22 { |
19 RawPtr<PaintWorkletGlobalScope> paintWorkletGlobalScope = new PaintWorkletGl
obalScope(frame, url, userAgent, securityOrigin, isolate); | 23 RawPtr<PaintWorkletGlobalScope> paintWorkletGlobalScope = new PaintWorkletGl
obalScope(frame, url, userAgent, securityOrigin, isolate); |
20 paintWorkletGlobalScope->scriptController()->initializeContextIfNeeded(); | 24 paintWorkletGlobalScope->scriptController()->initializeContextIfNeeded(); |
21 MainThreadDebugger::instance()->contextCreated(paintWorkletGlobalScope->scri
ptController()->getScriptState(), paintWorkletGlobalScope->frame(), paintWorklet
GlobalScope->getSecurityOrigin()); | 25 MainThreadDebugger::instance()->contextCreated(paintWorkletGlobalScope->scri
ptController()->getScriptState(), paintWorkletGlobalScope->frame(), paintWorklet
GlobalScope->getSecurityOrigin()); |
22 return paintWorkletGlobalScope.release(); | 26 return paintWorkletGlobalScope.release(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 return; | 100 return; |
97 } | 101 } |
98 | 102 |
99 if (!paintValue->IsFunction()) { | 103 if (!paintValue->IsFunction()) { |
100 exceptionState.throwTypeError("The 'paint' property on the prototype is
not a function."); | 104 exceptionState.throwTypeError("The 'paint' property on the prototype is
not a function."); |
101 return; | 105 return; |
102 } | 106 } |
103 | 107 |
104 v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paintValue); | 108 v8::Local<v8::Function> paint = v8::Local<v8::Function>::Cast(paintValue); |
105 | 109 |
106 RawPtr<CSSPaintDefinition> definition = CSSPaintDefinition::create(scriptCon
troller()->getScriptState(), constructor, paint); | 110 CSSPaintDefinition* definition = CSSPaintDefinition::create(scriptController
()->getScriptState(), constructor, paint); |
107 m_paintDefinitions.set(name, definition); | 111 m_paintDefinitions.set(name, definition); |
| 112 |
| 113 // Set the definition on any pending generators. |
| 114 Member<GeneratorHashSet> set = m_pendingGenerators.get(name); |
| 115 if (set) { |
| 116 for (const WeakMember<CSSPaintImageGeneratorImpl> generator : *set) { |
| 117 if (generator) { |
| 118 generator->setDefinition(definition); |
| 119 } |
| 120 } |
| 121 } |
| 122 m_pendingGenerators.remove(name); |
108 } | 123 } |
109 | 124 |
110 CSSPaintDefinition* PaintWorkletGlobalScope::findDefinition(const String& name) | 125 CSSPaintDefinition* PaintWorkletGlobalScope::findDefinition(const String& name) |
111 { | 126 { |
112 return m_paintDefinitions.get(name); | 127 return m_paintDefinitions.get(name); |
113 } | 128 } |
114 | 129 |
| 130 void PaintWorkletGlobalScope::addPendingGenerator(const String& name, CSSPaintIm
ageGeneratorImpl* generator) |
| 131 { |
| 132 Member<GeneratorHashSet>& set = m_pendingGenerators.add(name, nullptr).store
dValue->value; |
| 133 if (!set) |
| 134 set = new GeneratorHashSet; |
| 135 set->add(generator); |
| 136 } |
| 137 |
115 DEFINE_TRACE(PaintWorkletGlobalScope) | 138 DEFINE_TRACE(PaintWorkletGlobalScope) |
116 { | 139 { |
117 visitor->trace(m_paintDefinitions); | 140 visitor->trace(m_paintDefinitions); |
| 141 visitor->trace(m_pendingGenerators); |
118 WorkletGlobalScope::trace(visitor); | 142 WorkletGlobalScope::trace(visitor); |
119 } | 143 } |
120 | 144 |
121 } // namespace blink | 145 } // namespace blink |
OLD | NEW |