Loosen requirement that there be only one GrDrawTarget
BUG=skia:4094
Review URL: https://codereview.chromium.org/1406173003
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index cd86458..323599d 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -37,7 +37,8 @@
, fResourceProvider(resourceProvider)
, fFlushState(fGpu, fResourceProvider, 0)
, fFlushing(false)
- , fFirstUnpreparedBatch(0) {
+ , fFirstUnpreparedBatch(0)
+ , fClosed(false) {
// TODO: Stop extracting the context (currently needed by GrClipMaskManager)
fContext = fGpu->getContext();
fClipMaskManager.reset(new GrClipMaskManager(this));
@@ -118,6 +119,12 @@
}
fFlushing = true;
+ // Semi-usually the drawTargets are already closed at this point, but sometimes Ganesh
+ // needs to flush mid-draw. In that case, the SkGpuDevice's drawTargets won't be closed
+ // but need to be flushed anyway. Closing such drawTargets here will mean new
+ // drawTargets will be created to replace them if the SkGpuDevice(s) write to them again.
+ this->makeClosed();
+
// Loop over all batches and generate geometry
for (; fFirstUnpreparedBatch < fBatches.count(); ++fFirstUnpreparedBatch) {
fBatches[fFirstUnpreparedBatch]->prepare(&fFlushState);
@@ -406,6 +413,9 @@
}
void GrDrawTarget::recordBatch(GrBatch* batch) {
+ // A closed drawTarget should never receive new/more batches
+ SkASSERT(!fClosed);
+
// Check if there is a Batch Draw we can batch with by linearly searching back until we either
// 1) check every draw
// 2) intersect with something