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 #include "SkLinearBitmapPipeline.h" | 8 #include "SkLinearBitmapPipeline.h" |
9 | 9 |
10 #include "SkPM4f.h" | 10 #include "SkPM4f.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 // to expand the bilerp filter around the point and sample using that filter
. | 27 // to expand the bilerp filter around the point and sample using that filter
. |
28 virtual void VECTORCALL pointListFew(int n, Sk4s xs, Sk4s ys) = 0; | 28 virtual void VECTORCALL pointListFew(int n, Sk4s xs, Sk4s ys) = 0; |
29 // Same as pointListFew, but n = 4. | 29 // Same as pointListFew, but n = 4. |
30 virtual void VECTORCALL pointList4(Sk4s xs, Sk4s ys) = 0; | 30 virtual void VECTORCALL pointList4(Sk4s xs, Sk4s ys) = 0; |
31 // A span is a compact form of sample points that are obtained by mapping po
ints from | 31 // A span is a compact form of sample points that are obtained by mapping po
ints from |
32 // destination space to source space. This is used for horizontal lines only
, and is mainly | 32 // destination space to source space. This is used for horizontal lines only
, and is mainly |
33 // used to take advantage of memory coherence for horizontal spans. | 33 // used to take advantage of memory coherence for horizontal spans. |
34 virtual void pointSpan(Span span) = 0; | 34 virtual void pointSpan(Span span) = 0; |
35 }; | 35 }; |
36 | 36 |
37 class SkLinearBitmapPipeline::BilerpProcessorInterface | 37 class SkLinearBitmapPipeline::SampleProcessorInterface |
38 : public SkLinearBitmapPipeline::PointProcessorInterface { | 38 : public SkLinearBitmapPipeline::PointProcessorInterface { |
39 public: | 39 public: |
| 40 // Used for nearest neighbor when scale factor is 1.0. The span can just be
repeated with no |
| 41 // edge pixel alignment problems. This is for handling a very common case. |
| 42 virtual void repeatSpan(Span span, int32_t repeatCount) = 0; |
| 43 |
40 // The x's and y's are setup in the following order: | 44 // The x's and y's are setup in the following order: |
41 // +--------+--------+ | 45 // +--------+--------+ |
42 // | | | | 46 // | | | |
43 // | px00 | px10 | | 47 // | px00 | px10 | |
44 // | 0 | 1 | | 48 // | 0 | 1 | |
45 // +--------+--------+ | 49 // +--------+--------+ |
46 // | | | | 50 // | | | |
47 // | px01 | px11 | | 51 // | px01 | px11 | |
48 // | 2 | 3 | | 52 // | 2 | 3 | |
49 // +--------+--------+ | 53 // +--------+--------+ |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 Next* next, SkLinearBitmapPipeline::TileStage* tileStage) { | 336 Next* next, SkLinearBitmapPipeline::TileStage* tileStage) { |
333 if (filterQuality == kNone_SkFilterQuality) { | 337 if (filterQuality == kNone_SkFilterQuality) { |
334 tileStage->Initialize<NearestTileStage<XStrategy, YStrategy, Next>>(next
, dimensions); | 338 tileStage->Initialize<NearestTileStage<XStrategy, YStrategy, Next>>(next
, dimensions); |
335 } else { | 339 } else { |
336 tileStage->Initialize<BilerpTileStage<XStrategy, YStrategy, Next>>(next,
dimensions); | 340 tileStage->Initialize<BilerpTileStage<XStrategy, YStrategy, Next>>(next,
dimensions); |
337 } | 341 } |
338 } | 342 } |
339 template <typename XStrategy> | 343 template <typename XStrategy> |
340 void choose_tiler_ymode( | 344 void choose_tiler_ymode( |
341 SkShader::TileMode yMode, SkFilterQuality filterQuality, SkISize dimensions, | 345 SkShader::TileMode yMode, SkFilterQuality filterQuality, SkISize dimensions, |
342 SkLinearBitmapPipeline::BilerpProcessorInterface* next, | 346 SkLinearBitmapPipeline::SampleProcessorInterface* next, |
343 SkLinearBitmapPipeline::TileStage* tileStage) { | 347 SkLinearBitmapPipeline::TileStage* tileStage) { |
344 switch (yMode) { | 348 switch (yMode) { |
345 case SkShader::kClamp_TileMode: | 349 case SkShader::kClamp_TileMode: |
346 make_tile_stage<XStrategy, YClampStrategy>(filterQuality, dimensions
, next, tileStage); | 350 make_tile_stage<XStrategy, YClampStrategy>(filterQuality, dimensions
, next, tileStage); |
347 break; | 351 break; |
348 case SkShader::kRepeat_TileMode: | 352 case SkShader::kRepeat_TileMode: |
349 make_tile_stage<XStrategy, YRepeatStrategy>(filterQuality, dimension
s, next, tileStage); | 353 make_tile_stage<XStrategy, YRepeatStrategy>(filterQuality, dimension
s, next, tileStage); |
350 break; | 354 break; |
351 case SkShader::kMirror_TileMode: | 355 case SkShader::kMirror_TileMode: |
352 make_tile_stage<XStrategy, YMirrorStrategy>(filterQuality, dimension
s, next, tileStage); | 356 make_tile_stage<XStrategy, YMirrorStrategy>(filterQuality, dimension
s, next, tileStage); |
353 break; | 357 break; |
354 } | 358 } |
355 }; | 359 }; |
356 | 360 |
357 static SkLinearBitmapPipeline::PointProcessorInterface* choose_tiler( | 361 static SkLinearBitmapPipeline::PointProcessorInterface* choose_tiler( |
358 SkLinearBitmapPipeline::BilerpProcessorInterface* next, | 362 SkLinearBitmapPipeline::SampleProcessorInterface* next, |
359 SkISize dimensions, | 363 SkISize dimensions, |
360 SkShader::TileMode xMode, | 364 SkShader::TileMode xMode, |
361 SkShader::TileMode yMode, | 365 SkShader::TileMode yMode, |
362 SkFilterQuality filterQuality, | 366 SkFilterQuality filterQuality, |
363 SkLinearBitmapPipeline::TileStage* tileStage) { | 367 SkLinearBitmapPipeline::TileStage* tileStage) { |
364 switch (xMode) { | 368 switch (xMode) { |
365 case SkShader::kClamp_TileMode: | 369 case SkShader::kClamp_TileMode: |
366 choose_tiler_ymode<XClampStrategy>(yMode, filterQuality, dimensions,
next, tileStage); | 370 choose_tiler_ymode<XClampStrategy>(yMode, filterQuality, dimensions,
next, tileStage); |
367 break; | 371 break; |
368 case SkShader::kRepeat_TileMode: | 372 case SkShader::kRepeat_TileMode: |
369 choose_tiler_ymode<XRepeatStrategy>(yMode, filterQuality, dimensions
, next, tileStage); | 373 choose_tiler_ymode<XRepeatStrategy>(yMode, filterQuality, dimensions
, next, tileStage); |
370 break; | 374 break; |
371 case SkShader::kMirror_TileMode: | 375 case SkShader::kMirror_TileMode: |
372 choose_tiler_ymode<XMirrorStrategy>(yMode, filterQuality, dimensions
, next, tileStage); | 376 choose_tiler_ymode<XMirrorStrategy>(yMode, filterQuality, dimensions
, next, tileStage); |
373 break; | 377 break; |
374 } | 378 } |
375 | 379 |
376 return tileStage->get(); | 380 return tileStage->get(); |
377 } | 381 } |
378 | 382 |
379 | 383 |
380 ////////////////////////////////////////////////////////////////////////////////
//////////////////// | 384 ////////////////////////////////////////////////////////////////////////////////
//////////////////// |
381 // Source Sampling Stage | 385 // Source Sampling Stage |
382 template <typename SourceStrategy, typename Next> | 386 template <typename SourceStrategy, typename Next> |
383 class NearestNeighborSampler final : public SkLinearBitmapPipeline::BilerpProces
sorInterface { | 387 class NearestNeighborSampler final : public SkLinearBitmapPipeline::SampleProces
sorInterface { |
384 public: | 388 public: |
385 template <typename... Args> | 389 template <typename... Args> |
386 NearestNeighborSampler(Next* next, Args&&... args) | 390 NearestNeighborSampler(Next* next, Args&&... args) |
387 : fSampler{next, std::forward<Args>(args)...} { } | 391 : fSampler{next, std::forward<Args>(args)...} { } |
388 | 392 |
389 void VECTORCALL pointListFew(int n, Sk4s xs, Sk4s ys) override { | 393 void VECTORCALL pointListFew(int n, Sk4s xs, Sk4s ys) override { |
390 fSampler.nearestListFew(n, xs, ys); | 394 fSampler.nearestListFew(n, xs, ys); |
391 } | 395 } |
| 396 |
392 void VECTORCALL pointList4(Sk4s xs, Sk4s ys) override { | 397 void VECTORCALL pointList4(Sk4s xs, Sk4s ys) override { |
393 fSampler.nearestList4(xs, ys); | 398 fSampler.nearestList4(xs, ys); |
394 } | 399 } |
| 400 |
395 void pointSpan(Span span) override { | 401 void pointSpan(Span span) override { |
396 fSampler.nearestSpan(span); | 402 fSampler.nearestSpan(span); |
397 } | 403 } |
| 404 |
| 405 virtual void repeatSpan(Span span, int32_t repeatCount) override { |
| 406 while (repeatCount > 0) { |
| 407 fSampler.nearestSpan(span); |
| 408 repeatCount--; |
| 409 } |
| 410 } |
| 411 |
398 void VECTORCALL bilerpEdge(Sk4s xs, Sk4s ys) override { | 412 void VECTORCALL bilerpEdge(Sk4s xs, Sk4s ys) override { |
399 SkFAIL("Using nearest neighbor sampler, but calling a bilerpEdge."); | 413 SkFAIL("Using nearest neighbor sampler, but calling a bilerpEdge."); |
400 } | 414 } |
401 | 415 |
402 virtual void bilerpSpan(Span span, SkScalar y) override { | 416 virtual void bilerpSpan(Span span, SkScalar y) override { |
403 SkFAIL("Using nearest neighbor sampler, but calling a bilerpSpan."); | 417 SkFAIL("Using nearest neighbor sampler, but calling a bilerpSpan."); |
404 } | 418 } |
405 | 419 |
406 private: | 420 private: |
407 GeneralSampler<SourceStrategy, Next> fSampler; | 421 GeneralSampler<SourceStrategy, Next> fSampler; |
408 }; | 422 }; |
409 | 423 |
410 template <typename SourceStrategy, typename Next> | 424 template <typename SourceStrategy, typename Next> |
411 class BilerpSampler final : public SkLinearBitmapPipeline::BilerpProcessorInterf
ace { | 425 class BilerpSampler final : public SkLinearBitmapPipeline::SampleProcessorInterf
ace { |
412 public: | 426 public: |
413 template <typename... Args> | 427 template <typename... Args> |
414 BilerpSampler(Next* next, Args&&... args) | 428 BilerpSampler(Next* next, Args&&... args) |
415 : fSampler{next, std::forward<Args>(args)...} { } | 429 : fSampler{next, std::forward<Args>(args)...} { } |
416 | 430 |
417 void VECTORCALL pointListFew(int n, Sk4s xs, Sk4s ys) override { | 431 void VECTORCALL pointListFew(int n, Sk4s xs, Sk4s ys) override { |
418 fSampler.bilerpListFew(n, xs, ys); | 432 fSampler.bilerpListFew(n, xs, ys); |
419 } | 433 } |
| 434 |
420 void VECTORCALL pointList4(Sk4s xs, Sk4s ys) override { | 435 void VECTORCALL pointList4(Sk4s xs, Sk4s ys) override { |
421 fSampler.bilerpList4(xs, ys); | 436 fSampler.bilerpList4(xs, ys); |
422 } | 437 } |
| 438 |
423 void pointSpan(Span span) override { | 439 void pointSpan(Span span) override { |
424 fSampler.bilerpSpan(span); | 440 fSampler.bilerpSpan(span); |
425 } | 441 } |
| 442 |
| 443 virtual void repeatSpan(Span span, int32_t repeatCount) override { |
| 444 while (repeatCount > 0) { |
| 445 fSampler.bilerpSpan(span); |
| 446 repeatCount--; |
| 447 } |
| 448 } |
| 449 |
426 void VECTORCALL bilerpEdge(Sk4s xs, Sk4s ys) override { | 450 void VECTORCALL bilerpEdge(Sk4s xs, Sk4s ys) override { |
427 fSampler.bilerpEdge(xs, ys); | 451 fSampler.bilerpEdge(xs, ys); |
428 } | 452 } |
429 | 453 |
430 virtual void bilerpSpan(Span span, SkScalar y) override { | 454 virtual void bilerpSpan(Span span, SkScalar y) override { |
431 fSampler.bilerpSpanWithY(span, y); | 455 fSampler.bilerpSpanWithY(span, y); |
432 } | 456 } |
433 | 457 |
434 private: | 458 private: |
435 GeneralSampler<SourceStrategy, Next> fSampler; | 459 GeneralSampler<SourceStrategy, Next> fSampler; |
436 }; | 460 }; |
437 | 461 |
438 using Placer = SkLinearBitmapPipeline::PixelPlacerInterface; | 462 using Placer = SkLinearBitmapPipeline::PixelPlacerInterface; |
439 | 463 |
440 template<template <typename, typename> class Sampler> | 464 template<template <typename, typename> class Sampler> |
441 static SkLinearBitmapPipeline::BilerpProcessorInterface* choose_pixel_sampler_ba
se( | 465 static SkLinearBitmapPipeline::SampleProcessorInterface* choose_pixel_sampler_ba
se( |
442 Placer* next, | 466 Placer* next, |
443 const SkPixmap& srcPixmap, | 467 const SkPixmap& srcPixmap, |
444 SkLinearBitmapPipeline::SampleStage* sampleStage) { | 468 SkLinearBitmapPipeline::SampleStage* sampleStage) { |
445 const SkImageInfo& imageInfo = srcPixmap.info(); | 469 const SkImageInfo& imageInfo = srcPixmap.info(); |
446 switch (imageInfo.colorType()) { | 470 switch (imageInfo.colorType()) { |
447 case kRGBA_8888_SkColorType: | 471 case kRGBA_8888_SkColorType: |
448 if (imageInfo.profileType() == kSRGB_SkColorProfileType) { | 472 if (imageInfo.profileType() == kSRGB_SkColorProfileType) { |
449 sampleStage->Initialize<Sampler<Pixel8888SRGB, Placer>>(next, sr
cPixmap); | 473 sampleStage->Initialize<Sampler<Pixel8888SRGB, Placer>>(next, sr
cPixmap); |
450 } else { | 474 } else { |
451 sampleStage->Initialize<Sampler<Pixel8888LRGB, Placer>>(next, sr
cPixmap); | 475 sampleStage->Initialize<Sampler<Pixel8888LRGB, Placer>>(next, sr
cPixmap); |
(...skipping 13 matching lines...) Expand all Loading... |
465 sampleStage->Initialize<Sampler<PixelIndex8LRGB, Placer>>(next,
srcPixmap); | 489 sampleStage->Initialize<Sampler<PixelIndex8LRGB, Placer>>(next,
srcPixmap); |
466 } | 490 } |
467 break; | 491 break; |
468 default: | 492 default: |
469 SkFAIL("Not implemented. Unsupported src"); | 493 SkFAIL("Not implemented. Unsupported src"); |
470 break; | 494 break; |
471 } | 495 } |
472 return sampleStage->get(); | 496 return sampleStage->get(); |
473 } | 497 } |
474 | 498 |
475 SkLinearBitmapPipeline::BilerpProcessorInterface* choose_pixel_sampler( | 499 SkLinearBitmapPipeline::SampleProcessorInterface* choose_pixel_sampler( |
476 Placer* next, | 500 Placer* next, |
477 SkFilterQuality filterQuality, | 501 SkFilterQuality filterQuality, |
478 const SkPixmap& srcPixmap, | 502 const SkPixmap& srcPixmap, |
479 SkLinearBitmapPipeline::SampleStage* sampleStage) { | 503 SkLinearBitmapPipeline::SampleStage* sampleStage) { |
480 if (filterQuality == kNone_SkFilterQuality) { | 504 if (filterQuality == kNone_SkFilterQuality) { |
481 return choose_pixel_sampler_base<NearestNeighborSampler>(next, srcPixmap
, sampleStage); | 505 return choose_pixel_sampler_base<NearestNeighborSampler>(next, srcPixmap
, sampleStage); |
482 } else { | 506 } else { |
483 return choose_pixel_sampler_base<BilerpSampler>(next, srcPixmap, sampleS
tage); | 507 return choose_pixel_sampler_base<BilerpSampler>(next, srcPixmap, sampleS
tage); |
484 } | 508 } |
485 } | 509 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 | 606 |
583 void SkLinearBitmapPipeline::shadeSpan4f(int x, int y, SkPM4f* dst, int count) { | 607 void SkLinearBitmapPipeline::shadeSpan4f(int x, int y, SkPM4f* dst, int count) { |
584 SkASSERT(count > 0); | 608 SkASSERT(count > 0); |
585 fPixelStage->setDestination(dst); | 609 fPixelStage->setDestination(dst); |
586 // The count and length arguments start out in a precise relation in order t
o keep the | 610 // The count and length arguments start out in a precise relation in order t
o keep the |
587 // math correct through the different stages. Count is the number of pixel t
o produce. | 611 // math correct through the different stages. Count is the number of pixel t
o produce. |
588 // Since the code samples at pixel centers, length is the distance from the
center of the | 612 // Since the code samples at pixel centers, length is the distance from the
center of the |
589 // first pixel to the center of the last pixel. This implies that length is
count-1. | 613 // first pixel to the center of the last pixel. This implies that length is
count-1. |
590 fFirstStage->pointSpan(Span{{x + 0.5f, y + 0.5f}, count - 1.0f, count}); | 614 fFirstStage->pointSpan(Span{{x + 0.5f, y + 0.5f}, count - 1.0f, count}); |
591 } | 615 } |
OLD | NEW |