joshualitt | 23ac62c | 2015-03-30 09:53:47 -0700 | [diff] [blame] | 1 | /* |
| 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 Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 8 | #include "GrOp.h" |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 9 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 10 | int32_t GrOp::gCurrOpClassID = GrOp::kIllegalOpID; |
joshualitt | ca1f07e | 2015-08-07 08:11:19 -0700 | [diff] [blame] | 11 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 12 | int32_t GrOp::gCurrOpUniqueID = GrOp::kIllegalOpID; |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 13 | |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 14 | #ifdef SK_DEBUG |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 15 | void* GrOp::operator new(size_t size) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 16 | // All GrOp-derived class should be allocated in a GrMemoryPool |
| 17 | SkASSERT(0); |
| 18 | return ::operator new(size); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 19 | } |
| 20 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 21 | void GrOp::operator delete(void* target) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 22 | // All GrOp-derived class should be released from their owning GrMemoryPool |
| 23 | SkASSERT(0); |
| 24 | ::operator delete(target); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 25 | } |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 26 | #endif |
bsalomon | b5238a7 | 2015-05-05 07:49:49 -0700 | [diff] [blame] | 27 | |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 28 | GrOp::GrOp(uint32_t classID) : fClassID(classID) { |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 29 | SkASSERT(classID == SkToU32(fClassID)); |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 30 | SkASSERT(classID); |
bsalomon | 88cf17d | 2016-07-08 06:40:56 -0700 | [diff] [blame] | 31 | SkDEBUGCODE(fBoundsFlags = kUninitialized_BoundsFlag); |
bsalomon | a387a11 | 2015-08-11 14:47:42 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 34 | GrOp::~GrOp() {} |
Brian Salomon | d25f5bc | 2018-08-08 11:25:17 -0400 | [diff] [blame] | 35 | |
| 36 | GrOp::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 | |
| 47 | void 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 | } |