Chromium Code Reviews| Index: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp |
| diff --git a/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp b/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp |
| index 17b4b39f12defdd116529aa1c96d2b49ac095d51..8b51dfb36d8d23e06723bd73f49b5dd6d8b7c01e 100644 |
| --- a/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp |
| +++ b/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp |
| @@ -272,6 +272,40 @@ void CanvasRenderingContext2DState::resetTransform() { |
| m_isTransformInvertible = true; |
| } |
| +sk_sp<SkImageFilter> CanvasRenderingContext2DState::getFilterForOffscreenCanvas( |
| + IntSize canvasSize) const { |
| + if (!m_filterValue) |
| + return nullptr; |
| + |
| + if (m_resolvedFilter) |
| + return m_resolvedFilter; |
| + |
| + FilterOperations operations = |
| + FilterOperationResolver::createOffscreenFilterOperations(*m_filterValue); |
| + |
| + // We can't reuse m_fillPaint and m_strokePaint for the filter, since these |
| + // incorporate the global alpha, which isn't applicable here. |
| + SkPaint fillPaintForFilter; |
| + m_fillStyle->applyToPaint(fillPaintForFilter); |
| + fillPaintForFilter.setColor(m_fillStyle->paintColor()); |
| + SkPaint strokePaintForFilter; |
| + m_strokeStyle->applyToPaint(strokePaintForFilter); |
| + strokePaintForFilter.setColor(m_strokeStyle->paintColor()); |
| + |
| + FilterEffectBuilder filterEffectBuilder( |
| + FloatRect((FloatPoint()), FloatSize(canvasSize)), |
| + 1.0f, // Deliberately ignore zoom on the canvas element. |
| + &fillPaintForFilter, &strokePaintForFilter); |
| + |
| + FilterEffect* lastEffect = filterEffectBuilder.buildFilterEffect(operations); |
| + if (lastEffect) { |
| + m_resolvedFilter = |
| + SkiaImageFilterBuilder::build(lastEffect, ColorSpaceDeviceRGB); |
| + } |
| + |
| + return m_resolvedFilter; |
| +} |
| + |
| sk_sp<SkImageFilter> CanvasRenderingContext2DState::getFilter( |
| Element* styleResolutionHost, |
| IntSize canvasSize, |
| @@ -325,6 +359,13 @@ sk_sp<SkImageFilter> CanvasRenderingContext2DState::getFilter( |
| return m_resolvedFilter; |
| } |
| +bool CanvasRenderingContext2DState::hasFilterForOffscreenCanvas( |
| + IntSize canvasSize) const { |
| + // Checking for a non-null m_filterValue isn't sufficient, since this value |
|
Justin Novosad
2017/01/17 21:59:47
Good point. Do we have a test that covers this?
fserb
2017/01/17 22:10:42
it's just a small detail. It usually will happen w
|
| + // might refer to a non-existent filter. |
| + return !!getFilterForOffscreenCanvas(canvasSize); |
| +} |
| + |
| bool CanvasRenderingContext2DState::hasFilter( |
| Element* styleResolutionHost, |
| IntSize canvasSize, |