OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkPatch_DEFINED | 8 #ifndef SkPatch_DEFINED |
9 #define SkPatch_DEFINED | 9 #define SkPatch_DEFINED |
10 | 10 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 }; | 70 }; |
71 | 71 |
72 // Enum for corner colors also clockwise. | 72 // Enum for corner colors also clockwise. |
73 enum CornerColors { | 73 enum CornerColors { |
74 kTopLeft_CornerColors = 0, | 74 kTopLeft_CornerColors = 0, |
75 kTopRight_CornerColors, | 75 kTopRight_CornerColors, |
76 kBottomRight_CornerColors, | 76 kBottomRight_CornerColors, |
77 kBottomLeft_CornerColors | 77 kBottomLeft_CornerColors |
78 }; | 78 }; |
79 | 79 |
80 enum { | |
81 kNumCtrlPts = 12, | |
82 kNumColors = 4, | |
83 kNumPtsCubic = 4 | |
84 }; | |
85 | |
80 /** | 86 /** |
81 * Points are in the following order: | 87 * Points are in the following order: |
82 * (top curve) | 88 * (top curve) |
83 * 0 1 2 3 | 89 * 0 1 2 3 |
84 * (left curve) 11 4 (right curve) | 90 * (left curve) 11 4 (right curve) |
85 * 10 5 | 91 * 10 5 |
86 * 9 8 7 6 | 92 * 9 8 7 6 |
87 * (bottom curve) | 93 * (bottom curve) |
88 */ | 94 */ |
89 SkPatch(SkPoint points[12], SkColor colors[4]); | 95 SkPatch() { } |
96 SkPatch(const SkPoint points[kNumCtrlPts], const SkColor colors[kNumColors]) ; | |
90 | 97 |
91 /** | 98 /** |
92 * Function that evaluates the coons patch interpolation. | 99 * Function that evaluates the coons patch interpolation. |
93 * data refers to the pointer of the PatchData struct in which the tessellat ion data is set. | 100 * data refers to the pointer of the PatchData struct in which the tessellat ion data is set. |
94 * lod refers the level of detail for each axis. | 101 * lod refers the level of detail for each axis. |
95 */ | 102 */ |
96 bool getVertexData(SkPatch::VertexData* data, int lodX, int lodY) const; | 103 bool getVertexData(SkPatch::VertexData* data, int lodX, int lodY) const; |
97 | 104 |
98 void getTopPoints(SkPoint points[4]) const { | 105 void getTopPoints(SkPoint points[kNumPtsCubic]) const { |
99 points[0] = fCtrlPoints[kTopP0_CubicCtrlPts]; | 106 points[0] = fCtrlPoints[kTopP0_CubicCtrlPts]; |
100 points[1] = fCtrlPoints[kTopP1_CubicCtrlPts]; | 107 points[1] = fCtrlPoints[kTopP1_CubicCtrlPts]; |
101 points[2] = fCtrlPoints[kTopP2_CubicCtrlPts]; | 108 points[2] = fCtrlPoints[kTopP2_CubicCtrlPts]; |
102 points[3] = fCtrlPoints[kTopP3_CubicCtrlPts]; | 109 points[3] = fCtrlPoints[kTopP3_CubicCtrlPts]; |
103 } | 110 } |
104 | 111 |
105 void getBottomPoints(SkPoint points[4]) const { | 112 void getBottomPoints(SkPoint points[kNumPtsCubic]) const { |
106 points[0] = fCtrlPoints[kBottomP0_CubicCtrlPts]; | 113 points[0] = fCtrlPoints[kBottomP0_CubicCtrlPts]; |
107 points[1] = fCtrlPoints[kBottomP1_CubicCtrlPts]; | 114 points[1] = fCtrlPoints[kBottomP1_CubicCtrlPts]; |
108 points[2] = fCtrlPoints[kBottomP2_CubicCtrlPts]; | 115 points[2] = fCtrlPoints[kBottomP2_CubicCtrlPts]; |
109 points[3] = fCtrlPoints[kBottomP3_CubicCtrlPts]; | 116 points[3] = fCtrlPoints[kBottomP3_CubicCtrlPts]; |
110 } | 117 } |
111 | 118 |
112 void getLeftPoints(SkPoint points[4]) const { | 119 void getLeftPoints(SkPoint points[kNumPtsCubic]) const { |
113 points[0] = fCtrlPoints[kLeftP0_CubicCtrlPts]; | 120 points[0] = fCtrlPoints[kLeftP0_CubicCtrlPts]; |
114 points[1] = fCtrlPoints[kLeftP1_CubicCtrlPts]; | 121 points[1] = fCtrlPoints[kLeftP1_CubicCtrlPts]; |
115 points[2] = fCtrlPoints[kLeftP2_CubicCtrlPts]; | 122 points[2] = fCtrlPoints[kLeftP2_CubicCtrlPts]; |
116 points[3] = fCtrlPoints[kLeftP3_CubicCtrlPts]; | 123 points[3] = fCtrlPoints[kLeftP3_CubicCtrlPts]; |
117 } | 124 } |
118 | 125 |
119 void getRightPoints(SkPoint points[4]) const { | 126 void getRightPoints(SkPoint points[kNumPtsCubic]) const { |
120 points[0] = fCtrlPoints[kRightP0_CubicCtrlPts]; | 127 points[0] = fCtrlPoints[kRightP0_CubicCtrlPts]; |
121 points[1] = fCtrlPoints[kRightP1_CubicCtrlPts]; | 128 points[1] = fCtrlPoints[kRightP1_CubicCtrlPts]; |
122 points[2] = fCtrlPoints[kRightP2_CubicCtrlPts]; | 129 points[2] = fCtrlPoints[kRightP2_CubicCtrlPts]; |
123 points[3] = fCtrlPoints[kRightP3_CubicCtrlPts]; | 130 points[3] = fCtrlPoints[kRightP3_CubicCtrlPts]; |
124 } | 131 } |
125 | 132 |
robertphillips
2014/08/05 12:44:45
Not sure about this use of kNumPtsCubic. This coul
dandov
2014/08/05 14:27:11
Done.
| |
126 void getCornerPoints(SkPoint points[4]) const { | 133 void getCornerPoints(SkPoint points[kNumPtsCubic]) const { |
127 points[0] = fCtrlPoints[kTopP0_CubicCtrlPts]; | 134 points[0] = fCtrlPoints[kTopP0_CubicCtrlPts]; |
128 points[1] = fCtrlPoints[kTopP3_CubicCtrlPts]; | 135 points[1] = fCtrlPoints[kTopP3_CubicCtrlPts]; |
129 points[2] = fCtrlPoints[kBottomP3_CubicCtrlPts]; | 136 points[2] = fCtrlPoints[kBottomP3_CubicCtrlPts]; |
130 points[3] = fCtrlPoints[kBottomP0_CubicCtrlPts]; | 137 points[3] = fCtrlPoints[kBottomP0_CubicCtrlPts]; |
131 } | 138 } |
132 | 139 |
133 const SkPoint* getControlPoints() const { | 140 const SkPoint* getControlPoints() const { |
134 return fCtrlPoints; | 141 return fCtrlPoints; |
135 } | 142 } |
136 | 143 |
137 const SkColor* getColors() const { | 144 const SkColor* getColors() const { |
138 return fCornerColors; | 145 return fCornerColors; |
139 } | 146 } |
140 | 147 |
148 void setPoints(const SkPoint points[kNumCtrlPts]) { | |
149 memcpy(fCtrlPoints, points, kNumCtrlPts * sizeof(SkPoint)); | |
150 | |
151 } | |
152 | |
153 void setColors(const SkColor colors[kNumColors]) { | |
154 memcpy(fCornerColors, colors, kNumColors * sizeof(SkColor)); | |
155 } | |
156 | |
157 void reset(const SkPoint points[kNumCtrlPts], const SkColor colors[kNumColor s]) { | |
158 this->setPoints(points); | |
159 this->setColors(colors); | |
160 } | |
161 | |
162 /** | |
163 * Write the patch to the buffer, and return the number of bytes written. | |
164 * If buffer is NULL, it still returns the number of bytes. | |
165 */ | |
166 size_t writeToMemory(void* buffer) const; | |
167 | |
168 /** | |
169 * Initializes the patch from the buffer | |
170 * | |
171 * buffer Memory to read from | |
172 * length Amount of memory available in the buffer | |
robertphillips
2014/08/05 12:44:45
Add a "Returns" before "number" ?
dandov
2014/08/05 14:27:11
Done.
| |
173 * number of bytes read (must be a multiple of 4) or | |
174 * 0 if there was not enough memory available | |
175 */ | |
176 size_t readFromMemory(const void* buffer, size_t length); | |
177 | |
141 private: | 178 private: |
142 SkPoint fCtrlPoints[12]; | 179 SkPoint fCtrlPoints[kNumCtrlPts]; |
143 SkColor fCornerColors[4]; | 180 SkColor fCornerColors[kNumColors]; |
144 }; | 181 }; |
145 | 182 |
146 #endif | 183 #endif |
OLD | NEW |