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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 // px00 px10 px01 px11 | 55 // px00 px10 px01 px11 |
56 virtual void VECTORCALL bilerpEdge(Sk4s xs, Sk4s ys) = 0; | 56 virtual void VECTORCALL bilerpEdge(Sk4s xs, Sk4s ys) = 0; |
57 | 57 |
58 // A span represents sample points that have been mapped from destination sp ace to source | 58 // A span represents sample points that have been mapped from destination sp ace to source |
59 // space. Each sample point is then expanded to the four bilerp points by ad d +/- 0.5. The | 59 // space. Each sample point is then expanded to the four bilerp points by ad d +/- 0.5. The |
60 // resulting Y values my be off the tile. When y +/- 0.5 are more than 1 apa rt because of | 60 // resulting Y values my be off the tile. When y +/- 0.5 are more than 1 apa rt because of |
61 // tiling, the second Y is used to denote the retiled Y value. | 61 // tiling, the second Y is used to denote the retiled Y value. |
62 virtual void bilerpSpan(Span span, SkScalar y) = 0; | 62 virtual void bilerpSpan(Span span, SkScalar y) = 0; |
63 }; | 63 }; |
64 | 64 |
65 class SkLinearBitmapPipeline::PixelPlacerInterface { | 65 class SkLinearBitmapPipeline::DestinationInterface { |
66 public: | |
67 virtual ~DestinationInterface() { } | |
68 virtual void setDestination(void* dst, int count) = 0; | |
69 }; | |
70 | |
71 class SkLinearBitmapPipeline::PixelPlacerInterface | |
72 : public SkLinearBitmapPipeline::DestinationInterface { | |
66 public: | 73 public: |
67 virtual ~PixelPlacerInterface() { } | 74 virtual ~PixelPlacerInterface() { } |
68 // Count is normally not needed, but in these early stages of development it is useful to | 75 // Count is normally not needed, but in these early stages of development it is useful to |
69 // check bounds. | 76 // check bounds. |
70 // TODO(herb): 4/6/2016 - remove count when code is stable. | 77 // TODO(herb): 4/6/2016 - remove count when code is stable. |
71 virtual void setDestination(void* dst, int count) = 0; | 78 virtual void setDestination(void* dst, int count) = 0; |
72 virtual void VECTORCALL placePixel(Sk4f pixel0) = 0; | 79 virtual void VECTORCALL placePixel(Sk4f pixel0) = 0; |
73 virtual void VECTORCALL place4Pixels(Sk4f p0, Sk4f p1, Sk4f p2, Sk4f p3) = 0 ; | 80 virtual void VECTORCALL place4Pixels(Sk4f p0, Sk4f p1, Sk4f p2, Sk4f p3) = 0 ; |
74 }; | 81 }; |
75 | 82 |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 } | 397 } |
391 break; | 398 break; |
392 case SkShader::kMirror_TileMode: | 399 case SkShader::kMirror_TileMode: |
393 choose_tiler_ymode<XMirrorStrategy>(yMode, filterQuality, dimensions , next, tileStage); | 400 choose_tiler_ymode<XMirrorStrategy>(yMode, filterQuality, dimensions , next, tileStage); |
394 break; | 401 break; |
395 } | 402 } |
396 | 403 |
397 return tileStage->get(); | 404 return tileStage->get(); |
398 } | 405 } |
399 | 406 |
400 | |
401 //////////////////////////////////////////////////////////////////////////////// //////////////////// | 407 //////////////////////////////////////////////////////////////////////////////// //////////////////// |
402 // Source Sampling Stage | 408 // Source Sampling Stage |
403 template <typename SourceStrategy, typename Next> | 409 template <typename SourceStrategy, typename Next> |
404 class NearestNeighborSampler final : public SkLinearBitmapPipeline::SampleProces sorInterface { | 410 class NearestNeighborSampler final : public SkLinearBitmapPipeline::SampleProces sorInterface { |
405 public: | 411 public: |
406 template <typename... Args> | 412 template <typename... Args> |
407 NearestNeighborSampler(Next* next, Args&&... args) | 413 NearestNeighborSampler(Next* next, Args&&... args) |
408 : fSampler{next, std::forward<Args>(args)...} { } | 414 : fSampler{next, std::forward<Args>(args)...} { } |
409 | 415 |
410 void VECTORCALL pointListFew(int n, Sk4s xs, Sk4s ys) override { | 416 void VECTORCALL pointListFew(int n, Sk4s xs, Sk4s ys) override { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 } | 475 } |
470 | 476 |
471 void bilerpSpan(Span span, SkScalar y) override { | 477 void bilerpSpan(Span span, SkScalar y) override { |
472 fSampler.bilerpSpanWithY(span, y); | 478 fSampler.bilerpSpanWithY(span, y); |
473 } | 479 } |
474 | 480 |
475 private: | 481 private: |
476 GeneralSampler<SourceStrategy, Next> fSampler; | 482 GeneralSampler<SourceStrategy, Next> fSampler; |
477 }; | 483 }; |
478 | 484 |
485 // RGBA8888UnitRepeatSrc - A sampler that takes advantage of the fact the the sr c and destination | |
486 // are the same format and do not need in transformations in pixel space. Theref ore, there is no | |
487 // need to convert them to HiFi pixel format. | |
488 class RGBA8888UnitRepeat final : public SkLinearBitmapPipeline::SampleProcessorI nterface, | |
489 public SkLinearBitmapPipeline::DestinationInter face { | |
490 public: | |
491 RGBA8888UnitRepeat(const uint32_t* src, int32_t width) | |
492 : fSrc{src}, fWidth{width} { } | |
493 | |
494 void VECTORCALL pointListFew(int n, Sk4s xs, Sk4s ys) override { | |
495 SkASSERT(fDest + n <= fEnd); | |
496 // At this point xs and ys should be >= 0, so trunc is the same as floor . | |
497 Sk4i iXs = SkNx_cast<int>(xs); | |
498 Sk4i iYs = SkNx_cast<int>(ys); | |
499 | |
500 if (n >= 1) *fDest++ = *this->pixelAddress(iXs[0], iYs[0]); | |
501 if (n >= 2) *fDest++ = *this->pixelAddress(iXs[1], iYs[1]); | |
502 if (n >= 3) *fDest++ = *this->pixelAddress(iXs[2], iYs[2]); | |
503 } | |
504 | |
505 void VECTORCALL pointList4(Sk4s xs, Sk4s ys) override { | |
506 SkASSERT(fDest + 4 <= fEnd); | |
507 Sk4i iXs = SkNx_cast<int>(xs); | |
508 Sk4i iYs = SkNx_cast<int>(ys); | |
509 *fDest++ = *this->pixelAddress(iXs[0], iYs[0]); | |
510 *fDest++ = *this->pixelAddress(iXs[1], iYs[1]); | |
511 *fDest++ = *this->pixelAddress(iXs[2], iYs[2]); | |
512 *fDest++ = *this->pixelAddress(iXs[3], iYs[3]); | |
513 } | |
514 | |
515 void pointSpan(Span span) override { | |
516 SkASSERT(fDest + span.count() <= fEnd); | |
517 int32_t x = (int32_t)span.startX(); | |
518 int32_t y = (int32_t)span.startY(); | |
519 const uint32_t* src = this->pixelAddress(x, y); | |
520 memmove(fDest, src, span.count() * sizeof(uint32_t)); | |
521 fDest += span.count(); | |
522 } | |
523 | |
524 void repeatSpan(Span span, int32_t repeatCount) override { | |
525 SkASSERT(fDest + span.count() * repeatCount <= fEnd); | |
526 | |
527 int32_t x = (int32_t)span.startX(); | |
528 int32_t y = (int32_t)span.startY(); | |
529 const uint32_t* src = this->pixelAddress(x, y); | |
530 uint32_t* dest = fDest; | |
531 while (repeatCount --> 0) { | |
532 memmove(dest, src, span.count() * sizeof(uint32_t)); | |
533 dest += span.count(); | |
534 } | |
535 fDest = dest; | |
536 } | |
537 | |
538 void VECTORCALL bilerpEdge(Sk4s xs, Sk4s ys) override { SkFAIL("Not Implemen ted"); } | |
539 | |
540 void bilerpSpan(Span span, SkScalar y) override { SkFAIL("Not Implemented"); } | |
541 | |
542 void setDestination(void* dst, int count) override { | |
543 fDest = static_cast<uint32_t*>(dst); | |
544 fEnd = fDest + count; | |
545 } | |
546 | |
547 private: | |
548 const uint32_t* pixelAddress(int32_t x, int32_t y) { | |
549 return &fSrc[fWidth * y + x]; | |
f(malita)
2016/04/08 12:58:12
Do we need to worry about row padding here or rowb
herb_g
2016/04/08 13:48:59
I talked with MikeR about this. RowBytes must alwa
| |
550 } | |
551 const uint32_t* const fSrc; | |
552 const int32_t fWidth; | |
553 uint32_t* fDest; | |
554 uint32_t* fEnd; | |
555 }; | |
556 | |
479 using Placer = SkLinearBitmapPipeline::PixelPlacerInterface; | 557 using Placer = SkLinearBitmapPipeline::PixelPlacerInterface; |
480 | 558 |
481 template<template <typename, typename> class Sampler> | 559 template<template <typename, typename> class Sampler> |
482 static SkLinearBitmapPipeline::SampleProcessorInterface* choose_pixel_sampler_ba se( | 560 static SkLinearBitmapPipeline::SampleProcessorInterface* choose_pixel_sampler_ba se( |
483 Placer* next, | 561 Placer* next, |
484 const SkPixmap& srcPixmap, | 562 const SkPixmap& srcPixmap, |
485 SkLinearBitmapPipeline::SampleStage* sampleStage) { | 563 SkLinearBitmapPipeline::SampleStage* sampleStage) { |
486 const SkImageInfo& imageInfo = srcPixmap.info(); | 564 const SkImageInfo& imageInfo = srcPixmap.info(); |
487 switch (imageInfo.colorType()) { | 565 switch (imageInfo.colorType()) { |
488 case kRGBA_8888_SkColorType: | 566 case kRGBA_8888_SkColorType: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 return choose_pixel_sampler_base<BilerpSampler>(next, srcPixmap, sampleS tage); | 602 return choose_pixel_sampler_base<BilerpSampler>(next, srcPixmap, sampleS tage); |
525 } | 603 } |
526 } | 604 } |
527 | 605 |
528 //////////////////////////////////////////////////////////////////////////////// //////////////////// | 606 //////////////////////////////////////////////////////////////////////////////// //////////////////// |
529 // Pixel Placement Stage | 607 // Pixel Placement Stage |
530 template <SkAlphaType alphaType> | 608 template <SkAlphaType alphaType> |
531 class PlaceFPPixel final : public SkLinearBitmapPipeline::PixelPlacerInterface { | 609 class PlaceFPPixel final : public SkLinearBitmapPipeline::PixelPlacerInterface { |
532 public: | 610 public: |
533 PlaceFPPixel(float postAlpha) : fPostAlpha{postAlpha} { } | 611 PlaceFPPixel(float postAlpha) : fPostAlpha{postAlpha} { } |
612 | |
534 void VECTORCALL placePixel(Sk4f pixel) override { | 613 void VECTORCALL placePixel(Sk4f pixel) override { |
535 SkASSERT(fDst + 1 <= fEnd ); | 614 SkASSERT(fDst + 1 <= fEnd ); |
536 PlacePixel(fDst, pixel, 0); | 615 PlacePixel(fDst, pixel, 0); |
537 fDst += 1; | 616 fDst += 1; |
538 } | 617 } |
539 | 618 |
540 void VECTORCALL place4Pixels(Sk4f p0, Sk4f p1, Sk4f p2, Sk4f p3) override { | 619 void VECTORCALL place4Pixels(Sk4f p0, Sk4f p1, Sk4f p2, Sk4f p3) override { |
541 SkASSERT(fDst + 4 <= fEnd); | 620 SkASSERT(fDst + 4 <= fEnd); |
542 SkPM4f* dst = fDst; | 621 SkPM4f* dst = fDst; |
543 PlacePixel(dst, p0, 0); | 622 PlacePixel(dst, p0, 0); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 } | 698 } |
620 | 699 |
621 // As the stages are built, the chooser function may skip a stage. For examp le, with the | 700 // As the stages are built, the chooser function may skip a stage. For examp le, with the |
622 // identity matrix, the matrix stage is skipped, and the tilerStage is the f irst stage. | 701 // identity matrix, the matrix stage is skipped, and the tilerStage is the f irst stage. |
623 auto placementStage = choose_pixel_placer(alphaType, postAlpha, &fPixelStage ); | 702 auto placementStage = choose_pixel_placer(alphaType, postAlpha, &fPixelStage ); |
624 auto samplerStage = choose_pixel_sampler(placementStage, | 703 auto samplerStage = choose_pixel_sampler(placementStage, |
625 filterQuality, srcPixmap, &fSampl eStage); | 704 filterQuality, srcPixmap, &fSampl eStage); |
626 auto tilerStage = choose_tiler(samplerStage, | 705 auto tilerStage = choose_tiler(samplerStage, |
627 dimensions, xTile, yTile, filterQuality, dx, &fTiler); | 706 dimensions, xTile, yTile, filterQuality, dx, &fTiler); |
628 fFirstStage = choose_matrix(tilerStage, adjustedInverse, &fMatrixSta ge); | 707 fFirstStage = choose_matrix(tilerStage, adjustedInverse, &fMatrixSta ge); |
708 fLastStage = placementStage; | |
709 | |
629 } | 710 } |
630 | 711 |
631 void SkLinearBitmapPipeline::shadeSpan4f(int x, int y, SkPM4f* dst, int count) { | 712 void SkLinearBitmapPipeline::shadeSpan4f(int x, int y, SkPM4f* dst, int count) { |
632 SkASSERT(count > 0); | 713 SkASSERT(count > 0); |
633 fPixelStage->setDestination(dst, count); | 714 fLastStage->setDestination(dst, count); |
715 | |
634 // The count and length arguments start out in a precise relation in order t o keep the | 716 // The count and length arguments start out in a precise relation in order t o keep the |
635 // math correct through the different stages. Count is the number of pixel t o produce. | 717 // math correct through the different stages. Count is the number of pixel t o produce. |
636 // Since the code samples at pixel centers, length is the distance from the center of the | 718 // Since the code samples at pixel centers, length is the distance from the center of the |
637 // first pixel to the center of the last pixel. This implies that length is count-1. | 719 // first pixel to the center of the last pixel. This implies that length is count-1. |
638 fFirstStage->pointSpan(Span{{x + 0.5f, y + 0.5f}, count - 1.0f, count}); | 720 fFirstStage->pointSpan(Span{{x + 0.5f, y + 0.5f}, count - 1.0f, count}); |
639 } | 721 } |
OLD | NEW |