Migrate last public API to GrDirectContext

Cut & paste with some reorganization of includes & forward-decls.

Next up is GrContextPriv.

Change-Id: I72d2d95c62692e3b37608517b796c0041ffedea3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/326157
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
diff --git a/include/gpu/GrDirectContext.h b/include/gpu/GrDirectContext.h
index 75a91b8..170b065 100644
--- a/include/gpu/GrDirectContext.h
+++ b/include/gpu/GrDirectContext.h
@@ -10,8 +10,29 @@
 
 #include "include/private/GrContext.h"
 
-class GrAtlasManager;
-class GrSmallPathAtlasMgr;
+#include "include/gpu/GrBackendSurface.h"
+
+// We shouldn't need this but currently Android is relying on this being include transitively.
+#include "include/core/SkUnPreMultiply.h"
+
+class GrBackendSemaphore;
+class GrContextThreadSafeProxy;
+struct GrD3DBackendContext;
+class GrFragmentProcessor;
+struct GrGLInterface;
+struct GrMockOptions;
+class GrPath;
+class GrRenderTargetContext;
+class GrSurfaceProxy;
+class GrSwizzle;
+class GrTextureProxy;
+struct GrVkBackendContext;
+
+class SkImage;
+class SkString;
+class SkSurfaceCharacterization;
+class SkSurfaceProps;
+class SkTraceMemoryDump;
 
 class SK_API GrDirectContext : public GrContext {
 public:
@@ -632,6 +653,61 @@
                                         GrGpuFinishedProc finishedProc,
                                         GrGpuFinishedContext finishedContext);
 
+    /**
+     * Updates the state of the GrBackendTexture/RenderTarget to have the passed in
+     * GrBackendSurfaceMutableState. All objects that wrap the backend surface (i.e. SkSurfaces and
+     * SkImages) will also be aware of this state change. This call does not submit the state change
+     * to the gpu, but requires the client to call `submit` to send it to the GPU. The work
+     * for this call is ordered linearly with all other calls that require GrContext::submit to be
+     * called (e.g updateBackendTexture and flush). If finishedProc is not null then it will be
+     * called with finishedContext after the state transition is known to have occurred on the GPU.
+     *
+     * See GrBackendSurfaceMutableState to see what state can be set via this call.
+     *
+     * If the backend API is Vulkan, the caller can set the GrBackendSurfaceMutableState's
+     * VkImageLayout to VK_IMAGE_LAYOUT_UNDEFINED or queueFamilyIndex to VK_QUEUE_FAMILY_IGNORED to
+     * tell Skia to not change those respective states.
+     *
+     * If previousState is not null and this returns true, then Skia will have filled in
+     * previousState to have the values of the state before this call.
+     */
+    bool setBackendTextureState(const GrBackendTexture&,
+                                const GrBackendSurfaceMutableState&,
+                                GrBackendSurfaceMutableState* previousState = nullptr,
+                                GrGpuFinishedProc finishedProc = nullptr,
+                                GrGpuFinishedContext finishedContext = nullptr);
+    bool setBackendRenderTargetState(const GrBackendRenderTarget&,
+                                     const GrBackendSurfaceMutableState&,
+                                     GrBackendSurfaceMutableState* previousState = nullptr,
+                                     GrGpuFinishedProc finishedProc = nullptr,
+                                     GrGpuFinishedContext finishedContext = nullptr);
+
+    void deleteBackendTexture(GrBackendTexture);
+
+    // This interface allows clients to pre-compile shaders and populate the runtime program cache.
+    // The key and data blobs should be the ones passed to the PersistentCache, in SkSL format.
+    //
+    // Steps to use this API:
+    //
+    // 1) Create a GrContext as normal, but set fPersistentCache on GrContextOptions to something
+    //    that will save the cached shader blobs. Set fShaderCacheStrategy to kSkSL. This will
+    //    ensure that the blobs are SkSL, and are suitable for pre-compilation.
+    // 2) Run your application, and save all of the key/data pairs that are fed to the cache.
+    //
+    // 3) Switch over to shipping your application. Include the key/data pairs from above.
+    // 4) At startup (or any convenient time), call precompileShader for each key/data pair.
+    //    This will compile the SkSL to create a GL program, and populate the runtime cache.
+    //
+    // This is only guaranteed to work if the context/device used in step #2 are created in the
+    // same way as the one used in step #4, and the same GrContextOptions are specified.
+    // Using cached shader blobs on a different device or driver are undefined.
+    bool precompileShader(const SkData& key, const SkData& data);
+
+#ifdef SK_ENABLE_DUMP_GPU
+    /** Returns a string with detailed information about the context & GPU, in JSON format. */
+    SkString dump() const;
+#endif
+
 protected:
     GrDirectContext(GrBackendApi backend, const GrContextOptions& options);
 
