Move auditTrail and opMemoryPool from GrContext to GrRecordingContext

Any context that records ops (i.e., direct and/or DDL) will need these two objects.

Change-Id: Ifd3527c23a4015f7d469ad2222563508cccbd339
Reviewed-on: https://skia-review.googlesource.com/c/190307
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 290e959..67319d5 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -11,7 +11,6 @@
 #include "SkMatrix.h"
 #include "SkPathEffect.h"
 #include "SkTypes.h"
-#include "../private/GrAuditTrail.h"
 #include "../private/GrRecordingContext.h"
 #include "GrContextOptions.h"
 
@@ -30,7 +29,6 @@
 class GrStrikeCache;
 class GrGpu;
 struct GrMockOptions;
-class GrOpMemoryPool;
 class GrPath;
 class GrRenderTargetContext;
 class GrResourceCache;
@@ -298,10 +296,7 @@
     GrResourceCache*                        fResourceCache;
     GrResourceProvider*                     fResourceProvider;
 
-    // All the GrOp-derived classes use this pool.
-    sk_sp<GrOpMemoryPool>                   fOpMemoryPool;
-
-    GrStrikeCache*                           fGlyphCache;
+    GrStrikeCache*                          fGlyphCache;
     std::unique_ptr<GrTextBlobCache>        fTextBlobCache;
 
     bool                                    fDidTestPMConversions;
@@ -310,8 +305,6 @@
 
     std::unique_ptr<GrDrawingManager>       fDrawingManager;
 
-    GrAuditTrail                            fAuditTrail;
-
     GrContextOptions::PersistentCache*      fPersistentCache;
 
     // TODO: have the GrClipStackClip use renderTargetContexts and rm this friending
diff --git a/include/private/GrRecordingContext.h b/include/private/GrRecordingContext.h
index e75c450..42ef747 100644
--- a/include/private/GrRecordingContext.h
+++ b/include/private/GrRecordingContext.h
@@ -8,8 +8,10 @@
 #ifndef GrRecordingContext_DEFINED
 #define GrRecordingContext_DEFINED
 
+#include "GrAuditTrail.h"
 #include "GrImageContext.h"
 
+class GrOpMemoryPool;
 class GrRecordingContextPriv;
 
 class SK_API GrRecordingContext : public GrImageContext {
@@ -25,9 +27,18 @@
 
     GrRecordingContext(GrBackendApi, const GrContextOptions&, uint32_t contextID);
 
+    sk_sp<GrOpMemoryPool> refOpMemoryPool();
+    GrOpMemoryPool* opMemoryPool();
+
+    GrAuditTrail* auditTrail() { return &fAuditTrail; }
+
     GrRecordingContext* asRecordingContext() override { return this; }
 
 private:
+    // All the GrOp-derived classes use this pool.
+    sk_sp<GrOpMemoryPool> fOpMemoryPool;
+    GrAuditTrail          fAuditTrail;
+
     typedef GrImageContext INHERITED;
 };
 
diff --git a/src/gpu/GrContextPriv.cpp b/src/gpu/GrContextPriv.cpp
index 5dbbe30..d9d969c 100644
--- a/src/gpu/GrContextPriv.cpp
+++ b/src/gpu/GrContextPriv.cpp
@@ -40,19 +40,7 @@
 }
 
 sk_sp<GrOpMemoryPool> GrContextPriv::refOpMemoryPool() {
-    if (!fContext->fOpMemoryPool) {
-        // DDL TODO: should the size of the memory pool be decreased in DDL mode? CPU-side memory
-        // consumed in DDL mode vs. normal mode for a single skp might be a good metric of wasted
-        // memory.
-        fContext->fOpMemoryPool = sk_sp<GrOpMemoryPool>(new GrOpMemoryPool(16384, 16384));
-    }
-
-    SkASSERT(fContext->fOpMemoryPool);
-    return fContext->fOpMemoryPool;
-}
-
-GrOpMemoryPool* GrContextPriv::opMemoryPool() {
-    return this->refOpMemoryPool().get();
+    return fContext->refOpMemoryPool();
 }
 
 sk_sp<GrSurfaceContext> GrContextPriv::makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy> proxy,
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index 9db268b..982656e 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -53,15 +53,16 @@
     SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } )
 
     // from GrRecordingContext
