• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 */
7 #include "SkOpContour.h"
8 #include "SkOpTAllocator.h"
9 #include "SkPathWriter.h"
10 #include "SkReduceOrder.h"
11 #include "SkTSort.h"
12 
addCurve(SkPath::Verb verb,const SkPoint pts[4],SkChunkAlloc * allocator)13 SkOpSegment* SkOpContour::addCurve(SkPath::Verb verb, const SkPoint pts[4],
14         SkChunkAlloc* allocator) {
15     switch (verb) {
16         case SkPath::kLine_Verb: {
17             SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 2);
18             memcpy(ptStorage, pts, sizeof(SkPoint) * 2);
19             return appendSegment(allocator).addLine(ptStorage, this);
20         } break;
21         case SkPath::kQuad_Verb: {
22             SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 3);
23             memcpy(ptStorage, pts, sizeof(SkPoint) * 3);
24             return appendSegment(allocator).addQuad(ptStorage, this);
25         } break;
26         case SkPath::kConic_Verb: {
27             SkASSERT(0);  // the original curve is a cubic, which will never reduce to a conic
28         } break;
29         case SkPath::kCubic_Verb: {
30             SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 4);
31             memcpy(ptStorage, pts, sizeof(SkPoint) * 4);
32             return appendSegment(allocator).addCubic(ptStorage, this);
33         } break;
34         default:
35             SkASSERT(0);
36     }
37     return nullptr;
38 }
39 
toPath(SkPathWriter * path) const40 void SkOpContour::toPath(SkPathWriter* path) const {
41     const SkPoint& pt = fHead.pts()[0];
42     path->deferredMove(pt);
43     const SkOpSegment* segment = &fHead;
44     do {
45         SkAssertResult(segment->addCurveTo(segment->head(), segment->tail(), path));
46     } while ((segment = segment->next()));
47     path->close();
48 }
49 
toReversePath(SkPathWriter * path) const50 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         SkAssertResult(segment->addCurveTo(segment->tail(), segment->head(), path));
56     } while ((segment = segment->prev()));
57     path->close();
58 }
59 
undoneSegment(SkOpSpanBase ** startPtr,SkOpSpanBase ** endPtr)60 SkOpSegment* SkOpContour::undoneSegment(SkOpSpanBase** startPtr, SkOpSpanBase** endPtr) {
61     SkOpSegment* segment = &fHead;
62     do {
63         if (segment->done()) {
64             continue;
65         }
66         segment->undoneSpan(startPtr, endPtr);
67         return segment;
68     } while ((segment = segment->next()));
69     return nullptr;
70 }
71