Try to normalize tangents more robustly in stroke tessellators

I noticed the old version of cosine_between_vectors was causing issues
after https://skia-review.googlesource.com/c/skia/+/532014 landed, which
had the effect that tan0 and tan1 tended to be larger for lines.

That said, I could find instances of the same visual glitches on other
devices before that change landed, so depending on the hardware we were
running into issues either way.

This changes the cosine function to assume the tangents are already
normalized, and restructures the curve evaluation logic to assume that
as well. This is a reduction in work that hopefully makes up for the
work of always normalizing tan0 and tan1, whereas before the cosine_
function attempted to avoid that, and do a single inversesqrt call.

From a precision standpoint, just switching to calling normalize() on
tan0 and tan1 before getting the cosine improves the problem compared
to the precision required to store (dot(tan0,tan0)*dot(tan1,tan1))
before normalization. However, I also added some additional logic for
when coordinates get very large to try and scale the two end points of
the line to a more normalized exponent range. Since it returns the unit
vector, it should be equivalent but more accurate.

Bug: skia:11268, skia:12703, skia:13056
Change-Id: I34b6e1df1f57a8913443d75ed78710fcd27731e6
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/532777
Auto-Submit: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
4 files changed