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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
178 kCache32Count = (1 << kCache32Bits), | 178 kCache32Count = (1 << kCache32Bits), |
179 kCache32Shift = 16 - kCache32Bits, | 179 kCache32Shift = 16 - kCache32Bits, |
180 kSqrt32Shift = 8 - kCache32Bits, | 180 kSqrt32Shift = 8 - kCache32Bits, |
181 | 181 |
182 /// This value is used to *read* the dither cache; it may be 0 | 182 /// This value is used to *read* the dither cache; it may be 0 |
183 /// if dithering is disabled. | 183 /// if dithering is disabled. |
184 kDitherStride32 = kCache32Count, | 184 kDitherStride32 = kCache32Count, |
185 kDitherStride16 = kCache16Count, | 185 kDitherStride16 = kCache16Count, |
186 }; | 186 }; |
187 | 187 |
188 enum ColorType { | |
bsalomon
2014/04/17 20:43:40
Since this is a GPU notion in a non-GPU-specific c
| |
189 kTwo_ColorType, | |
190 kThree_ColorType, // Symmetric three color | |
191 kTexture_ColorType | |
192 }; | |
193 | |
194 // Determines and returns the gradient is a two color gradient, three color gradient | |
bsalomon
2014/04/17 20:43:40
*symmetric* three color?
| |
195 // or other (texture gradient). If it is two or three color, the colors arra y will | |
196 // also be filled with the gradient colors | |
197 ColorType getGradientColorType(SkColor colors[3]) const; | |
bsalomon
2014/04/17 20:43:40
getGpuColorType()?
| |
198 | |
199 uint32_t getGradientFlags() const { return fGradFlags; } | |
bsalomon
2014/04/17 20:43:40
getFlags()?
| |
200 | |
188 protected: | 201 protected: |
189 SkGradientShaderBase(SkReadBuffer& ); | 202 SkGradientShaderBase(SkReadBuffer& ); |
190 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | 203 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
191 SK_TO_STRING_OVERRIDE() | 204 SK_TO_STRING_OVERRIDE() |
192 | 205 |
193 SkUnitMapper* fMapper; | 206 SkUnitMapper* fMapper; |
194 SkMatrix fPtsToUnit; // set by subclass | 207 SkMatrix fPtsToUnit; // set by subclass |
195 TileMode fTileMode; | 208 TileMode fTileMode; |
196 TileProc fTileProc; | 209 TileProc fTileProc; |
197 int fColorCount; | 210 int fColorCount; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 const SkMatrix& matrix, | 299 const SkMatrix& matrix, |
287 SkShader::TileMode tileMode); | 300 SkShader::TileMode tileMode); |
288 | 301 |
289 virtual ~GrGradientEffect(); | 302 virtual ~GrGradientEffect(); |
290 | 303 |
291 bool useAtlas() const { return SkToBool(-1 != fRow); } | 304 bool useAtlas() const { return SkToBool(-1 != fRow); } |
292 SkScalar getYCoord() const { return fYCoord; }; | 305 SkScalar getYCoord() const { return fYCoord; }; |
293 | 306 |
294 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; | 307 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; |
295 | 308 |
296 enum ColorType { | 309 SkGradientShaderBase::ColorType getColorType() const { return fColorType; } |
297 kTwo_ColorType, | |
298 kThree_ColorType, | |
299 kTexture_ColorType | |
300 }; | |
301 | |
302 ColorType getColorType() const { return fColorType; } | |
303 | 310 |
304 enum PremulType { | 311 enum PremulType { |
305 kBeforeInterp_PremulType, | 312 kBeforeInterp_PremulType, |
306 kAfterInterp_PremulType, | 313 kAfterInterp_PremulType, |
307 }; | 314 }; |
308 | 315 |
309 PremulType getPremulType() const { return fPremulType; } | 316 PremulType getPremulType() const { return fPremulType; } |
310 | 317 |
311 const SkColor* getColors(int pos) const { | 318 const SkColor* getColors(int pos) const { |
312 SkASSERT(fColorType != kTexture_ColorType); | 319 SkASSERT(fColorType != SkGradientShaderBase::kTexture_ColorType); |
313 SkASSERT((pos-1) <= fColorType); | 320 SkASSERT((pos-1) <= fColorType); |
314 return &fColors[pos]; | 321 return &fColors[pos]; |
315 } | 322 } |
316 | 323 |
317 protected: | 324 protected: |
318 | 325 |
319 /** Populates a pair of arrays with colors and stop info to construct a rand om gradient. | 326 /** Populates a pair of arrays with colors and stop info to construct a rand om gradient. |
320 The function decides whether stop values should be used or not. The retu rn value indicates | 327 The function decides whether stop values should be used or not. The retu rn value indicates |
321 the number of colors, which will be capped by kMaxRandomGradientColors. colors should be | 328 the number of colors, which will be capped by kMaxRandomGradientColors. colors should be |
322 sized to be at least kMaxRandomGradientColors. stops is a pointer to an array of at least | 329 sized to be at least kMaxRandomGradientColors. stops is a pointer to an array of at least |
323 size kMaxRandomGradientColors. It may be updated to NULL, indicating tha t NULL should be | 330 size kMaxRandomGradientColors. It may be updated to NULL, indicating tha t NULL should be |
324 passed to the gradient factory rather than the array. | 331 passed to the gradient factory rather than the array. |
325 */ | 332 */ |
326 static const int kMaxRandomGradientColors = 4; | 333 static const int kMaxRandomGradientColors = 4; |
327 static int RandomGradientParams(SkRandom* r, | 334 static int RandomGradientParams(SkRandom* r, |
328 SkColor colors[kMaxRandomGradientColors], | 335 SkColor colors[kMaxRandomGradientColors], |
329 SkScalar** stops, | 336 SkScalar** stops, |
330 SkShader::TileMode* tm); | 337 SkShader::TileMode* tm); |
331 | 338 |
332 virtual bool onIsEqual(const GrEffect& effect) const SK_OVERRIDE; | 339 virtual bool onIsEqual(const GrEffect& effect) const SK_OVERRIDE; |
333 | 340 |
334 const GrCoordTransform& getCoordTransform() const { return fCoordTransform; } | 341 const GrCoordTransform& getCoordTransform() const { return fCoordTransform; } |
335 | 342 |
336 private: | 343 private: |
337 static const GrCoordSet kCoordSet = kLocal_GrCoordSet; | 344 static const GrCoordSet kCoordSet = kLocal_GrCoordSet; |
338 | 345 |
339 enum { | |
340 kMaxAnalyticColors = 3 // if more colors use texture | |
341 }; | |
342 | |
343 GrCoordTransform fCoordTransform; | 346 GrCoordTransform fCoordTransform; |
344 GrTextureAccess fTextureAccess; | 347 GrTextureAccess fTextureAccess; |
345 SkScalar fYCoord; | 348 SkScalar fYCoord; |
346 GrTextureStripAtlas* fAtlas; | 349 GrTextureStripAtlas* fAtlas; |
347 int fRow; | 350 int fRow; |
348 bool fIsOpaque; | 351 bool fIsOpaque; |
349 ColorType fColorType; | 352 SkGradientShaderBase::ColorType fColorType; |
350 SkColor fColors[kMaxAnalyticColors]; | 353 SkColor fColors[3]; // More than 3 colors we use texture |
351 PremulType fPremulType; // This only changes behavior for two and three colo r special cases. | 354 PremulType fPremulType; // This only changes behavior for two and three colo r special cases. |
352 // It is already baked into to the table for texture gradients. | 355 // It is already baked into to the table for texture gradients. |
353 typedef GrEffect INHERITED; | 356 typedef GrEffect INHERITED; |
354 | 357 |
355 }; | 358 }; |
356 | 359 |
357 /////////////////////////////////////////////////////////////////////////////// | 360 /////////////////////////////////////////////////////////////////////////////// |
358 | 361 |
359 // Base class for GL gradient effects | 362 // Base class for GL gradient effects |
360 class GrGLGradientEffect : public GrGLEffect { | 363 class GrGLGradientEffect : public GrGLEffect { |
(...skipping 12 matching lines...) Expand all Loading... | |
373 kTwoColorKey = 2 << kPremulTypeKeyBitCnt, | 376 kTwoColorKey = 2 << kPremulTypeKeyBitCnt, |
374 kThreeColorKey = 3 << kPremulTypeKeyBitCnt, | 377 kThreeColorKey = 3 << kPremulTypeKeyBitCnt, |
375 kColorKeyMask = kTwoColorKey | kThreeColorKey, | 378 kColorKeyMask = kTwoColorKey | kThreeColorKey, |
376 kColorKeyBitCnt = 2, | 379 kColorKeyBitCnt = 2, |
377 | 380 |
378 // Subclasses must shift any key bits they produce up by this amount | 381 // Subclasses must shift any key bits they produce up by this amount |
379 // and combine with the result of GenBaseGradientKey. | 382 // and combine with the result of GenBaseGradientKey. |
380 kBaseKeyBitCnt = (kPremulTypeKeyBitCnt + kColorKeyBitCnt) | 383 kBaseKeyBitCnt = (kPremulTypeKeyBitCnt + kColorKeyBitCnt) |
381 }; | 384 }; |
382 | 385 |
383 static GrGradientEffect::ColorType ColorTypeFromKey(EffectKey key){ | 386 static SkGradientShaderBase::ColorType ColorTypeFromKey(EffectKey key){ |
384 if (kTwoColorKey == (key & kColorKeyMask)) { | 387 if (kTwoColorKey == (key & kColorKeyMask)) { |
385 return GrGradientEffect::kTwo_ColorType; | 388 return SkGradientShaderBase::kTwo_ColorType; |
386 } else if (kThreeColorKey == (key & kColorKeyMask)) { | 389 } else if (kThreeColorKey == (key & kColorKeyMask)) { |
387 return GrGradientEffect::kThree_ColorType; | 390 return SkGradientShaderBase::kThree_ColorType; |
388 } else {return GrGradientEffect::kTexture_ColorType;} | 391 } else {return SkGradientShaderBase::kTexture_ColorType;} |
389 } | 392 } |
390 | 393 |
391 static GrGradientEffect::PremulType PremulTypeFromKey(EffectKey key){ | 394 static GrGradientEffect::PremulType PremulTypeFromKey(EffectKey key){ |
392 if (kPremulBeforeInterpKey == (key & kPremulTypeMask)) { | 395 if (kPremulBeforeInterpKey == (key & kPremulTypeMask)) { |
393 return GrGradientEffect::kBeforeInterp_PremulType; | 396 return GrGradientEffect::kBeforeInterp_PremulType; |
394 } else { | 397 } else { |
395 return GrGradientEffect::kAfterInterp_PremulType; | 398 return GrGradientEffect::kAfterInterp_PremulType; |
396 } | 399 } |
397 } | 400 } |
398 | 401 |
(...skipping 24 matching lines...) Expand all Loading... | |
423 GrGLUniformManager::UniformHandle fColorStartUni; | 426 GrGLUniformManager::UniformHandle fColorStartUni; |
424 GrGLUniformManager::UniformHandle fColorMidUni; | 427 GrGLUniformManager::UniformHandle fColorMidUni; |
425 GrGLUniformManager::UniformHandle fColorEndUni; | 428 GrGLUniformManager::UniformHandle fColorEndUni; |
426 | 429 |
427 typedef GrGLEffect INHERITED; | 430 typedef GrGLEffect INHERITED; |
428 }; | 431 }; |
429 | 432 |
430 #endif | 433 #endif |
431 | 434 |
432 #endif | 435 #endif |
OLD | NEW |