Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 | 7 |
| 8 #include "GrConvexPolyEffect.h" | 8 #include "GrConvexPolyEffect.h" |
| 9 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
| 10 #include "SkPathPriv.h" | 10 #include "SkPathPriv.h" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 GrFragmentProcessor* GrConvexPolyEffect::Create(GrPrimitiveEdgeType type, const SkPath& path, | 240 GrFragmentProcessor* GrConvexPolyEffect::Create(GrPrimitiveEdgeType type, const SkPath& path, |
| 241 const SkVector* offset) { | 241 const SkVector* offset) { |
| 242 if (kHairlineAA_GrProcessorEdgeType == type) { | 242 if (kHairlineAA_GrProcessorEdgeType == type) { |
| 243 return nullptr; | 243 return nullptr; |
| 244 } | 244 } |
| 245 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || | 245 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || |
| 246 !path.isConvex()) { | 246 !path.isConvex()) { |
| 247 return nullptr; | 247 return nullptr; |
| 248 } | 248 } |
| 249 | 249 |
| 250 if (path.countPoints() > kMaxEdges) { | |
| 251 return nullptr; | |
| 252 } | |
| 253 | |
| 254 SkPoint pts[kMaxEdges]; | |
| 255 SkScalar edges[3 * kMaxEdges]; | |
| 256 | |
| 257 SkPathPriv::FirstDirection dir; | 250 SkPathPriv::FirstDirection dir; |
| 258 // The only way this should fail is if the clip is effectively a infinitely thin line. In that | 251 // The only way this should fail is if the clip is effectively a infinitely thin line. In that |
| 259 // case nothing is inside the clip. It'd be nice to detect this at a higher level and either | 252 // case nothing is inside the clip. It'd be nice to detect this at a higher level and either |
| 260 // skip the draw or omit the clip element. | 253 // skip the draw or omit the clip element. |
| 261 if (!SkPathPriv::CheapComputeFirstDirection(path, &dir)) { | 254 if (!SkPathPriv::CheapComputeFirstDirection(path, &dir)) { |
| 262 if (GrProcessorEdgeTypeIsInverseFill(type)) { | 255 if (GrProcessorEdgeTypeIsInverseFill(type)) { |
| 263 return GrConstColorProcessor::Create(0xFFFFFFFF, | 256 return GrConstColorProcessor::Create(0xFFFFFFFF, |
| 264 GrConstColorProcessor::kModulat eRGBA_InputMode); | 257 GrConstColorProcessor::kModulat eRGBA_InputMode); |
| 265 } | 258 } |
| 266 return GrConstColorProcessor::Create(0, GrConstColorProcessor::kIgnore_I nputMode); | 259 return GrConstColorProcessor::Create(0, GrConstColorProcessor::kIgnore_I nputMode); |
| 267 } | 260 } |
| 268 | 261 |
| 269 SkVector t; | 262 SkVector t; |
| 270 if (nullptr == offset) { | 263 if (nullptr == offset) { |
| 271 t.set(0, 0); | 264 t.set(0, 0); |
| 272 } else { | 265 } else { |
| 273 t = *offset; | 266 t = *offset; |
| 274 } | 267 } |
| 275 | 268 |
| 276 int count = path.getPoints(pts, kMaxEdges); | 269 SkScalar edges[3 * kMaxEdges]; |
| 270 SkPoint pts[4]; | |
| 271 SkPath::Verb verb; | |
| 272 SkPath::Iter iter(path, true); | |
| 273 | |
| 277 int n = 0; | 274 int n = 0; |
| 278 for (int lastPt = count - 1, i = 0; i < count; lastPt = i++) { | 275 while ((verb = iter.next(pts, true, true)) != SkPath::kDone_Verb) { |
|
bsalomon
2016/05/27 20:30:30
Perhaps we should have a comment that has multiple
| |
| 279 if (pts[lastPt] != pts[i]) { | 276 switch (verb) { |
| 280 SkVector v = pts[i] - pts[lastPt]; | 277 case SkPath::kMove_Verb: |
|
bsalomon
2016/05/27 20:30:30
Should we assert here that n is 0?
| |
| 281 v.normalize(); | 278 case SkPath::kClose_Verb: |
| 282 if (SkPathPriv::kCCW_FirstDirection == dir) { | 279 break; |
| 283 edges[3 * n] = v.fY; | 280 case SkPath::kLine_Verb: { |
| 284 edges[3 * n + 1] = -v.fX; | 281 if (n >= kMaxEdges) { |
| 285 } else { | 282 return nullptr; |
| 286 edges[3 * n] = -v.fY; | 283 } |
| 287 edges[3 * n + 1] = v.fX; | 284 SkVector v = pts[1] - pts[0]; |
| 285 v.normalize(); | |
| 286 if (SkPathPriv::kCCW_FirstDirection == dir) { | |
| 287 edges[3 * n] = v.fY; | |
| 288 edges[3 * n + 1] = -v.fX; | |
| 289 } else { | |
| 290 edges[3 * n] = -v.fY; | |
| 291 edges[3 * n + 1] = v.fX; | |
| 292 } | |
| 293 SkPoint p = pts[1] + t; | |
| 294 edges[3 * n + 2] = -(edges[3 * n] * p.fX + edges[3 * n + 1] * p. fY); | |
| 295 ++n; | |
| 296 break; | |
| 288 } | 297 } |
| 289 SkPoint p = pts[i] + t; | 298 default: |
| 290 edges[3 * n + 2] = -(edges[3 * n] * p.fX + edges[3 * n + 1] * p.fY); | 299 return nullptr; |
| 291 ++n; | |
| 292 } | 300 } |
| 293 } | 301 } |
| 302 | |
| 294 if (path.isInverseFillType()) { | 303 if (path.isInverseFillType()) { |
| 295 type = GrInvertProcessorEdgeType(type); | 304 type = GrInvertProcessorEdgeType(type); |
| 296 } | 305 } |
| 297 return Create(type, n, edges); | 306 return Create(type, n, edges); |
| 298 } | 307 } |
| 299 | 308 |
| 300 GrFragmentProcessor* GrConvexPolyEffect::Create(GrPrimitiveEdgeType edgeType, co nst SkRect& rect) { | 309 GrFragmentProcessor* GrConvexPolyEffect::Create(GrPrimitiveEdgeType edgeType, co nst SkRect& rect) { |
| 301 if (kHairlineAA_GrProcessorEdgeType == edgeType){ | 310 if (kHairlineAA_GrProcessorEdgeType == edgeType){ |
| 302 return nullptr; | 311 return nullptr; |
| 303 } | 312 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 } | 362 } |
| 354 | 363 |
| 355 GrFragmentProcessor* fp; | 364 GrFragmentProcessor* fp; |
| 356 do { | 365 do { |
| 357 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( | 366 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( |
| 358 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); | 367 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); |
| 359 fp = GrConvexPolyEffect::Create(edgeType, count, edges); | 368 fp = GrConvexPolyEffect::Create(edgeType, count, edges); |
| 360 } while (nullptr == fp); | 369 } while (nullptr == fp); |
| 361 return fp; | 370 return fp; |
| 362 } | 371 } |
| OLD | NEW |