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

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

Issue 1829303002: move setshader to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: addressing comments from #8 Created 4 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 | « src/effects/SkLayerDrawLooper.cpp ('k') | src/pdf/SkPDFDevice.cpp » ('j') | 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 "SkPerlinNoiseShader.h" 8 #include "SkPerlinNoiseShader.h"
9 #include "SkColorFilter.h" 9 #include "SkColorFilter.h"
10 #include "SkReadBuffer.h" 10 #include "SkReadBuffer.h"
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 242
243 public: 243 public:
244 244
245 #if SK_SUPPORT_GPU 245 #if SK_SUPPORT_GPU
246 const SkBitmap& getPermutationsBitmap() const { return fPermutationsBitmap; } 246 const SkBitmap& getPermutationsBitmap() const { return fPermutationsBitmap; }
247 247
248 const SkBitmap& getNoiseBitmap() const { return fNoiseBitmap; } 248 const SkBitmap& getNoiseBitmap() const { return fNoiseBitmap; }
249 #endif 249 #endif
250 }; 250 };
251 251
252 SkShader* SkPerlinNoiseShader::CreateFractalNoise(SkScalar baseFrequencyX, SkSca lar baseFrequencyY, 252 sk_sp<SkShader> SkPerlinNoiseShader::MakeFractalNoise(SkScalar baseFrequencyX,
253 int numOctaves, SkScalar seed, 253 SkScalar baseFrequencyY,
254 const SkISize* tileSize) { 254 int numOctaves, SkScalar s eed,
255 return new SkPerlinNoiseShader(kFractalNoise_Type, baseFrequencyX, baseFrequ encyY, numOctaves, 255 const SkISize* tileSize) {
256 seed, tileSize); 256 return sk_sp<SkShader>(new SkPerlinNoiseShader(kFractalNoise_Type, baseFrequ encyX,
257 baseFrequencyY, numOctaves,
258 seed, tileSize));
257 } 259 }
258 260
259 SkShader* SkPerlinNoiseShader::CreateTurbulence(SkScalar baseFrequencyX, SkScala r baseFrequencyY, 261 sk_sp<SkShader> SkPerlinNoiseShader::MakeTurbulence(SkScalar baseFrequencyX,
260 int numOctaves, SkScalar seed, 262 SkScalar baseFrequencyY,
261 const SkISize* tileSize) { 263 int numOctaves, SkScalar see d,
262 return new SkPerlinNoiseShader(kTurbulence_Type, baseFrequencyX, baseFrequen cyY, numOctaves, 264 const SkISize* tileSize) {
263 seed, tileSize); 265 return sk_sp<SkShader>(new SkPerlinNoiseShader(kTurbulence_Type, baseFrequen cyX, baseFrequencyY,
266 numOctaves, seed, tileSize));
264 } 267 }
265 268
266 SkPerlinNoiseShader::SkPerlinNoiseShader(SkPerlinNoiseShader::Type type, 269 SkPerlinNoiseShader::SkPerlinNoiseShader(SkPerlinNoiseShader::Type type,
267 SkScalar baseFrequencyX, 270 SkScalar baseFrequencyX,
268 SkScalar baseFrequencyY, 271 SkScalar baseFrequencyY,
269 int numOctaves, 272 int numOctaves,
270 SkScalar seed, 273 SkScalar seed,
271 const SkISize* tileSize) 274 const SkISize* tileSize)
272 : fType(type) 275 : fType(type)
273 , fBaseFrequencyX(baseFrequencyX) 276 , fBaseFrequencyX(baseFrequencyX)
(...skipping 14 matching lines...) Expand all
288 SkScalar freqX = buffer.readScalar(); 291 SkScalar freqX = buffer.readScalar();
289 SkScalar freqY = buffer.readScalar(); 292 SkScalar freqY = buffer.readScalar();
290 int octaves = buffer.readInt(); 293 int octaves = buffer.readInt();
291 SkScalar seed = buffer.readScalar(); 294 SkScalar seed = buffer.readScalar();
292 SkISize tileSize; 295 SkISize tileSize;
293 tileSize.fWidth = buffer.readInt(); 296 tileSize.fWidth = buffer.readInt();
294 tileSize.fHeight = buffer.readInt(); 297 tileSize.fHeight = buffer.readInt();
295 298
296 switch (type) { 299 switch (type) {
297 case kFractalNoise_Type: 300 case kFractalNoise_Type:
298 return SkPerlinNoiseShader::CreateFractalNoise(freqX, freqY, octaves , seed, &tileSize); 301 return SkPerlinNoiseShader::MakeFractalNoise(freqX, freqY, octaves, seed,
302 &tileSize).release();
299 case kTurbulence_Type: 303 case kTurbulence_Type:
300 return SkPerlinNoiseShader::CreateTubulence(freqX, freqY, octaves, s eed, &tileSize); 304 return SkPerlinNoiseShader::MakeTurbulence(freqX, freqY, octaves, se ed,
305 &tileSize).release();
301 default: 306 default:
302 return nullptr; 307 return nullptr;
303 } 308 }
304 } 309 }
305 310
306 void SkPerlinNoiseShader::flatten(SkWriteBuffer& buffer) const { 311 void SkPerlinNoiseShader::flatten(SkWriteBuffer& buffer) const {
307 buffer.writeInt((int) fType); 312 buffer.writeInt((int) fType);
308 buffer.writeScalar(fBaseFrequencyX); 313 buffer.writeScalar(fBaseFrequencyX);
309 buffer.writeScalar(fBaseFrequencyY); 314 buffer.writeScalar(fBaseFrequencyY);
310 buffer.writeInt(fNumOctaves); 315 buffer.writeInt(fNumOctaves);
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 int numOctaves = d->fRandom->nextRangeU(2, 10); 578 int numOctaves = d->fRandom->nextRangeU(2, 10);
574 bool stitchTiles = d->fRandom->nextBool(); 579 bool stitchTiles = d->fRandom->nextBool();
575 SkScalar seed = SkIntToScalar(d->fRandom->nextU()); 580 SkScalar seed = SkIntToScalar(d->fRandom->nextU());
576 SkISize tileSize = SkISize::Make(d->fRandom->nextRangeU(4, 4096), 581 SkISize tileSize = SkISize::Make(d->fRandom->nextRangeU(4, 4096),
577 d->fRandom->nextRangeU(4, 4096)); 582 d->fRandom->nextRangeU(4, 4096));
578 SkScalar baseFrequencyX = d->fRandom->nextRangeScalar(0.01f, 583 SkScalar baseFrequencyX = d->fRandom->nextRangeScalar(0.01f,
579 0.99f); 584 0.99f);
580 SkScalar baseFrequencyY = d->fRandom->nextRangeScalar(0.01f, 585 SkScalar baseFrequencyY = d->fRandom->nextRangeScalar(0.01f,
581 0.99f); 586 0.99f);
582 587
583 SkAutoTUnref<SkShader> shader(d->fRandom->nextBool() ? 588 sk_sp<SkShader> shader(d->fRandom->nextBool() ?
584 SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY, numOctaves, seed, 589 SkPerlinNoiseShader::MakeFractalNoise(baseFrequencyX, baseFrequencyY, nu mOctaves, seed,
585 stitchTiles ? &tileSize : nullpt r) : 590 stitchTiles ? &tileSize : nullptr) :
586 SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, nu mOctaves, seed, 591 SkPerlinNoiseShader::MakeTurbulence(baseFrequencyX, baseFrequencyY, numO ctaves, seed,
587 stitchTiles ? &tileSize : nullptr)) ; 592 stitchTiles ? &tileSize : nullptr));
588 593
589 return shader->asFragmentProcessor(d->fContext, 594 return shader->asFragmentProcessor(d->fContext,
590 GrTest::TestMatrix(d->fRandom), nullptr, 595 GrTest::TestMatrix(d->fRandom), nullptr,
591 kNone_SkFilterQuality); 596 kNone_SkFilterQuality);
592 } 597 }
593 598
594 void GrGLPerlinNoise::emitCode(EmitArgs& args) { 599 void GrGLPerlinNoise::emitCode(EmitArgs& args) {
595 const GrPerlinNoiseEffect& pne = args.fFp.cast<GrPerlinNoiseEffect>(); 600 const GrPerlinNoiseEffect& pne = args.fFp.cast<GrPerlinNoiseEffect>();
596 601
597 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; 602 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 str->append(" seed: "); 975 str->append(" seed: ");
971 str->appendScalar(fSeed); 976 str->appendScalar(fSeed);
972 str->append(" stitch tiles: "); 977 str->append(" stitch tiles: ");
973 str->append(fStitchTiles ? "true " : "false "); 978 str->append(fStitchTiles ? "true " : "false ");
974 979
975 this->INHERITED::toString(str); 980 this->INHERITED::toString(str);
976 981
977 str->append(")"); 982 str->append(")");
978 } 983 }
979 #endif 984 #endif
OLDNEW
« no previous file with comments | « src/effects/SkLayerDrawLooper.cpp ('k') | src/pdf/SkPDFDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698