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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
242 const SkGradientShaderBase& shader, | 242 const SkGradientShaderBase& shader, |
243 const SkMatrix& matrix, | 243 const SkMatrix& matrix, |
244 SkShader::TileMode tileMode); | 244 SkShader::TileMode tileMode); |
245 | 245 |
246 virtual ~GrGradientEffect(); | 246 virtual ~GrGradientEffect(); |
247 | 247 |
248 bool useAtlas() const { return SkToBool(-1 != fRow); } | 248 bool useAtlas() const { return SkToBool(-1 != fRow); } |
249 SkScalar getYCoord() const { return fYCoord; }; | 249 SkScalar getYCoord() const { return fYCoord; }; |
250 const SkMatrix& getMatrix() const { return fMatrix;} | 250 const SkMatrix& getMatrix() const { return fMatrix;} |
251 | 251 |
252 int numColors; | |
reed1
2013/08/13 12:33:41
nit:
- does this guy really need to be public?
- w
dierk
2013/08/13 19:50:17
Done.
| |
253 | |
252 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; | 254 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; |
253 | 255 |
254 protected: | 256 protected: |
255 | 257 |
256 /** Populates a pair of arrays with colors and stop info to construct a rand om gradient. | 258 /** Populates a pair of arrays with colors and stop info to construct a rand om gradient. |
257 The function decides whether stop values should be used or not. The retu rn value indicates | 259 The function decides whether stop values should be used or not. The retu rn value indicates |
258 the number of colors, which will be capped by kMaxRandomGradientColors. colors should be | 260 the number of colors, which will be capped by kMaxRandomGradientColors. colors should be |
259 sized to be at least kMaxRandomGradientColors. stops is a pointer to an array of at least | 261 sized to be at least kMaxRandomGradientColors. stops is a pointer to an array of at least |
260 size kMaxRandomGradientColors. It may be updated to NULL, indicating tha t NULL should be | 262 size kMaxRandomGradientColors. It may be updated to NULL, indicating tha t NULL should be |
261 passed to the gradient factory rather than the array. | 263 passed to the gradient factory rather than the array. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 protected: | 296 protected: |
295 /** | 297 /** |
296 * Subclasses must reserve the lower kMatrixKeyBitCnt of their key for use b y | 298 * Subclasses must reserve the lower kMatrixKeyBitCnt of their key for use b y |
297 * GrGLGradientEffect. | 299 * GrGLGradientEffect. |
298 */ | 300 */ |
299 enum { | 301 enum { |
300 kMatrixKeyBitCnt = GrGLEffectMatrix::kKeyBits, | 302 kMatrixKeyBitCnt = GrGLEffectMatrix::kKeyBits, |
301 kMatrixKeyMask = (1 << kMatrixKeyBitCnt) - 1, | 303 kMatrixKeyMask = (1 << kMatrixKeyBitCnt) - 1, |
302 }; | 304 }; |
303 | 305 |
306 static inline bool is2Color(const GrGradientEffect& e){ | |
bsalomon
2013/08/13 14:28:37
How about an enum named ColorType (or something li
dierk
2013/08/13 19:50:17
Done.
| |
307 return e.numColors == 2; | |
308 } | |
309 static inline bool is3Color(const GrGradientEffect& e){ | |
310 return e.numColors == 3; | |
311 } | |
312 | |
313 static inline bool is2Color(const EffectKey key){ | |
314 return (key & 0x4000) == 0x4000; | |
315 } | |
316 static inline bool is3Color(const EffectKey key){ | |
317 return (key & 0x6000) == 0x6000; | |
318 } | |
319 | |
320 | |
304 /** | 321 /** |
305 * Subclasses must call this. It will return a value restricted to the lower kMatrixKeyBitCnt | 322 * Subclasses must call this. It will return a value restricted to the lower kMatrixKeyBitCnt |
306 * bits. | 323 * bits. |
307 */ | 324 */ |
308 static EffectKey GenMatrixKey(const GrDrawEffect&); | 325 static EffectKey GenMatrixKey(const GrDrawEffect&); |
309 | 326 |
310 /** | 327 /** |
311 * Inserts code to implement the GrGradientEffect's matrix. This should be c alled before a | 328 * Inserts code to implement the GrGradientEffect's matrix. This should be c alled before a |
312 * subclass emits its own code. The name of the 2D coords is output via fsCo ordName and already | 329 * subclass emits its own code. The name of the 2D coords is output via fsCo ordName and already |
313 * incorporates any perspective division. The caller can also optionally ret rieve the name of | 330 * incorporates any perspective division. The caller can also optionally ret rieve the name of |
314 * the varying inserted in the VS and its type, which may be either vec2f or vec3f depending | 331 * the varying inserted in the VS and its type, which may be either vec2f or vec3f depending |
315 * upon whether the matrix has perspective or not. It is not necessary to ma sk the key before | 332 * upon whether the matrix has perspective or not. It is not necessary to ma sk the key before |
316 * calling. | 333 * calling. |
317 */ | 334 */ |
318 void setupMatrix(GrGLShaderBuilder* builder, | 335 void setupMatrix(GrGLShaderBuilder* builder, |
319 EffectKey key, | 336 EffectKey key, |
320 const char** fsCoordName, | 337 const char** fsCoordName, |
321 const char** vsVaryingName = NULL, | 338 const char** vsVaryingName = NULL, |
322 GrSLType* vsVaryingType = NULL); | 339 GrSLType* vsVaryingType = NULL); |
323 | 340 |
324 // Emits the uniform used as the y-coord to texture samples in derived class es. Subclasses | 341 // Emits the uniform used as the y-coord to texture samples in derived class es. Subclasses |
325 // should call this method from their emitCode(). | 342 // should call this method from their emitCode(). |
326 void emitYCoordUniform(GrGLShaderBuilder* builder); | 343 void emitUniforms(GrGLShaderBuilder* builder, EffectKey key); |
327 | 344 |
328 // emit code that gets a fragment's color from an expression for t; for now this always uses the | 345 |
329 // texture, but for simpler cases we'll be able to lerp. Subclasses should c all this method from | 346 // emit code that gets a fragment's color from an expression for t; Only use d if 4 or more |
bsalomon
2013/08/13 14:28:37
Do you mean the sampler array is only used for 4+?
dierk
2013/08/13 19:50:17
Done.
| |
347 // colors, a simpler lerp is used for 2 and 3 colors. Subclasses should call this method from | |
330 // their emitCode(). | 348 // their emitCode(). |
331 void emitColorLookup(GrGLShaderBuilder* builder, | 349 void emitColor(GrGLShaderBuilder* builder, |
332 const char* gradientTValue, | 350 const char* gradientTValue, |
333 const char* outputColor, | 351 EffectKey key, |
334 const char* inputColor, | 352 const char* outputColor, |
335 const GrGLShaderBuilder::TextureSampler&); | 353 const char* inputColor, |
354 const GrGLShaderBuilder::TextureSamplerArray& samplers); | |
336 | 355 |
337 private: | 356 private: |
338 static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType; | 357 static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType; |
339 | 358 |
340 SkScalar fCachedYCoord; | 359 SkScalar fCachedYCoord; |
341 GrGLUniformManager::UniformHandle fFSYUni; | 360 GrGLUniformManager::UniformHandle fFSYUni; |
361 GrGLUniformManager::UniformHandle fColorStartUni; | |
362 GrGLUniformManager::UniformHandle fColorMidUni; | |
363 GrGLUniformManager::UniformHandle fColorEndUni; | |
342 GrGLEffectMatrix fEffectMatrix; | 364 GrGLEffectMatrix fEffectMatrix; |
343 | 365 |
344 typedef GrGLEffect INHERITED; | 366 typedef GrGLEffect INHERITED; |
345 }; | 367 }; |
346 | 368 |
347 #endif | 369 #endif |
348 | 370 |
349 #endif | 371 #endif |
OLD | NEW |