Make GPU coord transforms automatic
Adds a GrCoordTransform class and updates the framework to handle
coord transforms similar to how it handles textures with
GrTextureAccess. Renames GrGLEffectMatrix to GrGLCoordTransform and
slightly repurposes it to be used by the framework instead of effects.
R=bsalomon@google.com, robertphillips@google.com
Review URL: https://codereview.chromium.org/24853002
git-svn-id: http://skia.googlecode.com/svn/trunk@11569 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/effects/SkArithmeticMode.cpp b/src/effects/SkArithmeticMode.cpp
index fd3a683..d746ecb 100644
--- a/src/effects/SkArithmeticMode.cpp
+++ b/src/effects/SkArithmeticMode.cpp
@@ -12,8 +12,8 @@
#include "SkUnPreMultiply.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
+#include "GrCoordTransform.h"
#include "gl/GrGLEffect.h"
-#include "gl/GrGLEffectMatrix.h"
#include "GrTBackendEffectFactory.h"
#include "SkImageFilterUtils.h"
#endif
@@ -246,15 +246,12 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
- static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
-
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
private:
- static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType;
- GrGLEffectMatrix fBackgroundEffectMatrix;
GrGLUniformManager::UniformHandle fKUni;
typedef GrGLEffect INHERITED;
@@ -289,6 +286,7 @@
GrArithmeticEffect(float k1, float k2, float k3, float k4, GrTexture* background);
float fK1, fK2, fK3, fK4;
+ GrCoordTransform fBackgroundTransform;
GrTextureAccess fBackgroundAccess;
GR_DECLARE_EFFECT_TEST;
@@ -302,6 +300,8 @@
GrTexture* background)
: fK1(k1), fK2(k2), fK3(k3), fK4(k4) {
if (background) {
+ fBackgroundTransform.reset(kLocal_GrCoordSet, background);
+ this->addCoordTransform(&fBackgroundTransform);
fBackgroundAccess.reset(background);
this->addTextureAccess(&fBackgroundAccess);
} else {
@@ -334,8 +334,7 @@
GrGLArithmeticEffect::GrGLArithmeticEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
- : INHERITED(factory)
- , fBackgroundEffectMatrix(kCoordsType) {
+ : INHERITED(factory) {
}
GrGLArithmeticEffect::~GrGLArithmeticEffect() {
@@ -346,15 +345,14 @@
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
GrTexture* backgroundTex = drawEffect.castEffect<GrArithmeticEffect>().backgroundTexture();
const char* dstColor;
if (backgroundTex) {
- SkString bgCoords;
- GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(builder, key, &bgCoords, NULL, "BG");
builder->fsCodeAppend("\t\tvec4 bgColor = ");
- builder->fsAppendTextureLookup(samplers[0], bgCoords.c_str(), bgCoordsType);
+ builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coords[0].type());
builder->fsCodeAppendf(";\n");
dstColor = "bgColor";
} else {
@@ -393,26 +391,6 @@
void GrGLArithmeticEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect& drawEffect) {
const GrArithmeticEffect& arith = drawEffect.castEffect<GrArithmeticEffect>();
uman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4());
- GrTexture* bgTex = arith.backgroundTexture();
- if (bgTex) {
- fBackgroundEffectMatrix.setData(uman,
- GrEffect::MakeDivByTextureWHMatrix(bgTex),
- drawEffect,
- bgTex);
- }
-}
-
-GrGLEffect::EffectKey GrGLArithmeticEffect::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
- const GrArithmeticEffect& effect = drawEffect.castEffect<GrArithmeticEffect>();
- GrTexture* bgTex = effect.backgroundTexture();
- EffectKey bgKey = 0;
- if (bgTex) {
- bgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatrix(bgTex),
- drawEffect,
- GrGLArithmeticEffect::kCoordsType,
- bgTex);
- }
- return bgKey;
}
GrEffectRef* GrArithmeticEffect::TestCreate(SkRandom* rand,
diff --git a/src/effects/SkBitmapAlphaThresholdShader.cpp b/src/effects/SkBitmapAlphaThresholdShader.cpp
index 84cdbf2..c8db3a5 100644
--- a/src/effects/SkBitmapAlphaThresholdShader.cpp
+++ b/src/effects/SkBitmapAlphaThresholdShader.cpp
@@ -62,9 +62,9 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
+#include "GrCoordTransform.h"
#include "GrEffect.h"
#include "gl/GrGLEffect.h"
-#include "gl/GrGLEffectMatrix.h"
#include "GrTBackendEffectFactory.h"
#include "GrTextureAccess.h"
@@ -109,36 +109,24 @@
GLEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& e)
: GrGLEffect(factory)
- , fBmpMatrix(GrEffect::kLocal_CoordsType)
- , fMaskMatrix(GrEffect::kLocal_CoordsType)
, fPrevThreshold(-SK_Scalar1) {
}
virtual void emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect& drawEffect,
- EffectKey key,
- const char* outputColor,
- const char* inputColor,
- const TextureSamplerArray& samplers) SK_OVERRIDE {
- SkString bmpCoord;
- SkString maskCoord;
-
- GrSLType bmpCoordType = fBmpMatrix.emitCode(builder, key, &bmpCoord, NULL, "Bmp");
- EffectKey maskMatrixKey = key >> GrGLEffectMatrix::kKeyBits;
- GrSLType maskCoordType = fMaskMatrix.emitCode(builder,
- maskMatrixKey,
- &maskCoord,
- NULL,
- "Mask");
-
+ const GrDrawEffect& drawEffect,
+ EffectKey key,
+ const char* outputColor,
+ const char* inputColor,
+ const TransformedCoordsArray& coords,
+ const TextureSamplerArray& samplers) SK_OVERRIDE {
// put bitmap color in "color"
builder->fsCodeAppend("\t\tvec4 color = ");
- builder->fsAppendTextureLookup(samplers[0], bmpCoord.c_str(), bmpCoordType);
+ builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coords[0].type());
builder->fsCodeAppend(";\n");
// put alpha from mask texture in "mask"
builder->fsCodeAppend("\t\tfloat mask = ");
- builder->fsAppendTextureLookup(samplers[1], maskCoord.c_str(), maskCoordType);
+ builder->fsAppendTextureLookup(samplers[1], coords[1].c_str(), coords[1].type());
builder->fsCodeAppend(".a;\n");
const char* threshold;
@@ -171,31 +159,12 @@
virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect& e) SK_OVERRIDE {
const ThresholdEffect& effect = e.castEffect<ThresholdEffect>();
- fBmpMatrix.setData(uman, effect.fBmpMatrix, e, effect.fBmpAccess.getTexture());
- fMaskMatrix.setData(uman, effect.fMaskMatrix, e, effect.fMaskAccess.getTexture());
if (fPrevThreshold != effect.fThreshold) {
uman.set1f(fThresholdUniHandle, effect.fThreshold);
}
}
- static inline EffectKey GenKey(const GrDrawEffect& e, const GrGLCaps&) {
- const ThresholdEffect& effect = e.castEffect<ThresholdEffect>();
-
- EffectKey bmpMKey = GrGLEffectMatrix::GenKey(effect.fBmpMatrix,
- e,
- GrEffect::kLocal_CoordsType,
- effect.fBmpAccess.getTexture());
- EffectKey maskMKey = GrGLEffectMatrix::GenKey(effect.fMaskMatrix,
- e,
- GrEffect::kLocal_CoordsType,
- effect.fMaskAccess.getTexture());
- return bmpMKey | (maskMKey << GrGLEffectMatrix::kKeyBits);
- }
-
private:
- GrGLEffectMatrix fBmpMatrix;
- GrGLEffectMatrix fMaskMatrix;
-
GrGLUniformManager::UniformHandle fThresholdUniHandle;
SkScalar fPrevThreshold;
};
@@ -206,12 +175,14 @@
ThresholdEffect(GrTexture* bmpTexture, const SkMatrix& bmpMatrix,
GrTexture* maskTexture, const SkMatrix& maskMatrix,
SkScalar threshold)
- : fBmpAccess(bmpTexture, GrTextureParams())
+ : fBmpTransform(kLocal_GrCoordSet, bmpMatrix, bmpTexture)
+ , fBmpAccess(bmpTexture, GrTextureParams())
+ , fMaskTransform(kLocal_GrCoordSet, maskMatrix, maskTexture)
, fMaskAccess(maskTexture, GrTextureParams())
- , fBmpMatrix(bmpMatrix)
- , fMaskMatrix(maskMatrix)
, fThreshold(threshold) {
+ this->addCoordTransform(&fBmpTransform);
this->addTextureAccess(&fBmpAccess);
+ this->addCoordTransform(&fMaskTransform);
this->addTextureAccess(&fMaskAccess);
}
@@ -219,16 +190,15 @@
const ThresholdEffect& e = CastEffect<ThresholdEffect>(other);
return e.fBmpAccess.getTexture() == fBmpAccess.getTexture() &&
e.fMaskAccess.getTexture() == fMaskAccess.getTexture() &&
- e.fBmpMatrix == fBmpMatrix &&
- e.fMaskMatrix == fMaskMatrix &&
+ e.fBmpTransform.getMatrix() == fBmpTransform.getMatrix() &&
+ e.fMaskTransform.getMatrix() == fMaskTransform.getMatrix() &&
e.fThreshold == fThreshold;
}
- GrTextureAccess fBmpAccess;
- GrTextureAccess fMaskAccess;
-
- SkMatrix fBmpMatrix;
- SkMatrix fMaskMatrix;
+ GrCoordTransform fBmpTransform;
+ GrTextureAccess fBmpAccess;
+ GrCoordTransform fMaskTransform;
+ GrTextureAccess fMaskAccess;
SkScalar fThreshold;
};
diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp
index 1f841d0..484836a 100644
--- a/src/effects/SkColorMatrixFilter.cpp
+++ b/src/effects/SkColorMatrixFilter.cpp
@@ -399,6 +399,7 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE {
fMatrixHandle = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kMat44f_GrSLType,
diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp
index a751365..020ee02 100644
--- a/src/effects/SkDisplacementMapEffect.cpp
+++ b/src/effects/SkDisplacementMapEffect.cpp
@@ -11,8 +11,8 @@
#include "SkColorPriv.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
+#include "GrCoordTransform.h"
#include "gl/GrGLEffect.h"
-#include "gl/GrGLEffectMatrix.h"
#include "GrTBackendEffectFactory.h"
#include "SkImageFilterUtils.h"
#endif
@@ -209,6 +209,7 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
@@ -216,12 +217,8 @@
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
private:
- static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType;
-
SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector;
SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector;
- GrGLEffectMatrix fDisplacementEffectMatrix;
- GrGLEffectMatrix fColorEffectMatrix;
GrGLUniformManager::UniformHandle fScaleUni;
typedef GrGLEffect INHERITED;
@@ -257,7 +254,6 @@
virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
private:
-
virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChannelSelector,
@@ -266,7 +262,9 @@
GR_DECLARE_EFFECT_TEST;
+ GrCoordTransform fDisplacementTransform;
GrTextureAccess fDisplacementAccess;
+ GrCoordTransform fColorTransform;
GrTextureAccess fColorAccess;
SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector;
SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector;
@@ -327,12 +325,16 @@
SkScalar scale,
GrTexture* displacement,
GrTexture* color)
- : fDisplacementAccess(displacement)
+ : fDisplacementTransform(kLocal_GrCoordSet, displacement)
+ , fDisplacementAccess(displacement)
+ , fColorTransform(kLocal_GrCoordSet, color)
, fColorAccess(color)
, fXChannelSelector(xChannelSelector)
, fYChannelSelector(yChannelSelector)
, fScale(scale) {
+ this->addCoordTransform(&fDisplacementTransform);
this->addTextureAccess(&fDisplacementAccess);
+ this->addCoordTransform(&fColorTransform);
this->addTextureAccess(&fColorAccess);
}
@@ -393,9 +395,7 @@
const GrDrawEffect& drawEffect)
: INHERITED(factory)
, fXChannelSelector(drawEffect.castEffect<GrDisplacementMapEffect>().xChannelSelector())
- , fYChannelSelector(drawEffect.castEffect<GrDisplacementMapEffect>().yChannelSelector())
- , fDisplacementEffectMatrix(kCoordsType)
- , fColorEffectMatrix(kCoordsType) {
+ , fYChannelSelector(drawEffect.castEffect<GrDisplacementMapEffect>().yChannelSelector()) {
}
GrGLDisplacementMapEffect::~GrGLDisplacementMapEffect() {
@@ -406,20 +406,13 @@
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
sk_ignore_unused_variable(inputColor);
fScaleUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec2f_GrSLType, "Scale");
const char* scaleUni = builder->getUniformCStr(fScaleUni);
-
- SkString dCoordsIn;
- GrSLType dCoordsType = fDisplacementEffectMatrix.emitCode(
- builder, key, &dCoordsIn, NULL, "DISPL");
- SkString cCoordsIn;
- GrSLType cCoordsType = fColorEffectMatrix.emitCode(
- builder, key, &cCoordsIn, NULL, "COLOR");
-
const char* dColor = "dColor";
const char* cCoords = "cCoords";
const char* outOfBounds = "outOfBounds";
@@ -428,7 +421,7 @@
// leave room for 32-bit float GPU rounding errors.
builder->fsCodeAppendf("\t\tvec4 %s = ", dColor);
- builder->fsAppendTextureLookup(samplers[0], dCoordsIn.c_str(), dCoordsType);
+ builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coords[0].type());
builder->fsCodeAppend(";\n");
// Unpremultiply the displacement
@@ -436,7 +429,7 @@
dColor, dColor, nearZero, dColor, dColor);
builder->fsCodeAppendf("\t\tvec2 %s = %s + %s*(%s.",
- cCoords, cCoordsIn.c_str(), scaleUni, dColor);
+ cCoords, coords[1].c_str(), scaleUni, dColor);
switch (fXChannelSelector) {
case SkDisplacementMapEffect::kR_ChannelSelectorType:
@@ -481,7 +474,7 @@
"bool %s = (%s.x < 0.0) || (%s.y < 0.0) || (%s.x > 1.0) || (%s.y > 1.0);\t\t",
outOfBounds, cCoords, cCoords, cCoords, cCoords);
builder->fsCodeAppendf("%s = %s ? vec4(0.0) : ", outputColor, outOfBounds);
- builder->fsAppendTextureLookup(samplers[1], cCoords, cCoordsType);
+ builder->fsAppendTextureLookup(samplers[1], cCoords, coords[1].type());
builder->fsCodeAppend(";\n");
}
@@ -489,17 +482,7 @@
const GrDrawEffect& drawEffect) {
const GrDisplacementMapEffect& displacementMap =
drawEffect.castEffect<GrDisplacementMapEffect>();
- GrTexture* displTex = displacementMap.texture(0);
GrTexture* colorTex = displacementMap.texture(1);
- fDisplacementEffectMatrix.setData(uman,
- GrEffect::MakeDivByTextureWHMatrix(displTex),
- drawEffect,
- displTex);
- fColorEffectMatrix.setData(uman,
- GrEffect::MakeDivByTextureWHMatrix(colorTex),
- drawEffect,
- colorTex);
-
SkScalar scaleX = SkScalarDiv(displacementMap.scale(), SkIntToScalar(colorTex->width()));
SkScalar scaleY = SkScalarDiv(displacementMap.scale(), SkIntToScalar(colorTex->height()));
uman.set2f(fScaleUni, SkScalarToFloat(scaleX),
@@ -512,24 +495,9 @@
const GrDisplacementMapEffect& displacementMap =
drawEffect.castEffect<GrDisplacementMapEffect>();
- GrTexture* displTex = displacementMap.texture(0);
- GrTexture* colorTex = displacementMap.texture(1);
+ EffectKey xKey = displacementMap.xChannelSelector();
+ EffectKey yKey = displacementMap.yChannelSelector() << SkDisplacementMapEffect::kKeyBits;
- EffectKey displKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatrix(displTex),
- drawEffect,
- kCoordsType,
- displTex);
-
- EffectKey colorKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatrix(colorTex),
- drawEffect,
- kCoordsType,
- colorTex);
-
- colorKey <<= GrGLEffectMatrix::kKeyBits;
- EffectKey xKey = displacementMap.xChannelSelector() << (2 * GrGLEffectMatrix::kKeyBits);
- EffectKey yKey = displacementMap.yChannelSelector() << (2 * GrGLEffectMatrix::kKeyBits +
- SkDisplacementMapEffect::kKeyBits);
-
- return xKey | yKey | displKey | colorKey;
+ return xKey | yKey;
}
#endif
diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp
index ca52b98..aac5462 100644
--- a/src/effects/SkLightingImageFilter.cpp
+++ b/src/effects/SkLightingImageFilter.cpp
@@ -16,7 +16,6 @@
#if SK_SUPPORT_GPU
#include "effects/GrSingleTextureEffect.h"
#include "gl/GrGLEffect.h"
-#include "gl/GrGLEffectMatrix.h"
#include "GrEffect.h"
#include "GrTBackendEffectFactory.h"
@@ -1075,6 +1074,7 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
@@ -1093,7 +1093,6 @@
UniformHandle fImageIncrementUni;
UniformHandle fSurfaceScaleUni;
GrGLLight* fLight;
- GrGLEffectMatrix fEffectMatrix;
};
///////////////////////////////////////////////////////////////////////////////
@@ -1196,8 +1195,7 @@
GrGLLightingEffect::GrGLLightingEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
- : INHERITED(factory)
- , fEffectMatrix(drawEffect.castEffect<GrLightingEffect>().coordsType()) {
+ : INHERITED(factory) {
const GrLightingEffect& m = drawEffect.castEffect<GrLightingEffect>();
fLight = m.light()->createGLLight();
}
@@ -1211,9 +1209,9 @@
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
- SkString coords;
- fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
+ SkString coords2D = builder->ensureFSCoords2D(coords, 0);
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec2f_GrSLType,
@@ -1272,7 +1270,7 @@
interiorNormalBody.c_str(),
&interiorNormalName);
- builder->fsCodeAppendf("\t\tvec2 coord = %s;\n", coords.c_str());
+ builder->fsCodeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
builder->fsCodeAppend("\t\tfloat m[9];\n");
const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
@@ -1304,14 +1302,7 @@
GrGLEffect::EffectKey GrGLLightingEffect::GenKey(const GrDrawEffect& drawEffect,
const GrGLCaps& caps) {
- const GrLightingEffect& lighting = drawEffect.castEffect<GrLightingEffect>();
- EffectKey key = lighting.light()->type();
- key <<= GrGLEffectMatrix::kKeyBits;
- EffectKey matrixKey = GrGLEffectMatrix::GenKey(lighting.getMatrix(),
- drawEffect,
- lighting.coordsType(),
- lighting.texture(0));
- return key | matrixKey;
+ return drawEffect.castEffect<GrLightingEffect>().light()->type();
}
void GrGLLightingEffect::setData(const GrGLUniformManager& uman,
@@ -1323,10 +1314,6 @@
uman.set1f(fSurfaceScaleUni, lighting.surfaceScale());
SkAutoTUnref<SkLight> transformedLight(lighting.light()->transform(lighting.filterMatrix()));
fLight->setData(uman, transformedLight);
- fEffectMatrix.setData(uman,
- lighting.getMatrix(),
- drawEffect,
- lighting.texture(0));
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/effects/SkLumaXfermode.cpp b/src/effects/SkLumaXfermode.cpp
index a23e010..3ecb0be 100644
--- a/src/effects/SkLumaXfermode.cpp
+++ b/src/effects/SkLumaXfermode.cpp
@@ -12,7 +12,6 @@
#if SK_SUPPORT_GPU
#include "gl/GrGLEffect.h"
-#include "gl/GrGLEffectMatrix.h"
#include "GrContext.h"
#include "GrTBackendEffectFactory.h"
#endif
@@ -159,6 +158,7 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
@@ -203,11 +203,12 @@
}
void GrGLLumaMaskEffect::emitCode(GrGLShaderBuilder* builder,
- const GrDrawEffect& effect,
- EffectKey key,
- const char* outputColor,
- const char* inputColor,
- const TextureSamplerArray& samplers) {
+ const GrDrawEffect& effect,
+ EffectKey key,
+ const char* outputColor,
+ const char* inputColor,
+ const TransformedCoordsArray&,
+ const TextureSamplerArray& samplers) {
const GrLumaMaskEffect& lumaEffect = effect.castEffect<GrLumaMaskEffect>();
const char* dstColor = builder->dstColor();
diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp
index c74b067..e3d6efd 100644
--- a/src/effects/SkMagnifierImageFilter.cpp
+++ b/src/effects/SkMagnifierImageFilter.cpp
@@ -14,7 +14,6 @@
#if SK_SUPPORT_GPU
#include "effects/GrSingleTextureEffect.h"
#include "gl/GrGLEffect.h"
-#include "gl/GrGLEffectMatrix.h"
#include "gl/GrGLSL.h"
#include "gl/GrGLTexture.h"
#include "GrTBackendEffectFactory.h"
@@ -99,26 +98,21 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
- static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
-
private:
UniformHandle fOffsetVar;
UniformHandle fZoomVar;
UniformHandle fInsetVar;
- GrGLEffectMatrix fEffectMatrix;
-
typedef GrGLEffect INHERITED;
};
-GrGLMagnifierEffect::GrGLMagnifierEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
- : INHERITED(factory)
- , fEffectMatrix(drawEffect.castEffect<GrMagnifierEffect>().coordsType()) {
+GrGLMagnifierEffect::GrGLMagnifierEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
+ : INHERITED(factory) {
}
void GrGLMagnifierEffect::emitCode(GrGLShaderBuilder* builder,
@@ -126,9 +120,9 @@
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
- SkString coords;
- fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
+ SkString coords2D = builder->ensureFSCoords2D(coords, 0);
fOffsetVar = builder->addUniform(
GrGLShaderBuilder::kFragment_Visibility |
GrGLShaderBuilder::kVertex_Visibility,
@@ -142,10 +136,10 @@
GrGLShaderBuilder::kVertex_Visibility,
kVec2f_GrSLType, "uInset");
- builder->fsCodeAppendf("\t\tvec2 coord = %s;\n", coords.c_str());
+ builder->fsCodeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
builder->fsCodeAppendf("\t\tvec2 zoom_coord = %s + %s / %s;\n",
builder->getUniformCStr(fOffsetVar),
- coords.c_str(),
+ coords2D.c_str(),
builder->getUniformCStr(fZoomVar));
builder->fsCodeAppend("\t\tvec2 delta = min(coord, vec2(1.0, 1.0) - coord);\n");
@@ -180,16 +174,6 @@
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));
-}
-
-GrGLEffect::EffectKey GrGLMagnifierEffect::GenKey(const GrDrawEffect& drawEffect,
- const GrGLCaps&) {
- const GrMagnifierEffect& zoom = drawEffect.castEffect<GrMagnifierEffect>();
- return GrGLEffectMatrix::GenKey(zoom.getMatrix(),
- drawEffect,
- zoom.coordsType(),
- zoom.texture(0));
}
/////////////////////////////////////////////////////////////////////
diff --git a/src/effects/SkMatrixConvolutionImageFilter.cpp b/src/effects/SkMatrixConvolutionImageFilter.cpp
index 9446b8e..d73f633 100644
--- a/src/effects/SkMatrixConvolutionImageFilter.cpp
+++ b/src/effects/SkMatrixConvolutionImageFilter.cpp
@@ -14,7 +14,6 @@
#if SK_SUPPORT_GPU
#include "gl/GrGLEffect.h"
-#include "gl/GrGLEffectMatrix.h"
#include "effects/GrSingleTextureEffect.h"
#include "GrTBackendEffectFactory.h"
#include "GrTexture.h"
@@ -324,6 +323,7 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
@@ -343,15 +343,12 @@
UniformHandle fGainUni;
UniformHandle fBiasUni;
- GrGLEffectMatrix fEffectMatrix;
-
typedef GrGLEffect INHERITED;
};
GrGLMatrixConvolutionEffect::GrGLMatrixConvolutionEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
- : INHERITED(factory)
- , fEffectMatrix(drawEffect.castEffect<GrMatrixConvolutionEffect>().coordsType()) {
+ : INHERITED(factory) {
const GrMatrixConvolutionEffect& m = drawEffect.castEffect<GrMatrixConvolutionEffect>();
fKernelSize = m.kernelSize();
fTileMode = m.tileMode();
@@ -384,9 +381,9 @@
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
- SkString coords;
- fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
+ SkString coords2D = builder->ensureFSCoords2D(coords, 0);
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec2f_GrSLType, "ImageIncrement");
fKernelUni = builder->addUniformArray(GrGLShaderBuilder::kFragment_Visibility,
@@ -407,7 +404,7 @@
int kHeight = fKernelSize.height();
builder->fsCodeAppend("\t\tvec4 sum = vec4(0, 0, 0, 0);\n");
- builder->fsCodeAppendf("\t\tvec2 coord = %s - %s * %s;\n", coords.c_str(), target, imgInc);
+ builder->fsCodeAppendf("\t\tvec2 coord = %s - %s * %s;\n", coords2D.c_str(), target, imgInc);
builder->fsCodeAppendf("\t\tfor (int y = 0; y < %d; y++) {\n", kHeight);
builder->fsCodeAppendf("\t\t\tfor (int x = 0; x < %d; x++) {\n", kWidth);
builder->fsCodeAppendf("\t\t\t\tfloat k = %s[y * %d + x];\n", kernel, kWidth);
@@ -426,7 +423,7 @@
builder->fsCodeAppendf("\t\t%s.rgb = clamp(%s.rgb, 0.0, %s.a);\n", outputColor, outputColor, outputColor);
} else {
builder->fsCodeAppend("\t\tvec4 c = ");
- appendTextureLookup(builder, samplers[0], coords.c_str(), fTileMode);
+ appendTextureLookup(builder, samplers[0], coords2D.c_str(), fTileMode);
builder->fsCodeAppend(";\n");
builder->fsCodeAppendf("\t\t%s.a = c.a;\n", outputColor);
builder->fsCodeAppendf("\t\t%s.rgb = sum.rgb * %s + %s;\n", outputColor, gain, bias);
@@ -452,12 +449,7 @@
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(),
- m.texture(0));
- return key | matrixKey;
+ return key;
}
void GrGLMatrixConvolutionEffect::setData(const GrGLUniformManager& uman,
@@ -476,10 +468,6 @@
uman.set1fv(fKernelUni, 0, fKernelSize.width() * fKernelSize.height(), conv.kernel());
uman.set1f(fGainUni, conv.gain());
uman.set1f(fBiasUni, conv.bias());
- fEffectMatrix.setData(uman,
- conv.getMatrix(),
- drawEffect,
- conv.texture(0));
}
GrMatrixConvolutionEffect::GrMatrixConvolutionEffect(GrTexture* texture,
diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp
index 949dc4a..8b314c8 100644
--- a/src/effects/SkMorphologyImageFilter.cpp
+++ b/src/effects/SkMorphologyImageFilter.cpp
@@ -15,7 +15,6 @@
#include "GrTexture.h"
#include "GrTBackendEffectFactory.h"
#include "gl/GrGLEffect.h"
-#include "gl/GrGLEffectMatrix.h"
#include "effects/Gr1DKernelEffect.h"
#include "SkImageFilterUtils.h"
#endif
@@ -314,6 +313,7 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
@@ -326,15 +326,13 @@
int fRadius;
GrMorphologyEffect::MorphologyType fType;
GrGLUniformManager::UniformHandle fImageIncrementUni;
- GrGLEffectMatrix fEffectMatrix;
typedef GrGLEffect INHERITED;
};
GrGLMorphologyEffect::GrGLMorphologyEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
- : INHERITED(factory)
- , fEffectMatrix(drawEffect.castEffect<GrMorphologyEffect>().coordsType()) {
+ : INHERITED(factory) {
const GrMorphologyEffect& m = drawEffect.castEffect<GrMorphologyEffect>();
fRadius = m.radius();
fType = m.type();
@@ -345,9 +343,9 @@
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
- SkString coords;
- fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
+ SkString coords2D = builder->ensureFSCoords2D(coords, 0);
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec2f_GrSLType, "ImageIncrement");
@@ -368,7 +366,7 @@
}
const char* imgInc = builder->getUniformCStr(fImageIncrementUni);
- builder->fsCodeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords.c_str(), fRadius, imgInc);
+ builder->fsCodeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords2D.c_str(), fRadius, imgInc);
builder->fsCodeAppendf("\t\tfor (int i = 0; i < %d; i++) {\n", this->width());
builder->fsCodeAppendf("\t\t\t%s = %s(%s, ", outputColor, func, outputColor);
builder->fsAppendTextureLookup(samplers[0], "coord");
@@ -385,12 +383,7 @@
const GrMorphologyEffect& m = drawEffect.castEffect<GrMorphologyEffect>();
EffectKey key = static_cast<EffectKey>(m.radius());
key |= (m.type() << 8);
- key <<= GrGLEffectMatrix::kKeyBits;
- EffectKey matrixKey = GrGLEffectMatrix::GenKey(m.getMatrix(),
- drawEffect,
- m.coordsType(),
- m.texture(0));
- return key | matrixKey;
+ return key;
}
void GrGLMorphologyEffect::setData(const GrGLUniformManager& uman,
@@ -411,7 +404,6 @@
GrCrash("Unknown filter direction.");
}
uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
- fEffectMatrix.setData(uman, kern.getMatrix(), drawEffect, kern.texture(0));
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp
index de418c3..df6b78e 100644
--- a/src/effects/SkPerlinNoiseShader.cpp
+++ b/src/effects/SkPerlinNoiseShader.cpp
@@ -14,8 +14,8 @@
#if SK_SUPPORT_GPU
#include "GrContext.h"
+#include "GrCoordTransform.h"
#include "gl/GrGLEffect.h"
-#include "gl/GrGLEffectMatrix.h"
#include "GrTBackendEffectFactory.h"
#include "SkGr.h"
#endif
@@ -515,7 +515,6 @@
GrGLUniformManager::UniformHandle fBaseFrequencyUni;
GrGLUniformManager::UniformHandle fAlphaUni;
GrGLUniformManager::UniformHandle fInvMatrixUni;
- GrGLEffectMatrix fEffectMatrix;
private:
typedef GrGLEffect INHERITED;
@@ -533,6 +532,7 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
@@ -557,6 +557,7 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
@@ -577,9 +578,8 @@
bool stitchTiles() const { return fStitchTiles; }
const SkVector& baseFrequency() const { return fBaseFrequency; }
int numOctaves() const { return fNumOctaves; }
- const SkMatrix& matrix() const { return fMatrix; }
+ const SkMatrix& matrix() const { return fCoordTransform.getMatrix(); }
uint8_t alpha() const { return fAlpha; }
- GrGLEffectMatrix::CoordsType coordsType() const { return GrEffect::kLocal_CoordsType; }
void getConstantColorComponents(GrColor*, uint32_t* validFlags) const SK_OVERRIDE {
*validFlags = 0; // This is noise. Nothing is constant.
@@ -592,7 +592,7 @@
fBaseFrequency == s.fBaseFrequency &&
fNumOctaves == s.fNumOctaves &&
fStitchTiles == s.fStitchTiles &&
- fMatrix == s.fMatrix &&
+ fCoordTransform.getMatrix() == s.fCoordTransform.getMatrix() &&
fAlpha == s.fAlpha;
}
@@ -604,9 +604,16 @@
, fStitchTiles(stitchTiles)
, fMatrix(matrix)
, fAlpha(alpha) {
+ // This (1,1) translation is due to WebKit's 1 based coordinates for the noise
+ // (as opposed to 0 based, usually). The same adjustment is in the shadeSpan() functions.
+ SkMatrix m = matrix;
+ m.postTranslate(SK_Scalar1, SK_Scalar1);
+ fCoordTransform.reset(kLocal_GrCoordSet, m);
+ this->addCoordTransform(&fCoordTransform);
}
SkPerlinNoiseShader::Type fType;
+ GrCoordTransform fCoordTransform;
SkVector fBaseFrequency;
int fNumOctaves;
bool fStitchTiles;
@@ -746,11 +753,11 @@
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray& coords,
const TextureSamplerArray&) {
sk_ignore_unused_variable(inputColor);
- SkString vCoords;
- fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &vCoords);
+ SkString vCoords = builder->ensureFSCoords2D(coords, 0);
fSeedUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kFloat_GrSLType, "seed");
@@ -962,11 +969,11 @@
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
sk_ignore_unused_variable(inputColor);
- SkString vCoords;
- fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &vCoords);
+ SkString vCoords = builder->ensureFSCoords2D(coords, 0);
fInvMatrixUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kMat33f_GrSLType, "invMatrix");
@@ -1217,8 +1224,7 @@
: INHERITED (factory)
, fType(drawEffect.castEffect<GrPerlinNoiseEffect>().type())
, fStitchTiles(drawEffect.castEffect<GrPerlinNoiseEffect>().stitchTiles())
- , fNumOctaves(drawEffect.castEffect<GrPerlinNoiseEffect>().numOctaves())
- , fEffectMatrix(drawEffect.castEffect<GrPerlinNoiseEffect>().coordsType()) {
+ , fNumOctaves(drawEffect.castEffect<GrPerlinNoiseEffect>().numOctaves()) {
}
GrGLEffect::EffectKey GrGLNoise::GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
@@ -1244,12 +1250,7 @@
key |= 0x4; // Flip the 3rd bit if tile stitching is on
}
- key = key << GrGLEffectMatrix::kKeyBits;
-
- SkMatrix m = turbulence.matrix();
- m.postTranslate(SK_Scalar1, SK_Scalar1);
- return key | GrGLEffectMatrix::GenKey(m, drawEffect,
- drawEffect.castEffect<GrPerlinNoiseEffect>().coordsType(), NULL);
+ return key;
}
void GrGLNoise::setData(const GrGLUniformManager& uman, const GrDrawEffect& drawEffect) {
@@ -1260,6 +1261,7 @@
uman.set1f(fAlphaUni, SkScalarDiv(SkIntToScalar(turbulence.alpha()), SkIntToScalar(255)));
SkMatrix m = turbulence.matrix();
+ m.postTranslate(-SK_Scalar1, -SK_Scalar1);
SkMatrix invM;
if (!m.invert(&invM)) {
invM.reset();
@@ -1267,11 +1269,6 @@
invM.postConcat(invM); // Square the matrix
}
uman.setSkMatrix(fInvMatrixUni, invM);
-
- // This (1,1) translation is due to WebKit's 1 based coordinates for the noise
- // (as opposed to 0 based, usually). The same adjustment is in the shadeSpan() functions.
- m.postTranslate(SK_Scalar1, SK_Scalar1);
- fEffectMatrix.setData(uman, m, drawEffect, NULL);
}
void GrGLPerlinNoise::setData(const GrGLUniformManager& uman, const GrDrawEffect& drawEffect) {
diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp
index f6088f5..083b54c 100644
--- a/src/effects/SkTableColorFilter.cpp
+++ b/src/effects/SkTableColorFilter.cpp
@@ -272,6 +272,7 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE {}
@@ -292,6 +293,7 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray& samplers) {
static const float kColorScaleFactor = 255.0f / 256.0f;
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp
index be6fdb0..74355b8 100644
--- a/src/effects/gradients/SkGradientShader.cpp
+++ b/src/effects/gradients/SkGradientShader.cpp
@@ -825,8 +825,7 @@
GrGLGradientEffect::GrGLGradientEffect(const GrBackendEffectFactory& factory)
: INHERITED(factory)
- , fCachedYCoord(SK_ScalarMax)
- , fEffectMatrix(kCoordsType) {
+ , fCachedYCoord(SK_ScalarMax) {
}
GrGLGradientEffect::~GrGLGradientEffect() { }
@@ -883,7 +882,6 @@
if (GrGradientEffect::kTwo_ColorType == e.getColorType()){
- fEffectMatrix.setData(uman, e.getMatrix(), drawEffect, NULL);
if (GrGradientEffect::kBeforeInterp_PremulType == e.getPremulType()) {
set_mul_color_uni(uman, fColorStartUni, e.getColors(0));
set_mul_color_uni(uman, fColorEndUni, e.getColors(1));
@@ -894,7 +892,6 @@
} else if (GrGradientEffect::kThree_ColorType == e.getColorType()){
- fEffectMatrix.setData(uman, e.getMatrix(), drawEffect, NULL);
if (GrGradientEffect::kBeforeInterp_PremulType == e.getPremulType()) {
set_mul_color_uni(uman, fColorStartUni, e.getColors(0));
set_mul_color_uni(uman, fColorMidUni, e.getColors(1));
@@ -905,8 +902,6 @@
set_color_uni(uman, fColorEndUni, e.getColors(2));
}
} else {
- const GrTexture* texture = e.texture(0);
- fEffectMatrix.setData(uman, e.getMatrix(), drawEffect, texture);
SkScalar yCoord = e.getYCoord();
if (yCoord != fCachedYCoord) {
@@ -919,13 +914,8 @@
GrGLEffect::EffectKey GrGLGradientEffect::GenBaseGradientKey(const GrDrawEffect& drawEffect) {
const GrGradientEffect& e = drawEffect.castEffect<GrGradientEffect>();
- const GrTexture* texture = NULL;
- if (GrGradientEffect::kTexture_ColorType == e.getColorType()){
- texture = e.texture(0);
- }
-
- EffectKey key = GrGLEffectMatrix::GenKey(e.getMatrix(), drawEffect, kCoordsType, texture);
+ EffectKey key = 0;
if (GrGradientEffect::kTwo_ColorType == e.getColorType()) {
key |= kTwoColorKey;
@@ -940,18 +930,6 @@
return key;
}
-void GrGLGradientEffect::setupMatrix(GrGLShaderBuilder* builder,
- EffectKey key,
- SkString* fsCoordName,
- SkString* vsVaryingName,
- GrSLType* vsVaryingType) {
- fEffectMatrix.emitCodeMakeFSCoords2D(builder,
- key & kMatrixKeyMask,
- fsCoordName,
- vsVaryingName,
- vsVaryingType);
-}
-
void GrGLGradientEffect::emitColor(GrGLShaderBuilder* builder,
const char* gradientTValue,
EffectKey key,
@@ -1023,8 +1001,6 @@
const SkMatrix& matrix,
SkShader::TileMode tileMode) {
-
- fMatrix = matrix;
fIsOpaque = shader.isOpaque();
SkShader::GradientInfo info;
@@ -1055,6 +1031,7 @@
} else {
fPremulType = kAfterInterp_PremulType;
}
+ fCoordTransform.reset(kCoordSet, matrix);
} else {
// doesn't matter how this is set, just be consistent because it is part of the effect key.
fPremulType = kBeforeInterp_PremulType;
@@ -1080,9 +1057,11 @@
if (-1 != fRow) {
fYCoord = fAtlas->getYOffset(fRow) + SK_ScalarHalf *
fAtlas->getVerticalScaleFactor();
+ fCoordTransform.reset(kCoordSet, matrix, fAtlas->getTexture());
fTextureAccess.reset(fAtlas->getTexture(), params);
} else {
GrTexture* texture = GrLockAndRefCachedBitmapTexture(ctx, bitmap, ¶ms);
+ fCoordTransform.reset(kCoordSet, matrix, texture);
fTextureAccess.reset(texture, params);
fYCoord = SK_ScalarHalf;
@@ -1093,6 +1072,7 @@
}
this->addTextureAccess(&fTextureAccess);
}
+ this->addCoordTransform(&fCoordTransform);
}
GrGradientEffect::~GrGradientEffect() {
@@ -1124,7 +1104,7 @@
s.fTextureAccess.getParams().getTileModeX() &&
this->useAtlas() == s.useAtlas() &&
fYCoord == s.getYCoord() &&
- fMatrix.cheapEqualTo(s.getMatrix());
+ fCoordTransform.getMatrix().cheapEqualTo(s.fCoordTransform.getMatrix());
}
return false;
diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h
index 55a0061..d573783 100644
--- a/src/effects/gradients/SkGradientShaderPriv.h
+++ b/src/effects/gradients/SkGradientShaderPriv.h
@@ -203,8 +203,8 @@
#if SK_SUPPORT_GPU
+#include "GrCoordTransform.h"
#include "gl/GrGLEffect.h"
-#include "gl/GrGLEffectMatrix.h"
class GrEffectStage;
class GrBackendEffectFactory;
@@ -247,7 +247,6 @@
bool useAtlas() const { return SkToBool(-1 != fRow); }
SkScalar getYCoord() const { return fYCoord; };
- const SkMatrix& getMatrix() const { return fMatrix;}
virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
@@ -290,16 +289,17 @@
virtual bool onIsEqual(const GrEffect& effect) const SK_OVERRIDE;
private:
+ static const GrCoordSet kCoordSet = kLocal_GrCoordSet;
enum {
kMaxAnalyticColors = 3 // if more colors use texture
};
+ GrCoordTransform fCoordTransform;
GrTextureAccess fTextureAccess;
SkScalar fYCoord;
GrTextureStripAtlas* fAtlas;
int fRow;
- SkMatrix fMatrix;
bool fIsOpaque;
ColorType fColorType;
SkColor fColors[kMaxAnalyticColors];
@@ -320,26 +320,19 @@
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
protected:
- /**
- * Subclasses must reserve the lower kMatrixKeyBitCnt of their key for use by
- * GrGLGradientEffect.
- */
enum {
- kMatrixKeyBitCnt = GrGLEffectMatrix::kKeyBits,
- kMatrixKeyMask = (1 << kMatrixKeyBitCnt) - 1,
-
kPremulTypeKeyBitCnt = 1,
- kPremulTypeMask = 1 << kMatrixKeyBitCnt,
+ kPremulTypeMask = 1,
kPremulBeforeInterpKey = kPremulTypeMask,
- kTwoColorKey = 2 << (kMatrixKeyBitCnt + kPremulTypeKeyBitCnt),
- kThreeColorKey = 3 << (kMatrixKeyBitCnt + kPremulTypeKeyBitCnt),
+ kTwoColorKey = 2 << kPremulTypeKeyBitCnt,
+ kThreeColorKey = 3 << kPremulTypeKeyBitCnt,
kColorKeyMask = kTwoColorKey | kThreeColorKey,
kColorKeyBitCnt = 2,
// Subclasses must shift any key bits they produce up by this amount
// and combine with the result of GenBaseGradientKey.
- kBaseKeyBitCnt = (kMatrixKeyBitCnt + kPremulTypeKeyBitCnt + kColorKeyBitCnt)
+ kBaseKeyBitCnt = (kPremulTypeKeyBitCnt + kColorKeyBitCnt)
};
static GrGradientEffect::ColorType ColorTypeFromKey(EffectKey key){
@@ -364,20 +357,6 @@
*/
static EffectKey GenBaseGradientKey(const GrDrawEffect&);
- /**
- * Inserts code to implement the GrGradientEffect's matrix. This should be called before a
- * subclass emits its own code. The name of the 2D coords is output via fsCoordName and already
- * incorporates any perspective division. The caller can also optionally retrieve the name of
- * the varying inserted in the VS and its type, which may be either vec2f or vec3f depending
- * upon whether the matrix has perspective or not. It is not necessary to mask the key before
- * calling.
- */
- void setupMatrix(GrGLShaderBuilder* builder,
- EffectKey key,
- SkString* fsCoordName,
- SkString* vsVaryingName = NULL,
- GrSLType* vsVaryingType = NULL);
-
// Emits the uniform used as the y-coord to texture samples in derived classes. Subclasses
// should call this method from their emitCode().
void emitUniforms(GrGLShaderBuilder* builder, EffectKey key);
@@ -394,14 +373,11 @@
const GrGLShaderBuilder::TextureSamplerArray& samplers);
private:
- static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType;
-
SkScalar fCachedYCoord;
GrGLUniformManager::UniformHandle fFSYUni;
GrGLUniformManager::UniformHandle fColorStartUni;
GrGLUniformManager::UniformHandle fColorMidUni;
GrGLUniformManager::UniformHandle fColorEndUni;
- GrGLEffectMatrix fEffectMatrix;
typedef GrGLEffect INHERITED;
};
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp
index aa8486d..5563a03 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -448,6 +448,7 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
static EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
@@ -522,12 +523,10 @@
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
this->emitUniforms(builder, key);
- SkString coords;
- this->setupMatrix(builder, key, &coords);
- SkString t;
- t.append(coords);
+ SkString t = builder->ensureFSCoords2D(coords, 0);
t.append(".x");
this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers);
}
diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp
index 923d31f..8bac12a 100644
--- a/src/effects/gradients/SkRadialGradient.cpp
+++ b/src/effects/gradients/SkRadialGradient.cpp
@@ -481,6 +481,7 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
static EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
@@ -557,12 +558,11 @@
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
this->emitUniforms(builder, key);
- SkString coords;
- this->setupMatrix(builder, key, &coords);
SkString t("length(");
- t.append(coords);
+ t.append(builder->ensureFSCoords2D(coords, 0));
t.append(")");
this->emitColor(builder, t.c_str(), key, outputColor, inputColor, samplers);
}
diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index 65e6c96..c38205b 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -402,6 +402,7 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
static EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
@@ -471,12 +472,12 @@
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
this->emitUniforms(builder, key);
- SkString coords;
- this->setupMatrix(builder, key, &coords);
+ SkString coords2D = builder->ensureFSCoords2D(coords, 0);
SkString t;
- t.printf("atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5", coords.c_str(), coords.c_str());
+ t.printf("atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5", coords2D.c_str(), coords2D.c_str());
this->emitColor(builder, t.c_str(), key,
outputColor, inputColor, samplers);
}
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp
index 6315565..0a5e29b 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient.cpp
+++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp
@@ -347,6 +347,7 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
@@ -488,12 +489,8 @@
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
- SkString fsCoords;
- SkString vsCoordsVarying;
- GrSLType coordsVaryingType;
- this->setupMatrix(builder, key, &fsCoords, &vsCoordsVarying, &coordsVaryingType);
-
this->emitUniforms(builder, key);
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
// to work around Xoom bug. Doesn't seem to cause performance decrease
@@ -506,7 +503,7 @@
// For radial gradients without perspective we can pass the linear
// part of the quadratic as a varying.
GrGLShaderBuilder::VertexBuilder* vertexBuilder =
- (kVec2f_GrSLType == coordsVaryingType) ? builder->getVertexBuilder() : NULL;
+ (kVec2f_GrSLType == coords[0].type()) ? builder->getVertexBuilder() : NULL;
if (NULL != vertexBuilder) {
vertexBuilder->addVarying(kFloat_GrSLType, "Conical2BCoeff",
&fVSVaryingName, &fFSVaryingName);
@@ -527,13 +524,13 @@
// r2Var = -2 * (r2Parm[2] * varCoord.x - r2Param[3] * r2Param[5])
vertexBuilder->vsCodeAppendf("\t%s = -2.0 * (%s * %s.x + %s * %s);\n",
fVSVaryingName, p2.c_str(),
- vsCoordsVarying.c_str(), p3.c_str(), p5.c_str());
+ coords[0].getVSName().c_str(), p3.c_str(), p5.c_str());
}
}
// FS
{
-
+ SkString coords2D = builder->ensureFSCoords2D(coords, 0);
SkString cName("c");
SkString ac4Name("ac4");
SkString dName("d");
@@ -563,7 +560,7 @@
} else {
bVar = "b";
builder->fsCodeAppendf("\tfloat %s = -2.0 * (%s * %s.x + %s * %s);\n",
- bVar.c_str(), p2.c_str(), fsCoords.c_str(),
+ bVar.c_str(), p2.c_str(), coords2D.c_str(),
p3.c_str(), p5.c_str());
}
@@ -573,7 +570,7 @@
// c = (x^2)+(y^2) - params[4]
builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n", cName.c_str(),
- fsCoords.c_str(), fsCoords.c_str(),
+ coords2D.c_str(), coords2D.c_str(),
p4.c_str());
// Non-degenerate case (quadratic)
diff --git a/src/effects/gradients/SkTwoPointRadialGradient.cpp b/src/effects/gradients/SkTwoPointRadialGradient.cpp
index e3f5e9f..53d980a 100644
--- a/src/effects/gradients/SkTwoPointRadialGradient.cpp
+++ b/src/effects/gradients/SkTwoPointRadialGradient.cpp
@@ -389,6 +389,7 @@
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
@@ -530,15 +531,10 @@
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
this->emitUniforms(builder, key);
- SkString fsCoords;
- SkString vsCoordsVarying;
-
- GrSLType coordsVaryingType;
- this->setupMatrix(builder, key, &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
// in test apps, but need to keep an eye on it.
@@ -550,7 +546,7 @@
// For radial gradients without perspective we can pass the linear
// part of the quadratic as a varying.
GrGLShaderBuilder::VertexBuilder* vertexBuilder =
- (kVec2f_GrSLType == coordsVaryingType) ? builder->getVertexBuilder() : NULL;
+ (kVec2f_GrSLType == coords[0].type()) ? builder->getVertexBuilder() : NULL;
if (NULL != vertexBuilder) {
vertexBuilder->addVarying(kFloat_GrSLType, "Radial2BCoeff",
&fVSVaryingName, &fFSVaryingName);
@@ -569,12 +565,13 @@
// r2Var = 2 * (r2Parm[2] * varCoord.x - r2Param[3])
vertexBuilder->vsCodeAppendf("\t%s = 2.0 *(%s * %s.x - %s);\n",
fVSVaryingName, p2.c_str(),
- vsCoordsVarying.c_str(), p3.c_str());
+ coords[0].getVSName().c_str(), p3.c_str());
}
}
// FS
{
+ SkString coords2D = builder->ensureFSCoords2D(coords, 0);
SkString cName("c");
SkString ac4Name("ac4");
SkString rootName("root");
@@ -600,14 +597,14 @@
} else {
bVar = "b";
builder->fsCodeAppendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n",
- bVar.c_str(), p2.c_str(), fsCoords.c_str(), p3.c_str());
+ bVar.c_str(), p2.c_str(), coords2D.c_str(), p3.c_str());
}
// c = (x^2)+(y^2) - params[4]
builder->fsCodeAppendf("\tfloat %s = dot(%s, %s) - %s;\n",
cName.c_str(),
- fsCoords.c_str(),
- fsCoords.c_str(),
+ coords2D.c_str(),
+ coords2D.c_str(),
p4.c_str());
// If we aren't degenerate, emit some extra code, and accept a slightly