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

Side by Side Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp

Issue 1886063002: Make canvas filters use the font size in effect when the filter is set (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/canvas2d/CanvasRenderingContext2DState.h" 5 #include "modules/canvas2d/CanvasRenderingContext2DState.h"
6 6
7 #include "core/css/CSSFontSelector.h" 7 #include "core/css/CSSFontSelector.h"
8 #include "core/css/resolver/FilterOperationResolver.h" 8 #include "core/css/resolver/FilterOperationResolver.h"
9 #include "core/css/resolver/StyleBuilder.h" 9 #include "core/css/resolver/StyleBuilder.h"
10 #include "core/css/resolver/StyleResolverState.h" 10 #include "core/css/resolver/StyleResolverState.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 , m_shadowOnlyDrawLooper(other.m_shadowOnlyDrawLooper) 80 , m_shadowOnlyDrawLooper(other.m_shadowOnlyDrawLooper)
81 , m_shadowAndForegroundDrawLooper(other.m_shadowAndForegroundDrawLooper) 81 , m_shadowAndForegroundDrawLooper(other.m_shadowAndForegroundDrawLooper)
82 , m_shadowOnlyImageFilter(other.m_shadowOnlyImageFilter) 82 , m_shadowOnlyImageFilter(other.m_shadowOnlyImageFilter)
83 , m_shadowAndForegroundImageFilter(other.m_shadowAndForegroundImageFilter) 83 , m_shadowAndForegroundImageFilter(other.m_shadowAndForegroundImageFilter)
84 , m_globalAlpha(other.m_globalAlpha) 84 , m_globalAlpha(other.m_globalAlpha)
85 , m_transform(other.m_transform) 85 , m_transform(other.m_transform)
86 , m_lineDash(other.m_lineDash) 86 , m_lineDash(other.m_lineDash)
87 , m_lineDashOffset(other.m_lineDashOffset) 87 , m_lineDashOffset(other.m_lineDashOffset)
88 , m_unparsedFont(other.m_unparsedFont) 88 , m_unparsedFont(other.m_unparsedFont)
89 , m_font(other.m_font) 89 , m_font(other.m_font)
90 , m_fontForFilter(other.m_fontForFilter)
90 , m_unparsedFilter(other.m_unparsedFilter) 91 , m_unparsedFilter(other.m_unparsedFilter)
91 , m_filterValue(other.m_filterValue) 92 , m_filterValue(other.m_filterValue)
92 , m_resolvedFilter(other.m_resolvedFilter) 93 , m_resolvedFilter(other.m_resolvedFilter)
93 , m_textAlign(other.m_textAlign) 94 , m_textAlign(other.m_textAlign)
94 , m_textBaseline(other.m_textBaseline) 95 , m_textBaseline(other.m_textBaseline)
95 , m_direction(other.m_direction) 96 , m_direction(other.m_direction)
96 , m_realizedFont(other.m_realizedFont) 97 , m_realizedFont(other.m_realizedFont)
97 , m_isTransformInvertible(other.m_isTransformInvertible) 98 , m_isTransformInvertible(other.m_isTransformInvertible)
98 , m_hasClip(other.m_hasClip) 99 , m_hasClip(other.m_hasClip)
99 , m_hasComplexClip(other.m_hasComplexClip) 100 , m_hasComplexClip(other.m_hasComplexClip)
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 if (!path.isRect(0)) 255 if (!path.isRect(0))
255 m_hasComplexClip = true; 256 m_hasComplexClip = true;
256 } 257 }
257 258
258 void CanvasRenderingContext2DState::setFont(const Font& font, CSSFontSelector* s elector) 259 void CanvasRenderingContext2DState::setFont(const Font& font, CSSFontSelector* s elector)
259 { 260 {
260 m_font = font; 261 m_font = font;
261 m_font.update(selector); 262 m_font.update(selector);
262 m_realizedFont = true; 263 m_realizedFont = true;
263 selector->registerForInvalidationCallbacks(this); 264 selector->registerForInvalidationCallbacks(this);
264 // FIXME: We only really need to invalidate the resolved filter if it
265 // uses font-relative units.
266 m_resolvedFilter.clear();
267 } 265 }
268 266
269 const Font& CanvasRenderingContext2DState::font() const 267 const Font& CanvasRenderingContext2DState::font() const
270 { 268 {
271 ASSERT(m_realizedFont); 269 ASSERT(m_realizedFont);
272 return m_font; 270 return m_font;
273 } 271 }
274 272
275 void CanvasRenderingContext2DState::setTransform(const AffineTransform& transfor m) 273 void CanvasRenderingContext2DState::setTransform(const AffineTransform& transfor m)
276 { 274 {
277 m_isTransformInvertible = transform.isInvertible(); 275 m_isTransformInvertible = transform.isInvertible();
278 m_transform = transform; 276 m_transform = transform;
279 } 277 }
280 278
281 void CanvasRenderingContext2DState::resetTransform() 279 void CanvasRenderingContext2DState::resetTransform()
282 { 280 {
283 m_transform.makeIdentity(); 281 m_transform.makeIdentity();
284 m_isTransformInvertible = true; 282 m_isTransformInvertible = true;
285 } 283 }
286 284
287 static void updateFilterReferences(HTMLCanvasElement* canvasElement, CanvasRende ringContext2D* context, const FilterOperations& filters) 285 static void updateFilterReferences(HTMLCanvasElement* canvasElement, CanvasRende ringContext2D* context, const FilterOperations& filters)
288 { 286 {
289 context->clearFilterReferences(); 287 context->clearFilterReferences();
290 context->addFilterReferences(filters, canvasElement->document()); 288 context->addFilterReferences(filters, canvasElement->document());
291 } 289 }
292 290
293 SkImageFilter* CanvasRenderingContext2DState::getFilter(Element* styleResolution Host, const Font& font, IntSize canvasSize, CanvasRenderingContext2D* context) c onst 291 SkImageFilter* CanvasRenderingContext2DState::getFilter(Element* styleResolution Host, IntSize canvasSize, CanvasRenderingContext2D* context) const
294 { 292 {
295 if (!m_filterValue) 293 if (!m_filterValue)
296 return nullptr; 294 return nullptr;
297 295
298 if (!m_resolvedFilter) { 296 if (!m_resolvedFilter) {
299 RefPtr<ComputedStyle> filterStyle = ComputedStyle::create(); 297 RefPtr<ComputedStyle> filterStyle = ComputedStyle::create();
300 // Must set font in case the filter uses any font-relative units (em, ex ) 298 // Must set font in case the filter uses any font-relative units (em, ex )
301 filterStyle->setFont(font); 299 filterStyle->setFont(m_fontForFilter);
302 300
303 StyleResolverState resolverState(styleResolutionHost->document(), styleR esolutionHost, filterStyle.get()); 301 StyleResolverState resolverState(styleResolutionHost->document(), styleR esolutionHost, filterStyle.get());
304 resolverState.setStyle(filterStyle); 302 resolverState.setStyle(filterStyle);
305 303
306 StyleBuilder::applyProperty(CSSPropertyWebkitFilter, resolverState, m_fi lterValue.get()); 304 StyleBuilder::applyProperty(CSSPropertyWebkitFilter, resolverState, m_fi lterValue.get());
307 resolverState.loadPendingResources(); 305 resolverState.loadPendingResources();
308 FilterEffectBuilder* filterEffectBuilder = FilterEffectBuilder::create() ; 306 FilterEffectBuilder* filterEffectBuilder = FilterEffectBuilder::create() ;
309 307
310 // We can't reuse m_fillPaint and m_strokePaint for the filter, since th ese incorporate 308 // We can't reuse m_fillPaint and m_strokePaint for the filter, since th ese incorporate
311 // the global alpha, which isn't applicable here. 309 // the global alpha, which isn't applicable here.
(...skipping 13 matching lines...) Expand all
325 if (m_resolvedFilter) { 323 if (m_resolvedFilter) {
326 updateFilterReferences(toHTMLCanvasElement(styleResolutionHost), con text, filterStyle->filter()); 324 updateFilterReferences(toHTMLCanvasElement(styleResolutionHost), con text, filterStyle->filter());
327 if (lastEffect->originTainted()) 325 if (lastEffect->originTainted())
328 context->setOriginTainted(); 326 context->setOriginTainted();
329 } 327 }
330 } 328 }
331 329
332 return m_resolvedFilter.get(); 330 return m_resolvedFilter.get();
333 } 331 }
334 332
335 bool CanvasRenderingContext2DState::hasFilter(Element* styleResolutionHost, cons t Font& font, IntSize canvasSize, CanvasRenderingContext2D* context) const 333 bool CanvasRenderingContext2DState::hasFilter(Element* styleResolutionHost, IntS ize canvasSize, CanvasRenderingContext2D* context) const
336 { 334 {
337 // Checking for a non-null m_filterValue isn't sufficient, since this value 335 // Checking for a non-null m_filterValue isn't sufficient, since this value
338 // might refer to a non-existent filter. 336 // might refer to a non-existent filter.
339 return !!getFilter(styleResolutionHost, font, canvasSize, context); 337 return !!getFilter(styleResolutionHost, canvasSize, context);
340 } 338 }
341 339
342 void CanvasRenderingContext2DState::clearResolvedFilter() const 340 void CanvasRenderingContext2DState::clearResolvedFilter() const
343 { 341 {
344 m_resolvedFilter.clear(); 342 m_resolvedFilter.clear();
345 } 343 }
346 344
347 SkDrawLooper* CanvasRenderingContext2DState::emptyDrawLooper() const 345 SkDrawLooper* CanvasRenderingContext2DState::emptyDrawLooper() const
348 { 346 {
349 if (!m_emptyDrawLooper) { 347 if (!m_emptyDrawLooper) {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 paint->setLooper(0); 555 paint->setLooper(0);
558 paint->setImageFilter(shadowAndForegroundImageFilter()); 556 paint->setImageFilter(shadowAndForegroundImageFilter());
559 return paint; 557 return paint;
560 } 558 }
561 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); 559 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper()));
562 paint->setImageFilter(0); 560 paint->setImageFilter(0);
563 return paint; 561 return paint;
564 } 562 }
565 563
566 } // namespace blink 564 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698