Make GrGLConfigConversionEffect work for Imagination and some other GPUs.
BUG=372341 Committed: https://skia.googlesource.com/skia/+/93cf46f7d687128d2ad05762bd65fea6c4539553 R=bsalomon@google.com, tomhudson@chromium.org Author: changjun.yang@intel.com Review URL: https://codereview.chromium.org/277323002
This commit is contained in:
parent
a19afb4180
commit
cecc91c444
@ -30,19 +30,26 @@ public:
|
||||
const char* inputColor,
|
||||
const TransformedCoordsArray& coords,
|
||||
const TextureSamplerArray& samplers) SK_OVERRIDE {
|
||||
builder->fsCodeAppendf("\t\t%s = ", outputColor);
|
||||
// Using highp for GLES here in order to avoid some precision issues on specific GPUs.
|
||||
GrGLShaderVar tmpVar("tmpColor", kVec4f_GrSLType, 0, GrGLShaderVar::kHigh_Precision);
|
||||
SkString tmpDecl;
|
||||
tmpVar.appendDecl(builder->ctxInfo(), &tmpDecl);
|
||||
builder->fsCodeAppendf("%s;", tmpDecl.c_str());
|
||||
|
||||
builder->fsCodeAppendf("%s = ", tmpVar.c_str());
|
||||
builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coords[0].type());
|
||||
builder->fsCodeAppend(";\n");
|
||||
builder->fsCodeAppend(";");
|
||||
|
||||
if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) {
|
||||
SkASSERT(fSwapRedAndBlue);
|
||||
builder->fsCodeAppendf("\t%s = %s.bgra;\n", outputColor, outputColor);
|
||||
builder->fsCodeAppendf("%s = %s.bgra;", outputColor, tmpVar.c_str());
|
||||
} else {
|
||||
const char* swiz = fSwapRedAndBlue ? "bgr" : "rgb";
|
||||
switch (fPMConversion) {
|
||||
case GrConfigConversionEffect::kMulByAlpha_RoundUp_PMConversion:
|
||||
builder->fsCodeAppendf(
|
||||
"\t\t%s = vec4(ceil(%s.%s * %s.a * 255.0) / 255.0, %s.a);\n",
|
||||
outputColor, outputColor, swiz, outputColor, outputColor);
|
||||
"%s = vec4(ceil(%s.%s * %s.a * 255.0) / 255.0, %s.a);",
|
||||
tmpVar.c_str(), tmpVar.c_str(), swiz, tmpVar.c_str(), tmpVar.c_str());
|
||||
break;
|
||||
case GrConfigConversionEffect::kMulByAlpha_RoundDown_PMConversion:
|
||||
// Add a compensation(0.001) here to avoid the side effect of the floor operation.
|
||||
@ -50,21 +57,24 @@ public:
|
||||
// is less than the integer value converted from %s.r by 1 when the %s.r is
|
||||
// converted from the integer value 2^n, such as 1, 2, 4, 8, etc.
|
||||
builder->fsCodeAppendf(
|
||||
"\t\t%s = vec4(floor(%s.%s * %s.a * 255.0 + 0.001) / 255.0, %s.a);\n",
|
||||
outputColor, outputColor, swiz, outputColor, outputColor);
|
||||
"%s = vec4(floor(%s.%s * %s.a * 255.0 + 0.001) / 255.0, %s.a);",
|
||||
tmpVar.c_str(), tmpVar.c_str(), swiz, tmpVar.c_str(), tmpVar.c_str());
|
||||
break;
|
||||
case GrConfigConversionEffect::kDivByAlpha_RoundUp_PMConversion:
|
||||
builder->fsCodeAppendf("\t\t%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(ceil(%s.%s / %s.a * 255.0) / 255.0, %s.a);\n",
|
||||
outputColor, outputColor, outputColor, swiz, outputColor, outputColor);
|
||||
builder->fsCodeAppendf(
|
||||
"%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(ceil(%s.%s / %s.a * 255.0) / 255.0, %s.a);",
|
||||
tmpVar.c_str(), tmpVar.c_str(), tmpVar.c_str(), swiz, tmpVar.c_str(), tmpVar.c_str());
|
||||
break;
|
||||
case GrConfigConversionEffect::kDivByAlpha_RoundDown_PMConversion:
|
||||
builder->fsCodeAppendf("\t\t%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(floor(%s.%s / %s.a * 255.0) / 255.0, %s.a);\n",
|
||||
outputColor, outputColor, outputColor, swiz, outputColor, outputColor);
|
||||
builder->fsCodeAppendf(
|
||||
"%s = %s.a <= 0.0 ? vec4(0,0,0,0) : vec4(floor(%s.%s / %s.a * 255.0) / 255.0, %s.a);",
|
||||
tmpVar.c_str(), tmpVar.c_str(), tmpVar.c_str(), swiz, tmpVar.c_str(), tmpVar.c_str());
|
||||
break;
|
||||
default:
|
||||
SkFAIL("Unknown conversion op.");
|
||||
break;
|
||||
}
|
||||
builder->fsCodeAppendf("%s = %s;", outputColor, tmpVar.c_str());
|
||||
}
|
||||
SkString modulate;
|
||||
GrGLSLMulVarBy4f(&modulate, 2, outputColor, inputColor);
|
||||
|
Loading…
Reference in New Issue
Block a user