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" |
| 9 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 10 | #include "GrRenderTargetOpList.h" |
| 11 | #include "GrSurface.h" |
Robert Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 12 | #include "GrSurfaceProxy.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 13 | |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 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 | |
Robert Phillips | dc83b89 | 2017-04-13 12:23:54 -0400 | [diff] [blame^] | 24 | GrOpList::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 Phillips | c7635fa | 2016-10-28 13:25:24 -0400 | [diff] [blame] | 31 | surfaceProxy->setLastOpList(this); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | GrOpList::~GrOpList() { |
| 35 | if (fTarget && this == fTarget->getLastOpList()) { |
| 36 | fTarget->setLastOpList(nullptr); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | // Add a GrOpList-based dependency |
| 41 | void 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 |
| 52 | void 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 |
| 70 | void GrOpList::dump() const { |
| 71 | SkDebugf("--------------------------------------------------------------\n"); |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 72 | SkDebugf("node: %d -> RT: %d\n", fUniqueID, fTarget ? fTarget->uniqueID().asUInt() : -1); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 73 | SkDebugf("relies On (%d): ", fDependencies.count()); |
| 74 | for (int i = 0; i < fDependencies.count(); ++i) { |
Robert Phillips | c013892 | 2017-03-08 11:50:55 -0500 | [diff] [blame] | 75 | SkDebugf("%d, ", fDependencies[i]->fUniqueID); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 76 | } |
| 77 | SkDebugf("\n"); |
| 78 | } |
| 79 | #endif |