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 | |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 13 | GrOp::GrOp(uint32_t classID) : fClassID(classID) { |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 14 | SkASSERT(classID == SkToU32(fClassID)); |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 15 | SkASSERT(classID); |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 16 | SkDEBUGCODE(fBoundsFlags = kUninitialized_BoundsFlag); |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 17 | } |
| 18 | |
Herb Derby | e25c300 | 2020-10-27 15:57:27 -0400 | [diff] [blame] | 19 | GrOp::CombineResult GrOp::combineIfPossible(GrOp* that, SkArenaAlloc* alloc, const GrCaps& caps) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 20 | SkASSERT(this != that); |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 21 | if (this->classID() != that->classID()) { |
| 22 | return CombineResult::kCannotCombine; |
| 23 | } |
Herb Derby | e25c300 | 2020-10-27 15:57:27 -0400 | [diff] [blame] | 24 | auto result = this->onCombineIfPossible(that, alloc, caps); |
Brian Salomon | b41417f | 2018-10-24 08:58:48 -0400 | [diff] [blame] | 25 | if (result == CombineResult::kMerged) { |
| 26 | this->joinBounds(*that); |
Brian Salomon | c525d4f | 2018-09-17 15:48:20 -0400 | [diff] [blame] | 27 | } |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 28 | return result; |
| 29 | } |
| 30 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 31 | void GrOp::chainConcat(GrOp::Owner next) { |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 32 | SkASSERT(next); |
| 33 | SkASSERT(this->classID() == next->classID()); |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 34 | SkASSERT(this->isChainTail()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 35 | SkASSERT(next->isChainHead()); |
| 36 | fNextInChain = std::move(next); |
| 37 | fNextInChain->fPrevInChain = this; |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 38 | } |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 39 | |
Herb Derby | c76d409 | 2020-10-07 16:46:15 -0400 | [diff] [blame] | 40 | GrOp::Owner GrOp::cutChain() { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 41 | if (fNextInChain) { |
| 42 | fNextInChain->fPrevInChain = nullptr; |
| 43 | return std::move(fNextInChain); |
| 44 | } |
| 45 | return nullptr; |
| 46 | } |
| 47 | |
| 48 | #ifdef SK_DEBUG |
| 49 | void GrOp::validateChain(GrOp* expectedTail) const { |
| 50 | SkASSERT(this->isChainHead()); |
| 51 | uint32_t classID = this->classID(); |
| 52 | const GrOp* op = this; |
| 53 | while (op) { |
| 54 | SkASSERT(op == this || (op->prevInChain() && op->prevInChain()->nextInChain() == op)); |
| 55 | SkASSERT(classID == op->classID()); |
| 56 | if (op->nextInChain()) { |
| 57 | SkASSERT(op->nextInChain()->prevInChain() == op); |
| 58 | SkASSERT(op != expectedTail); |
| 59 | } else { |
| 60 | SkASSERT(!expectedTail || op == expectedTail); |
| 61 | } |
| 62 | op = op->nextInChain(); |
| 63 | } |
| 64 | } |
| 65 | #endif |