1 /*
2 * Copyright 2016 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 "GrOpList.h"
9
10 #include "GrRenderTargetOpList.h"
11 #include "GrSurface.h"
12 #include "GrSurfaceProxy.h"
13
CreateUniqueID()14 uint32_t GrOpList::CreateUniqueID() {
15 static int32_t gUniqueID = SK_InvalidUniqueID;
16 uint32_t id;
17 // Loop in case our global wraps around, as we never want to return a 0.
18 do {
19 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
20 } while (id == SK_InvalidUniqueID);
21 return id;
22 }
23
GrOpList(GrSurfaceProxy * surfaceProxy,GrAuditTrail * auditTrail)24 GrOpList::GrOpList(GrSurfaceProxy* surfaceProxy, GrAuditTrail* auditTrail)
25 : fUniqueID(CreateUniqueID())
26 , fFlags(0)
27 , fTarget(surfaceProxy)
28 , fAuditTrail(auditTrail) {
29
30 surfaceProxy->setLastOpList(this);
31 }
32
~GrOpList()33 GrOpList::~GrOpList() {
34 if (fTarget && this == fTarget->getLastOpList()) {
35 fTarget->setLastOpList(nullptr);
36 }
37 }
38
39 // Add a GrOpList-based dependency
addDependency(GrOpList * dependedOn)40 void GrOpList::addDependency(GrOpList* dependedOn) {
41 SkASSERT(!dependedOn->dependsOn(this)); // loops are bad
42
43 if (this->dependsOn(dependedOn)) {
44 return; // don't add duplicate dependencies
45 }
46
47 *fDependencies.push() = dependedOn;
48 }
49
50 // Convert from a GrSurface-based dependency to a GrOpList one
addDependency(GrSurface * dependedOn)51 void GrOpList::addDependency(GrSurface* dependedOn) {
52 if (dependedOn->getLastOpList()) {
53 // If it is still receiving dependencies, this GrOpList shouldn't be closed
54 SkASSERT(!this->isClosed());
55
56 GrOpList* opList = dependedOn->getLastOpList();
57 if (opList == this) {
58 // self-read - presumably for dst reads
59 } else {
60 this->addDependency(opList);
61
62 // Can't make it closed in the self-read case
63 opList->makeClosed();
64 }
65 }
66 }
67
68 #ifdef SK_DEBUG
dump() const69 void GrOpList::dump() const {
70 SkDebugf("--------------------------------------------------------------\n");
71 SkDebugf("node: %d -> RT: %d\n", fUniqueID, fTarget ? fTarget->uniqueID().asUInt() : -1);
72 SkDebugf("relies On (%d): ", fDependencies.count());
73 for (int i = 0; i < fDependencies.count(); ++i) {
74 SkDebugf("%d, ", fDependencies[i]->fUniqueID);
75 }
76 SkDebugf("\n");
77 }
78 #endif
79