| 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 291 |
| 292 static inline int next_dither_toggle16(int toggle) { | 292 static inline int next_dither_toggle16(int toggle) { |
| 293 return toggle ^ SkGradientShaderBase::kDitherStride16; | 293 return toggle ^ SkGradientShaderBase::kDitherStride16; |
| 294 } | 294 } |
| 295 | 295 |
| 296 /////////////////////////////////////////////////////////////////////////////// | 296 /////////////////////////////////////////////////////////////////////////////// |
| 297 | 297 |
| 298 #if SK_SUPPORT_GPU | 298 #if SK_SUPPORT_GPU |
| 299 | 299 |
| 300 #include "GrCoordTransform.h" | 300 #include "GrCoordTransform.h" |
| 301 #include "gl/GrGLEffect.h" | 301 #include "gl/GrGLProcessor.h" |
| 302 | 302 |
| 303 class GrEffectStage; | 303 class GrProcessorStage; |
| 304 class GrBackendEffectFactory; | 304 class GrBackendProcessorFactory; |
| 305 | 305 |
| 306 /* | 306 /* |
| 307 * The interpretation of the texture matrix depends on the sample mode. The | 307 * The interpretation of the texture matrix depends on the sample mode. The |
| 308 * texture matrix is applied both when the texture coordinates are explicit | 308 * texture matrix is applied both when the texture coordinates are explicit |
| 309 * and when vertex positions are used as texture coordinates. In the latter | 309 * and when vertex positions are used as texture coordinates. In the latter |
| 310 * case the texture matrix is applied to the pre-view-matrix position | 310 * case the texture matrix is applied to the pre-view-matrix position |
| 311 * values. | 311 * values. |
| 312 * | 312 * |
| 313 * Normal SampleMode | 313 * Normal SampleMode |
| 314 * The post-matrix texture coordinates are in normalize space with (0,0) at | 314 * The post-matrix texture coordinates are in normalize space with (0,0) at |
| 315 * the top-left and (1,1) at the bottom right. | 315 * the top-left and (1,1) at the bottom right. |
| 316 * RadialGradient | 316 * RadialGradient |
| 317 * The matrix specifies the radial gradient parameters. | 317 * The matrix specifies the radial gradient parameters. |
| 318 * (0,0) in the post-matrix space is center of the radial gradient. | 318 * (0,0) in the post-matrix space is center of the radial gradient. |
| 319 * Radial2Gradient | 319 * Radial2Gradient |
| 320 * Matrix transforms to space where first circle is centered at the | 320 * Matrix transforms to space where first circle is centered at the |
| 321 * origin. The second circle will be centered (x, 0) where x may be | 321 * origin. The second circle will be centered (x, 0) where x may be |
| 322 * 0 and is provided by setRadial2Params. The post-matrix space is | 322 * 0 and is provided by setRadial2Params. The post-matrix space is |
| 323 * normalized such that 1 is the second radius - first radius. | 323 * normalized such that 1 is the second radius - first radius. |
| 324 * SweepGradient | 324 * SweepGradient |
| 325 * The angle from the origin of texture coordinates in post-matrix space | 325 * The angle from the origin of texture coordinates in post-matrix space |
| 326 * determines the gradient value. | 326 * determines the gradient value. |
| 327 */ | 327 */ |
| 328 | 328 |
| 329 class GrTextureStripAtlas; | 329 class GrTextureStripAtlas; |
| 330 | 330 |
| 331 // Base class for Gr gradient effects | 331 // Base class for Gr gradient effects |
| 332 class GrGradientEffect : public GrEffect { | 332 class GrGradientEffect : public GrFragmentProcessor { |
| 333 public: | 333 public: |
| 334 | 334 |
| 335 GrGradientEffect(GrContext* ctx, | 335 GrGradientEffect(GrContext* ctx, |
| 336 const SkGradientShaderBase& shader, | 336 const SkGradientShaderBase& shader, |
| 337 const SkMatrix& matrix, | 337 const SkMatrix& matrix, |
| 338 SkShader::TileMode tileMode); | 338 SkShader::TileMode tileMode); |
| 339 | 339 |
| 340 virtual ~GrGradientEffect(); | 340 virtual ~GrGradientEffect(); |
| 341 | 341 |
| 342 bool useAtlas() const { return SkToBool(-1 != fRow); } | 342 bool useAtlas() const { return SkToBool(-1 != fRow); } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 367 sized to be at least kMaxRandomGradientColors. stops is a pointer to an
array of at least | 367 sized to be at least kMaxRandomGradientColors. stops is a pointer to an
array of at least |
| 368 size kMaxRandomGradientColors. It may be updated to NULL, indicating tha
t NULL should be | 368 size kMaxRandomGradientColors. It may be updated to NULL, indicating tha
t NULL should be |
| 369 passed to the gradient factory rather than the array. | 369 passed to the gradient factory rather than the array. |
| 370 */ | 370 */ |
| 371 static const int kMaxRandomGradientColors = 4; | 371 static const int kMaxRandomGradientColors = 4; |
| 372 static int RandomGradientParams(SkRandom* r, | 372 static int RandomGradientParams(SkRandom* r, |
| 373 SkColor colors[kMaxRandomGradientColors], | 373 SkColor colors[kMaxRandomGradientColors], |
| 374 SkScalar** stops, | 374 SkScalar** stops, |
| 375 SkShader::TileMode* tm); | 375 SkShader::TileMode* tm); |
| 376 | 376 |
| 377 virtual bool onIsEqual(const GrEffect& effect) const SK_OVERRIDE; | 377 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE; |
| 378 | 378 |
| 379 const GrCoordTransform& getCoordTransform() const { return fCoordTransform;
} | 379 const GrCoordTransform& getCoordTransform() const { return fCoordTransform;
} |
| 380 | 380 |
| 381 private: | 381 private: |
| 382 static const GrCoordSet kCoordSet = kLocal_GrCoordSet; | 382 static const GrCoordSet kCoordSet = kLocal_GrCoordSet; |
| 383 | 383 |
| 384 GrCoordTransform fCoordTransform; | 384 GrCoordTransform fCoordTransform; |
| 385 GrTextureAccess fTextureAccess; | 385 GrTextureAccess fTextureAccess; |
| 386 SkScalar fYCoord; | 386 SkScalar fYCoord; |
| 387 GrTextureStripAtlas* fAtlas; | 387 GrTextureStripAtlas* fAtlas; |
| 388 int fRow; | 388 int fRow; |
| 389 bool fIsOpaque; | 389 bool fIsOpaque; |
| 390 SkGradientShaderBase::GpuColorType fColorType; | 390 SkGradientShaderBase::GpuColorType fColorType; |
| 391 SkColor fColors[3]; // More than 3 colors we use texture | 391 SkColor fColors[3]; // More than 3 colors we use texture |
| 392 PremulType fPremulType; // This only changes behavior for two and three colo
r special cases. | 392 PremulType fPremulType; // This only changes behavior for two and three colo
r special cases. |
| 393 // It is already baked into to the table for texture
gradients. | 393 // It is already baked into to the table for texture
gradients. |
| 394 typedef GrEffect INHERITED; | 394 typedef GrFragmentProcessor INHERITED; |
| 395 | 395 |
| 396 }; | 396 }; |
| 397 | 397 |
| 398 /////////////////////////////////////////////////////////////////////////////// | 398 /////////////////////////////////////////////////////////////////////////////// |
| 399 | 399 |
| 400 // Base class for GL gradient effects | 400 // Base class for GL gradient effects |
| 401 class GrGLGradientEffect : public GrGLEffect { | 401 class GrGLGradientEffect : public GrGLFragmentProcessor { |
| 402 public: | 402 public: |
| 403 GrGLGradientEffect(const GrBackendEffectFactory& factory); | 403 GrGLGradientEffect(const GrBackendProcessorFactory& factory); |
| 404 virtual ~GrGLGradientEffect(); | 404 virtual ~GrGLGradientEffect(); |
| 405 | 405 |
| 406 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) SK_OVER
RIDE; | 406 virtual void setData(const GrGLProgramDataManager&, const GrProcessor&) SK_O
VERRIDE; |
| 407 | 407 |
| 408 protected: | 408 protected: |
| 409 /** | 409 /** |
| 410 * Subclasses must call this. It will return a key for the part of the shade
r code controlled | 410 * Subclasses must call this. It will return a key for the part of the shade
r code controlled |
| 411 * by the base class. The subclasses must stick it in their key and then pas
s it to the below | 411 * by the base class. The subclasses must stick it in their key and then pas
s it to the below |
| 412 * emit* functions from their emitCode function. | 412 * emit* functions from their emitCode function. |
| 413 */ | 413 */ |
| 414 static uint32_t GenBaseGradientKey(const GrEffect&); | 414 static uint32_t GenBaseGradientKey(const GrProcessor&); |
| 415 | 415 |
| 416 // Emits the uniform used as the y-coord to texture samples in derived class
es. Subclasses | 416 // Emits the uniform used as the y-coord to texture samples in derived class
es. Subclasses |
| 417 // should call this method from their emitCode(). | 417 // should call this method from their emitCode(). |
| 418 void emitUniforms(GrGLProgramBuilder* builder, uint32_t baseKey); | 418 void emitUniforms(GrGLProgramBuilder* builder, uint32_t baseKey); |
| 419 | 419 |
| 420 | 420 |
| 421 // emit code that gets a fragment's color from an expression for t; Has bran
ches for 3 separate | 421 // emit code that gets a fragment's color from an expression for t; Has bran
ches for 3 separate |
| 422 // control flows inside -- 2 color gradients, 3 color symmetric gradients (b
oth using | 422 // control flows inside -- 2 color gradients, 3 color symmetric gradients (b
oth using |
| 423 // native GLSL mix), and 4+ color gradients that use the traditional texture
lookup. | 423 // native GLSL mix), and 4+ color gradients that use the traditional texture
lookup. |
| 424 void emitColor(GrGLProgramBuilder* builder, | 424 void emitColor(GrGLProgramBuilder* builder, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 return GrGradientEffect::kAfterInterp_PremulType; | 460 return GrGradientEffect::kAfterInterp_PremulType; |
| 461 } | 461 } |
| 462 } | 462 } |
| 463 | 463 |
| 464 SkScalar fCachedYCoord; | 464 SkScalar fCachedYCoord; |
| 465 GrGLProgramDataManager::UniformHandle fFSYUni; | 465 GrGLProgramDataManager::UniformHandle fFSYUni; |
| 466 GrGLProgramDataManager::UniformHandle fColorStartUni; | 466 GrGLProgramDataManager::UniformHandle fColorStartUni; |
| 467 GrGLProgramDataManager::UniformHandle fColorMidUni; | 467 GrGLProgramDataManager::UniformHandle fColorMidUni; |
| 468 GrGLProgramDataManager::UniformHandle fColorEndUni; | 468 GrGLProgramDataManager::UniformHandle fColorEndUni; |
| 469 | 469 |
| 470 typedef GrGLEffect INHERITED; | 470 typedef GrGLFragmentProcessor INHERITED; |
| 471 }; | 471 }; |
| 472 | 472 |
| 473 #endif | 473 #endif |
| 474 | 474 |
| 475 #endif | 475 #endif |
| OLD | NEW |