| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 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 | 8 |
| 9 #include "SkDiscretePathEffect.h" | 9 #include "SkDiscretePathEffect.h" |
| 10 #include "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 Copied from the original implementation of SkRandom. Only contains the | 40 Copied from the original implementation of SkRandom. Only contains the |
| 41 methods used by SkDiscretePathEffect::filterPath, with methods that were | 41 methods used by SkDiscretePathEffect::filterPath, with methods that were |
| 42 not called directly moved to private. | 42 not called directly moved to private. |
| 43 */ | 43 */ |
| 44 | 44 |
| 45 class LCGRandom { | 45 class LCGRandom { |
| 46 public: | 46 public: |
| 47 LCGRandom(uint32_t seed) : fSeed(seed) {} | 47 LCGRandom(uint32_t seed) : fSeed(seed) {} |
| 48 | 48 |
| 49 /** Return the next pseudo random number expressed as a SkScalar | 49 /** Return the next pseudo random number expressed as a SkScalar |
| 50 in the range (-SK_Scalar1..SK_Scalar1). | 50 in the range [-SK_Scalar1..SK_Scalar1). |
| 51 */ | 51 */ |
| 52 SkScalar nextSScalar1() { return SkFixedToScalar(this->nextSFixed1()); } | 52 SkScalar nextSScalar1() { return SkFixedToScalar(this->nextSFixed1()); } |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 /** Return the next pseudo random number as an unsigned 32bit value. | 55 /** Return the next pseudo random number as an unsigned 32bit value. |
| 56 */ | 56 */ |
| 57 uint32_t nextU() { uint32_t r = fSeed * kMul + kAdd; fSeed = r; return r; } | 57 uint32_t nextU() { uint32_t r = fSeed * kMul + kAdd; fSeed = r; return r; } |
| 58 | 58 |
| 59 /** Return the next pseudo random number as a signed 32bit value. | 59 /** Return the next pseudo random number as a signed 32bit value. |
| 60 */ | 60 */ |
| 61 int32_t nextS() { return (int32_t)this->nextU(); } | 61 int32_t nextS() { return (int32_t)this->nextU(); } |
| 62 | 62 |
| 63 /** Return the next pseudo random number expressed as a signed SkFixed | 63 /** Return the next pseudo random number expressed as a signed SkFixed |
| 64 in the range (-SK_Fixed1..SK_Fixed1). | 64 in the range [-SK_Fixed1..SK_Fixed1). |
| 65 */ | 65 */ |
| 66 SkFixed nextSFixed1() { return this->nextS() >> 15; } | 66 SkFixed nextSFixed1() { return this->nextS() >> 15; } |
| 67 | 67 |
| 68 // See "Numerical Recipes in C", 1992 page 284 for these constants | 68 // See "Numerical Recipes in C", 1992 page 284 for these constants |
| 69 enum { | 69 enum { |
| 70 kMul = 1664525, | 70 kMul = 1664525, |
| 71 kAdd = 1013904223 | 71 kAdd = 1013904223 |
| 72 }; | 72 }; |
| 73 uint32_t fSeed; | 73 uint32_t fSeed; |
| 74 }; | 74 }; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 buffer.writeUInt(fSeedAssist); | 134 buffer.writeUInt(fSeedAssist); |
| 135 } | 135 } |
| 136 | 136 |
| 137 #ifndef SK_IGNORE_TO_STRING | 137 #ifndef SK_IGNORE_TO_STRING |
| 138 void SkDiscretePathEffect::toString(SkString* str) const { | 138 void SkDiscretePathEffect::toString(SkString* str) const { |
| 139 str->appendf("SkDiscretePathEffect: ("); | 139 str->appendf("SkDiscretePathEffect: ("); |
| 140 str->appendf("segLength: %.2f deviation: %.2f seed %d", fSegLength, fPerterb
, fSeedAssist); | 140 str->appendf("segLength: %.2f deviation: %.2f seed %d", fSegLength, fPerterb
, fSeedAssist); |
| 141 str->append(")"); | 141 str->append(")"); |
| 142 } | 142 } |
| 143 #endif | 143 #endif |
| OLD | NEW |