#include "SkGr.h"
#include "effects/GrConstColorProcessor.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
#endif
}
void GrGLPerlinNoise2::emitCode(EmitArgs& args) {
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
- fBaseFrequencyUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fBaseFrequencyUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"baseFrequency");
const char* baseFrequencyUni = args.fBuilder->getUniformCStr(fBaseFrequencyUni);
const char* stitchDataUni = nullptr;
if (fStitchTiles) {
- fStitchDataUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fStitchDataUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"stitchData");
stitchDataUni = args.fBuilder->getUniformCStr(fStitchDataUni);
}
void GrGLPerlinNoise2::GenKey(const GrProcessor& processor, const GrGLSLCaps&,
- GrProcessorKeyBuilder* b) {
+ GrProcessorKeyBuilder* b) {
const GrPerlinNoise2Effect& turbulence = processor.cast<GrPerlinNoise2Effect>();
uint32_t key = turbulence.numOctaves();
}
void GrGLImprovedPerlinNoise::emitCode(EmitArgs& args) {
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
- fBaseFrequencyUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fBaseFrequencyUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"baseFrequency");
const char* baseFrequencyUni = args.fBuilder->getUniformCStr(fBaseFrequencyUni);
- fOctavesUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fOctavesUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"octaves");
const char* octavesUni = args.fBuilder->getUniformCStr(fOctavesUni);
- fZUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fZUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"z");
const char* zUni = args.fBuilder->getUniformCStr(fZUni);
#include "GrCoordTransform.h"
#include "effects/GrXfermodeFragmentProcessor.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
#include "Resources.h"
#include "SkReadBuffer.h"
GrGLFragmentProcessor* onCreateGLInstance() const override {
class DCGLFP : public GrGLFragmentProcessor {
void emitCode(EmitArgs& args) override {
- GrGLFragmentBuilder* fpb = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fpb = args.fBuilder->getFragmentShaderBuilder();
fpb->codeAppendf("vec2 c = %s;", fpb->ensureFSCoords2D(args.fCoords, 0).c_str());
fpb->codeAppend("vec2 r = mod(c, vec2(20.0));");
fpb->codeAppend("vec4 color = vec4(0.5*sin(c.x / 15.0) + 0.5,"
# Files for building GLSL shaders
'<(skia_src_path)/gpu/gl/builders/GrGLProgramBuilder.cpp',
'<(skia_src_path)/gpu/gl/builders/GrGLProgramBuilder.h',
- '<(skia_src_path)/gpu/gl/builders/GrGLShaderBuilder.cpp',
- '<(skia_src_path)/gpu/gl/builders/GrGLShaderBuilder.h',
'<(skia_src_path)/gpu/gl/builders/GrGLShaderStringBuilder.cpp',
'<(skia_src_path)/gpu/gl/builders/GrGLShaderStringBuilder.h',
'<(skia_src_path)/gpu/gl/builders/GrGLSLPrettyPrint.cpp',
- '<(skia_src_path)/gpu/gl/builders/GrGLVertexShaderBuilder.cpp',
- '<(skia_src_path)/gpu/gl/builders/GrGLVertexShaderBuilder.h',
- '<(skia_src_path)/gpu/gl/builders/GrGLFragmentShaderBuilder.cpp',
- '<(skia_src_path)/gpu/gl/builders/GrGLFragmentShaderBuilder.h',
- '<(skia_src_path)/gpu/gl/builders/GrGLGeometryShaderBuilder.cpp',
- '<(skia_src_path)/gpu/gl/builders/GrGLGeometryShaderBuilder.h',
# GLSL
'<(skia_src_path)/gpu/glsl/GrGLSL.cpp',
'<(skia_src_path)/gpu/glsl/GrGLSL_impl.h',
'<(skia_src_path)/gpu/glsl/GrGLSLCaps.cpp',
'<(skia_src_path)/gpu/glsl/GrGLSLCaps.h',
+ '<(skia_src_path)/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp',
+ '<(skia_src_path)/gpu/glsl/GrGLSLFragmentShaderBuilder.h',
+ '<(skia_src_path)/gpu/glsl/GrGLSLGeometryShaderBuilder.cpp',
+ '<(skia_src_path)/gpu/glsl/GrGLSLGeometryShaderBuilder.h',
'<(skia_src_path)/gpu/glsl/GrGLSLProcessorTypes.h',
'<(skia_src_path)/gpu/glsl/GrGLSLProgramBuilder.cpp',
'<(skia_src_path)/gpu/glsl/GrGLSLProgramBuilder.h',
'<(skia_src_path)/gpu/glsl/GrGLSLProgramDataManager.h',
+ '<(skia_src_path)/gpu/glsl/GrGLSLShaderBuilder.cpp',
+ '<(skia_src_path)/gpu/glsl/GrGLSLShaderBuilder.h',
'<(skia_src_path)/gpu/glsl/GrGLSLShaderVar.h',
'<(skia_src_path)/gpu/glsl/GrGLSLTextureSampler.h',
+ '<(skia_src_path)/gpu/glsl/GrGLSLVertexShaderBuilder.cpp',
+ '<(skia_src_path)/gpu/glsl/GrGLSLVertexShaderBuilder.h',
# Sk files
'<(skia_include_path)/gpu/SkGr.h',
#include "GrFragmentProcessor.h"
#include "GrTextureAccess.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
#include "SkGr.h"
#include "SkGrPriv.h"
void emitCode(EmitArgs& args) override {
- GrGLFragmentBuilder* fpb = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fpb = args.fBuilder->getFragmentShaderBuilder();
// add uniforms
const char* lightDirUniName = nullptr;
- fLightDirUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fLightDirUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec3f_GrSLType, kDefault_GrSLPrecision,
"LightDir", &lightDirUniName);
const char* lightColorUniName = nullptr;
- fLightColorUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fLightColorUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec3f_GrSLType, kDefault_GrSLPrecision,
"LightColor", &lightColorUniName);
const char* ambientColorUniName = nullptr;
- fAmbientColorUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fAmbientColorUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec3f_GrSLType, kDefault_GrSLPrecision,
"AmbientColor", &ambientColorUniName);
const char* xformUniName = nullptr;
- fXformUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fXformUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"Xform", &xformUniName);
#include "GrTextureProvider.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
class GrGLCircleBlurFragmentProcessor : public GrGLFragmentProcessor {
// x,y - the center of the circle
// z - the distance at which the intensity starts falling off (e.g., the start of the table)
// w - the size of the profile texture
- fDataUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fDataUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType,
kDefault_GrSLPrecision,
"data",
&dataName);
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
const char *fragmentPos = fsBuilder->fragmentPosition();
if (args.fInputColor) {
#include "SkGr.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
class AlphaThresholdEffect : public GrFragmentProcessor {
};
void GrGLAlphaThresholdEffect::emitCode(EmitArgs& args) {
- fInnerThresholdVar = args.fBuilder->addUniform(
- GrGLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType, kDefault_GrSLPrecision,
- "inner_threshold");
- fOuterThresholdVar = args.fBuilder->addUniform(
- GrGLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType, kDefault_GrSLPrecision,
- "outer_threshold");
-
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ fInnerThresholdVar = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
+ kFloat_GrSLType, kDefault_GrSLPrecision,
+ "inner_threshold");
+ fOuterThresholdVar = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
+ kFloat_GrSLType, kDefault_GrSLPrecision,
+ "outer_threshold");
+
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
SkString maskCoords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 1);
///////////////////////////////////////////////////////////////////////////////
void AlphaThresholdEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GrGLAlphaThresholdEffect::GenKey(*this, caps, b);
}
#include "GrTexture.h"
#include "gl/GrGLCaps.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "gl/GrGLXferProcessor.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
static const bool gUseUnpremul = false;
-static void add_arithmetic_code(GrGLFragmentBuilder* fsBuilder,
+static void add_arithmetic_code(GrGLSLFragmentBuilder* fsBuilder,
const char* srcColor,
const char* dstColor,
const char* outputColor,
~GLArithmeticFP() override {}
void emitCode(EmitArgs& args) override {
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkString dstColor("dstColor");
this->emitChild(0, nullptr, &dstColor, args);
- fKUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fKUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision,
"k");
const char* kUni = args.fBuilder->getUniformCStr(fKUni);
private:
void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb, const char* srcColor, const char* dstColor,
const char* outColor, const GrXferProcessor& proc) override {
- GrGLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
+ GrGLSLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
- fKUni = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fKUni = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision,
"k");
const char* kUni = pb->getUniformCStr(fKUni);
#include "SkDraw.h"
#include "effects/GrSimpleTextureEffect.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
#include "glsl/GrGLSLTextureSampler.h"
#endif
typedef GrGLFragmentProcessor INHERITED;
};
-void OutputRectBlurProfileLookup(GrGLFragmentBuilder* fsBuilder,
+void OutputRectBlurProfileLookup(GrGLSLFragmentBuilder* fsBuilder,
const GrGLSLTextureSampler& sampler,
const char *output,
const char *profileSize, const char *loc,
const char* precisionString = GrGLSLShaderVar::PrecisionString(args.fBuilder->glslCaps(),
fPrecision);
- fProxyRectUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fProxyRectUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType,
fPrecision,
"proxyRect",
&rectName);
- fProfileSizeUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fProfileSizeUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType,
kDefault_GrSLPrecision,
"profileSize",
&profileSizeName);
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
const char *fragmentPos = fsBuilder->fragmentPosition();
if (args.fInputColor) {
}
void GrRectBlurEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GrGLRectBlurEffect::GenKey(fPrecision, b);
}
// The proxy rect has left, top, right, and bottom edges correspond to
// components x, y, z, and w, respectively.
- fProxyRectUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kVec4f_GrSLType,
- kDefault_GrSLPrecision,
- "proxyRect",
- &rectName);
- fCornerRadiusUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType,
- kDefault_GrSLPrecision,
- "cornerRadius",
- &cornerRadiusName);
- fBlurRadiusUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType,
- kDefault_GrSLPrecision,
- "blurRadius",
- &blurRadiusName);
-
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ fProxyRectUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
+ kVec4f_GrSLType,
+ kDefault_GrSLPrecision,
+ "proxyRect",
+ &rectName);
+ fCornerRadiusUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
+ kFloat_GrSLType,
+ kDefault_GrSLPrecision,
+ "cornerRadius",
+ &cornerRadiusName);
+ fBlurRadiusUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
+ kFloat_GrSLType,
+ kDefault_GrSLPrecision,
+ "blurRadius",
+ &blurRadiusName);
+
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
const char* fragmentPos = fsBuilder->fragmentPosition();
// warp the fragment position to the appropriate part of the 9patch blur texture
#include "GrTexturePriv.h"
#include "SkGr.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
#endif
args.fInputColor = "vec4(1)";
}
- fColorCubeSizeUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fColorCubeSizeUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"Size");
const char* colorCubeSizeUni = args.fBuilder->getUniformCStr(fColorCubeSizeUni);
- fColorCubeInvSizeUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fColorCubeInvSizeUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"InvSize");
const char* colorCubeInvSizeUni = args.fBuilder->getUniformCStr(fColorCubeInvSizeUni);
// Note: if implemented using texture3D in OpenGL ES older than OpenGL ES 3.0,
// the shader might need "#extension GL_OES_texture_3D : enable".
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
// Unpremultiply color
fsBuilder->codeAppendf("\tfloat %s = max(%s.a, 0.00001);\n", nonZeroAlpha, args.fInputColor);
#include "GrFragmentProcessor.h"
#include "GrInvariantOutput.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
class ColorMatrixEffect : public GrFragmentProcessor {
GLProcessor(const GrProcessor&) {}
virtual void emitCode(EmitArgs& args) override {
- fMatrixHandle = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fMatrixHandle = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kMat44f_GrSLType, kDefault_GrSLPrecision,
"ColorMatrix");
- fVectorHandle = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fVectorHandle = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision,
"ColorMatrixVector");
// could optimize this case, but we aren't for now.
args.fInputColor = "vec4(1)";
}
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
// The max() is to guard against 0 / 0 during unpremul when the incoming color is
// transparent black.
fsBuilder->codeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n",
#include "GrInvariantOutput.h"
#include "effects/GrTextureDomain.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
#endif
void GrGLDisplacementMapEffect::emitCode(EmitArgs& args) {
const GrTextureDomain& domain = args.fFp.cast<GrDisplacementMapEffect>().domain();
- fScaleUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kVec2f_GrSLType, kDefault_GrSLPrecision, "Scale");
+ fScaleUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
+ kVec2f_GrSLType, kDefault_GrSLPrecision, "Scale");
const char* scaleUni = args.fBuilder->getUniformCStr(fScaleUni);
const char* dColor = "dColor";
const char* cCoords = "cCoords";
// a number smaller than that to approximate 0, but
// leave room for 32-bit float GPU rounding errors.
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
fsBuilder->codeAppendf("\t\tvec4 %s = ", dColor);
fsBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str(),
args.fCoords[0].getType());
#include "GrPaint.h"
#include "effects/GrSingleTextureEffect.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
class GrGLDiffuseLightingEffect;
}
void GrDiffuseLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GrGLDiffuseLightingEffect::GenKey(*this, caps, b);
}
}
void GrGLLightingEffect::emitCode(EmitArgs& args) {
- fImageIncrementUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fImageIncrementUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"ImageIncrement");
- fSurfaceScaleUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fSurfaceScaleUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"SurfaceScale");
fLight->emitLightColorUniform(args.fBuilder);
GrGLSLShaderVar("scale", kFloat_GrSLType),
};
SkString sobelFuncName;
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
fsBuilder->emitFunction(kFloat_GrSLType,
void GrGLDiffuseLightingEffect::emitLightFunc(GrGLSLFPBuilder* builder, SkString* funcName) {
const char* kd;
- fKDUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fKDUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"KD", &kd);
}
void GrSpecularLightingEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GrGLSpecularLightingEffect::GenKey(*this, caps, b);
}
const char* ks;
const char* shininess;
- fKSUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fKSUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision, "KS", &ks);
- fShininessUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fShininessUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType,
kDefault_GrSLPrecision,
"Shininess",
///////////////////////////////////////////////////////////////////////////////
void GrGLLight::emitLightColorUniform(GrGLSLFPBuilder* builder) {
- fColorUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fColorUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec3f_GrSLType, kDefault_GrSLPrecision,
"LightColor");
}
void GrGLDistantLight::emitSurfaceToLight(GrGLSLFPBuilder* builder, const char* z) {
const char* dir;
- fDirectionUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fDirectionUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec3f_GrSLType, kDefault_GrSLPrecision,
"LightDirection", &dir);
builder->getFragmentShaderBuilder()->codeAppend(dir);
void GrGLPointLight::emitSurfaceToLight(GrGLSLFPBuilder* builder, const char* z) {
const char* loc;
- fLocationUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fLocationUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec3f_GrSLType, kDefault_GrSLPrecision,
"LightLocation", &loc);
- GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
fsBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))",
loc, fsBuilder->fragmentPosition(), z);
}
void GrGLSpotLight::emitSurfaceToLight(GrGLSLFPBuilder* builder, const char* z) {
const char* location;
- fLocationUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fLocationUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec3f_GrSLType, kDefault_GrSLPrecision,
"LightLocation", &location);
- GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
fsBuilder->codeAppendf("normalize(%s - vec3(%s.xy, %s))",
location, fsBuilder->fragmentPosition(), z);
}
const char* cosOuter;
const char* coneScale;
const char* s;
- fExponentUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fExponentUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"Exponent", &exponent);
- fCosInnerConeAngleUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fCosInnerConeAngleUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"CosInnerConeAngle", &cosInner);
- fCosOuterConeAngleUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fCosOuterConeAngleUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"CosOuterConeAngle", &cosOuter);
- fConeScaleUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fConeScaleUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"ConeScale", &coneScale);
- fSUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fSUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec3f_GrSLType, kDefault_GrSLPrecision, "S", &s);
static const GrGLSLShaderVar gLightColorArgs[] = {
color, cosOuter, coneScale);
lightColorBody.appendf("\t}\n");
lightColorBody.appendf("\treturn %s;\n", color);
- GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
fsBuilder->emitFunction(kVec3f_GrSLType,
"lightColor",
SK_ARRAY_COUNT(gLightColorArgs),
#include "GrContext.h"
#include "GrInvariantOutput.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#endif
void SkLumaColorFilter::filterSpan(const SkPMColor src[], int count,
args.fInputColor = "vec4(1)";
}
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
fsBuilder->codeAppendf("\tfloat luma = dot(vec3(%f, %f, %f), %s.rgb);\n",
SK_ITU_BT709_LUM_COEFF_R,
SK_ITU_BT709_LUM_COEFF_G,
#include "effects/GrSingleTextureEffect.h"
#include "gl/GrGLFragmentProcessor.h"
#include "gl/GrGLTexture.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
class GrMagnifierEffect : public GrSingleTextureEffect {
void GrGLMagnifierEffect::emitCode(EmitArgs& args) {
fOffsetVar = args.fBuilder->addUniform(
- GrGLProgramBuilder::kFragment_Visibility |
- GrGLProgramBuilder::kVertex_Visibility,
+ GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision, "Offset");
fInvZoomVar = args.fBuilder->addUniform(
- GrGLProgramBuilder::kFragment_Visibility |
- GrGLProgramBuilder::kVertex_Visibility,
+ GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision, "InvZoom");
fInvInsetVar = args.fBuilder->addUniform(
- GrGLProgramBuilder::kFragment_Visibility |
- GrGLProgramBuilder::kVertex_Visibility,
+ GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision, "InvInset");
fBoundsVar = args.fBuilder->addUniform(
- GrGLProgramBuilder::kFragment_Visibility |
- GrGLProgramBuilder::kVertex_Visibility,
+ GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision, "Bounds");
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
fsBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
fsBuilder->codeAppendf("\t\tvec2 zoom_coord = %s + %s * %s;\n",
#include "GrTexture.h"
#include "effects/Gr1DKernelEffect.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
#endif
}
void GrGLMorphologyEffect::emitCode(EmitArgs& args) {
- fPixelSizeUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fPixelSizeUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"PixelSize");
const char* pixelSizeInc = args.fBuilder->getUniformCStr(fPixelSizeUni);
- fRangeUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fRangeUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"Range");
const char* range = args.fBuilder->getUniformCStr(fRangeUni);
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
const char* func;
switch (fType) {
#include "SkGr.h"
#include "effects/GrConstColorProcessor.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
#endif
}
void GrGLPerlinNoise::emitCode(EmitArgs& args) {
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
- fBaseFrequencyUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fBaseFrequencyUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"baseFrequency");
const char* baseFrequencyUni = args.fBuilder->getUniformCStr(fBaseFrequencyUni);
const char* stitchDataUni = nullptr;
if (fStitchTiles) {
- fStitchDataUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fStitchDataUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"stitchData");
stitchDataUni = args.fBuilder->getUniformCStr(fStitchDataUni);
#include "SkGr.h"
#include "effects/GrTextureStripAtlas.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
class ColorTableEffect : public GrFragmentProcessor {
"yoffsets", &yoffsets);
static const float kColorScaleFactor = 255.0f / 256.0f;
static const float kColorOffsetFactor = 1.0f / 512.0f;
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
if (nullptr == args.fInputColor) {
// the input color is solid white (all ones).
static const float kMaxValue = kColorScaleFactor + kColorOffsetFactor;
}
void ColorTableEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GLColorTableEffect::GenKey(*this, caps, b);
}
#include "effects/GrTextureStripAtlas.h"
#include "GrInvariantOutput.h"
#include "gl/GrGLContext.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
#include "SkGr.h"
void GrGLGradientEffect::emitUniforms(GrGLSLFPBuilder* builder, const GrGradientEffect& ge) {
if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()) { // 2 Color case
- fColorStartUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fColorStartUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision,
"GradientStartColor");
- fColorEndUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fColorEndUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision,
"GradientEndColor");
} else if (SkGradientShaderBase::kThree_GpuColorType == ge.getColorType()) { // 3 Color Case
- fColorStartUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fColorStartUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision,
"GradientStartColor");
- fColorMidUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fColorMidUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision,
"GradientMidColor");
- fColorEndUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fColorEndUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision,
"GradientEndColor");
} else { // if not a fast case
- fFSYUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fFSYUni = builder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"GradientYCoordFS");
}
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
- GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
if (SkGradientShaderBase::kTwo_GpuColorType == ge.getColorType()){
fsBuilder->codeAppendf("\tvec4 colorTemp = mix(%s, %s, clamp(%s, 0.0, 1.0));\n",
builder->getUniformVariable(fColorStartUni).c_str(),
#if SK_SUPPORT_GPU
#include "GrPaint.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
// For brevity
typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
};
void Edge2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GLEdge2PtConicalEffect::GenKey(*this, caps, b);
}
void GLEdge2PtConicalEffect::emitCode(EmitArgs& args) {
const Edge2PtConicalEffect& ge = args.fFp.cast<Edge2PtConicalEffect>();
this->emitUniforms(args.fBuilder, ge);
- fParamUni = args.fBuilder->addUniformArray(GrGLProgramBuilder::kFragment_Visibility,
+ fParamUni = args.fBuilder->addUniformArray(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"Conical2FSParams", 3);
SkASSERT(args.fCoords[0].getType() == args.fCoords[1].getType());
const char* coords2D;
SkString bVar;
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
if (kVec3f_GrSLType == args.fCoords[0].getType()) {
fsBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy / %s.z, %s.x / %s.z);\n",
args.fCoords[0].c_str(), args.fCoords[0].c_str(),
};
void FocalOutside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GLFocalOutside2PtConicalEffect::GenKey(*this, caps, b);
}
void GLFocalOutside2PtConicalEffect::emitCode(EmitArgs& args) {
const FocalOutside2PtConicalEffect& ge = args.fFp.cast<FocalOutside2PtConicalEffect>();
this->emitUniforms(args.fBuilder, ge);
- fParamUni = args.fBuilder->addUniformArray(GrGLProgramBuilder::kFragment_Visibility,
+ fParamUni = args.fBuilder->addUniformArray(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"Conical2FSParams", 2);
SkString tName("t");
args.fBuilder->getUniformVariable(fParamUni).appendArrayAccess(1, &p1);
// if we have a vec3 from being in perspective, convert it to a vec2 first
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
const char* coords2D = coords2DString.c_str();
};
void FocalInside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GLFocalInside2PtConicalEffect::GenKey(*this, caps, b);
}
void GLFocalInside2PtConicalEffect::emitCode(EmitArgs& args) {
const FocalInside2PtConicalEffect& ge = args.fFp.cast<FocalInside2PtConicalEffect>();
this->emitUniforms(args.fBuilder, ge);
- fFocalUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType, kDefault_GrSLPrecision,
- "Conical2FSParams");
+ fFocalUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
+ kFloat_GrSLType, kDefault_GrSLPrecision,
+ "Conical2FSParams");
SkString tName("t");
// this is the distance along x-axis from the end center to focal point in
GrGLSLShaderVar focal = args.fBuilder->getUniformVariable(fFocalUni);
// if we have a vec3 from being in perspective, convert it to a vec2 first
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
const char* coords2D = coords2DString.c_str();
};
void CircleInside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GLCircleInside2PtConicalEffect::GenKey(*this, caps, b);
}
void GLCircleInside2PtConicalEffect::emitCode(EmitArgs& args) {
const CircleInside2PtConicalEffect& ge = args.fFp.cast<CircleInside2PtConicalEffect>();
this->emitUniforms(args.fBuilder, ge);
- fCenterUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kVec2f_GrSLType, kDefault_GrSLPrecision,
- "Conical2FSCenter");
- fParamUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kVec3f_GrSLType, kDefault_GrSLPrecision,
- "Conical2FSParams");
+ fCenterUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
+ kVec2f_GrSLType, kDefault_GrSLPrecision,
+ "Conical2FSCenter");
+ fParamUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
+ kVec3f_GrSLType, kDefault_GrSLPrecision,
+ "Conical2FSParams");
SkString tName("t");
GrGLSLShaderVar center = args.fBuilder->getUniformVariable(fCenterUni);
GrGLSLShaderVar params = args.fBuilder->getUniformVariable(fParamUni);
// if we have a vec3 from being in perspective, convert it to a vec2 first
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
const char* coords2D = coords2DString.c_str();
};
void CircleOutside2PtConicalEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GLCircleOutside2PtConicalEffect::GenKey(*this, caps, b);
}
void GLCircleOutside2PtConicalEffect::emitCode(EmitArgs& args) {
const CircleOutside2PtConicalEffect& ge = args.fFp.cast<CircleOutside2PtConicalEffect>();
this->emitUniforms(args.fBuilder, ge);
- fCenterUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kVec2f_GrSLType, kDefault_GrSLPrecision,
- "Conical2FSCenter");
- fParamUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kVec4f_GrSLType, kDefault_GrSLPrecision,
- "Conical2FSParams");
+ fCenterUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
+ kVec2f_GrSLType, kDefault_GrSLPrecision,
+ "Conical2FSCenter");
+ fParamUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
+ kVec4f_GrSLType, kDefault_GrSLPrecision,
+ "Conical2FSParams");
SkString tName("t");
GrGLSLShaderVar center = args.fBuilder->getUniformVariable(fCenterUni);
GrGLSLShaderVar params = args.fBuilder->getUniformVariable(fParamUni);
// if we have a vec3 from being in perspective, convert it to a vec2 first
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkString coords2DString = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
const char* coords2D = coords2DString.c_str();
#include "GrInvariantOutput.h"
#include "gl/GrGLGeometryProcessor.h"
#include "gl/GrGLUtil.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
+#include "glsl/GrGLSLVertexShaderBuilder.h"
/*
* The default Geometry Processor simply takes position and multiplies it by the uniform view
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>();
GrGLSLGPBuilder* pb = args.fPB;
- GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
- GrGLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
+ GrGLSLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder();
// emit attributes
vsBuilder->emitAttributes(gp);
fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage);
} else {
const char* fragCoverage;
- fCoverageUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fCoverageUniform = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType,
kDefault_GrSLPrecision,
"Coverage",
#include "GrFragmentProcessor.h"
#include "GrCoordTransform.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
#include "effects/GrConstColorProcessor.h"
#include "effects/GrXfermodeFragmentProcessor.h"
GLFP() {}
void emitCode(EmitArgs& args) override {
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
this->emitChild(0, nullptr, args);
fsBuilder->codeAppendf("%s.rgb *= %s.rgb;", args.fOutputColor,
args.fInputColor);
GLFP() : fHaveSetColor(false) {}
void emitCode(EmitArgs& args) override {
const char* colorName;
- fColorUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fColorUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision,
"Color", &colorName);
this->emitChild(0, colorName, args);
#include "effects/GrRRectEffect.h"
#include "gl/GrGLUtil.h"
#include "gl/GrGLGeometryProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLVertexShaderBuilder.h"
// TODO(joshualitt) - Break this file up during GrBatch post implementation cleanup
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
const CircleEdgeEffect& ce = args.fGP.cast<CircleEdgeEffect>();
GrGLSLGPBuilder* pb = args.fPB;
- GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
// emit attributes
vsBuilder->emitAttributes(ce);
this->emitTransforms(args.fPB, gpArgs->fPositionVar, ce.inPosition()->fName,
ce.localMatrix(), args.fTransformsIn, args.fTransformsOut);
- GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
fsBuilder->codeAppendf("float d = length(%s.xy);", v.fsIn());
fsBuilder->codeAppendf("float edgeAlpha = clamp(%s.z * (1.0 - d), 0.0, 1.0);", v.fsIn());
if (ce.isStroked()) {
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
const EllipseEdgeEffect& ee = args.fGP.cast<EllipseEdgeEffect>();
GrGLSLGPBuilder* pb = args.fPB;
- GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
// emit attributes
vsBuilder->emitAttributes(ee);
ee.localMatrix(), args.fTransformsIn, args.fTransformsOut);
// for outer curve
- GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
fsBuilder->codeAppendf("vec2 scaledOffset = %s*%s.xy;", ellipseOffsets.fsIn(),
ellipseRadii.fsIn());
fsBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset) - 1.0;");
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const DIEllipseEdgeEffect& ee = args.fGP.cast<DIEllipseEdgeEffect>();
GrGLSLGPBuilder* pb = args.fPB;
- GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
// emit attributes
vsBuilder->emitAttributes(ee);
this->emitTransforms(args.fPB, gpArgs->fPositionVar, ee.inPosition()->fName,
args.fTransformsIn, args.fTransformsOut);
- GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
SkAssertResult(fsBuilder->enableFeature(
- GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
+ GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
// for outer curve
fsBuilder->codeAppendf("vec2 scaledOffset = %s.xy;", offsets0.fsIn());
fsBuilder->codeAppend("float test = dot(scaledOffset, scaledOffset) - 1.0;");
#include "gl/GrGLGpu.h"
#include "glsl/GrGLSLCaps.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLProcessorTypes.h"
+#include "glsl/GrGLSLProgramBuilder.h"
class GrGLPathProcessor : public GrGLPrimitiveProcessor {
public:
void emitCode(EmitArgs& args) override {
GrGLSLGPBuilder* pb = args.fPB;
- GrGLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder();
const GrPathProcessor& pathProc = args.fGP.cast<GrPathProcessor>();
// emit transforms
// Setup uniform color
if (pathProc.opts().readsColor()) {
const char* stagedLocalVarName;
- fColorUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fColorUniform = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType,
kDefault_GrSLPrecision,
"Color",
#include "SkTraceEvent.h"
#include "batches/GrVertexBatch.h"
#include "gl/GrGLGeometryProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
GrAAConvexPathRenderer::GrAAConvexPathRenderer() {
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const QuadEdgeEffect& qe = args.fGP.cast<QuadEdgeEffect>();
GrGLSLGPBuilder* pb = args.fPB;
- GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
// emit attributes
vsBuilder->emitAttributes(qe);
this->emitTransforms(args.fPB, gpArgs->fPositionVar, qe.inPosition()->fName,
qe.localMatrix(), args.fTransformsIn, args.fTransformsOut);
- GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
SkAssertResult(fsBuilder->enableFeature(
- GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
+ GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
fsBuilder->codeAppendf("float edgeAlpha;");
// keep the derivative instructions outside the conditional
#include "gl/GrGLFragmentProcessor.h"
#include "gl/GrGLGeometryProcessor.h"
#include "gl/GrGLUtil.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
class GrGLConicEffect : public GrGLGeometryProcessor {
void GrGLConicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
GrGLSLGPBuilder* pb = args.fPB;
- GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
const GrConicEffect& gp = args.fGP.cast<GrConicEffect>();
// emit attributes
this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName, gp.localMatrix(),
args.fTransformsIn, args.fTransformsOut);
- GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
fsBuilder->codeAppend("float edgeAlpha;");
switch (fEdgeType) {
case kHairlineAA_GrProcessorEdgeType: {
SkAssertResult(fsBuilder->enableFeature(
- GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
+ GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
fsBuilder->codeAppendf("vec3 dklmdx = dFdx(%s.xyz);", v.fsIn());
fsBuilder->codeAppendf("vec3 dklmdy = dFdy(%s.xyz);", v.fsIn());
fsBuilder->codeAppendf("float dfdx ="
}
case kFillAA_GrProcessorEdgeType: {
SkAssertResult(fsBuilder->enableFeature(
- GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
+ GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
fsBuilder->codeAppendf("vec3 dklmdx = dFdx(%s.xyz);", v.fsIn());
fsBuilder->codeAppendf("vec3 dklmdy = dFdy(%s.xyz);", v.fsIn());
fsBuilder->codeAppendf("float dfdx ="
// TODO should we really be doing this?
if (gp.coverageScale() != 0xff) {
const char* coverageScale;
- fCoverageScaleUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fCoverageScaleUniform = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType,
kDefault_GrSLPrecision,
"Coverage",
void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
GrGLSLGPBuilder* pb = args.fPB;
- GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>();
// emit attributes
this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName, gp.localMatrix(),
args.fTransformsIn, args.fTransformsOut);
- GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
fsBuilder->codeAppendf("float edgeAlpha;");
switch (fEdgeType) {
case kHairlineAA_GrProcessorEdgeType: {
SkAssertResult(fsBuilder->enableFeature(
- GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
+ GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
fsBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", v.fsIn());
fsBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", v.fsIn());
fsBuilder->codeAppendf("vec2 gF = vec2(2.0 * %s.x * duvdx.x - duvdx.y,"
}
case kFillAA_GrProcessorEdgeType: {
SkAssertResult(fsBuilder->enableFeature(
- GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
+ GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
fsBuilder->codeAppendf("vec2 duvdx = dFdx(%s.xy);", v.fsIn());
fsBuilder->codeAppendf("vec2 duvdy = dFdy(%s.xy);", v.fsIn());
fsBuilder->codeAppendf("vec2 gF = vec2(2.0 * %s.x * duvdx.x - duvdx.y,"
if (0xff != gp.coverageScale()) {
const char* coverageScale;
- fCoverageScaleUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fCoverageScaleUniform = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType,
kDefault_GrSLPrecision,
"Coverage",
}
void GrGLCubicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
- GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>();
// emit attributes
this->emitTransforms(args.fPB, gpArgs->fPositionVar, gp.inPosition()->fName, args.fTransformsIn,
args.fTransformsOut);
- GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
GrGLSLShaderVar edgeAlpha("edgeAlpha", kFloat_GrSLType, 0, kHigh_GrSLPrecision);
GrGLSLShaderVar dklmdx("dklmdx", kVec3f_GrSLType, 0, kHigh_GrSLPrecision);
switch (fEdgeType) {
case kHairlineAA_GrProcessorEdgeType: {
SkAssertResult(fsBuilder->enableFeature(
- GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
+ GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
fsBuilder->codeAppendf("%s = dFdx(%s.xyz);", dklmdx.c_str(), v.fsIn());
fsBuilder->codeAppendf("%s = dFdy(%s.xyz);", dklmdy.c_str(), v.fsIn());
fsBuilder->codeAppendf("%s = 3.0 * %s.x * %s.x * %s.x - %s.y * %s.z - %s.z * %s.y;",
}
case kFillAA_GrProcessorEdgeType: {
SkAssertResult(fsBuilder->enableFeature(
- GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
+ GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
fsBuilder->codeAppendf("%s = dFdx(%s.xyz);", dklmdx.c_str(), v.fsIn());
fsBuilder->codeAppendf("%s = dFdy(%s.xyz);", dklmdy.c_str(), v.fsIn());
fsBuilder->codeAppendf("%s ="
#include "GrBicubicEffect.h"
#include "GrInvariantOutput.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
#define DS(x) SkDoubleToScalar(x)
void GrGLBicubicEffect::emitCode(EmitArgs& args) {
const GrTextureDomain& domain = args.fFp.cast<GrBicubicEffect>().domain();
- fCoefficientsUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fCoefficientsUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kMat44f_GrSLType, kDefault_GrSLPrecision,
"Coefficients");
- fImageIncrementUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fImageIncrementUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"ImageIncrement");
GrGLSLShaderVar("c2", kVec4f_GrSLType),
GrGLSLShaderVar("c3", kVec4f_GrSLType),
};
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
fsBuilder->emitFunction(kVec4f_GrSLType,
"cubicBlend",
#include "gl/GrGLFragmentProcessor.h"
#include "gl/GrGLTexture.h"
#include "gl/GrGLGeometryProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLVertexShaderBuilder.h"
class GrGLBitmapTextGeoProc : public GrGLGeometryProcessor {
public:
const GrBitmapTextGeoProc& cte = args.fGP.cast<GrBitmapTextGeoProc>();
GrGLSLGPBuilder* pb = args.fPB;
- GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
// emit attributes
vsBuilder->emitAttributes(cte);
this->emitTransforms(args.fPB, gpArgs->fPositionVar, cte.inPosition()->fName,
cte.localMatrix(), args.fTransformsIn, args.fTransformsOut);
- GrGLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
if (cte.maskFormat() == kARGB_GrMaskFormat) {
fsBuilder->codeAppendf("%s = ", args.fOutputColor);
fsBuilder->appendTextureLookupAndModulate(args.fOutputColor,
#include "GrSimpleTextureEffect.h"
#include "SkMatrix.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
class GrGLConfigConversionEffect : public GrGLFragmentProcessor {
public:
SkString tmpDecl;
tmpVar.appendDecl(args.fBuilder->glslCaps(), &tmpDecl);
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
fsBuilder->codeAppendf("%s;", tmpDecl.c_str());
///////////////////////////////////////////////////////////////////////////////
void GrConfigConversionEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GrGLConfigConversionEffect::GenKey(*this, caps, b);
}
#include "effects/GrConstColorProcessor.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
class GLConstColorProcessor : public GrGLFragmentProcessor {
GLConstColorProcessor() : fPrevColor(GrColor_ILLEGAL) {}
void emitCode(EmitArgs& args) override {
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
const char* colorUni;
- fColorUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fColorUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, kMedium_GrSLPrecision, "constantColor",
&colorUni);
GrConstColorProcessor::InputMode mode = args.fFp.cast<GrConstColorProcessor>().inputMode();
#include "SkPathPriv.h"
#include "gl/GrGLContext.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
//////////////////////////////////////////////////////////////////////////////
const char *rectName;
// The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bottom - 0.5),
// respectively.
- fRectUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fRectUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType,
kDefault_GrSLPrecision,
"rect",
&rectName);
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
const char* fragmentPos = fsBuilder->fragmentPosition();
if (GrProcessorEdgeTypeIsAA(aare.getEdgeType())) {
// The amount of coverage removed in x and y by the edges is computed as a pair of negative
const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>();
const char *edgeArrayName;
- fEdgeUniform = args.fBuilder->addUniformArray(GrGLProgramBuilder::kFragment_Visibility,
+ fEdgeUniform = args.fBuilder->addUniformArray(GrGLSLProgramBuilder::kFragment_Visibility,
kVec3f_GrSLType,
kDefault_GrSLPrecision,
"edges",
cpe.getEdgeCount(),
&edgeArrayName);
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
fsBuilder->codeAppend("\t\tfloat alpha = 1.0;\n");
fsBuilder->codeAppend("\t\tfloat edge;\n");
const char* fragmentPos = fsBuilder->fragmentPosition();
}
void GrConvexPolyEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GrGLConvexPolyEffect::GenKey(*this, caps, b);
}
#include "GrConvolutionEffect.h"
#include "gl/GrGLFragmentProcessor.h"
#include "gl/GrGLTexture.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
// For brevity
}
void GrGLConvolutionEffect::emitCode(EmitArgs& args) {
- fImageIncrementUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fImageIncrementUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"ImageIncrement");
if (this->useBounds()) {
- fBoundsUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fBoundsUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"Bounds");
}
- fKernelUni = args.fBuilder->addUniformArray(GrGLProgramBuilder::kFragment_Visibility,
+ fKernelUni = args.fBuilder->addUniformArray(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"Kernel", this->width());
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
fsBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", args.fOutputColor);
#include "GrProcessor.h"
#include "GrProcOptInfo.h"
#include "gl/GrGLXferProcessor.h"
-#include "gl/builders/GrGLFragmentShaderBuilder.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
class CoverageSetOpXP : public GrXferProcessor {
public:
private:
void emitOutputsForBlendState(const EmitArgs& args) override {
const CoverageSetOpXP& xp = args.fXP.cast<CoverageSetOpXP>();
- GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
+ GrGLSLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
if (xp.invertCoverage()) {
fsBuilder->codeAppendf("%s = 1.0 - %s;", args.fOutputPrimary, args.fInputCoverage);
#include "gl/GrGLSLBlend.h"
#include "gl/GrGLFragmentProcessor.h"
#include "gl/GrGLProgramDataManager.h"
-#include "gl/builders/GrGLProgramBuilder.h"
#include "glsl/GrGLSLCaps.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
bool GrCustomXfermode::IsSupportedMode(SkXfermode::Mode mode) {
const CustomXP& xp = args.fXP.cast<CustomXP>();
SkASSERT(xp.hasHWBlendEquation());
- GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
+ GrGLSLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
fsBuilder->enableAdvancedBlendEquationIfNeeded(xp.hwBlendEquation());
// Apply coverage by multiplying it into the src color before blending. Mixed samples will
const CustomXP& xp = proc.cast<CustomXP>();
SkASSERT(!xp.hasHWBlendEquation());
- GrGLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
+ GrGLSLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
GrGLSLBlend::AppendMode(fsBuilder, srcColor, dstColor, outColor, xp.mode());
}
#include "batches/GrVertexBatch.h"
#include "gl/GrGLGeometryProcessor.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLVertexShaderBuilder.h"
///////////////////////////////////////////////////////////////////////////////
void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>();
GrGLSLGPBuilder* pb = args.fPB;
- GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
// emit attributes
vsBuilder->emitAttributes(dce);
args.fTransformsIn, args.fTransformsOut);
// transforms all points so that we can compare them to our test circle
- GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
fsBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;",
dashParams.fsIn(), dashParams.fsIn(), dashParams.fsIn(),
dashParams.fsIn());
const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>();
GrGLSLGPBuilder* pb = args.fPB;
- GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
// emit attributes
vsBuilder->emitAttributes(de);
args.fTransformsIn, args.fTransformsOut);
// transforms all points so that we can compare them to our test rect
- GrGLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
fsBuilder->codeAppendf("float xShifted = %s.x - floor(%s.x / %s.z) * %s.z;",
inDashParams.fsIn(), inDashParams.fsIn(), inDashParams.fsIn(),
inDashParams.fsIn());
#include "effects/GrDisableColorXP.h"
#include "GrProcessor.h"
#include "gl/GrGLXferProcessor.h"
-#include "gl/builders/GrGLFragmentShaderBuilder.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
/**
// This emit code should be empty. However, on the nexus 6 there is a driver bug where if
// you do not give gl_FragColor a value, the gl context is lost and we end up drawing
// nothing. So this fix just sets the gl_FragColor arbitrarily to 0.
- GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
+ GrGLSLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
fsBuilder->codeAppendf("%s = vec4(0);", args.fOutputPrimary);
}
#include "gl/GrGLFragmentProcessor.h"
#include "gl/GrGLTexture.h"
#include "gl/GrGLGeometryProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLVertexShaderBuilder.h"
// Assuming a radius of a little less than the diagonal of the fragment
#define SK_DistanceFieldAAFactor "0.65"
const GrDistanceFieldA8TextGeoProc& dfTexEffect =
args.fGP.cast<GrDistanceFieldA8TextGeoProc>();
GrGLSLGPBuilder* pb = args.fPB;
- GrGLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
SkAssertResult(fsBuilder->enableFeature(
- GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
+ GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
- GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
// emit attributes
vsBuilder->emitAttributes(dfTexEffect);
// adjust based on gamma
const char* distanceAdjustUniName = nullptr;
// width, height, 1/(3*width)
- fDistanceAdjustUni = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fDistanceAdjustUni = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kFloat_GrSLType, kDefault_GrSLPrecision,
"DistanceAdjust", &distanceAdjustUniName);
#endif
const GrDistanceFieldPathGeoProc& dfTexEffect = args.fGP.cast<GrDistanceFieldPathGeoProc>();
GrGLSLGPBuilder* pb = args.fPB;
- GrGLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
SkAssertResult(fsBuilder->enableFeature(
- GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
+ GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
- GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
// emit attributes
vsBuilder->emitAttributes(dfTexEffect);
args.fTransformsIn, args.fTransformsOut);
const char* textureSizeUniName = nullptr;
- fTextureSizeUni = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fTextureSizeUni = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType, kDefault_GrSLPrecision,
"TextureSize", &textureSizeUniName);
args.fGP.cast<GrDistanceFieldLCDTextGeoProc>();
GrGLSLGPBuilder* pb = args.fPB;
- GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
// emit attributes
vsBuilder->emitAttributes(dfTexEffect);
dfTexEffect.inTextureCoords()->fName);
// add frag shader code
- GrGLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
SkAssertResult(fsBuilder->enableFeature(
- GrGLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
+ GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
// create LCD offset adjusted by inverse of transform
// Use highp to work around aliasing issues
// adjust width based on gamma
const char* distanceAdjustUniName = nullptr;
- fDistanceAdjustUni = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fDistanceAdjustUni = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec3f_GrSLType, kDefault_GrSLPrecision,
"DistanceAdjust", &distanceAdjustUniName);
fsBuilder->codeAppendf("distance -= %s;", distanceAdjustUniName);
#include "GrInvariantOutput.h"
#include "SkRect.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
//////////////////////////////////////////////////////////////////////////////
}
void GLDitherEffect::emitCode(EmitArgs& args) {
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
// Generate a random number based on the fragment position. For this
// random number generator, we use the "GLSL rand" function
// that seems to be floating around on the internet. It works under
//////////////////////////////////////////////////////////////////////////////
void DitherEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GLDitherEffect::GenKey(*this, caps, b);
}
int kWidth = fKernelSize.width();
int kHeight = fKernelSize.height();
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
fsBuilder->codeAppend("vec4 sum = vec4(0, 0, 0, 0);");
fsBuilder->codeAppendf("vec2 coord = %s - %s * %s;", coords2D.c_str(), kernelOffset,
for (int y = 0; y < kHeight; y++) {
for (int x = 0; x < kWidth; x++) {
- GrGLShaderBuilder::ShaderBlock block(fsBuilder);
+ GrGLSLShaderBuilder::ShaderBlock block(fsBuilder);
fsBuilder->codeAppendf("float k = %s[%d * %d + %d];", kernel, y, kWidth, x);
SkString coord;
coord.printf("coord + vec2(%d, %d) * %s", x, y, imgInc);
#include "GrInvariantOutput.h"
#include "SkRect.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
//////////////////////////////////////////////////////////////////////////////
const char *circleName;
// The circle uniform is (center.x, center.y, radius + 0.5, 1 / (radius + 0.5)) for regular
// fills and (..., radius - 0.5, 1 / (radius - 0.5)) for inverse fills.
- fCircleUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fCircleUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision,
"circle",
&circleName);
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
const char* fragmentPos = fsBuilder->fragmentPosition();
SkASSERT(kHairlineAA_GrProcessorEdgeType != ce.getEdgeType());
const char *ellipseName;
// The ellipse uniform is (center.x, center.y, 1 / rx^2, 1 / ry^2)
// The last two terms can underflow on mediump, so we use highp.
- fEllipseUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fEllipseUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, kHigh_GrSLPrecision,
"ellipse",
&ellipseName);
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
const char* fragmentPos = fsBuilder->fragmentPosition();
// d is the offset to the ellipse center
#include "GrXferProcessor.h"
#include "gl/GrGLSLBlend.h"
#include "gl/GrGLXferProcessor.h"
-#include "gl/builders/GrGLFragmentShaderBuilder.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
/**
///////////////////////////////////////////////////////////////////////////////
-static void append_color_output(const PorterDuffXferProcessor& xp, GrGLXPFragmentBuilder* fsBuilder,
+static void append_color_output(const PorterDuffXferProcessor& xp,
+ GrGLSLXPFragmentBuilder* fsBuilder,
BlendFormula::OutputType outputType, const char* output,
const char* inColor, const char* inCoverage) {
switch (outputType) {
private:
void emitOutputsForBlendState(const EmitArgs& args) override {
const PorterDuffXferProcessor& xp = args.fXP.cast<PorterDuffXferProcessor>();
- GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
+ GrGLSLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
BlendFormula blendFormula = xp.getBlendFormula();
if (blendFormula.hasSecondaryOutput()) {
void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb, const char* srcColor, const char* dstColor,
const char* outColor, const GrXferProcessor& proc) override {
const ShaderPDXferProcessor& xp = proc.cast<ShaderPDXferProcessor>();
- GrGLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
+ GrGLSLXPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
GrGLSLBlend::AppendMode(fsBuilder, srcColor, dstColor, outColor, xp.getXfermode());
}
///////////////////////////////////////////////////////////////////////////////
void ShaderPDXferProcessor::onGetGLProcessorKey(const GrGLSLCaps&,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GLShaderPDXferProcessor::GenKey(*this, b);
}
private:
void emitOutputsForBlendState(const EmitArgs& args) override {
- GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
+ GrGLSLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
fsBuilder->codeAppendf("%s = %s * %s;", args.fOutputPrimary, args.fInputColor,
args.fInputCoverage);
}
#include "GrOvalEffect.h"
#include "SkRRect.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
// The effects defined here only handle rrect radii >= kRadiusMin.
// edges correspond to components x, y, z, and w, respectively. When a side of the rrect has
// only rectangular corners, that side's value corresponds to the rect edge's value outset by
// half a pixel.
- fInnerRectUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kVec4f_GrSLType, kDefault_GrSLPrecision,
- "innerRect",
- &rectName);
- fRadiusPlusHalfUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType, kDefault_GrSLPrecision,
- "radiusPlusHalf",
- &radiusPlusHalfName);
-
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ fInnerRectUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
+ kVec4f_GrSLType, kDefault_GrSLPrecision,
+ "innerRect",
+ &rectName);
+ fRadiusPlusHalfUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
+ kFloat_GrSLType, kDefault_GrSLPrecision,
+ "radiusPlusHalf",
+ &radiusPlusHalfName);
+
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
const char* fragmentPos = fsBuilder->fragmentPosition();
// At each quarter-circle corner we compute a vector that is the offset of the fragment position
// from the circle center. The vector is pinned in x and y to be in the quarter-plane relevant
////////////////////////////////////////////////////////////////////////////////////////////////////
void CircularRRectEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GLCircularRRectEffect::GenKey(*this, caps, b);
}
const EllipticalRRectEffect& erre = args.fFp.cast<EllipticalRRectEffect>();
const char *rectName;
// The inner rect is the rrect bounds inset by the x/y radii
- fInnerRectUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fInnerRectUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType, kDefault_GrSLPrecision,
"innerRect",
&rectName);
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
const char* fragmentPos = fsBuilder->fragmentPosition();
// At each quarter-ellipse corner we compute a vector that is the offset of the fragment pos
// to the ellipse center. The vector is pinned in x and y to be in the quarter-plane relevant
switch (erre.getRRect().getType()) {
case SkRRect::kSimple_Type: {
const char *invRadiiXYSqdName;
- fInvRadiiSqdUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kVec2f_GrSLType, kHigh_GrSLPrecision,
- "invRadiiXY",
- &invRadiiXYSqdName);
+ fInvRadiiSqdUniform = args.fBuilder->addUniform(
+ GrGLSLProgramBuilder::kFragment_Visibility,
+ kVec2f_GrSLType, kHigh_GrSLPrecision,
+ "invRadiiXY",
+ &invRadiiXYSqdName);
fsBuilder->codeAppend("\t\tvec2 dxy = max(max(dxy0, dxy1), 0.0);\n");
// Z is the x/y offsets divided by squared radii.
fsBuilder->codeAppendf("\t\tvec2 Z = dxy * %s;\n", invRadiiXYSqdName);
}
case SkRRect::kNinePatch_Type: {
const char *invRadiiLTRBSqdName;
- fInvRadiiSqdUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kVec4f_GrSLType, kHigh_GrSLPrecision,
- "invRadiiLTRB",
- &invRadiiLTRBSqdName);
+ fInvRadiiSqdUniform = args.fBuilder->addUniform(
+ GrGLSLProgramBuilder::kFragment_Visibility,
+ kVec4f_GrSLType, kHigh_GrSLPrecision,
+ "invRadiiLTRB",
+ &invRadiiLTRBSqdName);
fsBuilder->codeAppend("\t\tvec2 dxy = max(max(dxy0, dxy1), 0.0);\n");
// Z is the x/y offsets divided by squared radii. We only care about the (at most) one
// corner where both the x and y offsets are positive, hence the maxes. (The inverse
////////////////////////////////////////////////////////////////////////////////////////////////////
void EllipticalRRectEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GLEllipticalRRectEffect::GenKey(*this, caps, b);
}
#include "gl/GrGLCaps.h"
#include "gl/GrGLFragmentProcessor.h"
#include "gl/GrGLTexture.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
class GrGLSimpleTextureEffect : public GrGLFragmentProcessor {
public:
GrGLSimpleTextureEffect(const GrProcessor&) {}
virtual void emitCode(EmitArgs& args) override {
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
fsBuilder->codeAppendf("\t%s = ", args.fOutputColor);
fsBuilder->appendTextureLookupAndModulate(args.fInputColor,
args.fSamplers[0],
}
void GrSimpleTextureEffect::onGetGLProcessorKey(const GrGLSLCaps& caps,
- GrProcessorKeyBuilder* b) const {
+ GrProcessorKeyBuilder* b) const {
GrGLSimpleTextureEffect::GenKey(*this, caps, b);
}
//////////////////////////////////////////////////////////////////////////////
-void GrTextureDomain::GLDomain::sampleTexture(GrGLShaderBuilder* builder,
+void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
const GrTextureDomain& textureDomain,
const char* outColor,
const SkString& inCoords,
}
case kDecal_Mode: {
// Add a block since we're going to declare variables.
- GrGLShaderBuilder::ShaderBlock block(builder);
+ GrGLSLShaderBuilder::ShaderBlock block(builder);
const char* domain = fDomainName.c_str();
if (!program->glslCaps()->canUseAnyFunctionInShader()) {
const GrTextureDomainEffect& textureDomainEffect = args.fFp.cast<GrTextureDomainEffect>();
const GrTextureDomain& domain = textureDomainEffect.textureDomain();
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
fGLDomain.sampleTexture(fsBuilder, domain, args.fOutputColor, coords2D, args.fSamplers[0],
args.fInputColor);
#include "glsl/GrGLSLProgramDataManager.h"
class GrGLProgramBuilder;
-class GrGLShaderBuilder;
+class GrGLSLShaderBuilder;
class GrInvariantOutput;
class GrGLSLTextureSampler;
struct SkRect;
* @param inModulateColor if non-nullptr the sampled color will be modulated with this
* expression before being written to outColor.
*/
- void sampleTexture(GrGLShaderBuilder* builder,
+ void sampleTexture(GrGLSLShaderBuilder* builder,
const GrTextureDomain& textureDomain,
const char* outColor,
const SkString& inCoords,
#include "effects/GrConstColorProcessor.h"
#include "gl/GrGLFragmentProcessor.h"
#include "gl/GrGLSLBlend.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "SkGrPriv.h"
class ComposeTwoFragmentProcessor : public GrFragmentProcessor {
void GLComposeTwoFragmentProcessor::emitCode(EmitArgs& args) {
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
const ComposeTwoFragmentProcessor& cs = args.fFp.cast<ComposeTwoFragmentProcessor>();
const char* inputColor = nullptr;
GLComposeOneFragmentProcessor(const GrProcessor& processor) {}
void emitCode(EmitArgs& args) override {
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
SkXfermode::Mode mode = args.fFp.cast<ComposeOneFragmentProcessor>().mode();
ComposeOneFragmentProcessor::Child child =
args.fFp.cast<ComposeOneFragmentProcessor>().child();
#include "GrInvariantOutput.h"
#include "GrProcessor.h"
#include "gl/GrGLFragmentProcessor.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
namespace {
GLProcessor(const GrProcessor&) {}
virtual void emitCode(EmitArgs& args) override {
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
const char* yuvMatrix = nullptr;
- fMatrixUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- kMat44f_GrSLType, kDefault_GrSLPrecision,
- "YUVMatrix", &yuvMatrix);
+ fMatrixUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
+ kMat44f_GrSLType, kDefault_GrSLPrecision,
+ "YUVMatrix", &yuvMatrix);
fsBuilder->codeAppendf("\t%s = vec4(\n\t\t", args.fOutputColor);
fsBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str(),
args.fCoords[0].getType());
#include "GrGLFragmentProcessor.h"
#include "GrFragmentProcessor.h"
#include "GrProcessor.h"
-#include "builders/GrGLFragmentShaderBuilder.h"
-#include "builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
void GrGLFragmentProcessor::setData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& processor) {
SkString* outputColor, EmitArgs& args) {
SkASSERT(outputColor);
- GrGLFragmentBuilder* fb = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fb = args.fBuilder->getFragmentShaderBuilder();
outputColor->append(fb->getMangleString());
fb->codeAppendf("vec4 %s;", outputColor->c_str());
this->internalEmitChild(childIndex, inputColor, outputColor->c_str(), args);
void GrGLFragmentProcessor::internalEmitChild(int childIndex, const char* inputColor,
const char* outputColor, EmitArgs& args) {
- GrGLFragmentBuilder* fb = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fb = args.fBuilder->getFragmentShaderBuilder();
fb->onBeforeChildProcEmitCode(); // call first so mangleString is updated
#include "GrGLGeometryProcessor.h"
-#include "builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLProcessorTypes.h"
+#include "glsl/GrGLSLProgramBuilder.h"
+#include "glsl/GrGLSLVertexShaderBuilder.h"
void GrGLGeometryProcessor::emitCode(EmitArgs& args) {
- GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
GrGPArgs gpArgs;
this->onEmitCode(args, &gpArgs);
vsBuilder->transformToNormalizedDeviceSpace(gpArgs.fPositionVar);
const SkMatrix& localMatrix,
const TransformsIn& tin,
TransformsOut* tout) {
- GrGLVertexBuilder* vb = pb->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vb = pb->getVertexShaderBuilder();
tout->push_back_n(tin.count());
fInstalledTransforms.push_back_n(tin.count());
for (int i = 0; i < tin.count(); i++) {
const char* uniName;
fInstalledTransforms[i][t].fHandle =
- pb->addUniform(GrGLProgramBuilder::kVertex_Visibility,
+ pb->addUniform(GrGLSLProgramBuilder::kVertex_Visibility,
kMat33f_GrSLType, precision,
strUniName.c_str(),
&uniName).toIndex();
const char* localCoords,
const TransformsIn& tin,
TransformsOut* tout) {
- GrGLVertexBuilder* vb = pb->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vb = pb->getVertexShaderBuilder();
tout->push_back_n(tin.count());
for (int i = 0; i < tin.count(); i++) {
const ProcCoords& coordTransforms = tin[i];
void GrGLGeometryProcessor::setupPosition(GrGLSLGPBuilder* pb,
GrGPArgs* gpArgs,
const char* posName) {
- GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2");
vsBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), posName);
}
const char* posName,
const SkMatrix& mat,
UniformHandle* viewMatrixUniform) {
- GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
+ GrGLSLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
if (mat.isIdentity()) {
gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2");
vsBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), posName);
} else {
const char* viewMatrixName;
- *viewMatrixUniform = pb->addUniform(GrGLProgramBuilder::kVertex_Visibility,
+ *viewMatrixUniform = pb->addUniform(GrGLSLProgramBuilder::kVertex_Visibility,
kMat33f_GrSLType, kHigh_GrSLPrecision,
"uViewM",
&viewMatrixName);
#include "GrGLPrimitiveProcessor.h"
-#include "builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
SkMatrix GrGLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatrix,
const GrCoordTransform& coordTransform) {
void GrGLPrimitiveProcessor::setupUniformColor(GrGLSLGPBuilder* pb,
const char* outputName,
UniformHandle* colorUniform) {
- GrGLFragmentBuilder* fs = pb->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fs = pb->getFragmentShaderBuilder();
SkASSERT(colorUniform);
const char* stagedLocalVarName;
- *colorUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ *colorUniform = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec4f_GrSLType,
kDefault_GrSLPrecision,
"Color",
#include "GrGLGpu.h"
#include "GrPipeline.h"
#include "SkChecksum.h"
-#include "gl/builders/GrGLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
/**
* Do we need to either map r,g,b->a or a->r. configComponentMask indicates which channels are
if (pipeline.readsFragPosition()) {
header->fFragPosKey =
- GrGLFragmentShaderBuilder::KeyForFragmentPosition(pipeline.getRenderTarget());
+ GrGLSLFragmentShaderBuilder::KeyForFragmentPosition(pipeline.getRenderTarget());
} else {
header->fFragPosKey = 0;
}
* found in the LICENSE file.
*/
#include "GrGLSLBlend.h"
-#include "gl/builders/GrGLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
//////////////////////////////////////////////////////////////////////////////
// Advanced (non-coeff) blend helpers
//////////////////////////////////////////////////////////////////////////////
-static void hard_light(GrGLFragmentBuilder* fsBuilder,
+static void hard_light(GrGLSLFragmentBuilder* fsBuilder,
const char* final,
const char* src,
const char* dst) {
}
// Does one component of color-dodge
-static void color_dodge_component(GrGLFragmentBuilder* fsBuilder,
+static void color_dodge_component(GrGLSLFragmentBuilder* fsBuilder,
const char* final,
const char* src,
const char* dst,
}
// Does one component of color-burn
-static void color_burn_component(GrGLFragmentBuilder* fsBuilder,
+static void color_burn_component(GrGLSLFragmentBuilder* fsBuilder,
const char* final,
const char* src,
const char* dst,
}
// Does one component of soft-light. Caller should have already checked that dst alpha > 0.
-static void soft_light_component_pos_dst_alpha(GrGLFragmentBuilder* fsBuilder,
+static void soft_light_component_pos_dst_alpha(GrGLSLFragmentBuilder* fsBuilder,
const char* final,
const char* src,
const char* dst,
// hue and saturation of the first color, the luminosity of the second color, and the input
// alpha. It has this signature:
// vec3 set_luminance(vec3 hueSatColor, float alpha, vec3 lumColor).
-static void add_lum_function(GrGLFragmentBuilder* fsBuilder, SkString* setLumFunction) {
+static void add_lum_function(GrGLSLFragmentBuilder* fsBuilder, SkString* setLumFunction) {
// Emit a helper that gets the luminance of a color.
SkString getFunction;
GrGLSLShaderVar getLumArgs[] = {
// Adds a function that creates a color with the hue and luminosity of one input color and
// the saturation of another color. It will have this signature:
// float set_saturation(vec3 hueLumColor, vec3 satColor)
-static void add_sat_function(GrGLFragmentBuilder* fsBuilder, SkString* setSatFunction) {
+static void add_sat_function(GrGLSLFragmentBuilder* fsBuilder, SkString* setSatFunction) {
// Emit a helper that gets the saturation of a color
SkString getFunction;
GrGLSLShaderVar getSatArgs[] = { GrGLSLShaderVar("color", kVec3f_GrSLType) };
setSatFunction);
}
-static void emit_advanced_xfermode_code(GrGLFragmentBuilder* fsBuilder, const char* srcColor,
+static void emit_advanced_xfermode_code(GrGLSLFragmentBuilder* fsBuilder, const char* srcColor,
const char* dstColor, const char* outputColor,
SkXfermode::Mode mode) {
SkASSERT(srcColor);
// Porter-Duff blend helper
//////////////////////////////////////////////////////////////////////////////
-static bool append_porterduff_term(GrGLFragmentBuilder* fsBuilder, SkXfermode::Coeff coeff,
+static bool append_porterduff_term(GrGLSLFragmentBuilder* fsBuilder, SkXfermode::Coeff coeff,
const char* colorName, const char* srcColorName,
const char* dstColorName, bool hasPrevious) {
if (SkXfermode::kZero_Coeff == coeff) {
//////////////////////////////////////////////////////////////////////////////
-void GrGLSLBlend::AppendMode(GrGLFragmentBuilder* fsBuilder, const char* srcColor,
+void GrGLSLBlend::AppendMode(GrGLSLFragmentBuilder* fsBuilder, const char* srcColor,
const char* dstColor, const char* outColor,
SkXfermode::Mode mode) {
#include "SkXfermode.h"
-class GrGLFragmentBuilder;
+class GrGLSLFragmentBuilder;
namespace GrGLSLBlend {
/*
* Appends GLSL code to fsBuilder that assigns a specified blend of the srcColor and dstColor
* variables to the outColor variable.
*/
- void AppendMode(GrGLFragmentBuilder* fsBuilder, const char* srcColor,
+ void AppendMode(GrGLSLFragmentBuilder* fsBuilder, const char* srcColor,
const char* dstColor, const char* outColor, SkXfermode::Mode mode);
};
#include "gl/GrGLXferProcessor.h"
#include "GrXferProcessor.h"
-#include "gl/builders/GrGLFragmentShaderBuilder.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
void GrGLXferProcessor::emitCode(const EmitArgs& args) {
return;
}
- GrGLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
+ GrGLSLXPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
const char* dstColor = fsBuilder->dstColor();
if (args.fXP.getDstTexture()) {
const char* dstTopLeftName;
const char* dstCoordScaleName;
- fDstTopLeftUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fDstTopLeftUni = args.fPB->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType,
kDefault_GrSLPrecision,
"DstTextureUpperLeft",
&dstTopLeftName);
- fDstScaleUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility,
+ fDstScaleUni = args.fPB->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
kVec2f_GrSLType,
kDefault_GrSLPrecision,
"DstTextureCoordScale",
+++ /dev/null
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "GrGLFragmentShaderBuilder.h"
-#include "GrRenderTarget.h"
-#include "glsl/GrGLSL.h"
-#include "glsl/GrGLSLCaps.h"
-#include "glsl/GrGLSLProgramBuilder.h"
-
-const char* GrGLFragmentShaderBuilder::kDstTextureColorName = "_dstColor";
-
-static const char* specific_layout_qualifier_name(GrBlendEquation equation) {
- SkASSERT(GrBlendEquationIsAdvanced(equation));
-
- static const char* kLayoutQualifierNames[] = {
- "blend_support_screen",
- "blend_support_overlay",
- "blend_support_darken",
- "blend_support_lighten",
- "blend_support_colordodge",
- "blend_support_colorburn",
- "blend_support_hardlight",
- "blend_support_softlight",
- "blend_support_difference",
- "blend_support_exclusion",
- "blend_support_multiply",
- "blend_support_hsl_hue",
- "blend_support_hsl_saturation",
- "blend_support_hsl_color",
- "blend_support_hsl_luminosity"
- };
- return kLayoutQualifierNames[equation - kFirstAdvancedGrBlendEquation];
-
- GR_STATIC_ASSERT(0 == kScreen_GrBlendEquation - kFirstAdvancedGrBlendEquation);
- GR_STATIC_ASSERT(1 == kOverlay_GrBlendEquation - kFirstAdvancedGrBlendEquation);
- GR_STATIC_ASSERT(2 == kDarken_GrBlendEquation - kFirstAdvancedGrBlendEquation);
- GR_STATIC_ASSERT(3 == kLighten_GrBlendEquation - kFirstAdvancedGrBlendEquation);
- GR_STATIC_ASSERT(4 == kColorDodge_GrBlendEquation - kFirstAdvancedGrBlendEquation);
- GR_STATIC_ASSERT(5 == kColorBurn_GrBlendEquation - kFirstAdvancedGrBlendEquation);
- GR_STATIC_ASSERT(6 == kHardLight_GrBlendEquation - kFirstAdvancedGrBlendEquation);
- GR_STATIC_ASSERT(7 == kSoftLight_GrBlendEquation - kFirstAdvancedGrBlendEquation);
- GR_STATIC_ASSERT(8 == kDifference_GrBlendEquation - kFirstAdvancedGrBlendEquation);
- GR_STATIC_ASSERT(9 == kExclusion_GrBlendEquation - kFirstAdvancedGrBlendEquation);
- GR_STATIC_ASSERT(10 == kMultiply_GrBlendEquation - kFirstAdvancedGrBlendEquation);
- GR_STATIC_ASSERT(11 == kHSLHue_GrBlendEquation - kFirstAdvancedGrBlendEquation);
- GR_STATIC_ASSERT(12 == kHSLSaturation_GrBlendEquation - kFirstAdvancedGrBlendEquation);
- GR_STATIC_ASSERT(13 == kHSLColor_GrBlendEquation - kFirstAdvancedGrBlendEquation);
- GR_STATIC_ASSERT(14 == kHSLLuminosity_GrBlendEquation - kFirstAdvancedGrBlendEquation);
- GR_STATIC_ASSERT(SK_ARRAY_COUNT(kLayoutQualifierNames) ==
- kGrBlendEquationCnt - kFirstAdvancedGrBlendEquation);
-}
-
-GrGLFragmentShaderBuilder::FragPosKey
-GrGLFragmentShaderBuilder::KeyForFragmentPosition(const GrRenderTarget* dst) {
- if (kTopLeft_GrSurfaceOrigin == dst->origin()) {
- return kTopLeftFragPosRead_FragPosKey;
- } else {
- return kBottomLeftFragPosRead_FragPosKey;
- }
-}
-
-GrGLFragmentShaderBuilder::GrGLFragmentShaderBuilder(GrGLSLProgramBuilder* program,
- uint8_t fragPosKey)
- : INHERITED(program)
- , fSetupFragPosition(false)
- , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == fragPosKey)
- , fCustomColorOutputIndex(-1)
- , fHasReadDstColor(false)
- , fHasReadFragmentPosition(false) {
-}
-
-bool GrGLFragmentShaderBuilder::enableFeature(GLSLFeature feature) {
- switch (feature) {
- case kStandardDerivatives_GLSLFeature: {
- if (!fProgramBuilder->glslCaps()->shaderDerivativeSupport()) {
- return false;
- }
- const char* extension = fProgramBuilder->glslCaps()->shaderDerivativeExtensionString();
- if (extension) {
- this->addFeature(1 << kStandardDerivatives_GLSLFeature, extension);
- }
- return true;
- }
- default:
- SkFAIL("Unexpected GLSLFeature requested.");
- return false;
- }
-}
-
-SkString GrGLFragmentShaderBuilder::ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords,
- int index) {
- if (kVec3f_GrSLType != coords[index].getType()) {
- SkASSERT(kVec2f_GrSLType == coords[index].getType());
- return coords[index].getName();
- }
-
- SkString coords2D("coords2D");
- if (0 != index) {
- coords2D.appendf("_%i", index);
- }
- this->codeAppendf("\tvec2 %s = %s.xy / %s.z;",
- coords2D.c_str(), coords[index].c_str(), coords[index].c_str());
- return coords2D;
-}
-
-const char* GrGLFragmentShaderBuilder::fragmentPosition() {
- fHasReadFragmentPosition = true;
-
- const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps();
- // We only declare "gl_FragCoord" when we're in the case where we want to use layout qualifiers
- // to reverse y. Otherwise it isn't necessary and whether the "in" qualifier appears in the
- // declaration varies in earlier GLSL specs. So it is simpler to omit it.
- if (fTopLeftFragPosRead) {
- fSetupFragPosition = true;
- return "gl_FragCoord";
- } else if (const char* extension = glslCaps->fragCoordConventionsExtensionString()) {
- if (!fSetupFragPosition) {
- if (glslCaps->generation() < k150_GrGLSLGeneration) {
- this->addFeature(1 << kFragCoordConventions_GLSLPrivateFeature,
- extension);
- }
- fInputs.push_back().set(kVec4f_GrSLType,
- GrGLSLShaderVar::kIn_TypeModifier,
- "gl_FragCoord",
- kDefault_GrSLPrecision,
- GrGLSLShaderVar::kUpperLeft_Origin);
- fSetupFragPosition = true;
- }
- return "gl_FragCoord";
- } else {
- static const char* kTempName = "tmpXYFragCoord";
- static const char* kCoordName = "fragCoordYDown";
- if (!fSetupFragPosition) {
- SkASSERT(!fProgramBuilder->fUniformHandles.fRTHeightUni.isValid());
- const char* rtHeightName;
-
- fProgramBuilder->fUniformHandles.fRTHeightUni =
- fProgramBuilder->addFragPosUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType,
- kDefault_GrSLPrecision,
- "RTHeight",
- &rtHeightName);
-
- // The Adreno compiler seems to be very touchy about access to "gl_FragCoord".
- // Accessing glFragCoord.zw can cause a program to fail to link. Additionally,
- // depending on the surrounding code, accessing .xy with a uniform involved can
- // do the same thing. Copying gl_FragCoord.xy into a temp vec2 beforehand
- // (and only accessing .xy) seems to "fix" things.
- this->codePrependf("\tvec4 %s = vec4(%s.x, %s - %s.y, 1.0, 1.0);\n",
- kCoordName, kTempName, rtHeightName, kTempName);
- this->codePrependf("vec2 %s = gl_FragCoord.xy;", kTempName);
- fSetupFragPosition = true;
- }
- SkASSERT(fProgramBuilder->fUniformHandles.fRTHeightUni.isValid());
- return kCoordName;
- }
-}
-
-const char* GrGLFragmentShaderBuilder::dstColor() {
- fHasReadDstColor = true;
-
- const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps();
- if (glslCaps->fbFetchSupport()) {
- this->addFeature(1 << (GrGLFragmentShaderBuilder::kLastGLSLPrivateFeature + 1),
- glslCaps->fbFetchExtensionString());
-
- // Some versions of this extension string require declaring custom color output on ES 3.0+
- const char* fbFetchColorName = glslCaps->fbFetchColorName();
- if (glslCaps->fbFetchNeedsCustomOutput()) {
- this->enableCustomOutput();
- fOutputs[fCustomColorOutputIndex].setTypeModifier(GrShaderVar::kInOut_TypeModifier);
- fbFetchColorName = DeclaredColorOutputName();
- }
- return fbFetchColorName;
- } else {
- return kDstTextureColorName;
- }
-}
-
-void GrGLFragmentShaderBuilder::enableAdvancedBlendEquationIfNeeded(GrBlendEquation equation) {
- SkASSERT(GrBlendEquationIsAdvanced(equation));
-
- const GrGLSLCaps& caps = *fProgramBuilder->glslCaps();
- if (!caps.mustEnableAdvBlendEqs()) {
- return;
- }
-
- this->addFeature(1 << kBlendEquationAdvanced_GLSLPrivateFeature,
- "GL_KHR_blend_equation_advanced");
- if (caps.mustEnableSpecificAdvBlendEqs()) {
- this->addLayoutQualifier(specific_layout_qualifier_name(equation), kOut_InterfaceQualifier);
- } else {
- this->addLayoutQualifier("blend_support_all_equations", kOut_InterfaceQualifier);
- }
-}
-
-void GrGLFragmentShaderBuilder::enableCustomOutput() {
- if (!fHasCustomColorOutput) {
- fHasCustomColorOutput = true;
- fCustomColorOutputIndex = fOutputs.count();
- fOutputs.push_back().set(kVec4f_GrSLType,
- GrGLSLShaderVar::kOut_TypeModifier,
- DeclaredColorOutputName());
- }
-}
-
-void GrGLFragmentShaderBuilder::enableSecondaryOutput() {
- SkASSERT(!fHasSecondaryOutput);
- fHasSecondaryOutput = true;
- const GrGLSLCaps& caps = *fProgramBuilder->glslCaps();
- if (const char* extension = caps.secondaryOutputExtensionString()) {
- this->addFeature(1 << kBlendFuncExtended_GLSLPrivateFeature, extension);
- }
-
- // If the primary output is declared, we must declare also the secondary output
- // and vice versa, since it is not allowed to use a built-in gl_FragColor and a custom
- // output. The condition also co-incides with the condition in whici GLES SL 2.0
- // requires the built-in gl_SecondaryFragColorEXT, where as 3.0 requires a custom output.
- if (caps.mustDeclareFragmentShaderOutput()) {
- fOutputs.push_back().set(kVec4f_GrSLType, GrGLSLShaderVar::kOut_TypeModifier,
- DeclaredSecondaryColorOutputName());
- }
-}
-
-const char* GrGLFragmentShaderBuilder::getPrimaryColorOutputName() const {
- return fHasCustomColorOutput ? DeclaredColorOutputName() : "gl_FragColor";
-}
-
-const char* GrGLFragmentShaderBuilder::getSecondaryColorOutputName() const {
- const GrGLSLCaps& caps = *fProgramBuilder->glslCaps();
- return caps.mustDeclareFragmentShaderOutput() ? DeclaredSecondaryColorOutputName()
- : "gl_SecondaryFragColorEXT";
-}
-
-void GrGLFragmentShaderBuilder::onFinalize() {
- GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision,
- *fProgramBuilder->glslCaps(),
- &this->precisionQualifier());
-}
-
-void GrGLFragmentShaderBuilder::addVarying(GrGLSLVarying* v, GrSLPrecision fsPrec) {
- v->fFsIn = v->fVsOut;
- if (v->fGsOut) {
- v->fFsIn = v->fGsOut;
- }
- fInputs.push_back().set(v->fType, GrGLSLShaderVar::kVaryingIn_TypeModifier, v->fFsIn, fsPrec);
-}
-
-void GrGLFragmentBuilder::onBeforeChildProcEmitCode() {
- SkASSERT(fSubstageIndices.count() >= 1);
- fSubstageIndices.push_back(0);
- // second-to-last value in the fSubstageIndices stack is the index of the child proc
- // at that level which is currently emitting code.
- fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2]);
-}
-
-void GrGLFragmentBuilder::onAfterChildProcEmitCode() {
- SkASSERT(fSubstageIndices.count() >= 2);
- fSubstageIndices.pop_back();
- fSubstageIndices.back()++;
- int removeAt = fMangleString.findLastOf('_');
- fMangleString.remove(removeAt, fMangleString.size() - removeAt);
-}
-
+++ /dev/null
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrGLFragmentShaderBuilder_DEFINED
-#define GrGLFragmentShaderBuilder_DEFINED
-
-#include "GrGLShaderBuilder.h"
-
-#include "glsl/GrGLSLProcessorTypes.h"
-
-class GrRenderTarget;
-class GrGLSLVarying;
-
-/*
- * This base class encapsulates the functionality which the GP uses to build fragment shaders
- */
-class GrGLFragmentBuilder : public GrGLShaderBuilder {
-public:
- GrGLFragmentBuilder(GrGLSLProgramBuilder* program)
- : INHERITED(program)
- , fHasCustomColorOutput(false)
- , fHasSecondaryOutput(false) {
- fSubstageIndices.push_back(0);
- }
- virtual ~GrGLFragmentBuilder() {}
- /**
- * Use of these features may require a GLSL extension to be enabled. Shaders may not compile
- * if code is added that uses one of these features without calling enableFeature()
- */
- enum GLSLFeature {
- kStandardDerivatives_GLSLFeature = 0,
- kLastGLSLFeature = kStandardDerivatives_GLSLFeature
- };
-
- /**
- * If the feature is supported then true is returned and any necessary #extension declarations
- * are added to the shaders. If the feature is not supported then false will be returned.
- */
- virtual bool enableFeature(GLSLFeature) = 0;
-
- /**
- * This returns a variable name to access the 2D, perspective correct version of the coords in
- * the fragment shader. If the coordinates at index are 3-dimensional, it immediately emits a
- * perspective divide into the fragment shader (xy / z) to convert them to 2D.
- */
- virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords, int index) = 0;
-
-
- /** Returns a variable name that represents the position of the fragment in the FS. The position
- is in device space (e.g. 0,0 is the top left and pixel centers are at half-integers). */
- virtual const char* fragmentPosition() = 0;
-
- /**
- * Fragment procs with child procs should call these functions before/after calling emitCode
- * on a child proc.
- */
- void onBeforeChildProcEmitCode();
- void onAfterChildProcEmitCode();
-
- const SkString& getMangleString() const { return fMangleString; }
-
- bool hasCustomColorOutput() const { return fHasCustomColorOutput; }
- bool hasSecondaryOutput() const { return fHasSecondaryOutput; }
-
-protected:
- bool fHasCustomColorOutput;
- bool fHasSecondaryOutput;
-
-private:
- /*
- * State that tracks which child proc in the proc tree is currently emitting code. This is
- * used to update the fMangleString, which is used to mangle the names of uniforms and functions
- * emitted by the proc. fSubstageIndices is a stack: its count indicates how many levels deep
- * we are in the tree, and its second-to-last value is the index of the child proc at that
- * level which is currently emitting code. For example, if fSubstageIndices = [3, 1, 2, 0], that
- * means we're currently emitting code for the base proc's 3rd child's 1st child's 2nd child.
- */
- SkTArray<int> fSubstageIndices;
-
- /*
- * The mangle string is used to mangle the names of uniforms/functions emitted by the child
- * procs so no duplicate uniforms/functions appear in the generated shader program. The mangle
- * string is simply based on fSubstageIndices. For example, if fSubstageIndices = [3, 1, 2, 0],
- * then the manglestring will be "_c3_c1_c2", and any uniform/function emitted by that proc will
- * have "_c3_c1_c2" appended to its name, which can be interpreted as "base proc's 3rd child's
- * 1st child's 2nd child".
- */
- SkString fMangleString;
-
- friend class GrGLPathProcessor;
-
- typedef GrGLShaderBuilder INHERITED;
-};
-
-/*
- * Fragment processor's, in addition to all of the above, may need to use dst color so they use
- * this builder to create their shader. Because this is the only shader builder the FP sees, we
- * just call it FPShaderBuilder
- */
-class GrGLXPFragmentBuilder : public GrGLFragmentBuilder {
-public:
- GrGLXPFragmentBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
-
- /** Returns the variable name that holds the color of the destination pixel. This may be nullptr if
- no effect advertised that it will read the destination. */
- virtual const char* dstColor() = 0;
-
- /** Adds any necessary layout qualifiers in order to legalize the supplied blend equation with
- this shader. It is only legal to call this method with an advanced blend equation, and only
- if these equations are supported. */
- virtual void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) = 0;
-
-private:
- typedef GrGLFragmentBuilder INHERITED;
-};
-
-// TODO rename to Fragment Builder
-class GrGLFragmentShaderBuilder : public GrGLXPFragmentBuilder {
-public:
- typedef uint8_t FragPosKey;
-
- /** Returns a key for reading the fragment location. This should only be called if there is an
- effect that will requires the fragment position. If the fragment position is not required,
- the key is 0. */
- static FragPosKey KeyForFragmentPosition(const GrRenderTarget* dst);
-
- GrGLFragmentShaderBuilder(GrGLSLProgramBuilder* program, uint8_t fragPosKey);
-
- // true public interface, defined explicitly in the abstract interfaces above
- bool enableFeature(GLSLFeature) override;
- virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords,
- int index) override;
- const char* fragmentPosition() override;
- const char* dstColor() override;
-
- void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) override;
-
-private:
- // Private public interface, used by GrGLProgramBuilder to build a fragment shader
- void enableCustomOutput();
- void enableSecondaryOutput();
- const char* getPrimaryColorOutputName() const;
- const char* getSecondaryColorOutputName() const;
-
- // As GLProcessors emit code, there are some conditions we need to verify. We use the below
- // state to track this. The reset call is called per processor emitted.
- bool hasReadDstColor() const { return fHasReadDstColor; }
- bool hasReadFragmentPosition() const { return fHasReadFragmentPosition; }
- void reset() {
- fHasReadDstColor = false;
- fHasReadFragmentPosition = false;
- }
-
- static const char* DeclaredColorOutputName() { return "fsColorOut"; }
- static const char* DeclaredSecondaryColorOutputName() { return "fsSecondaryColorOut"; }
-
- /*
- * An internal call for GrGLProgramBuilder to use to add varyings to the vertex shader
- */
- void addVarying(GrGLSLVarying*, GrSLPrecision);
-
- void onFinalize() override;
-
- /**
- * Features that should only be enabled by GrGLFragmentShaderBuilder itself.
- */
- enum GLSLPrivateFeature {
- kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1,
- kBlendEquationAdvanced_GLSLPrivateFeature,
- kBlendFuncExtended_GLSLPrivateFeature,
- kLastGLSLPrivateFeature = kBlendFuncExtended_GLSLPrivateFeature
- };
-
- // Interpretation of FragPosKey when generating code
- enum {
- kNoFragPosRead_FragPosKey = 0, // The fragment positition will not be needed.
- kTopLeftFragPosRead_FragPosKey = 0x1,// Read frag pos relative to top-left.
- kBottomLeftFragPosRead_FragPosKey = 0x2,// Read frag pos relative to bottom-left.
- };
-
- static const char* kDstTextureColorName;
-
- bool fSetupFragPosition;
- bool fTopLeftFragPosRead;
- int fCustomColorOutputIndex;
-
- // some state to verify shaders and effects are consistent, this is reset between effects by
- // the program creator
- bool fHasReadDstColor;
- bool fHasReadFragmentPosition;
-
- friend class GrGLProgramBuilder;
-
- typedef GrGLXPFragmentBuilder INHERITED;
-};
-
-#endif
+++ /dev/null
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "GrGLGeometryShaderBuilder.h"
-#include "GrGLProgramBuilder.h"
-#include "../GrGLGpu.h"
-
-GrGLGeometryBuilder::GrGLGeometryBuilder(GrGLSLProgramBuilder* program)
- : INHERITED(program) {
-
-}
-
-void GrGLGeometryBuilder::addVarying(const char* name, GrSLPrecision precision, GrGLSLVarying* v) {
- // if we have a GS take each varying in as an array
- // and output as non-array.
- if (v->vsVarying()) {
- fInputs.push_back();
- fInputs.back().setType(v->fType);
- fInputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingIn_TypeModifier);
- fInputs.back().setPrecision(precision);
- fInputs.back().setUnsizedArray();
- *fInputs.back().accessName() = v->fVsOut;
- v->fGsIn = v->fVsOut;
- }
-
- if (v->fsVarying()) {
- fOutputs.push_back();
- fOutputs.back().setType(v->fType);
- fOutputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingOut_TypeModifier);
- fOutputs.back().setPrecision(precision);
- fProgramBuilder->nameVariable(fOutputs.back().accessName(), 'g', name);
- v->fGsOut = fOutputs.back().getName().c_str();
- }
-}
-
+++ /dev/null
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrGLGeometryShaderBuilder_DEFINED
-#define GrGLGeometryShaderBuilder_DEFINED
-
-#include "GrGLShaderBuilder.h"
-
-class GrGLSLVarying;
-
-class GrGLGeometryBuilder : public GrGLShaderBuilder {
-public:
- GrGLGeometryBuilder(GrGLSLProgramBuilder* program);
-
-private:
- /*
- * an internal call for GrGLFullProgramBuilder to add varyings
- */
- void addVarying(const char* name, GrSLPrecision precision, GrGLSLVarying*);
-
- void onFinalize() override {}
-
- friend class GrGLProgramBuilder;
-
- typedef GrGLShaderBuilder INHERITED;
-};
-
-#endif
}
}
-bool GrGLProgramBuilder::compileAndAttachShaders(GrGLShaderBuilder& shader,
+bool GrGLProgramBuilder::compileAndAttachShaders(GrGLSLShaderBuilder& shader,
GrGLuint programId,
GrGLenum type,
SkTDArray<GrGLuint>* shaderIds) {
const GrGLCaps& caps = this->gpu()->glCaps();
if (fFS.hasCustomColorOutput() && caps.bindFragDataLocationSupport()) {
GL_CALL(BindFragDataLocation(programID, 0,
- GrGLFragmentShaderBuilder::DeclaredColorOutputName()));
+ GrGLSLFragmentShaderBuilder::DeclaredColorOutputName()));
}
if (fFS.hasSecondaryOutput() && caps.glslCaps()->mustDeclareFragmentShaderOutput()) {
GL_CALL(BindFragDataLocationIndexed(programID, 0, 1,
- GrGLFragmentShaderBuilder::DeclaredSecondaryColorOutputName()));
+ GrGLSLFragmentShaderBuilder::DeclaredSecondaryColorOutputName()));
}
// handle NVPR separable varyings
class GrFragmentProcessor;
class GrGLContextInfo;
-class GrGLShaderBuilder;
+class GrGLSLShaderBuilder;
class GrGLSLCaps;
-// Enough precision to represent 1 / 2048 accurately in printf
-#define GR_SIGNIFICANT_POW2_DECIMAL_DIG 11
-
/**
* The below struct represent processors installed in programs.
*/
GrGLSLTextureSampler::TextureSamplerArray* outSamplers,
GrGLInstalledProc<Proc>*);
- bool compileAndAttachShaders(GrGLShaderBuilder& shader,
+ bool compileAndAttachShaders(GrGLSLShaderBuilder& shader,
GrGLuint programId,
GrGLenum type,
SkTDArray<GrGLuint>* shaderIds);
SkTArray<UniformHandle> fSamplerUniforms;
SeparableVaryingInfoArray fSeparableVaryingInfos;
- friend class GrGLShaderBuilder;
- friend class GrGLVertexBuilder;
- friend class GrGLFragmentShaderBuilder;
- friend class GrGLGeometryBuilder;
+ friend class GrGLSLShaderBuilder;
+ friend class GrGLSLVertexBuilder;
+ friend class GrGLSLFragmentShaderBuilder;
+ friend class GrGLSLGeometryBuilder;
typedef GrGLSLProgramBuilder INHERITED;
};
+++ /dev/null
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "GrGLShaderBuilder.h"
-#include "glsl/GrGLSLCaps.h"
-#include "glsl/GrGLSLShaderVar.h"
-#include "glsl/GrGLSLTextureSampler.h"
-#include "glsl/GrGLSLProgramBuilder.h"
-
-static void map_swizzle(const char* swizzleMap, const char* swizzle, char* mangledSwizzle) {
- int i;
- for (i = 0; '\0' != swizzle[i]; ++i) {
- switch (swizzle[i]) {
- case 'r':
- mangledSwizzle[i] = swizzleMap[0];
- break;
- case 'g':
- mangledSwizzle[i] = swizzleMap[1];
- break;
- case 'b':
- mangledSwizzle[i] = swizzleMap[2];
- break;
- case 'a':
- mangledSwizzle[i] = swizzleMap[3];
- break;
- default:
- SkFAIL("Unsupported swizzle");
- }
- }
- mangledSwizzle[i] ='\0';
-}
-
-static void append_texture_lookup(SkString* out,
- const GrGLSLCaps* glslCaps,
- const char* samplerName,
- const char* coordName,
- GrPixelConfig config,
- const char* swizzle,
- GrSLType varyingType = kVec2f_GrSLType) {
- SkASSERT(coordName);
-
- out->appendf("%s(%s, %s)",
- GrGLSLTexture2DFunctionName(varyingType, glslCaps->generation()),
- samplerName,
- coordName);
-
- char mangledSwizzle[5];
-
- // This refers to any swizzling we may need to get from some backend internal format to the
- // format used in GrPixelConfig. Some backends will automatically do the sizzling for us.
- if (glslCaps->mustSwizzleInShader()) {
- const char* swizzleMap = glslCaps->getSwizzleMap(config);
- // if the map is simply 'rgba' then we don't need to do any manual swizzling to get us to
- // a GrPixelConfig format.
- if (memcmp(swizzleMap, "rgba", 4)) {
- // Manually 'swizzle' the swizzle using our mapping
- map_swizzle(swizzleMap, swizzle, mangledSwizzle);
- swizzle = mangledSwizzle;
- }
- }
-
- // For shader prettiness we omit the swizzle rather than appending ".rgba".
- if (memcmp(swizzle, "rgba", 4)) {
- out->appendf(".%s", swizzle);
- }
-}
-
-GrGLShaderBuilder::GrGLShaderBuilder(GrGLSLProgramBuilder* program)
- : fProgramBuilder(program)
- , fInputs(GrGLSLProgramBuilder::kVarsPerBlock)
- , fOutputs(GrGLSLProgramBuilder::kVarsPerBlock)
- , fFeaturesAddedMask(0)
- , fCodeIndex(kCode)
- , fFinalized(false) {
- // We push back some dummy pointers which will later become our header
- for (int i = 0; i <= kCode; i++) {
- fShaderStrings.push_back();
- fCompilerStrings.push_back(nullptr);
- fCompilerStringLengths.push_back(0);
- }
-
- this->main() = "void main() {";
-}
-
-void GrGLShaderBuilder::declAppend(const GrGLSLShaderVar& var) {
- SkString tempDecl;
- var.appendDecl(fProgramBuilder->glslCaps(), &tempDecl);
- this->codeAppendf("%s;", tempDecl.c_str());
-}
-
-void GrGLShaderBuilder::emitFunction(GrSLType returnType,
- const char* name,
- int argCnt,
- const GrGLSLShaderVar* args,
- const char* body,
- SkString* outName) {
- this->functions().append(GrGLSLTypeString(returnType));
- fProgramBuilder->nameVariable(outName, '\0', name);
- this->functions().appendf(" %s", outName->c_str());
- this->functions().append("(");
- for (int i = 0; i < argCnt; ++i) {
- args[i].appendDecl(fProgramBuilder->glslCaps(), &this->functions());
- if (i < argCnt - 1) {
- this->functions().append(", ");
- }
- }
- this->functions().append(") {\n");
- this->functions().append(body);
- this->functions().append("}\n\n");
-}
-
-void GrGLShaderBuilder::appendTextureLookup(SkString* out,
- const GrGLSLTextureSampler& sampler,
- const char* coordName,
- GrSLType varyingType) const {
- append_texture_lookup(out,
- fProgramBuilder->glslCaps(),
- fProgramBuilder->getUniformCStr(sampler.fSamplerUniform),
- coordName,
- sampler.config(),
- sampler.swizzle(),
- varyingType);
-}
-
-void GrGLShaderBuilder::appendTextureLookup(const GrGLSLTextureSampler& sampler,
- const char* coordName,
- GrSLType varyingType) {
- this->appendTextureLookup(&this->code(), sampler, coordName, varyingType);
-}
-
-void GrGLShaderBuilder::appendTextureLookupAndModulate(const char* modulation,
- const GrGLSLTextureSampler& sampler,
- const char* coordName,
- GrSLType varyingType) {
- SkString lookup;
- this->appendTextureLookup(&lookup, sampler, coordName, varyingType);
- this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str());
-}
-
-void GrGLShaderBuilder::addFeature(uint32_t featureBit, const char* extensionName) {
- if (!(featureBit & fFeaturesAddedMask)) {
- this->extensions().appendf("#extension %s: require\n", extensionName);
- fFeaturesAddedMask |= featureBit;
- }
-}
-
-void GrGLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const {
- for (int i = 0; i < vars.count(); ++i) {
- vars[i].appendDecl(fProgramBuilder->glslCaps(), out);
- out->append(";\n");
- }
-}
-
-void GrGLShaderBuilder::addLayoutQualifier(const char* param, InterfaceQualifier interface) {
- SkASSERT(fProgramBuilder->glslCaps()->generation() >= k330_GrGLSLGeneration ||
- fProgramBuilder->glslCaps()->mustEnableAdvBlendEqs());
- fLayoutParams[interface].push_back() = param;
-}
-
-void GrGLShaderBuilder::compileAndAppendLayoutQualifiers() {
- static const char* interfaceQualifierNames[] = {
- "out"
- };
-
- for (int interface = 0; interface <= kLastInterfaceQualifier; ++interface) {
- const SkTArray<SkString>& params = fLayoutParams[interface];
- if (params.empty()) {
- continue;
- }
- this->layoutQualifiers().appendf("layout(%s", params[0].c_str());
- for (int i = 1; i < params.count(); ++i) {
- this->layoutQualifiers().appendf(", %s", params[i].c_str());
- }
- this->layoutQualifiers().appendf(") %s;\n", interfaceQualifierNames[interface]);
- }
-
- GR_STATIC_ASSERT(0 == GrGLShaderBuilder::kOut_InterfaceQualifier);
- GR_STATIC_ASSERT(SK_ARRAY_COUNT(interfaceQualifierNames) == kLastInterfaceQualifier + 1);
-}
-
-void GrGLShaderBuilder::finalize(uint32_t visibility) {
- SkASSERT(!fFinalized);
- this->versionDecl() = fProgramBuilder->glslCaps()->versionDeclString();
- this->compileAndAppendLayoutQualifiers();
- SkASSERT(visibility);
- fProgramBuilder->appendUniformDecls((GrGLSLProgramBuilder::ShaderVisibility) visibility,
- &this->uniforms());
- this->appendDecls(fInputs, &this->inputs());
- // We should not have any outputs in the fragment shader when using version 1.10
- SkASSERT(GrGLSLProgramBuilder::kFragment_Visibility != visibility ||
- k110_GrGLSLGeneration != fProgramBuilder->glslCaps()->generation() ||
- fOutputs.empty());
- this->appendDecls(fOutputs, &this->outputs());
- this->onFinalize();
- // append the 'footer' to code
- this->code().append("}");
-
- for (int i = 0; i <= fCodeIndex; i++) {
- fCompilerStrings[i] = fShaderStrings[i].c_str();
- fCompilerStringLengths[i] = (int)fShaderStrings[i].size();
- }
-
- fFinalized = true;
-}
-
+++ /dev/null
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrGLShaderBuilder_DEFINED
-#define GrGLShaderBuilder_DEFINED
-
-#include "GrAllocator.h"
-#include "glsl/GrGLSLShaderVar.h"
-#include "SkTDArray.h"
-
-#include <stdarg.h>
-
-class GrGLSLProgramBuilder;
-class GrGLSLTextureSampler;
-
-/**
- base class for all shaders builders
-*/
-class GrGLShaderBuilder {
-public:
- GrGLShaderBuilder(GrGLSLProgramBuilder* program);
- virtual ~GrGLShaderBuilder() {}
-
- void addInput(const GrGLSLShaderVar& input) { fInputs.push_back(input); }
- void addOutput(const GrGLSLShaderVar& output) { fOutputs.push_back(output); }
-
- /*
- * We put texture lookups in the base class because it is TECHNICALLY possible to do texture
- * lookups in any kind of shader. However, for the time being using these calls on non-fragment
- * shaders will result in a shader compilation error as texture sampler uniforms are only
- * visible to the fragment shader. It would not be hard to change this behavior, if someone
- * actually wants to do texture lookups in a non-fragment shader
- *
- * TODO if append texture lookup is used on a non-fragment shader, sampler uniforms should be
- * made visible to that shaders
- */
- /** Appends a 2D texture sample with projection if necessary. coordType must either be Vec2f or
- Vec3f. The latter is interpreted as projective texture coords. The vec length and swizzle
- order of the result depends on the GrTextureAccess associated with the GrGLSLTextureSampler.
- */
- void appendTextureLookup(SkString* out,
- const GrGLSLTextureSampler&,
- const char* coordName,
- GrSLType coordType = kVec2f_GrSLType) const;
-
- /** Version of above that appends the result to the fragment shader code instead.*/
- void appendTextureLookup(const GrGLSLTextureSampler&,
- const char* coordName,
- GrSLType coordType = kVec2f_GrSLType);
-
-
- /** Does the work of appendTextureLookup and modulates the result by modulation. The result is
- always a vec4. modulation and the swizzle specified by GrGLSLTextureSampler must both be
- vec4 or float. If modulation is "" or nullptr it this function acts as though
- appendTextureLookup were called. */
- void appendTextureLookupAndModulate(const char* modulation,
- const GrGLSLTextureSampler&,
- const char* coordName,
- GrSLType coordType = kVec2f_GrSLType);
-
- /**
- * Called by GrGLProcessors to add code to one of the shaders.
- */
- void codeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
- va_list args;
- va_start(args, format);
- this->code().appendVAList(format, args);
- va_end(args);
- }
-
- void codeAppend(const char* str) { this->code().append(str); }
-
- void codePrependf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
- va_list args;
- va_start(args, format);
- this->code().prependVAList(format, args);
- va_end(args);
- }
-
- /**
- * Appends a variable declaration to one of the shaders
- */
- void declAppend(const GrGLSLShaderVar& var);
-
- /** Emits a helper function outside of main() in the fragment shader. */
- void emitFunction(GrSLType returnType,
- const char* name,
- int argCnt,
- const GrGLSLShaderVar* args,
- const char* body,
- SkString* outName);
-
- /*
- * Combines the various parts of the shader to create a single finalized shader string.
- */
- void finalize(uint32_t visibility);
-
- /*
- * Get parent builder for adding uniforms
- */
- GrGLSLProgramBuilder* getProgramBuilder() { return fProgramBuilder; }
-
- /**
- * Helper for begining and ending a block in the shader code.
- */
- class ShaderBlock {
- public:
- ShaderBlock(GrGLShaderBuilder* builder) : fBuilder(builder) {
- SkASSERT(builder);
- fBuilder->codeAppend("{");
- }
-
- ~ShaderBlock() {
- fBuilder->codeAppend("}");
- }
- private:
- GrGLShaderBuilder* fBuilder;
- };
-
-protected:
- typedef GrTAllocator<GrGLSLShaderVar> VarArray;
- void appendDecls(const VarArray& vars, SkString* out) const;
-
- /*
- * A general function which enables an extension in a shader if the feature bit is not present
- */
- void addFeature(uint32_t featureBit, const char* extensionName);
-
- enum InterfaceQualifier {
- kOut_InterfaceQualifier,
- kLastInterfaceQualifier = kOut_InterfaceQualifier
- };
-
- /*
- * A low level function to build default layout qualifiers.
- *
- * e.g. layout(param1, param2, ...) out;
- *
- * GLSL allows default layout qualifiers for in, out, and uniform.
- */
- void addLayoutQualifier(const char* param, InterfaceQualifier);
-
- void compileAndAppendLayoutQualifiers();
-
- void nextStage() {
- fShaderStrings.push_back();
- fCompilerStrings.push_back(this->code().c_str());
- fCompilerStringLengths.push_back((int)this->code().size());
- fCodeIndex++;
- }
-
- SkString& versionDecl() { return fShaderStrings[kVersionDecl]; }
- SkString& extensions() { return fShaderStrings[kExtensions]; }
- SkString& precisionQualifier() { return fShaderStrings[kPrecisionQualifier]; }
- SkString& layoutQualifiers() { return fShaderStrings[kLayoutQualifiers]; }
- SkString& uniforms() { return fShaderStrings[kUniforms]; }
- SkString& inputs() { return fShaderStrings[kInputs]; }
- SkString& outputs() { return fShaderStrings[kOutputs]; }
- SkString& functions() { return fShaderStrings[kFunctions]; }
- SkString& main() { return fShaderStrings[kMain]; }
- SkString& code() { return fShaderStrings[fCodeIndex]; }
-
- virtual void onFinalize() = 0;
-
- enum {
- kVersionDecl,
- kExtensions,
- kPrecisionQualifier,
- kLayoutQualifiers,
- kUniforms,
- kInputs,
- kOutputs,
- kFunctions,
- kMain,
- kCode,
- };
-
- GrGLSLProgramBuilder* fProgramBuilder;
- SkSTArray<kCode, const char*, true> fCompilerStrings;
- SkSTArray<kCode, int, true> fCompilerStringLengths;
- SkSTArray<kCode, SkString> fShaderStrings;
- SkString fCode;
- SkString fFunctions;
- SkString fExtensions;
-
- VarArray fInputs;
- VarArray fOutputs;
- uint32_t fFeaturesAddedMask;
- SkSTArray<1, SkString> fLayoutParams[kLastInterfaceQualifier + 1];
- int fCodeIndex;
- bool fFinalized;
-
- friend class GrGLProgramBuilder;
- friend class GrGLPathProgramBuilder; // to access fInputs.
-};
-#endif
+++ /dev/null
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "GrGLVertexShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
-
-GrGLVertexBuilder::GrGLVertexBuilder(GrGLSLProgramBuilder* program)
- : INHERITED(program)
- , fRtAdjustName(nullptr) {
-}
-
-void GrGLVertexBuilder::addVarying(const char* name, GrSLPrecision precision, GrGLSLVarying* v) {
- fOutputs.push_back();
- fOutputs.back().setType(v->fType);
- fOutputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingOut_TypeModifier);
- fOutputs.back().setPrecision(precision);
- fProgramBuilder->nameVariable(fOutputs.back().accessName(), 'v', name);
- v->fVsOut = fOutputs.back().getName().c_str();
-}
-
-void GrGLVertexBuilder::emitAttributes(const GrGeometryProcessor& gp) {
- int vaCount = gp.numAttribs();
- for (int i = 0; i < vaCount; i++) {
- this->addAttribute(&gp.getAttrib(i));
- }
- return;
-}
-
-void GrGLVertexBuilder::transformToNormalizedDeviceSpace(const GrShaderVar& posVar) {
- SkASSERT(!fRtAdjustName);
-
- GrSLPrecision precision = kDefault_GrSLPrecision;
- if (fProgramBuilder->glslCaps()->forceHighPrecisionNDSTransform()) {
- precision = kHigh_GrSLPrecision;
- }
-
- // setup RT Uniform
- fProgramBuilder->fUniformHandles.fRTAdjustmentUni =
- fProgramBuilder->addUniform(GrGLSLProgramBuilder::kVertex_Visibility,
- kVec4f_GrSLType, precision,
- fProgramBuilder->rtAdjustment(),
- &fRtAdjustName);
- if (this->getProgramBuilder()->desc().header().fSnapVerticesToPixelCenters) {
- if (kVec3f_GrSLType == posVar.getType()) {
- const char* p = posVar.c_str();
- this->codeAppendf("{vec2 _posTmp = vec2(%s.x/%s.z, %s.y/%s.z);", p, p, p, p);
- } else {
- SkASSERT(kVec2f_GrSLType == posVar.getType());
- this->codeAppendf("{vec2 _posTmp = %s;", posVar.c_str());
- }
- this->codeAppendf("_posTmp = floor(_posTmp) + vec2(0.5, 0.5);"
- "gl_Position = vec4(_posTmp.x * %s.x + %s.y,"
- "_posTmp.y * %s.z + %s.w, 0, 1);}",
- fRtAdjustName, fRtAdjustName, fRtAdjustName, fRtAdjustName);
- } else if (kVec3f_GrSLType == posVar.getType()) {
- this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy), dot(%s.yz, %s.zw), 0, %s.z);",
- posVar.c_str(), fRtAdjustName,
- posVar.c_str(), fRtAdjustName,
- posVar.c_str());
- } else {
- SkASSERT(kVec2f_GrSLType == posVar.getType());
- this->codeAppendf("gl_Position = vec4(%s.x * %s.x + %s.y, %s.y * %s.z + %s.w, 0, 1);",
- posVar.c_str(), fRtAdjustName, fRtAdjustName,
- posVar.c_str(), fRtAdjustName, fRtAdjustName);
- }
- // We could have the GrGeometryProcessor do this, but its just easier to have it performed
- // here. If we ever need to set variable pointsize, then we can reinvestigate
- this->codeAppend("gl_PointSize = 1.0;");
-}
-
-bool GrGLVertexBuilder::addAttribute(const GrShaderVar& var) {
- SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier());
- for (int i = 0; i < fInputs.count(); ++i) {
- const GrGLSLShaderVar& attr = fInputs[i];
- // if attribute already added, don't add it again
- if (attr.getName().equals(var.getName())) {
- return false;
- }
- }
- fInputs.push_back(var);
- return true;
-}
-
+++ /dev/null
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrGLVertexShader_DEFINED
-#define GrGLVertexShader_DEFINED
-
-#include "GrGLShaderBuilder.h"
-#include "GrGeometryProcessor.h"
-
-class GrGLSLVarying;
-
-class GrGLVertexBuilder : public GrGLShaderBuilder {
-public:
- GrGLVertexBuilder(GrGLSLProgramBuilder* program);
-
- void transformToNormalizedDeviceSpace(const GrShaderVar& posVar);
- void emitAttributes(const GrGeometryProcessor& gp);
-
- void addAttribute(const GrGeometryProcessor::Attribute* attr) {
- this->addAttribute(GrShaderVar(attr->fName,
- GrVertexAttribTypeToSLType(attr->fType),
- GrShaderVar::kAttribute_TypeModifier,
- GrShaderVar::kNonArray,
- attr->fPrecision));
- }
-
-private:
- /*
- * Internal call for GrGLProgramBuilder.addVarying
- */
- void addVarying(const char* name, GrSLPrecision, GrGLSLVarying*);
-
- // an internal call which checks for uniquness of a var before adding it to the list of inputs
- bool addAttribute(const GrShaderVar& var);
-
- void onFinalize() override {}
-
- const char* fRtAdjustName;
-
- friend class GrGLProgramBuilder;
-
- typedef GrGLShaderBuilder INHERITED;
-};
-
-#endif
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrGLSLFragmentShaderBuilder.h"
+#include "GrRenderTarget.h"
+#include "glsl/GrGLSL.h"
+#include "glsl/GrGLSLCaps.h"
+#include "glsl/GrGLSLProgramBuilder.h"
+
+const char* GrGLSLFragmentShaderBuilder::kDstTextureColorName = "_dstColor";
+
+static const char* specific_layout_qualifier_name(GrBlendEquation equation) {
+ SkASSERT(GrBlendEquationIsAdvanced(equation));
+
+ static const char* kLayoutQualifierNames[] = {
+ "blend_support_screen",
+ "blend_support_overlay",
+ "blend_support_darken",
+ "blend_support_lighten",
+ "blend_support_colordodge",
+ "blend_support_colorburn",
+ "blend_support_hardlight",
+ "blend_support_softlight",
+ "blend_support_difference",
+ "blend_support_exclusion",
+ "blend_support_multiply",
+ "blend_support_hsl_hue",
+ "blend_support_hsl_saturation",
+ "blend_support_hsl_color",
+ "blend_support_hsl_luminosity"
+ };
+ return kLayoutQualifierNames[equation - kFirstAdvancedGrBlendEquation];
+
+ GR_STATIC_ASSERT(0 == kScreen_GrBlendEquation - kFirstAdvancedGrBlendEquation);
+ GR_STATIC_ASSERT(1 == kOverlay_GrBlendEquation - kFirstAdvancedGrBlendEquation);
+ GR_STATIC_ASSERT(2 == kDarken_GrBlendEquation - kFirstAdvancedGrBlendEquation);
+ GR_STATIC_ASSERT(3 == kLighten_GrBlendEquation - kFirstAdvancedGrBlendEquation);
+ GR_STATIC_ASSERT(4 == kColorDodge_GrBlendEquation - kFirstAdvancedGrBlendEquation);
+ GR_STATIC_ASSERT(5 == kColorBurn_GrBlendEquation - kFirstAdvancedGrBlendEquation);
+ GR_STATIC_ASSERT(6 == kHardLight_GrBlendEquation - kFirstAdvancedGrBlendEquation);
+ GR_STATIC_ASSERT(7 == kSoftLight_GrBlendEquation - kFirstAdvancedGrBlendEquation);
+ GR_STATIC_ASSERT(8 == kDifference_GrBlendEquation - kFirstAdvancedGrBlendEquation);
+ GR_STATIC_ASSERT(9 == kExclusion_GrBlendEquation - kFirstAdvancedGrBlendEquation);
+ GR_STATIC_ASSERT(10 == kMultiply_GrBlendEquation - kFirstAdvancedGrBlendEquation);
+ GR_STATIC_ASSERT(11 == kHSLHue_GrBlendEquation - kFirstAdvancedGrBlendEquation);
+ GR_STATIC_ASSERT(12 == kHSLSaturation_GrBlendEquation - kFirstAdvancedGrBlendEquation);
+ GR_STATIC_ASSERT(13 == kHSLColor_GrBlendEquation - kFirstAdvancedGrBlendEquation);
+ GR_STATIC_ASSERT(14 == kHSLLuminosity_GrBlendEquation - kFirstAdvancedGrBlendEquation);
+ GR_STATIC_ASSERT(SK_ARRAY_COUNT(kLayoutQualifierNames) ==
+ kGrBlendEquationCnt - kFirstAdvancedGrBlendEquation);
+}
+
+GrGLSLFragmentShaderBuilder::FragPosKey
+GrGLSLFragmentShaderBuilder::KeyForFragmentPosition(const GrRenderTarget* dst) {
+ if (kTopLeft_GrSurfaceOrigin == dst->origin()) {
+ return kTopLeftFragPosRead_FragPosKey;
+ } else {
+ return kBottomLeftFragPosRead_FragPosKey;
+ }
+}
+
+GrGLSLFragmentShaderBuilder::GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* program,
+ uint8_t fragPosKey)
+ : INHERITED(program)
+ , fSetupFragPosition(false)
+ , fTopLeftFragPosRead(kTopLeftFragPosRead_FragPosKey == fragPosKey)
+ , fCustomColorOutputIndex(-1)
+ , fHasReadDstColor(false)
+ , fHasReadFragmentPosition(false) {
+}
+
+bool GrGLSLFragmentShaderBuilder::enableFeature(GLSLFeature feature) {
+ switch (feature) {
+ case kStandardDerivatives_GLSLFeature: {
+ if (!fProgramBuilder->glslCaps()->shaderDerivativeSupport()) {
+ return false;
+ }
+ const char* extension = fProgramBuilder->glslCaps()->shaderDerivativeExtensionString();
+ if (extension) {
+ this->addFeature(1 << kStandardDerivatives_GLSLFeature, extension);
+ }
+ return true;
+ }
+ default:
+ SkFAIL("Unexpected GLSLFeature requested.");
+ return false;
+ }
+}
+
+SkString GrGLSLFragmentShaderBuilder::ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords,
+ int index) {
+ if (kVec3f_GrSLType != coords[index].getType()) {
+ SkASSERT(kVec2f_GrSLType == coords[index].getType());
+ return coords[index].getName();
+ }
+
+ SkString coords2D("coords2D");
+ if (0 != index) {
+ coords2D.appendf("_%i", index);
+ }
+ this->codeAppendf("\tvec2 %s = %s.xy / %s.z;",
+ coords2D.c_str(), coords[index].c_str(), coords[index].c_str());
+ return coords2D;
+}
+
+const char* GrGLSLFragmentShaderBuilder::fragmentPosition() {
+ fHasReadFragmentPosition = true;
+
+ const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps();
+ // We only declare "gl_FragCoord" when we're in the case where we want to use layout qualifiers
+ // to reverse y. Otherwise it isn't necessary and whether the "in" qualifier appears in the
+ // declaration varies in earlier GLSL specs. So it is simpler to omit it.
+ if (fTopLeftFragPosRead) {
+ fSetupFragPosition = true;
+ return "gl_FragCoord";
+ } else if (const char* extension = glslCaps->fragCoordConventionsExtensionString()) {
+ if (!fSetupFragPosition) {
+ if (glslCaps->generation() < k150_GrGLSLGeneration) {
+ this->addFeature(1 << kFragCoordConventions_GLSLPrivateFeature,
+ extension);
+ }
+ fInputs.push_back().set(kVec4f_GrSLType,
+ GrGLSLShaderVar::kIn_TypeModifier,
+ "gl_FragCoord",
+ kDefault_GrSLPrecision,
+ GrGLSLShaderVar::kUpperLeft_Origin);
+ fSetupFragPosition = true;
+ }
+ return "gl_FragCoord";
+ } else {
+ static const char* kTempName = "tmpXYFragCoord";
+ static const char* kCoordName = "fragCoordYDown";
+ if (!fSetupFragPosition) {
+ SkASSERT(!fProgramBuilder->fUniformHandles.fRTHeightUni.isValid());
+ const char* rtHeightName;
+
+ fProgramBuilder->fUniformHandles.fRTHeightUni =
+ fProgramBuilder->addFragPosUniform(GrGLSLProgramBuilder::kFragment_Visibility,
+ kFloat_GrSLType,
+ kDefault_GrSLPrecision,
+ "RTHeight",
+ &rtHeightName);
+
+ // The Adreno compiler seems to be very touchy about access to "gl_FragCoord".
+ // Accessing glFragCoord.zw can cause a program to fail to link. Additionally,
+ // depending on the surrounding code, accessing .xy with a uniform involved can
+ // do the same thing. Copying gl_FragCoord.xy into a temp vec2 beforehand
+ // (and only accessing .xy) seems to "fix" things.
+ this->codePrependf("\tvec4 %s = vec4(%s.x, %s - %s.y, 1.0, 1.0);\n",
+ kCoordName, kTempName, rtHeightName, kTempName);
+ this->codePrependf("vec2 %s = gl_FragCoord.xy;", kTempName);
+ fSetupFragPosition = true;
+ }
+ SkASSERT(fProgramBuilder->fUniformHandles.fRTHeightUni.isValid());
+ return kCoordName;
+ }
+}
+
+const char* GrGLSLFragmentShaderBuilder::dstColor() {
+ fHasReadDstColor = true;
+
+ const GrGLSLCaps* glslCaps = fProgramBuilder->glslCaps();
+ if (glslCaps->fbFetchSupport()) {
+ this->addFeature(1 << (GrGLSLFragmentShaderBuilder::kLastGLSLPrivateFeature + 1),
+ glslCaps->fbFetchExtensionString());
+
+ // Some versions of this extension string require declaring custom color output on ES 3.0+
+ const char* fbFetchColorName = glslCaps->fbFetchColorName();
+ if (glslCaps->fbFetchNeedsCustomOutput()) {
+ this->enableCustomOutput();
+ fOutputs[fCustomColorOutputIndex].setTypeModifier(GrShaderVar::kInOut_TypeModifier);
+ fbFetchColorName = DeclaredColorOutputName();
+ }
+ return fbFetchColorName;
+ } else {
+ return kDstTextureColorName;
+ }
+}
+
+void GrGLSLFragmentShaderBuilder::enableAdvancedBlendEquationIfNeeded(GrBlendEquation equation) {
+ SkASSERT(GrBlendEquationIsAdvanced(equation));
+
+ const GrGLSLCaps& caps = *fProgramBuilder->glslCaps();
+ if (!caps.mustEnableAdvBlendEqs()) {
+ return;
+ }
+
+ this->addFeature(1 << kBlendEquationAdvanced_GLSLPrivateFeature,
+ "GL_KHR_blend_equation_advanced");
+ if (caps.mustEnableSpecificAdvBlendEqs()) {
+ this->addLayoutQualifier(specific_layout_qualifier_name(equation), kOut_InterfaceQualifier);
+ } else {
+ this->addLayoutQualifier("blend_support_all_equations", kOut_InterfaceQualifier);
+ }
+}
+
+void GrGLSLFragmentShaderBuilder::enableCustomOutput() {
+ if (!fHasCustomColorOutput) {
+ fHasCustomColorOutput = true;
+ fCustomColorOutputIndex = fOutputs.count();
+ fOutputs.push_back().set(kVec4f_GrSLType,
+ GrGLSLShaderVar::kOut_TypeModifier,
+ DeclaredColorOutputName());
+ }
+}
+
+void GrGLSLFragmentShaderBuilder::enableSecondaryOutput() {
+ SkASSERT(!fHasSecondaryOutput);
+ fHasSecondaryOutput = true;
+ const GrGLSLCaps& caps = *fProgramBuilder->glslCaps();
+ if (const char* extension = caps.secondaryOutputExtensionString()) {
+ this->addFeature(1 << kBlendFuncExtended_GLSLPrivateFeature, extension);
+ }
+
+ // If the primary output is declared, we must declare also the secondary output
+ // and vice versa, since it is not allowed to use a built-in gl_FragColor and a custom
+ // output. The condition also co-incides with the condition in whici GLES SL 2.0
+ // requires the built-in gl_SecondaryFragColorEXT, where as 3.0 requires a custom output.
+ if (caps.mustDeclareFragmentShaderOutput()) {
+ fOutputs.push_back().set(kVec4f_GrSLType, GrGLSLShaderVar::kOut_TypeModifier,
+ DeclaredSecondaryColorOutputName());
+ }
+}
+
+const char* GrGLSLFragmentShaderBuilder::getPrimaryColorOutputName() const {
+ return fHasCustomColorOutput ? DeclaredColorOutputName() : "gl_FragColor";
+}
+
+const char* GrGLSLFragmentShaderBuilder::getSecondaryColorOutputName() const {
+ const GrGLSLCaps& caps = *fProgramBuilder->glslCaps();
+ return caps.mustDeclareFragmentShaderOutput() ? DeclaredSecondaryColorOutputName()
+ : "gl_SecondaryFragColorEXT";
+}
+
+void GrGLSLFragmentShaderBuilder::onFinalize() {
+ GrGLSLAppendDefaultFloatPrecisionDeclaration(kDefault_GrSLPrecision,
+ *fProgramBuilder->glslCaps(),
+ &this->precisionQualifier());
+}
+
+void GrGLSLFragmentShaderBuilder::addVarying(GrGLSLVarying* v, GrSLPrecision fsPrec) {
+ v->fFsIn = v->fVsOut;
+ if (v->fGsOut) {
+ v->fFsIn = v->fGsOut;
+ }
+ fInputs.push_back().set(v->fType, GrGLSLShaderVar::kVaryingIn_TypeModifier, v->fFsIn, fsPrec);
+}
+
+void GrGLSLFragmentBuilder::onBeforeChildProcEmitCode() {
+ SkASSERT(fSubstageIndices.count() >= 1);
+ fSubstageIndices.push_back(0);
+ // second-to-last value in the fSubstageIndices stack is the index of the child proc
+ // at that level which is currently emitting code.
+ fMangleString.appendf("_c%d", fSubstageIndices[fSubstageIndices.count() - 2]);
+}
+
+void GrGLSLFragmentBuilder::onAfterChildProcEmitCode() {
+ SkASSERT(fSubstageIndices.count() >= 2);
+ fSubstageIndices.pop_back();
+ fSubstageIndices.back()++;
+ int removeAt = fMangleString.findLastOf('_');
+ fMangleString.remove(removeAt, fMangleString.size() - removeAt);
+}
+
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrGLSLFragmentShaderBuilder_DEFINED
+#define GrGLSLFragmentShaderBuilder_DEFINED
+
+#include "GrGLSLShaderBuilder.h"
+
+#include "glsl/GrGLSLProcessorTypes.h"
+
+class GrRenderTarget;
+class GrGLSLVarying;
+
+/*
+ * This base class encapsulates the functionality which the GP uses to build fragment shaders
+ */
+class GrGLSLFragmentBuilder : public GrGLSLShaderBuilder {
+public:
+ GrGLSLFragmentBuilder(GrGLSLProgramBuilder* program)
+ : INHERITED(program)
+ , fHasCustomColorOutput(false)
+ , fHasSecondaryOutput(false) {
+ fSubstageIndices.push_back(0);
+ }
+ virtual ~GrGLSLFragmentBuilder() {}
+ /**
+ * Use of these features may require a GLSL extension to be enabled. Shaders may not compile
+ * if code is added that uses one of these features without calling enableFeature()
+ */
+ enum GLSLFeature {
+ kStandardDerivatives_GLSLFeature = 0,
+ kLastGLSLFeature = kStandardDerivatives_GLSLFeature
+ };
+
+ /**
+ * If the feature is supported then true is returned and any necessary #extension declarations
+ * are added to the shaders. If the feature is not supported then false will be returned.
+ */
+ virtual bool enableFeature(GLSLFeature) = 0;
+
+ /**
+ * This returns a variable name to access the 2D, perspective correct version of the coords in
+ * the fragment shader. If the coordinates at index are 3-dimensional, it immediately emits a
+ * perspective divide into the fragment shader (xy / z) to convert them to 2D.
+ */
+ virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords, int index) = 0;
+
+
+ /** Returns a variable name that represents the position of the fragment in the FS. The position
+ is in device space (e.g. 0,0 is the top left and pixel centers are at half-integers). */
+ virtual const char* fragmentPosition() = 0;
+
+ /**
+ * Fragment procs with child procs should call these functions before/after calling emitCode
+ * on a child proc.
+ */
+ void onBeforeChildProcEmitCode();
+ void onAfterChildProcEmitCode();
+
+ const SkString& getMangleString() const { return fMangleString; }
+
+ bool hasCustomColorOutput() const { return fHasCustomColorOutput; }
+ bool hasSecondaryOutput() const { return fHasSecondaryOutput; }
+
+protected:
+ bool fHasCustomColorOutput;
+ bool fHasSecondaryOutput;
+
+private:
+ /*
+ * State that tracks which child proc in the proc tree is currently emitting code. This is
+ * used to update the fMangleString, which is used to mangle the names of uniforms and functions
+ * emitted by the proc. fSubstageIndices is a stack: its count indicates how many levels deep
+ * we are in the tree, and its second-to-last value is the index of the child proc at that
+ * level which is currently emitting code. For example, if fSubstageIndices = [3, 1, 2, 0], that
+ * means we're currently emitting code for the base proc's 3rd child's 1st child's 2nd child.
+ */
+ SkTArray<int> fSubstageIndices;
+
+ /*
+ * The mangle string is used to mangle the names of uniforms/functions emitted by the child
+ * procs so no duplicate uniforms/functions appear in the generated shader program. The mangle
+ * string is simply based on fSubstageIndices. For example, if fSubstageIndices = [3, 1, 2, 0],
+ * then the manglestring will be "_c3_c1_c2", and any uniform/function emitted by that proc will
+ * have "_c3_c1_c2" appended to its name, which can be interpreted as "base proc's 3rd child's
+ * 1st child's 2nd child".
+ */
+ SkString fMangleString;
+
+ friend class GrGLPathProcessor;
+
+ typedef GrGLSLShaderBuilder INHERITED;
+};
+
+/*
+ * Fragment processor's, in addition to all of the above, may need to use dst color so they use
+ * this builder to create their shader. Because this is the only shader builder the FP sees, we
+ * just call it FPShaderBuilder
+ */
+class GrGLSLXPFragmentBuilder : public GrGLSLFragmentBuilder {
+public:
+ GrGLSLXPFragmentBuilder(GrGLSLProgramBuilder* program) : INHERITED(program) {}
+
+ /** Returns the variable name that holds the color of the destination pixel. This may be nullptr if
+ no effect advertised that it will read the destination. */
+ virtual const char* dstColor() = 0;
+
+ /** Adds any necessary layout qualifiers in order to legalize the supplied blend equation with
+ this shader. It is only legal to call this method with an advanced blend equation, and only
+ if these equations are supported. */
+ virtual void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) = 0;
+
+private:
+ typedef GrGLSLFragmentBuilder INHERITED;
+};
+
+// TODO rename to Fragment Builder
+class GrGLSLFragmentShaderBuilder : public GrGLSLXPFragmentBuilder {
+public:
+ typedef uint8_t FragPosKey;
+
+ /** Returns a key for reading the fragment location. This should only be called if there is an
+ effect that will requires the fragment position. If the fragment position is not required,
+ the key is 0. */
+ static FragPosKey KeyForFragmentPosition(const GrRenderTarget* dst);
+
+ GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder* program, uint8_t fragPosKey);
+
+ // true public interface, defined explicitly in the abstract interfaces above
+ bool enableFeature(GLSLFeature) override;
+ virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords,
+ int index) override;
+ const char* fragmentPosition() override;
+ const char* dstColor() override;
+
+ void enableAdvancedBlendEquationIfNeeded(GrBlendEquation) override;
+
+private:
+ // Private public interface, used by GrGLProgramBuilder to build a fragment shader
+ void enableCustomOutput();
+ void enableSecondaryOutput();
+ const char* getPrimaryColorOutputName() const;
+ const char* getSecondaryColorOutputName() const;
+
+ // As GLProcessors emit code, there are some conditions we need to verify. We use the below
+ // state to track this. The reset call is called per processor emitted.
+ bool hasReadDstColor() const { return fHasReadDstColor; }
+ bool hasReadFragmentPosition() const { return fHasReadFragmentPosition; }
+ void reset() {
+ fHasReadDstColor = false;
+ fHasReadFragmentPosition = false;
+ }
+
+ static const char* DeclaredColorOutputName() { return "fsColorOut"; }
+ static const char* DeclaredSecondaryColorOutputName() { return "fsSecondaryColorOut"; }
+
+ /*
+ * An internal call for GrGLProgramBuilder to use to add varyings to the vertex shader
+ */
+ void addVarying(GrGLSLVarying*, GrSLPrecision);
+
+ void onFinalize() override;
+
+ /**
+ * Features that should only be enabled by GrGLSLFragmentShaderBuilder itself.
+ */
+ enum GLSLPrivateFeature {
+ kFragCoordConventions_GLSLPrivateFeature = kLastGLSLFeature + 1,
+ kBlendEquationAdvanced_GLSLPrivateFeature,
+ kBlendFuncExtended_GLSLPrivateFeature,
+ kLastGLSLPrivateFeature = kBlendFuncExtended_GLSLPrivateFeature
+ };
+
+ // Interpretation of FragPosKey when generating code
+ enum {
+ kNoFragPosRead_FragPosKey = 0, // The fragment positition will not be needed.
+ kTopLeftFragPosRead_FragPosKey = 0x1,// Read frag pos relative to top-left.
+ kBottomLeftFragPosRead_FragPosKey = 0x2,// Read frag pos relative to bottom-left.
+ };
+
+ static const char* kDstTextureColorName;
+
+ bool fSetupFragPosition;
+ bool fTopLeftFragPosRead;
+ int fCustomColorOutputIndex;
+
+ // some state to verify shaders and effects are consistent, this is reset between effects by
+ // the program creator
+ bool fHasReadDstColor;
+ bool fHasReadFragmentPosition;
+
+ friend class GrGLProgramBuilder;
+
+ typedef GrGLSLXPFragmentBuilder INHERITED;
+};
+
+#endif
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrGLSLGeometryShaderBuilder.h"
+#include "GrGLSLProgramBuilder.h"
+
+GrGLSLGeometryBuilder::GrGLSLGeometryBuilder(GrGLSLProgramBuilder* program)
+ : INHERITED(program) {
+
+}
+
+void GrGLSLGeometryBuilder::addVarying(const char* name,
+ GrSLPrecision precision,
+ GrGLSLVarying* v) {
+ // if we have a GS take each varying in as an array
+ // and output as non-array.
+ if (v->vsVarying()) {
+ fInputs.push_back();
+ fInputs.back().setType(v->fType);
+ fInputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingIn_TypeModifier);
+ fInputs.back().setPrecision(precision);
+ fInputs.back().setUnsizedArray();
+ *fInputs.back().accessName() = v->fVsOut;
+ v->fGsIn = v->fVsOut;
+ }
+
+ if (v->fsVarying()) {
+ fOutputs.push_back();
+ fOutputs.back().setType(v->fType);
+ fOutputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingOut_TypeModifier);
+ fOutputs.back().setPrecision(precision);
+ fProgramBuilder->nameVariable(fOutputs.back().accessName(), 'g', name);
+ v->fGsOut = fOutputs.back().getName().c_str();
+ }
+}
+
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrGLSLGeometryShaderBuilder_DEFINED
+#define GrGLSLGeometryShaderBuilder_DEFINED
+
+#include "GrGLSLShaderBuilder.h"
+
+class GrGLSLVarying;
+
+class GrGLSLGeometryBuilder : public GrGLSLShaderBuilder {
+public:
+ GrGLSLGeometryBuilder(GrGLSLProgramBuilder* program);
+
+private:
+ /*
+ * an internal call for GrGLFullProgramBuilder to add varyings
+ */
+ void addVarying(const char* name, GrSLPrecision precision, GrGLSLVarying*);
+
+ void onFinalize() override {}
+
+ friend class GrGLProgramBuilder;
+
+ typedef GrGLSLShaderBuilder INHERITED;
+};
+
+#endif
#include "GrGeometryProcessor.h"
#include "GrGpu.h"
-#include "gl/builders/GrGLFragmentShaderBuilder.h"
-#include "gl/builders/GrGLGeometryShaderBuilder.h"
-#include "gl/builders/GrGLVertexShaderBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLGeometryShaderBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLVertexShaderBuilder.h"
class GrGLSLCaps;
class GrGLSLShaderVar;
+// Enough precision to represent 1 / 2048 accurately in printf
+#define GR_SIGNIFICANT_POW2_DECIMAL_DIG 11
+
class GrGLSLUniformBuilder {
public:
enum ShaderVisibility {
const char* fGsOut;
const char* fFsIn;
- friend class GrGLVertexBuilder;
- friend class GrGLGeometryBuilder;
- friend class GrGLXferBuilder;
- friend class GrGLFragmentShaderBuilder;
+ friend class GrGLSLVertexBuilder;
+ friend class GrGLSLGeometryBuilder;
+ friend class GrGLSLXferBuilder;
+ friend class GrGLSLFragmentShaderBuilder;
};
struct GrGLSLVertToFrag : public GrGLSLVarying {
GrSLPrecision fsPrecision = kDefault_GrSLPrecision) = 0;
// TODO rename getFragmentBuilder
- virtual GrGLFragmentBuilder* getFragmentShaderBuilder() = 0;
- virtual GrGLVertexBuilder* getVertexShaderBuilder() = 0;
+ virtual GrGLSLFragmentBuilder* getFragmentShaderBuilder() = 0;
+ virtual GrGLSLVertexBuilder* getVertexShaderBuilder() = 0;
/*
* *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
/* a specializations for FPs. Lets the user add uniforms and FS code */
class GrGLSLFPBuilder : public virtual GrGLSLUniformBuilder {
public:
- virtual GrGLFragmentBuilder* getFragmentShaderBuilder() = 0;
+ virtual GrGLSLFragmentBuilder* getFragmentShaderBuilder() = 0;
/*
* *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
/* a specializations for XPs. Lets the user add uniforms and FS code */
class GrGLSLXPBuilder : public virtual GrGLSLUniformBuilder {
public:
- virtual GrGLXPFragmentBuilder* getFragmentShaderBuilder() = 0;
+ virtual GrGLSLXPFragmentBuilder* getFragmentShaderBuilder() = 0;
/*
* *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
public:
typedef GrGpu::DrawArgs DrawArgs;
- GrGLXPFragmentBuilder* getFragmentShaderBuilder() override { return &fFS; }
- GrGLVertexBuilder* getVertexShaderBuilder() override { return &fVS; }
+ GrGLSLXPFragmentBuilder* getFragmentShaderBuilder() override { return &fFS; }
+ GrGLSLVertexBuilder* getVertexShaderBuilder() override { return &fVS; }
// Handles for program uniforms (other than per-effect uniforms)
struct BuiltinUniformHandles {
// number of each input/output type in a single allocation block, used by many builders
static const int kVarsPerBlock;
- GrGLVertexBuilder fVS;
- GrGLGeometryBuilder fGS;
- GrGLFragmentShaderBuilder fFS;
+ GrGLSLVertexBuilder fVS;
+ GrGLSLGeometryBuilder fGS;
+ GrGLSLFragmentShaderBuilder fFS;
int fStageIndex;
BuiltinUniformHandles fUniformHandles;
private:
virtual void onAppendUniformDecls(ShaderVisibility visibility, SkString* out) const = 0;
- friend class GrGLShaderBuilder;
- friend class GrGLVertexBuilder;
- friend class GrGLFragmentShaderBuilder;
- friend class GrGLGeometryBuilder;
+ friend class GrGLSLShaderBuilder;
+ friend class GrGLSLVertexBuilder;
+ friend class GrGLSLFragmentShaderBuilder;
+ friend class GrGLSLGeometryBuilder;
};
#endif
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "glsl/GrGLSLShaderBuilder.h"
+#include "glsl/GrGLSLCaps.h"
+#include "glsl/GrGLSLShaderVar.h"
+#include "glsl/GrGLSLTextureSampler.h"
+#include "glsl/GrGLSLProgramBuilder.h"
+
+static void map_swizzle(const char* swizzleMap, const char* swizzle, char* mangledSwizzle) {
+ int i;
+ for (i = 0; '\0' != swizzle[i]; ++i) {
+ switch (swizzle[i]) {
+ case 'r':
+ mangledSwizzle[i] = swizzleMap[0];
+ break;
+ case 'g':
+ mangledSwizzle[i] = swizzleMap[1];
+ break;
+ case 'b':
+ mangledSwizzle[i] = swizzleMap[2];
+ break;
+ case 'a':
+ mangledSwizzle[i] = swizzleMap[3];
+ break;
+ default:
+ SkFAIL("Unsupported swizzle");
+ }
+ }
+ mangledSwizzle[i] ='\0';
+}
+
+static void append_texture_lookup(SkString* out,
+ const GrGLSLCaps* glslCaps,
+ const char* samplerName,
+ const char* coordName,
+ GrPixelConfig config,
+ const char* swizzle,
+ GrSLType varyingType = kVec2f_GrSLType) {
+ SkASSERT(coordName);
+
+ out->appendf("%s(%s, %s)",
+ GrGLSLTexture2DFunctionName(varyingType, glslCaps->generation()),
+ samplerName,
+ coordName);
+
+ char mangledSwizzle[5];
+
+ // This refers to any swizzling we may need to get from some backend internal format to the
+ // format used in GrPixelConfig. Some backends will automatically do the sizzling for us.
+ if (glslCaps->mustSwizzleInShader()) {
+ const char* swizzleMap = glslCaps->getSwizzleMap(config);
+ // if the map is simply 'rgba' then we don't need to do any manual swizzling to get us to
+ // a GrPixelConfig format.
+ if (memcmp(swizzleMap, "rgba", 4)) {
+ // Manually 'swizzle' the swizzle using our mapping
+ map_swizzle(swizzleMap, swizzle, mangledSwizzle);
+ swizzle = mangledSwizzle;
+ }
+ }
+
+ // For shader prettiness we omit the swizzle rather than appending ".rgba".
+ if (memcmp(swizzle, "rgba", 4)) {
+ out->appendf(".%s", swizzle);
+ }
+}
+
+GrGLSLShaderBuilder::GrGLSLShaderBuilder(GrGLSLProgramBuilder* program)
+ : fProgramBuilder(program)
+ , fInputs(GrGLSLProgramBuilder::kVarsPerBlock)
+ , fOutputs(GrGLSLProgramBuilder::kVarsPerBlock)
+ , fFeaturesAddedMask(0)
+ , fCodeIndex(kCode)
+ , fFinalized(false) {
+ // We push back some dummy pointers which will later become our header
+ for (int i = 0; i <= kCode; i++) {
+ fShaderStrings.push_back();
+ fCompilerStrings.push_back(nullptr);
+ fCompilerStringLengths.push_back(0);
+ }
+
+ this->main() = "void main() {";
+}
+
+void GrGLSLShaderBuilder::declAppend(const GrGLSLShaderVar& var) {
+ SkString tempDecl;
+ var.appendDecl(fProgramBuilder->glslCaps(), &tempDecl);
+ this->codeAppendf("%s;", tempDecl.c_str());
+}
+
+void GrGLSLShaderBuilder::emitFunction(GrSLType returnType,
+ const char* name,
+ int argCnt,
+ const GrGLSLShaderVar* args,
+ const char* body,
+ SkString* outName) {
+ this->functions().append(GrGLSLTypeString(returnType));
+ fProgramBuilder->nameVariable(outName, '\0', name);
+ this->functions().appendf(" %s", outName->c_str());
+ this->functions().append("(");
+ for (int i = 0; i < argCnt; ++i) {
+ args[i].appendDecl(fProgramBuilder->glslCaps(), &this->functions());
+ if (i < argCnt - 1) {
+ this->functions().append(", ");
+ }
+ }
+ this->functions().append(") {\n");
+ this->functions().append(body);
+ this->functions().append("}\n\n");
+}
+
+void GrGLSLShaderBuilder::appendTextureLookup(SkString* out,
+ const GrGLSLTextureSampler& sampler,
+ const char* coordName,
+ GrSLType varyingType) const {
+ append_texture_lookup(out,
+ fProgramBuilder->glslCaps(),
+ fProgramBuilder->getUniformCStr(sampler.fSamplerUniform),
+ coordName,
+ sampler.config(),
+ sampler.swizzle(),
+ varyingType);
+}
+
+void GrGLSLShaderBuilder::appendTextureLookup(const GrGLSLTextureSampler& sampler,
+ const char* coordName,
+ GrSLType varyingType) {
+ this->appendTextureLookup(&this->code(), sampler, coordName, varyingType);
+}
+
+void GrGLSLShaderBuilder::appendTextureLookupAndModulate(const char* modulation,
+ const GrGLSLTextureSampler& sampler,
+ const char* coordName,
+ GrSLType varyingType) {
+ SkString lookup;
+ this->appendTextureLookup(&lookup, sampler, coordName, varyingType);
+ this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str());
+}
+
+void GrGLSLShaderBuilder::addFeature(uint32_t featureBit, const char* extensionName) {
+ if (!(featureBit & fFeaturesAddedMask)) {
+ this->extensions().appendf("#extension %s: require\n", extensionName);
+ fFeaturesAddedMask |= featureBit;
+ }
+}
+
+void GrGLSLShaderBuilder::appendDecls(const VarArray& vars, SkString* out) const {
+ for (int i = 0; i < vars.count(); ++i) {
+ vars[i].appendDecl(fProgramBuilder->glslCaps(), out);
+ out->append(";\n");
+ }
+}
+
+void GrGLSLShaderBuilder::addLayoutQualifier(const char* param, InterfaceQualifier interface) {
+ SkASSERT(fProgramBuilder->glslCaps()->generation() >= k330_GrGLSLGeneration ||
+ fProgramBuilder->glslCaps()->mustEnableAdvBlendEqs());
+ fLayoutParams[interface].push_back() = param;
+}
+
+void GrGLSLShaderBuilder::compileAndAppendLayoutQualifiers() {
+ static const char* interfaceQualifierNames[] = {
+ "out"
+ };
+
+ for (int interface = 0; interface <= kLastInterfaceQualifier; ++interface) {
+ const SkTArray<SkString>& params = fLayoutParams[interface];
+ if (params.empty()) {
+ continue;
+ }
+ this->layoutQualifiers().appendf("layout(%s", params[0].c_str());
+ for (int i = 1; i < params.count(); ++i) {
+ this->layoutQualifiers().appendf(", %s", params[i].c_str());
+ }
+ this->layoutQualifiers().appendf(") %s;\n", interfaceQualifierNames[interface]);
+ }
+
+ GR_STATIC_ASSERT(0 == GrGLSLShaderBuilder::kOut_InterfaceQualifier);
+ GR_STATIC_ASSERT(SK_ARRAY_COUNT(interfaceQualifierNames) == kLastInterfaceQualifier + 1);
+}
+
+void GrGLSLShaderBuilder::finalize(uint32_t visibility) {
+ SkASSERT(!fFinalized);
+ this->versionDecl() = fProgramBuilder->glslCaps()->versionDeclString();
+ this->compileAndAppendLayoutQualifiers();
+ SkASSERT(visibility);
+ fProgramBuilder->appendUniformDecls((GrGLSLProgramBuilder::ShaderVisibility) visibility,
+ &this->uniforms());
+ this->appendDecls(fInputs, &this->inputs());
+ // We should not have any outputs in the fragment shader when using version 1.10
+ SkASSERT(GrGLSLProgramBuilder::kFragment_Visibility != visibility ||
+ k110_GrGLSLGeneration != fProgramBuilder->glslCaps()->generation() ||
+ fOutputs.empty());
+ this->appendDecls(fOutputs, &this->outputs());
+ this->onFinalize();
+ // append the 'footer' to code
+ this->code().append("}");
+
+ for (int i = 0; i <= fCodeIndex; i++) {
+ fCompilerStrings[i] = fShaderStrings[i].c_str();
+ fCompilerStringLengths[i] = (int)fShaderStrings[i].size();
+ }
+
+ fFinalized = true;
+}
+
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrGLSLShaderBuilder_DEFINED
+#define GrGLSLShaderBuilder_DEFINED
+
+#include "GrAllocator.h"
+#include "glsl/GrGLSLShaderVar.h"
+#include "SkTDArray.h"
+
+#include <stdarg.h>
+
+class GrGLSLProgramBuilder;
+class GrGLSLTextureSampler;
+
+/**
+ base class for all shaders builders
+*/
+class GrGLSLShaderBuilder {
+public:
+ GrGLSLShaderBuilder(GrGLSLProgramBuilder* program);
+ virtual ~GrGLSLShaderBuilder() {}
+
+ void addInput(const GrGLSLShaderVar& input) { fInputs.push_back(input); }
+ void addOutput(const GrGLSLShaderVar& output) { fOutputs.push_back(output); }
+
+ /*
+ * We put texture lookups in the base class because it is TECHNICALLY possible to do texture
+ * lookups in any kind of shader. However, for the time being using these calls on non-fragment
+ * shaders will result in a shader compilation error as texture sampler uniforms are only
+ * visible to the fragment shader. It would not be hard to change this behavior, if someone
+ * actually wants to do texture lookups in a non-fragment shader
+ *
+ * TODO if append texture lookup is used on a non-fragment shader, sampler uniforms should be
+ * made visible to that shaders
+ */
+ /** Appends a 2D texture sample with projection if necessary. coordType must either be Vec2f or
+ Vec3f. The latter is interpreted as projective texture coords. The vec length and swizzle
+ order of the result depends on the GrTextureAccess associated with the GrGLSLTextureSampler.
+ */
+ void appendTextureLookup(SkString* out,
+ const GrGLSLTextureSampler&,
+ const char* coordName,
+ GrSLType coordType = kVec2f_GrSLType) const;
+
+ /** Version of above that appends the result to the fragment shader code instead.*/
+ void appendTextureLookup(const GrGLSLTextureSampler&,
+ const char* coordName,
+ GrSLType coordType = kVec2f_GrSLType);
+
+
+ /** Does the work of appendTextureLookup and modulates the result by modulation. The result is
+ always a vec4. modulation and the swizzle specified by GrGLSLTextureSampler must both be
+ vec4 or float. If modulation is "" or nullptr it this function acts as though
+ appendTextureLookup were called. */
+ void appendTextureLookupAndModulate(const char* modulation,
+ const GrGLSLTextureSampler&,
+ const char* coordName,
+ GrSLType coordType = kVec2f_GrSLType);
+
+ /**
+ * Called by GrGLProcessors to add code to one of the shaders.
+ */
+ void codeAppendf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
+ va_list args;
+ va_start(args, format);
+ this->code().appendVAList(format, args);
+ va_end(args);
+ }
+
+ void codeAppend(const char* str) { this->code().append(str); }
+
+ void codePrependf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
+ va_list args;
+ va_start(args, format);
+ this->code().prependVAList(format, args);
+ va_end(args);
+ }
+
+ /**
+ * Appends a variable declaration to one of the shaders
+ */
+ void declAppend(const GrGLSLShaderVar& var);
+
+ /** Emits a helper function outside of main() in the fragment shader. */
+ void emitFunction(GrSLType returnType,
+ const char* name,
+ int argCnt,
+ const GrGLSLShaderVar* args,
+ const char* body,
+ SkString* outName);
+
+ /*
+ * Combines the various parts of the shader to create a single finalized shader string.
+ */
+ void finalize(uint32_t visibility);
+
+ /*
+ * Get parent builder for adding uniforms
+ */
+ GrGLSLProgramBuilder* getProgramBuilder() { return fProgramBuilder; }
+
+ /**
+ * Helper for begining and ending a block in the shader code.
+ */
+ class ShaderBlock {
+ public:
+ ShaderBlock(GrGLSLShaderBuilder* builder) : fBuilder(builder) {
+ SkASSERT(builder);
+ fBuilder->codeAppend("{");
+ }
+
+ ~ShaderBlock() {
+ fBuilder->codeAppend("}");
+ }
+ private:
+ GrGLSLShaderBuilder* fBuilder;
+ };
+
+protected:
+ typedef GrTAllocator<GrGLSLShaderVar> VarArray;
+ void appendDecls(const VarArray& vars, SkString* out) const;
+
+ /*
+ * A general function which enables an extension in a shader if the feature bit is not present
+ */
+ void addFeature(uint32_t featureBit, const char* extensionName);
+
+ enum InterfaceQualifier {
+ kOut_InterfaceQualifier,
+ kLastInterfaceQualifier = kOut_InterfaceQualifier
+ };
+
+ /*
+ * A low level function to build default layout qualifiers.
+ *
+ * e.g. layout(param1, param2, ...) out;
+ *
+ * GLSL allows default layout qualifiers for in, out, and uniform.
+ */
+ void addLayoutQualifier(const char* param, InterfaceQualifier);
+
+ void compileAndAppendLayoutQualifiers();
+
+ void nextStage() {
+ fShaderStrings.push_back();
+ fCompilerStrings.push_back(this->code().c_str());
+ fCompilerStringLengths.push_back((int)this->code().size());
+ fCodeIndex++;
+ }
+
+ SkString& versionDecl() { return fShaderStrings[kVersionDecl]; }
+ SkString& extensions() { return fShaderStrings[kExtensions]; }
+ SkString& precisionQualifier() { return fShaderStrings[kPrecisionQualifier]; }
+ SkString& layoutQualifiers() { return fShaderStrings[kLayoutQualifiers]; }
+ SkString& uniforms() { return fShaderStrings[kUniforms]; }
+ SkString& inputs() { return fShaderStrings[kInputs]; }
+ SkString& outputs() { return fShaderStrings[kOutputs]; }
+ SkString& functions() { return fShaderStrings[kFunctions]; }
+ SkString& main() { return fShaderStrings[kMain]; }
+ SkString& code() { return fShaderStrings[fCodeIndex]; }
+
+ virtual void onFinalize() = 0;
+
+ enum {
+ kVersionDecl,
+ kExtensions,
+ kPrecisionQualifier,
+ kLayoutQualifiers,
+ kUniforms,
+ kInputs,
+ kOutputs,
+ kFunctions,
+ kMain,
+ kCode,
+ };
+
+ GrGLSLProgramBuilder* fProgramBuilder;
+ SkSTArray<kCode, const char*, true> fCompilerStrings;
+ SkSTArray<kCode, int, true> fCompilerStringLengths;
+ SkSTArray<kCode, SkString> fShaderStrings;
+ SkString fCode;
+ SkString fFunctions;
+ SkString fExtensions;
+
+ VarArray fInputs;
+ VarArray fOutputs;
+ uint32_t fFeaturesAddedMask;
+ SkSTArray<1, SkString> fLayoutParams[kLastInterfaceQualifier + 1];
+ int fCodeIndex;
+ bool fFinalized;
+
+ friend class GrGLProgramBuilder;
+ friend class GrGLPathProgramBuilder; // to access fInputs.
+};
+#endif
GrPixelConfig fConfig;
char fSwizzle[5];
- friend class GrGLShaderBuilder;
+ friend class GrGLSLShaderBuilder;
};
#endif
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "GrGLSLVertexShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
+
+GrGLSLVertexBuilder::GrGLSLVertexBuilder(GrGLSLProgramBuilder* program)
+ : INHERITED(program)
+ , fRtAdjustName(nullptr) {
+}
+
+void GrGLSLVertexBuilder::addVarying(const char* name, GrSLPrecision precision, GrGLSLVarying* v) {
+ fOutputs.push_back();
+ fOutputs.back().setType(v->fType);
+ fOutputs.back().setTypeModifier(GrGLSLShaderVar::kVaryingOut_TypeModifier);
+ fOutputs.back().setPrecision(precision);
+ fProgramBuilder->nameVariable(fOutputs.back().accessName(), 'v', name);
+ v->fVsOut = fOutputs.back().getName().c_str();
+}
+
+void GrGLSLVertexBuilder::emitAttributes(const GrGeometryProcessor& gp) {
+ int vaCount = gp.numAttribs();
+ for (int i = 0; i < vaCount; i++) {
+ this->addAttribute(&gp.getAttrib(i));
+ }
+ return;
+}
+
+void GrGLSLVertexBuilder::transformToNormalizedDeviceSpace(const GrShaderVar& posVar) {
+ SkASSERT(!fRtAdjustName);
+
+ GrSLPrecision precision = kDefault_GrSLPrecision;
+ if (fProgramBuilder->glslCaps()->forceHighPrecisionNDSTransform()) {
+ precision = kHigh_GrSLPrecision;
+ }
+
+ // setup RT Uniform
+ fProgramBuilder->fUniformHandles.fRTAdjustmentUni =
+ fProgramBuilder->addUniform(GrGLSLProgramBuilder::kVertex_Visibility,
+ kVec4f_GrSLType, precision,
+ fProgramBuilder->rtAdjustment(),
+ &fRtAdjustName);
+ if (this->getProgramBuilder()->desc().header().fSnapVerticesToPixelCenters) {
+ if (kVec3f_GrSLType == posVar.getType()) {
+ const char* p = posVar.c_str();
+ this->codeAppendf("{vec2 _posTmp = vec2(%s.x/%s.z, %s.y/%s.z);", p, p, p, p);
+ } else {
+ SkASSERT(kVec2f_GrSLType == posVar.getType());
+ this->codeAppendf("{vec2 _posTmp = %s;", posVar.c_str());
+ }
+ this->codeAppendf("_posTmp = floor(_posTmp) + vec2(0.5, 0.5);"
+ "gl_Position = vec4(_posTmp.x * %s.x + %s.y,"
+ "_posTmp.y * %s.z + %s.w, 0, 1);}",
+ fRtAdjustName, fRtAdjustName, fRtAdjustName, fRtAdjustName);
+ } else if (kVec3f_GrSLType == posVar.getType()) {
+ this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy), dot(%s.yz, %s.zw), 0, %s.z);",
+ posVar.c_str(), fRtAdjustName,
+ posVar.c_str(), fRtAdjustName,
+ posVar.c_str());
+ } else {
+ SkASSERT(kVec2f_GrSLType == posVar.getType());
+ this->codeAppendf("gl_Position = vec4(%s.x * %s.x + %s.y, %s.y * %s.z + %s.w, 0, 1);",
+ posVar.c_str(), fRtAdjustName, fRtAdjustName,
+ posVar.c_str(), fRtAdjustName, fRtAdjustName);
+ }
+ // We could have the GrGeometryProcessor do this, but its just easier to have it performed
+ // here. If we ever need to set variable pointsize, then we can reinvestigate
+ this->codeAppend("gl_PointSize = 1.0;");
+}
+
+bool GrGLSLVertexBuilder::addAttribute(const GrShaderVar& var) {
+ SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier());
+ for (int i = 0; i < fInputs.count(); ++i) {
+ const GrGLSLShaderVar& attr = fInputs[i];
+ // if attribute already added, don't add it again
+ if (attr.getName().equals(var.getName())) {
+ return false;
+ }
+ }
+ fInputs.push_back(var);
+ return true;
+}
+
--- /dev/null
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrGLSLVertexShader_DEFINED
+#define GrGLSLVertexShader_DEFINED
+
+#include "GrGLSLShaderBuilder.h"
+#include "GrGeometryProcessor.h"
+
+class GrGLSLVarying;
+
+class GrGLSLVertexBuilder : public GrGLSLShaderBuilder {
+public:
+ GrGLSLVertexBuilder(GrGLSLProgramBuilder* program);
+
+ void transformToNormalizedDeviceSpace(const GrShaderVar& posVar);
+ void emitAttributes(const GrGeometryProcessor& gp);
+
+ void addAttribute(const GrGeometryProcessor::Attribute* attr) {
+ this->addAttribute(GrShaderVar(attr->fName,
+ GrVertexAttribTypeToSLType(attr->fType),
+ GrShaderVar::kAttribute_TypeModifier,
+ GrShaderVar::kNonArray,
+ attr->fPrecision));
+ }
+
+private:
+ /*
+ * Internal call for GrGLProgramBuilder.addVarying
+ */
+ void addVarying(const char* name, GrSLPrecision, GrGLSLVarying*);
+
+ // an internal call which checks for uniquness of a var before adding it to the list of inputs
+ bool addAttribute(const GrShaderVar& var);
+
+ void onFinalize() override {}
+
+ const char* fRtAdjustName;
+
+ friend class GrGLProgramBuilder;
+
+ typedef GrGLSLShaderBuilder INHERITED;
+};
+
+#endif
#include "gl/GrGLFragmentProcessor.h"
#include "gl/GrGLGpu.h"
-#include "gl/GrGLPathRendering.h"
-#include "gl/builders/GrGLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLProgramBuilder.h"
/*
* A dummy processor which just tries to insert a massive key and verify that it can retrieve the
virtual void emitCode(EmitArgs& args) override {
// pass through
- GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
+ GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
if (args.fInputColor) {
fsBuilder->codeAppendf("%s = %s;\n", args.fOutputColor, args.fInputColor);
} else {