diff --git a/include/private/GrContext.h b/include/private/GrContext.h
index b7d0f19..0e47bac 100644
--- a/include/private/GrContext.h
+++ b/include/private/GrContext.h
@@ -8,44 +8,19 @@
 #ifndef GrContext_DEFINED
 #define GrContext_DEFINED
 
-#include "include/core/SkMatrix.h"
-#include "include/core/SkPathEffect.h"
 #include "include/core/SkTypes.h"
-#include "include/gpu/GrBackendSurface.h"
 #include "include/gpu/GrContextOptions.h"
 #include "include/gpu/GrRecordingContext.h"
 
-// We shouldn't need this but currently Android is relying on this being include transitively.
-#include "include/core/SkUnPreMultiply.h"
-
 class GrAtlasManager;
-class GrBackendSemaphore;
-class GrCaps;
 class GrClientMappedBufferManager;
 class GrContextPriv;
-class GrContextThreadSafeProxy;
-struct GrD3DBackendContext;
-class GrFragmentProcessor;
-struct GrGLInterface;
 class GrGpu;
-struct GrMockOptions;
-class GrPath;
-class GrRenderTargetContext;
 class GrResourceCache;
 class GrResourceProvider;
 class GrSmallPathAtlasMgr;
 class GrStrikeCache;
-class GrSurfaceProxy;
-class GrSwizzle;
-class GrTextureProxy;
-struct GrVkBackendContext;
-
-class SkImage;
-class SkString;
-class SkSurfaceCharacterization;
-class SkSurfaceProps;
 class SkTaskGroup;
-class SkTraceMemoryDump;
 
 /**
  * This deprecated class is being merged into GrDirectContext and removed.
@@ -57,61 +32,6 @@
 public:
     ~GrContext() override;
 
-    /**
-     * Updates the state of the GrBackendTexture/RenderTarget to have the passed in
-     * GrBackendSurfaceMutableState. All objects that wrap the backend surface (i.e. SkSurfaces and
-     * SkImages) will also be aware of this state change. This call does not submit the state change
-     * to the gpu, but requires the client to call GrContext::submit to send it to the GPU. The work
-     * for this call is ordered linearly with all other calls that require GrContext::submit to be
-     * called (e.g updateBackendTexture and flush). If finishedProc is not null then it will be
-     * called with finishedContext after the state transition is known to have occurred on the GPU.
-     *
-     * See GrBackendSurfaceMutableState to see what state can be set via this call.
-     *
-     * If the backend API is Vulkan, the caller can set the GrBackendSurfaceMutableState's
-     * VkImageLayout to VK_IMAGE_LAYOUT_UNDEFINED or queueFamilyIndex to VK_QUEUE_FAMILY_IGNORED to
-     * tell Skia to not change those respective states.
-     *
-     * If previousState is not null and this returns true, then Skia will have filled in
-     * previousState to have the values of the state before this call.
-     */
-    bool setBackendTextureState(const GrBackendTexture&,
-                                const GrBackendSurfaceMutableState&,
-                                GrBackendSurfaceMutableState* previousState = nullptr,
-                                GrGpuFinishedProc finishedProc = nullptr,
-                                GrGpuFinishedContext finishedContext = nullptr);
-    bool setBackendRenderTargetState(const GrBackendRenderTarget&,
-                                     const GrBackendSurfaceMutableState&,
-                                     GrBackendSurfaceMutableState* previousState = nullptr,
-                                     GrGpuFinishedProc finishedProc = nullptr,
-                                     GrGpuFinishedContext finishedContext = nullptr);
-
-    void deleteBackendTexture(GrBackendTexture);
-
-    // This interface allows clients to pre-compile shaders and populate the runtime program cache.
-    // The key and data blobs should be the ones passed to the PersistentCache, in SkSL format.
-    //
-    // Steps to use this API:
-    //
-    // 1) Create a GrContext as normal, but set fPersistentCache on GrContextOptions to something
-    //    that will save the cached shader blobs. Set fShaderCacheStrategy to kSkSL. This will
-    //    ensure that the blobs are SkSL, and are suitable for pre-compilation.
-    // 2) Run your application, and save all of the key/data pairs that are fed to the cache.
-    //
-    // 3) Switch over to shipping your application. Include the key/data pairs from above.
-    // 4) At startup (or any convenient time), call precompileShader for each key/data pair.
-    //    This will compile the SkSL to create a GL program, and populate the runtime cache.
-    //
-    // This is only guaranteed to work if the context/device used in step #2 are created in the
-    // same way as the one used in step #4, and the same GrContextOptions are specified.
-    // Using cached shader blobs on a different device or driver are undefined.
-    bool precompileShader(const SkData& key, const SkData& data);
-
-#ifdef SK_ENABLE_DUMP_GPU
-    /** Returns a string with detailed information about the context & GPU, in JSON format. */
-    SkString dump() const;
-#endif
-
     // Provides access to functions that aren't part of the public API.
     GrContextPriv priv();
     const GrContextPriv priv() const;  // NOLINT(readability-const-return-type)
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index fefdcbf..929f0e8 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -7,134 +7,14 @@
 
 #include "include/gpu/GrDirectContext.h"
 
