Make all GrContext draws go through the draw buffer.
Review URL: http://codereview.appspot.com/6462069/ git-svn-id: http://skia.googlecode.com/svn/trunk@5136 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
da17f75844
commit
1d4edd38f6
@ -336,6 +336,14 @@ inline void GrCrash(const char* msg) { GrPrintf(msg); GrAlwaysAssert(false); }
|
|||||||
#define GR_STATIC_RECT_VB 0
|
#define GR_STATIC_RECT_VB 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GR_DISABLE_DRAW_BUFFERING prevents GrContext from queueing draws in a
|
||||||
|
* GrInOrderDrawBuffer.
|
||||||
|
*/
|
||||||
|
#if !defined(GR_DISABLE_DRAW_BUFFERING)
|
||||||
|
#define GR_DISABLE_DRAW_BUFFERING 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GR_AGGRESSIVE_SHADER_OPTS controls how aggressively shaders are optimized
|
* GR_AGGRESSIVE_SHADER_OPTS controls how aggressively shaders are optimized
|
||||||
* for special cases. On systems where program changes are expensive this
|
* for special cases. On systems where program changes are expensive this
|
||||||
|
@ -748,12 +748,12 @@ public:
|
|||||||
bool allowSW);
|
bool allowSW);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// used to keep track of when we need to flush the draw buffer
|
// Used to indicate whether a draw should be performed immediately or queued in fDrawBuffer.
|
||||||
enum DrawCategory {
|
enum BufferedDraw {
|
||||||
kBuffered_DrawCategory, // last draw was inserted in draw buffer
|
kYes_BufferedDraw,
|
||||||
kUnbuffered_DrawCategory, // last draw was not inserted in the draw buffer
|
kNo_BufferedDraw,
|
||||||
};
|
};
|
||||||
DrawCategory fLastDrawCategory;
|
BufferedDraw fLastDrawWasBuffered;
|
||||||
|
|
||||||
GrGpu* fGpu;
|
GrGpu* fGpu;
|
||||||
GrDrawState* fDrawState;
|
GrDrawState* fDrawState;
|
||||||
@ -778,7 +778,7 @@ private:
|
|||||||
|
|
||||||
void setPaint(const GrPaint& paint);
|
void setPaint(const GrPaint& paint);
|
||||||
|
|
||||||
GrDrawTarget* prepareToDraw(const GrPaint& paint, DrawCategory drawType);
|
GrDrawTarget* prepareToDraw(const GrPaint&, BufferedDraw);
|
||||||
|
|
||||||
void internalDrawPath(const GrPaint& paint, const SkPath& path,
|
void internalDrawPath(const GrPaint& paint, const SkPath& path,
|
||||||
GrPathFill fill, const GrPoint* translate);
|
GrPathFill fill, const GrPoint* translate);
|
||||||
|
@ -22,8 +22,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* To diagnose texture cache performance, define this to 1 if you want to see
|
* To diagnose texture cache performance, define this to 1 if you want to see
|
||||||
* a log statement everytime we upload an image to create a texture.
|
* a log statement everytime we upload an image to create a texture.
|
||||||
*/
|
*/
|
||||||
//#define GR_DUMP_TEXTURE_UPLOAD 1
|
//#define GR_DUMP_TEXTURE_UPLOAD 1
|
||||||
|
|
||||||
@ -35,6 +35,12 @@
|
|||||||
*/
|
*/
|
||||||
//#define GR_STATIC_RECT_VB 1
|
//#define GR_STATIC_RECT_VB 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This causes the GrContext to execute all draws immediately in the 3D API
|
||||||
|
* rather than internally queuing draws.
|
||||||
|
*/
|
||||||
|
//#define GR_DISABLE_DRAW_BUFFERING 1
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This causes more aggressive shader optimization. May hurt performance if
|
* This causes more aggressive shader optimization. May hurt performance if
|
||||||
* switching shaders is expensive.
|
* switching shaders is expensive.
|
||||||
|
@ -30,11 +30,10 @@
|
|||||||
SK_DEFINE_INST_COUNT(GrContext)
|
SK_DEFINE_INST_COUNT(GrContext)
|
||||||
SK_DEFINE_INST_COUNT(GrDrawState)
|
SK_DEFINE_INST_COUNT(GrDrawState)
|
||||||
|
|
||||||
#define DEFER_TEXT_RENDERING 1
|
// It can be useful to set this to kNo_BufferedDraw to test whether a bug is caused by using the
|
||||||
|
// InOrderDrawBuffer, to compare performance of using/not using InOrderDrawBuffer, or to make
|
||||||
#define DEFER_PATHS 1
|
// debugging easier.
|
||||||
|
#define DEFAULT_BUFFERING (GR_DISABLE_DRAW_BUFFERING ? kNo_BufferedDraw : kYes_BufferedDraw)
|
||||||
#define BATCH_RECT_TO_RECT (1 && !GR_STATIC_RECT_VB)
|
|
||||||
|
|
||||||
#define MAX_BLUR_SIGMA 4.0f
|
#define MAX_BLUR_SIGMA 4.0f
|
||||||
|
|
||||||
@ -55,9 +54,8 @@ static const size_t MAX_TEXTURE_CACHE_BYTES = 16 * 1024 * 1024;
|
|||||||
static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15;
|
static const size_t DRAW_BUFFER_VBPOOL_BUFFER_SIZE = 1 << 15;
|
||||||
static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4;
|
static const int DRAW_BUFFER_VBPOOL_PREALLOC_BUFFERS = 4;
|
||||||
|
|
||||||
// path rendering is the only thing we defer today that uses non-static indices
|
static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = 1 << 11;
|
||||||
static const size_t DRAW_BUFFER_IBPOOL_BUFFER_SIZE = DEFER_PATHS ? 1 << 11 : 0;
|
static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = 4;
|
||||||
static const int DRAW_BUFFER_IBPOOL_PREALLOC_BUFFERS = DEFER_PATHS ? 4 : 0;
|
|
||||||
|
|
||||||
#define ASSERT_OWNED_RESOURCE(R) GrAssert(!(R) || (R)->getContext() == this)
|
#define ASSERT_OWNED_RESOURCE(R) GrAssert(!(R) || (R)->getContext() == this)
|
||||||
|
|
||||||
@ -740,7 +738,7 @@ void GrContext::drawRect(const GrPaint& paint,
|
|||||||
const GrMatrix* matrix) {
|
const GrMatrix* matrix) {
|
||||||
SK_TRACE_EVENT0("GrContext::drawRect");
|
SK_TRACE_EVENT0("GrContext::drawRect");
|
||||||
|
|
||||||
GrDrawTarget* target = this->prepareToDraw(paint, kUnbuffered_DrawCategory);
|
GrDrawTarget* target = this->prepareToDraw(paint, DEFAULT_BUFFERING);
|
||||||
GrDrawState::AutoStageDisable atr(fDrawState);
|
GrDrawState::AutoStageDisable atr(fDrawState);
|
||||||
|
|
||||||
GrRect devRect = rect;
|
GrRect devRect = rect;
|
||||||
@ -857,10 +855,9 @@ void GrContext::drawRectToRect(const GrPaint& paint,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GR_STATIC_ASSERT(!BATCH_RECT_TO_RECT || !GR_STATIC_RECT_VB);
|
GrDrawTarget* target = this->prepareToDraw(paint, DEFAULT_BUFFERING);
|
||||||
|
|
||||||
#if GR_STATIC_RECT_VB
|
#if GR_STATIC_RECT_VB
|
||||||
GrDrawTarget* target = this->prepareToDraw(paint, kUnbuffered_DrawCategory);
|
|
||||||
GrDrawState::AutoStageDisable atr(fDrawState);
|
GrDrawState::AutoStageDisable atr(fDrawState);
|
||||||
GrDrawState* drawState = target->drawState();
|
GrDrawState* drawState = target->drawState();
|
||||||
GrDrawState::AutoViewMatrixRestore avmr(drawState);
|
GrDrawState::AutoViewMatrixRestore avmr(drawState);
|
||||||
@ -899,13 +896,6 @@ void GrContext::drawRectToRect(const GrPaint& paint,
|
|||||||
target->setVertexSourceToBuffer(0, sqVB);
|
target->setVertexSourceToBuffer(0, sqVB);
|
||||||
target->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
|
target->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
GrDrawTarget* target;
|
|
||||||
#if BATCH_RECT_TO_RECT
|
|
||||||
target = this->prepareToDraw(paint, kBuffered_DrawCategory);
|
|
||||||
#else
|
|
||||||
target = this->prepareToDraw(paint, kUnbuffered_DrawCategory);
|
|
||||||
#endif
|
|
||||||
GrDrawState::AutoStageDisable atr(fDrawState);
|
GrDrawState::AutoStageDisable atr(fDrawState);
|
||||||
|
|
||||||
const GrRect* srcRects[GrDrawState::kNumStages] = {NULL};
|
const GrRect* srcRects[GrDrawState::kNumStages] = {NULL};
|
||||||
@ -929,7 +919,7 @@ void GrContext::drawVertices(const GrPaint& paint,
|
|||||||
|
|
||||||
GrDrawTarget::AutoReleaseGeometry geo;
|
GrDrawTarget::AutoReleaseGeometry geo;
|
||||||
|
|
||||||
GrDrawTarget* target = this->prepareToDraw(paint, kUnbuffered_DrawCategory);
|
GrDrawTarget* target = this->prepareToDraw(paint, DEFAULT_BUFFERING);
|
||||||
GrDrawState::AutoStageDisable atr(fDrawState);
|
GrDrawState::AutoStageDisable atr(fDrawState);
|
||||||
|
|
||||||
GrVertexLayout layout = 0;
|
GrVertexLayout layout = 0;
|
||||||
@ -1041,9 +1031,7 @@ void GrContext::drawOval(const GrPaint& paint,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawCategory category = (DEFER_PATHS) ? kBuffered_DrawCategory :
|
GrDrawTarget* target = this->prepareToDraw(paint, DEFAULT_BUFFERING);
|
||||||
kUnbuffered_DrawCategory;
|
|
||||||
GrDrawTarget* target = this->prepareToDraw(paint, category);
|
|
||||||
GrDrawState* drawState = target->drawState();
|
GrDrawState* drawState = target->drawState();
|
||||||
GrDrawState::AutoStageDisable atr(fDrawState);
|
GrDrawState::AutoStageDisable atr(fDrawState);
|
||||||
const GrMatrix vm = drawState->getViewMatrix();
|
const GrMatrix vm = drawState->getViewMatrix();
|
||||||
@ -1141,9 +1129,7 @@ void GrContext::internalDrawPath(const GrPaint& paint, const SkPath& path,
|
|||||||
// cache. This presents a potential hazard for buffered drawing. However,
|
// cache. This presents a potential hazard for buffered drawing. However,
|
||||||
// the writePixels that uploads to the scratch will perform a flush so we're
|
// the writePixels that uploads to the scratch will perform a flush so we're
|
||||||
// OK.
|
// OK.
|
||||||
DrawCategory category = (DEFER_PATHS) ? kBuffered_DrawCategory :
|
GrDrawTarget* target = this->prepareToDraw(paint, DEFAULT_BUFFERING);
|
||||||
kUnbuffered_DrawCategory;
|
|
||||||
GrDrawTarget* target = this->prepareToDraw(paint, category);
|
|
||||||
GrDrawState::AutoStageDisable atr(fDrawState);
|
GrDrawState::AutoStageDisable atr(fDrawState);
|
||||||
|
|
||||||
bool prAA = paint.fAntiAlias && !this->getRenderTarget()->isMultisampled();
|
bool prAA = paint.fAntiAlias && !this->getRenderTarget()->isMultisampled();
|
||||||
@ -1594,27 +1580,20 @@ void GrContext::setPaint(const GrPaint& paint) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
GrDrawTarget* GrContext::prepareToDraw(const GrPaint& paint,
|
GrDrawTarget* GrContext::prepareToDraw(const GrPaint& paint, BufferedDraw buffered) {
|
||||||
DrawCategory category) {
|
if (kNo_BufferedDraw == buffered && kYes_BufferedDraw == fLastDrawWasBuffered) {
|
||||||
if (category != fLastDrawCategory) {
|
|
||||||
this->flushDrawBuffer();
|
this->flushDrawBuffer();
|
||||||
fLastDrawCategory = category;
|
fLastDrawWasBuffered = kNo_BufferedDraw;
|
||||||
}
|
}
|
||||||
this->setPaint(paint);
|
this->setPaint(paint);
|
||||||
GrDrawTarget* target = fGpu;
|
if (kYes_BufferedDraw == buffered) {
|
||||||
switch (category) {
|
fDrawBuffer->setClip(fGpu->getClip());
|
||||||
case kUnbuffered_DrawCategory:
|
fLastDrawWasBuffered = kYes_BufferedDraw;
|
||||||
target = fGpu;
|
return fDrawBuffer;
|
||||||
break;
|
} else {
|
||||||
case kBuffered_DrawCategory:
|
GrAssert(kNo_BufferedDraw == buffered);
|
||||||
target = fDrawBuffer;
|
return fGpu;
|
||||||
fDrawBuffer->setClip(fGpu->getClip());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
GrCrash("Unexpected DrawCategory.");
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return target;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1711,7 +1690,7 @@ GrContext::GrContext(GrGpu* gpu) {
|
|||||||
MAX_TEXTURE_CACHE_BYTES));
|
MAX_TEXTURE_CACHE_BYTES));
|
||||||
fFontCache = SkNEW_ARGS(GrFontCache, (fGpu));
|
fFontCache = SkNEW_ARGS(GrFontCache, (fGpu));
|
||||||
|
|
||||||
fLastDrawCategory = kUnbuffered_DrawCategory;
|
fLastDrawWasBuffered = kNo_BufferedDraw;
|
||||||
|
|
||||||
fDrawBuffer = NULL;
|
fDrawBuffer = NULL;
|
||||||
fDrawBufferVBAllocPool = NULL;
|
fDrawBufferVBAllocPool = NULL;
|
||||||
@ -1728,7 +1707,6 @@ void GrContext::setupDrawBuffer() {
|
|||||||
GrAssert(NULL == fDrawBufferVBAllocPool);
|
GrAssert(NULL == fDrawBufferVBAllocPool);
|
||||||
GrAssert(NULL == fDrawBufferIBAllocPool);
|
GrAssert(NULL == fDrawBufferIBAllocPool);
|
||||||
|
|
||||||
#if DEFER_TEXT_RENDERING || BATCH_RECT_TO_RECT || DEFER_PATHS
|
|
||||||
fDrawBufferVBAllocPool =
|
fDrawBufferVBAllocPool =
|
||||||
SkNEW_ARGS(GrVertexBufferAllocPool, (fGpu, false,
|
SkNEW_ARGS(GrVertexBufferAllocPool, (fGpu, false,
|
||||||
DRAW_BUFFER_VBPOOL_BUFFER_SIZE,
|
DRAW_BUFFER_VBPOOL_BUFFER_SIZE,
|
||||||
@ -1741,11 +1719,8 @@ void GrContext::setupDrawBuffer() {
|
|||||||
fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu,
|
fDrawBuffer = SkNEW_ARGS(GrInOrderDrawBuffer, (fGpu,
|
||||||
fDrawBufferVBAllocPool,
|
fDrawBufferVBAllocPool,
|
||||||
fDrawBufferIBAllocPool));
|
fDrawBufferIBAllocPool));
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BATCH_RECT_TO_RECT
|
|
||||||
fDrawBuffer->setQuadIndexBuffer(this->getQuadIndexBuffer());
|
fDrawBuffer->setQuadIndexBuffer(this->getQuadIndexBuffer());
|
||||||
#endif
|
|
||||||
if (fDrawBuffer) {
|
if (fDrawBuffer) {
|
||||||
fDrawBuffer->setAutoFlushTarget(fGpu);
|
fDrawBuffer->setAutoFlushTarget(fGpu);
|
||||||
fDrawBuffer->setDrawState(fDrawState);
|
fDrawBuffer->setDrawState(fDrawState);
|
||||||
@ -1753,11 +1728,7 @@ void GrContext::setupDrawBuffer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GrDrawTarget* GrContext::getTextTarget(const GrPaint& paint) {
|
GrDrawTarget* GrContext::getTextTarget(const GrPaint& paint) {
|
||||||
#if DEFER_TEXT_RENDERING
|
return prepareToDraw(paint, DEFAULT_BUFFERING);
|
||||||
return prepareToDraw(paint, kBuffered_DrawCategory);
|
|
||||||
#else
|
|
||||||
return prepareToDraw(paint, kUnbuffered_DrawCategory);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const GrIndexBuffer* GrContext::getQuadIndexBuffer() const {
|
const GrIndexBuffer* GrContext::getQuadIndexBuffer() const {
|
||||||
|
Loading…
Reference in New Issue
Block a user