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

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

Issue 2871513002: Worklet: Lazily create PaintWorkletGlobalScopes (Closed)
Patch Set: fix layout test failures 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 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 #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 CSSPaintImageGeneratorImpl;
18 class ExceptionState; 19 class ExceptionState;
19 20
20 class MODULES_EXPORT PaintWorkletGlobalScope final 21 class MODULES_EXPORT PaintWorkletGlobalScope final
21 : public MainThreadWorkletGlobalScope { 22 : public MainThreadWorkletGlobalScope {
22 DEFINE_WRAPPERTYPEINFO(); 23 DEFINE_WRAPPERTYPEINFO();
23 USING_GARBAGE_COLLECTED_MIXIN(PaintWorkletGlobalScope); 24 USING_GARBAGE_COLLECTED_MIXIN(PaintWorkletGlobalScope);
24 25
25 public: 26 public:
26 static PaintWorkletGlobalScope* Create(LocalFrame*, 27 static PaintWorkletGlobalScope* Create(LocalFrame*,
27 const KURL&, 28 const KURL&,
28 const String& user_agent, 29 const String& user_agent,
29 PassRefPtr<SecurityOrigin>, 30 PassRefPtr<SecurityOrigin>,
30 v8::Isolate*); 31 v8::Isolate*);
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 void AddPendingGenerator(const String& name, CSSPaintImageGeneratorImpl*);
42 void SetPendingGeneratorRegistry(
43 PaintWorkletPendingGeneratorRegistry* registry) {
44 pending_generator_registry_ = registry;
45 }
41 46
42 DECLARE_VIRTUAL_TRACE(); 47 DECLARE_VIRTUAL_TRACE();
43 48
44 private: 49 private:
45 PaintWorkletGlobalScope(LocalFrame*, 50 PaintWorkletGlobalScope(LocalFrame*,
46 const KURL&, 51 const KURL&,
47 const String& user_agent, 52 const String& user_agent,
48 PassRefPtr<SecurityOrigin>, 53 PassRefPtr<SecurityOrigin>,
49 v8::Isolate*); 54 v8::Isolate*);
50 55
51 typedef HeapHashMap<String, Member<CSSPaintDefinition>> DefinitionMap; 56 typedef HeapHashMap<String, Member<CSSPaintDefinition>> DefinitionMap;
52 DefinitionMap paint_definitions_; 57 DefinitionMap paint_definitions_;
53 58
54 // The map of CSSPaintImageGeneratorImpl which are waiting for a 59 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 }; 60 };
61 61
62 DEFINE_TYPE_CASTS(PaintWorkletGlobalScope, 62 DEFINE_TYPE_CASTS(PaintWorkletGlobalScope,
63 ExecutionContext, 63 ExecutionContext,
64 context, 64 context,
65 context->IsPaintWorkletGlobalScope(), 65 context->IsPaintWorkletGlobalScope(),
66 context.IsPaintWorkletGlobalScope()); 66 context.IsPaintWorkletGlobalScope());
67 67
68 } // namespace blink 68 } // namespace blink
69 69
70 #endif // PaintWorkletGlobalScope_h 70 #endif // PaintWorkletGlobalScope_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698