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

Unified Diff: cc/output/shader.cc

Issue 2645953007: cc: Add analytic color conversion to shaders (Closed)
Patch Set: Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/output/shader.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/output/shader.cc
diff --git a/cc/output/shader.cc b/cc/output/shader.cc
index 3bd260f4a3deee18948fe883f19a62e9ef5b164d..8a398fd26cbdca450a680a941572f25f1757dd9b 100644
--- a/cc/output/shader.cc
+++ b/cc/output/shader.cc
@@ -449,6 +449,11 @@ void FragmentShader::Init(GLES2Interface* context,
uniforms.push_back("color");
break;
}
+ if (color_conversion_mode_ == COLOR_CONVERSION_MODE_ANALYTIC) {
+ uniforms.push_back("color_src_to_dst_primary_matrix");
+ uniforms.push_back("color_src_to_linear_tr_fn");
+ uniforms.push_back("color_linear_to_dst_tr_fn");
+ }
locations.resize(uniforms.size());
@@ -506,6 +511,11 @@ void FragmentShader::Init(GLES2Interface* context,
color_location_ = locations[index++];
break;
}
+ if (color_conversion_mode_ == COLOR_CONVERSION_MODE_ANALYTIC) {
+ color_src_to_dst_primary_matrix_location_ = locations[index++];
+ color_src_to_linear_tr_fn_location_ = locations[index++];
+ color_linear_to_dst_tr_fn_location_ = locations[index++];
+ }
DCHECK_EQ(index, locations.size());
}
@@ -898,6 +908,30 @@ std::string FragmentShader::GetShaderSource() const {
SRC("vec4 texColor = color;");
break;
}
+
+ // Apply color conversion
+ if (color_conversion_mode_ == COLOR_CONVERSION_MODE_ANALYTIC) {
+ HDR("uniform mat3 color_src_to_dst_primary_matrix;");
+ HDR("// Transfer function parameter uniforms. Parameters are based on");
+ HDR("// SkColorSpaceTransferFn (as fA at index 0 through fG at index 6).");
+ HDR("uniform float color_src_to_linear_tr_fn[7];");
+ HDR("uniform float color_linear_to_dst_tr_fn[7];");
+ HDR("float TransferFn(float x, float params[7]) {");
+ HDR(" x = clamp(x, 0.0, 1.0);");
+ HDR(" if (x < params[3])");
+ HDR(" return params[2]*x + params[5];");
+ HDR(" return pow(params[0] * x + params[1], params[6]) + params[4];");
+ HDR("}");
+ SRC("// Apply color conversion");
+ SRC("texColor.r = TransferFn(texColor.x, color_src_to_linear_tr_fn);");
+ SRC("texColor.g = TransferFn(texColor.y, color_src_to_linear_tr_fn);");
+ SRC("texColor.b = TransferFn(texColor.z, color_src_to_linear_tr_fn);");
+ SRC("texColor.rgb = color_src_to_dst_primary_matrix * texColor.rgb;");
+ SRC("texColor.r = TransferFn(texColor.x, color_linear_to_dst_tr_fn);");
+ SRC("texColor.g = TransferFn(texColor.y, color_linear_to_dst_tr_fn);");
+ SRC("texColor.b = TransferFn(texColor.z, color_linear_to_dst_tr_fn);");
+ }
+
// Apply the color matrix to texColor.
if (has_color_matrix_) {
HDR("uniform mat4 colorMatrix;");
« no previous file with comments | « cc/output/shader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698