| 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 348 |
| 349 if (!m_resolvedFilter) { | 349 if (!m_resolvedFilter) { |
| 350 RefPtr<ComputedStyle> filterStyle = ComputedStyle::create(); | 350 RefPtr<ComputedStyle> filterStyle = ComputedStyle::create(); |
| 351 // Must set font in case the filter uses any font-relative units (em, ex
) | 351 // Must set font in case the filter uses any font-relative units (em, ex
) |
| 352 filterStyle->setFont(font); | 352 filterStyle->setFont(font); |
| 353 | 353 |
| 354 StyleResolverState resolverState(styleResolutionHost->document(), styleR
esolutionHost, filterStyle.get()); | 354 StyleResolverState resolverState(styleResolutionHost->document(), styleR
esolutionHost, filterStyle.get()); |
| 355 resolverState.setStyle(filterStyle); | 355 resolverState.setStyle(filterStyle); |
| 356 | 356 |
| 357 StyleBuilder::applyProperty(CSSPropertyWebkitFilter, resolverState, m_fi
lterValue.get()); | 357 StyleBuilder::applyProperty(CSSPropertyWebkitFilter, resolverState, m_fi
lterValue.get()); |
| 358 RefPtrWillBeRawPtr<FilterEffectBuilder> filterEffectBuilder = FilterEffe
ctBuilder::create(); | 358 RawPtr<FilterEffectBuilder> filterEffectBuilder = FilterEffectBuilder::c
reate(); |
| 359 | 359 |
| 360 // We can't reuse m_fillPaint and m_strokePaint for the filter, since th
ese incorporate | 360 // We can't reuse m_fillPaint and m_strokePaint for the filter, since th
ese incorporate |
| 361 // the global alpha, which isn't applicable here. | 361 // the global alpha, which isn't applicable here. |
| 362 SkPaint fillPaintForFilter; | 362 SkPaint fillPaintForFilter; |
| 363 SkPaint strokePaintForFilter; | 363 SkPaint strokePaintForFilter; |
| 364 m_fillStyle->applyToPaint(fillPaintForFilter); | 364 m_fillStyle->applyToPaint(fillPaintForFilter); |
| 365 m_strokeStyle->applyToPaint(strokePaintForFilter); | 365 m_strokeStyle->applyToPaint(strokePaintForFilter); |
| 366 fillPaintForFilter.setColor(m_fillStyle->paintColor()); | 366 fillPaintForFilter.setColor(m_fillStyle->paintColor()); |
| 367 strokePaintForFilter.setColor(m_strokeStyle->paintColor()); | 367 strokePaintForFilter.setColor(m_strokeStyle->paintColor()); |
| 368 FloatSize floatCanvasSize(canvasSize); | 368 FloatSize floatCanvasSize(canvasSize); |
| 369 const double effectiveZoom = 1.0; // Deliberately ignore zoom on the can
vas element | 369 const double effectiveZoom = 1.0; // Deliberately ignore zoom on the can
vas element |
| 370 filterEffectBuilder->build(styleResolutionHost, filterStyle->filter(), e
ffectiveZoom, &floatCanvasSize, &fillPaintForFilter, &strokePaintForFilter); | 370 filterEffectBuilder->build(styleResolutionHost, filterStyle->filter(), e
ffectiveZoom, &floatCanvasSize, &fillPaintForFilter, &strokePaintForFilter); |
| 371 | 371 |
| 372 SkiaImageFilterBuilder imageFilterBuilder; | 372 SkiaImageFilterBuilder imageFilterBuilder; |
| 373 RefPtrWillBeRawPtr<FilterEffect> lastEffect = filterEffectBuilder->lastE
ffect(); | 373 RawPtr<FilterEffect> lastEffect = filterEffectBuilder->lastEffect(); |
| 374 m_resolvedFilter = imageFilterBuilder.build(lastEffect.get(), ColorSpace
DeviceRGB); | 374 m_resolvedFilter = imageFilterBuilder.build(lastEffect.get(), ColorSpace
DeviceRGB); |
| 375 } | 375 } |
| 376 | 376 |
| 377 return m_resolvedFilter.get(); | 377 return m_resolvedFilter.get(); |
| 378 } | 378 } |
| 379 | 379 |
| 380 bool CanvasRenderingContext2DState::hasFilter(Element* styleResolutionHost, cons
t Font& font, IntSize canvasSize) const | 380 bool CanvasRenderingContext2DState::hasFilter(Element* styleResolutionHost, cons
t Font& font, IntSize canvasSize) const |
| 381 { | 381 { |
| 382 // Checking for a non-null m_filterValue isn't sufficient, since this value | 382 // Checking for a non-null m_filterValue isn't sufficient, since this value |
| 383 // might refer to a non-existent filter. | 383 // might refer to a non-existent filter. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 m_shadowBlur = shadowBlur; | 457 m_shadowBlur = shadowBlur; |
| 458 shadowParameterChanged(); | 458 shadowParameterChanged(); |
| 459 } | 459 } |
| 460 | 460 |
| 461 void CanvasRenderingContext2DState::setShadowColor(SkColor shadowColor) | 461 void CanvasRenderingContext2DState::setShadowColor(SkColor shadowColor) |
| 462 { | 462 { |
| 463 m_shadowColor = shadowColor; | 463 m_shadowColor = shadowColor; |
| 464 shadowParameterChanged(); | 464 shadowParameterChanged(); |
| 465 } | 465 } |
| 466 | 466 |
| 467 void CanvasRenderingContext2DState::setFilter(PassRefPtrWillBeRawPtr<CSSValue> f
ilterValue) | 467 void CanvasRenderingContext2DState::setFilter(RawPtr<CSSValue> filterValue) |
| 468 { | 468 { |
| 469 m_filterValue = filterValue; | 469 m_filterValue = filterValue; |
| 470 m_resolvedFilter.clear(); | 470 m_resolvedFilter.clear(); |
| 471 } | 471 } |
| 472 | 472 |
| 473 void CanvasRenderingContext2DState::setGlobalComposite(SkXfermode::Mode mode) | 473 void CanvasRenderingContext2DState::setGlobalComposite(SkXfermode::Mode mode) |
| 474 { | 474 { |
| 475 m_strokePaint.setXfermodeMode(mode); | 475 m_strokePaint.setXfermodeMode(mode); |
| 476 m_fillPaint.setXfermodeMode(mode); | 476 m_fillPaint.setXfermodeMode(mode); |
| 477 m_imagePaint.setXfermodeMode(mode); | 477 m_imagePaint.setXfermodeMode(mode); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 paint->setLooper(0); | 597 paint->setLooper(0); |
| 598 paint->setImageFilter(shadowAndForegroundImageFilter()); | 598 paint->setImageFilter(shadowAndForegroundImageFilter()); |
| 599 return paint; | 599 return paint; |
| 600 } | 600 } |
| 601 paint->setLooper(shadowAndForegroundDrawLooper()); | 601 paint->setLooper(shadowAndForegroundDrawLooper()); |
| 602 paint->setImageFilter(0); | 602 paint->setImageFilter(0); |
| 603 return paint; | 603 return paint; |
| 604 } | 604 } |
| 605 | 605 |
| 606 } // namespace blink | 606 } // namespace blink |
| OLD | NEW |