aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/effects/SkBlurMaskFilter.cpp26
-rw-r--r--src/gpu/effects/GrDistanceFieldGeoProc.cpp15
-rw-r--r--src/gpu/effects/GrTextureDomain.cpp6
-rw-r--r--src/gpu/glsl/GrGLSL.h17
-rw-r--r--src/gpu/glsl/GrGLSLShaderBuilder.cpp6
-rw-r--r--src/gpu/glsl/GrGLSLShaderBuilder.h5
-rw-r--r--src/gpu/glsl/GrGLSLShaderVar.h22
7 files changed, 54 insertions, 43 deletions
diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp
index 609e168f01..443373e23b 100644
--- a/src/effects/SkBlurMaskFilter.cpp
+++ b/src/effects/SkBlurMaskFilter.cpp
@@ -723,7 +723,10 @@ void GrGLRectBlurEffect::emitCode(EmitArgs& args) {
const char *rectName;
const char *profileSizeName;
- const char* precisionString = GrGLSLShaderVar::PrecisionString(args.fGLSLCaps, rbe.precision());
+ SkString precisionString;
+ if (args.fGLSLCaps->usesPrecisionModifiers()) {
+ precisionString.printf("%s ", GrGLSLPrecisionString(rbe.precision()));
+ }
fProxyRectUniform = uniformHandler->addUniform(kFragment_GrShaderFlag,
kVec4f_GrSLType,
rbe.precision(),
@@ -744,16 +747,19 @@ void GrGLRectBlurEffect::emitCode(EmitArgs& args) {
fragBuilder->codeAppendf("vec4 src=vec4(1);");
}
- fragBuilder->codeAppendf("%s vec2 translatedPos = %s.xy - %s.xy;", precisionString, fragmentPos,
+ fragBuilder->codeAppendf("%s vec2 translatedPos = %s.xy - %s.xy;", precisionString.c_str(),
+ fragmentPos, rectName);
+ fragBuilder->codeAppendf("%s float width = %s.z - %s.x;", precisionString.c_str(), rectName,
+ rectName);
+ fragBuilder->codeAppendf("%s float height = %s.w - %s.y;", precisionString.c_str(), rectName,
rectName);
- fragBuilder->codeAppendf("%s float width = %s.z - %s.x;", precisionString, rectName, rectName);
- fragBuilder->codeAppendf("%s float height = %s.w - %s.y;", precisionString, rectName, rectName);
-
- fragBuilder->codeAppendf("%s vec2 smallDims = vec2(width - %s, height - %s);", precisionString,
- profileSizeName, profileSizeName);
- fragBuilder->codeAppendf("%s float center = 2.0 * floor(%s/2.0 + .25) - 1.0;", precisionString,
- profileSizeName);
- fragBuilder->codeAppendf("%s vec2 wh = smallDims - vec2(center,center);", precisionString);
+
+ fragBuilder->codeAppendf("%s vec2 smallDims = vec2(width - %s, height - %s);",
+ precisionString.c_str(), profileSizeName, profileSizeName);
+ fragBuilder->codeAppendf("%s float center = 2.0 * floor(%s/2.0 + .25) - 1.0;",
+ precisionString.c_str(), profileSizeName);
+ fragBuilder->codeAppendf("%s vec2 wh = smallDims - vec2(center,center);",
+ precisionString.c_str());
OutputRectBlurProfileLookup(fragBuilder, args.fSamplers[0], "horiz_lookup", profileSizeName,
"translatedPos.x", "width", "wh.x");
diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.cpp b/src/gpu/effects/GrDistanceFieldGeoProc.cpp
index 7d474a16e1..5153ad848a 100644
--- a/src/gpu/effects/GrDistanceFieldGeoProc.cpp
+++ b/src/gpu/effects/GrDistanceFieldGeoProc.cpp
@@ -97,8 +97,7 @@ public:
dfTexEffect.inTextureCoords()->fName);
// Use highp to work around aliasing issues
- fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps,
- kHigh_GrSLPrecision));
+ fragBuilder->appendPrecisionModifier(kHigh_GrSLPrecision);
fragBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn());
fragBuilder->codeAppend("\tfloat texColor = ");
@@ -335,8 +334,7 @@ public:
"TextureSize", &textureSizeUniName);
// Use highp to work around aliasing issues
- fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps,
- kHigh_GrSLPrecision));
+ fragBuilder->appendPrecisionModifier(kHigh_GrSLPrecision);
fragBuilder->codeAppendf("vec2 uv = %s;", v.fsIn());
fragBuilder->codeAppend("float texColor = ");
@@ -347,8 +345,7 @@ public:
fragBuilder->codeAppend("float distance = "
SK_DistanceFieldMultiplier "*(texColor - " SK_DistanceFieldThreshold ");");
- fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps,
- kHigh_GrSLPrecision));
+ fragBuilder->appendPrecisionModifier(kHigh_GrSLPrecision);
fragBuilder->codeAppendf("vec2 st = uv*%s;", textureSizeUniName);
fragBuilder->codeAppend("float afwidth;");
bool isUniformScale = (dfTexEffect.getFlags() & kUniformScale_DistanceFieldEffectMask) ==
@@ -579,11 +576,9 @@ public:
// create LCD offset adjusted by inverse of transform
// Use highp to work around aliasing issues
- fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps,
- kHigh_GrSLPrecision));
+ fragBuilder->appendPrecisionModifier(kHigh_GrSLPrecision);
fragBuilder->codeAppendf("vec2 uv = %s;\n", uv.fsIn());
- fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps,
- kHigh_GrSLPrecision));
+ fragBuilder->appendPrecisionModifier(kHigh_GrSLPrecision);
SkScalar lcdDelta = 1.0f / (3.0f * atlas->width());
if (dfTexEffect.getFlags() & kBGR_DistanceFieldEffectFlag) {
diff --git a/src/gpu/effects/GrTextureDomain.cpp b/src/gpu/effects/GrTextureDomain.cpp
index d3850a31c2..724b3ec21d 100644
--- a/src/gpu/effects/GrTextureDomain.cpp
+++ b/src/gpu/effects/GrTextureDomain.cpp
@@ -103,11 +103,9 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
inCoords.c_str());
builder->codeAppend(";");
- builder->codeAppend(GrGLSLShaderVar::PrecisionString(glslCaps,
- kHigh_GrSLPrecision));
+ builder->appendPrecisionModifier(kHigh_GrSLPrecision);
builder->codeAppendf("float x = (%s).x;", inCoords.c_str());
- builder->codeAppend(GrGLSLShaderVar::PrecisionString(glslCaps,
- kHigh_GrSLPrecision));
+ builder->appendPrecisionModifier(kHigh_GrSLPrecision);
builder->codeAppendf("float y = (%s).y;", inCoords.c_str());
builder->codeAppendf("x = abs(2.0*(x - %s.x)/(%s.z - %s.x) - 1.0);",
diff --git a/src/gpu/glsl/GrGLSL.h b/src/gpu/glsl/GrGLSL.h
index 12c1f1fcc6..9f5f2b05b4 100644
--- a/src/gpu/glsl/GrGLSL.h
+++ b/src/gpu/glsl/GrGLSL.h
@@ -84,6 +84,23 @@ void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision,
SkString* out);
/**
+ * Converts a GrSLPrecision to its corresponding GLSL precision qualifier.
+ */
+static inline const char* GrGLSLPrecisionString(GrSLPrecision p) {
+ switch (p) {
+ case kLow_GrSLPrecision:
+ return "lowp";
+ case kMedium_GrSLPrecision:
+ return "mediump";
+ case kHigh_GrSLPrecision:
+ return "highp";
+ default:
+ SkFAIL("Unexpected precision type.");
+ return "";
+ }
+}
+
+/**
* Converts a GrSLType to a string containing the name of the equivalent GLSL type.
*/
static inline const char* GrGLSLTypeString(GrSLType t) {
diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.cpp b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
index 93b9f8a57a..795e5cb585 100644
--- a/src/gpu/glsl/GrGLSLShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
@@ -35,6 +35,12 @@ void GrGLSLShaderBuilder::declAppend(const GrGLSLShaderVar& var) {
this->codeAppendf("%s;", tempDecl.c_str());
}
+void GrGLSLShaderBuilder::appendPrecisionModifier(GrSLPrecision precision) {
+ if (fProgramBuilder->glslCaps()->usesPrecisionModifiers()) {
+ this->codeAppendf("%s ", GrGLSLPrecisionString(precision));
+ }
+}
+
void GrGLSLShaderBuilder::emitFunction(GrSLType returnType,
const char* name,
int argCnt,
diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.h b/src/gpu/glsl/GrGLSLShaderBuilder.h
index 5b3a01f3e9..cddf7b2db4 100644
--- a/src/gpu/glsl/GrGLSLShaderBuilder.h
+++ b/src/gpu/glsl/GrGLSLShaderBuilder.h
@@ -93,6 +93,11 @@ public:
*/
void declAppend(const GrGLSLShaderVar& var);
+ /**
+ * Appends a precision qualifier followed by a space, if relevant for the GLSL version.
+ */
+ void appendPrecisionModifier(GrSLPrecision);
+
/** Emits a helper function outside of main() in the fragment shader. */
void emitFunction(GrSLType returnType,
const char* name,
diff --git a/src/gpu/glsl/GrGLSLShaderVar.h b/src/gpu/glsl/GrGLSLShaderVar.h
index a7d7479d39..9d162ecaa4 100644
--- a/src/gpu/glsl/GrGLSLShaderVar.h
+++ b/src/gpu/glsl/GrGLSLShaderVar.h
@@ -174,8 +174,9 @@ public:
out->append(" ");
}
GrSLType effectiveType = this->getType();
- if (GrSLTypeAcceptsPrecision(effectiveType)) {
- out->append(PrecisionString(glslCaps, fPrecision));
+ if (glslCaps->usesPrecisionModifiers() && GrSLTypeAcceptsPrecision(effectiveType)) {
+ // Desktop GLSL has added precision qualifiers but they don't do anything.
+ out->appendf("%s ", GrGLSLPrecisionString(fPrecision));
}
if (this->isArray()) {
if (this->isUnsizedArray()) {
@@ -210,23 +211,6 @@ public:
fUseUniformFloatArrays ? "" : ".x");
}
- static const char* PrecisionString(const GrGLSLCaps* glslCaps, GrSLPrecision p) {
- // Desktop GLSL has added precision qualifiers but they don't do anything.
- if (glslCaps->usesPrecisionModifiers()) {
- switch (p) {
- case kLow_GrSLPrecision:
- return "lowp ";
- case kMedium_GrSLPrecision:
- return "mediump ";
- case kHigh_GrSLPrecision:
- return "highp ";
- default:
- SkFAIL("Unexpected precision type.");
- }
- }
- return "";
- }
-
private:
static const char* TypeModifierString(const GrGLSLCaps* glslCaps, TypeModifier t) {
GrGLSLGeneration gen = glslCaps->generation();