Add ContextRec param to SkShader::contextSize()

To facilitate upcoming context selection changes.

R=reed@google.com,mtklein@google.com,herb@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1720933002

Review URL: https://codereview.chromium.org/1720933002
diff --git a/bench/SkLinearBitmapPipelineBench.cpp b/bench/SkLinearBitmapPipelineBench.cpp
index 0fc2ac6..8a4ba2c 100644
--- a/bench/SkLinearBitmapPipelineBench.cpp
+++ b/bench/SkLinearBitmapPipelineBench.cpp
@@ -196,10 +196,9 @@
         SkAutoTMalloc<SkPMColor> buffer4b(width*height);
 
         uint32_t storage[200];
-        SkASSERT(fPaint.getShader()->contextSize() <= sizeof(storage));
-        SkShader::Context* ctx = fPaint.getShader()->createContext(
-            {fPaint, fM, nullptr},
-            storage);
+        const SkShader::ContextRec rec(fPaint, fM, nullptr);
+        SkASSERT(fPaint.getShader()->contextSize(rec) <= sizeof(storage));
+        SkShader::Context* ctx = fPaint.getShader()->createContext(rec, storage);
 
         int count = 100;
 
diff --git a/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp b/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp
index 73ce1a3..a5a2a21 100644
--- a/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp
+++ b/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.cpp
@@ -571,7 +571,7 @@
     return new (storage) PerlinNoiseShaderContext(*this, rec);
 }
 
-size_t SkPerlinNoiseShader2::contextSize() const {
+size_t SkPerlinNoiseShader2::contextSize(const ContextRec&) const {
     return sizeof(PerlinNoiseShaderContext);
 }
 
diff --git a/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.h b/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.h
index fd93a8d..a129ef8 100644
--- a/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.h
+++ b/experimental/SkPerlinNoiseShader2/SkPerlinNoiseShader2.h
@@ -84,7 +84,7 @@
     }
 
 
-    size_t contextSize() const override;
+    size_t contextSize(const ContextRec&) const override;
 
     class PerlinNoiseShaderContext : public SkShader::Context {
     public:
diff --git a/gm/SkLinearBitmapPipelineGM.cpp b/gm/SkLinearBitmapPipelineGM.cpp
index a446b74..fea0952 100644
--- a/gm/SkLinearBitmapPipelineGM.cpp
+++ b/gm/SkLinearBitmapPipelineGM.cpp
@@ -67,11 +67,10 @@
         paint.setFilterQuality(SkFilterQuality::kNone_SkFilterQuality);
     }
     paint.setShader(shader)->unref();
-    SkASSERT(paint.getShader()->contextSize() <= sizeof(storage));
+    const SkShader::ContextRec rec(paint, *mat, nullptr);
+    SkASSERT(paint.getShader()->contextSize(rec) <= sizeof(storage));
 
