add API for Op creation
Introduce three calls on GrOp: Make, MakeWithExtraMemory,
and MakeWithProcessorSet. Instead of returning
unique_ptr<GrOp>, they return a type of GrOp::OpOwner.
GrOp::OpOwner safely deletes the op when it goes out
of scope for either new/delete or GrOpMemoryPool
allocations.
In order to make the code easier to refactor, I
eliminated MakeArg from the helpers.
Change-Id: Icfd697906f3147a8734575d08bd7195e7517383a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/323778
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/gpu/ops/GrOp.cpp b/src/gpu/ops/GrOp.cpp
index ee2bd11..e635d81 100644
--- a/src/gpu/ops/GrOp.cpp
+++ b/src/gpu/ops/GrOp.cpp
@@ -10,6 +10,15 @@
std::atomic<uint32_t> GrOp::gCurrOpClassID {GrOp::kIllegalOpID + 1};
std::atomic<uint32_t> GrOp::gCurrOpUniqueID{GrOp::kIllegalOpID + 1};
+#if !defined(GR_OP_ALLOCATE_USE_NEW)
+ void GrOp::DeleteFromPool::operator() (GrOp* op) {
+ if (op != nullptr) {
+ op->~GrOp();
+ fPool->release(op);
+ }
+ }
+#endif
+
#if !defined(GR_OP_ALLOCATE_USE_NEW) && defined(SK_DEBUG)
void* GrOp::operator new(size_t size) {
// All GrOp-derived class should be allocated in a GrMemoryPool
@@ -43,7 +52,7 @@
return result;
}
-void GrOp::chainConcat(std::unique_ptr<GrOp> next) {
+void GrOp::chainConcat(GrOp::Owner next) {
SkASSERT(next);
SkASSERT(this->classID() == next->classID());
SkASSERT(this->isChainTail());
@@ -52,7 +61,7 @@
fNextInChain->fPrevInChain = this;
}
-std::unique_ptr<GrOp> GrOp::cutChain() {
+GrOp::Owner GrOp::cutChain() {
if (fNextInChain) {
fNextInChain->fPrevInChain = nullptr;
return std::move(fNextInChain);