+    sk_sp<GrOpMemoryPool> refOpMemoryPool();
+    GrOpMemoryPool* opMemoryPool() { return fContext->opMemoryPool(); }
+
+    GrAuditTrail* auditTrail() { return fContext->auditTrail(); }
 
     /**
      * Create a GrContext without a resource cache
      */
     static sk_sp<GrContext> MakeDDL(const sk_sp<GrContextThreadSafeProxy>&);
 
-    sk_sp<GrOpMemoryPool> refOpMemoryPool();
-    GrOpMemoryPool* opMemoryPool();
-
     GrDrawingManager* drawingManager() { return fContext->fDrawingManager.get(); }
 
     sk_sp<GrSurfaceContext> makeWrappedSurfaceContext(sk_sp<GrSurfaceProxy>,
@@ -264,8 +265,6 @@
                                                  const SkSurfaceProps* surfaceProps = nullptr,
                                                  SkBudgeted budgeted = SkBudgeted::kYes);
 
-    GrAuditTrail* getAuditTrail() { return &fContext->fAuditTrail; }
-
     GrContextOptions::PersistentCache* getPersistentCache() { return fContext->fPersistentCache; }
 
 #ifdef SK_ENABLE_DUMP_GPU
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index 29c72d1..f63c7e8 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -598,7 +598,7 @@
                                                         resourceProvider,
                                                         fContext->priv().refOpMemoryPool(),
                                                         rtp,
-                                                        fContext->priv().getAuditTrail()));
+                                                        fContext->priv().auditTrail()));
     SkASSERT(rtp->getLastOpList() == opList.get());
 
     if (managedOpList) {
@@ -638,7 +638,7 @@
     sk_sp<GrTextureOpList> opList(new GrTextureOpList(fContext->priv().resourceProvider(),
                                                       fContext->priv().refOpMemoryPool(),
                                                       textureProxy,
-                                                      fContext->priv().getAuditTrail()));
+                                                      fContext->priv().auditTrail()));
 
     SkASSERT(textureProxy->getLastOpList() == opList.get());
 
@@ -731,7 +731,7 @@
                                                         fContext, this, std::move(rtp),
                                                         std::move(colorSpace),
                                                         surfaceProps,
-                                                        fContext->priv().getAuditTrail(),
+                                                        fContext->priv().auditTrail(),
                                                         fSingleOwner, managedOpList));
 }
 
@@ -755,6 +755,6 @@
 
     return sk_sp<GrTextureContext>(new GrTextureContext(fContext, this, std::move(textureProxy),
                                                         std::move(colorSpace),
-                                                        fContext->priv().getAuditTrail(),
+                                                        fContext->priv().auditTrail(),
                                                         fSingleOwner));
 }
diff --git a/src/gpu/GrRecordingContext.cpp b/src/gpu/GrRecordingContext.cpp
index 1067950..6edfd65 100644
--- a/src/gpu/GrRecordingContext.cpp
+++ b/src/gpu/GrRecordingContext.cpp
@@ -8,6 +8,7 @@
 #include "GrRecordingContext.h"
 
 #include "GrCaps.h"
+#include "GrMemoryPool.h"
 #include "GrRecordingContextPriv.h"
 #include "GrSkSLFPFactoryCache.h"
 
@@ -19,6 +20,23 @@
 
 GrRecordingContext::~GrRecordingContext() { }
 
