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