Index: src/effects/SkDiscretePathEffect.cpp |
diff --git a/src/effects/SkDiscretePathEffect.cpp b/src/effects/SkDiscretePathEffect.cpp |
index 8aa0e223562d39a28c9f8a1a29c38dbfb31f4e85..6765b296a54b9b6c7306860cb18c16ba1aad21a9 100644 |
--- a/src/effects/SkDiscretePathEffect.cpp |
+++ b/src/effects/SkDiscretePathEffect.cpp |
@@ -11,7 +11,6 @@ |
#include "SkReadBuffer.h" |
#include "SkWriteBuffer.h" |
#include "SkPathMeasure.h" |
-#include "SkRandom.h" |
static void Perterb(SkPoint* p, const SkVector& tangent, SkScalar scale) { |
SkVector normal = tangent; |
@@ -27,6 +26,48 @@ SkDiscretePathEffect::SkDiscretePathEffect(SkScalar segLength, |
{ |
} |
+/** \class LCGRandom |
+ |
+ Utility class that implements pseudo random 32bit numbers using a fast |
+ linear equation. Unlike rand(), this class holds its own seed (initially |
+ set to 0), so that multiple instances can be used with no side-effects. |
+ |
+ Copied from the original implementation of SkRandom. Only contains the |
+ methods used by SkDiscretePathEffect::filterPath, with methods that were |
+ not called directly moved to private. |
+*/ |
+ |
+class LCGRandom { |
+public: |
+ LCGRandom(uint32_t seed) : fSeed(seed) {} |
+ |
+ /** Return the next pseudo random number expressed as a SkScalar |
+ in the range (-SK_Scalar1..SK_Scalar1). |
+ */ |
+ SkScalar nextSScalar1() { return SkFixedToScalar(this->nextSFixed1()); } |
+ |
+private: |
+ /** Return the next pseudo random number as an unsigned 32bit value. |
+ */ |
+ uint32_t nextU() { uint32_t r = fSeed * kMul + kAdd; fSeed = r; return r; } |
+ |
+ /** Return the next pseudo random number as a signed 32bit value. |
+ */ |
+ int32_t nextS() { return (int32_t)this->nextU(); } |
+ |
+ /** Return the next pseudo random number expressed as a signed SkFixed |
+ in the range (-SK_Fixed1..SK_Fixed1). |
+ */ |
+ SkFixed nextSFixed1() { return this->nextS() >> 15; } |
+ |
+ // See "Numerical Recipes in C", 1992 page 284 for these constants |
+ enum { |
+ kMul = 1664525, |
+ kAdd = 1013904223 |
+ }; |
+ uint32_t fSeed; |
+}; |
+ |
bool SkDiscretePathEffect::filterPath(SkPath* dst, const SkPath& src, |
SkStrokeRec* rec, const SkRect*) const { |
bool doFill = rec->isFillStyle(); |
@@ -36,10 +77,10 @@ bool SkDiscretePathEffect::filterPath(SkPath* dst, const SkPath& src, |
/* Caller may supply their own seed assist, which by default is 0 */ |
uint32_t seed = fSeedAssist ^ SkScalarRoundToInt(meas.getLength()); |
- SkLCGRandom rand(seed ^ ((seed << 16) | (seed >> 16))); |
- SkScalar scale = fPerterb; |
- SkPoint p; |
- SkVector v; |
+ LCGRandom rand(seed ^ ((seed << 16) | (seed >> 16))); |
+ SkScalar scale = fPerterb; |
+ SkPoint p; |
+ SkVector v; |
do { |
SkScalar length = meas.getLength(); |