aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects/SkBitmapAlphaThresholdShader.cpp
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/effects/SkBitmapAlphaThresholdShader.cpp
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/effects/SkBitmapAlphaThresholdShader.cpp')
-rw-r--r--src/effects/SkBitmapAlphaThresholdShader.cpp70
1 files changed, 20 insertions, 50 deletions
diff --git a/src/effects/SkBitmapAlphaThresholdShader.cpp b/src/effects/SkBitmapAlphaThresholdShader.cpp
index 84cdbf262b..c8db3a56ca 100644
--- a/src/effects/SkBitmapAlphaThresholdShader.cpp
+++ b/src/effects/SkBitmapAlphaThresholdShader.cpp
@@ -62,9 +62,9 @@ void BATShader::toString(SkString* str) const {
#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 @@ public:
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 @@ public:
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 @@ private:
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 @@ private:
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;
};