blob: e635d81e72170e6236c34683071b74d8f87fe00d [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
Herb Derbyc76d4092020-10-07 16:46:15 -040013#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 Derbyd6cfe722020-10-05 15:50:47 -040022#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 }
joshualitt4d8da812015-01-28 12:53:54 -080028
Herb Derbyd6cfe722020-10-05 15:50:47 -040029 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 Phillipsc994a932018-06-19 13:09:54 -040034#endif
bsalomonb5238a72015-05-05 07:49:49 -070035
Brian Salomond25f5bc2018-08-08 11:25:17 -040036GrOp::GrOp(uint32_t classID) : fClassID(classID) {
bsalomon88cf17d2016-07-08 06:40:56 -070037 SkASSERT(classID == SkToU32(fClassID));
Brian Salomond25f5bc2018-08-08 11:25:17 -040038 SkASSERT(classID);
bsalomon88cf17d2016-07-08 06:40:56 -070039 SkDEBUGCODE(fBoundsFlags = kUninitialized_BoundsFlag);
bsalomona387a112015-08-11 14:47:42 -070040}
41
Michael Ludwig28b0c5d2019-12-19 14:51:00 -050042GrOp::CombineResult GrOp::combineIfPossible(GrOp* that, GrRecordingContext::Arenas* arenas,
43 const GrCaps& caps) {
Brian Salomon588cec72018-11-14 13:56:37 -050044 SkASSERT(this != that);
Brian Salomond25f5bc2018-08-08 11:25:17 -040045 if (this->classID() != that->classID()) {
46 return CombineResult::kCannotCombine;
47 }
Michael Ludwig28b0c5d2019-12-19 14:51:00 -050048 auto result = this->onCombineIfPossible(that, arenas, caps);
Brian Salomonb41417f2018-10-24 08:58:48 -040049 if (result == CombineResult::kMerged) {
50 this->joinBounds(*that);
Brian Salomonc525d4f2018-09-17 15:48:20 -040051 }
Brian Salomond25f5bc2018-08-08 11:25:17 -040052 return result;
53}
54
Herb Derbyc76d4092020-10-07 16:46:15 -040055void GrOp::chainConcat(GrOp::Owner next) {
Brian Salomond25f5bc2018-08-08 11:25:17 -040056 SkASSERT(next);
57 SkASSERT(this->classID() == next->classID());
Brian Salomond25f5bc2018-08-08 11:25:17 -040058 SkASSERT(this->isChainTail());
Brian Salomon588cec72018-11-14 13:56:37 -050059 SkASSERT(next->isChainHead());
60 fNextInChain = std::move(next);
61 fNextInChain->fPrevInChain = this;
Brian Salomond25f5bc2018-08-08 11:25:17 -040062}
Brian Salomon588cec72018-11-14 13:56:37 -050063
Herb Derbyc76d4092020-10-07 16:46:15 -040064GrOp::Owner GrOp::cutChain() {
Brian Salomon588cec72018-11-14 13:56:37 -050065 if (fNextInChain) {
66 fNextInChain->fPrevInChain = nullptr;
67 return std::move(fNextInChain);
68 }
69 return nullptr;
70}
71
72#ifdef SK_DEBUG
73void 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