Add flag to switch op allocation to new

Added a flag to switch from using the memory pool to
using new and delete for GrOp allocation.

Just add the following to your gn args.
extra_cflags = [
    "-DGR_OP_ALLOCATE_USE_NEW",
]

Change-Id: Icea4a6df047cff2cd5e50032f0bd4b714a5740d4
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322625
Commit-Queue: Herb Derby <herb@google.com>
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrOpsTask.cpp b/src/gpu/GrOpsTask.cpp
index 64145d4..65241cd 100644
--- a/src/gpu/GrOpsTask.cpp
+++ b/src/gpu/GrOpsTask.cpp
@@ -154,7 +154,12 @@
 
 void GrOpsTask::OpChain::deleteOps(GrOpMemoryPool* pool) {
     while (!fList.empty()) {
-        pool->release(fList.popHead());
+        #if defined(GR_OP_ALLOCATE_USE_NEW)
+            // Since the value goes out of scope immediately, the unique_ptr deletes the op.
+            fList.popHead();
+        #else
+            pool->release(fList.popHead());
+        #endif
     }
 }
 
@@ -197,7 +202,12 @@
             if (merged) {
                 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, a, chainB.head());
                 if (canBackwardMerge) {
-                    arenas->opMemoryPool()->release(chainB.popHead());
+                    #if defined(GR_OP_ALLOCATE_USE_NEW)
+                        // The unique_ptr releases the op.
+                        chainB.popHead();
+                    #else
+                        arenas->opMemoryPool()->release(chainB.popHead());
+                    #endif
                 } else {
                     // We merged the contents of b's head into a. We will replace b's head with a in
                     // chain b.
@@ -206,7 +216,12 @@
                         origATail = a->prevInChain();
                     }
                     std::unique_ptr<GrOp> detachedA = chainA.removeOp(a);
-                    arenas->opMemoryPool()->release(chainB.popHead());
+                    #if defined(GR_OP_ALLOCATE_USE_NEW)
+                        // The unique_ptr releases the op.
+                        chainB.popHead();
+                    #else
+                        arenas->opMemoryPool()->release(chainB.popHead());
+                    #endif
                     chainB.pushHead(std::move(detachedA));
                     if (chainA.empty()) {
                         // We merged all the nodes in chain a to chain b.
@@ -282,7 +297,12 @@
                           list->tail()->name(), list->tail()->uniqueID(), list->head()->name(),
                           list->head()->uniqueID());
                 GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head());
-                arenas->opMemoryPool()->release(list->popHead());
+                #if defined(GR_OP_ALLOCATE_USE_NEW)
+                    // The unique_ptr releases the op.
+                    list->popHead();
+                #else
+                    arenas->opMemoryPool()->release(list->popHead());
+                #endif
                 break;
             }
         }
@@ -796,7 +816,9 @@
     // A closed GrOpsTask should never receive new/more ops
     SkASSERT(!this->isClosed());
     if (!op->bounds().isFinite()) {
-        fArenas.opMemoryPool()->release(std::move(op));
+        #if !defined(GR_OP_ALLOCATE_USE_NEW)
+            fArenas.opMemoryPool()->release(std::move(op));
+        #endif
         return;
     }