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 94fbc5cda53008ab813598cd8b48e27211c42e3d..510dce7e35379fcd02d19d9e1b8ada5b0547de63 100644 |
--- a/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp |
+++ b/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp |
@@ -272,6 +272,41 @@ 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::createFilterOperations(nullptr, *m_filterValue); |
esprehn
2016/11/22 01:38:37
createOffscreen(...)
it's more clear than passing
fserb
2017/01/17 17:58:44
done.
|
+ |
+ // 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( |
+ nullptr, // styleResolutionHost |
esprehn
2016/11/22 01:38:37
Probably want two constructors instead, add one th
fserb
2017/01/17 17:58:44
done.
|
+ 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 +360,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); |
+} |
+ |
bool CanvasRenderingContext2DState::hasFilter( |
Element* styleResolutionHost, |
IntSize canvasSize, |