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 #include "modules/csspaint/CSSPaintDefinition.h" | 5 #include "modules/csspaint/CSSPaintDefinition.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptState.h" | 7 #include "bindings/core/v8/ScriptState.h" |
8 #include "bindings/core/v8/V8Binding.h" | 8 #include "bindings/core/v8/V8Binding.h" |
9 #include "bindings/core/v8/V8BindingMacros.h" | 9 #include "bindings/core/v8/V8BindingMacros.h" |
10 #include "bindings/core/v8/V8ObjectConstructor.h" | 10 #include "bindings/core/v8/V8ObjectConstructor.h" |
11 #include "core/css/CSSComputedStyleDeclaration.h" | 11 #include "core/css/CSSComputedStyleDeclaration.h" |
12 #include "core/css/cssom/FilteredComputedStylePropertyMap.h" | 12 #include "core/css/cssom/FilteredComputedStylePropertyMap.h" |
13 #include "core/dom/ExecutionContext.h" | 13 #include "core/dom/ExecutionContext.h" |
14 #include "core/layout/LayoutObject.h" | 14 #include "core/layout/LayoutObject.h" |
15 #include "modules/csspaint/PaintRenderingContext2D.h" | 15 #include "modules/csspaint/PaintRenderingContext2D.h" |
16 #include "modules/csspaint/PaintSize.h" | 16 #include "modules/csspaint/PaintSize.h" |
17 #include "platform/graphics/ImageBuffer.h" | 17 #include "platform/graphics/ImageBuffer.h" |
18 #include "platform/graphics/PaintGeneratedImage.h" | 18 #include "platform/graphics/PaintGeneratedImage.h" |
19 #include "platform/graphics/RecordingImageBufferSurface.h" | 19 #include "platform/graphics/RecordingImageBufferSurface.h" |
20 #include "wtf/PtrUtil.h" | 20 #include "wtf/PtrUtil.h" |
21 | 21 |
22 namespace blink { | 22 namespace blink { |
23 | 23 |
24 CSSPaintDefinition* CSSPaintDefinition::create(ScriptState* scriptState, v8::Loc
al<v8::Function> constructor, v8::Local<v8::Function> paint, Vector<CSSPropertyI
D>& nativeInvalidationProperties, Vector<AtomicString>& customInvalidationProper
ties) | 24 CSSPaintDefinition* CSSPaintDefinition::create(ScriptState* scriptState, v8::Loc
al<v8::Function> constructor, v8::Local<v8::Function> paint, Vector<CSSPropertyI
D>& nativeInvalidationProperties, Vector<AtomicString>& customInvalidationProper
ties, bool hasAlphaChannel) |
25 { | 25 { |
26 return new CSSPaintDefinition(scriptState, constructor, paint, nativeInvalid
ationProperties, customInvalidationProperties); | 26 return new CSSPaintDefinition(scriptState, constructor, paint, nativeInvalid
ationProperties, customInvalidationProperties, hasAlphaChannel); |
27 } | 27 } |
28 | 28 |
29 CSSPaintDefinition::CSSPaintDefinition(ScriptState* scriptState, v8::Local<v8::F
unction> constructor, v8::Local<v8::Function> paint, Vector<CSSPropertyID>& nati
veInvalidationProperties, Vector<AtomicString>& customInvalidationProperties) | 29 CSSPaintDefinition::CSSPaintDefinition(ScriptState* scriptState, v8::Local<v8::F
unction> constructor, v8::Local<v8::Function> paint, Vector<CSSPropertyID>& nati
veInvalidationProperties, Vector<AtomicString>& customInvalidationProperties, bo
ol hasAlphaChannel) |
30 : m_scriptState(scriptState) | 30 : m_scriptState(scriptState) |
31 , m_constructor(scriptState->isolate(), constructor) | 31 , m_constructor(scriptState->isolate(), constructor) |
32 , m_paint(scriptState->isolate(), paint) | 32 , m_paint(scriptState->isolate(), paint) |
| 33 , m_didCallConstructor(false) |
| 34 , m_hasAlphaChannel(hasAlphaChannel) |
33 { | 35 { |
34 m_nativeInvalidationProperties.swap(nativeInvalidationProperties); | 36 m_nativeInvalidationProperties.swap(nativeInvalidationProperties); |
35 m_customInvalidationProperties.swap(customInvalidationProperties); | 37 m_customInvalidationProperties.swap(customInvalidationProperties); |
36 } | 38 } |
37 | 39 |
38 CSSPaintDefinition::~CSSPaintDefinition() | 40 CSSPaintDefinition::~CSSPaintDefinition() |
39 { | 41 { |
40 } | 42 } |
41 | 43 |
42 PassRefPtr<Image> CSSPaintDefinition::paint(const LayoutObject& layoutObject, co
nst IntSize& size) | 44 PassRefPtr<Image> CSSPaintDefinition::paint(const LayoutObject& layoutObject, co
nst IntSize& size) |
43 { | 45 { |
44 ScriptState::Scope scope(m_scriptState.get()); | 46 ScriptState::Scope scope(m_scriptState.get()); |
45 | 47 |
46 maybeCreatePaintInstance(); | 48 maybeCreatePaintInstance(); |
47 | 49 |
48 v8::Isolate* isolate = m_scriptState->isolate(); | 50 v8::Isolate* isolate = m_scriptState->isolate(); |
49 v8::Local<v8::Object> instance = m_instance.newLocal(isolate); | 51 v8::Local<v8::Object> instance = m_instance.newLocal(isolate); |
50 | 52 |
51 // We may have failed to create an instance class, in which case produce an | 53 // We may have failed to create an instance class, in which case produce an |
52 // invalid image. | 54 // invalid image. |
53 if (isUndefinedOrNull(instance)) | 55 if (isUndefinedOrNull(instance)) |
54 return nullptr; | 56 return nullptr; |
55 | 57 |
56 DCHECK(layoutObject.node()); | 58 DCHECK(layoutObject.node()); |
57 | 59 |
58 PaintRenderingContext2D* renderingContext = PaintRenderingContext2D::create( | 60 PaintRenderingContext2D* renderingContext = PaintRenderingContext2D::create( |
59 ImageBuffer::create(wrapUnique(new RecordingImageBufferSurface(size)))); | 61 ImageBuffer::create(wrapUnique(new RecordingImageBufferSurface(size, nul
lptr /* fallbackFactory */, m_hasAlphaChannel ? NonOpaque : Opaque))), m_hasAlp
haChannel); |
60 PaintSize* paintSize = PaintSize::create(size); | 62 PaintSize* paintSize = PaintSize::create(size); |
61 StylePropertyMap* styleMap = FilteredComputedStylePropertyMap::create( | 63 StylePropertyMap* styleMap = FilteredComputedStylePropertyMap::create( |
62 CSSComputedStyleDeclaration::create(layoutObject.node()), | 64 CSSComputedStyleDeclaration::create(layoutObject.node()), |
63 m_nativeInvalidationProperties, m_customInvalidationProperties); | 65 m_nativeInvalidationProperties, m_customInvalidationProperties); |
64 | 66 |
65 v8::Local<v8::Value> argv[] = { | 67 v8::Local<v8::Value> argv[] = { |
66 toV8(renderingContext, m_scriptState->context()->Global(), isolate), | 68 toV8(renderingContext, m_scriptState->context()->Global(), isolate), |
67 toV8(paintSize, m_scriptState->context()->Global(), isolate), | 69 toV8(paintSize, m_scriptState->context()->Global(), isolate), |
68 toV8(styleMap, m_scriptState->context()->Global(), isolate) | 70 toV8(styleMap, m_scriptState->context()->Global(), isolate) |
69 }; | 71 }; |
(...skipping 27 matching lines...) Expand all Loading... |
97 | 99 |
98 v8::Local<v8::Object> paintInstance; | 100 v8::Local<v8::Object> paintInstance; |
99 if (V8ObjectConstructor::newInstance(isolate, constructor).ToLocal(&paintIns
tance)) { | 101 if (V8ObjectConstructor::newInstance(isolate, constructor).ToLocal(&paintIns
tance)) { |
100 m_instance.set(isolate, paintInstance); | 102 m_instance.set(isolate, paintInstance); |
101 } | 103 } |
102 | 104 |
103 m_didCallConstructor = true; | 105 m_didCallConstructor = true; |
104 } | 106 } |
105 | 107 |
106 } // namespace blink | 108 } // namespace blink |
OLD | NEW |