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

Unified Diff: include/effects/SkPerlinNoiseShader.h

Issue 169973002: Begin making SkPerlinNoiseShader const. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Make methods const and simplify const comments. Created 6 years, 10 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 | src/effects/SkPerlinNoiseShader.cpp » ('j') | src/effects/SkPerlinNoiseShader.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/effects/SkPerlinNoiseShader.h
diff --git a/include/effects/SkPerlinNoiseShader.h b/include/effects/SkPerlinNoiseShader.h
index dd89c70925954deefd9fa6d7f05e4335454f9465..fd9f19fe29650573f60be4415f6dc51dbf319f2e 100644
--- a/include/effects/SkPerlinNoiseShader.h
+++ b/include/effects/SkPerlinNoiseShader.h
@@ -8,6 +8,8 @@
#ifndef SkPerlinNoiseShader_DEFINED
#define SkPerlinNoiseShader_DEFINED
+#include "SkBitmap.h"
+#include "SkPoint.h"
#include "SkShader.h"
/** \class SkPerlinNoiseShader
@@ -23,10 +25,7 @@
http://www.w3.org/TR/SVG/filters.html#feTurbulenceElement
*/
class SK_API SkPerlinNoiseShader : public SkShader {
- struct PaintingData;
public:
- struct StitchData;
-
/**
* About the noise types : the difference between the 2 is just minor tweaks to the algorithm,
* they're not 2 entirely different noises. The output looks different, but once the noise is
@@ -69,6 +68,27 @@ public:
virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
+ struct StitchData {
scroggo 2014/03/04 22:26:34 StitchData is now defined in the class declaration
+ StitchData()
+ : fWidth(0)
+ , fWrapX(0)
+ , fHeight(0)
+ , fWrapY(0)
+ {}
+
+ bool operator==(const StitchData& other) const {
+ return fWidth == other.fWidth &&
+ fWrapX == other.fWrapX &&
+ fHeight == other.fHeight &&
+ fWrapY == other.fWrapY;
+ }
+
+ int fWidth; // How much to subtract to wrap for stitching.
+ int fWrapX; // Minimum value to wrap.
+ int fHeight;
+ int fWrapY;
+ };
+
SK_DEVELOPER_TO_STRING()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPerlinNoiseShader)
@@ -80,30 +100,44 @@ private:
SkPerlinNoiseShader(SkPerlinNoiseShader::Type type, SkScalar baseFrequencyX,
SkScalar baseFrequencyY, int numOctaves, SkScalar seed,
const SkISize* tileSize = NULL);
- virtual ~SkPerlinNoiseShader();
- void setTileSize(const SkISize&);
+ SkScalar noise2D(int channel, const StitchData& stitchData, const SkPoint& noiseVector) const;
- void initPaint(PaintingData& paintingData);
+ SkScalar calculateTurbulenceValueForPoint(int channel, StitchData& stitchData,
+ const SkPoint& point) const;
- SkScalar noise2D(int channel, const PaintingData& paintingData,
- const StitchData& stitchData, const SkPoint& noiseVector);
+ SkPMColor shade(const SkPoint& point, StitchData& stitchData) const;
- SkScalar calculateTurbulenceValueForPoint(int channel, const PaintingData& paintingData,
- StitchData& stitchData, const SkPoint& point);
+ // TODO (scroggo): Investigate making fields const.
+ SkPerlinNoiseShader::Type fType;
+ SkVector fBaseFrequency;
+ int fNumOctaves;
+ // fSeed changes on each call to random.
+ mutable int fSeed;
scroggo 2014/03/04 22:26:34 fSeed is now an int, like PaintingData::fSeed was.
+ SkISize fTileSize;
+ bool fStitchTiles;
- SkPMColor shade(const SkPoint& point, StitchData& stitchData);
+ static const int kBlockSize = 256;
scroggo 2014/03/04 22:26:34 Now defined here for members referencing it that u
+ static const int kBlockMask = kBlockSize - 1;
- SkPerlinNoiseShader::Type fType;
- SkScalar fBaseFrequencyX;
- SkScalar fBaseFrequencyY;
- int fNumOctaves;
- SkScalar fSeed;
- SkISize fTileSize;
- bool fStitchTiles;
+ uint8_t fLatticeSelector[kBlockSize];
+ uint16_t fNoise[4][kBlockSize][2];
+ SkPoint fGradient[4][kBlockSize];
+
+ StitchData fStitchDataInit;
+
+ // These are caches. Instead of accessing directly, getPermutationsBitmap and getNoiseBitmap
+ // should be called.
+ mutable SkBitmap fPermutationsBitmap;
scroggo 2014/03/04 22:26:34 I changed these from pointers on fPaintingData to
+ mutable SkBitmap fNoiseBitmap;
+
+
+ // TODO (scroggo): Once setContext creates a new object, place this on that object.
SkMatrix fMatrix;
- PaintingData* fPaintingData;
+ void init();
scroggo 2014/03/04 22:26:34 This should now be the only function that modifies
+ const SkBitmap& getPermutationsBitmap() const;
+ const SkBitmap& getNoiseBitmap() const;
typedef SkShader INHERITED;
};
« no previous file with comments | « no previous file | src/effects/SkPerlinNoiseShader.cpp » ('j') | src/effects/SkPerlinNoiseShader.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698