Debian Codegraph @

src/core/SkEdgeBuilder.h

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