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 #include "SkPatchUtils.h" | 8 #include "SkPatchUtils.h" |
9 | 9 |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 points[1] = cubics[kRightP1_CubicCtrlPts]; | 197 points[1] = cubics[kRightP1_CubicCtrlPts]; |
198 points[2] = cubics[kRightP2_CubicCtrlPts]; | 198 points[2] = cubics[kRightP2_CubicCtrlPts]; |
199 points[3] = cubics[kRightP3_CubicCtrlPts]; | 199 points[3] = cubics[kRightP3_CubicCtrlPts]; |
200 } | 200 } |
201 | 201 |
202 bool SkPatchUtils::getVertexData(SkPatchUtils::VertexData* data, const SkPoint c
ubics[12], | 202 bool SkPatchUtils::getVertexData(SkPatchUtils::VertexData* data, const SkPoint c
ubics[12], |
203 const SkColor colors[4], const SkPoint texCoords[4], int lodX
, int lodY) { | 203 const SkColor colors[4], const SkPoint texCoords[4], int lodX
, int lodY) { |
204 if (lodX < 1 || lodY < 1 || NULL == cubics || NULL == data) { | 204 if (lodX < 1 || lodY < 1 || NULL == cubics || NULL == data) { |
205 return false; | 205 return false; |
206 } | 206 } |
207 | 207 |
208 // number of indices is limited by size of uint16_t, so we clamp it to avoid
overflow | 208 // check for overflow in multiplication |
209 data->fVertexCount = SkMin32((lodX + 1) * (lodY + 1), 65536); | 209 const int64_t lodX64 = (lodX + 1), |
210 lodX = SkMin32(lodX, 255); | 210 lodY64 = (lodY + 1), |
211 lodY = SkMin32(lodY, 255); | 211 mult64 = lodX64 * lodY64; |
| 212 if (mult64 > SK_MaxS32) { |
| 213 return false; |
| 214 } |
| 215 data->fVertexCount = SkToS32(mult64); |
| 216 |
| 217 // it is recommended to generate draw calls of no more than 65536 indices, s
o we never generate |
| 218 // more than 60000 indices. To accomplish that we resize the LOD and vertex
count |
| 219 if (data->fVertexCount > 10000 || lodX > 200 || lodY > 200) { |
| 220 SkScalar weightX = static_cast<SkScalar>(lodX) / (lodX + lodY); |
| 221 SkScalar weightY = static_cast<SkScalar>(lodY) / (lodX + lodY); |
| 222 |
| 223 // 200 comes from the 100 * 2 which is the max value of vertices because
of the limit of |
| 224 // 60000 indices ( sqrt(60000 / 6) that comes from data->fIndexCount = l
odX * lodY * 6) |
| 225 lodX = static_cast<int>(weightX * 200); |
| 226 lodY = static_cast<int>(weightY * 200); |
| 227 data->fVertexCount = (lodX + 1) * (lodY + 1); |
| 228 } |
212 data->fIndexCount = lodX * lodY * 6; | 229 data->fIndexCount = lodX * lodY * 6; |
213 | 230 |
214 data->fPoints = SkNEW_ARRAY(SkPoint, data->fVertexCount); | 231 data->fPoints = SkNEW_ARRAY(SkPoint, data->fVertexCount); |
215 data->fIndices = SkNEW_ARRAY(uint16_t, data->fIndexCount); | 232 data->fIndices = SkNEW_ARRAY(uint16_t, data->fIndexCount); |
216 | 233 |
217 // if colors is not null then create array for colors | 234 // if colors is not null then create array for colors |
218 SkPMColor colorsPM[kNumCorners]; | 235 SkPMColor colorsPM[kNumCorners]; |
219 if (NULL != colors) { | 236 if (NULL != colors) { |
220 // premultiply colors to avoid color bleeding. | 237 // premultiply colors to avoid color bleeding. |
221 for (int i = 0; i < kNumCorners; i++) { | 238 for (int i = 0; i < kNumCorners; i++) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 data->fIndices[i + 4] = data->fIndices[i + 2]; | 332 data->fIndices[i + 4] = data->fIndices[i + 2]; |
316 data->fIndices[i + 5] = (x + 1) * stride + y; | 333 data->fIndices[i + 5] = (x + 1) * stride + y; |
317 } | 334 } |
318 v = SkScalarClampMax(v + 1.f / lodY, 1); | 335 v = SkScalarClampMax(v + 1.f / lodY, 1); |
319 } | 336 } |
320 u = SkScalarClampMax(u + 1.f / lodX, 1); | 337 u = SkScalarClampMax(u + 1.f / lodX, 1); |
321 } | 338 } |
322 return true; | 339 return true; |
323 | 340 |
324 } | 341 } |
OLD | NEW |