Chromium Code Reviews| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 kCache32Count = (1 << kCache32Bits), | 121 kCache32Count = (1 << kCache32Bits), |
| 122 kCache32Shift = 16 - kCache32Bits, | 122 kCache32Shift = 16 - kCache32Bits, |
| 123 kSqrt32Shift = 8 - kCache32Bits, | 123 kSqrt32Shift = 8 - kCache32Bits, |
| 124 | 124 |
| 125 /// This value is used to *read* the dither cache; it may be 0 | 125 /// This value is used to *read* the dither cache; it may be 0 |
| 126 /// if dithering is disabled. | 126 /// if dithering is disabled. |
| 127 kDitherStride32 = kCache32Count, | 127 kDitherStride32 = kCache32Count, |
| 128 kDitherStride16 = kCache16Count, | 128 kDitherStride16 = kCache16Count, |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 enum GpuColorType { | |
| 132 kTwo_GpuColorType, | |
| 133 kThree_GpuColorType, // Symmetric three color | |
| 134 kTexture_GpuColorType | |
| 135 }; | |
| 136 | |
| 137 // Determines and returns the gradient is a two color gradient, symmetric th ree color gradient | |
| 138 // or other (texture gradient). If it is two or symmetric three color, the c olors array will | |
| 139 // also be filled with the gradient colors | |
| 140 GpuColorType getGpuColorType(SkColor colors[3]) const; | |
| 141 | |
| 142 uint32_t getFlags() const { return fGradFlags; } | |
|
Dominik Grewe
2014/04/22 10:19:33
I don't think getFlags is a good name if we alread
bsalomon
2014/04/22 13:14:51
Good point... I didn't notice the other getFlags()
| |
| 131 | 143 |
| 132 protected: | 144 protected: |
| 133 SkGradientShaderBase(SkReadBuffer& ); | 145 SkGradientShaderBase(SkReadBuffer& ); |
| 134 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | 146 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
| 135 SK_TO_STRING_OVERRIDE() | 147 SK_TO_STRING_OVERRIDE() |
| 136 | 148 |
| 137 SkUnitMapper* fMapper; | 149 SkUnitMapper* fMapper; |
| 138 SkMatrix fPtsToUnit; // set by subclass | 150 SkMatrix fPtsToUnit; // set by subclass |
| 139 SkMatrix fDstToIndex; | 151 SkMatrix fDstToIndex; |
| 140 SkMatrix::MapXYProc fDstToIndexProc; | 152 SkMatrix::MapXYProc fDstToIndexProc; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 const SkMatrix& matrix, | 256 const SkMatrix& matrix, |
| 245 SkShader::TileMode tileMode); | 257 SkShader::TileMode tileMode); |
| 246 | 258 |
| 247 virtual ~GrGradientEffect(); | 259 virtual ~GrGradientEffect(); |
| 248 | 260 |
| 249 bool useAtlas() const { return SkToBool(-1 != fRow); } | 261 bool useAtlas() const { return SkToBool(-1 != fRow); } |
| 250 SkScalar getYCoord() const { return fYCoord; }; | 262 SkScalar getYCoord() const { return fYCoord; }; |
| 251 | 263 |
| 252 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; | 264 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; |
| 253 | 265 |
| 254 enum ColorType { | 266 SkGradientShaderBase::GpuColorType getColorType() const { return fColorType; } |
| 255 kTwo_ColorType, | |
| 256 kThree_ColorType, | |
| 257 kTexture_ColorType | |
| 258 }; | |
| 259 | |
| 260 ColorType getColorType() const { return fColorType; } | |
| 261 | 267 |
| 262 enum PremulType { | 268 enum PremulType { |
| 263 kBeforeInterp_PremulType, | 269 kBeforeInterp_PremulType, |
| 264 kAfterInterp_PremulType, | 270 kAfterInterp_PremulType, |
| 265 }; | 271 }; |
| 266 | 272 |
| 267 PremulType getPremulType() const { return fPremulType; } | 273 PremulType getPremulType() const { return fPremulType; } |
| 268 | 274 |
| 269 const SkColor* getColors(int pos) const { | 275 const SkColor* getColors(int pos) const { |
| 270 SkASSERT(fColorType != kTexture_ColorType); | 276 SkASSERT(fColorType != SkGradientShaderBase::kTexture_GpuColorType); |
| 271 SkASSERT((pos-1) <= fColorType); | 277 SkASSERT((pos-1) <= fColorType); |
| 272 return &fColors[pos]; | 278 return &fColors[pos]; |
| 273 } | 279 } |
| 274 | 280 |
| 275 protected: | 281 protected: |
| 276 | 282 |
| 277 /** Populates a pair of arrays with colors and stop info to construct a rand om gradient. | 283 /** Populates a pair of arrays with colors and stop info to construct a rand om gradient. |
| 278 The function decides whether stop values should be used or not. The retu rn value indicates | 284 The function decides whether stop values should be used or not. The retu rn value indicates |
| 279 the number of colors, which will be capped by kMaxRandomGradientColors. colors should be | 285 the number of colors, which will be capped by kMaxRandomGradientColors. colors should be |
| 280 sized to be at least kMaxRandomGradientColors. stops is a pointer to an array of at least | 286 sized to be at least kMaxRandomGradientColors. stops is a pointer to an array of at least |
| 281 size kMaxRandomGradientColors. It may be updated to NULL, indicating tha t NULL should be | 287 size kMaxRandomGradientColors. It may be updated to NULL, indicating tha t NULL should be |
| 282 passed to the gradient factory rather than the array. | 288 passed to the gradient factory rather than the array. |
| 283 */ | 289 */ |
| 284 static const int kMaxRandomGradientColors = 4; | 290 static const int kMaxRandomGradientColors = 4; |
| 285 static int RandomGradientParams(SkRandom* r, | 291 static int RandomGradientParams(SkRandom* r, |
| 286 SkColor colors[kMaxRandomGradientColors], | 292 SkColor colors[kMaxRandomGradientColors], |
| 287 SkScalar** stops, | 293 SkScalar** stops, |
| 288 SkShader::TileMode* tm); | 294 SkShader::TileMode* tm); |
| 289 | 295 |
| 290 virtual bool onIsEqual(const GrEffect& effect) const SK_OVERRIDE; | 296 virtual bool onIsEqual(const GrEffect& effect) const SK_OVERRIDE; |
| 291 | 297 |
| 292 const GrCoordTransform& getCoordTransform() const { return fCoordTransform; } | 298 const GrCoordTransform& getCoordTransform() const { return fCoordTransform; } |
| 293 | 299 |
| 294 private: | 300 private: |
| 295 static const GrCoordSet kCoordSet = kLocal_GrCoordSet; | 301 static const GrCoordSet kCoordSet = kLocal_GrCoordSet; |
| 296 | 302 |
| 297 enum { | |
| 298 kMaxAnalyticColors = 3 // if more colors use texture | |
| 299 }; | |
| 300 | |
| 301 GrCoordTransform fCoordTransform; | 303 GrCoordTransform fCoordTransform; |
| 302 GrTextureAccess fTextureAccess; | 304 GrTextureAccess fTextureAccess; |
| 303 SkScalar fYCoord; | 305 SkScalar fYCoord; |
| 304 GrTextureStripAtlas* fAtlas; | 306 GrTextureStripAtlas* fAtlas; |
| 305 int fRow; | 307 int fRow; |
| 306 bool fIsOpaque; | 308 bool fIsOpaque; |
| 307 ColorType fColorType; | 309 SkGradientShaderBase::GpuColorType fColorType; |
| 308 SkColor fColors[kMaxAnalyticColors]; | 310 SkColor fColors[3]; // More than 3 colors we use texture |
| 309 PremulType fPremulType; // This only changes behavior for two and three colo r special cases. | 311 PremulType fPremulType; // This only changes behavior for two and three colo r special cases. |
| 310 // It is already baked into to the table for texture gradients. | 312 // It is already baked into to the table for texture gradients. |
| 311 typedef GrEffect INHERITED; | 313 typedef GrEffect INHERITED; |
| 312 | 314 |
| 313 }; | 315 }; |
| 314 | 316 |
| 315 /////////////////////////////////////////////////////////////////////////////// | 317 /////////////////////////////////////////////////////////////////////////////// |
| 316 | 318 |
| 317 // Base class for GL gradient effects | 319 // Base class for GL gradient effects |
| 318 class GrGLGradientEffect : public GrGLEffect { | 320 class GrGLGradientEffect : public GrGLEffect { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 331 kTwoColorKey = 2 << kPremulTypeKeyBitCnt, | 333 kTwoColorKey = 2 << kPremulTypeKeyBitCnt, |
| 332 kThreeColorKey = 3 << kPremulTypeKeyBitCnt, | 334 kThreeColorKey = 3 << kPremulTypeKeyBitCnt, |
| 333 kColorKeyMask = kTwoColorKey | kThreeColorKey, | 335 kColorKeyMask = kTwoColorKey | kThreeColorKey, |
| 334 kColorKeyBitCnt = 2, | 336 kColorKeyBitCnt = 2, |
| 335 | 337 |
| 336 // Subclasses must shift any key bits they produce up by this amount | 338 // Subclasses must shift any key bits they produce up by this amount |
| 337 // and combine with the result of GenBaseGradientKey. | 339 // and combine with the result of GenBaseGradientKey. |
| 338 kBaseKeyBitCnt = (kPremulTypeKeyBitCnt + kColorKeyBitCnt) | 340 kBaseKeyBitCnt = (kPremulTypeKeyBitCnt + kColorKeyBitCnt) |
| 339 }; | 341 }; |
| 340 | 342 |
| 341 static GrGradientEffect::ColorType ColorTypeFromKey(EffectKey key){ | 343 static SkGradientShaderBase::GpuColorType ColorTypeFromKey(EffectKey key){ |
| 342 if (kTwoColorKey == (key & kColorKeyMask)) { | 344 if (kTwoColorKey == (key & kColorKeyMask)) { |
| 343 return GrGradientEffect::kTwo_ColorType; | 345 return SkGradientShaderBase::kTwo_GpuColorType; |
| 344 } else if (kThreeColorKey == (key & kColorKeyMask)) { | 346 } else if (kThreeColorKey == (key & kColorKeyMask)) { |
| 345 return GrGradientEffect::kThree_ColorType; | 347 return SkGradientShaderBase::kThree_GpuColorType; |
| 346 } else {return GrGradientEffect::kTexture_ColorType;} | 348 } else {return SkGradientShaderBase::kTexture_GpuColorType;} |
| 347 } | 349 } |
| 348 | 350 |
| 349 static GrGradientEffect::PremulType PremulTypeFromKey(EffectKey key){ | 351 static GrGradientEffect::PremulType PremulTypeFromKey(EffectKey key){ |
| 350 if (kPremulBeforeInterpKey == (key & kPremulTypeMask)) { | 352 if (kPremulBeforeInterpKey == (key & kPremulTypeMask)) { |
| 351 return GrGradientEffect::kBeforeInterp_PremulType; | 353 return GrGradientEffect::kBeforeInterp_PremulType; |
| 352 } else { | 354 } else { |
| 353 return GrGradientEffect::kAfterInterp_PremulType; | 355 return GrGradientEffect::kAfterInterp_PremulType; |
| 354 } | 356 } |
| 355 } | 357 } |
| 356 | 358 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 381 GrGLUniformManager::UniformHandle fColorStartUni; | 383 GrGLUniformManager::UniformHandle fColorStartUni; |
| 382 GrGLUniformManager::UniformHandle fColorMidUni; | 384 GrGLUniformManager::UniformHandle fColorMidUni; |
| 383 GrGLUniformManager::UniformHandle fColorEndUni; | 385 GrGLUniformManager::UniformHandle fColorEndUni; |
| 384 | 386 |
| 385 typedef GrGLEffect INHERITED; | 387 typedef GrGLEffect INHERITED; |
| 386 }; | 388 }; |
| 387 | 389 |
| 388 #endif | 390 #endif |
| 389 | 391 |
| 390 #endif | 392 #endif |
| OLD | NEW |