Incrementally flush GrDrawTarget

BUG=skia:

Committed: https://skia.googlesource.com/skia/+/a7e878064509ef96b54d5507dab0b50def66dc13

Review URL: https://codereview.chromium.org/1386463004
This commit is contained in:
joshualitt 2015-10-02 11:27:14 -07:00 committed by Commit bot
parent 41518ebc82
commit f6d259bd96
3 changed files with 24 additions and 11 deletions

View File

@ -46,7 +46,7 @@ class GrBatchFlushState {
public: public:
GrBatchFlushState(GrGpu*, GrResourceProvider*, GrBatchToken lastFlushedToken); GrBatchFlushState(GrGpu*, GrResourceProvider*, GrBatchToken lastFlushedToken);
~GrBatchFlushState() { SkASSERT(fLastFlushedToken == fCurrentToken); } ~GrBatchFlushState() { this->reset(); }
void advanceToken() { ++fCurrentToken; } void advanceToken() { ++fCurrentToken; }
@ -99,6 +99,11 @@ public:
GrGpu* gpu() { return fGpu; } GrGpu* gpu() { return fGpu; }
void reset() {
fVertexPool.reset();
fIndexPool.reset();
}
private: private:
GrGpu* fGpu; GrGpu* fGpu;
GrBatchUploader::TextureUploader fUploader; GrBatchUploader::TextureUploader fUploader;

View File

@ -35,8 +35,9 @@
GrDrawTarget::GrDrawTarget(GrGpu* gpu, GrResourceProvider* resourceProvider) GrDrawTarget::GrDrawTarget(GrGpu* gpu, GrResourceProvider* resourceProvider)
: fGpu(SkRef(gpu)) : fGpu(SkRef(gpu))
, fResourceProvider(resourceProvider) , fResourceProvider(resourceProvider)
, fFlushState(fGpu, fResourceProvider, 0)
, fFlushing(false) , fFlushing(false)
, fLastFlushToken(0) { , fFirstUnpreparedBatch(0) {
// TODO: Stop extracting the context (currently needed by GrClipMaskManager) // TODO: Stop extracting the context (currently needed by GrClipMaskManager)
fContext = fGpu->getContext(); fContext = fGpu->getContext();
fClipMaskManager.reset(new GrClipMaskManager(this)); fClipMaskManager.reset(new GrClipMaskManager(this));
@ -117,29 +118,29 @@ void GrDrawTarget::flush() {
} }
fFlushing = true; fFlushing = true;
GrBatchFlushState flushState(fGpu, fResourceProvider, fLastFlushToken);
// Loop over all batches and generate geometry // Loop over all batches and generate geometry
for (int i = 0; i < fBatches.count(); ++i) { for (; fFirstUnpreparedBatch < fBatches.count(); ++fFirstUnpreparedBatch) {
fBatches[i]->prepare(&flushState); fBatches[fFirstUnpreparedBatch]->prepare(&fFlushState);
} }
// Upload all data to the GPU // Upload all data to the GPU
flushState.preIssueDraws(); fFlushState.preIssueDraws();
// Draw all the generated geometry. // Draw all the generated geometry.
for (int i = 0; i < fBatches.count(); ++i) { for (int i = 0; i < fBatches.count(); ++i) {
fBatches[i]->draw(&flushState); fBatches[i]->draw(&fFlushState);
} }
fLastFlushToken = flushState.lastFlushedToken(); SkASSERT(fFlushState.lastFlushedToken() == fFlushState.currentToken());
this->reset();
fFlushing = false; fFlushing = false;
this->reset();
} }
void GrDrawTarget::reset() { void GrDrawTarget::reset() {
fFirstUnpreparedBatch = 0;
fBatches.reset(); fBatches.reset();
fFlushState.reset();
} }
void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBatch* batch) { void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBatch* batch) {
@ -434,6 +435,10 @@ void GrDrawTarget::recordBatch(GrBatch* batch) {
GrBATCH_INFO("\t\tFirstBatch\n"); GrBATCH_INFO("\t\tFirstBatch\n");
} }
fBatches.push_back().reset(SkRef(batch)); fBatches.push_back().reset(SkRef(batch));
if (fBatches.count() > kMaxLookback) {
SkASSERT(fBatches.count() - kMaxLookback - fFirstUnpreparedBatch == 1);
fBatches[fFirstUnpreparedBatch++]->prepare(&fFlushState);
}
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -8,6 +8,7 @@
#ifndef GrDrawTarget_DEFINED #ifndef GrDrawTarget_DEFINED
#define GrDrawTarget_DEFINED #define GrDrawTarget_DEFINED
#include "GrBatchFlushState.h"
#include "GrClip.h" #include "GrClip.h"
#include "GrClipMaskManager.h" #include "GrClipMaskManager.h"
#include "GrContext.h" #include "GrContext.h"
@ -33,6 +34,7 @@
#include "SkXfermode.h" #include "SkXfermode.h"
class GrBatch; class GrBatch;
class GrBatchFlushState;
class GrClip; class GrClip;
class GrCaps; class GrCaps;
class GrPath; class GrPath;
@ -228,8 +230,9 @@ private:
GrContext* fContext; GrContext* fContext;
GrGpu* fGpu; GrGpu* fGpu;
GrResourceProvider* fResourceProvider; GrResourceProvider* fResourceProvider;
GrBatchFlushState fFlushState;
bool fFlushing; bool fFlushing;
GrBatchToken fLastFlushToken; int fFirstUnpreparedBatch;
typedef SkRefCnt INHERITED; typedef SkRefCnt INHERITED;
}; };