From a8d95f899bf3fe404d3cd5c357531ff852c15b29 Mon Sep 17 00:00:00 2001 From: "senorblanco@chromium.org" Date: Fri, 4 Apr 2014 14:46:10 +0000 Subject: [PATCH] Perform perlin noise matrix computations once per frame, not per pixel. Before (Retina MBP): running bench [640 480] perlinnoise 8888: cmsecs = 1853.18 After: running bench [640 480] perlinnoise 8888: cmsecs = 1667.06 Review URL: https://codereview.chromium.org/225583006 git-svn-id: http://skia.googlecode.com/svn/trunk@14060 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/effects/SkPerlinNoiseShader.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp index 7494a54ac4..ed63fafae1 100644 --- a/src/effects/SkPerlinNoiseShader.cpp +++ b/src/effects/SkPerlinNoiseShader.cpp @@ -410,20 +410,8 @@ SkScalar SkPerlinNoiseShader::calculateTurbulenceValueForPoint(int channel, } SkPMColor SkPerlinNoiseShader::shade(const SkPoint& point, StitchData& stitchData) const { - SkMatrix matrix = fMatrix; - matrix.postConcat(getLocalMatrix()); - SkMatrix invMatrix; - if (!matrix.invert(&invMatrix)) { - invMatrix.reset(); - } else { - invMatrix.postConcat(invMatrix); // Square the matrix - } - // This (1,1) translation is due to WebKit's 1 based coordinates for the noise - // (as opposed to 0 based, usually). The same adjustment is in the setData() function. - matrix.postTranslate(SK_Scalar1, SK_Scalar1); SkPoint newPoint; - matrix.mapPoints(&newPoint, &point, 1); - invMatrix.mapPoints(&newPoint, &newPoint, 1); + fMatrix.mapPoints(&newPoint, &point, 1); newPoint.fX = SkScalarRoundToScalar(newPoint.fX); newPoint.fY = SkScalarRoundToScalar(newPoint.fY); @@ -437,7 +425,18 @@ SkPMColor SkPerlinNoiseShader::shade(const SkPoint& point, StitchData& stitchDat bool SkPerlinNoiseShader::setContext(const SkBitmap& device, const SkPaint& paint, const SkMatrix& matrix) { - fMatrix = matrix; + SkMatrix newMatrix = matrix; + newMatrix.postConcat(getLocalMatrix()); + SkMatrix invMatrix; + if (!newMatrix.invert(&invMatrix)) { + invMatrix.reset(); + } + // This (1,1) translation is due to WebKit's 1 based coordinates for the noise + // (as opposed to 0 based, usually). The same adjustment is in the setData() function. + newMatrix.postTranslate(SK_Scalar1, SK_Scalar1); + newMatrix.postConcat(invMatrix); + newMatrix.postConcat(invMatrix); + fMatrix = newMatrix; return INHERITED::setContext(device, paint, matrix); }