blob: 28b972df999b415f435c3af6cc2345e214323484 [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"
9
Robert Phillipsf2361d22016-10-25 14:20:06 -040010#include "GrRenderTargetOpList.h"
11#include "GrSurface.h"
Robert Phillipsc7635fa2016-10-28 13:25:24 -040012#include "GrSurfaceProxy.h"
Robert Phillipsf2361d22016-10-25 14:20:06 -040013
Robert Phillipsc0138922017-03-08 11:50:55 -050014uint32_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
Robert Phillipsdc83b892017-04-13 12:23:54 -040024GrOpList::GrOpList(sk_sp<GrSurfaceProxy> surfaceProxy, GrAuditTrail* auditTrail)
25 // MDB TODO: in the future opLists will own the GrSurfaceProxy they target.
26 // For now, preserve the status quo.
27 : fTarget(surfaceProxy.get())
28 , fAuditTrail(auditTrail)
29 , fUniqueID(CreateUniqueID())
30 , fFlags(0) {
Robert Phillipsc7635fa2016-10-28 13:25:24 -040031 surfaceProxy->setLastOpList(this);
Robert Phillipsf2361d22016-10-25 14:20:06 -040032}
33
34GrOpList::~GrOpList() {
35 if (fTarget && this == fTarget->getLastOpList()) {
36 fTarget->setLastOpList(nullptr);
37 }
38}
39
40// Add a GrOpList-based dependency
41void GrOpList::addDependency(GrOpList* dependedOn) {
42 SkASSERT(!dependedOn->dependsOn(this)); // loops are bad
43
44 if (this->dependsOn(dependedOn)) {
45 return; // don't add duplicate dependencies
46 }
47
48 *fDependencies.push() = dependedOn;
49}
50
51// Convert from a GrSurface-based dependency to a GrOpList one
52void GrOpList::addDependency(GrSurface* dependedOn) {
53 if (dependedOn->getLastOpList()) {
54 // If it is still receiving dependencies, this GrOpList shouldn't be closed
55 SkASSERT(!this->isClosed());
56
57 GrOpList* opList = dependedOn->getLastOpList();
58 if (opList == this) {
59 // self-read - presumably for dst reads
60 } else {
61 this->addDependency(opList);
62
63 // Can't make it closed in the self-read case
64 opList->makeClosed();
65 }
66 }
67}
68
69#ifdef SK_DEBUG
70void GrOpList::dump() const {
71 SkDebugf("--------------------------------------------------------------\n");
Robert Phillipsc0138922017-03-08 11:50:55 -050072 SkDebugf("node: %d -> RT: %d\n", fUniqueID, fTarget ? fTarget->uniqueID().asUInt() : -1);
Robert Phillipsf2361d22016-10-25 14:20:06 -040073 SkDebugf("relies On (%d): ", fDependencies.count());
74 for (int i = 0; i < fDependencies.count(); ++i) {
Robert Phillipsc0138922017-03-08 11:50:55 -050075 SkDebugf("%d, ", fDependencies[i]->fUniqueID);
Robert Phillipsf2361d22016-10-25 14:20:06 -040076 }
77 SkDebugf("\n");
78}
79#endif