| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); | 49 combined[SkMatrix::kMPersp1] - combined[SkMatrix::kMScaleY]); |
| 50 combined.set(SkMatrix::kMTransY, | 50 combined.set(SkMatrix::kMTransY, |
| 51 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); | 51 combined[SkMatrix::kMPersp2] - combined[SkMatrix::kMTransY]); |
| 52 } | 52 } |
| 53 return combined; | 53 return combined; |
| 54 } | 54 } |
| 55 | 55 |
| 56 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 56 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 57 | 57 |
| 58 GrGLProgram::GrGLProgram(GrGpuGL* gpu, | 58 GrGLProgram::GrGLProgram(GrGpuGL* gpu, |
| 59 const GrGLProgramDesc& desc, | 59 const GrProgramDesc& desc, |
| 60 const BuiltinUniformHandles& builtinUniforms, | 60 const BuiltinUniformHandles& builtinUniforms, |
| 61 GrGLuint programID, | 61 GrGLuint programID, |
| 62 const UniformInfoArray& uniforms, | 62 const UniformInfoArray& uniforms, |
| 63 GrGLInstalledGeoProc* geometryProcessor, | 63 GrGLInstalledGeoProc* geometryProcessor, |
| 64 GrGLInstalledFragProcs* fragmentProcessors) | 64 GrGLInstalledFragProcs* fragmentProcessors) |
| 65 : fColor(GrColor_ILLEGAL) | 65 : fColor(GrColor_ILLEGAL) |
| 66 , fCoverage(GrColor_ILLEGAL) | 66 , fCoverage(GrColor_ILLEGAL) |
| 67 , fDstCopyTexUnit(-1) | 67 , fDstCopyTexUnit(-1) |
| 68 , fBuiltinUniformHandles(builtinUniforms) | 68 , fBuiltinUniformHandles(builtinUniforms) |
| 69 , fProgramID(programID) | 69 , fProgramID(programID) |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 transforms[t].fCurrentValue = matrix; | 194 transforms[t].fCurrentValue = matrix; |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 | 198 |
| 199 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { | 199 void GrGLProgram::didSetData(GrGpu::DrawType drawType) { |
| 200 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); | 200 SkASSERT(!GrGpu::IsPathRenderingDrawType(drawType)); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void GrGLProgram::setColor(const GrOptDrawState& optState, GrColor color) { | 203 void GrGLProgram::setColor(const GrOptDrawState& optState, GrColor color) { |
| 204 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 204 const GrProgramDesc::KeyHeader& header = fDesc.header(); |
| 205 switch (header.fColorInput) { | 205 switch (header.fColorInput) { |
| 206 case GrGLProgramDesc::kAttribute_ColorInput: | 206 case GrProgramDesc::kAttribute_ColorInput: |
| 207 // Attribute case is handled in GrGpuGL::setupGeometry | 207 // Attribute case is handled in GrGpuGL::setupGeometry |
| 208 break; | 208 break; |
| 209 case GrGLProgramDesc::kUniform_ColorInput: | 209 case GrProgramDesc::kUniform_ColorInput: |
| 210 if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid()) { | 210 if (fColor != color && fBuiltinUniformHandles.fColorUni.isValid()) { |
| 211 // OpenGL ES doesn't support unsigned byte varieties of glUnifor
m | 211 // OpenGL ES doesn't support unsigned byte varieties of glUnifor
m |
| 212 GrGLfloat c[4]; | 212 GrGLfloat c[4]; |
| 213 GrColorToRGBAFloat(color, c); | 213 GrColorToRGBAFloat(color, c); |
| 214 fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni, 1,
c); | 214 fProgramDataManager.set4fv(fBuiltinUniformHandles.fColorUni, 1,
c); |
| 215 fColor = color; | 215 fColor = color; |
| 216 } | 216 } |
| 217 break; | 217 break; |
| 218 case GrGLProgramDesc::kAllOnes_ColorInput: | 218 case GrProgramDesc::kAllOnes_ColorInput: |
| 219 // Handled by shader creation | 219 // Handled by shader creation |
| 220 break; | 220 break; |
| 221 default: | 221 default: |
| 222 SkFAIL("Unexpected color type."); | 222 SkFAIL("Unexpected color type."); |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 | 225 |
| 226 void GrGLProgram::setCoverage(const GrOptDrawState& optState, GrColor coverage)
{ | 226 void GrGLProgram::setCoverage(const GrOptDrawState& optState, GrColor coverage)
{ |
| 227 const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader(); | 227 const GrProgramDesc::KeyHeader& header = fDesc.header(); |
| 228 switch (header.fCoverageInput) { | 228 switch (header.fCoverageInput) { |
| 229 case GrGLProgramDesc::kAttribute_ColorInput: | 229 case GrProgramDesc::kAttribute_ColorInput: |
| 230 // Attribute case is handled in GrGpuGL::setupGeometry | 230 // Attribute case is handled in GrGpuGL::setupGeometry |
| 231 break; | 231 break; |
| 232 case GrGLProgramDesc::kUniform_ColorInput: | 232 case GrProgramDesc::kUniform_ColorInput: |
| 233 if (fCoverage != coverage) { | 233 if (fCoverage != coverage) { |
| 234 // OpenGL ES doesn't support unsigned byte varieties of glUnifor
m | 234 // OpenGL ES doesn't support unsigned byte varieties of glUnifor
m |
| 235 GrGLfloat c[4]; | 235 GrGLfloat c[4]; |
| 236 GrColorToRGBAFloat(coverage, c); | 236 GrColorToRGBAFloat(coverage, c); |
| 237 fProgramDataManager.set4fv(fBuiltinUniformHandles.fCoverageUni,
1, c); | 237 fProgramDataManager.set4fv(fBuiltinUniformHandles.fCoverageUni,
1, c); |
| 238 fCoverage = coverage; | 238 fCoverage = coverage; |
| 239 } | 239 } |
| 240 break; | 240 break; |
| 241 case GrGLProgramDesc::kAllOnes_ColorInput: | 241 case GrProgramDesc::kAllOnes_ColorInput: |
| 242 // Handled by shader creation | 242 // Handled by shader creation |
| 243 break; | 243 break; |
| 244 default: | 244 default: |
| 245 SkFAIL("Unexpected coverage type."); | 245 SkFAIL("Unexpected coverage type."); |
| 246 } | 246 } |
| 247 } | 247 } |
| 248 | 248 |
| 249 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, | 249 void GrGLProgram::setMatrixAndRenderTargetHeight(GrGpu::DrawType drawType, |
| 250 const GrOptDrawState& optState)
{ | 250 const GrOptDrawState& optState)
{ |
| 251 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. | 251 // Load the RT height uniform if it is needed to y-flip gl_FragCoord. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 279 | 279 |
| 280 GrGLfloat rtAdjustmentVec[4]; | 280 GrGLfloat rtAdjustmentVec[4]; |
| 281 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); | 281 fMatrixState.getRTAdjustmentVec(rtAdjustmentVec); |
| 282 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r
tAdjustmentVec); | 282 fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, r
tAdjustmentVec); |
| 283 } | 283 } |
| 284 } | 284 } |
| 285 | 285 |
| 286 ////////////////////////////////////////////////////////////////////////////////
///////// | 286 ////////////////////////////////////////////////////////////////////////////////
///////// |
| 287 | 287 |
| 288 GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu, | 288 GrGLNvprProgramBase::GrGLNvprProgramBase(GrGpuGL* gpu, |
| 289 const GrGLProgramDesc& desc, | 289 const GrProgramDesc& desc, |
| 290 const BuiltinUniformHandles& builtinUni
forms, | 290 const BuiltinUniformHandles& builtinUni
forms, |
| 291 GrGLuint programID, | 291 GrGLuint programID, |
| 292 const UniformInfoArray& uniforms, | 292 const UniformInfoArray& uniforms, |
| 293 GrGLInstalledFragProcs* fragmentProcess
ors) | 293 GrGLInstalledFragProcs* fragmentProcess
ors) |
| 294 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, fragmentP
rocessors) { | 294 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, NULL, fragmentP
rocessors) { |
| 295 } | 295 } |
| 296 | 296 |
| 297 void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawT
ype, | 297 void GrGLNvprProgramBase::onSetMatrixAndRenderTargetHeight(GrGpu::DrawType drawT
ype, |
| 298 const GrOptDrawState&
optState) { | 298 const GrOptDrawState&
optState) { |
| 299 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | 299 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); |
| 300 const GrRenderTarget* rt = optState.getRenderTarget(); | 300 const GrRenderTarget* rt = optState.getRenderTarget(); |
| 301 SkISize size; | 301 SkISize size; |
| 302 size.set(rt->width(), rt->height()); | 302 size.set(rt->width(), rt->height()); |
| 303 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size,
rt->origin()); | 303 fGpu->glPathRendering()->setProjectionMatrix(optState.getViewMatrix(), size,
rt->origin()); |
| 304 } | 304 } |
| 305 | 305 |
| 306 ////////////////////////////////////////////////////////////////////////////////
///////// | 306 ////////////////////////////////////////////////////////////////////////////////
///////// |
| 307 | 307 |
| 308 GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu, | 308 GrGLNvprProgram::GrGLNvprProgram(GrGpuGL* gpu, |
| 309 const GrGLProgramDesc& desc, | 309 const GrProgramDesc& desc, |
| 310 const BuiltinUniformHandles& builtinUniforms, | 310 const BuiltinUniformHandles& builtinUniforms, |
| 311 GrGLuint programID, | 311 GrGLuint programID, |
| 312 const UniformInfoArray& uniforms, | 312 const UniformInfoArray& uniforms, |
| 313 GrGLInstalledFragProcs* fragmentProcessors, | 313 GrGLInstalledFragProcs* fragmentProcessors, |
| 314 const SeparableVaryingInfoArray& separableVaryi
ngs) | 314 const SeparableVaryingInfoArray& separableVaryi
ngs) |
| 315 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fragmentProcess
ors) { | 315 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fragmentProcess
ors) { |
| 316 int count = separableVaryings.count(); | 316 int count = separableVaryings.count(); |
| 317 fVaryings.push_back_n(count); | 317 fVaryings.push_back_n(count); |
| 318 for (int i = 0; i < count; i++) { | 318 for (int i = 0; i < count; i++) { |
| 319 Varying& varying = fVaryings[i]; | 319 Varying& varying = fVaryings[i]; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 348 fragmentIn
put.fLocation, | 348 fragmentIn
put.fLocation, |
| 349 GR_GL_OBJE
CT_LINEAR, | 349 GR_GL_OBJE
CT_LINEAR, |
| 350 components
, | 350 components
, |
| 351 transform)
; | 351 transform)
; |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 | 354 |
| 355 ////////////////////////////////////////////////////////////////////////////////
////// | 355 ////////////////////////////////////////////////////////////////////////////////
////// |
| 356 | 356 |
| 357 GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGpuGL* gpu, | 357 GrGLLegacyNvprProgram::GrGLLegacyNvprProgram(GrGpuGL* gpu, |
| 358 const GrGLProgramDesc& desc, | 358 const GrProgramDesc& desc, |
| 359 const BuiltinUniformHandles& builti
nUniforms, | 359 const BuiltinUniformHandles& builti
nUniforms, |
| 360 GrGLuint programID, | 360 GrGLuint programID, |
| 361 const UniformInfoArray& uniforms, | 361 const UniformInfoArray& uniforms, |
| 362 GrGLInstalledFragProcs* fps, | 362 GrGLInstalledFragProcs* fps, |
| 363 int texCoordSetCnt) | 363 int texCoordSetCnt) |
| 364 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fps) | 364 : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, fps) |
| 365 , fTexCoordSetCnt(texCoordSetCnt) { | 365 , fTexCoordSetCnt(texCoordSetCnt) { |
| 366 } | 366 } |
| 367 | 367 |
| 368 void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { | 368 void GrGLLegacyNvprProgram::didSetData(GrGpu::DrawType drawType) { |
| 369 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); | 369 SkASSERT(GrGpu::IsPathRenderingDrawType(drawType)); |
| 370 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); | 370 fGpu->glPathRendering()->flushPathTexGenSettings(fTexCoordSetCnt); |
| 371 } | 371 } |
| 372 | 372 |
| 373 void | 373 void |
| 374 GrGLLegacyNvprProgram::setTransformData(const GrFragmentStage& proc, GrGLInstall
edFragProc* ip) { | 374 GrGLLegacyNvprProgram::setTransformData(const GrFragmentStage& proc, GrGLInstall
edFragProc* ip) { |
| 375 // We've hidden the texcoord index in the first entry of the transforms arra
y for each effect | 375 // We've hidden the texcoord index in the first entry of the transforms arra
y for each effect |
| 376 int texCoordIndex = ip->fTransforms[0].fHandle.handle(); | 376 int texCoordIndex = ip->fTransforms[0].fHandle.handle(); |
| 377 int numTransforms = proc.getProcessor()->numTransforms(); | 377 int numTransforms = proc.getProcessor()->numTransforms(); |
| 378 for (int t = 0; t < numTransforms; ++t) { | 378 for (int t = 0; t < numTransforms; ++t) { |
| 379 const SkMatrix& transform = get_transform_matrix(proc, false, t); | 379 const SkMatrix& transform = get_transform_matrix(proc, false, t); |
| 380 GrGLPathRendering::PathTexGenComponents components = | 380 GrGLPathRendering::PathTexGenComponents components = |
| 381 GrGLPathRendering::kST_PathTexGenComponents; | 381 GrGLPathRendering::kST_PathTexGenComponents; |
| 382 if (proc.isPerspectiveCoordTransform(t, false)) { | 382 if (proc.isPerspectiveCoordTransform(t, false)) { |
| 383 components = GrGLPathRendering::kSTR_PathTexGenComponents; | 383 components = GrGLPathRendering::kSTR_PathTexGenComponents; |
| 384 } | 384 } |
| 385 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); | 385 fGpu->glPathRendering()->enablePathTexGen(texCoordIndex++, components, t
ransform); |
| 386 } | 386 } |
| 387 } | 387 } |
| OLD | NEW |