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) { | |
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()) return true; | |
281 | |
282 // At this point the span should be aligned to zero. | |
283 SkASSERT(SkScalarFloorToScalar(span.startX()) == 0.0f); | |
284 | |
285 SkScalar div = span.length() / fXMax; | |
286 int32_t repeatCount = SkScalarFloorToInt(div); | |
287 Span repeatableSpan{{0.0f, y}, fXMax - 1.0f, SkScalarFloorToInt(fXMax)}; | |
288 | |
289 // Repeat the center section. | |
290 next->repeatSpan(repeatableSpan, repeatCount); | |
291 | |
292 // There may be some of the span left over. | |
293 span.breakAt(SkScalar(repeatCount) * fXMax, 1.0f); | |
294 | |
295 // All on a single tile. | |
296 if (!span.isEmpty()) { | |
297 next->pointSpan(span); | |
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 | |
310 class YRepeatStrategy { | 237 class YRepeatStrategy { |
311 public: | 238 public: |
312 YRepeatStrategy(int32_t max) | 239 YRepeatStrategy(int32_t max) |
313 : fYMax{SkScalar(max)} | 240 : fYMax{SkScalar(max)} |
314 , fYsMax{SkScalar(max)} | 241 , fYsMax{SkScalar(max)} |
315 , fYsInvMax{1.0f / SkScalar(max)} { } | 242 , fYsInvMax{1.0f / SkScalar(max)} { } |
316 | 243 |
317 void tileYPoints(Sk4s* ys) { | 244 void tileYPoints(Sk4s* ys) { |
318 Sk4s divY = *ys * fYsInvMax; | 245 Sk4s divY = *ys * fYsInvMax; |
319 Sk4s modY = *ys - divY.floor() * fYsMax; | 246 Sk4s modY = *ys - divY.floor() * fYsMax; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 | 324 |
398 private: | 325 private: |
399 SkScalar fYMax; | 326 SkScalar fYMax; |
400 Sk4f fYsMax; | 327 Sk4f fYsMax; |
401 Sk4f fYsCap; | 328 Sk4f fYsCap; |
402 Sk4f fYsDoubleInvMax; | 329 Sk4f fYsDoubleInvMax; |
403 }; | 330 }; |
404 | 331 |
405 } // namespace | 332 } // namespace |
406 #endif // SkLinearBitmapPipeline_tile_DEFINED | 333 #endif // SkLinearBitmapPipeline_tile_DEFINED |
OLD | NEW |