joshualitt | 23ac62c | 2015-03-30 09:53:47 -0700 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/ops/GrOp.h" |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 9 | |
Mike Klein | 0ec1c57 | 2018-12-04 11:52:51 -0500 | [diff] [blame] | 10 | std::atomic<uint32_t> GrOp::gCurrOpClassID {GrOp::kIllegalOpID + 1}; |
| 11 | std::atomic<uint32_t> GrOp::gCurrOpUniqueID{GrOp::kIllegalOpID + 1}; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 12 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame^] | 13 | #if !defined(GR_OP_ALLOCATE_USE_NEW) |
| 14 | void GrOp::DeleteFromPool::operator() (GrOp* op) { |
| 15 | if (op != nullptr) { |
| 16 | op->~GrOp(); |
| 17 | fPool->release(op); |
| 18 | } |
| 19 | } |
| 20 | #endif |
| 21 | |
Herb Derby | d6cfe72 | 2020-10-05 15:50:47 -0400 | [diff] [blame] | 22 | #if !defined(GR_OP_ALLOCATE_USE_NEW) && defined(SK_DEBUG) |
| 23 | void* GrOp::operator new(size_t size) { |
| 24 | // All GrOp-derived class should be allocated in a GrMemoryPool |
| 25 | SkASSERT(0); |
| 26 | return ::operator new(size); |
| 27 | } |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 28 | |
Herb Derby | d6cfe72 | 2020-10-05 15:50:47 -0400 | [diff] [blame] | 29 | void GrOp::operator delete(void* target) { |
| 30 | // All GrOp-derived class should be released from their owning GrMemoryPool |
| 31 | SkASSERT(0); |
| 32 | ::operator delete(target); |
| 33 | } |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 34 | #endif |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 35 | |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 36 | GrOp::GrOp(uint32_t classID) : fClassID(classID) { |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 37 | SkASSERT(classID == SkToU32(fClassID)); |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 38 | SkASSERT(classID); |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 39 | SkDEBUGCODE(fBoundsFlags = kUninitialized_BoundsFlag); |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 42 | GrOp::CombineResult GrOp::combineIfPossible(GrOp* that, GrRecordingContext::Arenas* arenas, |
| 43 | const GrCaps& caps) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 44 | SkASSERT(this != that); |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 45 | if (this->classID() != that->classID()) { |
| 46 | return CombineResult::kCannotCombine; |
| 47 | } |
Michael Ludwig | 28b0c5d | 2019-12-19 14:51:00 -0500 | [diff] [blame] | 48 | auto result = this->onCombineIfPossible(that, arenas, caps); |
Brian Salomon | b41417f | 2018-10-24 08:58:48 -0400 | [diff] [blame] | 49 | if (result == CombineResult::kMerged) { |
| 50 | this->joinBounds(*that); |
Brian Salomon | c525d4f | 2018-09-17 15:48:20 -0400 | [diff] [blame] | 51 | } |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 52 | return result; |
| 53 | } |
| 54 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame^] | 55 | void GrOp::chainConcat(GrOp::Owner next) { |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 56 | SkASSERT(next); |
| 57 | SkASSERT(this->classID() == next->classID()); |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 58 | SkASSERT(this->isChainTail()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 59 | SkASSERT(next->isChainHead()); |
| 60 | fNextInChain = std::move(next); |
| 61 | fNextInChain->fPrevInChain = this; |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 62 | } |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 63 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame^] | 64 | GrOp::Owner GrOp::cutChain() { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 65 | if (fNextInChain) { |
| 66 | fNextInChain->fPrevInChain = nullptr; |
| 67 | return std::move(fNextInChain); |
| 68 | } |
| 69 | return nullptr; |
| 70 | } |
| 71 | |
| 72 | #ifdef SK_DEBUG |
| 73 | void GrOp::validateChain(GrOp* expectedTail) const { |
| 74 | SkASSERT(this->isChainHead()); |
| 75 | uint32_t classID = this->classID(); |
| 76 | const GrOp* op = this; |
| 77 | while (op) { |
| 78 | SkASSERT(op == this || (op->prevInChain() && op->prevInChain()->nextInChain() == op)); |
| 79 | SkASSERT(classID == op->classID()); |
| 80 | if (op->nextInChain()) { |
| 81 | SkASSERT(op->nextInChain()->prevInChain() == op); |
| 82 | SkASSERT(op != expectedTail); |
| 83 | } else { |
| 84 | SkASSERT(!expectedTail || op == expectedTail); |
| 85 | } |
| 86 | op = op->nextInChain(); |
| 87 | } |
| 88 | } |
| 89 | #endif |