Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: src/core/SkXfermode.cpp

Issue 23826002: Rename ShaderType enum to ShaderVisibility (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/effects/SkArithmeticMode.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkXfermode.h" 10 #include "SkXfermode.h"
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 const char* inputColor, 945 const char* inputColor,
946 const TextureSamplerArray& samplers) SK_OVERRIDE { 946 const TextureSamplerArray& samplers) SK_OVERRIDE {
947 SkXfermode::Mode mode = drawEffect.castEffect<XferEffect>().mode(); 947 SkXfermode::Mode mode = drawEffect.castEffect<XferEffect>().mode();
948 const GrTexture* backgroundTex = drawEffect.castEffect<XferEffect>() .backgroundAccess().getTexture(); 948 const GrTexture* backgroundTex = drawEffect.castEffect<XferEffect>() .backgroundAccess().getTexture();
949 const char* dstColor; 949 const char* dstColor;
950 if (backgroundTex) { 950 if (backgroundTex) {
951 SkString bgCoords; 951 SkString bgCoords;
952 GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(builder , key, &bgCoords, NULL, "BG"); 952 GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(builder , key, &bgCoords, NULL, "BG");
953 dstColor = "bgColor"; 953 dstColor = "bgColor";
954 builder->fsCodeAppendf("\t\tvec4 %s = ", dstColor); 954 builder->fsCodeAppendf("\t\tvec4 %s = ", dstColor);
955 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_Shader Type, 955 builder->fsAppendTextureLookup(samplers[0], bgCoords.c_str(), bg CoordsType);
956 samplers[0],
957 bgCoords.c_str(),
958 bgCoordsType);
959 builder->fsCodeAppendf(";\n"); 956 builder->fsCodeAppendf(";\n");
960 } else { 957 } else {
961 dstColor = builder->dstColor(); 958 dstColor = builder->dstColor();
962 } 959 }
963 SkASSERT(NULL != dstColor); 960 SkASSERT(NULL != dstColor);
964 961
965 // We don't try to optimize for this case at all 962 // We don't try to optimize for this case at all
966 if (NULL == inputColor) { 963 if (NULL == inputColor) {
967 builder->fsCodeAppendf("\t\tconst vec4 ones = %s;\n", GrGLSLOnes Vecf(4)); 964 builder->fsCodeAppendf("\t\tconst vec4 ones = %s;\n", GrGLSLOnes Vecf(4));
968 inputColor = "ones"; 965 inputColor = "ones";
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 // hue and saturation of the first color, the luminosity of the second c olor, and the input 1215 // hue and saturation of the first color, the luminosity of the second c olor, and the input
1219 // alpha. It has this signature: 1216 // alpha. It has this signature:
1220 // vec3 set_luminance(vec3 hueSatColor, float alpha, vec3 lumColor) . 1217 // vec3 set_luminance(vec3 hueSatColor, float alpha, vec3 lumColor) .
1221 static void AddLumFunction(GrGLShaderBuilder* builder, SkString* setLumF unction) { 1218 static void AddLumFunction(GrGLShaderBuilder* builder, SkString* setLumF unction) {
1222 // Emit a helper that gets the luminance of a color. 1219 // Emit a helper that gets the luminance of a color.
1223 SkString getFunction; 1220 SkString getFunction;
1224 GrGLShaderVar getLumArgs[] = { 1221 GrGLShaderVar getLumArgs[] = {
1225 GrGLShaderVar("color", kVec3f_GrSLType), 1222 GrGLShaderVar("color", kVec3f_GrSLType),
1226 }; 1223 };
1227 SkString getLumBody("\treturn dot(vec3(0.3, 0.59, 0.11), color);\n") ; 1224 SkString getLumBody("\treturn dot(vec3(0.3, 0.59, 0.11), color);\n") ;
1228 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, 1225 builder->fsEmitFunction(kFloat_GrSLType,
1229 kFloat_GrSLType, 1226 "luminance",
1230 "luminance", 1227 SK_ARRAY_COUNT(getLumArgs), getLumArgs,
1231 SK_ARRAY_COUNT(getLumArgs), getLumArgs, 1228 getLumBody.c_str(),
1232 getLumBody.c_str(), 1229 &getFunction);
1233 &getFunction);
1234 1230
1235 // Emit the set luminance function. 1231 // Emit the set luminance function.
1236 GrGLShaderVar setLumArgs[] = { 1232 GrGLShaderVar setLumArgs[] = {
1237 GrGLShaderVar("hueSat", kVec3f_GrSLType), 1233 GrGLShaderVar("hueSat", kVec3f_GrSLType),
1238 GrGLShaderVar("alpha", kFloat_GrSLType), 1234 GrGLShaderVar("alpha", kFloat_GrSLType),
1239 GrGLShaderVar("lumColor", kVec3f_GrSLType), 1235 GrGLShaderVar("lumColor", kVec3f_GrSLType),
1240 }; 1236 };
1241 SkString setLumBody; 1237 SkString setLumBody;
1242 setLumBody.printf("\tfloat diff = %s(lumColor - hueSat);\n", getFunc tion.c_str()); 1238 setLumBody.printf("\tfloat diff = %s(lumColor - hueSat);\n", getFunc tion.c_str());
1243 setLumBody.append("\tvec3 outColor = hueSat + diff;\n"); 1239 setLumBody.append("\tvec3 outColor = hueSat + diff;\n");
1244 setLumBody.appendf("\tfloat outLum = %s(outColor);\n", getFunction.c _str()); 1240 setLumBody.appendf("\tfloat outLum = %s(outColor);\n", getFunction.c _str());
1245 setLumBody.append("\tfloat minComp = min(min(outColor.r, outColor.g) , outColor.b);\n" 1241 setLumBody.append("\tfloat minComp = min(min(outColor.r, outColor.g) , outColor.b);\n"
1246 "\tfloat maxComp = max(max(outColor.r, outColor.g) , outColor.b);\n" 1242 "\tfloat maxComp = max(max(outColor.r, outColor.g) , outColor.b);\n"
1247 "\tif (minComp < 0.0) {\n" 1243 "\tif (minComp < 0.0) {\n"
1248 "\t\toutColor = outLum + ((outColor - vec3(outLum, outLum, outLum)) * outLum) / (outLum - minComp);\n" 1244 "\t\toutColor = outLum + ((outColor - vec3(outLum, outLum, outLum)) * outLum) / (outLum - minComp);\n"
1249 "\t}\n" 1245 "\t}\n"
1250 "\tif (maxComp > alpha) {\n" 1246 "\tif (maxComp > alpha) {\n"
1251 "\t\toutColor = outLum + ((outColor - vec3(outLum, outLum, outLum)) * (alpha - outLum)) / (maxComp - outLum);\n" 1247 "\t\toutColor = outLum + ((outColor - vec3(outLum, outLum, outLum)) * (alpha - outLum)) / (maxComp - outLum);\n"
1252 "\t}\n" 1248 "\t}\n"
1253 "\treturn outColor;\n"); 1249 "\treturn outColor;\n");
1254 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, 1250 builder->fsEmitFunction(kVec3f_GrSLType,
1255 kVec3f_GrSLType,
1256 "set_luminance", 1251 "set_luminance",
bsalomon 2013/08/30 17:47:55 nit, can we realign these params?
Chris Dalton 2013/08/30 18:22:17 Done.
1257 SK_ARRAY_COUNT(setLumArgs), setLumArgs, 1252 SK_ARRAY_COUNT(setLumArgs), setLumArgs,
1258 setLumBody.c_str(), 1253 setLumBody.c_str(),
1259 setLumFunction); 1254 setLumFunction);
1260 } 1255 }
1261 1256
1262 // Adds a function that creates a color with the hue and luminosity of o ne input color and 1257 // Adds a function that creates a color with the hue and luminosity of o ne input color and
1263 // the saturation of another color. It will have this signature: 1258 // the saturation of another color. It will have this signature:
1264 // float set_saturation(vec3 hueLumColor, vec3 satColor) 1259 // float set_saturation(vec3 hueLumColor, vec3 satColor)
1265 static void AddSatFunction(GrGLShaderBuilder* builder, SkString* setSatF unction) { 1260 static void AddSatFunction(GrGLShaderBuilder* builder, SkString* setSatF unction) {
1266 // Emit a helper that gets the saturation of a color 1261 // Emit a helper that gets the saturation of a color
1267 SkString getFunction; 1262 SkString getFunction;
1268 GrGLShaderVar getSatArgs[] = { GrGLShaderVar("color", kVec3f_GrSLTyp e) }; 1263 GrGLShaderVar getSatArgs[] = { GrGLShaderVar("color", kVec3f_GrSLTyp e) };
1269 SkString getSatBody; 1264 SkString getSatBody;
1270 getSatBody.printf("\treturn max(max(color.r, color.g), color.b) - " 1265 getSatBody.printf("\treturn max(max(color.r, color.g), color.b) - "
1271 "min(min(color.r, color.g), color.b);\n"); 1266 "min(min(color.r, color.g), color.b);\n");
1272 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, 1267 builder->fsEmitFunction(kFloat_GrSLType,
1273 kFloat_GrSLType, 1268 "saturation",
1274 "saturation", 1269 SK_ARRAY_COUNT(getSatArgs), getSatArgs,
1275 SK_ARRAY_COUNT(getSatArgs), getSatArgs, 1270 getSatBody.c_str(),
1276 getSatBody.c_str(), 1271 &getFunction);
1277 &getFunction);
1278 1272
1279 // Emit a helper that sets the saturation given sorted input channel s. This used 1273 // Emit a helper that sets the saturation given sorted input channel s. This used
1280 // to use inout params for min, mid, and max components but that see ms to cause 1274 // to use inout params for min, mid, and max components but that see ms to cause
1281 // problems on PowerVR drivers. So instead it returns a vec3 where r , g ,b are the 1275 // problems on PowerVR drivers. So instead it returns a vec3 where r , g ,b are the
1282 // adjusted min, mid, and max inputs, respectively. 1276 // adjusted min, mid, and max inputs, respectively.
1283 SkString helperFunction; 1277 SkString helperFunction;
1284 GrGLShaderVar helperArgs[] = { 1278 GrGLShaderVar helperArgs[] = {
1285 GrGLShaderVar("minComp", kFloat_GrSLType), 1279 GrGLShaderVar("minComp", kFloat_GrSLType),
1286 GrGLShaderVar("midComp", kFloat_GrSLType), 1280 GrGLShaderVar("midComp", kFloat_GrSLType),
1287 GrGLShaderVar("maxComp", kFloat_GrSLType), 1281 GrGLShaderVar("maxComp", kFloat_GrSLType),
1288 GrGLShaderVar("sat", kFloat_GrSLType), 1282 GrGLShaderVar("sat", kFloat_GrSLType),
1289 }; 1283 };
1290 static const char kHelperBody[] = "\tif (minComp < maxComp) {\n" 1284 static const char kHelperBody[] = "\tif (minComp < maxComp) {\n"
1291 "\t\tvec3 result;\n" 1285 "\t\tvec3 result;\n"
1292 "\t\tresult.r = 0.0;\n" 1286 "\t\tresult.r = 0.0;\n"
1293 "\t\tresult.g = sat * (midComp - m inComp) / (maxComp - minComp);\n" 1287 "\t\tresult.g = sat * (midComp - m inComp) / (maxComp - minComp);\n"
1294 "\t\tresult.b = sat;\n" 1288 "\t\tresult.b = sat;\n"
1295 "\t\treturn result;\n" 1289 "\t\treturn result;\n"
1296 "\t} else {\n" 1290 "\t} else {\n"
1297 "\t\treturn vec3(0, 0, 0);\n" 1291 "\t\treturn vec3(0, 0, 0);\n"
1298 "\t}\n"; 1292 "\t}\n";
1299 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, 1293 builder->fsEmitFunction(kVec3f_GrSLType,
1300 kVec3f_GrSLType, 1294 "set_saturation_helper",
1301 "set_saturation_helper", 1295 SK_ARRAY_COUNT(helperArgs), helperArgs,
1302 SK_ARRAY_COUNT(helperArgs), helperArgs, 1296 kHelperBody,
1303 kHelperBody, 1297 &helperFunction);
1304 &helperFunction);
1305 1298
1306 GrGLShaderVar setSatArgs[] = { 1299 GrGLShaderVar setSatArgs[] = {
1307 GrGLShaderVar("hueLumColor", kVec3f_GrSLType), 1300 GrGLShaderVar("hueLumColor", kVec3f_GrSLType),
1308 GrGLShaderVar("satColor", kVec3f_GrSLType), 1301 GrGLShaderVar("satColor", kVec3f_GrSLType),
1309 }; 1302 };
1310 const char* helpFunc = helperFunction.c_str(); 1303 const char* helpFunc = helperFunction.c_str();
1311 SkString setSatBody; 1304 SkString setSatBody;
1312 setSatBody.appendf("\tfloat sat = %s(satColor);\n" 1305 setSatBody.appendf("\tfloat sat = %s(satColor);\n"
1313 "\tif (hueLumColor.r <= hueLumColor.g) {\n" 1306 "\tif (hueLumColor.r <= hueLumColor.g) {\n"
1314 "\t\tif (hueLumColor.g <= hueLumColor.b) {\n" 1307 "\t\tif (hueLumColor.g <= hueLumColor.b) {\n"
1315 "\t\t\thueLumColor.rgb = %s(hueLumColor.r, hueLum Color.g, hueLumColor.b, sat);\n" 1308 "\t\t\thueLumColor.rgb = %s(hueLumColor.r, hueLum Color.g, hueLumColor.b, sat);\n"
1316 "\t\t} else if (hueLumColor.r <= hueLumColor.b) { \n" 1309 "\t\t} else if (hueLumColor.r <= hueLumColor.b) { \n"
1317 "\t\t\thueLumColor.rbg = %s(hueLumColor.r, hueLum Color.b, hueLumColor.g, sat);\n" 1310 "\t\t\thueLumColor.rbg = %s(hueLumColor.r, hueLum Color.b, hueLumColor.g, sat);\n"
1318 "\t\t} else {\n" 1311 "\t\t} else {\n"
1319 "\t\t\thueLumColor.brg = %s(hueLumColor.b, hueLum Color.r, hueLumColor.g, sat);\n" 1312 "\t\t\thueLumColor.brg = %s(hueLumColor.b, hueLum Color.r, hueLumColor.g, sat);\n"
1320 "\t\t}\n" 1313 "\t\t}\n"
1321 "\t} else if (hueLumColor.r <= hueLumColor.b) {\n " 1314 "\t} else if (hueLumColor.r <= hueLumColor.b) {\n "
1322 "\t\thueLumColor.grb = %s(hueLumColor.g, hueLumCo lor.r, hueLumColor.b, sat);\n" 1315 "\t\thueLumColor.grb = %s(hueLumColor.g, hueLumCo lor.r, hueLumColor.b, sat);\n"
1323 "\t} else if (hueLumColor.g <= hueLumColor.b) {\n " 1316 "\t} else if (hueLumColor.g <= hueLumColor.b) {\n "
1324 "\t\thueLumColor.gbr = %s(hueLumColor.g, hueLumCo lor.b, hueLumColor.r, sat);\n" 1317 "\t\thueLumColor.gbr = %s(hueLumColor.g, hueLumCo lor.b, hueLumColor.r, sat);\n"
1325 "\t} else {\n" 1318 "\t} else {\n"
1326 "\t\thueLumColor.bgr = %s(hueLumColor.b, hueLumCo lor.g, hueLumColor.r, sat);\n" 1319 "\t\thueLumColor.bgr = %s(hueLumColor.b, hueLumCo lor.g, hueLumColor.r, sat);\n"
1327 "\t}\n" 1320 "\t}\n"
1328 "\treturn hueLumColor;\n", 1321 "\treturn hueLumColor;\n",
1329 getFunction.c_str(), helpFunc, helpFunc, helpFunc , helpFunc, 1322 getFunction.c_str(), helpFunc, helpFunc, helpFunc , helpFunc,
1330 helpFunc, helpFunc); 1323 helpFunc, helpFunc);
1331 builder->emitFunction(GrGLShaderBuilder::kFragment_ShaderType, 1324 builder->fsEmitFunction(kVec3f_GrSLType,
1332 kVec3f_GrSLType, 1325 "set_saturation",
1333 "set_saturation", 1326 SK_ARRAY_COUNT(setSatArgs), setSatArgs,
1334 SK_ARRAY_COUNT(setSatArgs), setSatArgs, 1327 setSatBody.c_str(),
1335 setSatBody.c_str(), 1328 setSatFunction);
1336 setSatFunction);
1337 1329
1338 } 1330 }
1339 1331
1340 static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsT ype; 1332 static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsT ype;
1341 GrGLEffectMatrix fBackgroundEffectMatrix; 1333 GrGLEffectMatrix fBackgroundEffectMatrix;
1342 typedef GrGLEffect INHERITED; 1334 typedef GrGLEffect INHERITED;
1343 }; 1335 };
1344 1336
1345 GR_DECLARE_EFFECT_TEST; 1337 GR_DECLARE_EFFECT_TEST;
1346 1338
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
1971 return proc16; 1963 return proc16;
1972 } 1964 }
1973 1965
1974 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode) 1966 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkXfermode)
1975 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode) 1967 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkProcCoeffXfermode)
1976 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkClearXfermode) 1968 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkClearXfermode)
1977 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSrcXfermode) 1969 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSrcXfermode)
1978 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstInXfermode) 1970 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstInXfermode)
1979 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstOutXfermode) 1971 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDstOutXfermode)
1980 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1972 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « no previous file | src/effects/SkArithmeticMode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698