Move caps and FP factory cache to GrContext_Base

Both GrContext and GrContextThreadSafeProxy had their own copies. This centralizes ownership and standardizes how all the contexts get initialized.

Change-Id: Ib2e418fbb53fcd6b0054789ef30a5fc4a3d80b20
Reviewed-on: https://skia-review.googlesource.com/c/189305
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrDirectContext.cpp b/src/gpu/GrDirectContext.cpp
index 9fdb3b8..fb2adf6 100644
--- a/src/gpu/GrDirectContext.cpp
+++ b/src/gpu/GrDirectContext.cpp
@@ -10,6 +10,7 @@
 
 #include "GrContextPriv.h"
 #include "GrContextThreadSafeProxy.h"
+#include "GrContextThreadSafeProxyPriv.h"
 #include "GrGpu.h"
 
 #include "effects/GrSkSLFP.h"
@@ -58,23 +59,27 @@
     }
 
 protected:
-    bool init() override {
-        SkASSERT(fCaps);  // should've been set in ctor
+    bool init(sk_sp<const GrCaps> caps, sk_sp<GrSkSLFPFactoryCache> FPFactoryCache) override {
+        SkASSERT(caps && !FPFactoryCache);
         SkASSERT(!fThreadSafeProxy);
-        SkASSERT(!fFPFactoryCache);
-        fFPFactoryCache.reset(new GrSkSLFPFactoryCache());
-        fThreadSafeProxy.reset(new GrContextThreadSafeProxy(fCaps, this->contextID(),
-                                                            this->backend(),
-                                                            this->options(), fFPFactoryCache));
 
-        if (!INHERITED::initCommon()) {
+        FPFactoryCache.reset(new GrSkSLFPFactoryCache());
+        fThreadSafeProxy = GrContextThreadSafeProxyPriv::Make(this->backend(),
+                                                              this->options(),
+                                                              this->contextID(),
+                                                              caps, FPFactoryCache);
+
+        if (!INHERITED::init(std::move(caps), std::move(FPFactoryCache))) {
             return false;
         }
 
+        SkASSERT(this->caps());
+
         GrDrawOpAtlas::AllowMultitexturing allowMultitexturing;
         if (GrContextOptions::Enable::kNo == this->options().fAllowMultipleGlyphCacheTextures ||
             // multitexturing supported only if range can represent the index + texcoords fully
-            !(fCaps->shaderCaps()->floatIs32Bits() || fCaps->shaderCaps()->integerSupport())) {
+            !(this->caps()->shaderCaps()->floatIs32Bits() ||
+              this->caps()->shaderCaps()->integerSupport())) {
             allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kNo;
         } else {
             allowMultitexturing = GrDrawOpAtlas::AllowMultitexturing::kYes;
@@ -122,8 +127,7 @@
         return nullptr;
     }
 
-    context->fCaps = context->fGpu->refCaps();
-    if (!context->init()) {
+    if (!context->init(context->fGpu->refCaps(), nullptr)) {
         return nullptr;
     }
     return context;
@@ -143,8 +147,7 @@
         return nullptr;
     }
 
-    context->fCaps = context->fGpu->refCaps();
-    if (!context->init()) {
+    if (!context->init(context->fGpu->refCaps(), nullptr)) {
         return nullptr;
     }
     return context;
@@ -170,8 +173,7 @@
         return nullptr;
     }
 
-    context->fCaps = context->fGpu->refCaps();
-    if (!context->init()) {
+    if (!context->init(context->fGpu->refCaps(), nullptr)) {
         return nullptr;
     }
     return context;
@@ -194,8 +196,7 @@
         return nullptr;
     }
 
-    context->fCaps = context->fGpu->refCaps();
-    if (!context->init()) {
+    if (!context->init(context->fGpu->refCaps(), nullptr)) {
         return nullptr;
     }
     return context;