revert 8265-8264 (broke build)
git-svn-id: http://skia.googlecode.com/svn/trunk@8268 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/effects/SkBicubicImageFilter.cpp b/src/effects/SkBicubicImageFilter.cpp
index 507612e..f4d474d 100644
--- a/src/effects/SkBicubicImageFilter.cpp
+++ b/src/effects/SkBicubicImageFilter.cpp
@@ -185,17 +185,18 @@
class GrGLBicubicEffect : public GrGLEffect {
public:
GrGLBicubicEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect&);
+ const GrEffectRef& effect);
virtual void emitCode(GrGLShaderBuilder*,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
- static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
+ static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
- virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
+ virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
private:
typedef GrGLUniformManager::UniformHandle UniformHandle;
@@ -209,21 +210,21 @@
};
GrGLBicubicEffect::GrGLBicubicEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
+ const GrEffectRef& effect)
: INHERITED(factory)
, fCoefficientsUni(GrGLUniformManager::kInvalidUniformHandle)
- , fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle)
- , fEffectMatrix(drawEffect.castEffect<GrBicubicEffect>().coordsType()) {
+ , fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle) {
}
void GrGLBicubicEffect::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);
fCoefficientsUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kMat44f_GrSLType, "Coefficients");
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
@@ -268,18 +269,17 @@
builder->fsCodeAppendf("\t%s = %s(%s, f.y, s0, s1, s2, s3);\n", outputColor, cubicBlendName.c_str(), coeff);
}
-GrGLEffect::EffectKey GrGLBicubicEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
- const GrBicubicEffect& bicubic = drawEffect.castEffect<GrBicubicEffect>();
- EffectKey matrixKey = GrGLEffectMatrix::GenKey(bicubic.getMatrix(),
- drawEffect,
- bicubic.coordsType(),
- bicubic.texture(0));
+GrGLEffect::EffectKey GrGLBicubicEffect::GenKey(const GrEffectStage& s, const GrGLCaps&) {
+ const GrBicubicEffect& m = GetEffectFromStage<GrBicubicEffect>(s);
+ EffectKey matrixKey = GrGLEffectMatrix::GenKey(m.getMatrix(),
+ s.getCoordChangeMatrix(),
+ m.texture(0));
return matrixKey;
}
void GrGLBicubicEffect::setData(const GrGLUniformManager& uman,
- const GrDrawEffect& drawEffect) {
- const GrBicubicEffect& effect = drawEffect.castEffect<GrBicubicEffect>();
+ const GrEffectStage& stage) {
+ const GrBicubicEffect& effect = GetEffectFromStage<GrBicubicEffect>(stage);
GrTexture& texture = *effect.texture(0);
float imageIncrement[2];
imageIncrement[0] = 1.0f / texture.width();
@@ -288,7 +288,7 @@
uman.setMatrix4f(fCoefficientsUni, effect.coefficients());
fEffectMatrix.setData(uman,
effect.getMatrix(),
- drawEffect,
+ stage.getCoordChangeMatrix(),
effect.texture(0));
}
diff --git a/src/effects/SkBlendImageFilter.cpp b/src/effects/SkBlendImageFilter.cpp
index 767d181..ae129eb 100644
--- a/src/effects/SkBlendImageFilter.cpp
+++ b/src/effects/SkBlendImageFilter.cpp
@@ -94,23 +94,23 @@
#if SK_SUPPORT_GPU
class GrGLBlendEffect : public GrGLEffect {
public:
- GrGLBlendEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
+ GrGLBlendEffect(const GrBackendEffectFactory& factory,
+ const GrEffectRef& effect);
virtual ~GrGLBlendEffect();
virtual void emitCode(GrGLShaderBuilder*,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
- static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
+ static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
- virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
+ virtual void setData(const GrGLUniformManager&, const GrEffectStage&);
private:
- static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType;
-
SkBlendImageFilter::Mode fMode;
GrGLEffectMatrix fForegroundEffectMatrix;
GrGLEffectMatrix fBackgroundEffectMatrix;
@@ -131,13 +131,13 @@
virtual ~GrBlendEffect();
- virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
+ const GrBackendEffectFactory& getFactory() const;
SkBlendImageFilter::Mode mode() const { return fMode; }
typedef GrGLBlendEffect GLEffect;
static const char* Name() { return "Blend"; }
- virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+ void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
private:
virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
@@ -224,28 +224,27 @@
///////////////////////////////////////////////////////////////////////////////
-GrGLBlendEffect::GrGLBlendEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
- : INHERITED(factory)
- , fMode(drawEffect.castEffect<GrBlendEffect>().mode())
- , fForegroundEffectMatrix(kCoordsType)
- , fBackgroundEffectMatrix(kCoordsType) {
+GrGLBlendEffect::GrGLBlendEffect(const GrBackendEffectFactory& factory, const GrEffectRef& effect)
+ : INHERITED(factory),
+ fMode(CastEffect<GrBlendEffect>(effect).mode()) {
}
GrGLBlendEffect::~GrGLBlendEffect() {
}
void GrGLBlendEffect::emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey key,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
- const GrGLShaderVar& localCoords = builder->localCoordsAttribute();
const char* fgCoords;
const char* bgCoords;
- GrSLType fgCoordsType = fForegroundEffectMatrix.emitCode(builder, key, &fgCoords, NULL, "FG");
- GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(builder, key, &bgCoords, NULL, "BG");
+ GrSLType fgCoordsType = fForegroundEffectMatrix.emitCode(
+ builder, key, vertexCoords, &fgCoords, NULL, "FG");
+ GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(
+ builder, key, vertexCoords, &bgCoords, NULL, "BG");
const char* bgColor = "bgColor";
const char* fgColor = "fgColor";
@@ -284,35 +283,33 @@
}
}
-void GrGLBlendEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect& drawEffect) {
- const GrBlendEffect& blend = drawEffect.castEffect<GrBlendEffect>();
+void GrGLBlendEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
+ const GrBlendEffect& blend = GetEffectFromStage<GrBlendEffect>(stage);
GrTexture* fgTex = blend.texture(0);
GrTexture* bgTex = blend.texture(1);
fForegroundEffectMatrix.setData(uman,
GrEffect::MakeDivByTextureWHMatrix(fgTex),
- drawEffect,
+ stage.getCoordChangeMatrix(),
fgTex);
fBackgroundEffectMatrix.setData(uman,
GrEffect::MakeDivByTextureWHMatrix(bgTex),
- drawEffect,
+ stage.getCoordChangeMatrix(),
bgTex);
}
-GrGLEffect::EffectKey GrGLBlendEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
- const GrBlendEffect& blend = drawEffect.castEffect<GrBlendEffect>();
+GrGLEffect::EffectKey GrGLBlendEffect::GenKey(const GrEffectStage& stage, const GrGLCaps&) {
+ const GrBlendEffect& blend = GetEffectFromStage<GrBlendEffect>(stage);
GrTexture* fgTex = blend.texture(0);
GrTexture* bgTex = blend.texture(1);
EffectKey fgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatrix(fgTex),
- drawEffect,
- kCoordsType,
+ stage.getCoordChangeMatrix(),
fgTex);
EffectKey bgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatrix(bgTex),
- drawEffect,
- kCoordsType,
+ stage.getCoordChangeMatrix(),
bgTex);
bgKey <<= GrGLEffectMatrix::kKeyBits;
EffectKey modeKey = blend.mode() << (2 * GrGLEffectMatrix::kKeyBits);
diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp
index 55e8bba..b39c5f8 100644
--- a/src/effects/SkColorMatrixFilter.cpp
+++ b/src/effects/SkColorMatrixFilter.cpp
@@ -386,17 +386,18 @@
class GLEffect : public GrGLEffect {
public:
// this class always generates the same code.
- static EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&) { return 0; }
+ static EffectKey GenKey(const GrEffectStage&, const GrGLCaps&) { return 0; }
GLEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect&)
+ const GrEffectRef& effect)
: INHERITED(factory)
, fMatrixHandle(GrGLUniformManager::kInvalidUniformHandle)
, fVectorHandle(GrGLUniformManager::kInvalidUniformHandle) {}
virtual void emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE {
@@ -423,8 +424,8 @@
}
virtual void setData(const GrGLUniformManager& uniManager,
- const GrDrawEffect& drawEffect) SK_OVERRIDE {
- const ColorMatrixEffect& cme = drawEffect.castEffect<ColorMatrixEffect>();
+ const GrEffectStage& stage) SK_OVERRIDE {
+ const ColorMatrixEffect& cme = GetEffectFromStage<ColorMatrixEffect>(stage);
const float* m = cme.fMatrix.fMat;
// The GL matrix is transposed from SkColorMatrix.
GrGLfloat mt[] = {
diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp
index 516afe7..9c89a6a 100644
--- a/src/effects/SkDisplacementMapEffect.cpp
+++ b/src/effects/SkDisplacementMapEffect.cpp
@@ -201,23 +201,22 @@
class GrGLDisplacementMapEffect : public GrGLEffect {
public:
GrGLDisplacementMapEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect);
+ const GrEffectRef& effect);
virtual ~GrGLDisplacementMapEffect();
virtual void emitCode(GrGLShaderBuilder*,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
- static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
+ static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
- virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
+ virtual void setData(const GrGLUniformManager&, const GrEffectStage&);
private:
- static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType;
-
SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector;
SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector;
GrGLEffectMatrix fDisplacementEffectMatrix;
@@ -246,7 +245,7 @@
virtual ~GrDisplacementMapEffect();
- virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
+ const GrBackendEffectFactory& getFactory() const;
SkDisplacementMapEffect::ChannelSelectorType xChannelSelector() const
{ return fXChannelSelector; }
SkDisplacementMapEffect::ChannelSelectorType yChannelSelector() const
@@ -256,10 +255,9 @@
typedef GrGLDisplacementMapEffect GLEffect;
static const char* Name() { return "DisplacementMap"; }
- virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
+ void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
private:
-
virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChannelSelector,
@@ -384,33 +382,32 @@
///////////////////////////////////////////////////////////////////////////////
GrGLDisplacementMapEffect::GrGLDisplacementMapEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
+ const GrEffectRef& effect)
: INHERITED(factory)
- , fDisplacementEffectMatrix(kCoordsType)
- , fColorEffectMatrix(kCoordsType)
- , fXChannelSelector(drawEffect.castEffect<GrDisplacementMapEffect>().xChannelSelector())
- , fYChannelSelector(drawEffect.castEffect<GrDisplacementMapEffect>().yChannelSelector()) {
+ , fXChannelSelector(CastEffect<GrDisplacementMapEffect>(effect).xChannelSelector())
+ , fYChannelSelector(CastEffect<GrDisplacementMapEffect>(effect).yChannelSelector()) {
}
GrGLDisplacementMapEffect::~GrGLDisplacementMapEffect() {
}
void GrGLDisplacementMapEffect::emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect&,
- EffectKey key,
- const char* outputColor,
- const char* inputColor,
- const TextureSamplerArray& samplers) {
+ const GrEffectStage&,
+ EffectKey key,
+ const char* vertexCoords,
+ const char* outputColor,
+ const char* inputColor,
+ const TextureSamplerArray& samplers) {
fScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec2f_GrSLType, "Scale");
const char* scaleUni = builder->getUniformCStr(fScaleUni);
const char* dCoordsIn;
GrSLType dCoordsType = fDisplacementEffectMatrix.emitCode(
- builder, key, &dCoordsIn, NULL, "DISPL");
+ builder, key, vertexCoords, &dCoordsIn, NULL, "DISPL");
const char* cCoordsIn;
GrSLType cCoordsType = fColorEffectMatrix.emitCode(
- builder, key, &cCoordsIn, NULL, "COLOR");
+ builder, key, vertexCoords, &cCoordsIn, NULL, "COLOR");
const char* dColor = "dColor";
const char* cCoords = "cCoords";
@@ -481,19 +478,17 @@
builder->fsCodeAppend(";\n");
}
-void GrGLDisplacementMapEffect::setData(const GrGLUniformManager& uman,
- const GrDrawEffect& drawEffect) {
- const GrDisplacementMapEffect& displacementMap =
- drawEffect.castEffect<GrDisplacementMapEffect>();
+void GrGLDisplacementMapEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
+ const GrDisplacementMapEffect& displacementMap = GetEffectFromStage<GrDisplacementMapEffect>(stage);
GrTexture* displTex = displacementMap.texture(0);
GrTexture* colorTex = displacementMap.texture(1);
fDisplacementEffectMatrix.setData(uman,
GrEffect::MakeDivByTextureWHMatrix(displTex),
- drawEffect,
+ stage.getCoordChangeMatrix(),
displTex);
fColorEffectMatrix.setData(uman,
GrEffect::MakeDivByTextureWHMatrix(colorTex),
- drawEffect,
+ stage.getCoordChangeMatrix(),
colorTex);
SkScalar scaleX = SkScalarDiv(displacementMap.scale(), SkIntToScalar(colorTex->width()));
@@ -503,22 +498,20 @@
SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY));
}
-GrGLEffect::EffectKey GrGLDisplacementMapEffect::GenKey(const GrDrawEffect& drawEffect,
+GrGLEffect::EffectKey GrGLDisplacementMapEffect::GenKey(const GrEffectStage& stage,
const GrGLCaps&) {
const GrDisplacementMapEffect& displacementMap =
- drawEffect.castEffect<GrDisplacementMapEffect>();
+ GetEffectFromStage<GrDisplacementMapEffect>(stage);
GrTexture* displTex = displacementMap.texture(0);
GrTexture* colorTex = displacementMap.texture(1);
EffectKey displKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatrix(displTex),
- drawEffect,
- kCoordsType,
+ stage.getCoordChangeMatrix(),
displTex);
EffectKey colorKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatrix(colorTex),
- drawEffect,
- kCoordsType,
+ stage.getCoordChangeMatrix(),
colorTex);
colorKey <<= GrGLEffectMatrix::kKeyBits;
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index 2d2d3b2..177ba09 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -980,22 +980,23 @@
class GrGLLightingEffect : public GrGLEffect {
public:
GrGLLightingEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& effect);
+ const GrEffectRef& effect);
virtual ~GrGLLightingEffect();
virtual void emitCode(GrGLShaderBuilder*,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
- static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
+ static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
/**
* Subclasses of GrGLLightingEffect must call INHERITED::setData();
*/
- virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
+ virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
protected:
virtual void emitLightFunc(GrGLShaderBuilder*, SkString* funcName) = 0;
@@ -1014,9 +1015,9 @@
class GrGLDiffuseLightingEffect : public GrGLLightingEffect {
public:
GrGLDiffuseLightingEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect);
+ const GrEffectRef& effect);
virtual void emitLightFunc(GrGLShaderBuilder*, SkString* funcName) SK_OVERRIDE;
- virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
+ virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
private:
typedef GrGLLightingEffect INHERITED;
@@ -1029,9 +1030,9 @@
class GrGLSpecularLightingEffect : public GrGLLightingEffect {
public:
GrGLSpecularLightingEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& effect);
+ const GrEffectRef& effect);
virtual void emitLightFunc(GrGLShaderBuilder*, SkString* funcName) SK_OVERRIDE;
- virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
+ virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
private:
typedef GrGLLightingEffect INHERITED;
@@ -1092,12 +1093,11 @@
///////////////////////////////////////////////////////////////////////////////
GrGLLightingEffect::GrGLLightingEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
+ const GrEffectRef& effect)
: INHERITED(factory)
, fImageIncrementUni(kInvalidUniformHandle)
- , fSurfaceScaleUni(kInvalidUniformHandle)
- , fEffectMatrix(drawEffect.castEffect<GrLightingEffect>().coordsType()) {
- const GrLightingEffect& m = drawEffect.castEffect<GrLightingEffect>();
+ , fSurfaceScaleUni(kInvalidUniformHandle) {
+ const GrLightingEffect& m = CastEffect<GrLightingEffect>(effect);
fLight = m.light()->createGLLight();
}
@@ -1106,14 +1106,14 @@
}
void GrGLLightingEffect::emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey key,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
const char* coords;
- const GrGLShaderVar& localCoords = builder->localCoordsAttribute();
- fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
+ fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, vertexCoords, &coords);
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec2f_GrSLType,
@@ -1207,30 +1207,28 @@
builder->fsCodeAppend(modulate.c_str());
}
-GrGLEffect::EffectKey GrGLLightingEffect::GenKey(const GrDrawEffect& drawEffect,
+GrGLEffect::EffectKey GrGLLightingEffect::GenKey(const GrEffectStage& s,
const GrGLCaps& caps) {
- const GrLightingEffect& lighting = drawEffect.castEffect<GrLightingEffect>();
- EffectKey key = lighting.light()->type();
+ const GrLightingEffect& effect = GetEffectFromStage<GrLightingEffect>(s);
+ EffectKey key = effect.light()->type();
key <<= GrGLEffectMatrix::kKeyBits;
- EffectKey matrixKey = GrGLEffectMatrix::GenKey(lighting.getMatrix(),
- drawEffect,
- lighting.coordsType(),
- lighting.texture(0));
+ EffectKey matrixKey = GrGLEffectMatrix::GenKey(effect.getMatrix(),
+ s.getCoordChangeMatrix(),
+ effect.texture(0));
return key | matrixKey;
}
-void GrGLLightingEffect::setData(const GrGLUniformManager& uman,
- const GrDrawEffect& drawEffect) {
- const GrLightingEffect& lighting = drawEffect.castEffect<GrLightingEffect>();
- GrTexture* texture = lighting.texture(0);
+void GrGLLightingEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
+ const GrLightingEffect& effect = GetEffectFromStage<GrLightingEffect>(stage);
+ GrTexture* texture = effect.texture(0);
float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f;
uman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->height());
- uman.set1f(fSurfaceScaleUni, lighting.surfaceScale());
- fLight->setData(uman, lighting.light());
+ uman.set1f(fSurfaceScaleUni, effect.surfaceScale());
+ fLight->setData(uman, effect.light());
fEffectMatrix.setData(uman,
- lighting.getMatrix(),
- drawEffect,
- lighting.texture(0));
+ effect.getMatrix(),
+ stage.getCoordChangeMatrix(),
+ effect.texture(0));
}
///////////////////////////////////////////////////////////////////////////////
@@ -1238,8 +1236,8 @@
///////////////////////////////////////////////////////////////////////////////
GrGLDiffuseLightingEffect::GrGLDiffuseLightingEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
- : INHERITED(factory, drawEffect)
+ const GrEffectRef& effect)
+ : INHERITED(factory, effect)
, fKDUni(kInvalidUniformHandle) {
}
@@ -1268,10 +1266,10 @@
}
void GrGLDiffuseLightingEffect::setData(const GrGLUniformManager& uman,
- const GrDrawEffect& drawEffect) {
- INHERITED::setData(uman, drawEffect);
- const GrDiffuseLightingEffect& diffuse = drawEffect.castEffect<GrDiffuseLightingEffect>();
- uman.set1f(fKDUni, diffuse.kd());
+ const GrEffectStage& stage) {
+ INHERITED::setData(uman, stage);
+ const GrDiffuseLightingEffect& effect = GetEffectFromStage<GrDiffuseLightingEffect>(stage);
+ uman.set1f(fKDUni, effect.kd());
}
///////////////////////////////////////////////////////////////////////////////
@@ -1309,8 +1307,8 @@
///////////////////////////////////////////////////////////////////////////////
GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
- : GrGLLightingEffect(factory, drawEffect)
+ const GrEffectRef& effect)
+ : GrGLLightingEffect(factory, effect)
, fKSUni(kInvalidUniformHandle)
, fShininessUni(kInvalidUniformHandle) {
}
@@ -1344,11 +1342,11 @@
}
void GrGLSpecularLightingEffect::setData(const GrGLUniformManager& uman,
- const GrDrawEffect& drawEffect) {
- INHERITED::setData(uman, drawEffect);
- const GrSpecularLightingEffect& spec = drawEffect.castEffect<GrSpecularLightingEffect>();
- uman.set1f(fKSUni, spec.ks());
- uman.set1f(fShininessUni, spec.shininess());
+ const GrEffectStage& stage) {
+ INHERITED::setData(uman, stage);
+ const GrSpecularLightingEffect& effect = GetEffectFromStage<GrSpecularLightingEffect>(stage);
+ uman.set1f(fKSUni, effect.ks());
+ uman.set1f(fShininessUni, effect.shininess());
}
///////////////////////////////////////////////////////////////////////////////
@@ -1362,7 +1360,8 @@
builder->fsCodeAppend(builder->getUniformCStr(this->lightColorUni()));
}
-void GrGLLight::setData(const GrGLUniformManager& uman, const SkLight* light) const {
+void GrGLLight::setData(const GrGLUniformManager& uman,
+ const SkLight* light) const {
setUniformPoint3(uman, fColorUni, light->color() * SkScalarInvert(SkIntToScalar(255)));
}
@@ -1384,7 +1383,8 @@
///////////////////////////////////////////////////////////////////////////////
-void GrGLPointLight::setData(const GrGLUniformManager& uman, const SkLight* light) const {
+void GrGLPointLight::setData(const GrGLUniformManager& uman,
+ const SkLight* light) const {
INHERITED::setData(uman, light);
SkASSERT(light->type() == SkLight::kPoint_LightType);
const SkPointLight* pointLight = static_cast<const SkPointLight*>(light);
@@ -1400,7 +1400,8 @@
///////////////////////////////////////////////////////////////////////////////
-void GrGLSpotLight::setData(const GrGLUniformManager& uman, const SkLight* light) const {
+void GrGLSpotLight::setData(const GrGLUniformManager& uman,
+ const SkLight* light) const {
INHERITED::setData(uman, light);
SkASSERT(light->type() == SkLight::kSpot_LightType);
const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light);
diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp
index 0c4cde1..215ebc0 100644
--- a/src/effects/SkMagnifierImageFilter.cpp
+++ b/src/effects/SkMagnifierImageFilter.cpp
@@ -92,20 +92,22 @@
class GrGLMagnifierEffect : public GrGLEffect {
public:
- GrGLMagnifierEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
+ GrGLMagnifierEffect(const GrBackendEffectFactory& factory, const GrEffectRef& effect);
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& uman, const GrEffectStage& stage) SK_OVERRIDE;
- static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
+ static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
private:
+
UniformHandle fOffsetVar;
UniformHandle fZoomVar;
UniformHandle fInsetVar;
@@ -115,23 +117,22 @@
typedef GrGLEffect INHERITED;
};
-GrGLMagnifierEffect::GrGLMagnifierEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
+GrGLMagnifierEffect::GrGLMagnifierEffect(const GrBackendEffectFactory& factory, const GrEffectRef&)
: INHERITED(factory)
, fOffsetVar(GrGLUniformManager::kInvalidUniformHandle)
, fZoomVar(GrGLUniformManager::kInvalidUniformHandle)
- , fInsetVar(GrGLUniformManager::kInvalidUniformHandle)
- , fEffectMatrix(drawEffect.castEffect<GrMagnifierEffect>().coordsType()) {
+ , fInsetVar(GrGLUniformManager::kInvalidUniformHandle) {
}
void GrGLMagnifierEffect::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);
fOffsetVar = builder->addUniform(
GrGLShaderBuilder::kFragment_ShaderType |
GrGLShaderBuilder::kVertex_ShaderType,
@@ -178,20 +179,18 @@
}
void GrGLMagnifierEffect::setData(const GrGLUniformManager& uman,
- const GrDrawEffect& drawEffect) {
- const GrMagnifierEffect& zoom = drawEffect.castEffect<GrMagnifierEffect>();
+ const GrEffectStage& stage) {
+ const GrMagnifierEffect& zoom = GetEffectFromStage<GrMagnifierEffect>(stage);
uman.set2f(fOffsetVar, zoom.x_offset(), zoom.y_offset());
uman.set2f(fZoomVar, zoom.x_zoom(), zoom.y_zoom());
uman.set2f(fInsetVar, zoom.x_inset(), zoom.y_inset());
- fEffectMatrix.setData(uman, zoom.getMatrix(), drawEffect, zoom.texture(0));
+ fEffectMatrix.setData(uman, zoom.getMatrix(), stage.getCoordChangeMatrix(), zoom.texture(0));
}
-GrGLEffect::EffectKey GrGLMagnifierEffect::GenKey(const GrDrawEffect& drawEffect,
- const GrGLCaps&) {
- const GrMagnifierEffect& zoom = drawEffect.castEffect<GrMagnifierEffect>();
+GrGLEffect::EffectKey GrGLMagnifierEffect::GenKey(const GrEffectStage& stage, const GrGLCaps&) {
+ const GrMagnifierEffect& zoom = GetEffectFromStage<GrMagnifierEffect>(stage);
return GrGLEffectMatrix::GenKey(zoom.getMatrix(),
- drawEffect,
- zoom.coordsType(),
+ stage.getCoordChangeMatrix(),
zoom.texture(0));
}
diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp
index c4cffea..cda4f28 100644
--- a/src/effects/SkMatrixConvolutionImageFilter.cpp
+++ b/src/effects/SkMatrixConvolutionImageFilter.cpp
@@ -284,6 +284,8 @@
typedef GrGLMatrixConvolutionEffect GLEffect;
+
+
virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE;
private:
@@ -314,17 +316,18 @@
class GrGLMatrixConvolutionEffect : public GrGLEffect {
public:
GrGLMatrixConvolutionEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& effect);
+ const GrEffectRef& effect);
virtual void emitCode(GrGLShaderBuilder*,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
- static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
+ static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
- virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
+ virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
private:
typedef GrGLUniformManager::UniformHandle UniformHandle;
@@ -345,15 +348,14 @@
};
GrGLMatrixConvolutionEffect::GrGLMatrixConvolutionEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
+ const GrEffectRef& effect)
: INHERITED(factory)
, fKernelUni(GrGLUniformManager::kInvalidUniformHandle)
, fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle)
, fTargetUni(GrGLUniformManager::kInvalidUniformHandle)
, fGainUni(GrGLUniformManager::kInvalidUniformHandle)
- , fBiasUni(GrGLUniformManager::kInvalidUniformHandle)
- , fEffectMatrix(drawEffect.castEffect<GrMatrixConvolutionEffect>().coordsType()) {
- const GrMatrixConvolutionEffect& m = drawEffect.castEffect<GrMatrixConvolutionEffect>();
+ , fBiasUni(GrGLUniformManager::kInvalidUniformHandle) {
+ const GrMatrixConvolutionEffect& m = CastEffect<GrMatrixConvolutionEffect>(effect);
fKernelSize = m.kernelSize();
fTileMode = m.tileMode();
fConvolveAlpha = m.convolveAlpha();
@@ -381,13 +383,14 @@
}
void GrGLMatrixConvolutionEffect::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,
@@ -447,40 +450,38 @@
};
-GrGLEffect::EffectKey GrGLMatrixConvolutionEffect::GenKey(const GrDrawEffect& drawEffect,
- const GrGLCaps&) {
- const GrMatrixConvolutionEffect& m = drawEffect.castEffect<GrMatrixConvolutionEffect>();
+GrGLEffect::EffectKey GrGLMatrixConvolutionEffect::GenKey(const GrEffectStage& s, const GrGLCaps&) {
+ const GrMatrixConvolutionEffect& m = GetEffectFromStage<GrMatrixConvolutionEffect>(s);
EffectKey key = encodeXY(m.kernelSize().width(), m.kernelSize().height());
key |= m.tileMode() << 7;
key |= m.convolveAlpha() ? 1 << 9 : 0;
key <<= GrGLEffectMatrix::kKeyBits;
EffectKey matrixKey = GrGLEffectMatrix::GenKey(m.getMatrix(),
- drawEffect,
- m.coordsType(),
+ s.getCoordChangeMatrix(),
m.texture(0));
return key | matrixKey;
}
void GrGLMatrixConvolutionEffect::setData(const GrGLUniformManager& uman,
- const GrDrawEffect& drawEffect) {
- const GrMatrixConvolutionEffect& conv = drawEffect.castEffect<GrMatrixConvolutionEffect>();
- GrTexture& texture = *conv.texture(0);
+ const GrEffectStage& stage) {
+ const GrMatrixConvolutionEffect& effect = GetEffectFromStage<GrMatrixConvolutionEffect>(stage);
+ GrTexture& texture = *effect.texture(0);
// the code we generated was for a specific kernel size
- GrAssert(conv.kernelSize() == fKernelSize);
- GrAssert(conv.tileMode() == fTileMode);
+ GrAssert(effect.kernelSize() == fKernelSize);
+ GrAssert(effect.tileMode() == fTileMode);
float imageIncrement[2];
float ySign = texture.origin() == kTopLeft_GrSurfaceOrigin ? 1.0f : -1.0f;
imageIncrement[0] = 1.0f / texture.width();
imageIncrement[1] = ySign / texture.height();
uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
- uman.set2fv(fTargetUni, 0, 1, conv.target());
- uman.set1fv(fKernelUni, 0, fKernelSize.width() * fKernelSize.height(), conv.kernel());
- uman.set1f(fGainUni, conv.gain());
- uman.set1f(fBiasUni, conv.bias());
+ uman.set2fv(fTargetUni, 0, 1, effect.target());
+ uman.set1fv(fKernelUni, 0, fKernelSize.width() * fKernelSize.height(), effect.kernel());
+ uman.set1f(fGainUni, effect.gain());
+ uman.set1f(fBiasUni, effect.bias());
fEffectMatrix.setData(uman,
- conv.getMatrix(),
- drawEffect,
- conv.texture(0));
+ effect.getMatrix(),
+ stage.getCoordChangeMatrix(),
+ effect.texture(0));
}
GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(GrTexture* texture,
diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp
index f2b37f2..bca18e6 100644
--- a/src/effects/SkMorphologyImageFilter.cpp
+++ b/src/effects/SkMorphologyImageFilter.cpp
@@ -278,18 +278,19 @@
class GrGLMorphologyEffect : public GrGLEffect {
public:
- GrGLMorphologyEffect (const GrBackendEffectFactory&, const GrDrawEffect&);
+ GrGLMorphologyEffect (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;
- static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
+ static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
- virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
+ virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
private:
int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); }
@@ -303,23 +304,23 @@
};
GrGLMorphologyEffect::GrGLMorphologyEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
+ const GrEffectRef& effect)
: INHERITED(factory)
- , fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle)
- , fEffectMatrix(drawEffect.castEffect<GrMorphologyEffect>().coordsType()) {
- const GrMorphologyEffect& m = drawEffect.castEffect<GrMorphologyEffect>();
+ , fImageIncrementUni(GrGLUniformManager::kInvalidUniformHandle) {
+ const GrMorphologyEffect& m = CastEffect<GrMorphologyEffect>(effect);
fRadius = m.radius();
fType = m.type();
}
void GrGLMorphologyEffect::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");
@@ -352,22 +353,19 @@
builder->fsCodeAppend(modulate.c_str());
}
-GrGLEffect::EffectKey GrGLMorphologyEffect::GenKey(const GrDrawEffect& drawEffect,
- const GrGLCaps&) {
- const GrMorphologyEffect& m = drawEffect.castEffect<GrMorphologyEffect>();
+GrGLEffect::EffectKey GrGLMorphologyEffect::GenKey(const GrEffectStage& s, const GrGLCaps&) {
+ const GrMorphologyEffect& m = GetEffectFromStage<GrMorphologyEffect>(s);
EffectKey key = static_cast<EffectKey>(m.radius());
key |= (m.type() << 8);
key <<= GrGLEffectMatrix::kKeyBits;
EffectKey matrixKey = GrGLEffectMatrix::GenKey(m.getMatrix(),
- drawEffect,
- m.coordsType(),
+ s.getCoordChangeMatrix(),
m.texture(0));
return key | matrixKey;
}
-void GrGLMorphologyEffect::setData(const GrGLUniformManager& uman,
- const GrDrawEffect& drawEffect) {
- const Gr1DKernelEffect& kern = drawEffect.castEffect<Gr1DKernelEffect>();
+void GrGLMorphologyEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
+ const Gr1DKernelEffect& kern = GetEffectFromStage<Gr1DKernelEffect>(stage);
GrTexture& texture = *kern.texture(0);
// the code we generated was for a specific kernel radius
GrAssert(kern.radius() == fRadius);
@@ -383,7 +381,7 @@
GrCrash("Unknown filter direction.");
}
uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
- fEffectMatrix.setData(uman, kern.getMatrix(), drawEffect, kern.texture(0));
+ fEffectMatrix.setData(uman, kern.getMatrix(), stage.getCoordChangeMatrix(), kern.texture(0));
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp
index e0c4978..16f2876 100644
--- a/src/effects/SkTableColorFilter.cpp
+++ b/src/effects/SkTableColorFilter.cpp
@@ -256,31 +256,33 @@
class GLColorTableEffect : public GrGLEffect {
public:
- GLColorTableEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
+ GLColorTableEffect(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 EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
+ static EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
private:
typedef GrGLEffect INHERITED;
};
-GLColorTableEffect::GLColorTableEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
+GLColorTableEffect::GLColorTableEffect(const GrBackendEffectFactory& factory, const GrEffectRef&)
: INHERITED(factory) {
}
void GLColorTableEffect::emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
@@ -321,7 +323,7 @@
builder->fsCodeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor);
}
-GrGLEffect::EffectKey GLColorTableEffect::GenKey(const GrDrawEffect&, const GrGLCaps&) {
+GrGLEffect::EffectKey GLColorTableEffect::GenKey(const GrEffectStage&, const GrGLCaps&) {
return 0;
}
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp
index d3b2fd4..1158dcf 100644
--- a/src/effects/gradients/SkGradientShader.cpp
+++ b/src/effects/gradients/SkGradientShader.cpp
@@ -734,14 +734,12 @@
#if SK_SUPPORT_GPU
#include "effects/GrTextureStripAtlas.h"
-#include "GrTBackendEffectFactory.h"
#include "SkGr.h"
GrGLGradientEffect::GrGLGradientEffect(const GrBackendEffectFactory& factory)
: INHERITED(factory)
, fCachedYCoord(SK_ScalarMax)
- , fFSYUni(GrGLUniformManager::kInvalidUniformHandle)
- , fEffectMatrix(kCoordsType) {
+ , fFSYUni(GrGLUniformManager::kInvalidUniformHandle) {
}
GrGLGradientEffect::~GrGLGradientEffect() { }
@@ -751,11 +749,10 @@
kFloat_GrSLType, "GradientYCoordFS");
}
-void GrGLGradientEffect::setData(const GrGLUniformManager& uman,
- const GrDrawEffect& drawEffect) {
- const GrGradientEffect& e = drawEffect.castEffect<GrGradientEffect>();
+void GrGLGradientEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
+ const GrGradientEffect& e = GetEffectFromStage<GrGradientEffect>(stage);
const GrTexture* texture = e.texture(0);
- fEffectMatrix.setData(uman, e.getMatrix(), drawEffect, texture);
+ fEffectMatrix.setData(uman, e.getMatrix(), stage.getCoordChangeMatrix(), texture);
SkScalar yCoord = e.getYCoord();
if (yCoord != fCachedYCoord) {
@@ -764,19 +761,21 @@
}
}
-GrGLEffect::EffectKey GrGLGradientEffect::GenMatrixKey(const GrDrawEffect& drawEffect) {
- const GrGradientEffect& e = drawEffect.castEffect<GrGradientEffect>();
+GrGLEffect::EffectKey GrGLGradientEffect::GenMatrixKey(const GrEffectStage& s) {
+ const GrGradientEffect& e = GetEffectFromStage<GrGradientEffect>(s);
const GrTexture* texture = e.texture(0);
- return GrGLEffectMatrix::GenKey(e.getMatrix(), drawEffect, kCoordsType, texture);
+ return GrGLEffectMatrix::GenKey(e.getMatrix(), s.getCoordChangeMatrix(), texture);
}
void GrGLGradientEffect::setupMatrix(GrGLShaderBuilder* builder,
EffectKey key,
+ const char* vertexCoords,
const char** fsCoordName,
const char** vsVaryingName,
GrSLType* vsVaryingType) {
fEffectMatrix.emitCodeMakeFSCoords2D(builder,
key & kMatrixKeyMask,
+ vertexCoords,
fsCoordName,
vsVaryingName,
vsVaryingType);
diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h
index b9dbf1b..271a2b6 100644
--- a/src/effects/gradients/SkGradientShaderPriv.h
+++ b/src/effects/gradients/SkGradientShaderPriv.h
@@ -274,7 +274,7 @@
GrGLGradientEffect(const GrBackendEffectFactory& factory);
virtual ~GrGLGradientEffect();
- virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
+ virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
protected:
/**
@@ -290,7 +290,7 @@
* Subclasses must call this. It will return a value restricted to the lower kMatrixKeyBitCnt
* bits.
*/
- static EffectKey GenMatrixKey(const GrDrawEffect&);
+ static EffectKey GenMatrixKey(const GrEffectStage& s);
/**
* Inserts code to implement the GrGradientEffect's matrix. This should be called before a
@@ -302,6 +302,7 @@
*/
void setupMatrix(GrGLShaderBuilder* builder,
EffectKey key,
+ const char* vertexCoords,
const char** fsCoordName,
const char** vsVaryingName = NULL,
GrSLType* vsVaryingType = NULL);
@@ -320,8 +321,6 @@
const GrGLShaderBuilder::TextureSampler&);
private:
- static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType;
-
SkScalar fCachedYCoord;
GrGLUniformManager::UniformHandle fFSYUni;
GrGLEffectMatrix fEffectMatrix;
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp
index 76168a9..3f8d7cc 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -453,20 +453,21 @@
class GrGLLinearGradient : public GrGLGradientEffect {
public:
- GrGLLinearGradient(const GrBackendEffectFactory& factory, const GrDrawEffect&)
+ GrGLLinearGradient(const GrBackendEffectFactory& factory, const GrEffectRef&)
: INHERITED (factory) { }
virtual ~GrGLLinearGradient() { }
virtual void emitCode(GrGLShaderBuilder*,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
- static EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
- return GenMatrixKey(drawEffect);
+ static EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) {
+ return GenMatrixKey(stage);
}
private:
@@ -532,14 +533,15 @@
/////////////////////////////////////////////////////////////////////
void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect&,
+ const GrEffectStage& stage,
EffectKey key,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
const char* coords;
- this->setupMatrix(builder, key, &coords);
+ this->setupMatrix(builder, key, vertexCoords, &coords);
SkString t;
t.append(coords);
t.append(".x");
diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp
index a80cb81..3f670ad 100644
--- a/src/effects/gradients/SkRadialGradient.cpp
+++ b/src/effects/gradients/SkRadialGradient.cpp
@@ -474,18 +474,19 @@
public:
GrGLRadialGradient(const GrBackendEffectFactory& factory,
- const GrDrawEffect&) : INHERITED (factory) { }
+ const GrEffectRef&) : INHERITED (factory) { }
virtual ~GrGLRadialGradient() { }
virtual void emitCode(GrGLShaderBuilder*,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
- static EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
- return GenMatrixKey(drawEffect);
+ static EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) {
+ return GenMatrixKey(stage);
}
private:
@@ -553,14 +554,15 @@
/////////////////////////////////////////////////////////////////////
void GrGLRadialGradient::emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey key,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
const char* coords;
- this->setupMatrix(builder, key, &coords);
+ this->setupMatrix(builder, key, vertexCoords, &coords);
SkString t("length(");
t.append(coords);
t.append(")");
diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index 9d24d40..44b03d6 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -391,18 +391,19 @@
public:
GrGLSweepGradient(const GrBackendEffectFactory& factory,
- const GrDrawEffect&) : INHERITED (factory) { }
+ const GrEffectRef&) : INHERITED (factory) { }
virtual ~GrGLSweepGradient() { }
virtual void emitCode(GrGLShaderBuilder*,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
- static EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
- return GenMatrixKey(drawEffect);
+ static EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) {
+ return GenMatrixKey(stage);
}
private:
@@ -463,14 +464,15 @@
/////////////////////////////////////////////////////////////////////
void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey key,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
const char* coords;
- this->setupMatrix(builder, key, &coords);
+ this->setupMatrix(builder, key, vertexCoords, &coords);
SkString t;
t.printf("atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5", coords, coords);
this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplers[0]);
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp
index 0b6e30d..04cf1eb 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient.cpp
+++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp
@@ -343,18 +343,20 @@
class GrGLConical2Gradient : public GrGLGradientEffect {
public:
- GrGLConical2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffect&);
+ GrGLConical2Gradient(const GrBackendEffectFactory& factory,
+ const GrEffectRef&);
virtual ~GrGLConical2Gradient() { }
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 EffectKey GenKey(const GrDrawEffect&, const GrGLCaps& caps);
+ static EffectKey GenKey(const GrEffectStage&, const GrGLCaps& caps);
protected:
@@ -474,7 +476,7 @@
/////////////////////////////////////////////////////////////////////
GrGLConical2Gradient::GrGLConical2Gradient(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
+ const GrEffectRef& baseData)
: INHERITED(factory)
, fVSParamUni(kInvalidUniformHandle)
, fFSParamUni(kInvalidUniformHandle)
@@ -484,20 +486,21 @@
, fCachedRadius(-SK_ScalarMax)
, fCachedDiffRadius(-SK_ScalarMax) {
- const GrConical2Gradient& data = drawEffect.castEffect<GrConical2Gradient>();
+ const GrConical2Gradient& data = CastEffect<GrConical2Gradient>(baseData);
fIsDegenerate = data.isDegenerate();
}
void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect&,
+ const GrEffectStage&,
EffectKey key,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
const char* fsCoords;
const char* vsCoordsVarying;
GrSLType coordsVaryingType;
- this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingType);
+ this->setupMatrix(builder, key, vertexCoords, &fsCoords, &vsCoordsVarying, &coordsVaryingType);
this->emitYCoordUniform(builder);
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
@@ -655,10 +658,9 @@
}
}
-void GrGLConical2Gradient::setData(const GrGLUniformManager& uman,
- const GrDrawEffect& drawEffect) {
- INHERITED::setData(uman, drawEffect);
- const GrConical2Gradient& data = drawEffect.castEffect<GrConical2Gradient>();
+void GrGLConical2Gradient::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
+ INHERITED::setData(uman, stage);
+ const GrConical2Gradient& data = GetEffectFromStage<GrConical2Gradient>(stage);
GrAssert(data.isDegenerate() == fIsDegenerate);
SkScalar centerX1 = data.center();
SkScalar radius0 = data.radius();
@@ -692,14 +694,13 @@
}
}
-GrGLEffect::EffectKey GrGLConical2Gradient::GenKey(const GrDrawEffect& drawEffect,
- const GrGLCaps&) {
+GrGLEffect::EffectKey GrGLConical2Gradient::GenKey(const GrEffectStage& s, const GrGLCaps&) {
enum {
kIsDegenerate = 1 << kMatrixKeyBitCnt,
};
- EffectKey key = GenMatrixKey(drawEffect);
- if (drawEffect.castEffect<GrConical2Gradient>().isDegenerate()) {
+ EffectKey key = GenMatrixKey(s);
+ if (GetEffectFromStage<GrConical2Gradient>(s).isDegenerate()) {
key |= kIsDegenerate;
}
return key;
diff --git a/src/effects/gradients/SkTwoPointRadialGradient.cpp b/src/effects/gradients/SkTwoPointRadialGradient.cpp
index 6784818..0bf308b 100644
--- a/src/effects/gradients/SkTwoPointRadialGradient.cpp
+++ b/src/effects/gradients/SkTwoPointRadialGradient.cpp
@@ -384,18 +384,19 @@
public:
- GrGLRadial2Gradient(const GrBackendEffectFactory& factory, const GrDrawEffect&);
+ GrGLRadial2Gradient(const GrBackendEffectFactory& factory, const GrEffectRef&);
virtual ~GrGLRadial2Gradient() { }
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 EffectKey GenKey(const GrDrawEffect&, const GrGLCaps& caps);
+ static EffectKey GenKey(const GrEffectStage&, const GrGLCaps& caps);
protected:
@@ -515,7 +516,7 @@
/////////////////////////////////////////////////////////////////////
GrGLRadial2Gradient::GrGLRadial2Gradient(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
+ const GrEffectRef& baseData)
: INHERITED(factory)
, fVSParamUni(kInvalidUniformHandle)
, fFSParamUni(kInvalidUniformHandle)
@@ -525,13 +526,14 @@
, fCachedRadius(-SK_ScalarMax)
, fCachedPosRoot(0) {
- const GrRadial2Gradient& data = drawEffect.castEffect<GrRadial2Gradient>();
+ const GrRadial2Gradient& data = CastEffect<GrRadial2Gradient>(baseData);
fIsDegenerate = data.isDegenerate();
}
void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect& drawEffect,
+ const GrEffectStage&,
EffectKey key,
+ const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
@@ -540,7 +542,7 @@
const char* fsCoords;
const char* vsCoordsVarying;
GrSLType coordsVaryingType;
- this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingType);
+ this->setupMatrix(builder, key, vertexCoords, &fsCoords, &vsCoordsVarying, &coordsVaryingType);
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
// to work around Xoom bug. Doesn't seem to cause performance decrease
@@ -637,10 +639,9 @@
}
}
-void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman,
- const GrDrawEffect& drawEffect) {
- INHERITED::setData(uman, drawEffect);
- const GrRadial2Gradient& data = drawEffect.castEffect<GrRadial2Gradient>();
+void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
+ INHERITED::setData(uman, stage);
+ const GrRadial2Gradient& data = GetEffectFromStage<GrRadial2Gradient>(stage);
GrAssert(data.isDegenerate() == fIsDegenerate);
SkScalar centerX1 = data.center();
SkScalar radius0 = data.radius();
@@ -672,14 +673,13 @@
}
}
-GrGLEffect::EffectKey GrGLRadial2Gradient::GenKey(const GrDrawEffect& drawEffect,
- const GrGLCaps&) {
+GrGLEffect::EffectKey GrGLRadial2Gradient::GenKey(const GrEffectStage& s, const GrGLCaps&) {
enum {
kIsDegenerate = 1 << kMatrixKeyBitCnt,
};
- EffectKey key = GenMatrixKey(drawEffect);
- if (drawEffect.castEffect<GrRadial2Gradient>().isDegenerate()) {
+ EffectKey key = GenMatrixKey(s);
+ if (GetEffectFromStage<GrRadial2Gradient>(s).isDegenerate()) {
key |= kIsDegenerate;
}
return key;
diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp
index 6415859..99068c7 100644
--- a/src/gpu/GrClipMaskManager.cpp
+++ b/src/gpu/GrClipMaskManager.cpp
@@ -40,9 +40,6 @@
static const int kMaskStage = GrPaint::kTotalStages+1;
SkMatrix mat;
- // We want to use device coords to compute the texture coordinates. We set our matrix to be
- // equal to the view matrix followed by an offset to the devBound, and then a scaling matrix to
- // normalized coords. We apply this matrix to the vertex positions rather than local coords.
mat.setIDiv(result->width(), result->height());
mat.preTranslate(SkIntToScalar(-devBound.fLeft),
SkIntToScalar(-devBound.fTop));
@@ -54,9 +51,7 @@
GrTextureDomainEffect::Create(result,
mat,
GrTextureDomainEffect::MakeTexelDomain(result, domainTexels),
- GrTextureDomainEffect::kDecal_WrapMode,
- false,
- GrEffect::kPosition_CoordsType))->unref();
+ GrTextureDomainEffect::kDecal_WrapMode))->unref();
}
bool path_needs_SW_renderer(GrContext* context,
@@ -359,8 +354,7 @@
GrTextureDomainEffect::Create(srcMask,
sampleM,
GrTextureDomainEffect::MakeTexelDomain(srcMask, srcBound),
- GrTextureDomainEffect::kDecal_WrapMode,
- false))->unref();
+ GrTextureDomainEffect::kDecal_WrapMode))->unref();
fGpu->drawSimpleRect(SkRect::MakeFromIRect(dstBound), NULL);
drawState->disableStage(0);
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 4798297..4c18574 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -360,12 +360,12 @@
{kVec2f_GrVertexAttribType, 0},
{kVec2f_GrVertexAttribType, sizeof(GrPoint)}
};
-
- static const GrAttribBindings kAttribBindings = GrDrawState::kLocalCoords_AttribBindingsBit;
+ static const GrAttribBindings kAttribBindings =
+ GrDrawState::ExplicitTexCoordAttribBindingsBit(0);
drawState->setAttribBindings(kAttribBindings);
drawState->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs));
drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
- drawState->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, 1);
+ drawState->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, 1);
GrDrawTarget::AutoReleaseGeometry arg(fGpu, 4, 0);
if (arg.succeeded()) {
@@ -852,15 +852,21 @@
void GrContext::drawRectToRect(const GrPaint& paint,
const GrRect& dstRect,
- const GrRect& localRect,
+ const GrRect& srcRect,
const SkMatrix* dstMatrix,
- const SkMatrix* localMatrix) {
+ const SkMatrix* srcMatrix) {
SK_TRACE_EVENT0("GrContext::drawRectToRect");
+ // srcRect refers to paint's first color stage
+ if (!paint.isColorStageEnabled(0)) {
+ drawRect(paint, dstRect, -1, dstMatrix);
+ return;
+ }
+
GrDrawTarget* target = this->prepareToDraw(&paint, BUFFERED_DRAW);
- GrDrawState::AutoStageDisable atr(fDrawState);
#if GR_STATIC_RECT_VB
+ GrDrawState::AutoStageDisable atr(fDrawState);
GrDrawState* drawState = target->drawState();
SkMatrix m;
@@ -872,21 +878,19 @@
m.postConcat(*dstMatrix);
}
- // This code path plays a little fast and loose with the notion of local coords and coord
- // change matrices in order to account for localRect and localMatrix. The unit square VB only
- // has one set of coords. Rather than using AutoViewMatrixRestore we instead directly set concat
- // with m and then call GrDrawState::localCoordChange() with a matrix that accounts for
- // localRect and localMatrix. This code path is preventing some encapsulation in GrDrawState.
- SkMatrix savedViewMatrix = drawState->getViewMatrix();
- drawState->preConcatViewMatrix(m);
+ // The first color stage's coords come from srcRect rather than applying a matrix to dstRect.
+ // We explicitly compute a matrix for that stage below, no need to adjust here.
+ static const uint32_t kExplicitCoordMask = 1 << GrPaint::kFirstColorStage;
+ GrDrawState::AutoViewMatrixRestore avmr(drawState, m, kExplicitCoordMask);
- m.setAll(localRect.width(), 0, localRect.fLeft,
- 0, localRect.height(), localRect.fTop,
- 0, 0, SkMatrix::I()[8]);
- if (NULL != localMatrix) {
- m.postConcat(*localMatrix);
+ m.setAll(srcRect.width(), 0, srcRect.fLeft,
+ 0, srcRect.height(), srcRect.fTop,
+ 0, 0, SkMatrix::I()[8]);
+ if (NULL != srcMatrix) {
+ m.postConcat(*srcMatrix);
}
- drawState->localCoordChange(m);
+
+ drawState->preConcatStageMatrices(kExplicitCoordMask, m);
const GrVertexBuffer* sqVB = fGpu->getUnitSquareVertexBuffer();
if (NULL == sqVB) {
@@ -896,9 +900,10 @@
drawState->setDefaultVertexAttribs();
target->setVertexSourceToBuffer(sqVB);
target->drawNonIndexed(kTriangleFan_GrPrimitiveType, 0, 4);
- drawState->setViewMatrix(savedViewMatrix);
#else
- target->drawRect(dstRect, dstMatrix, &localRect, localMatrix);
+ GrDrawState::AutoStageDisable atr(fDrawState);
+
+ target->drawRect(dstRect, dstMatrix, &srcRect, srcMatrix, 0);
#endif
}
@@ -932,8 +937,8 @@
// set up optional texture coordinate attributes
if (NULL != texCoords) {
- bindings |= GrDrawState::kLocalCoords_AttribBindingsBit;
- drawState->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, attribs.count());
+ bindings |= GrDrawState::ExplicitTexCoordAttribBindingsBit(0);
+ drawState->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, attribs.count());
currAttrib.set(kVec2f_GrVertexAttribType, currentOffset);
attribs.push_back(currAttrib);
texOffset = currentOffset;
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp
index 7982935..cd5fe1c 100644
--- a/src/gpu/GrDrawState.cpp
+++ b/src/gpu/GrDrawState.cpp
@@ -46,6 +46,28 @@
////////////////////////////////////////////////////////////////////////////////
+namespace {
+
+/**
+ * This function generates a mask that we like to have known at compile
+ * time. When the number of stages is bumped or the way bits are defined in
+ * GrDrawState.h changes this function should be rerun to generate the new mask.
+ * (We attempted to force the compiler to generate the mask using recursive
+ * templates but always wound up with static initializers under gcc, even if
+ * they were just a series of immediate->memory moves.)
+ *
+ */
+void gen_tex_coord_mask(GrAttribBindings* texCoordMask) {
+ *texCoordMask = 0;
+ for (int s = 0; s < GrDrawState::kNumStages; ++s) {
+ *texCoordMask |= GrDrawState::ExplicitTexCoordAttribBindingsBit(s);
+ }
+}
+
+const GrAttribBindings kTexCoord_AttribBindingsMask = (1 << GrDrawState::kNumStages)-1;
+
+} //unnamed namespace
+
const size_t GrDrawState::kVertexAttribSizes[kGrVertexAttribTypeCount] = {
sizeof(float), // kFloat_GrVertexAttribType
2*sizeof(float), // kVec2_GrVertexAttribType
@@ -84,7 +106,7 @@
kColor_AttribBindingsBit,
kCoverage_AttribBindingsBit,
kEdge_AttribBindingsBit,
- kLocalCoords_AttribBindingsBit,
+ kTexCoord_AttribBindingsMask
};
////////////////////////////////////////////////////////////////////////////////
@@ -188,8 +210,20 @@
return true;
}
+////////////////////////////////////////////////////////////////////////////////
+
+bool GrDrawState::AttributesBindExplicitTexCoords(GrAttribBindings attribBindings) {
+ return SkToBool(kTexCoord_AttribBindingsMask & attribBindings);
+}
+
+////////////////////////////////////////////////////////////////////////////////
void GrDrawState::VertexAttributesUnitTest() {
+ // Ensure that our tex coord mask is correct
+ GrAttribBindings texCoordMask;
+ gen_tex_coord_mask(&texCoordMask);
+ GrAssert(texCoordMask == kTexCoord_AttribBindingsMask);
+
// not necessarily exhaustive
static bool run;
if (!run) {
@@ -225,11 +259,27 @@
attribs.push_back(currAttrib);
GrAssert(4*sizeof(char) + 2*sizeof(float) + 3*sizeof(float) + sizeof(float) + 4*sizeof(float) ==
vertex_size(attribs.begin(), attribs.count()));
+
+ GrAttribBindings tcMask = 0;
+ GrAssert(!AttributesBindExplicitTexCoords(0));
+ for (int s = 0; s < GrDrawState::kNumStages; ++s) {
+ tcMask |= ExplicitTexCoordAttribBindingsBit(s);
+ GrAssert(AttributesBindExplicitTexCoords(tcMask));
+ GrAssert(StageBindsExplicitTexCoords(tcMask, s));
+ for (int s2 = s + 1; s2 < GrDrawState::kNumStages; ++s2) {
+ GrAssert(!StageBindsExplicitTexCoords(tcMask, s2));
+ }
+ }
+ GrAssert(kTexCoord_AttribBindingsMask == tcMask);
}
}
////////////////////////////////////////////////////////////////////////////////
+bool GrDrawState::StageBindsExplicitTexCoords(GrAttribBindings bindings, int stageIdx) {
+ return SkToBool(bindings & ExplicitTexCoordAttribBindingsBit(stageIdx));
+}
+
bool GrDrawState::srcAlphaWillBeOne(GrAttribBindings bindings) const {
uint32_t validComponentFlags;
@@ -450,7 +500,8 @@
}
void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState,
- const SkMatrix& preconcatMatrix) {
+ const SkMatrix& preconcatMatrix,
+ uint32_t explicitCoordStageMask) {
this->restore();
fDrawState = drawState;
@@ -462,10 +513,10 @@
fViewMatrix = drawState->getViewMatrix();
drawState->preConcatViewMatrix(preconcatMatrix);
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- if (drawState->isStageEnabled(s)) {
+ if (!(explicitCoordStageMask & (1 << s)) && drawState->isStageEnabled(s)) {
fRestoreMask |= (1 << s);
fDrawState->fStages[s].saveCoordChange(&fSavedCoordChanges[s]);
- drawState->fStages[s].localCoordChange(preconcatMatrix);
+ drawState->fStages[s].preConcatCoordChange(preconcatMatrix);
}
}
}
@@ -484,7 +535,8 @@
fDrawState = NULL;
}
-bool GrDrawState::AutoDeviceCoordDraw::set(GrDrawState* drawState) {
+bool GrDrawState::AutoDeviceCoordDraw::set(GrDrawState* drawState,
+ uint32_t explicitCoordStageMask) {
GrAssert(NULL != drawState);
this->restore();
@@ -500,7 +552,7 @@
bool inverted = false;
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
- if (drawState->isStageEnabled(s)) {
+ if (!(explicitCoordStageMask & (1 << s)) && drawState->isStageEnabled(s)) {
if (!inverted && !fViewMatrix.invert(&invVM)) {
// sad trombone sound
fDrawState = NULL;
@@ -511,7 +563,7 @@
fRestoreMask |= (1 << s);
GrEffectStage* stage = drawState->fStages + s;
stage->saveCoordChange(&fSavedCoordChanges[s]);
- stage->localCoordChange(invVM);
+ stage->preConcatCoordChange(invVM);
}
}
drawState->viewMatrix()->reset();
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index ffa7b09..2203e88 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -257,26 +257,38 @@
/**
* The vertex data used by the current program is represented as a bitfield
* of flags. Programs always use positions and may also use texture
- * coordinates, per-vertex colors, per-vertex coverage and edge data. The
- * local coords accessible by effects may either come from positions or
- * be specified explicitly.
+ * coordinates, per-vertex colors, per-vertex coverage and edge data. Each
+ * stage can use the explicit texture coordinates as its input texture
+ * coordinates or it may use the positions as texture coordinates.
*/
/**
+ * Generates a bit indicating that a texture stage uses texture coordinates
+ *
+ * @param stageIdx the stage that will use texture coordinates.
+ *
+ * @return the bit to add to a GrAttribBindings bitfield.
+ */
+ static int ExplicitTexCoordAttribBindingsBit(int stageIdx) {
+ GrAssert(stageIdx < kNumStages);
+ return (1 << stageIdx);
+ }
+
+ static bool StageBindsExplicitTexCoords(GrAttribBindings bindings, int stageIdx);
+
+ /**
* Additional Bits that can be specified in GrAttribBindings.
*/
enum AttribBindingsBits {
- /** explicit local coords are provided (instead of using pre-view-matrix positions) */
- kLocalCoords_AttribBindingsBit = 0x1,
/* program uses colors (GrColor) */
- kColor_AttribBindingsBit = 0x2,
+ kColor_AttribBindingsBit = 1 << (kNumStages + 0),
/* program uses coverage (GrColor)
*/
- kCoverage_AttribBindingsBit = 0x4,
+ kCoverage_AttribBindingsBit = 1 << (kNumStages + 1),
/* program uses edge data. Distance to the edge is used to
* compute a coverage. See GrDrawState::setVertexEdgeType().
*/
- kEdge_AttribBindingsBit = 0x8,
+ kEdge_AttribBindingsBit = 1 << (kNumStages + 2),
// for below assert
kDummyAttribBindingsBit,
kHighAttribBindingsBit = kDummyAttribBindingsBit - 1
@@ -301,6 +313,17 @@
// Helpers for picking apart attribute bindings
/**
+ * Helper function to determine if program uses explicit texture
+ * coordinates.
+ *
+ * @param bindings attribute bindings to query
+ *
+ * @return true if program uses texture coordinates,
+ * false otherwise.
+ */
+ static bool AttributesBindExplicitTexCoords(GrAttribBindings bindings);
+
+ /**
* Determines whether src alpha is guaranteed to be one for all src pixels
*/
bool srcAlphaWillBeOne(GrAttribBindings) const;
@@ -333,9 +356,9 @@
kColor_AttribIndex,
kCoverage_AttribIndex,
kEdge_AttribIndex,
- kLocalCoords_AttribIndex,
+ kTexCoord_AttribIndex,
- kLast_AttribIndex = kLocalCoords_AttribIndex
+ kLast_AttribIndex = kTexCoord_AttribIndex
};
static const int kAttribIndexCount = kLast_AttribIndex + 1;
@@ -387,7 +410,7 @@
/**
* Add a color filter that can be represented by a color and a mode. Applied
- * after color-computing effect stages.
+ * after color-computing texture stages.
*/
void setColorFilter(GrColor c, SkXfermode::Mode mode) {
fCommon.fColorFilterColor = c;
@@ -474,7 +497,7 @@
}
/**
- * Creates a GrSimpleTextureEffect that uses local coords as texture coordinates.
+ * Creates a GrSimpleTextureEffect.
*/
void createTextureEffect(int stageIdx, GrTexture* texture, const SkMatrix& matrix) {
GrAssert(!this->getStage(stageIdx).getEffect());
@@ -533,18 +556,44 @@
}
/**
- * Called when the source coord system is changing. This ensures that effects will see the
- * correct local coordinates. oldToNew gives the transformation from the old coord system in
- * which the geometry was specified to the new coordinate system from which it will be rendered.
+ * Called when the source coord system is changing. preConcat gives the transformation from the
+ * old coord system to the new coord system.
*/
- void localCoordChange(const SkMatrix& oldToNew) {
+ void preConcatStageMatrices(const SkMatrix& preConcat) {
+ this->preConcatStageMatrices(~0U, preConcat);
+ }
+ /**
+ * Version of above that applies the update matrix selectively to stages via a mask.
+ */
+ void preConcatStageMatrices(uint32_t stageMask, const SkMatrix& preConcat) {
for (int i = 0; i < kNumStages; ++i) {
- if (this->isStageEnabled(i)) {
- fStages[i].localCoordChange(oldToNew);
+ if (((1 << i) & stageMask) && this->isStageEnabled(i)) {
+ fStages[i].preConcatCoordChange(preConcat);
}
}
}
+ /**
+ * Called when the source coord system is changing. preConcatInverse is the inverse of the
+ * transformation from the old coord system to the new coord system. Returns false if the matrix
+ * cannot be inverted.
+ */
+ bool preConcatStageMatricesWithInverse(const SkMatrix& preConcatInverse) {
+ SkMatrix inv;
+ bool computed = false;
+ for (int i = 0; i < kNumStages; ++i) {
+ if (this->isStageEnabled(i)) {
+ if (!computed && !preConcatInverse.invert(&inv)) {
+ return false;
+ } else {
+ computed = true;
+ }
+ fStages[i].preConcatCoordChange(preConcatInverse);
+ }
+ }
+ return true;
+ }
+
/// @}
///////////////////////////////////////////////////////////////////////////
@@ -783,9 +832,11 @@
public:
AutoViewMatrixRestore() : fDrawState(NULL) {}
- AutoViewMatrixRestore(GrDrawState* ds, const SkMatrix& preconcatMatrix) {
+ AutoViewMatrixRestore(GrDrawState* ds,
+ const SkMatrix& preconcatMatrix,
+ uint32_t explicitCoordStageMask = 0) {
fDrawState = NULL;
- this->set(ds, preconcatMatrix);
+ this->set(ds, preconcatMatrix, explicitCoordStageMask);
}
~AutoViewMatrixRestore() { this->restore(); }
@@ -795,7 +846,9 @@
*/
void restore();
- void set(GrDrawState* drawState, const SkMatrix& preconcatMatrix);
+ void set(GrDrawState* drawState,
+ const SkMatrix& preconcatMatrix,
+ uint32_t explicitCoordStageMask = 0);
bool isSet() const { return NULL != fDrawState; }
@@ -822,14 +875,15 @@
* positions, then we don't want to modify its matrix. The explicitCoordStageMask is used
* to specify such stages.
*/
- AutoDeviceCoordDraw(GrDrawState* drawState) {
+ AutoDeviceCoordDraw(GrDrawState* drawState,
+ uint32_t explicitCoordStageMask = 0) {
fDrawState = NULL;
- this->set(drawState);
+ this->set(drawState, explicitCoordStageMask);
}
~AutoDeviceCoordDraw() { this->restore(); }
- bool set(GrDrawState* drawState);
+ bool set(GrDrawState* drawState, uint32_t explicitCoordStageMask = 0);
/**
* Returns true if this object was successfully initialized on to a GrDrawState. It may
@@ -1143,7 +1197,8 @@
return false;
}
for (int i = 0; i < kAttribIndexCount; ++i) {
- if ((i == kPosition_AttribIndex || s.fCommon.fAttribBindings & (1 << i)) &&
+ if ((i == kPosition_AttribIndex ||
+ s.fCommon.fAttribBindings & kAttribIndexMasks[i]) &&
fAttribIndices[i] != s.fAttribIndices[i]) {
return false;
}
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index cd4d4d2..6fdc3a0 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -529,9 +529,11 @@
void GrDrawTarget::drawRect(const GrRect& rect,
const SkMatrix* matrix,
- const GrRect* localRect,
- const SkMatrix* localMatrix) {
+ const GrRect* srcRect,
+ const SkMatrix* srcMatrix,
+ int stage) {
GrAttribBindings bindings = 0;
+ uint32_t explicitCoordMask = 0;
// position + (optional) texture coord
static const GrVertexAttrib kAttribs[] = {
{kVec2f_GrVertexAttribType, 0},
@@ -539,15 +541,16 @@
};
int attribCount = 1;
- if (NULL != localRect) {
- bindings |= GrDrawState::kLocalCoords_AttribBindingsBit;
+ if (NULL != srcRect) {
+ bindings |= GrDrawState::ExplicitTexCoordAttribBindingsBit(stage);
attribCount = 2;
- this->drawState()->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, 1);
+ this->drawState()->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, 1);
+ explicitCoordMask = (1 << stage);
}
GrDrawState::AutoViewMatrixRestore avmr;
if (NULL != matrix) {
- avmr.set(this->drawState(), *matrix);
+ avmr.set(this->drawState(), *matrix, explicitCoordMask);
}
this->drawState()->setVertexAttribs(kAttribs, attribCount);
@@ -561,15 +564,15 @@
size_t vsize = this->drawState()->getVertexSize();
geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize);
- if (NULL != localRect) {
+ if (NULL != srcRect) {
GrAssert(attribCount == 2);
GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) +
kAttribs[1].fOffset);
- coords->setRectFan(localRect->fLeft, localRect->fTop,
- localRect->fRight, localRect->fBottom,
- vsize);
- if (NULL != localMatrix) {
- localMatrix->mapPointsWithStride(coords, vsize, 4);
+ coords->setRectFan(srcRect->fLeft, srcRect->fTop,
+ srcRect->fRight, srcRect->fBottom,
+ vsize);
+ if (NULL != srcMatrix) {
+ srcMatrix->mapPointsWithStride(coords, vsize, 4);
}
}
diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h
index de8c5c4..a011aae 100644
--- a/src/gpu/GrDrawTarget.h
+++ b/src/gpu/GrDrawTarget.h
@@ -388,8 +388,8 @@
/**
* Helper function for drawing rects. This does not use the current index
* and vertex sources. After returning, the vertex and index sources may
- * have changed. They should be reestablished before the next draw call.
- * This cannot be called between reserving and releasing
+ * have changed. They should be reestablished before the next drawIndexed
+ * or drawNonIndexed. This cannot be called between reserving and releasing
* geometry.
*
* A subclass may override this to perform more optimal rect rendering. Its
@@ -397,29 +397,34 @@
* (e.g. drawNonIndexed, drawIndexedInstances, ...). The base class draws a two
* triangle fan using drawNonIndexed from reserved vertex space.
*
- * @param rect the rect to draw
- * @param matrix optional matrix applied to rect (before viewMatrix)
- * @param localRect optional rect that specifies local coords to map onto
- * rect. If NULL then rect serves as the local coords.
- * @param localMatrix optional matrix applied to localRect. If
+ * @param rect the rect to draw
+ * @param matrix optional matrix applied to rect (before viewMatrix)
+ * @param srcRects specifies rect for explicit texture coordinates.
+ * if srcRect is non-NULL then that rect will be used
+ * as the coordinates for the given stage.
+ * @param srcMatrix optional matrix applied to srcRect. If
* srcRect is non-NULL and srcMatrix is non-NULL
* then srcRect will be transformed by srcMatrix.
* srcMatrix can be NULL when no srcMatrix is desired.
+ * @param stage the stage to be given explicit texture coordinates.
+ * Ignored if srcRect is NULL.
*/
virtual void drawRect(const GrRect& rect,
const SkMatrix* matrix,
- const GrRect* localRect,
- const SkMatrix* localMatrix);
+ const GrRect* srcRect,
+ const SkMatrix* srcMatrix,
+ int stage);
/**
- * Helper for drawRect when the caller doesn't need separate local rects or matrices.
+ * Helper for drawRect when the caller doesn't need separate src rects or
+ * matrices.
*/
void drawSimpleRect(const GrRect& rect, const SkMatrix* matrix = NULL) {
- drawRect(rect, matrix, NULL, NULL);
+ drawRect(rect, matrix, NULL, NULL, 0);
}
void drawSimpleRect(const GrIRect& irect, const SkMatrix* matrix = NULL) {
SkRect rect = SkRect::MakeFromIRect(irect);
- this->drawRect(rect, matrix, NULL, NULL);
+ this->drawRect(rect, matrix, NULL, NULL, 0);
}
/**
diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp
index 6966858..31b1a57 100644
--- a/src/gpu/GrInOrderDrawBuffer.cpp
+++ b/src/gpu/GrInOrderDrawBuffer.cpp
@@ -74,8 +74,9 @@
void GrInOrderDrawBuffer::drawRect(const GrRect& rect,
const SkMatrix* matrix,
- const GrRect* localRect,
- const SkMatrix* localMatrix) {
+ const GrRect* srcRect,
+ const SkMatrix* srcMatrix,
+ int stage) {
GrAttribBindings bindings = GrDrawState::kDefault_AttribBindings;
GrDrawState::AutoColorRestore acr;
@@ -85,7 +86,7 @@
GrColor color = drawState->getColor();
GrVertexAttribArray<3> attribs;
size_t currentOffset = 0;
- int colorOffset = -1, localOffset = -1;
+ int colorOffset = -1, texOffset = -1;
// set position attrib
drawState->setAttribIndex(GrDrawState::kPosition_AttribIndex, attribs.count());
@@ -114,13 +115,15 @@
acr.set(drawState, 0xFFFFFFFF);
}
- if (NULL != localRect) {
- bindings |= GrDrawState::kLocalCoords_AttribBindingsBit;
- drawState->setAttribIndex(GrDrawState::kLocalCoords_AttribIndex, attribs.count());
+ uint32_t explicitCoordMask = 0;
+ if (NULL != srcRect) {
+ bindings |= GrDrawState::ExplicitTexCoordAttribBindingsBit(stage);
+ drawState->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, attribs.count());
currAttrib.set(kVec2f_GrVertexAttribType, currentOffset);
attribs.push_back(currAttrib);
- localOffset = currentOffset;
+ texOffset = currentOffset;
currentOffset += sizeof(GrPoint);
+ explicitCoordMask = (1 << stage);
}
drawState->setVertexAttribs(attribs.begin(), attribs.count());
@@ -142,7 +145,7 @@
// When the caller has provided an explicit source rect for a stage then we don't want to
// modify that stage's matrix. Otherwise if the effect is generating its source rect from
// the vertex positions then we have to account for the view matrix change.
- GrDrawState::AutoDeviceCoordDraw adcd(drawState);
+ GrDrawState::AutoDeviceCoordDraw adcd(drawState, explicitCoordMask);
if (!adcd.succeeded()) {
return;
}
@@ -158,13 +161,15 @@
// unnecessary clipping in our onDraw().
get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds);
- if (localOffset >= 0) {
- GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + localOffset);
- coords->setRectFan(localRect->fLeft, localRect->fTop,
- localRect->fRight, localRect->fBottom,
+ if (texOffset >= 0) {
+ GrAssert(explicitCoordMask != 0);
+ GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) +
+ texOffset);
+ coords->setRectFan(srcRect->fLeft, srcRect->fTop,
+ srcRect->fRight, srcRect->fBottom,
vsize);
- if (NULL != localMatrix) {
- localMatrix->mapPointsWithStride(coords, vsize, 4);
+ if (NULL != srcMatrix) {
+ srcMatrix->mapPointsWithStride(coords, vsize, 4);
}
}
diff --git a/src/gpu/GrInOrderDrawBuffer.h b/src/gpu/GrInOrderDrawBuffer.h
index cb51bc4..f04bb84 100644
--- a/src/gpu/GrInOrderDrawBuffer.h
+++ b/src/gpu/GrInOrderDrawBuffer.h
@@ -78,8 +78,9 @@
GrRenderTarget* renderTarget = NULL) SK_OVERRIDE;
virtual void drawRect(const GrRect& rect,
const SkMatrix* matrix,
- const GrRect* localRect,
- const SkMatrix* localMatrix) SK_OVERRIDE;
+ const GrRect* srcRect,
+ const SkMatrix* srcMatrix,
+ int stage) SK_OVERRIDE;
protected:
virtual void clipWillBeSet(const GrClipData* newClip) SK_OVERRIDE;
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp
index 2cf56d6..fe9fd82 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -197,29 +197,18 @@
// && edge rendering (kEdgeEffectStage in GrContext)
kPathMaskStage = GrPaint::kTotalStages,
};
+ GrAssert(!drawState->isStageEnabled(kPathMaskStage));
+ drawState->createTextureEffect(kPathMaskStage, texture, SkMatrix::I());
+ SkScalar w = SkIntToScalar(rect.width());
+ SkScalar h = SkIntToScalar(rect.height());
+ GrRect maskRect = GrRect::MakeWH(w / texture->width(),
+ h / texture->height());
GrRect dstRect = GrRect::MakeLTRB(
SK_Scalar1 * rect.fLeft,
SK_Scalar1 * rect.fTop,
SK_Scalar1 * rect.fRight,
SK_Scalar1 * rect.fBottom);
-
- // We want to use device coords to compute the texture coordinates. We set our matrix to be
- // equal to the view matrix followed by a translation so that the top-left of the device bounds
- // maps to 0,0, and then a scaling matrix to normalized coords. We apply this matrix to the
- // vertex positions rather than local coords.
- SkMatrix maskMatrix;
- maskMatrix.setIDiv(texture->width(), texture->height());
- maskMatrix.preTranslate(SkIntToScalar(-rect.fLeft), SkIntToScalar(-rect.fTop));
- maskMatrix.preConcat(drawState->getViewMatrix());
-
- GrAssert(!drawState->isStageEnabled(kPathMaskStage));
- drawState->setEffect(kPathMaskStage,
- GrSimpleTextureEffect::Create(texture,
- maskMatrix,
- false,
- GrEffect::kPosition_CoordsType))->unref();
-
- target->drawSimpleRect(dstRect);
+ target->drawRect(dstRect, NULL, &maskRect, NULL, kPathMaskStage);
drawState->disableStage(kPathMaskStage);
}
diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp
index ab2bc42..5ff13b0 100644
--- a/src/gpu/GrTextContext.cpp
+++ b/src/gpu/GrTextContext.cpp
@@ -18,10 +18,12 @@
#include "SkPath.h"
#include "SkStrokeRec.h"
-// glyph rendering shares this stage with edge rendering (kEdgeEffectStage in GrContext) && SW path
-// rendering (kPathMaskStage in GrSWMaskHelper)
-static const int kGlyphMaskStage = GrPaint::kTotalStages;
-static const int kGlyphCoordsAttributeIndex = 1;
+enum {
+ // glyph rendering shares this stage with edge rendering
+ // (kEdgeEffectStage in GrContext) && SW path rendering
+ // (kPathMaskStage in GrSWMaskHelper)
+ kGlyphMaskStage = GrPaint::kTotalStages,
+};
void GrTextContext::flushGlyphs() {
if (NULL == fDrawTarget) {
@@ -33,11 +35,7 @@
GrAssert(GrIsALIGN4(fCurrVertex));
GrAssert(fCurrTexture);
GrTextureParams params(SkShader::kRepeat_TileMode, false);
-
- // This effect could be stored with one of the cache objects (atlas?)
- drawState->setEffect(kGlyphMaskStage,
- GrSimpleTextureEffect::CreateWithCustomCoords(fCurrTexture, params),
- kGlyphCoordsAttributeIndex)->unref();
+ drawState->createTextureEffect(kGlyphMaskStage, fCurrTexture, SkMatrix::I(), params);
if (!GrPixelConfigIsAlphaOnly(fCurrTexture->config())) {
if (kOne_GrBlendCoeff != fPaint.getSrcBlendCoeff() ||
@@ -197,7 +195,7 @@
{kVec2f_GrVertexAttribType, 0},
{kVec2f_GrVertexAttribType, sizeof(GrPoint)}
};
- static const GrAttribBindings kAttribBindings = 0;
+ static const GrAttribBindings kAttribBindings = GrDrawState::ExplicitTexCoordAttribBindingsBit(kGlyphMaskStage);
// If we need to reserve vertices allow the draw target to suggest
// a number of verts to reserve and whether to perform a flush.
@@ -216,6 +214,7 @@
fDrawTarget->drawState()->setVertexAttribs(kVertexAttribs, SK_ARRAY_COUNT(kVertexAttribs));
}
fDrawTarget->drawState()->setAttribIndex(GrDrawState::kPosition_AttribIndex, 0);
+ fDrawTarget->drawState()->setAttribIndex(GrDrawState::kTexCoord_AttribIndex, 1);
fDrawTarget->drawState()->setAttribBindings(kAttribBindings);
fMaxVertices = kDefaultRequestedVerts;
// ignore return, no point in flushing again.
diff --git a/src/gpu/effects/GrCircleEdgeEffect.cpp b/src/gpu/effects/GrCircleEdgeEffect.cpp
index 4ecdedb..ba73502 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 @@
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 df8ab8d..5cc05e2 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 @@
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 924b03c..794a936 100644
--- a/src/gpu/effects/GrConvolutionEffect.cpp
+++ b/src/gpu/effects/GrConvolutionEffect.cpp
@@ -18,18 +18,19 @@
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 @@
};
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 @@
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 @@
}
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 12f3197..37432f0 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 @@
// 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 @@
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 80627aa..37e6eb4 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 @@
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 661f40f..ffc05e5 100644
--- a/src/gpu/effects/GrSimpleTextureEffect.h
+++ b/src/gpu/effects/GrSimpleTextureEffect.h
@@ -14,50 +14,25 @@
/**
* 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 @@
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 0c671f1..7183ba3 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 82037cf..4f25ddb 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 @@
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 @@
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 b1fd3ed..e54af25 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 @@
};
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 @@
"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::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 @@
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 @@
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 @@
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 @@
matrix,
clippedDomain,
wrapMode,
- bilerp,
- coordsType)));
+ bilerp)));
return CreateEffectRef(effect);
}
@@ -186,9 +182,8 @@
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 @@
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 @@
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 8b1f2b6..b7f665c 100644
--- a/src/gpu/effects/GrTextureDomainEffect.h
+++ b/src/gpu/effects/GrTextureDomainEffect.h
@@ -38,8 +38,7 @@
const SkMatrix&,
const SkRect& domain,
WrapMode,
- bool bilerp,
- CoordsType = kLocal_CoordsType);
+ bool bilerp = false);
virtual ~GrTextureDomainEffect();
@@ -76,8 +75,7 @@
const SkMatrix&,
const GrRect& domain,
WrapMode,
- bool bilerp,
- CoordsType type);
+ bool bilerp);
virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
diff --git a/src/gpu/gl/GrGLEffect.cpp b/src/gpu/gl/GrGLEffect.cpp
index e21ab1d..478d03d 100644
--- a/src/gpu/gl/GrGLEffect.cpp
+++ b/src/gpu/gl/GrGLEffect.cpp
@@ -7,7 +7,6 @@
#include "GrGLSL.h"
#include "GrGLEffect.h"
-#include "GrDrawEffect.h"
GrGLEffect::GrGLEffect(const GrBackendEffectFactory& factory)
: fFactory(factory) {
@@ -18,15 +17,14 @@
///////////////////////////////////////////////////////////////////////////////
-void GrGLEffect::setData(const GrGLUniformManager&, const GrDrawEffect&) {
+void GrGLEffect::setData(const GrGLUniformManager&, const GrEffectStage&) {
}
-GrGLEffect::EffectKey GrGLEffect::GenTextureKey(const GrDrawEffect& drawEffect,
+GrGLEffect::EffectKey GrGLEffect::GenTextureKey(const GrEffectRef* effect,
const GrGLCaps& caps) {
EffectKey key = 0;
- int numTextures = (*drawEffect.effect())->numTextures();
- for (int index = 0; index < numTextures; ++index) {
- const GrTextureAccess& access = (*drawEffect.effect())->textureAccess(index);
+ for (int index = 0; index < (*effect)->numTextures(); ++index) {
+ const GrTextureAccess& access = (*effect)->textureAccess(index);
EffectKey value = GrGLShaderBuilder::KeyForTextureAccess(access, caps) << index;
GrAssert(0 == (value & key)); // keys for each access ought not to overlap
key |= value;
@@ -34,12 +32,12 @@
return key;
}
-GrGLEffect::EffectKey GrGLEffect::GenAttribKey(const GrDrawEffect& drawEffect) {
+GrGLEffect::EffectKey GrGLEffect::GenAttribKey(const GrEffectStage& stage) {
EffectKey key = 0;
- int numAttributes = drawEffect.getVertexAttribIndexCount();
+ int numAttributes = stage.getVertexAttribIndexCount();
GrAssert(numAttributes <= 2);
- const int* attributeIndices = drawEffect.getVertexAttribIndices();
+ const int* attributeIndices = stage.getVertexAttribIndices();
for (int index = 0; index < numAttributes; ++index) {
EffectKey value = attributeIndices[index] << 3*index;
GrAssert(0 == (value & key)); // keys for each attribute ought not to overlap
diff --git a/src/gpu/gl/GrGLEffect.h b/src/gpu/gl/GrGLEffect.h
index 5df2281..869fbda 100644
--- a/src/gpu/gl/GrGLEffect.h
+++ b/src/gpu/gl/GrGLEffect.h
@@ -12,6 +12,7 @@
#include "GrGLShaderBuilder.h"
#include "GrGLShaderVar.h"
#include "GrGLSL.h"
+#include "GrEffectStage.h"
class GrGLTexture;
@@ -20,20 +21,13 @@
include/gpu/GrEffect.h. Objects of type GrGLEffect are responsible for emitting the
GLSL code that implements a GrEffect and for uploading uniforms at draw time. They also
must have a function:
- static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&)
+ static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&)
that is used to implement a program cache. When two GrEffects produce the same key this means
that their GrGLEffects would emit the same GLSL code.
- The GrGLEffect subclass must also have a constructor of the form:
- EffectSubclass::EffectSubclass(const GrBackendEffectFactory&, const GrDrawEffect&)
- The effect held by the GrDrawEffect is guaranteed to be of the type that generated the
- GrGLEffect subclass instance.
-
These objects are created by the factory object returned by the GrEffect::getFactory().
*/
-class GrDrawEffect;
-
class GrGLEffect {
public:
@@ -56,10 +50,14 @@
stages.
@param builder Interface used to emit code in the shaders.
- @param drawEffect A wrapper on the effect that generated this program stage.
+ @param stage The effect stage that generated this program stage.
@param key The key that was computed by GenKey() from the generating GrEffect.
Only the bits indicated by GrBackendEffectFactory::kEffectKeyBits are
guaranteed to match the value produced by GenKey();
+ @param vertexCoords A vec2 in the VS that holds the position in local coords. This is either
+ the pre-view-matrix vertex position or if explicit per-vertex texture
+ coords are used with a stage then it is those coordinates. See
+ GrVertexLayout.
@param outputColor A predefined vec4 in the FS in which the stage should place its output
color (or coverage).
@param inputColor A vec4 that holds the input color to the stage in the FS. This may be
@@ -72,8 +70,9 @@
reads in the generated code.
*/
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) = 0;
@@ -82,15 +81,34 @@
key; this function reads data from a stage and uploads any uniform variables required
by the shaders created in emitCode(). The GrEffect installed in the GrEffectStage is
guaranteed to be of the same type that created this GrGLEffect and to have an identical
- EffectKey as the one that created this GrGLEffect. Effects that use local coords have
- to consider whether the GrEffectStage's coord change matrix should be used. When explicit
- local coordinates are used it can be ignored. */
- virtual void setData(const GrGLUniformManager&, const GrDrawEffect&);
+ EffectKey as the one that created this GrGLEffect. */
+ virtual void setData(const GrGLUniformManager&, const GrEffectStage&);
const char* name() const { return fFactory.name(); }
- static EffectKey GenTextureKey(const GrDrawEffect&, const GrGLCaps&);
- static EffectKey GenAttribKey(const GrDrawEffect& stage);
+ static EffectKey GenTextureKey(const GrEffectRef*, const GrGLCaps&);
+ static EffectKey GenAttribKey(const GrEffectStage& stage);
+
+ /**
+ * GrGLEffect subclasses get passed a GrEffectStage in their emitCode and setData functions.
+ * The GrGLEffect usually needs to cast the stage's effect to the GrEffect subclass that
+ * generated the GrGLEffect. This helper does just that.
+ */
+ template <typename T>
+ static const T& GetEffectFromStage(const GrEffectStage& effectStage) {
+ GrAssert(NULL != effectStage.getEffect());
+ return CastEffect<T>(*effectStage.getEffect());
+ }
+
+ /**
+ * Extracts the GrEffect from a GrEffectRef and down-casts to a GrEffect subclass. Usually used
+ * in a GrGLEffect subclass's constructor (which takes const GrEffectRef&).
+ */
+ template <typename T>
+ static const T& CastEffect(const GrEffectRef& effectRef) {
+ GrAssert(NULL != effectRef.get());
+ return *static_cast<const T*>(effectRef.get());
+ }
protected:
const GrBackendEffectFactory& fFactory;
diff --git a/src/gpu/gl/GrGLEffectMatrix.cpp b/src/gpu/gl/GrGLEffectMatrix.cpp
index aaca240..c37098e 100644
--- a/src/gpu/gl/GrGLEffectMatrix.cpp
+++ b/src/gpu/gl/GrGLEffectMatrix.cpp
@@ -6,67 +6,58 @@
*/
#include "GrGLEffectMatrix.h"
-#include "GrDrawEffect.h"
#include "GrTexture.h"
GrGLEffect::EffectKey GrGLEffectMatrix::GenKey(const SkMatrix& effectMatrix,
- const GrDrawEffect& drawEffect,
- CoordsType coordsType,
+ const SkMatrix& coordChangeMatrix,
const GrTexture* texture) {
- EffectKey key = 0;
SkMatrix::TypeMask type0 = effectMatrix.getType();
- SkMatrix::TypeMask type1;
- if (GrEffect::kLocal_CoordsType == coordsType) {
- type1 = drawEffect.getCoordChangeMatrix().getType();
- } else {
- if (drawEffect.programHasExplicitLocalCoords()) {
- // We only make the key indicate that device coords are referenced when the local coords
- // are not actually determined by positions.
- key |= kPositionCoords_Flag;
- }
- type1 = SkMatrix::kIdentity_Mask;
- }
+ SkMatrix::TypeMask type1 = coordChangeMatrix.getType();
+ static const int kNonTransMask = SkMatrix::kAffine_Mask |
+ SkMatrix::kScale_Mask |
+ SkMatrix::kPerspective_Mask;
int combinedTypes = type0 | type1;
bool reverseY = (NULL != texture) && kBottomLeft_GrSurfaceOrigin == texture->origin();
if (SkMatrix::kPerspective_Mask & combinedTypes) {
- key |= kGeneral_MatrixType;
- } else if (((SkMatrix::kAffine_Mask | SkMatrix::kScale_Mask) & combinedTypes) || reverseY) {
- key |= kNoPersp_MatrixType;
- } else if (SkMatrix::kTranslate_Mask & combinedTypes) {
- key |= kTrans_MatrixType;
+ return kGeneral_Key;
+ } else if ((kNonTransMask & combinedTypes) || reverseY) {
+ return kNoPersp_Key;
+ } else if (kTrans_Key & combinedTypes) {
+ return kTrans_Key;
} else {
- key |= kIdentity_MatrixType;
+ GrAssert(effectMatrix.isIdentity() && coordChangeMatrix.isIdentity());
+ return kIdentity_Key;
}
- return key;
}
GrSLType GrGLEffectMatrix::emitCode(GrGLShaderBuilder* builder,
EffectKey key,
+ const char* vertexCoords,
const char** fsCoordName,
const char** vsCoordName,
const char* suffix) {
GrSLType varyingType;
const char* uniName;
key &= kKeyMask;
- switch (key & kMatrixTypeKeyMask) {
- case kIdentity_MatrixType:
+ switch (key) {
+ case kIdentity_Key:
fUniType = kVoid_GrSLType;
varyingType = kVec2f_GrSLType;
break;
- case kTrans_MatrixType:
+ case kTrans_Key:
fUniType = kVec2f_GrSLType;
uniName = "StageTranslate";
varyingType = kVec2f_GrSLType;
break;
- case kNoPersp_MatrixType:
+ case kNoPersp_Key:
fUniType = kMat33f_GrSLType;
uniName = "StageMatrix";
varyingType = kVec2f_GrSLType;
break;
- case kGeneral_MatrixType:
+ case kGeneral_Key:
fUniType = kMat33f_GrSLType;
uniName = "StageMatrix";
varyingType = kVec3f_GrSLType;
@@ -98,38 +89,24 @@
const char* fsVaryingName;
builder->addVarying(varyingType, varyingName, &vsVaryingName, &fsVaryingName);
- const GrGLShaderVar* coords;
- switch (fCoordsType) {
- case GrEffect::kLocal_CoordsType:
- GrAssert(!(kPositionCoords_Flag & key));
- coords = &builder->localCoordsAttribute();
- break;
- case GrEffect::kPosition_CoordsType:
- GrAssert((kPositionCoords_Flag & key) || !builder->hasExplicitLocalCoords());
- coords = &builder->positionAttribute();
- break;
- default:
- GrCrash("Unexpected coords type.");
- }
- // varying = matrix * coords (logically)
+ // varying = matrix * vertex-coords (logically)
switch (fUniType) {
case kVoid_GrSLType:
GrAssert(kVec2f_GrSLType == varyingType);
- builder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, coords->c_str());
+ builder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, vertexCoords);
break;
case kVec2f_GrSLType:
GrAssert(kVec2f_GrSLType == varyingType);
- builder->vsCodeAppendf("\t%s = %s + %s;\n",
- vsVaryingName, uniName, coords->c_str());
+ builder->vsCodeAppendf("\t%s = %s + %s;\n", vsVaryingName, uniName, vertexCoords);
break;
case kMat33f_GrSLType: {
GrAssert(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingType);
if (kVec2f_GrSLType == varyingType) {
builder->vsCodeAppendf("\t%s = (%s * vec3(%s, 1)).xy;\n",
- vsVaryingName, uniName, coords->c_str());
+ vsVaryingName, uniName, vertexCoords);
} else {
builder->vsCodeAppendf("\t%s = %s * vec3(%s, 1);\n",
- vsVaryingName, uniName, coords->c_str());
+ vsVaryingName, uniName, vertexCoords);
}
break;
}
@@ -151,6 +128,7 @@
*/
void GrGLEffectMatrix::emitCodeMakeFSCoords2D(GrGLShaderBuilder* builder,
EffectKey key,
+ const char* vertexCoords,
const char** fsCoordName,
const char** vsVaryingName,
GrSLType* vsVaryingType,
@@ -159,6 +137,7 @@
GrSLType varyingType = this->emitCode(builder,
key,
+ vertexCoords,
&fsVaryingName,
vsVaryingName,
suffix);
@@ -185,14 +164,11 @@
}
void GrGLEffectMatrix::setData(const GrGLUniformManager& uniformManager,
- const SkMatrix& matrix,
- const GrDrawEffect& drawEffect,
- const GrTexture* texture) {
+ const SkMatrix& matrix,
+ const SkMatrix& coordChangeMatrix,
+ const GrTexture* texture) {
GrAssert((GrGLUniformManager::kInvalidUniformHandle == fUni) ==
- (kVoid_GrSLType == fUniType));
- const SkMatrix& coordChangeMatrix = GrEffect::kLocal_CoordsType == fCoordsType ?
- drawEffect.getCoordChangeMatrix() :
- SkMatrix::I();
+ (kVoid_GrSLType == fUniType));
switch (fUniType) {
case kVoid_GrSLType:
GrAssert(matrix.isIdentity());
@@ -202,8 +178,8 @@
case kVec2f_GrSLType: {
GrAssert(SkMatrix::kTranslate_Mask == (matrix.getType() | coordChangeMatrix.getType()));
GrAssert(NULL == texture || kTopLeft_GrSurfaceOrigin == texture->origin());
- SkScalar tx = matrix[SkMatrix::kMTransX] + (coordChangeMatrix)[SkMatrix::kMTransX];
- SkScalar ty = matrix[SkMatrix::kMTransY] + (coordChangeMatrix)[SkMatrix::kMTransY];
+ SkScalar tx = matrix[SkMatrix::kMTransX] + coordChangeMatrix[SkMatrix::kMTransX];
+ SkScalar ty = matrix[SkMatrix::kMTransY] + coordChangeMatrix[SkMatrix::kMTransY];
if (fPrevMatrix.get(SkMatrix::kMTransX) != tx ||
fPrevMatrix.get(SkMatrix::kMTransY) != ty) {
uniformManager.set2f(fUni, tx, ty);
diff --git a/src/gpu/gl/GrGLEffectMatrix.h b/src/gpu/gl/GrGLEffectMatrix.h
index fc4b783..1a11656 100644
--- a/src/gpu/gl/GrGLEffectMatrix.h
+++ b/src/gpu/gl/GrGLEffectMatrix.h
@@ -14,68 +14,34 @@
class GrTexture;
/**
- * This is a helper to implement a matrix in a GrGLEffect that operates on incoming coords in the
- * vertex shader and writes them to an attribute to be used in the fragment shader. When the input
- * coords in the vertex shader are local coordinates this class accounts for the coord change matrix
- * communicated via GrDrawEffect. The input coords may also be positions and in this case the coord
- * change matrix is ignored. The GrGLEffectMatrix will emit different code based on the type of
- * matrix and thus must contribute to the effect's key.
- *
- * This class cannot be used to apply a matrix to coordinates that come in the form of custom vertex
- * attributes.
+ * This is a helper to implement a texture matrix in a GrGLEffect.
*/
class GrGLEffectMatrix {
-private:
- // We specialize the generated code for each of these matrix types.
- enum MatrixTypes {
- kIdentity_MatrixType = 0,
- kTrans_MatrixType = 1,
- kNoPersp_MatrixType = 2,
- kGeneral_MatrixType = 3,
- };
- // The key for is made up of a matrix type and a bit that indicates the source of the input
- // coords.
- enum {
- kMatrixTypeKeyBits = 2,
- kMatrixTypeKeyMask = (1 << kMatrixTypeKeyBits) - 1,
- kPositionCoords_Flag = (1 << kMatrixTypeKeyBits),
- kKeyBitsPrivate = kMatrixTypeKeyBits + 1,
- };
-
public:
-
- typedef GrEffect::CoordsType CoordsType;
-
typedef GrGLEffect::EffectKey EffectKey;
-
/**
* The matrix uses kKeyBits of the effect's EffectKey. A GrGLEffect may place these bits at an
* arbitrary shift in its final key. However, when GrGLEffectMatrix::emitCode*() code is called
* the relevant bits must be in the lower kKeyBits of the key parameter.
*/
enum {
- kKeyBits = kKeyBitsPrivate,
+ kKeyBits = 2,
kKeyMask = (1 << kKeyBits) - 1,
};
- GrGLEffectMatrix(CoordsType coordsType)
- : fUni(GrGLUniformManager::kInvalidUniformHandle)
- , fCoordsType(coordsType) {
- GrAssert(GrEffect::kLocal_CoordsType == coordsType ||
- GrEffect::kPosition_CoordsType == coordsType);
+ GrGLEffectMatrix() : fUni(GrGLUniformManager::kInvalidUniformHandle) {
fPrevMatrix = SkMatrix::InvalidMatrix();
}
/**
* Generates the key for the portion of the code emitted by this class's emitCode() function.
* Pass a texture to make GrGLEffectMatrix automatically adjust for the texture's origin. Pass
- * NULL when not using the EffectMatrix for a texture lookup, or if the GrGLEffect subclass
- * wants to handle origin adjustments in some other manner. The coords type param must match the
- * param that would be used to initialize GrGLEffectMatrix for the generating GrEffect.
+ * NULL when not using the EffectMatrix for a texture lookups, or if the GrGLEffect subclass
+ * wants to handle origin adjustments in some other manner. coordChangeMatrix is the matrix
+ * from GrEffectStage.
*/
static EffectKey GenKey(const SkMatrix& effectMatrix,
- const GrDrawEffect&,
- CoordsType,
+ const SkMatrix& coordChangeMatrix,
const GrTexture*);
/**
@@ -89,6 +55,7 @@
*/
GrSLType emitCode(GrGLShaderBuilder*,
EffectKey,
+ const char* vertexCoords,
const char** fsCoordName, /* optional */
const char** vsCoordName = NULL,
const char* suffix = NULL);
@@ -99,23 +66,31 @@
*/
void emitCodeMakeFSCoords2D(GrGLShaderBuilder*,
EffectKey,
+ const char* vertexCoords,
const char** fsCoordName, /* optional */
const char** vsVaryingName = NULL,
GrSLType* vsVaryingType = NULL,
const char* suffix = NULL);
/**
- * Call from a GrGLEffect's subclass to update the texture matrix. The effectMatrix and texture
- * params should match those used with GenKey.
+ * Call from a GrGLEffect's subclass to update the texture matrix. The matrix,
+ * coordChangeMatrix, and texture params should match those used with GenKey.
*/
void setData(const GrGLUniformManager& uniformManager,
const SkMatrix& effectMatrix,
- const GrDrawEffect& drawEffect,
+ const SkMatrix& coordChangeMatrix,
const GrTexture*);
+private:
+ enum {
+ kIdentity_Key = 0,
+ kTrans_Key = 1,
+ kNoPersp_Key = 2,
+ kGeneral_Key = 3,
+ };
+
GrGLUniformManager::UniformHandle fUni;
GrSLType fUniType;
SkMatrix fPrevMatrix;
- CoordsType fCoordsType;
};
#endif
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index 21729cd..7d6420e 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -9,7 +9,6 @@
#include "GrAllocator.h"
#include "GrEffect.h"
-#include "GrDrawEffect.h"
#include "GrGLEffect.h"
#include "GrGpuGL.h"
#include "GrGLShaderVar.h"
@@ -27,6 +26,7 @@
SK_CONF_DECLARE(bool, c_PrintShaders, "gpu.printShaders", false,
"Print the source code for all shaders generated.");
+#define TEX_ATTR_NAME "aTexCoord"
#define COL_ATTR_NAME "aColor"
#define COV_ATTR_NAME "aCoverage"
#define EDGE_ATTR_NAME "aEdge"
@@ -134,10 +134,7 @@
lastEnabledStage = s;
const GrEffectRef& effect = *drawState.getStage(s).getEffect();
const GrBackendEffectFactory& factory = effect->getFactory();
- bool explicitLocalCoords = (drawState.getAttribBindings() &
- GrDrawState::kLocalCoords_AttribBindingsBit);
- GrDrawEffect drawEffect(drawState.getStage(s), explicitLocalCoords);
- desc->fEffectKeys[s] = factory.glEffectKey(drawEffect, gpu->glCaps());
+ desc->fEffectKeys[s] = factory.glEffectKey(drawState.getStage(s), gpu->glCaps());
} else {
desc->fEffectKeys[s] = 0;
}
@@ -210,8 +207,8 @@
if (desc->fAttribBindings & GrDrawState::kEdge_AttribBindingsBit) {
desc->fEdgeAttributeIndex = drawState.getAttribIndex(GrDrawState::kEdge_AttribIndex);
}
- if (desc->fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) {
- desc->fLocalCoordsAttributeIndex = drawState.getAttribIndex(GrDrawState::kLocalCoords_AttribIndex);
+ if (GrDrawState::AttributesBindExplicitTexCoords(desc->fAttribBindings)) {
+ desc->fTexCoordAttributeIndex = drawState.getAttribIndex(GrDrawState::kTexCoord_AttribIndex);
}
#if GR_DEBUG
@@ -230,10 +227,10 @@
if (desc->fAttribBindings & GrDrawState::kEdge_AttribBindingsBit) {
GrAssert(desc->fEdgeAttributeIndex < GrDrawState::kVertexAttribCnt);
GrAssert(kAttribLayouts[vertexAttribs[desc->fEdgeAttributeIndex].fType].fCount == 4);
- }
- if (desc->fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) {
- GrAssert(desc->fLocalCoordsAttributeIndex < GrDrawState::kVertexAttribCnt);
- GrAssert(kAttribLayouts[vertexAttribs[desc->fLocalCoordsAttributeIndex].fType].fCount == 2);
+ }
+ if (GrDrawState::AttributesBindExplicitTexCoords(desc->fAttribBindings)) {
+ GrAssert(desc->fTexCoordAttributeIndex < GrDrawState::kVertexAttribCnt);
+ GrAssert(kAttribLayouts[vertexAttribs[desc->fTexCoordAttributeIndex].fType].fCount == 2);
}
#endif
}
@@ -682,10 +679,8 @@
bool GrGLProgram::genProgram(const GrEffectStage* stages[]) {
GrAssert(0 == fProgramID);
+ GrGLShaderBuilder builder(fContext.info(), fUniformManager);
const GrAttribBindings& attribBindings = fDesc.fAttribBindings;
- bool hasExplicitLocalCoords =
- SkToBool(attribBindings & GrDrawState::kLocalCoords_AttribBindingsBit);
- GrGLShaderBuilder builder(fContext.info(), fUniformManager, hasExplicitLocalCoords);
#if GR_GL_EXPERIMENTAL_GS
builder.fUsesGS = fDesc.fExperimentalGS;
@@ -765,6 +760,11 @@
builder.vsCodeAppend("\tgl_PointSize = 1.0;\n");
}
+ // add texture coordinates that are used to the list of vertex attr decls
+ if (GrDrawState::AttributesBindExplicitTexCoords(attribBindings)) {
+ builder.addAttribute(kVec2f_GrSLType, TEX_ATTR_NAME);
+ }
+
///////////////////////////////////////////////////////////////////////////
// compute the final color
@@ -779,11 +779,21 @@
outColor.appendS32(s);
builder.fsCodeAppendf("\tvec4 %s;\n", outColor.c_str());
+ const char* inCoords;
+ // figure out what our input coords are
+ if (!GrDrawState::StageBindsExplicitTexCoords(attribBindings, s)) {
+ inCoords = builder.positionAttribute().c_str();
+ } else {
+ // must have input tex coordinates if stage is enabled.
+ inCoords = TEX_ATTR_NAME;
+ }
+
builder.setCurrentStage(s);
fEffects[s] = builder.createAndEmitGLEffect(*stages[s],
fDesc.fEffectKeys[s],
inColor.size() ? inColor.c_str() : NULL,
outColor.c_str(),
+ inCoords,
&fUniformHandles.fSamplerUnis[s]);
builder.setNonStage();
inColor = outColor;
@@ -861,6 +871,16 @@
outCoverage.appendS32(s);
builder.fsCodeAppendf("\tvec4 %s;\n", outCoverage.c_str());
+ const char* inCoords;
+ // figure out what our input coords are
+ if (!GrDrawState::StageBindsExplicitTexCoords(attribBindings, s)) {
+ inCoords = builder.positionAttribute().c_str();
+ } else {
+ // must have input tex coordinates if stage is
+ // enabled.
+ inCoords = TEX_ATTR_NAME;
+ }
+
// stages don't know how to deal with a scalar input. (Maybe they should. We
// could pass a GrGLShaderVar)
if (inCoverageIsScalar) {
@@ -874,6 +894,7 @@
fDesc.fEffectKeys[s],
inCoverage.size() ? inCoverage.c_str() : NULL,
outCoverage.c_str(),
+ inCoords,
&fUniformHandles.fSamplerUnis[s]);
builder.setNonStage();
inCoverage = outCoverage;
@@ -987,10 +1008,8 @@
if (fDesc.fAttribBindings & GrDrawState::kEdge_AttribBindingsBit) {
GL_CALL(BindAttribLocation(fProgramID, fDesc.fEdgeAttributeIndex, EDGE_ATTR_NAME));
}
- if (fDesc.fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit) {
- GL_CALL(BindAttribLocation(fProgramID,
- fDesc.fLocalCoordsAttributeIndex,
- builder.localCoordsAttribute().c_str()));
+ if (GrDrawState::AttributesBindExplicitTexCoords(fDesc.fAttribBindings)) {
+ GL_CALL(BindAttribLocation(fProgramID, fDesc.fTexCoordAttributeIndex, TEX_ATTR_NAME));
}
const GrGLShaderBuilder::AttributePair* attribEnd = builder.getEffectAttributes().end();
@@ -1069,11 +1088,7 @@
if (NULL != fEffects[s]) {
const GrEffectStage& stage = drawState.getStage(s);
GrAssert(NULL != stage.getEffect());
-
- bool explicitLocalCoords =
- (fDesc.fAttribBindings & GrDrawState::kLocalCoords_AttribBindingsBit);
- GrDrawEffect drawEffect(stage, explicitLocalCoords);
- fEffects[s]->setData(fUniformManager, drawEffect);
+ fEffects[s]->setData(fUniformManager, stage);
int numSamplers = fUniformHandles.fSamplerUnis[s].count();
for (int u = 0; u < numSamplers; ++u) {
UniformHandle handle = fUniformHandles.fSamplerUnis[s][u];
diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h
index 9fd01fd..cde918b 100644
--- a/src/gpu/gl/GrGLProgram.h
+++ b/src/gpu/gl/GrGLProgram.h
@@ -192,7 +192,7 @@
int8_t fColorAttributeIndex;
int8_t fCoverageAttributeIndex;
int8_t fEdgeAttributeIndex;
- int8_t fLocalCoordsAttributeIndex;
+ int8_t fTexCoordAttributeIndex;
friend class GrGLProgram;
};
diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp
index 1179626..b3b09cc 100644
--- a/src/gpu/gl/GrGLShaderBuilder.cpp
+++ b/src/gpu/gl/GrGLShaderBuilder.cpp
@@ -8,7 +8,6 @@
#include "gl/GrGLShaderBuilder.h"
#include "gl/GrGLProgram.h"
#include "gl/GrGLUniformHandle.h"
-#include "GrDrawEffect.h"
#include "GrTexture.h"
// number of each input/output type in a single allocation block
@@ -83,8 +82,7 @@
//const int GrGLShaderBuilder::fCoordDims = 2;
GrGLShaderBuilder::GrGLShaderBuilder(const GrGLContextInfo& ctxInfo,
- GrGLUniformManager& uniformManager,
- bool explicitLocalCoords)
+ GrGLUniformManager& uniformManager)
: fUniforms(kVarsPerBlock)
, fVSAttrs(kVarsPerBlock)
, fVSOutputs(kVarsPerBlock)
@@ -101,14 +99,6 @@
fPositionVar = &fVSAttrs.push_back();
fPositionVar->set(kVec2f_GrSLType, GrGLShaderVar::kAttribute_TypeModifier, "aPosition");
- if (explicitLocalCoords) {
- fLocalCoordsVar = &fVSAttrs.push_back();
- fLocalCoordsVar->set(kVec2f_GrSLType,
- GrGLShaderVar::kAttribute_TypeModifier,
- "aLocalCoords");
- } else {
- fLocalCoordsVar = fPositionVar;
- }
}
void GrGLShaderBuilder::codeAppendf(ShaderType type, const char format[], va_list args) {
@@ -504,6 +494,7 @@
GrGLEffect::EffectKey key,
const char* fsInColor,
const char* fsOutColor,
+ const char* vsInCoord,
SkTArray<GrGLUniformManager::UniformHandle, true>* samplerHandles) {
GrAssert(NULL != stage.getEffect());
@@ -515,7 +506,6 @@
textureSamplers[i].init(this, &effect->textureAccess(i), i);
samplerHandles->push_back(textureSamplers[i].fSamplerUniform);
}
- GrDrawEffect drawEffect(stage, this->hasExplicitLocalCoords());
int numAttributes = stage.getVertexAttribIndexCount();
const int* attributeIndices = stage.getVertexAttribIndices();
@@ -529,15 +519,15 @@
}
}
- GrGLEffect* glEffect = effect->getFactory().createGLInstance(drawEffect);
+ GrGLEffect* glEffect = effect->getFactory().createGLInstance(effect);
// Enclose custom code in a block to avoid namespace conflicts
this->fVSCode.appendf("\t{ // %s\n", glEffect->name());
this->fFSCode.appendf("\t{ // %s \n", glEffect->name());
-
glEffect->emitCode(this,
- drawEffect,
+ stage,
key,
+ vsInCoord,
fsOutColor,
fsInColor,
textureSamplers);
diff --git a/src/gpu/gl/GrGLShaderBuilder.h b/src/gpu/gl/GrGLShaderBuilder.h
index f87dc07..524a885 100644
--- a/src/gpu/gl/GrGLShaderBuilder.h
+++ b/src/gpu/gl/GrGLShaderBuilder.h
@@ -80,7 +80,7 @@
kFragment_ShaderType = 0x4,
};
- GrGLShaderBuilder(const GrGLContextInfo&, GrGLUniformManager&, bool explicitLocalCoords);
+ GrGLShaderBuilder(const GrGLContextInfo&, GrGLUniformManager&);
/**
* Called by GrGLEffects to add code to one of the shaders.
@@ -205,16 +205,6 @@
*/
const GrGLShaderVar& positionAttribute() const { return *fPositionVar; }
- /** Returns a vertex attribute that represents the local coords in the VS. This may be the same
- as positionAttribute() or it may not be. It depends upon whether the rendering code
- specified explicit local coords or not in the GrDrawState. */
- const GrGLShaderVar& localCoordsAttribute() const { return *fLocalCoordsVar; }
-
- /**
- * Are explicit local coordinates provided as input to the vertex shader.
- */
- bool hasExplicitLocalCoords() const { return (fLocalCoordsVar != fPositionVar); }
-
/**
* Interfaces used by GrGLProgram.
* TODO: Hide these from the GrEffects using friend or splitting this into two related classes.
@@ -233,6 +223,7 @@
GrBackendEffectFactory::EffectKey key,
const char* fsInColor, // NULL means no incoming color
const char* fsOutColor,
+ const char* vsInCoord,
SkTArray<GrGLUniformManager::UniformHandle, true>* samplerHandles);
GrGLUniformManager::UniformHandle getRTHeightUniform() const { return fRTHeightUniform; }
@@ -299,8 +290,6 @@
SkSTArray<10, AttributePair, true> fEffectAttributes;
GrGLShaderVar* fPositionVar;
- GrGLShaderVar* fLocalCoordsVar;
-
};
#endif