1 | /* |
2 | * Copyright 2011 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 | #ifndef SkEdgeBuilder_DEFINED |
8 | #define SkEdgeBuilder_DEFINED |
9 | |
10 | #include "include/core/SkRect.h" |
11 | #include "include/private/SkTDArray.h" |
12 | #include "src/core/SkAnalyticEdge.h" |
13 | #include "src/core/SkArenaAlloc.h" |
14 | #include "src/core/SkEdge.h" |
15 | |
16 | struct SkPathView; |
17 | |
18 | class SkEdgeBuilder { |
19 | public: |
20 | int buildEdges(const SkPathView&, const SkIRect* shiftedClip); |
21 | |
22 | protected: |
23 | SkEdgeBuilder() = default; |
24 | virtual ~SkEdgeBuilder() = default; |
25 | |
26 | // In general mode we allocate pointers in fList and fEdgeList points to its head. |
27 | // In polygon mode we preallocated edges contiguously in fAlloc and fEdgeList points there. |
28 | void** fEdgeList = nullptr; |
29 | SkTDArray<void*> fList; |
30 | SkSTArenaAlloc<512> fAlloc; |
31 | |
32 | enum Combine { |
33 | kNo_Combine, |
34 | kPartial_Combine, |
35 | kTotal_Combine |
36 | }; |
37 | |
38 | private: |
39 | int build (const SkPathView&, const SkIRect* clip, bool clipToTheRight); |
40 | int buildPoly(const SkPathView&, const SkIRect* clip, bool clipToTheRight); |
41 | |
42 | virtual char* allocEdges(size_t n, size_t* sizeof_edge) = 0; |
43 | virtual SkRect recoverClip(const SkIRect&) const = 0; |
44 | |
45 | virtual void addLine (const SkPoint pts[]) = 0; |
46 | virtual void addQuad (const SkPoint pts[]) = 0; |
47 | virtual void addCubic(const SkPoint pts[]) = 0; |
48 | virtual Combine addPolyLine(const SkPoint pts[], char* edge, char** edgePtr) = 0; |
49 | }; |
50 | |
51 | class SkBasicEdgeBuilder final : public SkEdgeBuilder { |
52 | public: |
53 | explicit SkBasicEdgeBuilder(int clipShift) : fClipShift(clipShift) {} |
54 | |
55 | SkEdge** edgeList() { return (SkEdge**)fEdgeList; } |
56 | |
57 | private: |
58 | Combine combineVertical(const SkEdge* edge, SkEdge* last); |
59 | |
60 | char* allocEdges(size_t, size_t*) override; |
61 | SkRect recoverClip(const SkIRect&) const override; |
62 | |
63 | void addLine (const SkPoint pts[]) override; |
64 | void addQuad (const SkPoint pts[]) override; |
65 | void addCubic(const SkPoint pts[]) override; |
66 | Combine addPolyLine(const SkPoint pts[], char* edge, char** edgePtr) override; |
67 | |
68 | const int fClipShift; |
69 | }; |
70 | |
71 | class SkAnalyticEdgeBuilder final : public SkEdgeBuilder { |
72 | public: |
73 | SkAnalyticEdgeBuilder() {} |
74 | |
75 | SkAnalyticEdge** analyticEdgeList() { return (SkAnalyticEdge**)fEdgeList; } |
76 | |
77 | private: |
78 | Combine combineVertical(const SkAnalyticEdge* edge, SkAnalyticEdge* last); |
79 | |
80 | char* allocEdges(size_t, size_t*) override; |
81 | SkRect recoverClip(const SkIRect&) const override; |
82 | |
83 | void addLine (const SkPoint pts[]) override; |
84 | void addQuad (const SkPoint pts[]) override; |
85 | void addCubic(const SkPoint pts[]) override; |
86 | Combine addPolyLine(const SkPoint pts[], char* edge, char** edgePtr) override; |
87 | }; |
88 | #endif |
89 | |