1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrOpList.h"
#include "GrContext.h"
#include "GrPrepareCallback.h"
#include "GrSurfaceProxy.h"
#include "SkAtomics.h"
uint32_t GrOpList::CreateUniqueID() {
static int32_t gUniqueID = SK_InvalidUniqueID;
uint32_t id;
// Loop in case our global wraps around, as we never want to return a 0.
do {
id = static_cast<uint32_t>(sk_atomic_inc(&gUniqueID) + 1);
} while (id == SK_InvalidUniqueID);
return id;
}
GrOpList::GrOpList(GrResourceProvider* resourceProvider,
GrSurfaceProxy* surfaceProxy, GrAuditTrail* auditTrail)
: fAuditTrail(auditTrail)
, fUniqueID(CreateUniqueID())
, fFlags(0) {
fTarget.setProxy(sk_ref_sp(surfaceProxy), kWrite_GrIOType);
fTarget.get()->setLastOpList(this);
#ifndef MDB_ALLOC_RESOURCES
// MDB TODO: remove this! We are currently moving to having all the ops that target
// the RT as a dest (e.g., clear, etc.) rely on the opList's 'fTarget' pointer
// for the IO Ref. This works well but until they are all swapped over (and none
// are pre-emptively instantiating proxies themselves) we need to instantiate
// here so that the GrSurfaces are created in an order that preserves the GrSurface
// re-use assumptions.
fTarget.get()->instantiate(resourceProvider);
#endif
fTarget.markPendingIO();
}
GrOpList::~GrOpList() {
this->reset();
}
bool GrOpList::instantiate(GrResourceProvider* resourceProvider) {
return SkToBool(fTarget.get()->instantiate(resourceProvider));
}
void GrOpList::reset() {
if (fTarget.get() && this == fTarget.get()->getLastOpList()) {
fTarget.get()->setLastOpList(nullptr);
}
fTarget.reset();
fPrepareCallbacks.reset();
fAuditTrail = nullptr;
}
void GrOpList::addPrepareCallback(std::unique_ptr<GrPrepareCallback> callback) {
fPrepareCallbacks.push_back(std::move(callback));
}
void GrOpList::prepare(GrOpFlushState* flushState) {
for (int i = 0; i < fPrepareCallbacks.count(); ++i) {
(*fPrepareCallbacks[i])(flushState);
}
this->onPrepare(flushState);
}
// Add a GrOpList-based dependency
void GrOpList::addDependency(GrOpList* dependedOn) {
SkASSERT(!dependedOn->dependsOn(this)); // loops are bad
if (this->dependsOn(dependedOn)) {
return; // don't add duplicate dependencies
}
fDependencies.push_back(dependedOn);
}
// Convert from a GrSurface-based dependency to a GrOpList one
void GrOpList::addDependency(GrSurfaceProxy* dependedOn, const GrCaps& caps) {
if (dependedOn->getLastOpList()) {
// If it is still receiving dependencies, this GrOpList shouldn't be closed
SkASSERT(!this->isClosed());
GrOpList* opList = dependedOn->getLastOpList();
if (opList == this) {
// self-read - presumably for dst reads
} else {
this->addDependency(opList);
// Can't make it closed in the self-read case
opList->makeClosed(caps);
}
}
}
#ifdef SK_DEBUG
bool GrOpList::isInstantiated() const {
return fTarget.get()->priv().isInstantiated();
}
void GrOpList::dump() const {
SkDebugf("--------------------------------------------------------------\n");
SkDebugf("node: %d -> RT: %d\n", fUniqueID, fTarget.get() ? fTarget.get()->uniqueID().asUInt()
: -1);
SkDebugf("relies On (%d): ", fDependencies.count());
for (int i = 0; i < fDependencies.count(); ++i) {
SkDebugf("%d, ", fDependencies[i]->fUniqueID);
}
SkDebugf("\n");
}
#endif
|