Add a clamp stage to SkRasterPipelineBlitter.
authormtklein <mtklein@chromium.org>
Mon, 25 Jul 2016 13:13:47 +0000 (06:13 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 25 Jul 2016 13:13:47 +0000 (06:13 -0700)
commitb5acf6e702e318b405a04d38bfdac602dc3ed773
treefb333817745639dba0dfc74d27d3a20de5e2b70e
parent8bc90e2db692e02048f15e2f165f6d61c6110419
Add a clamp stage to SkRasterPipelineBlitter.

This clamps to [0,1] premul just before every store to memory.

By making the clamp a stage itself, this design makes it easy to move the clamp
around, to replace it with a debug-only assert-we're-clamped stage for certain
formats, clamp in more places, programatically not clamp, etc. etc.

Before this change, clamping was a little haphazard: store_srgb clamped
R, G and B to [0,1], but not A, and didn't clamp the colors to A.  565
didn't clamp at all.

6 GMs draw subtly differently in sRGB, I think because we've started clamping
colors to alpha to enforce premultiplication better.  No changes for 565.

My hope is that now no other stage need ever concern itself with clamping.

So we don't double-clamp, I've added a _noclamp version of sk_linear_to_srgb()
that simply asserts a clamp isn't necessary.  This happens to expose the Sk4f
_needs_trunc version that might be useful for power users (*cough* Matt *cough*).

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2178793002

Review-Url: https://codereview.chromium.org/2178793002
src/core/SkRasterPipelineBlitter.cpp
src/core/SkSRGB.h