When cache is full delay flush until GrContext draw is finished

R=robertphillips@google.com

Author: bsalomon@google.com

Review URL: https://codereview.chromium.org/25673004

git-svn-id: http://skia.googlecode.com/svn/trunk@11613 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2013-10-04 16:23:58 +00:00
Родитель 261dc569b6
Коммит 5dbb149fda
2 изменённых файлов: 40 добавлений и 13 удалений

Просмотреть файл

@ -877,6 +877,9 @@ private:
GrIndexBufferAllocPool* fDrawBufferIBAllocPool;
GrInOrderDrawBuffer* fDrawBuffer;
// Set by OverbudgetCB() to request that GrContext flush before exiting a draw.
bool fFlushToReduceCacheSize;
GrAARectRenderer* fAARectRenderer;
GrOvalRenderer* fOvalRenderer;
@ -899,9 +902,10 @@ private:
void setupDrawBuffer();
class AutoRestoreEffects;
class AutoCheckFlush;
/// Sets the paint and returns the target to draw into. The paint can be NULL in which case the
/// draw state is left unmodified.
GrDrawTarget* prepareToDraw(const GrPaint*, BufferedDraw, AutoRestoreEffects*);
GrDrawTarget* prepareToDraw(const GrPaint*, BufferedDraw, AutoRestoreEffects*, AutoCheckFlush*);
void internalDrawPath(GrDrawTarget* target, bool useAA, const SkPath& path,
const SkStrokeRec& stroke);

Просмотреть файл

@ -68,6 +68,20 @@ static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4;
// Glorified typedef to avoid including GrDrawState.h in GrContext.h
class GrContext::AutoRestoreEffects : public GrDrawState::AutoRestoreEffects {};
class GrContext::AutoCheckFlush {
public:
AutoCheckFlush(GrContext* context) : fContext(context) { SkASSERT(NULL != context); }
~AutoCheckFlush() {
if (fContext->fFlushToReduceCacheSize) {
fContext->flush();
}
}
private:
GrContext* fContext;
};
GrContext* GrContext::Create(GrBackend backend, GrBackendContext backendContext) {
GrContext* context = SkNEW(GrContext);
if (context->init(backend, backendContext)) {
@ -101,6 +115,7 @@ GrContext::GrContext() {
fDrawBuffer = NULL;
fDrawBufferVBAllocPool = NULL;
fDrawBufferIBAllocPool = NULL;
fFlushToReduceCacheSize = false;
fAARectRenderer = NULL;
fOvalRenderer = NULL;
fViewMatrix.reset();
@ -533,10 +548,8 @@ bool GrContext::OverbudgetCB(void* data) {
GrContext* context = reinterpret_cast<GrContext*>(data);
// Flush the InOrderDrawBuffer to possibly free up some textures
context->flush();
context->fFlushToReduceCacheSize = true;
// TODO: actually track flush's behavior rather than always just
// returning true.
return true;
}
@ -606,7 +619,8 @@ void GrContext::clear(const SkIRect* rect,
const GrColor color,
GrRenderTarget* target) {
AutoRestoreEffects are;
this->prepareToDraw(NULL, BUFFERED_DRAW, &are)->clear(rect, color, target);
AutoCheckFlush acf(this);
this->prepareToDraw(NULL, BUFFERED_DRAW, &are, &acf)->clear(rect, color, target);
}
void GrContext::drawPaint(const GrPaint& origPaint) {
@ -755,7 +769,8 @@ void GrContext::drawRect(const GrPaint& paint,
SK_TRACE_EVENT0("GrContext::drawRect");
AutoRestoreEffects are;
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are);
AutoCheckFlush acf(this);
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf);
SkMatrix combinedMatrix = target->drawState()->getViewMatrix();
if (NULL != matrix) {
@ -874,7 +889,8 @@ void GrContext::drawRectToRect(const GrPaint& paint,
const SkMatrix* localMatrix) {
SK_TRACE_EVENT0("GrContext::drawRectToRect");
AutoRestoreEffects are;
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are);
AutoCheckFlush acf(this);
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf);
target->drawRect(dstRect, dstMatrix, &localRect, localMatrix);
}
@ -930,7 +946,8 @@ void GrContext::drawVertices(const GrPaint& paint,
GrDrawTarget::AutoReleaseGeometry geo;
AutoRestoreEffects are;
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are);
AutoCheckFlush acf(this);
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf);
GrDrawState* drawState = target->drawState();
@ -982,7 +999,8 @@ void GrContext::drawRRect(const GrPaint& paint,
}
AutoRestoreEffects are;
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are);
AutoCheckFlush acf(this);
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf);
bool useAA = paint.isAntiAlias() &&
!target->getDrawState().getRenderTarget()->isMultisampled() &&
@ -1005,7 +1023,8 @@ void GrContext::drawOval(const GrPaint& paint,
}
AutoRestoreEffects are;
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are);
AutoCheckFlush acf(this);
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf);
bool useAA = paint.isAntiAlias() &&
!target->getDrawState().getRenderTarget()->isMultisampled() &&
@ -1088,7 +1107,8 @@ void GrContext::drawPath(const GrPaint& paint, const SkPath& path, const SkStrok
// the writePixels that uploads to the scratch will perform a flush so we're
// OK.
AutoRestoreEffects are;
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are);
AutoCheckFlush acf(this);
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW, &are, &acf);
bool useAA = paint.isAntiAlias() && !target->getDrawState().getRenderTarget()->isMultisampled();
if (useAA && stroke.getWidth() < 0 && !path.isConvex()) {
@ -1183,6 +1203,7 @@ void GrContext::flush(int flagsBitfield) {
} else {
fDrawBuffer->flush();
}
fFlushToReduceCacheSize = false;
}
bool GrContext::writeTexturePixels(GrTexture* texture,
@ -1590,7 +1611,8 @@ bool GrContext::writeRenderTargetPixels(GrRenderTarget* target,
GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint,
BufferedDraw buffered,
AutoRestoreEffects* are) {
AutoRestoreEffects* are,
AutoCheckFlush* acf) {
// All users of this draw state should be freeing up all effects when they're done.
// Otherwise effects that own resources may keep those resources alive indefinitely.
SkASSERT(0 == fDrawState->numColorStages() && 0 == fDrawState->numCoverageStages());
@ -1602,6 +1624,7 @@ GrDrawTarget* GrContext::prepareToDraw(const GrPaint* paint,
ASSERT_OWNED_RESOURCE(fRenderTarget.get());
if (NULL != paint) {
SkASSERT(NULL != are);
SkASSERT(NULL != acf);
are->set(fDrawState);
fDrawState->setFromPaint(*paint, fViewMatrix, fRenderTarget.get());
#if GR_DEBUG_PARTIAL_COVERAGE_CHECK
@ -1701,7 +1724,7 @@ void GrContext::setupDrawBuffer() {
}
GrDrawTarget* GrContext::getTextTarget() {
return this->prepareToDraw(NULL, BUFFERED_DRAW, NULL);
return this->prepareToDraw(NULL, BUFFERED_DRAW, NULL, NULL);
}
const GrIndexBuffer* GrContext::getQuadIndexBuffer() const {