diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/effects/GrYUVtoRGBEffect.cpp | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgram.cpp | 114 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgram.h | 28 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgramDesc.cpp | 15 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL.cpp | 1 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL.h | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGpuGL_program.cpp | 2 |
7 files changed, 109 insertions, 55 deletions
diff --git a/src/gpu/effects/GrYUVtoRGBEffect.cpp b/src/gpu/effects/GrYUVtoRGBEffect.cpp index 703c672cfd..f02c1b2295 100644 --- a/src/gpu/effects/GrYUVtoRGBEffect.cpp +++ b/src/gpu/effects/GrYUVtoRGBEffect.cpp @@ -109,7 +109,7 @@ private: virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERRIDE { // YUV is opaque inout->setToOther(kA_GrColorComponentFlag, 0xFF << GrColor_SHIFT_A, - InvariantOutput::kWillNot_ReadInput); + InvariantOutput::kWill_ReadInput); } GrCoordTransform fCoordTransform; diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index bfa5f3cbc1..2d9b569333 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -129,12 +129,13 @@ void GrGLProgram::bindTextures(const GrGLInstalledProc* ip, const GrProcessor& p void GrGLProgram::setData(const GrOptDrawState& optState, GrGpu::DrawType drawType, - const GrDeviceCoordTexture* dstCopy) { + const GrDeviceCoordTexture* dstCopy, + SharedGLState* sharedState) { GrColor color = optState.getColor(); GrColor coverage = optState.getCoverageColor(); - this->setColor(optState, color); - this->setCoverage(optState, coverage); + this->setColor(optState, color, sharedState); + this->setCoverage(optState, coverage, sharedState); this->setMatrixAndRenderTargetHeight(drawType, optState); if (dstCopy) { @@ -200,49 +201,80 @@ void GrGLProgram::didSetData(GrGpu::DrawType drawType) { SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); } -void GrGLProgram::setColor(const GrOptDrawState& optState, GrColor color) { +void GrGLProgram::setColor(const GrOptDrawState& optState, + GrColor color, + SharedGLState* sharedState) { const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); - switch (header.fColorInput) { - case GrGLProgramDesc::kAttribute_ColorInput: - // Attribute case is handled in GrGpuGL::setupGeometry - break; - case GrGLProgramDesc::kUniform_ColorInput: - if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid()) { - // OpenGL ES doesn't support unsigned byte varieties of glUniform - GrGLfloat c[4]; - GrColorToRGBAFloat(color, c); - fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni, 1, c); - fColor = color; - } - break; - case GrGLProgramDesc::kAllOnes_ColorInput: - // Handled by shader creation - break; - default: - SkFAIL("Unexpected color type."); + if (!optState.hasColorVertexAttribute()) { + switch (header.fColorInput) { + case GrGLProgramDesc::kAttribute_ColorInput: + SkASSERT(-1 != header.fColorAttributeIndex); + if (sharedState->fConstAttribColor != color || + sharedState->fConstAttribColorIndex != header.fColorAttributeIndex) { + // OpenGL ES only supports the float varieties of glVertexAttrib + GrGLfloat c[4]; + GrColorToRGBAFloat(color, c); + GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); + sharedState->fConstAttribColor = color; + sharedState->fConstAttribColorIndex = header.fColorAttributeIndex; + } + break; + case GrGLProgramDesc::kUniform_ColorInput: + if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid()) { + // OpenGL ES doesn't support unsigned byte varieties of glUniform + GrGLfloat c[4]; + GrColorToRGBAFloat(color, c); + fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni, 1, c); + fColor = color; + } + sharedState->fConstAttribColorIndex = -1; + break; + case GrGLProgramDesc::kAllOnes_ColorInput: + sharedState->fConstAttribColorIndex = -1; + break; + default: + SkFAIL("Unexpected color type."); + } + } else { + sharedState->fConstAttribColorIndex = -1; } } -void GrGLProgram::setCoverage(const GrOptDrawState& optState, GrColor coverage) { +void GrGLProgram::setCoverage(const GrOptDrawState& optState, + GrColor coverage, + SharedGLState* sharedState) { const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); - switch (header.fCoverageInput) { - case GrGLProgramDesc::kAttribute_ColorInput: - // Attribute case is handled in GrGpuGL::setupGeometry - break; - case GrGLProgramDesc::kUniform_ColorInput: - if (fCoverage != coverage) { - // OpenGL ES doesn't support unsigned byte varieties of glUniform - GrGLfloat c[4]; - GrColorToRGBAFloat(coverage, c); - fProgramDataManager.set4fv(fBuiltinUniformHandles.fCoverageUni, 1, c); - fCoverage = coverage; - } - break; - case GrGLProgramDesc::kAllOnes_ColorInput: - // Handled by shader creation - break; - default: - SkFAIL("Unexpected coverage type."); + if (!optState.hasCoverageVertexAttribute()) { + switch (header.fCoverageInput) { + case GrGLProgramDesc::kAttribute_ColorInput: + if (sharedState->fConstAttribCoverage != coverage || + sharedState->fConstAttribCoverageIndex != header.fCoverageAttributeIndex) { + // OpenGL ES only supports the float varieties of glVertexAttrib + GrGLfloat c[4]; + GrColorToRGBAFloat(coverage, c); + GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); + sharedState->fConstAttribCoverage = coverage; + sharedState->fConstAttribCoverageIndex = header.fCoverageAttributeIndex; + } + break; + case GrGLProgramDesc::kUniform_ColorInput: + if (fCoverage != coverage) { + // OpenGL ES doesn't support unsigned byte varieties of glUniform + GrGLfloat c[4]; + GrColorToRGBAFloat(coverage, c); + fProgramDataManager.set4fv(fBuiltinUniformHandles.fCoverageUni, 1, c); + fCoverage = coverage; + } + sharedState->fConstAttribCoverageIndex = -1; + break; + case GrGLProgramDesc::kAllOnes_ColorInput: + sharedState->fConstAttribCoverageIndex = -1; + break; + default: + SkFAIL("Unexpected coverage type."); + } + } else { + sharedState->fConstAttribCoverageIndex = -1; } } diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h index ca75e206f1..e8aef35f1d 100644 --- a/src/gpu/gl/GrGLProgram.h +++ b/src/gpu/gl/GrGLProgram.h @@ -60,6 +60,27 @@ public: virtual bool hasVertexShader() const { return true; } /** + * Some GL state that is relevant to programs is not stored per-program. In particular color + * and coverage attributes can be global state. This struct is read and updated by + * GrGLProgram::setColor and GrGLProgram::setCoverage to allow us to avoid setting this state + * redundantly. + */ + struct SharedGLState { + GrColor fConstAttribColor; + int fConstAttribColorIndex; + GrColor fConstAttribCoverage; + int fConstAttribCoverageIndex; + + SharedGLState() { this->invalidate(); } + void invalidate() { + fConstAttribColor = GrColor_ILLEGAL; + fConstAttribColorIndex = -1; + fConstAttribCoverage = GrColor_ILLEGAL; + fConstAttribCoverageIndex = -1; + } + }; + + /** * The GrDrawState's view matrix along with the aspects of the render target determine the * matrix sent to GL. The size of the render target affects the GL matrix because we must * convert from Skia device coords to GL's normalized coords. Also the origin of the render @@ -131,7 +152,8 @@ public: */ void setData(const GrOptDrawState&, GrGpu::DrawType, - const GrDeviceCoordTexture* dstCopy /* can be NULL*/); + const GrDeviceCoordTexture* dstCopy, // can be NULL + SharedGLState*); protected: typedef GrGLProgramDataManager::UniformHandle UniformHandle; @@ -151,11 +173,11 @@ protected: // Helper for setData(). Makes GL calls to specify the initial color when there is not // per-vertex colors. - void setColor(const GrOptDrawState&, GrColor color); + void setColor(const GrOptDrawState&, GrColor color, SharedGLState*); // Helper for setData(). Makes GL calls to specify the initial coverage when there is not // per-vertex coverages. - void setCoverage(const GrOptDrawState&, GrColor coverage); + void setCoverage(const GrOptDrawState&, GrColor coverage, SharedGLState*); // A templated helper to loop over effects, set the transforms(via subclass) and bind textures void setFragmentData(const GrOptDrawState&); diff --git a/src/gpu/gl/GrGLProgramDesc.cpp b/src/gpu/gl/GrGLProgramDesc.cpp index 733de13dc6..79088137ca 100644 --- a/src/gpu/gl/GrGLProgramDesc.cpp +++ b/src/gpu/gl/GrGLProgramDesc.cpp @@ -257,8 +257,8 @@ bool GrGLProgramDesc::Build(const GrOptDrawState& optState, header->fEmitsPointSize = GrGpu::kDrawPoints_DrawType == drawType; - bool isPathRendering = GrGpu::IsPathRenderingDrawType(drawType); - if (gpu->caps()->pathRenderingSupport() && isPathRendering && + if (gpu->caps()->pathRenderingSupport() && + GrGpu::IsPathRenderingDrawType(drawType) && gpu->glPathRendering()->texturingMode() == GrGLPathRendering::FixedFunction_TexturingMode) { header->fUseFragShaderOnly = true; SkASSERT(!optState.hasGeometryProcessor()); @@ -266,15 +266,12 @@ bool GrGLProgramDesc::Build(const GrOptDrawState& optState, header->fUseFragShaderOnly = false; } - bool hasUniformColor = inputColorIsUsed && - (isPathRendering || !optState.hasColorVertexAttribute()); - - bool hasUniformCoverage = inputCoverageIsUsed && - (isPathRendering || !optState.hasCoverageVertexAttribute()); + bool defaultToUniformInputs = GrGpu::IsPathRenderingDrawType(drawType) || + GR_GL_NO_CONSTANT_ATTRIBUTES; if (!inputColorIsUsed) { header->fColorInput = kAllOnes_ColorInput; - } else if (hasUniformColor) { + } else if (defaultToUniformInputs && !optState.hasColorVertexAttribute()) { header->fColorInput = kUniform_ColorInput; } else { header->fColorInput = kAttribute_ColorInput; @@ -286,7 +283,7 @@ bool GrGLProgramDesc::Build(const GrOptDrawState& optState, if (covIsSolidWhite || !inputCoverageIsUsed) { header->fCoverageInput = kAllOnes_ColorInput; - } else if (hasUniformCoverage) { + } else if (defaultToUniformInputs && !optState.hasCoverageVertexAttribute()) { header->fCoverageInput = kUniform_ColorInput; } else { header->fCoverageInput = kAttribute_ColorInput; diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp index a85548ea64..7b892913c5 100644 --- a/src/gpu/gl/GrGpuGL.cpp +++ b/src/gpu/gl/GrGpuGL.cpp @@ -342,6 +342,7 @@ void GrGpuGL::onResetContext(uint32_t resetBits) { if (resetBits & kProgram_GrGLBackendState) { fHWProgramID = 0; + fSharedGLProgramState.invalidate(); } } diff --git a/src/gpu/gl/GrGpuGL.h b/src/gpu/gl/GrGpuGL.h index dc0d076a2d..973a568981 100644 --- a/src/gpu/gl/GrGpuGL.h +++ b/src/gpu/gl/GrGpuGL.h @@ -288,6 +288,8 @@ private: int fHWActiveTextureUnitIdx; GrGLuint fHWProgramID; + GrGLProgram::SharedGLState fSharedGLProgramState; + enum TriState { kNo_TriState, kYes_TriState, diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp index a1259c9bf8..bf73f0059c 100644 --- a/src/gpu/gl/GrGpuGL_program.cpp +++ b/src/gpu/gl/GrGpuGL_program.cpp @@ -256,7 +256,7 @@ bool GrGpuGL::flushGraphicsState(DrawType type, this->flushBlend(*optState.get(), kDrawLines_DrawType == type, srcCoeff, dstCoeff); - fCurrentProgram->setData(*optState.get(), type, dstCopy); + fCurrentProgram->setData(*optState.get(), type, dstCopy, &fSharedGLProgramState); } GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(optState->getRenderTarget()); |