| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "gl/GrGLShaderBuilder.h" | 8 #include "gl/GrGLShaderBuilder.h" |
| 9 #include "gl/GrGLProgram.h" | 9 #include "gl/GrGLProgram.h" |
| 10 #include "gl/GrGLUniformHandle.h" | 10 #include "gl/GrGLUniformHandle.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 } | 107 } |
| 108 return false; | 108 return false; |
| 109 } | 109 } |
| 110 | 110 |
| 111 bool GrGLShaderBuilder::genProgram(const GrEffectStage* colorStages[], | 111 bool GrGLShaderBuilder::genProgram(const GrEffectStage* colorStages[], |
| 112 const GrEffectStage* coverageStages[]) { | 112 const GrEffectStage* coverageStages[]) { |
| 113 const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader(); | 113 const GrGLProgramDesc::KeyHeader& header = this->desc().getHeader(); |
| 114 | 114 |
| 115 /////////////////////////////////////////////////////////////////////////// | 115 /////////////////////////////////////////////////////////////////////////// |
| 116 // emit code to read the dst copy texture, if necessary | 116 // emit code to read the dst copy texture, if necessary |
| 117 if (kNoDstRead_DstReadKey != header.fDstReadKey && | 117 if (kNoDstRead_DstReadKey != header.fDstReadKey && !fGpu->glCaps().fbFetchSu
pport()) { |
| 118 GrGLCaps::kNone_FBFetchType == fGpu->glCaps().fbFetchType()) { | |
| 119 bool topDown = SkToBool(kTopLeftOrigin_DstReadKeyBit & header.fDstReadKe
y); | 118 bool topDown = SkToBool(kTopLeftOrigin_DstReadKeyBit & header.fDstReadKe
y); |
| 120 const char* dstCopyTopLeftName; | 119 const char* dstCopyTopLeftName; |
| 121 const char* dstCopyCoordScaleName; | 120 const char* dstCopyCoordScaleName; |
| 122 const char* dstCopySamplerName; | 121 const char* dstCopySamplerName; |
| 123 uint32_t configMask; | 122 uint32_t configMask; |
| 124 if (SkToBool(kUseAlphaConfig_DstReadKeyBit & header.fDstReadKey)) { | 123 if (SkToBool(kUseAlphaConfig_DstReadKeyBit & header.fDstReadKey)) { |
| 125 configMask = kA_GrColorComponentFlag; | 124 configMask = kA_GrColorComponentFlag; |
| 126 } else { | 125 } else { |
| 127 configMask = kRGBA_GrColorComponentFlags; | 126 configMask = kRGBA_GrColorComponentFlags; |
| 128 } | 127 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 switch (feature) { | 283 switch (feature) { |
| 285 case kFragCoordConventions_GLSLPrivateFeature: | 284 case kFragCoordConventions_GLSLPrivateFeature: |
| 286 if (!fGpu->glCaps().fragCoordConventionsSupport()) { | 285 if (!fGpu->glCaps().fragCoordConventionsSupport()) { |
| 287 return false; | 286 return false; |
| 288 } | 287 } |
| 289 if (fGpu->glslGeneration() < k150_GrGLSLGeneration) { | 288 if (fGpu->glslGeneration() < k150_GrGLSLGeneration) { |
| 290 this->addFSFeature(1 << kFragCoordConventions_GLSLPrivateFeature
, | 289 this->addFSFeature(1 << kFragCoordConventions_GLSLPrivateFeature
, |
| 291 "GL_ARB_fragment_coord_conventions"); | 290 "GL_ARB_fragment_coord_conventions"); |
| 292 } | 291 } |
| 293 return true; | 292 return true; |
| 294 case kEXTShaderFramebufferFetch_GLSLPrivateFeature: | |
| 295 if (GrGLCaps::kEXT_FBFetchType != fGpu->glCaps().fbFetchType()) { | |
| 296 return false; | |
| 297 } | |
| 298 this->addFSFeature(1 << kEXTShaderFramebufferFetch_GLSLPrivateFeatur
e, | |
| 299 "GL_EXT_shader_framebuffer_fetch"); | |
| 300 return true; | |
| 301 case kNVShaderFramebufferFetch_GLSLPrivateFeature: | |
| 302 if (GrGLCaps::kNV_FBFetchType != fGpu->glCaps().fbFetchType()) { | |
| 303 return false; | |
| 304 } | |
| 305 this->addFSFeature(1 << kNVShaderFramebufferFetch_GLSLPrivateFeature
, | |
| 306 "GL_NV_shader_framebuffer_fetch"); | |
| 307 return true; | |
| 308 default: | 293 default: |
| 309 SkFAIL("Unexpected GLSLPrivateFeature requested."); | 294 SkFAIL("Unexpected GLSLPrivateFeature requested."); |
| 310 return false; | 295 return false; |
| 311 } | 296 } |
| 312 } | 297 } |
| 313 | 298 |
| 314 void GrGLShaderBuilder::addFSFeature(uint32_t featureBit, const char* extensionN
ame) { | 299 void GrGLShaderBuilder::addFSFeature(uint32_t featureBit, const char* extensionN
ame) { |
| 315 if (!(featureBit & fFSFeaturesAddedMask)) { | 300 if (!(featureBit & fFSFeaturesAddedMask)) { |
| 316 fFSExtensions.appendf("#extension %s: require\n", extensionName); | 301 fFSExtensions.appendf("#extension %s: require\n", extensionName); |
| 317 fFSFeaturesAddedMask |= featureBit; | 302 fFSFeaturesAddedMask |= featureBit; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 335 | 320 |
| 336 const char* GrGLShaderBuilder::dstColor() { | 321 const char* GrGLShaderBuilder::dstColor() { |
| 337 if (fCodeStage.inStageCode()) { | 322 if (fCodeStage.inStageCode()) { |
| 338 const GrEffect* effect = fCodeStage.effectStage()->getEffect(); | 323 const GrEffect* effect = fCodeStage.effectStage()->getEffect(); |
| 339 if (!effect->willReadDstColor()) { | 324 if (!effect->willReadDstColor()) { |
| 340 SkDEBUGFAIL("GrGLEffect asked for dst color but its generating GrEff
ect " | 325 SkDEBUGFAIL("GrGLEffect asked for dst color but its generating GrEff
ect " |
| 341 "did not request access."); | 326 "did not request access."); |
| 342 return ""; | 327 return ""; |
| 343 } | 328 } |
| 344 } | 329 } |
| 345 static const char kFBFetchColorName[] = "gl_LastFragData[0]"; | 330 |
| 346 GrGLCaps::FBFetchType fetchType = fGpu->glCaps().fbFetchType(); | 331 if (fGpu->glCaps().fbFetchSupport()) { |
| 347 if (GrGLCaps::kEXT_FBFetchType == fetchType) { | 332 this->addFSFeature(1 << (kLastGLSLPrivateFeature + 1), |
| 348 SkAssertResult(this->enablePrivateFeature(kEXTShaderFramebufferFetch_GLS
LPrivateFeature)); | 333 fGpu->glCaps().fbFetchExtensionString()); |
| 349 return kFBFetchColorName; | 334 return fGpu->glCaps().fbFetchColorName(); |
| 350 } else if (GrGLCaps::kNV_FBFetchType == fetchType) { | |
| 351 SkAssertResult(this->enablePrivateFeature(kNVShaderFramebufferFetch_GLSL
PrivateFeature)); | |
| 352 return kFBFetchColorName; | |
| 353 } else if (fOutput.fUniformHandles.fDstCopySamplerUni.isValid()) { | 335 } else if (fOutput.fUniformHandles.fDstCopySamplerUni.isValid()) { |
| 354 return kDstCopyColorName; | 336 return kDstCopyColorName; |
| 355 } else { | 337 } else { |
| 356 return ""; | 338 return ""; |
| 357 } | 339 } |
| 358 } | 340 } |
| 359 | 341 |
| 360 void GrGLShaderBuilder::appendTextureLookup(SkString* out, | 342 void GrGLShaderBuilder::appendTextureLookup(SkString* out, |
| 361 const GrGLShaderBuilder::TextureSamp
ler& sampler, | 343 const GrGLShaderBuilder::TextureSamp
ler& sampler, |
| 362 const char* coordName, | 344 const char* coordName, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 382 const char* coordName, | 364 const char* coordName, |
| 383 GrSLType varyingType) { | 365 GrSLType varyingType) { |
| 384 SkString lookup; | 366 SkString lookup; |
| 385 this->appendTextureLookup(&lookup, sampler, coordName, varyingType); | 367 this->appendTextureLookup(&lookup, sampler, coordName, varyingType); |
| 386 fFSCode.append((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str()); | 368 fFSCode.append((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str()); |
| 387 } | 369 } |
| 388 | 370 |
| 389 GrGLShaderBuilder::DstReadKey GrGLShaderBuilder::KeyForDstRead(const GrTexture*
dstCopy, | 371 GrGLShaderBuilder::DstReadKey GrGLShaderBuilder::KeyForDstRead(const GrTexture*
dstCopy, |
| 390 const GrGLCaps& c
aps) { | 372 const GrGLCaps& c
aps) { |
| 391 uint32_t key = kYesDstRead_DstReadKeyBit; | 373 uint32_t key = kYesDstRead_DstReadKeyBit; |
| 392 if (GrGLCaps::kNone_FBFetchType != caps.fbFetchType()) { | 374 if (caps.fbFetchSupport()) { |
| 393 return key; | 375 return key; |
| 394 } | 376 } |
| 395 SkASSERT(NULL != dstCopy); | 377 SkASSERT(NULL != dstCopy); |
| 396 if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(dstCopy->confi
g())) { | 378 if (!caps.textureSwizzleSupport() && GrPixelConfigIsAlphaOnly(dstCopy->confi
g())) { |
| 397 // The fact that the config is alpha-only must be considered when genera
ting code. | 379 // The fact that the config is alpha-only must be considered when genera
ting code. |
| 398 key |= kUseAlphaConfig_DstReadKeyBit; | 380 key |= kUseAlphaConfig_DstReadKeyBit; |
| 399 } | 381 } |
| 400 if (kTopLeft_GrSurfaceOrigin == dstCopy->origin()) { | 382 if (kTopLeft_GrSurfaceOrigin == dstCopy->origin()) { |
| 401 key |= kTopLeftOrigin_DstReadKeyBit; | 383 key |= kTopLeftOrigin_DstReadKeyBit; |
| 402 } | 384 } |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 | 1079 |
| 1098 GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this, | 1080 GrGLPathTexGenProgramEffectsBuilder pathTexGenEffectsBuilder(this, |
| 1099 effectCnt); | 1081 effectCnt); |
| 1100 this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder, | 1082 this->INHERITED::createAndEmitEffects(&pathTexGenEffectsBuilder, |
| 1101 effectStages, | 1083 effectStages, |
| 1102 effectCnt, | 1084 effectCnt, |
| 1103 keyProvider, | 1085 keyProvider, |
| 1104 inOutFSColor); | 1086 inOutFSColor); |
| 1105 return pathTexGenEffectsBuilder.finish(); | 1087 return pathTexGenEffectsBuilder.finish(); |
| 1106 } | 1088 } |
| OLD | NEW |