Make GrAuditTrail V1-only

This CL has some rough edges since some classes that use it (e.g., GrOpsTask) aren't yet V1-only. That said, the big CL has to be broken up somehow.

Bug: skia:11837
Change-Id: I41ed9982ca4664f893e447ba23c7aec59f42c964
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/426416
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/gn/gpu.gni b/gn/gpu.gni
index bdd94d8..5208919 100644
--- a/gn/gpu.gni
+++ b/gn/gpu.gni
@@ -38,7 +38,6 @@
   "$_src/gpu/GrAppliedClip.h",
   "$_src/gpu/GrAttachment.cpp",
   "$_src/gpu/GrAttachment.h",
-  "$_src/gpu/GrAuditTrail.cpp",
   "$_src/gpu/GrAuditTrail.h",
   "$_src/gpu/GrAutoLocaleSetter.h",
   "$_src/gpu/GrBackendSemaphore.cpp",
@@ -556,6 +555,7 @@
 ]
 
 skia_skgpu_v1_sources = [
+  "$_src/gpu/GrAuditTrail.cpp",
   "$_src/gpu/GrClipStack.cpp",
   "$_src/gpu/GrClipStack.h",
   "$_src/gpu/GrClipStackClip.cpp",
diff --git a/include/gpu/GrRecordingContext.h b/include/gpu/GrRecordingContext.h
index 3e83684..fc060e1 100644
--- a/include/gpu/GrRecordingContext.h
+++ b/include/gpu/GrRecordingContext.h
@@ -197,8 +197,6 @@
      */
     void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
 
-    GrAuditTrail* auditTrail() { return fAuditTrail.get(); }
-
     GrRecordingContext* asRecordingContext() override { return this; }
 
     class Stats {
@@ -251,10 +249,11 @@
     const Stats* stats() const { return &fStats; }
     void dumpJSON(SkJSONWriter*) const;
 
-private:
+protected:
     // Delete last in case other objects call it during destruction.
     std::unique_ptr<GrAuditTrail>     fAuditTrail;
 
+private:
     OwnedArenas                       fArenas;
 
     std::unique_ptr<GrDrawingManager> fDrawingManager;
diff --git a/src/gpu/GrAuditTrail.h b/src/gpu/GrAuditTrail.h
index a6eb8d3..f2d78dc 100644
--- a/src/gpu/GrAuditTrail.h
+++ b/src/gpu/GrAuditTrail.h
@@ -8,6 +8,10 @@
 #ifndef GrAuditTrail_DEFINED
 #define GrAuditTrail_DEFINED
 
+#include "include/gpu/GrTypes.h"
+
+#if SK_GPU_V1
+
 #include "include/core/SkRect.h"
 #include "include/core/SkString.h"
 #include "include/gpu/GrConfig.h"
@@ -172,4 +176,14 @@
 #define GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(audit_trail, combineWith, op) \
     GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, opsCombined, combineWith, op)
 
-#endif
+#else // SK_GPU_V1
+
+class GrAuditTrail {
+};
+
+#define GR_AUDIT_TRAIL_AUTO_FRAME(audit_trail, framename)
+#define GR_AUDIT_TRAIL_ADD_OP(audit_trail, op, proxy_id)
+#define GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(audit_trail, combineWith, op)
+
+#endif // SK_GPU_V1
+#endif // GrAuditTrail_DEFINED
diff --git a/src/gpu/GrDirectContextPriv.cpp b/src/gpu/GrDirectContextPriv.cpp
index 15de5ce..e8a39d5 100644
--- a/src/gpu/GrDirectContextPriv.cpp
+++ b/src/gpu/GrDirectContextPriv.cpp
@@ -10,7 +10,6 @@
 #include "include/gpu/GrContextThreadSafeProxy.h"
 #include "include/gpu/GrDirectContext.h"
 #include "src/core/SkRuntimeEffectPriv.h"
-#include "src/gpu/GrAuditTrail.h"
 #include "src/gpu/GrContextThreadSafeProxyPriv.h"
 #include "src/gpu/GrDrawingManager.h"
 #include "src/gpu/GrGpu.h"
diff --git a/src/gpu/GrDirectContextPriv.h b/src/gpu/GrDirectContextPriv.h
index ac65748..c25fd4f 100644
--- a/src/gpu/GrDirectContextPriv.h
+++ b/src/gpu/GrDirectContextPriv.h
@@ -70,7 +70,7 @@
      */
     void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
 
-    GrAuditTrail* auditTrail() { return fContext->auditTrail(); }
+    GrAuditTrail* auditTrail() { return fContext->fAuditTrail.get(); }
 
     /**
      * Finalizes all pending reads and writes to the surfaces and also performs an MSAA resolves
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index d9a3e9d..77e754b 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -16,7 +16,6 @@
 #include "include/gpu/GrRecordingContext.h"
 #include "src/core/SkDeferredDisplayListPriv.h"
 #include "src/core/SkTInternalLList.h"
-#include "src/gpu/GrAuditTrail.h"
 #include "src/gpu/GrClientMappedBufferManager.h"
 #include "src/gpu/GrCopyRenderTask.h"
 #include "src/gpu/GrDDLTask.h"
@@ -703,6 +702,7 @@
                                            std::move(surfaceView),
                                            fContext->priv().auditTrail(),
                                            std::move(arenas)));
+
     SkASSERT(this->getLastRenderTask(opsTask->target(0)) == opsTask.get());
 
     if (flushTimeOpsTask) {
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 3022526..e8f33ae 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -15,7 +15,6 @@
 #include "src/core/SkMathPriv.h"
 #include "src/core/SkMipmap.h"
 #include "src/gpu/GrAttachment.h"
-#include "src/gpu/GrAuditTrail.h"
 #include "src/gpu/GrBackendUtils.h"
 #include "src/gpu/GrCaps.h"
 #include "src/gpu/GrDataUtils.h"
diff --git a/src/gpu/GrRecordingContextPriv.h b/src/gpu/GrRecordingContextPriv.h
index 21f5467..8edd06e6 100644
--- a/src/gpu/GrRecordingContextPriv.h
+++ b/src/gpu/GrRecordingContextPriv.h
@@ -73,7 +73,7 @@
      */
     void addOnFlushCallbackObject(GrOnFlushCallbackObject*);
 
-    GrAuditTrail* auditTrail() { return fContext->auditTrail(); }
+    GrAuditTrail* auditTrail() { return fContext->fAuditTrail.get(); }
 
 #if GR_TEST_UTILS
     // Used by tests that intentionally exercise codepaths that print warning messages, in order to
diff --git a/src/gpu/GrSoftwarePathRenderer.cpp b/src/gpu/GrSoftwarePathRenderer.cpp
index 0fe5979..885f377 100644
--- a/src/gpu/GrSoftwarePathRenderer.cpp
+++ b/src/gpu/GrSoftwarePathRenderer.cpp
@@ -225,8 +225,9 @@
 ////////////////////////////////////////////////////////////////////////////////
 // return true on success; false on failure
 bool GrSoftwarePathRenderer::onDrawPath(const DrawPathArgs& args) {
-    GR_AUDIT_TRAIL_AUTO_FRAME(args.fSurfaceDrawContext->auditTrail(),
+    GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(),
                               "GrSoftwarePathRenderer::onDrawPath");
+
     if (!fProxyProvider) {
         return false;
     }
diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp
index 44e25db..33cdd68 100644
--- a/src/gpu/GrSurfaceContext.cpp
+++ b/src/gpu/GrSurfaceContext.cpp
@@ -14,7 +14,6 @@
 #include "src/core/SkAutoPixmapStorage.h"
 #include "src/core/SkMipmap.h"
 #include "src/core/SkYUVMath.h"
-#include "src/gpu/GrAuditTrail.h"
 #include "src/gpu/GrClientMappedBufferManager.h"
 #include "src/gpu/GrColorSpaceXform.h"
 #include "src/gpu/GrDataUtils.h"
@@ -147,10 +146,6 @@
 
 const GrCaps* GrSurfaceContext::caps() const { return fContext->priv().caps(); }
 
-GrAuditTrail* GrSurfaceContext::auditTrail() {
-    return fContext->priv().auditTrail();
-}
-
 GrDrawingManager* GrSurfaceContext::drawingManager() {
     return fContext->priv().drawingManager();
 }
@@ -172,7 +167,8 @@
     ASSERT_SINGLE_OWNER
     RETURN_FALSE_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
-    GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContext::readPixels");
+    GR_CREATE_TRACE_MARKER_CONTEXT("GrSurfaceContext", "readPixels", fContext);
+
     if (!fContext->priv().matches(dContext)) {
         return false;
     }
@@ -421,7 +417,7 @@
                                            const GrCPixmap src[],
                                            int numLevels,
                                            SkIPoint pt) {
-    GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContext::internalWritePixels");
+    GR_CREATE_TRACE_MARKER_CONTEXT("GrSurfaceContext", "internalWritePixels", fContext);
 
     SkASSERT(numLevels >= 1);
     SkASSERT(src);
@@ -1132,7 +1128,7 @@
     ASSERT_SINGLE_OWNER
     RETURN_NULLPTR_IF_ABANDONED
     SkDEBUGCODE(this->validate();)
-    GR_AUDIT_TRAIL_AUTO_FRAME(this->auditTrail(), "GrSurfaceContextPriv::copy");
+    GR_CREATE_TRACE_MARKER_CONTEXT("GrSurfaceContext", "copy", fContext);
 
     const GrCaps* caps = fContext->priv().caps();
 
diff --git a/src/gpu/GrSurfaceContext.h b/src/gpu/GrSurfaceContext.h
index 77bd090..d9946e0 100644
--- a/src/gpu/GrSurfaceContext.h
+++ b/src/gpu/GrSurfaceContext.h
@@ -21,7 +21,6 @@
 #include "src/gpu/GrSurfaceProxy.h"
 #include "src/gpu/GrSurfaceProxyView.h"
 
-class GrAuditTrail;
 class GrDrawingManager;
 class GrRecordingContext;
 class GrRenderTargetProxy;
@@ -191,8 +190,6 @@
                      SkImage::RescaleGamma,
                      SkImage::RescaleMode);
 
-    GrAuditTrail* auditTrail();
-
 #if GR_TEST_UTILS
     bool testCopy(sk_sp<GrSurfaceProxy> src, const SkIRect& srcRect, const SkIPoint& dstPoint) {
         return this->copy(std::move(src), srcRect, dstPoint) != nullptr;
diff --git a/src/gpu/GrSurfaceDrawContext.cpp b/src/gpu/GrSurfaceDrawContext.cpp
index 50ce321..bfcc88c 100644
--- a/src/gpu/GrSurfaceDrawContext.cpp
+++ b/src/gpu/GrSurfaceDrawContext.cpp
@@ -28,7 +28,6 @@
 #include "src/core/SkSurfacePriv.h"
 #include "src/gpu/GrAppliedClip.h"
 #include "src/gpu/GrAttachment.h"
-#include "src/gpu/GrAuditTrail.h"
 #include "src/gpu/GrBlurUtils.h"
 #include "src/gpu/GrCaps.h"
 #include "src/gpu/GrClip.h"
diff --git a/src/gpu/GrTracing.h b/src/gpu/GrTracing.h
index 9e0559b..8b5dbf1 100644
--- a/src/gpu/GrTracing.h
+++ b/src/gpu/GrTracing.h
@@ -18,4 +18,5 @@
 #define GR_CREATE_TRACE_MARKER_CONTEXT(classname, op, context)                            \
     GR_AUDIT_TRAIL_AUTO_FRAME(context->priv().auditTrail(), classname "::" op); \
     TRACE_EVENT0("skia.gpu", classname "::" op)
+
 #endif
diff --git a/src/gpu/ops/GrAAConvexPathRenderer.cpp b/src/gpu/ops/GrAAConvexPathRenderer.cpp
index 660bcc0..e75dfcb 100644
--- a/src/gpu/ops/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/ops/GrAAConvexPathRenderer.cpp
@@ -920,7 +920,7 @@
 }  // anonymous namespace
 
 bool GrAAConvexPathRenderer::onDrawPath(const DrawPathArgs& args) {
-    GR_AUDIT_TRAIL_AUTO_FRAME(args.fSurfaceDrawContext->auditTrail(),
+    GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(),
                               "GrAAConvexPathRenderer::onDrawPath");
     SkASSERT(args.fSurfaceDrawContext->numSamples() <= 1);
     SkASSERT(!args.fShape->isEmpty());
diff --git a/src/gpu/ops/GrAAHairLinePathRenderer.cpp b/src/gpu/ops/GrAAHairLinePathRenderer.cpp
index 6c10f27..6715c54 100644
--- a/src/gpu/ops/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/ops/GrAAHairLinePathRenderer.cpp
@@ -1310,7 +1310,7 @@
 }
 
 bool GrAAHairLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
-    GR_AUDIT_TRAIL_AUTO_FRAME(args.fSurfaceDrawContext->auditTrail(),
+    GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(),
                               "GrAAHairlinePathRenderer::onDrawPath");
     SkASSERT(args.fSurfaceDrawContext->numSamples() <= 1);
 
diff --git a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
index e19b57e..8057528 100644
--- a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
+++ b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
@@ -388,7 +388,7 @@
 }  // anonymous namespace
 
 bool GrAALinearizingConvexPathRenderer::onDrawPath(const DrawPathArgs& args) {
-    GR_AUDIT_TRAIL_AUTO_FRAME(args.fSurfaceDrawContext->auditTrail(),
+    GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(),
                               "GrAALinearizingConvexPathRenderer::onDrawPath");
     SkASSERT(args.fSurfaceDrawContext->numSamples() <= 1);
     SkASSERT(!args.fShape->isEmpty());
diff --git a/src/gpu/ops/GrDashLinePathRenderer.cpp b/src/gpu/ops/GrDashLinePathRenderer.cpp
index d880283..1580ab7 100644
--- a/src/gpu/ops/GrDashLinePathRenderer.cpp
+++ b/src/gpu/ops/GrDashLinePathRenderer.cpp
@@ -29,7 +29,7 @@
 }
 
 bool GrDashLinePathRenderer::onDrawPath(const DrawPathArgs& args) {
-    GR_AUDIT_TRAIL_AUTO_FRAME(args.fSurfaceDrawContext->auditTrail(),
+    GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(),
                               "GrDashLinePathRenderer::onDrawPath");
     GrDashOp::AAMode aaMode;
     switch (args.fAAType) {
diff --git a/src/gpu/ops/GrDefaultPathRenderer.cpp b/src/gpu/ops/GrDefaultPathRenderer.cpp
index 73568c4..c706a94 100644
--- a/src/gpu/ops/GrDefaultPathRenderer.cpp
+++ b/src/gpu/ops/GrDefaultPathRenderer.cpp
@@ -757,7 +757,7 @@
 }
 
 bool GrDefaultPathRenderer::onDrawPath(const DrawPathArgs& args) {
-    GR_AUDIT_TRAIL_AUTO_FRAME(args.fSurfaceDrawContext->auditTrail(),
+    GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(),
                               "GrDefaultPathRenderer::onDrawPath");
     GrAAType aaType = (GrAAType::kNone != args.fAAType) ? GrAAType::kMSAA : GrAAType::kNone;
 
@@ -767,7 +767,7 @@
 }
 
 void GrDefaultPathRenderer::onStencilPath(const StencilPathArgs& args) {
-    GR_AUDIT_TRAIL_AUTO_FRAME(args.fSurfaceDrawContext->auditTrail(),
+    GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(),
                               "GrDefaultPathRenderer::onStencilPath");
     SkASSERT(!args.fShape->inverseFilled());
 
diff --git a/src/gpu/ops/GrSmallPathRenderer.cpp b/src/gpu/ops/GrSmallPathRenderer.cpp
index c2eee7d..9ddbc6a 100644
--- a/src/gpu/ops/GrSmallPathRenderer.cpp
+++ b/src/gpu/ops/GrSmallPathRenderer.cpp
@@ -694,7 +694,7 @@
 };
 
 bool GrSmallPathRenderer::onDrawPath(const DrawPathArgs& args) {
-    GR_AUDIT_TRAIL_AUTO_FRAME(args.fSurfaceDrawContext->auditTrail(),
+    GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(),
                               "GrSmallPathRenderer::onDrawPath");
 
     // we've already bailed on inverse filled paths, so this is safe
diff --git a/src/gpu/ops/GrTriangulatingPathRenderer.cpp b/src/gpu/ops/GrTriangulatingPathRenderer.cpp
index b924238..aada2b0 100644
--- a/src/gpu/ops/GrTriangulatingPathRenderer.cpp
+++ b/src/gpu/ops/GrTriangulatingPathRenderer.cpp
@@ -583,7 +583,7 @@
 }  // anonymous namespace
 
 bool GrTriangulatingPathRenderer::onDrawPath(const DrawPathArgs& args) {
-    GR_AUDIT_TRAIL_AUTO_FRAME(args.fSurfaceDrawContext->auditTrail(),
+    GR_AUDIT_TRAIL_AUTO_FRAME(args.fContext->priv().auditTrail(),
                               "GrTriangulatingPathRenderer::onDrawPath");
 
     GrOp::Owner op = TriangulatingPathOp::Make(
diff --git a/src/gpu/tessellate/GrAtlasRenderTask.cpp b/src/gpu/tessellate/GrAtlasRenderTask.cpp
index 79c0b8b..3defd36 100644
--- a/src/gpu/tessellate/GrAtlasRenderTask.cpp
+++ b/src/gpu/tessellate/GrAtlasRenderTask.cpp
@@ -14,11 +14,12 @@
 #include "src/gpu/ops/GrFillRectOp.h"
 #include "src/gpu/tessellate/GrPathStencilCoverOp.h"
 
-GrAtlasRenderTask::GrAtlasRenderTask(GrRecordingContext* rContext, GrAuditTrail* auditTrail,
+GrAtlasRenderTask::GrAtlasRenderTask(GrRecordingContext* rContext,
                                      sk_sp<GrArenas> arenas,
                                      std::unique_ptr<GrDynamicAtlas> dynamicAtlas)
         : GrOpsTask(rContext->priv().drawingManager(),
-                    dynamicAtlas->writeView(*rContext->priv().caps()), auditTrail,
+                    dynamicAtlas->writeView(*rContext->priv().caps()),
+                    rContext->priv().auditTrail(),
                     std::move(arenas))
         , fDynamicAtlas(std::move(dynamicAtlas)) {
 }
diff --git a/src/gpu/tessellate/GrAtlasRenderTask.h b/src/gpu/tessellate/GrAtlasRenderTask.h
index 8215ec4..4834ea4 100644
--- a/src/gpu/tessellate/GrAtlasRenderTask.h
+++ b/src/gpu/tessellate/GrAtlasRenderTask.h
@@ -22,7 +22,8 @@
 // call instantiate() at flush time.
 class GrAtlasRenderTask : public GrOpsTask {
 public:
-    GrAtlasRenderTask(GrRecordingContext*, GrAuditTrail*, sk_sp<GrArenas>,
+    GrAtlasRenderTask(GrRecordingContext*,
+                      sk_sp<GrArenas>,
                       std::unique_ptr<GrDynamicAtlas>);
 
     const GrTextureProxy* atlasProxy() const { return fDynamicAtlas->textureProxy(); }
diff --git a/src/gpu/tessellate/GrTessellationPathRenderer.cpp b/src/gpu/tessellate/GrTessellationPathRenderer.cpp
index 21d48b8..397bc70 100644
--- a/src/gpu/tessellate/GrTessellationPathRenderer.cpp
+++ b/src/gpu/tessellate/GrTessellationPathRenderer.cpp
@@ -403,7 +403,7 @@
                 kAtlasAlpha8Type, GrDynamicAtlas::InternalMultisample::kYes,
                 SkISize{fAtlasInitialSize, fAtlasInitialSize}, fAtlasMaxSize,
                 *rContext->priv().caps(), kAtlasAlgorithm);
-        auto newAtlasTask = sk_make_sp<GrAtlasRenderTask>(rContext, rContext->priv().auditTrail(),
+        auto newAtlasTask = sk_make_sp<GrAtlasRenderTask>(rContext,
                                                           sk_make_sp<GrArenas>(),
                                                           std::move(dynamicAtlas));
         rContext->priv().drawingManager()->addAtlasTask(newAtlasTask, currentAtlasTask);
diff --git a/tools/debugger/DebugCanvas.cpp b/tools/debugger/DebugCanvas.cpp
index 10be6e2..9298660 100644
--- a/tools/debugger/DebugCanvas.cpp
+++ b/tools/debugger/DebugCanvas.cpp
@@ -17,7 +17,6 @@
 #include "src/core/SkCanvasPriv.h"
 #include "src/core/SkClipOpPriv.h"
 #include "src/core/SkRectPriv.h"
-#include "src/gpu/GrAuditTrail.h"
 #include "src/gpu/GrRecordingContextPriv.h"
 #include "src/gpu/GrSurfaceDrawContext.h"
 #include "src/utils/SkJSONWriter.h"
@@ -26,6 +25,10 @@
 
 #include <string>
 
+#if SK_GPU_V1
+#include "src/gpu/GrAuditTrail.h"
+#endif
+
 #define SKDEBUGCANVAS_VERSION 1
 #define SKDEBUGCANVAS_ATTRIBUTE_VERSION "version"
 #define SKDEBUGCANVAS_ATTRIBUTE_COMMANDS "commands"
@@ -141,6 +144,7 @@
     DebugPaintFilterCanvas filterCanvas(originalCanvas);
     SkCanvas* finalCanvas = fOverdrawViz ? &filterCanvas : originalCanvas;
 
+#if SK_GPU_V1
     auto dContext = GrAsDirectContext(finalCanvas->recordingContext());
 
     // If we have a GPU backend we can also visualize the op information
@@ -149,8 +153,10 @@
         // The audit trail must be obtained from the original canvas.
         at = this->getAuditTrail(originalCanvas);
     }
+#endif
 
     for (int i = 0; i <= index; i++) {
+#if SK_GPU_V1
         GrAuditTrail::AutoCollectOps* acb = nullptr;
         if (at) {
             // We need to flush any pending operations, or they might combine with commands below.
@@ -161,12 +167,15 @@
             }
             acb = new GrAuditTrail::AutoCollectOps(at, i);
         }
+#endif
         if (fCommandVector[i]->isVisible()) {
             fCommandVector[i]->execute(finalCanvas);
         }
+#if SK_GPU_V1
         if (at && acb) {
             delete acb;
         }
+#endif
     }
 
     if (SkColorGetA(fClipVizColor) != 0) {
@@ -196,6 +205,7 @@
         finalCanvas->drawRect(fAndroidClip, androidClipPaint);
     }
 
+#if SK_GPU_V1
     // draw any ops if required and issue a full reset onto GrAuditTrail
     if (at) {
         // just in case there is global reordering, we flush the canvas before querying
@@ -247,8 +257,9 @@
             }
         }
         finalCanvas->restore();
+        this->cleanupAuditTrail(at);
     }
-    this->cleanupAuditTrail(originalCanvas);
+#endif
 }
 
 void DebugCanvas::deleteDrawCommandAt(int index) {
@@ -262,6 +273,7 @@
     return fCommandVector[index];
 }
 
+#if SK_GPU_V1
 GrAuditTrail* DebugCanvas::getAuditTrail(SkCanvas* canvas) {
     GrAuditTrail* at  = nullptr;
     auto ctx = canvas->recordingContext();
@@ -293,21 +305,23 @@
     }
 }
 
-void DebugCanvas::cleanupAuditTrail(SkCanvas* canvas) {
-    GrAuditTrail* at = this->getAuditTrail(canvas);
+void DebugCanvas::cleanupAuditTrail(GrAuditTrail* at) {
     if (at) {
         GrAuditTrail::AutoEnable ae(at);
         at->fullReset();
     }
 }
+#endif
 
 void DebugCanvas::toJSON(SkJSONWriter&   writer,
                          UrlDataManager& urlDataManager,
                          SkCanvas*       canvas) {
+#if SK_GPU_V1
     this->drawAndCollectOps(canvas);
 
     // now collect json
     GrAuditTrail* at = this->getAuditTrail(canvas);
+#endif
     writer.appendS32(SKDEBUGCANVAS_ATTRIBUTE_VERSION, SKDEBUGCANVAS_VERSION);
     writer.beginArray(SKDEBUGCANVAS_ATTRIBUTE_COMMANDS);
 
@@ -315,29 +329,36 @@
         writer.beginObject();  // command
         this->getDrawCommandAt(i)->toJSON(writer, urlDataManager);
 
+#if SK_GPU_V1
         if (at) {
             writer.appendName(SKDEBUGCANVAS_ATTRIBUTE_AUDITTRAIL);
             at->toJson(writer, i);
         }
+#endif
         writer.endObject();  // command
     }
 
     writer.endArray();  // commands
-    this->cleanupAuditTrail(canvas);
+#if SK_GPU_V1
+    this->cleanupAuditTrail(at);
+#endif
 }
 
 void DebugCanvas::toJSONOpsTask(SkJSONWriter& writer, SkCanvas* canvas) {
+#if SK_GPU_V1
     this->drawAndCollectOps(canvas);
 
     GrAuditTrail* at = this->getAuditTrail(canvas);
     if (at) {
         GrAuditTrail::AutoManageOpsTask enable(at);
         at->toJson(writer);
-    } else {
-        writer.beginObject();
-        writer.endObject();
+        this->cleanupAuditTrail(at);
+        return;
     }
-    this->cleanupAuditTrail(canvas);
+#endif
+
+    writer.beginObject();
+    writer.endObject();
 }
 
 void DebugCanvas::setOverdrawViz(bool overdrawViz) { fOverdrawViz = overdrawViz; }
diff --git a/tools/debugger/DebugCanvas.h b/tools/debugger/DebugCanvas.h
index 893dae5..b3bc096 100644
--- a/tools/debugger/DebugCanvas.h
+++ b/tools/debugger/DebugCanvas.h
@@ -231,10 +231,11 @@
      */
     void addDrawCommand(DrawCommand* command);
 
+#if SK_GPU_V1
     GrAuditTrail* getAuditTrail(SkCanvas*);
-
     void drawAndCollectOps(SkCanvas*);
-    void cleanupAuditTrail(SkCanvas*);
+    void cleanupAuditTrail(GrAuditTrail*);
+#endif
 
     using INHERITED = SkCanvasVirtualEnforcer<SkCanvas>;
 };