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