aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/effects
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-10-02 13:04:56 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-10-02 13:04:56 +0000
commit77af6805e5faea1e2a5c0220098aec9082f3a6e5 (patch)
treeda604c305177b007bb8a669ab753290143431ca8 /src/gpu/effects
parent693a837082404d212fd9b2c3d2ab65dd269211c9 (diff)
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
Diffstat (limited to 'src/gpu/effects')
-rw-r--r--src/gpu/effects/GrBezierEffect.cpp6
-rw-r--r--src/gpu/effects/GrBicubicEffect.cpp34
-rw-r--r--src/gpu/effects/GrBicubicEffect.h11
-rw-r--r--src/gpu/effects/GrConfigConversionEffect.cpp24
-rw-r--r--src/gpu/effects/GrConvolutionEffect.cpp20
-rw-r--r--src/gpu/effects/GrCustomCoordsTextureEffect.cpp6
-rw-r--r--src/gpu/effects/GrSimpleTextureEffect.cpp40
-rw-r--r--src/gpu/effects/GrSimpleTextureEffect.h22
-rw-r--r--src/gpu/effects/GrSingleTextureEffect.cpp24
-rw-r--r--src/gpu/effects/GrSingleTextureEffect.h23
-rw-r--r--src/gpu/effects/GrTextureDomainEffect.cpp51
-rw-r--r--src/gpu/effects/GrTextureDomainEffect.h4
12 files changed, 93 insertions, 172 deletions
diff --git a/src/gpu/effects/GrBezierEffect.cpp b/src/gpu/effects/GrBezierEffect.cpp
index b3e9f62f69..9adf59261b 100644
--- a/src/gpu/effects/GrBezierEffect.cpp
+++ b/src/gpu/effects/GrBezierEffect.cpp
@@ -20,6 +20,7 @@ public:
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
@@ -44,6 +45,7 @@ void GrGLConicEffect::emitCode(GrGLShaderBuilder* builder,
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray& samplers) {
GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuilder();
SkASSERT(NULL != vertexBuilder);
@@ -163,6 +165,7 @@ public:
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
@@ -187,6 +190,7 @@ void GrGLQuadEffect::emitCode(GrGLShaderBuilder* builder,
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray& samplers) {
GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuilder();
SkASSERT(NULL != vertexBuilder);
@@ -295,6 +299,7 @@ public:
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&);
@@ -319,6 +324,7 @@ void GrGLCubicEffect::emitCode(GrGLShaderBuilder* builder,
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray& samplers) {
GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuilder();
SkASSERT(NULL != vertexBuilder);
diff --git a/src/gpu/effects/GrBicubicEffect.cpp b/src/gpu/effects/GrBicubicEffect.cpp
index cf20d15169..ccbf78808b 100644
--- a/src/gpu/effects/GrBicubicEffect.cpp
+++ b/src/gpu/effects/GrBicubicEffect.cpp
@@ -19,10 +19,9 @@ public:
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:
@@ -31,15 +30,11 @@ private:
UniformHandle fCoefficientsUni;
UniformHandle fImageIncrementUni;
- GrGLEffectMatrix fEffectMatrix;
-
typedef GrGLEffect INHERITED;
};
-GrGLBicubicEffect::GrGLBicubicEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
- : INHERITED(factory)
- , fEffectMatrix(drawEffect.castEffect<GrBicubicEffect>().coordsType()) {
+GrGLBicubicEffect::GrGLBicubicEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
+ : INHERITED(factory) {
}
void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder,
@@ -47,9 +42,9 @@ void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder,
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);
fCoefficientsUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kMat44f_GrSLType, "Coefficients");
fImageIncrementUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
@@ -76,7 +71,7 @@ void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder,
"\tvec4 c = coefficients * ts;\n"
"\treturn c.x * c0 + c.y * c1 + c.z * c2 + c.w * c3;\n",
&cubicBlendName);
- builder->fsCodeAppendf("\tvec2 coord = %s - %s * vec2(0.5, 0.5);\n", coords.c_str(), imgInc);
+ builder->fsCodeAppendf("\tvec2 coord = %s - %s * vec2(0.5, 0.5);\n", coords2D.c_str(), imgInc);
builder->fsCodeAppendf("\tvec2 f = fract(coord / %s);\n", imgInc);
for (int y = 0; y < 4; ++y) {
for (int x = 0; x < 4; ++x) {
@@ -91,15 +86,6 @@ void GrGLBicubicEffect::emitCode(GrGLShaderBuilder* builder,
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));
- return matrixKey;
-}
-
void GrGLBicubicEffect::setData(const GrGLUniformManager& uman,
const GrDrawEffect& drawEffect) {
const GrBicubicEffect& effect = drawEffect.castEffect<GrBicubicEffect>();
@@ -109,10 +95,6 @@ void GrGLBicubicEffect::setData(const GrGLUniformManager& uman,
imageIncrement[1] = 1.0f / texture.height();
uman.set2fv(fImageIncrementUni, 0, 1, imageIncrement);
uman.setMatrix4f(fCoefficientsUni, effect.coefficients());
- fEffectMatrix.setData(uman,
- effect.getMatrix(),
- drawEffect,
- effect.texture(0));
}
GrBicubicEffect::GrBicubicEffect(GrTexture* texture,
@@ -130,8 +112,8 @@ GrBicubicEffect::GrBicubicEffect(GrTexture* texture,
const SkScalar coefficients[16],
const SkMatrix &matrix,
const GrTextureParams &params,
- CoordsType coordsType)
- : INHERITED(texture, MakeDivByTextureWHMatrix(texture), params, coordsType) {
+ GrCoordSet coordSet)
+ : INHERITED(texture, MakeDivByTextureWHMatrix(texture), params, coordSet) {
for (int y = 0; y < 4; y++) {
for (int x = 0; x < 4; x++) {
// Convert from row-major scalars to column-major floats.
diff --git a/src/gpu/effects/GrBicubicEffect.h b/src/gpu/effects/GrBicubicEffect.h
index 0a408916f1..eabc79fe56 100644
--- a/src/gpu/effects/GrBicubicEffect.h
+++ b/src/gpu/effects/GrBicubicEffect.h
@@ -11,7 +11,6 @@
#include "GrSingleTextureEffect.h"
#include "GrDrawEffect.h"
#include "gl/GrGLEffect.h"
-#include "gl/GrGLEffectMatrix.h"
#include "GrTBackendEffectFactory.h"
class GrGLBicubicEffect;
@@ -36,8 +35,8 @@ public:
static GrEffectRef* Create(GrTexture* tex, const SkScalar coefficients[16],
const SkMatrix& matrix,
const GrTextureParams& p,
- CoordsType coordsType = kLocal_CoordsType) {
- AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, coefficients, matrix, p, coordsType)));
+ GrCoordSet coordSet = kLocal_GrCoordSet) {
+ AutoEffectUnref effect(SkNEW_ARGS(GrBicubicEffect, (tex, coefficients, matrix, p, coordSet)));
return CreateEffectRef(effect);
}
@@ -48,14 +47,14 @@ public:
static GrEffectRef* Create(GrTexture* tex,
const SkMatrix& matrix,
const GrTextureParams& p,
- CoordsType coordsType = kLocal_CoordsType) {
- return Create(tex, gMitchellCoefficients, matrix, p, coordsType);
+ GrCoordSet coordSet = kLocal_GrCoordSet) {
+ return Create(tex, gMitchellCoefficients, matrix, p, coordSet);
}
private:
GrBicubicEffect(GrTexture*, const SkScalar coefficients[16]);
GrBicubicEffect(GrTexture*, const SkScalar coefficients[16],
- const SkMatrix &matrix, const GrTextureParams &p, CoordsType coordsType);
+ const SkMatrix &matrix, const GrTextureParams &p, GrCoordSet coordSet);
virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;
float fCoefficients[16];
diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp
index 935e074e03..daf51414f2 100644
--- a/src/gpu/effects/GrConfigConversionEffect.cpp
+++ b/src/gpu/effects/GrConfigConversionEffect.cpp
@@ -10,15 +10,13 @@
#include "GrTBackendEffectFactory.h"
#include "GrSimpleTextureEffect.h"
#include "gl/GrGLEffect.h"
-#include "gl/GrGLEffectMatrix.h"
#include "SkMatrix.h"
class GrGLConfigConversionEffect : public GrGLEffect {
public:
GrGLConfigConversionEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
- : INHERITED (factory)
- , fEffectMatrix(drawEffect.castEffect<GrConfigConversionEffect>().coordsType()) {
+ : INHERITED (factory) {
const GrConfigConversionEffect& effect = drawEffect.castEffect<GrConfigConversionEffect>();
fSwapRedAndBlue = effect.swapsRedAndBlue();
fPMConversion = effect.pmConversion();
@@ -29,11 +27,10 @@ public:
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) SK_OVERRIDE {
- SkString coords;
- GrSLType coordsType = fEffectMatrix.emitCode(builder, key, &coords);
builder->fsCodeAppendf("\t\t%s = ", outputColor);
- builder->fsAppendTextureLookup(samplers[0], coords.c_str(), coordsType);
+ builder->fsAppendTextureLookup(samplers[0], coords[0].c_str(), coords[0].type());
builder->fsCodeAppend(";\n");
if (GrConfigConversionEffect::kNone_PMConversion == fPMConversion) {
SkASSERT(fSwapRedAndBlue);
@@ -73,27 +70,14 @@ public:
builder->fsCodeAppend(modulate.c_str());
}
- void setData(const GrGLUniformManager& uman, const GrDrawEffect& drawEffect) {
- const GrConfigConversionEffect& conv = drawEffect.castEffect<GrConfigConversionEffect>();
- fEffectMatrix.setData(uman, conv.getMatrix(), drawEffect, conv.texture(0));
- }
-
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);
- key <<= GrGLEffectMatrix::kKeyBits;
- EffectKey matrixKey = GrGLEffectMatrix::GenKey(conv.getMatrix(),
- drawEffect,
- conv.coordsType(),
- conv.texture(0));
- SkASSERT(!(matrixKey & key));
- return matrixKey | key;
+ return static_cast<EffectKey>(conv.swapsRedAndBlue()) | (conv.pmConversion() << 1);
}
private:
bool fSwapRedAndBlue;
GrConfigConversionEffect::PMConversion fPMConversion;
- GrGLEffectMatrix fEffectMatrix;
typedef GrGLEffect INHERITED;
diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp
index 19fed1cfbd..4d16361fe5 100644
--- a/src/gpu/effects/GrConvolutionEffect.cpp
+++ b/src/gpu/effects/GrConvolutionEffect.cpp
@@ -7,7 +7,6 @@
#include "GrConvolutionEffect.h"
#include "gl/GrGLEffect.h"
-#include "gl/GrGLEffectMatrix.h"
#include "gl/GrGLSL.h"
#include "gl/GrGLTexture.h"
#include "GrTBackendEffectFactory.h"
@@ -24,6 +23,7 @@ public:
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager& uman, const GrDrawEffect&) SK_OVERRIDE;
@@ -41,15 +41,13 @@ private:
UniformHandle fKernelUni;
UniformHandle fImageIncrementUni;
UniformHandle fBoundsUni;
- GrGLEffectMatrix fEffectMatrix;
typedef GrGLEffect INHERITED;
};
GrGLConvolutionEffect::GrGLConvolutionEffect(const GrBackendEffectFactory& factory,
const GrDrawEffect& drawEffect)
- : INHERITED(factory)
- , fEffectMatrix(drawEffect.castEffect<GrConvolutionEffect>().coordsType()) {
+ : INHERITED(factory) {
const GrConvolutionEffect& c = drawEffect.castEffect<GrConvolutionEffect>();
fRadius = c.radius();
fUseBounds = c.useBounds();
@@ -61,9 +59,9 @@ void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
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");
if (this->useBounds()) {
@@ -79,7 +77,7 @@ void GrGLConvolutionEffect::emitCode(GrGLShaderBuilder* builder,
const GrGLShaderVar& kernel = builder->getUniformVariable(fKernelUni);
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);
// Manually unroll loop because some drivers don't; yields 20-30% speedup.
for (int i = 0; i < width; i++) {
@@ -133,7 +131,6 @@ void GrGLConvolutionEffect::setData(const GrGLUniformManager& uman,
}
}
uman.set1fv(fKernelUni, 0, this->width(), conv.kernel());
- fEffectMatrix.setData(uman, conv.getMatrix(), drawEffect, conv.texture(0));
}
GrGLEffect::EffectKey GrGLConvolutionEffect::GenKey(const GrDrawEffect& drawEffect,
@@ -145,12 +142,7 @@ GrGLEffect::EffectKey GrGLConvolutionEffect::GenKey(const GrDrawEffect& drawEffe
key |= 0x2;
key |= GrConvolutionEffect::kY_Direction == conv.direction() ? 0x1 : 0x0;
}
- key <<= GrGLEffectMatrix::kKeyBits;
- EffectKey matrixKey = GrGLEffectMatrix::GenKey(conv.getMatrix(),
- drawEffect,
- conv.coordsType(),
- conv.texture(0));
- return key | matrixKey;
+ return key;
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/effects/GrCustomCoordsTextureEffect.cpp b/src/gpu/effects/GrCustomCoordsTextureEffect.cpp
index a5c28c5c4d..b14de8bd34 100644
--- a/src/gpu/effects/GrCustomCoordsTextureEffect.cpp
+++ b/src/gpu/effects/GrCustomCoordsTextureEffect.cpp
@@ -7,7 +7,6 @@
#include "GrCustomCoordsTextureEffect.h"
#include "gl/GrGLEffect.h"
-#include "gl/GrGLEffectMatrix.h"
#include "gl/GrGLSL.h"
#include "gl/GrGLTexture.h"
#include "GrTBackendEffectFactory.h"
@@ -23,6 +22,7 @@ public:
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray& samplers) SK_OVERRIDE {
GrGLShaderBuilder::VertexBuilder* vertexBuilder = builder->getVertexBuilder();
SkASSERT(NULL != vertexBuilder);
@@ -46,10 +46,6 @@ public:
builder->fsCodeAppend(";\n");
}
- static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
- return 1 << GrGLEffectMatrix::kKeyBits;
- }
-
virtual void setData(const GrGLUniformManager& uman,
const GrDrawEffect& drawEffect) SK_OVERRIDE {}
diff --git a/src/gpu/effects/GrSimpleTextureEffect.cpp b/src/gpu/effects/GrSimpleTextureEffect.cpp
index 0ee6f78dd5..b27b737f39 100644
--- a/src/gpu/effects/GrSimpleTextureEffect.cpp
+++ b/src/gpu/effects/GrSimpleTextureEffect.cpp
@@ -7,7 +7,6 @@
#include "GrSimpleTextureEffect.h"
#include "gl/GrGLEffect.h"
-#include "gl/GrGLEffectMatrix.h"
#include "gl/GrGLSL.h"
#include "gl/GrGLTexture.h"
#include "GrTBackendEffectFactory.h"
@@ -15,9 +14,8 @@
class GrGLSimpleTextureEffect : public GrGLEffect {
public:
- GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrDrawEffect& drawEffect)
- : INHERITED (factory)
- , fEffectMatrix(drawEffect.castEffect<GrSimpleTextureEffect>().coordsType()) {
+ GrGLSimpleTextureEffect(const GrBackendEffectFactory& factory, const GrDrawEffect&)
+ : INHERITED (factory) {
}
virtual void emitCode(GrGLShaderBuilder* builder,
@@ -25,35 +23,17 @@ public:
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) SK_OVERRIDE {
- SkString fsCoordName;
- GrSLType fsCoordSLType;
- fsCoordSLType = fEffectMatrix.emitCode(builder, key, &fsCoordName);
-
builder->fsCodeAppendf("\t%s = ", outputColor);
builder->fsAppendTextureLookupAndModulate(inputColor,
samplers[0],
- fsCoordName.c_str(),
- fsCoordSLType);
+ coords[0].c_str(),
+ coords[0].type());
builder->fsCodeAppend(";\n");
}
- static inline EffectKey GenKey(const GrDrawEffect& drawEffect, const GrGLCaps&) {
- const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTextureEffect>();
- return GrGLEffectMatrix::GenKey(ste.getMatrix(),
- drawEffect,
- ste.coordsType(),
- ste.texture(0));
- }
-
- virtual void setData(const GrGLUniformManager& uman,
- const GrDrawEffect& drawEffect) SK_OVERRIDE {
- const GrSimpleTextureEffect& ste = drawEffect.castEffect<GrSimpleTextureEffect>();
- fEffectMatrix.setData(uman, ste.getMatrix(), drawEffect, ste.texture(0));
- }
-
private:
- GrGLEffectMatrix fEffectMatrix;
typedef GrGLEffect INHERITED;
};
@@ -89,12 +69,12 @@ GrEffectRef* GrSimpleTextureEffect::TestCreate(SkRandom* random,
GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBilerp_FilterMode :
GrTextureParams::kNone_FilterMode);
- static const CoordsType kCoordsTypes[] = {
- kLocal_CoordsType,
- kPosition_CoordsType
+ static const GrCoordSet kCoordSets[] = {
+ kLocal_GrCoordSet,
+ kPosition_GrCoordSet
};
- CoordsType coordsType = kCoordsTypes[random->nextULessThan(GR_ARRAY_COUNT(kCoordsTypes))];
+ GrCoordSet coordSet = kCoordSets[random->nextULessThan(GR_ARRAY_COUNT(kCoordSets))];
const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
- return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordsType);
+ return GrSimpleTextureEffect::Create(textures[texIdx], matrix, coordSet);
}
diff --git a/src/gpu/effects/GrSimpleTextureEffect.h b/src/gpu/effects/GrSimpleTextureEffect.h
index c694197206..c326ccf4c8 100644
--- a/src/gpu/effects/GrSimpleTextureEffect.h
+++ b/src/gpu/effects/GrSimpleTextureEffect.h
@@ -25,8 +25,8 @@ public:
/* unfiltered, clamp mode */
static GrEffectRef* Create(GrTexture* tex,
const SkMatrix& matrix,
- CoordsType coordsType = kLocal_CoordsType) {
- AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, GrTextureParams::kNone_FilterMode, coordsType)));
+ GrCoordSet coordSet = kLocal_GrCoordSet) {
+ AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, GrTextureParams::kNone_FilterMode, coordSet)));
return CreateEffectRef(effect);
}
@@ -34,17 +34,17 @@ public:
static GrEffectRef* Create(GrTexture* tex,
const SkMatrix& matrix,
GrTextureParams::FilterMode filterMode,
- CoordsType coordsType = kLocal_CoordsType) {
+ GrCoordSet coordSet = kLocal_GrCoordSet) {
AutoEffectUnref effect(
- SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, filterMode, coordsType)));
+ SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, filterMode, coordSet)));
return CreateEffectRef(effect);
}
static GrEffectRef* Create(GrTexture* tex,
const SkMatrix& matrix,
const GrTextureParams& p,
- CoordsType coordsType = kLocal_CoordsType) {
- AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, p, coordsType)));
+ GrCoordSet coordSet = kLocal_GrCoordSet) {
+ AutoEffectUnref effect(SkNEW_ARGS(GrSimpleTextureEffect, (tex, matrix, p, coordSet)));
return CreateEffectRef(effect);
}
@@ -62,20 +62,20 @@ private:
GrSimpleTextureEffect(GrTexture* texture,
const SkMatrix& matrix,
GrTextureParams::FilterMode filterMode,
- CoordsType coordsType)
- : GrSingleTextureEffect(texture, matrix, filterMode, coordsType) {
+ GrCoordSet coordSet)
+ : GrSingleTextureEffect(texture, matrix, filterMode, coordSet) {
}
GrSimpleTextureEffect(GrTexture* texture,
const SkMatrix& matrix,
const GrTextureParams& params,
- CoordsType coordsType)
- : GrSingleTextureEffect(texture, matrix, params, coordsType) {
+ GrCoordSet coordSet)
+ : GrSingleTextureEffect(texture, matrix, params, coordSet) {
}
virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE {
const GrSimpleTextureEffect& ste = CastEffect<GrSimpleTextureEffect>(other);
- return this->hasSameTextureParamsMatrixAndCoordsType(ste);
+ return this->hasSameTextureParamsMatrixAndSourceCoords(ste);
}
GR_DECLARE_EFFECT_TEST;
diff --git a/src/gpu/effects/GrSingleTextureEffect.cpp b/src/gpu/effects/GrSingleTextureEffect.cpp
index 532ce04217..3ab5e3ae05 100644
--- a/src/gpu/effects/GrSingleTextureEffect.cpp
+++ b/src/gpu/effects/GrSingleTextureEffect.cpp
@@ -9,30 +9,30 @@
GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture,
const SkMatrix& m,
- CoordsType coordsType)
- : fTextureAccess(texture)
- , fMatrix(m)
- , fCoordsType(coordsType) {
+ GrCoordSet coordSet)
+ : fCoordTransform(coordSet, m, texture)
+ , fTextureAccess(texture) {
+ this->addCoordTransform(&fCoordTransform);
this->addTextureAccess(&fTextureAccess);
}
GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture,
const SkMatrix& m,
GrTextureParams::FilterMode filterMode,
- CoordsType coordsType)
- : fTextureAccess(texture, filterMode)
- , fMatrix(m)
- , fCoordsType(coordsType) {
+ GrCoordSet coordSet)
+ : fCoordTransform(coordSet, m, texture)
+ , fTextureAccess(texture, filterMode) {
+ this->addCoordTransform(&fCoordTransform);
this->addTextureAccess(&fTextureAccess);
}
GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture,
const SkMatrix& m,
const GrTextureParams& params,
- CoordsType coordsType)
- : fTextureAccess(texture, params)
- , fMatrix(m)
- , fCoordsType(coordsType) {
+ GrCoordSet coordSet)
+ : fCoordTransform(coordSet, m, texture)
+ , fTextureAccess(texture, params) {
+ this->addCoordTransform(&fCoordTransform);
this->addTextureAccess(&fTextureAccess);
}
diff --git a/src/gpu/effects/GrSingleTextureEffect.h b/src/gpu/effects/GrSingleTextureEffect.h
index 27a7d7956d..a8f9a6d521 100644
--- a/src/gpu/effects/GrSingleTextureEffect.h
+++ b/src/gpu/effects/GrSingleTextureEffect.h
@@ -10,6 +10,7 @@
#include "GrEffect.h"
#include "SkMatrix.h"
+#include "GrCoordTransform.h"
class GrTexture;
@@ -21,30 +22,25 @@ class GrSingleTextureEffect : public GrEffect {
public:
virtual ~GrSingleTextureEffect();
- 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);
+ GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrCoordSet = kLocal_GrCoordSet);
/** clamp mode */
GrSingleTextureEffect(GrTexture*, const SkMatrix&, GrTextureParams::FilterMode filterMode,
- CoordsType = kLocal_CoordsType);
+ GrCoordSet = kLocal_GrCoordSet);
GrSingleTextureEffect(GrTexture*,
const SkMatrix&,
const GrTextureParams&,
- CoordsType = kLocal_CoordsType);
+ GrCoordSet = kLocal_GrCoordSet);
/**
* Helper for subclass onIsEqual() functions.
*/
- bool hasSameTextureParamsMatrixAndCoordsType(const GrSingleTextureEffect& other) const {
+ bool hasSameTextureParamsMatrixAndSourceCoords(const GrSingleTextureEffect& other) const {
// We don't have to check the accesses' swizzles because they are inferred from the texture.
return fTextureAccess == other.fTextureAccess &&
- this->getMatrix().cheapEqualTo(other.getMatrix()) &&
- fCoordsType == other.fCoordsType;
+ fCoordTransform.getMatrix().cheapEqualTo(other.fCoordTransform.getMatrix()) &&
+ fCoordTransform.sourceCoords() == other.fCoordTransform.sourceCoords();
}
/**
@@ -62,9 +58,8 @@ protected:
}
private:
- GrTextureAccess fTextureAccess;
- SkMatrix fMatrix;
- CoordsType fCoordsType;
+ GrCoordTransform fCoordTransform;
+ GrTextureAccess fTextureAccess;
typedef GrEffect INHERITED;
};
diff --git a/src/gpu/effects/GrTextureDomainEffect.cpp b/src/gpu/effects/GrTextureDomainEffect.cpp
index 59bd9099a4..eca99d73a8 100644
--- a/src/gpu/effects/GrTextureDomainEffect.cpp
+++ b/src/gpu/effects/GrTextureDomainEffect.cpp
@@ -9,7 +9,6 @@
#include "GrSimpleTextureEffect.h"
#include "GrTBackendEffectFactory.h"
#include "gl/GrGLEffect.h"
-#include "gl/GrGLEffectMatrix.h"
#include "SkFloatingPoint.h"
class GrGLTextureDomainEffect : public GrGLEffect {
@@ -21,6 +20,7 @@ public:
EffectKey,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray&,
const TextureSamplerArray&) SK_OVERRIDE;
virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE;
@@ -29,16 +29,14 @@ public:
private:
GrGLUniformManager::UniformHandle fNameUni;
- GrGLEffectMatrix fEffectMatrix;
GrGLfloat fPrevDomain[4];
typedef GrGLEffect INHERITED;
};
GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrBackendEffectFactory& factory,
- const GrDrawEffect& drawEffect)
- : INHERITED(factory)
- , fEffectMatrix(drawEffect.castEffect<GrTextureDomainEffect>().coordsType()) {
+ const GrDrawEffect&)
+ : INHERITED(factory) {
fPrevDomain[0] = SK_FloatNaN;
}
@@ -47,18 +45,18 @@ void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
EffectKey key,
const char* outputColor,
const char* inputColor,
+ const TransformedCoordsArray& coords,
const TextureSamplerArray& samplers) {
const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainEffect>();
- SkString coords;
- fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords);
+ SkString coords2D = builder->ensureFSCoords2D(coords, 0);
const char* domain;
fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
kVec4f_GrSLType, "TexDom", &domain);
if (GrTextureDomainEffect::kClamp_WrapMode == texDom.wrapMode()) {
builder->fsCodeAppendf("\tvec2 clampCoord = clamp(%s, %s.xy, %s.zw);\n",
- coords.c_str(), domain, domain);
+ coords2D.c_str(), domain, domain);
builder->fsCodeAppendf("\t%s = ", outputColor);
builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], "clampCoord");
@@ -75,21 +73,21 @@ void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
// result=white;" code fails to compile.
builder->fsCodeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0);\n");
builder->fsCodeAppend("\tvec4 inside = ");
- builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], coords.c_str());
+ builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], coords2D.c_str());
builder->fsCodeAppend(";\n");
builder->fsCodeAppendf("\tfloat x = abs(2.0*(%s.x - %s.x)/(%s.z - %s.x) - 1.0);\n",
- coords.c_str(), domain, domain, domain);
+ coords2D.c_str(), domain, domain, domain);
builder->fsCodeAppendf("\tfloat y = abs(2.0*(%s.y - %s.y)/(%s.w - %s.y) - 1.0);\n",
- coords.c_str(), domain, domain, domain);
+ coords2D.c_str(), domain, domain, domain);
builder->fsCodeAppend("\tfloat blend = step(1.0, max(x, y));\n");
builder->fsCodeAppendf("\t%s = mix(inside, outside, blend);\n", outputColor);
} else {
builder->fsCodeAppend("\tbvec4 outside;\n");
- builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", coords.c_str(), domain);
- builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", coords.c_str(), domain);
+ builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", coords2D.c_str(), domain);
+ builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", coords2D.c_str(), domain);
builder->fsCodeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.0) : ", outputColor);
- builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], coords.c_str());
+ builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], coords2D.c_str());
builder->fsCodeAppend(";\n");
}
}
@@ -118,22 +116,11 @@ void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman,
uman.set4fv(fNameUni, 0, 1, values);
memcpy(fPrevDomain, values, 4 * sizeof(GrGLfloat));
}
- fEffectMatrix.setData(uman,
- texDom.getMatrix(),
- drawEffect,
- texDom.texture(0));
}
GrGLEffect::EffectKey GrGLTextureDomainEffect::GenKey(const GrDrawEffect& drawEffect,
const GrGLCaps&) {
- const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainEffect>();
- EffectKey key = texDom.wrapMode();
- key <<= GrGLEffectMatrix::kKeyBits;
- EffectKey matrixKey = GrGLEffectMatrix::GenKey(texDom.getMatrix(),
- drawEffect,
- texDom.coordsType(),
- texDom.texture(0));
- return key | matrixKey;
+ return drawEffect.castEffect<GrTextureDomainEffect>().wrapMode();
}
@@ -144,7 +131,7 @@ GrEffectRef* GrTextureDomainEffect::Create(GrTexture* texture,
const SkRect& domain,
WrapMode wrapMode,
GrTextureParams::FilterMode filterMode,
- CoordsType coordsType) {
+ GrCoordSet coordSet) {
static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1};
if (kClamp_WrapMode == wrapMode && domain.contains(kFullRect)) {
return GrSimpleTextureEffect::Create(texture, matrix, filterMode);
@@ -167,7 +154,7 @@ GrEffectRef* GrTextureDomainEffect::Create(GrTexture* texture,
clippedDomain,
wrapMode,
filterMode,
- coordsType)));
+ coordSet)));
return CreateEffectRef(effect);
}
@@ -178,8 +165,8 @@ GrTextureDomainEffect::GrTextureDomainEffect(GrTexture* texture,
const SkRect& domain,
WrapMode wrapMode,
GrTextureParams::FilterMode filterMode,
- CoordsType coordsType)
- : GrSingleTextureEffect(texture, matrix, filterMode, coordsType)
+ GrCoordSet coordSet)
+ : GrSingleTextureEffect(texture, matrix, filterMode, coordSet)
, fWrapMode(wrapMode)
, fTextureDomain(domain) {
}
@@ -194,7 +181,7 @@ const GrBackendEffectFactory& GrTextureDomainEffect::getFactory() const {
bool GrTextureDomainEffect::onIsEqual(const GrEffect& sBase) const {
const GrTextureDomainEffect& s = CastEffect<GrTextureDomainEffect>(sBase);
- return this->hasSameTextureParamsMatrixAndCoordsType(s) &&
+ return this->hasSameTextureParamsMatrixAndSourceCoords(s) &&
this->fTextureDomain == s.fTextureDomain;
}
@@ -224,7 +211,7 @@ GrEffectRef* GrTextureDomainEffect::TestCreate(SkRandom* random,
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;
+ GrCoordSet coords = random->nextBool() ? kLocal_GrCoordSet : kPosition_GrCoordSet;
return GrTextureDomainEffect::Create(textures[texIdx],
matrix,
domain,
diff --git a/src/gpu/effects/GrTextureDomainEffect.h b/src/gpu/effects/GrTextureDomainEffect.h
index d07f2fc006..46ee2a6506 100644
--- a/src/gpu/effects/GrTextureDomainEffect.h
+++ b/src/gpu/effects/GrTextureDomainEffect.h
@@ -39,7 +39,7 @@ public:
const SkRect& domain,
WrapMode,
GrTextureParams::FilterMode filterMode,
- CoordsType = kLocal_CoordsType);
+ GrCoordSet = kLocal_GrCoordSet);
virtual ~GrTextureDomainEffect();
@@ -77,7 +77,7 @@ private:
const SkRect& domain,
WrapMode,
GrTextureParams::FilterMode filterMode,
- CoordsType type);
+ GrCoordSet);
virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE;