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

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: 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 adjustSizeForZoom(const IntSize& size, float zoom)
27 {
28 IntSize newSize(size);
29 newSize.scale(1 / zoom);
30 return newSize;
31 }
32
33 } // namespace
34
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) 35 CSSPaintDefinition* CSSPaintDefinition::create(ScriptState* scriptState, v8::Loc al<v8::Function> constructor, v8::Local<v8::Function> paint, Vector<CSSPropertyI D>& nativeInvalidationProperties, Vector<AtomicString>& customInvalidationProper ties)
25 { 36 {
26 return new CSSPaintDefinition(scriptState, constructor, paint, nativeInvalid ationProperties, customInvalidationProperties); 37 return new CSSPaintDefinition(scriptState, constructor, paint, nativeInvalid ationProperties, customInvalidationProperties);
27 } 38 }
28 39
29 CSSPaintDefinition::CSSPaintDefinition(ScriptState* scriptState, v8::Local<v8::F unction> constructor, v8::Local<v8::Function> paint, Vector<CSSPropertyID>& nati veInvalidationProperties, Vector<AtomicString>& customInvalidationProperties) 40 CSSPaintDefinition::CSSPaintDefinition(ScriptState* scriptState, v8::Local<v8::F unction> constructor, v8::Local<v8::Function> paint, Vector<CSSPropertyID>& nati veInvalidationProperties, Vector<AtomicString>& customInvalidationProperties)
30 : m_scriptState(scriptState) 41 : m_scriptState(scriptState)
31 , m_constructor(scriptState->isolate(), constructor) 42 , m_constructor(scriptState->isolate(), constructor)
32 , m_paint(scriptState->isolate(), paint) 43 , m_paint(scriptState->isolate(), paint)
33 { 44 {
34 m_nativeInvalidationProperties.swap(nativeInvalidationProperties); 45 m_nativeInvalidationProperties.swap(nativeInvalidationProperties);
35 m_customInvalidationProperties.swap(customInvalidationProperties); 46 m_customInvalidationProperties.swap(customInvalidationProperties);
36 } 47 }
37 48
38 CSSPaintDefinition::~CSSPaintDefinition() 49 CSSPaintDefinition::~CSSPaintDefinition()
39 { 50 {
40 } 51 }
41 52
42 PassRefPtr<Image> CSSPaintDefinition::paint(const LayoutObject& layoutObject, co nst IntSize& size) 53 PassRefPtr<Image> CSSPaintDefinition::paint(const LayoutObject& layoutObject, co nst IntSize& size, float zoom)
43 { 54 {
55 const auto adjustedSize = adjustSizeForZoom(size, zoom);
ikilpatrick 2016/06/30 17:24:54 add a comment as to why we are doing this.
Gleb Lanbin 2016/06/30 23:57:20 renamed the function and variable to make clear ou
56
44 ScriptState::Scope scope(m_scriptState.get()); 57 ScriptState::Scope scope(m_scriptState.get());
45 58
46 maybeCreatePaintInstance(); 59 maybeCreatePaintInstance();
47 60
48 v8::Isolate* isolate = m_scriptState->isolate(); 61 v8::Isolate* isolate = m_scriptState->isolate();
49 v8::Local<v8::Object> instance = m_instance.newLocal(isolate); 62 v8::Local<v8::Object> instance = m_instance.newLocal(isolate);
50 63
51 // We may have failed to create an instance class, in which case produce an 64 // We may have failed to create an instance class, in which case produce an
52 // invalid image. 65 // invalid image.
53 if (isUndefinedOrNull(instance)) 66 if (isUndefinedOrNull(instance))
54 return nullptr; 67 return nullptr;
55 68
56 DCHECK(layoutObject.node()); 69 DCHECK(layoutObject.node());
57 70
58 PaintRenderingContext2D* renderingContext = PaintRenderingContext2D::create( 71 PaintRenderingContext2D* renderingContext = PaintRenderingContext2D::create(
59 ImageBuffer::create(wrapUnique(new RecordingImageBufferSurface(size)))); 72 ImageBuffer::create(wrapUnique(new RecordingImageBufferSurface(size))), zoom);
60 PaintSize* paintSize = PaintSize::create(size); 73 PaintSize* paintSize = PaintSize::create(adjustedSize);
61 StylePropertyMap* styleMap = FilteredComputedStylePropertyMap::create( 74 StylePropertyMap* styleMap = FilteredComputedStylePropertyMap::create(
62 CSSComputedStyleDeclaration::create(layoutObject.node()), 75 CSSComputedStyleDeclaration::create(layoutObject.node()),
63 m_nativeInvalidationProperties, m_customInvalidationProperties); 76 m_nativeInvalidationProperties, m_customInvalidationProperties);
64 77
65 v8::Local<v8::Value> argv[] = { 78 v8::Local<v8::Value> argv[] = {
66 toV8(renderingContext, m_scriptState->context()->Global(), isolate), 79 toV8(renderingContext, m_scriptState->context()->Global(), isolate),
67 toV8(paintSize, m_scriptState->context()->Global(), isolate), 80 toV8(paintSize, m_scriptState->context()->Global(), isolate),
68 toV8(styleMap, m_scriptState->context()->Global(), isolate) 81 toV8(styleMap, m_scriptState->context()->Global(), isolate)
69 }; 82 };
70 83
71 v8::Local<v8::Function> paint = m_paint.newLocal(isolate); 84 v8::Local<v8::Function> paint = m_paint.newLocal(isolate);
72 85
73 v8::TryCatch block(isolate); 86 v8::TryCatch block(isolate);
74 block.SetVerbose(true); 87 block.SetVerbose(true);
75 88
76 V8ScriptRunner::callFunction(paint, m_scriptState->getExecutionContext(), in stance, 3, argv, isolate); 89 V8ScriptRunner::callFunction(paint, m_scriptState->getExecutionContext(), in stance, 3, argv, isolate);
77 90
78 // The paint function may have produced an error, in which case produce an 91 // The paint function may have produced an error, in which case produce an
79 // invalid image. 92 // invalid image.
80 if (block.HasCaught()) { 93 if (block.HasCaught()) {
81 return nullptr; 94 return nullptr;
82 } 95 }
83 96
84 return PaintGeneratedImage::create(renderingContext->imageBuffer()->getPictu re(), size); 97 return PaintGeneratedImage::create(renderingContext->imageBuffer()->getPictu re(), adjustedSize);
85 } 98 }
86 99
87 void CSSPaintDefinition::maybeCreatePaintInstance() 100 void CSSPaintDefinition::maybeCreatePaintInstance()
88 { 101 {
89 if (m_didCallConstructor) 102 if (m_didCallConstructor)
90 return; 103 return;
91 104
92 DCHECK(m_instance.isEmpty()); 105 DCHECK(m_instance.isEmpty());
93 106
94 v8::Isolate* isolate = m_scriptState->isolate(); 107 v8::Isolate* isolate = m_scriptState->isolate();
95 v8::Local<v8::Function> constructor = m_constructor.newLocal(isolate); 108 v8::Local<v8::Function> constructor = m_constructor.newLocal(isolate);
96 DCHECK(!isUndefinedOrNull(constructor)); 109 DCHECK(!isUndefinedOrNull(constructor));
97 110
98 v8::Local<v8::Object> paintInstance; 111 v8::Local<v8::Object> paintInstance;
99 if (V8ObjectConstructor::newInstance(isolate, constructor).ToLocal(&paintIns tance)) { 112 if (V8ObjectConstructor::newInstance(isolate, constructor).ToLocal(&paintIns tance)) {
100 m_instance.set(isolate, paintInstance); 113 m_instance.set(isolate, paintInstance);
101 } 114 }
102 115
103 m_didCallConstructor = true; 116 m_didCallConstructor = true;
104 } 117 }
105 118
106 } // namespace blink 119 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698