+sk_sp<GrOpMemoryPool> GrRecordingContext::refOpMemoryPool() {
+    if (!fOpMemoryPool) {
+        // DDL TODO: should the size of the memory pool be decreased in DDL mode? CPU-side memory
+        // consumed in DDL mode vs. normal mode for a single skp might be a good metric of wasted
+        // memory.
+        fOpMemoryPool = sk_sp<GrOpMemoryPool>(new GrOpMemoryPool(16384, 16384));
+    }
+
+    SkASSERT(fOpMemoryPool);
+    return fOpMemoryPool;
+}
+
+GrOpMemoryPool* GrRecordingContext::opMemoryPool() {
+    return this->refOpMemoryPool().get();
+}
+
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 sk_sp<const GrCaps> GrRecordingContextPriv::refCaps() const {
     return fContext->refCaps();
@@ -27,3 +45,7 @@
 sk_sp<GrSkSLFPFactoryCache> GrRecordingContextPriv::fpFactoryCache() {
     return fContext->fpFactoryCache();
 }
+
+sk_sp<GrOpMemoryPool> GrRecordingContextPriv::refOpMemoryPool() {
+    return fContext->refOpMemoryPool();
+}
diff --git a/src/gpu/GrRecordingContextPriv.h b/src/gpu/GrRecordingContextPriv.h
index 92eadb0..c264eaa 100644
--- a/src/gpu/GrRecordingContextPriv.h
+++ b/src/gpu/GrRecordingContextPriv.h
@@ -39,6 +39,10 @@
     SkDEBUGCODE(GrSingleOwner* singleOwner() const { return fContext->singleOwner(); } )
 
     // from GrRecordingContext
+    sk_sp<GrOpMemoryPool> refOpMemoryPool();
+    GrOpMemoryPool* opMemoryPool() { return fContext->opMemoryPool(); }
+
+    GrAuditTrail* auditTrail() { return fContext->auditTrail(); }
 
 private:
     explicit GrRecordingContextPriv(GrRecordingContext* context) : fContext(context) {}
diff --git a/src/gpu/GrTracing.h b/src/gpu/GrTracing.h
index 82c6f8d..64adf1d 100644
--- a/src/gpu/GrTracing.h
+++ b/src/gpu/GrTracing.h
@@ -16,7 +16,7 @@
  * Context level GrTracing macros, classname and op are const char*, context is GrContext
  */
 #define GR_CREATE_TRACE_MARKER_CONTEXT(classname, op, context)                            \
-    GR_AUDIT_TRAIL_AUTO_FRAME(context->priv().getAuditTrail(), classname "::" op); \
+    GR_AUDIT_TRAIL_AUTO_FRAME(context->priv().auditTrail(), classname "::" op); \
     TRACE_EVENT0("skia.gpu", classname "::" op)
 
 #endif
diff --git a/tests/OpChainTest.cpp b/tests/OpChainTest.cpp
index 3c2f9e1..a7bd46b 100644
--- a/tests/OpChainTest.cpp
+++ b/tests/OpChainTest.cpp
@@ -207,7 +207,7 @@
                 GrRenderTargetOpList opList(context->priv().resourceProvider(),
                                             sk_ref_sp(context->priv().opMemoryPool()),
                                             proxy->asRenderTargetProxy(),
-                                            context->priv().getAuditTrail());
+                                            context->priv().auditTrail());
                 // This assumes the particular values of kRanges.
                 std::fill_n(result, result_width(), -1);
                 std::fill_n(validResult, result_width(), -1);
diff --git a/tools/debugger/SkDebugCanvas.cpp b/tools/debugger/SkDebugCanvas.cpp
index cbb420c..3a4522f 100644
--- a/tools/debugger/SkDebugCanvas.cpp
+++ b/tools/debugger/SkDebugCanvas.cpp
@@ -218,7 +218,7 @@
     GrAuditTrail* at = nullptr;
     GrContext* ctx = canvas->getGrContext();
     if (ctx) {
-        at = ctx->priv().getAuditTrail();
+        at = ctx->priv().auditTrail();
     }
     return at;
 }