blob: 994cddfd8062261a435b9b84c3897e0e209d34b3 [file] [log] [blame]
joshualitt23ac62c2015-03-30 09:53:47 -07001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/ops/GrOp.h"
joshualitt4d8da812015-01-28 12:53:54 -08009
Mike Klein0ec1c572018-12-04 11:52:51 -050010std::atomic<uint32_t> GrOp::gCurrOpClassID {GrOp::kIllegalOpID + 1};
11std::atomic<uint32_t> GrOp::gCurrOpUniqueID{GrOp::kIllegalOpID + 1};
joshualitt4d8da812015-01-28 12:53:54 -080012
Brian Salomond25f5bc2018-08-08 11:25:17 -040013GrOp::GrOp(uint32_t classID) : fClassID(classID) {
bsalomon88cf17d2016-07-08 06:40:56 -070014 SkASSERT(classID == SkToU32(fClassID));
Brian Salomond25f5bc2018-08-08 11:25:17 -040015 SkASSERT(classID);
bsalomon88cf17d2016-07-08 06:40:56 -070016 SkDEBUGCODE(fBoundsFlags = kUninitialized_BoundsFlag);
bsalomona387a112015-08-11 14:47:42 -070017}
18
Herb Derbye25c3002020-10-27 15:57:27 -040019GrOp::CombineResult GrOp::combineIfPossible(GrOp* that, SkArenaAlloc* alloc, const GrCaps& caps) {
Brian Salomon588cec72018-11-14 13:56:37 -050020 SkASSERT(this != that);
Brian Salomond25f5bc2018-08-08 11:25:17 -040021 if (this->classID() != that->classID()) {
22 return CombineResult::kCannotCombine;
23 }
Herb Derbye25c3002020-10-27 15:57:27 -040024 auto result = this->onCombineIfPossible(that, alloc, caps);
Brian Salomonb41417f2018-10-24 08:58:48 -040025 if (result == CombineResult::kMerged) {
26 this->joinBounds(*that);
Brian Salomonc525d4f2018-09-17 15:48:20 -040027 }
Brian Salomond25f5bc2018-08-08 11:25:17 -040028 return result;
29}
30
Herb Derbyc76d4092020-10-07 16:46:15 -040031void GrOp::chainConcat(GrOp::Owner next) {
Brian Salomond25f5bc2018-08-08 11:25:17 -040032 SkASSERT(next);
33 SkASSERT(this->classID() == next->classID());
Brian Salomond25f5bc2018-08-08 11:25:17 -040034 SkASSERT(this->isChainTail());
Brian Salomon588cec72018-11-14 13:56:37 -050035 SkASSERT(next->isChainHead());
36 fNextInChain = std::move(next);
37 fNextInChain->fPrevInChain = this;
Brian Salomond25f5bc2018-08-08 11:25:17 -040038}
Brian Salomon588cec72018-11-14 13:56:37 -050039
Herb Derbyc76d4092020-10-07 16:46:15 -040040GrOp::Owner GrOp::cutChain() {
Brian Salomon588cec72018-11-14 13:56:37 -050041 if (fNextInChain) {
42 fNextInChain->fPrevInChain = nullptr;
43 return std::move(fNextInChain);
44 }
45 return nullptr;
46}
47
48#ifdef SK_DEBUG
49void 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