# Private includes
"$_include/private/GrAuditTrail.h",
"$_include/private/GrGLSL.h",
- "$_include/private/GrGLSL_impl.h",
"$_include/private/GrInstancedPipelineInfo.h",
"$_include/private/GrSingleOwner.h",
"$_include/private/GrRenderTargetProxy.h",
return ""; // suppress warning
}
-/** A generic base-class representing a GLSL expression.
- * The instance can be a variable name, expression or vecN(0) or vecN(1). Does simple constant
- * folding with help of 1 and 0.
- *
- * Clients should not use this class, rather the specific instantiations defined
- * later, for example GrGLSLExpr4.
- */
-template <typename Self>
-class GrGLSLExpr {
-public:
- bool isOnes() const { return kOnes_ExprType == fType; }
- bool isZeros() const { return kZeros_ExprType == fType; }
-
- const char* c_str() const {
- if (kZeros_ExprType == fType) {
- return Self::ZerosStr();
- } else if (kOnes_ExprType == fType) {
- return Self::OnesStr();
- }
- SkASSERT(!fExpr.isEmpty()); // Empty expressions should not be used.
- return fExpr.c_str();
- }
-
- bool isValid() const {
- return kFullExpr_ExprType != fType || !fExpr.isEmpty();
- }
-
-protected:
- /** Constructs an invalid expression.
- * Useful only as a return value from functions that never actually return
- * this and instances that will be assigned to later. */
- GrGLSLExpr()
- : fType(kFullExpr_ExprType) {
- // The only constructor that is allowed to build an empty expression.
- SkASSERT(!this->isValid());
- }
-
- /** Constructs an expression with all components as value v */
- explicit GrGLSLExpr(int v) {
- if (v == 0) {
- fType = kZeros_ExprType;
- } else if (v == 1) {
- fType = kOnes_ExprType;
- } else {
- fType = kFullExpr_ExprType;
- fExpr.appendf(Self::CastIntStr(), v);
- }
- }
-
- /** Constructs an expression from a string.
- * Argument expr is a simple expression or a parenthesized expression. */
- // TODO: make explicit once effects input Exprs.
- GrGLSLExpr(const char expr[]) {
- if (nullptr == expr) { // TODO: remove this once effects input Exprs.
- fType = kOnes_ExprType;
- } else {
- fType = kFullExpr_ExprType;
- fExpr = expr;
- }
- SkASSERT(this->isValid());
- }
-
- /** Constructs an expression from a string.
- * Argument expr is a simple expression or a parenthesized expression. */
- // TODO: make explicit once effects input Exprs.
- GrGLSLExpr(const SkString& expr) {
- if (expr.isEmpty()) { // TODO: remove this once effects input Exprs.
- fType = kOnes_ExprType;
- } else {
- fType = kFullExpr_ExprType;
- fExpr = expr;
- }
- SkASSERT(this->isValid());
- }
-
- /** Constructs an expression from a string with one substitution. */
- GrGLSLExpr(const char format[], const char in0[])
- : fType(kFullExpr_ExprType) {
- fExpr.appendf(format, in0);
- }
-
- /** Constructs an expression from a string with two substitutions. */
- GrGLSLExpr(const char format[], const char in0[], const char in1[])
- : fType(kFullExpr_ExprType) {
- fExpr.appendf(format, in0, in1);
- }
-
- /** Returns expression casted to another type.
- * Generic implementation that is called for non-trivial cases of casts. */
- template <typename T>
- static Self VectorCastImpl(const T& other);
-
- /** Returns a GLSL multiplication: component-wise or component-by-scalar.
- * The multiplication will be component-wise or multiply each component by a scalar.
- *
- * The returned expression will compute the value of:
- * vecN(in0.x * in1.x, ...) if dim(T0) == dim(T1) (component-wise)
- * vecN(in0.x * in1, ...) if dim(T1) == 1 (vector by scalar)
- * vecN(in0 * in1.x, ...) if dim(T0) == 1 (scalar by vector)
- */
- template <typename T0, typename T1>
- static Self Mul(T0 in0, T1 in1);
-
- /** Returns a GLSL addition: component-wise or add a scalar to each component.
- * Return value computes:
- * vecN(in0.x + in1.x, ...) or vecN(in0.x + in1, ...) or vecN(in0 + in1.x, ...).
- */
- template <typename T0, typename T1>
- static Self Add(T0 in0, T1 in1);
-
- /** Returns a GLSL subtraction: component-wise or subtract compoments by a scalar.
- * Return value computes
- * vecN(in0.x - in1.x, ...) or vecN(in0.x - in1, ...) or vecN(in0 - in1.x, ...).
- */
- template <typename T0, typename T1>
- static Self Sub(T0 in0, T1 in1);
-
- /** Returns expression that accesses component(s) of the expression.
- * format should be the form "%s.x" where 'x' is the component(s) to access.
- * Caller is responsible for making sure the amount of components in the
- * format string is equal to dim(T).
- */
- template <typename T>
- T extractComponents(const char format[]) const;
-
-private:
- enum ExprType {
- kZeros_ExprType,
- kOnes_ExprType,
- kFullExpr_ExprType,
- };
- ExprType fType;
- SkString fExpr;
-};
-
-class GrGLSLExpr1;
-class GrGLSLExpr4;
-
-/** Class representing a float GLSL expression. */
-class GrGLSLExpr1 : public GrGLSLExpr<GrGLSLExpr1> {
-public:
- GrGLSLExpr1()
- : INHERITED() {
- }
- explicit GrGLSLExpr1(int v)
- : INHERITED(v) {
- }
- GrGLSLExpr1(const char* expr)
- : INHERITED(expr) {
- }
- GrGLSLExpr1(const SkString& expr)
- : INHERITED(expr) {
- }
-
- static GrGLSLExpr1 VectorCast(const GrGLSLExpr1& expr);
-
-private:
- GrGLSLExpr1(const char format[], const char in0[])
- : INHERITED(format, in0) {
- }
- GrGLSLExpr1(const char format[], const char in0[], const char in1[])
- : INHERITED(format, in0, in1) {
- }
-
- static const char* ZerosStr();
- static const char* OnesStr();
- static const char* CastStr();
- static const char* CastIntStr();
-
- friend GrGLSLExpr1 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1);
- friend GrGLSLExpr1 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1);
- friend GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1&in1);
-
- friend class GrGLSLExpr<GrGLSLExpr1>;
- friend class GrGLSLExpr<GrGLSLExpr4>;
-
- typedef GrGLSLExpr<GrGLSLExpr1> INHERITED;
-};
-
-/** Class representing a float vector (vec4) GLSL expression. */
-class GrGLSLExpr4 : public GrGLSLExpr<GrGLSLExpr4> {
-public:
- GrGLSLExpr4()
- : INHERITED() {
- }
- explicit GrGLSLExpr4(int v)
- : INHERITED(v) {
- }
- GrGLSLExpr4(const char* expr)
- : INHERITED(expr) {
- }
- GrGLSLExpr4(const SkString& expr)
- : INHERITED(expr) {
- }
-
- typedef GrGLSLExpr1 AExpr;
- AExpr a() const;
-
- /** GLSL vec4 cast / constructor, eg vec4(floatv) -> vec4(floatv, floatv, floatv, floatv) */
- static GrGLSLExpr4 VectorCast(const GrGLSLExpr1& expr);
- static GrGLSLExpr4 VectorCast(const GrGLSLExpr4& expr);
-
-private:
- GrGLSLExpr4(const char format[], const char in0[])
- : INHERITED(format, in0) {
- }
- GrGLSLExpr4(const char format[], const char in0[], const char in1[])
- : INHERITED(format, in0, in1) {
- }
-
- static const char* ZerosStr();
- static const char* OnesStr();
- static const char* CastStr();
- static const char* CastIntStr();
-
- // The vector-by-scalar and scalar-by-vector binary operations.
- friend GrGLSLExpr4 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1);
- friend GrGLSLExpr4 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1);
- friend GrGLSLExpr4 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr4&in1);
- friend GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1);
- friend GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1);
- friend GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr1&in1);
-
- // The vector-by-vector, i.e. component-wise, binary operations.
- friend GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1);
- friend GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1);
- friend GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4&in1);
-
- friend class GrGLSLExpr<GrGLSLExpr4>;
-
- typedef GrGLSLExpr<GrGLSLExpr4> INHERITED;
-};
-
-/**
- * Does an inplace mul, *=, of vec4VarName by mulFactor.
- * A semicolon is added after the assignment.
- */
-void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSLExpr4& mulFactor);
-
-#include "GrGLSL_impl.h"
-
#endif
+++ /dev/null
-/*
- * Copyright 2013 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrGLSL_impl_DEFINED
-#define GrGLSL_impl_DEFINED
-
-template<typename Self>
-template<typename T>
-inline Self GrGLSLExpr<Self>::VectorCastImpl(const T& expr) {
- if (expr.isZeros()) {
- return Self(0);
- }
- if (expr.isOnes()) {
- return Self(1);
- }
- return Self(Self::CastStr(), expr.c_str());
-}
-
-template<typename Self>
-template<typename T0, typename T1>
-inline Self GrGLSLExpr<Self>::Mul(T0 in0, T1 in1) {
- if (in0.isZeros() || in1.isZeros()) {
- return Self(0);
- }
- if (in0.isOnes()) {
- return Self::VectorCast(in1);
- }
- if (in1.isOnes()) {
- return Self::VectorCast(in0);
- }
- return Self("(%s * %s)", in0.c_str(), in1.c_str());
-}
-
-template<typename Self>
-template<typename T0, typename T1>
-inline Self GrGLSLExpr<Self>::Add(T0 in0, T1 in1) {
- if (in1.isZeros()) {
- return Self::VectorCast(in0);
- }
- if (in0.isZeros()) {
- return Self::VectorCast(in1);
- }
- if (in0.isOnes() && in1.isOnes()) {
- return Self(2);
- }
- return Self("(%s + %s)", in0.c_str(), in1.c_str());
-}
-
-template<typename Self>
-template<typename T0, typename T1>
-inline Self GrGLSLExpr<Self>::Sub(T0 in0, T1 in1) {
- if (in1.isZeros()) {
- return Self::VectorCast(in0);
- }
- if (in1.isOnes()) {
- if (in0.isOnes()) {
- return Self(0);
- }
- }
-
- return Self("(%s - %s)", in0.c_str(), in1.c_str());
-}
-
-template <typename Self>
-template <typename T>
-T GrGLSLExpr<Self>::extractComponents(const char format[]) const {
- if (this->isZeros()) {
- return T(0);
- }
- if (this->isOnes()) {
- return T(1);
- }
- return T(format, this->c_str());
-}
-
-inline GrGLSLExpr1 GrGLSLExpr1::VectorCast(const GrGLSLExpr1& expr) {
- return expr;
-}
-
-inline const char* GrGLSLExpr1::ZerosStr() {
- return "0";
-}
-
-inline const char* GrGLSLExpr1::OnesStr() {
- return "1.0";
-}
-
-// GrGLSLExpr1::CastStr() is unimplemented because using them is likely an
-// error. This is now caught compile-time.
-
-inline const char* GrGLSLExpr1::CastIntStr() {
- return "%d";
-}
-
-inline GrGLSLExpr1 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
- return GrGLSLExpr1::Mul(in0, in1);
-}
-
-inline GrGLSLExpr1 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
- return GrGLSLExpr1::Add(in0, in1);
-}
-
-inline GrGLSLExpr1 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr1& in1) {
- return GrGLSLExpr1::Sub(in0, in1);
-}
-
-inline const char* GrGLSLExpr4::ZerosStr() {
- return "vec4(0)";
-}
-
-inline const char* GrGLSLExpr4::OnesStr() {
- return "vec4(1)";
-}
-
-inline const char* GrGLSLExpr4::CastStr() {
- return "vec4(%s)";
-}
-
-inline const char* GrGLSLExpr4::CastIntStr() {
- return "vec4(%d)";
-}
-
-inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr1& expr) {
- return INHERITED::VectorCastImpl(expr);
-}
-
-inline GrGLSLExpr4 GrGLSLExpr4::VectorCast(const GrGLSLExpr4& expr) {
- return expr;
-}
-
-inline GrGLSLExpr4::AExpr GrGLSLExpr4::a() const {
- return this->extractComponents<GrGLSLExpr4::AExpr>("%s.a");
-}
-
-inline GrGLSLExpr4 operator*(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
- return GrGLSLExpr4::Mul(in0, in1);
-}
-
-inline GrGLSLExpr4 operator+(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
- return GrGLSLExpr4::Add(in0, in1);
-}
-
-inline GrGLSLExpr4 operator-(const GrGLSLExpr1& in0, const GrGLSLExpr4& in1) {
- return GrGLSLExpr4::Sub(in0, in1);
-}
-
-inline GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) {
- return GrGLSLExpr4::Mul(in0, in1);
-}
-
-inline GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) {
- return GrGLSLExpr4::Add(in0, in1);
-}
-
-inline GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr1& in1) {
- return GrGLSLExpr4::Sub(in0, in1);
-}
-
-inline GrGLSLExpr4 operator*(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
- return GrGLSLExpr4::Mul(in0, in1);
-}
-
-inline GrGLSLExpr4 operator+(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
- return GrGLSLExpr4::Add(in0, in1);
-}
-
-inline GrGLSLExpr4 operator-(const GrGLSLExpr4& in0, const GrGLSLExpr4& in1) {
- return GrGLSLExpr4::Sub(in0, in1);
-}
-
-#endif
fragBuilder->codeAppendf("vec4 diffuseColor = %s;", args.fInputColor);
SkString dstNormalName("dstNormal");
- this->emitChild(0, nullptr, &dstNormalName, args);
+ this->emitChild(0, &dstNormalName, args);
fragBuilder->codeAppendf("vec3 normal = %s.xyz;", dstNormalName.c_str());
kDefault_GrSLPrecision, "Xform", &xformUniName);
SkString dstNormalColorName("dstNormalColor");
- this->emitChild(0, nullptr, &dstNormalColorName, args);
+ this->emitChild(0, &dstNormalColorName, args);
fragBuilder->codeAppendf("vec3 normal = normalize(%s.rgb - vec3(0.5));",
dstNormalColorName.c_str());
"color.a = inner_thresh;"
"}");
- fragBuilder->codeAppendf("%s = %s;", args.fOutputColor,
- (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr4("color")).c_str());
+ fragBuilder->codeAppendf("%s = %s * color;", args.fOutputColor, args.fInputColor);
}
void GrGLAlphaThresholdFragmentProcessor::onSetData(const GrGLSLProgramDataManager& pdman,
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
SkString dstColor("dstColor");
- this->emitChild(0, nullptr, &dstColor, args);
+ this->emitChild(0, &dstColor, args);
fKUni = args.fUniformHandler->addUniform(kFragment_GrShaderFlag, kVec4f_GrSLType,
kDefault_GrSLPrecision, "k");
args.fOutputColor, lightFunc.c_str(), normalName.c_str(), surfScale);
fLight->emitLightColor(uniformHandler, fragBuilder, "surfaceToLight");
fragBuilder->codeAppend(");\n");
- SkString modulate;
- GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
- fragBuilder->codeAppend(modulate.c_str());
+ fragBuilder->codeAppendf("%s *= %s;\n", args.fOutputColor, args.fInputColor);
}
void GrGLLightingEffect::GenKey(const GrProcessor& proc,
&fColorSpaceHelper);
fragBuilder->codeAppend(";\n");
- fragBuilder->codeAppendf("\t\t%s = output_color;", args.fOutputColor);
- SkString modulate;
- GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
- fragBuilder->codeAppend(modulate.c_str());
+ fragBuilder->codeAppendf("\t\t%s = output_color;\n", args.fOutputColor);
+ fragBuilder->codeAppendf("%s *= %s;\n", args.fOutputColor, args.fInputColor);
}
void GrGLMagnifierEffect::onSetData(const GrGLSLProgramDataManager& pdman,
fragBuilder->codeAppendf("\t\t\tcoord.%s = min(highBound, coord.%s);", dir, dir);
}
fragBuilder->codeAppend("\t\t}\n");
- SkString modulate;
- GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
- fragBuilder->codeAppend(modulate.c_str());
+ fragBuilder->codeAppendf("%s *= %s;\n", args.fOutputColor, args.fInputColor);
}
void GrGLMorphologyEffect::GenKey(const GrProcessor& proc,
if (ge.fColorSpaceXform) {
fragBuilder->codeAppend("colorTemp.rgb = clamp(colorTemp.rgb, 0, colorTemp.a);");
}
- fragBuilder->codeAppendf("%s = %s;", outputColor,
- (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp")).c_str());
+ fragBuilder->codeAppendf("%s = %s * colorTemp;", outputColor, inputColor);
break;
}
if (ge.fColorSpaceXform) {
fragBuilder->codeAppend("colorTemp.rgb = clamp(colorTemp.rgb, 0, colorTemp.a);");
}
- fragBuilder->codeAppendf("%s = %s;", outputColor,
- (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp")).c_str());
+ fragBuilder->codeAppendf("%s = %s * colorTemp;", outputColor, inputColor);
break;
}
if (ge.fColorSpaceXform) {
fragBuilder->codeAppend("colorTemp.rgb = clamp(colorTemp.rgb, 0, colorTemp.a);");
}
- fragBuilder->codeAppendf("%s = %s;", outputColor,
- (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp")).c_str());
+ fragBuilder->codeAppendf("%s = %s * colorTemp;", outputColor, inputColor);
break;
}
fragBuilder->codeAppend("colorTemp.rgb = clamp(colorTemp.rgb, 0, colorTemp.a);");
}
- fragBuilder->codeAppendf("%s = %s;", outputColor,
- (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp")).c_str());
+ fragBuilder->codeAppendf("%s = %s * colorTemp;", outputColor, inputColor);
break;
}
fragBuilder->codeAppend("colorTemp.rgb = clamp(colorTemp.rgb, 0, colorTemp.a);");
}
- fragBuilder->codeAppendf("%s = %s;", outputColor,
- (GrGLSLExpr4(inputColor) * GrGLSLExpr4("colorTemp")).c_str());
+ fragBuilder->codeAppendf("%s = %s * colorTemp;", outputColor, inputColor);
break;
}
public:
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- this->emitChild(0, nullptr, args);
+ this->emitChild(0, args);
fragBuilder->codeAppendf("%s.rgb *= %s.rgb;", args.fOutputColor,
args.fInputColor);
fragBuilder->codeAppendf("%s *= %s.a;", args.fOutputColor, args.fInputColor);
fragBuilder->appendColorGamutXform(&xformedColor, bicubicColor.c_str(), &fColorSpaceHelper);
bicubicColor.swap(xformedColor);
}
- fragBuilder->codeAppendf("%s = %s;",
- args.fOutputColor, (GrGLSLExpr4(bicubicColor.c_str()) *
- GrGLSLExpr4(args.fInputColor)).c_str());
+ fragBuilder->codeAppendf("%s = %s * %s;", args.fOutputColor, bicubicColor.c_str(),
+ args.fInputColor);
}
void GrGLBicubicEffect::onSetData(const GrGLSLProgramDataManager& pdman,
if (GrProcessorEdgeTypeIsInverseFill(aare.getEdgeType())) {
fragBuilder->codeAppend("\t\talpha = 1.0 - alpha;\n");
}
- fragBuilder->codeAppendf("\t\t%s = %s;\n", args.fOutputColor,
- (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")).c_str());
+ fragBuilder->codeAppendf("\t\t%s = %s * alpha;\n", args.fOutputColor, args.fInputColor);
}
void GLAARectEffect::onSetData(const GrGLSLProgramDataManager& pdman,
if (GrProcessorEdgeTypeIsInverseFill(cpe.getEdgeType())) {
fragBuilder->codeAppend("\talpha = 1.0 - alpha;\n");
}
- fragBuilder->codeAppendf("\t%s = %s;\n", args.fOutputColor,
- (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")).c_str());
+ fragBuilder->codeAppendf("\t%s = %s * alpha;\n", args.fOutputColor, args.fInputColor);
}
void GrGLConvexPolyEffect::onSetData(const GrGLSLProgramDataManager& pdman,
"fract(sin(dot(sk_FragCoord.xy, vec2(12.9898,78.233))) * "
"43758.5453);\n");
fragBuilder->codeAppendf("\t\t%s = clamp((1.0/255.0) * vec4(r, r, r, r) + %s, 0, 1);\n",
- args.fOutputColor, GrGLSLExpr4(args.fInputColor).c_str());
+ args.fOutputColor, args.fInputColor);
}
//////////////////////////////////////////////////////////////////////////////
}
fragBuilder->codeAppendf("coord += %s;\n", imgInc);
}
-
- SkString modulate;
- GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
- fragBuilder->codeAppend(modulate.c_str());
+ fragBuilder->codeAppendf("%s *= %s;\n", args.fOutputColor, args.fInputColor);
}
void GrGLConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman,
fragBuilder->codeAppendf("%s.rgb = clamp(sum.rgb * %s + %s, 0, 1);", args.fOutputColor, gain, bias);
fragBuilder->codeAppendf("%s.rgb *= %s.a;", args.fOutputColor, args.fOutputColor);
}
-
- SkString modulate;
- GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
- fragBuilder->codeAppend(modulate.c_str());
+ fragBuilder->codeAppendf("%s *= %s;\n", args.fOutputColor, args.fInputColor);
}
void GrGLMatrixConvolutionEffect::GenKey(const GrProcessor& processor,
fragBuilder->codeAppend("d = d > 0.5 ? 1.0 : 0.0;");
}
- fragBuilder->codeAppendf("%s = %s;", args.fOutputColor,
- (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("d")).c_str());
+ fragBuilder->codeAppendf("%s = %s * d;", args.fOutputColor, args.fInputColor);
}
void GLCircleEffect::GenKey(const GrProcessor& processor, const GrShaderCaps&,
SkFAIL("Hairline not expected here.");
}
- fragBuilder->codeAppendf("%s = %s;", args.fOutputColor,
- (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")).c_str());
+ fragBuilder->codeAppendf("%s = %s * alpha;", args.fOutputColor, args.fInputColor);
}
void GLEllipseEffect::GenKey(const GrProcessor& effect, const GrShaderCaps&,
fragBuilder->codeAppend("alpha = 1.0 - alpha;");
}
- fragBuilder->codeAppendf("%s = %s;", args.fOutputColor,
- (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")).c_str());
+ fragBuilder->codeAppendf("%s = %s * alpha;", args.fOutputColor, args.fInputColor);
}
void GLCircularRRectEffect::GenKey(const GrProcessor& processor, const GrShaderCaps&,
fragBuilder->codeAppend("float alpha = clamp(0.5 + approx_dist, 0.0, 1.0);");
}
- fragBuilder->codeAppendf("%s = %s;", args.fOutputColor,
- (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")).c_str());
+ fragBuilder->codeAppendf("%s = %s * alpha;", args.fOutputColor, args.fInputColor);
}
void GLEllipticalRRectEffect::GenKey(const GrProcessor& effect, const GrShaderCaps&,
ComposeOneFragmentProcessor::Child child =
args.fFp.cast<ComposeOneFragmentProcessor>().child();
SkString childColor("child");
- this->emitChild(0, nullptr, &childColor, args);
+ this->emitChild(0, &childColor, args);
const char* inputColor = args.fInputColor;
// We don't try to optimize for this case at all
// uniforms, varyings, textures, etc
GrGLProgramBuilder builder(gpu, pipeline, primProc, desc);
- // TODO: Once all stages can handle taking a float or vec4 and correctly handling them we can
- // seed correctly here
- GrGLSLExpr4 inputColor;
- GrGLSLExpr4 inputCoverage;
-
- if (!builder.emitAndInstallProcs(&inputColor, &inputCoverage)) {
+ if (!builder.emitAndInstallProcs()) {
builder.cleanupFragmentProcessors();
return nullptr;
}
}
}
}
-
-void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSLExpr4& mulFactor) {
- if (mulFactor.isOnes()) {
- *outAppend = SkString();
- }
-
- if (mulFactor.isZeros()) {
- outAppend->appendf("%s = vec4(0);", vec4VarName);
- } else {
- outAppend->appendf("%s *= %s;", vec4VarName, mulFactor.c_str());
- }
-}
void GrGLSLFragmentProcessor::emitChild(int childIndex, const char* inputColor,
SkString* outputColor, EmitArgs& args) {
-
SkASSERT(outputColor);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
outputColor->append(fragBuilder->getMangleString());
void GrGLSLFragmentProcessor::internalEmitChild(int childIndex, const char* inputColor,
const char* outputColor, EmitArgs& args) {
+ SkASSERT(inputColor);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
fragBuilder->onBeforeChildProcEmitCode(); // call first so mangleString is updated
return fChildProcessors[index];
}
+ inline void emitChild(int childIndex, SkString* outputColor, EmitArgs& parentArgs) {
+ this->emitChild(childIndex, "vec4(1.0)", outputColor, parentArgs);
+ }
+
/** Will emit the code of a child proc in its own scope. Pass in the parent's EmitArgs and
* emitChild will automatically extract the coords and samplers of that child and pass them
* on to the child's emitCode(). Also, any uniforms or functions emitted by the child will
void emitChild(int childIndex, const char* inputColor, SkString* outputColor,
EmitArgs& parentArgs);
+ inline void emitChild(int childIndex, EmitArgs& args) {
+ this->emitChild(childIndex, "vec4(1.0)", args);
+ }
+
/** Variation that uses the parent's output color variable to hold the child's output.*/
void emitChild(int childIndex, const char* inputColor, EmitArgs& parentArgs);
}
}
-bool GrGLSLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor,
- GrGLSLExpr4* inputCoverage) {
+bool GrGLSLProgramBuilder::emitAndInstallProcs() {
// First we loop over all of the installed processors and collect coord transforms. These will
// be sent to the GrGLSLPrimitiveProcessor in its emitCode function
const GrPrimitiveProcessor& primProc = this->primitiveProcessor();
- this->emitAndInstallPrimProc(primProc, inputColor, inputCoverage);
-
- this->emitAndInstallFragProcs(inputColor, inputCoverage);
- this->emitAndInstallXferProc(*inputColor, *inputCoverage);
+ SkString inputColor;
+ SkString inputCoverage;
+ this->emitAndInstallPrimProc(primProc, &inputColor, &inputCoverage);
+ this->emitAndInstallFragProcs(&inputColor, &inputCoverage);
+ this->emitAndInstallXferProc(inputColor, inputCoverage);
this->emitFSOutputSwizzle(this->pipeline().getXferProcessor().hasSecondaryOutput());
return this->checkSamplerCounts() && this->checkImageStorageCounts();
}
void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& proc,
- GrGLSLExpr4* outputColor,
- GrGLSLExpr4* outputCoverage) {
+ SkString* outputColor,
+ SkString* outputCoverage) {
// Program builders have a bit of state we need to clear with each effect
AutoStageAdvance adv(this);
this->nameExpression(outputColor, "outputColor");
fFS.codeAppend("}");
}
-void GrGLSLProgramBuilder::emitAndInstallFragProcs(GrGLSLExpr4* color, GrGLSLExpr4* coverage) {
+void GrGLSLProgramBuilder::emitAndInstallFragProcs(SkString* color, SkString* coverage) {
int transformedCoordVarsIdx = 0;
- GrGLSLExpr4** inOut = &color;
+ SkString** inOut = &color;
for (int i = 0; i < this->pipeline().numFragmentProcessors(); ++i) {
if (i == this->pipeline().numColorFragmentProcessors()) {
inOut = &coverage;
}
- GrGLSLExpr4 output;
+ SkString output;
const GrFragmentProcessor& fp = this->pipeline().getFragmentProcessor(i);
- this->emitAndInstallFragProc(fp, i, transformedCoordVarsIdx, **inOut, &output);
+ output = this->emitAndInstallFragProc(fp, i, transformedCoordVarsIdx, **inOut, output);
GrFragmentProcessor::Iter iter(&fp);
while (const GrFragmentProcessor* fp = iter.next()) {
transformedCoordVarsIdx += fp->numCoordTransforms();
}
// TODO Processors cannot output zeros because an empty string is all 1s
-// the fix is to allow effects to take the GrGLSLExpr4 directly
-void GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor& fp,
- int index,
- int transformedCoordVarsIdx,
- const GrGLSLExpr4& input,
- GrGLSLExpr4* output) {
+// the fix is to allow effects to take the SkString directly
+SkString GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor& fp,
+ int index,
+ int transformedCoordVarsIdx,
+ const SkString& input,
+ SkString output) {
+ SkASSERT(input.size());
// Program builders have a bit of state we need to clear with each effect
AutoStageAdvance adv(this);
- this->nameExpression(output, "output");
+ this->nameExpression(&output, "output");
// Enclose custom code in a block to avoid namespace conflicts
SkString openBrace;
this->uniformHandler(),
this->shaderCaps(),
fp,
- output->c_str(),
- input.isOnes() ? nullptr : input.c_str(),
+ output.c_str(),
+ input.c_str(),
coords,
textureSamplers,
bufferSamplers,
fFragmentProcessors.push_back(fragProc);
fFS.codeAppend("}");
+ return output;
}
-void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrGLSLExpr4& colorIn,
- const GrGLSLExpr4& coverageIn) {
+void GrGLSLProgramBuilder::emitAndInstallXferProc(const SkString& colorIn,
+ const SkString& coverageIn) {
// Program builders have a bit of state we need to clear with each effect
AutoStageAdvance adv(this);
this->uniformHandler(),
this->shaderCaps(),
xp,
- colorIn.c_str(),
- coverageIn.c_str(),
+ colorIn.size() ? colorIn.c_str() : "vec4(1)",
+ coverageIn.size() ? coverageIn.c_str() : "vec4(1)",
fFS.getPrimaryColorOutputName(),
fFS.getSecondaryColorOutputName(),
dstTextureSamplerHandle,
}
}
-void GrGLSLProgramBuilder::nameExpression(GrGLSLExpr4* output, const char* baseName) {
+void GrGLSLProgramBuilder::nameExpression(SkString* output, const char* baseName) {
// create var to hold stage result. If we already have a valid output name, just use that
// otherwise create a new mangled one. This name is only valid if we are reordering stages
// and have to tell stage exactly where to put its output.
SkString outName;
- if (output->isValid()) {
+ if (output->size()) {
outName = output->c_str();
} else {
this->nameVariable(&outName, '\0', baseName);
class GrShaderVar;
class GrGLSLVaryingHandler;
-class GrGLSLExpr4;
+class SkString;
class GrShaderCaps;
typedef SkSTArray<8, GrGLSLFragmentProcessor*, true> GrGLSLFragProcs;
void addFeature(GrShaderFlags shaders, uint32_t featureBit, const char* extensionName);
- bool emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr4* inputCoverage);
+ bool emitAndInstallProcs();
void cleanupFragmentProcessors();
};
// Generates a possibly mangled name for a stage variable and writes it to the fragment shader.
- // If GrGLSLExpr4 has a valid name then it will use that instead
- void nameExpression(GrGLSLExpr4*, const char* baseName);
+ void nameExpression(SkString*, const char* baseName);
void emitAndInstallPrimProc(const GrPrimitiveProcessor&,
- GrGLSLExpr4* outputColor,
- GrGLSLExpr4* outputCoverage);
- void emitAndInstallFragProcs(GrGLSLExpr4* colorInOut, GrGLSLExpr4* coverageInOut);
- void emitAndInstallFragProc(const GrFragmentProcessor&,
- int index,
- int transformedCoordVarsIdx,
- const GrGLSLExpr4& input,
- GrGLSLExpr4* output);
- void emitAndInstallXferProc(const GrGLSLExpr4& colorIn, const GrGLSLExpr4& coverageIn);
+ SkString* outputColor,
+ SkString* outputCoverage);
+ void emitAndInstallFragProcs(SkString* colorInOut, SkString* coverageInOut);
+ SkString emitAndInstallFragProc(const GrFragmentProcessor&,
+ int index,
+ int transformedCoordVarsIdx,
+ const SkString& input,
+ SkString output);
+ void emitAndInstallXferProc(const SkString& colorIn, const SkString& coverageIn);
void emitSamplersAndImageStorages(const GrResourceIOProcessor& processor,
SkTArray<SamplerHandle>* outTexSamplerHandles,
SkTArray<SamplerHandle>* outBufferSamplerHandles,
if (colorXformHelper && colorXformHelper->isValid()) {
SkString xform;
this->appendColorGamutXform(&xform, lookup.c_str(), colorXformHelper);
- this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(xform)).c_str());
+ if (modulation) {
+ this->codeAppendf("%s * %s", modulation, xform.c_str());
+ } else {
+ this->codeAppendf("%s", xform.c_str());
+ }
} else {
- this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str());
+ if (modulation) {
+ this->codeAppendf("%s * %s", modulation, lookup.c_str());
+ } else {
+ this->codeAppendf("%s", lookup.c_str());
+ }
}
}
// uniforms, varyings, textures, etc
GrVkPipelineStateBuilder builder(gpu, pipeline, primProc, desc);
- GrGLSLExpr4 inputColor;
- GrGLSLExpr4 inputCoverage;
-
- if (!builder.emitAndInstallProcs(&inputColor, &inputCoverage)) {
+ if (!builder.emitAndInstallProcs()) {
builder.cleanupFragmentProcessors();
return nullptr;
}
class GLFP : public GrGLSLFragmentProcessor {
public:
void emitCode(EmitArgs& args) override {
- this->emitChild(0, nullptr, args);
+ this->emitChild(0, args);
}
private: