blob: 3a36d73a2affba5c208f4c25ea59502be599fe4a [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
Brian Salomon25a88092016-12-01 09:36:50 -050010int32_t GrOp::gCurrOpClassID = GrOp::kIllegalOpID;
joshualittca1f07e2015-08-07 08:11:19 -070011
Brian Salomon25a88092016-12-01 09:36:50 -050012int32_t GrOp::gCurrOpUniqueID = GrOp::kIllegalOpID;
joshualitt4d8da812015-01-28 12:53:54 -080013
Robert Phillipsc994a932018-06-19 13:09:54 -040014#ifdef SK_DEBUG
Brian Salomon25a88092016-12-01 09:36:50 -050015void* GrOp::operator new(size_t size) {
Robert Phillipsc994a932018-06-19 13:09:54 -040016 // All GrOp-derived class should be allocated in a GrMemoryPool
17 SkASSERT(0);
18 return ::operator new(size);
joshualitt4d8da812015-01-28 12:53:54 -080019}
20
Brian Salomon25a88092016-12-01 09:36:50 -050021void GrOp::operator delete(void* target) {
Robert Phillipsc994a932018-06-19 13:09:54 -040022 // All GrOp-derived class should be released from their owning GrMemoryPool
23 SkASSERT(0);
24 ::operator delete(target);
joshualitt4d8da812015-01-28 12:53:54 -080025}
Robert Phillipsc994a932018-06-19 13:09:54 -040026#endif
bsalomonb5238a72015-05-05 07:49:49 -070027
Brian Salomond25f5bc2018-08-08 11:25:17 -040028GrOp::GrOp(uint32_t classID) : fClassID(classID) {
bsalomon88cf17d2016-07-08 06:40:56 -070029 SkASSERT(classID == SkToU32(fClassID));
Brian Salomond25f5bc2018-08-08 11:25:17 -040030 SkASSERT(classID);
bsalomon88cf17d2016-07-08 06:40:56 -070031 SkDEBUGCODE(fBoundsFlags = kUninitialized_BoundsFlag);
bsalomona387a112015-08-11 14:47:42 -070032}
33
Brian Salomond25f5bc2018-08-08 11:25:17 -040034GrOp::CombineResult GrOp::combineIfPossible(GrOp* that, const GrCaps& caps) {
Brian Salomon588cec72018-11-14 13:56:37 -050035 SkASSERT(this != that);
Brian Salomond25f5bc2018-08-08 11:25:17 -040036 if (this->classID() != that->classID()) {
37 return CombineResult::kCannotCombine;
38 }
Brian Salomond25f5bc2018-08-08 11:25:17 -040039 auto result = this->onCombineIfPossible(that, caps);
Brian Salomonb41417f2018-10-24 08:58:48 -040040 if (result == CombineResult::kMerged) {
41 this->joinBounds(*that);
Brian Salomonc525d4f2018-09-17 15:48:20 -040042 }
Brian Salomond25f5bc2018-08-08 11:25:17 -040043 return result;
44}
45
Brian Salomon588cec72018-11-14 13:56:37 -050046void GrOp::chainConcat(std::unique_ptr<GrOp> next) {
Brian Salomond25f5bc2018-08-08 11:25:17 -040047 SkASSERT(next);
48 SkASSERT(this->classID() == next->classID());
Brian Salomond25f5bc2018-08-08 11:25:17 -040049 SkASSERT(this->isChainTail());
Brian Salomon588cec72018-11-14 13:56:37 -050050 SkASSERT(next->isChainHead());
51 fNextInChain = std::move(next);
52 fNextInChain->fPrevInChain = this;
Brian Salomond25f5bc2018-08-08 11:25:17 -040053}
Brian Salomon588cec72018-11-14 13:56:37 -050054
55std::unique_ptr<GrOp> GrOp::cutChain() {
56 if (fNextInChain) {
57 fNextInChain->fPrevInChain = nullptr;
58 return std::move(fNextInChain);
59 }
60 return nullptr;
61}
62
63#ifdef SK_DEBUG
64void GrOp::validateChain(GrOp* expectedTail) const {
65 SkASSERT(this->isChainHead());
66 uint32_t classID = this->classID();
67 const GrOp* op = this;
68 while (op) {
69 SkASSERT(op == this || (op->prevInChain() && op->prevInChain()->nextInChain() == op));
70 SkASSERT(classID == op->classID());
71 if (op->nextInChain()) {
72 SkASSERT(op->nextInChain()->prevInChain() == op);
73 SkASSERT(op != expectedTail);
74 } else {
75 SkASSERT(!expectedTail || op == expectedTail);
76 }
77 op = op->nextInChain();
78 }
79}
80#endif