tolerate alpha slightly out of [0,1]

It's interesting but perhaps not consequential that bilerp can produce
alpha just greater than 1.0f.  I think this setup of what clamps what
where mirrors the GPU backend more closely.  No pixel diffs.

The p3 GM would draw a little differently if we only min(rgb, alpha),
and that would make it inconsistent with the GPU backend, so I've kept
it as clamp(rgb, 0, alpha).

Change-Id: I5cfacb9aae56c33b542cbc4e5e740b4d24c6b9e3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/262812
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Mike Klein 2020-01-07 12:07:24 -06:00 committed by Skia Commit-Bot
parent 49f7a49973
commit 17edb8df09
2 changed files with 4 additions and 18 deletions

View File

@ -186,9 +186,6 @@ namespace {
params.quality, params.colorSpace.get(),
uniforms, alloc,
x,y, &src.r, &src.g, &src.b, &src.a));
// We don't know if the src color is normalized (logical [0,1], premul [0,a]) or not.
bool src_is_normalized = false;
if (params.coverage == Coverage::Mask3D) {
skvm::F32 M = unorm(8, load8(varying<uint8_t>())),
A = unorm(8, load8(varying<uint8_t>()));
@ -204,17 +201,9 @@ namespace {
// So we clamp the shader to gamut here before blending and coverage.
if (params.alphaType == kPremul_SkAlphaType
&& SkColorTypeIsNormalized(params.colorType)) {
assert_true(gte(src.a, splat(0.0f)), src.a);
assert_true(lte(src.a, splat(1.0f)), src.a);
src.r = clamp(src.r, splat(0.0f), src.a);
src.g = clamp(src.g, splat(0.0f), src.a);
src.b = clamp(src.b, splat(0.0f), src.a);
// Knowing that we're normalizing here and that blending and coverage
// won't affect that when the destination is normalized, we can avoid
// avoid a redundant clamp just before storing.
src_is_normalized = true;
}
// There are several orderings here of when we load dst and coverage
@ -297,13 +286,11 @@ namespace {
}
// Clamp to fit destination color format if needed.
if (!src_is_normalized && SkColorTypeIsNormalized(params.colorType)) {
if (SkColorTypeIsNormalized(params.colorType)) {
src.r = clamp(src.r, splat(0.0f), splat(1.0f));
src.g = clamp(src.g, splat(0.0f), splat(1.0f));
src.b = clamp(src.b, splat(0.0f), splat(1.0f));
assert_true(gte(src.a, splat(0.0f)), src.a);
assert_true(lte(src.a, splat(1.0f)), src.a);
src.a = clamp(src.a, splat(0.0f), splat(1.0f));
}
if (force_opaque) {
src.a = splat(1.0f);

View File

@ -814,9 +814,8 @@ bool SkImageShader::onProgram(skvm::Builder* p,
}
}
// Filtering can produce out of range values on both sides of [0,1],
// bicubic naturally mathematically so, bilerp only very, very slightly due to float rounding.
if (quality > kNone_SkFilterQuality) {
// Bicubic filtering naturally produces out of range values on both sides of [0,1].
if (quality == kHigh_SkFilterQuality) {
*a = p->clamp(*a, p->splat(0.0f), p->splat(1.0f));
skvm::F32 limit = (pm.alphaType() == kUnpremul_SkAlphaType || fClampAsIfUnpremul)