blob: f115d4ca1a8ebfbd2bb7fe89fb3720498658147a [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
Herb Derbye25c3002020-10-27 15:57:27 -040042GrOp::CombineResult GrOp::combineIfPossible(GrOp* that, SkArenaAlloc* alloc, const GrCaps& caps) {
Brian Salomon588cec72018-11-14 13:56:37 -050043 SkASSERT(this != that);
Brian Salomond25f5bc2018-08-08 11:25:17 -040044 if (this->classID() != that->classID()) {
45 return CombineResult::kCannotCombine;
46 }
Herb Derbye25c3002020-10-27 15:57:27 -040047 auto result = this->onCombineIfPossible(that, alloc, caps);
Brian Salomonb41417f2018-10-24 08:58:48 -040048 if (result == CombineResult::kMerged) {
49 this->joinBounds(*that);
Brian Salomonc525d4f2018-09-17 15:48:20 -040050 }
Brian Salomond25f5bc2018-08-08 11:25:17 -040051 return result;
52}
53
Herb Derbyc76d4092020-10-07 16:46:15 -040054void GrOp::chainConcat(GrOp::Owner next) {
Brian Salomond25f5bc2018-08-08 11:25:17 -040055 SkASSERT(next);
56 SkASSERT(this->classID() == next->classID());
Brian Salomond25f5bc2018-08-08 11:25:17 -040057 SkASSERT(this->isChainTail());
Brian Salomon588cec72018-11-14 13:56:37 -050058 SkASSERT(next->isChainHead());
59 fNextInChain = std::move(next);
60 fNextInChain->fPrevInChain = this;
Brian Salomond25f5bc2018-08-08 11:25:17 -040061}
Brian Salomon588cec72018-11-14 13:56:37 -050062
Herb Derbyc76d4092020-10-07 16:46:15 -040063GrOp::Owner GrOp::cutChain() {
Brian Salomon588cec72018-11-14 13:56:37 -050064 if (fNextInChain) {
65 fNextInChain->fPrevInChain = nullptr;
66 return std::move(fNextInChain);
67 }
68 return nullptr;
69}
70
71#ifdef SK_DEBUG
72void GrOp::validateChain(GrOp* expectedTail) const {
73 SkASSERT(this->isChainHead());
74 uint32_t classID = this->classID();
75 const GrOp* op = this;
76 while (op) {
77 SkASSERT(op == this || (op->prevInChain() && op->prevInChain()->nextInChain() == op));
78 SkASSERT(classID == op->classID());
79 if (op->nextInChain()) {
80 SkASSERT(op->nextInChain()->prevInChain() == op);
81 SkASSERT(op != expectedTail);
82 } else {
83 SkASSERT(!expectedTail || op == expectedTail);
84 }
85 op = op->nextInChain();
86 }
87}
88#endif