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 #ifndef PaintWorkletGlobalScope_h | 5 #ifndef PaintWorkletGlobalScope_h |
6 #define PaintWorkletGlobalScope_h | 6 #define PaintWorkletGlobalScope_h |
7 | 7 |
8 #include "bindings/core/v8/ScriptValue.h" | 8 #include "bindings/core/v8/ScriptValue.h" |
9 #include "core/dom/ExecutionContext.h" | 9 #include "core/dom/ExecutionContext.h" |
10 #include "core/workers/MainThreadWorkletGlobalScope.h" | 10 #include "core/workers/MainThreadWorkletGlobalScope.h" |
11 #include "modules/ModulesExport.h" | 11 #include "modules/ModulesExport.h" |
| 12 #include "modules/csspaint/PaintWorkletPendingGeneratorRegistry.h" |
12 #include "platform/graphics/ImageBuffer.h" | 13 #include "platform/graphics/ImageBuffer.h" |
13 | 14 |
14 namespace blink { | 15 namespace blink { |
15 | 16 |
16 class CSSPaintDefinition; | 17 class CSSPaintDefinition; |
17 class CSSPaintImageGeneratorImpl; | |
18 class ExceptionState; | 18 class ExceptionState; |
19 | 19 |
20 class MODULES_EXPORT PaintWorkletGlobalScope final | 20 class MODULES_EXPORT PaintWorkletGlobalScope final |
21 : public MainThreadWorkletGlobalScope { | 21 : public MainThreadWorkletGlobalScope { |
22 DEFINE_WRAPPERTYPEINFO(); | 22 DEFINE_WRAPPERTYPEINFO(); |
23 USING_GARBAGE_COLLECTED_MIXIN(PaintWorkletGlobalScope); | 23 USING_GARBAGE_COLLECTED_MIXIN(PaintWorkletGlobalScope); |
24 | 24 |
25 public: | 25 public: |
26 static PaintWorkletGlobalScope* Create(LocalFrame*, | 26 static PaintWorkletGlobalScope* Create(LocalFrame*, |
27 const KURL&, | 27 const KURL&, |
28 const String& user_agent, | 28 const String& user_agent, |
29 PassRefPtr<SecurityOrigin>, | 29 PassRefPtr<SecurityOrigin>, |
30 v8::Isolate*); | 30 v8::Isolate*, |
| 31 PaintWorkletPendingGeneratorRegistry*); |
31 ~PaintWorkletGlobalScope() override; | 32 ~PaintWorkletGlobalScope() override; |
32 void Dispose() final; | 33 void Dispose() final; |
33 | 34 |
34 bool IsPaintWorkletGlobalScope() const final { return true; } | 35 bool IsPaintWorkletGlobalScope() const final { return true; } |
35 void registerPaint(const String& name, | 36 void registerPaint(const String& name, |
36 const ScriptValue& ctor, | 37 const ScriptValue& ctor, |
37 ExceptionState&); | 38 ExceptionState&); |
38 | 39 |
39 CSSPaintDefinition* FindDefinition(const String& name); | 40 CSSPaintDefinition* FindDefinition(const String& name); |
40 void AddPendingGenerator(const String& name, CSSPaintImageGeneratorImpl*); | |
41 | 41 |
42 DECLARE_VIRTUAL_TRACE(); | 42 DECLARE_VIRTUAL_TRACE(); |
43 | 43 |
44 private: | 44 private: |
45 PaintWorkletGlobalScope(LocalFrame*, | 45 PaintWorkletGlobalScope(LocalFrame*, |
46 const KURL&, | 46 const KURL&, |
47 const String& user_agent, | 47 const String& user_agent, |
48 PassRefPtr<SecurityOrigin>, | 48 PassRefPtr<SecurityOrigin>, |
49 v8::Isolate*); | 49 v8::Isolate*, |
| 50 PaintWorkletPendingGeneratorRegistry*); |
50 | 51 |
| 52 // The implementation of the "paint definition" concept: |
| 53 // https://drafts.css-houdini.org/css-paint-api/#paint-definition |
51 typedef HeapHashMap<String, Member<CSSPaintDefinition>> DefinitionMap; | 54 typedef HeapHashMap<String, Member<CSSPaintDefinition>> DefinitionMap; |
52 DefinitionMap paint_definitions_; | 55 DefinitionMap paint_definitions_; |
53 | 56 |
54 // The map of CSSPaintImageGeneratorImpl which are waiting for a | 57 Member<PaintWorkletPendingGeneratorRegistry> pending_generator_registry_; |
55 // CSSPaintDefinition to be registered. The global scope is expected to | |
56 // outlive the generators hence are held onto with a WeakMember. | |
57 typedef HeapHashSet<WeakMember<CSSPaintImageGeneratorImpl>> GeneratorHashSet; | |
58 typedef HeapHashMap<String, Member<GeneratorHashSet>> PendingGeneratorMap; | |
59 PendingGeneratorMap pending_generators_; | |
60 }; | 58 }; |
61 | 59 |
62 DEFINE_TYPE_CASTS(PaintWorkletGlobalScope, | 60 DEFINE_TYPE_CASTS(PaintWorkletGlobalScope, |
63 ExecutionContext, | 61 ExecutionContext, |
64 context, | 62 context, |
65 context->IsPaintWorkletGlobalScope(), | 63 context->IsPaintWorkletGlobalScope(), |
66 context.IsPaintWorkletGlobalScope()); | 64 context.IsPaintWorkletGlobalScope()); |
67 | 65 |
68 } // namespace blink | 66 } // namespace blink |
69 | 67 |
70 #endif // PaintWorkletGlobalScope_h | 68 #endif // PaintWorkletGlobalScope_h |
OLD | NEW |