-    SkShader::Context* ctx = paint.getShader()->createContext(
-        {paint, *mat, nullptr},
-        storage);
+    SkShader::Context* ctx = paint.getShader()->createContext(rec, storage);
 
     for (int y = 0; y < ir.height(); y++) {
         ctx->shadeSpan(0, y, pmdst.writable_addr32(0, y), ir.width());
diff --git a/include/core/SkShader.h b/include/core/SkShader.h
index 36256f6..8e69faf 100644
--- a/include/core/SkShader.h
+++ b/include/core/SkShader.h
@@ -188,7 +188,7 @@
      *  Override this if your subclass overrides createContext, to return the correct size of
      *  your subclass' context.
      */
-    virtual size_t contextSize() const;
+    virtual size_t contextSize(const ContextRec&) const;
 
     /**
      *  Returns true if this shader is just a bitmap, and if not null, returns the bitmap,
diff --git a/include/effects/SkPerlinNoiseShader.h b/include/effects/SkPerlinNoiseShader.h
index ec7c08c..e9c22d4 100644
--- a/include/effects/SkPerlinNoiseShader.h
+++ b/include/effects/SkPerlinNoiseShader.h
@@ -72,7 +72,7 @@
     }
 
 
-    size_t contextSize() const override;
+    size_t contextSize(const ContextRec&) const override;
 
     class PerlinNoiseShaderContext : public SkShader::Context {
     public:
diff --git a/src/core/SkBitmapProcShader.h b/src/core/SkBitmapProcShader.h
index 2134927..05c5955 100644
--- a/src/core/SkBitmapProcShader.h
+++ b/src/core/SkBitmapProcShader.h
@@ -23,7 +23,7 @@
 
     bool isOpaque() const override;
 
-    size_t contextSize() const override { return ContextSize(); }
+    size_t contextSize(const ContextRec&) const override { return ContextSize(); }
 
     SK_TO_STRING_OVERRIDE()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader)
diff --git a/src/core/SkBlitter.cpp b/src/core/SkBlitter.cpp
index 41d6071..804bc81 100644
--- a/src/core/SkBlitter.cpp
+++ b/src/core/SkBlitter.cpp
@@ -592,10 +592,10 @@
         SkSafeUnref(fProxy);
     }
 
-    size_t contextSize() const override {
+    size_t contextSize(const ContextRec& rec) const override {
         size_t size = sizeof(Sk3DShaderContext);
         if (fProxy) {
-            size += fProxy->contextSize();
+            size += fProxy->contextSize(rec);
         }
         return size;
     }
@@ -876,7 +876,7 @@
     SkShader::Context* shaderContext = nullptr;
     if (shader) {
         SkShader::ContextRec rec(*paint, matrix, nullptr);
-        size_t contextSize = shader->contextSize();
+        size_t contextSize = shader->contextSize(rec);
         if (contextSize) {
             // Try to create the ShaderContext
             void* storage = allocator->reserveT<SkShader::Context>(contextSize);
diff --git a/src/core/SkColorFilterShader.cpp b/src/core/SkColorFilterShader.cpp
index 618bf71..7b421e9 100644
--- a/src/core/SkColorFilterShader.cpp
+++ b/src/core/SkColorFilterShader.cpp
@@ -62,8 +62,8 @@
     return new (storage) FilterShaderContext(*this, shaderContext, rec);
 }
 
-size_t SkColorFilterShader::contextSize() const {
-    return sizeof(FilterShaderContext) + fShader->contextSize();
+size_t SkColorFilterShader::contextSize(const ContextRec& rec) const {
+    return sizeof(FilterShaderContext) + fShader->contextSize(rec);
 }
 
 SkColorFilterShader::FilterShaderContext::FilterShaderContext(
diff --git a/src/core/SkColorFilterShader.h b/src/core/SkColorFilterShader.h
index 55625b6..60c4595 100644
--- a/src/core/SkColorFilterShader.h
+++ b/src/core/SkColorFilterShader.h
@@ -15,7 +15,7 @@
 public:
     SkColorFilterShader(SkShader* shader, SkColorFilter* filter);
     
-    size_t contextSize() const override;
+    size_t contextSize(const ContextRec&) const override;
     
 #if SK_SUPPORT_GPU
     const GrFragmentProcessor* asFragmentProcessor(GrContext*,
diff --git a/src/core/SkColorShader.h b/src/core/SkColorShader.h
index eb55a07..6e4e42a 100644
--- a/src/core/SkColorShader.h
+++ b/src/core/SkColorShader.h
@@ -26,7 +26,7 @@
 
     bool isOpaque() const override;
 
-    size_t contextSize() const override {
+    size_t contextSize(const ContextRec&) const override {
         return sizeof(ColorShaderContext);
     }
 
diff --git a/src/core/SkComposeShader.cpp b/src/core/SkComposeShader.cpp
index 9e5e2c6..46ff401 100644
--- a/src/core/SkComposeShader.cpp
+++ b/src/core/SkComposeShader.cpp
@@ -30,8 +30,10 @@
     fShaderA->unref();
 }
 
-size_t SkComposeShader::contextSize() const {
-    return sizeof(ComposeShaderContext) + fShaderA->contextSize() + fShaderB->contextSize();
+size_t SkComposeShader::contextSize(const ContextRec& rec) const {
+    return sizeof(ComposeShaderContext)
+        + fShaderA->contextSize(rec)
+        + fShaderB->contextSize(rec);
 }
 
 class SkAutoAlphaRestore {
@@ -75,7 +77,7 @@
 
 SkShader::Context* SkComposeShader::onCreateContext(const ContextRec& rec, void* storage) const {
     char* aStorage = (char*) storage + sizeof(ComposeShaderContext);
-    char* bStorage = aStorage + fShaderA->contextSize();
+    char* bStorage = aStorage + fShaderA->contextSize(rec);
 
     // we preconcat our localMatrix (if any) with the device matrix
     // before calling our sub-shaders
diff --git a/src/core/SkComposeShader.h b/src/core/SkComposeShader.h
index bc9d932..6f6aa59 100644
--- a/src/core/SkComposeShader.h
+++ b/src/core/SkComposeShader.h
@@ -34,7 +34,7 @@
     SkComposeShader(SkShader* sA, SkShader* sB, SkXfermode* mode = NULL);
     virtual ~SkComposeShader();
 
-    size_t contextSize() const override;
+    size_t contextSize(const ContextRec&) const override;
 
 #if SK_SUPPORT_GPU
     const GrFragmentProcessor*  asFragmentProcessor(GrContext*,
diff --git a/src/core/SkDraw.cpp b/src/core/SkDraw.cpp
index d07bcb8..d42a179 100644
--- a/src/core/SkDraw.cpp
+++ b/src/core/SkDraw.cpp
@@ -1697,7 +1697,7 @@
 public:
     SkTriColorShader() {}
 
-    size_t contextSize() const override;
+    size_t contextSize(const ContextRec&) const override;
 
     class TriColorShaderContext : public SkShader::Context {
     public:
@@ -1771,7 +1771,7 @@
 
 SkTriColorShader::TriColorShaderContext::~TriColorShaderContext() {}
 
-size_t SkTriColorShader::contextSize() const {
+size_t SkTriColorShader::contextSize(const ContextRec&) const {
     return sizeof(TriColorShaderContext);
 }
 void SkTriColorShader::TriColorShaderContext::shadeSpan(int x, int y, SkPMColor dstC[], int count) {
diff --git a/src/core/SkEmptyShader.h b/src/core/SkEmptyShader.h
index 6453e0e..c1713d1 100644
--- a/src/core/SkEmptyShader.h
+++ b/src/core/SkEmptyShader.h
@@ -20,7 +20,7 @@
 public:
     SkEmptyShader() {}
 
-    size_t contextSize() const override {
+    size_t contextSize(const ContextRec&) const override {
         // Even though createContext returns nullptr we have to return a value of at least
         // sizeof(SkShader::Context) to satisfy SkSmallAllocator.
         return sizeof(SkShader::Context);
diff --git a/src/core/SkLightingShader.cpp b/src/core/SkLightingShader.cpp
index a68553e..9d6c586 100644
--- a/src/core/SkLightingShader.cpp
+++ b/src/core/SkLightingShader.cpp
@@ -79,7 +79,7 @@
                                                    SkFilterQuality) const override;
 #endif
 
-    size_t contextSize() const override;
+    size_t contextSize(const ContextRec&) const override;
 
     class LightingShaderContext : public SkShader::Context {
     public:
@@ -416,7 +416,7 @@
     return fDiffuseMap.isOpaque();
 }
 
-size_t SkLightingShaderImpl::contextSize() const {
+size_t SkLightingShaderImpl::contextSize(const ContextRec&) const {
     return 2 * sizeof(SkBitmapProcState) + sizeof(LightingShaderContext);
 }
 
diff --git a/src/core/SkLocalMatrixShader.h b/src/core/SkLocalMatrixShader.h
index 6265427..d897d49 100644
--- a/src/core/SkLocalMatrixShader.h
+++ b/src/core/SkLocalMatrixShader.h
@@ -19,8 +19,8 @@
     , fProxyShader(SkRef(proxy))
     {}
 
-    size_t contextSize() const override {
-        return fProxyShader->contextSize();
+    size_t contextSize(const ContextRec& rec) const override {
+        return fProxyShader->contextSize(rec);
     }
 
     GradientType asAGradient(GradientInfo* info) const override {
diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp
index 44f6ef1..8f6d43f 100644
--- a/src/core/SkPictureShader.cpp
+++ b/src/core/SkPictureShader.cpp
@@ -237,7 +237,7 @@
     return tileShader.detach();
 }
 
-size_t SkPictureShader::contextSize() const {
+size_t SkPictureShader::contextSize(const ContextRec&) const {
     return sizeof(PictureShaderContext);
 }
 
@@ -266,7 +266,7 @@
     : INHERITED(shader, rec)
     , fBitmapShader(SkRef(bitmapShader))
 {
-    fBitmapShaderContextStorage = sk_malloc_throw(bitmapShader->contextSize());
+    fBitmapShaderContextStorage = sk_malloc_throw(bitmapShader->contextSize(rec));
     fBitmapShaderContext = bitmapShader->createContext(rec, fBitmapShaderContextStorage);
     //if fBitmapShaderContext is null, we are invalid
 }
diff --git a/src/core/SkPictureShader.h b/src/core/SkPictureShader.h
index 02fc87f..c7a6a44 100644
--- a/src/core/SkPictureShader.h
+++ b/src/core/SkPictureShader.h
@@ -25,7 +25,7 @@
     static SkShader* Create(const SkPicture*, TileMode, TileMode, const SkMatrix*,
                                    const SkRect*);
 
-    size_t contextSize() const override;
+    size_t contextSize(const ContextRec&) const override;
 
     SK_TO_STRING_OVERRIDE()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader)
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp
index 20402a9..9d0af03 100644
--- a/src/core/SkShader.cpp
+++ b/src/core/SkShader.cpp
@@ -96,7 +96,7 @@
     return nullptr;
 }
 
-size_t SkShader::contextSize() const {
+size_t SkShader::contextSize(const ContextRec&) const {
     return 0;
 }
 
diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp
index 07917c3..ed7340c 100644
--- a/src/effects/SkPerlinNoiseShader.cpp
+++ b/src/effects/SkPerlinNoiseShader.cpp
@@ -434,7 +434,7 @@
     return new (storage) PerlinNoiseShaderContext(*this, rec);
 }
 
-size_t SkPerlinNoiseShader::contextSize() const {
+size_t SkPerlinNoiseShader::contextSize(const ContextRec&) const {
     return sizeof(PerlinNoiseShaderContext);
 }
 
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp
index 9a350b8..1fbd96e 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -81,7 +81,7 @@
     buffer.writePoint(fEnd);
 }
 
-size_t SkLinearGradient::contextSize() const {
+size_t SkLinearGradient::contextSize(const ContextRec&) const {
     return use_4f_context(fGradFlags)
         ? sizeof(LinearGradient4fContext)
         : sizeof(LinearGradientContext);
diff --git a/src/effects/gradients/SkLinearGradient.h b/src/effects/gradients/SkLinearGradient.h
index c81eea6..33ddfc2 100644
--- a/src/effects/gradients/SkLinearGradient.h
+++ b/src/effects/gradients/SkLinearGradient.h
@@ -33,7 +33,7 @@
 
     SkLinearGradient(const SkPoint pts[2], const Descriptor&);
 
-    size_t contextSize() const override;
+    size_t contextSize(const ContextRec&) const override;
 
     class LinearGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
     public:
diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp
index 020c25e..466ae04 100644
--- a/src/effects/gradients/SkRadialGradient.cpp
+++ b/src/effects/gradients/SkRadialGradient.cpp
@@ -40,7 +40,7 @@
     , fRadius(radius) {
 }
 
-size_t SkRadialGradient::contextSize() const {
+size_t SkRadialGradient::contextSize(const ContextRec&) const {
     return sizeof(RadialGradientContext);
 }
 
diff --git a/src/effects/gradients/SkRadialGradient.h b/src/effects/gradients/SkRadialGradient.h
index bd6fb35..9d98f18 100644
--- a/src/effects/gradients/SkRadialGradient.h
+++ b/src/effects/gradients/SkRadialGradient.h
@@ -15,7 +15,7 @@
 public:
     SkRadialGradient(const SkPoint& center, SkScalar radius, const Descriptor&);
 
-    size_t contextSize() const override;
+    size_t contextSize(const ContextRec&) const override;
 
     class RadialGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
     public:
diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index 9468652..de80c79 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -45,7 +45,7 @@
     buffer.writePoint(fCenter);
 }
 
-size_t SkSweepGradient::contextSize() const {
+size_t SkSweepGradient::contextSize(const ContextRec&) const {
     return sizeof(SweepGradientContext);
 }
 
diff --git a/src/effects/gradients/SkSweepGradient.h b/src/effects/gradients/SkSweepGradient.h
index a6a0971..ec6df45 100644
--- a/src/effects/gradients/SkSweepGradient.h
+++ b/src/effects/gradients/SkSweepGradient.h
@@ -15,7 +15,7 @@
 public:
     SkSweepGradient(SkScalar cx, SkScalar cy, const Descriptor&);
 
-    size_t contextSize() const override;
+    size_t contextSize(const ContextRec&) const override;
 
     class SweepGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
     public:
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp
index b7c95bc..b938ebd 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient.cpp
+++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp
@@ -211,7 +211,7 @@
     return false;
 }
 
-size_t SkTwoPointConicalGradient::contextSize() const {
+size_t SkTwoPointConicalGradient::contextSize(const ContextRec&) const {
     return sizeof(TwoPointConicalGradientContext);
 }
 
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.h b/src/effects/gradients/SkTwoPointConicalGradient.h
index 117e6e9..f468de8 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient.h
+++ b/src/effects/gradients/SkTwoPointConicalGradient.h
@@ -45,7 +45,7 @@
                               bool flippedGrad, const Descriptor&);
 
 
-    size_t contextSize() const override;
+    size_t contextSize(const ContextRec&) const override;
 
     class TwoPointConicalGradientContext : public SkGradientShaderBase::GradientShaderBaseContext {
     public:
diff --git a/src/image/SkImageShader.cpp b/src/image/SkImageShader.cpp
index 22189fa..1c4d422 100644
--- a/src/image/SkImageShader.cpp
+++ b/src/image/SkImageShader.cpp
@@ -42,7 +42,7 @@
     return fImage->isOpaque();
 }
 
-size_t SkImageShader::contextSize() const {
+size_t SkImageShader::contextSize(const ContextRec&) const {
     return SkBitmapProcShader::ContextSize();
 }
 
diff --git a/src/image/SkImageShader.h b/src/image/SkImageShader.h
index e209b35..d51dc5d 100644
--- a/src/image/SkImageShader.h
+++ b/src/image/SkImageShader.h
@@ -16,7 +16,7 @@
     static SkShader* Create(const SkImage*, TileMode tx, TileMode ty, const SkMatrix* localMatrix);
 
     bool isOpaque() const override;
-    size_t contextSize() const override;
+    size_t contextSize(const ContextRec&) const override;
 
     SK_TO_STRING_OVERRIDE()
     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkImageShader)
diff --git a/tests/SkColor4fTest.cpp b/tests/SkColor4fTest.cpp
index 5700e4b..97ae5e3 100644
--- a/tests/SkColor4fTest.cpp
+++ b/tests/SkColor4fTest.cpp
@@ -148,9 +148,9 @@
     for (const auto& rec : recs) {
         uint32_t storage[200];
         paint.setShader(rec.fFact())->unref();
-        SkASSERT(paint.getShader()->contextSize() <= sizeof(storage));
-        SkShader::Context* ctx = paint.getShader()->createContext({paint, SkMatrix::I(), nullptr},
-                                                                  storage);
+        const SkShader::ContextRec contextRec(paint, SkMatrix::I(), nullptr);
+        SkASSERT(paint.getShader()->contextSize(contextRec) <= sizeof(storage));
+        SkShader::Context* ctx = paint.getShader()->createContext(contextRec, storage);
         REPORTER_ASSERT(reporter, ctx->supports4f() == rec.fSupports4f);
         if (ctx->supports4f()) {
             const int N = 100;