| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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.reset(); | |
| 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 16 matching lines...) Expand all Loading... |
| 328 if (m_resolvedFilter) { | 326 if (m_resolvedFilter) { |
| 329 updateFilterReferences(toHTMLCanvasElement(styleResolutionHost), con
text, filterStyle->filter()); | 327 updateFilterReferences(toHTMLCanvasElement(styleResolutionHost), con
text, filterStyle->filter()); |
| 330 if (lastEffect->originTainted()) | 328 if (lastEffect->originTainted()) |
| 331 context->setOriginTainted(); | 329 context->setOriginTainted(); |
| 332 } | 330 } |
| 333 } | 331 } |
| 334 | 332 |
| 335 return m_resolvedFilter.get(); | 333 return m_resolvedFilter.get(); |
| 336 } | 334 } |
| 337 | 335 |
| 338 bool CanvasRenderingContext2DState::hasFilter(Element* styleResolutionHost, cons
t Font& font, IntSize canvasSize, CanvasRenderingContext2D* context) const | 336 bool CanvasRenderingContext2DState::hasFilter(Element* styleResolutionHost, IntS
ize canvasSize, CanvasRenderingContext2D* context) const |
| 339 { | 337 { |
| 340 // Checking for a non-null m_filterValue isn't sufficient, since this value | 338 // Checking for a non-null m_filterValue isn't sufficient, since this value |
| 341 // might refer to a non-existent filter. | 339 // might refer to a non-existent filter. |
| 342 return !!getFilter(styleResolutionHost, font, canvasSize, context); | 340 return !!getFilter(styleResolutionHost, canvasSize, context); |
| 343 } | 341 } |
| 344 | 342 |
| 345 void CanvasRenderingContext2DState::clearResolvedFilter() const | 343 void CanvasRenderingContext2DState::clearResolvedFilter() const |
| 346 { | 344 { |
| 347 m_resolvedFilter.reset(); | 345 m_resolvedFilter.reset(); |
| 348 } | 346 } |
| 349 | 347 |
| 350 SkDrawLooper* CanvasRenderingContext2DState::emptyDrawLooper() const | 348 SkDrawLooper* CanvasRenderingContext2DState::emptyDrawLooper() const |
| 351 { | 349 { |
| 352 if (!m_emptyDrawLooper) { | 350 if (!m_emptyDrawLooper) { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 paint->setLooper(0); | 558 paint->setLooper(0); |
| 561 paint->setImageFilter(shadowAndForegroundImageFilter()); | 559 paint->setImageFilter(shadowAndForegroundImageFilter()); |
| 562 return paint; | 560 return paint; |
| 563 } | 561 } |
| 564 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); | 562 paint->setLooper(sk_ref_sp(shadowAndForegroundDrawLooper())); |
| 565 paint->setImageFilter(0); | 563 paint->setImageFilter(0); |
| 566 return paint; | 564 return paint; |
| 567 } | 565 } |
| 568 | 566 |
| 569 } // namespace blink | 567 } // namespace blink |
| OLD | NEW |