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

Unified Diff: Source/core/platform/graphics/filters/FETurbulence.cpp

Issue 14263013: Added Skia turbulence filter to Webkit. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Adding TestExpectations typo-related failures Created 7 years, 6 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: Source/core/platform/graphics/filters/FETurbulence.cpp
diff --git a/Source/core/platform/graphics/filters/FETurbulence.cpp b/Source/core/platform/graphics/filters/FETurbulence.cpp
index a15127db6f637ebafb9d044ebb651b81a71860f8..2c7e512c97c95d3b2cdba9568b75fd9b26d48c12 100644
--- a/Source/core/platform/graphics/filters/FETurbulence.cpp
+++ b/Source/core/platform/graphics/filters/FETurbulence.cpp
@@ -26,7 +26,8 @@
#include "config.h"
#include "core/platform/graphics/filters/FETurbulence.h"
-
+#include "SkPerlinNoiseShader.h"
+#include "SkRectShaderImageFilter.h"
#include "core/platform/graphics/filters/Filter.h"
#include "core/platform/text/TextStream.h"
#include "core/rendering/RenderTreeAsText.h"
@@ -365,7 +366,14 @@ void FETurbulence::applySoftware()
return;
}
- PaintingData paintingData(m_seed, roundedIntSize(filterPrimitiveSubregion().size()));
+ // FIXME : Ideally, filterPrimitiveSubregion() should do the trick for all cases, but since
+ // it's currently not being set when an SVG filter is used in CSS, we have to use
Stephen White 2013/06/13 17:28:06 BTW, I think filterPrimitiveSubregion() should now
sugoi 2013/06/13 17:46:33 Done.
+ // absolutePaintRect() instead (which includes the zoom factor, unfortunately).
+ // This code should be reverted to only use filterPrimitiveSubregion() directly
+ // as soon as it works in all cases.
+ IntSize noiseSize = roundedIntSize(filterPrimitiveSubregion().size());
+ PaintingData paintingData(m_seed,
+ noiseSize.isEmpty() ? absolutePaintRect().size() : noiseSize);
initPaint(paintingData);
int optimalThreadNumber = (absolutePaintRect().width() * absolutePaintRect().height()) / s_minimalRectDimension;
@@ -402,6 +410,41 @@ void FETurbulence::applySoftware()
fillRegion(pixelArray, paintingData, 0, absolutePaintRect().height());
}
+SkShader* FETurbulence::createShader(const IntRect& filterRegion) const
+{
+ const SkISize size = SkISize::Make(filterRegion.width(), filterRegion.height());
+ return (type() == FETURBULENCE_TYPE_FRACTALNOISE) ?
+ SkPerlinNoiseShader::CreateFractalNoise(SkFloatToScalar(baseFrequencyX()),
+ SkFloatToScalar(baseFrequencyY()), numOctaves(), SkFloatToScalar(seed()),
+ stitchTiles() ? &size : 0) :
+ SkPerlinNoiseShader::CreateTubulence(SkFloatToScalar(baseFrequencyX()),
+ SkFloatToScalar(baseFrequencyY()), numOctaves(), SkFloatToScalar(seed()),
+ stitchTiles() ? &size : 0);
+}
+
+bool FETurbulence::platformApplySkia()
+{
+ // For now, only use the skia implementation for accelerated rendering.
+ if (filter()->renderingMode() != Accelerated)
+ return false;
+
+ ImageBuffer* resultImage = createImageBufferResult();
+ if (!resultImage)
+ return false;
+
+ const IntRect filterRegion = absolutePaintRect();
+
+ SkPaint paint;
+ paint.setShader(createShader(filterRegion))->unref();
+ resultImage->context()->drawRect((SkRect)filterRegion, paint);
+ return true;
+}
+
+SkImageFilter* FETurbulence::createImageFilter(SkiaImageFilterBuilder* builder)
+{
+ return SkRectShaderImageFilter::Create(createShader(IntRect()), SkRect());
+}
+
static TextStream& operator<<(TextStream& ts, const TurbulenceType& type)
{
switch (type) {
@@ -409,7 +452,7 @@ static TextStream& operator<<(TextStream& ts, const TurbulenceType& type)
ts << "UNKNOWN";
break;
case FETURBULENCE_TYPE_TURBULENCE:
- ts << "TURBULANCE";
+ ts << "TURBULENCE";
break;
case FETURBULENCE_TYPE_FRACTALNOISE:
ts << "NOISE";

Powered by Google App Engine
This is Rietveld 408576698