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

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: Fixed comments 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
« no previous file with comments | « Source/core/platform/graphics/filters/FETurbulence.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b6834aff3f32046744d7918c922854b760ad49f4 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"
@@ -402,6 +403,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::applySkia()
+{
+ // 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 +445,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";
« no previous file with comments | « Source/core/platform/graphics/filters/FETurbulence.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698