Add the machinery to GrDrawTarget to enable topological sorting
This relies on https://codereview.chromium.org/1414503003/ (Add SkTTopoSort) landing first.
BUG=skia:4094
Review URL: https://codereview.chromium.org/1414773002
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 323599d..7f84f8e 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -38,7 +38,7 @@
, fFlushState(fGpu, fResourceProvider, 0)
, fFlushing(false)
, fFirstUnpreparedBatch(0)
- , fClosed(false) {
+ , fFlags(0) {
// TODO: Stop extracting the context (currently needed by GrClipMaskManager)
fContext = fGpu->getContext();
fClipMaskManager.reset(new GrClipMaskManager(this));
@@ -50,6 +50,35 @@
////////////////////////////////////////////////////////////////////////////////
+// Add a GrDrawTarget-based dependency
+void GrDrawTarget::addDependency(GrDrawTarget* dependedOn) {
+ SkASSERT(!dependedOn->dependsOn(this)); // loops are bad
+
+ if (this->dependsOn(dependedOn)) {
+ return; // don't add duplicate dependencies
+ }
+
+ *fDependencies.push() = dependedOn;
+}
+
+// Convert from a GrSurface-based dependency to a GrDrawTarget one
+void GrDrawTarget::addDependency(GrSurface* dependedOn) {
+ if (dependedOn->asRenderTarget() && dependedOn->asRenderTarget()->getLastDrawTarget()) {
+ // If it is still receiving dependencies, this DT shouldn't be closed
+ SkASSERT(!this->isClosed());
+
+ GrDrawTarget* dt = dependedOn->asRenderTarget()->getLastDrawTarget();
+ if (dt == this) {
+ // self-read - presumably for dst reads
+ } else {
+ this->addDependency(dt);
+
+ // Can't make it closed in the self-read case
+ dt->makeClosed();
+ }
+ }
+}
+
bool GrDrawTarget::setupDstReadIfNecessary(const GrPipelineBuilder& pipelineBuilder,
const GrProcOptInfo& colorPOI,
const GrProcOptInfo& coveragePOI,
@@ -414,7 +443,7 @@
void GrDrawTarget::recordBatch(GrBatch* batch) {
// A closed drawTarget should never receive new/more batches
- SkASSERT(!fClosed);
+ SkASSERT(!this->isClosed());
// Check if there is a Batch Draw we can batch with by linearly searching back until we either
// 1) check every draw