Sanitizing source files in Skia_Periodic_House_Keeping

git-svn-id: http://skia.googlecode.com/svn/trunk@7484 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
skia.committer@gmail.com 2013-01-31 07:06:15 +00:00
parent c3ecf65c69
commit 24d5ee4f88

View File

@ -152,11 +152,11 @@ private:
}; };
/** \class SkMWCRandom /** \class SkMWCRandom
Utility class that implements pseudo random 32bit numbers using Marsaglia's Utility class that implements pseudo random 32bit numbers using Marsaglia's
multiply-with-carry "mother of all" algorithm. Unlike rand(), this class holds multiply-with-carry "mother of all" algorithm. Unlike rand(), this class holds
its own state, so that multiple instances can be used with no side-effects. its own state, so that multiple instances can be used with no side-effects.
Has a large period and all bits are well-randomized. Has a large period and all bits are well-randomized.
*/ */
class SkMWCRandom { class SkMWCRandom {
@ -165,13 +165,13 @@ public:
SkMWCRandom(uint32_t seed) { init(seed); } SkMWCRandom(uint32_t seed) { init(seed); }
SkMWCRandom(const SkMWCRandom& rand) : fK(rand.fK), fJ(rand.fJ) {} SkMWCRandom(const SkMWCRandom& rand) : fK(rand.fK), fJ(rand.fJ) {}
SkMWCRandom& operator=(const SkMWCRandom& rand) { SkMWCRandom& operator=(const SkMWCRandom& rand) {
fK = rand.fK; fK = rand.fK;
fJ = rand.fJ; fJ = rand.fJ;
return *this; return *this;
} }
/** Return the next pseudo random number as an unsigned 32bit value. /** Return the next pseudo random number as an unsigned 32bit value.
*/ */
uint32_t nextU() { uint32_t nextU() {
@ -179,19 +179,19 @@ public:
fJ = kJMul*(fJ & 0xffff) + (fJ >> 16); fJ = kJMul*(fJ & 0xffff) + (fJ >> 16);
return (((fK << 16) | (fK >> 16)) + fJ); return (((fK << 16) | (fK >> 16)) + fJ);
} }
/** Return the next pseudo random number as a signed 32bit value. /** Return the next pseudo random number as a signed 32bit value.
*/ */
int32_t nextS() { return (int32_t)this->nextU(); } int32_t nextS() { return (int32_t)this->nextU(); }
/** Return the next pseudo random number as an unsigned 16bit value. /** Return the next pseudo random number as an unsigned 16bit value.
*/ */
U16CPU nextU16() { return this->nextU() >> 16; } U16CPU nextU16() { return this->nextU() >> 16; }
/** Return the next pseudo random number as a signed 16bit value. /** Return the next pseudo random number as a signed 16bit value.
*/ */
S16CPU nextS16() { return this->nextS() >> 16; } S16CPU nextS16() { return this->nextS() >> 16; }
/** /**
* Returns value [0...1) as an IEEE float * Returns value [0...1) as an IEEE float
*/ */
@ -200,14 +200,14 @@ public:
float f = *(float*)(&floatint) - 1.0f; float f = *(float*)(&floatint) - 1.0f;
return f; return f;
} }
/** /**
* Returns value [min...max) as a float * Returns value [min...max) as a float
*/ */
float nextRangeF(float min, float max) { float nextRangeF(float min, float max) {
return min + this->nextF() * (max - min); return min + this->nextF() * (max - min);
} }
/** Return the next pseudo random number, as an unsigned value of /** Return the next pseudo random number, as an unsigned value of
at most bitCount bits. at most bitCount bits.
@param bitCount The maximum number of bits to be returned @param bitCount The maximum number of bits to be returned
@ -216,7 +216,7 @@ public:
SkASSERT(bitCount > 0 && bitCount <= 32); SkASSERT(bitCount > 0 && bitCount <= 32);
return this->nextU() >> (32 - bitCount); return this->nextU() >> (32 - bitCount);
} }
/** Return the next pseudo random unsigned number, mapped to lie within /** Return the next pseudo random unsigned number, mapped to lie within
[min, max] inclusive. [min, max] inclusive.
*/ */
@ -229,7 +229,7 @@ public:
return min + this->nextU() % range; return min + this->nextU() % range;
} }
} }
/** Return the next pseudo random unsigned number, mapped to lie within /** Return the next pseudo random unsigned number, mapped to lie within
[0, count). [0, count).
*/ */
@ -237,59 +237,59 @@ public:
SkASSERT(count > 0); SkASSERT(count > 0);
return this->nextRangeU(0, count - 1); return this->nextRangeU(0, count - 1);
} }
/** Return the next pseudo random number expressed as an unsigned SkFixed /** Return the next pseudo random number expressed as an unsigned SkFixed
in the range [0..SK_Fixed1). in the range [0..SK_Fixed1).
*/ */
SkFixed nextUFixed1() { return this->nextU() >> 16; } SkFixed nextUFixed1() { return this->nextU() >> 16; }
/** Return the next pseudo random number expressed as a signed SkFixed /** Return the next pseudo random number expressed as a signed SkFixed
in the range (-SK_Fixed1..SK_Fixed1). in the range (-SK_Fixed1..SK_Fixed1).
*/ */
SkFixed nextSFixed1() { return this->nextS() >> 15; } SkFixed nextSFixed1() { return this->nextS() >> 15; }
/** Return the next pseudo random number expressed as a SkScalar /** Return the next pseudo random number expressed as a SkScalar
in the range [0..SK_Scalar1). in the range [0..SK_Scalar1).
*/ */
SkScalar nextUScalar1() { return SkFixedToScalar(this->nextUFixed1()); } SkScalar nextUScalar1() { return SkFixedToScalar(this->nextUFixed1()); }
/** Return the next pseudo random number expressed as a SkScalar /** Return the next pseudo random number expressed as a SkScalar
in the range [min..max). in the range [min..max).
*/ */
SkScalar nextRangeScalar(SkScalar min, SkScalar max) { SkScalar nextRangeScalar(SkScalar min, SkScalar max) {
return SkScalarMul(this->nextUScalar1(), (max - min)) + min; return SkScalarMul(this->nextUScalar1(), (max - min)) + min;
} }
/** Return the next pseudo random number expressed as a SkScalar /** Return the next pseudo random number expressed as a SkScalar
in the range (-SK_Scalar1..SK_Scalar1). in the range (-SK_Scalar1..SK_Scalar1).
*/ */
SkScalar nextSScalar1() { return SkFixedToScalar(this->nextSFixed1()); } SkScalar nextSScalar1() { return SkFixedToScalar(this->nextSFixed1()); }
/** Return the next pseudo random number as a bool. /** Return the next pseudo random number as a bool.
*/ */
bool nextBool() { return this->nextU() >= 0x80000000; } bool nextBool() { return this->nextU() >= 0x80000000; }
/** A biased version of nextBool(). /** A biased version of nextBool().
*/ */
bool nextBiasedBool(SkScalar fractionTrue) { bool nextBiasedBool(SkScalar fractionTrue) {
SkASSERT(fractionTrue >= 0 && fractionTrue <= SK_Scalar1); SkASSERT(fractionTrue >= 0 && fractionTrue <= SK_Scalar1);
return this->nextUScalar1() <= fractionTrue; return this->nextUScalar1() <= fractionTrue;
} }
/** Return the next pseudo random number as a signed 64bit value. /** Return the next pseudo random number as a signed 64bit value.
*/ */
void next64(Sk64* a) { void next64(Sk64* a) {
SkASSERT(a); SkASSERT(a);
a->set(this->nextS(), this->nextU()); a->set(this->nextS(), this->nextU());
} }
/** Reset the random object. /** Reset the random object.
*/ */
void setSeed(uint32_t seed) { init(seed); } void setSeed(uint32_t seed) { init(seed); }
private: private:
// Initialize state variables with LCG. // Initialize state variables with LCG.
// We must ensure that both J and K are non-zero, otherwise the // We must ensure that both J and K are non-zero, otherwise the
// multiply-with-carry step will forevermore return zero. // multiply-with-carry step will forevermore return zero.
void init(uint32_t seed) { void init(uint32_t seed) {
fK = NextLCG(seed); fK = NextLCG(seed);
@ -315,7 +315,7 @@ private:
kKMul = 30345, kKMul = 30345,
kJMul = 18000, kJMul = 18000,
}; };
uint32_t fK; uint32_t fK;
uint32_t fJ; uint32_t fJ;
}; };