Merge latest Skia into master (2 commits)

https://skia.googlesource.com/skia.git/+log/757914d..9ae32a2

Test: Presubmit checks will test this change.
Change-Id: Iaa8fa744163941a72a5ba10ad0ca758d428f042f
diff --git a/include/gpu/GrProcessorUnitTest.h b/include/gpu/GrProcessorUnitTest.h
index 49f26fd..7cec307 100644
--- a/include/gpu/GrProcessorUnitTest.h
+++ b/include/gpu/GrProcessorUnitTest.h
@@ -45,12 +45,10 @@
 struct GrProcessorTestData {
     GrProcessorTestData(SkRandom* random,
                         GrContext* context,
-                        const GrCaps* caps,
                         const GrRenderTargetContext* renderTargetContext,
                         GrTexture* textures[2])
         : fRandom(random)
         , fContext(context)
-        , fCaps(caps)
         , fRenderTargetContext(renderTargetContext) {
         fTextures[0] = textures[0];
         fTextures[1] = textures[1];
@@ -60,7 +58,6 @@
     }
     SkRandom* fRandom;
     GrContext* fContext;
-    const GrCaps* fCaps;
     const GrRenderTargetContext* fRenderTargetContext;
     GrTexture* fTextures[2];
 
diff --git a/src/core/SkArenaAlloc.cpp b/src/core/SkArenaAlloc.cpp
index 787c5ca..90b7037 100644
--- a/src/core/SkArenaAlloc.cpp
+++ b/src/core/SkArenaAlloc.cpp
@@ -23,8 +23,8 @@
         Footer footer;
         memcpy(&footer, footerEnd - sizeof(Footer), sizeof(Footer));
 
-        FooterAction* action = (FooterAction*)((char*)end_chain + (footer >> 5));
-        ptrdiff_t padding = footer & 31;
+        FooterAction* action = (FooterAction*)(footer >> 6);
+        ptrdiff_t padding = footer & 63;
 
         footerEnd = action(footerEnd) - padding;
     }
@@ -65,27 +65,22 @@
     new (this) SkArenaAlloc{fFirstBlock, fFirstSize, fExtraSize};
 }
 
-void SkArenaAlloc::installFooter(FooterAction* releaser, ptrdiff_t padding) {
-    ptrdiff_t releaserDiff = (char *)releaser - (char *)end_chain;
-    ptrdiff_t footerData = SkLeftShift((int64_t)releaserDiff, 5) | padding;
-    if (padding >= 32 || !SkTFitsIn<Footer>(footerData)) {
-        // Footer data will not fit.
-        SkFAIL("Constraints are busted.");
-    }
-
-    Footer footer = (Footer)(footerData);
-    memmove(fCursor, &footer, sizeof(Footer));
+void SkArenaAlloc::installFooter(FooterAction* action, uint32_t padding) {
+    SkASSERT(padding < 64);
+    int64_t actionInt = (int64_t)(intptr_t)action;
+    Footer encodedFooter = (actionInt << 6) | padding;
+    memmove(fCursor, &encodedFooter, sizeof(Footer));
     fCursor += sizeof(Footer);
     fDtorCursor = fCursor;
 }
 
-void SkArenaAlloc::installPtrFooter(FooterAction* action, char* ptr, ptrdiff_t padding) {
+void SkArenaAlloc::installPtrFooter(FooterAction* action, char* ptr, uint32_t padding) {
     memmove(fCursor, &ptr, sizeof(char*));
     fCursor += sizeof(char*);
     this->installFooter(action, padding);
 }
 
-void SkArenaAlloc::installUint32Footer(FooterAction* action, uint32_t value, ptrdiff_t padding) {
+void SkArenaAlloc::installUint32Footer(FooterAction* action, uint32_t value, uint32_t padding) {
     memmove(fCursor, &value, sizeof(uint32_t));
     fCursor += sizeof(uint32_t);
     this->installFooter(action, padding);
diff --git a/src/core/SkArenaAlloc.h b/src/core/SkArenaAlloc.h
index e53ea99..b2e81e2 100644
--- a/src/core/SkArenaAlloc.h
+++ b/src/core/SkArenaAlloc.h
@@ -68,6 +68,7 @@
 
     template <typename T, typename... Args>
     T* make(Args&&... args) {
+
         SkASSERT(SkTFitsIn<uint32_t>(sizeof(T)));
         char* objStart;
         if (skstd::is_trivially_destructible<T>::value) {
@@ -75,7 +76,8 @@
             fCursor = objStart + sizeof(T);
         } else {
             objStart = this->allocObjectWithFooter(sizeof(T) + sizeof(Footer), alignof(T));
-            size_t padding = objStart - fCursor;
+            // Can never be UB because max value is alignof(T).
+            uint32_t padding = SkTo<uint32_t>(objStart - fCursor);
 
             // Advance to end of object to install footer.
             fCursor = objStart + sizeof(T);
@@ -125,9 +127,9 @@
     static void RunDtorsOnBlock(char* footerEnd);
     static char* NextBlock(char* footerEnd);
 
-    void installFooter(FooterAction* releaser, ptrdiff_t padding);
-    void installUint32Footer(FooterAction* action, uint32_t value, ptrdiff_t padding);
-    void installPtrFooter(FooterAction* action, char* ptr, ptrdiff_t padding);
+    void installFooter(FooterAction* releaser, uint32_t padding);
+    void installUint32Footer(FooterAction* action, uint32_t value, uint32_t padding);
+    void installPtrFooter(FooterAction* action, char* ptr, uint32_t padding);
 
     void ensureSpace(size_t size, size_t alignment);
 
@@ -148,7 +150,9 @@
         } else {
             size_t totalSize = arraySize + sizeof(Footer) + sizeof(uint32_t);
             objStart = this->allocObjectWithFooter(totalSize, alignof(T));
-            size_t padding = objStart - fCursor;
+
+            // Can never be UB because max value is alignof(T).
+            uint32_t padding = SkTo<uint32_t>(objStart - fCursor);
 
             // Advance to end of array to install footer.?
             fCursor = objStart + arraySize;
diff --git a/src/gpu/effects/GrBezierEffect.cpp b/src/gpu/effects/GrBezierEffect.cpp
index cb0e0c5..834b11d 100644
--- a/src/gpu/effects/GrBezierEffect.cpp
+++ b/src/gpu/effects/GrBezierEffect.cpp
@@ -6,7 +6,7 @@
  */
 
 #include "GrBezierEffect.h"
-
+#include "GrContext.h"
 #include "GrShaderCaps.h"
 #include "glsl/GrGLSLFragmentShaderBuilder.h"
 #include "glsl/GrGLSLGeometryProcessor.h"
@@ -265,8 +265,8 @@
                 static_cast<GrPrimitiveEdgeType>(
                         d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt));
         gp = GrConicEffect::Make(GrRandomColor(d->fRandom), GrTest::TestMatrix(d->fRandom),
-                                 edgeType, *d->fCaps,
-                                 GrTest::TestMatrix(d->fRandom), d->fRandom->nextBool());
+                                 edgeType, *d->fContext->caps(), GrTest::TestMatrix(d->fRandom),
+                                 d->fRandom->nextBool());
     } while (nullptr == gp);
     return gp;
 }
@@ -464,10 +464,8 @@
     do {
         GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(
                 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt));
-        gp = GrQuadEffect::Make(GrRandomColor(d->fRandom),
-                                GrTest::TestMatrix(d->fRandom),
-                                edgeType, *d->fCaps,
-                                GrTest::TestMatrix(d->fRandom),
+        gp = GrQuadEffect::Make(GrRandomColor(d->fRandom), GrTest::TestMatrix(d->fRandom), edgeType,
+                                *d->fContext->caps(), GrTest::TestMatrix(d->fRandom),
                                 d->fRandom->nextBool());
     } while (nullptr == gp);
     return gp;
@@ -687,8 +685,8 @@
         GrPrimitiveEdgeType edgeType =
                 static_cast<GrPrimitiveEdgeType>(
                         d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt));
-        gp = GrCubicEffect::Make(GrRandomColor(d->fRandom),
-                                 GrTest::TestMatrix(d->fRandom), edgeType, *d->fCaps);
+        gp = GrCubicEffect::Make(GrRandomColor(d->fRandom), GrTest::TestMatrix(d->fRandom),
+                                 edgeType, *d->fContext->caps());
     } while (nullptr == gp);
     return gp;
 }
