| 1 | /* |
|---|---|
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "src/gpu/ops/GrOp.h" |
| 9 | |
| 10 | std::atomic<uint32_t> GrOp::gCurrOpClassID {GrOp::kIllegalOpID + 1}; |
| 11 | std::atomic<uint32_t> GrOp::gCurrOpUniqueID{GrOp::kIllegalOpID + 1}; |
| 12 | |
| 13 | #ifdef SK_DEBUG |
| 14 | void* GrOp::operator new(size_t size) { |
| 15 | // All GrOp-derived class should be allocated in a GrMemoryPool |
| 16 | SkASSERT(0); |
| 17 | return ::operator new(size); |
| 18 | } |
| 19 | |
| 20 | void GrOp::operator delete(void* target) { |
| 21 | // All GrOp-derived class should be released from their owning GrMemoryPool |
| 22 | SkASSERT(0); |
| 23 | ::operator delete(target); |
| 24 | } |
| 25 | #endif |
| 26 | |
| 27 | GrOp::GrOp(uint32_t classID) : fClassID(classID) { |
| 28 | SkASSERT(classID == SkToU32(fClassID)); |
| 29 | SkASSERT(classID); |
| 30 | SkDEBUGCODE(fBoundsFlags = kUninitialized_BoundsFlag); |
| 31 | } |
| 32 | |
| 33 | GrOp::CombineResult GrOp::combineIfPossible(GrOp* that, GrRecordingContext::Arenas* arenas, |
| 34 | const GrCaps& caps) { |
| 35 | SkASSERT(this != that); |
| 36 | if (this->classID() != that->classID()) { |
| 37 | return CombineResult::kCannotCombine; |
| 38 | } |
| 39 | auto result = this->onCombineIfPossible(that, arenas, caps); |
| 40 | if (result == CombineResult::kMerged) { |
| 41 | this->joinBounds(*that); |
| 42 | } |
| 43 | return result; |
| 44 | } |
| 45 | |
| 46 | void GrOp::chainConcat(std::unique_ptr<GrOp> next) { |
| 47 | SkASSERT(next); |
| 48 | SkASSERT(this->classID() == next->classID()); |
| 49 | SkASSERT(this->isChainTail()); |
| 50 | SkASSERT(next->isChainHead()); |
| 51 | fNextInChain = std::move(next); |
| 52 | fNextInChain->fPrevInChain = this; |
| 53 | } |
| 54 | |
| 55 | std::unique_ptr<GrOp> GrOp::cutChain() { |
| 56 | if (fNextInChain) { |
| 57 | fNextInChain->fPrevInChain = nullptr; |
| 58 | return std::move(fNextInChain); |
| 59 | } |
| 60 | return nullptr; |
| 61 | } |
| 62 | |
| 63 | #ifdef SK_DEBUG |
| 64 | void GrOp::validateChain(GrOp* expectedTail) const { |
| 65 | SkASSERT(this->isChainHead()); |
| 66 | uint32_t classID = this->classID(); |
| 67 | const GrOp* op = this; |
| 68 | while (op) { |
| 69 | SkASSERT(op == this || (op->prevInChain() && op->prevInChain()->nextInChain() == op)); |
| 70 | SkASSERT(classID == op->classID()); |
| 71 | if (op->nextInChain()) { |
| 72 | SkASSERT(op->nextInChain()->prevInChain() == op); |
| 73 | SkASSERT(op != expectedTail); |
| 74 | } else { |
| 75 | SkASSERT(!expectedTail || op == expectedTail); |
| 76 | } |
| 77 | op = op->nextInChain(); |
| 78 | } |
| 79 | } |
| 80 | #endif |
| 81 |