diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrGpu.cpp | 8 | ||||
-rw-r--r-- | src/gpu/GrGpu.h | 2 | ||||
-rw-r--r-- | src/gpu/GrInOrderDrawBuffer.cpp | 6 | ||||
-rw-r--r-- | src/gpu/GrInOrderDrawBuffer.h | 10 | ||||
-rw-r--r-- | src/gpu/GrOptDrawState.cpp | 104 | ||||
-rw-r--r-- | src/gpu/GrOptDrawState.h | 35 | ||||
-rw-r--r-- | src/gpu/GrProgramDesc.h | 2 | ||||
-rw-r--r-- | src/gpu/GrTest.cpp | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgram.cpp | 19 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgram.h | 8 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgramDesc.cpp | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL.cpp | 4 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL.h | 6 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL_program.cpp | 18 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLGeometryShaderBuilder.cpp | 4 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLProgramBuilder.cpp | 10 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLProgramBuilder.h | 3 |
17 files changed, 133 insertions, 110 deletions
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index ac76e1503c..d97809f952 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -277,7 +277,7 @@ const GrIndexBuffer* GrGpu::getQuadIndexBuffer() const { void GrGpu::draw(const GrOptDrawState& ds, const GrDrawTarget::DrawInfo& info) { this->handleDirtyContext(); - if (!this->flushGraphicsState(ds)) { + if (!this->flushGraphicsState(ds, PrimTypeToDrawType(info.primitiveType()))) { return; } this->onDraw(ds, info); @@ -288,7 +288,7 @@ void GrGpu::stencilPath(const GrOptDrawState& ds, const GrStencilSettings& stencilSettings) { this->handleDirtyContext(); - if (!this->flushGraphicsState(ds)) { + if (!this->flushGraphicsState(ds, kStencilPath_DrawType)) { return; } @@ -301,7 +301,7 @@ void GrGpu::drawPath(const GrOptDrawState& ds, const GrStencilSettings& stencilSettings) { this->handleDirtyContext(); - if (!this->flushGraphicsState(ds)) { + if (!this->flushGraphicsState(ds, kDrawPath_DrawType)) { return; } @@ -318,7 +318,7 @@ void GrGpu::drawPaths(const GrOptDrawState& ds, const GrStencilSettings& stencilSettings) { this->handleDirtyContext(); - if (!this->flushGraphicsState(ds)) { + if (!this->flushGraphicsState(ds, kDrawPaths_DrawType)) { return; } diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index c88e1c85d0..d0bff30262 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -469,7 +469,7 @@ private: // deltas from previous state at draw time. This function does the // backend-specific flush of the state. // returns false if current state is unsupported. - virtual bool flushGraphicsState(const GrOptDrawState&) = 0; + virtual bool flushGraphicsState(const GrOptDrawState&, DrawType) = 0; // clears target's entire stencil buffer to 0 virtual void clearStencil(GrRenderTarget* target) = 0; diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp index 83b9701f09..5533174853 100644 --- a/src/gpu/GrInOrderDrawBuffer.cpp +++ b/src/gpu/GrInOrderDrawBuffer.cpp @@ -394,7 +394,7 @@ void GrInOrderDrawBuffer::onFlush() { // Updated every time we find a set state cmd to reflect the current state in the playback // stream. - GrOptDrawState* currentOptState = NULL; + const GrOptDrawState* currentOptState = NULL; while (iter.next()) { GrGpuTraceMarker newMarker("", -1); @@ -409,7 +409,6 @@ void GrInOrderDrawBuffer::onFlush() { if (kSetState_Cmd == strip_trace_bit(iter->fType)) { SetState* ss = reinterpret_cast<SetState*>(iter.get()); currentOptState = &ss->fState; - currentOptState->finalize(this->getGpu()); } else { iter->execute(this, currentOptState); } @@ -487,8 +486,7 @@ bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrDrawState& ds, const GrClipMaskManager::ScissorState& scissor, const GrDeviceCoordTexture* dstCopy) { SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, - (ds, *this->getGpu()->caps(), scissor, dstCopy, - drawType)); + (ds, this->getGpu(), scissor, dstCopy, drawType)); if (ss->fState.mustSkip()) { fCmdBuffer.pop_back(); return false; diff --git a/src/gpu/GrInOrderDrawBuffer.h b/src/gpu/GrInOrderDrawBuffer.h index 01e560ac08..532842a3b4 100644 --- a/src/gpu/GrInOrderDrawBuffer.h +++ b/src/gpu/GrInOrderDrawBuffer.h @@ -171,15 +171,15 @@ private: }; struct SetState : public Cmd { - SetState(const GrDrawState& drawState, const GrDrawTargetCaps& caps, - const ScissorState& scissor, const GrDeviceCoordTexture* dstCopy, - GrGpu::DrawType drawType) + SetState(const GrDrawState& drawState, GrGpu* gpu, const ScissorState& scissor, + const GrDeviceCoordTexture* dstCopy, GrGpu::DrawType drawType) : Cmd(kSetState_Cmd) - , fState(drawState, caps, scissor, dstCopy, drawType) {} + , fState(drawState, gpu, scissor, dstCopy, drawType) {} void execute(GrInOrderDrawBuffer*, const GrOptDrawState*) SK_OVERRIDE; - GrOptDrawState fState; + const GrOptDrawState fState; + GrGpu::DrawType fDrawType; }; typedef void* TCmdAlign; // This wouldn't be enough align if a command used long double. diff --git a/src/gpu/GrOptDrawState.cpp b/src/gpu/GrOptDrawState.cpp index 6eee0c25a3..6f6f0af888 100644 --- a/src/gpu/GrOptDrawState.cpp +++ b/src/gpu/GrOptDrawState.cpp @@ -13,12 +13,11 @@ #include "GrProcOptInfo.h" GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, - const GrDrawTargetCaps& caps, + GrGpu* gpu, const ScissorState& scissorState, const GrDeviceCoordTexture* dstCopy, - GrGpu::DrawType drawType) - : fFinalized(false) { - fDrawType = drawType; + GrGpu::DrawType drawType) { + GrBlendCoeff optSrcCoeff; GrBlendCoeff optDstCoeff; GrDrawState::BlendOpt blendOpt = drawState.getBlendOpt(false, &optSrcCoeff, &optDstCoeff); @@ -53,6 +52,8 @@ GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, fDstCopy = *dstCopy; } + GrProgramDesc::DescInfo descInfo; + fFlags = 0; if (drawState.isHWAntialias()) { fFlags |= kHWAA_Flag; @@ -64,33 +65,34 @@ GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, fFlags |= kDither_Flag; } - fDescInfo.fHasVertexColor = drawState.hasGeometryProcessor() && - drawState.getGeometryProcessor()->hasVertexColor(); + descInfo.fHasVertexColor = drawState.hasGeometryProcessor() && + drawState.getGeometryProcessor()->hasVertexColor(); - fDescInfo.fHasVertexCoverage = drawState.hasGeometryProcessor() && - drawState.getGeometryProcessor()->hasVertexCoverage(); + descInfo.fHasVertexCoverage = drawState.hasGeometryProcessor() && + drawState.getGeometryProcessor()->hasVertexCoverage(); bool hasLocalCoords = drawState.hasGeometryProcessor() && drawState.getGeometryProcessor()->hasLocalCoords(); const GrProcOptInfo& colorPOI = drawState.colorProcInfo(); int firstColorStageIdx = colorPOI.firstEffectiveStageIndex(); - fDescInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed(); + descInfo.fInputColorIsUsed = colorPOI.inputColorIsUsed(); fColor = colorPOI.inputColorToEffectiveStage(); if (colorPOI.removeVertexAttrib()) { - fDescInfo.fHasVertexColor = false; + descInfo.fHasVertexColor = false; } // TODO: Once we can handle single or four channel input into coverage stages then we can use // drawState's coverageProcInfo (like color above) to set this initial information. int firstCoverageStageIdx = 0; - fDescInfo.fInputCoverageIsUsed = true; + descInfo.fInputCoverageIsUsed = true; fCoverage = drawState.getCoverage(); - this->adjustProgramForBlendOpt(drawState, blendOpt, &firstColorStageIdx, + this->adjustProgramForBlendOpt(drawState, blendOpt, &descInfo, &firstColorStageIdx, &firstCoverageStageIdx); - this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, hasLocalCoords); + this->getStageStats(drawState, firstColorStageIdx, firstCoverageStageIdx, hasLocalCoords, + &descInfo); // Copy GeometryProcesssor from DS or ODS SkASSERT(GrGpu::IsPathRenderingDrawType(drawType) || @@ -116,15 +118,19 @@ GrOptDrawState::GrOptDrawState(const GrDrawState& drawState, (drawState.fCoverageStages[i], hasLocalCoords)); } - this->setOutputStateInfo(drawState, blendOpt, caps); + this->setOutputStateInfo(drawState, blendOpt, *gpu->caps(), &descInfo); + + // now create a key + gpu->buildProgramDesc(*this, descInfo, drawType, &fDesc); }; void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, GrDrawState::BlendOpt blendOpt, - const GrDrawTargetCaps& caps) { + const GrDrawTargetCaps& caps, + GrProgramDesc::DescInfo* descInfo) { // Set this default and then possibly change our mind if there is coverage. - fDescInfo.fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; - fDescInfo.fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; + descInfo->fPrimaryOutputType = GrProgramDesc::kModulate_PrimaryOutputType; + descInfo->fSecondaryOutputType = GrProgramDesc::kNone_SecondaryOutputType; // Determine whether we should use dual source blending or shader code to keep coverage // separate from color. @@ -134,27 +140,28 @@ void GrOptDrawState::setOutputStateInfo(const GrDrawState& ds, if (caps.dualSourceBlendingSupport()) { if (kZero_GrBlendCoeff == fDstBlend) { // write the coverage value to second color - fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverage_SecondaryOutputType; + descInfo->fSecondaryOutputType = GrProgramDesc::kCoverage_SecondaryOutputType; fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; } else if (kSA_GrBlendCoeff == fDstBlend) { // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. - fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverageISA_SecondaryOutputType; + descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISA_SecondaryOutputType; fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; } else if (kSC_GrBlendCoeff == fDstBlend) { // SA dst coeff becomes 1-(1-SA)*coverage when dst is partially covered. - fDescInfo.fSecondaryOutputType = GrProgramDesc::kCoverageISC_SecondaryOutputType; + descInfo->fSecondaryOutputType = GrProgramDesc::kCoverageISC_SecondaryOutputType; fDstBlend = (GrBlendCoeff)GrGpu::kIS2C_GrBlendCoeff; } - } else if (fDescInfo.fReadsDst && + } else if (descInfo->fReadsDst && kOne_GrBlendCoeff == fSrcBlend && kZero_GrBlendCoeff == fDstBlend) { - fDescInfo.fPrimaryOutputType = GrProgramDesc::kCombineWithDst_PrimaryOutputType; + descInfo->fPrimaryOutputType = GrProgramDesc::kCombineWithDst_PrimaryOutputType; } } } void GrOptDrawState::adjustProgramForBlendOpt(const GrDrawState& ds, GrDrawState::BlendOpt blendOpt, + GrProgramDesc::DescInfo* descInfo, int* firstColorStageIdx, int* firstCoverageStageIdx) { switch (blendOpt) { @@ -164,19 +171,19 @@ void GrOptDrawState::adjustProgramForBlendOpt(const GrDrawState& ds, break; case GrDrawState::kEmitCoverage_BlendOpt: fColor = 0xffffffff; - fDescInfo.fInputColorIsUsed = true; + descInfo->fInputColorIsUsed = true; *firstColorStageIdx = ds.numColorStages(); - fDescInfo.fHasVertexColor = false; + descInfo->fHasVertexColor = false; break; case GrDrawState::kEmitTransBlack_BlendOpt: fColor = 0; fCoverage = 0xff; - fDescInfo.fInputColorIsUsed = true; - fDescInfo.fInputCoverageIsUsed = true; + descInfo->fInputColorIsUsed = true; + descInfo->fInputCoverageIsUsed = true; *firstColorStageIdx = ds.numColorStages(); *firstCoverageStageIdx = ds.numCoverageStages(); - fDescInfo.fHasVertexColor = false; - fDescInfo.fHasVertexCoverage = false; + descInfo->fHasVertexColor = false; + descInfo->fHasVertexCoverage = false; break; } } @@ -191,57 +198,46 @@ static void get_stage_stats(const GrFragmentStage& stage, bool* readsDst, bool* } void GrOptDrawState::getStageStats(const GrDrawState& ds, int firstColorStageIdx, - int firstCoverageStageIdx, bool hasLocalCoords) { + int firstCoverageStageIdx, bool hasLocalCoords, + GrProgramDesc::DescInfo* descInfo) { // We will need a local coord attrib if there is one currently set on the optState and we are // actually generating some effect code - fDescInfo.fRequiresLocalCoordAttrib = hasLocalCoords && + descInfo->fRequiresLocalCoordAttrib = hasLocalCoords && ds.numTotalStages() - firstColorStageIdx - firstCoverageStageIdx > 0; - fDescInfo.fReadsDst = false; - fDescInfo.fReadsFragPosition = false; + descInfo->fReadsDst = false; + descInfo->fReadsFragPosition = false; for (int s = firstColorStageIdx; s < ds.numColorStages(); ++s) { const GrFragmentStage& stage = ds.getColorStage(s); - get_stage_stats(stage, &fDescInfo.fReadsDst, &fDescInfo.fReadsFragPosition); + get_stage_stats(stage, &descInfo->fReadsDst, &descInfo->fReadsFragPosition); } for (int s = firstCoverageStageIdx; s < ds.numCoverageStages(); ++s) { const GrFragmentStage& stage = ds.getCoverageStage(s); - get_stage_stats(stage, &fDescInfo.fReadsDst, &fDescInfo.fReadsFragPosition); + get_stage_stats(stage, &descInfo->fReadsDst, &descInfo->fReadsFragPosition); } if (ds.hasGeometryProcessor()) { const GrGeometryProcessor& gp = *ds.getGeometryProcessor(); - fDescInfo.fReadsFragPosition = fDescInfo.fReadsFragPosition || gp.willReadFragmentPosition(); + descInfo->fReadsFragPosition = descInfo->fReadsFragPosition || gp.willReadFragmentPosition(); } } -void GrOptDrawState::finalize(GrGpu* gpu) { - gpu->buildProgramDesc(*this, fDescInfo, fDrawType, &fDesc); - fFinalized = true; -} - //////////////////////////////////////////////////////////////////////////////// bool GrOptDrawState::operator== (const GrOptDrawState& that) const { - if (!fDescInfo.fHasVertexColor && this->fColor != that.fColor) { + if (this->fDesc != that.fDesc) { + return false; + } + bool hasVertexColors = this->fDesc.header().fColorInput == GrProgramDesc::kAttribute_ColorInput; + if (!hasVertexColors && this->fColor != that.fColor) { return false; } if (this->getRenderTarget() != that.getRenderTarget() || - this->fFragmentStages.count() != that.fFragmentStages.count() || - this->fNumColorStages != that.fNumColorStages || this->fScissorState != that.fScissorState || !this->fViewMatrix.cheapEqualTo(that.fViewMatrix) || this->fSrcBlend != that.fSrcBlend || this->fDstBlend != that.fDstBlend || - this->fDrawType != that.fDrawType || - fDescInfo.fInputColorIsUsed != that.fDescInfo.fInputColorIsUsed || - fDescInfo.fInputCoverageIsUsed != that.fDescInfo.fInputCoverageIsUsed || - fDescInfo.fReadsDst != that.fDescInfo.fReadsDst || - fDescInfo.fReadsFragPosition != that.fDescInfo.fReadsFragPosition || - fDescInfo.fRequiresLocalCoordAttrib != that.fDescInfo.fRequiresLocalCoordAttrib || - fDescInfo.fPrimaryOutputType != that.fDescInfo.fPrimaryOutputType || - fDescInfo.fSecondaryOutputType != that.fDescInfo.fSecondaryOutputType || - this->fScissorState != that.fScissorState || this->fBlendConstant != that.fBlendConstant || this->fFlags != that.fFlags || this->fStencilSettings != that.fStencilSettings || @@ -250,7 +246,9 @@ bool GrOptDrawState::operator== (const GrOptDrawState& that) const { return false; } - if (!fDescInfo.fHasVertexCoverage && this->fCoverage != that.fCoverage) { + bool hasVertexCoverage = + this->fDesc.header().fCoverageInput == GrProgramDesc::kAttribute_ColorInput; + if (!hasVertexCoverage && this->fCoverage != that.fCoverage) { return false; } diff --git a/src/gpu/GrOptDrawState.h b/src/gpu/GrOptDrawState.h index 25a3a49995..ac7ec16402 100644 --- a/src/gpu/GrOptDrawState.h +++ b/src/gpu/GrOptDrawState.h @@ -30,7 +30,7 @@ public: typedef GrClipMaskManager::ScissorState ScissorState; - GrOptDrawState(const GrDrawState& drawState, const GrDrawTargetCaps&, const ScissorState&, + GrOptDrawState(const GrDrawState& drawState, GrGpu*, const ScissorState&, const GrDeviceCoordTexture* dstCopy, GrGpu::DrawType); bool operator== (const GrOptDrawState& that) const; @@ -180,20 +180,33 @@ public: /////////////////////////////////////////////////////////////////////////// - GrGpu::DrawType drawType() const { return fDrawType; } - const GrDeviceCoordTexture* getDstCopy() const { return fDstCopy.texture() ? &fDstCopy : NULL; } - // Finalize *MUST* be called before programDesc() - void finalize(GrGpu*); - - const GrProgramDesc& programDesc() const { SkASSERT(fFinalized); return fDesc; } + const GrProgramDesc& programDesc() const { return fDesc; } private: /** + * Loops through all the color stage effects to check if the stage will ignore color input or + * always output a constant color. In the ignore color input case we can ignore all previous + * stages. In the constant color case, we can ignore all previous stages and + * the current one and set the state color to the constant color. + */ + void computeEffectiveColorStages(const GrDrawState& ds, GrProgramDesc::DescInfo*, + int* firstColorStageIdx, uint8_t* fixFunctionVAToRemove); + + /** + * Loops through all the coverage stage effects to check if the stage will ignore color input. + * If a coverage stage will ignore input, then we can ignore all coverage stages before it. We + * loop to determine the first effective coverage stage. + */ + void computeEffectiveCoverageStages(const GrDrawState& ds, GrProgramDesc::DescInfo* descInfo, + int* firstCoverageStageIdx); + + /** * Alter the program desc and inputs (attribs and processors) based on the blend optimization. */ void adjustProgramForBlendOpt(const GrDrawState& ds, GrDrawState::BlendOpt, + GrProgramDesc::DescInfo*, int* firstColorStageIdx, int* firstCoverageStageIdx); /** @@ -201,14 +214,15 @@ private: * shaders they require. */ void getStageStats(const GrDrawState& ds, int firstColorStageIdx, int firstCoverageStageIdx, - bool hasLocalCoords); + bool hasLocalCoords, GrProgramDesc::DescInfo*); /** * Calculates the primary and secondary output types of the shader. For certain output types * the function may adjust the blend coefficients. After this function is called the src and dst * blend coeffs will represent those used by backend API. */ - void setOutputStateInfo(const GrDrawState& ds, GrDrawState::BlendOpt, const GrDrawTargetCaps&); + void setOutputStateInfo(const GrDrawState& ds, GrDrawState::BlendOpt, const GrDrawTargetCaps&, + GrProgramDesc::DescInfo*); enum Flags { kDither_Flag = 0x1, @@ -235,9 +249,6 @@ private: ProgramGeometryProcessor fGeometryProcessor; ProgramXferProcessor fXferProcessor; FragmentStageArray fFragmentStages; - GrGpu::DrawType fDrawType; - GrProgramDesc::DescInfo fDescInfo; - bool fFinalized; // This function is equivalent to the offset into fFragmentStages where coverage stages begin. int fNumColorStages; diff --git a/src/gpu/GrProgramDesc.h b/src/gpu/GrProgramDesc.h index b51da04658..655254f892 100644 --- a/src/gpu/GrProgramDesc.h +++ b/src/gpu/GrProgramDesc.h @@ -103,6 +103,8 @@ public: // effects that read the fragment position. // Otherwise, 0. + SkBool8 fEmitsPointSize; + ColorInput fColorInput : 8; ColorInput fCoverageInput : 8; diff --git a/src/gpu/GrTest.cpp b/src/gpu/GrTest.cpp index 7038c10966..48f72a7e4c 100644 --- a/src/gpu/GrTest.cpp +++ b/src/gpu/GrTest.cpp @@ -140,7 +140,7 @@ private: return false; } - bool flushGraphicsState(const GrOptDrawState&) SK_OVERRIDE { return false; } + bool flushGraphicsState(const GrOptDrawState&, DrawType) SK_OVERRIDE { return false; } void clearStencil(GrRenderTarget* target) SK_OVERRIDE {} diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index 3b04edb8c8..63cb9da20b 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -123,13 +123,13 @@ void GrGLProgram::bindTextures(const GrGLInstalledProc* ip, const GrProcessor& p /////////////////////////////////////////////////////////////////////////////// -void GrGLProgram::setData(const GrOptDrawState& optState) { +void GrGLProgram::setData(const GrOptDrawState& optState, GrGpu::DrawType drawType) { GrColor color = optState.getColor(); uint8_t coverage = optState.getCoverage(); this->setColor(optState, color); this->setCoverage(optState, coverage); - this->setMatrixAndRenderTargetHeight(optState); + this->setMatrixAndRenderTargetHeight(drawType, optState); const GrDeviceCoordTexture* dstCopy = optState.getDstCopy(); if (dstCopy) { @@ -164,7 +164,7 @@ void GrGLProgram::setData(const GrOptDrawState& optState) { this->setFragmentData(optState); // Some of GrGLProgram subclasses need to update state here - this->didSetData(optState.drawType()); + this->didSetData(drawType); } void GrGLProgram::setFragmentData(const GrOptDrawState& optState) { @@ -241,7 +241,8 @@ void GrGLProgram::setCoverage(const GrOptDrawState& optState, uint8_t coverage) } } -void GrGLProgram::setMatrixAndRenderTargetHeight(const GrOptDrawState& optState) { +void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, + const GrOptDrawState& optState) { // Load the RT height uniform if it is needed to y-flip gl_FragCoord. if (fBuiltinUniformHandles.fRTHeightUni.isValid() && fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->height()) { @@ -250,10 +251,11 @@ void GrGLProgram::setMatrixAndRenderTargetHeight(const GrOptDrawState& optState) } // call subclasses to set the actual view matrix - this->onSetMatrixAndRenderTargetHeight(optState); + this->onSetMatrixAndRenderTargetHeight(drawType, optState); } -void GrGLProgram::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) { +void GrGLProgram::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, + const GrOptDrawState& optState) { const GrRenderTarget* rt = optState.getRenderTarget(); SkISize size; size.set(rt->width(), rt->height()); @@ -287,8 +289,9 @@ GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu, : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, fragmentProcessors) { } -void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(const GrOptDrawState& optState) { - SkASSERT(GrGpu::IsPathRenderingDrawType(optState.drawType())); +void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, + const GrOptDrawState& optState) { + SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); const GrRenderTarget* rt = optState.getRenderTarget(); SkISize size; size.set(rt->width(), rt->height()); diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h index 36bf860233..a273a0381e 100644 --- a/src/gpu/gl/GrGLProgram.h +++ b/src/gpu/gl/GrGLProgram.h @@ -129,7 +129,7 @@ public: * GrGpuGL object to bind the textures required by the GrGLProcessors. The color and coverage * stages come from GrGLProgramDesc::Build(). */ - void setData(const GrOptDrawState&); + void setData(const GrOptDrawState&, GrGpu::DrawType); protected: typedef GrGLProgramDataManager::UniformHandle UniformHandle; @@ -167,8 +167,8 @@ protected: virtual void didSetData(GrGpu::DrawType); // Helper for setData() that sets the view matrix and loads the render target height uniform - void setMatrixAndRenderTargetHeight(const GrOptDrawState&); - virtual void onSetMatrixAndRenderTargetHeight(const GrOptDrawState&); + void setMatrixAndRenderTargetHeight(GrGpu::DrawType, const GrOptDrawState&); + virtual void onSetMatrixAndRenderTargetHeight(GrGpu::DrawType, const GrOptDrawState&); // these reflect the current values of uniforms (GL uniform values travel with program) MatrixState fMatrixState; @@ -206,7 +206,7 @@ protected: GrGLuint programID, const UniformInfoArray&, GrGLInstalledFragProcs* fragmentProcessors); - virtual void onSetMatrixAndRenderTargetHeight(const GrOptDrawState&); + virtual void onSetMatrixAndRenderTargetHeight(GrGpu::DrawType, const GrOptDrawState&); typedef GrGLProgram INHERITED; }; diff --git a/src/gpu/gl/GrGLProgramDesc.cpp b/src/gpu/gl/GrGLProgramDesc.cpp index f8dbbc26f9..74f669f2e3 100644 --- a/src/gpu/gl/GrGLProgramDesc.cpp +++ b/src/gpu/gl/GrGLProgramDesc.cpp @@ -196,6 +196,8 @@ bool GrGLProgramDescBuilder::Build(const GrOptDrawState& optState, header->fHasGeometryProcessor = optState.hasGeometryProcessor(); + header->fEmitsPointSize = GrGpu::kDrawPoints_DrawType == drawType; + bool isPathRendering = GrGpu::IsPathRenderingDrawType(drawType); if (gpu->caps()->pathRenderingSupport() && isPathRendering) { header->fUseNvpr = true; diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp index 383427d9c2..df35d2c78c 100644 --- a/src/gpu/gl/GrGpuGL.cpp +++ b/src/gpu/gl/GrGpuGL.cpp @@ -1894,14 +1894,14 @@ void GrGpuGL::flushStencil(const GrStencilSettings& stencilSettings, DrawType ty } } -void GrGpuGL::flushAAState(const GrOptDrawState& optState) { +void GrGpuGL::flushAAState(const GrOptDrawState& optState, DrawType type) { // At least some ATI linux drivers will render GL_LINES incorrectly when MSAA state is enabled but // the target is not multisampled. Single pixel wide lines are rendered thicker than 1 pixel wide. #if 0 // Replace RT_HAS_MSAA with this definition once this driver bug is no longer a relevant concern #define RT_HAS_MSAA rt->isMultisampled() #else - #define RT_HAS_MSAA (rt->isMultisampled() || kDrawLines_DrawType == optState.drawType()) + #define RT_HAS_MSAA (rt->isMultisampled() || kDrawLines_DrawType == type) #endif const GrRenderTarget* rt = optState.getRenderTarget(); diff --git a/src/gpu/gl/GrGpuGL.h b/src/gpu/gl/GrGpuGL.h index 8a609884e1..4224ba64fd 100644 --- a/src/gpu/gl/GrGpuGL.h +++ b/src/gpu/gl/GrGpuGL.h @@ -155,7 +155,7 @@ private: virtual void clearStencil(GrRenderTarget*) SK_OVERRIDE; - virtual bool flushGraphicsState(const GrOptDrawState&) SK_OVERRIDE; + virtual bool flushGraphicsState(const GrOptDrawState&, DrawType) SK_OVERRIDE; // GrDrawTarget overrides virtual void didAddGpuTraceMarker() SK_OVERRIDE; @@ -188,7 +188,7 @@ private: ~ProgramCache(); void abandon(); - GrGLProgram* getProgram(const GrOptDrawState&); + GrGLProgram* getProgram(const GrOptDrawState&, DrawType); private: enum { @@ -248,7 +248,7 @@ private: void flushRenderTarget(GrGLRenderTarget*, const SkIRect* bounds); void flushStencil(const GrStencilSettings&, DrawType); - void flushAAState(const GrOptDrawState&); + void flushAAState(const GrOptDrawState&, DrawType); bool configToGLFormats(GrPixelConfig config, bool getSizedInternal, diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp index a808aa8dda..cb8810cc79 100644 --- a/src/gpu/gl/GrGpuGL_program.cpp +++ b/src/gpu/gl/GrGpuGL_program.cpp @@ -91,7 +91,7 @@ int GrGpuGL::ProgramCache::search(const GrProgramDesc& desc) const { return SkTSearch(fEntries, fCount, desc, sizeof(Entry*), less); } -GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrOptDrawState& optState) { +GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrOptDrawState& optState, DrawType type) { #ifdef PROGRAM_CACHE_STATS ++fTotalRequests; #endif @@ -126,7 +126,7 @@ GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrOptDrawState& optState) { #ifdef PROGRAM_CACHE_STATS ++fCacheMisses; #endif - GrGLProgram* program = GrGLProgramBuilder::CreateProgram(optState, fGpu); + GrGLProgram* program = GrGLProgramBuilder::CreateProgram(optState, type, fGpu); if (NULL == program) { return NULL; } @@ -201,11 +201,11 @@ GrGLProgram* GrGpuGL::ProgramCache::getProgram(const GrOptDrawState& optState) { #define GL_CALL(X) GR_GL_CALL(this->glInterface(), X) -bool GrGpuGL::flushGraphicsState(const GrOptDrawState& optState) { +bool GrGpuGL::flushGraphicsState(const GrOptDrawState& optState, DrawType type) { // GrGpu::setupClipAndFlushState should have already checked this and bailed if not true. SkASSERT(optState.getRenderTarget()); - if (kStencilPath_DrawType == optState.drawType()) { + if (kStencilPath_DrawType == type) { const GrRenderTarget* rt = optState.getRenderTarget(); SkISize size; size.set(rt->width(), rt->height()); @@ -216,7 +216,7 @@ bool GrGpuGL::flushGraphicsState(const GrOptDrawState& optState) { GrBlendCoeff srcCoeff = optState.getSrcBlendCoeff(); GrBlendCoeff dstCoeff = optState.getDstBlendCoeff(); - fCurrentProgram.reset(fProgramCache->getProgram(optState)); + fCurrentProgram.reset(fProgramCache->getProgram(optState, type)); if (NULL == fCurrentProgram.get()) { SkDEBUGFAIL("Failed to create program!"); return false; @@ -230,15 +230,15 @@ bool GrGpuGL::flushGraphicsState(const GrOptDrawState& optState) { fHWProgramID = programID; } - this->flushBlend(optState, kDrawLines_DrawType == optState.drawType(), srcCoeff, dstCoeff); + this->flushBlend(optState, kDrawLines_DrawType == type, srcCoeff, dstCoeff); - fCurrentProgram->setData(optState); + fCurrentProgram->setData(optState, type); } GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(optState.getRenderTarget()); - this->flushStencil(optState.getStencil(), optState.drawType()); + this->flushStencil(optState.getStencil(), type); this->flushScissor(optState.getScissorState(), glRT->getViewport(), glRT->origin()); - this->flushAAState(optState); + this->flushAAState(optState, type); // This must come after textures are flushed because a texture may need // to be msaa-resolved (which will modify bound FBO state). diff --git a/src/gpu/gl/builders/GrGLGeometryShaderBuilder.cpp b/src/gpu/gl/builders/GrGLGeometryShaderBuilder.cpp index ef8d1a2a35..f35c9ba910 100644 --- a/src/gpu/gl/builders/GrGLGeometryShaderBuilder.cpp +++ b/src/gpu/gl/builders/GrGLGeometryShaderBuilder.cpp @@ -48,7 +48,9 @@ bool GrGLGeometryBuilder::compileAndAttachShaders(GrGLuint programId, geomShaderSrc.append("void main() {\n"); geomShaderSrc.append("\tfor (int i = 0; i < 3; ++i) {\n" "\t\tgl_Position = gl_in[i].gl_Position;\n"); - geomShaderSrc.append("\t\tgl_PointSize = 1.0;\n"); + if (fProgramBuilder->desc().header().fEmitsPointSize) { + geomShaderSrc.append("\t\tgl_PointSize = 1.0;\n"); + } SkASSERT(fInputs.count() == fOutputs.count()); for (int i = 0; i < fInputs.count(); ++i) { geomShaderSrc.appendf("\t\t%s = %s[i];\n", diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp index aa9e40c3f2..64150a4fda 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp +++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp @@ -28,10 +28,13 @@ static const GrGLShaderVar::Precision kDefaultFragmentPrecision = GrGLShaderVar: const int GrGLProgramBuilder::kVarsPerBlock = 8; -GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrOptDrawState& optState, GrGpuGL* gpu) { +GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrOptDrawState& optState, + GrGpu::DrawType drawType, + GrGpuGL* gpu) { // create a builder. This will be handed off to effects so they can use it to add // uniforms, varyings, textures, etc SkAutoTDelete<GrGLProgramBuilder> builder(CreateProgramBuilder(optState, + drawType, optState.hasGeometryProcessor(), gpu)); @@ -70,6 +73,7 @@ GrGLProgram* GrGLProgramBuilder::CreateProgram(const GrOptDrawState& optState, G GrGLProgramBuilder* GrGLProgramBuilder::CreateProgramBuilder(const GrOptDrawState& optState, + GrGpu::DrawType drawType, bool hasGeometryProcessor, GrGpuGL* gpu) { const GrProgramDesc& desc = optState.programDesc(); @@ -230,7 +234,9 @@ void GrGLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr fVS.setupUniformViewMatrix(); const GrProgramDesc::KeyHeader& header = this->header(); - fVS.codeAppend("gl_PointSize = 1.0;"); + if (header.fEmitsPointSize) { + fVS.codeAppend("gl_PointSize = 1.0;"); + } // Setup position // TODO it'd be possible to remove these from the vertexshader builder and have them diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.h b/src/gpu/gl/builders/GrGLProgramBuilder.h index 973ae5e078..76f7ae97c3 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.h +++ b/src/gpu/gl/builders/GrGLProgramBuilder.h @@ -186,7 +186,7 @@ public: * to be used. * @return true if generation was successful. */ - static GrGLProgram* CreateProgram(const GrOptDrawState&, GrGpuGL*); + static GrGLProgram* CreateProgram(const GrOptDrawState&, GrGpu::DrawType, GrGpuGL*); virtual UniformHandle addUniform(uint32_t visibility, GrSLType type, @@ -246,6 +246,7 @@ protected: typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; static GrGLProgramBuilder* CreateProgramBuilder(const GrOptDrawState&, + GrGpu::DrawType, bool hasGeometryProcessor, GrGpuGL*); |