diff options
author | Florin Malita <fmalita@chromium.org> | 2017-10-28 11:06:48 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-10-28 19:06:17 +0000 |
commit | ed6ae56e0ee8c51f6b74025a49dee348d8f26d25 (patch) | |
tree | 85698bcdaa7d95917618930261cd3378c83b216f | |
parent | c543f3e03f6b001cf58698d60ee71273805cc4f4 (diff) |
Re-land: Stop using fixed point recs for gradient positioning info
The fixed point gradient records are historical relics. Instead of
round-tripping through FP, just use the float positions directly.
We can remove the recs completely in a follow-up.
TBR=
Change-Id: Ic3c8e58af6dfa76744799513c9e60af0462014d0
Reviewed-on: https://skia-review.googlesource.com/64680
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
-rw-r--r-- | src/shaders/gradients/SkGradientShader.cpp | 27 | ||||
-rw-r--r-- | src/shaders/gradients/SkGradientShaderPriv.h | 5 |
2 files changed, 13 insertions, 19 deletions
diff --git a/src/shaders/gradients/SkGradientShader.cpp b/src/shaders/gradients/SkGradientShader.cpp index 8e24919c94..de4247c8e4 100644 --- a/src/shaders/gradients/SkGradientShader.cpp +++ b/src/shaders/gradients/SkGradientShader.cpp @@ -498,11 +498,6 @@ bool SkGradientShaderBase::onAsLuminanceColor(SkColor* lum) const { return true; } -static inline int SkFixedToFFFF(SkFixed x) { - SkASSERT((unsigned)x <= SK_Fixed1); - return x - (x >> 16); -} - static constexpr int kGradientTextureSize = 256; void SkGradientShaderBase::initLinearBitmap(SkBitmap* bitmap, GradientBitmapType bitmapType) const { @@ -540,14 +535,13 @@ void SkGradientShaderBase::initLinearBitmap(SkBitmap* bitmap, GradientBitmapType // our own CS for identity/no transform. auto* cs = bitmapType != GradientBitmapType::kLegacy ? fColorSpace.get() : nullptr; - // TODO: refactor to avoid using fRecs. - static constexpr unsigned kCacheShift = 8; - int prevIndex = 0; for (int i = 1; i < fColorCount; i++) { - int nextIndex = (fColorCount == 2) ? (kGradientTextureSize - 1) - : SkFixedToFFFF(fRecs[i].fPos) >> kCacheShift; - SkASSERT(nextIndex < kGradientTextureSize); + // Historically, stops have been mapped to [0, 256], with 256 then nudged to the + // next smaller value, then truncate for the texture index. This seems to produce + // the best results for some common distributions, so we preserve the behavior. + int nextIndex = SkTMin(this->getPos(i) * kGradientTextureSize, + SkIntToScalar(kGradientTextureSize - 1)); if (nextIndex > prevIndex) { SkColor4f color0 = this->getXformedColor(i - 1, cs), @@ -654,13 +648,8 @@ void SkGradientShaderBase::commonAsAGradient(GradientInfo* info) const { memcpy(info->fColors, fOrigColors, fColorCount * sizeof(SkColor)); } if (info->fColorOffsets) { - if (fColorCount == 2) { - info->fColorOffsets[0] = 0; - info->fColorOffsets[1] = SK_Scalar1; - } else if (fColorCount > 2) { - for (int i = 0; i < fColorCount; ++i) { - info->fColorOffsets[i] = SkFixedToScalar(fRecs[i].fPos); - } + for (int i = 0; i < fColorCount; ++i) { + info->fColorOffsets[i] = this->getPos(i); } } } @@ -685,7 +674,7 @@ void SkGradientShaderBase::toString(SkString* str) const { if (fColorCount > 2) { str->append(" points: ("); for (int i = 0; i < fColorCount; ++i) { - str->appendScalar(SkFixedToScalar(fRecs[i].fPos)); + str->appendScalar(this->getPos(i)); if (i < fColorCount-1) { str->append(", "); } diff --git a/src/shaders/gradients/SkGradientShaderPriv.h b/src/shaders/gradients/SkGradientShaderPriv.h index 9aad102491..983c3ef124 100644 --- a/src/shaders/gradients/SkGradientShaderPriv.h +++ b/src/shaders/gradients/SkGradientShaderPriv.h @@ -125,6 +125,11 @@ private: }; SkColor fStorage[(kStorageSize + 3) >> 2]; public: + SkScalar getPos(int i) const { + SkASSERT(i < fColorCount); + return fOrigPos ? fOrigPos[i] : SkIntToScalar(i) / (fColorCount - 1); + } + SkColor* fOrigColors; // original colors, before modulation by paint in context. SkColor4f* fOrigColors4f; // original colors, as linear floats SkScalar* fOrigPos; // original positions |