OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
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 #include "SkOpContour.h" | 7 #include "SkOpContour.h" |
8 #include "SkOpTAllocator.h" | 8 #include "SkOpTAllocator.h" |
9 #include "SkPathWriter.h" | 9 #include "SkPathWriter.h" |
10 #include "SkReduceOrder.h" | 10 #include "SkReduceOrder.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocato
r, 4); | 30 SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocato
r, 4); |
31 memcpy(ptStorage, pts, sizeof(SkPoint) * 4); | 31 memcpy(ptStorage, pts, sizeof(SkPoint) * 4); |
32 return appendSegment(allocator).addCubic(ptStorage, this); | 32 return appendSegment(allocator).addCubic(ptStorage, this); |
33 } break; | 33 } break; |
34 default: | 34 default: |
35 SkASSERT(0); | 35 SkASSERT(0); |
36 } | 36 } |
37 return NULL; | 37 return NULL; |
38 } | 38 } |
39 | 39 |
40 SkOpSegment* SkOpContour::nonVerticalSegment(SkOpSpanBase** start, SkOpSpanBase*
* end) { | |
41 int segmentCount = fSortedSegments.count(); | |
42 SkASSERT(segmentCount > 0); | |
43 for (int sortedIndex = fFirstSorted; sortedIndex < segmentCount; ++sortedInd
ex) { | |
44 SkOpSegment* testSegment = fSortedSegments[sortedIndex]; | |
45 if (testSegment->done()) { | |
46 continue; | |
47 } | |
48 SkOpSpanBase* span = testSegment->head(); | |
49 SkOpSpanBase* testS, * testE; | |
50 while (SkOpSegment::NextCandidate(span, &testS, &testE)) { | |
51 if (!testSegment->isVertical(testS, testE)) { | |
52 *start = testS; | |
53 *end = testE; | |
54 return testSegment; | |
55 } | |
56 span = span->upCast()->next(); | |
57 } | |
58 } | |
59 return NULL; | |
60 } | |
61 | |
62 void SkOpContour::toPath(SkPathWriter* path) const { | 40 void SkOpContour::toPath(SkPathWriter* path) const { |
63 const SkPoint& pt = fHead.pts()[0]; | 41 const SkPoint& pt = fHead.pts()[0]; |
64 path->deferredMove(pt); | 42 path->deferredMove(pt); |
65 const SkOpSegment* segment = &fHead; | 43 const SkOpSegment* segment = &fHead; |
66 do { | 44 do { |
67 segment->addCurveTo(segment->head(), segment->tail(), path, true); | 45 segment->addCurveTo(segment->head(), segment->tail(), path, true); |
68 } while ((segment = segment->next())); | 46 } while ((segment = segment->next())); |
69 path->close(); | 47 path->close(); |
70 } | 48 } |
71 | 49 |
72 void SkOpContour::topSortableSegment(const SkDPoint& topLeft, SkDPoint* bestXY, | |
73 SkOpSegment** topStart) { | |
74 int segmentCount = fSortedSegments.count(); | |
75 SkASSERT(segmentCount > 0); | |
76 int sortedIndex = fFirstSorted; | |
77 fDone = true; // may be cleared below | |
78 for ( ; sortedIndex < segmentCount; ++sortedIndex) { | |
79 SkOpSegment* testSegment = fSortedSegments[sortedIndex]; | |
80 if (testSegment->done()) { | |
81 if (sortedIndex == fFirstSorted) { | |
82 ++fFirstSorted; | |
83 } | |
84 continue; | |
85 } | |
86 fDone = false; | |
87 SkDPoint testXY = testSegment->activeLeftTop(NULL); | |
88 if (*topStart) { | |
89 if (testXY.fY < topLeft.fY) { | |
90 continue; | |
91 } | |
92 if (testXY.fY == topLeft.fY && testXY.fX < topLeft.fX) { | |
93 continue; | |
94 } | |
95 if (bestXY->fY < testXY.fY) { | |
96 continue; | |
97 } | |
98 if (bestXY->fY == testXY.fY && bestXY->fX < testXY.fX) { | |
99 continue; | |
100 } | |
101 } | |
102 *topStart = testSegment; | |
103 *bestXY = testXY; | |
104 } | |
105 } | |
106 | |
107 SkOpSegment* SkOpContour::undoneSegment(SkOpSpanBase** startPtr, SkOpSpanBase**
endPtr) { | 50 SkOpSegment* SkOpContour::undoneSegment(SkOpSpanBase** startPtr, SkOpSpanBase**
endPtr) { |
108 SkOpSegment* segment = &fHead; | 51 SkOpSegment* segment = &fHead; |
109 do { | 52 do { |
110 if (segment->done()) { | 53 if (segment->done()) { |
111 continue; | 54 continue; |
112 } | 55 } |
113 segment->undoneSpan(startPtr, endPtr); | 56 segment->undoneSpan(startPtr, endPtr); |
114 return segment; | 57 return segment; |
115 } while ((segment = segment->next())); | 58 } while ((segment = segment->next())); |
116 return NULL; | 59 return NULL; |
117 } | 60 } |
OLD | NEW |