OLD | NEW |
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 "gm.h" | 8 #include "gm.h" |
9 #include "SkPerlinNoiseShader.h" | 9 #include "SkPerlinNoiseShader.h" |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()), | 30 SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()), |
31 SkIntToScalar(size.height())); | 31 SkIntToScalar(size.height())); |
32 canvas->drawRect(r, paint); | 32 canvas->drawRect(r, paint); |
33 canvas->restore(); | 33 canvas->restore(); |
34 } | 34 } |
35 | 35 |
36 void test(SkCanvas* canvas, int x, int y, SkPerlinNoiseShader::Type type, | 36 void test(SkCanvas* canvas, int x, int y, SkPerlinNoiseShader::Type type, |
37 float baseFrequencyX, float baseFrequencyY, int numOctaves, float
seed, | 37 float baseFrequencyX, float baseFrequencyY, int numOctaves, float
seed, |
38 bool stitchTiles) { | 38 bool stitchTiles) { |
39 SkISize tileSize = SkISize::Make(fSize.width() / 2, fSize.height() / 2); | 39 SkISize tileSize = SkISize::Make(fSize.width() / 2, fSize.height() / 2); |
40 SkShader* shader = (type == SkPerlinNoiseShader::kFractalNoise_Type) ? | 40 sk_sp<SkShader> shader = (type == SkPerlinNoiseShader::kFractalNoise_Typ
e) ? |
41 SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequenc
yY, numOctaves, | 41 SkPerlinNoiseShader::MakeFractalNoise(baseFrequencyX, baseFrequencyY
, numOctaves, |
42 seed, stitchTiles ? &tileSize
: nullptr) : | 42 seed, stitchTiles ? &tileSize
: nullptr) : |
43 SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY
, numOctaves, | 43 SkPerlinNoiseShader::MakeTurbulence(baseFrequencyX, baseFrequencyY,
numOctaves, |
44 seed, stitchTiles ? &tileSize :
nullptr); | 44 seed, stitchTiles ? &tileSize :
nullptr); |
45 SkPaint paint; | 45 SkPaint paint; |
46 paint.setShader(shader)->unref(); | 46 paint.setShader(std::move(shader)); |
47 if (stitchTiles) { | 47 if (stitchTiles) { |
48 drawRect(canvas, x, y, paint, tileSize); | 48 drawRect(canvas, x, y, paint, tileSize); |
49 x += tileSize.width(); | 49 x += tileSize.width(); |
50 drawRect(canvas, x, y, paint, tileSize); | 50 drawRect(canvas, x, y, paint, tileSize); |
51 y += tileSize.width(); | 51 y += tileSize.width(); |
52 drawRect(canvas, x, y, paint, tileSize); | 52 drawRect(canvas, x, y, paint, tileSize); |
53 x -= tileSize.width(); | 53 x -= tileSize.width(); |
54 drawRect(canvas, x, y, paint, tileSize); | 54 drawRect(canvas, x, y, paint, tileSize); |
55 } else { | 55 } else { |
56 drawRect(canvas, x, y, paint, fSize); | 56 drawRect(canvas, x, y, paint, fSize); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 return SkString("perlinnoise_localmatrix"); | 103 return SkString("perlinnoise_localmatrix"); |
104 } | 104 } |
105 | 105 |
106 virtual SkISize onISize() { | 106 virtual SkISize onISize() { |
107 return SkISize::Make(640, 480); | 107 return SkISize::Make(640, 480); |
108 } | 108 } |
109 | 109 |
110 void install(SkPaint* paint, SkPerlinNoiseShader::Type type, | 110 void install(SkPaint* paint, SkPerlinNoiseShader::Type type, |
111 float baseFrequencyX, float baseFrequencyY, int numOctaves, float
seed, | 111 float baseFrequencyX, float baseFrequencyY, int numOctaves, float
seed, |
112 bool stitchTiles) { | 112 bool stitchTiles) { |
113 SkShader* shader = (type == SkPerlinNoiseShader::kFractalNoise_Type) ? | 113 sk_sp<SkShader> shader = (type == SkPerlinNoiseShader::kFractalNoise_Typ
e) ? |
114 SkPerlinNoiseShader::CreateFractalNoise(baseFrequencyX, baseFrequencyY,
numOctaves, | 114 SkPerlinNoiseShader::MakeFractalNoise(baseFrequencyX, baseFrequencyY
, numOctaves, |
115 seed, stitchTiles ? &fSize : nul
lptr) : | 115 seed, stitchTiles ? &fSize : n
ullptr) : |
116 SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, nu
mOctaves, | 116 SkPerlinNoiseShader::MakeTurbulence(baseFrequencyX, baseFrequencyY,
numOctaves, |
117 seed, stitchTiles ? &fSize : nullp
tr); | 117 seed, stitchTiles ? &fSize : nul
lptr); |
118 paint->setShader(shader)->unref(); | 118 paint->setShader(std::move(shader)); |
119 } | 119 } |
120 | 120 |
121 virtual void onDraw(SkCanvas* canvas) { | 121 virtual void onDraw(SkCanvas* canvas) { |
122 canvas->translate(10, 10); | 122 canvas->translate(10, 10); |
123 | 123 |
124 SkPaint paint; | 124 SkPaint paint; |
125 install(&paint, SkPerlinNoiseShader::kFractalNoise_Type, 0.1f, 0.1f, 2,
0, false); | 125 install(&paint, SkPerlinNoiseShader::kFractalNoise_Type, 0.1f, 0.1f, 2,
0, false); |
126 | 126 |
127 const SkScalar w = SkIntToScalar(fSize.width()); | 127 const SkScalar w = SkIntToScalar(fSize.width()); |
128 const SkScalar h = SkIntToScalar(fSize.height()); | 128 const SkScalar h = SkIntToScalar(fSize.height()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 171 |
172 private: | 172 private: |
173 typedef GM INHERITED; | 173 typedef GM INHERITED; |
174 SkISize fSize; | 174 SkISize fSize; |
175 }; | 175 }; |
176 | 176 |
177 ////////////////////////////////////////////////////////////////////////////// | 177 ////////////////////////////////////////////////////////////////////////////// |
178 | 178 |
179 DEF_GM( return new PerlinNoiseGM; ) | 179 DEF_GM( return new PerlinNoiseGM; ) |
180 DEF_GM( return new PerlinNoiseGM2; ) | 180 DEF_GM( return new PerlinNoiseGM2; ) |
OLD | NEW |