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

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

Issue 2104103003: Fix zoom in CSS paint worklets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2nd rebase 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 namespace {
25
26 IntSize getSpecifiedSize(const IntSize& size, float zoom)
27 {
28 float unZoomFactor = 1 / zoom;
29 auto unZoomFn = [unZoomFactor](int a) -> int {
30 return round(a * unZoomFactor);
31 };
32 return IntSize(unZoomFn(size.width()), unZoomFn(size.height()));
33 }
34
35 } // namespace
36
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) 37 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 { 38 {
26 return new CSSPaintDefinition(scriptState, constructor, paint, nativeInvalid ationProperties, customInvalidationProperties, hasAlpha); 39 return new CSSPaintDefinition(scriptState, constructor, paint, nativeInvalid ationProperties, customInvalidationProperties, hasAlpha);
27 } 40 }
28 41
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) 42 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) 43 : m_scriptState(scriptState)
31 , m_constructor(scriptState->isolate(), constructor) 44 , m_constructor(scriptState->isolate(), constructor)
32 , m_paint(scriptState->isolate(), paint) 45 , m_paint(scriptState->isolate(), paint)
33 , m_didCallConstructor(false) 46 , m_didCallConstructor(false)
34 , m_hasAlpha(hasAlpha) 47 , m_hasAlpha(hasAlpha)
35 { 48 {
36 m_nativeInvalidationProperties.swap(nativeInvalidationProperties); 49 m_nativeInvalidationProperties.swap(nativeInvalidationProperties);
37 m_customInvalidationProperties.swap(customInvalidationProperties); 50 m_customInvalidationProperties.swap(customInvalidationProperties);
38 } 51 }
39 52
40 CSSPaintDefinition::~CSSPaintDefinition() 53 CSSPaintDefinition::~CSSPaintDefinition()
41 { 54 {
42 } 55 }
43 56
44 PassRefPtr<Image> CSSPaintDefinition::paint(const LayoutObject& layoutObject, co nst IntSize& size) 57 PassRefPtr<Image> CSSPaintDefinition::paint(const LayoutObject& layoutObject, co nst IntSize& size, float zoom)
45 { 58 {
59 const IntSize specifiedSize = getSpecifiedSize(size, zoom);
60
46 ScriptState::Scope scope(m_scriptState.get()); 61 ScriptState::Scope scope(m_scriptState.get());
47 62
48 maybeCreatePaintInstance(); 63 maybeCreatePaintInstance();
49 64
50 v8::Isolate* isolate = m_scriptState->isolate(); 65 v8::Isolate* isolate = m_scriptState->isolate();
51 v8::Local<v8::Object> instance = m_instance.newLocal(isolate); 66 v8::Local<v8::Object> instance = m_instance.newLocal(isolate);
52 67
53 // We may have failed to create an instance class, in which case produce an 68 // We may have failed to create an instance class, in which case produce an
54 // invalid image. 69 // invalid image.
55 if (isUndefinedOrNull(instance)) 70 if (isUndefinedOrNull(instance))
56 return nullptr; 71 return nullptr;
57 72
58 DCHECK(layoutObject.node()); 73 DCHECK(layoutObject.node());
59 74
60 PaintRenderingContext2D* renderingContext = PaintRenderingContext2D::create( 75 PaintRenderingContext2D* renderingContext = PaintRenderingContext2D::create(
61 ImageBuffer::create(wrapUnique(new RecordingImageBufferSurface(size, nul lptr /* fallbackFactory */, m_hasAlpha ? NonOpaque : Opaque))), m_hasAlpha); 76 ImageBuffer::create(wrapUnique(new RecordingImageBufferSurface(size, nul lptr /* fallbackFactory */, m_hasAlpha ? NonOpaque : Opaque))), m_hasAlpha, zoo m);
62 PaintSize* paintSize = PaintSize::create(size); 77 PaintSize* paintSize = PaintSize::create(specifiedSize);
63 StylePropertyMap* styleMap = FilteredComputedStylePropertyMap::create( 78 StylePropertyMap* styleMap = FilteredComputedStylePropertyMap::create(
64 CSSComputedStyleDeclaration::create(layoutObject.node()), 79 CSSComputedStyleDeclaration::create(layoutObject.node()),
65 m_nativeInvalidationProperties, m_customInvalidationProperties); 80 m_nativeInvalidationProperties, m_customInvalidationProperties);
66 81
67 v8::Local<v8::Value> argv[] = { 82 v8::Local<v8::Value> argv[] = {
68 toV8(renderingContext, m_scriptState->context()->Global(), isolate), 83 toV8(renderingContext, m_scriptState->context()->Global(), isolate),
69 toV8(paintSize, m_scriptState->context()->Global(), isolate), 84 toV8(paintSize, m_scriptState->context()->Global(), isolate),
70 toV8(styleMap, m_scriptState->context()->Global(), isolate) 85 toV8(styleMap, m_scriptState->context()->Global(), isolate)
71 }; 86 };
72 87
73 v8::Local<v8::Function> paint = m_paint.newLocal(isolate); 88 v8::Local<v8::Function> paint = m_paint.newLocal(isolate);
74 89
75 v8::TryCatch block(isolate); 90 v8::TryCatch block(isolate);
76 block.SetVerbose(true); 91 block.SetVerbose(true);
77 92
78 V8ScriptRunner::callFunction(paint, m_scriptState->getExecutionContext(), in stance, 3, argv, isolate); 93 V8ScriptRunner::callFunction(paint, m_scriptState->getExecutionContext(), in stance, 3, argv, isolate);
79 94
80 // The paint function may have produced an error, in which case produce an 95 // The paint function may have produced an error, in which case produce an
81 // invalid image. 96 // invalid image.
82 if (block.HasCaught()) { 97 if (block.HasCaught()) {
83 return nullptr; 98 return nullptr;
84 } 99 }
85 100
86 return PaintGeneratedImage::create(renderingContext->imageBuffer()->getPictu re(), size); 101 return PaintGeneratedImage::create(renderingContext->imageBuffer()->getPictu re(), specifiedSize);
87 } 102 }
88 103
89 void CSSPaintDefinition::maybeCreatePaintInstance() 104 void CSSPaintDefinition::maybeCreatePaintInstance()
90 { 105 {
91 if (m_didCallConstructor) 106 if (m_didCallConstructor)
92 return; 107 return;
93 108
94 DCHECK(m_instance.isEmpty()); 109 DCHECK(m_instance.isEmpty());
95 110
96 v8::Isolate* isolate = m_scriptState->isolate(); 111 v8::Isolate* isolate = m_scriptState->isolate();
97 v8::Local<v8::Function> constructor = m_constructor.newLocal(isolate); 112 v8::Local<v8::Function> constructor = m_constructor.newLocal(isolate);
98 DCHECK(!isUndefinedOrNull(constructor)); 113 DCHECK(!isUndefinedOrNull(constructor));
99 114
100 v8::Local<v8::Object> paintInstance; 115 v8::Local<v8::Object> paintInstance;
101 if (V8ObjectConstructor::newInstance(isolate, constructor).ToLocal(&paintIns tance)) { 116 if (V8ObjectConstructor::newInstance(isolate, constructor).ToLocal(&paintIns tance)) {
102 m_instance.set(isolate, paintInstance); 117 m_instance.set(isolate, paintInstance);
103 } 118 }
104 119
105 m_didCallConstructor = true; 120 m_didCallConstructor = true;
106 } 121 }
107 122
108 } // namespace blink 123 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698