aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrDefaultGeoProcFactory.cpp33
-rw-r--r--src/gpu/GrFragmentProcessor.cpp11
-rw-r--r--src/gpu/GrOvalRenderer.cpp37
-rw-r--r--src/gpu/GrPathProcessor.cpp14
-rw-r--r--src/gpu/batches/GrAAConvexPathRenderer.cpp15
-rw-r--r--src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp1
-rw-r--r--src/gpu/effects/GrBezierEffect.cpp61
-rw-r--r--src/gpu/effects/GrBicubicEffect.cpp20
-rw-r--r--src/gpu/effects/GrBitmapTextGeoProc.cpp13
-rw-r--r--src/gpu/effects/GrConfigConversionEffect.cpp1
-rw-r--r--src/gpu/effects/GrConstColorProcessor.cpp10
-rw-r--r--src/gpu/effects/GrConvexPolyEffect.cpp24
-rw-r--r--src/gpu/effects/GrConvolutionEffect.cpp27
-rw-r--r--src/gpu/effects/GrCoverageSetOpXP.cpp6
-rw-r--r--src/gpu/effects/GrCustomXfermode.cpp6
-rw-r--r--src/gpu/effects/GrDashingEffect.cpp22
-rw-r--r--src/gpu/effects/GrDisableColorXP.cpp1
-rw-r--r--src/gpu/effects/GrDistanceFieldGeoProc.cpp58
-rw-r--r--src/gpu/effects/GrDitherEffect.cpp1
-rw-r--r--src/gpu/effects/GrMatrixConvolutionEffect.cpp43
-rw-r--r--src/gpu/effects/GrOvalEffect.cpp18
-rw-r--r--src/gpu/effects/GrPorterDuffXferProcessor.cpp6
-rw-r--r--src/gpu/effects/GrRRectEffect.cpp37
-rw-r--r--src/gpu/effects/GrSimpleTextureEffect.cpp1
-rw-r--r--src/gpu/effects/GrTextureDomain.cpp14
-rw-r--r--src/gpu/effects/GrTextureDomain.h2
-rw-r--r--src/gpu/effects/GrXfermodeFragmentProcessor.cpp2
-rw-r--r--src/gpu/effects/GrYUVtoRGBEffect.cpp10
-rw-r--r--src/gpu/gl/GrGLProgram.h3
-rw-r--r--src/gpu/gl/GrGLProgramDataManager.cpp5
-rw-r--r--src/gpu/gl/GrGLProgramDataManager.h1
-rw-r--r--src/gpu/gl/GrGLUniformHandler.cpp90
-rw-r--r--src/gpu/gl/GrGLUniformHandler.h61
-rw-r--r--src/gpu/gl/GrGLVaryingHandler.h2
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.cpp101
-rw-r--r--src/gpu/gl/builders/GrGLProgramBuilder.h29
-rw-r--r--src/gpu/glsl/GrGLSLFragmentProcessor.cpp6
-rw-r--r--src/gpu/glsl/GrGLSLFragmentProcessor.h13
-rw-r--r--src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp9
-rw-r--r--src/gpu/glsl/GrGLSLGeometryProcessor.cpp33
-rw-r--r--src/gpu/glsl/GrGLSLGeometryProcessor.h20
-rw-r--r--src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp18
-rw-r--r--src/gpu/glsl/GrGLSLPrimitiveProcessor.h15
-rw-r--r--src/gpu/glsl/GrGLSLProgramBuilder.cpp23
-rw-r--r--src/gpu/glsl/GrGLSLProgramBuilder.h139
-rw-r--r--src/gpu/glsl/GrGLSLShaderBuilder.cpp5
-rw-r--r--src/gpu/glsl/GrGLSLUniformHandler.h79
-rw-r--r--src/gpu/glsl/GrGLSLVertexShaderBuilder.cpp9
-rw-r--r--src/gpu/glsl/GrGLSLVertexShaderBuilder.h3
-rw-r--r--src/gpu/glsl/GrGLSLXferProcessor.cpp27
-rw-r--r--src/gpu/glsl/GrGLSLXferProcessor.h17
51 files changed, 662 insertions, 540 deletions
diff --git a/src/gpu/GrDefaultGeoProcFactory.cpp b/src/gpu/GrDefaultGeoProcFactory.cpp
index 85339ea9b5..25da4dcae9 100644
--- a/src/gpu/GrDefaultGeoProcFactory.cpp
+++ b/src/gpu/GrDefaultGeoProcFactory.cpp
@@ -10,9 +10,9 @@
#include "GrInvariantOutput.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLGeometryProcessor.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLVertexShaderBuilder.h"
#include "glsl/GrGLSLVarying.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLUtil.h"
/*
@@ -64,10 +64,10 @@ public:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>();
- GrGLSLGPBuilder* pb = args.fPB;
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// emit attributes
varyingHandler->emitAttributes(gp);
@@ -77,13 +77,14 @@ public:
if (gp.hasVertexColor()) {
varyingHandler->addPassThroughAttribute(gp.inColor(), args.fOutputColor);
} else {
- this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUniform);
+ this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
+ &fColorUniform);
}
}
// Setup position
- this->setupPosition(pb,
- vertBuilder,
+ this->setupPosition(vertBuilder,
+ uniformHandler,
gpArgs,
gp.inPosition()->fName,
gp.viewMatrix(),
@@ -91,9 +92,9 @@ public:
if (gp.hasExplicitLocalCoords()) {
// emit transforms with explicit local coords
- this->emitTransforms(pb,
- vertBuilder,
+ this->emitTransforms(vertBuilder,
varyingHandler,
+ uniformHandler,
gpArgs->fPositionVar,
gp.inLocalCoords()->fName,
gp.localMatrix(),
@@ -101,17 +102,16 @@ public:
args.fTransformsOut);
} else if(gp.hasTransformedLocalCoords()) {
// transforms have already been applied to vertex attributes on the cpu
- this->emitTransforms(pb,
- vertBuilder,
+ this->emitTransforms(vertBuilder,
varyingHandler,
gp.inLocalCoords()->fName,
args.fTransformsIn,
args.fTransformsOut);
} else {
// emit transforms with position
- this->emitTransforms(pb,
- vertBuilder,
+ this->emitTransforms(vertBuilder,
varyingHandler,
+ uniformHandler,
gpArgs->fPositionVar,
gp.inPosition()->fName,
gp.localMatrix(),
@@ -129,11 +129,12 @@ public:
fragBuilder->codeAppendf("%s = vec4(1);", args.fOutputCoverage);
} else {
const char* fragCoverage;
- fCoverageUniform = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType,
- kDefault_GrSLPrecision,
- "Coverage",
- &fragCoverage);
+ fCoverageUniform = uniformHandler->addUniform(
+ GrGLSLUniformHandler::kFragment_Visibility,
+ kFloat_GrSLType,
+ kDefault_GrSLPrecision,
+ "Coverage",
+ &fragCoverage);
fragBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, fragCoverage);
}
}
diff --git a/src/gpu/GrFragmentProcessor.cpp b/src/gpu/GrFragmentProcessor.cpp
index 4cf2e73099..f05b7aa084 100644
--- a/src/gpu/GrFragmentProcessor.cpp
+++ b/src/gpu/GrFragmentProcessor.cpp
@@ -8,10 +8,12 @@
#include "GrFragmentProcessor.h"
#include "GrCoordTransform.h"
+#include "GrInvariantOutput.h"
+#include "GrProcOptInfo.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "effects/GrConstColorProcessor.h"
#include "effects/GrXfermodeFragmentProcessor.h"
@@ -226,9 +228,10 @@ const GrFragmentProcessor* GrFragmentProcessor::OverrideInput(const GrFragmentPr
GLFP() : fHaveSetColor(false) {}
void emitCode(EmitArgs& args) override {
const char* colorName;
- fColorUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec4f_GrSLType, kDefault_GrSLPrecision,
- "Color", &colorName);
+ fColorUni = args.fUniformHandler->addUniform(
+ GrGLSLUniformHandler::kFragment_Visibility,
+ kVec4f_GrSLType, kDefault_GrSLPrecision,
+ "Color", &colorName);
this->emitChild(0, colorName, args);
}
diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp
index e13c0d11e4..3862900d4c 100644
--- a/src/gpu/GrOvalRenderer.cpp
+++ b/src/gpu/GrOvalRenderer.cpp
@@ -23,10 +23,10 @@
#include "effects/GrRRectEffect.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLGeometryProcessor.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
#include "glsl/GrGLSLVarying.h"
#include "glsl/GrGLSLVertexShaderBuilder.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLUtil.h"
// TODO(joshualitt) - Break this file up during GrBatch post implementation cleanup
@@ -98,9 +98,9 @@ public:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
const CircleEdgeEffect& ce = args.fGP.cast<CircleEdgeEffect>();
- GrGLSLGPBuilder* pb = args.fPB;
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// emit attributes
varyingHandler->emitAttributes(ce);
@@ -112,16 +112,17 @@ public:
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
// setup pass through color
if (!ce.colorIgnored()) {
- this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUniform);
+ this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
+ &fColorUniform);
}
// Setup position
- this->setupPosition(pb, vertBuilder, gpArgs, ce.inPosition()->fName);
+ this->setupPosition(vertBuilder, gpArgs, ce.inPosition()->fName);
// emit transforms
- this->emitTransforms(args.fPB,
- vertBuilder,
+ this->emitTransforms(vertBuilder,
varyingHandler,
+ uniformHandler,
gpArgs->fPositionVar,
ce.inPosition()->fName,
ce.localMatrix(),
@@ -254,9 +255,9 @@ public:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
const EllipseEdgeEffect& ee = args.fGP.cast<EllipseEdgeEffect>();
- GrGLSLGPBuilder* pb = args.fPB;
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// emit attributes
varyingHandler->emitAttributes(ee);
@@ -274,16 +275,17 @@ public:
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
// setup pass through color
if (!ee.colorIgnored()) {
- this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUniform);
+ this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
+ &fColorUniform);
}
// Setup position
- this->setupPosition(pb, vertBuilder, gpArgs, ee.inPosition()->fName);
+ this->setupPosition(vertBuilder, gpArgs, ee.inPosition()->fName);
// emit transforms
- this->emitTransforms(args.fPB,
- vertBuilder,
+ this->emitTransforms(vertBuilder,
varyingHandler,
+ uniformHandler,
gpArgs->fPositionVar,
ee.inPosition()->fName,
ee.localMatrix(),
@@ -436,9 +438,9 @@ public:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const DIEllipseEdgeEffect& ee = args.fGP.cast<DIEllipseEdgeEffect>();
- GrGLSLGPBuilder* pb = args.fPB;
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// emit attributes
varyingHandler->emitAttributes(ee);
@@ -456,21 +458,22 @@ public:
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
// setup pass through color
if (!ee.colorIgnored()) {
- this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUniform);
+ this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
+ &fColorUniform);
}
// Setup position
- this->setupPosition(pb,
- vertBuilder,
+ this->setupPosition(vertBuilder,
+ uniformHandler,
gpArgs,
ee.inPosition()->fName,
ee.viewMatrix(),
&fViewMatrixUniform);
// emit transforms
- this->emitTransforms(args.fPB,
- vertBuilder,
+ this->emitTransforms(vertBuilder,
varyingHandler,
+ uniformHandler,
gpArgs->fPositionVar,
ee.inPosition()->fName,
args.fTransformsIn,
diff --git a/src/gpu/GrPathProcessor.cpp b/src/gpu/GrPathProcessor.cpp
index 66f94eaaab..f1faa7d239 100644
--- a/src/gpu/GrPathProcessor.cpp
+++ b/src/gpu/GrPathProcessor.cpp
@@ -11,7 +11,7 @@
#include "glsl/GrGLSLCaps.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLProcessorTypes.h"
-#include "glsl/GrGLSLProgramBuilder.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLVarying.h"
class GrGLPathProcessor : public GrGLSLPrimitiveProcessor {
@@ -26,7 +26,6 @@ public:
}
void emitCode(EmitArgs& args) override {
- GrGLSLGPBuilder* pb = args.fPB;
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
const GrPathProcessor& pathProc = args.fGP.cast<GrPathProcessor>();
@@ -36,11 +35,12 @@ public:
// Setup uniform color
if (pathProc.overrides().readsColor()) {
const char* stagedLocalVarName;
- fColorUniform = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec4f_GrSLType,
- kDefault_GrSLPrecision,
- "Color",
- &stagedLocalVarName);
+ fColorUniform = args.fUniformHandler->addUniform(
+ GrGLSLUniformHandler::kFragment_Visibility,
+ kVec4f_GrSLType,
+ kDefault_GrSLPrecision,
+ "Color",
+ &stagedLocalVarName);
fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, stagedLocalVarName);
}
diff --git a/src/gpu/batches/GrAAConvexPathRenderer.cpp b/src/gpu/batches/GrAAConvexPathRenderer.cpp
index c5b7c579b7..cd8579c1f8 100644
--- a/src/gpu/batches/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/batches/GrAAConvexPathRenderer.cpp
@@ -25,10 +25,12 @@
#include "SkString.h"
#include "SkTraceEvent.h"
#include "batches/GrVertexBatch.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLGeometryProcessor.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLVarying.h"
+#include "glsl/GrGLSLVertexShaderBuilder.h"
GrAAConvexPathRenderer::GrAAConvexPathRenderer() {
}
@@ -549,9 +551,9 @@ public:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const QuadEdgeEffect& qe = args.fGP.cast<QuadEdgeEffect>();
- GrGLSLGPBuilder* pb = args.fPB;
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// emit attributes
varyingHandler->emitAttributes(qe);
@@ -563,16 +565,17 @@ public:
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
if (!qe.colorIgnored()) {
- this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUniform);
+ this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
+ &fColorUniform);
}
// Setup position
- this->setupPosition(pb, vertBuilder, gpArgs, qe.inPosition()->fName);
+ this->setupPosition(vertBuilder, gpArgs, qe.inPosition()->fName);
// emit transforms
- this->emitTransforms(args.fPB,
- vertBuilder,
+ this->emitTransforms(vertBuilder,
varyingHandler,
+ uniformHandler,
gpArgs->fPositionVar,
qe.inPosition()->fName,
qe.localMatrix(),
diff --git a/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp
index 4b03c5a3f6..d07eb70e84 100644
--- a/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp
+++ b/src/gpu/batches/GrAALinearizingConvexPathRenderer.cpp
@@ -25,7 +25,6 @@
#include "SkPathPriv.h"
#include "batches/GrVertexBatch.h"
#include "glsl/GrGLSLGeometryProcessor.h"
-#include "glsl/GrGLSLProgramBuilder.h"
static const int DEFAULT_BUFFER_SIZE = 100;
diff --git a/src/gpu/effects/GrBezierEffect.cpp b/src/gpu/effects/GrBezierEffect.cpp
index 13672da6ea..c7e7b3647a 100644
--- a/src/gpu/effects/GrBezierEffect.cpp
+++ b/src/gpu/effects/GrBezierEffect.cpp
@@ -7,11 +7,13 @@
#include "GrBezierEffect.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLGeometryProcessor.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLUtil.h"
#include "glsl/GrGLSLVarying.h"
+#include "glsl/GrGLSLVertexShaderBuilder.h"
class GrGLConicEffect : public GrGLSLGeometryProcessor {
public:
@@ -73,10 +75,10 @@ GrGLConicEffect::GrGLConicEffect(const GrGeometryProcessor& processor)
}
void GrGLConicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
- GrGLSLGPBuilder* pb = args.fPB;
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
const GrConicEffect& gp = args.fGP.cast<GrConicEffect>();
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// emit attributes
varyingHandler->emitAttributes(gp);
@@ -88,21 +90,21 @@ void GrGLConicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
if (!gp.colorIgnored()) {
- this->setupUniformColor(args.fPB, fragBuilder, args.fOutputColor, &fColorUniform);
+ this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform);
}
// Setup position
- this->setupPosition(pb,
- vertBuilder,
+ this->setupPosition(vertBuilder,
+ uniformHandler,
gpArgs,
gp.inPosition()->fName,
gp.viewMatrix(),
&fViewMatrixUniform);
// emit transforms with position
- this->emitTransforms(pb,
- vertBuilder,
+ this->emitTransforms(vertBuilder,
varyingHandler,
+ uniformHandler,
gpArgs->fPositionVar,
gp.inPosition()->fName,
gp.localMatrix(),
@@ -168,11 +170,12 @@ void GrGLConicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
// TODO should we really be doing this?
if (gp.coverageScale() != 0xff) {
const char* coverageScale;
- fCoverageScaleUniform = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType,
- kDefault_GrSLPrecision,
- "Coverage",
- &coverageScale);
+ fCoverageScaleUniform = uniformHandler->addUniform(
+ GrGLSLUniformHandler::kFragment_Visibility,
+ kFloat_GrSLType,
+ kDefault_GrSLPrecision,
+ "Coverage",
+ &coverageScale);
fragBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverage, coverageScale);
} else {
fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
@@ -301,10 +304,10 @@ GrGLQuadEffect::GrGLQuadEffect(const GrGeometryProcessor& processor)
}
void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
- GrGLSLGPBuilder* pb = args.fPB;
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>();
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// emit attributes
varyingHandler->emitAttributes(gp);
@@ -316,21 +319,21 @@ void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
if (!gp.colorIgnored()) {
- this->setupUniformColor(args.fPB, fragBuilder, args.fOutputColor, &fColorUniform);
+ this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform);
}
// Setup position
- this->setupPosition(pb,
- vertBuilder,
+ this->setupPosition(vertBuilder,
+ uniformHandler,
gpArgs,
gp.inPosition()->fName,
gp.viewMatrix(),
&fViewMatrixUniform);
// emit transforms with position
- this->emitTransforms(pb,
- vertBuilder,
+ this->emitTransforms(vertBuilder,
varyingHandler,
+ uniformHandler,
gpArgs->fPositionVar,
gp.inPosition()->fName,
gp.localMatrix(),
@@ -384,11 +387,12 @@ void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
if (0xff != gp.coverageScale()) {
const char* coverageScale;
- fCoverageScaleUniform = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType,
- kDefault_GrSLPrecision,
- "Coverage",
- &coverageScale);
+ fCoverageScaleUniform = uniformHandler->addUniform(
+ GrGLSLUniformHandler::kFragment_Visibility,
+ kFloat_GrSLType,
+ kDefault_GrSLPrecision,
+ "Coverage",
+ &coverageScale);
fragBuilder->codeAppendf("%s = vec4(%s * edgeAlpha);", args.fOutputCoverage, coverageScale);
} else {
fragBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
@@ -507,6 +511,7 @@ void GrGLCubicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>();
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// emit attributes
varyingHandler->emitAttributes(gp);
@@ -518,21 +523,21 @@ void GrGLCubicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
if (!gp.colorIgnored()) {
- this->setupUniformColor(args.fPB, fragBuilder, args.fOutputColor, &fColorUniform);
+ this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform);
}
// Setup position
- this->setupPosition(args.fPB,
- vertBuilder,
+ this->setupPosition(vertBuilder,
+ uniformHandler,
gpArgs,
gp.inPosition()->fName,
gp.viewMatrix(),
&fViewMatrixUniform);
// emit transforms with position
- this->emitTransforms(args.fPB,
- vertBuilder,
+ this->emitTransforms(vertBuilder,
varyingHandler,
+ uniformHandler,
gpArgs->fPositionVar,
gp.inPosition()->fName,
args.fTransformsIn,
diff --git a/src/gpu/effects/GrBicubicEffect.cpp b/src/gpu/effects/GrBicubicEffect.cpp
index 8efcffdf03..37ac4ab766 100644
--- a/src/gpu/effects/GrBicubicEffect.cpp
+++ b/src/gpu/effects/GrBicubicEffect.cpp
@@ -8,8 +8,8 @@
#include "GrBicubicEffect.h"
#include "GrInvariantOutput.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
#define DS(x) SkDoubleToScalar(x)
@@ -52,15 +52,16 @@ GrGLBicubicEffect::GrGLBicubicEffect(const GrProcessor&) {
void GrGLBicubicEffect::emitCode(EmitArgs& args) {
const GrTextureDomain& domain = args.fFp.cast<GrBicubicEffect>().domain();
- fCoefficientsUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kMat44f_GrSLType, kDefault_GrSLPrecision,
- "Coefficients");
- fImageIncrementUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec2f_GrSLType, kDefault_GrSLPrecision,
- "ImageIncrement");
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
+ fCoefficientsUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kMat44f_GrSLType, kDefault_GrSLPrecision,
+ "Coefficients");
+ fImageIncrementUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec2f_GrSLType, kDefault_GrSLPrecision,
+ "ImageIncrement");
- const char* imgInc = args.fBuilder->getUniformCStr(fImageIncrementUni);
- const char* coeff = args.fBuilder->getUniformCStr(fCoefficientsUni);
+ const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni);
+ const char* coeff = uniformHandler->getUniformCStr(fCoefficientsUni);
SkString cubicBlendName;
@@ -98,6 +99,7 @@ void GrGLBicubicEffect::emitCode(EmitArgs& args) {
SkString sampleVar;
sampleVar.printf("rowColors[%d]", x);
fDomain.sampleTexture(fragBuilder,
+ args.fUniformHandler,
args.fGLSLCaps,
domain,
sampleVar.c_str(),
diff --git a/src/gpu/effects/GrBitmapTextGeoProc.cpp b/src/gpu/effects/GrBitmapTextGeoProc.cpp
index 594646256e..a8643b03f9 100644
--- a/src/gpu/effects/GrBitmapTextGeoProc.cpp
+++ b/src/gpu/effects/GrBitmapTextGeoProc.cpp
@@ -10,8 +10,8 @@
#include "GrTexture.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLGeometryProcessor.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLVarying.h"
#include "glsl/GrGLSLVertexShaderBuilder.h"
@@ -22,9 +22,9 @@ public:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override {
const GrBitmapTextGeoProc& cte = args.fGP.cast<GrBitmapTextGeoProc>();
- GrGLSLGPBuilder* pb = args.fPB;
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// emit attributes
varyingHandler->emitAttributes(cte);
@@ -49,17 +49,18 @@ public:
if (cte.hasVertexColor()) {
varyingHandler->addPassThroughAttribute(cte.inColor(), args.fOutputColor);
} else {
- this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUniform);
+ this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
+ &fColorUniform);
}
}
// Setup position
- this->setupPosition(pb, vertBuilder, gpArgs, cte.inPosition()->fName);
+ this->setupPosition(vertBuilder, gpArgs, cte.inPosition()->fName);
// emit transforms
- this->emitTransforms(args.fPB,
- vertBuilder,
+ this->emitTransforms(vertBuilder,
varyingHandler,
+ uniformHandler,
gpArgs->fPositionVar,
cte.inPosition()->fName,
cte.localMatrix(),
diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp
index 4df894b40a..129d057b7f 100644
--- a/src/gpu/effects/GrConfigConversionEffect.cpp
+++ b/src/gpu/effects/GrConfigConversionEffect.cpp
@@ -13,7 +13,6 @@
#include "SkMatrix.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
class GrGLConfigConversionEffect : public GrGLSLFragmentProcessor {
public:
diff --git a/src/gpu/effects/GrConstColorProcessor.cpp b/src/gpu/effects/GrConstColorProcessor.cpp
index cf567aac5c..03b0fa4054 100644
--- a/src/gpu/effects/GrConstColorProcessor.cpp
+++ b/src/gpu/effects/GrConstColorProcessor.cpp
@@ -6,10 +6,11 @@
*/
#include "effects/GrConstColorProcessor.h"
+#include "GrInvariantOutput.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
class GLConstColorProcessor : public GrGLSLFragmentProcessor {
public:
@@ -18,9 +19,10 @@ public:
void emitCode(EmitArgs& args) override {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
const char* colorUni;
- fColorUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec4f_GrSLType, kMedium_GrSLPrecision, "constantColor",
- &colorUni);
+ fColorUniform = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec4f_GrSLType, kMedium_GrSLPrecision,
+ "constantColor",
+ &colorUni);
GrConstColorProcessor::InputMode mode = args.fFp.cast<GrConstColorProcessor>().inputMode();
if (!args.fInputColor) {
mode = GrConstColorProcessor::kIgnore_InputMode;
diff --git a/src/gpu/effects/GrConvexPolyEffect.cpp b/src/gpu/effects/GrConvexPolyEffect.cpp
index 13df7bc4bd..dc7a528501 100644
--- a/src/gpu/effects/GrConvexPolyEffect.cpp
+++ b/src/gpu/effects/GrConvexPolyEffect.cpp
@@ -10,8 +10,8 @@
#include "SkPathPriv.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
//////////////////////////////////////////////////////////////////////////////
class AARectEffect : public GrFragmentProcessor {
@@ -105,11 +105,11 @@ void GLAARectEffect::emitCode(EmitArgs& args) {
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(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec4f_GrSLType,
- kDefault_GrSLPrecision,
- "rect",
- &rectName);
+ fRectUniform = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec4f_GrSLType,
+ kDefault_GrSLPrecision,
+ "rect",
+ &rectName);
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
const char* fragmentPos = fragBuilder->fragmentPosition();
@@ -191,12 +191,12 @@ void GrGLConvexPolyEffect::emitCode(EmitArgs& args) {
const GrConvexPolyEffect& cpe = args.fFp.cast<GrConvexPolyEffect>();
const char *edgeArrayName;
- fEdgeUniform = args.fBuilder->addUniformArray(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec3f_GrSLType,
- kDefault_GrSLPrecision,
- "edges",
- cpe.getEdgeCount(),
- &edgeArrayName);
+ fEdgeUniform = args.fUniformHandler->addUniformArray(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec3f_GrSLType,
+ kDefault_GrSLPrecision,
+ "edges",
+ cpe.getEdgeCount(),
+ &edgeArrayName);
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
fragBuilder->codeAppend("\t\tfloat alpha = 1.0;\n");
fragBuilder->codeAppend("\t\tfloat edge;\n");
diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp
index 8e05f4789b..fb68a29420 100644
--- a/src/gpu/effects/GrConvolutionEffect.cpp
+++ b/src/gpu/effects/GrConvolutionEffect.cpp
@@ -8,8 +8,8 @@
#include "GrConvolutionEffect.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
// For brevity
typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
@@ -48,17 +48,18 @@ GrGLConvolutionEffect::GrGLConvolutionEffect(const GrProcessor& processor) {
}
void GrGLConvolutionEffect::emitCode(EmitArgs& args) {
- fImageIncrementUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec2f_GrSLType, kDefault_GrSLPrecision,
- "ImageIncrement");
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
+ fImageIncrementUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec2f_GrSLType, kDefault_GrSLPrecision,
+ "ImageIncrement");
if (this->useBounds()) {
- fBoundsUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec2f_GrSLType, kDefault_GrSLPrecision,
- "Bounds");
+ fBoundsUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec2f_GrSLType, kDefault_GrSLPrecision,
+ "Bounds");
}
- fKernelUni = args.fBuilder->addUniformArray(GrGLSLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType, kDefault_GrSLPrecision,
- "Kernel", this->width());
+ fKernelUni = uniformHandler->addUniformArray(GrGLSLUniformHandler::kFragment_Visibility,
+ kFloat_GrSLType, kDefault_GrSLPrecision,
+ "Kernel", this->width());
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
@@ -66,8 +67,8 @@ void GrGLConvolutionEffect::emitCode(EmitArgs& args) {
fragBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", args.fOutputColor);
int width = this->width();
- const GrGLSLShaderVar& kernel = args.fBuilder->getUniformVariable(fKernelUni);
- const char* imgInc = args.fBuilder->getUniformCStr(fImageIncrementUni);
+ const GrGLSLShaderVar& kernel = uniformHandler->getUniformVariable(fKernelUni);
+ const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni);
fragBuilder->codeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords2D.c_str(), fRadius, imgInc);
@@ -82,7 +83,7 @@ void GrGLConvolutionEffect::emitCode(EmitArgs& args) {
// We used to compute a bool indicating whether we're in bounds or not, cast it to a
// float, and then mul weight*texture_sample by the float. However, the Adreno 430 seems
// to have a bug that caused corruption.
- const char* bounds = args.fBuilder->getUniformCStr(fBoundsUni);
+ const char* bounds = uniformHandler->getUniformCStr(fBoundsUni);
const char* component = this->direction() == Gr1DKernelEffect::kY_Direction ? "y" : "x";
fragBuilder->codeAppendf("if (coord.%s >= %s.x && coord.%s <= %s.y) {",
component, bounds, component, bounds);
diff --git a/src/gpu/effects/GrCoverageSetOpXP.cpp b/src/gpu/effects/GrCoverageSetOpXP.cpp
index 219ed0b505..7761a6445a 100644
--- a/src/gpu/effects/GrCoverageSetOpXP.cpp
+++ b/src/gpu/effects/GrCoverageSetOpXP.cpp
@@ -12,8 +12,8 @@
#include "GrProcessor.h"
#include "GrProcOptInfo.h"
#include "glsl/GrGLSLBlend.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLXferProcessor.h"
class CoverageSetOpXP : public GrXferProcessor {
@@ -200,8 +200,8 @@ public:
}
private:
- void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb,
- GrGLSLXPFragmentBuilder* fragBuilder,
+ void emitBlendCodeForDstRead(GrGLSLXPFragmentBuilder* fragBuilder,
+ GrGLSLUniformHandler* uniformHandler,
const char* srcColor,
const char* srcCoverage,
const char* dstColor,
diff --git a/src/gpu/effects/GrCustomXfermode.cpp b/src/gpu/effects/GrCustomXfermode.cpp
index d2aff6042c..04ff4a746b 100644
--- a/src/gpu/effects/GrCustomXfermode.cpp
+++ b/src/gpu/effects/GrCustomXfermode.cpp
@@ -20,8 +20,8 @@
#include "glsl/GrGLSLCaps.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLXferProcessor.h"
bool GrCustomXfermode::IsSupportedMode(SkXfermode::Mode mode) {
@@ -158,8 +158,8 @@ private:
}
}
- void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb,
- GrGLSLXPFragmentBuilder* fragBuilder,
+ void emitBlendCodeForDstRead(GrGLSLXPFragmentBuilder* fragBuilder,
+ GrGLSLUniformHandler* uniformHandler,
const char* srcColor,
const char* srcCoverage,
const char* dstColor,
diff --git a/src/gpu/effects/GrDashingEffect.cpp b/src/gpu/effects/GrDashingEffect.cpp
index e62ede0a33..1516efd2b2 100644
--- a/src/gpu/effects/GrDashingEffect.cpp
+++ b/src/gpu/effects/GrDashingEffect.cpp
@@ -23,8 +23,8 @@
#include "batches/GrVertexBatch.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLGeometryProcessor.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLVarying.h"
#include "glsl/GrGLSLVertexShaderBuilder.h"
@@ -863,9 +863,9 @@ GLDashingCircleEffect::GLDashingCircleEffect() {
void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>();
- GrGLSLGPBuilder* pb = args.fPB;
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// emit attributes
varyingHandler->emitAttributes(dce);
@@ -883,16 +883,16 @@ void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
if (!dce.colorIgnored()) {
- this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUniform);
+ this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform);
}
// Setup position
- this->setupPosition(pb, vertBuilder, gpArgs, dce.inPosition()->fName);
+ this->setupPosition(vertBuilder, gpArgs, dce.inPosition()->fName);
// emit transforms
- this->emitTransforms(args.fPB,
- vertBuilder,
+ this->emitTransforms(vertBuilder,
varyingHandler,
+ uniformHandler,
gpArgs->fPositionVar,
dce.inPosition()->fName,
dce.localMatrix(),
@@ -1075,10 +1075,10 @@ GLDashingLineEffect::GLDashingLineEffect() {
void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>();
- GrGLSLGPBuilder* pb = args.fPB;
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// emit attributes
varyingHandler->emitAttributes(de);
@@ -1097,16 +1097,16 @@ void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
if (!de.colorIgnored()) {
- this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUniform);
+ this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform);
}
// Setup position
- this->setupPosition(pb, vertBuilder, gpArgs, de.inPosition()->fName);
+ this->setupPosition(vertBuilder, gpArgs, de.inPosition()->fName);
// emit transforms
- this->emitTransforms(args.fPB,
- vertBuilder,
+ this->emitTransforms(vertBuilder,
varyingHandler,
+ uniformHandler,
gpArgs->fPositionVar,
de.inPosition()->fName,
de.localMatrix(),
diff --git a/src/gpu/effects/GrDisableColorXP.cpp b/src/gpu/effects/GrDisableColorXP.cpp
index e669f8b024..70e40e4a14 100644
--- a/src/gpu/effects/GrDisableColorXP.cpp
+++ b/src/gpu/effects/GrDisableColorXP.cpp
@@ -8,7 +8,6 @@
#include "effects/GrDisableColorXP.h"
#include "GrProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
#include "glsl/GrGLSLXferProcessor.h"
diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.cpp b/src/gpu/effects/GrDistanceFieldGeoProc.cpp
index cf77157e0d..fab936903e 100644
--- a/src/gpu/effects/GrDistanceFieldGeoProc.cpp
+++ b/src/gpu/effects/GrDistanceFieldGeoProc.cpp
@@ -13,8 +13,8 @@
#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLGeometryProcessor.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLUtil.h"
#include "glsl/GrGLSLVarying.h"
#include "glsl/GrGLSLVertexShaderBuilder.h"
@@ -35,13 +35,13 @@ public:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
const GrDistanceFieldA8TextGeoProc& dfTexEffect =
args.fGP.cast<GrDistanceFieldA8TextGeoProc>();
- GrGLSLGPBuilder* pb = args.fPB;
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
SkAssertResult(fragBuilder->enableFeature(
GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// emit attributes
varyingHandler->emitAttributes(dfTexEffect);
@@ -50,9 +50,9 @@ public:
// adjust based on gamma
const char* distanceAdjustUniName = nullptr;
// width, height, 1/(3*width)
- fDistanceAdjustUni = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType, kDefault_GrSLPrecision,
- "DistanceAdjust", &distanceAdjustUniName);
+ fDistanceAdjustUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kFloat_GrSLType, kDefault_GrSLPrecision,
+ "DistanceAdjust", &distanceAdjustUniName);
#endif
// Setup pass through color
@@ -60,22 +60,23 @@ public:
if (dfTexEffect.hasVertexColor()) {
varyingHandler->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputColor);
} else {
- this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUniform);
+ this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
+ &fColorUniform);
}
}
// Setup position
- this->setupPosition(pb,
- vertBuilder,
+ this->setupPosition(vertBuilder,
+ uniformHandler,
gpArgs,
dfTexEffect.inPosition()->fName,
dfTexEffect.viewMatrix(),
&fViewMatrixUniform);
// emit transforms
- this->emitTransforms(pb,
- vertBuilder,
+ this->emitTransforms(vertBuilder,
varyingHandler,
+ uniformHandler,
gpArgs->fPositionVar,
dfTexEffect.inPosition()->fName,
args.fTransformsIn,
@@ -296,13 +297,13 @@ public:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
const GrDistanceFieldPathGeoProc& dfTexEffect = args.fGP.cast<GrDistanceFieldPathGeoProc>();
- GrGLSLGPBuilder* pb = args.fPB;
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
SkAssertResult(fragBuilder->enableFeature(
GrGLSLFragmentShaderBuilder::kStandardDerivatives_GLSLFeature));
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// emit attributes
varyingHandler->emitAttributes(dfTexEffect);
@@ -315,32 +316,33 @@ public:
if (dfTexEffect.hasVertexColor()) {
varyingHandler->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputColor);
} else {
- this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUniform);
+ this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
+ &fColorUniform);
}
}
vertBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoords()->fName);
// Setup position
- this->setupPosition(pb,
- vertBuilder,
+ this->setupPosition(vertBuilder,
+ uniformHandler,
gpArgs,
dfTexEffect.inPosition()->fName,
dfTexEffect.viewMatrix(),
&fViewMatrixUniform);
// emit transforms
- this->emitTransforms(pb,
- vertBuilder,
+ this->emitTransforms(vertBuilder,
varyingHandler,
+ uniformHandler,
gpArgs->fPositionVar,
dfTexEffect.inPosition()->fName,
args.fTransformsIn,
args.fTransformsOut);
const char* textureSizeUniName = nullptr;
- fTextureSizeUni = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec2f_GrSLType, kDefault_GrSLPrecision,
- "TextureSize", &textureSizeUniName);
+ fTextureSizeUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec2f_GrSLType, kDefault_GrSLPrecision,
+ "TextureSize", &textureSizeUniName);
// Use highp to work around aliasing issues
fragBuilder->codeAppend(GrGLSLShaderVar::PrecisionString(args.fGLSLCaps,
@@ -521,10 +523,10 @@ public:
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
const GrDistanceFieldLCDTextGeoProc& dfTexEffect =
args.fGP.cast<GrDistanceFieldLCDTextGeoProc>();
- GrGLSLGPBuilder* pb = args.fPB;
GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder;
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
// emit attributes
varyingHandler->emitAttributes(dfTexEffect);
@@ -533,21 +535,21 @@ public:
// setup pass through color
if (!dfTexEffect.colorIgnored()) {
- this->setupUniformColor(pb, fragBuilder, args.fOutputColor, &fColorUniform);
+ this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform);
}
// Setup position
- this->setupPosition(pb,
- vertBuilder,
+ this->setupPosition(vertBuilder,
+ uniformHandler,
gpArgs,
dfTexEffect.inPosition()->fName,
dfTexEffect.viewMatrix(),
&fViewMatrixUniform);
// emit transforms
- this->emitTransforms(pb,
- vertBuilder,
+ this->emitTransforms(vertBuilder,
varyingHandler,
+ uniformHandler,
gpArgs->fPositionVar,
dfTexEffect.inPosition()->fName,
args.fTransformsIn,
@@ -628,9 +630,9 @@ public:
// adjust width based on gamma
const char* distanceAdjustUniName = nullptr;
- fDistanceAdjustUni = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec3f_GrSLType, kDefault_GrSLPrecision,
- "DistanceAdjust", &distanceAdjustUniName);
+ fDistanceAdjustUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec3f_GrSLType, kDefault_GrSLPrecision,
+ "DistanceAdjust", &distanceAdjustUniName);
fragBuilder->codeAppendf("distance -= %s;", distanceAdjustUniName);
// To be strictly correct, we should compute the anti-aliasing factor separately
diff --git a/src/gpu/effects/GrDitherEffect.cpp b/src/gpu/effects/GrDitherEffect.cpp
index 37cc1ae570..44aacfccab 100644
--- a/src/gpu/effects/GrDitherEffect.cpp
+++ b/src/gpu/effects/GrDitherEffect.cpp
@@ -11,7 +11,6 @@
#include "SkRect.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
//////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/effects/GrMatrixConvolutionEffect.cpp b/src/gpu/effects/GrMatrixConvolutionEffect.cpp
index 5fb694b0d7..8867ab9dba 100644
--- a/src/gpu/effects/GrMatrixConvolutionEffect.cpp
+++ b/src/gpu/effects/GrMatrixConvolutionEffect.cpp
@@ -6,8 +6,9 @@
*/
#include "GrMatrixConvolutionEffect.h"
#include "glsl/GrGLSLFragmentProcessor.h"
-#include "glsl/GrGLSLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
class GrGLMatrixConvolutionEffect : public GrGLSLFragmentProcessor {
public:
@@ -42,25 +43,27 @@ GrGLMatrixConvolutionEffect::GrGLMatrixConvolutionEffect(const GrProcessor& proc
void GrGLMatrixConvolutionEffect::emitCode(EmitArgs& args) {
const GrTextureDomain& domain = args.fFp.cast<GrMatrixConvolutionEffect>().domain();
- fImageIncrementUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec2f_GrSLType, kDefault_GrSLPrecision,
- "ImageIncrement");
- fKernelUni = args.fBuilder->addUniformArray(GrGLSLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType, kDefault_GrSLPrecision,
- "Kernel",
- fKernelSize.width() * fKernelSize.height());
- fKernelOffsetUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec2f_GrSLType, kDefault_GrSLPrecision, "KernelOffset");
- fGainUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType, kDefault_GrSLPrecision, "Gain");
- fBiasUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType, kDefault_GrSLPrecision, "Bias");
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
+ fImageIncrementUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec2f_GrSLType, kDefault_GrSLPrecision,
+ "ImageIncrement");
+ fKernelUni = uniformHandler->addUniformArray(GrGLSLUniformHandler::kFragment_Visibility,
+ kFloat_GrSLType, kDefault_GrSLPrecision,
+ "Kernel",
+ fKernelSize.width() * fKernelSize.height());
+ fKernelOffsetUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec2f_GrSLType, kDefault_GrSLPrecision,
+ "KernelOffset");
+ fGainUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kFloat_GrSLType, kDefault_GrSLPrecision, "Gain");
+ fBiasUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kFloat_GrSLType, kDefault_GrSLPrecision, "Bias");
- const char* kernelOffset = args.fBuilder->getUniformCStr(fKernelOffsetUni);
- const char* imgInc = args.fBuilder->getUniformCStr(fImageIncrementUni);
- const char* kernel = args.fBuilder->getUniformCStr(fKernelUni);
- const char* gain = args.fBuilder->getUniformCStr(fGainUni);
- const char* bias = args.fBuilder->getUniformCStr(fBiasUni);
+ const char* kernelOffset = uniformHandler->getUniformCStr(fKernelOffsetUni);
+ const char* imgInc = uniformHandler->getUniformCStr(fImageIncrementUni);
+ const char* kernel = uniformHandler->getUniformCStr(fKernelUni);
+ const char* gain = uniformHandler->getUniformCStr(fGainUni);
+ const char* bias = uniformHandler->getUniformCStr(fBiasUni);
int kWidth = fKernelSize.width();
int kHeight = fKernelSize.height();
@@ -77,6 +80,7 @@ void GrGLMatrixConvolutionEffect::emitCode(EmitArgs& args) {
SkString coord;
coord.printf("coord + vec2(%d, %d) * %s", x, y, imgInc);
fDomain.sampleTexture(fragBuilder,
+ uniformHandler,
args.fGLSLCaps,
domain,
"c",
@@ -95,6 +99,7 @@ void GrGLMatrixConvolutionEffect::emitCode(EmitArgs& args) {
args.fOutputColor, args.fOutputColor, args.fOutputColor);
} else {
fDomain.sampleTexture(fragBuilder,
+ uniformHandler,
args.fGLSLCaps,
domain,
"c",
diff --git a/src/gpu/effects/GrOvalEffect.cpp b/src/gpu/effects/GrOvalEffect.cpp
index 94c5acd949..4532ddfd3c 100644
--- a/src/gpu/effects/GrOvalEffect.cpp
+++ b/src/gpu/effects/GrOvalEffect.cpp
@@ -12,8 +12,8 @@
#include "SkRect.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
//////////////////////////////////////////////////////////////////////////////
@@ -119,10 +119,10 @@ void GLCircleEffect::emitCode(EmitArgs& args) {
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(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec4f_GrSLType, kDefault_GrSLPrecision,
- "circle",
- &circleName);
+ fCircleUniform = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec4f_GrSLType, kDefault_GrSLPrecision,
+ "circle",
+ &circleName);
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
const char* fragmentPos = fragBuilder->fragmentPosition();
@@ -291,10 +291,10 @@ void GLEllipseEffect::emitCode(EmitArgs& args) {
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(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec4f_GrSLType, kHigh_GrSLPrecision,
- "ellipse",
- &ellipseName);
+ fEllipseUniform = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec4f_GrSLType, kHigh_GrSLPrecision,
+ "ellipse",
+ &ellipseName);
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
const char* fragmentPos = fragBuilder->fragmentPosition();
diff --git a/src/gpu/effects/GrPorterDuffXferProcessor.cpp b/src/gpu/effects/GrPorterDuffXferProcessor.cpp
index 42a9631976..69e77cfc48 100644
--- a/src/gpu/effects/GrPorterDuffXferProcessor.cpp
+++ b/src/gpu/effects/GrPorterDuffXferProcessor.cpp
@@ -16,8 +16,8 @@
#include "GrXferProcessor.h"
#include "glsl/GrGLSLBlend.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLXferProcessor.h"
/**
@@ -545,8 +545,8 @@ public:
}
private:
- void emitBlendCodeForDstRead(GrGLSLXPBuilder* pb,
- GrGLSLXPFragmentBuilder* fragBuilder,
+ void emitBlendCodeForDstRead(GrGLSLXPFragmentBuilder* fragBuilder,
+ GrGLSLUniformHandler* uniformHandler,
const char* srcColor,
const char* srcCoverage,
const char* dstColor,
diff --git a/src/gpu/effects/GrRRectEffect.cpp b/src/gpu/effects/GrRRectEffect.cpp
index c45f5f309c..f8c6a41dad 100644
--- a/src/gpu/effects/GrRRectEffect.cpp
+++ b/src/gpu/effects/GrRRectEffect.cpp
@@ -12,10 +12,11 @@
#include "GrInvariantOutput.h"
#include "GrOvalEffect.h"
#include "SkRRect.h"
+#include "SkTLazy.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
// The effects defined here only handle rrect radii >= kRadiusMin.
static const SkScalar kRadiusMin = SK_ScalarHalf;
@@ -150,20 +151,21 @@ GLCircularRRectEffect::GLCircularRRectEffect(const GrProcessor& ) {
void GLCircularRRectEffect::emitCode(EmitArgs& args) {
const CircularRRectEffect& crre = args.fFp.cast<CircularRRectEffect>();
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
const char *rectName;
const char *radiusPlusHalfName;
// The inner rect is the rrect bounds inset by the radius. Its left, top, right, and bottom
// 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(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec4f_GrSLType, kDefault_GrSLPrecision,
- "innerRect",
- &rectName);
- fRadiusPlusHalfUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kFloat_GrSLType, kDefault_GrSLPrecision,
- "radiusPlusHalf",
- &radiusPlusHalfName);
+ fInnerRectUniform = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec4f_GrSLType, kDefault_GrSLPrecision,
+ "innerRect",
+ &rectName);
+ fRadiusPlusHalfUniform = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kFloat_GrSLType, kDefault_GrSLPrecision,
+ "radiusPlusHalf",
+ &radiusPlusHalfName);
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
const char* fragmentPos = fragBuilder->fragmentPosition();
@@ -504,12 +506,13 @@ GLEllipticalRRectEffect::GLEllipticalRRectEffect(const GrProcessor& effect) {
void GLEllipticalRRectEffect::emitCode(EmitArgs& args) {
const EllipticalRRectEffect& erre = args.fFp.cast<EllipticalRRectEffect>();
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
const char *rectName;
// The inner rect is the rrect bounds inset by the x/y radii
- fInnerRectUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec4f_GrSLType, kDefault_GrSLPrecision,
- "innerRect",
- &rectName);
+ fInnerRectUniform = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec4f_GrSLType, kDefault_GrSLPrecision,
+ "innerRect",
+ &rectName);
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
const char* fragmentPos = fragBuilder->fragmentPosition();
@@ -531,8 +534,8 @@ void GLEllipticalRRectEffect::emitCode(EmitArgs& args) {
switch (erre.getRRect().getType()) {
case SkRRect::kSimple_Type: {
const char *invRadiiXYSqdName;
- fInvRadiiSqdUniform = args.fBuilder->addUniform(
- GrGLSLProgramBuilder::kFragment_Visibility,
+ fInvRadiiSqdUniform = uniformHandler->addUniform(
+ GrGLSLUniformHandler::kFragment_Visibility,
kVec2f_GrSLType, kHigh_GrSLPrecision,
"invRadiiXY",
&invRadiiXYSqdName);
@@ -543,8 +546,8 @@ void GLEllipticalRRectEffect::emitCode(EmitArgs& args) {
}
case SkRRect::kNinePatch_Type: {
const char *invRadiiLTRBSqdName;
- fInvRadiiSqdUniform = args.fBuilder->addUniform(
- GrGLSLProgramBuilder::kFragment_Visibility,
+ fInvRadiiSqdUniform = uniformHandler->addUniform(
+ GrGLSLUniformHandler::kFragment_Visibility,
kVec4f_GrSLType, kHigh_GrSLPrecision,
"invRadiiLTRB",
&invRadiiLTRBSqdName);
diff --git a/src/gpu/effects/GrSimpleTextureEffect.cpp b/src/gpu/effects/GrSimpleTextureEffect.cpp
index 4db6f2c509..74e86249b0 100644
--- a/src/gpu/effects/GrSimpleTextureEffect.cpp
+++ b/src/gpu/effects/GrSimpleTextureEffect.cpp
@@ -10,7 +10,6 @@
#include "GrTexture.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
class GrGLSimpleTextureEffect : public GrGLSLFragmentProcessor {
public:
diff --git a/src/gpu/effects/GrTextureDomain.cpp b/src/gpu/effects/GrTextureDomain.cpp
index c0902c6176..00e8e82c8e 100644
--- a/src/gpu/effects/GrTextureDomain.cpp
+++ b/src/gpu/effects/GrTextureDomain.cpp
@@ -10,9 +10,11 @@
#include "GrSimpleTextureEffect.h"
#include "SkFloatingPoint.h"
#include "glsl/GrGLSLFragmentProcessor.h"
-#include "glsl/GrGLSLProgramBuilder.h"
+#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLShaderBuilder.h"
#include "glsl/GrGLSLTextureSampler.h"
+#include "glsl/GrGLSLUniformHandler.h"
GrTextureDomain::GrTextureDomain(const SkRect& domain, Mode mode, int index)
: fIndex(index) {
@@ -42,6 +44,7 @@ GrTextureDomain::GrTextureDomain(const SkRect& domain, Mode mode, int index)
//////////////////////////////////////////////////////////////////////////////
void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
+ GrGLSLUniformHandler* uniformHandler,
const GrGLSLCaps* glslCaps,
const GrTextureDomain& textureDomain,
const char* outColor,
@@ -51,17 +54,15 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLSLShaderBuilder* builder,
SkASSERT((Mode)-1 == fMode || textureDomain.mode() == fMode);
SkDEBUGCODE(fMode = textureDomain.mode();)
- GrGLSLProgramBuilder* program = builder->getProgramBuilder();
-
if (textureDomain.mode() != kIgnore_Mode && !fDomainUni.isValid()) {
const char* name;
SkString uniName("TexDom");
if (textureDomain.fIndex >= 0) {
uniName.appendS32(textureDomain.fIndex);
}
- fDomainUni = program->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec4f_GrSLType, kDefault_GrSLPrecision,
- uniName.c_str(), &name);
+ fDomainUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec4f_GrSLType, kDefault_GrSLPrecision,
+ uniName.c_str(), &name);
fDomainName = name;
}
@@ -199,6 +200,7 @@ void GrGLTextureDomainEffect::emitCode(EmitArgs& args) {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
fGLDomain.sampleTexture(fragBuilder,
+ args.fUniformHandler,
args.fGLSLCaps,
domain,
args.fOutputColor,
diff --git a/src/gpu/effects/GrTextureDomain.h b/src/gpu/effects/GrTextureDomain.h
index 49e557d18a..891ce10b38 100644
--- a/src/gpu/effects/GrTextureDomain.h
+++ b/src/gpu/effects/GrTextureDomain.h
@@ -16,6 +16,7 @@ class GrGLProgramBuilder;
class GrGLSLShaderBuilder;
class GrInvariantOutput;
class GrGLSLTextureSampler;
+class GrGLSLUniformHandler;
struct SkRect;
/**
@@ -114,6 +115,7 @@ public:
* expression before being written to outColor.
*/
void sampleTexture(GrGLSLShaderBuilder* builder,
+ GrGLSLUniformHandler* uniformHandler,
const GrGLSLCaps* glslCaps,
const GrTextureDomain& textureDomain,
const char* outColor,
diff --git a/src/gpu/effects/GrXfermodeFragmentProcessor.cpp b/src/gpu/effects/GrXfermodeFragmentProcessor.cpp
index 6ff4d32f06..c83d6bee55 100644
--- a/src/gpu/effects/GrXfermodeFragmentProcessor.cpp
+++ b/src/gpu/effects/GrXfermodeFragmentProcessor.cpp
@@ -8,11 +8,11 @@
#include "effects/GrXfermodeFragmentProcessor.h"
#include "GrFragmentProcessor.h"
+#include "GrInvariantOutput.h"
#include "effects/GrConstColorProcessor.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLBlend.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "SkGrPriv.h"
class ComposeTwoFragmentProcessor : public GrFragmentProcessor {
diff --git a/src/gpu/effects/GrYUVtoRGBEffect.cpp b/src/gpu/effects/GrYUVtoRGBEffect.cpp
index 6d1c864b82..16dad8635c 100644
--- a/src/gpu/effects/GrYUVtoRGBEffect.cpp
+++ b/src/gpu/effects/GrYUVtoRGBEffect.cpp
@@ -8,12 +8,13 @@
#include "GrYUVtoRGBEffect.h"
#include "GrCoordTransform.h"
+#include "GrFragmentProcessor.h"
#include "GrInvariantOutput.h"
#include "GrProcessor.h"
#include "glsl/GrGLSLFragmentProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
namespace {
@@ -67,9 +68,10 @@ public:
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
const char* yuvMatrix = nullptr;
- fMatrixUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kMat44f_GrSLType, kDefault_GrSLPrecision,
- "YUVMatrix", &yuvMatrix);
+ fMatrixUni = args.fUniformHandler->addUniform(
+ GrGLSLUniformHandler::kFragment_Visibility,
+ kMat44f_GrSLType, kDefault_GrSLPrecision,
+ "YUVMatrix", &yuvMatrix);
fragBuilder->codeAppendf("\t%s = vec4(\n\t\t", args.fOutputColor);
fragBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str(),
args.fCoords[0].getType());
diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h
index 72fa9b01a0..ad0569817b 100644
--- a/src/gpu/gl/GrGLProgram.h
+++ b/src/gpu/gl/GrGLProgram.h
@@ -14,6 +14,7 @@
#include "GrGLTexture.h"
#include "GrGLProgramDataManager.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "SkString.h"
#include "SkXfermode.h"
@@ -35,7 +36,7 @@ class GrPipeline;
*/
class GrGLProgram : public SkRefCnt {
public:
- typedef GrGLProgramBuilder::BuiltinUniformHandles BuiltinUniformHandles;
+ typedef GrGLSLProgramBuilder::BuiltinUniformHandles BuiltinUniformHandles;
~GrGLProgram();
diff --git a/src/gpu/gl/GrGLProgramDataManager.cpp b/src/gpu/gl/GrGLProgramDataManager.cpp
index f0aba49720..54ca73a205 100644
--- a/src/gpu/gl/GrGLProgramDataManager.cpp
+++ b/src/gpu/gl/GrGLProgramDataManager.cpp
@@ -8,6 +8,7 @@
#include "SkMatrix.h"
#include "gl/GrGLProgramDataManager.h"
#include "gl/GrGLGpu.h"
+#include "glsl/GrGLSLUniformHandler.h"
#define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \
SkASSERT(arrayCount <= uni.fArrayCount || \
@@ -31,12 +32,12 @@ GrGLProgramDataManager::GrGLProgramDataManager(GrGLGpu* gpu, GrGLuint programID,
);
// TODO: Move the Xoom uniform array in both FS and VS bug workaround here.
- if (GrGLProgramBuilder::kVertex_Visibility & builderUniform.fVisibility) {
+ if (GrGLSLUniformHandler::kVertex_Visibility & builderUniform.fVisibility) {
uniform.fVSLocation = builderUniform.fLocation;
} else {
uniform.fVSLocation = kUnusedUniform;
}
- if (GrGLProgramBuilder::kFragment_Visibility & builderUniform.fVisibility) {
+ if (GrGLSLUniformHandler::kFragment_Visibility & builderUniform.fVisibility) {
uniform.fFSLocation = builderUniform.fLocation;
} else {
uniform.fFSLocation = kUnusedUniform;
diff --git a/src/gpu/gl/GrGLProgramDataManager.h b/src/gpu/gl/GrGLProgramDataManager.h
index d47745334d..1fce6ed62d 100644
--- a/src/gpu/gl/GrGLProgramDataManager.h
+++ b/src/gpu/gl/GrGLProgramDataManager.h
@@ -19,7 +19,6 @@
class GrGLGpu;
class SkMatrix;
class GrGLProgram;
-class GrGLProgramBuilder;
/** Manages the resources used by a shader program.
* The resources are objects the program uses to communicate with the
diff --git a/src/gpu/gl/GrGLUniformHandler.cpp b/src/gpu/gl/GrGLUniformHandler.cpp
new file mode 100644
index 0000000000..1ddb789668
--- /dev/null
+++ b/src/gpu/gl/GrGLUniformHandler.cpp
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gl/GrGLUniformHandler.h"
+
+#include "gl/GrGLCaps.h"
+#include "gl/GrGLGpu.h"
+#include "gl/builders/GrGLProgramBuilder.h"
+
+#define GL_CALL(X) GR_GL_CALL(this->glGpu()->glInterface(), X)
+#define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->glGpu()->glInterface(), R, X)
+
+GrGLSLUniformHandler::UniformHandle GrGLUniformHandler::internalAddUniformArray(
+ uint32_t visibility,
+ GrSLType type,
+ GrSLPrecision precision,
+ const char* name,
+ bool mangleName,
+ int arrayCount,
+ const char** outName) {
+ SkASSERT(name && strlen(name));
+ SkDEBUGCODE(static const uint32_t kVisibilityMask = kVertex_Visibility | kFragment_Visibility);
+ SkASSERT(0 == (~kVisibilityMask & visibility));
+ SkASSERT(0 != visibility);
+ SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type));
+
+ UniformInfo& uni = fUniforms.push_back();
+ uni.fVariable.setType(type);
+ uni.fVariable.setTypeModifier(GrGLSLShaderVar::kUniform_TypeModifier);
+ // TODO this is a bit hacky, lets think of a better way. Basically we need to be able to use
+ // the uniform view matrix name in the GP, and the GP is immutable so it has to tell the PB
+ // exactly what name it wants to use for the uniform view matrix. If we prefix anythings, then
+ // the names will mismatch. I think the correct solution is to have all GPs which need the
+ // uniform view matrix, they should upload the view matrix in their setData along with regular
+ // uniforms.
+ char prefix = 'u';
+ if ('u' == name[0]) {
+ prefix = '\0';
+ }
+ fProgramBuilder->nameVariable(uni.fVariable.accessName(), prefix, name, mangleName);
+ uni.fVariable.setArrayCount(arrayCount);
+ uni.fVisibility = visibility;
+ uni.fVariable.setPrecision(precision);
+
+ if (outName) {
+ *outName = uni.fVariable.c_str();
+ }
+ return GrGLSLUniformHandler::UniformHandle(fUniforms.count() - 1);
+}
+
+void GrGLUniformHandler::appendUniformDecls(ShaderVisibility visibility, SkString* out) const {
+ for (int i = 0; i < fUniforms.count(); ++i) {
+ if (fUniforms[i].fVisibility & visibility) {
+ fUniforms[i].fVariable.appendDecl(fProgramBuilder->glslCaps(), out);
+ out->append(";\n");
+ }
+ }
+}
+
+void GrGLUniformHandler::bindUniformLocations(GrGLuint programID, const GrGLCaps& caps) {
+ if (caps.bindUniformLocationSupport()) {
+ int count = fUniforms.count();
+ for (int i = 0; i < count; ++i) {
+ GL_CALL(BindUniformLocation(programID, i, fUniforms[i].fVariable.c_str()));
+ fUniforms[i].fLocation = i;
+ }
+ }
+}
+
+void GrGLUniformHandler::getUniformLocations(GrGLuint programID, const GrGLCaps& caps) {
+ if (!caps.bindUniformLocationSupport()) {
+ int count = fUniforms.count();
+ for (int i = 0; i < count; ++i) {
+ GrGLint location;
+ GL_CALL_RET(location, GetUniformLocation(programID, fUniforms[i].fVariable.c_str()));
+ fUniforms[i].fLocation = location;
+ }
+ }
+}
+
+const GrGLGpu* GrGLUniformHandler::glGpu() const {
+ GrGLProgramBuilder* glPB = (GrGLProgramBuilder*) fProgramBuilder;
+ return glPB->gpu();
+}
+
+
diff --git a/src/gpu/gl/GrGLUniformHandler.h b/src/gpu/gl/GrGLUniformHandler.h
new file mode 100644
index 0000000000..a782bcb1c3
--- /dev/null
+++ b/src/gpu/gl/GrGLUniformHandler.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrGLUniformHandler_DEFINED
+#define GrGLUniformHandler_DEFINED
+
+#include "glsl/GrGLSLUniformHandler.h"
+
+#include "gl/GrGLProgramDataManager.h"
+
+class GrGLCaps;
+
+static const int kUniformsPerBlock = 8;
+
+class GrGLUniformHandler : public GrGLSLUniformHandler {
+public:
+ const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const override {
+ return fUniforms[u.toIndex()].fVariable;
+ }
+
+ const char* getUniformCStr(UniformHandle u) const override {
+ return this->getUniformVariable(u).c_str();
+ }
+private:
+ explicit GrGLUniformHandler(GrGLSLProgramBuilder* program)
+ : INHERITED(program)
+ , fUniforms(kUniformsPerBlock) {}
+
+ UniformHandle internalAddUniformArray(uint32_t visibility,
+ GrSLType type,
+ GrSLPrecision precision,
+ const char* name,
+ bool mangleName,
+ int arrayCount,
+ const char** outName) override;
+
+ void appendUniformDecls(ShaderVisibility, SkString*) const override;
+
+ // Manually set uniform locations for all our uniforms.
+ void bindUniformLocations(GrGLuint programID, const GrGLCaps& caps);
+
+ // Updates the loction of the Uniforms if we cannot bind uniform locations manually
+ void getUniformLocations(GrGLuint programID, const GrGLCaps& caps);
+
+ const GrGLGpu* glGpu() const;
+
+ typedef GrGLProgramDataManager::UniformInfo UniformInfo;
+ typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray;
+
+ UniformInfoArray fUniforms;
+
+ friend class GrGLProgramBuilder;
+
+ typedef GrGLSLUniformHandler INHERITED;
+};
+
+#endif
diff --git a/src/gpu/gl/GrGLVaryingHandler.h b/src/gpu/gl/GrGLVaryingHandler.h
index ab931debd7..50a87adc03 100644
--- a/src/gpu/gl/GrGLVaryingHandler.h
+++ b/src/gpu/gl/GrGLVaryingHandler.h
@@ -21,7 +21,7 @@ public:
// This function is used by the NVPR PathProcessor to add a varying directly into the fragment
// shader since there is no vertex shader.
VaryingHandle addPathProcessingVarying(const char* name, GrGLSLVertToFrag*,
- GrSLPrecision fsPrecision = kDefault_GrSLPrecision);
+ GrSLPrecision fsPrecision = kDefault_GrSLPrecision);
private:
typedef GrGLProgramDataManager::VaryingInfo VaryingInfo;
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index 86264c02de..dc9393db07 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -55,56 +55,9 @@ GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu, const DrawArgs& args)
, fGeometryProcessor(nullptr)
, fXferProcessor(nullptr)
, fGpu(gpu)
- , fUniforms(kVarsPerBlock)
, fSamplerUniforms(4)
- , fVaryingHandler(this) {
-}
-
-GrGLSLProgramDataManager::UniformHandle GrGLProgramBuilder::internalAddUniformArray(
- uint32_t visibility,
- GrSLType type,
- GrSLPrecision precision,
- const char* name,
- bool mangleName,
- int count,
- const char** outName) {
- SkASSERT(name && strlen(name));
- SkDEBUGCODE(static const uint32_t kVisibilityMask = kVertex_Visibility | kFragment_Visibility);
- SkASSERT(0 == (~kVisibilityMask & visibility));
- SkASSERT(0 != visibility);
- SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type));
-
- UniformInfo& uni = fUniforms.push_back();
- uni.fVariable.setType(type);
- uni.fVariable.setTypeModifier(GrGLSLShaderVar::kUniform_TypeModifier);
- // TODO this is a bit hacky, lets think of a better way. Basically we need to be able to use
- // the uniform view matrix name in the GP, and the GP is immutable so it has to tell the PB
- // exactly what name it wants to use for the uniform view matrix. If we prefix anythings, then
- // the names will mismatch. I think the correct solution is to have all GPs which need the
- // uniform view matrix, they should upload the view matrix in their setData along with regular
- // uniforms.
- char prefix = 'u';
- if ('u' == name[0]) {
- prefix = '\0';
- }
- this->nameVariable(uni.fVariable.accessName(), prefix, name, mangleName);
- uni.fVariable.setArrayCount(count);
- uni.fVisibility = visibility;
- uni.fVariable.setPrecision(precision);
-
- if (outName) {
- *outName = uni.fVariable.c_str();
- }
- return GrGLSLProgramDataManager::UniformHandle(fUniforms.count() - 1);
-}
-
-void GrGLProgramBuilder::onAppendUniformDecls(ShaderVisibility visibility, SkString* out) const {
- for (int i = 0; i < fUniforms.count(); ++i) {
- if (fUniforms[i].fVisibility & visibility) {
- fUniforms[i].fVariable.appendDecl(this->glslCaps(), out);
- out->append(";\n");
- }
- }
+ , fVaryingHandler(this)
+ , fUniformHandler(this) {
}
const GrGLSLCaps* GrGLProgramBuilder::glslCaps() const {
@@ -220,8 +173,8 @@ void GrGLProgramBuilder::emitAndInstallProc(const GrFragmentProcessor& fp,
SkSTArray<4, GrGLSLTextureSampler> samplers(fp.numTextures());
this->emitSamplers(fp, &samplers, ifp);
- GrGLSLFragmentProcessor::EmitArgs args(this,
- &fFS,
+ GrGLSLFragmentProcessor::EmitArgs args(&fFS,
+ &fUniformHandler,
this->glslCaps(),
fp,
outColor,
@@ -247,10 +200,10 @@ void GrGLProgramBuilder::emitAndInstallProc(const GrPrimitiveProcessor& gp,
SkSTArray<4, GrGLSLTextureSampler> samplers(gp.numTextures());
this->emitSamplers(gp, &samplers, fGeometryProcessor);
- GrGLSLGeometryProcessor::EmitArgs args(this,
- &fVS,
+ GrGLSLGeometryProcessor::EmitArgs args(&fVS,
&fFS,
&fVaryingHandler,
+ &fUniformHandler,
this->glslCaps(),
gp,
outColor,
@@ -293,8 +246,8 @@ void GrGLProgramBuilder::emitAndInstallXferProc(const GrXferProcessor& xp,
SkSTArray<4, GrGLSLTextureSampler> samplers(xp.numTextures());
this->emitSamplers(xp, &samplers, fXferProcessor);
- GrGLSLXferProcessor::EmitArgs args(this,
- &fFS,
+ GrGLSLXferProcessor::EmitArgs args(&fFS,
+ &fUniformHandler,
this->glslCaps(),
xp, colorIn.c_str(),
ignoresCoverage ? nullptr : coverageIn.c_str(),
@@ -342,9 +295,10 @@ void GrGLProgramBuilder::emitSamplers(const GrProcessor& processor,
for (int t = 0; t < numTextures; ++t) {
name.printf("Sampler%d", t);
GrSLType samplerType = get_sampler_type(processor.textureAccess(t));
- localSamplerUniforms[t] = this->addUniform(GrGLProgramBuilder::kFragment_Visibility,
- samplerType, kDefault_GrSLPrecision,
- name.c_str());
+ localSamplerUniforms[t] =
+ fUniformHandler.addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ samplerType, kDefault_GrSLPrecision,
+ name.c_str());
SkNEW_APPEND_TO_TARRAY(outSamplers, GrGLSLTextureSampler,
(localSamplerUniforms[t], processor.textureAccess(t)));
if (kSamplerExternal_GrSLType == samplerType) {
@@ -389,7 +343,7 @@ GrGLProgram* GrGLProgramBuilder::finalize() {
// compile shaders and bind attributes / uniforms
SkTDArray<GrGLuint> shadersToDelete;
- fVS.finalize(kVertex_Visibility);
+ fVS.finalize(GrGLSLUniformHandler::kVertex_Visibility);
if (!this->compileAndAttachShaders(fVS, programID, GR_GL_VERTEX_SHADER, &shadersToDelete)) {
this->cleanupProgram(programID, shadersToDelete);
return nullptr;
@@ -406,7 +360,7 @@ GrGLProgram* GrGLProgramBuilder::finalize() {
}
}
- fFS.finalize(kFragment_Visibility);
+ fFS.finalize(GrGLSLUniformHandler::kFragment_Visibility);
if (!this->compileAndAttachShaders(fFS, programID, GR_GL_FRAGMENT_SHADER, &shadersToDelete)) {
this->cleanupProgram(programID, shadersToDelete);
return nullptr;
@@ -432,13 +386,7 @@ GrGLProgram* GrGLProgramBuilder::finalize() {
}
void GrGLProgramBuilder::bindProgramResourceLocations(GrGLuint programID) {
- if (fGpu->glCaps().bindUniformLocationSupport()) {
- int count = fUniforms.count();
- for (int i = 0; i < count; ++i) {
- GL_CALL(BindUniformLocation(programID, i, fUniforms[i].fVariable.c_str()));
- fUniforms[i].fLocation = i;
- }
- }
+ fUniformHandler.bindUniformLocations(programID, fGpu->glCaps());
const GrGLCaps& caps = this->gpu()->glCaps();
if (fFS.hasCustomColorOutput() && caps.bindFragDataLocationSupport()) {
@@ -488,14 +436,7 @@ bool GrGLProgramBuilder::checkLinkStatus(GrGLuint programID) {
}
void GrGLProgramBuilder::resolveProgramResourceLocations(GrGLuint programID) {
- if (!fGpu->glCaps().bindUniformLocationSupport()) {
- int count = fUniforms.count();
- for (int i = 0; i < count; ++i) {
- GrGLint location;
- GL_CALL_RET(location, GetUniformLocation(programID, fUniforms[i].fVariable.c_str()));
- fUniforms[i].fLocation = location;
- }
- }
+ fUniformHandler.getUniformLocations(programID, fGpu->glCaps());
// handle NVPR separable varyings
if (!fGpu->glCaps().shaderCaps()->pathRenderingSupport() ||
@@ -524,9 +465,15 @@ void GrGLProgramBuilder::cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs) {
}
GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) {
- return new GrGLProgram(fGpu, this->desc(), fUniformHandles, programID, fUniforms,
+ return new GrGLProgram(fGpu,
+ this->desc(),
+ fUniformHandles,
+ programID,
+ fUniformHandler.fUniforms,
fVaryingHandler.fPathProcVaryingInfos,
- fGeometryProcessor, fXferProcessor, fFragmentProcessors.get(),
+ fGeometryProcessor,
+ fXferProcessor,
+ fFragmentProcessors.get(),
&fSamplerUniforms);
}
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.h b/src/gpu/gl/builders/GrGLProgramBuilder.h
index 329e5d7d08..cbec5a9863 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.h
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.h
@@ -10,6 +10,7 @@
#include "GrPipeline.h"
#include "gl/GrGLProgramDataManager.h"
+#include "gl/GrGLUniformHandler.h"
#include "gl/GrGLVaryingHandler.h"
#include "glsl/GrGLSLPrimitiveProcessor.h"
#include "glsl/GrGLSLProgramBuilder.h"
@@ -58,32 +59,13 @@ public:
*/
static GrGLProgram* CreateProgram(const DrawArgs&, GrGLGpu*);
- const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const override {
- return fUniforms[u.toIndex()].fVariable;
- }
-
- const char* getUniformCStr(UniformHandle u) const override {
- return this->getUniformVariable(u).c_str();
- }
-
const GrGLSLCaps* glslCaps() const override;
GrGLGpu* gpu() const { return fGpu; }
private:
- typedef GrGLProgramDataManager::UniformInfo UniformInfo;
- typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray;
-
GrGLProgramBuilder(GrGLGpu*, const DrawArgs&);
- UniformHandle internalAddUniformArray(uint32_t visibility,
- GrSLType type,
- GrSLPrecision precision,
- const char* name,
- bool mangleName,
- int arrayCount,
- const char** outName) override;
-
// Generates a possibly mangled name for a stage variable and writes it to the fragment shader.
// If GrGLSLExpr4 has a valid name then it will use that instead
void nameExpression(GrGLSLExpr4*, const char* baseName);
@@ -133,8 +115,8 @@ private:
// Subclasses create different programs
GrGLProgram* createProgram(GrGLuint programID);
- void onAppendUniformDecls(ShaderVisibility visibility, SkString* out) const override;
-
+ GrGLSLUniformHandler* uniformHandler() override { return &fUniformHandler; }
+ const GrGLSLUniformHandler* uniformHandler() const override { return &fUniformHandler; }
GrGLSLVaryingHandler* varyingHandler() override { return &fVaryingHandler; }
// reset is called by program creator between each processor's emit code. It increments the
@@ -164,14 +146,13 @@ private:
SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors;
GrGLGpu* fGpu;
- UniformInfoArray fUniforms;
GrGLSLPrimitiveProcessor::TransformsIn fCoordTransforms;
GrGLSLPrimitiveProcessor::TransformsOut fOutCoords;
+ typedef GrGLSLUniformHandler::UniformHandle UniformHandle;
SkTArray<UniformHandle> fSamplerUniforms;
GrGLVaryingHandler fVaryingHandler;
-
- friend class GrGLVaryingHandler;
+ GrGLUniformHandler fUniformHandler;
typedef GrGLSLProgramBuilder INHERITED;
};
diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.cpp b/src/gpu/glsl/GrGLSLFragmentProcessor.cpp
index a0019669f2..649bd99dea 100644
--- a/src/gpu/glsl/GrGLSLFragmentProcessor.cpp
+++ b/src/gpu/glsl/GrGLSLFragmentProcessor.cpp
@@ -9,7 +9,7 @@
#include "GrFragmentProcessor.h"
#include "GrProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
+#include "glsl/GrGLSLUniformHandler.h"
void GrGLSLFragmentProcessor::setData(const GrGLSLProgramDataManager& pdman,
const GrFragmentProcessor& processor) {
@@ -93,8 +93,8 @@ void GrGLSLFragmentProcessor::internalEmitChild(int childIndex, const char* inpu
fragBuilder->codeAppend("{\n");
fragBuilder->codeAppendf("// Child Index %d (mangle: %s): %s\n", childIndex,
fragBuilder->getMangleString().c_str(), childProc.name());
- EmitArgs childArgs(args.fBuilder,
- fragBuilder,
+ EmitArgs childArgs(fragBuilder,
+ args.fUniformHandler,
args.fGLSLCaps,
childProc,
outputColor,
diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.h b/src/gpu/glsl/GrGLSLFragmentProcessor.h
index 0fd1ae3c32..ca72a9c415 100644
--- a/src/gpu/glsl/GrGLSLFragmentProcessor.h
+++ b/src/gpu/glsl/GrGLSLFragmentProcessor.h
@@ -14,9 +14,10 @@
class GrProcessor;
class GrProcessorKeyBuilder;
+class GrGLSLCaps;
class GrGLSLFPBuilder;
class GrGLSLFragmentBuilder;
-class GrGLSLCaps;
+class GrGLSLUniformHandler;
class GrGLSLFragmentProcessor {
public:
@@ -51,24 +52,24 @@ public:
*/
struct EmitArgs {
- EmitArgs(GrGLSLFPBuilder* builder,
- GrGLSLFragmentBuilder* fragBuilder,
+ EmitArgs(GrGLSLFragmentBuilder* fragBuilder,
+ GrGLSLUniformHandler* uniformHandler,
const GrGLSLCaps* caps,
const GrFragmentProcessor& fp,
const char* outputColor,
const char* inputColor,
const GrGLSLTransformedCoordsArray& coords,
const TextureSamplerArray& samplers)
- : fBuilder(builder)
- , fFragBuilder(fragBuilder)
+ : fFragBuilder(fragBuilder)
+ , fUniformHandler(uniformHandler)
, fGLSLCaps(caps)
, fFp(fp)
, fOutputColor(outputColor)
, fInputColor(inputColor)
, fCoords(coords)
, fSamplers(samplers) {}
- GrGLSLFPBuilder* fBuilder;
GrGLSLFragmentBuilder* fFragBuilder;
+ GrGLSLUniformHandler* fUniformHandler;
const GrGLSLCaps* fGLSLCaps;
const GrFragmentProcessor& fFp;
const char* fOutputColor;
diff --git a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
index 122db10ec9..47708f370d 100644
--- a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp
@@ -10,6 +10,7 @@
#include "glsl/GrGLSL.h"
#include "glsl/GrGLSLCaps.h"
#include "glsl/GrGLSLProgramBuilder.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLVarying.h"
const char* GrGLSLFragmentShaderBuilder::kDstTextureColorName = "_dstColor";
@@ -136,15 +137,9 @@ const char* GrGLSLFragmentShaderBuilder::fragmentPosition() {
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);
+ fProgramBuilder->addRTHeightUniform("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,
diff --git a/src/gpu/glsl/GrGLSLGeometryProcessor.cpp b/src/gpu/glsl/GrGLSLGeometryProcessor.cpp
index 8a1e81a1f8..a8bd8ac4f8 100644
--- a/src/gpu/glsl/GrGLSLGeometryProcessor.cpp
+++ b/src/gpu/glsl/GrGLSLGeometryProcessor.cpp
@@ -7,9 +7,10 @@
#include "GrGLSLGeometryProcessor.h"
+#include "GrCoordTransform.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLProcessorTypes.h"
-#include "glsl/GrGLSLProgramBuilder.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLVarying.h"
#include "glsl/GrGLSLVertexShaderBuilder.h"
@@ -20,9 +21,9 @@ void GrGLSLGeometryProcessor::emitCode(EmitArgs& args) {
vBuilder->transformToNormalizedDeviceSpace(gpArgs.fPositionVar);
}
-void GrGLSLGeometryProcessor::emitTransforms(GrGLSLGPBuilder* pb,
- GrGLSLVertexBuilder* vb,
+void GrGLSLGeometryProcessor::emitTransforms(GrGLSLVertexBuilder* vb,
GrGLSLVaryingHandler* varyingHandler,
+ GrGLSLUniformHandler* uniformHandler,
const GrShaderVar& posVar,
const char* localCoords,
const SkMatrix& localMatrix,
@@ -49,10 +50,10 @@ void GrGLSLGeometryProcessor::emitTransforms(GrGLSLGPBuilder* pb,
const char* uniName;
fInstalledTransforms[i][t].fHandle =
- pb->addUniform(GrGLSLProgramBuilder::kVertex_Visibility,
- kMat33f_GrSLType, precision,
- strUniName.c_str(),
- &uniName).toIndex();
+ uniformHandler->addUniform(GrGLSLUniformHandler::kVertex_Visibility,
+ kMat33f_GrSLType, precision,
+ strUniName.c_str(),
+ &uniName).toIndex();
SkString strVaryingName("MatrixCoord");
strVaryingName.appendf("_%i_%i", i, t);
@@ -94,8 +95,7 @@ void GrGLSLGeometryProcessor::emitTransforms(GrGLSLGPBuilder* pb,
}
}
-void GrGLSLGeometryProcessor::emitTransforms(GrGLSLGPBuilder* pb,
- GrGLSLVertexBuilder* vb,
+void GrGLSLGeometryProcessor::emitTransforms(GrGLSLVertexBuilder* vb,
GrGLSLVaryingHandler* varyingHandler,
const char* localCoords,
const TransformsIn& tin,
@@ -124,16 +124,15 @@ void GrGLSLGeometryProcessor::emitTransforms(GrGLSLGPBuilder* pb,
}
}
-void GrGLSLGeometryProcessor::setupPosition(GrGLSLGPBuilder* pb,
- GrGLSLVertexBuilder* vertBuilder,
+void GrGLSLGeometryProcessor::setupPosition(GrGLSLVertexBuilder* vertBuilder,
GrGPArgs* gpArgs,
const char* posName) {
gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2");
vertBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), posName);
}
-void GrGLSLGeometryProcessor::setupPosition(GrGLSLGPBuilder* pb,
- GrGLSLVertexBuilder* vertBuilder,
+void GrGLSLGeometryProcessor::setupPosition(GrGLSLVertexBuilder* vertBuilder,
+ GrGLSLUniformHandler* uniformHandler,
GrGPArgs* gpArgs,
const char* posName,
const SkMatrix& mat,
@@ -143,10 +142,10 @@ void GrGLSLGeometryProcessor::setupPosition(GrGLSLGPBuilder* pb,
vertBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), posName);
} else {
const char* viewMatrixName;
- *viewMatrixUniform = pb->addUniform(GrGLSLProgramBuilder::kVertex_Visibility,
- kMat33f_GrSLType, kHigh_GrSLPrecision,
- "uViewM",
- &viewMatrixName);
+ *viewMatrixUniform = uniformHandler->addUniform(GrGLSLUniformHandler::kVertex_Visibility,
+ kMat33f_GrSLType, kHigh_GrSLPrecision,
+ "uViewM",
+ &viewMatrixName);
if (!mat.hasPerspective()) {
gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2");
vertBuilder->codeAppendf("vec2 %s = vec2(%s * vec3(%s, 1));",
diff --git a/src/gpu/glsl/GrGLSLGeometryProcessor.h b/src/gpu/glsl/GrGLSLGeometryProcessor.h
index 4c586a7900..84a8f8b963 100644
--- a/src/gpu/glsl/GrGLSLGeometryProcessor.h
+++ b/src/gpu/glsl/GrGLSLGeometryProcessor.h
@@ -42,20 +42,21 @@ public:
protected:
// Emit a uniform matrix for each coord transform.
- void emitTransforms(GrGLSLGPBuilder* gp,
- GrGLSLVertexBuilder* vb,
+ void emitTransforms(GrGLSLVertexBuilder* vb,
GrGLSLVaryingHandler* varyingHandler,
+ GrGLSLUniformHandler* uniformHandler,
const GrShaderVar& posVar,
const char* localCoords,
const TransformsIn& tin,
TransformsOut* tout) {
- this->emitTransforms(gp, vb, varyingHandler, posVar, localCoords, SkMatrix::I(), tin, tout);
+ this->emitTransforms(vb, varyingHandler, uniformHandler,
+ posVar, localCoords, SkMatrix::I(), tin, tout);
}
// Emit pre-transformed coords as a vertex attribute per coord-transform.
- void emitTransforms(GrGLSLGPBuilder*,
- GrGLSLVertexBuilder*,
+ void emitTransforms(GrGLSLVertexBuilder*,
GrGLSLVaryingHandler*,
+ GrGLSLUniformHandler*,
const GrShaderVar& posVar,
const char* localCoords,
const SkMatrix& localMatrix,
@@ -63,8 +64,7 @@ protected:
TransformsOut*);
// caller has emitted transforms via attributes
- void emitTransforms(GrGLSLGPBuilder*,
- GrGLSLVertexBuilder*,
+ void emitTransforms(GrGLSLVertexBuilder*,
GrGLSLVaryingHandler*,
const char* localCoords,
const TransformsIn& tin,
@@ -77,9 +77,9 @@ protected:
};
// Create the correct type of position variable given the CTM
- void setupPosition(GrGLSLGPBuilder*, GrGLSLVertexBuilder*, GrGPArgs*, const char* posName);
- void setupPosition(GrGLSLGPBuilder*,
- GrGLSLVertexBuilder*,
+ void setupPosition(GrGLSLVertexBuilder*, GrGPArgs*, const char* posName);
+ void setupPosition(GrGLSLVertexBuilder*,
+ GrGLSLUniformHandler* uniformHandler,
GrGPArgs*,
const char* posName,
const SkMatrix& mat,
diff --git a/src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp b/src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp
index 70b58cda94..23bb249af7 100644
--- a/src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp
+++ b/src/gpu/glsl/GrGLSLPrimitiveProcessor.cpp
@@ -7,8 +7,10 @@
#include "GrGLSLPrimitiveProcessor.h"
-#include "glsl/GrGLSLProgramBuilder.h"
+#include "GrCoordTransform.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
+#include "glsl/GrGLSLUniformHandler.h"
+#include "glsl/GrGLSLVertexShaderBuilder.h"
SkMatrix GrGLSLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatrix,
const GrCoordTransform& coordTransform) {
@@ -32,16 +34,16 @@ SkMatrix GrGLSLPrimitiveProcessor::GetTransformMatrix(const SkMatrix& localMatri
return combined;
}
-void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLGPBuilder* pb,
- GrGLSLFragmentBuilder* fragBuilder,
+void GrGLSLPrimitiveProcessor::setupUniformColor(GrGLSLFragmentBuilder* fragBuilder,
+ GrGLSLUniformHandler* uniformHandler,
const char* outputName,
UniformHandle* colorUniform) {
SkASSERT(colorUniform);
const char* stagedLocalVarName;
- *colorUniform = pb->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec4f_GrSLType,
- kDefault_GrSLPrecision,
- "Color",
- &stagedLocalVarName);
+ *colorUniform = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec4f_GrSLType,
+ kDefault_GrSLPrecision,
+ "Color",
+ &stagedLocalVarName);
fragBuilder->codeAppendf("%s = %s;", outputName, stagedLocalVarName);
}
diff --git a/src/gpu/glsl/GrGLSLPrimitiveProcessor.h b/src/gpu/glsl/GrGLSLPrimitiveProcessor.h
index d164bbe53e..9fa5150e82 100644
--- a/src/gpu/glsl/GrGLSLPrimitiveProcessor.h
+++ b/src/gpu/glsl/GrGLSLPrimitiveProcessor.h
@@ -18,6 +18,7 @@ class GrPrimitiveProcessor;
class GrGLSLCaps;
class GrGLSLFragmentBuilder;
class GrGLSLGPBuilder;
+class GrGLSLUniformHandler;
class GrGLSLVaryingHandler;
class GrGLSLVertexBuilder;
@@ -33,10 +34,10 @@ public:
typedef SkSTArray<8, GrGLSLTransformedCoordsArray> TransformsOut;
struct EmitArgs {
- EmitArgs(GrGLSLGPBuilder* pb,
- GrGLSLVertexBuilder* vertBuilder,
+ EmitArgs(GrGLSLVertexBuilder* vertBuilder,
GrGLSLFragmentBuilder* fragBuilder,
GrGLSLVaryingHandler* varyingHandler,
+ GrGLSLUniformHandler* uniformHandler,
const GrGLSLCaps* caps,
const GrPrimitiveProcessor& gp,
const char* outputColor,
@@ -44,10 +45,10 @@ public:
const TextureSamplerArray& samplers,
const TransformsIn& transformsIn,
TransformsOut* transformsOut)
- : fPB(pb)
- , fVertBuilder(vertBuilder)
+ : fVertBuilder(vertBuilder)
, fFragBuilder(fragBuilder)
, fVaryingHandler(varyingHandler)
+ , fUniformHandler(uniformHandler)
, fGLSLCaps(caps)
, fGP(gp)
, fOutputColor(outputColor)
@@ -55,10 +56,10 @@ public:
, fSamplers(samplers)
, fTransformsIn(transformsIn)
, fTransformsOut(transformsOut) {}
- GrGLSLGPBuilder* fPB;
GrGLSLVertexBuilder* fVertBuilder;
GrGLSLFragmentBuilder* fFragBuilder;
GrGLSLVaryingHandler* fVaryingHandler;
+ GrGLSLUniformHandler* fUniformHandler;
const GrGLSLCaps* fGLSLCaps;
const GrPrimitiveProcessor& fGP;
const char* fOutputColor;
@@ -91,8 +92,8 @@ public:
const SkTArray<const GrCoordTransform*, true>& transforms) = 0;
protected:
- void setupUniformColor(GrGLSLGPBuilder* pb,
- GrGLSLFragmentBuilder* fragBuilder,
+ void setupUniformColor(GrGLSLFragmentBuilder* fragBuilder,
+ GrGLSLUniformHandler* uniformHandler,
const char* outputName,
UniformHandle* colorUniform);
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
index 54e82b30c0..d3ed719fdc 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
@@ -34,6 +34,27 @@ void GrGLSLProgramBuilder::nameVariable(SkString* out, char prefix, const char*
void GrGLSLProgramBuilder::appendUniformDecls(ShaderVisibility visibility,
SkString* out) const {
- this->onAppendUniformDecls(visibility, out);
+ this->uniformHandler()->appendUniformDecls(visibility, out);
+}
+
+void GrGLSLProgramBuilder::addRTAdjustmentUniform(GrSLPrecision precision,
+ const char* name,
+ const char** outName) {
+ SkASSERT(!fUniformHandles.fRTAdjustmentUni.isValid());
+ fUniformHandles.fRTAdjustmentUni =
+ this->uniformHandler()->addUniform(GrGLSLUniformHandler::kVertex_Visibility,
+ kVec4f_GrSLType,
+ precision,
+ name,
+ outName);
+}
+
+void GrGLSLProgramBuilder::addRTHeightUniform(const char* name, const char** outName) {
+ SkASSERT(!fUniformHandles.fRTHeightUni.isValid());
+ GrGLSLUniformHandler* uniformHandler = this->uniformHandler();
+ fUniformHandles.fRTHeightUni =
+ uniformHandler->internalAddUniformArray(GrGLSLUniformHandler::kFragment_Visibility,
+ kFloat_GrSLType, kDefault_GrSLPrecision,
+ name, false, 0, outName);
}
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.h b/src/gpu/glsl/GrGLSLProgramBuilder.h
index 81037084e9..2a3b48508c 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.h
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.h
@@ -13,104 +13,29 @@
#include "glsl/GrGLSLFragmentShaderBuilder.h"
#include "glsl/GrGLSLGeometryShaderBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLVertexShaderBuilder.h"
class GrGLSLCaps;
class GrGLSLShaderVar;
class GrGLSLVaryingHandler;
-// Enough precision to represent 1 / 2048 accurately in printf
-#define GR_SIGNIFICANT_POW2_DECIMAL_DIG 11
-
-class GrGLSLUniformBuilder {
-public:
- enum ShaderVisibility {
- kVertex_Visibility = 1 << kVertex_GrShaderType,
- kGeometry_Visibility = 1 << kGeometry_GrShaderType,
- kFragment_Visibility = 1 << kFragment_GrShaderType,
- };
-
- virtual ~GrGLSLUniformBuilder() {}
-
- typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
-
- /** Add a uniform variable to the current program, that has visibility in one or more shaders.
- visibility is a bitfield of ShaderVisibility values indicating from which shaders the
- uniform should be accessible. At least one bit must be set. Geometry shader uniforms are not
- supported at this time. The actual uniform name will be mangled. If outName is not nullptr
- then it will refer to the final uniform name after return. Use the addUniformArray variant
- to add an array of uniforms. */
- UniformHandle addUniform(uint32_t visibility,
- GrSLType type,
- GrSLPrecision precision,
- const char* name,
- const char** outName = nullptr) {
- return this->addUniformArray(visibility, type, precision, name, 0, outName);
- }
-
- UniformHandle addUniformArray(uint32_t visibility,
- GrSLType type,
- GrSLPrecision precision,
- const char* name,
- int arrayCount,
- const char** outName = nullptr) {
- return this->internalAddUniformArray(visibility, type, precision, name, true, arrayCount,
- outName);
- }
-
- virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0;
-
- /**
- * Shortcut for getUniformVariable(u).c_str()
- */
- virtual const char* getUniformCStr(UniformHandle u) const = 0;
-
- /*
- * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
- */
-protected:
- virtual UniformHandle internalAddUniformArray(
- uint32_t visibility,
- GrSLType type,
- GrSLPrecision precision,
- const char* name,
- bool mangleName,
- int arrayCount,
- const char** outName) = 0;
-};
-
-/* a specialization of the above for GPs. Lets the user add uniforms, varyings, and VS / FS code */
-class GrGLSLGPBuilder : public virtual GrGLSLUniformBuilder {
+class GrGLSLProgramBuilder {
public:
- /*
- * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
- */
-};
-
+ typedef GrGpu::DrawArgs DrawArgs;
+ typedef GrGLSLUniformHandler::ShaderVisibility ShaderVisibility;
+ typedef GrGLSLUniformHandler::UniformHandle UniformHandle;
-/* a specializations for FPs. Lets the user add uniforms and FS code */
-class GrGLSLFPBuilder : public virtual GrGLSLUniformBuilder {
-public:
- /*
- * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
- */
-};
+ virtual ~GrGLSLProgramBuilder() {}
-/* a specializations for XPs. Lets the user add uniforms and FS code */
-class GrGLSLXPBuilder : public virtual GrGLSLUniformBuilder {
-public:
- /*
- * *NOTE* NO MEMBERS ALLOWED, MULTIPLE INHERITANCE
- */
-};
+ virtual const GrGLSLCaps* glslCaps() const = 0;
-class GrGLSLProgramBuilder : public GrGLSLGPBuilder,
- public GrGLSLFPBuilder,
- public GrGLSLXPBuilder {
-public:
- typedef GrGpu::DrawArgs DrawArgs;
+ const GrPrimitiveProcessor& primitiveProcessor() const { return *fArgs.fPrimitiveProcessor; }
+ const GrPipeline& pipeline() const { return *fArgs.fPipeline; }
+ const GrProgramDesc& desc() const { return *fArgs.fDesc; }
+ const GrProgramDesc::KeyHeader& header() const { return fArgs.fDesc->header(); }
- virtual const GrGLSLCaps* glslCaps() const = 0;
+ void appendUniformDecls(ShaderVisibility, SkString*) const;
// Handles for program uniforms (other than per-effect uniforms)
struct BuiltinUniformHandles {
@@ -121,33 +46,21 @@ public:
UniformHandle fRTHeightUni;
};
-protected:
- explicit GrGLSLProgramBuilder(const DrawArgs& args);
-
- const GrPrimitiveProcessor& primitiveProcessor() const { return *fArgs.fPrimitiveProcessor; }
- const GrPipeline& pipeline() const { return *fArgs.fPipeline; }
- const GrProgramDesc& desc() const { return *fArgs.fDesc; }
- const GrProgramDesc::KeyHeader& header() const { return fArgs.fDesc->header(); }
-
- void appendUniformDecls(ShaderVisibility, SkString*) const;
-
- // Used to add a uniform for frag position without mangling the name of the uniform inside of a
- // stage.
- UniformHandle addFragPosUniform(uint32_t visibility,
- GrSLType type,
- GrSLPrecision precision,
- const char* name,
- const char** outName) {
- return this->internalAddUniformArray(visibility, type, precision, name, false, 0, outName);
- }
-
+ // Used to add a uniform in the vertex shader for transforming into normalized device space.
+ void addRTAdjustmentUniform(GrSLPrecision precision, const char* name, const char** outName);
const char* rtAdjustment() const { return "rtAdjustment"; }
+
+ // Used to add a uniform for the RenderTarget height (used for frag position) without mangling
+ // the name of the uniform inside of a stage.
+ void addRTHeightUniform(const char* name, const char** outName);
// Generates a name for a variable. The generated string will be name prefixed by the prefix
// char (unless the prefix is '\0'). It also will mangle the name to be stage-specific unless
// explicitly asked not to.
void nameVariable(SkString* out, char prefix, const char* name, bool mangle = true);
+ virtual GrGLSLUniformHandler* uniformHandler() = 0;
+ virtual const GrGLSLUniformHandler* uniformHandler() const = 0;
virtual GrGLSLVaryingHandler* varyingHandler() = 0;
// number of each input/output type in a single allocation block, used by many builders
@@ -159,18 +72,12 @@ protected:
int fStageIndex;
- BuiltinUniformHandles fUniformHandles;
-
const DrawArgs& fArgs;
-private:
- virtual void onAppendUniformDecls(ShaderVisibility visibility, SkString* out) const = 0;
+ BuiltinUniformHandles fUniformHandles;
- friend class GrGLSLShaderBuilder;
- friend class GrGLSLVertexBuilder;
- friend class GrGLSLFragmentShaderBuilder;
- friend class GrGLSLGeometryBuilder;
- friend class GrGLSLVaryingHandler;
+protected:
+ explicit GrGLSLProgramBuilder(const DrawArgs& args);
};
#endif
diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.cpp b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
index 1fc15ecb3c..5716c0bd12 100644
--- a/src/gpu/glsl/GrGLSLShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
@@ -117,9 +117,10 @@ void GrGLSLShaderBuilder::appendTextureLookup(SkString* out,
const GrGLSLTextureSampler& sampler,
const char* coordName,
GrSLType varyingType) const {
+ GrGLSLUniformHandler* uniformHandler = fProgramBuilder->uniformHandler();
append_texture_lookup(out,
fProgramBuilder->glslCaps(),
- fProgramBuilder->getUniformCStr(sampler.fSamplerUniform),
+ uniformHandler->getUniformCStr(sampler.fSamplerUniform),
coordName,
sampler.config(),
sampler.swizzle(),
@@ -187,7 +188,7 @@ void GrGLSLShaderBuilder::finalize(uint32_t visibility) {
this->versionDecl() = fProgramBuilder->glslCaps()->versionDeclString();
this->compileAndAppendLayoutQualifiers();
SkASSERT(visibility);
- fProgramBuilder->appendUniformDecls((GrGLSLProgramBuilder::ShaderVisibility) visibility,
+ fProgramBuilder->appendUniformDecls((GrGLSLUniformHandler::ShaderVisibility) visibility,
&this->uniforms());
this->appendDecls(fInputs, &this->inputs());
this->appendDecls(fOutputs, &this->outputs());
diff --git a/src/gpu/glsl/GrGLSLUniformHandler.h b/src/gpu/glsl/GrGLSLUniformHandler.h
new file mode 100644
index 0000000000..e72716d04e
--- /dev/null
+++ b/src/gpu/glsl/GrGLSLUniformHandler.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef GrGLSLUniformHandler_DEFINED
+#define GrGLSLUniformHandler_DEFINED
+
+#include "GrGLSLProgramDataManager.h"
+#include "GrGLSLShaderVar.h"
+
+class GrGLSLProgramBuilder;
+
+class GrGLSLUniformHandler {
+public:
+ enum ShaderVisibility {
+ kVertex_Visibility = 1 << kVertex_GrShaderType,
+ kGeometry_Visibility = 1 << kGeometry_GrShaderType,
+ kFragment_Visibility = 1 << kFragment_GrShaderType,
+ };
+
+ virtual ~GrGLSLUniformHandler() {}
+
+ typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
+
+ /** Add a uniform variable to the current program, that has visibility in one or more shaders.
+ visibility is a bitfield of ShaderVisibility values indicating from which shaders the
+ uniform should be accessible. At least one bit must be set. Geometry shader uniforms are not
+ supported at this time. The actual uniform name will be mangled. If outName is not nullptr
+ then it will refer to the final uniform name after return. Use the addUniformArray variant
+ to add an array of uniforms. */
+ UniformHandle addUniform(uint32_t visibility,
+ GrSLType type,
+ GrSLPrecision precision,
+ const char* name,
+ const char** outName = nullptr) {
+ return this->addUniformArray(visibility, type, precision, name, 0, outName);
+ }
+
+ UniformHandle addUniformArray(uint32_t visibility,
+ GrSLType type,
+ GrSLPrecision precision,
+ const char* name,
+ int arrayCount,
+ const char** outName = nullptr) {
+ return this->internalAddUniformArray(visibility, type, precision, name, true, arrayCount,
+ outName);
+ }
+
+ virtual const GrGLSLShaderVar& getUniformVariable(UniformHandle u) const = 0;
+
+ /**
+ * Shortcut for getUniformVariable(u).c_str()
+ */
+ virtual const char* getUniformCStr(UniformHandle u) const = 0;
+protected:
+ explicit GrGLSLUniformHandler(GrGLSLProgramBuilder* program) : fProgramBuilder(program) {}
+
+ // This is not owned by the class
+ GrGLSLProgramBuilder* fProgramBuilder;
+
+private:
+ virtual UniformHandle internalAddUniformArray(uint32_t visibility,
+ GrSLType type,
+ GrSLPrecision precision,
+ const char* name,
+ bool mangleName,
+ int arrayCount,
+ const char** outName) = 0;
+
+ virtual void appendUniformDecls(ShaderVisibility, SkString*) const = 0;
+
+ friend class GrGLSLProgramBuilder;
+};
+
+#endif
+
diff --git a/src/gpu/glsl/GrGLSLVertexShaderBuilder.cpp b/src/gpu/glsl/GrGLSLVertexShaderBuilder.cpp
index 73c0fcd81e..0504bbb354 100644
--- a/src/gpu/glsl/GrGLSLVertexShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLVertexShaderBuilder.cpp
@@ -7,6 +7,7 @@
#include "GrGLSLVertexShaderBuilder.h"
#include "glsl/GrGLSLProgramBuilder.h"
+#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLVarying.h"
GrGLSLVertexBuilder::GrGLSLVertexBuilder(GrGLSLProgramBuilder* program)
@@ -23,11 +24,9 @@ void GrGLSLVertexBuilder::transformToNormalizedDeviceSpace(const GrShaderVar& po
}
// setup RT Uniform
- fProgramBuilder->fUniformHandles.fRTAdjustmentUni =
- fProgramBuilder->addUniform(GrGLSLProgramBuilder::kVertex_Visibility,
- kVec4f_GrSLType, precision,
- fProgramBuilder->rtAdjustment(),
- &fRtAdjustName);
+ fProgramBuilder->addRTAdjustmentUniform(precision,
+ fProgramBuilder->rtAdjustment(),
+ &fRtAdjustName);
if (this->getProgramBuilder()->desc().header().fSnapVerticesToPixelCenters) {
if (kVec3f_GrSLType == posVar.getType()) {
const char* p = posVar.c_str();
diff --git a/src/gpu/glsl/GrGLSLVertexShaderBuilder.h b/src/gpu/glsl/GrGLSLVertexShaderBuilder.h
index b76721fd00..7c624cee65 100644
--- a/src/gpu/glsl/GrGLSLVertexShaderBuilder.h
+++ b/src/gpu/glsl/GrGLSLVertexShaderBuilder.h
@@ -13,6 +13,9 @@
class GrGLSLVarying;
+// Enough precision to represent 1 / 2048 accurately in printf
+#define GR_SIGNIFICANT_POW2_DECIMAL_DIG 11
+
class GrGLSLVertexBuilder : public GrGLSLShaderBuilder {
public:
GrGLSLVertexBuilder(GrGLSLProgramBuilder* program);
diff --git a/src/gpu/glsl/GrGLSLXferProcessor.cpp b/src/gpu/glsl/GrGLSLXferProcessor.cpp
index b6af968651..81bd015718 100644
--- a/src/gpu/glsl/GrGLSLXferProcessor.cpp
+++ b/src/gpu/glsl/GrGLSLXferProcessor.cpp
@@ -9,8 +9,8 @@
#include "GrXferProcessor.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProgramBuilder.h"
#include "glsl/GrGLSLProgramDataManager.h"
+#include "glsl/GrGLSLUniformHandler.h"
void GrGLSLXferProcessor::emitCode(const EmitArgs& args) {
if (!args.fXP.willReadDstColor()) {
@@ -19,6 +19,7 @@ void GrGLSLXferProcessor::emitCode(const EmitArgs& args) {
}
GrGLSLXPFragmentBuilder* fragBuilder = args.fXPFragBuilder;
+ GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
const char* dstColor = fragBuilder->dstColor();
if (args.fXP.getDstTexture()) {
@@ -35,16 +36,16 @@ void GrGLSLXferProcessor::emitCode(const EmitArgs& args) {
const char* dstTopLeftName;
const char* dstCoordScaleName;
- fDstTopLeftUni = args.fPB->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec2f_GrSLType,
- kDefault_GrSLPrecision,
- "DstTextureUpperLeft",
- &dstTopLeftName);
- fDstScaleUni = args.fPB->addUniform(GrGLSLProgramBuilder::kFragment_Visibility,
- kVec2f_GrSLType,
- kDefault_GrSLPrecision,
- "DstTextureCoordScale",
- &dstCoordScaleName);
+ fDstTopLeftUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec2f_GrSLType,
+ kDefault_GrSLPrecision,
+ "DstTextureUpperLeft",
+ &dstTopLeftName);
+ fDstScaleUni = uniformHandler->addUniform(GrGLSLUniformHandler::kFragment_Visibility,
+ kVec2f_GrSLType,
+ kDefault_GrSLPrecision,
+ "DstTextureCoordScale",
+ &dstCoordScaleName);
const char* fragPos = fragBuilder->fragmentPosition();
fragBuilder->codeAppend("// Read color from copy of the destination.\n");
@@ -60,8 +61,8 @@ void GrGLSLXferProcessor::emitCode(const EmitArgs& args) {
fragBuilder->codeAppend(";");
}
- this->emitBlendCodeForDstRead(args.fPB,
- fragBuilder,
+ this->emitBlendCodeForDstRead(fragBuilder,
+ uniformHandler,
args.fInputColor,
args.fInputCoverage,
dstColor,
diff --git a/src/gpu/glsl/GrGLSLXferProcessor.h b/src/gpu/glsl/GrGLSLXferProcessor.h
index 3707d93459..ed8099b6f3 100644
--- a/src/gpu/glsl/GrGLSLXferProcessor.h
+++ b/src/gpu/glsl/GrGLSLXferProcessor.h
@@ -12,9 +12,10 @@
#include "glsl/GrGLSLTextureSampler.h"
class GrXferProcessor;
+class GrGLSLCaps;
+class GrGLSLUniformHandler;
class GrGLSLXPBuilder;
class GrGLSLXPFragmentBuilder;
-class GrGLSLCaps;
class GrGLSLXferProcessor {
public:
@@ -23,8 +24,8 @@ public:
typedef GrGLSLTextureSampler::TextureSamplerArray TextureSamplerArray;
struct EmitArgs {
- EmitArgs(GrGLSLXPBuilder* pb,
- GrGLSLXPFragmentBuilder* fragBuilder,
+ EmitArgs(GrGLSLXPFragmentBuilder* fragBuilder,
+ GrGLSLUniformHandler* uniformHandler,
const GrGLSLCaps* caps,
const GrXferProcessor& xp,
const char* inputColor,
@@ -32,8 +33,8 @@ public:
const char* outputPrimary,
const char* outputSecondary,
const TextureSamplerArray& samplers)
- : fPB(pb)
- , fXPFragBuilder(fragBuilder)
+ : fXPFragBuilder(fragBuilder)
+ , fUniformHandler(uniformHandler)
, fGLSLCaps(caps)
, fXP(xp)
, fInputColor(inputColor)
@@ -42,8 +43,8 @@ public:
, fOutputSecondary(outputSecondary)
, fSamplers(samplers) {}
- GrGLSLXPBuilder* fPB;
GrGLSLXPFragmentBuilder* fXPFragBuilder;
+ GrGLSLUniformHandler* fUniformHandler;
const GrGLSLCaps* fGLSLCaps;
const GrXferProcessor& fXP;
const char* fInputColor;
@@ -82,8 +83,8 @@ private:
* the blending logic. The base class applies coverage. A subclass only needs to implement this
* method if it can construct a GrXferProcessor that reads the dst color.
*/
- virtual void emitBlendCodeForDstRead(GrGLSLXPBuilder*,
- GrGLSLXPFragmentBuilder*,
+ virtual void emitBlendCodeForDstRead(GrGLSLXPFragmentBuilder*,
+ GrGLSLUniformHandler*,
const char* srcColor,
const char* srcCoverage,
const char* dstColor,