| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkGradientShaderPriv_DEFINED | 8 #ifndef SkGradientShaderPriv_DEFINED |
| 9 #define SkGradientShaderPriv_DEFINED | 9 #define SkGradientShaderPriv_DEFINED |
| 10 | 10 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 | 372 |
| 373 // Base class for GL gradient effects | 373 // Base class for GL gradient effects |
| 374 class GrGLGradientEffect : public GrGLEffect { | 374 class GrGLGradientEffect : public GrGLEffect { |
| 375 public: | 375 public: |
| 376 GrGLGradientEffect(const GrBackendEffectFactory& factory); | 376 GrGLGradientEffect(const GrBackendEffectFactory& factory); |
| 377 virtual ~GrGLGradientEffect(); | 377 virtual ~GrGLGradientEffect(); |
| 378 | 378 |
| 379 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 379 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; |
| 380 | 380 |
| 381 protected: | 381 protected: |
| 382 /** |
| 383 * Subclasses must call this. It will return a key for the part of the shade
r code controlled |
| 384 * by the base class. The subclasses must stick it in their key and then pas
s it to the below |
| 385 * emit* functions from their emitCode function. |
| 386 */ |
| 387 static uint32_t GenBaseGradientKey(const GrDrawEffect&); |
| 388 |
| 389 // Emits the uniform used as the y-coord to texture samples in derived class
es. Subclasses |
| 390 // should call this method from their emitCode(). |
| 391 void emitUniforms(GrGLShaderBuilder* builder, uint32_t baseKey); |
| 392 |
| 393 |
| 394 // emit code that gets a fragment's color from an expression for t; Has bran
ches for 3 separate |
| 395 // control flows inside -- 2 color gradients, 3 color symmetric gradients (b
oth using |
| 396 // native GLSL mix), and 4+ color gradients that use the traditional texture
lookup. |
| 397 void emitColor(GrGLShaderBuilder* builder, |
| 398 const char* gradientTValue, |
| 399 uint32_t baseKey, |
| 400 const char* outputColor, |
| 401 const char* inputColor, |
| 402 const TextureSamplerArray& samplers); |
| 403 |
| 404 private: |
| 382 enum { | 405 enum { |
| 383 kPremulTypeKeyBitCnt = 1, | 406 kPremulTypeKeyBitCnt = 1, |
| 384 kPremulTypeMask = 1, | 407 kPremulTypeMask = 1, |
| 385 kPremulBeforeInterpKey = kPremulTypeMask, | 408 kPremulBeforeInterpKey = kPremulTypeMask, |
| 386 | 409 |
| 387 kTwoColorKey = 2 << kPremulTypeKeyBitCnt, | 410 kTwoColorKey = 2 << kPremulTypeKeyBitCnt, |
| 388 kThreeColorKey = 3 << kPremulTypeKeyBitCnt, | 411 kThreeColorKey = 3 << kPremulTypeKeyBitCnt, |
| 389 kColorKeyMask = kTwoColorKey | kThreeColorKey, | 412 kColorKeyMask = kTwoColorKey | kThreeColorKey, |
| 390 kColorKeyBitCnt = 2, | 413 kColorKeyBitCnt = 2, |
| 391 | 414 |
| 392 // Subclasses must shift any key bits they produce up by this amount | 415 // Subclasses must shift any key bits they produce up by this amount |
| 393 // and combine with the result of GenBaseGradientKey. | 416 // and combine with the result of GenBaseGradientKey. |
| 394 kBaseKeyBitCnt = (kPremulTypeKeyBitCnt + kColorKeyBitCnt) | 417 kBaseKeyBitCnt = (kPremulTypeKeyBitCnt + kColorKeyBitCnt) |
| 395 }; | 418 }; |
| 419 GR_STATIC_ASSERT(kBaseKeyBitCnt <= 32); |
| 396 | 420 |
| 397 static SkGradientShaderBase::GpuColorType ColorTypeFromKey(EffectKey key){ | 421 static SkGradientShaderBase::GpuColorType ColorTypeFromKey(uint32_t baseKey)
{ |
| 398 if (kTwoColorKey == (key & kColorKeyMask)) { | 422 if (kTwoColorKey == (baseKey & kColorKeyMask)) { |
| 399 return SkGradientShaderBase::kTwo_GpuColorType; | 423 return SkGradientShaderBase::kTwo_GpuColorType; |
| 400 } else if (kThreeColorKey == (key & kColorKeyMask)) { | 424 } else if (kThreeColorKey == (baseKey & kColorKeyMask)) { |
| 401 return SkGradientShaderBase::kThree_GpuColorType; | 425 return SkGradientShaderBase::kThree_GpuColorType; |
| 402 } else {return SkGradientShaderBase::kTexture_GpuColorType;} | 426 } else {return SkGradientShaderBase::kTexture_GpuColorType;} |
| 403 } | 427 } |
| 404 | 428 |
| 405 static GrGradientEffect::PremulType PremulTypeFromKey(EffectKey key){ | 429 static GrGradientEffect::PremulType PremulTypeFromKey(uint32_t baseKey){ |
| 406 if (kPremulBeforeInterpKey == (key & kPremulTypeMask)) { | 430 if (kPremulBeforeInterpKey == (baseKey & kPremulTypeMask)) { |
| 407 return GrGradientEffect::kBeforeInterp_PremulType; | 431 return GrGradientEffect::kBeforeInterp_PremulType; |
| 408 } else { | 432 } else { |
| 409 return GrGradientEffect::kAfterInterp_PremulType; | 433 return GrGradientEffect::kAfterInterp_PremulType; |
| 410 } | 434 } |
| 411 } | 435 } |
| 412 | 436 |
| 413 /** | |
| 414 * Subclasses must call this. It will return a value restricted to the lower
kBaseKeyBitCnt | |
| 415 * bits. | |
| 416 */ | |
| 417 static EffectKey GenBaseGradientKey(const GrDrawEffect&); | |
| 418 | |
| 419 // Emits the uniform used as the y-coord to texture samples in derived class
es. Subclasses | |
| 420 // should call this method from their emitCode(). | |
| 421 void emitUniforms(GrGLShaderBuilder* builder, EffectKey key); | |
| 422 | |
| 423 | |
| 424 // emit code that gets a fragment's color from an expression for t; Has bran
ches for 3 separate | |
| 425 // control flows inside -- 2 color gradients, 3 color symmetric gradients (b
oth using | |
| 426 // native GLSL mix), and 4+ color gradients that use the traditional texture
lookup. | |
| 427 void emitColor(GrGLShaderBuilder* builder, | |
| 428 const char* gradientTValue, | |
| 429 EffectKey key, | |
| 430 const char* outputColor, | |
| 431 const char* inputColor, | |
| 432 const TextureSamplerArray& samplers); | |
| 433 | |
| 434 private: | |
| 435 SkScalar fCachedYCoord; | 437 SkScalar fCachedYCoord; |
| 436 GrGLUniformManager::UniformHandle fFSYUni; | 438 GrGLUniformManager::UniformHandle fFSYUni; |
| 437 GrGLUniformManager::UniformHandle fColorStartUni; | 439 GrGLUniformManager::UniformHandle fColorStartUni; |
| 438 GrGLUniformManager::UniformHandle fColorMidUni; | 440 GrGLUniformManager::UniformHandle fColorMidUni; |
| 439 GrGLUniformManager::UniformHandle fColorEndUni; | 441 GrGLUniformManager::UniformHandle fColorEndUni; |
| 440 | 442 |
| 441 typedef GrGLEffect INHERITED; | 443 typedef GrGLEffect INHERITED; |
| 442 }; | 444 }; |
| 443 | 445 |
| 444 #endif | 446 #endif |
| 445 | 447 |
| 446 #endif | 448 #endif |
| OLD | NEW |