diff --git a/src/gpu/ops/GrAAConvexPathRenderer.cpp b/src/gpu/ops/GrAAConvexPathRenderer.cpp
index e845e5e..a279a8c 100644
--- a/src/gpu/ops/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/ops/GrAAConvexPathRenderer.cpp
@@ -656,10 +656,11 @@
 
 sk_sp<GrGeometryProcessor> QuadEdgeEffect::TestCreate(GrProcessorTestData* d) {
     // Doesn't work without derivative instructions.
-    return d->fCaps->shaderCaps()->shaderDerivativeSupport() ?
-           QuadEdgeEffect::Make(GrRandomColor(d->fRandom),
-                                GrTest::TestMatrix(d->fRandom),
-                                d->fRandom->nextBool()) : nullptr;
+    return d->fContext->caps()->shaderCaps()->shaderDerivativeSupport()
+                   ? QuadEdgeEffect::Make(GrRandomColor(d->fRandom),
+                                          GrTest::TestMatrix(d->fRandom),
+                                          d->fRandom->nextBool())
+                   : nullptr;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index 2ac57ff..b9f31e6 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -327,8 +327,7 @@
         std::unique_ptr<GrDrawOp> op(GrRandomDrawOp(&random, context));
         SkASSERT(op);
 
-        GrProcessorTestData ptd(&random, context, context->caps(),
-                                renderTargetContext.get(), dummyTextures);
+        GrProcessorTestData ptd(&random, context, renderTargetContext.get(), dummyTextures);
         set_random_color_coverage_stages(&grPaint, &ptd, maxStages);
         set_random_xpf(&grPaint, &ptd);
         bool snapToCenters = set_random_state(&grPaint, &random);
@@ -362,8 +361,7 @@
         for (int j = 0; j < 10; ++j) {
             std::unique_ptr<GrDrawOp> op(GrRandomDrawOp(&random, context));
             SkASSERT(op);
-            GrProcessorTestData ptd(&random, context, context->caps(),
-                                    renderTargetContext.get(), dummyTextures);
+            GrProcessorTestData ptd(&random, context, renderTargetContext.get(), dummyTextures);
             GrPaint grPaint;
             grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc));