Store context options on caps.

Review URL: https://codereview.chromium.org/1158433006
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index f4ca6c4..3ed0b6b 100755
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -15,6 +15,7 @@
 #include "GrBatchTarget.h"
 #include "GrBatchTest.h"
 #include "GrCaps.h"
+#include "GrContextOptions.h"
 #include "GrDefaultGeoProcFactory.h"
 #include "GrGpuResource.h"
 #include "GrGpuResourcePriv.h"
@@ -70,16 +71,16 @@
     GrContext* fContext;
 };
 
-GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext,
-                             const Options* opts) {
-    GrContext* context;
-    if (NULL == opts) {
-        context = SkNEW_ARGS(GrContext, (Options()));
-    } else {
-        context = SkNEW_ARGS(GrContext, (*opts));
-    }
+GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) {
+    GrContextOptions defaultOptions;
+    return Create(backend, backendContext, defaultOptions);
+}
 
-    if (context->init(backend, backendContext)) {
+GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext,
+                             const GrContextOptions& options) {
+    GrContext* context = SkNEW(GrContext);
+
+    if (context->init(backend, backendContext, options)) {
         return context;
     } else {
         context->unref();
@@ -96,7 +97,7 @@
     return id;
 }
 
-GrContext::GrContext(const Options& opts) : fOptions(opts), fUniqueID(next_id()) {
+GrContext::GrContext() : fUniqueID(next_id()) {
     fGpu = NULL;
     fResourceCache = NULL;
     fResourceProvider = NULL;
@@ -110,10 +111,11 @@
     fMaxTextureSizeOverride = 1 << 20;
 }
 
-bool GrContext::init(GrBackend backend, GrBackendContext backendContext) {
+bool GrContext::init(GrBackend backend, GrBackendContext backendContext,
+                     const GrContextOptions& options) {
     SkASSERT(NULL == fGpu);
 
-    fGpu = GrGpu::Create(backend, backendContext, this);
+    fGpu = GrGpu::Create(backend, backendContext, options, this);
     if (NULL == fGpu) {
         return false;
     }
diff --git a/src/gpu/GrContextFactory.cpp b/src/gpu/GrContextFactory.cpp
index 1a3864a..7df1917 100755
--- a/src/gpu/GrContextFactory.cpp
+++ b/src/gpu/GrContextFactory.cpp
@@ -75,7 +75,7 @@
 
     glCtx->makeCurrent();
     GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get());
-    grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, &fGlobalOptions));
+    grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions));
     if (!grCtx.get()) {
         return NULL;
     }
diff --git a/src/gpu/GrContextFactory.h b/src/gpu/GrContextFactory.h
index 353e3d9..7fd4b77 100644
--- a/src/gpu/GrContextFactory.h
+++ b/src/gpu/GrContextFactory.h
@@ -9,6 +9,7 @@
 #define GrContextFactory_DEFINED
 
 #include "GrContext.h"
+#include "GrContextOptions.h"
 
 #include "gl/SkGLContext.h"
 #include "SkTArray.h"
@@ -80,7 +81,7 @@
         }
     }
 
-    explicit GrContextFactory(const GrContext::Options& opts) : fGlobalOptions(opts) { }
+    explicit GrContextFactory(const GrContextOptions& opts) : fGlobalOptions(opts) { }
     GrContextFactory() { }
 
     ~GrContextFactory() { this->destroyContexts(); }
@@ -126,7 +127,7 @@
         return NULL;
     }
 
-    const GrContext::Options& getGlobalOptions() const { return fGlobalOptions; }
+    const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; }
 
 private:
     struct GPUContext {
@@ -135,7 +136,7 @@
         GrContext*                fGrContext;
     };
     SkTArray<GPUContext, true>    fContexts;
-    const GrContext::Options      fGlobalOptions;
+    const GrContextOptions        fGlobalOptions;
 };
 
 #endif
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 2d5d0b8..e5baaa7 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -11,6 +11,7 @@
 #include "GrBatch.h"
 #include "GrCaps.h"
 #include "GrContext.h"
