Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 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" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 9 | #include "GrSurfaceProxy.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 10 | |
Robert Phillips | c589b0b | 2017-04-17 07:53:07 -0400 | [diff] [blame] | 11 | #include "SkAtomics.h" |
| 12 | |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 13 | uint32_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 Phillips | b6deea8 | 2017-05-11 14:14:30 -0400 | [diff] [blame] | 23 | GrOpList::GrOpList(GrSurfaceProxy* surfaceProxy, GrAuditTrail* auditTrail) |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 24 | : fAuditTrail(auditTrail) |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame] | 25 | , fUniqueID(CreateUniqueID()) |
| 26 | , fFlags(0) { |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 27 | fTarget.reset(surfaceProxy); |
| 28 | fTarget.get()->setLastOpList(this); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | GrOpList::~GrOpList() { |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 32 | if (fTarget.get() && this == fTarget.get()->getLastOpList()) { |
| 33 | fTarget.get()->setLastOpList(nullptr); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 37 | bool GrOpList::instantiate(GrResourceProvider* resourceProvider) { |
| 38 | return SkToBool(fTarget.get()->instantiate(resourceProvider)); |
| 39 | } |
| 40 | |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 41 | void 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 Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 50 | // Add a GrOpList-based dependency |
| 51 | void 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 Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 62 | void GrOpList::addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps) { |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 63 | 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 Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 74 | opList->makeClosed(caps); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | #ifdef SK_DEBUG |
| 80 | void GrOpList::dump() const { |
| 81 | SkDebugf("--------------------------------------------------------------\n"); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 82 | SkDebugf("node: %d -> RT: %d\n", fUniqueID, fTarget.get() ? fTarget.get()->uniqueID().asUInt() |
| 83 | : -1); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 84 | SkDebugf("relies On (%d): ", fDependencies.count()); |
| 85 | for (int i = 0; i < fDependencies.count(); ++i) { |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 86 | SkDebugf("%d, ", fDependencies[i]->fUniqueID); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 87 | } |
| 88 | SkDebugf("\n"); |
| 89 | } |
| 90 | #endif |