Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(768)

Unified Diff: third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp

Issue 2326633002: Adds filter support for offscreen canvas (Closed)
Patch Set: Sync Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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);
+}
+
bool CanvasRenderingContext2DState::hasFilter(
Element* styleResolutionHost,
IntSize canvasSize,

Powered by Google App Engine
This is Rietveld 408576698