| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrSwizzle.h" | 8 #include "GrSwizzle.h" |
| 9 #include "glsl/GrGLSLShaderBuilder.h" | 9 #include "glsl/GrGLSLShaderBuilder.h" |
| 10 #include "glsl/GrGLSLCaps.h" | 10 #include "glsl/GrGLSLCaps.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } else { | 126 } else { |
| 127 this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str()
); | 127 this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str()
); |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 | 130 |
| 131 void GrGLSLShaderBuilder::appendColorGamutXform(SkString* out, | 131 void GrGLSLShaderBuilder::appendColorGamutXform(SkString* out, |
| 132 const char* srcColor, | 132 const char* srcColor, |
| 133 GrGLSLColorSpaceXformHelper* col
orXformHelper) { | 133 GrGLSLColorSpaceXformHelper* col
orXformHelper) { |
| 134 // Our color is (r, g, b, a), but we want to multiply (r, g, b, 1) by our ma
trix, then | 134 // Our color is (r, g, b, a), but we want to multiply (r, g, b, 1) by our ma
trix, then |
| 135 // re-insert the original alpha. The supplied srcColor is likely to be of th
e form | 135 // re-insert the original alpha. The supplied srcColor is likely to be of th
e form |
| 136 // "texture(...)", and we don't want to evaluate that twice. | 136 // "texture(...)", and we don't want to evaluate that twice, so wrap everyth
ing in a function. |
| 137 // | |
| 138 // Worse: We can't do the transformation on premultiplied colors, so if the
source is premul, | |
| 139 // we need to unpremul, transform, then multiply again. Anyways, we wrap all
of the work in a | |
| 140 // function. | |
| 141 static const GrGLSLShaderVar gColorGamutXformArgs[] = { | 137 static const GrGLSLShaderVar gColorGamutXformArgs[] = { |
| 142 GrGLSLShaderVar("color", kVec4f_GrSLType), | 138 GrGLSLShaderVar("color", kVec4f_GrSLType), |
| 143 GrGLSLShaderVar("xform", kMat44f_GrSLType), | 139 GrGLSLShaderVar("xform", kMat44f_GrSLType), |
| 144 }; | 140 }; |
| 145 SkString functionBody; | 141 SkString functionBody; |
| 146 if (kPremul_SkAlphaType == colorXformHelper->alphaType()) { | |
| 147 // Unpremultiply | |
| 148 functionBody.append("\tfloat nonZeroAlpha = max(color.a, 0.00001);\n" | |
| 149 "\tcolor.rgb = color.rgb / nonZeroAlpha;\n"); | |
| 150 } | |
| 151 // Gamut xform, clamp to destination gamut | 142 // Gamut xform, clamp to destination gamut |
| 152 functionBody.append("\tcolor.rgb = clamp((xform * vec4(color.rgb, 1.0)).rgb,
0.0, 1.0);\n"); | 143 functionBody.append("\tcolor.rgb = clamp((xform * vec4(color.rgb, 1.0)).rgb,
0.0, 1.0);\n"); |
| 153 if (kPremul_SkAlphaType == colorXformHelper->alphaType()) { | |
| 154 // Re-multiply by alpha | |
| 155 functionBody.append("\tcolor.rgb = color.rgb * nonZeroAlpha;\n"); | |
| 156 } | |
| 157 functionBody.append("\treturn color;"); | 144 functionBody.append("\treturn color;"); |
| 158 SkString colorGamutXformFuncName; | 145 SkString colorGamutXformFuncName; |
| 159 this->emitFunction(kVec4f_GrSLType, | 146 this->emitFunction(kVec4f_GrSLType, |
| 160 "colorGamutXform", | 147 "colorGamutXform", |
| 161 SK_ARRAY_COUNT(gColorGamutXformArgs), | 148 SK_ARRAY_COUNT(gColorGamutXformArgs), |
| 162 gColorGamutXformArgs, | 149 gColorGamutXformArgs, |
| 163 functionBody.c_str(), | 150 functionBody.c_str(), |
| 164 &colorGamutXformFuncName); | 151 &colorGamutXformFuncName); |
| 165 | 152 |
| 166 out->appendf("%s(%s, %s)", colorGamutXformFuncName.c_str(), srcColor, | 153 out->appendf("%s(%s, %s)", colorGamutXformFuncName.c_str(), srcColor, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 // append the 'footer' to code | 240 // append the 'footer' to code |
| 254 this->code().append("}"); | 241 this->code().append("}"); |
| 255 | 242 |
| 256 for (int i = 0; i <= fCodeIndex; i++) { | 243 for (int i = 0; i <= fCodeIndex; i++) { |
| 257 fCompilerStrings[i] = fShaderStrings[i].c_str(); | 244 fCompilerStrings[i] = fShaderStrings[i].c_str(); |
| 258 fCompilerStringLengths[i] = (int)fShaderStrings[i].size(); | 245 fCompilerStringLengths[i] = (int)fShaderStrings[i].size(); |
| 259 } | 246 } |
| 260 | 247 |
| 261 fFinalized = true; | 248 fFinalized = true; |
| 262 } | 249 } |
| OLD | NEW |