Index: src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp |
diff --git a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp |
index 86c622d45686693b8ec25df5a705db14a00b45d8..61932f3084bbd290b301b50a0b1f2cc3ccab4590 100644 |
--- a/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp |
+++ b/src/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp |
@@ -179,9 +179,56 @@ const char* GrGLFragmentShaderBuilder::dstColor() { |
fbFetchColorName = declared_color_output_name(); |
} |
return fbFetchColorName; |
- } else { |
+ } else if (fProgramBuilder->fUniformHandles.fDstCopySamplerUni.isValid()) { |
return kDstCopyColorName; |
- } |
+ } else { |
+ return ""; |
+ } |
+} |
+ |
+void GrGLFragmentShaderBuilder::emitCodeToReadDstTexture() { |
+ bool topDown = SkToBool(kTopLeftOrigin_DstReadKeyBit & fProgramBuilder->header().fDstReadKey); |
+ const char* dstCopyTopLeftName; |
+ const char* dstCopyCoordScaleName; |
+ const char* dstCopySamplerName; |
+ uint32_t configMask; |
+ if (SkToBool(kUseAlphaConfig_DstReadKeyBit & fProgramBuilder->header().fDstReadKey)) { |
+ configMask = kA_GrColorComponentFlag; |
+ } else { |
+ configMask = kRGBA_GrColorComponentFlags; |
+ } |
+ fProgramBuilder->fUniformHandles.fDstCopySamplerUni = |
+ fProgramBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
+ kSampler2D_GrSLType, |
+ kDefault_GrSLPrecision, |
+ "DstCopySampler", |
+ &dstCopySamplerName); |
+ fProgramBuilder->fUniformHandles.fDstCopyTopLeftUni = |
+ fProgramBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
+ kVec2f_GrSLType, |
+ kDefault_GrSLPrecision, |
+ "DstCopyUpperLeft", |
+ &dstCopyTopLeftName); |
+ fProgramBuilder->fUniformHandles.fDstCopyScaleUni = |
+ fProgramBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
+ kVec2f_GrSLType, |
+ kDefault_GrSLPrecision, |
+ "DstCopyCoordScale", |
+ &dstCopyCoordScaleName); |
+ const char* fragPos = this->fragmentPosition(); |
+ |
+ this->codeAppend("// Read color from copy of the destination.\n"); |
+ this->codeAppendf("vec2 _dstTexCoord = (%s.xy - %s) * %s;", |
+ fragPos, dstCopyTopLeftName, dstCopyCoordScaleName); |
+ if (!topDown) { |
+ this->codeAppend("_dstTexCoord.y = 1.0 - _dstTexCoord.y;"); |
+ } |
+ this->codeAppendf("vec4 %s = ", GrGLFragmentShaderBuilder::kDstCopyColorName); |
+ this->appendTextureLookup(dstCopySamplerName, |
+ "_dstTexCoord", |
+ configMask, |
+ "rgba"); |
+ this->codeAppend(";"); |
} |
void GrGLFragmentShaderBuilder::enableCustomOutput() { |