Double down on abandoned being publicly accessible on contexts

abandoned() is publicly accessible on GrContext. Since
GrRecordingContext is taking its place in many locations, make its
abandoned() call also publicly accessible.

This CL also removes abandoned() from GrContextPriv since it is
publicly accessible.

Change-Id: I72bdae369d06e34ec3f99a18a0feb72e2ae67666
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299876
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/gm/asyncrescaleandread.cpp b/gm/asyncrescaleandread.cpp
index 3ad5b8f..c27cb5f 100644
--- a/gm/asyncrescaleandread.cpp
+++ b/gm/asyncrescaleandread.cpp
@@ -206,7 +206,7 @@
         if (!surface) {
             *errorMsg = "Could not create surface for image.";
             // When testing abandoned GrContext we expect surface creation to fail.
-            if (canvas->recordingContext() && canvas->recordingContext()->priv().abandoned()) {
+            if (canvas->recordingContext() && canvas->recordingContext()->abandoned()) {
                 return skiagm::DrawResult::kSkip;
             }
             return skiagm::DrawResult::kFail;
@@ -221,7 +221,7 @@
         if (!image) {
             *errorMsg = "Could not create image.";
             // When testing abandoned GrContext we expect surface creation to fail.
-            if (canvas->recordingContext() && canvas->recordingContext()->priv().abandoned()) {
+            if (canvas->recordingContext() && canvas->recordingContext()->abandoned()) {
                 return skiagm::DrawResult::kSkip;
             }
             return skiagm::DrawResult::kFail;
diff --git a/gm/gm.cpp b/gm/gm.cpp
index f5786b4..054f2c6 100644
--- a/gm/gm.cpp
+++ b/gm/gm.cpp
@@ -21,7 +21,6 @@
 #include "include/core/SkTypeface.h"
 #include "include/private/GrRecordingContext.h"
 #include "src/core/SkTraceEvent.h"
-#include "src/gpu/GrRecordingContextPriv.h"
 #include "tools/ToolUtils.h"
 
 #include <stdarg.h>
@@ -205,7 +204,7 @@
         *errorMsg = kErrorMsg_DrawSkippedGpuOnly;
         return DrawResult::kSkip;
     }
-    if (ctx->priv().abandoned()) {
+    if (ctx->abandoned()) {
         *errorMsg = "GrContext abandoned.";
         return DrawResult::kSkip;
     }
diff --git a/gm/windowrectangles.cpp b/gm/windowrectangles.cpp
index 5b7f268..b35c559 100644
--- a/gm/windowrectangles.cpp
+++ b/gm/windowrectangles.cpp
@@ -259,7 +259,7 @@
                                                   GrRenderTargetContext* rtc,
                                                   const GrReducedClip& reducedClip,
                                                   GrPaint&& paint) {
-    if (ctx->priv().abandoned()) {
+    if (ctx->abandoned()) {
         // GrReducedClip assumes the context hasn't been abandoned, which is reasonable since it is
         // only ever used if a draw op is made. Since this GM calls it directly, it has to be taken
         // into account.
diff --git a/gm/yuv420_odd_dim.cpp b/gm/yuv420_odd_dim.cpp
index 3e2222f..bc3508a 100644
--- a/gm/yuv420_odd_dim.cpp
+++ b/gm/yuv420_odd_dim.cpp
@@ -18,7 +18,6 @@
 #include "include/private/GrRecordingContext.h"
 #include "include/utils/SkRandom.h"
 #include "src/core/SkCachedData.h"
-#include "src/gpu/GrRecordingContextPriv.h"
 #include "src/image/SkImage_Base.h"
 
 static constexpr int kScale = 10;
@@ -78,7 +77,7 @@
                        kScale* kImageDim.width(), kScale* kImageDim.height()) {
     auto image = make_image(canvas->getGrContext());
     if (!image) {
-        if (canvas->recordingContext() && canvas->recordingContext()->priv().abandoned()) {
+        if (canvas->recordingContext() && canvas->recordingContext()->abandoned()) {
             return skiagm::DrawResult::kOk;
         }
         return skiagm::DrawResult::kFail;
diff --git a/include/private/GrRecordingContext.h b/include/private/GrRecordingContext.h
index fb6d2af..8b6e04a 100644
--- a/include/private/GrRecordingContext.h
+++ b/include/private/GrRecordingContext.h
@@ -34,6 +34,14 @@
         return INHERITED::defaultBackendFormat(ct, renderable);
     }
 
+    /**
+     * Reports whether the GrDirectContext associated with this GrRecordingContext is abandoned.
+     * When called on a GrDirectContext it may actively check whether the underlying 3D API
+     * device/context has been disconnected before reporting the status. If so, calling this
+     * method will transition the GrDirectContext to the abandoned state.
+     */
+    bool abandoned() override { return INHERITED::abandoned(); }
+
     // Provides access to functions that aren't part of the public API.
     GrRecordingContextPriv priv();
     const GrRecordingContextPriv priv() const;
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp
index f434bd5..ac64a94 100644
--- a/src/core/SkSpecialImage.cpp
+++ b/src/core/SkSpecialImage.cpp
@@ -458,7 +458,7 @@
                                                           sk_sp<SkColorSpace> colorSpace,
                                                           const SkSurfaceProps* props,
                                                           SkAlphaType at) {
-    if (!context || context->priv().abandoned() || !view.asTextureProxy()) {
+    if (!context || context->abandoned() || !view.asTextureProxy()) {
         return nullptr;
     }
     SkASSERT_RELEASE(rect_fits(subset, view.proxy()->width(), view.proxy()->height()));
diff --git a/src/gpu/GrAHardwareBufferImageGenerator.cpp b/src/gpu/GrAHardwareBufferImageGenerator.cpp
index a8a3f05..4bb2c91 100644
--- a/src/gpu/GrAHardwareBufferImageGenerator.cpp
+++ b/src/gpu/GrAHardwareBufferImageGenerator.cpp
@@ -81,7 +81,7 @@
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 GrSurfaceProxyView GrAHardwareBufferImageGenerator::makeView(GrRecordingContext* context) {
-    if (context->priv().abandoned()) {
+    if (context->abandoned()) {
         return {};
     }
 
diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp
index 084e8ef..87cc7f2 100644
--- a/src/gpu/GrBlurUtils.cpp
+++ b/src/gpu/GrBlurUtils.cpp
@@ -449,7 +449,7 @@
                                           const SkPaint& paint,
                                           const SkMatrixProvider& matrixProvider,
                                           const GrStyledShape& shape) {
-    if (context->priv().abandoned()) {
+    if (context->abandoned()) {
         return;
     }
 
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index b17d9da..4789030 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -46,8 +46,6 @@
     GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); }
     const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); }
 
-    bool abandoned() const { return fContext->abandoned(); }
-
     /** This is only useful for debug purposes */
     SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } )
 
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index cffc136..f14da9b 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -161,7 +161,7 @@
 }
 
 bool GrDrawingManager::wasAbandoned() const {
-    return fContext->priv().abandoned();
+    return fContext->abandoned();
 }
 
 void GrDrawingManager::freeGpuResources() {
diff --git a/src/gpu/GrRecordingContextPriv.h b/src/gpu/GrRecordingContextPriv.h
index bec89b5..f4c4487 100644
--- a/src/gpu/GrRecordingContextPriv.h
+++ b/src/gpu/GrRecordingContextPriv.h
@@ -34,8 +34,6 @@
     GrProxyProvider* proxyProvider() { return fContext->proxyProvider(); }
     const GrProxyProvider* proxyProvider() const { return fContext->proxyProvider(); }
 
-    bool abandoned() const { return fContext->abandoned(); }
-
     /** This is only useful for debug purposes */
     SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } )
 
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index 4e2a438..eab1436 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -120,11 +120,11 @@
 #define ASSERT_OWNED_RESOURCE(R) SkASSERT(!(R) || (R)->getContext() == this->drawingManager()->getContext())
 #define ASSERT_SINGLE_OWNER        GR_ASSERT_SINGLE_OWNER(this->singleOwner())
 #define ASSERT_SINGLE_OWNER_PRIV   GR_ASSERT_SINGLE_OWNER(fRenderTargetContext->singleOwner())
-#define RETURN_IF_ABANDONED        if (fContext->priv().abandoned()) { return; }
-#define RETURN_IF_ABANDONED_PRIV   if (fRenderTargetContext->fContext->priv().abandoned()) { return; }
-#define RETURN_FALSE_IF_ABANDONED  if (fContext->priv().abandoned()) { return false; }
-#define RETURN_FALSE_IF_ABANDONED_PRIV  if (fRenderTargetContext->fContext->priv().abandoned()) { return false; }
-#define RETURN_NULL_IF_ABANDONED   if (fContext->priv().abandoned()) { return nullptr; }
+#define RETURN_IF_ABANDONED        if (fContext->abandoned()) { return; }
+#define RETURN_IF_ABANDONED_PRIV   if (fRenderTargetContext->fContext->abandoned()) { return; }
+#define RETURN_FALSE_IF_ABANDONED  if (fContext->abandoned()) { return false; }
+#define RETURN_FALSE_IF_ABANDONED_PRIV  if (fRenderTargetContext->fContext->abandoned()) { return false; }
+#define RETURN_NULL_IF_ABANDONED   if (fContext->abandoned()) { return nullptr; }
 
 //////////////////////////////////////////////////////////////////////////////
 
@@ -183,7 +183,7 @@
     // GrRenderTargetContext which need the context will mostly likely fail later on without an
     // issue. However having this hear adds some reassurance in case there is a path doesn't handle
     // an abandoned context correctly. It also lets us early out of some extra work.
-    if (context->priv().abandoned()) {
+    if (context->abandoned()) {
         return nullptr;
     }
 
@@ -1225,7 +1225,7 @@
                                            const SkPath& path,
                                            const SkDrawShadowRec& rec) {
     ASSERT_SINGLE_OWNER
-    if (fContext->priv().abandoned()) {
+    if (fContext->abandoned()) {
         return true;
     }
     SkDEBUGCODE(this->validate();)
@@ -1882,7 +1882,7 @@
 SkBudgeted GrRenderTargetContextPriv::isBudgeted() const {
     ASSERT_SINGLE_OWNER_PRIV
 
-    if (fRenderTargetContext->fContext->priv().abandoned()) {
+    if (fRenderTargetContext->fContext->abandoned()) {
         return SkBudgeted::kNo;
     }
 
@@ -2022,7 +2022,7 @@
 void GrRenderTargetContext::addDrawOp(const GrClip* clip, std::unique_ptr<GrDrawOp> op,
                                       const std::function<WillAddOpFn>& willAddFn) {
     ASSERT_SINGLE_OWNER
-    if (fContext->priv().abandoned()) {
+    if (fContext->abandoned()) {
         fContext->priv().opMemoryPool()->release(std::move(op));
         return;
     }
diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp
index 655eab4..c9dc239 100644
--- a/src/gpu/GrSurfaceContext.cpp
+++ b/src/gpu/GrSurfaceContext.cpp
@@ -27,7 +27,7 @@
 #include "src/gpu/effects/generated/GrColorMatrixFragmentProcessor.h"
 
 #define ASSERT_SINGLE_OWNER        GR_ASSERT_SINGLE_OWNER(this->singleOwner())
-#define RETURN_FALSE_IF_ABANDONED  if (this->fContext->priv().abandoned()) { return false; }
+#define RETURN_FALSE_IF_ABANDONED  if (this->fContext->abandoned()) { return false; }
 
 std::unique_ptr<GrSurfaceContext> GrSurfaceContext::Make(GrRecordingContext* context,
                                                          GrSurfaceProxyView readView,
@@ -38,7 +38,7 @@
     // GrSurfaceContext which need the context will mostly likely fail later on without an issue.
     // However having this hear adds some reassurance in case there is a path doesn't handle an
     // abandoned context correctly. It also lets us early out of some extra work.
-    if (context->priv().abandoned()) {
+    if (context->abandoned()) {
         return nullptr;
     }
     GrSurfaceProxy* proxy = readView.proxy();
@@ -108,7 +108,7 @@
         : fContext(context)
         , fReadView(std::move(readView))
         , fColorInfo(colorType, alphaType, std::move(colorSpace)) {
-    SkASSERT(!context->priv().abandoned());
+    SkASSERT(!context->abandoned());
 }
 
 const GrCaps* GrSurfaceContext::caps() const { return fContext->priv().caps(); }
@@ -1151,7 +1151,7 @@
                                               const GrFlushInfo& info,
                                               const GrBackendSurfaceMutableState* newState) {
     ASSERT_SINGLE_OWNER
-    if (fContext->priv().abandoned()) {
+    if (fContext->abandoned()) {
         if (info.fSubmittedProc) {
             info.fSubmittedProc(info.fSubmittedContext, false);
         }
diff --git a/src/gpu/GrTextureAdjuster.cpp b/src/gpu/GrTextureAdjuster.cpp
index d3371d7..43ac22b 100644
--- a/src/gpu/GrTextureAdjuster.cpp
+++ b/src/gpu/GrTextureAdjuster.cpp
@@ -50,7 +50,7 @@
 }
 
 GrSurfaceProxyView GrTextureAdjuster::onView(GrMipMapped mipMapped) {
-    if (this->context()->priv().abandoned()) {
+    if (this->context()->abandoned()) {
         // The texture was abandoned.
         return {};
     }
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 700ef68..7824574 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -32,10 +32,8 @@
 #include "src/core/SkVerticesPriv.h"
 #include "src/gpu/GrBitmapTextureMaker.h"
 #include "src/gpu/GrBlurUtils.h"
-#include "src/gpu/GrContextPriv.h"
 #include "src/gpu/GrGpu.h"
 #include "src/gpu/GrImageTextureMaker.h"
-#include "src/gpu/GrRecordingContextPriv.h"
 #include "src/gpu/GrRenderTargetContextPriv.h"
 #include "src/gpu/GrStyle.h"
 #include "src/gpu/GrSurfaceProxyPriv.h"
@@ -79,7 +77,7 @@
 sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context,
                                      std::unique_ptr<GrRenderTargetContext> renderTargetContext,
                                      InitContents init) {
-    if (!renderTargetContext || context->priv().abandoned()) {
+    if (!renderTargetContext || context->abandoned()) {
         return nullptr;
     }
 
@@ -220,7 +218,7 @@
     SkASSERT(rtc->numSamples() == fRenderTargetContext->numSamples());
     SkASSERT(rtc->asSurfaceProxy()->priv().isExact());
     if (mode == SkSurface::kRetain_ContentChangeMode) {
-        if (this->recordingContext()->priv().abandoned()) {
+        if (this->recordingContext()->abandoned()) {
             return;
         }
 
diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp
index 4597d36..7a7d5ba 100644
--- a/src/image/SkImage_GpuBase.cpp
+++ b/src/image/SkImage_GpuBase.cpp
@@ -251,7 +251,7 @@
 
 bool SkImage_GpuBase::onIsValid(GrContext* context) const {
     // The base class has already checked that context isn't abandoned (if it's not nullptr)
-    if (fContext->priv().abandoned()) {
+    if (fContext->abandoned()) {
         return false;
     }
 
diff --git a/tools/gpu/GrTest.cpp b/tools/gpu/GrTest.cpp
index d628667..0622068 100644
--- a/tools/gpu/GrTest.cpp
+++ b/tools/gpu/GrTest.cpp
@@ -69,7 +69,7 @@
         std::unique_ptr<GrDrawOp> op,
         const std::function<GrRenderTargetContext::WillAddOpFn>& willAddFn) {
     ASSERT_SINGLE_OWNER
-    if (fRenderTargetContext->fContext->priv().abandoned()) {
+    if (fRenderTargetContext->fContext->abandoned()) {
         fRenderTargetContext->fContext->priv().opMemoryPool()->release(std::move(op));
         return;
     }
diff --git a/tools/gpu/ProxyUtils.cpp b/tools/gpu/ProxyUtils.cpp
index 1347c1b..9064546 100644
--- a/tools/gpu/ProxyUtils.cpp
+++ b/tools/gpu/ProxyUtils.cpp
@@ -27,7 +27,7 @@
                                                const GrImageInfo& imageInfo,
                                                const void* data,
                                                size_t rowBytes) {
-    if (context->priv().abandoned()) {
+    if (context->abandoned()) {
         return nullptr;
     }