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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: include/effects/SkPerlinNoiseShader.h
diff --git a/include/effects/SkPerlinNoiseShader.h b/include/effects/SkPerlinNoiseShader.h
index 497c0e0e8c476bc2934abb9bf315dac90065bb05..261accf9fd5d331b77003edb0e1d99d963f06558 100644
--- a/include/effects/SkPerlinNoiseShader.h
+++ b/include/effects/SkPerlinNoiseShader.h
@@ -62,10 +62,33 @@ public:
int numOctaves, SkScalar seed,
const SkISize* tileSize = NULL);
- virtual bool setContext(const SkBitmap& device, const SkPaint& paint,
- const SkMatrix& matrix);
- virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE;
- virtual void shadeSpan16(int x, int y, uint16_t[], int count) SK_OVERRIDE;
+ virtual bool validContext(const SkBitmap& device, const SkPaint& paint,
+ const SkMatrix& matrix) const SK_OVERRIDE;
+ virtual SkShader::Context* createContext(
+ const SkBitmap& device, const SkPaint& paint,
+ const SkMatrix& matrix, void* storage) const SK_OVERRIDE;
+ virtual size_t contextSize() const SK_OVERRIDE;
+
+ class PerlinNoiseShaderContext : public SkShader::Context {
+ public:
+ PerlinNoiseShaderContext(const SkPerlinNoiseShader& shader, const SkBitmap& device,
+ const SkPaint& paint, const SkMatrix& matrix);
+ virtual ~PerlinNoiseShaderContext();
+
+ virtual void shadeSpan(int x, int y, SkPMColor[], int count) SK_OVERRIDE;
+ virtual void shadeSpan16(int x, int y, uint16_t[], int count) SK_OVERRIDE;
+ private:
+ SkPMColor shade(const SkPoint& point, StitchData& stitchData) const;
+ SkScalar calculateTurbulenceValueForPoint(
+ int channel, const PaintingData& paintingData,
+ StitchData& stitchData, const SkPoint& point) const;
+ SkScalar noise2D(int channel, const PaintingData& paintingData,
+ const StitchData& stitchData, const SkPoint& noiseVector) const;
+
+ SkMatrix fMatrix;
+
+ typedef SkShader::Context INHERITED;
+ };
virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
@@ -75,21 +98,12 @@ public:
protected:
SkPerlinNoiseShader(SkReadBuffer&);
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
-
private:
SkPerlinNoiseShader(SkPerlinNoiseShader::Type type, SkScalar baseFrequencyX,
SkScalar baseFrequencyY, int numOctaves, SkScalar seed,
const SkISize* tileSize);
virtual ~SkPerlinNoiseShader();
- SkScalar noise2D(int channel, const PaintingData& paintingData,
- const StitchData& stitchData, const SkPoint& noiseVector) const;
-
- SkScalar calculateTurbulenceValueForPoint(int channel, const PaintingData& paintingData,
- StitchData& stitchData, const SkPoint& point) const;
-
- SkPMColor shade(const SkPoint& point, StitchData& stitchData) const;
-
// TODO (scroggo): Once all SkShaders are created from a factory, and we have removed the
// constructor that creates SkPerlinNoiseShader from an SkReadBuffer, several fields can
// be made constant.
@@ -100,8 +114,6 @@ private:
/*const*/ SkScalar fSeed;
/*const*/ SkISize fTileSize;
/*const*/ bool fStitchTiles;
- // TODO (scroggo): Once setContext creates a new object, place this on that object.
- SkMatrix fMatrix;
PaintingData* fPaintingData;

Powered by Google App Engine
This is Rietveld 408576698