| 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 | 7 |
| 8 #include "GrGLProgram.h" | 8 #include "GrGLProgram.h" |
| 9 | 9 |
| 10 #include "GrAllocator.h" | 10 #include "GrAllocator.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 textureAccess.getParams(), | 122 textureAccess.getParams(), |
| 123 static_cast<GrGLTexture*>(textureAccess.getTexture()))
; | 123 static_cast<GrGLTexture*>(textureAccess.getTexture()))
; |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 | 127 |
| 128 /////////////////////////////////////////////////////////////////////////////// | 128 /////////////////////////////////////////////////////////////////////////////// |
| 129 | 129 |
| 130 void GrGLProgram::setData(const GrOptDrawState& optState, | 130 void GrGLProgram::setData(const GrOptDrawState& optState, |
| 131 GrGpu::DrawType drawType, | 131 GrGpu::DrawType drawType, |
| 132 const GrDeviceCoordTexture* dstCopy) { | 132 const GrDeviceCoordTexture* dstCopy, |
| 133 SharedGLState* sharedState) { |
| 133 GrColor color = optState.getColor(); | 134 GrColor color = optState.getColor(); |
| 134 GrColor coverage = optState.getCoverageColor(); | 135 GrColor coverage = optState.getCoverageColor(); |
| 135 | 136 |
| 136 this->setColor(optState, color); | 137 this->setColor(optState, color, sharedState); |
| 137 this->setCoverage(optState, coverage); | 138 this->setCoverage(optState, coverage, sharedState); |
| 138 this->setMatrixAndRenderTargetHeight(drawType, optState); | 139 this->setMatrixAndRenderTargetHeight(drawType, optState); |
| 139 | 140 |
| 140 if (dstCopy) { | 141 if (dstCopy) { |
| 141 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { | 142 if (fBuiltinUniformHandles.fDstCopyTopLeftUni.isValid()) { |
| 142 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, | 143 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyTopLeftUni, |
| 143 static_cast<GrGLfloat>(dstCopy->offset().
fX), | 144 static_cast<GrGLfloat>(dstCopy->offset().
fX), |
| 144 static_cast<GrGLfloat>(dstCopy->offset().
fY)); | 145 static_cast<GrGLfloat>(dstCopy->offset().
fY)); |
| 145 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, | 146 fProgramDataManager.set2f(fBuiltinUniformHandles.fDstCopyScaleUni, |
| 146 1.f / dstCopy->texture()->width(), | 147 1.f / dstCopy->texture()->width(), |
| 147 1.f / dstCopy->texture()->height()); | 148 1.f / dstCopy->texture()->height()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUnifo
rmHandle(), matrix); | 194 fProgramDataManager.setSkMatrix(transforms[t].fHandle.convertToUnifo
rmHandle(), matrix); |
| 194 transforms[t].fCurrentValue = matrix; | 195 transforms[t].fCurrentValue = matrix; |
| 195 } | 196 } |
| 196 } | 197 } |
| 197 } | 198 } |
| 198 | 199 |
| 199 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { | 200 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { |
| 200 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); | 201 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); |
| 201 } | 202 } |
| 202 | 203 |
| 203 void GrGLProgram::setColor(const GrOptDrawState& optState, GrColor color) { | 204 void GrGLProgram::setColor(const GrOptDrawState& optState, |
| 205 GrColor color, |
| 206 SharedGLState* sharedState) { |
| 204 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 207 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
| 205 switch (header.fColorInput) { | 208 if (!optState.hasColorVertexAttribute()) { |
| 206 case GrGLProgramDesc::kAttribute_ColorInput: | 209 switch (header.fColorInput) { |
| 207 // Attribute case is handled in GrGpuGL::setupGeometry | 210 case GrGLProgramDesc::kAttribute_ColorInput: |
| 208 break; | 211 SkASSERT(-1 != header.fColorAttributeIndex); |
| 209 case GrGLProgramDesc::kUniform_ColorInput: | 212 if (sharedState->fConstAttribColor != color || |
| 210 if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid()) { | 213 sharedState->fConstAttribColorIndex != header.fColorAttribut
eIndex) { |
| 211 // OpenGL ES doesn't support unsigned byte varieties of glUnifor
m | 214 // OpenGL ES only supports the float varieties of glVertexAt
trib |
| 212 GrGLfloat c[4]; | 215 GrGLfloat c[4]; |
| 213 GrColorToRGBAFloat(color, c); | 216 GrColorToRGBAFloat(color, c); |
| 214 fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni, 1,
c); | 217 GL_CALL(VertexAttrib4fv(header.fColorAttributeIndex, c)); |
| 215 fColor = color; | 218 sharedState->fConstAttribColor = color; |
| 216 } | 219 sharedState->fConstAttribColorIndex = header.fColorAttribute
Index; |
| 217 break; | 220 } |
| 218 case GrGLProgramDesc::kAllOnes_ColorInput: | 221 break; |
| 219 // Handled by shader creation | 222 case GrGLProgramDesc::kUniform_ColorInput: |
| 220 break; | 223 if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid(
)) { |
| 221 default: | 224 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform |
| 222 SkFAIL("Unexpected color type."); | 225 GrGLfloat c[4]; |
| 226 GrColorToRGBAFloat(color, c); |
| 227 fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni,
1, c); |
| 228 fColor = color; |
| 229 } |
| 230 sharedState->fConstAttribColorIndex = -1; |
| 231 break; |
| 232 case GrGLProgramDesc::kAllOnes_ColorInput: |
| 233 sharedState->fConstAttribColorIndex = -1; |
| 234 break; |
| 235 default: |
| 236 SkFAIL("Unexpected color type."); |
| 237 } |
| 238 } else { |
| 239 sharedState->fConstAttribColorIndex = -1; |
| 223 } | 240 } |
| 224 } | 241 } |
| 225 | 242 |
| 226 void GrGLProgram::setCoverage(const GrOptDrawState& optState, GrColor coverage)
{ | 243 void GrGLProgram::setCoverage(const GrOptDrawState& optState, |
| 244 GrColor coverage, |
| 245 SharedGLState* sharedState) { |
| 227 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 246 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); |
| 228 switch (header.fCoverageInput) { | 247 if (!optState.hasCoverageVertexAttribute()) { |
| 229 case GrGLProgramDesc::kAttribute_ColorInput: | 248 switch (header.fCoverageInput) { |
| 230 // Attribute case is handled in GrGpuGL::setupGeometry | 249 case GrGLProgramDesc::kAttribute_ColorInput: |
| 231 break; | 250 if (sharedState->fConstAttribCoverage != coverage || |
| 232 case GrGLProgramDesc::kUniform_ColorInput: | 251 sharedState->fConstAttribCoverageIndex != header.fCoverageAt
tributeIndex) { |
| 233 if (fCoverage != coverage) { | 252 // OpenGL ES only supports the float varieties of glVertexA
ttrib |
| 234 // OpenGL ES doesn't support unsigned byte varieties of glUnifor
m | 253 GrGLfloat c[4]; |
| 235 GrGLfloat c[4]; | 254 GrColorToRGBAFloat(coverage, c); |
| 236 GrColorToRGBAFloat(coverage, c); | 255 GL_CALL(VertexAttrib4fv(header.fCoverageAttributeIndex, c)); |
| 237 fProgramDataManager.set4fv(fBuiltinUniformHandles.fCoverageUni,
1, c); | 256 sharedState->fConstAttribCoverage = coverage; |
| 238 fCoverage = coverage; | 257 sharedState->fConstAttribCoverageIndex = header.fCoverageAtt
ributeIndex; |
| 239 } | 258 } |
| 240 break; | 259 break; |
| 241 case GrGLProgramDesc::kAllOnes_ColorInput: | 260 case GrGLProgramDesc::kUniform_ColorInput: |
| 242 // Handled by shader creation | 261 if (fCoverage != coverage) { |
| 243 break; | 262 // OpenGL ES doesn't support unsigned byte varieties of glUn
iform |
| 244 default: | 263 GrGLfloat c[4]; |
| 245 SkFAIL("Unexpected coverage type."); | 264 GrColorToRGBAFloat(coverage, c); |
| 265 fProgramDataManager.set4fv(fBuiltinUniformHandles.fCoverageU
ni, 1, c); |
| 266 fCoverage = coverage; |
| 267 } |
| 268 sharedState->fConstAttribCoverageIndex = -1; |
| 269 break; |
| 270 case GrGLProgramDesc::kAllOnes_ColorInput: |
| 271 sharedState->fConstAttribCoverageIndex = -1; |
| 272 break; |
| 273 default: |
| 274 SkFAIL("Unexpected coverage type."); |
| 275 } |
| 276 } else { |
| 277 sharedState->fConstAttribCoverageIndex = -1; |
| 246 } | 278 } |
| 247 } | 279 } |
| 248 | 280 |
| 249 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, | 281 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, |
| 250 const GrOptDrawState& optState)
{ | 282 const GrOptDrawState& optState)
{ |
| 251 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. | 283 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. |
| 252 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && | 284 if (fBuiltinUniformHandles.fRTHeightUni.isValid() && |
| 253 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->he
ight()) { | 285 fMatrixState.fRenderTargetSize.fHeight != optState.getRenderTarget()->he
ight()) { |
| 254 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, | 286 fProgramDataManager.set1f(fBuiltinUniformHandles.fRTHeightUni, |
| 255 SkIntToScalar(optState.getRenderTarget()->hei
ght())); | 287 SkIntToScalar(optState.getRenderTarget()->hei
ght())); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 for (int t = 0; t < numTransforms; ++t) { | 410 for (int t = 0; t < numTransforms; ++t) { |
| 379 const SkMatrix& transform = get_transform_matrix(proc, false, t); | 411 const SkMatrix& transform = get_transform_matrix(proc, false, t); |
| 380 GrGLPathRendering::PathTexGenComponents components = | 412 GrGLPathRendering::PathTexGenComponents components = |
| 381 GrGLPathRendering::kST_PathTexGenComponents; | 413 GrGLPathRendering::kST_PathTexGenComponents; |
| 382 if (proc.isPerspectiveCoordTransform(t, false)) { | 414 if (proc.isPerspectiveCoordTransform(t, false)) { |
| 383 components = GrGLPathRendering::kSTR_PathTexGenComponents; | 415 components = GrGLPathRendering::kSTR_PathTexGenComponents; |
| 384 } | 416 } |
| 385 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); | 417 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); |
| 386 } | 418 } |
| 387 } | 419 } |
| OLD | NEW |