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

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

Issue 2326633002: Adds filter support for offscreen canvas (Closed)
Patch Set: New version without StyleResolver Created 4 years, 2 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 4ea962955da8ef164cddfa921b0bb7a8a0a408b4..8eaafb83cb4c1dfc30afd33e90816444410afb75 100644
--- a/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp
+++ b/third_party/WebKit/Source/modules/canvas2d/CanvasRenderingContext2DState.cpp
@@ -279,6 +279,39 @@ static void updateFilterReferences(HTMLCanvasElement* canvasElement,
context->addFilterReferences(filters, canvasElement->document());
}
+SkImageFilter* CanvasRenderingContext2DState::getFilterWithoutDocument(
+ IntSize canvasSize) const {
+ if (!m_filterValue)
+ return nullptr;
+
+ if (m_resolvedFilter)
+ return m_resolvedFilter.get();
+
+ FilterOperations op =
+ FilterOperationResolver::createFilterOperations(nullptr, *m_filterValue);
meade_UTC10 2016/10/26 06:57:34 Nit: don't abbreviate variable names.
fserb 2016/10/26 19:08:26 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, FloatRect((FloatPoint()), FloatSize(canvasSize)),
Justin Novosad 2016/10/24 18:51:22 This nullptr lacks readability. Please use a temp
fserb 2016/10/26 19:08:26 done
+ 1.0f, // Deliberately ignore zoom on the canvas element.
+ &fillPaintForFilter, &strokePaintForFilter);
meade_UTC10 2016/10/26 06:57:34 It looks like these get stored in the FilterEffect
fserb 2016/10/26 19:08:26 yep. They are used the same way on getFilter(). Th
+
+ if (FilterEffect* lastEffect = filterEffectBuilder.buildFilterEffect(op)) {
+ m_resolvedFilter =
+ SkiaImageFilterBuilder::build(lastEffect, ColorSpaceDeviceRGB);
+ }
+
+ return m_resolvedFilter.get();
+}
+
SkImageFilter* CanvasRenderingContext2DState::getFilter(
Element* styleResolutionHost,
IntSize canvasSize,
@@ -333,6 +366,13 @@ SkImageFilter* CanvasRenderingContext2DState::getFilter(
return m_resolvedFilter.get();
}
+bool CanvasRenderingContext2DState::hasFilterWithoutDocument(
+ IntSize canvasSize) const {
+ // Checking for a non-null m_filterValue isn't sufficient, since this value
+ // might refer to a non-existent filter.
+ return !!getFilterWithoutDocument(canvasSize);
+}
+
bool CanvasRenderingContext2DState::hasFilter(
Element* styleResolutionHost,
IntSize canvasSize,

Powered by Google App Engine
This is Rietveld 408576698