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

Side by Side Diff: src/effects/SkPerlinNoiseShader.cpp

Issue 169973002: Begin making SkPerlinNoiseShader const. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Don't lazily initialize bitmaps. Use setPixels 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 unified diff | Download patch
« no previous file with comments | « include/effects/SkPerlinNoiseShader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkDither.h" 8 #include "SkDither.h"
9 #include "SkPerlinNoiseShader.h" 9 #include "SkPerlinNoiseShader.h"
10 #include "SkColorFilter.h" 10 #include "SkColorFilter.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 fWrapY == other.fWrapY; 74 fWrapY == other.fWrapY;
75 } 75 }
76 76
77 int fWidth; // How much to subtract to wrap for stitching. 77 int fWidth; // How much to subtract to wrap for stitching.
78 int fWrapX; // Minimum value to wrap. 78 int fWrapX; // Minimum value to wrap.
79 int fHeight; 79 int fHeight;
80 int fWrapY; 80 int fWrapY;
81 }; 81 };
82 82
83 struct SkPerlinNoiseShader::PaintingData { 83 struct SkPerlinNoiseShader::PaintingData {
84 PaintingData(const SkISize& tileSize) 84 PaintingData(const SkISize& tileSize, SkScalar seed,
85 : fSeed(0) 85 SkScalar baseFrequencyX, SkScalar baseFrequencyY)
86 , fTileSize(tileSize) 86 : fTileSize(tileSize)
87 , fPermutationsBitmap(NULL) 87 , fBaseFrequency(SkPoint::Make(baseFrequencyX, baseFrequencyY))
88 , fNoiseBitmap(NULL) 88 {
89 {} 89 this->init(seed);
90 if (!fTileSize.isEmpty()) {
91 this->stitch();
92 }
90 93
91 ~PaintingData() 94 #if SK_SUPPORT_GPU && !defined(SK_USE_SIMPLEX_NOISE)
92 { 95 fPermutationsBitmap.setConfig(SkImageInfo::MakeA8(kBlockSize, 1));
93 SkDELETE(fPermutationsBitmap); 96 fPermutationsBitmap.setPixels(fLatticeSelector);
94 SkDELETE(fNoiseBitmap); 97
98 fNoiseBitmap.setConfig(SkImageInfo::MakeN32Premul(kBlockSize, 4));
99 fNoiseBitmap.setPixels(fNoise[0][0]);
100 #endif
95 } 101 }
96 102
97 int fSeed; 103 int fSeed;
98 uint8_t fLatticeSelector[kBlockSize]; 104 uint8_t fLatticeSelector[kBlockSize];
99 uint16_t fNoise[4][kBlockSize][2]; 105 uint16_t fNoise[4][kBlockSize][2];
100 SkPoint fGradient[4][kBlockSize]; 106 SkPoint fGradient[4][kBlockSize];
101 SkISize fTileSize; 107 SkISize fTileSize;
102 SkVector fBaseFrequency; 108 SkVector fBaseFrequency;
103 StitchData fStitchDataInit; 109 StitchData fStitchDataInit;
104 110
105 private: 111 private:
106 112
107 SkBitmap* fPermutationsBitmap; 113 #if SK_SUPPORT_GPU && !defined(SK_USE_SIMPLEX_NOISE)
108 SkBitmap* fNoiseBitmap; 114 SkBitmap fPermutationsBitmap;
109 115 SkBitmap fNoiseBitmap;
110 public: 116 #endif
111 117
112 inline int random() { 118 inline int random() {
113 static const int gRandAmplitude = 16807; // 7**5; primitive root of m 119 static const int gRandAmplitude = 16807; // 7**5; primitive root of m
114 static const int gRandQ = 127773; // m / a 120 static const int gRandQ = 127773; // m / a
115 static const int gRandR = 2836; // m % a 121 static const int gRandR = 2836; // m % a
116 122
117 int result = gRandAmplitude * (fSeed % gRandQ) - gRandR * (fSeed / gRand Q); 123 int result = gRandAmplitude * (fSeed % gRandQ) - gRandR * (fSeed / gRand Q);
118 if (result <= 0) 124 if (result <= 0)
119 result += kRandMaximum; 125 result += kRandMaximum;
120 fSeed = result; 126 fSeed = result;
121 return result; 127 return result;
122 } 128 }
123 129
130 // Only called once. Could be part of the constructor.
124 void init(SkScalar seed) 131 void init(SkScalar seed)
125 { 132 {
126 static const SkScalar gInvBlockSizef = SkScalarInvert(SkIntToScalar(kBlo ckSize)); 133 static const SkScalar gInvBlockSizef = SkScalarInvert(SkIntToScalar(kBlo ckSize));
127 134
128 // According to the SVG spec, we must truncate (not round) the seed valu e. 135 // According to the SVG spec, we must truncate (not round) the seed valu e.
129 fSeed = SkScalarTruncToInt(seed); 136 fSeed = SkScalarTruncToInt(seed);
130 // The seed value clamp to the range [1, kRandMaximum - 1]. 137 // The seed value clamp to the range [1, kRandMaximum - 1].
131 if (fSeed <= 0) { 138 if (fSeed <= 0) {
132 fSeed = -(fSeed % (kRandMaximum - 1)) + 1; 139 fSeed = -(fSeed % (kRandMaximum - 1)) + 1;
133 } 140 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 SkScalarMul(SkIntToScalar(fNoise[channel][i][1] - kBlockSize ), 190 SkScalarMul(SkIntToScalar(fNoise[channel][i][1] - kBlockSize ),
184 gInvBlockSizef)); 191 gInvBlockSizef));
185 fGradient[channel][i].normalize(); 192 fGradient[channel][i].normalize();
186 // Put the normalized gradient back into the noise data 193 // Put the normalized gradient back into the noise data
187 fNoise[channel][i][0] = SkScalarRoundToInt(SkScalarMul( 194 fNoise[channel][i][0] = SkScalarRoundToInt(SkScalarMul(
188 fGradient[channel][i].fX + SK_Scalar1, gHalfMax16bits)); 195 fGradient[channel][i].fX + SK_Scalar1, gHalfMax16bits));
189 fNoise[channel][i][1] = SkScalarRoundToInt(SkScalarMul( 196 fNoise[channel][i][1] = SkScalarRoundToInt(SkScalarMul(
190 fGradient[channel][i].fY + SK_Scalar1, gHalfMax16bits)); 197 fGradient[channel][i].fY + SK_Scalar1, gHalfMax16bits));
191 } 198 }
192 } 199 }
193
194 // Invalidate bitmaps
195 SkDELETE(fPermutationsBitmap);
196 fPermutationsBitmap = NULL;
197 SkDELETE(fNoiseBitmap);
198 fNoiseBitmap = NULL;
199 } 200 }
200 201
202 // Only called once. Could be part of the constructor.
201 void stitch() { 203 void stitch() {
202 SkScalar tileWidth = SkIntToScalar(fTileSize.width()); 204 SkScalar tileWidth = SkIntToScalar(fTileSize.width());
203 SkScalar tileHeight = SkIntToScalar(fTileSize.height()); 205 SkScalar tileHeight = SkIntToScalar(fTileSize.height());
204 SkASSERT(tileWidth > 0 && tileHeight > 0); 206 SkASSERT(tileWidth > 0 && tileHeight > 0);
205 // When stitching tiled turbulence, the frequencies must be adjusted 207 // When stitching tiled turbulence, the frequencies must be adjusted
206 // so that the tile borders will be continuous. 208 // so that the tile borders will be continuous.
207 if (fBaseFrequency.fX) { 209 if (fBaseFrequency.fX) {
208 SkScalar lowFrequencx = 210 SkScalar lowFrequencx =
209 SkScalarFloorToScalar(tileWidth * fBaseFrequency.fX) / tileWidth ; 211 SkScalarFloorToScalar(tileWidth * fBaseFrequency.fX) / tileWidth ;
210 SkScalar highFrequencx = 212 SkScalar highFrequencx =
(...skipping 20 matching lines...) Expand all
231 } 233 }
232 // Set up TurbulenceInitial stitch values. 234 // Set up TurbulenceInitial stitch values.
233 fStitchDataInit.fWidth = 235 fStitchDataInit.fWidth =
234 SkScalarRoundToInt(tileWidth * fBaseFrequency.fX); 236 SkScalarRoundToInt(tileWidth * fBaseFrequency.fX);
235 fStitchDataInit.fWrapX = kPerlinNoise + fStitchDataInit.fWidth; 237 fStitchDataInit.fWrapX = kPerlinNoise + fStitchDataInit.fWidth;
236 fStitchDataInit.fHeight = 238 fStitchDataInit.fHeight =
237 SkScalarRoundToInt(tileHeight * fBaseFrequency.fY); 239 SkScalarRoundToInt(tileHeight * fBaseFrequency.fY);
238 fStitchDataInit.fWrapY = kPerlinNoise + fStitchDataInit.fHeight; 240 fStitchDataInit.fWrapY = kPerlinNoise + fStitchDataInit.fHeight;
239 } 241 }
240 242
241 SkBitmap* getPermutationsBitmap() 243 public:
242 {
243 if (!fPermutationsBitmap) {
244 fPermutationsBitmap = SkNEW(SkBitmap);
245 fPermutationsBitmap->allocPixels(SkImageInfo::MakeA8(kBlockSize, 1)) ;
246 uint8_t* bitmapPixels = fPermutationsBitmap->getAddr8(0, 0);
247 memcpy(bitmapPixels, fLatticeSelector, sizeof(uint8_t) * kBlockSize) ;
248 }
249 return fPermutationsBitmap;
250 }
251 244
252 SkBitmap* getNoiseBitmap() 245 #if SK_SUPPORT_GPU && !defined(SK_USE_SIMPLEX_NOISE)
253 { 246 const SkBitmap& getPermutationsBitmap() const { return fPermutationsBitmap; }
254 if (!fNoiseBitmap) { 247
255 fNoiseBitmap = SkNEW(SkBitmap); 248 const SkBitmap& getNoiseBitmap() const { return fNoiseBitmap; }
256 fNoiseBitmap->allocPixels(SkImageInfo::MakeN32Premul(kBlockSize, 4)) ; 249 #endif
257 uint32_t* bitmapPixels = fNoiseBitmap->getAddr32(0, 0);
258 memcpy(bitmapPixels, fNoise[0][0], sizeof(uint16_t) * kBlockSize * 4 * 2);
259 }
260 return fNoiseBitmap;
261 }
262 }; 250 };
263 251
264 SkShader* SkPerlinNoiseShader::CreateFractalNoise(SkScalar baseFrequencyX, SkSca lar baseFrequencyY, 252 SkShader* SkPerlinNoiseShader::CreateFractalNoise(SkScalar baseFrequencyX, SkSca lar baseFrequencyY,
265 int numOctaves, SkScalar seed, 253 int numOctaves, SkScalar seed,
266 const SkISize* tileSize) { 254 const SkISize* tileSize) {
267 return SkNEW_ARGS(SkPerlinNoiseShader, (kFractalNoise_Type, baseFrequencyX, baseFrequencyY, 255 return SkNEW_ARGS(SkPerlinNoiseShader, (kFractalNoise_Type, baseFrequencyX, baseFrequencyY,
268 numOctaves, seed, tileSize)); 256 numOctaves, seed, tileSize));
269 } 257 }
270 258
271 SkShader* SkPerlinNoiseShader::CreateTubulence(SkScalar baseFrequencyX, SkScalar baseFrequencyY, 259 SkShader* SkPerlinNoiseShader::CreateTubulence(SkScalar baseFrequencyX, SkScalar baseFrequencyY,
272 int numOctaves, SkScalar seed, 260 int numOctaves, SkScalar seed,
273 const SkISize* tileSize) { 261 const SkISize* tileSize) {
274 return SkNEW_ARGS(SkPerlinNoiseShader, (kTurbulence_Type, baseFrequencyX, ba seFrequencyY, 262 return SkNEW_ARGS(SkPerlinNoiseShader, (kTurbulence_Type, baseFrequencyX, ba seFrequencyY,
275 numOctaves, seed, tileSize)); 263 numOctaves, seed, tileSize));
276 } 264 }
277 265
278 SkPerlinNoiseShader::SkPerlinNoiseShader(SkPerlinNoiseShader::Type type, 266 SkPerlinNoiseShader::SkPerlinNoiseShader(SkPerlinNoiseShader::Type type,
279 SkScalar baseFrequencyX, 267 SkScalar baseFrequencyX,
280 SkScalar baseFrequencyY, 268 SkScalar baseFrequencyY,
281 int numOctaves, 269 int numOctaves,
282 SkScalar seed, 270 SkScalar seed,
283 const SkISize* tileSize) 271 const SkISize* tileSize)
284 : fType(type) 272 : fType(type)
285 , fBaseFrequencyX(baseFrequencyX) 273 , fBaseFrequencyX(baseFrequencyX)
286 , fBaseFrequencyY(baseFrequencyY) 274 , fBaseFrequencyY(baseFrequencyY)
287 , fNumOctaves(numOctaves > 255 ? 255 : numOctaves/*[0,255] octaves allowed*/) 275 , fNumOctaves(numOctaves > 255 ? 255 : numOctaves/*[0,255] octaves allowed*/)
288 , fSeed(seed) 276 , fSeed(seed)
289 , fStitchTiles((tileSize != NULL) && !tileSize->isEmpty()) 277 , fTileSize(NULL == tileSize ? SkISize::Make(0, 0) : *tileSize)
290 , fPaintingData(NULL) 278 , fStitchTiles(!fTileSize.isEmpty())
291 { 279 {
292 SkASSERT(numOctaves >= 0 && numOctaves < 256); 280 SkASSERT(numOctaves >= 0 && numOctaves < 256);
293 setTileSize(fStitchTiles ? *tileSize : SkISize::Make(0,0));
294 fMatrix.reset(); 281 fMatrix.reset();
282 fPaintingData = SkNEW_ARGS(PaintingData, (fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY));
295 } 283 }
296 284
297 SkPerlinNoiseShader::SkPerlinNoiseShader(SkReadBuffer& buffer) : 285 SkPerlinNoiseShader::SkPerlinNoiseShader(SkReadBuffer& buffer)
298 INHERITED(buffer), fPaintingData(NULL) { 286 : INHERITED(buffer)
287 {
299 fType = (SkPerlinNoiseShader::Type) buffer.readInt(); 288 fType = (SkPerlinNoiseShader::Type) buffer.readInt();
300 fBaseFrequencyX = buffer.readScalar(); 289 fBaseFrequencyX = buffer.readScalar();
301 fBaseFrequencyY = buffer.readScalar(); 290 fBaseFrequencyY = buffer.readScalar();
302 fNumOctaves = buffer.readInt(); 291 fNumOctaves = buffer.readInt();
303 fSeed = buffer.readScalar(); 292 fSeed = buffer.readScalar();
304 fStitchTiles = buffer.readBool(); 293 fStitchTiles = buffer.readBool();
305 fTileSize.fWidth = buffer.readInt(); 294 fTileSize.fWidth = buffer.readInt();
306 fTileSize.fHeight = buffer.readInt(); 295 fTileSize.fHeight = buffer.readInt();
307 setTileSize(fTileSize);
308 fMatrix.reset(); 296 fMatrix.reset();
297 fPaintingData = SkNEW_ARGS(PaintingData, (fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY));
309 buffer.validate(perlin_noise_type_is_valid(fType) && 298 buffer.validate(perlin_noise_type_is_valid(fType) &&
310 (fNumOctaves >= 0) && (fNumOctaves <= 255)); 299 (fNumOctaves >= 0) && (fNumOctaves <= 255) &&
300 (fStitchTiles != fTileSize.isEmpty()));
311 } 301 }
312 302
313 SkPerlinNoiseShader::~SkPerlinNoiseShader() { 303 SkPerlinNoiseShader::~SkPerlinNoiseShader() {
314 // Safety, should have been done in endContext() 304 // Safety, should have been done in endContext()
315 SkDELETE(fPaintingData); 305 SkDELETE(fPaintingData);
316 } 306 }
317 307
318 void SkPerlinNoiseShader::flatten(SkWriteBuffer& buffer) const { 308 void SkPerlinNoiseShader::flatten(SkWriteBuffer& buffer) const {
319 this->INHERITED::flatten(buffer); 309 this->INHERITED::flatten(buffer);
320 buffer.writeInt((int) fType); 310 buffer.writeInt((int) fType);
321 buffer.writeScalar(fBaseFrequencyX); 311 buffer.writeScalar(fBaseFrequencyX);
322 buffer.writeScalar(fBaseFrequencyY); 312 buffer.writeScalar(fBaseFrequencyY);
323 buffer.writeInt(fNumOctaves); 313 buffer.writeInt(fNumOctaves);
324 buffer.writeScalar(fSeed); 314 buffer.writeScalar(fSeed);
325 buffer.writeBool(fStitchTiles); 315 buffer.writeBool(fStitchTiles);
326 buffer.writeInt(fTileSize.fWidth); 316 buffer.writeInt(fTileSize.fWidth);
327 buffer.writeInt(fTileSize.fHeight); 317 buffer.writeInt(fTileSize.fHeight);
328 } 318 }
329 319
330 void SkPerlinNoiseShader::initPaint(PaintingData& paintingData)
331 {
332 paintingData.init(fSeed);
333
334 // Set frequencies to original values
335 paintingData.fBaseFrequency.set(fBaseFrequencyX, fBaseFrequencyY);
336 // Adjust frequecies based on size if stitching is enabled
337 if (fStitchTiles) {
338 paintingData.stitch();
339 }
340 }
341
342 void SkPerlinNoiseShader::setTileSize(const SkISize& tileSize) {
343 fTileSize = tileSize;
344
345 if (NULL == fPaintingData) {
346 fPaintingData = SkNEW_ARGS(PaintingData, (fTileSize));
347 initPaint(*fPaintingData);
348 } else {
349 // Set Size
350 fPaintingData->fTileSize = fTileSize;
351 // Set frequencies to original values
352 fPaintingData->fBaseFrequency.set(fBaseFrequencyX, fBaseFrequencyY);
353 // Adjust frequecies based on size if stitching is enabled
354 if (fStitchTiles) {
355 fPaintingData->stitch();
356 }
357 }
358 }
359
360 SkScalar SkPerlinNoiseShader::noise2D(int channel, const PaintingData& paintingD ata, 320 SkScalar SkPerlinNoiseShader::noise2D(int channel, const PaintingData& paintingD ata,
361 const StitchData& stitchData, const SkPoint & noiseVector) 321 const StitchData& stitchData,
362 { 322 const SkPoint& noiseVector) const {
363 struct Noise { 323 struct Noise {
364 int noisePositionIntegerValue; 324 int noisePositionIntegerValue;
365 SkScalar noisePositionFractionValue; 325 SkScalar noisePositionFractionValue;
366 Noise(SkScalar component) 326 Noise(SkScalar component)
367 { 327 {
368 SkScalar position = component + kPerlinNoise; 328 SkScalar position = component + kPerlinNoise;
369 noisePositionIntegerValue = SkScalarFloorToInt(position); 329 noisePositionIntegerValue = SkScalarFloorToInt(position);
370 noisePositionFractionValue = position - SkIntToScalar(noisePositionI ntegerValue); 330 noisePositionFractionValue = position - SkIntToScalar(noisePositionI ntegerValue);
371 } 331 }
372 }; 332 };
(...skipping 25 matching lines...) Expand all
398 v = paintingData.fGradient[channel][nextLatticeIndex & kBlockMask].dot(fract ionValue); 358 v = paintingData.fGradient[channel][nextLatticeIndex & kBlockMask].dot(fract ionValue);
399 SkScalar a = SkScalarInterp(u, v, sx); 359 SkScalar a = SkScalarInterp(u, v, sx);
400 fractionValue.fY -= SK_Scalar1; // Offset (-1,-1) 360 fractionValue.fY -= SK_Scalar1; // Offset (-1,-1)
401 v = paintingData.fGradient[channel][(nextLatticeIndex + 1) & kBlockMask].dot (fractionValue); 361 v = paintingData.fGradient[channel][(nextLatticeIndex + 1) & kBlockMask].dot (fractionValue);
402 fractionValue.fX = noiseX.noisePositionFractionValue; // Offset (0,-1) 362 fractionValue.fX = noiseX.noisePositionFractionValue; // Offset (0,-1)
403 u = paintingData.fGradient[channel][(latticeIndex + 1) & kBlockMask].dot(fra ctionValue); 363 u = paintingData.fGradient[channel][(latticeIndex + 1) & kBlockMask].dot(fra ctionValue);
404 SkScalar b = SkScalarInterp(u, v, sx); 364 SkScalar b = SkScalarInterp(u, v, sx);
405 return SkScalarInterp(a, b, sy); 365 return SkScalarInterp(a, b, sy);
406 } 366 }
407 367
408 SkScalar SkPerlinNoiseShader::calculateTurbulenceValueForPoint( 368 SkScalar SkPerlinNoiseShader::calculateTurbulenceValueForPoint(int channel,
409 int channel, const PaintingData& paintingData, StitchData& stitchData, const SkPoint& point) 369 const PaintingDat a& paintingData,
410 { 370 StitchData& stitc hData,
371 const SkPoint& po int) const {
411 if (fStitchTiles) { 372 if (fStitchTiles) {
412 // Set up TurbulenceInitial stitch values. 373 // Set up TurbulenceInitial stitch values.
413 stitchData = paintingData.fStitchDataInit; 374 stitchData = paintingData.fStitchDataInit;
414 } 375 }
415 SkScalar turbulenceFunctionResult = 0; 376 SkScalar turbulenceFunctionResult = 0;
416 SkPoint noiseVector(SkPoint::Make(SkScalarMul(point.x(), paintingData.fBaseF requency.fX), 377 SkPoint noiseVector(SkPoint::Make(SkScalarMul(point.x(), paintingData.fBaseF requency.fX),
417 SkScalarMul(point.y(), paintingData.fBaseF requency.fY))); 378 SkScalarMul(point.y(), paintingData.fBaseF requency.fY)));
418 SkScalar ratio = SK_Scalar1; 379 SkScalar ratio = SK_Scalar1;
419 for (int octave = 0; octave < fNumOctaves; ++octave) { 380 for (int octave = 0; octave < fNumOctaves; ++octave) {
420 SkScalar noise = noise2D(channel, paintingData, stitchData, noiseVector) ; 381 SkScalar noise = noise2D(channel, paintingData, stitchData, noiseVector) ;
(...skipping 20 matching lines...) Expand all
441 402
442 if (channel == 3) { // Scale alpha by paint value 403 if (channel == 3) { // Scale alpha by paint value
443 turbulenceFunctionResult = SkScalarMul(turbulenceFunctionResult, 404 turbulenceFunctionResult = SkScalarMul(turbulenceFunctionResult,
444 SkScalarDiv(SkIntToScalar(getPaintAlpha()), SkIntToScalar(255))); 405 SkScalarDiv(SkIntToScalar(getPaintAlpha()), SkIntToScalar(255)));
445 } 406 }
446 407
447 // Clamp result 408 // Clamp result
448 return SkScalarPin(turbulenceFunctionResult, 0, SK_Scalar1); 409 return SkScalarPin(turbulenceFunctionResult, 0, SK_Scalar1);
449 } 410 }
450 411
451 SkPMColor SkPerlinNoiseShader::shade(const SkPoint& point, StitchData& stitchDat a) { 412 SkPMColor SkPerlinNoiseShader::shade(const SkPoint& point, StitchData& stitchDat a) const {
452 SkMatrix matrix = fMatrix; 413 SkMatrix matrix = fMatrix;
453 matrix.postConcat(getLocalMatrix()); 414 matrix.postConcat(getLocalMatrix());
454 SkMatrix invMatrix; 415 SkMatrix invMatrix;
455 if (!matrix.invert(&invMatrix)) { 416 if (!matrix.invert(&invMatrix)) {
456 invMatrix.reset(); 417 invMatrix.reset();
457 } else { 418 } else {
458 invMatrix.postConcat(invMatrix); // Square the matrix 419 invMatrix.postConcat(invMatrix); // Square the matrix
459 } 420 }
460 // This (1,1) translation is due to WebKit's 1 based coordinates for the noi se 421 // This (1,1) translation is due to WebKit's 1 based coordinates for the noi se
461 // (as opposed to 0 based, usually). The same adjustment is in the setData() function. 422 // (as opposed to 0 based, usually). The same adjustment is in the setData() function.
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after
1319 1280
1320 #ifdef SK_USE_SIMPLEX_NOISE 1281 #ifdef SK_USE_SIMPLEX_NOISE
1321 // Simplex noise is currently disabled but can be enabled by defining SK_USE _SIMPLEX_NOISE 1282 // Simplex noise is currently disabled but can be enabled by defining SK_USE _SIMPLEX_NOISE
1322 sk_ignore_unused_variable(context); 1283 sk_ignore_unused_variable(context);
1323 GrEffectRef* effect = 1284 GrEffectRef* effect =
1324 GrSimplexNoiseEffect::Create(fType, fPaintingData->fBaseFrequency, 1285 GrSimplexNoiseEffect::Create(fType, fPaintingData->fBaseFrequency,
1325 fNumOctaves, fStitchTiles, fSeed, 1286 fNumOctaves, fStitchTiles, fSeed,
1326 this->getLocalMatrix(), paint.getAlpha()); 1287 this->getLocalMatrix(), paint.getAlpha());
1327 #else 1288 #else
1328 GrTexture* permutationsTexture = GrLockAndRefCachedBitmapTexture( 1289 GrTexture* permutationsTexture = GrLockAndRefCachedBitmapTexture(
1329 context, *fPaintingData->getPermutationsBitmap(), NULL); 1290 context, fPaintingData->getPermutationsBitmap(), NULL);
1330 GrTexture* noiseTexture = GrLockAndRefCachedBitmapTexture( 1291 GrTexture* noiseTexture = GrLockAndRefCachedBitmapTexture(
1331 context, *fPaintingData->getNoiseBitmap(), NULL); 1292 context, fPaintingData->getNoiseBitmap(), NULL);
1332 1293
1333 GrEffectRef* effect = (NULL != permutationsTexture) && (NULL != noiseTexture ) ? 1294 GrEffectRef* effect = (NULL != permutationsTexture) && (NULL != noiseTexture ) ?
1334 GrPerlinNoiseEffect::Create(fType, fPaintingData->fBaseFrequency, 1295 GrPerlinNoiseEffect::Create(fType, fPaintingData->fBaseFrequency,
1335 fNumOctaves, fStitchTiles, 1296 fNumOctaves, fStitchTiles,
1336 fPaintingData->fStitchDataInit, 1297 fPaintingData->fStitchDataInit,
1337 permutationsTexture, noiseTexture, 1298 permutationsTexture, noiseTexture,
1338 this->getLocalMatrix(), paint.getAlpha()) : 1299 this->getLocalMatrix(), paint.getAlpha()) :
1339 NULL; 1300 NULL;
1340 1301
1341 // Unlock immediately, this is not great, but we don't have a way of 1302 // Unlock immediately, this is not great, but we don't have a way of
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 str->append(" seed: "); 1347 str->append(" seed: ");
1387 str->appendScalar(fSeed); 1348 str->appendScalar(fSeed);
1388 str->append(" stitch tiles: "); 1349 str->append(" stitch tiles: ");
1389 str->append(fStitchTiles ? "true " : "false "); 1350 str->append(fStitchTiles ? "true " : "false ");
1390 1351
1391 this->INHERITED::toString(str); 1352 this->INHERITED::toString(str);
1392 1353
1393 str->append(")"); 1354 str->append(")");
1394 } 1355 }
1395 #endif 1356 #endif
OLDNEW
« no previous file with comments | « include/effects/SkPerlinNoiseShader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698