• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "src/gpu/ops/GrOp.h"
9 
10 std::atomic<uint32_t> GrOp::gCurrOpClassID {GrOp::kIllegalOpID + 1};
11 std::atomic<uint32_t> GrOp::gCurrOpUniqueID{GrOp::kIllegalOpID + 1};
12 
GrOp(uint32_t classID)13 GrOp::GrOp(uint32_t classID) : fClassID(classID) {
14     SkASSERT(classID == SkToU32(fClassID));
15     SkASSERT(classID);
16     SkDEBUGCODE(fBoundsFlags = kUninitialized_BoundsFlag);
17 }
18 
combineIfPossible(GrOp * that,SkArenaAlloc * alloc,const GrCaps & caps)19 GrOp::CombineResult GrOp::combineIfPossible(GrOp* that, SkArenaAlloc* alloc, const GrCaps& caps) {
20     SkASSERT(this != that);
21     if (this->classID() != that->classID()) {
22         return CombineResult::kCannotCombine;
23     }
24     auto result = this->onCombineIfPossible(that, alloc, caps);
25     if (result == CombineResult::kMerged) {
26         this->joinBounds(*that);
27     }
28     return result;
29 }
30 
chainConcat(GrOp::Owner next)31 void GrOp::chainConcat(GrOp::Owner next) {
32     SkASSERT(next);
33     SkASSERT(this->classID() == next->classID());
34     SkASSERT(this->isChainTail());
35     SkASSERT(next->isChainHead());
36     fNextInChain = std::move(next);
37     fNextInChain->fPrevInChain = this;
38 }
39 
cutChain()40 GrOp::Owner GrOp::cutChain() {
41     if (fNextInChain) {
42         fNextInChain->fPrevInChain = nullptr;
43         return std::move(fNextInChain);
44     }
45     return nullptr;
46 }
47 
48 #ifdef SK_DEBUG
validateChain(GrOp * expectedTail) const49 void GrOp::validateChain(GrOp* expectedTail) const {
50     SkASSERT(this->isChainHead());
51     uint32_t classID = this->classID();
52     const GrOp* op = this;
53     while (op) {
54         SkASSERT(op == this || (op->prevInChain() && op->prevInChain()->nextInChain() == op));
55         SkASSERT(classID == op->classID());
56         if (op->nextInChain()) {
57             SkASSERT(op->nextInChain()->prevInChain() == op);
58             SkASSERT(op != expectedTail);
59         } else {
60             SkASSERT(!expectedTail || op == expectedTail);
61         }
62         op = op->nextInChain();
63     }
64 }
65 #endif
66