| 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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 protected: | 410 protected: |
| 411 /** | 411 /** |
| 412 * Subclasses must call this. It will return a key for the part of the shade
r code controlled | 412 * Subclasses must call this. It will return a key for the part of the shade
r code controlled |
| 413 * by the base class. The subclasses must stick it in their key and then pas
s it to the below | 413 * by the base class. The subclasses must stick it in their key and then pas
s it to the below |
| 414 * emit* functions from their emitCode function. | 414 * emit* functions from their emitCode function. |
| 415 */ | 415 */ |
| 416 static uint32_t GenBaseGradientKey(const GrProcessor&); | 416 static uint32_t GenBaseGradientKey(const GrProcessor&); |
| 417 | 417 |
| 418 // Emits the uniform used as the y-coord to texture samples in derived class
es. Subclasses | 418 // Emits the uniform used as the y-coord to texture samples in derived class
es. Subclasses |
| 419 // should call this method from their emitCode(). | 419 // should call this method from their emitCode(). |
| 420 void emitUniforms(GrGLFPBuilder* builder, uint32_t baseKey); | 420 void emitUniforms(GrGLFPBuilder* builder, const GrGradientEffect&); |
| 421 | 421 |
| 422 | 422 |
| 423 // emit code that gets a fragment's color from an expression for t; Has bran
ches for 3 separate | 423 // emit code that gets a fragment's color from an expression for t; Has bran
ches for 3 separate |
| 424 // control flows inside -- 2 color gradients, 3 color symmetric gradients (b
oth using | 424 // control flows inside -- 2 color gradients, 3 color symmetric gradients (b
oth using |
| 425 // native GLSL mix), and 4+ color gradients that use the traditional texture
lookup. | 425 // native GLSL mix), and 4+ color gradients that use the traditional texture
lookup. |
| 426 void emitColor(GrGLFPBuilder* builder, | 426 void emitColor(GrGLFPBuilder* builder, |
| 427 const GrGradientEffect&, |
| 427 const char* gradientTValue, | 428 const char* gradientTValue, |
| 428 uint32_t baseKey, | |
| 429 const char* outputColor, | 429 const char* outputColor, |
| 430 const char* inputColor, | 430 const char* inputColor, |
| 431 const TextureSamplerArray& samplers); | 431 const TextureSamplerArray& samplers); |
| 432 | 432 |
| 433 private: | 433 private: |
| 434 enum { | 434 enum { |
| 435 kPremulTypeKeyBitCnt = 1, | 435 kPremulTypeKeyBitCnt = 1, |
| 436 kPremulTypeMask = 1, | 436 kPremulTypeMask = 1, |
| 437 kPremulBeforeInterpKey = kPremulTypeMask, | 437 kPremulBeforeInterpKey = kPremulTypeMask, |
| 438 | 438 |
| 439 kTwoColorKey = 2 << kPremulTypeKeyBitCnt, | 439 kTwoColorKey = 2 << kPremulTypeKeyBitCnt, |
| 440 kThreeColorKey = 3 << kPremulTypeKeyBitCnt, | 440 kThreeColorKey = 3 << kPremulTypeKeyBitCnt, |
| 441 kColorKeyMask = kTwoColorKey | kThreeColorKey, | 441 kColorKeyMask = kTwoColorKey | kThreeColorKey, |
| 442 kColorKeyBitCnt = 2, | 442 kColorKeyBitCnt = 2, |
| 443 | 443 |
| 444 // Subclasses must shift any key bits they produce up by this amount | 444 // Subclasses must shift any key bits they produce up by this amount |
| 445 // and combine with the result of GenBaseGradientKey. | 445 // and combine with the result of GenBaseGradientKey. |
| 446 kBaseKeyBitCnt = (kPremulTypeKeyBitCnt + kColorKeyBitCnt) | 446 kBaseKeyBitCnt = (kPremulTypeKeyBitCnt + kColorKeyBitCnt) |
| 447 }; | 447 }; |
| 448 GR_STATIC_ASSERT(kBaseKeyBitCnt <= 32); | 448 GR_STATIC_ASSERT(kBaseKeyBitCnt <= 32); |
| 449 | 449 |
| 450 static SkGradientShaderBase::GpuColorType ColorTypeFromKey(uint32_t baseKey)
{ | |
| 451 if (kTwoColorKey == (baseKey & kColorKeyMask)) { | |
| 452 return SkGradientShaderBase::kTwo_GpuColorType; | |
| 453 } else if (kThreeColorKey == (baseKey & kColorKeyMask)) { | |
| 454 return SkGradientShaderBase::kThree_GpuColorType; | |
| 455 } else {return SkGradientShaderBase::kTexture_GpuColorType;} | |
| 456 } | |
| 457 | |
| 458 static GrGradientEffect::PremulType PremulTypeFromKey(uint32_t baseKey){ | |
| 459 if (kPremulBeforeInterpKey == (baseKey & kPremulTypeMask)) { | |
| 460 return GrGradientEffect::kBeforeInterp_PremulType; | |
| 461 } else { | |
| 462 return GrGradientEffect::kAfterInterp_PremulType; | |
| 463 } | |
| 464 } | |
| 465 | |
| 466 SkScalar fCachedYCoord; | 450 SkScalar fCachedYCoord; |
| 467 GrGLProgramDataManager::UniformHandle fFSYUni; | 451 GrGLProgramDataManager::UniformHandle fFSYUni; |
| 468 GrGLProgramDataManager::UniformHandle fColorStartUni; | 452 GrGLProgramDataManager::UniformHandle fColorStartUni; |
| 469 GrGLProgramDataManager::UniformHandle fColorMidUni; | 453 GrGLProgramDataManager::UniformHandle fColorMidUni; |
| 470 GrGLProgramDataManager::UniformHandle fColorEndUni; | 454 GrGLProgramDataManager::UniformHandle fColorEndUni; |
| 471 | 455 |
| 472 typedef GrGLFragmentProcessor INHERITED; | 456 typedef GrGLFragmentProcessor INHERITED; |
| 473 }; | 457 }; |
| 474 | 458 |
| 475 #endif | 459 #endif |
| 476 | 460 |
| 477 #endif | 461 #endif |
| OLD | NEW |