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 v8::Local<v8::Object> paintInstance(); | |
34 ScriptState* getScriptState() const { return m_scriptState.get(); } | |
35 | |
22 v8::Local<v8::Function> paintFunctionForTesting(v8::Isolate* isolate) { retu rn m_paint.newLocal(isolate); } | 36 v8::Local<v8::Function> paintFunctionForTesting(v8::Isolate* isolate) { retu rn m_paint.newLocal(isolate); } |
23 | 37 |
24 DEFINE_INLINE_TRACE() { }; | 38 DEFINE_INLINE_TRACE() { }; |
25 | 39 |
26 private: | 40 private: |
27 CSSPaintDefinition(ScriptState*, v8::Local<v8::Function> constructor, v8::Lo cal<v8::Function> paint); | 41 CSSPaintDefinition(ScriptState*, v8::Local<v8::Function> constructor, v8::Lo cal<v8::Function> paint); |
28 | 42 |
29 RefPtr<ScriptState> m_scriptState; | 43 RefPtr<ScriptState> m_scriptState; |
30 | 44 |
31 // This object keeps the constructor and paint functions alive. This object | 45 // This object keeps the constructor and paint functions alive. This object |
32 // needs to be destroyed to break a reference cycle between it and the | 46 // needs to be destroyed to break a reference cycle between it and the |
33 // PaintWorkletGlobalScope. | 47 // PaintWorkletGlobalScope. |
34 ScopedPersistent<v8::Function> m_constructor; | 48 ScopedPersistent<v8::Function> m_constructor; |
35 ScopedPersistent<v8::Function> m_paint; | 49 ScopedPersistent<v8::Function> m_paint; |
50 | |
51 // At the moment there is only ever one instance of a paint class per type. | |
52 // This is a weak reference, CSSPaintImageGeneratorImpl holds a persistent | |
53 // reference which keeps it alive. | |
54 ScopedPersistent<v8::Object> m_instance; | |
haraken
2016/04/08 04:31:19
I guess it's a bit nasty to add m_instance to both
ikilpatrick
2016/04/08 18:43:21
The initial thinking was when a CSSPaintValue was
| |
36 }; | 55 }; |
37 | 56 |
38 } // namespace blink | 57 } // namespace blink |
39 | 58 |
40 #endif // CSSPaintDefinition_h | 59 #endif // CSSPaintDefinition_h |
OLD | NEW |