Revert "Merge GrContext::init into GrDirectContext ..."

This reverts commit 48d8724097d0b108259c2aef7df8ed1aa08bd574.

Reason for revert: Breaking MSVC bots

Original change's description:
> Merge GrContext::init into GrDirectContext ...
>
> And minor cleanups associated with the initialization of these classes.
>
> Change-Id: Ida0372d0b1a0b8bf5b309814de5418e47ea34fdb
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/324122
> Commit-Queue: Adlai Holler <adlai@google.com>
> Reviewed-by: Robert Phillips <robertphillips@google.com>
> Auto-Submit: Adlai Holler <adlai@google.com>

TBR=robertphillips@google.com,adlai@google.com

Change-Id: I00b2ddaeaef53e3fe05a338c88158cf235f325c4
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/324132
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index f7486d0..91f328f 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -25,6 +25,7 @@
 #include "src/gpu/GrResourceCache.h"
 #include "src/gpu/GrResourceProvider.h"
 #include "src/gpu/GrSemaphore.h"
+#include "src/gpu/GrShaderUtils.h"
 #include "src/gpu/GrSoftwarePathRenderer.h"
 #include "src/gpu/GrThreadSafeCache.h"
 #include "src/gpu/GrTracing.h"
@@ -50,7 +51,59 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 
-GrContext::GrContext(sk_sp<GrContextThreadSafeProxy> proxy) : INHERITED(std::move(proxy)) { }
+GrContext::GrContext(sk_sp<GrContextThreadSafeProxy> proxy) : INHERITED(std::move(proxy)) {
+    fResourceCache = nullptr;
+    fResourceProvider = nullptr;
+}
+
+GrContext::~GrContext() {
+    ASSERT_SINGLE_OWNER
+
+    this->destroyDrawingManager();
+    fMappedBufferManager.reset();
+    delete fResourceProvider;
+    delete fResourceCache;
+}
+
+bool GrContext::init() {
+    ASSERT_SINGLE_OWNER
+    SkASSERT(this->proxyProvider());
+
+    if (!INHERITED::init()) {
+        return false;
+    }
+
+    SkASSERT(this->getTextBlobCache());
+    SkASSERT(this->threadSafeCache());
+
+    if (fGpu) {
+        fStrikeCache = std::make_unique<GrStrikeCache>();
+        fResourceCache = new GrResourceCache(this->caps(), this->singleOwner(), this->contextID());
+        fResourceProvider = new GrResourceProvider(fGpu.get(), fResourceCache, this->singleOwner());
+        fMappedBufferManager = std::make_unique<GrClientMappedBufferManager>(this->contextID());
+    }
+
+    if (fResourceCache) {
+        fResourceCache->setProxyProvider(this->proxyProvider());
+        fResourceCache->setThreadSafeCache(this->threadSafeCache());
+    }
+
+    fDidTestPMConversions = false;
+
+    // DDL TODO: we need to think through how the task group & persistent cache
+    // get passed on to/shared between all the DDLRecorders created with this context.
+    if (this->options().fExecutor) {
+        fTaskGroup = std::make_unique<SkTaskGroup>(*this->options().fExecutor);
+    }
+
+    fPersistentCache = this->options().fPersistentCache;
+    fShaderErrorHandler = this->options().fShaderErrorHandler;
+    if (!fShaderErrorHandler) {
+        fShaderErrorHandler = GrShaderUtils::DefaultShaderErrorHandler();
+    }
+
+    return true;
+}
 
 sk_sp<GrContextThreadSafeProxy> GrContext::threadSafeProxy() {
     return INHERITED::threadSafeProxy();
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index cbea452..2823a1d 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -101,10 +101,10 @@
 
     SkTaskGroup* getTaskGroup() { return fContext->fTaskGroup.get(); }
 
-    GrResourceProvider* resourceProvider() { return fContext->fResourceProvider.get(); }
-    const GrResourceProvider* resourceProvider() const { return fContext->fResourceProvider.get(); }
+    GrResourceProvider* resourceProvider() { return fContext->fResourceProvider; }
+    const GrResourceProvider* resourceProvider() const { return fContext->fResourceProvider; }
 
-    GrResourceCache* getResourceCache() { return fContext->fResourceCache.get(); }
+    GrResourceCache* getResourceCache() { return fContext->fResourceCache; }
 
     GrGpu* getGpu() { return fContext->fGpu.get(); }
     const GrGpu* getGpu() const { return fContext->fGpu.get(); }
diff --git a/src/gpu/GrDirectContext.cpp b/src/gpu/GrDirectContext.cpp
index 239ae4a..84b6c59 100644
--- a/src/gpu/GrDirectContext.cpp
+++ b/src/gpu/GrDirectContext.cpp
@@ -9,13 +9,9 @@
 #include "include/gpu/GrDirectContext.h"
 
 #include "include/gpu/GrContextThreadSafeProxy.h"
-#include "src/core/SkTaskGroup.h"
-#include "src/gpu/GrClientMappedBufferManager.h"
 #include "src/gpu/GrContextPriv.h"
 #include "src/gpu/GrContextThreadSafeProxyPriv.h"
 #include "src/gpu/GrGpu.h"
-#include "src/gpu/GrResourceProvider.h"
-#include "src/gpu/GrShaderUtils.h"
 
 #include "src/gpu/effects/GrSkSLFP.h"
 #include "src/gpu/gl/GrGLGpu.h"
@@ -49,27 +45,16 @@
 static const bool kDefaultReduceOpsTaskSplitting = false;
 #endif
 
-#define ASSERT_SINGLE_OWNER GR_ASSERT_SINGLE_OWNER(this->singleOwner())
-
 GrDirectContext::GrDirectContext(GrBackendApi backend, const GrContextOptions& options)
         : INHERITED(GrContextThreadSafeProxyPriv::Make(backend, options)) {
 }
 
 GrDirectContext::~GrDirectContext() {
-    ASSERT_SINGLE_OWNER
     // this if-test protects against the case where the context is being destroyed
     // before having been fully created
-    if (fGpu) {
+    if (this->priv().getGpu()) {
         this->flushAndSubmit();
     }
-
-    this->destroyDrawingManager();
-    fMappedBufferManager.reset();
-
-    // Ideally we could just let the ptr drop, but resource cache queries this ptr in releaseAll.
-    if (fResourceCache) {
-        fResourceCache->releaseAll();
-    }
 }
 
 void GrDirectContext::abandonContext() {
@@ -99,42 +84,16 @@
 }
 
 bool GrDirectContext::init() {
-    ASSERT_SINGLE_OWNER
-    if (!fGpu) {
+    const GrGpu* gpu = this->priv().getGpu();
+    if (!gpu) {
         return false;
     }
 
-    fThreadSafeProxy->priv().init(fGpu->refCaps());
+    fThreadSafeProxy->priv().init(gpu->refCaps());
     if (!INHERITED::init()) {
         return false;
     }
 
-    SkASSERT(this->getTextBlobCache());
-    SkASSERT(this->threadSafeCache());
-
-    fStrikeCache = std::make_unique<GrStrikeCache>();
-    fResourceCache = std::make_unique<GrResourceCache>(this->caps(), this->singleOwner(),
-                                                       this->contextID());
-    fResourceCache->setProxyProvider(this->proxyProvider());
-    fResourceCache->setThreadSafeCache(this->threadSafeCache());
-    fResourceProvider = std::make_unique<GrResourceProvider>(fGpu.get(), fResourceCache.get(),
-                                                             this->singleOwner());
-    fMappedBufferManager = std::make_unique<GrClientMappedBufferManager>(this->contextID());
-
-    fDidTestPMConversions = false;
-
-    // DDL TODO: we need to think through how the task group & persistent cache
-    // get passed on to/shared between all the DDLRecorders created with this context.
-    if (this->options().fExecutor) {
-        fTaskGroup = std::make_unique<SkTaskGroup>(*this->options().fExecutor);
-    }
-
-    fPersistentCache = this->options().fPersistentCache;
-    fShaderErrorHandler = this->options().fShaderErrorHandler;
-    if (!fShaderErrorHandler) {
-        fShaderErrorHandler = GrShaderUtils::DefaultShaderErrorHandler();
-    }
-
     bool reduceOpsTaskSplitting = kDefaultReduceOpsTaskSplitting;
     if (GrContextOptions::Enable::kNo == this->options().fReduceOpsTaskSplitting) {
         reduceOpsTaskSplitting = false;
diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp
index 3813d69..f6378db 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -685,7 +685,7 @@
 
 void GrResourceCache::removeFromNonpurgeableArray(GrGpuResource* resource) {
     int* index = resource->cacheAccess().accessCacheIndex();
-    // Fill the hole we will create in the array with the tail object, adjust its index, and
+    // Fill the whole we will create in the array with the tail object, adjust its index, and
     // then pop the array
     GrGpuResource* tail = *(fNonpurgeableResources.end() - 1);
     SkASSERT(fNonpurgeableResources[*index] == resource);