Fix for png encoding performance regressions - downstream diff

The original fix was:

> Fix performance regression in png encoding caused by libpng update
>
> libpng calculates "filter heuristics" to choose which png
> filter to apply.  Chrome need not calculate these "filter
> heuristics" because we always choose to use the SUB filter,
> for speed.
>
> libpng 1.6 refactors the SUB filter to share code, also
> forcing us to calculate the filter heuristics, even though
> we don't need to.  This caused a performance regression.
>
> This CL cherry picks a fix from upstream that:
> (1) Passes PNG_SIZE_MAX to the filter code.  This allows
> the compiler to optimize out the heuristic calculation
> code, fixing the performance regression.
> (2) Fixes overflow handling in the calculation of filter
> heuristics.  This won't affect Chrome.
>
> Review-Url: https://codereview.chromium.org/2062423002

This fix was effective everywhere we use clang, but did
not work on Android (GCC) or Windows (MSVS) because the
compiler was not applying the appropriate optimizations.

This CL contains a more portable fix.  This was briefly
landed by libpng, but backed out.  They fear it increases
code size and that the compiler can be forced to make
the same optimization.

FWIW, we have demonstrated that we can force the compiler
to make the same optimization.
https://codereview.chromium.org/2119813003/

But we feel that changing the compiler options is fragile
and it is better to just carry a diff.

BUG=619850
BUG=599917

Review-Url: https://codereview.chromium.org/2132783002
Cr-Commit-Position: refs/heads/master@{#404379}
2 files changed