OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2014 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 | |
8 #ifndef SkPatch_DEFINED | |
9 #define SkPatch_DEFINED | |
10 | |
11 #include "SkPreConfig.h" | |
egdaniel
2014/07/21 21:16:03
In general we like to keep includes in alphabetica
dandov
2014/07/22 13:55:14
Done.
| |
12 #include "SkTypes.h" | |
13 #include "SkScalar.h" | |
14 #include "SkPoint.h" | |
15 #include "SkColor.h" | |
16 #include "GrColor.h" | |
17 | |
18 #include <stdint.h> | |
19 | |
20 | |
21 class SkPatchMesh; | |
jvanverth1
2014/07/21 22:10:09
This forward declaration isn't needed.
dandov
2014/07/22 13:55:14
Done.
| |
22 | |
23 class SkPatchMesh { | |
egdaniel
2014/07/21 21:16:03
Comment here describing what an SkPatchMesh is
dandov
2014/07/22 13:55:14
Done.
| |
24 | |
25 public: | |
26 | |
27 /** | |
28 * Client is responsible for setting up the PatchMesh by providing which vari ables it is going | |
egdaniel
2014/07/21 21:16:03
Nit: all the "*" should be lined up with the first
dandov
2014/07/22 13:55:14
Done.
| |
29 * to use and by allocating its memory. | |
30 * Vertices and Indices are always generated. | |
31 * useColors and useTexCoords define if this patchmesh will handle colors and texture coordinates | |
32 * intercalated defines if the data is: | |
33 * array of objects {{vertex,color,uv}, {vertex,color,uv}, {vertex,col or,uv}} | |
34 * object of arrays {{vertex, vertex, vertex}, {color, color, color}, {uv, uv, uv}} | |
35 */ | |
36 SkPatchMesh(); | |
37 | |
38 enum SkColorFormat { | |
39 kNoColor_ColorFormat, | |
40 kSkColor_ColorFormat, | |
41 //kSkPMColor_ColorFormat, | |
42 kGrColor_ColorFormat | |
43 }; | |
44 | |
45 void init(int vertCount, int indexCount, SkColorFormat format, bool useTexCo ords, | |
46 bool intercalate); | |
47 | |
48 ~SkPatchMesh(); | |
49 | |
50 /** | |
51 * The client is responsible for setting the values using the functions verte xAt, colorAt, | |
52 * texCoordAt. These functions have an assert to check if this patchmesh hand les colors or | |
53 * texture coordinates and if it is an array of objects or and object of arra ys, based on this | |
54 * and the type of arrays being used they return a reference to the value to be set. | |
55 */ | |
56 SkPoint& pointAt(int index); | |
57 | |
58 uint32_t& colorAt(int index); | |
59 bool setColorAt(int index, uint8_t r, uint8_t g, uint8_t b, uint8_t a); | |
60 | |
61 SkPoint& texCoordAt(int index); | |
62 | |
63 /** | |
64 * The client is responsible for setting up the indices. Index refers to whic h group of indices | |
65 * to set, indices refers to the pointer of the data to set and size is the n umber of elements | |
66 * that are going to set. | |
67 * They need to be separated because (depending on the patch) they might be l ess number of | |
68 * indices than vertices. | |
69 */ | |
70 void setIndices(int index, uint16_t* indices, int size); | |
71 | |
72 int getVertexCount(); | |
73 | |
74 int getIndexCount(); | |
75 | |
76 bool useColors(); | |
77 | |
78 bool useTexCoords(); | |
79 | |
80 bool isIntercalated(); | |
81 | |
82 const SkPoint* getPoints(); | |
83 | |
84 const uint16_t* getIndices(); | |
85 | |
86 const SkColor* getColors(); | |
87 | |
88 const SkPoint* getTexCoords(); | |
89 | |
90 const uint8_t* getData(); | |
91 | |
92 private: | |
93 int fVertCount, fIndexCount; | |
94 uint8_t* fData; | |
95 uint16_t* fIndices; | |
96 bool fUseColors, fUseTexCoords, fIntercalate; | |
97 int fColorOffset, fTexOffset, fDataSize; | |
98 SkColorFormat fColorFormat; | |
99 | |
100 void reset(); | |
101 }; | |
102 | |
103 class SK_API SkPatch { | |
egdaniel
2014/07/21 21:16:03
Comment describing what an SkPatch is
dandov
2014/07/22 13:55:14
Done.
| |
104 | |
jvanverth1
2014/07/21 22:10:09
Unless we're planning on supporting other patch ty
| |
105 public: | |
106 | |
107 virtual ~SkPatch() { } | |
108 | |
109 virtual bool genMesh(SkPatchMesh* mesh, SkPatchMesh::SkColorFormat format, b ool useTexCoords, | |
110 bool intercalate) const = 0; | |
111 virtual bool usesColors() const = 0; | |
112 virtual bool usesTexCoords() const = 0; | |
113 }; | |
114 | |
115 class CubicEvaluator { | |
jvanverth1
2014/07/21 22:10:09
SkCubicEvaluator
| |
116 | |
117 public: | |
118 CubicEvaluator(){ } | |
119 | |
120 /** | |
121 * Receives the 4 control points for the cubic. | |
122 */ | |
123 CubicEvaluator(SkPoint a, SkPoint b, SkPoint c, SkPoint d); | |
124 | |
125 /* | |
126 * Evaluate cubic bezier given a t parameter. | |
127 */ | |
128 SkPoint eval(SkScalar t); | |
129 | |
130 /* | |
131 * Evaluate cubic bezier using forward differences. | |
132 * Call hasNext to check if the next value is still within the range t=[0,1]. | |
133 * Call next to obtain the SkPoint sampled at the next t. | |
134 * Call reset to start sampling from t=0 | |
135 */ | |
136 bool hasNext(); | |
137 | |
138 SkPoint next(); | |
139 | |
140 void reset(int res); | |
jvanverth1
2014/07/21 22:10:09
Since reset() is the first thing you'd do, I'd put
dandov
2014/07/22 13:55:14
Done.
| |
141 | |
142 const SkPoint* getPoints(); | |
143 | |
144 const SkPoint* getCoefs(); | |
145 | |
146 int getResolution(); | |
147 | |
148 private: | |
149 int fMax, fCurrent, fRes; | |
jvanverth1
2014/07/21 22:10:09
Indented too far.
dandov
2014/07/22 13:55:14
I don't know why these are indented like that beca
| |
150 SkPoint fFwDiff[4], fCoefs[4], fPoints[4]; | |
151 }; | |
152 | |
153 class SK_API SkCoonsPatch : public SkPatch{ | |
154 | |
155 public: | |
156 SkCoonsPatch() { } | |
jvanverth1
2014/07/21 22:10:09
Indent.
| |
157 | |
158 /* | |
159 * Points are in the following order: | |
160 * (bottom curve) | |
161 * 0 1 2 3 | |
162 * (left curve) 8 10 (right curve) | |
163 * 9 11 | |
164 * 4 5 6 7 | |
165 * (top curve) | |
166 * Used pointer to an array to guarantee that this method receives an array o f 4 SkColors | |
167 */ | |
168 SkCoonsPatch(SkPoint points[12], SkColor (*colors)[4], int resX); | |
169 | |
170 virtual bool genMesh(SkPatchMesh* mesh, | |
171 SkPatchMesh::SkColorFormat format = SkPatchMesh::kSkColor_ColorFormat, | |
172 bool useTexCoords = false, bool intercalate = false) const; | |
jvanverth1
2014/07/21 22:10:09
With two booleans in a row, it's going to be uncle
dandov
2014/07/22 13:55:14
Added an enum for the array format that also provi
| |
173 | |
174 virtual bool usesColors() const { | |
175 return true; | |
176 } | |
177 | |
178 virtual bool usesTexCoords() const SK_OVERRIDE { | |
179 return false; | |
180 } | |
181 | |
182 CubicEvaluator getTop() { return fTop; } | |
183 | |
184 CubicEvaluator getLeft() { return fLeft; } | |
185 | |
186 CubicEvaluator getRight() { return fRight; } | |
187 | |
188 CubicEvaluator getBottom() { return fBottom; } | |
189 | |
190 const SkPoint* getTopPoints() { return fTop.getPoints(); } | |
191 | |
192 const SkPoint* getLeftPoints() { return fLeft.getPoints(); } | |
193 | |
194 const SkPoint* getRightPoints() { return fRight.getPoints(); } | |
195 | |
196 const SkPoint* getBottomPoints() { return fBottom.getPoints(); } | |
197 | |
198 private: | |
199 SkPoint* fPoints; | |
200 mutable CubicEvaluator fBottom, fTop, fLeft, fRight; | |
jvanverth1
2014/07/21 22:10:09
Indent.
| |
201 SkPMColor fColors[4]; | |
202 int fResX, fResY; | |
203 | |
204 typedef SkPatch INHERITED; | |
205 }; | |
206 | |
207 #endif | |
OLD | NEW |