| 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 <algorithm> | 10 #include <algorithm> |
| 11 #include <cmath> | 11 #include <cmath> |
| 12 #include <limits> | 12 #include <limits> |
| 13 #include <tuple> | 13 #include <tuple> |
| 14 | 14 |
| 15 #include "SkLinearBitmapPipeline_core.h" | 15 #include "SkLinearBitmapPipeline_core.h" |
| 16 #include "SkLinearBitmapPipeline_matrix.h" | 16 #include "SkLinearBitmapPipeline_matrix.h" |
| 17 #include "SkLinearBitmapPipeline_tile.h" | 17 #include "SkLinearBitmapPipeline_tile.h" |
| 18 #include "SkLinearBitmapPipeline_sample.h" | 18 #include "SkLinearBitmapPipeline_sample.h" |
| 19 #include "SkNx.h" | 19 #include "SkNx.h" |
| 20 #include "SkOpts.h" | 20 #include "SkOpts.h" |
| 21 #include "SkPM4f.h" | 21 #include "SkPM4f.h" |
| 22 | 22 |
| 23 class SkLinearBitmapPipeline::PointProcessorInterface { | |
| 24 public: | |
| 25 virtual ~PointProcessorInterface() { } | |
| 26 // Take the first n (where 0 < n && n < 4) items from xs and ys and sample t
hose points. For | |
| 27 // nearest neighbor, that means just taking the floor xs and ys. For bilerp,
this means | |
| 28 // to expand the bilerp filter around the point and sample using that filter
. | |
| 29 virtual void VECTORCALL pointListFew(int n, Sk4s xs, Sk4s ys) = 0; | |
| 30 // Same as pointListFew, but n = 4. | |
| 31 virtual void VECTORCALL pointList4(Sk4s xs, Sk4s ys) = 0; | |
| 32 // A span is a compact form of sample points that are obtained by mapping po
ints from | |
| 33 // destination space to source space. This is used for horizontal lines only
, and is mainly | |
| 34 // used to take advantage of memory coherence for horizontal spans. | |
| 35 virtual void pointSpan(Span span) = 0; | |
| 36 }; | |
| 37 | |
| 38 class SkLinearBitmapPipeline::SampleProcessorInterface | |
| 39 : public SkLinearBitmapPipeline::PointProcessorInterface { | |
| 40 public: | |
| 41 // Used for nearest neighbor when scale factor is 1.0. The span can just be
repeated with no | |
| 42 // edge pixel alignment problems. This is for handling a very common case. | |
| 43 virtual void repeatSpan(Span span, int32_t repeatCount) = 0; | |
| 44 | |
| 45 // The x's and y's are setup in the following order: | |
| 46 // +--------+--------+ | |
| 47 // | | | | |
| 48 // | px00 | px10 | | |
| 49 // | 0 | 1 | | |
| 50 // +--------+--------+ | |
| 51 // | | | | |
| 52 // | px01 | px11 | | |
| 53 // | 2 | 3 | | |
| 54 // +--------+--------+ | |
| 55 // These pixels coordinates are arranged in the following order in xs and ys
: | |
| 56 // px00 px10 px01 px11 | |
| 57 virtual void VECTORCALL bilerpEdge(Sk4s xs, Sk4s ys) = 0; | |
| 58 | |
| 59 // A span represents sample points that have been mapped from destination sp
ace to source | |
| 60 // space. Each sample point is then expanded to the four bilerp points by ad
d +/- 0.5. The | |
| 61 // resulting Y values my be off the tile. When y +/- 0.5 are more than 1 apa
rt because of | |
| 62 // tiling, the second Y is used to denote the retiled Y value. | |
| 63 virtual void bilerpSpan(Span span, SkScalar y) = 0; | |
| 64 }; | |
| 65 | |
| 66 class SkLinearBitmapPipeline::DestinationInterface { | |
| 67 public: | |
| 68 virtual ~DestinationInterface() { } | |
| 69 // Count is normally not needed, but in these early stages of development it
is useful to | |
| 70 // check bounds. | |
| 71 // TODO(herb): 4/6/2016 - remove count when code is stable. | |
| 72 virtual void setDestination(void* dst, int count) = 0; | |
| 73 }; | |
| 74 | |
| 75 class SkLinearBitmapPipeline::BlendProcessorInterface | |
| 76 : public SkLinearBitmapPipeline::DestinationInterface { | |
| 77 public: | |
| 78 virtual void VECTORCALL blendPixel(Sk4f pixel0) = 0; | |
| 79 virtual void VECTORCALL blend4Pixels(Sk4f p0, Sk4f p1, Sk4f p2, Sk4f p3) = 0
; | |
| 80 }; | |
| 81 | |
| 82 ////////////////////////////////////////////////////////////////////////////////
//////////////////// | 23 ////////////////////////////////////////////////////////////////////////////////
//////////////////// |
| 83 // SkLinearBitmapPipeline::Stage | 24 // SkLinearBitmapPipeline::Stage |
| 84 template<typename Base, size_t kSize, typename Next> | 25 template<typename Base, size_t kSize, typename Next> |
| 85 SkLinearBitmapPipeline::Stage<Base, kSize, Next>::~Stage() { | 26 SkLinearBitmapPipeline::Stage<Base, kSize, Next>::~Stage() { |
| 86 if (fIsInitialized) { | 27 if (fIsInitialized) { |
| 87 this->get()->~Base(); | 28 this->get()->~Base(); |
| 88 } | 29 } |
| 89 } | 30 } |
| 90 | 31 |
| 91 template<typename Base, size_t kSize, typename Next> | 32 template<typename Base, size_t kSize, typename Next> |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 break; | 403 break; |
| 463 case SkShader::kMirror_TileMode: | 404 case SkShader::kMirror_TileMode: |
| 464 choose_tiler_ymode<XMirrorStrategy>(yMode, filterQuality, dimensions
, next, tileStage); | 405 choose_tiler_ymode<XMirrorStrategy>(yMode, filterQuality, dimensions
, next, tileStage); |
| 465 break; | 406 break; |
| 466 } | 407 } |
| 467 | 408 |
| 468 return tileStage->get(); | 409 return tileStage->get(); |
| 469 } | 410 } |
| 470 | 411 |
| 471 ////////////////////////////////////////////////////////////////////////////////
//////////////////// | 412 ////////////////////////////////////////////////////////////////////////////////
//////////////////// |
| 472 // Source Sampling Stage | |
| 473 template <SkColorType colorType, SkColorProfileType colorProfile, typename Next> | |
| 474 class NearestNeighborSampler final : public SkLinearBitmapPipeline::SampleProces
sorInterface { | |
| 475 public: | |
| 476 template <typename... Args> | |
| 477 NearestNeighborSampler(Next* next, Args&&... args) | |
| 478 : fSampler{next, std::forward<Args>(args)...} { } | |
| 479 | |
| 480 NearestNeighborSampler(Next* next, const NearestNeighborSampler& sampler) | |
| 481 : fSampler{next, sampler.fSampler} { } | |
| 482 | |
| 483 void VECTORCALL pointListFew(int n, Sk4s xs, Sk4s ys) override { | |
| 484 fSampler.nearestListFew(n, xs, ys); | |
| 485 } | |
| 486 | |
| 487 void VECTORCALL pointList4(Sk4s xs, Sk4s ys) override { | |
| 488 fSampler.nearestList4(xs, ys); | |
| 489 } | |
| 490 | |
| 491 void pointSpan(Span span) override { | |
| 492 fSampler.nearestSpan(span); | |
| 493 } | |
| 494 | |
| 495 void repeatSpan(Span span, int32_t repeatCount) override { | |
| 496 while (repeatCount > 0) { | |
| 497 fSampler.nearestSpan(span); | |
| 498 repeatCount--; | |
| 499 } | |
| 500 } | |
| 501 | |
| 502 void VECTORCALL bilerpEdge(Sk4s xs, Sk4s ys) override { | |
| 503 SkFAIL("Using nearest neighbor sampler, but calling a bilerpEdge."); | |
| 504 } | |
| 505 | |
| 506 void bilerpSpan(Span span, SkScalar y) override { | |
| 507 SkFAIL("Using nearest neighbor sampler, but calling a bilerpSpan."); | |
| 508 } | |
| 509 | |
| 510 private: | |
| 511 GeneralSampler<colorType, colorProfile, Next> fSampler; | |
| 512 }; | |
| 513 | |
| 514 template <SkColorType colorType, SkColorProfileType colorProfile, typename Next> | |
| 515 class BilerpSampler final : public SkLinearBitmapPipeline::SampleProcessorInterf
ace { | |
| 516 public: | |
| 517 template <typename... Args> | |
| 518 BilerpSampler(Next* next, Args&&... args) | |
| 519 : fSampler{next, std::forward<Args>(args)...} { } | |
| 520 | |
| 521 BilerpSampler(Next* next, const BilerpSampler& sampler) | |
| 522 : fSampler{next, sampler.fSampler} { } | |
| 523 | |
| 524 void VECTORCALL pointListFew(int n, Sk4s xs, Sk4s ys) override { | |
| 525 fSampler.bilerpListFew(n, xs, ys); | |
| 526 } | |
| 527 | |
| 528 void VECTORCALL pointList4(Sk4s xs, Sk4s ys) override { | |
| 529 fSampler.bilerpList4(xs, ys); | |
| 530 } | |
| 531 | |
| 532 void pointSpan(Span span) override { | |
| 533 fSampler.bilerpSpan(span); | |
| 534 } | |
| 535 | |
| 536 void repeatSpan(Span span, int32_t repeatCount) override { | |
| 537 while (repeatCount > 0) { | |
| 538 fSampler.bilerpSpan(span); | |
| 539 repeatCount--; | |
| 540 } | |
| 541 } | |
| 542 | |
| 543 void VECTORCALL bilerpEdge(Sk4s xs, Sk4s ys) override { | |
| 544 fSampler.bilerpEdge(xs, ys); | |
| 545 } | |
| 546 | |
| 547 void bilerpSpan(Span span, SkScalar y) override { | |
| 548 fSampler.bilerpSpanWithY(span, y); | |
| 549 } | |
| 550 | |
| 551 private: | |
| 552 GeneralSampler<colorType, colorProfile, Next> fSampler; | |
| 553 }; | |
| 554 | |
| 555 ////////////////////////////////////////////////////////////////////////////////
//////////////////// | |
| 556 // Specialized Samplers | 413 // Specialized Samplers |
| 557 | 414 |
| 558 // RGBA8888UnitRepeatSrc - A sampler that takes advantage of the fact the the sr
c and destination | 415 // RGBA8888UnitRepeatSrc - A sampler that takes advantage of the fact the the sr
c and destination |
| 559 // are the same format and do not need in transformations in pixel space. Theref
ore, there is no | 416 // are the same format and do not need in transformations in pixel space. Theref
ore, there is no |
| 560 // need to convert them to HiFi pixel format. | 417 // need to convert them to HiFi pixel format. |
| 561 class RGBA8888UnitRepeatSrc final : public SkLinearBitmapPipeline::SampleProcess
orInterface, | 418 class RGBA8888UnitRepeatSrc final : public SkLinearBitmapPipeline::SampleProcess
orInterface, |
| 562 public SkLinearBitmapPipeline::DestinationIn
terface { | 419 public SkLinearBitmapPipeline::DestinationIn
terface { |
| 563 public: | 420 public: |
| 564 RGBA8888UnitRepeatSrc(const uint32_t* src, int32_t width) | 421 RGBA8888UnitRepeatSrc(const uint32_t* src, int32_t width) |
| 565 : fSrc{src}, fWidth{width} { } | 422 : fSrc{src}, fWidth{width} { } |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 void SkLinearBitmapPipeline::blitSpan(int x, int y, void* dst, int count) { | 820 void SkLinearBitmapPipeline::blitSpan(int x, int y, void* dst, int count) { |
| 964 SkASSERT(count > 0); | 821 SkASSERT(count > 0); |
| 965 fLastStage->setDestination(dst, count); | 822 fLastStage->setDestination(dst, count); |
| 966 | 823 |
| 967 // The count and length arguments start out in a precise relation in order t
o keep the | 824 // The count and length arguments start out in a precise relation in order t
o keep the |
| 968 // math correct through the different stages. Count is the number of pixel t
o produce. | 825 // math correct through the different stages. Count is the number of pixel t
o produce. |
| 969 // Since the code samples at pixel centers, length is the distance from the
center of the | 826 // Since the code samples at pixel centers, length is the distance from the
center of the |
| 970 // first pixel to the center of the last pixel. This implies that length is
count-1. | 827 // first pixel to the center of the last pixel. This implies that length is
count-1. |
| 971 fFirstStage->pointSpan(Span{{x + 0.5f, y + 0.5f}, count - 1.0f, count}); | 828 fFirstStage->pointSpan(Span{{x + 0.5f, y + 0.5f}, count - 1.0f, count}); |
| 972 } | 829 } |
| OLD | NEW |