-#include "include/core/SkDeferredDisplayList.h"
-#include "include/core/SkTraceMemoryDump.h"
-#include "include/gpu/GrBackendSemaphore.h"
-#include "include/private/SkImageInfoPriv.h"
-#include "src/core/SkMipmap.h"
+#include "include/gpu/GrContextThreadSafeProxy.h"
 #include "src/core/SkTaskGroup.h"
 #include "src/gpu/GrClientMappedBufferManager.h"
-#include "src/gpu/GrContextPriv.h"
-#include "src/gpu/GrDrawingManager.h"
 #include "src/gpu/GrGpu.h"
-#include "src/gpu/GrImageContextPriv.h"
-#include "src/gpu/GrMemoryPool.h"
-#include "src/gpu/GrPathRendererChain.h"
-#include "src/gpu/GrProxyProvider.h"
-#include "src/gpu/GrRenderTargetProxy.h"
 #include "src/gpu/GrResourceCache.h"
 #include "src/gpu/GrResourceProvider.h"
-#include "src/gpu/GrSemaphore.h"
-#include "src/gpu/GrSoftwarePathRenderer.h"
-#include "src/gpu/GrThreadSafeCache.h"
-#include "src/gpu/GrTracing.h"
-#include "src/gpu/SkGr.h"
-#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
-#include "src/gpu/effects/GrSkSLFP.h"
-#include "src/gpu/text/GrSDFTOptions.h"
 #include "src/gpu/text/GrStrikeCache.h"
-#include "src/gpu/text/GrTextBlobCache.h"
-#include "src/image/SkImage_GpuBase.h"
-#include "src/image/SkSurface_Gpu.h"
-#include <atomic>
-#include <memory>
 
 GrContext::GrContext(sk_sp<GrContextThreadSafeProxy> proxy) : INHERITED(std::move(proxy)) { }
 
 GrContext::~GrContext() = default;
-
-//////////////////////////////////////////////////////////////////////////////
-
-bool GrContext::setBackendTextureState(const GrBackendTexture& backendTexture,
-                                       const GrBackendSurfaceMutableState& state,
-                                       GrBackendSurfaceMutableState* previousState,
-                                       GrGpuFinishedProc finishedProc,
-                                       GrGpuFinishedContext finishedContext) {
-    sk_sp<GrRefCntedCallback> callback;
-    if (finishedProc) {
-        callback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
-    }
-
-    if (!this->asDirectContext()) {
-        return false;
-    }
-
-    if (this->abandoned()) {
-        return false;
-    }
-
-    return fGpu->setBackendTextureState(backendTexture, state, previousState, std::move(callback));
-}
-
-
-bool GrContext::setBackendRenderTargetState(const GrBackendRenderTarget& backendRenderTarget,
-                                            const GrBackendSurfaceMutableState& state,
-                                            GrBackendSurfaceMutableState* previousState,
-                                            GrGpuFinishedProc finishedProc,
-                                            GrGpuFinishedContext finishedContext) {
-    sk_sp<GrRefCntedCallback> callback;
-    if (finishedProc) {
-        callback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
-    }
-
-    if (!this->asDirectContext()) {
-        return false;
-    }
-
-    if (this->abandoned()) {
-        return false;
-    }
-
-    return fGpu->setBackendRenderTargetState(backendRenderTarget, state, previousState,
-                                             std::move(callback));
-}
-
-void GrContext::deleteBackendTexture(GrBackendTexture backendTex) {
-    TRACE_EVENT0("skia.gpu", TRACE_FUNC);
-    // For the Vulkan backend we still must destroy the backend texture when the context is
-    // abandoned.
-    if ((this->abandoned() && this->backend() != GrBackendApi::kVulkan) || !backendTex.isValid()) {
-        return;
-    }
-
-    fGpu->deleteBackendTexture(backendTex);
-}
-
-//////////////////////////////////////////////////////////////////////////////
-
-bool GrContext::precompileShader(const SkData& key, const SkData& data) {
-    return fGpu->precompileShader(key, data);
-}
-
-#ifdef SK_ENABLE_DUMP_GPU
-#include "include/core/SkString.h"
-#include "src/utils/SkJSONWriter.h"
-SkString GrContext::dump() const {
-    SkDynamicMemoryWStream stream;
-    SkJSONWriter writer(&stream, SkJSONWriter::Mode::kPretty);
-    writer.beginObject();
-
-    writer.appendString("backend", GrBackendApiToStr(this->backend()));
-
-    writer.appendName("caps");
-    this->caps()->dumpJSON(&writer);
-
-    writer.appendName("gpu");
-    this->fGpu->dumpJSON(&writer);
-
-    writer.appendName("context");
-    this->dumpJSON(&writer);
-
-    // Flush JSON to the memory stream
-    writer.endObject();
-    writer.flush();
-
-    // Null terminate the JSON data in the memory stream
-    stream.write8(0);
-
-    // Allocate a string big enough to hold all the data, then copy out of the stream
-    SkString result(stream.bytesWritten());
-    stream.copyToAndReset(result.writable_str());
-    return result;
-}
-#endif
diff --git a/src/gpu/GrDirectContext.cpp b/src/gpu/GrDirectContext.cpp
index aafe5a6..a0502d6 100644
--- a/src/gpu/GrDirectContext.cpp
+++ b/src/gpu/GrDirectContext.cpp
@@ -39,6 +39,7 @@
 #ifdef SK_DAWN
 #include "src/gpu/dawn/GrDawnGpu.h"
 #endif
