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

Side by Side Diff: include/effects/SkPerlinNoiseShader.h

Issue 207683004: Extract most of the mutable state of SkShader into a separate Context object. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: clean up 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
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 #ifndef SkPerlinNoiseShader_DEFINED 8 #ifndef SkPerlinNoiseShader_DEFINED
9 #define SkPerlinNoiseShader_DEFINED 9 #define SkPerlinNoiseShader_DEFINED
10 10
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 * the frequencies so that the noise will be tileable for the given tile si ze. If tileSize 55 * the frequencies so that the noise will be tileable for the given tile si ze. If tileSize
56 * is NULL or an empty size, the frequencies will be used as is without mod ification. 56 * is NULL or an empty size, the frequencies will be used as is without mod ification.
57 */ 57 */
58 static SkShader* CreateFractalNoise(SkScalar baseFrequencyX, SkScalar baseFr equencyY, 58 static SkShader* CreateFractalNoise(SkScalar baseFrequencyX, SkScalar baseFr equencyY,
59 int numOctaves, SkScalar seed, 59 int numOctaves, SkScalar seed,
60 const SkISize* tileSize = NULL); 60 const SkISize* tileSize = NULL);
61 static SkShader* CreateTubulence(SkScalar baseFrequencyX, SkScalar baseFrequ encyY, 61 static SkShader* CreateTubulence(SkScalar baseFrequencyX, SkScalar baseFrequ encyY,
62 int numOctaves, SkScalar seed, 62 int numOctaves, SkScalar seed,
63 const SkISize* tileSize = NULL); 63 const SkISize* tileSize = NULL);
64 64
65 virtual bool setContext(const SkBitmap& device, const SkPaint& paint, 65 virtual bool validContext(const SkBitmap& device, const SkPaint& paint,
66 const SkMatrix& matrix); 66 const SkMatrix& matrix) const SK_OVERRIDE;
67 virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE; 67 virtual SkShader::Context* createContext(
68 virtual void shadeSpan16(int x, int y, uint16_t[], int count) SK_OVERRIDE; 68 const SkBitmap& device, const SkPaint& paint,
69 const SkMatrix& matrix, void* storage) const SK_OVERRIDE;
70 virtual size_t contextSize() const SK_OVERRIDE;
71
72 class PerlinNoiseShaderContext : public SkShader::Context {
73 public:
74 PerlinNoiseShaderContext(const SkPerlinNoiseShader& shader, const SkBitm ap& device,
75 const SkPaint& paint, const SkMatrix& matrix);
76 virtual ~PerlinNoiseShaderContext();
77
78 virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE ;
79 virtual void shadeSpan16(int x, int y, uint16_t[], int count) SK_OVERRID E;
80 private:
81 SkPMColor shade(const SkPoint& point, StitchData& stitchData) const;
82 SkScalar calculateTurbulenceValueForPoint(
83 int channel, const PaintingData& paintingData,
84 StitchData& stitchData, const SkPoint& point) const;
85 SkScalar noise2D(int channel, const PaintingData& paintingData,
86 const StitchData& stitchData, const SkPoint& noiseVecto r) const;
87
88 SkMatrix fMatrix;
89
90 typedef SkShader::Context INHERITED;
91 };
69 92
70 virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const S K_OVERRIDE; 93 virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const S K_OVERRIDE;
71 94
72 SK_DEVELOPER_TO_STRING() 95 SK_DEVELOPER_TO_STRING()
73 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPerlinNoiseShader) 96 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPerlinNoiseShader)
74 97
75 protected: 98 protected:
76 SkPerlinNoiseShader(SkReadBuffer&); 99 SkPerlinNoiseShader(SkReadBuffer&);
77 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; 100 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
78
79 private: 101 private:
80 SkPerlinNoiseShader(SkPerlinNoiseShader::Type type, SkScalar baseFrequencyX, 102 SkPerlinNoiseShader(SkPerlinNoiseShader::Type type, SkScalar baseFrequencyX,
81 SkScalar baseFrequencyY, int numOctaves, SkScalar seed, 103 SkScalar baseFrequencyY, int numOctaves, SkScalar seed,
82 const SkISize* tileSize); 104 const SkISize* tileSize);
83 virtual ~SkPerlinNoiseShader(); 105 virtual ~SkPerlinNoiseShader();
84 106
85 SkScalar noise2D(int channel, const PaintingData& paintingData,
86 const StitchData& stitchData, const SkPoint& noiseVector) c onst;
87
88 SkScalar calculateTurbulenceValueForPoint(int channel, const PaintingData& p aintingData,
89 StitchData& stitchData, const SkPo int& point) const;
90
91 SkPMColor shade(const SkPoint& point, StitchData& stitchData) const;
92
93 // TODO (scroggo): Once all SkShaders are created from a factory, and we hav e removed the 107 // TODO (scroggo): Once all SkShaders are created from a factory, and we hav e removed the
94 // constructor that creates SkPerlinNoiseShader from an SkReadBuffer, severa l fields can 108 // constructor that creates SkPerlinNoiseShader from an SkReadBuffer, severa l fields can
95 // be made constant. 109 // be made constant.
96 /*const*/ SkPerlinNoiseShader::Type fType; 110 /*const*/ SkPerlinNoiseShader::Type fType;
97 /*const*/ SkScalar fBaseFrequencyX; 111 /*const*/ SkScalar fBaseFrequencyX;
98 /*const*/ SkScalar fBaseFrequencyY; 112 /*const*/ SkScalar fBaseFrequencyY;
99 /*const*/ int fNumOctaves; 113 /*const*/ int fNumOctaves;
100 /*const*/ SkScalar fSeed; 114 /*const*/ SkScalar fSeed;
101 /*const*/ SkISize fTileSize; 115 /*const*/ SkISize fTileSize;
102 /*const*/ bool fStitchTiles; 116 /*const*/ bool fStitchTiles;
103 // TODO (scroggo): Once setContext creates a new object, place this on that object.
104 SkMatrix fMatrix;
105 117
106 PaintingData* fPaintingData; 118 PaintingData* fPaintingData;
107 119
108 typedef SkShader INHERITED; 120 typedef SkShader INHERITED;
109 }; 121 };
110 122
111 #endif 123 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698