caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 7 | #include "SkOpContour.h" |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 8 | #include "SkOpTAllocator.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 9 | #include "SkPathWriter.h" |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 10 | #include "SkReduceOrder.h" |
commit-bot@chromium.org | b76d3b6 | 2013-04-22 19:55:19 +0000 | [diff] [blame] | 11 | #include "SkTSort.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 12 | |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 13 | SkOpSegment* SkOpContour::addCurve(SkPath::Verb verb, const SkPoint pts[4], |
| 14 | SkChunkAlloc* allocator) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 15 | switch (verb) { |
| 16 | case SkPath::kLine_Verb: { |
| 17 | SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 2); |
| 18 | memcpy(ptStorage, pts, sizeof(SkPoint) * 2); |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 19 | return appendSegment(allocator).addLine(ptStorage, this); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 20 | } break; |
| 21 | case SkPath::kQuad_Verb: { |
| 22 | SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 3); |
| 23 | memcpy(ptStorage, pts, sizeof(SkPoint) * 3); |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 24 | return appendSegment(allocator).addQuad(ptStorage, this); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 25 | } break; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 26 | case SkPath::kConic_Verb: { |
| 27 | SkASSERT(0); // the original curve is a cubic, which will never reduce to a conic |
| 28 | } break; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 29 | case SkPath::kCubic_Verb: { |
| 30 | SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 4); |
| 31 | memcpy(ptStorage, pts, sizeof(SkPoint) * 4); |
caryclark | 03b03ca | 2015-04-23 09:13:37 -0700 | [diff] [blame] | 32 | return appendSegment(allocator).addCubic(ptStorage, this); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 33 | } break; |
| 34 | default: |
| 35 | SkASSERT(0); |
caryclark@google.com | 7eaa53d | 2013-10-02 14:49:34 +0000 | [diff] [blame] | 36 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 37 | return nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 38 | } |
| 39 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 40 | void SkOpContour::toPath(SkPathWriter* path) const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 41 | const SkPoint& pt = fHead.pts()[0]; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 42 | path->deferredMove(pt); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 43 | const SkOpSegment* segment = &fHead; |
| 44 | do { |
| 45 | segment->addCurveTo(segment->head(), segment->tail(), path, true); |
| 46 | } while ((segment = segment->next())); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 47 | path->close(); |
| 48 | } |
| 49 | |
caryclark | 5b5ddd7 | 2015-05-18 05:12:56 -0700 | [diff] [blame] | 50 | void SkOpContour::toReversePath(SkPathWriter* path) const { |
| 51 | const SkPoint& pt = fTail->pts()[0]; |
| 52 | path->deferredMove(pt); |
| 53 | const SkOpSegment* segment = fTail; |
| 54 | do { |
| 55 | segment->addCurveTo(segment->tail(), segment->head(), path, true); |
| 56 | } while ((segment = segment->prev())); |
| 57 | path->close(); |
| 58 | } |
| 59 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 60 | SkOpSegment* SkOpContour::undoneSegment(SkOpSpanBase** startPtr, SkOpSpanBase** endPtr) { |
| 61 | SkOpSegment* segment = &fHead; |
| 62 | do { |
| 63 | if (segment->done()) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 64 | continue; |
| 65 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 66 | segment->undoneSpan(startPtr, endPtr); |
| 67 | return segment; |
| 68 | } while ((segment = segment->next())); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 69 | return nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 70 | } |