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