aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2015-01-18 08:14:14 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-01-18 08:14:14 -0800
commit46d36f0e7b709a077c647841eee23bd3efdc4117 (patch)
treef1af8cebc0e3fbaa0eabc29cfbd781eedffee287 /src
parent75d98fd6f23fc73aad3ce87d6c4b6c41c2d1536e (diff)
Refactor position computation to enable device space "nudge"
To match raster's handling of BW geometry we want to be able to perform a device space "nudge" on all geometry. This CL sets us up to be able to do that in GrGLVertexBuilder::transformToNormalizedDeviceSpace. BUG=423834 TBR=bsalomon@google.com Review URL: https://codereview.chromium.org/854013002
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrAAConvexPathRenderer.cpp14
-rw-r--r--src/gpu/GrDefaultGeoProcFactory.cpp15
-rw-r--r--src/gpu/GrGeometryProcessor.cpp44
-rw-r--r--src/gpu/GrGeometryProcessor.h2
-rw-r--r--src/gpu/GrOvalRenderer.cpp46
-rw-r--r--src/gpu/effects/GrBezierEffect.cpp48
-rw-r--r--src/gpu/effects/GrBitmapTextGeoProc.cpp9
-rw-r--r--src/gpu/effects/GrDashingEffect.cpp40
-rwxr-xr-xsrc/gpu/effects/GrDistanceFieldTextureEffect.cpp46
-rw-r--r--src/gpu/gl/GrGLGeometryProcessor.h34
-rw-r--r--src/gpu/gl/GrGLShaderVar.h8
-rw-r--r--src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp18
-rw-r--r--src/gpu/gl/builders/GrGLVertexShaderBuilder.h2
13 files changed, 201 insertions, 125 deletions
diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp
index c589f8cb1d..27cc8aa3be 100644
--- a/src/gpu/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/GrAAConvexPathRenderer.cpp
@@ -535,7 +535,7 @@ public:
const GrBatchTracker&)
: fColor(GrColor_ILLEGAL) {}
- void onEmitCode(EmitArgs& args) SK_OVERRIDE {
+ void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE {
const QuadEdgeEffect& qe = args.fGP.cast<QuadEdgeEffect>();
GrGLGPBuilder* pb = args.fPB;
GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
@@ -557,11 +557,11 @@ public:
this->addUniformViewMatrix(pb);
// Setup position
- vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", this->position(), this->uViewM(),
- qe.inPosition()->fName);
+ SetupPosition(vsBuilder, gpArgs, qe.inPosition()->fName,
+ qe.viewMatrix(), this->uViewM());
// emit transforms
- this->emitTransforms(args.fPB, this->position(), qe.inPosition()->fName,
+ this->emitTransforms(args.fPB, gpArgs->fPositionVar, qe.inPosition()->fName,
qe.localMatrix(), args.fTransformsIn, args.fTransformsOut);
GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
@@ -594,8 +594,10 @@ public:
const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const BatchTracker& local = bt.cast<BatchTracker>();
- b->add32((local.fInputColorType << 16) |
- (local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 : 0x0));
+ uint32_t key = local.fInputColorType << 16;
+ key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 : 0x0;
+ key |= ComputePosKey(gp.viewMatrix()) << 1;
+ b->add32(key);
}
virtual void setData(const GrGLProgramDataManager& pdman,
diff --git a/src/gpu/GrDefaultGeoProcFactory.cpp b/src/gpu/GrDefaultGeoProcFactory.cpp
index 25c34ed929..3e32e65c62 100644
--- a/src/gpu/GrDefaultGeoProcFactory.cpp
+++ b/src/gpu/GrDefaultGeoProcFactory.cpp
@@ -83,15 +83,15 @@ public:
GLProcessor(const GrGeometryProcessor& gp, const GrBatchTracker&)
: fColor(GrColor_ILLEGAL), fCoverage(0xff) {}
- void onEmitCode(EmitArgs& args) SK_OVERRIDE {
+ void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE {
const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>();
GrGLGPBuilder* pb = args.fPB;
- GrGLVertexBuilder* vs = pb->getVertexShaderBuilder();
+ GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder();
GrGLGPFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder();
const BatchTracker& local = args.fBT.cast<BatchTracker>();
// emit attributes
- vs->emitAttributes(gp);
+ vsBuilder->emitAttributes(gp);
// Setup pass through color
this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor, gp.inColor(),
@@ -101,16 +101,16 @@ public:
this->addUniformViewMatrix(pb);
// Setup position
- vs->codeAppendf("%s = %s * vec3(%s, 1);", this->position(), this->uViewM(),
- gp.inPosition()->fName);
+ SetupPosition(vsBuilder, gpArgs, gp.inPosition()->fName,
+ gp.viewMatrix(), this->uViewM());
if (gp.inLocalCoords()) {
// emit transforms with explicit local coords
- this->emitTransforms(pb, this->position(), gp.inLocalCoords()->fName,
+ this->emitTransforms(pb, gpArgs->fPositionVar, gp.inLocalCoords()->fName,
gp.localMatrix(), args.fTransformsIn, args.fTransformsOut);
} else {
// emit transforms with position
- this->emitTransforms(pb, this->position(), gp.inPosition()->fName,
+ this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName,
gp.localMatrix(), args.fTransformsIn, args.fTransformsOut);
}
@@ -142,6 +142,7 @@ public:
uint32_t key = def.fFlags;
key |= local.fInputColorType << 8 | local.fInputCoverageType << 16;
key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24 : 0x0;
+ key |= ComputePosKey(gp.viewMatrix()) << 25;
b->add32(key);
}
diff --git a/src/gpu/GrGeometryProcessor.cpp b/src/gpu/GrGeometryProcessor.cpp
index 344dccc731..662f28f386 100644
--- a/src/gpu/GrGeometryProcessor.cpp
+++ b/src/gpu/GrGeometryProcessor.cpp
@@ -163,13 +163,13 @@ void GrGLPrimitiveProcessor::setUniformViewMatrix(const GrGLProgramDataManager&
void GrGLGeometryProcessor::emitCode(EmitArgs& args) {
GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
- vsBuilder->codeAppendf("vec3 %s;", this->position());
- this->onEmitCode(args);
- vsBuilder->transformToNormalizedDeviceSpace(this->position());
+ GrGPArgs gpArgs;
+ this->onEmitCode(args, &gpArgs);
+ vsBuilder->transformToNormalizedDeviceSpace(gpArgs.fPositionVar);
}
void GrGLGeometryProcessor::emitTransforms(GrGLGPBuilder* pb,
- const char* position,
+ const GrShaderVar& posVar,
const char* localCoords,
const SkMatrix& localMatrix,
const TransformsIn& tin,
@@ -214,9 +214,19 @@ void GrGLGeometryProcessor::emitTransforms(GrGLGPBuilder* pb,
// varying = matrix * coords (logically)
if (kDevice_GrCoordSet == coordType) {
if (kVec2f_GrSLType == varyingType) {
- vb->codeAppendf("%s = (%s * %s).xy;", v.vsOut(), uniName, position);
+ if (kVec2f_GrSLType == posVar.getType()) {
+ vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;",
+ v.vsOut(), uniName, posVar.c_str());
+ } else {
+ vb->codeAppendf("%s = (%s * %s).xy;", v.vsOut(), uniName, posVar.c_str());
+ }
} else {
- vb->codeAppendf("%s = %s * %s;", v.vsOut(), uniName, position);
+ if (kVec2f_GrSLType == posVar.getType()) {
+ vb->codeAppendf("%s = %s * vec3(%s, 1);",
+ v.vsOut(), uniName, posVar.c_str());
+ } else {
+ vb->codeAppendf("%s = %s * %s;", v.vsOut(), uniName, posVar.c_str());
+ }
}
} else {
if (kVec2f_GrSLType == varyingType) {
@@ -247,6 +257,28 @@ GrGLGeometryProcessor::setTransformData(const GrPrimitiveProcessor* primProc,
}
}
+void GrGLGeometryProcessor::SetupPosition(GrGLVertexBuilder* vsBuilder,
+ GrGPArgs* gpArgs,
+ const char* posName,
+ const SkMatrix& mat,
+ const char* matName) {
+ if (mat.isIdentity()) {
+ gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2");
+
+ vsBuilder->codeAppendf("vec2 %s = %s;", gpArgs->fPositionVar.c_str(), posName);
+ } else if (!mat.hasPerspective()) {
+ gpArgs->fPositionVar.set(kVec2f_GrSLType, "pos2");
+
+ vsBuilder->codeAppendf("vec2 %s = vec2(%s * vec3(%s, 1));",
+ gpArgs->fPositionVar.c_str(), matName, posName);
+ } else {
+ gpArgs->fPositionVar.set(kVec3f_GrSLType, "pos3");
+
+ vsBuilder->codeAppendf("vec3 %s = %s * vec3(%s, 1);",
+ gpArgs->fPositionVar.c_str(), matName, posName);
+ }
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "gl/GrGLGpu.h"
diff --git a/src/gpu/GrGeometryProcessor.h b/src/gpu/GrGeometryProcessor.h
index 43b6a7e31a..736c515e88 100644
--- a/src/gpu/GrGeometryProcessor.h
+++ b/src/gpu/GrGeometryProcessor.h
@@ -220,7 +220,7 @@ protected:
private:
virtual bool hasExplicitLocalCoords() const = 0;
- SkMatrix fViewMatrix;
+ const SkMatrix fViewMatrix;
SkMatrix fLocalMatrix;
typedef GrProcessor INHERITED;
diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp
index 2f8af8d175..a35d70859a 100644
--- a/src/gpu/GrOvalRenderer.cpp
+++ b/src/gpu/GrOvalRenderer.cpp
@@ -83,7 +83,7 @@ public:
const GrBatchTracker&)
: fColor(GrColor_ILLEGAL) {}
- void onEmitCode(EmitArgs& args) SK_OVERRIDE {
+ void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{
const CircleEdgeEffect& ce = args.fGP.cast<CircleEdgeEffect>();
GrGLGPBuilder* pb = args.fPB;
const BatchTracker& local = args.fBT.cast<BatchTracker>();
@@ -104,11 +104,11 @@ public:
this->addUniformViewMatrix(pb);
// Setup position
- vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", this->position(), this->uViewM(),
- ce.inPosition()->fName);
+ SetupPosition(vsBuilder, gpArgs, ce.inPosition()->fName,
+ ce.viewMatrix(), this->uViewM());
// emit transforms
- this->emitTransforms(args.fPB, this->position(), ce.inPosition()->fName,
+ this->emitTransforms(args.fPB, gpArgs->fPositionVar, ce.inPosition()->fName,
ce.localMatrix(), args.fTransformsIn, args.fTransformsOut);;
GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
@@ -123,14 +123,15 @@ public:
fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
}
- static void GenKey(const GrGeometryProcessor& processor,
+ static void GenKey(const GrGeometryProcessor& gp,
const GrBatchTracker& bt,
const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const BatchTracker& local = bt.cast<BatchTracker>();
- const CircleEdgeEffect& circleEffect = processor.cast<CircleEdgeEffect>();
+ const CircleEdgeEffect& circleEffect = gp.cast<CircleEdgeEffect>();
uint16_t key = circleEffect.isStroked() ? 0x1 : 0x0;
- key |= local.fUsesLocalCoords && processor.localMatrix().hasPerspective() ? 0x2 : 0x0;
+ key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x2 : 0x0;
+ key |= ComputePosKey(gp.viewMatrix()) << 2;
b->add32(key << 16 | local.fInputColorType);
}
@@ -259,7 +260,7 @@ public:
const GrBatchTracker&)
: fColor(GrColor_ILLEGAL) {}
- void onEmitCode(EmitArgs& args) SK_OVERRIDE {
+ void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{
const EllipseEdgeEffect& ee = args.fGP.cast<EllipseEdgeEffect>();
GrGLGPBuilder* pb = args.fPB;
const BatchTracker& local = args.fBT.cast<BatchTracker>();
@@ -286,11 +287,11 @@ public:
this->addUniformViewMatrix(pb);
// Setup position
- vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", this->position(), this->uViewM(),
- ee.inPosition()->fName);
+ SetupPosition(vsBuilder, gpArgs, ee.inPosition()->fName,
+ ee.viewMatrix(), this->uViewM());
// emit transforms
- this->emitTransforms(args.fPB, this->position(), ee.inPosition()->fName,
+ this->emitTransforms(args.fPB, gpArgs->fPositionVar, ee.inPosition()->fName,
ee.localMatrix(), args.fTransformsIn, args.fTransformsOut);
// for outer curve
@@ -320,14 +321,15 @@ public:
fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
}
- static void GenKey(const GrGeometryProcessor& processor,
+ static void GenKey(const GrGeometryProcessor& gp,
const GrBatchTracker& bt,
const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const BatchTracker& local = bt.cast<BatchTracker>();
- const EllipseEdgeEffect& ellipseEffect = processor.cast<EllipseEdgeEffect>();
+ const EllipseEdgeEffect& ellipseEffect = gp.cast<EllipseEdgeEffect>();
uint16_t key = ellipseEffect.isStroked() ? 0x1 : 0x0;
- key |= local.fUsesLocalCoords && processor.localMatrix().hasPerspective() ? 0x2 : 0x0;
+ key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x2 : 0x0;
+ key |= ComputePosKey(gp.viewMatrix()) << 2;
b->add32(key << 16 | local.fInputColorType);
}
@@ -463,7 +465,7 @@ public:
const GrBatchTracker&)
: fColor(GrColor_ILLEGAL) {}
- void onEmitCode(EmitArgs& args) SK_OVERRIDE {
+ void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{
const DIEllipseEdgeEffect& ee = args.fGP.cast<DIEllipseEdgeEffect>();
GrGLGPBuilder* pb = args.fPB;
const BatchTracker& local = args.fBT.cast<BatchTracker>();
@@ -490,11 +492,11 @@ public:
this->addUniformViewMatrix(pb);
// Setup position
- vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", this->position(), this->uViewM(),
- ee.inPosition()->fName);
+ SetupPosition(vsBuilder, gpArgs, ee.inPosition()->fName,
+ ee.viewMatrix(), this->uViewM());
// emit transforms
- this->emitTransforms(args.fPB, this->position(), ee.inPosition()->fName,
+ this->emitTransforms(args.fPB, gpArgs->fPositionVar, ee.inPosition()->fName,
ee.localMatrix(), args.fTransformsIn, args.fTransformsOut);
GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
@@ -538,15 +540,15 @@ public:
fsBuilder->codeAppendf("%s = vec4(edgeAlpha);", args.fOutputCoverage);
}
- static void GenKey(const GrGeometryProcessor& processor,
+ static void GenKey(const GrGeometryProcessor& gp,
const GrBatchTracker& bt,
const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const BatchTracker& local = bt.cast<BatchTracker>();
- const DIEllipseEdgeEffect& ellipseEffect = processor.cast<DIEllipseEdgeEffect>();
+ const DIEllipseEdgeEffect& ellipseEffect = gp.cast<DIEllipseEdgeEffect>();
uint16_t key = ellipseEffect.getMode();
- key |= local.fUsesLocalCoords && processor.localMatrix().hasPerspective() ? 0x1 << 8 :
- 0x0;
+ key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 8 : 0x0;
+ key |= ComputePosKey(gp.viewMatrix()) << 9;
b->add32(key << 16 | local.fInputColorType);
}
diff --git a/src/gpu/effects/GrBezierEffect.cpp b/src/gpu/effects/GrBezierEffect.cpp
index b8e4c0cb18..1c6d469033 100644
--- a/src/gpu/effects/GrBezierEffect.cpp
+++ b/src/gpu/effects/GrBezierEffect.cpp
@@ -24,7 +24,7 @@ public:
GrGLConicEffect(const GrGeometryProcessor&,
const GrBatchTracker&);
- void onEmitCode(EmitArgs&) SK_OVERRIDE;
+ void onEmitCode(EmitArgs&, GrGPArgs*) SK_OVERRIDE;
static inline void GenKey(const GrGeometryProcessor&,
const GrBatchTracker&,
@@ -66,7 +66,7 @@ GrGLConicEffect::GrGLConicEffect(const GrGeometryProcessor& processor,
fEdgeType = ce.getEdgeType();
}
-void GrGLConicEffect::onEmitCode(EmitArgs& args) {
+void GrGLConicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
GrGLGPBuilder* pb = args.fPB;
GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
const GrConicEffect& gp = args.fGP.cast<GrConicEffect>();
@@ -87,11 +87,10 @@ void GrGLConicEffect::onEmitCode(EmitArgs& args) {
this->addUniformViewMatrix(pb);
// Setup position
- vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", this->position(), this->uViewM(),
- gp.inPosition()->fName);
+ SetupPosition(vsBuilder, gpArgs, gp.inPosition()->fName, gp.viewMatrix(), this->uViewM());
// emit transforms with position
- this->emitTransforms(pb, this->position(), gp.inPosition()->fName, gp.localMatrix(),
+ this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName, gp.localMatrix(),
args.fTransformsIn, args.fTransformsOut);
GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
@@ -164,16 +163,17 @@ void GrGLConicEffect::onEmitCode(EmitArgs& args) {
}
}
-void GrGLConicEffect::GenKey(const GrGeometryProcessor& processor,
+void GrGLConicEffect::GenKey(const GrGeometryProcessor& gp,
const GrBatchTracker& bt,
const GrGLCaps&,
GrProcessorKeyBuilder* b) {
- const GrConicEffect& ce = processor.cast<GrConicEffect>();
+ const GrConicEffect& ce = gp.cast<GrConicEffect>();
const ConicBatchTracker& local = bt.cast<ConicBatchTracker>();
uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2;
key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x0;
key |= 0xff != local.fCoverageScale ? 0x8 : 0x0;
- key |= local.fUsesLocalCoords && processor.localMatrix().hasPerspective() ? 0x10 : 0x0;
+ key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x10 : 0x0;
+ key |= ComputePosKey(gp.viewMatrix()) << 5;
b->add32(key);
}
@@ -262,7 +262,7 @@ public:
GrGLQuadEffect(const GrGeometryProcessor&,
const GrBatchTracker&);
- void onEmitCode(EmitArgs&) SK_OVERRIDE;
+ void onEmitCode(EmitArgs&, GrGPArgs*) SK_OVERRIDE;
static inline void GenKey(const GrGeometryProcessor&,
const GrBatchTracker&,
@@ -304,7 +304,7 @@ GrGLQuadEffect::GrGLQuadEffect(const GrGeometryProcessor& processor,
fEdgeType = ce.getEdgeType();
}
-void GrGLQuadEffect::onEmitCode(EmitArgs& args) {
+void GrGLQuadEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
GrGLGPBuilder* pb = args.fPB;
GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
const GrQuadEffect& gp = args.fGP.cast<GrQuadEffect>();
@@ -325,11 +325,10 @@ void GrGLQuadEffect::onEmitCode(EmitArgs& args) {
this->addUniformViewMatrix(pb);
// Setup position
- vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", this->position(), this->uViewM(),
- gp.inPosition()->fName);
+ SetupPosition(vsBuilder, gpArgs, gp.inPosition()->fName, gp.viewMatrix(), this->uViewM());
// emit transforms with position
- this->emitTransforms(pb, this->position(), gp.inPosition()->fName, gp.localMatrix(),
+ this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->fName, gp.localMatrix(),
args.fTransformsIn, args.fTransformsOut);
GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
@@ -388,16 +387,17 @@ void GrGLQuadEffect::onEmitCode(EmitArgs& args) {
}
}
-void GrGLQuadEffect::GenKey(const GrGeometryProcessor& processor,
+void GrGLQuadEffect::GenKey(const GrGeometryProcessor& gp,
const GrBatchTracker& bt,
const GrGLCaps&,
GrProcessorKeyBuilder* b) {
- const GrQuadEffect& ce = processor.cast<GrQuadEffect>();
+ const GrQuadEffect& ce = gp.cast<GrQuadEffect>();
const QuadBatchTracker& local = bt.cast<QuadBatchTracker>();
uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2;
key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x0;
key |= 0xff != local.fCoverageScale ? 0x8 : 0x0;
- key |= local.fUsesLocalCoords && processor.localMatrix().hasPerspective() ? 0x10 : 0x0;
+ key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x10 : 0x0;
+ key |= ComputePosKey(gp.viewMatrix()) << 5;
b->add32(key);
}
@@ -486,7 +486,7 @@ public:
GrGLCubicEffect(const GrGeometryProcessor&,
const GrBatchTracker&);
- void onEmitCode(EmitArgs&) SK_OVERRIDE;
+ void onEmitCode(EmitArgs&, GrGPArgs*) SK_OVERRIDE;
static inline void GenKey(const GrGeometryProcessor&,
const GrBatchTracker&,
@@ -522,7 +522,7 @@ GrGLCubicEffect::GrGLCubicEffect(const GrGeometryProcessor& processor,
fEdgeType = ce.getEdgeType();
}
-void GrGLCubicEffect::onEmitCode(EmitArgs& args) {
+void GrGLCubicEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder();
const GrCubicEffect& gp = args.fGP.cast<GrCubicEffect>();
const CubicBatchTracker& local = args.fBT.cast<CubicBatchTracker>();
@@ -542,11 +542,10 @@ void GrGLCubicEffect::onEmitCode(EmitArgs& args) {
this->addUniformViewMatrix(args.fPB);
// Setup position
- vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", this->position(), this->uViewM(),
- gp.inPosition()->fName);
+ SetupPosition(vsBuilder, gpArgs, gp.inPosition()->fName, gp.viewMatrix(), this->uViewM());
// emit transforms with position
- this->emitTransforms(args.fPB, this->position(), gp.inPosition()->fName, gp.localMatrix(),
+ this->emitTransforms(args.fPB, gpArgs->fPositionVar, gp.inPosition()->fName, gp.localMatrix(),
args.fTransformsIn, args.fTransformsOut);
GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder();
@@ -636,15 +635,16 @@ void GrGLCubicEffect::onEmitCode(EmitArgs& args) {
fsBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, edgeAlpha.c_str());
}
-void GrGLCubicEffect::GenKey(const GrGeometryProcessor& processor,
+void GrGLCubicEffect::GenKey(const GrGeometryProcessor& gp,
const GrBatchTracker& bt,
const GrGLCaps&,
GrProcessorKeyBuilder* b) {
- const GrCubicEffect& ce = processor.cast<GrCubicEffect>();
+ const GrCubicEffect& ce = gp.cast<GrCubicEffect>();
const CubicBatchTracker& local = bt.cast<CubicBatchTracker>();
uint32_t key = ce.isAntiAliased() ? (ce.isFilled() ? 0x0 : 0x1) : 0x2;
key |= kUniform_GrGPInput == local.fInputColorType ? 0x4 : 0x8;
- key |= local.fUsesLocalCoords && processor.localMatrix().hasPerspective() ? 0x10 : 0x0;
+ key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x10 : 0x0;
+ key |= ComputePosKey(gp.viewMatrix()) << 5;
b->add32(key);
}
diff --git a/src/gpu/effects/GrBitmapTextGeoProc.cpp b/src/gpu/effects/GrBitmapTextGeoProc.cpp
index 146fb0672f..924f7cd952 100644
--- a/src/gpu/effects/GrBitmapTextGeoProc.cpp
+++ b/src/gpu/effects/GrBitmapTextGeoProc.cpp
@@ -25,7 +25,7 @@ public:
GrGLBitmapTextGeoProc(const GrGeometryProcessor&, const GrBatchTracker&)
: fColor(GrColor_ILLEGAL) {}
- void onEmitCode(EmitArgs& args) SK_OVERRIDE {
+ void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{
const GrBitmapTextGeoProc& cte = args.fGP.cast<GrBitmapTextGeoProc>();
const BitmapTextBatchTracker& local = args.fBT.cast<BitmapTextBatchTracker>();
@@ -47,11 +47,11 @@ public:
this->addUniformViewMatrix(pb);
// Setup position
- vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", this->position(), this->uViewM(),
- cte.inPosition()->fName);
+ SetupPosition(vsBuilder, gpArgs, cte.inPosition()->fName,
+ cte.viewMatrix(), this->uViewM());
// emit transforms
- this->emitTransforms(args.fPB, this->position(), cte.inPosition()->fName,
+ this->emitTransforms(args.fPB, gpArgs->fPositionVar, cte.inPosition()->fName,
cte.localMatrix(), args.fTransformsIn, args.fTransformsOut);
GrGLGPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder();
@@ -86,6 +86,7 @@ public:
uint32_t key = 0;
key |= SkToBool(gp.inColor()) ? 0x1 : 0x0;
key |= local.fUsesLocalCoords && proc.localMatrix().hasPerspective() ? 0x2 : 0x0;
+ key |= ComputePosKey(gp.viewMatrix()) << 2;
b->add32(local.fInputColorType << 16 | key);
}
diff --git a/src/gpu/effects/GrDashingEffect.cpp b/src/gpu/effects/GrDashingEffect.cpp
index 7016ef203e..88ffad0c2e 100644
--- a/src/gpu/effects/GrDashingEffect.cpp
+++ b/src/gpu/effects/GrDashingEffect.cpp
@@ -531,7 +531,7 @@ class GLDashingCircleEffect : public GrGLGeometryProcessor {
public:
GLDashingCircleEffect(const GrGeometryProcessor&, const GrBatchTracker&);
- void onEmitCode(EmitArgs&) SK_OVERRIDE;
+ void onEmitCode(EmitArgs&, GrGPArgs*) SK_OVERRIDE;
static inline void GenKey(const GrGeometryProcessor&,
const GrBatchTracker&,
@@ -560,7 +560,7 @@ GLDashingCircleEffect::GLDashingCircleEffect(const GrGeometryProcessor&,
fPrevIntervalLength = SK_ScalarMax;
}
-void GLDashingCircleEffect::onEmitCode(EmitArgs& args) {
+void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
const DashingCircleEffect& dce = args.fGP.cast<DashingCircleEffect>();
const DashingCircleBatchTracker local = args.fBT.cast<DashingCircleBatchTracker>();
GrGLGPBuilder* pb = args.fPB;
@@ -587,11 +587,10 @@ void GLDashingCircleEffect::onEmitCode(EmitArgs& args) {
this->addUniformViewMatrix(pb);
// Setup position
- vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", this->position(), this->uViewM(),
- dce.inPosition()->fName);
+ SetupPosition(vsBuilder, gpArgs, dce.inPosition()->fName, dce.viewMatrix(), this->uViewM());
// emit transforms
- this->emitTransforms(args.fPB, this->position(), dce.inPosition()->fName, dce.localMatrix(),
+ this->emitTransforms(args.fPB, gpArgs->fPositionVar, dce.inPosition()->fName, dce.localMatrix(),
args.fTransformsIn, args.fTransformsOut);
// transforms all points so that we can compare them to our test circle
@@ -637,14 +636,17 @@ void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman,
}
}
-void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& processor,
+void GLDashingCircleEffect::GenKey(const GrGeometryProcessor& gp,
const GrBatchTracker& bt,
const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const DashingCircleBatchTracker& local = bt.cast<DashingCircleBatchTracker>();
- const DashingCircleEffect& dce = processor.cast<DashingCircleEffect>();
- b->add32(local.fUsesLocalCoords && processor.localMatrix().hasPerspective());
- b->add32(dce.getEdgeType() << 16 | local.fInputColorType);
+ const DashingCircleEffect& dce = gp.cast<DashingCircleEffect>();
+ uint32_t key = 0;
+ key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 : 0x0;
+ key |= ComputePosKey(gp.viewMatrix()) << 1;
+ key |= dce.getEdgeType() << 8;
+ b->add32(key << 16 | local.fInputColorType);
}
//////////////////////////////////////////////////////////////////////////////
@@ -822,7 +824,7 @@ class GLDashingLineEffect : public GrGLGeometryProcessor {
public:
GLDashingLineEffect(const GrGeometryProcessor&, const GrBatchTracker&);
- void onEmitCode(EmitArgs&) SK_OVERRIDE;
+ void onEmitCode(EmitArgs&, GrGPArgs*) SK_OVERRIDE;
static inline void GenKey(const GrGeometryProcessor&,
const GrBatchTracker&,
@@ -850,7 +852,7 @@ GLDashingLineEffect::GLDashingLineEffect(const GrGeometryProcessor&,
fPrevIntervalLength = SK_ScalarMax;
}
-void GLDashingLineEffect::onEmitCode(EmitArgs& args) {
+void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
const DashingLineEffect& de = args.fGP.cast<DashingLineEffect>();
const DashingLineBatchTracker& local = args.fBT.cast<DashingLineBatchTracker>();
GrGLGPBuilder* pb = args.fPB;
@@ -885,11 +887,10 @@ void GLDashingLineEffect::onEmitCode(EmitArgs& args) {
this->addUniformViewMatrix(pb);
// Setup position
- vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", this->position(), this->uViewM(),
- de.inPosition()->fName);
+ SetupPosition(vsBuilder, gpArgs, de.inPosition()->fName, de.viewMatrix(), this->uViewM());
// emit transforms
- this->emitTransforms(args.fPB, this->position(), de.inPosition()->fName, de.localMatrix(),
+ this->emitTransforms(args.fPB, gpArgs->fPositionVar, de.inPosition()->fName, de.localMatrix(),
args.fTransformsIn, args.fTransformsOut);
// transforms all points so that we can compare them to our test rect
@@ -942,14 +943,17 @@ void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman,
}
}
-void GLDashingLineEffect::GenKey(const GrGeometryProcessor& processor,
+void GLDashingLineEffect::GenKey(const GrGeometryProcessor& gp,
const GrBatchTracker& bt,
const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const DashingLineBatchTracker& local = bt.cast<DashingLineBatchTracker>();
- const DashingLineEffect& de = processor.cast<DashingLineEffect>();
- b->add32(local.fUsesLocalCoords && processor.localMatrix().hasPerspective());
- b->add32(de.getEdgeType() << 16 | local.fInputColorType);
+ const DashingLineEffect& de = gp.cast<DashingLineEffect>();
+ uint32_t key = 0;
+ key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 : 0x0;
+ key |= ComputePosKey(gp.viewMatrix()) << 1;
+ key |= de.getEdgeType() << 8;
+ b->add32(key << 16 | local.fInputColorType);
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
index 00713d6351..f65492e9f0 100755
--- a/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
+++ b/src/gpu/effects/GrDistanceFieldTextureEffect.cpp
@@ -35,7 +35,7 @@ public:
#endif
{}
- void onEmitCode(EmitArgs& args) SK_OVERRIDE {
+ void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{
const GrDistanceFieldTextureEffect& dfTexEffect =
args.fGP.cast<GrDistanceFieldTextureEffect>();
const DistanceFieldBatchTracker& local = args.fBT.cast<DistanceFieldBatchTracker>();
@@ -61,11 +61,11 @@ public:
this->addUniformViewMatrix(pb);
// Setup position
- vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", this->position(), this->uViewM(),
- dfTexEffect.inPosition()->fName);
+ SetupPosition(vsBuilder, gpArgs, dfTexEffect.inPosition()->fName,
+ dfTexEffect.viewMatrix(), this->uViewM());
// emit transforms
- this->emitTransforms(args.fPB, this->position(), dfTexEffect.inPosition()->fName,
+ this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosition()->fName,
dfTexEffect.localMatrix(), args.fTransformsIn, args.fTransformsOut);
const char* textureSizeUniName = NULL;
@@ -166,16 +166,16 @@ public:
}
}
- static inline void GenKey(const GrGeometryProcessor& processor,
+ static inline void GenKey(const GrGeometryProcessor& gp,
const GrBatchTracker& bt,
const GrGLCaps&,
GrProcessorKeyBuilder* b) {
- const GrDistanceFieldTextureEffect& dfTexEffect =
- processor.cast<GrDistanceFieldTextureEffect>();
+ const GrDistanceFieldTextureEffect& dfTexEffect = gp.cast<GrDistanceFieldTextureEffect>();
const DistanceFieldBatchTracker& local = bt.cast<DistanceFieldBatchTracker>();
uint32_t key = dfTexEffect.getFlags();
key |= local.fInputColorType << 16;
- key |= local.fUsesLocalCoords && processor.localMatrix().hasPerspective() ? 0x1 << 24: 0x0;
+ key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0;
+ key |= ComputePosKey(gp.viewMatrix()) << 25;
b->add32(key);
}
@@ -324,7 +324,7 @@ public:
const GrBatchTracker&)
: fColor(GrColor_ILLEGAL), fTextureSize(SkISize::Make(-1, -1)) {}
- void onEmitCode(EmitArgs& args) SK_OVERRIDE {
+ void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{
const GrDistanceFieldNoGammaTextureEffect& dfTexEffect =
args.fGP.cast<GrDistanceFieldNoGammaTextureEffect>();
@@ -353,11 +353,11 @@ public:
this->addUniformViewMatrix(pb);
// Setup position
- vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", this->position(), this->uViewM(),
- dfTexEffect.inPosition()->fName);
+ SetupPosition(vsBuilder, gpArgs, dfTexEffect.inPosition()->fName,
+ dfTexEffect.viewMatrix(), this->uViewM());
// emit transforms
- this->emitTransforms(args.fPB, this->position(), dfTexEffect.inPosition()->fName,
+ this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosition()->fName,
dfTexEffect.localMatrix(), args.fTransformsIn, args.fTransformsOut);
const char* textureSizeUniName = NULL;
@@ -434,17 +434,18 @@ public:
}
}
- static inline void GenKey(const GrGeometryProcessor& proc,
+ static inline void GenKey(const GrGeometryProcessor& gp,
const GrBatchTracker& bt,
const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const GrDistanceFieldNoGammaTextureEffect& dfTexEffect =
- proc.cast<GrDistanceFieldNoGammaTextureEffect>();
+ gp.cast<GrDistanceFieldNoGammaTextureEffect>();
const DistanceFieldNoGammaBatchTracker& local = bt.cast<DistanceFieldNoGammaBatchTracker>();
uint32_t key = dfTexEffect.getFlags();
key |= local.fInputColorType << 16;
- key |= local.fUsesLocalCoords && proc.localMatrix().hasPerspective() ? 0x1 << 24: 0x0;
+ key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0;
+ key |= ComputePosKey(gp.viewMatrix()) << 25;
b->add32(key);
}
@@ -568,7 +569,7 @@ public:
, fTextureSize(SkISize::Make(-1,-1))
, fTextColor(GrColor_ILLEGAL) {}
- void onEmitCode(EmitArgs& args) SK_OVERRIDE {
+ void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{
const GrDistanceFieldLCDTextureEffect& dfTexEffect =
args.fGP.cast<GrDistanceFieldLCDTextureEffect>();
const DistanceFieldLCDBatchTracker& local = args.fBT.cast<DistanceFieldLCDBatchTracker>();
@@ -591,11 +592,11 @@ public:
this->addUniformViewMatrix(pb);
// Setup position
- vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", this->position(), this->uViewM(),
- dfTexEffect.inPosition()->fName);
+ SetupPosition(vsBuilder, gpArgs, dfTexEffect.inPosition()->fName,
+ dfTexEffect.viewMatrix(), this->uViewM());
// emit transforms
- this->emitTransforms(args.fPB, this->position(), dfTexEffect.inPosition()->fName,
+ this->emitTransforms(args.fPB, gpArgs->fPositionVar, dfTexEffect.inPosition()->fName,
dfTexEffect.localMatrix(), args.fTransformsIn, args.fTransformsOut);
const char* textureSizeUniName = NULL;
@@ -749,17 +750,18 @@ public:
}
}
- static inline void GenKey(const GrGeometryProcessor& processor,
+ static inline void GenKey(const GrGeometryProcessor& gp,
const GrBatchTracker& bt,
const GrGLCaps&,
GrProcessorKeyBuilder* b) {
const GrDistanceFieldLCDTextureEffect& dfTexEffect =
- processor.cast<GrDistanceFieldLCDTextureEffect>();
+ gp.cast<GrDistanceFieldLCDTextureEffect>();
const DistanceFieldLCDBatchTracker& local = bt.cast<DistanceFieldLCDBatchTracker>();
uint32_t key = dfTexEffect.getFlags();
key |= local.fInputColorType << 16;
- key |= local.fUsesLocalCoords && processor.localMatrix().hasPerspective() ? 0x1 << 24: 0x0;
+ key |= local.fUsesLocalCoords && gp.localMatrix().hasPerspective() ? 0x1 << 24: 0x0;
+ key |= ComputePosKey(gp.viewMatrix()) << 25;
b->add32(key);
}
diff --git a/src/gpu/gl/GrGLGeometryProcessor.h b/src/gpu/gl/GrGLGeometryProcessor.h
index 3c95830fb2..88b69a6d8f 100644
--- a/src/gpu/gl/GrGLGeometryProcessor.h
+++ b/src/gpu/gl/GrGLGeometryProcessor.h
@@ -127,6 +127,7 @@ private:
};
class GrGLPathRendering;
+class GrGLVertexBuilder;
/**
* If a GL effect needs a GrGLFullShaderBuilder* object to emit vertex code, then it must inherit
* from this class. Since paths don't have vertices, this class is only meant to be used internally
@@ -143,26 +144,47 @@ public:
const SkTArray<const GrCoordTransform*, true>& transforms);
protected:
- const char* position() const { return "pos3"; }
-
// Many GrGeometryProcessors do not need explicit local coords
void emitTransforms(GrGLGPBuilder* gp,
- const char* position,
+ const GrShaderVar& posVar,
const SkMatrix& localMatrix,
const TransformsIn& tin,
TransformsOut* tout) {
- this->emitTransforms(gp, position, position, localMatrix, tin, tout);
+ this->emitTransforms(gp, posVar, posVar.c_str(), localMatrix, tin, tout);
}
void emitTransforms(GrGLGPBuilder*,
- const char* position,
+ const GrShaderVar& posVar,
const char* localCoords,
const SkMatrix& localMatrix,
const TransformsIn&,
TransformsOut*);
+ struct GrGPArgs {
+ // The variable used by a GP to store its position. It can be
+ // either a vec2 or a vec3 depending on the presence of perspective.
+ GrShaderVar fPositionVar;
+ };
+
+ // Create the correct type of position variable given the CTM
+ static void SetupPosition(GrGLVertexBuilder* vsBuilder,
+ GrGPArgs* gpArgs,
+ const char* posName,
+ const SkMatrix& mat,
+ const char* matName);
+
+ static uint32_t ComputePosKey(const SkMatrix& mat) {
+ if (mat.isIdentity()) {
+ return 0x0;
+ } else if (!mat.hasPerspective()) {
+ return 0x01;
+ } else {
+ return 0x02;
+ }
+ }
+
private:
- virtual void onEmitCode(EmitArgs&) = 0;
+ virtual void onEmitCode(EmitArgs&, GrGPArgs*) = 0;
typedef GrGLPrimitiveProcessor INHERITED;
};
diff --git a/src/gpu/gl/GrGLShaderVar.h b/src/gpu/gl/GrGLShaderVar.h
index 0a7b1deda3..e32683ab4f 100644
--- a/src/gpu/gl/GrGLShaderVar.h
+++ b/src/gpu/gl/GrGLShaderVar.h
@@ -88,7 +88,7 @@ public:
bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) {
SkASSERT(kVoid_GrSLType != type);
SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type));
- INHERITED::set(type, typeModifier, name, precision);
+ INHERITED::set(type, name, typeModifier, precision);
fOrigin = origin;
fUseUniformFloatArrays = useUniformFloatArrays;
}
@@ -104,7 +104,7 @@ public:
bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) {
SkASSERT(kVoid_GrSLType != type);
SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type));
- INHERITED::set(type, typeModifier, name, precision);
+ INHERITED::set(type, name, typeModifier, precision);
fOrigin = origin;
fUseUniformFloatArrays = useUniformFloatArrays;
}
@@ -121,7 +121,7 @@ public:
bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) {
SkASSERT(kVoid_GrSLType != type);
SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type));
- INHERITED::set(type, typeModifier, name, count, precision);
+ INHERITED::set(type, name, typeModifier, precision, count);
fOrigin = origin;
fUseUniformFloatArrays = useUniformFloatArrays;
}
@@ -138,7 +138,7 @@ public:
bool useUniformFloatArrays = USE_UNIFORM_FLOAT_ARRAYS) {
SkASSERT(kVoid_GrSLType != type);
SkASSERT(kDefault_GrSLPrecision == precision || GrSLTypeIsFloatType(type));
- INHERITED::set(type, typeModifier, name, count, precision);
+ INHERITED::set(type, name, typeModifier, precision, count);
fOrigin = origin;
fUseUniformFloatArrays = useUniformFloatArrays;
}
diff --git a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
index d67a476c68..a8d08656bd 100644
--- a/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLVertexShaderBuilder.cpp
@@ -34,7 +34,7 @@ void GrGLVertexBuilder::emitAttributes(const GrGeometryProcessor& gp) {
return;
}
-void GrGLVertexBuilder::transformToNormalizedDeviceSpace(const char* pos3) {
+void GrGLVertexBuilder::transformToNormalizedDeviceSpace(const GrShaderVar& posVar) {
SkASSERT(!fRtAdjustName);
// setup RT Uniform
@@ -44,9 +44,19 @@ void GrGLVertexBuilder::transformToNormalizedDeviceSpace(const char* pos3) {
fProgramBuilder->rtAdjustment(),
&fRtAdjustName);
- // Transform from Skia's device coords to GL's normalized device coords.
- this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy), dot(%s.yz, %s.zw), 0, %s.z);",
- pos3, fRtAdjustName, pos3, fRtAdjustName, pos3);
+ // Transform from Skia's device coords to GL's normalized device coords. Note that
+ // because we want to "nudge" the device space positions we are converting to
+ // non-homogeneous NDC.
+ if (kVec3f_GrSLType == posVar.getType()) {
+ this->codeAppendf("gl_Position = vec4(dot(%s.xz, %s.xy)/%s.z, dot(%s.yz, %s.zw)/%s.z, 0, 1);",
+ posVar.c_str(), fRtAdjustName, posVar.c_str(),
+ posVar.c_str(), fRtAdjustName, posVar.c_str());
+ } else {
+ SkASSERT(kVec2f_GrSLType == posVar.getType());
+ this->codeAppendf("gl_Position = vec4(%s.x * %s.x + %s.y, %s.y * %s.z + %s.w, 0, 1);",
+ posVar.c_str(), fRtAdjustName, fRtAdjustName,
+ posVar.c_str(), fRtAdjustName, fRtAdjustName);
+ }
// We could have the GrGeometryProcessor do this, but its just easier to have it performed here.
// If we ever need to set variable pointsize, then we can reinvestigate
diff --git a/src/gpu/gl/builders/GrGLVertexShaderBuilder.h b/src/gpu/gl/builders/GrGLVertexShaderBuilder.h
index 355f37e361..4c99a7b728 100644
--- a/src/gpu/gl/builders/GrGLVertexShaderBuilder.h
+++ b/src/gpu/gl/builders/GrGLVertexShaderBuilder.h
@@ -16,7 +16,7 @@ class GrGLVertexBuilder : public GrGLShaderBuilder {
public:
GrGLVertexBuilder(GrGLProgramBuilder* program);
- void transformToNormalizedDeviceSpace(const char* pos3);
+ void transformToNormalizedDeviceSpace(const GrShaderVar& posVar);
void emitAttributes(const GrGeometryProcessor& gp);
void addAttribute(const GrGeometryProcessor::Attribute* attr) {