diff options
author | herb <herb@google.com> | 2016-02-22 13:13:28 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-22 13:13:28 -0800 |
commit | 933ad4389f0d558a6a31bc850b46373a36948f08 (patch) | |
tree | 68af9e457e38da30199af261e38cf65271d3db5d /src/core | |
parent | bc2f4dfd4175bd35961092bbbbeccee77dc8aa04 (diff) |
Add spans for matrix ops.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1722703002
Review URL: https://codereview.chromium.org/1722703002
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/SkLinearBitmapPipeline.cpp | 53 |
1 files changed, 51 insertions, 2 deletions
diff --git a/src/core/SkLinearBitmapPipeline.cpp b/src/core/SkLinearBitmapPipeline.cpp index 958a945aef..5a4f86daa7 100644 --- a/src/core/SkLinearBitmapPipeline.cpp +++ b/src/core/SkLinearBitmapPipeline.cpp @@ -54,6 +54,19 @@ void span_fallback(SkPoint start, SkScalar length, int count, Stage* stage) { } } +// PointProcessor uses a strategy to help complete the work of the different stages. The strategy +// must implement the following methods: +// * processPoints(xs, ys) - must mutate the xs and ys for the stage. +// * maybeProcessSpan(start, length, count) - This represents a horizontal series of pixels +// to work over. +// start - is the starting pixel. This is in destination space before the matrix stage, and in +// source space after the matrix stage. +// length - is this distance between the first pixel center and the last pixel center. Like start, +// this is in destination space before the matrix stage, and in source space after. +// count - the number of pixels in source space to produce. +// next - a pointer to the next stage. +// maybeProcessSpan - returns false if it can not process the span and needs to fallback to +// point lists for processing. template<typename Strategy, typename Next> class PointProcessor final : public PointProcessorInterface { public: @@ -77,7 +90,9 @@ public: } void pointSpan(SkPoint start, SkScalar length, int count) override { - span_fallback(start, length, count, this); + if (!fStrategy.maybeProcessSpan(start, length, count, fNext)) { + span_fallback(start, length, count, this); + } } private: @@ -85,6 +100,7 @@ private: Strategy fStrategy; }; +// See PointProcessor for responsibilities of Strategy. template<typename Strategy, typename Next> class BilerpProcessor final : public BilerpProcessorInterface { public: @@ -115,7 +131,9 @@ public: } void pointSpan(SkPoint start, SkScalar length, int count) override { - span_fallback(start, length, count, this); + if (!fStrategy.maybeProcessSpan(start, length, count, fNext)) { + span_fallback(start, length, count, this); + } } private: @@ -143,11 +161,18 @@ public: TranslateMatrixStrategy(SkVector offset) : fXOffset{X(offset)} , fYOffset{Y(offset)} { } + void processPoints(Sk4f* xs, Sk4f* ys) { *xs = *xs + fXOffset; *ys = *ys + fYOffset; } + template <typename Next> + bool maybeProcessSpan(SkPoint start, SkScalar length, int count, Next* next) { + next->pointSpan(start + SkPoint{fXOffset[0], fYOffset[0]}, length, count); + return true; + } + private: const Sk4f fXOffset, fYOffset; }; @@ -164,6 +189,15 @@ public: *ys = *ys * fYScale + fYOffset; } + template <typename Next> + bool maybeProcessSpan(SkPoint start, SkScalar length, int count, Next* next) { + SkPoint newStart = + SkPoint{X(start) * fXScale[0] + fXOffset[0], Y(start) * fYScale[0] + fYOffset[0]}; + SkScalar newLength = length * fXScale[0]; + next->pointSpan(newStart, newLength, count); + return true; + } + private: const Sk4f fXOffset, fYOffset; const Sk4f fXScale, fYScale; @@ -185,6 +219,11 @@ public: *ys = newYs; } + template <typename Next> + bool maybeProcessSpan(SkPoint start, SkScalar length, int count, Next* next) { + return false; + } + private: const Sk4f fXOffset, fYOffset; const Sk4f fXScale, fYScale; @@ -286,6 +325,11 @@ public: *ys = Sk4f::Min(Sk4f::Max(*ys, fYMin), fYMax); } + template <typename Next> + bool maybeProcessSpan(SkPoint start, SkScalar length, int count, Next* next) { + return false; + } + private: const Sk4f fXMin{SK_FloatNegativeInfinity}; const Sk4f fYMin{SK_FloatNegativeInfinity}; @@ -314,6 +358,11 @@ public: *ys = *ys - baseY; } + template <typename Next> + bool maybeProcessSpan(SkPoint start, SkScalar length, int count, Next* next) { + return false; + } + private: const Sk4f fXMax{0.0f}; const Sk4f fXInvMax{0.0f}; |