Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: third_party/WebKit/Source/modules/csspaint/CSSPaintDefinition.cpp

Issue 2077413005: Add "alpha" option to PaintWorklet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: set alpha to be true by default Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 hasAlpha)
25 { 25 {
26 return new CSSPaintDefinition(scriptState, constructor, paint, nativeInvalid ationProperties, customInvalidationProperties); 26 return new CSSPaintDefinition(scriptState, constructor, paint, nativeInvalid ationProperties, customInvalidationProperties, hasAlpha);
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 hasAlpha)
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_hasAlpha(hasAlpha)
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_hasAlpha ? NonOpaque : Opaque))), m_hasAlpha);
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698