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 CSSPaintDefinition_h | 5 #ifndef CSSPaintDefinition_h |
6 #define CSSPaintDefinition_h | 6 #define CSSPaintDefinition_h |
7 | 7 |
8 #include "bindings/core/v8/ScopedPersistent.h" | 8 #include "bindings/core/v8/ScopedPersistent.h" |
| 9 #include "core/CSSPropertyNames.h" |
9 #include "platform/geometry/IntSize.h" | 10 #include "platform/geometry/IntSize.h" |
10 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
11 #include <v8.h> | 12 #include <v8.h> |
12 | 13 |
13 namespace blink { | 14 namespace blink { |
14 | 15 |
15 class Image; | 16 class Image; |
16 class ScriptState; | 17 class ScriptState; |
17 | 18 |
18 // Represents a javascript class registered on the PaintWorkletGlobalScope by | 19 // Represents a javascript class registered on the PaintWorkletGlobalScope by |
19 // the author. | 20 // the author. |
20 class CSSPaintDefinition final : public GarbageCollectedFinalized<CSSPaintDefini
tion> { | 21 class CSSPaintDefinition final : public GarbageCollectedFinalized<CSSPaintDefini
tion> { |
21 public: | 22 public: |
22 static CSSPaintDefinition* create(ScriptState*, v8::Local<v8::Function> cons
tructor, v8::Local<v8::Function> paint); | 23 static CSSPaintDefinition* create(ScriptState*, v8::Local<v8::Function> cons
tructor, v8::Local<v8::Function> paint, Vector<CSSPropertyID>&, Vector<AtomicStr
ing>& customInvalidationProperties); |
23 virtual ~CSSPaintDefinition(); | 24 virtual ~CSSPaintDefinition(); |
24 | 25 |
25 // Invokes the javascript 'paint' callback on an instance of the javascript | 26 // Invokes the javascript 'paint' callback on an instance of the javascript |
26 // class. The size given will be the size of the PaintRenderingContext2D | 27 // class. The size given will be the size of the PaintRenderingContext2D |
27 // given to the callback. | 28 // given to the callback. |
28 // | 29 // |
29 // This may return a nullptr (representing an invalid image) if javascript | 30 // This may return a nullptr (representing an invalid image) if javascript |
30 // throws an error. | 31 // throws an error. |
31 PassRefPtr<Image> paint(const IntSize&); | 32 PassRefPtr<Image> paint(const IntSize&); |
| 33 const Vector<CSSPropertyID>& nativeInvalidationProperties() const { return m
_nativeInvalidationProperties; } |
| 34 const Vector<AtomicString>& customInvalidationProperties() const { return m_
customInvalidationProperties; } |
32 | 35 |
33 ScriptState* getScriptState() const { return m_scriptState.get(); } | 36 ScriptState* getScriptState() const { return m_scriptState.get(); } |
34 | 37 |
35 v8::Local<v8::Function> paintFunctionForTesting(v8::Isolate* isolate) { retu
rn m_paint.newLocal(isolate); } | 38 v8::Local<v8::Function> paintFunctionForTesting(v8::Isolate* isolate) { retu
rn m_paint.newLocal(isolate); } |
36 | 39 |
37 DEFINE_INLINE_TRACE() { }; | 40 DEFINE_INLINE_TRACE() { }; |
38 | 41 |
39 private: | 42 private: |
40 CSSPaintDefinition(ScriptState*, v8::Local<v8::Function> constructor, v8::Lo
cal<v8::Function> paint); | 43 CSSPaintDefinition(ScriptState*, v8::Local<v8::Function> constructor, v8::Lo
cal<v8::Function> paint, Vector<CSSPropertyID>& nativeInvalidationProperties, Ve
ctor<AtomicString>& customInvalidationProperties); |
41 | 44 |
42 void maybeCreatePaintInstance(); | 45 void maybeCreatePaintInstance(); |
43 | 46 |
44 RefPtr<ScriptState> m_scriptState; | 47 RefPtr<ScriptState> m_scriptState; |
45 | 48 |
46 // This object keeps the class instance object, constructor function and | 49 // This object keeps the class instance object, constructor function and |
47 // paint function alive. This object needs to be destroyed to break a | 50 // paint function alive. This object needs to be destroyed to break a |
48 // reference cycle between it and the PaintWorkletGlobalScope. | 51 // reference cycle between it and the PaintWorkletGlobalScope. |
49 ScopedPersistent<v8::Function> m_constructor; | 52 ScopedPersistent<v8::Function> m_constructor; |
50 ScopedPersistent<v8::Function> m_paint; | 53 ScopedPersistent<v8::Function> m_paint; |
51 | 54 |
52 // At the moment there is only ever one instance of a paint class per type. | 55 // At the moment there is only ever one instance of a paint class per type. |
53 ScopedPersistent<v8::Object> m_instance; | 56 ScopedPersistent<v8::Object> m_instance; |
54 | 57 |
55 bool m_didCallConstructor; | 58 bool m_didCallConstructor; |
| 59 |
| 60 Vector<CSSPropertyID> m_nativeInvalidationProperties; |
| 61 Vector<AtomicString> m_customInvalidationProperties; |
56 }; | 62 }; |
57 | 63 |
58 } // namespace blink | 64 } // namespace blink |
59 | 65 |
60 #endif // CSSPaintDefinition_h | 66 #endif // CSSPaintDefinition_h |
OLD | NEW |