Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: src/effects/gradients/SkGradientShaderPriv.h

Issue 2221133002: Refactor various gradient effect classes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Brian's suggestions Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/gradients/SkGradientShader.cpp ('k') | src/effects/gradients/SkLinearGradient.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 * SweepGradient 319 * SweepGradient
320 * The angle from the origin of texture coordinates in post-matrix space 320 * The angle from the origin of texture coordinates in post-matrix space
321 * determines the gradient value. 321 * determines the gradient value.
322 */ 322 */
323 323
324 class GrTextureStripAtlas; 324 class GrTextureStripAtlas;
325 325
326 // Base class for Gr gradient effects 326 // Base class for Gr gradient effects
327 class GrGradientEffect : public GrFragmentProcessor { 327 class GrGradientEffect : public GrFragmentProcessor {
328 public: 328 public:
329 class GLSLProcessor;
329 330
330 GrGradientEffect(GrContext* ctx, 331 GrGradientEffect(GrContext* ctx,
331 const SkGradientShaderBase& shader, 332 const SkGradientShaderBase& shader,
332 const SkMatrix& matrix, 333 const SkMatrix& matrix,
333 SkShader::TileMode tileMode); 334 SkShader::TileMode tileMode);
334 335
335 virtual ~GrGradientEffect(); 336 virtual ~GrGradientEffect();
336 337
337 bool useAtlas() const { return SkToBool(-1 != fRow); } 338 bool useAtlas() const { return SkToBool(-1 != fRow); }
338 SkScalar getYCoord() const { return fYCoord; }; 339 SkScalar getYCoord() const { return fYCoord; };
339 340
340 SkGradientShaderBase::GpuColorType getColorType() const { return fColorType; } 341 SkGradientShaderBase::GpuColorType getColorType() const { return fColorType; }
341 342
342 enum PremulType { 343 enum PremulType {
343 kBeforeInterp_PremulType, 344 kBeforeInterp_PremulType,
344 kAfterInterp_PremulType, 345 kAfterInterp_PremulType,
345 }; 346 };
346 347
347 PremulType getPremulType() const { return fPremulType; } 348 PremulType getPremulType() const { return fPremulType; }
348 349
349 const SkColor* getColors(int pos) const { 350 const SkColor* getColors(int pos) const {
350 SkASSERT(fColorType != SkGradientShaderBase::kTexture_GpuColorType); 351 SkASSERT(fColorType != SkGradientShaderBase::kTexture_GpuColorType);
351 SkASSERT((pos-1) <= fColorType); 352 SkASSERT((pos-1) <= fColorType);
352 return &fColors[pos]; 353 return &fColors[pos];
353 } 354 }
354 355
355 protected: 356 protected:
356
357 /** Populates a pair of arrays with colors and stop info to construct a rand om gradient. 357 /** Populates a pair of arrays with colors and stop info to construct a rand om gradient.
358 The function decides whether stop values should be used or not. The retu rn value indicates 358 The function decides whether stop values should be used or not. The retu rn value indicates
359 the number of colors, which will be capped by kMaxRandomGradientColors. colors should be 359 the number of colors, which will be capped by kMaxRandomGradientColors. colors should be
360 sized to be at least kMaxRandomGradientColors. stops is a pointer to an array of at least 360 sized to be at least kMaxRandomGradientColors. stops is a pointer to an array of at least
361 size kMaxRandomGradientColors. It may be updated to nullptr, indicating that nullptr should be 361 size kMaxRandomGradientColors. It may be updated to nullptr, indicating that nullptr should be
362 passed to the gradient factory rather than the array. 362 passed to the gradient factory rather than the array.
363 */ 363 */
364 static const int kMaxRandomGradientColors = 4; 364 static const int kMaxRandomGradientColors = 4;
365 static int RandomGradientParams(SkRandom* r, 365 static int RandomGradientParams(SkRandom* r,
366 SkColor colors[kMaxRandomGradientColors], 366 SkColor colors[kMaxRandomGradientColors],
(...skipping 18 matching lines...) Expand all
385 SkGradientShaderBase::GpuColorType fColorType; 385 SkGradientShaderBase::GpuColorType fColorType;
386 SkColor fColors[3]; // More than 3 colors we use texture 386 SkColor fColors[3]; // More than 3 colors we use texture
387 PremulType fPremulType; // This only changes behavior for two and three colo r special cases. 387 PremulType fPremulType; // This only changes behavior for two and three colo r special cases.
388 // It is already baked into to the table for texture gradients. 388 // It is already baked into to the table for texture gradients.
389 typedef GrFragmentProcessor INHERITED; 389 typedef GrFragmentProcessor INHERITED;
390 390
391 }; 391 };
392 392
393 /////////////////////////////////////////////////////////////////////////////// 393 ///////////////////////////////////////////////////////////////////////////////
394 394
395 // Base class for GL gradient effects 395 // Base class for GLSL gradient effects
396 class GrGLGradientEffect : public GrGLSLFragmentProcessor { 396 class GrGradientEffect::GLSLProcessor : public GrGLSLFragmentProcessor {
397 public: 397 public:
398 GrGLGradientEffect(); 398 GLSLProcessor();
399 399
400 protected: 400 protected:
401 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ; 401 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override ;
402 402
403 protected: 403 protected:
404 /** 404 /**
405 * Subclasses must call this. It will return a key for the part of the shade r code controlled 405 * Subclasses must call this. It will return a key for the part of the shade r code controlled
406 * by the base class. The subclasses must stick it in their key and then pas s it to the below 406 * by the base class. The subclasses must stick it in their key and then pas s it to the below
407 * emit* functions from their emitCode function. 407 * emit* functions from their emitCode function.
408 */ 408 */
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 GrGLSLProgramDataManager::UniformHandle fColorStartUni; 440 GrGLSLProgramDataManager::UniformHandle fColorStartUni;
441 GrGLSLProgramDataManager::UniformHandle fColorMidUni; 441 GrGLSLProgramDataManager::UniformHandle fColorMidUni;
442 GrGLSLProgramDataManager::UniformHandle fColorEndUni; 442 GrGLSLProgramDataManager::UniformHandle fColorEndUni;
443 443
444 typedef GrGLSLFragmentProcessor INHERITED; 444 typedef GrGLSLFragmentProcessor INHERITED;
445 }; 445 };
446 446
447 #endif 447 #endif
448 448
449 #endif 449 #endif
OLDNEW
« no previous file with comments | « src/effects/gradients/SkGradientShader.cpp ('k') | src/effects/gradients/SkLinearGradient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698