OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkDiscretePathEffect.h" | 10 #include "SkDiscretePathEffect.h" |
11 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
12 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
13 #include "SkPathMeasure.h" | 13 #include "SkPathMeasure.h" |
14 #include "SkRandom.h" | 14 #include "SkRandom.h" |
15 | 15 |
16 static void Perterb(SkPoint* p, const SkVector& tangent, SkScalar scale) { | 16 static void Perterb(SkPoint* p, const SkVector& tangent, SkScalar scale) { |
17 SkVector normal = tangent; | 17 SkVector normal = tangent; |
18 normal.rotateCCW(); | 18 normal.rotateCCW(); |
19 normal.setLength(scale); | 19 normal.setLength(scale); |
20 *p += normal; | 20 *p += normal; |
21 } | 21 } |
22 | 22 |
23 | 23 SkDiscretePathEffect::SkDiscretePathEffect(SkScalar segLength, |
24 SkDiscretePathEffect::SkDiscretePathEffect(SkScalar segLength, SkScalar deviatio
n) | 24 SkScalar deviation, |
25 : fSegLength(segLength), fPerterb(deviation) | 25 uint32_t seedAssist) |
| 26 : fSegLength(segLength), fPerterb(deviation), fSeedAssist(seedAssist) |
26 { | 27 { |
27 } | 28 } |
28 | 29 |
29 bool SkDiscretePathEffect::filterPath(SkPath* dst, const SkPath& src, | 30 bool SkDiscretePathEffect::filterPath(SkPath* dst, const SkPath& src, |
30 SkStrokeRec* rec, const SkRect*) const { | 31 SkStrokeRec* rec, const SkRect*) const { |
31 bool doFill = rec->isFillStyle(); | 32 bool doFill = rec->isFillStyle(); |
32 | 33 |
33 SkPathMeasure meas(src, doFill); | 34 SkPathMeasure meas(src, doFill); |
34 uint32_t seed = SkScalarRoundToInt(meas.getLength()); | 35 |
| 36 /* Caller may supply their own seed assist, which by default is 0 */ |
| 37 uint32_t seed = fSeedAssist ^ SkScalarRoundToInt(meas.getLength()); |
| 38 |
35 SkLCGRandom rand(seed ^ ((seed << 16) | (seed >> 16))); | 39 SkLCGRandom rand(seed ^ ((seed << 16) | (seed >> 16))); |
36 SkScalar scale = fPerterb; | 40 SkScalar scale = fPerterb; |
37 SkPoint p; | 41 SkPoint p; |
38 SkVector v; | 42 SkVector v; |
39 | 43 |
40 do { | 44 do { |
41 SkScalar length = meas.getLength(); | 45 SkScalar length = meas.getLength(); |
42 | 46 |
43 if (fSegLength * (2 + doFill) > length) { | 47 if (fSegLength * (2 + doFill) > length) { |
44 meas.getSegment(0, length, dst, true); // to short for us to mangle | 48 meas.getSegment(0, length, dst, true); // to short for us to mangle |
(...skipping 23 matching lines...) Expand all Loading... |
68 } | 72 } |
69 } | 73 } |
70 } while (meas.nextContour()); | 74 } while (meas.nextContour()); |
71 return true; | 75 return true; |
72 } | 76 } |
73 | 77 |
74 void SkDiscretePathEffect::flatten(SkWriteBuffer& buffer) const { | 78 void SkDiscretePathEffect::flatten(SkWriteBuffer& buffer) const { |
75 this->INHERITED::flatten(buffer); | 79 this->INHERITED::flatten(buffer); |
76 buffer.writeScalar(fSegLength); | 80 buffer.writeScalar(fSegLength); |
77 buffer.writeScalar(fPerterb); | 81 buffer.writeScalar(fPerterb); |
| 82 buffer.writeUInt(fSeedAssist); |
78 } | 83 } |
79 | 84 |
80 SkDiscretePathEffect::SkDiscretePathEffect(SkReadBuffer& buffer) { | 85 SkDiscretePathEffect::SkDiscretePathEffect(SkReadBuffer& buffer) { |
81 fSegLength = buffer.readScalar(); | 86 fSegLength = buffer.readScalar(); |
82 fPerterb = buffer.readScalar(); | 87 fPerterb = buffer.readScalar(); |
| 88 fSeedAssist = buffer.readUInt(); |
83 } | 89 } |
OLD | NEW |