From bc3d0de755c4164563d136fc6b28fc186d275db7 Mon Sep 17 00:00:00 2001 From: bsalomon Date: Mon, 15 Dec 2014 13:45:03 -0800 Subject: [PATCH] Move all non-program cache functions out of GrGpuGL_program.cpp Review URL: https://codereview.chromium.org/794343006 --- src/gpu/gl/GrGpuGL.cpp | 106 +++++++++++++++++++++++++++++++ src/gpu/gl/GrGpuGL_program.cpp | 110 --------------------------------- 2 files changed, 106 insertions(+), 110 deletions(-) diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp index a22988b01b..0efb7ebdd0 100644 --- a/src/gpu/gl/GrGpuGL.cpp +++ b/src/gpu/gl/GrGpuGL.cpp @@ -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(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(gp->getVertexStride()); + + size_t vertexOffsetInBytes = stride * info.startVertex(); + + vertexOffsetInBytes += vbuf->baseOffset(); + + const SkTArray& 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(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)); diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp index 19ddc76944..f094ee9c80 100644 --- a/src/gpu/gl/GrGpuGL_program.cpp +++ b/src/gpu/gl/GrGpuGL_program.cpp @@ -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(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(gp->getVertexStride()); - - size_t vertexOffsetInBytes = stride * info.startVertex(); - - vertexOffsetInBytes += vbuf->baseOffset(); - - const SkTArray& 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(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"); - } -}