+#include "GrContextOptions.h"
 #include "GrPath.h"
 #include "GrPipeline.h"
 #include "GrMemoryPool.h"
@@ -68,8 +69,8 @@
         drawBounds->roundOut(&drawIBounds);
         if (!copyRect.intersect(drawIBounds)) {
 #ifdef SK_DEBUG
-            GrContextDebugf(fContext, "Missed an early reject. "
-                                      "Bailing on draw from setupDstReadIfNecessary.\n");
+            GrCapsDebugf(fCaps, "Missed an early reject. "
+                         "Bailing on draw from setupDstReadIfNecessary.\n");
 #endif
             return false;
         }
@@ -598,7 +599,7 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-GrCaps::GrCaps() {
+GrCaps::GrCaps(const GrContextOptions& options) {
     fMipMapSupport = false;
     fNPOTTextureTileSupport = false;
     fTwoSidedStencilSupport = false;
@@ -621,6 +622,9 @@
 
     memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport));
     memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport));
+
+    fSupressPrints = options.fSuppressPrints;
+    fDrawPathMasksToCompressedTextureSupport = options.fDrawPathToCompressedTexture;
 }
 
 static SkString map_flags_to_string(uint32_t flags) {
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index 6e8dc43..5b5be1b 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -31,7 +31,7 @@
      * not supported (at compile-time or run-time) this returns NULL. The context will not be
      * fully constructed and should not be used by GrGpu until after this function returns.
      */
-    static GrGpu* Create(GrBackend, GrBackendContext, GrContext* context);
+    static GrGpu* Create(GrBackend, GrBackendContext, const GrContextOptions&, GrContext* context);
 
     ////////////////////////////////////////////////////////////////////////////
 
diff --git a/src/gpu/GrGpuFactory.cpp b/src/gpu/GrGpuFactory.cpp
index bd572e6..3001a0d 100644
--- a/src/gpu/GrGpuFactory.cpp
+++ b/src/gpu/GrGpuFactory.cpp
@@ -20,10 +20,13 @@
     gGpuFactories[i] = proc;
 }
 
