Cache more aggressively in GrSoftwarePathRenderer for Android

Discard fractional translation from the cache key in
GrSoftwarePathRenderer for Android framework. This improves
cache hit ratio and speeds up draw frame 50th percentile for quick
settings jank test by 0.7ms. This quality trade-off is fine and
it is matching HWUI OpenGL renderer behavior.

Bug: b/64487466
Change-Id: I865169aa2acbca80f1399da8bdd7f624f413295e
Reviewed-on: https://skia-review.googlesource.com/34900
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Stan Iliev <stani@google.com>
This commit is contained in:
Stan Iliev 2017-08-15 17:10:26 -04:00 committed by Skia Commit-Bot
parent 228276dabf
commit 67cd673291

View File

@ -186,19 +186,30 @@ bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
SkScalar sy = args.fViewMatrix->get(SkMatrix::kMScaleY);
SkScalar kx = args.fViewMatrix->get(SkMatrix::kMSkewX);
SkScalar ky = args.fViewMatrix->get(SkMatrix::kMSkewY);
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
// Fractional translate does not affect caching on Android. This is done for better cache
// hit ratio and speed, but it is matching HWUI behavior, which doesn't consider the matrix
// at all when caching paths.
GrUniqueKey::Builder builder(&maskKey, kDomain, 4 + args.fShape->unstyledKeySize());
#else
SkScalar tx = args.fViewMatrix->get(SkMatrix::kMTransX);
SkScalar ty = args.fViewMatrix->get(SkMatrix::kMTransY);
// Allow 8 bits each in x and y of subpixel positioning.
SkFixed fracX = SkScalarToFixed(SkScalarFraction(tx)) & 0x0000FF00;
SkFixed fracY = SkScalarToFixed(SkScalarFraction(ty)) & 0x0000FF00;
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
GrUniqueKey::Builder builder(&maskKey, kDomain, 5 + args.fShape->unstyledKeySize());
#endif
builder[0] = SkFloat2Bits(sx);
builder[1] = SkFloat2Bits(sy);
builder[2] = SkFloat2Bits(kx);
builder[3] = SkFloat2Bits(ky);
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
args.fShape->writeUnstyledKey(&builder[4]);
#else
builder[4] = fracX | (fracY >> 8);
args.fShape->writeUnstyledKey(&builder[5]);
#endif
// FIXME: Doesn't the key need to consider whether we're using AA or not? In practice that
// should always be true, though.
}