+#include <memory>
 
 #if GR_TEST_UTILS
 #   include "include/utils/SkRandom.h"
@@ -817,6 +818,94 @@
     return fGpu->updateCompressedBackendTexture(backendTexture, std::move(finishedCallback), &data);
 }
 
+//////////////////////////////////////////////////////////////////////////////
+
+bool GrDirectContext::setBackendTextureState(const GrBackendTexture& backendTexture,
+                                             const GrBackendSurfaceMutableState& state,
+                                             GrBackendSurfaceMutableState* previousState,
+                                             GrGpuFinishedProc finishedProc,
+                                             GrGpuFinishedContext finishedContext) {
+    sk_sp<GrRefCntedCallback> callback;
+    if (finishedProc) {
+        callback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
+    }
+
+    if (this->abandoned()) {
+        return false;
+    }
+
+    return fGpu->setBackendTextureState(backendTexture, state, previousState, std::move(callback));
+}
+
+
+bool GrDirectContext::setBackendRenderTargetState(const GrBackendRenderTarget& backendRenderTarget,
+                                                  const GrBackendSurfaceMutableState& state,
+                                                  GrBackendSurfaceMutableState* previousState,
+                                                  GrGpuFinishedProc finishedProc,
+                                                  GrGpuFinishedContext finishedContext) {
+    sk_sp<GrRefCntedCallback> callback;
+    if (finishedProc) {
+        callback.reset(new GrRefCntedCallback(finishedProc, finishedContext));
+    }
+
+    if (this->abandoned()) {
+        return false;
+    }
+
+    return fGpu->setBackendRenderTargetState(backendRenderTarget, state, previousState,
+                                             std::move(callback));
+}
+
+void GrDirectContext::deleteBackendTexture(GrBackendTexture backendTex) {
+    TRACE_EVENT0("skia.gpu", TRACE_FUNC);
+    // For the Vulkan backend we still must destroy the backend texture when the context is
+    // abandoned.
+    if ((this->abandoned() && this->backend() != GrBackendApi::kVulkan) || !backendTex.isValid()) {
+        return;
+    }
+
+    fGpu->deleteBackendTexture(backendTex);
+}
+
+//////////////////////////////////////////////////////////////////////////////
+
+bool GrDirectContext::precompileShader(const SkData& key, const SkData& data) {
+    return fGpu->precompileShader(key, data);
+}
+
+#ifdef SK_ENABLE_DUMP_GPU
+#include "include/core/SkString.h"
+#include "src/utils/SkJSONWriter.h"
+SkString GrDirectContext::dump() const {
+    SkDynamicMemoryWStream stream;
+    SkJSONWriter writer(&stream, SkJSONWriter::Mode::kPretty);
+    writer.beginObject();
+
+    writer.appendString("backend", GrBackendApiToStr(this->backend()));
+
+    writer.appendName("caps");
+    this->caps()->dumpJSON(&writer);
+
+    writer.appendName("gpu");
+    this->fGpu->dumpJSON(&writer);
+
+    writer.appendName("context");
+    this->dumpJSON(&writer);
+
+    // Flush JSON to the memory stream
+    writer.endObject();
+    writer.flush();
+
+    // Null terminate the JSON data in the memory stream
+    stream.write8(0);
+
+    // Allocate a string big enough to hold all the data, then copy out of the stream
+    SkString result(stream.bytesWritten());
+    stream.copyToAndReset(result.writable_str());
+    return result;
+}
+#endif
+
 #ifdef SK_GL
 
 /*************************************************************************************************/