Move all non-program cache functions out of GrGpuGL_program.cpp

Review URL: https://codereview.chromium.org/794343006
This commit is contained in:
bsalomon 2014-12-15 13:45:03 -08:00 committed by Commit bot
parent 0393912de7
commit bc3d0de755
2 changed files with 106 additions and 110 deletions

View File

@ -1344,6 +1344,112 @@ void GrGpuGL::flushScissor(const GrClipMaskManager::ScissorState& scissorState,
this->disableScissor();
}
bool GrGpuGL::flushGraphicsState(const GrOptDrawState& optState) {
// GrGpu::setupClipAndFlushState should have already checked this and bailed if not true.
SkASSERT(optState.getRenderTarget());
if (kStencilPath_DrawType == optState.drawType()) {
const GrRenderTarget* rt = optState.getRenderTarget();
SkISize size;
size.set(rt->width(), rt->height());
this->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size, rt->origin());
} else {
this->flushMiscFixedFunctionState(optState);
fCurrentProgram.reset(fProgramCache->getProgram(optState));
if (NULL == fCurrentProgram.get()) {
SkDEBUGFAIL("Failed to create program!");
return false;
}
fCurrentProgram.get()->ref();
GrGLuint programID = fCurrentProgram->programID();
if (fHWProgramID != programID) {
GL_CALL(UseProgram(programID));
fHWProgramID = programID;
}
this->flushBlend(optState);
fCurrentProgram->setData(optState);
}
GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(optState.getRenderTarget());
this->flushStencil(optState.getStencil(), optState.drawType());
this->flushScissor(optState.getScissorState(), glRT->getViewport(), glRT->origin());
this->flushAAState(optState);
// This must come after textures are flushed because a texture may need
// to be msaa-resolved (which will modify bound FBO state).
this->flushRenderTarget(glRT, NULL);
return true;
}
void GrGpuGL::setupGeometry(const GrOptDrawState& optState,
const GrDrawTarget::DrawInfo& info,
size_t* indexOffsetInBytes) {
GrGLVertexBuffer* vbuf;
vbuf = (GrGLVertexBuffer*) info.vertexBuffer();
SkASSERT(vbuf);
SkASSERT(!vbuf->isMapped());
GrGLIndexBuffer* ibuf = NULL;
if (info.isIndexed()) {
SkASSERT(indexOffsetInBytes);
*indexOffsetInBytes = 0;
ibuf = (GrGLIndexBuffer*)info.indexBuffer();
SkASSERT(ibuf);
SkASSERT(!ibuf->isMapped());
*indexOffsetInBytes += ibuf->baseOffset();
}
GrGLAttribArrayState* attribState =
fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf);
if (fCurrentProgram->hasVertexShader()) {
const GrGeometryProcessor* gp = optState.getGeometryProcessor();
GrGLsizei stride = static_cast<GrGLsizei>(gp->getVertexStride());
size_t vertexOffsetInBytes = stride * info.startVertex();
vertexOffsetInBytes += vbuf->baseOffset();
const SkTArray<GrGeometryProcessor::GrAttribute, true>& attribs = gp->getAttribs();
int vaCount = attribs.count();
uint32_t usedAttribArraysMask = 0;
size_t offset = 0;
for (int attribIndex = 0; attribIndex < vaCount; attribIndex++) {
usedAttribArraysMask |= (1 << attribIndex);
GrVertexAttribType attribType = attribs[attribIndex].fType;
attribState->set(this,
attribIndex,
vbuf,
GrGLAttribTypeToLayout(attribType).fCount,
GrGLAttribTypeToLayout(attribType).fType,
GrGLAttribTypeToLayout(attribType).fNormalized,
stride,
reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + offset));
offset += attribs[attribIndex].fOffset;
}
attribState->disableUnusedArrays(this, usedAttribArraysMask);
}
}
void GrGpuGL::buildProgramDesc(const GrOptDrawState& optState,
const GrProgramDesc::DescInfo& descInfo,
GrGpu::DrawType drawType,
GrProgramDesc* desc) {
if (!GrGLProgramDescBuilder::Build(optState, descInfo, drawType, this, desc)) {
SkDEBUGFAIL("Failed to generate GL program descriptor");
}
}
void GrGpuGL::disableScissor() {
if (kNo_TriState != fHWScissorSettings.fEnabled) {
GL_CALL(Disable(GR_GL_SCISSOR_TEST));

View File

@ -196,113 +196,3 @@ GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrOptDrawState& optState) {
++fCurrLRUStamp;
return entry->fProgram;
}
////////////////////////////////////////////////////////////////////////////////
#define GL_CALL(X) GR_GL_CALL(this->glInterface(), X)
bool GrGpuGL::flushGraphicsState(const GrOptDrawState& optState) {
// GrGpu::setupClipAndFlushState should have already checked this and bailed if not true.
SkASSERT(optState.getRenderTarget());
if (kStencilPath_DrawType == optState.drawType()) {
const GrRenderTarget* rt = optState.getRenderTarget();
SkISize size;
size.set(rt->width(), rt->height());
this->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size, rt->origin());
} else {
this->flushMiscFixedFunctionState(optState);
fCurrentProgram.reset(fProgramCache->getProgram(optState));
if (NULL == fCurrentProgram.get()) {
SkDEBUGFAIL("Failed to create program!");
return false;
}
fCurrentProgram.get()->ref();
GrGLuint programID = fCurrentProgram->programID();
if (fHWProgramID != programID) {
GL_CALL(UseProgram(programID));
fHWProgramID = programID;
}
this->flushBlend(optState);
fCurrentProgram->setData(optState);
}
GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(optState.getRenderTarget());
this->flushStencil(optState.getStencil(), optState.drawType());
this->flushScissor(optState.getScissorState(), glRT->getViewport(), glRT->origin());
this->flushAAState(optState);
// This must come after textures are flushed because a texture may need
// to be msaa-resolved (which will modify bound FBO state).
this->flushRenderTarget(glRT, NULL);
return true;
}
void GrGpuGL::setupGeometry(const GrOptDrawState& optState,
const GrDrawTarget::DrawInfo& info,
size_t* indexOffsetInBytes) {
GrGLVertexBuffer* vbuf;
vbuf = (GrGLVertexBuffer*) info.vertexBuffer();
SkASSERT(vbuf);
SkASSERT(!vbuf->isMapped());
GrGLIndexBuffer* ibuf = NULL;
if (info.isIndexed()) {
SkASSERT(indexOffsetInBytes);
*indexOffsetInBytes = 0;
ibuf = (GrGLIndexBuffer*)info.indexBuffer();
SkASSERT(ibuf);
SkASSERT(!ibuf->isMapped());
*indexOffsetInBytes += ibuf->baseOffset();
}
GrGLAttribArrayState* attribState =
fHWGeometryState.bindArrayAndBuffersToDraw(this, vbuf, ibuf);
if (fCurrentProgram->hasVertexShader()) {
const GrGeometryProcessor* gp = optState.getGeometryProcessor();
GrGLsizei stride = static_cast<GrGLsizei>(gp->getVertexStride());
size_t vertexOffsetInBytes = stride * info.startVertex();
vertexOffsetInBytes += vbuf->baseOffset();
const SkTArray<GrGeometryProcessor::GrAttribute, true>& attribs = gp->getAttribs();
int vaCount = attribs.count();
uint32_t usedAttribArraysMask = 0;
size_t offset = 0;
for (int attribIndex = 0; attribIndex < vaCount; attribIndex++) {
usedAttribArraysMask |= (1 << attribIndex);
GrVertexAttribType attribType = attribs[attribIndex].fType;
attribState->set(this,
attribIndex,
vbuf,
GrGLAttribTypeToLayout(attribType).fCount,
GrGLAttribTypeToLayout(attribType).fType,
GrGLAttribTypeToLayout(attribType).fNormalized,
stride,
reinterpret_cast<GrGLvoid*>(vertexOffsetInBytes + offset));
offset += attribs[attribIndex].fOffset;
}
attribState->disableUnusedArrays(this, usedAttribArraysMask);
}
}
void GrGpuGL::buildProgramDesc(const GrOptDrawState& optState,
const GrProgramDesc::DescInfo& descInfo,
GrGpu::DrawType drawType,
GrProgramDesc* desc) {
if (!GrGLProgramDescBuilder::Build(optState, descInfo, drawType, this, desc)) {
SkDEBUGFAIL("Failed to generate GL program descriptor");
}
}