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

Unified Diff: src/effects/gradients/SkGradientShaderPriv.h

Issue 2241483003: Revert of Exact Ganesh Gradients for Special Cases (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/effects/gradients/SkGradientShader.cpp ('k') | src/effects/gradients/SkSweepGradient.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/gradients/SkGradientShaderPriv.h
diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h
index ba3a65a20af46f35a546d25aeec8bce2d2af7bd7..50ad427e4ae1d5f3aa03f37b79e496d930be5b52 100644
--- a/src/effects/gradients/SkGradientShaderPriv.h
+++ b/src/effects/gradients/SkGradientShaderPriv.h
@@ -18,10 +18,6 @@
#include "SkUtils.h"
#include "SkShader.h"
#include "SkOnce.h"
-
-#if SK_SUPPORT_GPU
- #define GR_GL_USE_ACCURATE_HARD_STOP_GRADIENTS 1
-#endif
static inline void sk_memset32_dither(uint32_t dst[], uint32_t v0, uint32_t v1,
int count) {
@@ -132,8 +128,7 @@
bool getDither() const { return fCacheDither; }
private:
- // Working pointers. If either is nullptr, we need to recompute the corresponding
- // cache values.
+ // Working pointers. If either is nullptr, we need to recompute the corresponding cache values.
uint16_t* fCache16;
SkPMColor* fCache32;
@@ -202,6 +197,17 @@
kDitherStride16 = kCache16Count,
};
+ enum GpuColorType {
+ kTwo_GpuColorType,
+ kThree_GpuColorType, // Symmetric three color
+ kTexture_GpuColorType
+ };
+
+ // Determines and returns the gradient is a two color gradient, symmetric three color gradient
+ // or other (texture gradient). If it is two or symmetric three color, the colors array will
+ // also be filled with the gradient colors
+ GpuColorType getGpuColorType(SkColor colors[3]) const;
+
uint32_t getGradFlags() const { return fGradFlags; }
protected:
@@ -214,6 +220,7 @@
const SkMatrix fPtsToUnit;
TileMode fTileMode;
TileProc fTileProc;
+ int fColorCount;
uint8_t fGradFlags;
struct Rec {
@@ -247,14 +254,8 @@
public:
SkColor* fOrigColors; // original colors, before modulation by paint in context.
SkScalar* fOrigPos; // original positions
- int fColorCount;
-
- SkTArray<sk_sp<SkShader>> fSubGradients;
bool colorsAreOpaque() const { return fColorsAreOpaque; }
-
- TileMode getTileMode() const { return fTileMode; }
- Rec* getRecs() const { return fRecs; }
private:
bool fColorsAreOpaque;
@@ -335,30 +336,9 @@
virtual ~GrGradientEffect();
bool useAtlas() const { return SkToBool(-1 != fRow); }
- SkScalar getYCoord() const { return fYCoord; }
-
- enum ColorType {
- kTwo_ColorType,
- kThree_ColorType, // Symmetric three color
- kTexture_ColorType,
-
-#if GR_GL_USE_ACCURATE_HARD_STOP_GRADIENTS
- kHardStopCentered_ColorType, // 0, 0.5, 0.5, 1
- kHardStopLeftEdged_ColorType, // 0, 0, 1
- kHardStopRightEdged_ColorType, // 0, 1, 1
-#endif
- };
-
- ColorType getColorType() const { return fColorType; }
-
- // Determines the type of gradient, one of:
- // - Two-color
- // - Symmetric three-color
- // - Texture
- // - Centered hard stop
- // - Left-edged hard stop
- // - Right-edged hard stop
- ColorType determineColorType(const SkGradientShaderBase& shader);
+ SkScalar getYCoord() const { return fYCoord; };
+
+ SkGradientShaderBase::GpuColorType getColorType() const { return fColorType; }
enum PremulType {
kBeforeInterp_PremulType,
@@ -368,8 +348,8 @@
PremulType getPremulType() const { return fPremulType; }
const SkColor* getColors(int pos) const {
- SkASSERT(fColorType != kTexture_ColorType);
- SkASSERT(pos < fColors.count());
+ SkASSERT(fColorType != SkGradientShaderBase::kTexture_GpuColorType);
+ SkASSERT((pos-1) <= fColorType);
return &fColors[pos];
}
@@ -378,8 +358,8 @@
The function decides whether stop values should be used or not. The return value indicates
the number of colors, which will be capped by kMaxRandomGradientColors. colors should be
sized to be at least kMaxRandomGradientColors. stops is a pointer to an array of at least
- size kMaxRandomGradientColors. It may be updated to nullptr, indicating that nullptr should
- be passed to the gradient factory rather than the array.
+ size kMaxRandomGradientColors. It may be updated to nullptr, indicating that nullptr should be
+ passed to the gradient factory rather than the array.
*/
static const int kMaxRandomGradientColors = 4;
static int RandomGradientParams(SkRandom* r,
@@ -396,31 +376,26 @@
private:
static const GrCoordSet kCoordSet = kLocal_GrCoordSet;
- SkTDArray<SkColor> fColors;
- SkTDArray<SkScalar> fPositions;
- SkShader::TileMode fTileMode;
-
GrCoordTransform fCoordTransform;
GrTextureAccess fTextureAccess;
SkScalar fYCoord;
GrTextureStripAtlas* fAtlas;
int fRow;
bool fIsOpaque;
- ColorType fColorType;
- PremulType fPremulType; // This is already baked into the table for texture gradients, and
- // only changes behavior for gradients that don't use a texture.
+ SkGradientShaderBase::GpuColorType fColorType;
+ SkColor fColors[3]; // More than 3 colors we use texture
+ PremulType fPremulType; // This only changes behavior for two and three color special cases.
+ // It is already baked into to the table for texture gradients.
typedef GrFragmentProcessor INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
-// Base class for GL gradient effects
+// Base class for GLSL gradient effects
class GrGradientEffect::GLSLProcessor : public GrGLSLFragmentProcessor {
public:
- GLSLProcessor() {
- fCachedYCoord = SK_ScalarMax;
- }
+ GLSLProcessor();
protected:
void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override;
@@ -437,10 +412,10 @@
// should call this method from their emitCode().
void emitUniforms(GrGLSLUniformHandler*, const GrGradientEffect&);
- // Emit code that gets a fragment's color from an expression for t; has branches for
- // several control flows inside -- 2-color gradients, 3-color symmetric gradients, 4+
- // color gradients that use the traditional texture lookup, as well as several varieties
- // of hard stop gradients
+
+ // emit code that gets a fragment's color from an expression for t; Has branches for 3 separate
+ // control flows inside -- 2 color gradients, 3 color symmetric gradients (both using
+ // native GLSL mix), and 4+ color gradients that use the traditional texture lookup.
void emitColor(GrGLSLFPFragmentBuilder* fragBuilder,
GrGLSLUniformHandler* uniformHandler,
const GrGLSLCaps* caps,
@@ -453,30 +428,18 @@
private:
enum {
// First bit for premul before/after interp
- kPremulBeforeInterpKey = 1,
-
- // Next three bits for 2/3 color type or different special
- // hard stop cases (neither means using texture atlas)
- kTwoColorKey = 2,
- kThreeColorKey = 4,
-#if GR_GL_USE_ACCURATE_HARD_STOP_GRADIENTS
- kHardStopCenteredKey = 6,
- kHardStopZeroZeroOneKey = 8,
- kHardStopZeroOneOneKey = 10,
-
- // Next two bits for tile mode
- kClampTileMode = 16,
- kRepeatTileMode = 32,
- kMirrorTileMode = 48,
-
- // Lower six bits for premul, 2/3 color type, and tile mode
- kReservedBits = 6,
-#endif
+ kPremulBeforeInterpKey = 1,
+
+ // Next two bits for 2/3 color type (neither means using texture atlas)
+ kTwoColorKey = 4,
+ kThreeColorKey = 6,
};
SkScalar fCachedYCoord;
- GrGLSLProgramDataManager::UniformHandle fColorsUni;
GrGLSLProgramDataManager::UniformHandle fFSYUni;
+ GrGLSLProgramDataManager::UniformHandle fColorStartUni;
+ GrGLSLProgramDataManager::UniformHandle fColorMidUni;
+ GrGLSLProgramDataManager::UniformHandle fColorEndUni;
typedef GrGLSLFragmentProcessor INHERITED;
};
« no previous file with comments | « src/effects/gradients/SkGradientShader.cpp ('k') | src/effects/gradients/SkSweepGradient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698