-GrGpu* GrGpu::Create(GrBackend backend, GrBackendContext backendContext, GrContext* context) {
+GrGpu* GrGpu::Create(GrBackend backend,
+                     GrBackendContext backendContext,
+                     const GrContextOptions& options,
+                     GrContext* context) {
     SkASSERT((int)backend < kMaxNumBackends);
     if (!gGpuFactories[backend]) {
         return NULL;
     }
-    return (gGpuFactories[backend])(backendContext, context);
+    return (gGpuFactories[backend])(backendContext, options, context);
 }
diff --git a/src/gpu/GrGpuFactory.h b/src/gpu/GrGpuFactory.h
index 180f264..aecc2c1 100644
--- a/src/gpu/GrGpuFactory.h
+++ b/src/gpu/GrGpuFactory.h
@@ -12,8 +12,9 @@
 
 class GrGpu;
 class GrContext;
+struct GrContextOptions;
 
-typedef GrGpu* (*CreateGpuProc)(GrBackendContext, GrContext*);
+typedef GrGpu* (*CreateGpuProc)(GrBackendContext, const GrContextOptions& options, GrContext*);
 
 class GrGpuFactoryRegistrar {
 public:
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp
index aa922ca..2591186 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -174,7 +174,7 @@
                                      resultBounds.height());
 
     if (allowCompression &&
-        fContext->getOptions().fDrawPathToCompressedTexture &&
+        fContext->getGpu()->caps()->drawPathMasksToCompressedTexturesSupport() &&
         choose_compressed_fmt(fContext->getGpu()->caps(), &fCompressedFormat)) {
         fCompressionMode = kCompress_CompressionMode;
     }
diff --git a/src/gpu/GrTest.cpp b/src/gpu/GrTest.cpp
index 0801d03..8580661 100644
--- a/src/gpu/GrTest.cpp
+++ b/src/gpu/GrTest.cpp
@@ -7,6 +7,7 @@
  */
 
 #include "GrTest.h"
+#include "GrContextOptions.h"
 
 #include "GrGpuResourceCacheAccess.h"
 #include "GrInOrderDrawBuffer.h"
@@ -138,7 +139,9 @@
 
 class MockGpu : public GrGpu {
 public:
-    MockGpu(GrContext* context) : INHERITED(context) { fCaps.reset(SkNEW(GrCaps)); }
+    MockGpu(GrContext* context, const GrContextOptions& options) : INHERITED(context) {
+        fCaps.reset(SkNEW_ARGS(GrCaps, (options)));
+    }
     ~MockGpu() override {}
     bool canWriteTexturePixels(const GrTexture*, GrPixelConfig srcConfig) const override {
         return true;
@@ -249,15 +252,16 @@
 };
 
 GrContext* GrContext::CreateMockContext() {
-    GrContext* context = SkNEW_ARGS(GrContext, (Options()));
+    GrContext* context = SkNEW(GrContext);
 
     context->initMockContext();
     return context;
 }
 
 void GrContext::initMockContext() {
+    GrContextOptions options;
     SkASSERT(NULL == fGpu);
-    fGpu = SkNEW_ARGS(MockGpu, (this));
+    fGpu = SkNEW_ARGS(MockGpu, (this, options));
     SkASSERT(fGpu);
     this->initCommon();
 
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 2a97137..6f272b7 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -12,7 +12,9 @@
 #include "SkTSearch.h"
 #include "SkTSort.h"
 
-GrGLCaps::GrGLCaps(const GrGLContextInfo& ctxInfo, const GrGLInterface* glInterface) {
+GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
+                   const GrGLContextInfo& ctxInfo,
+                   const GrGLInterface* glInterface) : INHERITED(contextOptions) {
     fVerifiedColorConfigs.reset();
     fStencilFormats.reset();
     fStencilVerifiedColorConfigs.reset();
diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h
index cd84242..9d38c82 100644
--- a/src/gpu/gl/GrGLCaps.h
+++ b/src/gpu/gl/GrGLCaps.h
@@ -91,7 +91,8 @@
      * Initializes the GrGLCaps to the set of features supported in the current
      * OpenGL context accessible via ctxInfo.
      */
-    GrGLCaps(const GrGLContextInfo& ctxInfo, const GrGLInterface* glInterface);
+    GrGLCaps(const GrContextOptions& contextOptions, const GrGLContextInfo& ctxInfo,
+             const GrGLInterface* glInterface);
 
     /**
      * Call to note that a color config has been verified as a valid color
diff --git a/src/gpu/gl/GrGLContext.cpp b/src/gpu/gl/GrGLContext.cpp
index 8115687..3359865 100644
--- a/src/gpu/gl/GrGLContext.cpp
+++ b/src/gpu/gl/GrGLContext.cpp
@@ -9,7 +9,7 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 
-GrGLContext* GrGLContext::Create(const GrGLInterface* interface) {
+GrGLContext* GrGLContext::Create(const GrGLInterface* interface, const GrContextOptions& options) {
     // We haven't validated the GrGLInterface yet, so check for GetString function pointer
     if (!interface->fFunctions.fGetString) {
         return NULL;
@@ -55,6 +55,9 @@
     args.fIsMesa = GrGLIsMesaFromVersionString(ver);
 
     args.fIsChromium = GrGLIsChromiumFromRendererString(renderer);
+
+    args.fContextOptions = &options;
+
     return SkNEW_ARGS(GrGLContext, (args));
 }
 
@@ -67,5 +70,5 @@
     fIsMesa = args.fIsMesa;
     fIsChromium = args.fIsChromium;
 
-    fGLCaps.reset(SkNEW_ARGS(GrGLCaps, (*this, fInterface)));
+    fGLCaps.reset(SkNEW_ARGS(GrGLCaps, (*args.fContextOptions, *this, fInterface)));
 }
diff --git a/src/gpu/gl/GrGLContext.h b/src/gpu/gl/GrGLContext.h
index e84c8ec..50262cf 100644
--- a/src/gpu/gl/GrGLContext.h
+++ b/src/gpu/gl/GrGLContext.h
@@ -15,7 +15,7 @@
 #include "GrGLSL.h"
 #include "GrGLUtil.h"
 
-#include "SkString.h"
+struct GrContextOptions;
 
 /**
  * Encapsulates information about an OpenGL context including the OpenGL
@@ -51,6 +51,7 @@
         GrGLRenderer                        fRenderer;
         bool                                fIsMesa;
         bool                                fIsChromium;
+        const  GrContextOptions*            fContextOptions;
     };
 
     GrGLContextInfo(const ConstructorArgs& args);
@@ -74,7 +75,7 @@
      * Creates a GrGLContext from a GrGLInterface and the currently
      * bound OpenGL context accessible by the GrGLInterface.
      */
-    static GrGLContext* Create(const GrGLInterface* interface);
+    static GrGLContext* Create(const GrGLInterface* interface, const GrContextOptions& options);
 
     const GrGLInterface* interface() const { return fInterface; }
 
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index 07aaaae..3a3b833 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -157,7 +157,8 @@
 
 ///////////////////////////////////////////////////////////////////////////////
 
-GrGpu* GrGLGpu::Create(GrBackendContext backendContext, GrContext* context) {
+GrGpu* GrGLGpu::Create(GrBackendContext backendContext, const GrContextOptions& options,
+                       GrContext* context) {
     SkAutoTUnref<const GrGLInterface> glInterface(
         reinterpret_cast<const GrGLInterface*>(backendContext));
     if (!glInterface) {
@@ -168,7 +169,7 @@
     if (!glInterface) {
         return NULL;
     }
-    GrGLContext* glContext = GrGLContext::Create(glInterface);
+    GrGLContext* glContext = GrGLContext::Create(glInterface, options);
     if (glContext) {
         return SkNEW_ARGS(GrGLGpu, (glContext, context));
     }
@@ -1436,7 +1437,7 @@
 
     fCurrentProgram.reset(fProgramCache->getProgram(args));
     if (NULL == fCurrentProgram.get()) {
-        GrContextDebugf(this->getContext(), "Failed to create program!\n");
+        GrCapsDebugf(this->caps(), "Failed to create program!\n");
         return false;
     }
 
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index d7b1102..c777f77 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -32,7 +32,8 @@
 
 class GrGLGpu : public GrGpu {
 public:
-    static GrGpu* Create(GrBackendContext backendContext, GrContext* context);
+    static GrGpu* Create(GrBackendContext backendContext, const GrContextOptions& options,
+                         GrContext* context);
     ~GrGLGpu() override;
 
     void contextAbandoned() override;
diff --git a/src/gpu/gl/GrGLProgramDataManager.cpp b/src/gpu/gl/GrGLProgramDataManager.cpp
index ef2f59e..ce2598e 100644
--- a/src/gpu/gl/GrGLProgramDataManager.cpp
+++ b/src/gpu/gl/GrGLProgramDataManager.cpp
@@ -261,7 +261,7 @@
 #ifdef SK_DEBUG
 void GrGLProgramDataManager::printUnused(const Uniform& uni) const {
     if (kUnusedUniform == uni.fFSLocation && kUnusedUniform == uni.fVSLocation) {
-        GrContextDebugf(fGpu->getContext(), "Unused uniform in shader\n");
+        GrCapsDebugf(fGpu->caps(), "Unused uniform in shader\n");
     }
 }
 #endif
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index 28e1fba..a3b0d68 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -207,7 +207,7 @@
 
         totalTextures += processor->numTextures();
         if (totalTextures >= maxTextureUnits) {
-            GrContextDebugf(fGpu->getContext(), "Program would use too many texture units\n");
+            GrCapsDebugf(fGpu->caps(), "Program would use too many texture units\n");
             return false;
         }
     }