aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/effects
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/effects')
-rw-r--r--src/gpu/effects/GrCircleEdgeEffect.cpp20
-rw-r--r--src/gpu/effects/GrConfigConversionEffect.cpp35
-rw-r--r--src/gpu/effects/GrConvolutionEffect.cpp36
-rw-r--r--src/gpu/effects/GrEllipseEdgeEffect.cpp21
-rw-r--r--src/gpu/effects/GrSimpleTextureEffect.cpp88
-rw-r--r--src/gpu/effects/GrSimpleTextureEffect.h67
-rw-r--r--src/gpu/effects/GrSingleTextureEffect.cpp21
-rw-r--r--src/gpu/effects/GrSingleTextureEffect.h23
-rw-r--r--src/gpu/effects/GrTextureDomainEffect.cpp77
-rw-r--r--src/gpu/effects/GrTextureDomainEffect.h6
10 files changed, 138 insertions, 256 deletions
diff --git a/src/gpu/effects/GrCircleEdgeEffect.cpp b/src/gpu/effects/GrCircleEdgeEffect.cpp
index 4ecdedbcde..ba7350226b 100644
--- a/src/gpu/effects/GrCircleEdgeEffect.cpp
+++ b/src/gpu/effects/GrCircleEdgeEffect.cpp
@@ -17,27 +17,29 @@
class GrGLCircleEdgeEffect : public GrGLEffect {
public:
- GrGLCircleEdgeEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
+ GrGLCircleEdgeEffect(const GrBackendEffectFactory& factory, const GrEffectRef&)
: INHERITED (factory) {}
virtual void emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect& drawEffect,
+ const GrEffectStage& stage,
EffectKey key,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) SK_OVERRIDE {
- const GrCircleEdgeEffect& circleEffect = drawEffect.castEffect<GrCircleEdgeEffect>();
+ const GrCircleEdgeEffect& effect = GetEffectFromStage<GrCircleEdgeEffect>(stage);
+
const char *vsName, *fsName;
builder->addVarying(kVec4f_GrSLType, "CircleEdge", &vsName, &fsName);
const SkString* attrName =
- builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]);
+ builder->getEffectAttributeName(stage.getVertexAttribIndices()[0]);
builder->vsCodeAppendf("\t%s = %s;\n", vsName, attrName->c_str());
builder->fsCodeAppendf("\tfloat d = distance(%s.xy, %s.xy);\n",
builder->fragmentPosition(), fsName);
builder->fsCodeAppendf("\tfloat edgeAlpha = clamp(%s.z - d, 0.0, 1.0);\n", fsName);
- if (circleEffect.isStroked()) {
+ if (effect.isStroked()) {
builder->fsCodeAppendf("\tfloat innerAlpha = clamp(d - %s.w, 0.0, 1.0);\n", fsName);
builder->fsCodeAppend("\tedgeAlpha *= innerAlpha;\n");
}
@@ -46,13 +48,13 @@ public:
builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str());
}
- static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
- const GrCircleEdgeEffect& circleEffect = drawEffect.castEffect<GrCircleEdgeEffect>();
+ static inline EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) {
+ const GrCircleEdgeEffect& effect = GetEffectFromStage<GrCircleEdgeEffect>(stage);
- return circleEffect.isStroked() ? 0x1 : 0x0;
+ return effect.isStroked() ? 0x1 : 0x0;
}
- virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE {
+ virtual void setData(const GrGLUniformManager& uman, const GrEffectStage& stage) SK_OVERRIDE {
}
private:
diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp
index df8ab8d835..5cc05e2f39 100644
--- a/src/gpu/effects/GrConfigConversionEffect.cpp
+++ b/src/gpu/effects/GrConfigConversionEffect.cpp
@@ -16,22 +16,21 @@
class GrGLConfigConversionEffect : public GrGLEffect {
public:
GrGLConfigConversionEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
- : INHERITED (factory)
- , fEffectMatrix(drawEffect.castEffect<GrConfigConversionEffect>().coordsType()) {
- const GrConfigConversionEffect& effect = drawEffect.castEffect<GrConfigConversionEffect>();
+ const GrEffectRef& s) : INHERITED (factory) {
+ const GrConfigConversionEffect& effect = CastEffect<GrConfigConversionEffect>(s);
fSwapRedAndBlue = effect.swapsRedAndBlue();
fPMConversion = effect.pmConversion();
}
virtual void emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey key,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) SK_OVERRIDE {
const char* coords;
- GrSLType coordsType = fEffectMatrix.emitCode(builder, key, &coords);
+ GrSLType coordsType = fEffectMatrix.emitCode(builder, key, vertexCoords, &coords);
builder->fsCodeAppendf("\t\t%s = ", outputColor);
builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType,
samplers[0],
@@ -72,19 +71,23 @@ public:
builder->fsCodeAppend(modulate.c_str());
}
- void setData(const GrGLUniformManager& uman, const GrDrawEffect& drawEffect) {
- const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigConversionEffect>();
- fEffectMatrix.setData(uman, conv.getMatrix(), drawEffect, conv.texture(0));
+ void setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
+ const GrConfigConversionEffect& effect =
+ GetEffectFromStage<GrConfigConversionEffect>(stage);
+ fEffectMatrix.setData(uman,
+ effect.getMatrix(),
+ stage.getCoordChangeMatrix(),
+ effect.texture(0));
}
- static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
- const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigConversionEffect>();
- EffectKey key = static_cast<EffectKey>(conv.swapsRedAndBlue()) | (conv.pmConversion() << 1);
+ static inline EffectKey GenKey(const GrEffectStage& s, const GrGLCaps&) {
+ const GrConfigConversionEffect& effect = GetEffectFromStage<GrConfigConversionEffect>(s);
+ EffectKey key = static_cast<EffectKey>(effect.swapsRedAndBlue()) |
+ (effect.pmConversion() << 1);
key <<= GrGLEffectMatrix::kKeyBits;
- EffectKey matrixKey = GrGLEffectMatrix::GenKey(conv.getMatrix(),
- drawEffect,
- conv.coordsType(),
- conv.texture(0));
+ EffectKey matrixKey = GrGLEffectMatrix::GenKey(effect.getMatrix(),
+ s.getCoordChangeMatrix(),
+ effect.texture(0));
GrAssert(!(matrixKey & key));
return matrixKey | key;
}
diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp
index 924b03c177..794a9367df 100644
--- a/src/gpu/effects/GrConvolutionEffect.cpp
+++ b/src/gpu/effects/GrConvolutionEffect.cpp
@@ -18,18 +18,19 @@ static const UniformHandle kInvalidUniformHandle = GrGLUniformManager::kInvalidU
class GrGLConvolutionEffect : public GrGLEffect {
public:
- GrGLConvolutionEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
+ GrGLConvolutionEffect(const GrBackendEffectFactory&, const GrEffectRef&);
virtual void emitCode(GrGLShaderBuilder*,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
- virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect&) SK_OVERRIDE;
+ virtual void setData(const GrGLUniformManager& uman, const GrEffectStage&) SK_OVERRIDE;
- static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
+ static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
private:
int width() const { return Gr1DKernelEffect::WidthFromRadius(fRadius); }
@@ -43,23 +44,23 @@ private:
};
GrGLConvolutionEffect::GrGLConvolutionEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
+ const GrEffectRef& effect)
: INHERITED(factory)
, fKernelUni(kInvalidUniformHandle)
- , fImageIncrementUni(kInvalidUniformHandle)
- , fEffectMatrix(drawEffect.castEffect<GrConvolutionEffect>().coordsType()) {
- const GrConvolutionEffect& c = drawEffect.castEffect<GrConvolutionEffect>();
+ , fImageIncrementUni(kInvalidUniformHandle) {
+ const GrConvolutionEffect& c = CastEffect<GrConvolutionEffect>(effect);
fRadius = c.radius();
}
void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey key,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
const char* coords;
- fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
+ fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords);
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec2f_GrSLType, "ImageIncrement");
fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_ShaderType,
@@ -89,9 +90,8 @@ void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
builder->fsCodeAppend(modulate.c_str());
}
-void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman,
- const GrDrawEffect& drawEffect) {
- const GrConvolutionEffect& conv = drawEffect.castEffect<GrConvolutionEffect>();
+void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
+ const GrConvolutionEffect& conv = GetEffectFromStage<GrConvolutionEffect>(stage);
GrTexture& texture = *conv.texture(0);
// the code we generated was for a specific kernel radius
GrAssert(conv.radius() == fRadius);
@@ -108,17 +108,15 @@ void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman,
}
uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
uman.set1fv(fKernelUni, 0, this->width(), conv.kernel());
- fEffectMatrix.setData(uman, conv.getMatrix(), drawEffect, conv.texture(0));
+ fEffectMatrix.setData(uman, conv.getMatrix(), stage.getCoordChangeMatrix(), conv.texture(0));
}
-GrGLEffect::EffectKey GrGLConvolutionEffect::GenKey(const GrDrawEffect& drawEffect,
- const GrGLCaps&) {
- const GrConvolutionEffect& conv = drawEffect.castEffect<GrConvolutionEffect>();
+GrGLEffect::EffectKey GrGLConvolutionEffect::GenKey(const GrEffectStage& s, const GrGLCaps&) {
+ const GrConvolutionEffect& conv = GetEffectFromStage<GrConvolutionEffect>(s);
EffectKey key = conv.radius();
key <<= GrGLEffectMatrix::kKeyBits;
EffectKey matrixKey = GrGLEffectMatrix::GenKey(conv.getMatrix(),
- drawEffect,
- conv.coordsType(),
+ s.getCoordChangeMatrix(),
conv.texture(0));
return key | matrixKey;
}
diff --git a/src/gpu/effects/GrEllipseEdgeEffect.cpp b/src/gpu/effects/GrEllipseEdgeEffect.cpp
index 12f3197d55..37432f0565 100644
--- a/src/gpu/effects/GrEllipseEdgeEffect.cpp
+++ b/src/gpu/effects/GrEllipseEdgeEffect.cpp
@@ -15,28 +15,29 @@
class GrGLEllipseEdgeEffect : public GrGLEffect {
public:
- GrGLEllipseEdgeEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
+ GrGLEllipseEdgeEffect(const GrBackendEffectFactory& factory, const GrEffectRef&)
: INHERITED (factory) {}
virtual void emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect& drawEffect,
+ const GrEffectStage& stage,
EffectKey key,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) SK_OVERRIDE {
- const GrEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<GrEllipseEdgeEffect>();
+ const GrEllipseEdgeEffect& effect = GetEffectFromStage<GrEllipseEdgeEffect>(stage);
const char *vsCenterName, *fsCenterName;
const char *vsEdgeName, *fsEdgeName;
builder->addVarying(kVec2f_GrSLType, "EllipseCenter", &vsCenterName, &fsCenterName);
const SkString* attr0Name =
- builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0]);
+ builder->getEffectAttributeName(stage.getVertexAttribIndices()[0]);
builder->vsCodeAppendf("\t%s = %s;\n", vsCenterName, attr0Name->c_str());
builder->addVarying(kVec4f_GrSLType, "EllipseEdge", &vsEdgeName, &fsEdgeName);
const SkString* attr1Name =
- builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[1]);
+ builder->getEffectAttributeName(stage.getVertexAttribIndices()[1]);
builder->vsCodeAppendf("\t%s = %s;\n", vsEdgeName, attr1Name->c_str());
// translate to origin
@@ -49,7 +50,7 @@ public:
// compare outer lengths against xOuterRadius
builder->fsCodeAppendf("\tfloat edgeAlpha = clamp(%s.x-dOuter, 0.0, 1.0);\n", fsEdgeName);
- if (ellipseEffect.isStroked()) {
+ if (effect.isStroked()) {
builder->fsCodeAppendf("\tinnerOffset.y *= %s.w;\n", fsEdgeName);
builder->fsCodeAppend("\tfloat dInner = length(innerOffset);\n");
@@ -63,13 +64,13 @@ public:
builder->fsCodeAppendf("\t%s = %s;\n", outputColor, modulate.c_str());
}
- static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
- const GrEllipseEdgeEffect& ellipseEffect = drawEffect.castEffect<GrEllipseEdgeEffect>();
+ static inline EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) {
+ const GrEllipseEdgeEffect& effect = GetEffectFromStage<GrEllipseEdgeEffect>(stage);
- return ellipseEffect.isStroked() ? 0x1 : 0x0;
+ return effect.isStroked() ? 0x1 : 0x0;
}
- virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE {
+ virtual void setData(const GrGLUniformManager& uman, const GrEffectStage& stage) SK_OVERRIDE {
}
private:
diff --git a/src/gpu/effects/GrSimpleTextureEffect.cpp b/src/gpu/effects/GrSimpleTextureEffect.cpp
index 80627aabd2..37e6eb4b25 100644
--- a/src/gpu/effects/GrSimpleTextureEffect.cpp
+++ b/src/gpu/effects/GrSimpleTextureEffect.cpp
@@ -15,69 +15,41 @@
class GrGLSimpleTextureEffect : public GrGLEffect {
public:
- GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrDrawEffect& drawEffect)
- : INHERITED (factory) {
- GrEffect::CoordsType coordsType =
- drawEffect.castEffect<GrSimpleTextureEffect>().coordsType();
- if (GrEffect::kCustom_CoordsType != coordsType) {
- SkNEW_IN_TLAZY(&fEffectMatrix, GrGLEffectMatrix, (coordsType));
- }
- }
+ GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrEffectRef&)
+ : INHERITED (factory) {}
virtual void emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect& drawEffect,
+ const GrEffectStage&,
EffectKey key,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) SK_OVERRIDE {
- const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTextureEffect>();
- const char* fsCoordName;
- GrSLType fsCoordSLType;
- if (GrEffect::kCustom_CoordsType == ste.coordsType()) {
- GrAssert(ste.getMatrix().isIdentity());
- GrAssert(1 == ste.numVertexAttribs());
- fsCoordSLType = kVec2f_GrSLType;
- const char* vsVaryingName;
- builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingName, &fsCoordName);
- const char* attrName =
- builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[0])->c_str();
- builder->vsCodeAppendf("\t%s = %s;", vsVaryingName, attrName);
- } else {
- fsCoordSLType = fEffectMatrix.get()->emitCode(builder, key, &fsCoordName);
- }
+ const char* coordName;
+ GrSLType coordType = fEffectMatrix.emitCode(builder, key, vertexCoords, &coordName);
builder->fsCodeAppendf("\t%s = ", outputColor);
builder->appendTextureLookupAndModulate(GrGLShaderBuilder::kFragment_ShaderType,
inputColor,
samplers[0],
- fsCoordName,
- fsCoordSLType);
+ coordName,
+ coordType);
builder->fsCodeAppend(";\n");
}
- static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
- const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTextureEffect>();
- if (GrEffect::kCustom_CoordsType == ste.coordsType()) {
- return 1 << GrGLEffectMatrix::kKeyBits;
- } else {
- return GrGLEffectMatrix::GenKey(ste.getMatrix(),
- drawEffect,
- ste.coordsType(),
- ste.texture(0));
- }
+ static inline EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) {
+ const GrSimpleTextureEffect& ste = GetEffectFromStage<GrSimpleTextureEffect>(stage);
+ return GrGLEffectMatrix::GenKey(ste.getMatrix(),
+ stage.getCoordChangeMatrix(),
+ ste.texture(0));
}
- virtual void setData(const GrGLUniformManager& uman,
- const GrDrawEffect& drawEffect) SK_OVERRIDE {
- const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTextureEffect>();
- if (GrEffect::kCustom_CoordsType == ste.coordsType()) {
- GrAssert(ste.getMatrix().isIdentity());
- } else {
- fEffectMatrix.get()->setData(uman, ste.getMatrix(), drawEffect, ste.texture(0));
- }
+ virtual void setData(const GrGLUniformManager& uman, const GrEffectStage& stage) SK_OVERRIDE {
+ const GrSimpleTextureEffect& ste = GetEffectFromStage<GrSimpleTextureEffect>(stage);
+ fEffectMatrix.setData(uman, ste.getMatrix(), stage.getCoordChangeMatrix(), ste.texture(0));
}
private:
- SkTLazy<GrGLEffectMatrix> fEffectMatrix;
+ GrGLEffectMatrix fEffectMatrix;
typedef GrGLEffect INHERITED;
};
@@ -100,28 +72,6 @@ GrEffectRef* GrSimpleTextureEffect::TestCreate(SkMWCRandom* random,
GrTexture* textures[]) {
int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
GrEffectUnitTest::kAlphaTextureIdx;
- static const SkShader::TileMode kTileModes[] = {
- SkShader::kClamp_TileMode,
- SkShader::kRepeat_TileMode,
- SkShader::kMirror_TileMode,
- };
- SkShader::TileMode tileModes[] = {
- kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
- kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))],
- };
- GrTextureParams params(tileModes, random->nextBool());
-
- static const CoordsType kCoordsTypes[] = {
- kLocal_CoordsType,
- kPosition_CoordsType,
- kCustom_CoordsType
- };
- CoordsType coordsType = kCoordsTypes[random->nextULessThan(GR_ARRAY_COUNT(kCoordsTypes))];
-
- if (kCustom_CoordsType == coordsType) {
- return GrSimpleTextureEffect::CreateWithCustomCoords(textures[texIdx], params);
- } else {
- const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
- return GrSimpleTextureEffect::Create(textures[texIdx], matrix);
- }
+ const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
+ return GrSimpleTextureEffect::Create(textures[texIdx], matrix);
}
diff --git a/src/gpu/effects/GrSimpleTextureEffect.h b/src/gpu/effects/GrSimpleTextureEffect.h
index 661f40f037..ffc05e5b52 100644
--- a/src/gpu/effects/GrSimpleTextureEffect.h
+++ b/src/gpu/effects/GrSimpleTextureEffect.h
@@ -14,50 +14,25 @@ class GrGLSimpleTextureEffect;
/**
* The output color of this effect is a modulation of the input color and a sample from a texture.
- * It allows explicit specification of the filtering and wrap modes (GrTextureParams). It can use
- * local coords, positions, or a custom vertex attribute as input texture coords. The input coords
- * can have a matrix applied in the VS in both the local and position cases but not with a custom
- * attribute coords at this time. It will add a varying to input interpolate texture coords to the
- * FS.
+ * The coord to sample the texture is determine by a matrix. It allows explicit specification of
+ * the filtering and wrap modes (GrTextureParams).
*/
class GrSimpleTextureEffect : public GrSingleTextureEffect {
public:
/* unfiltered, clamp mode */
- static GrEffectRef* Create(GrTexture* tex,
- const SkMatrix& matrix,
- CoordsType coordsType = kLocal_CoordsType) {
- GrAssert(kLocal_CoordsType == coordsType || kPosition_CoordsType == coordsType);
- AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, false, coordsType)));
+ static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix) {
+ AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix)));
return CreateEffectRef(effect);
}
/* clamp mode */
- static GrEffectRef* Create(GrTexture* tex,
- const SkMatrix& matrix,
- bool bilerp,
- CoordsType coordsType = kLocal_CoordsType) {
- GrAssert(kLocal_CoordsType == coordsType || kPosition_CoordsType == coordsType);
- AutoEffectUnref effect(
- SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, bilerp, coordsType)));
+ static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, bool bilerp) {
+ AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, bilerp)));
return CreateEffectRef(effect);
}
- static GrEffectRef* Create(GrTexture* tex,
- const SkMatrix& matrix,
- const GrTextureParams& p,
- CoordsType coordsType = kLocal_CoordsType) {
- GrAssert(kLocal_CoordsType == coordsType || kPosition_CoordsType == coordsType);
- AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, p, coordsType)));
- return CreateEffectRef(effect);
- }
-
- /** Variant that requires the client to install a custom kVec2 vertex attribute that will be
- the source of the coords. No matrix is allowed in this mode. */
- static GrEffectRef* CreateWithCustomCoords(GrTexture* tex, const GrTextureParams& p) {
- AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex,
- SkMatrix::I(),
- p,
- kCustom_CoordsType)));
+ static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, const GrTextureParams& p) {
+ AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, p)));
return CreateEffectRef(effect);
}
@@ -72,28 +47,16 @@ public:
virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
private:
- GrSimpleTextureEffect(GrTexture* texture,
- const SkMatrix& matrix,
- bool bilerp,
- CoordsType coordsType)
- : GrSingleTextureEffect(texture, matrix, bilerp, coordsType) {
- GrAssert(kLocal_CoordsType == coordsType || kPosition_CoordsType == coordsType);
- }
-
- GrSimpleTextureEffect(GrTexture* texture,
- const SkMatrix& matrix,
- const GrTextureParams& params,
- CoordsType coordsType)
- : GrSingleTextureEffect(texture, matrix, params, coordsType) {
- if (kCustom_CoordsType == coordsType) {
- GrAssert(matrix.isIdentity());
- this->addVertexAttrib(kVec2f_GrSLType);
- }
- }
+ GrSimpleTextureEffect(GrTexture* texture, const SkMatrix& matrix)
+ : GrSingleTextureEffect(texture, matrix) {}
+ GrSimpleTextureEffect(GrTexture* texture, const SkMatrix& matrix, bool bilerp)
+ : GrSingleTextureEffect(texture, matrix, bilerp) {}
+ GrSimpleTextureEffect(GrTexture* texture, const SkMatrix& matrix, const GrTextureParams& params)
+ : GrSingleTextureEffect(texture, matrix, params) {}
virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE {
const GrSimpleTextureEffect& ste = CastEffect<GrSimpleTextureEffect>(other);
- return this->hasSameTextureParamsMatrixAndCoordsType(ste);
+ return this->hasSameTextureParamsAndMatrix(ste);
}
GR_DECLARE_EFFECT_TEST;
diff --git a/src/gpu/effects/GrSingleTextureEffect.cpp b/src/gpu/effects/GrSingleTextureEffect.cpp
index 0c671f16d0..7183ba3244 100644
--- a/src/gpu/effects/GrSingleTextureEffect.cpp
+++ b/src/gpu/effects/GrSingleTextureEffect.cpp
@@ -7,32 +7,23 @@
#include "effects/GrSingleTextureEffect.h"
-GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture,
- const SkMatrix& m,
- CoordsType coordsType)
+GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const SkMatrix& m)
: fTextureAccess(texture)
- , fMatrix(m)
- , fCoordsType(coordsType) {
+ , fMatrix(m) {
this->addTextureAccess(&fTextureAccess);
}
-GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture,
- const SkMatrix& m,
- bool bilerp,
- CoordsType coordsType)
+GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const SkMatrix& m, bool bilerp)
: fTextureAccess(texture, bilerp)
- , fMatrix(m)
- , fCoordsType(coordsType) {
+ , fMatrix(m) {
this->addTextureAccess(&fTextureAccess);
}
GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture,
const SkMatrix& m,
- const GrTextureParams& params,
- CoordsType coordsType)
+ const GrTextureParams& params)
: fTextureAccess(texture, params)
- , fMatrix(m)
- , fCoordsType(coordsType) {
+ , fMatrix(m) {
this->addTextureAccess(&fTextureAccess);
}
diff --git a/src/gpu/effects/GrSingleTextureEffect.h b/src/gpu/effects/GrSingleTextureEffect.h
index 82037cf6e9..4f25ddb38d 100644
--- a/src/gpu/effects/GrSingleTextureEffect.h
+++ b/src/gpu/effects/GrSingleTextureEffect.h
@@ -14,8 +14,7 @@
class GrTexture;
/**
- * A base class for effects that draw a single texture with a texture matrix. This effect has no
- * backend implementations. One must be provided by the subclass.
+ * A base class for effects that draw a single texture with a texture matrix.
*/
class GrSingleTextureEffect : public GrEffect {
public:
@@ -23,29 +22,20 @@ public:
const SkMatrix& getMatrix() const { return fMatrix; }
- /** Indicates whether the matrix operates on local coords or positions */
- CoordsType coordsType() const { return fCoordsType; }
-
protected:
- /** unfiltered, clamp mode */
- GrSingleTextureEffect(GrTexture*, const SkMatrix&, CoordsType = kLocal_CoordsType);
- /** clamp mode */
- GrSingleTextureEffect(GrTexture*, const SkMatrix&, bool bilerp, CoordsType = kLocal_CoordsType);
- GrSingleTextureEffect(GrTexture*,
- const SkMatrix&,
- const GrTextureParams&,
- CoordsType = kLocal_CoordsType);
+ GrSingleTextureEffect(GrTexture*, const SkMatrix&); /* unfiltered, clamp mode */
+ GrSingleTextureEffect(GrTexture*, const SkMatrix&, bool bilerp); /* clamp mode */
+ GrSingleTextureEffect(GrTexture*, const SkMatrix&, const GrTextureParams&);
/**
* Helper for subclass onIsEqual() functions.
*/
- bool hasSameTextureParamsMatrixAndCoordsType(const GrSingleTextureEffect& other) const {
+ bool hasSameTextureParamsAndMatrix(const GrSingleTextureEffect& other) const {
const GrTextureAccess& otherAccess = other.fTextureAccess;
// We don't have to check the accesses' swizzles because they are inferred from the texture.
return fTextureAccess.getTexture() == otherAccess.getTexture() &&
fTextureAccess.getParams() == otherAccess.getParams() &&
- this->getMatrix().cheapEqualTo(other.getMatrix()) &&
- fCoordsType == other.fCoordsType;
+ this->getMatrix().cheapEqualTo(other.getMatrix());
}
/**
@@ -65,7 +55,6 @@ protected:
private:
GrTextureAccess fTextureAccess;
SkMatrix fMatrix;
- CoordsType fCoordsType;
typedef GrEffect INHERITED;
};
diff --git a/src/gpu/effects/GrTextureDomainEffect.cpp b/src/gpu/effects/GrTextureDomainEffect.cpp
index b1fd3ed6d5..e54af25ca0 100644
--- a/src/gpu/effects/GrTextureDomainEffect.cpp
+++ b/src/gpu/effects/GrTextureDomainEffect.cpp
@@ -14,18 +14,19 @@
class GrGLTextureDomainEffect : public GrGLEffect {
public:
- GrGLTextureDomainEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
+ GrGLTextureDomainEffect(const GrBackendEffectFactory&, const GrEffectRef&);
virtual void emitCode(GrGLShaderBuilder*,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
- virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
+ virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
- static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
+ static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
private:
GrGLUniformManager::UniformHandle fNameUni;
@@ -36,27 +37,27 @@ private:
};
GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
+ const GrEffectRef&)
: INHERITED(factory)
- , fNameUni(GrGLUniformManager::kInvalidUniformHandle)
- , fEffectMatrix(drawEffect.castEffect<GrTextureDomainEffect>().coordsType()) {
+ , fNameUni(GrGLUniformManager::kInvalidUniformHandle) {
fPrevDomain[0] = SK_FloatNaN;
}
void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect& drawEffect,
+ const GrEffectStage& stage,
EffectKey key,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
- const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainEffect>();
+ const GrTextureDomainEffect& effect = GetEffectFromStage<GrTextureDomainEffect>(stage);
const char* coords;
- fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
+ fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords);
const char* domain;
fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec4f_GrSLType, "TexDom", &domain);
- if (GrTextureDomainEffect::kClamp_WrapMode == texDom.wrapMode()) {
+ if (GrTextureDomainEffect::kClamp_WrapMode == effect.wrapMode()) {
builder->fsCodeAppendf("\tvec2 clampCoord = clamp(%s, %s.xy, %s.zw);\n",
coords, domain, domain);
@@ -68,7 +69,7 @@ void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
"clampCoord");
builder->fsCodeAppend(";\n");
} else {
- GrAssert(GrTextureDomainEffect::kDecal_WrapMode == texDom.wrapMode());
+ GrAssert(GrTextureDomainEffect::kDecal_WrapMode == effect.wrapMode());
if (kImagination_GrGLVendor == builder->ctxInfo().vendor()) {
// On the NexusS and GalaxyNexus, the other path (with the 'any'
@@ -105,10 +106,9 @@ void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
}
}
-void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman,
- const GrDrawEffect& drawEffect) {
- const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainEffect>();
- const GrRect& domain = texDom.domain();
+void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
+ const GrTextureDomainEffect& effect = GetEffectFromStage<GrTextureDomainEffect>(stage);
+ const GrRect& domain = effect.domain();
float values[4] = {
SkScalarToFloat(domain.left()),
@@ -117,7 +117,7 @@ void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman,
SkScalarToFloat(domain.bottom())
};
// vertical flip if necessary
- if (kBottomLeft_GrSurfaceOrigin == texDom.texture(0)->origin()) {
+ if (kBottomLeft_GrSurfaceOrigin == effect.texture(0)->origin()) {
values[1] = 1.0f - values[1];
values[3] = 1.0f - values[3];
// The top and bottom were just flipped, so correct the ordering
@@ -128,20 +128,18 @@ void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman,
uman.set4fv(fNameUni, 0, 1, values);
}
fEffectMatrix.setData(uman,
- texDom.getMatrix(),
- drawEffect,
- texDom.texture(0));
+ effect.getMatrix(),
+ stage.getCoordChangeMatrix(),
+ effect.texture(0));
}
-GrGLEffect::EffectKey GrGLTextureDomainEffect::GenKey(const GrDrawEffect& drawEffect,
- const GrGLCaps&) {
- const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainEffect>();
- EffectKey key = texDom.wrapMode();
+GrGLEffect::EffectKey GrGLTextureDomainEffect::GenKey(const GrEffectStage& stage, const GrGLCaps&) {
+ const GrTextureDomainEffect& effect = GetEffectFromStage<GrTextureDomainEffect>(stage);
+ EffectKey key = effect.wrapMode();
key <<= GrGLEffectMatrix::kKeyBits;
- EffectKey matrixKey = GrGLEffectMatrix::GenKey(texDom.getMatrix(),
- drawEffect,
- texDom.coordsType(),
- texDom.texture(0));
+ EffectKey matrixKey = GrGLEffectMatrix::GenKey(effect.getMatrix(),
+ stage.getCoordChangeMatrix(),
+ effect.texture(0));
return key | matrixKey;
}
@@ -152,8 +150,7 @@ GrEffectRef* GrTextureDomainEffect::Create(GrTexture* texture,
const SkMatrix& matrix,
const GrRect& domain,
WrapMode wrapMode,
- bool bilerp,
- CoordsType coordsType) {
+ bool bilerp) {
static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1};
if (kClamp_WrapMode == wrapMode && domain.contains(kFullRect)) {
return GrSimpleTextureEffect::Create(texture, matrix, bilerp);
@@ -175,8 +172,7 @@ GrEffectRef* GrTextureDomainEffect::Create(GrTexture* texture,
matrix,
clippedDomain,
wrapMode,
- bilerp,
- coordsType)));
+ bilerp)));
return CreateEffectRef(effect);
}
@@ -186,9 +182,8 @@ GrTextureDomainEffect::GrTextureDomainEffect(GrTexture* texture,
const SkMatrix& matrix,
const GrRect& domain,
WrapMode wrapMode,
- bool bilerp,
- CoordsType coordsType)
- : GrSingleTextureEffect(texture, matrix, bilerp, coordsType)
+ bool bilerp)
+ : GrSingleTextureEffect(texture, matrix, bilerp)
, fWrapMode(wrapMode)
, fTextureDomain(domain) {
}
@@ -203,8 +198,7 @@ const GrBackendEffectFactory& GrTextureDomainEffect::getFactory() const {
bool GrTextureDomainEffect::onIsEqual(const GrEffect& sBase) const {
const GrTextureDomainEffect& s = CastEffect<GrTextureDomainEffect>(sBase);
- return this->hasSameTextureParamsMatrixAndCoordsType(s) &&
- this->fTextureDomain == s.fTextureDomain;
+ return this->hasSameTextureParamsAndMatrix(s) && this->fTextureDomain == s.fTextureDomain;
}
void GrTextureDomainEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const {
@@ -231,12 +225,5 @@ GrEffectRef* GrTextureDomainEffect::TestCreate(SkMWCRandom* random,
domain.fBottom = random->nextRangeScalar(domain.fTop, SK_Scalar1);
WrapMode wrapMode = random->nextBool() ? kClamp_WrapMode : kDecal_WrapMode;
const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
- bool bilerp = random->nextBool();
- CoordsType coords = random->nextBool() ? kLocal_CoordsType : kPosition_CoordsType;
- return GrTextureDomainEffect::Create(textures[texIdx],
- matrix,
- domain,
- wrapMode,
- bilerp,
- coords);
+ return GrTextureDomainEffect::Create(textures[texIdx], matrix, domain, wrapMode);
}
diff --git a/src/gpu/effects/GrTextureDomainEffect.h b/src/gpu/effects/GrTextureDomainEffect.h
index 8b1f2b6f61..b7f665cba3 100644
--- a/src/gpu/effects/GrTextureDomainEffect.h
+++ b/src/gpu/effects/GrTextureDomainEffect.h
@@ -38,8 +38,7 @@ public:
const SkMatrix&,
const SkRect& domain,
WrapMode,
- bool bilerp,
- CoordsType = kLocal_CoordsType);
+ bool bilerp = false);
virtual ~GrTextureDomainEffect();
@@ -76,8 +75,7 @@ private:
const SkMatrix&,
const GrRect& domain,
WrapMode,
- bool bilerp,
- CoordsType type);
+ bool bilerp);
virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;