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 dcc455b8659eda3ccc7c754e942228e0c205f3db..98c248c184bf90f8ef1733e6bb80347e2a4492b3 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, |
| @@ -329,6 +363,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 |
| + // might refer to a non-existent filter. |
| + return !!getFilterForOffscreenCanvas(canvasSize); |
|
esprehn
2017/01/27 19:44:39
This is super wasteful since you do all the work t
fserb
2017/01/27 19:54:47
The problem is there's no way to know if you actua
|
| +} |
| + |
| bool CanvasRenderingContext2DState::hasFilter( |
| Element* styleResolutionHost, |
| IntSize canvasSize, |