| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "modules/canvas2d/CanvasRenderingContext2DState.h" | 7 #include "modules/canvas2d/CanvasRenderingContext2DState.h" |
| 8 | 8 |
| 9 #include "core/css/CSSFontSelector.h" | 9 #include "core/css/CSSFontSelector.h" |
| 10 #include "core/css/resolver/FilterOperationResolver.h" | 10 #include "core/css/resolver/FilterOperationResolver.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 CanvasRenderingContext2DState::CanvasRenderingContext2DState() | 29 CanvasRenderingContext2DState::CanvasRenderingContext2DState() |
| 30 : m_unrealizedSaveCount(0) | 30 : m_unrealizedSaveCount(0) |
| 31 , m_strokeStyle(CanvasStyle::createFromRGBA(SK_ColorBLACK)) | 31 , m_strokeStyle(CanvasStyle::createFromRGBA(SK_ColorBLACK)) |
| 32 , m_fillStyle(CanvasStyle::createFromRGBA(SK_ColorBLACK)) | 32 , m_fillStyle(CanvasStyle::createFromRGBA(SK_ColorBLACK)) |
| 33 , m_shadowBlur(0) | 33 , m_shadowBlur(0) |
| 34 , m_shadowColor(Color::transparent) | 34 , m_shadowColor(Color::transparent) |
| 35 , m_globalAlpha(1) | 35 , m_globalAlpha(1) |
| 36 , m_lineDashOffset(0) | 36 , m_lineDashOffset(0) |
| 37 , m_unparsedFont(defaultFont) | 37 , m_unparsedFont(defaultFont) |
| 38 , m_unparsedFilter(defaultFilter) | 38 , m_unparsedFilter(defaultFilter) |
| 39 , m_unparsedBackdropFilter(defaultFilter) |
| 39 , m_textAlign(StartTextAlign) | 40 , m_textAlign(StartTextAlign) |
| 40 , m_textBaseline(AlphabeticTextBaseline) | 41 , m_textBaseline(AlphabeticTextBaseline) |
| 41 , m_direction(DirectionInherit) | 42 , m_direction(DirectionInherit) |
| 42 , m_realizedFont(false) | 43 , m_realizedFont(false) |
| 43 , m_isTransformInvertible(true) | 44 , m_isTransformInvertible(true) |
| 44 , m_hasClip(false) | 45 , m_hasClip(false) |
| 45 , m_hasComplexClip(false) | 46 , m_hasComplexClip(false) |
| 46 , m_fillStyleDirty(true) | 47 , m_fillStyleDirty(true) |
| 47 , m_strokeStyleDirty(true) | 48 , m_strokeStyleDirty(true) |
| 48 , m_lineDashDirty(false) | 49 , m_lineDashDirty(false) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 78 , m_shadowAndForegroundDrawLooper(other.m_shadowAndForegroundDrawLooper) | 79 , m_shadowAndForegroundDrawLooper(other.m_shadowAndForegroundDrawLooper) |
| 79 , m_shadowOnlyImageFilter(other.m_shadowOnlyImageFilter) | 80 , m_shadowOnlyImageFilter(other.m_shadowOnlyImageFilter) |
| 80 , m_shadowAndForegroundImageFilter(other.m_shadowAndForegroundImageFilter) | 81 , m_shadowAndForegroundImageFilter(other.m_shadowAndForegroundImageFilter) |
| 81 , m_globalAlpha(other.m_globalAlpha) | 82 , m_globalAlpha(other.m_globalAlpha) |
| 82 , m_transform(other.m_transform) | 83 , m_transform(other.m_transform) |
| 83 , m_lineDash(other.m_lineDash) | 84 , m_lineDash(other.m_lineDash) |
| 84 , m_lineDashOffset(other.m_lineDashOffset) | 85 , m_lineDashOffset(other.m_lineDashOffset) |
| 85 , m_unparsedFont(other.m_unparsedFont) | 86 , m_unparsedFont(other.m_unparsedFont) |
| 86 , m_font(other.m_font) | 87 , m_font(other.m_font) |
| 87 , m_unparsedFilter(other.m_unparsedFilter) | 88 , m_unparsedFilter(other.m_unparsedFilter) |
| 89 , m_unparsedBackdropFilter(other.m_unparsedBackdropFilter) |
| 88 , m_filterValue(other.m_filterValue) | 90 , m_filterValue(other.m_filterValue) |
| 89 , m_resolvedFilter(other.m_resolvedFilter) | 91 , m_resolvedFilter(other.m_resolvedFilter) |
| 92 , m_backdropFilterValue(other.m_backdropFilterValue) |
| 93 , m_resolvedBackdropFilter(other.m_resolvedBackdropFilter) |
| 90 , m_textAlign(other.m_textAlign) | 94 , m_textAlign(other.m_textAlign) |
| 91 , m_textBaseline(other.m_textBaseline) | 95 , m_textBaseline(other.m_textBaseline) |
| 92 , m_direction(other.m_direction) | 96 , m_direction(other.m_direction) |
| 93 , m_realizedFont(other.m_realizedFont) | 97 , m_realizedFont(other.m_realizedFont) |
| 94 , m_isTransformInvertible(other.m_isTransformInvertible) | 98 , m_isTransformInvertible(other.m_isTransformInvertible) |
| 95 , m_hasClip(other.m_hasClip) | 99 , m_hasClip(other.m_hasClip) |
| 96 , m_hasComplexClip(other.m_hasComplexClip) | 100 , m_hasComplexClip(other.m_hasComplexClip) |
| 97 , m_fillStyleDirty(other.m_fillStyleDirty) | 101 , m_fillStyleDirty(other.m_fillStyleDirty) |
| 98 , m_strokeStyleDirty(other.m_strokeStyleDirty) | 102 , m_strokeStyleDirty(other.m_strokeStyleDirty) |
| 99 , m_lineDashDirty(other.m_lineDashDirty) | 103 , m_lineDashDirty(other.m_lineDashDirty) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 169 |
| 166 void CanvasRenderingContext2DState::fontsNeedUpdate(CSSFontSelector* fontSelecto
r) | 170 void CanvasRenderingContext2DState::fontsNeedUpdate(CSSFontSelector* fontSelecto
r) |
| 167 { | 171 { |
| 168 ASSERT_ARG(fontSelector, fontSelector == m_font.fontSelector()); | 172 ASSERT_ARG(fontSelector, fontSelector == m_font.fontSelector()); |
| 169 ASSERT(m_realizedFont); | 173 ASSERT(m_realizedFont); |
| 170 | 174 |
| 171 m_font.update(fontSelector); | 175 m_font.update(fontSelector); |
| 172 // FIXME: We only really need to invalidate the resolved filter if the font | 176 // FIXME: We only really need to invalidate the resolved filter if the font |
| 173 // update above changed anything and the filter uses font-dependent units. | 177 // update above changed anything and the filter uses font-dependent units. |
| 174 m_resolvedFilter.clear(); | 178 m_resolvedFilter.clear(); |
| 179 m_resolvedBackdropFilter.clear(); // TODO(hendrikw): Not so sure if this is
needed. |
| 175 } | 180 } |
| 176 | 181 |
| 177 DEFINE_TRACE(CanvasRenderingContext2DState) | 182 DEFINE_TRACE(CanvasRenderingContext2DState) |
| 178 { | 183 { |
| 179 visitor->trace(m_strokeStyle); | 184 visitor->trace(m_strokeStyle); |
| 180 visitor->trace(m_fillStyle); | 185 visitor->trace(m_fillStyle); |
| 181 visitor->trace(m_filterValue); | 186 visitor->trace(m_filterValue); |
| 187 visitor->trace(m_backdropFilterValue); |
| 182 CSSFontSelectorClient::trace(visitor); | 188 CSSFontSelectorClient::trace(visitor); |
| 183 } | 189 } |
| 184 | 190 |
| 185 void CanvasRenderingContext2DState::setLineDashOffset(float offset) | 191 void CanvasRenderingContext2DState::setLineDashOffset(float offset) |
| 186 { | 192 { |
| 187 m_lineDashOffset = offset; | 193 m_lineDashOffset = offset; |
| 188 m_lineDashDirty = true; | 194 m_lineDashDirty = true; |
| 189 } | 195 } |
| 190 | 196 |
| 191 void CanvasRenderingContext2DState::setLineDash(const Vector<float>& dash) | 197 void CanvasRenderingContext2DState::setLineDash(const Vector<float>& dash) |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 if (m_realizedFont) | 306 if (m_realizedFont) |
| 301 static_cast<CSSFontSelector*>(m_font.fontSelector())->unregisterForInval
idationCallbacks(this); | 307 static_cast<CSSFontSelector*>(m_font.fontSelector())->unregisterForInval
idationCallbacks(this); |
| 302 #endif | 308 #endif |
| 303 m_font = font; | 309 m_font = font; |
| 304 m_font.update(selector); | 310 m_font.update(selector); |
| 305 m_realizedFont = true; | 311 m_realizedFont = true; |
| 306 selector->registerForInvalidationCallbacks(this); | 312 selector->registerForInvalidationCallbacks(this); |
| 307 // FIXME: We only really need to invalidate the resolved filter if it | 313 // FIXME: We only really need to invalidate the resolved filter if it |
| 308 // uses font-relative units. | 314 // uses font-relative units. |
| 309 m_resolvedFilter.clear(); | 315 m_resolvedFilter.clear(); |
| 316 m_resolvedBackdropFilter.clear(); // TODO(hendrikw): Not so sure if this is
needed. |
| 310 } | 317 } |
| 311 | 318 |
| 312 const Font& CanvasRenderingContext2DState::font() const | 319 const Font& CanvasRenderingContext2DState::font() const |
| 313 { | 320 { |
| 314 ASSERT(m_realizedFont); | 321 ASSERT(m_realizedFont); |
| 315 return m_font; | 322 return m_font; |
| 316 } | 323 } |
| 317 | 324 |
| 318 void CanvasRenderingContext2DState::setTransform(const AffineTransform& transfor
m) | 325 void CanvasRenderingContext2DState::setTransform(const AffineTransform& transfor
m) |
| 319 { | 326 { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 348 filterEffectBuilder->build(styleResolutionHost, filterStyle->filter(), e
ffectiveZoom); | 355 filterEffectBuilder->build(styleResolutionHost, filterStyle->filter(), e
ffectiveZoom); |
| 349 | 356 |
| 350 SkiaImageFilterBuilder imageFilterBuilder; | 357 SkiaImageFilterBuilder imageFilterBuilder; |
| 351 RefPtrWillBeRawPtr<FilterEffect> lastEffect = filterEffectBuilder->lastE
ffect(); | 358 RefPtrWillBeRawPtr<FilterEffect> lastEffect = filterEffectBuilder->lastE
ffect(); |
| 352 m_resolvedFilter = imageFilterBuilder.build(lastEffect.get(), ColorSpace
DeviceRGB); | 359 m_resolvedFilter = imageFilterBuilder.build(lastEffect.get(), ColorSpace
DeviceRGB); |
| 353 } | 360 } |
| 354 | 361 |
| 355 return m_resolvedFilter.get(); | 362 return m_resolvedFilter.get(); |
| 356 } | 363 } |
| 357 | 364 |
| 365 SkImageFilter* CanvasRenderingContext2DState::getBackdropFilter(Element* styleRe
solutionHost, const Font& font) const |
| 366 { |
| 367 // TODO(hendrikw): Better understand what this function is doing and determi
ne if we can reuse getFilter, |
| 368 // of if this function needs to be modified. |
| 369 if (!m_backdropFilterValue) |
| 370 return nullptr; |
| 371 |
| 372 if (!m_resolvedBackdropFilter) { |
| 373 RefPtr<ComputedStyle> filterStyle = ComputedStyle::create(); |
| 374 // Must set font in case the filter uses any font-relative units (em, ex
) |
| 375 filterStyle->setFont(font); |
| 376 |
| 377 StyleResolverState resolverState(styleResolutionHost->document(), styleR
esolutionHost, filterStyle.get()); |
| 378 resolverState.setStyle(filterStyle); |
| 379 |
| 380 // TODO(junov): crbug.com/502877 Feed m_fillStyle and m_strokeStyle into
FillPaint and |
| 381 // StrokePaint respectively for filters that reference SVG. |
| 382 StyleBuilder::applyProperty(CSSPropertyBackdropFilter, resolverState, m_
backdropFilterValue.get()); |
| 383 RefPtrWillBeRawPtr<FilterEffectBuilder> filterEffectBuilder = FilterEffe
ctBuilder::create(); |
| 384 const float effectiveZoom = 1.0f; // Deliberately ignore zoom on the can
vas element |
| 385 filterEffectBuilder->build(styleResolutionHost, filterStyle->filter(), e
ffectiveZoom); |
| 386 |
| 387 SkiaImageFilterBuilder imageFilterBuilder; |
| 388 RefPtrWillBeRawPtr<FilterEffect> lastEffect = filterEffectBuilder->lastE
ffect(); |
| 389 m_resolvedBackdropFilter = imageFilterBuilder.build(lastEffect.get(), Co
lorSpaceDeviceRGB); |
| 390 } |
| 391 |
| 392 return m_resolvedBackdropFilter.get(); |
| 393 } |
| 394 |
| 358 SkDrawLooper* CanvasRenderingContext2DState::emptyDrawLooper() const | 395 SkDrawLooper* CanvasRenderingContext2DState::emptyDrawLooper() const |
| 359 { | 396 { |
| 360 if (!m_emptyDrawLooper) { | 397 if (!m_emptyDrawLooper) { |
| 361 OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create(
); | 398 OwnPtr<DrawLooperBuilder> drawLooperBuilder = DrawLooperBuilder::create(
); |
| 362 m_emptyDrawLooper = drawLooperBuilder->detachDrawLooper(); | 399 m_emptyDrawLooper = drawLooperBuilder->detachDrawLooper(); |
| 363 } | 400 } |
| 364 return m_emptyDrawLooper.get(); | 401 return m_emptyDrawLooper.get(); |
| 365 } | 402 } |
| 366 | 403 |
| 367 SkDrawLooper* CanvasRenderingContext2DState::shadowOnlyDrawLooper() const | 404 SkDrawLooper* CanvasRenderingContext2DState::shadowOnlyDrawLooper() const |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 m_shadowColor = shadowColor; | 471 m_shadowColor = shadowColor; |
| 435 shadowParameterChanged(); | 472 shadowParameterChanged(); |
| 436 } | 473 } |
| 437 | 474 |
| 438 void CanvasRenderingContext2DState::setFilter(PassRefPtrWillBeRawPtr<CSSValue> f
ilterValue) | 475 void CanvasRenderingContext2DState::setFilter(PassRefPtrWillBeRawPtr<CSSValue> f
ilterValue) |
| 439 { | 476 { |
| 440 m_filterValue = filterValue; | 477 m_filterValue = filterValue; |
| 441 m_resolvedFilter.clear(); | 478 m_resolvedFilter.clear(); |
| 442 } | 479 } |
| 443 | 480 |
| 481 void CanvasRenderingContext2DState::setBackdropFilter(PassRefPtrWillBeRawPtr<CSS
Value> filterValue) |
| 482 { |
| 483 m_backdropFilterValue = filterValue; |
| 484 m_resolvedBackdropFilter.clear(); |
| 485 } |
| 486 |
| 444 void CanvasRenderingContext2DState::setGlobalComposite(SkXfermode::Mode mode) | 487 void CanvasRenderingContext2DState::setGlobalComposite(SkXfermode::Mode mode) |
| 445 { | 488 { |
| 446 m_strokePaint.setXfermodeMode(mode); | 489 m_strokePaint.setXfermodeMode(mode); |
| 447 m_fillPaint.setXfermodeMode(mode); | 490 m_fillPaint.setXfermodeMode(mode); |
| 448 m_imagePaint.setXfermodeMode(mode); | 491 m_imagePaint.setXfermodeMode(mode); |
| 449 } | 492 } |
| 450 | 493 |
| 451 SkXfermode::Mode CanvasRenderingContext2DState::globalComposite() const | 494 SkXfermode::Mode CanvasRenderingContext2DState::globalComposite() const |
| 452 { | 495 { |
| 453 SkXfermode* xferMode = m_strokePaint.getXfermode(); | 496 SkXfermode* xferMode = m_strokePaint.getXfermode(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 paint->setLooper(0); | 567 paint->setLooper(0); |
| 525 paint->setImageFilter(shadowAndForegroundImageFilter()); | 568 paint->setImageFilter(shadowAndForegroundImageFilter()); |
| 526 return paint; | 569 return paint; |
| 527 } | 570 } |
| 528 paint->setLooper(shadowAndForegroundDrawLooper()); | 571 paint->setLooper(shadowAndForegroundDrawLooper()); |
| 529 paint->setImageFilter(0); | 572 paint->setImageFilter(0); |
| 530 return paint; | 573 return paint; |
| 531 } | 574 } |
| 532 | 575 |
| 533 } // blink | 576 } // blink |
| OLD | NEW |