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