| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | |
| 8 #include "GrGLProgram.h" | 7 #include "GrGLProgram.h" |
| 9 | 8 |
| 10 #include "GrAllocator.h" | 9 #include "GrAllocator.h" |
| 11 #include "GrEffect.h" | 10 #include "GrEffect.h" |
| 12 #include "GrCoordTransform.h" | 11 #include "GrCoordTransform.h" |
| 13 #include "GrGLEffect.h" | 12 #include "GrGLEffect.h" |
| 14 #include "GrGpuGL.h" | 13 #include "GrGpuGL.h" |
| 15 #include "GrGLPathRendering.h" | 14 #include "GrGLPathRendering.h" |
| 16 #include "GrGLShaderVar.h" | 15 #include "GrGLShaderVar.h" |
| 17 #include "GrGLSL.h" | 16 #include "GrGLSL.h" |
| 17 #include "GrOptDrawState.h" |
| 18 #include "SkXfermode.h" | 18 #include "SkXfermode.h" |
| 19 | 19 |
| 20 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) | 20 #define GL_CALL(X) GR_GL_CALL(fGpu->glInterface(), X) |
| 21 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) | 21 #define GL_CALL_RET(R, X) GR_GL_CALL_RET(fGpu->glInterface(), R, X) |
| 22 | 22 |
| 23 GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu, | 23 GrGLProgram* GrGLProgram::Create(GrGpuGL* gpu, |
| 24 const GrGLProgramDesc& desc, | 24 const GrGLProgramDesc& desc, |
| 25 const GrEffectStage* geometryProcessor, | 25 const GrEffectStage* geometryProcessor, |
| 26 const GrEffectStage* colorStages[], | 26 const GrEffectStage* colorStages[], |
| 27 const GrEffectStage* coverageStages[]) { | 27 const GrEffectStage* coverageStages[]) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 } | 101 } |
| 102 if (fGeometryProcessor.get()) { | 102 if (fGeometryProcessor.get()) { |
| 103 fGeometryProcessor->initSamplers(fProgramDataManager, &texUnitIdx); | 103 fGeometryProcessor->initSamplers(fProgramDataManager, &texUnitIdx); |
| 104 } | 104 } |
| 105 fColorEffects->initSamplers(fProgramDataManager, &texUnitIdx); | 105 fColorEffects->initSamplers(fProgramDataManager, &texUnitIdx); |
| 106 fCoverageEffects->initSamplers(fProgramDataManager, &texUnitIdx); | 106 fCoverageEffects->initSamplers(fProgramDataManager, &texUnitIdx); |
| 107 } | 107 } |
| 108 | 108 |
| 109 /////////////////////////////////////////////////////////////////////////////// | 109 /////////////////////////////////////////////////////////////////////////////// |
| 110 | 110 |
| 111 void GrGLProgram::setData(GrGpu::DrawType drawType, | 111 void GrGLProgram::setData(const GrOptDrawState& optState, |
| 112 GrDrawState::BlendOptFlags blendOpts, | 112 GrGpu::DrawType drawType, |
| 113 const GrEffectStage* geometryProcessor, | 113 const GrEffectStage* geometryProcessor, |
| 114 const GrEffectStage* colorStages[], | 114 const GrEffectStage* colorStages[], |
| 115 const GrEffectStage* coverageStages[], | 115 const GrEffectStage* coverageStages[], |
| 116 const GrDeviceCoordTexture* dstCopy, | 116 const GrDeviceCoordTexture* dstCopy, |
| 117 SharedGLState* sharedState) { | 117 SharedGLState* sharedState) { |
| 118 const GrDrawState& drawState = fGpu->getDrawState(); | 118 GrColor color = optState.getColor(); |
| 119 GrColor coverage = optState.getCoverageColor(); |
| 119 | 120 |
| 120 GrColor color; | 121 this->setColor(optState, color, sharedState); |
| 121 GrColor coverage; | 122 this->setCoverage(optState, coverage, sharedState); |
| 122 if (blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag) { | 123 this->setMatrixAndRenderTargetHeight(drawType, optState); |
| 123 color = 0; | |
| 124 coverage = 0; | |
| 125 } else if (blendOpts & GrDrawState::kEmitCoverage_BlendOptFlag) { | |
| 126 color = 0xffffffff; | |
| 127 coverage = drawState.getCoverageColor(); | |
| 128 } else { | |
| 129 color = drawState.getColor(); | |
| 130 coverage = drawState.getCoverageColor(); | |
| 131 } | |
| 132 | |
| 133 this->setColor(drawState, color, sharedState); | |
| 134 this->setCoverage(drawState, coverage, sharedState); | |
| 135 this->setMatrixAndRenderTargetHeight(drawType, drawState); | |
| 136 | 124 |
| 137 if (dstCopy) { | 125 if (dstCopy) { |
| 138 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { | 126 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { |
| 139 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, | 127 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, |
| 140 static_cast<GrGLfloat>(dstCopy->offset().
fX), | 128 static_cast<GrGLfloat>(dstCopy->offset().
fX), |
| 141 static_cast<GrGLfloat>(dstCopy->offset().
fY)); | 129 static_cast<GrGLfloat>(dstCopy->offset().
fY)); |
| 142 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, | 130 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, |
| 143 1.f / dstCopy->texture()->width(), | 131 1.f / dstCopy->texture()->width(), |
| 144 1.f / dstCopy->texture()->height()); | 132 1.f / dstCopy->texture()->height()); |
| 145 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture())
; | 133 GrGLTexture* texture = static_cast<GrGLTexture*>(dstCopy->texture())
; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 163 fCoverageEffects->setData(fGpu, drawType,fProgramDataManager, coverageStages
); | 151 fCoverageEffects->setData(fGpu, drawType,fProgramDataManager, coverageStages
); |
| 164 | 152 |
| 165 // PathTexGen state applies to the the fixed function vertex shader. For | 153 // PathTexGen state applies to the the fixed function vertex shader. For |
| 166 // custom shaders, it's ignored, so we don't need to change the texgen | 154 // custom shaders, it's ignored, so we don't need to change the texgen |
| 167 // settings in that case. | 155 // settings in that case. |
| 168 if (!fHasVertexShader) { | 156 if (!fHasVertexShader) { |
| 169 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); | 157 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); |
| 170 } | 158 } |
| 171 } | 159 } |
| 172 | 160 |
| 173 void GrGLProgram::setColor(const GrDrawState& drawState, | 161 void GrGLProgram::setColor(const GrOptDrawState& optState, |
| 174 GrColor color, | 162 GrColor color, |
| 175 SharedGLState* sharedState) { | 163 SharedGLState* sharedState) { |
| 176 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 164 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
| 177 if (!drawState.hasColorVertexAttribute() || drawState.canIgnoreColorAttribut
e()) { | 165 if (!optState.hasColorVertexAttribute()) { |
| 178 switch (header.fColorInput) { | 166 switch (header.fColorInput) { |
| 179 case GrGLProgramDesc::kAttribute_ColorInput: | 167 case GrGLProgramDesc::kAttribute_ColorInput: |
| 180 SkASSERT(-1 != header.fColorAttributeIndex); | 168 SkASSERT(-1 != header.fColorAttributeIndex); |
| 181 if (sharedState->fConstAttribColor != color || | 169 if (sharedState->fConstAttribColor != color || |
| 182 sharedState->fConstAttribColorIndex != header.fColorAttribut
eIndex) { | 170 sharedState->fConstAttribColorIndex != header.fColorAttribut
eIndex) { |
| 183 // OpenGL ES only supports the float varieties of glVertexAt
trib | 171 // OpenGL ES only supports the float varieties of glVertexAt
trib |
| 184 GrGLfloat c[4]; | 172 GrGLfloat c[4]; |
| 185 GrColorToRGBAFloat(color, c); | 173 GrColorToRGBAFloat(color, c); |
| 186 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); | 174 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); |
| 187 sharedState->fConstAttribColor = color; | 175 sharedState->fConstAttribColor = color; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 202 sharedState->fConstAttribColorIndex = -1; | 190 sharedState->fConstAttribColorIndex = -1; |
| 203 break; | 191 break; |
| 204 default: | 192 default: |
| 205 SkFAIL("Unexpected color type."); | 193 SkFAIL("Unexpected color type."); |
| 206 } | 194 } |
| 207 } else { | 195 } else { |
| 208 sharedState->fConstAttribColorIndex = -1; | 196 sharedState->fConstAttribColorIndex = -1; |
| 209 } | 197 } |
| 210 } | 198 } |
| 211 | 199 |
| 212 void GrGLProgram::setCoverage(const GrDrawState& drawState, | 200 void GrGLProgram::setCoverage(const GrOptDrawState& optState, |
| 213 GrColor coverage, | 201 GrColor coverage, |
| 214 SharedGLState* sharedState) { | 202 SharedGLState* sharedState) { |
| 215 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 203 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
| 216 if (!drawState.hasCoverageVertexAttribute()) { | 204 if (!optState.hasCoverageVertexAttribute()) { |
| 217 switch (header.fCoverageInput) { | 205 switch (header.fCoverageInput) { |
| 218 case GrGLProgramDesc::kAttribute_ColorInput: | 206 case GrGLProgramDesc::kAttribute_ColorInput: |
| 219 if (sharedState->fConstAttribCoverage != coverage || | 207 if (sharedState->fConstAttribCoverage != coverage || |
| 220 sharedState->fConstAttribCoverageIndex != header.fCoverageAt
tributeIndex) { | 208 sharedState->fConstAttribCoverageIndex != header.fCoverageAt
tributeIndex) { |
| 221 // OpenGL ES only supports the float varieties of glVertexA
ttrib | 209 // OpenGL ES only supports the float varieties of glVertexA
ttrib |
| 222 GrGLfloat c[4]; | 210 GrGLfloat c[4]; |
| 223 GrColorToRGBAFloat(coverage, c); | 211 GrColorToRGBAFloat(coverage, c); |
| 224 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); | 212 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); |
| 225 sharedState->fConstAttribCoverage = coverage; | 213 sharedState->fConstAttribCoverage = coverage; |
| 226 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt
ributeIndex; | 214 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt
ributeIndex; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 241 break; | 229 break; |
| 242 default: | 230 default: |
| 243 SkFAIL("Unexpected coverage type."); | 231 SkFAIL("Unexpected coverage type."); |
| 244 } | 232 } |
| 245 } else { | 233 } else { |
| 246 sharedState->fConstAttribCoverageIndex = -1; | 234 sharedState->fConstAttribCoverageIndex = -1; |
| 247 } | 235 } |
| 248 } | 236 } |
| 249 | 237 |
| 250 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, | 238 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, |
| 251 const GrDrawState& drawState) { | 239 const GrOptDrawState& optState)
{ |
| 252 const GrRenderTarget* rt = drawState.getRenderTarget(); | 240 const GrRenderTarget* rt = optState.getRenderTarget(); |
| 253 SkISize size; | 241 SkISize size; |
| 254 size.set(rt->width(), rt->height()); | 242 size.set(rt->width(), rt->height()); |
| 255 | 243 |
| 256 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. | 244 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. |
| 257 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && | 245 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && |
| 258 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { | 246 fMatrixState.fRenderTargetSize.fHeight != size.fHeight) { |
| 259 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, | 247 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, |
| 260 SkIntToScalar(size.fHeight)); | 248 SkIntToScalar(size.fHeight)); |
| 261 } | 249 } |
| 262 | 250 |
| 263 if (GrGpu::IsPathRenderingDrawType(drawType)) { | 251 if (GrGpu::IsPathRenderingDrawType(drawType)) { |
| 264 fGpu->glPathRendering()->setProjectionMatrix(drawState.getViewMatrix(),
size, rt->origin()); | 252 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), s
ize, rt->origin()); |
| 265 } else if (fMatrixState.fRenderTargetOrigin != rt->origin() || | 253 } else if (fMatrixState.fRenderTargetOrigin != rt->origin() || |
| 266 fMatrixState.fRenderTargetSize != size || | 254 fMatrixState.fRenderTargetSize != size || |
| 267 !fMatrixState.fViewMatrix.cheapEqualTo(drawState.getViewMatrix())
) { | 255 !fMatrixState.fViewMatrix.cheapEqualTo(optState.getViewMatrix()))
{ |
| 268 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid()); | 256 SkASSERT(fBuiltinUniformHandles.fViewMatrixUni.isValid()); |
| 269 | 257 |
| 270 fMatrixState.fViewMatrix = drawState.getViewMatrix(); | 258 fMatrixState.fViewMatrix = optState.getViewMatrix(); |
| 271 fMatrixState.fRenderTargetSize = size; | 259 fMatrixState.fRenderTargetSize = size; |
| 272 fMatrixState.fRenderTargetOrigin = rt->origin(); | 260 fMatrixState.fRenderTargetOrigin = rt->origin(); |
| 273 | 261 |
| 274 GrGLfloat viewMatrix[3 * 3]; | 262 GrGLfloat viewMatrix[3 * 3]; |
| 275 fMatrixState.getGLMatrix<3>(viewMatrix); | 263 fMatrixState.getGLMatrix<3>(viewMatrix); |
| 276 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, v
iewMatrix); | 264 fProgramDataManager.setMatrix3f(fBuiltinUniformHandles.fViewMatrixUni, v
iewMatrix); |
| 277 | 265 |
| 278 GrGLfloat rtAdjustmentVec[4]; | 266 GrGLfloat rtAdjustmentVec[4]; |
| 279 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); | 267 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); |
| 280 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r
tAdjustmentVec); | 268 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r
tAdjustmentVec); |
| 281 } | 269 } |
| 282 } | 270 } |
| OLD | NEW |