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

Unified Diff: src/effects/SkPerlinNoiseShader.cpp

Issue 225583006: Perform perlin noise matrix computations once per frame, not per pixel. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Perform matrix computations once per frame, not one per span Created 6 years, 9 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkPerlinNoiseShader.cpp
diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp
index 7494a54ac4c38d199cab494c32ecdc39003d108e..ed63fafae14c14093c5f66c21f482c9011ffa482 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);
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698