Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkGeometry.h" | 7 #include "SkGeometry.h" |
| 8 #include "SkOpEdgeBuilder.h" | 8 #include "SkOpEdgeBuilder.h" |
| 9 #include "SkReduceOrder.h" | 9 #include "SkReduceOrder.h" |
| 10 | 10 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 case SkPath::kQuad_Verb: | 107 case SkPath::kQuad_Verb: |
| 108 force_small_to_zero(&pts[1]); | 108 force_small_to_zero(&pts[1]); |
| 109 force_small_to_zero(&pts[2]); | 109 force_small_to_zero(&pts[2]); |
| 110 curve[1] = pts[1]; | 110 curve[1] = pts[1]; |
| 111 curve[2] = pts[2]; | 111 curve[2] = pts[2]; |
| 112 verb = SkReduceOrder::Quad(curve, pts); | 112 verb = SkReduceOrder::Quad(curve, pts); |
| 113 if (verb == SkPath::kMove_Verb) { | 113 if (verb == SkPath::kMove_Verb) { |
| 114 continue; // skip degenerate points | 114 continue; // skip degenerate points |
| 115 } | 115 } |
| 116 break; | 116 break; |
| 117 case SkPath::kConic_Verb: { | 117 case SkPath::kConic_Verb: |
| 118 if (true) { | |
|
reed1
2015/04/15 20:06:24
do we need to keep the "else" code?
| |
| 119 force_small_to_zero(&pts[1]); | |
| 120 force_small_to_zero(&pts[2]); | |
| 121 curve[1] = pts[1]; | |
| 122 curve[2] = pts[2]; | |
| 123 verb = SkReduceOrder::Conic(curve, iter.conicWeight(), pts); | |
| 124 if (verb == SkPath::kMove_Verb) { | |
| 125 continue; // skip degenerate points | |
| 126 } | |
| 127 break; | |
| 128 } else { | |
| 118 const SkPoint* quadPts = quadder.computeQuads(pts, iter.coni cWeight(), | 129 const SkPoint* quadPts = quadder.computeQuads(pts, iter.coni cWeight(), |
| 119 quadderTol); | 130 quadderTol); |
| 120 const int nQuads = quadder.countQuads(); | 131 const int nQuads = quadder.countQuads(); |
| 121 for (int i = 0; i < nQuads; ++i) { | 132 for (int i = 0; i < nQuads; ++i) { |
| 122 *fPathVerbs.append() = SkPath::kQuad_Verb; | 133 *fPathVerbs.append() = SkPath::kQuad_Verb; |
| 123 } | 134 } |
| 124 fPathPts.append(nQuads * 2, &quadPts[1]); | 135 fPathPts.append(nQuads * 2, &quadPts[1]); |
| 125 curve[0] = pts[2]; | 136 curve[0] = pts[2]; |
| 126 lastCurve = true; | 137 lastCurve = true; |
| 138 verb = SkPath::kQuad_Verb; | |
| 139 continue; | |
| 127 } | 140 } |
| 128 continue; | |
| 129 case SkPath::kCubic_Verb: | 141 case SkPath::kCubic_Verb: |
| 130 force_small_to_zero(&pts[1]); | 142 force_small_to_zero(&pts[1]); |
| 131 force_small_to_zero(&pts[2]); | 143 force_small_to_zero(&pts[2]); |
| 132 force_small_to_zero(&pts[3]); | 144 force_small_to_zero(&pts[3]); |
| 133 curve[1] = pts[1]; | 145 curve[1] = pts[1]; |
| 134 curve[2] = pts[2]; | 146 curve[2] = pts[2]; |
| 135 curve[3] = pts[3]; | 147 curve[3] = pts[3]; |
| 136 verb = SkReduceOrder::Cubic(curve, pts); | 148 verb = SkReduceOrder::Cubic(curve, pts); |
| 137 if (verb == SkPath::kMove_Verb) { | 149 if (verb == SkPath::kMove_Verb) { |
| 138 continue; // skip degenerate points | 150 continue; // skip degenerate points |
| 139 } | 151 } |
| 140 break; | 152 break; |
| 141 case SkPath::kClose_Verb: | 153 case SkPath::kClose_Verb: |
| 142 closeContour(curve[0], curveStart); | 154 closeContour(curve[0], curveStart); |
| 143 lastCurve = false; | 155 lastCurve = false; |
| 144 continue; | 156 continue; |
| 145 case SkPath::kDone_Verb: | 157 case SkPath::kDone_Verb: |
| 146 continue; | 158 continue; |
| 147 } | 159 } |
| 148 *fPathVerbs.append() = verb; | 160 *fPathVerbs.append() = verb; |
| 149 int ptCount = SkPathOpsVerbToPoints(verb); | 161 int ptCount = SkPathOpsVerbToPoints(verb); |
| 150 fPathPts.append(ptCount, &pts[1]); | 162 fPathPts.append(ptCount, &pts[1]); |
| 163 if (verb == SkPath::kConic_Verb) { | |
| 164 *fWeights.append() = iter.conicWeight(); | |
| 165 } | |
| 151 curve[0] = pts[ptCount]; | 166 curve[0] = pts[ptCount]; |
| 152 lastCurve = true; | 167 lastCurve = true; |
| 153 } while (verb != SkPath::kDone_Verb); | 168 } while (verb != SkPath::kDone_Verb); |
| 154 if (!fAllowOpenContours && lastCurve) { | 169 if (!fAllowOpenContours && lastCurve) { |
| 155 closeContour(curve[0], curveStart); | 170 closeContour(curve[0], curveStart); |
| 156 } | 171 } |
| 157 *fPathVerbs.append() = SkPath::kDone_Verb; | 172 *fPathVerbs.append() = SkPath::kDone_Verb; |
| 158 return fPathVerbs.count() - 1; | 173 return fPathVerbs.count() - 1; |
| 159 } | 174 } |
| 160 | 175 |
| 161 bool SkOpEdgeBuilder::close() { | 176 bool SkOpEdgeBuilder::close() { |
| 162 complete(); | 177 complete(); |
| 163 return true; | 178 return true; |
| 164 } | 179 } |
| 165 | 180 |
| 166 bool SkOpEdgeBuilder::walk(SkChunkAlloc* allocator) { | 181 bool SkOpEdgeBuilder::walk(SkChunkAlloc* allocator) { |
| 167 uint8_t* verbPtr = fPathVerbs.begin(); | 182 uint8_t* verbPtr = fPathVerbs.begin(); |
| 168 uint8_t* endOfFirstHalf = &verbPtr[fSecondHalf]; | 183 uint8_t* endOfFirstHalf = &verbPtr[fSecondHalf]; |
| 169 SkPoint* pointsPtr = fPathPts.begin() - 1; | 184 SkPoint* pointsPtr = fPathPts.begin() - 1; |
| 185 SkScalar* weightPtr = fWeights.begin(); | |
| 170 SkPath::Verb verb; | 186 SkPath::Verb verb; |
| 171 while ((verb = (SkPath::Verb) *verbPtr) != SkPath::kDone_Verb) { | 187 while ((verb = (SkPath::Verb) *verbPtr) != SkPath::kDone_Verb) { |
| 172 if (verbPtr == endOfFirstHalf) { | 188 if (verbPtr == endOfFirstHalf) { |
| 173 fOperand = true; | 189 fOperand = true; |
| 174 } | 190 } |
| 175 verbPtr++; | 191 verbPtr++; |
| 176 switch (verb) { | 192 switch (verb) { |
| 177 case SkPath::kMove_Verb: | 193 case SkPath::kMove_Verb: |
| 178 if (fCurrentContour && fCurrentContour->count()) { | 194 if (fCurrentContour && fCurrentContour->count()) { |
| 179 if (fAllowOpenContours) { | 195 if (fAllowOpenContours) { |
| 180 complete(); | 196 complete(); |
| 181 } else if (!close()) { | 197 } else if (!close()) { |
| 182 return false; | 198 return false; |
| 183 } | 199 } |
| 184 } | 200 } |
| 185 if (!fCurrentContour) { | 201 if (!fCurrentContour) { |
| 186 fCurrentContour = fContoursHead->appendContour(allocator); | 202 fCurrentContour = fContoursHead->appendContour(allocator); |
| 187 } | 203 } |
| 188 fCurrentContour->init(fGlobalState, fOperand, | 204 fCurrentContour->init(fGlobalState, fOperand, |
| 189 fXorMask[fOperand] == kEvenOdd_PathOpsMask); | 205 fXorMask[fOperand] == kEvenOdd_PathOpsMask); |
| 190 pointsPtr += 1; | 206 pointsPtr += 1; |
| 191 continue; | 207 continue; |
| 192 case SkPath::kLine_Verb: | 208 case SkPath::kLine_Verb: |
| 193 fCurrentContour->addLine(pointsPtr, fAllocator); | 209 fCurrentContour->addLine(pointsPtr, fAllocator); |
| 194 break; | 210 break; |
| 195 case SkPath::kQuad_Verb: | 211 case SkPath::kQuad_Verb: |
| 196 fCurrentContour->addQuad(pointsPtr, fAllocator); | 212 fCurrentContour->addQuad(pointsPtr, fAllocator); |
| 197 break; | 213 break; |
| 214 case SkPath::kConic_Verb: | |
| 215 fCurrentContour->addConic(pointsPtr, *weightPtr++, fAllocator); | |
| 216 break; | |
| 198 case SkPath::kCubic_Verb: { | 217 case SkPath::kCubic_Verb: { |
| 199 // split self-intersecting cubics in two before proceeding | 218 // split self-intersecting cubics in two before proceeding |
| 200 // if the cubic is convex, it doesn't self intersect. | 219 // if the cubic is convex, it doesn't self intersect. |
| 201 SkScalar loopT; | 220 SkScalar loopT; |
| 202 if (SkDCubic::ComplexBreak(pointsPtr, &loopT)) { | 221 if (SkDCubic::ComplexBreak(pointsPtr, &loopT)) { |
| 203 SkPoint cubicPair[7]; | 222 SkPoint cubicPair[7]; |
| 204 SkChopCubicAt(pointsPtr, cubicPair, loopT); | 223 SkChopCubicAt(pointsPtr, cubicPair, loopT); |
| 205 SkPoint cStorage[2][4]; | 224 SkPoint cStorage[2][4]; |
| 206 SkPath::Verb v1 = SkReduceOrder::Cubic(&cubicPair[0], cStora ge[0]); | 225 SkPath::Verb v1 = SkReduceOrder::Cubic(&cubicPair[0], cStora ge[0]); |
| 207 SkPath::Verb v2 = SkReduceOrder::Cubic(&cubicPair[3], cStora ge[1]); | 226 SkPath::Verb v2 = SkReduceOrder::Cubic(&cubicPair[3], cStora ge[1]); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 235 } | 254 } |
| 236 SkASSERT(fCurrentContour); | 255 SkASSERT(fCurrentContour); |
| 237 fCurrentContour->debugValidate(); | 256 fCurrentContour->debugValidate(); |
| 238 pointsPtr += SkPathOpsVerbToPoints(verb); | 257 pointsPtr += SkPathOpsVerbToPoints(verb); |
| 239 } | 258 } |
| 240 if (fCurrentContour && fCurrentContour->count() &&!fAllowOpenContours && !clo se()) { | 259 if (fCurrentContour && fCurrentContour->count() &&!fAllowOpenContours && !clo se()) { |
| 241 return false; | 260 return false; |
| 242 } | 261 } |
| 243 return true; | 262 return true; |
| 244 } | 263 } |
| OLD | NEW |