Harden linear gradients
Ensure that the last offset == 1.0f when implict positions are used (previously subject to float imprecision). BUG=skia:5288,chromium:598484 R=reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1974463002 Review-Url: https://codereview.chromium.org/1974463002
This commit is contained in:
parent
87bf8f7d15
commit
748d620adc
@ -774,6 +774,8 @@ static bool valid_grad(const SkColor colors[], const SkScalar pos[], int count,
|
||||
static void desc_init(SkGradientShaderBase::Descriptor* desc,
|
||||
const SkColor colors[], const SkScalar pos[], int colorCount,
|
||||
SkShader::TileMode mode, uint32_t flags, const SkMatrix* localMatrix) {
|
||||
SkASSERT(colorCount > 1);
|
||||
|
||||
desc->fColors = colors;
|
||||
desc->fPos = pos;
|
||||
desc->fCount = colorCount;
|
||||
|
@ -99,7 +99,9 @@ SkLinearGradient::LinearGradientContext::LinearGradientContext(
|
||||
: INHERITED(shader, ctx)
|
||||
{
|
||||
// setup for Sk4f
|
||||
int count = shader.fColorCount;
|
||||
const int count = shader.fColorCount;
|
||||
SkASSERT(count > 1);
|
||||
|
||||
fRecs.setCount(count);
|
||||
Rec* rec = fRecs.begin();
|
||||
if (shader.fOrigPos) {
|
||||
@ -114,16 +116,16 @@ SkLinearGradient::LinearGradientContext::LinearGradientContext(
|
||||
rec[i].fPosScale = 0;
|
||||
}
|
||||
}
|
||||
rec[count - 1].fPos = 1; // overwrite the last value just to be sure we end at 1.0
|
||||
} else {
|
||||
// no pos specified, so we compute evenly spaced values
|
||||
const float scale = float(count - 1);
|
||||
float invScale = 1.0f / scale;
|
||||
const float invScale = 1.0f / scale;
|
||||
for (int i = 0; i < count; ++i) {
|
||||
rec[i].fPos = i * invScale;
|
||||
rec[i].fPosScale = scale;
|
||||
}
|
||||
}
|
||||
rec[count - 1].fPos = 1; // overwrite the last value just to be sure we end at 1.0
|
||||
|
||||
fApplyAlphaAfterInterp = true;
|
||||
if ((shader.getGradFlags() & SkGradientShader::kInterpolateColorsInPremul_Flag) ||
|
||||
|
Loading…
Reference in New Issue
Block a user