diff options
author | herb <herb@google.com> | 2016-11-08 08:19:07 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-11-08 08:19:07 -0800 |
commit | 93b0650084285400102f2d65d5c4411185111085 (patch) | |
tree | 9153446b4650b20a6b69f0c7e47e604d880dd59e | |
parent | 442fff958c911bbc354a56003e3a8d75805c45f6 (diff) |
Change code to not store Sk4* in data structures.
This allows the SkLinearBitmapPipeline system to avoid problems with alignment. This allows it to naturally fit with the rest of the system, and simplifies surrounding code.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2486523002
Review-Url: https://codereview.chromium.org/2486523002
-rw-r--r-- | src/core/SkLinearBitmapPipeline.cpp | 2 | ||||
-rw-r--r-- | src/core/SkLinearBitmapPipeline.h | 29 | ||||
-rw-r--r-- | src/core/SkLinearBitmapPipeline_matrix.h | 24 | ||||
-rw-r--r-- | src/core/SkLinearBitmapPipeline_sample.h | 10 | ||||
-rw-r--r-- | src/core/SkLinearBitmapPipeline_tile.h | 104 |
5 files changed, 79 insertions, 90 deletions
diff --git a/src/core/SkLinearBitmapPipeline.cpp b/src/core/SkLinearBitmapPipeline.cpp index 401eb41b79..d77f28bb5b 100644 --- a/src/core/SkLinearBitmapPipeline.cpp +++ b/src/core/SkLinearBitmapPipeline.cpp @@ -597,7 +597,7 @@ private: SkPM4f* fDst; SkPM4f* fEnd; - Sk4f fPostAlpha; + float fPostAlpha; }; static SkLinearBitmapPipeline::BlendProcessorInterface* choose_blender_for_shading( diff --git a/src/core/SkLinearBitmapPipeline.h b/src/core/SkLinearBitmapPipeline.h index 3abdb8014a..776f8d8603 100644 --- a/src/core/SkLinearBitmapPipeline.h +++ b/src/core/SkLinearBitmapPipeline.h @@ -84,7 +84,7 @@ public: private: std::function<void (Next*, void*)> fStageCloner; - alignas(16) mutable char fSpace[kSize]; + mutable char fSpace[kSize]; bool fIsInitialized; }; @@ -113,8 +113,8 @@ public: Base& operator*() const { return *(this->get()); } private: - alignas(16) mutable char fSpace[kSize]; - bool fIsInitialized; + mutable char fSpace[kSize]; + bool fIsInitialized; }; @@ -125,8 +125,8 @@ public: class PixelAccessorInterface; // These values were generated by the assert above in Stage::init{Sink|Stage}. - using MatrixStage = Stage<PointProcessorInterface, 160, PointProcessorInterface>; - using TileStage = Stage<PointProcessorInterface, 160, SampleProcessorInterface>; + using MatrixStage = Stage<PointProcessorInterface, 56, PointProcessorInterface>; + using TileStage = Stage<PointProcessorInterface, 48, SampleProcessorInterface>; using SampleStage = Stage<SampleProcessorInterface, 160, BlendProcessorInterface>; using BlenderStage = Stage<BlendProcessorInterface, 48>; using Accessor = PolyMemory<PixelAccessorInterface, 64>; @@ -147,29 +147,26 @@ class SkEmbeddableLinearPipeline { public: SkEmbeddableLinearPipeline() { } ~SkEmbeddableLinearPipeline() { - if (get() != nullptr) { + if (fInitialized) { get()->~SkLinearBitmapPipeline(); } } template <typename... Args> void init(Args&&... args) { - // Ensure that our pipeline is created at a 16 byte aligned address. - fPipeline = (SkLinearBitmapPipeline*)SkAlign16((intptr_t)fPipelineStorage); - new (fPipeline) SkLinearBitmapPipeline{std::forward<Args>(args)...}; + new (fPipelineStorage) SkLinearBitmapPipeline{std::forward<Args>(args)...}; + fInitialized = true; } - SkLinearBitmapPipeline* get() const { return fPipeline; } + SkLinearBitmapPipeline* get() const { + return reinterpret_cast<SkLinearBitmapPipeline*>(fPipelineStorage); + } SkLinearBitmapPipeline& operator*() const { return *this->get(); } SkLinearBitmapPipeline* operator->() const { return this->get(); } private: - enum { - kActualSize = sizeof(SkLinearBitmapPipeline), - kPaddedSize = SkAlignPtr(kActualSize + 12), - }; - void* fPipelineStorage[kPaddedSize / sizeof(void*)]; - SkLinearBitmapPipeline* fPipeline{nullptr}; + alignas(SkLinearBitmapPipeline) mutable char fPipelineStorage[sizeof(SkLinearBitmapPipeline)]; + bool fInitialized {false}; }; #endif // SkLinearBitmapPipeline_DEFINED diff --git a/src/core/SkLinearBitmapPipeline_matrix.h b/src/core/SkLinearBitmapPipeline_matrix.h index d194d0729a..2eb475d510 100644 --- a/src/core/SkLinearBitmapPipeline_matrix.h +++ b/src/core/SkLinearBitmapPipeline_matrix.h @@ -26,12 +26,12 @@ public: bool maybeProcessSpan(Span span, Next* next) { SkPoint start; SkScalar length; int count; std::tie(start, length, count) = span; - next->pointSpan(Span{start + SkPoint{fXOffset[0], fYOffset[0]}, length, count}); + next->pointSpan(Span{start + SkPoint{fXOffset, fYOffset}, length, count}); return true; } private: - const Sk4s fXOffset, fYOffset; + const SkScalar fXOffset, fYOffset; }; class ScaleMatrixStrategy { @@ -49,15 +49,15 @@ public: SkPoint start; SkScalar length; int count; std::tie(start, length, count) = span; SkPoint newStart = - SkPoint{X(start) * fXScale[0] + fXOffset[0], Y(start) * fYScale[0] + fYOffset[0]}; - SkScalar newLength = length * fXScale[0]; + SkPoint{X(start) * fXScale + fXOffset, Y(start) * fYScale + fYOffset}; + SkScalar newLength = length * fXScale; next->pointSpan(Span{newStart, newLength, count}); return true; } private: - const Sk4s fXOffset, fYOffset; - const Sk4s fXScale, fYScale; + const SkScalar fXOffset, fYOffset; + const SkScalar fXScale, fYScale; }; class AffineMatrixStrategy { @@ -80,9 +80,9 @@ public: } private: - const Sk4s fXOffset, fYOffset; - const Sk4s fXScale, fYScale; - const Sk4s fXSkew, fYSkew; + const SkScalar fXOffset, fYOffset; + const SkScalar fXScale, fYScale; + const SkScalar fXSkew, fYSkew; }; class PerspectiveMatrixStrategy { @@ -107,9 +107,9 @@ public: } private: - const Sk4s fXOffset, fYOffset, fZOffset; - const Sk4s fXScale, fYScale; - const Sk4s fXSkew, fYSkew, fZXSkew, fZYSkew; + const SkScalar fXOffset, fYOffset, fZOffset; + const SkScalar fXScale, fYScale; + const SkScalar fXSkew, fYSkew, fZXSkew, fZYSkew; }; diff --git a/src/core/SkLinearBitmapPipeline_sample.h b/src/core/SkLinearBitmapPipeline_sample.h index 5f9948c644..8e53136fea 100644 --- a/src/core/SkLinearBitmapPipeline_sample.h +++ b/src/core/SkLinearBitmapPipeline_sample.h @@ -65,15 +65,17 @@ template <> class PixelConverter<kAlpha_8_SkColorType, kLinear_SkGammaType> { public: using Element = uint8_t; - PixelConverter(const SkPixmap& srcPixmap, SkColor tintColor) - : fTintColor{set_alpha(Sk4f_from_SkColor(tintColor), 1.0f)} { } + PixelConverter(const SkPixmap& srcPixmap, SkColor tintColor) { + fTintColor = SkColor4f::FromColor(tintColor); + fTintColor.fA = 1.0f; + } Sk4f toSk4f(const Element pixel) const { - return fTintColor * (pixel * (1.0f/255.0f)); + return Sk4f::Load(&fTintColor) * (pixel * (1.0f/255.0f)); } private: - const Sk4f fTintColor; + SkColor4f fTintColor; }; template <SkGammaType gammaType> diff --git a/src/core/SkLinearBitmapPipeline_tile.h b/src/core/SkLinearBitmapPipeline_tile.h index 1e07c22cf5..df47ba0734 100644 --- a/src/core/SkLinearBitmapPipeline_tile.h +++ b/src/core/SkLinearBitmapPipeline_tile.h @@ -18,11 +18,11 @@ namespace { class XClampStrategy { public: XClampStrategy(int32_t max) - : fXsMax{SkScalar(max - 0.5f)} + : fXMaxPixel{SkScalar(max - 0.5f)} , fXMax{SkScalar(max)} { } void tileXPoints(Sk4s* xs) { - *xs = Sk4s::Min(Sk4s::Max(*xs, 0.0f), fXsMax); + *xs = Sk4s::Min(Sk4s::Max(*xs, 0.0f), fXMaxPixel); SkASSERT(0 <= (*xs)[0] && (*xs)[0] < fXMax); SkASSERT(0 <= (*xs)[1] && (*xs)[1] < fXMax); SkASSERT(0 <= (*xs)[2] && (*xs)[2] < fXMax); @@ -108,18 +108,17 @@ public: } private: - const Sk4s fXsMax; + const SkScalar fXMaxPixel; const SkScalar fXMax; }; class YClampStrategy { public: YClampStrategy(int32_t max) - : fYMax{SkScalar(max) - 0.5f} - , fYsMax{SkScalar(max) - 0.5f} { } + : fYMax{SkScalar(max) - 0.5f} { } void tileYPoints(Sk4s* ys) { - *ys = Sk4s::Min(Sk4s::Max(*ys, 0.0f), fYsMax); + *ys = Sk4s::Min(Sk4s::Max(*ys, 0.0f), fYMax); SkASSERT(0 <= (*ys)[0] && (*ys)[0] <= fYMax); SkASSERT(0 <= (*ys)[1] && (*ys)[1] <= fYMax); SkASSERT(0 <= (*ys)[2] && (*ys)[2] <= fYMax); @@ -132,7 +131,6 @@ public: private: const SkScalar fYMax; - const Sk4s fYsMax; }; SkScalar tile_mod(SkScalar x, SkScalar base) { @@ -143,14 +141,13 @@ class XRepeatStrategy { public: XRepeatStrategy(int32_t max) : fXMax{SkScalar(max)} - , fXsMax{SkScalar(max)} - , fXsCap{SkScalar(nextafterf(SkScalar(max), 0.0f))} - , fXsInvMax{1.0f / SkScalar(max)} { } + , fXCap{SkScalar(nextafterf(SkScalar(max), 0.0f))} + , fXInvMax{1.0f / SkScalar(max)} { } void tileXPoints(Sk4s* xs) { - Sk4s divX = *xs * fXsInvMax; - Sk4s modX = *xs - divX.floor() * fXsMax; - *xs = Sk4s::Min(fXsCap, modX); + Sk4s divX = *xs * fXInvMax; + Sk4s modX = *xs - divX.floor() * fXMax; + *xs = Sk4s::Min(fXCap, modX); SkASSERT(0 <= (*xs)[0] && (*xs)[0] < fXMax); SkASSERT(0 <= (*xs)[1] && (*xs)[1] < fXMax); SkASSERT(0 <= (*xs)[2] && (*xs)[2] < fXMax); @@ -228,9 +225,8 @@ public: private: const SkScalar fXMax; - const Sk4s fXsMax; - const Sk4s fXsCap; - const Sk4s fXsInvMax; + const SkScalar fXCap; + const SkScalar fXInvMax; }; // The XRepeatUnitScaleStrategy exploits the situation where dx = 1.0. The main advantage is that @@ -242,14 +238,13 @@ class XRepeatUnitScaleStrategy { public: XRepeatUnitScaleStrategy(int32_t max) : fXMax{SkScalar(max)} - , fXsMax{SkScalar(max)} - , fXsCap{SkScalar(nextafterf(SkScalar(max), 0.0f))} - , fXsInvMax{1.0f / SkScalar(max)} { } + , fXCap{SkScalar(nextafterf(SkScalar(max), 0.0f))} + , fXInvMax{1.0f / SkScalar(max)} { } void tileXPoints(Sk4s* xs) { - Sk4s divX = *xs * fXsInvMax; - Sk4s modX = *xs - divX.floor() * fXsMax; - *xs = Sk4s::Min(fXsCap, modX); + Sk4s divX = *xs * fXInvMax; + Sk4s modX = *xs - divX.floor() * fXMax; + *xs = Sk4s::Min(fXCap, modX); SkASSERT(0 <= (*xs)[0] && (*xs)[0] < fXMax); SkASSERT(0 <= (*xs)[1] && (*xs)[1] < fXMax); SkASSERT(0 <= (*xs)[2] && (*xs)[2] < fXMax); @@ -319,21 +314,19 @@ public: private: const SkScalar fXMax; - const Sk4s fXsMax; - const Sk4s fXsCap; - const Sk4s fXsInvMax; + const SkScalar fXCap; + const SkScalar fXInvMax; }; class YRepeatStrategy { public: YRepeatStrategy(int32_t max) : fYMax{SkScalar(max)} - , fYsMax{SkScalar(max)} , fYsInvMax{1.0f / SkScalar(max)} { } void tileYPoints(Sk4s* ys) { Sk4s divY = *ys * fYsInvMax; - Sk4s modY = *ys - divY.floor() * fYsMax; + Sk4s modY = *ys - divY.floor() * fYMax; *ys = modY; SkASSERT(0 <= (*ys)[0] && (*ys)[0] < fYMax); SkASSERT(0 <= (*ys)[1] && (*ys)[1] < fYMax); @@ -349,53 +342,51 @@ public: private: const SkScalar fYMax; - const Sk4s fYsMax; - const Sk4s fYsInvMax; + const SkScalar fYsInvMax; }; // max = 40 // mq2[x_] := Abs[(x - 40) - Floor[(x - 40)/80] * 80 - 40] class XMirrorStrategy { public: XMirrorStrategy(int32_t max) - : fXsMax{SkScalar(max)} - , fXsCap{SkScalar(nextafterf(SkScalar(max), 0.0f))} - , fXsDoubleInvMax{1.0f / (2.0f * SkScalar(max))} { } + : fXMax{SkScalar(max)} + , fXCap{SkScalar(nextafterf(SkScalar(max), 0.0f))} + , fXDoubleInvMax{1.0f / (2.0f * SkScalar(max))} { } void tileXPoints(Sk4s* xs) { - Sk4f bias = *xs - fXsMax; - Sk4f div = bias * fXsDoubleInvMax; - Sk4f mod = bias - div.floor() * 2.0f * fXsMax; - Sk4f unbias = mod - fXsMax; - *xs = Sk4f::Min(unbias.abs(), fXsCap); - SkASSERT(0 <= (*xs)[0] && (*xs)[0] < fXsMax[0]); - SkASSERT(0 <= (*xs)[1] && (*xs)[1] < fXsMax[0]); - SkASSERT(0 <= (*xs)[2] && (*xs)[2] < fXsMax[0]); - SkASSERT(0 <= (*xs)[3] && (*xs)[3] < fXsMax[0]); + Sk4f bias = *xs - fXMax; + Sk4f div = bias * fXDoubleInvMax; + Sk4f mod = bias - div.floor() * 2.0f * fXMax; + Sk4f unbias = mod - fXMax; + *xs = Sk4f::Min(unbias.abs(), fXCap); + SkASSERT(0 <= (*xs)[0] && (*xs)[0] < fXMax); + SkASSERT(0 <= (*xs)[1] && (*xs)[1] < fXMax); + SkASSERT(0 <= (*xs)[2] && (*xs)[2] < fXMax); + SkASSERT(0 <= (*xs)[3] && (*xs)[3] < fXMax); } template <typename Next> bool maybeProcessSpan(Span originalSpan, Next* next) { return false; } private: - Sk4f fXsMax; - Sk4f fXsCap; - Sk4f fXsDoubleInvMax; + SkScalar fXMax; + SkScalar fXCap; + SkScalar fXDoubleInvMax; }; class YMirrorStrategy { public: YMirrorStrategy(int32_t max) : fYMax{SkScalar(max)} - , fYsMax{SkScalar(max)} - , fYsCap{nextafterf(SkScalar(max), 0.0f)} - , fYsDoubleInvMax{1.0f / (2.0f * SkScalar(max))} { } + , fYCap{nextafterf(SkScalar(max), 0.0f)} + , fYDoubleInvMax{1.0f / (2.0f * SkScalar(max))} { } void tileYPoints(Sk4s* ys) { - Sk4f bias = *ys - fYsMax; - Sk4f div = bias * fYsDoubleInvMax; - Sk4f mod = bias - div.floor() * 2.0f * fYsMax; - Sk4f unbias = mod - fYsMax; - *ys = Sk4f::Min(unbias.abs(), fYsCap); + Sk4f bias = *ys - fYMax; + Sk4f div = bias * fYDoubleInvMax; + Sk4f mod = bias - div.floor() * 2.0f * fYMax; + Sk4f unbias = mod - fYMax; + *ys = Sk4f::Min(unbias.abs(), fYCap); SkASSERT(0 <= (*ys)[0] && (*ys)[0] < fYMax); SkASSERT(0 <= (*ys)[1] && (*ys)[1] < fYMax); SkASSERT(0 <= (*ys)[2] && (*ys)[2] < fYMax); @@ -404,19 +395,18 @@ public: SkScalar tileY(SkScalar y) { SkScalar bias = y - fYMax; - SkScalar div = bias * fYsDoubleInvMax[0]; + SkScalar div = bias * fYDoubleInvMax; SkScalar mod = bias - SkScalarFloorToScalar(div) * 2.0f * fYMax; SkScalar unbias = mod - fYMax; - SkScalar answer = SkMinScalar(SkScalarAbs(unbias), fYsCap[0]); + SkScalar answer = SkMinScalar(SkScalarAbs(unbias), fYCap); SkASSERT(0 <= answer && answer < fYMax); return answer; } private: SkScalar fYMax; - Sk4f fYsMax; - Sk4f fYsCap; - Sk4f fYsDoubleInvMax; + SkScalar fYCap; + SkScalar fYDoubleInvMax; }; } // namespace |