Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: src/core/SkLinearBitmapPipeline_tile.h

Issue 1837893004: Add unit repeat tiler (Closed) Base URL: https://skia.googlesource.com/skia.git@enhance-bilerp-interface
Patch Set: Address florin's comments. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkLinearBitmapPipeline.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
OLDNEW
« no previous file with comments | « src/core/SkLinearBitmapPipeline.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698