blob: 2af34a552b6acbe4f973d69e55a4633cc2605f86 [file] [log] [blame]
Robert Phillipsf2361d22016-10-25 14:20:06 -04001/*
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"
Robert Phillipsc7635fa2016-10-28 13:25:24 -04009#include "GrSurfaceProxy.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040010
Robert Phillipsc589b0b2017-04-17 07:53:07 -040011#include "SkAtomics.h"
12
Robert Phillipsc0138922017-03-08 11:50:55 -050013uint32_t GrOpList::CreateUniqueID() {
14 static int32_t gUniqueID = SK_InvalidUniqueID;
15 uint32_t id;
16 // Loop in case our global wraps around, as we never want to return a 0.
17 do {
18 id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
19 } while (id == SK_InvalidUniqueID);
20 return id;
21}
22
Robert Phillipsb6deea82017-05-11 14:14:30 -040023GrOpList::GrOpList(GrSurfaceProxy* surfaceProxy, GrAuditTrail* auditTrail)
Robert Phillips6cdc22c2017-05-11 16:29:14 -040024 : fAuditTrail(auditTrail)
Robert Phillipsdc83b892017-04-13 12:23:54 -040025 , fUniqueID(CreateUniqueID())
26 , fFlags(0) {
Robert Phillips6cdc22c2017-05-11 16:29:14 -040027 fTarget.reset(surfaceProxy);
28 fTarget.get()->setLastOpList(this);
Robert Phillipsf2361d22016-10-25 14:20:06 -040029}
30
31GrOpList::~GrOpList() {
Robert Phillips6cdc22c2017-05-11 16:29:14 -040032 if (fTarget.get() && this == fTarget.get()->getLastOpList()) {
33 fTarget.get()->setLastOpList(nullptr);
Robert Phillipsf2361d22016-10-25 14:20:06 -040034 }
35}
36
Robert Phillips318c4192017-05-17 09:36:38 -040037bool GrOpList::instantiate(GrResourceProvider* resourceProvider) {
38 return SkToBool(fTarget.get()->instantiate(resourceProvider));
39}
40
Robert Phillips6cdc22c2017-05-11 16:29:14 -040041void GrOpList::reset() {
42 if (fTarget.get() && this == fTarget.get()->getLastOpList()) {
43 fTarget.get()->setLastOpList(nullptr);
44 }
45
46 fTarget.reset(nullptr);
47 fAuditTrail = nullptr;
48}
49
Robert Phillipsf2361d22016-10-25 14:20:06 -040050// Add a GrOpList-based dependency
51void GrOpList::addDependency(GrOpList* dependedOn) {
52 SkASSERT(!dependedOn->dependsOn(this)); // loops are bad
53
54 if (this->dependsOn(dependedOn)) {
55 return; // don't add duplicate dependencies
56 }
57
58 *fDependencies.push() = dependedOn;
59}
60
61// Convert from a GrSurface-based dependency to a GrOpList one
Robert Phillipsee683652017-04-26 11:53:10 -040062void GrOpList::addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps) {
Robert Phillipsf2361d22016-10-25 14:20:06 -040063 if (dependedOn->getLastOpList()) {
64 // If it is still receiving dependencies, this GrOpList shouldn't be closed
65 SkASSERT(!this->isClosed());
66
67 GrOpList* opList = dependedOn->getLastOpList();
68 if (opList == this) {
69 // self-read - presumably for dst reads
70 } else {
71 this->addDependency(opList);
72
73 // Can't make it closed in the self-read case
Robert Phillipsee683652017-04-26 11:53:10 -040074 opList->makeClosed(caps);
Robert Phillipsf2361d22016-10-25 14:20:06 -040075 }
76 }
77}
78
79#ifdef SK_DEBUG
80void GrOpList::dump() const {
81 SkDebugf("--------------------------------------------------------------\n");
Robert Phillips6cdc22c2017-05-11 16:29:14 -040082 SkDebugf("node: %d -> RT: %d\n", fUniqueID, fTarget.get() ? fTarget.get()->uniqueID().asUInt()
83 : -1);
Robert Phillipsf2361d22016-10-25 14:20:06 -040084 SkDebugf("relies On (%d): ", fDependencies.count());
85 for (int i = 0; i < fDependencies.count(); ++i) {
Robert Phillipsc0138922017-03-08 11:50:55 -050086 SkDebugf("%d, ", fDependencies[i]->fUniqueID);
Robert Phillipsf2361d22016-10-25 14:20:06 -040087 }
88 SkDebugf("\n");
89}
90#endif