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 #include "SkTime.h" | |
scroggo
2014/06/05 16:09:30
Not used. Please remove.
rs.prinja
2014/06/07 10:46:05
Done.
| |
15 | 16 |
16 static void Perterb(SkPoint* p, const SkVector& tangent, SkScalar scale) { | 17 static void Perterb(SkPoint* p, const SkVector& tangent, SkScalar scale) { |
17 SkVector normal = tangent; | 18 SkVector normal = tangent; |
18 normal.rotateCCW(); | 19 normal.rotateCCW(); |
19 normal.setLength(scale); | 20 normal.setLength(scale); |
20 *p += normal; | 21 *p += normal; |
21 } | 22 } |
22 | 23 |
24 uint32_t SkDiscretePathEffect::fObjectIdGenerator = 0; | |
23 | 25 |
24 SkDiscretePathEffect::SkDiscretePathEffect(SkScalar segLength, SkScalar deviatio n) | 26 SkDiscretePathEffect::SkDiscretePathEffect(SkScalar segLength, SkScalar deviatio n, uint32_t seedAssist) |
scroggo
2014/06/05 16:09:30
Over 100 chars.
rs.prinja
2014/06/07 10:46:05
Done.
| |
25 : fSegLength(segLength), fPerterb(deviation) | 27 : fSegLength(segLength), fPerterb(deviation), fSeedAssist(seedAssist) |
26 { | 28 { |
29 fObjectId = fObjectIdGenerator++; | |
27 } | 30 } |
28 | 31 |
29 bool SkDiscretePathEffect::filterPath(SkPath* dst, const SkPath& src, | 32 bool SkDiscretePathEffect::filterPath(SkPath* dst, const SkPath& src, |
30 SkStrokeRec* rec, const SkRect*) const { | 33 SkStrokeRec* rec, const SkRect*) const { |
31 bool doFill = rec->isFillStyle(); | 34 bool doFill = rec->isFillStyle(); |
32 | 35 |
33 SkPathMeasure meas(src, doFill); | 36 SkPathMeasure meas(src, doFill); |
34 uint32_t seed = SkScalarRoundToInt(meas.getLength()); | 37 |
38 /* We want to have identical seeds for identical paths that share the same e ffect object | |
39 * but different seeds for identical paths that use different effect objects */ | |
40 uint32_t seed = fObjectId + SkScalarRoundToInt(meas.getLength()); | |
scroggo
2014/06/05 16:09:30
As stated elsewhere, please just use the length an
rs.prinja
2014/06/07 10:46:05
Done.
| |
41 | |
42 /* Also, across different runs of the same program, the same path should be seeded differently */ | |
43 seed += SkTime::GetMSecs() / 1000; | |
scroggo
2014/06/05 16:09:30
Please remove.
rs.prinja
2014/06/07 10:46:05
Done.
| |
44 | |
45 /* Caller may supply their own seed assist, which by default is 1 */ | |
46 seed *= fSeedAssist; | |
47 | |
35 SkLCGRandom rand(seed ^ ((seed << 16) | (seed >> 16))); | 48 SkLCGRandom rand(seed ^ ((seed << 16) | (seed >> 16))); |
36 SkScalar scale = fPerterb; | 49 SkScalar scale = fPerterb; |
37 SkPoint p; | 50 SkPoint p; |
38 SkVector v; | 51 SkVector v; |
39 | 52 |
40 do { | 53 do { |
41 SkScalar length = meas.getLength(); | 54 SkScalar length = meas.getLength(); |
42 | 55 |
43 if (fSegLength * (2 + doFill) > length) { | 56 if (fSegLength * (2 + doFill) > length) { |
44 meas.getSegment(0, length, dst, true); // to short for us to mangle | 57 meas.getSegment(0, length, dst, true); // to short for us to mangle |
(...skipping 29 matching lines...) Expand all Loading... | |
74 void SkDiscretePathEffect::flatten(SkWriteBuffer& buffer) const { | 87 void SkDiscretePathEffect::flatten(SkWriteBuffer& buffer) const { |
75 this->INHERITED::flatten(buffer); | 88 this->INHERITED::flatten(buffer); |
76 buffer.writeScalar(fSegLength); | 89 buffer.writeScalar(fSegLength); |
77 buffer.writeScalar(fPerterb); | 90 buffer.writeScalar(fPerterb); |
78 } | 91 } |
79 | 92 |
80 SkDiscretePathEffect::SkDiscretePathEffect(SkReadBuffer& buffer) { | 93 SkDiscretePathEffect::SkDiscretePathEffect(SkReadBuffer& buffer) { |
81 fSegLength = buffer.readScalar(); | 94 fSegLength = buffer.readScalar(); |
82 fPerterb = buffer.readScalar(); | 95 fPerterb = buffer.readScalar(); |
83 } | 96 } |
OLD | NEW |