Chromium Code Reviews| Index: src/effects/gradients/SkGradientShaderPriv.h |
| diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h |
| index 31cc9f26171c6184b4535004ea1388d2de024bc4..9c534bc9a32764cb18be7bec8f13e30ddedfc5db 100644 |
| --- a/src/effects/gradients/SkGradientShaderPriv.h |
| +++ b/src/effects/gradients/SkGradientShaderPriv.h |
| @@ -250,6 +250,19 @@ public: |
| const SkMatrix& getMatrix() const { return fMatrix;} |
| virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; |
| + |
| + enum ColorType{ |
| + kTwo_ColorType, |
| + kThree_ColorType, |
| + kTexture_ColorType |
| + }; |
| + |
| + inline int getNumColors() const { return fNumColors; }; |
|
bsalomon
2013/08/13 21:07:52
Do we need fNumColors or can we just store ColorTy
|
| + inline ColorType getColorType() const { |
| + if (2 == fNumColors) {return kTwo_ColorType;} |
| + else if (3 == fNumColors) {return kThree_ColorType;} |
| + else {return kTexture_ColorType;} |
| + } |
| protected: |
| @@ -276,6 +289,7 @@ private: |
| int fRow; |
| SkMatrix fMatrix; |
| bool fIsOpaque; |
| + int fNumColors; |
| typedef GrEffect INHERITED; |
| @@ -299,13 +313,25 @@ protected: |
| enum { |
| kMatrixKeyBitCnt = GrGLEffectMatrix::kKeyBits, |
| kMatrixKeyMask = (1 << kMatrixKeyBitCnt) - 1, |
| + |
| + kTwoColorKey = 2 << kMatrixKeyBitCnt, |
| + kThreeColorKey = 3 << kMatrixKeyBitCnt, |
| + kColorKeyMask = kThreeColorKey |
|
bsalomon
2013/08/13 21:07:52
maybe kTwoColorKey | kThreeColorKey... I realize t
dierk
2013/08/14 21:33:15
Done.
|
| }; |
| + inline GrGradientEffect::ColorType getColorType(EffectKey key){ |
|
bsalomon
2013/08/13 21:07:52
static?
dierk
2013/08/14 21:33:15
Done.
|
| + if (kTwoColorKey == (key & kColorKeyMask)) { |
| + return GrGradientEffect::kTwo_ColorType; |
| + } else if (kThreeColorKey == (key & kColorKeyMask)) { |
| + return GrGradientEffect::kThree_ColorType; |
| + } else {return GrGradientEffect::kTexture_ColorType;} |
| + } |
| + |
| /** |
| * Subclasses must call this. It will return a value restricted to the lower kMatrixKeyBitCnt |
| * bits. |
| */ |
| - static EffectKey GenMatrixKey(const GrDrawEffect&); |
| + static EffectKey GenBaseGradientKey(const GrDrawEffect&); |
| /** |
| * Inserts code to implement the GrGradientEffect's matrix. This should be called before a |
| @@ -323,22 +349,27 @@ protected: |
| // 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); |
| + void emitUniforms(GrGLShaderBuilder* builder, EffectKey key); |
| + |
| - // emit code that gets a fragment's color from an expression for t; for now this always uses the |
| - // texture, but for simpler cases we'll be able to lerp. Subclasses should call this method from |
| - // their emitCode(). |
| - void emitColorLookup(GrGLShaderBuilder* builder, |
| - const char* gradientTValue, |
| - const char* outputColor, |
| - const char* inputColor, |
| - const GrGLShaderBuilder::TextureSampler&); |
| + // emit code that gets a fragment's color from an expression for t; Has branches for 3 separate |
| + // control flows inside -- 2 color gradients, 3 color symmetric gradients (both using |
| + // native GLSL mix), and 4+ color gradients that use the traditional texture lookup. |
| + void emitColor(GrGLShaderBuilder* builder, |
| + const char* gradientTValue, |
| + EffectKey key, |
| + const char* outputColor, |
| + const char* inputColor, |
| + 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; |