OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 SkLinearBitmapPipeline_tile_DEFINED | 8 #ifndef SkLinearBitmapPipeline_tile_DEFINED |
9 #define SkLinearBitmapPipeline_tile_DEFINED | 9 #define SkLinearBitmapPipeline_tile_DEFINED |
10 | 10 |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
227 return true; | 227 return true; |
228 } | 228 } |
229 | 229 |
230 private: | 230 private: |
231 const SkScalar fXMax; | 231 const SkScalar fXMax; |
232 const Sk4s fXsMax; | 232 const Sk4s fXsMax; |
233 const Sk4s fXsCap; | 233 const Sk4s fXsCap; |
234 const Sk4s fXsInvMax; | 234 const Sk4s fXsInvMax; |
235 }; | 235 }; |
236 | 236 |
237 class XRepeatUnitScaleStrategy { | |
238 public: | |
239 XRepeatUnitScaleStrategy(int32_t max) | |
240 : fXMax{SkScalar(max)} | |
241 , fXsMax{SkScalar(max)} | |
242 , fXsCap{SkScalar(nextafterf(SkScalar(max), 0.0f))} | |
243 , fXsInvMax{1.0f / SkScalar(max)} { } | |
244 | |
245 void tileXPoints(Sk4s* xs) { | |
f(malita)
2016/03/31 13:58:19
I'm a bit behind on this - why Sk4s and not Sk4f?
mtklein
2016/03/31 15:12:42
It parallels SkScalar. Imagine if SkScalar were d
| |
246 Sk4s divX = *xs * fXsInvMax; | |
247 Sk4s modX = *xs - divX.floor() * fXsMax; | |
248 *xs = Sk4s::Min(fXsCap, modX); | |
249 SkASSERT(0 <= (*xs)[0] && (*xs)[0] < fXMax); | |
250 SkASSERT(0 <= (*xs)[1] && (*xs)[1] < fXMax); | |
251 SkASSERT(0 <= (*xs)[2] && (*xs)[2] < fXMax); | |
252 SkASSERT(0 <= (*xs)[3] && (*xs)[3] < fXMax); | |
253 } | |
254 | |
255 template<typename Next> | |
256 bool maybeProcessSpan(Span originalSpan, Next* next) { | |
257 SkASSERT(!originalSpan.isEmpty()); | |
258 SkPoint start; SkScalar length; int count; | |
259 std::tie(start, length, count) = originalSpan; | |
260 // Make x and y in range on the tile. | |
261 SkScalar x = tile_mod(X(start), fXMax); | |
262 SkScalar y = Y(start); | |
263 | |
264 // No need trying to go fast because the steps are larger than a tile or there is one point. | |
265 if (fXMax == 1 || count <= 1) { | |
266 return false; | |
267 } | |
268 | |
269 // x should be on the tile. | |
270 SkASSERT(0.0f <= x && x < fXMax); | |
271 Span span({x, y}, length, count); | |
272 | |
273 if (SkScalarFloorToScalar(x) != 0.0f) { | |
274 Span toDraw = span.breakAt(fXMax, 1.0f); | |
275 next->pointSpan(toDraw); | |
276 span.offset(-fXMax); | |
277 } | |
278 | |
279 // All of the span could have been on the first tile. If so, then no wor k to do. | |
280 if (!span.isEmpty()) { | |
f(malita)
2016/03/31 13:58:19
Nit: I would write this as an early return to unne
| |
281 // At this point the span should be aligned to zero. | |
282 SkASSERT(SkScalarFloorToScalar(span.startX()) == 0.0f); | |
283 | |
284 SkScalar div = span.length() / fXMax; | |
285 int32_t repeatCount = SkScalarFloorToInt(div); | |
286 Span repeatableSpan{{0.0f, y}, fXMax - 1.0f, SkScalarFloorToInt(fXMa x)}; | |
287 | |
288 // Repeat the center section. | |
289 next->repeatSpan(repeatableSpan, repeatCount); | |
290 | |
291 // There may be some of the span left over. | |
292 span.breakAt(SkScalar(repeatCount) * fXMax, 1.0f); | |
293 | |
294 // All on a single tile. | |
295 if (!span.isEmpty()) { | |
296 next->pointSpan(span); | |
297 } | |
298 } | |
299 | |
300 return true; | |
301 } | |
302 | |
303 private: | |
304 const SkScalar fXMax; | |
305 const Sk4s fXsMax; | |
306 const Sk4s fXsCap; | |
307 const Sk4s fXsInvMax; | |
308 }; | |
309 | |
237 class YRepeatStrategy { | 310 class YRepeatStrategy { |
238 public: | 311 public: |
239 YRepeatStrategy(int32_t max) | 312 YRepeatStrategy(int32_t max) |
240 : fYMax{SkScalar(max)} | 313 : fYMax{SkScalar(max)} |
241 , fYsMax{SkScalar(max)} | 314 , fYsMax{SkScalar(max)} |
242 , fYsInvMax{1.0f / SkScalar(max)} { } | 315 , fYsInvMax{1.0f / SkScalar(max)} { } |
243 | 316 |
244 void tileYPoints(Sk4s* ys) { | 317 void tileYPoints(Sk4s* ys) { |
245 Sk4s divY = *ys * fYsInvMax; | 318 Sk4s divY = *ys * fYsInvMax; |
246 Sk4s modY = *ys - divY.floor() * fYsMax; | 319 Sk4s modY = *ys - divY.floor() * fYsMax; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
324 | 397 |
325 private: | 398 private: |
326 SkScalar fYMax; | 399 SkScalar fYMax; |
327 Sk4f fYsMax; | 400 Sk4f fYsMax; |
328 Sk4f fYsCap; | 401 Sk4f fYsCap; |
329 Sk4f fYsDoubleInvMax; | 402 Sk4f fYsDoubleInvMax; |
330 }; | 403 }; |
331 | 404 |
332 } // namespace | 405 } // namespace |
333 #endif // SkLinearBitmapPipeline_tile_DEFINED | 406 #endif // SkLinearBitmapPipeline_tile_DEFINED |
OLD | NEW |