Add direct getter for GrCaps to GrContext.

TBR=joshualitt@google.com

Committed: https://skia.googlesource.com/skia/+/9138c46e572085870638b6f7ad7fcdfcdf3cac99

Review URL: https://codereview.chromium.org/1149773005
diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp
index 501d515..bbac9ed 100644
--- a/src/core/SkPictureShader.cpp
+++ b/src/core/SkPictureShader.cpp
@@ -17,6 +17,7 @@
 
 #if SK_SUPPORT_GPU
 #include "GrContext.h"
+#include "GrCaps.h"
 #endif
 
 namespace {
@@ -345,7 +346,7 @@
                                           GrFragmentProcessor** fp) const {
     int maxTextureSize = 0;
     if (context) {
-        maxTextureSize = context->getMaxTextureSize();
+        maxTextureSize = context->caps()->maxTextureSize();
     }
     SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(viewM, localMatrix, maxTextureSize));
     if (!bitmapShader) {
diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp
index 395408c..fe8887f 100644
--- a/src/effects/SkAlphaThresholdFilter.cpp
+++ b/src/effects/SkAlphaThresholdFilter.cpp
@@ -271,7 +271,7 @@
     if (fp) {
         GrContext* context = texture->getContext();
         GrSurfaceDesc maskDesc;
-        if (context->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
+        if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
             maskDesc.fConfig = kAlpha_8_GrPixelConfig;
         } else {
             maskDesc.fConfig = kRGBA_8888_GrPixelConfig;
diff --git a/src/effects/SkGpuBlurUtils.cpp b/src/effects/SkGpuBlurUtils.cpp
index 4997afe..ad268d6 100644
--- a/src/effects/SkGpuBlurUtils.cpp
+++ b/src/effects/SkGpuBlurUtils.cpp
@@ -13,6 +13,7 @@
 #include "effects/GrConvolutionEffect.h"
 #include "effects/GrMatrixConvolutionEffect.h"
 #include "GrContext.h"
+#include "GrCaps.h"
 #include "GrDrawContext.h"
 #endif
 
@@ -154,7 +155,7 @@
     SkIRect clearRect;
     int scaleFactorX, radiusX;
     int scaleFactorY, radiusY;
-    int maxTextureSize = context->getMaxTextureSize();
+    int maxTextureSize = context->caps()->maxTextureSize();
     sigmaX = adjust_sigma(sigmaX, maxTextureSize, &scaleFactorX, &radiusX);
     sigmaY = adjust_sigma(sigmaY, maxTextureSize, &scaleFactorY, &radiusY);
 
diff --git a/src/gpu/GrAddPathRenderers_default.cpp b/src/gpu/GrAddPathRenderers_default.cpp
index bc39b49..351b8eb 100644
--- a/src/gpu/GrAddPathRenderers_default.cpp
+++ b/src/gpu/GrAddPathRenderers_default.cpp
@@ -21,10 +21,10 @@
 #endif
 
 void GrPathRenderer::AddPathRenderers(GrContext* ctx, GrPathRendererChain* chain) {
-    chain->addPathRenderer(SkNEW_ARGS(GrDashLinePathRenderer, (ctx)))->unref();
+    chain->addPathRenderer(SkNEW(GrDashLinePathRenderer))->unref();
 
     if (GrPathRenderer* pr = GrStencilAndCoverPathRenderer::Create(ctx->resourceProvider(),
-                                                                   *ctx->getGpu()->caps())) {
+                                                                   *ctx->caps())) {
         chain->addPathRenderer(pr)->unref();
     }
 #if GR_TESSELLATING_PATH_RENDERING
diff --git a/src/gpu/GrAtlasTextContext.cpp b/src/gpu/GrAtlasTextContext.cpp
index 1d2cc4c..1006d4e 100644
--- a/src/gpu/GrAtlasTextContext.cpp
+++ b/src/gpu/GrAtlasTextContext.cpp
@@ -460,7 +460,7 @@
     // rasterizers and mask filters modify alpha, which doesn't
     // translate well to distance
     if (skPaint.getRasterizer() || skPaint.getMaskFilter() ||
-        !fContext->shaderDerivativeSupport()) {
+        !fContext->caps()->shaderCaps()->shaderDerivativeSupport()) {
         return false;
     }
 
diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp
index a757a4a..66861ec 100644
--- a/src/gpu/GrBlurUtils.cpp
+++ b/src/gpu/GrBlurUtils.cpp
@@ -7,6 +7,7 @@
 
 #include "GrBlurUtils.h"
 #include "GrDrawContext.h"
+#include "GrCaps.h"
 #include "GrContext.h"
 #include "effects/GrSimpleTextureEffect.h"
 #include "GrStrokeInfo.h"
@@ -110,7 +111,7 @@
     // render target so default to RGBA_8888
     desc.fConfig = kRGBA_8888_GrPixelConfig;
 
-    if (context->isConfigRenderable(kAlpha_8_GrPixelConfig, desc.fSampleCnt > 0)) {
+    if (context->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, desc.fSampleCnt > 0)) {
         desc.fConfig = kAlpha_8_GrPixelConfig;
     }
 
diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp
index 9279ba5..f8e045b 100644
--- a/src/gpu/GrClipMaskManager.cpp
+++ b/src/gpu/GrClipMaskManager.cpp
@@ -489,7 +489,7 @@
     desc.fFlags = kRenderTarget_GrSurfaceFlag;
     desc.fWidth = width;
     desc.fHeight = height;
-    if (this->getContext()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
+    if (this->getContext()->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
         desc.fConfig = kAlpha_8_GrPixelConfig;
     } else {
         desc.fConfig = kRGBA_8888_GrPixelConfig;
@@ -526,7 +526,8 @@
     desc.fWidth = clipSpaceIBounds.width();
     desc.fHeight = clipSpaceIBounds.height();
     desc.fConfig = kRGBA_8888_GrPixelConfig;
-    if (willUpload || this->getContext()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
+    if (willUpload ||
+        this->getContext()->caps()->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
         // We would always like A8 but it isn't supported on all platforms
         desc.fConfig = kAlpha_8_GrPixelConfig;
     }
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 5baf722..ca98ffb 100755
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -138,6 +138,7 @@
 
 GrContext::GrContext() : fUniqueID(next_id()) {
     fGpu = NULL;
+    fCaps = NULL;
     fResourceCache = NULL;
     fResourceProvider = NULL;
     fPathRendererChain = NULL;
@@ -159,6 +160,7 @@
 }
 
 void GrContext::initCommon() {
+    fCaps = SkRef(fGpu->caps());
     fResourceCache = SkNEW(GrResourceCache);
     fResourceCache->setOverBudgetCallback(OverBudgetCB, this);
     fResourceProvider = SkNEW_ARGS(GrResourceProvider, (fGpu, fResourceCache));
@@ -177,6 +179,7 @@
 
 GrContext::~GrContext() {
     if (!fGpu) {
+        SkASSERT(!fCaps);
         return;
     }
 
@@ -191,6 +194,7 @@
     SkDELETE(fBatchFontCache);
 
     fGpu->unref();
+    fCaps->unref();
     SkSafeUnref(fPathRendererChain);
     SkSafeUnref(fSoftwarePathRenderer);
 }
@@ -258,18 +262,6 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 
-bool GrContext::shaderDerivativeSupport() const {
-    return fGpu->caps()->shaderCaps()->shaderDerivativeSupport();
-}
-
-bool GrContext::isConfigTexturable(GrPixelConfig config) const {
-    return fGpu->caps()->isConfigTexturable(config);
-}
-
-bool GrContext::npotTextureTileSupport() const {
-    return fGpu->caps()->npotTextureTileSupport();
-}
-
 void GrContext::OverBudgetCB(void* data) {
     SkASSERT(data);
 
@@ -290,18 +282,6 @@
     context->flush();
 }
 
-int GrContext::getMaxTextureSize() const {
-    return fGpu->caps()->maxTextureSize();
-}
-
-int GrContext::getMaxRenderTargetSize() const {
-    return fGpu->caps()->maxRenderTargetSize();
-}
-
-int GrContext::getMaxSampleCount() const {
-    return fGpu->caps()->maxSampleCount();
-}
-
 ////////////////////////////////////////////////////////////////////////////////
 
 void GrContext::flush(int flagsBitfield) {
@@ -687,13 +667,9 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-bool GrContext::isConfigRenderable(GrPixelConfig config, bool withMSAA) const {
-    return fGpu->caps()->isConfigRenderable(config, withMSAA);
-}
-
 int GrContext::getRecommendedSampleCount(GrPixelConfig config,
                                          SkScalar dpi) const {
-    if (!this->isConfigRenderable(config, true)) {
+    if (!this->caps()->isConfigRenderable(config, true)) {
         return 0;
     }
     int chosenSampleCount = 0;
diff --git a/src/gpu/GrCoordTransform.cpp b/src/gpu/GrCoordTransform.cpp
index 596a94b..e7d9b1e 100644
--- a/src/gpu/GrCoordTransform.cpp
+++ b/src/gpu/GrCoordTransform.cpp
@@ -27,7 +27,7 @@
     int subPixelThresh = filter > GrTextureParams::kNone_FilterMode ? 4 : 1;
     fPrecision = kDefault_GrSLPrecision;
     if (texture->getContext()) {
-        const GrShaderCaps* caps = texture->getContext()->getGpu()->caps()->shaderCaps();
+        const GrShaderCaps* caps = texture->getContext()->caps()->shaderCaps();
         if (caps->floatPrecisionVaries()) {
             int maxD = SkTMax(texture->width(), texture->height());
             const GrShaderCaps::PrecisionInfo* info;
diff --git a/src/gpu/GrDashLinePathRenderer.cpp b/src/gpu/GrDashLinePathRenderer.cpp
index 67dc6c7..c27e61b 100644
--- a/src/gpu/GrDashLinePathRenderer.cpp
+++ b/src/gpu/GrDashLinePathRenderer.cpp
@@ -10,13 +10,6 @@
 #include "GrGpu.h"
 #include "effects/GrDashingEffect.h"
 
-GrDashLinePathRenderer::GrDashLinePathRenderer(GrContext* context)
-        : fGpu(SkRef(context->getGpu())) {
-}
-
-GrDashLinePathRenderer::~GrDashLinePathRenderer() {
-}
-
 bool GrDashLinePathRenderer::canDrawPath(const GrDrawTarget* target,
                                          const GrPipelineBuilder* pipelineBuilder,
                                          const SkMatrix& viewMatrix,
diff --git a/src/gpu/GrDashLinePathRenderer.h b/src/gpu/GrDashLinePathRenderer.h
index 632f30a..09dc7ee 100644
--- a/src/gpu/GrDashLinePathRenderer.h
+++ b/src/gpu/GrDashLinePathRenderer.h
@@ -13,9 +13,6 @@
 
 class GrDashLinePathRenderer : public GrPathRenderer {
 public:
-    GrDashLinePathRenderer(GrContext*);
-    ~GrDashLinePathRenderer();
-
     bool canDrawPath(const GrDrawTarget*,
                      const GrPipelineBuilder*,
                      const SkMatrix& viewMatrix,
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 7d5a4f9..a2c824b 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -32,7 +32,7 @@
 
 GrDrawTarget::GrDrawTarget(GrContext* context)
     : fContext(context)
-    , fCaps(SkRef(context->getGpu()->caps()))
+    , fCaps(SkRef(context->caps()))
     , fGpuTraceMarkerCount(0)
     , fFlushing(false) {
     SkASSERT(context);
diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp
index 10633fc..491e5cf 100644
--- a/src/gpu/GrInOrderDrawBuffer.cpp
+++ b/src/gpu/GrInOrderDrawBuffer.cpp
@@ -9,15 +9,14 @@
 
 // We will use the reordering buffer, unless we have NVPR.
 // TODO move NVPR to batch so we can reorder
-static inline bool allow_reordering(const GrGpu* gpu) {
-    //const GrCaps* caps = gpu->caps();
-    //return caps && caps->shaderCaps() && !caps->shaderCaps()->pathRenderingSupport();
+static inline bool allow_reordering(const GrCaps* caps) {
+    //return !caps->shaderCaps()->pathRenderingSupport();
     return false;
 }
 
 GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrContext* context)
     : INHERITED(context)
-    , fCommands(GrCommandBuilder::Create(context->getGpu(), allow_reordering(context->getGpu())))
+    , fCommands(GrCommandBuilder::Create(context->getGpu(), allow_reordering(context->caps())))
     , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4)
     , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4)
     , fPipelineBuffer(kPipelineBufferMinReserve)
diff --git a/src/gpu/GrPathRendererChain.cpp b/src/gpu/GrPathRendererChain.cpp
index bc74e2f..7c68a02 100644
--- a/src/gpu/GrPathRendererChain.cpp
+++ b/src/gpu/GrPathRendererChain.cpp
@@ -78,9 +78,9 @@
 
 void GrPathRendererChain::init() {
     SkASSERT(!fInit);
-    GrGpu* gpu = fOwner->getGpu();
-    bool twoSided = gpu->caps()->twoSidedStencilSupport();
-    bool wrapOp = gpu->caps()->stencilWrapOpsSupport();
+    const GrCaps* caps = fOwner->caps();
+    bool twoSided = caps->twoSidedStencilSupport();
+    bool wrapOp = caps->stencilWrapOpsSupport();
     GrPathRenderer::AddPathRenderers(fOwner, this);
     this->addPathRenderer(SkNEW_ARGS(GrDefaultPathRenderer,
                                      (twoSided, wrapOp)))->unref();
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp
index c978866..cc5fb00 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -174,8 +174,8 @@
                                      resultBounds.height());
 
     if (allowCompression &&
-        fContext->getGpu()->caps()->drawPathMasksToCompressedTexturesSupport() &&
-        choose_compressed_fmt(fContext->getGpu()->caps(), &fCompressedFormat)) {
+        fContext->caps()->drawPathMasksToCompressedTexturesSupport() &&
+        choose_compressed_fmt(fContext->caps(), &fCompressedFormat)) {
         fCompressionMode = kCompress_CompressionMode;
     }
 
@@ -245,7 +245,7 @@
 #endif
 
         desc.fConfig = fmt_to_config(fCompressedFormat);
-        SkASSERT(fContext->getGpu()->caps()->isConfigTexturable(desc.fConfig));
+        SkASSERT(fContext->caps()->isConfigTexturable(desc.fConfig));
     }
 
     return fContext->textureProvider()->refScratchTexture(
@@ -256,7 +256,7 @@
                                      const void *data, size_t rowbytes) {
     // If we aren't reusing scratch textures we don't need to flush before
     // writing since no one else will be using 'texture'
-    bool reuseScratch = fContext->getGpu()->caps()->reuseScratchTextures();
+    bool reuseScratch = fContext->caps()->reuseScratchTextures();
 
     // Since we're uploading to it, and it's compressed, 'texture' shouldn't
     // have a render target.
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 90e53a0..beed2fa 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -910,7 +910,7 @@
     // FIXME: the tiled bitmap code path doesn't currently support
     // anti-aliased edges, we work around that for now by drawing directly
     // if the image size exceeds maximum texture size.
-    int maxTextureSize = fContext->getMaxTextureSize();
+    int maxTextureSize = fContext->caps()->maxTextureSize();
     bool directDraw = fRenderTarget->isMultisampled() ||
                       !paint.isAntiAlias() ||
                       bitmap.width() > maxTextureSize ||
@@ -1034,7 +1034,7 @@
     }
     params.setFilterMode(textureFilterMode);
 
-    int maxTileSize = fContext->getMaxTextureSize() - 2 * tileFilterPad;
+    int maxTileSize = fContext->caps()->maxTextureSize() - 2 * tileFilterPad;
     int tileSize;
 
     SkIRect clippedSrcRect;
@@ -1163,8 +1163,8 @@
                                      SkCanvas::DrawBitmapRectFlags flags,
                                      bool bicubic,
                                      bool needsTextureDomain) {
-    SkASSERT(bitmap.width() <= fContext->getMaxTextureSize() &&
-             bitmap.height() <= fContext->getMaxTextureSize());
+    SkASSERT(bitmap.width() <= fContext->caps()->maxTextureSize() &&
+             bitmap.height() <= fContext->caps()->maxTextureSize());
 
     GrTexture* texture;
     AutoBitmapTexture abt(fContext, bitmap, &params, &texture);
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index decb358..70c81f9 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -7,6 +7,7 @@
 
 #include "SkGr.h"
 
+#include "GrCaps.h"
 #include "GrDrawContext.h"
 #include "GrXferProcessor.h"
 #include "SkColorFilter.h"
@@ -96,7 +97,7 @@
 static Stretch get_stretch_type(const GrContext* ctx, int width, int height,
                                 const GrTextureParams* params) {
     if (params && params->isTiled()) {
-        if (!ctx->npotTextureTileSupport() && (!SkIsPow2(width) || !SkIsPow2(height))) {
+        if (!ctx->caps()->npotTextureTileSupport() && (!SkIsPow2(width) || !SkIsPow2(height))) {
             switch(params->filterMode()) {
                 case GrTextureParams::kNone_FilterMode:
                     return kNearest_Stretch;
@@ -198,6 +199,7 @@
 
     GrContext* context = inputTexture->getContext();
     SkASSERT(context);
+    const GrCaps* caps = context->caps();
 
     // Either it's a cache miss or the original wasn't cached to begin with.
     GrSurfaceDesc rtDesc = inputTexture->desc();
@@ -208,18 +210,18 @@
 
     // If the config isn't renderable try converting to either A8 or an 32 bit config. Otherwise,
     // fail.
-    if (!context->isConfigRenderable(rtDesc.fConfig, false)) {
+    if (!caps->isConfigRenderable(rtDesc.fConfig, false)) {
         if (GrPixelConfigIsAlphaOnly(rtDesc.fConfig)) {
-            if (context->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
+            if (caps->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
                 rtDesc.fConfig = kAlpha_8_GrPixelConfig;
-            } else if (context->isConfigRenderable(kSkia8888_GrPixelConfig, false)) {
+            } else if (caps->isConfigRenderable(kSkia8888_GrPixelConfig, false)) {
                 rtDesc.fConfig = kSkia8888_GrPixelConfig;
             } else {
                 return NULL;
             }
         } else if (kRGB_GrColorComponentFlags ==
                    (kRGB_GrColorComponentFlags & GrPixelConfigComponentMask(rtDesc.fConfig))) {
-            if (context->isConfigRenderable(kSkia8888_GrPixelConfig, false)) {
+            if (caps->isConfigRenderable(kSkia8888_GrPixelConfig, false)) {
                 rtDesc.fConfig = kSkia8888_GrPixelConfig;
             } else {
                 return NULL;
@@ -423,9 +425,10 @@
 
     GrSurfaceDesc desc;
     generate_bitmap_texture_desc(*bitmap, &desc);
+    const GrCaps* caps = ctx->caps();
 
     if (kIndex_8_SkColorType == bitmap->colorType()) {
-        if (ctx->isConfigTexturable(kIndex_8_GrPixelConfig)) {
+        if (caps->isConfigTexturable(kIndex_8_GrPixelConfig)) {
             size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig,
                                                           bitmap->width(), bitmap->height());
             SkAutoMalloc storage(imageSize);
@@ -447,7 +450,7 @@
 #ifndef SK_IGNORE_ETC1_SUPPORT
     // Make sure that the underlying device supports ETC1 textures before we go ahead
     // and check the data.
-    else if (ctx->isConfigTexturable(kETC1_GrPixelConfig)
+    else if (caps->isConfigTexturable(kETC1_GrPixelConfig)
             // If the bitmap had compressed data and was then uncompressed, it'll still return
             // compressed data on 'refEncodedData' and upload it. Probably not good, since if
             // the bitmap has available pixels, then they might not be what the decompressed