blob: b8a0031cfd43f757680b1a0e360a92c811cf0b94 [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
Brian Salomon25a88092016-12-01 09:36:50 -05008#include "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
Robert Phillipsc994a932018-06-19 13:09:54 -040013#ifdef SK_DEBUG
Brian Salomon25a88092016-12-01 09:36:50 -050014void* GrOp::operator new(size_t size) {
Robert Phillipsc994a932018-06-19 13:09:54 -040015 // All GrOp-derived class should be allocated in a GrMemoryPool
16 SkASSERT(0);
17 return ::operator new(size);
joshualitt4d8da812015-01-28 12:53:54 -080018}
19
Brian Salomon25a88092016-12-01 09:36:50 -050020void GrOp::operator delete(void* target) {
Robert Phillipsc994a932018-06-19 13:09:54 -040021 // All GrOp-derived class should be released from their owning GrMemoryPool
22 SkASSERT(0);
23 ::operator delete(target);
joshualitt4d8da812015-01-28 12:53:54 -080024}
Robert Phillipsc994a932018-06-19 13:09:54 -040025#endif
bsalomonb5238a72015-05-05 07:49:49 -070026
Brian Salomond25f5bc2018-08-08 11:25:17 -040027GrOp::GrOp(uint32_t classID) : fClassID(classID) {
bsalomon88cf17d2016-07-08 06:40:56 -070028 SkASSERT(classID == SkToU32(fClassID));
Brian Salomond25f5bc2018-08-08 11:25:17 -040029 SkASSERT(classID);
bsalomon88cf17d2016-07-08 06:40:56 -070030 SkDEBUGCODE(fBoundsFlags = kUninitialized_BoundsFlag);
bsalomona387a112015-08-11 14:47:42 -070031}
32
Brian Salomond25f5bc2018-08-08 11:25:17 -040033GrOp::CombineResult GrOp::combineIfPossible(GrOp* that, const GrCaps& caps) {
Brian Salomon588cec72018-11-14 13:56:37 -050034 SkASSERT(this != that);
Brian Salomond25f5bc2018-08-08 11:25:17 -040035 if (this->classID() != that->classID()) {
36 return CombineResult::kCannotCombine;
37 }
Brian Salomond25f5bc2018-08-08 11:25:17 -040038 auto result = this->onCombineIfPossible(that, caps);
Brian Salomonb41417f2018-10-24 08:58:48 -040039 if (result == CombineResult::kMerged) {
40 this->joinBounds(*that);
Brian Salomonc525d4f2018-09-17 15:48:20 -040041 }
Brian Salomond25f5bc2018-08-08 11:25:17 -040042 return result;
43}
44
Brian Salomon588cec72018-11-14 13:56:37 -050045void GrOp::chainConcat(std::unique_ptr<GrOp> next) {
Brian Salomond25f5bc2018-08-08 11:25:17 -040046 SkASSERT(next);
47 SkASSERT(this->classID() == next->classID());
Brian Salomond25f5bc2018-08-08 11:25:17 -040048 SkASSERT(this->isChainTail());
Brian Salomon588cec72018-11-14 13:56:37 -050049 SkASSERT(next->isChainHead());
50 fNextInChain = std::move(next);
51 fNextInChain->fPrevInChain = this;
Brian Salomond25f5bc2018-08-08 11:25:17 -040052}
Brian Salomon588cec72018-11-14 13:56:37 -050053
54std::unique_ptr<GrOp> GrOp::cutChain() {
55 if (fNextInChain) {
56 fNextInChain->fPrevInChain = nullptr;
57 return std::move(fNextInChain);
58 }
59 return nullptr;
60}
61
62#ifdef SK_DEBUG
63void GrOp::validateChain(GrOp* expectedTail) const {
64 SkASSERT(this->isChainHead());
65 uint32_t classID = this->classID();
66 const GrOp* op = this;
67 while (op) {
68 SkASSERT(op == this || (op->prevInChain() && op->prevInChain()->nextInChain() == op));
69 SkASSERT(classID == op->classID());
70 if (op->nextInChain()) {
71 SkASSERT(op->nextInChain()->prevInChain() == op);
72 SkASSERT(op != expectedTail);
73 } else {
74 SkASSERT(!expectedTail || op == expectedTail);
75 }
76 op = op->nextInChain();
77 }
78}
79#endif