blob: 18b6328a7e2f815e949baf60a8b8790dcc236de2 [file] [log] [blame]
caryclark@google.com07393ca2013-04-08 11:47:37 +00001/*
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.com07393ca2013-04-08 11:47:37 +00007#include "SkOpContour.h"
caryclark54359292015-03-26 07:52:43 -07008#include "SkOpTAllocator.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +00009#include "SkPathWriter.h"
caryclark54359292015-03-26 07:52:43 -070010#include "SkReduceOrder.h"
commit-bot@chromium.orgb76d3b62013-04-22 19:55:19 +000011#include "SkTSort.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +000012
caryclark03b03ca2015-04-23 09:13:37 -070013SkOpSegment* SkOpContour::addCurve(SkPath::Verb verb, const SkPoint pts[4],
14 SkChunkAlloc* allocator) {
caryclark54359292015-03-26 07:52:43 -070015 switch (verb) {
16 case SkPath::kLine_Verb: {
17 SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 2);
18 memcpy(ptStorage, pts, sizeof(SkPoint) * 2);
caryclark03b03ca2015-04-23 09:13:37 -070019 return appendSegment(allocator).addLine(ptStorage, this);
caryclark54359292015-03-26 07:52:43 -070020 } break;
21 case SkPath::kQuad_Verb: {
22 SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 3);
23 memcpy(ptStorage, pts, sizeof(SkPoint) * 3);
caryclark03b03ca2015-04-23 09:13:37 -070024 return appendSegment(allocator).addQuad(ptStorage, this);
caryclark54359292015-03-26 07:52:43 -070025 } break;
caryclark1049f122015-04-20 08:31:59 -070026 case SkPath::kConic_Verb: {
27 SkASSERT(0); // the original curve is a cubic, which will never reduce to a conic
28 } break;
caryclark54359292015-03-26 07:52:43 -070029 case SkPath::kCubic_Verb: {
30 SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 4);
31 memcpy(ptStorage, pts, sizeof(SkPoint) * 4);
caryclark03b03ca2015-04-23 09:13:37 -070032 return appendSegment(allocator).addCubic(ptStorage, this);
caryclark54359292015-03-26 07:52:43 -070033 } break;
34 default:
35 SkASSERT(0);
caryclark@google.com7eaa53d2013-10-02 14:49:34 +000036 }
caryclark03b03ca2015-04-23 09:13:37 -070037 return NULL;
caryclark@google.com07393ca2013-04-08 11:47:37 +000038}
39
caryclark@google.com07393ca2013-04-08 11:47:37 +000040void SkOpContour::toPath(SkPathWriter* path) const {
caryclark54359292015-03-26 07:52:43 -070041 const SkPoint& pt = fHead.pts()[0];
caryclark@google.com07393ca2013-04-08 11:47:37 +000042 path->deferredMove(pt);
caryclark54359292015-03-26 07:52:43 -070043 const SkOpSegment* segment = &fHead;
44 do {
45 segment->addCurveTo(segment->head(), segment->tail(), path, true);
46 } while ((segment = segment->next()));
caryclark@google.com07393ca2013-04-08 11:47:37 +000047 path->close();
48}
49
caryclark5b5ddd72015-05-18 05:12:56 -070050void 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
caryclark54359292015-03-26 07:52:43 -070060SkOpSegment* SkOpContour::undoneSegment(SkOpSpanBase** startPtr, SkOpSpanBase** endPtr) {
61 SkOpSegment* segment = &fHead;
62 do {
63 if (segment->done()) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000064 continue;
65 }
caryclark54359292015-03-26 07:52:43 -070066 segment->undoneSpan(startPtr, endPtr);
67 return segment;
68 } while ((segment = segment->next()));
caryclark@google.com07393ca2013-04-08 11:47:37 +000069 return NULL;
70}