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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; | 252 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; |
253 | |
254 enum ColorType{ | |
255 kTwo_ColorType, | |
256 kThree_ColorType, | |
257 kTexture_ColorType | |
258 }; | |
259 | |
260 inline int getNumColors() const { return fNumColors; }; | |
bsalomon
2013/08/13 21:07:52
Do we need fNumColors or can we just store ColorTy
| |
261 inline ColorType getColorType() const { | |
262 if (2 == fNumColors) {return kTwo_ColorType;} | |
263 else if (3 == fNumColors) {return kThree_ColorType;} | |
264 else {return kTexture_ColorType;} | |
265 } | |
253 | 266 |
254 protected: | 267 protected: |
255 | 268 |
256 /** Populates a pair of arrays with colors and stop info to construct a rand om gradient. | 269 /** 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 | 270 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 | 271 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 | 272 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 | 273 size kMaxRandomGradientColors. It may be updated to NULL, indicating tha t NULL should be |
261 passed to the gradient factory rather than the array. | 274 passed to the gradient factory rather than the array. |
262 */ | 275 */ |
263 static const int kMaxRandomGradientColors = 4; | 276 static const int kMaxRandomGradientColors = 4; |
264 static int RandomGradientParams(SkMWCRandom* r, | 277 static int RandomGradientParams(SkMWCRandom* r, |
265 SkColor colors[kMaxRandomGradientColors], | 278 SkColor colors[kMaxRandomGradientColors], |
266 SkScalar** stops, | 279 SkScalar** stops, |
267 SkShader::TileMode* tm); | 280 SkShader::TileMode* tm); |
268 | 281 |
269 virtual bool onIsEqual(const GrEffect& effect) const SK_OVERRIDE; | 282 virtual bool onIsEqual(const GrEffect& effect) const SK_OVERRIDE; |
270 | 283 |
271 private: | 284 private: |
272 | 285 |
273 GrTextureAccess fTextureAccess; | 286 GrTextureAccess fTextureAccess; |
274 SkScalar fYCoord; | 287 SkScalar fYCoord; |
275 GrTextureStripAtlas* fAtlas; | 288 GrTextureStripAtlas* fAtlas; |
276 int fRow; | 289 int fRow; |
277 SkMatrix fMatrix; | 290 SkMatrix fMatrix; |
278 bool fIsOpaque; | 291 bool fIsOpaque; |
292 int fNumColors; | |
279 | 293 |
280 typedef GrEffect INHERITED; | 294 typedef GrEffect INHERITED; |
281 | 295 |
282 }; | 296 }; |
283 | 297 |
284 /////////////////////////////////////////////////////////////////////////////// | 298 /////////////////////////////////////////////////////////////////////////////// |
285 | 299 |
286 // Base class for GL gradient effects | 300 // Base class for GL gradient effects |
287 class GrGLGradientEffect : public GrGLEffect { | 301 class GrGLGradientEffect : public GrGLEffect { |
288 public: | 302 public: |
289 GrGLGradientEffect(const GrBackendEffectFactory& factory); | 303 GrGLGradientEffect(const GrBackendEffectFactory& factory); |
290 virtual ~GrGLGradientEffect(); | 304 virtual ~GrGLGradientEffect(); |
291 | 305 |
292 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE; | 306 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE; |
293 | 307 |
294 protected: | 308 protected: |
295 /** | 309 /** |
296 * Subclasses must reserve the lower kMatrixKeyBitCnt of their key for use b y | 310 * Subclasses must reserve the lower kMatrixKeyBitCnt of their key for use b y |
297 * GrGLGradientEffect. | 311 * GrGLGradientEffect. |
298 */ | 312 */ |
299 enum { | 313 enum { |
300 kMatrixKeyBitCnt = GrGLEffectMatrix::kKeyBits, | 314 kMatrixKeyBitCnt = GrGLEffectMatrix::kKeyBits, |
301 kMatrixKeyMask = (1 << kMatrixKeyBitCnt) - 1, | 315 kMatrixKeyMask = (1 << kMatrixKeyBitCnt) - 1, |
316 | |
317 kTwoColorKey = 2 << kMatrixKeyBitCnt, | |
318 kThreeColorKey = 3 << kMatrixKeyBitCnt, | |
319 kColorKeyMask = kThreeColorKey | |
bsalomon
2013/08/13 21:07:52
maybe kTwoColorKey | kThreeColorKey... I realize t
dierk
2013/08/14 21:33:15
Done.
| |
302 }; | 320 }; |
303 | 321 |
322 inline GrGradientEffect::ColorType getColorType(EffectKey key){ | |
bsalomon
2013/08/13 21:07:52
static?
dierk
2013/08/14 21:33:15
Done.
| |
323 if (kTwoColorKey == (key & kColorKeyMask)) { | |
324 return GrGradientEffect::kTwo_ColorType; | |
325 } else if (kThreeColorKey == (key & kColorKeyMask)) { | |
326 return GrGradientEffect::kThree_ColorType; | |
327 } else {return GrGradientEffect::kTexture_ColorType;} | |
328 } | |
329 | |
304 /** | 330 /** |
305 * Subclasses must call this. It will return a value restricted to the lower kMatrixKeyBitCnt | 331 * Subclasses must call this. It will return a value restricted to the lower kMatrixKeyBitCnt |
306 * bits. | 332 * bits. |
307 */ | 333 */ |
308 static EffectKey GenMatrixKey(const GrDrawEffect&); | 334 static EffectKey GenBaseGradientKey(const GrDrawEffect&); |
309 | 335 |
310 /** | 336 /** |
311 * Inserts code to implement the GrGradientEffect's matrix. This should be c alled before a | 337 * 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 | 338 * 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 | 339 * 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 | 340 * 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 | 341 * upon whether the matrix has perspective or not. It is not necessary to ma sk the key before |
316 * calling. | 342 * calling. |
317 */ | 343 */ |
318 void setupMatrix(GrGLShaderBuilder* builder, | 344 void setupMatrix(GrGLShaderBuilder* builder, |
319 EffectKey key, | 345 EffectKey key, |
320 const char** fsCoordName, | 346 const char** fsCoordName, |
321 const char** vsVaryingName = NULL, | 347 const char** vsVaryingName = NULL, |
322 GrSLType* vsVaryingType = NULL); | 348 GrSLType* vsVaryingType = NULL); |
323 | 349 |
324 // Emits the uniform used as the y-coord to texture samples in derived class es. Subclasses | 350 // Emits the uniform used as the y-coord to texture samples in derived class es. Subclasses |
325 // should call this method from their emitCode(). | 351 // should call this method from their emitCode(). |
326 void emitYCoordUniform(GrGLShaderBuilder* builder); | 352 void emitUniforms(GrGLShaderBuilder* builder, EffectKey key); |
327 | 353 |
328 // emit code that gets a fragment's color from an expression for t; for now this always uses the | 354 |
329 // texture, but for simpler cases we'll be able to lerp. Subclasses should c all this method from | 355 // emit code that gets a fragment's color from an expression for t; Has bran ches for 3 separate |
330 // their emitCode(). | 356 // control flows inside -- 2 color gradients, 3 color symmetric gradients (b oth using |
331 void emitColorLookup(GrGLShaderBuilder* builder, | 357 // native GLSL mix), and 4+ color gradients that use the traditional texture lookup. |
332 const char* gradientTValue, | 358 void emitColor(GrGLShaderBuilder* builder, |
333 const char* outputColor, | 359 const char* gradientTValue, |
334 const char* inputColor, | 360 EffectKey key, |
335 const GrGLShaderBuilder::TextureSampler&); | 361 const char* outputColor, |
362 const char* inputColor, | |
363 const GrGLShaderBuilder::TextureSamplerArray& samplers); | |
336 | 364 |
337 private: | 365 private: |
338 static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType; | 366 static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType; |
339 | 367 |
340 SkScalar fCachedYCoord; | 368 SkScalar fCachedYCoord; |
341 GrGLUniformManager::UniformHandle fFSYUni; | 369 GrGLUniformManager::UniformHandle fFSYUni; |
370 GrGLUniformManager::UniformHandle fColorStartUni; | |
371 GrGLUniformManager::UniformHandle fColorMidUni; | |
372 GrGLUniformManager::UniformHandle fColorEndUni; | |
342 GrGLEffectMatrix fEffectMatrix; | 373 GrGLEffectMatrix fEffectMatrix; |
343 | 374 |
344 typedef GrGLEffect INHERITED; | 375 typedef GrGLEffect INHERITED; |
345 }; | 376 }; |
346 | 377 |
347 #endif | 378 #endif |
348 | 379 |
349 #endif | 380 #endif |
OLD | NEW |