Plumb GrContext everywhere

There is no good way to split the monster CL up. This breaks out
the GrContext plumbing but doesn't use it.

Change-Id: I90856d428d372bcec3f8821e6364667b367927d4
Reviewed-on: https://skia-review.googlesource.com/133382
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrMemoryPool.h b/src/gpu/GrMemoryPool.h
index 825b83a..67991d3 100644
--- a/src/gpu/GrMemoryPool.h
+++ b/src/gpu/GrMemoryPool.h
@@ -9,6 +9,9 @@
 #define GrMemoryPool_DEFINED
 
 #include "GrTypes.h"
+
+#include "SkRefCnt.h"
+
 #ifdef SK_DEBUG
 #include "SkTHash.h"
 #endif
@@ -121,4 +124,30 @@
     };
 };
 
+class GrOp;
+
+// DDL TODO: for the DLL use case this could probably be the non-intrinsic-based style of
+// ref counting
+class GrOpMemoryPool : public SkRefCnt {
+public:
+    GrOpMemoryPool(size_t preallocSize, size_t minAllocSize)
+            : fMemoryPool(preallocSize, minAllocSize) {
+    }
+
+    template <typename Op, typename... OpArgs>
+    std::unique_ptr<Op> allocate(OpArgs&&... opArgs) {
+        char* mem = (char*) fMemoryPool.allocate(sizeof(Op));
+        return std::unique_ptr<Op>(new (mem) Op(std::forward<OpArgs>(opArgs)...));
+    }
+
+    void* allocate(size_t size) {
+        return fMemoryPool.allocate(size);
+    }
+
+    void release(std::unique_ptr<GrOp> op);
+
+private:
+    GrMemoryPool fMemoryPool;
+};
+
 #endif