aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-01 17:02:46 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-01 17:02:46 +0000
commitd8b5faca043100d7a1e4594b4d10e462532af390 (patch)
treeb1606326d0bf74396695da623c048fe0921402db /src/effects
parent6e7251669cc57515fd2783865fc1cdd49b8b6b9a (diff)
Reland r6233 with fix.
git-svn-id: http://skia.googlecode.com/svn/trunk@6241 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/effects')
-rw-r--r--src/effects/SkBlendImageFilter.cpp40
-rw-r--r--src/effects/SkColorMatrixFilter.cpp2
-rw-r--r--src/effects/gradients/SkGradientShader.cpp33
-rw-r--r--src/effects/gradients/SkGradientShaderPriv.h39
-rw-r--r--src/effects/gradients/SkLinearGradient.cpp22
-rw-r--r--src/effects/gradients/SkRadialGradient.cpp24
-rw-r--r--src/effects/gradients/SkSweepGradient.cpp20
-rw-r--r--src/effects/gradients/SkTwoPointConicalGradient.cpp36
-rw-r--r--src/effects/gradients/SkTwoPointRadialGradient.cpp46
9 files changed, 197 insertions, 65 deletions
diff --git a/src/effects/SkBlendImageFilter.cpp b/src/effects/SkBlendImageFilter.cpp
index fb0e4d089a..9ce5726892 100644
--- a/src/effects/SkBlendImageFilter.cpp
+++ b/src/effects/SkBlendImageFilter.cpp
@@ -13,6 +13,7 @@
#include "SkGr.h"
#include "SkGrPixelRef.h"
#include "gl/GrGLEffect.h"
+#include "gl/GrGLEffectMatrix.h"
#include "GrTBackendEffectFactory.h"
#endif
@@ -127,16 +128,19 @@ public:
static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&);
+ virtual void setData(const GrGLUniformManager&, const GrEffectStage&);
+
private:
typedef GrGLEffect INHERITED;
SkBlendImageFilter::Mode fMode;
+ GrGLEffectMatrix fEffectMatrix;
};
///////////////////////////////////////////////////////////////////////////////
class GrBlendEffect : public GrSingleTextureEffect {
public:
- GrBlendEffect(SkBlendImageFilter::Mode mode, GrTexture* foreground);
+ GrBlendEffect(SkBlendImageFilter::Mode mode, GrTexture* foreground, const SkMatrix&);
virtual ~GrBlendEffect();
virtual bool isEqual(const GrEffect&) const SK_OVERRIDE;
@@ -209,17 +213,19 @@ GrTexture* SkBlendImageFilter::onFilterImageGPU(Proxy* proxy, GrTexture* src, co
foregroundTexMatrix.setIDiv(foreground->width(), foreground->height());
GrPaint paint;
paint.colorStage(0)->setEffect(
- SkNEW_ARGS(GrSingleTextureEffect, (background.get())), backgroundTexMatrix)->unref();
+ SkNEW_ARGS(GrSingleTextureEffect, (background.get(), backgroundTexMatrix)))->unref();
paint.colorStage(1)->setEffect(
- SkNEW_ARGS(GrBlendEffect, (fMode, foreground.get())), foregroundTexMatrix)->unref();
+ SkNEW_ARGS(GrBlendEffect, (fMode, foreground.get(), foregroundTexMatrix)))->unref();
context->drawRect(paint, rect);
return dst;
}
///////////////////////////////////////////////////////////////////////////////
-GrBlendEffect::GrBlendEffect(SkBlendImageFilter::Mode mode, GrTexture* foreground)
- : INHERITED(foreground), fMode(mode) {
+GrBlendEffect::GrBlendEffect(SkBlendImageFilter::Mode mode,
+ GrTexture* foreground,
+ const SkMatrix& matrix)
+ : INHERITED(foreground, matrix), fMode(mode) {
}
GrBlendEffect::~GrBlendEffect() {
@@ -227,8 +233,7 @@ GrBlendEffect::~GrBlendEffect() {
bool GrBlendEffect::isEqual(const GrEffect& sBase) const {
const GrBlendEffect& s = static_cast<const GrBlendEffect&>(sBase);
- return INHERITED::isEqual(sBase) &&
- fMode == s.fMode;
+ return INHERITED::isEqual(sBase) && fMode == s.fMode;
}
const GrBackendEffectFactory& GrBlendEffect::getFactory() const {
@@ -241,6 +246,7 @@ GrGLBlendEffect::GrGLBlendEffect(const GrBackendEffectFactory& factory,
const GrEffect& effect)
: INHERITED(factory),
fMode(static_cast<const GrBlendEffect&>(effect).mode()) {
+ fRequiresTextureMatrix = false;
}
GrGLBlendEffect::~GrGLBlendEffect() {
@@ -248,16 +254,19 @@ GrGLBlendEffect::~GrGLBlendEffect() {
void GrGLBlendEffect::emitCode(GrGLShaderBuilder* builder,
const GrEffectStage&,
- EffectKey,
+ EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
+ const char* coords;
+ GrSLType coordsType = fEffectMatrix.emitCode(builder, key, vertexCoords, &coords);
+
SkString* code = &builder->fFSCode;
const char* bgColor = inputColor;
const char* fgColor = "fgColor";
code->appendf("\t\tvec4 %s = ", fgColor);
- builder->appendTextureLookup(code, samplers[0]);
+ builder->appendTextureLookup(code, samplers[0], coords, coordsType);
code->append(";\n");
code->appendf("\t\t%s.a = 1.0 - (1.0 - %s.a) * (1.0 - %s.b);\n", outputColor, bgColor, fgColor);
switch (fMode) {
@@ -279,7 +288,16 @@ void GrGLBlendEffect::emitCode(GrGLShaderBuilder* builder,
}
}
-GrGLEffect::EffectKey GrGLBlendEffect::GenKey(const GrEffectStage& s, const GrGLCaps&) {
- return static_cast<const GrBlendEffect&>(*s.getEffect()).mode();
+void GrGLBlendEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
+ const GrBlendEffect& blend = static_cast<const GrBlendEffect&>(*stage.getEffect());
+ fEffectMatrix.setData(uman, blend.getMatrix(), stage.getCoordChangeMatrix(), blend.texture(0));
+}
+
+GrGLEffect::EffectKey GrGLBlendEffect::GenKey(const GrEffectStage& stage, const GrGLCaps&) {
+ const GrBlendEffect& blend = static_cast<const GrBlendEffect&>(*stage.getEffect());
+ EffectKey key =
+ GrGLEffectMatrix::GenKey(blend.getMatrix(), stage.getCoordChangeMatrix(), blend.texture(0));
+ key |= (blend.mode() << GrGLEffectMatrix::kKeyBits);
+ return key;
}
#endif
diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp
index 58d26735a1..fa724cad11 100644
--- a/src/effects/SkColorMatrixFilter.cpp
+++ b/src/effects/SkColorMatrixFilter.cpp
@@ -350,6 +350,8 @@ public:
: INHERITED(factory)
, fMatrixHandle(GrGLUniformManager::kInvalidUniformHandle)
, fVectorHandle(GrGLUniformManager::kInvalidUniformHandle) {
+ // no texture
+ fRequiresTextureMatrix = false;
}
virtual void emitCode(GrGLShaderBuilder* builder,
diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp
index 60eff91d65..78c7e34a74 100644
--- a/src/effects/gradients/SkGradientShader.cpp
+++ b/src/effects/gradients/SkGradientShader.cpp
@@ -678,7 +678,9 @@ SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
GrGLGradientEffect::GrGLGradientEffect(const GrBackendEffectFactory& factory)
: INHERITED(factory)
, fCachedYCoord(GR_ScalarMax)
- , fFSYUni(GrGLUniformManager::kInvalidUniformHandle) { }
+ , fFSYUni(GrGLUniformManager::kInvalidUniformHandle) {
+ fRequiresTextureMatrix = false;
+}
GrGLGradientEffect::~GrGLGradientEffect() { }
@@ -688,13 +690,37 @@ void GrGLGradientEffect::emitYCoordUniform(GrGLShaderBuilder* builder) {
}
void GrGLGradientEffect::setData(const GrGLUniformManager& uman, const GrEffectStage& stage) {
- GrScalar yCoord = static_cast<const GrGradientEffect&>(*stage.getEffect()).getYCoord();
+ const GrGradientEffect& e = static_cast<const GrGradientEffect&>(*stage.getEffect());
+ const GrTexture* texture = e.texture(0);
+ fEffectMatrix.setData(uman, e.getMatrix(), stage.getCoordChangeMatrix(), texture);
+
+ GrScalar yCoord = e.getYCoord();
if (yCoord != fCachedYCoord) {
uman.set1f(fFSYUni, yCoord);
fCachedYCoord = yCoord;
}
}
+GrGLEffect::EffectKey GrGLGradientEffect::GenMatrixKey(const GrEffectStage& s) {
+ const GrGradientEffect& e = static_cast<const GrGradientEffect&>(*s.getEffect());
+ const GrTexture* texture = e.texture(0);
+ 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);
+}
+
void GrGLGradientEffect::emitColorLookup(GrGLShaderBuilder* builder,
const char* gradientTValue,
const char* outputColor,
@@ -714,6 +740,7 @@ void GrGLGradientEffect::emitColorLookup(GrGLShaderBuilder* builder,
GrGradientEffect::GrGradientEffect(GrContext* ctx,
const SkGradientShaderBase& shader,
+ const SkMatrix& matrix,
SkShader::TileMode tileMode)
: INHERITED(1) {
// TODO: check for simple cases where we don't need a texture:
@@ -721,6 +748,8 @@ GrGradientEffect::GrGradientEffect(GrContext* ctx,
//shader.asAGradient(&info);
//if (info.fColorCount == 2) { ...
+ fMatrix = matrix;
+
SkBitmap bitmap;
shader.getGradientTableBitmap(&bitmap);
diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h
index 9f14e7f727..24379110ee 100644
--- a/src/effects/gradients/SkGradientShaderPriv.h
+++ b/src/effects/gradients/SkGradientShaderPriv.h
@@ -193,12 +193,13 @@ private:
#if SK_SUPPORT_GPU
#include "gl/GrGLEffect.h"
+#include "gl/GrGLEffectMatrix.h"
class GrEffectStage;
class GrBackendEffectFactory;
/*
- * The intepretation of the texture matrix depends on the sample mode. The
+ * The interpretation of the texture matrix depends on the sample mode. The
* texture matrix is applied both when the texture coordinates are explicit
* and when vertex positions are used as texture coordinates. In the latter
* case the texture matrix is applied to the pre-view-matrix position
@@ -228,6 +229,7 @@ public:
GrGradientEffect(GrContext* ctx,
const SkGradientShaderBase& shader,
+ const SkMatrix& matrix,
SkShader::TileMode tileMode);
virtual ~GrGradientEffect();
@@ -236,11 +238,12 @@ public:
bool useAtlas() const { return SkToBool(-1 != fRow); }
GrScalar getYCoord() const { return fYCoord; };
+ const SkMatrix& getMatrix() const { return fMatrix;}
virtual bool isEqual(const GrEffect& effect) const SK_OVERRIDE {
const GrGradientEffect& s = static_cast<const GrGradientEffect&>(effect);
return INHERITED::isEqual(effect) && this->useAtlas() == s.useAtlas() &&
- fYCoord == s.getYCoord();
+ fYCoord == s.getYCoord() && fMatrix.cheapEqualTo(s.getMatrix());
}
protected:
@@ -263,6 +266,7 @@ private:
GrScalar fYCoord;
GrTextureStripAtlas* fAtlas;
int fRow;
+ SkMatrix fMatrix;
typedef GrEffect INHERITED;
@@ -279,6 +283,36 @@ public:
virtual void setData(const GrGLUniformManager&, const GrEffectStage&) SK_OVERRIDE;
protected:
+ /**
+ * Subclasses must reserve the lower kMatrixKeyBitCnt of their key for use by
+ * GrGLGradientEffect.
+ */
+ enum {
+ kMatrixKeyBitCnt = GrGLEffectMatrix::kKeyBits,
+ kMatrixKeyMask = (1 << kMatrixKeyBitCnt) - 1,
+ };
+
+ /**
+ * Subclasses must call this. It will return a value restricted to the lower kMatrixKeyBitCnt
+ * bits.
+ */
+ static EffectKey GenMatrixKey(const GrEffectStage& s);
+
+ /**
+ * 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,
+ const char* vertexCoords,
+ const char** fsCoordName,
+ const char** 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 emitYCoordUniform(GrGLShaderBuilder* builder);
@@ -295,6 +329,7 @@ protected:
private:
GrScalar fCachedYCoord;
GrGLUniformManager::UniformHandle fFSYUni;
+ GrGLEffectMatrix fEffectMatrix;
typedef GrGLEffect INHERITED;
};
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp
index d9576565b5..71614505a1 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -495,7 +495,9 @@ public:
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
- static EffectKey GenKey(const GrEffectStage&, const GrGLCaps& caps) { return 0; }
+ static EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) {
+ return GenMatrixKey(stage);
+ }
private:
@@ -507,8 +509,11 @@ private:
class GrLinearGradient : public GrGradientEffect {
public:
- GrLinearGradient(GrContext* ctx, const SkLinearGradient& shader, SkShader::TileMode tm)
- : INHERITED(ctx, shader, tm) { }
+ GrLinearGradient(GrContext* ctx,
+ const SkLinearGradient& shader,
+ const SkMatrix& matrix,
+ SkShader::TileMode tm)
+ : INHERITED(ctx, shader, matrix, tm) { }
virtual ~GrLinearGradient() { }
static const char* Name() { return "Linear Gradient"; }
@@ -553,15 +558,18 @@ GrEffect* GrLinearGradient::TestCreate(SkRandom* random,
/////////////////////////////////////////////////////////////////////
void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder,
- const GrEffectStage&,
- EffectKey,
+ 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, vertexCoords, &coords);
SkString t;
- t.printf("%s.x", builder->defaultTexCoordsName());
+ t.append(coords);
+ t.append(".x");
this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplers[0]);
}
@@ -574,7 +582,7 @@ bool SkLinearGradient::asNewEffect(GrContext* context, GrEffectStage* stage) con
return false;
}
matrix.postConcat(fPtsToUnit);
- stage->setEffect(SkNEW_ARGS(GrLinearGradient, (context, *this, fTileMode)), matrix)->unref();
+ stage->setEffect(SkNEW_ARGS(GrLinearGradient, (context, *this, matrix, fTileMode)))->unref();
return true;
}
diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp
index a20ea35a1a..02a56da588 100644
--- a/src/effects/gradients/SkRadialGradient.cpp
+++ b/src/effects/gradients/SkRadialGradient.cpp
@@ -490,7 +490,9 @@ public:
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
- static EffectKey GenKey(const GrEffectStage&, const GrGLCaps& caps) { return 0; }
+ static EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) {
+ return GenMatrixKey(stage);
+ }
private:
@@ -503,8 +505,11 @@ private:
class GrRadialGradient : public GrGradientEffect {
public:
- GrRadialGradient(GrContext* ctx, const SkRadialGradient& shader, SkShader::TileMode tm)
- : INHERITED(ctx, shader, tm) {
+ GrRadialGradient(GrContext* ctx,
+ const SkRadialGradient& shader,
+ const SkMatrix& matrix,
+ SkShader::TileMode tm)
+ : INHERITED(ctx, shader, matrix, tm) {
}
virtual ~GrRadialGradient() { }
@@ -551,15 +556,18 @@ GrEffect* GrRadialGradient::TestCreate(SkRandom* random,
/////////////////////////////////////////////////////////////////////
void GrGLRadialGradient::emitCode(GrGLShaderBuilder* builder,
- const GrEffectStage&,
- EffectKey,
+ const GrEffectStage& stage,
+ EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
- SkString t;
- t.printf("length(%s.xy)", builder->defaultTexCoordsName());
+ const char* coords;
+ this->setupMatrix(builder, key, vertexCoords, &coords);
+ SkString t("length(");
+ t.append(coords);
+ t.append(")");
this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplers[0]);
}
@@ -573,7 +581,7 @@ bool SkRadialGradient::asNewEffect(GrContext* context, GrEffectStage* stage) con
return false;
}
matrix.postConcat(fPtsToUnit);
- stage->setEffect(SkNEW_ARGS(GrRadialGradient, (context, *this, fTileMode)), matrix)->unref();
+ stage->setEffect(SkNEW_ARGS(GrRadialGradient, (context, *this, matrix, fTileMode)))->unref();
return true;
}
diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index a783e3757c..589cf4ad14 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -399,7 +399,9 @@ public:
const char* inputColor,
const TextureSamplerArray&) SK_OVERRIDE;
- static EffectKey GenKey(const GrEffectStage&, const GrGLCaps& caps) { return 0; }
+ static EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) {
+ return GenMatrixKey(stage);
+ }
private:
@@ -413,8 +415,9 @@ class GrSweepGradient : public GrGradientEffect {
public:
GrSweepGradient(GrContext* ctx,
- const SkSweepGradient& shader)
- : INHERITED(ctx, shader, SkShader::kClamp_TileMode) { }
+ const SkSweepGradient& shader,
+ const SkMatrix& matrix)
+ : INHERITED(ctx, shader, matrix, SkShader::kClamp_TileMode) { }
virtual ~GrSweepGradient() { }
static const char* Name() { return "Sweep Gradient"; }
@@ -457,16 +460,17 @@ GrEffect* GrSweepGradient::TestCreate(SkRandom* random,
/////////////////////////////////////////////////////////////////////
void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder,
- const GrEffectStage&,
- EffectKey,
+ 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, vertexCoords, &coords);
SkString t;
- t.printf("atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5",
- builder->defaultTexCoordsName(), builder->defaultTexCoordsName());
+ t.printf("atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5", coords, coords);
this->emitColorLookup(builder, t.c_str(), outputColor, inputColor, samplers[0]);
}
@@ -478,7 +482,7 @@ bool SkSweepGradient::asNewEffect(GrContext* context, GrEffectStage* stage) cons
return false;
}
matrix.postConcat(fPtsToUnit);
- stage->setEffect(SkNEW_ARGS(GrSweepGradient, (context, *this)), matrix)->unref();
+ stage->setEffect(SkNEW_ARGS(GrSweepGradient, (context, *this, matrix)))->unref();
return true;
}
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp
index f93f660837..41292bb43a 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient.cpp
+++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp
@@ -371,8 +371,9 @@ public:
GrConical2Gradient(GrContext* ctx,
const SkTwoPointConicalGradient& shader,
+ const SkMatrix& matrix,
SkShader::TileMode tm)
- : INHERITED(ctx, shader, tm)
+ : INHERITED(ctx, shader, matrix, tm)
, fCenterX1(shader.getCenterX1())
, fRadius0(shader.getStartRadius())
, fDiffRadius(shader.getDiffRadius()) { }
@@ -468,12 +469,17 @@ GrGLConical2Gradient::GrGLConical2Gradient(
}
void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
- const GrEffectStage&,
- EffectKey,
+ const GrEffectStage& stage,
+ 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, vertexCoords, &fsCoords, &vsCoordsVarying, &coordsVaryingType);
+
this->emitYCoordUniform(builder);
// 2 copies of uniform array, 1 for each of vertex & fragment shader,
// to work around Xoom bug. Doesn't seem to cause performance decrease
@@ -485,7 +491,7 @@ void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
// For radial gradients without perspective we can pass the linear
// part of the quadratic as a varying.
- if (!builder->defaultTextureMatrixIsPerspective()) {
+ if (kVec2f_GrSLType == coordsVaryingType) {
builder->addVarying(kFloat_GrSLType, "Conical2BCoeff",
&fVSVaryingName, &fFSVaryingName);
}
@@ -502,11 +508,11 @@ void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
// For radial gradients without perspective we can pass the linear
// part of the quadratic as a varying.
- if (!builder->defaultTextureMatrixIsPerspective()) {
+ if (kVec2f_GrSLType == coordsVaryingType) {
// r2Var = -2 * (r2Parm[2] * varCoord.x - r2Param[3] * r2Param[5])
code->appendf("\t%s = -2.0 * (%s * %s.x + %s * %s);\n",
fVSVaryingName, p2.c_str(),
- vertexCoords, p3.c_str(), p5.c_str());
+ vsCoordsVarying, p3.c_str(), p5.c_str());
}
}
@@ -538,12 +544,12 @@ void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
// If we we're able to interpolate the linear component,
// bVar is the varying; otherwise compute it
SkString bVar;
- if (!builder->defaultTextureMatrixIsPerspective()) {
+ if (kVec2f_GrSLType == coordsVaryingType) {
bVar = fFSVaryingName;
} else {
bVar = "b";
code->appendf("\tfloat %s = -2.0 * (%s * %s.x + %s * %s);\n",
- bVar.c_str(), p2.c_str(), builder->defaultTexCoordsName(),
+ bVar.c_str(), p2.c_str(), fsCoords,
p3.c_str(), p5.c_str());
}
@@ -553,7 +559,7 @@ void GrGLConical2Gradient::emitCode(GrGLShaderBuilder* builder,
// c = (x^2)+(y^2) - params[4]
code->appendf("\tfloat %s = dot(%s, %s) - %s;\n", cName.c_str(),
- builder->defaultTexCoordsName(), builder->defaultTexCoordsName(),
+ fsCoords, fsCoords,
p4.c_str());
// Non-degenerate case (quadratic)
@@ -669,7 +675,15 @@ void GrGLConical2Gradient::setData(const GrGLUniformManager& uman, const GrEffec
}
GrGLEffect::EffectKey GrGLConical2Gradient::GenKey(const GrEffectStage& s, const GrGLCaps&) {
- return (static_cast<const GrConical2Gradient&>(*s.getEffect()).isDegenerate());
+ enum {
+ kIsDegenerate = 1 << kMatrixKeyBitCnt,
+ };
+
+ EffectKey key = GenMatrixKey(s);
+ if (static_cast<const GrConical2Gradient&>(*s.getEffect()).isDegenerate()) {
+ key |= kIsDegenerate;
+ }
+ return key;
}
/////////////////////////////////////////////////////////////////////
@@ -695,7 +709,7 @@ bool SkTwoPointConicalGradient::asNewEffect(GrContext* context,
matrix.postConcat(rot);
}
- stage->setEffect(SkNEW_ARGS(GrConical2Gradient, (context, *this, fTileMode)), matrix)->unref();
+ stage->setEffect(SkNEW_ARGS(GrConical2Gradient, (context, *this, matrix, fTileMode)))->unref();
return true;
}
diff --git a/src/effects/gradients/SkTwoPointRadialGradient.cpp b/src/effects/gradients/SkTwoPointRadialGradient.cpp
index 659bce0099..d0186291f2 100644
--- a/src/effects/gradients/SkTwoPointRadialGradient.cpp
+++ b/src/effects/gradients/SkTwoPointRadialGradient.cpp
@@ -404,8 +404,11 @@ private:
class GrRadial2Gradient : public GrGradientEffect {
public:
- GrRadial2Gradient(GrContext* ctx, const SkTwoPointRadialGradient& shader, SkShader::TileMode tm)
- : INHERITED(ctx, shader, tm)
+ GrRadial2Gradient(GrContext* ctx,
+ const SkTwoPointRadialGradient& shader,
+ const SkMatrix& matrix,
+ SkShader::TileMode tm)
+ : INHERITED(ctx, shader, matrix, tm)
, fCenterX1(shader.getCenterX1())
, fRadius0(shader.getStartRadius())
, fPosRoot(shader.getDiffRadius() < 0) { }
@@ -501,14 +504,19 @@ GrGLRadial2Gradient::GrGLRadial2Gradient(
}
void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
- const GrEffectStage&,
- EffectKey,
+ const GrEffectStage& stage,
+ EffectKey key,
const char* vertexCoords,
const char* outputColor,
const char* inputColor,
const TextureSamplerArray& samplers) {
this->emitYCoordUniform(builder);
+ const char* fsCoords;
+ const char* vsCoordsVarying;
+ GrSLType 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
// in test apps, but need to keep an eye on it.
@@ -519,9 +527,8 @@ void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
// For radial gradients without perspective we can pass the linear
// part of the quadratic as a varying.
- if (!builder->defaultTextureMatrixIsPerspective()) {
- builder->addVarying(kFloat_GrSLType, "Radial2BCoeff",
- &fVSVaryingName, &fFSVaryingName);
+ if (kVec2f_GrSLType == coordsVaryingType) {
+ builder->addVarying(kFloat_GrSLType, "Radial2BCoeff", &fVSVaryingName, &fFSVaryingName);
}
// VS
@@ -534,11 +541,11 @@ void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
// For radial gradients without perspective we can pass the linear
// part of the quadratic as a varying.
- if (!builder->defaultTextureMatrixIsPerspective()) {
+ if (kVec2f_GrSLType == coordsVaryingType) {
// r2Var = 2 * (r2Parm[2] * varCoord.x - r2Param[3])
code->appendf("\t%s = 2.0 *(%s * %s.x - %s);\n",
fVSVaryingName, p2.c_str(),
- vertexCoords, p3.c_str());
+ vsCoordsVarying, p3.c_str());
}
}
@@ -565,20 +572,19 @@ void GrGLRadial2Gradient::emitCode(GrGLShaderBuilder* builder,
// If we we're able to interpolate the linear component,
// bVar is the varying; otherwise compute it
SkString bVar;
- if (!builder->defaultTextureMatrixIsPerspective()) {
+ if (kVec2f_GrSLType == coordsVaryingType) {
bVar = fFSVaryingName;
} else {
bVar = "b";
code->appendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n",
- bVar.c_str(), p2.c_str(),
- builder->defaultTexCoordsName(), p3.c_str());
+ bVar.c_str(), p2.c_str(), fsCoords, p3.c_str());
}
// c = (x^2)+(y^2) - params[4]
code->appendf("\tfloat %s = dot(%s, %s) - %s;\n",
cName.c_str(),
- builder->defaultTexCoordsName(),
- builder->defaultTexCoordsName(),
+ fsCoords,
+ fsCoords,
p4.c_str());
// If we aren't degenerate, emit some extra code, and accept a slightly
@@ -643,7 +649,15 @@ void GrGLRadial2Gradient::setData(const GrGLUniformManager& uman, const GrEffect
}
GrGLEffect::EffectKey GrGLRadial2Gradient::GenKey(const GrEffectStage& s, const GrGLCaps&) {
- return (static_cast<const GrRadial2Gradient&>(*s.getEffect()).isDegenerate());
+ enum {
+ kIsDegenerate = 1 << kMatrixKeyBitCnt,
+ };
+
+ EffectKey key = GenMatrixKey(s);
+ if (static_cast<const GrRadial2Gradient&>(*s.getEffect()).isDegenerate()) {
+ key |= kIsDegenerate;
+ }
+ return key;
}
/////////////////////////////////////////////////////////////////////
@@ -667,7 +681,7 @@ bool SkTwoPointRadialGradient::asNewEffect(GrContext* context,
matrix.postConcat(rot);
}
- stage->setEffect(SkNEW_ARGS(GrRadial2Gradient, (context, *this, fTileMode)), matrix)->unref();
+ stage->setEffect(SkNEW_ARGS(GrRadial2Gradient, (context, *this, matrix, fTileMode)))->unref();
return true;
}