blob: ed94d9902c9ea27ec0bd65b41d7d9dcafea9b67b [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 Salomon25a88092016-12-01 09:36:50 -050034GrOp::~GrOp() {}
Brian Salomond25f5bc2018-08-08 11:25:17 -040035
36GrOp::CombineResult GrOp::combineIfPossible(GrOp* that, const GrCaps& caps) {
37 if (this->classID() != that->classID()) {
38 return CombineResult::kCannotCombine;
39 }
40 SkDEBUGCODE(bool thatWasChained = that->isChained());
41 auto result = this->onCombineIfPossible(that, caps);
42 // Merging a chained 'that' would cause problems given the way op lists currently manage chains.
43 SkASSERT(!(thatWasChained && result == CombineResult::kMerged));
44 return result;
45}
46
47void GrOp::setNextInChain(GrOp* next) {
48 SkASSERT(next);
49 SkASSERT(this->classID() == next->classID());
50 // Each op begins life as a 1 element list. We assume lists are appended only with
51 SkASSERT(this->isChainTail());
52 SkASSERT(!next->isChained());
53 if (!fChainHead) {
54 // We were using null to mark 'this' as unchained. Now 'this' is the head of the new chain.
55 fChainHead = this;
56 }
57 fNextInChain = next;
58 fChainHead->joinBounds(*next);
59 next->fChainHead = this->fChainHead;
60}