Index: src/effects/SkPerlinNoiseShader.cpp |
diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp |
index 40da2db14a11871dd0fb469887ad7ef6e510c114..af6622be4dbc5bc37ad30d6b6513f464929297d8 100644 |
--- a/src/effects/SkPerlinNoiseShader.cpp |
+++ b/src/effects/SkPerlinNoiseShader.cpp |
@@ -19,8 +19,6 @@ |
#include "GrCoordTransform.h" |
#include "GrInvariantOutput.h" |
#include "SkGr.h" |
-#include "effects/GrConstColorProcessor.h" |
-#include "effects/GrExtractAlphaFragmentProcessor.h" |
#include "gl/GrGLFragmentProcessor.h" |
#include "gl/builders/GrGLProgramBuilder.h" |
#endif |
@@ -502,6 +500,7 @@ |
bool fStitchTiles; |
int fNumOctaves; |
GrGLProgramDataManager::UniformHandle fBaseFrequencyUni; |
+ GrGLProgramDataManager::UniformHandle fAlphaUni; |
private: |
typedef GrGLFragmentProcessor INHERITED; |
@@ -516,9 +515,9 @@ |
int numOctaves, bool stitchTiles, |
SkPerlinNoiseShader::PaintingData* paintingData, |
GrTexture* permutationsTexture, GrTexture* noiseTexture, |
- const SkMatrix& matrix) { |
+ const SkMatrix& matrix, uint8_t alpha) { |
return new GrPerlinNoiseEffect(procDataManager, type, numOctaves, stitchTiles, paintingData, |
- permutationsTexture, noiseTexture, matrix); |
+ permutationsTexture, noiseTexture, matrix, alpha); |
} |
virtual ~GrPerlinNoiseEffect() { delete fPaintingData; } |
@@ -532,6 +531,7 @@ |
const SkVector& baseFrequency() const { return fPaintingData->fBaseFrequency; } |
int numOctaves() const { return fNumOctaves; } |
const SkMatrix& matrix() const { return fCoordTransform.getMatrix(); } |
+ uint8_t alpha() const { return fAlpha; } |
private: |
GrGLFragmentProcessor* onCreateGLInstance() const override { |
@@ -549,6 +549,7 @@ |
fPaintingData->fBaseFrequency == s.fPaintingData->fBaseFrequency && |
fNumOctaves == s.fNumOctaves && |
fStitchTiles == s.fStitchTiles && |
+ fAlpha == s.fAlpha && |
fPaintingData->fStitchDataInit == s.fPaintingData->fStitchDataInit; |
} |
@@ -560,10 +561,11 @@ |
int numOctaves, bool stitchTiles, |
SkPerlinNoiseShader::PaintingData* paintingData, |
GrTexture* permutationsTexture, GrTexture* noiseTexture, |
- const SkMatrix& matrix) |
+ const SkMatrix& matrix, uint8_t alpha) |
: fType(type) |
, fNumOctaves(numOctaves) |
, fStitchTiles(stitchTiles) |
+ , fAlpha(alpha) |
, fPermutationsAccess(permutationsTexture) |
, fNoiseAccess(noiseTexture) |
, fPaintingData(paintingData) { |
@@ -580,6 +582,7 @@ |
GrCoordTransform fCoordTransform; |
int fNumOctaves; |
bool fStitchTiles; |
+ uint8_t fAlpha; |
GrTextureAccess fPermutationsAccess; |
GrTextureAccess fNoiseAccess; |
SkPerlinNoiseShader::PaintingData *fPaintingData; |
@@ -591,7 +594,7 @@ |
///////////////////////////////////////////////////////////////////// |
GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrPerlinNoiseEffect); |
-const GrFragmentProcessor* GrPerlinNoiseEffect::TestCreate(GrProcessorTestData* d) { |
+GrFragmentProcessor* GrPerlinNoiseEffect::TestCreate(GrProcessorTestData* d) { |
int numOctaves = d->fRandom->nextRangeU(2, 10); |
bool stitchTiles = d->fRandom->nextBool(); |
SkScalar seed = SkIntToScalar(d->fRandom->nextU()); |
@@ -608,12 +611,14 @@ |
SkPerlinNoiseShader::CreateTurbulence(baseFrequencyX, baseFrequencyY, numOctaves, seed, |
stitchTiles ? &tileSize : nullptr); |
+ SkPaint paint; |
+ GrColor paintColor; |
GrFragmentProcessor* effect; |
GrPaint grPaint; |
- return shader->asFragmentProcessor(d->fContext, |
- GrTest::TestMatrix(d->fRandom), NULL, |
- kNone_SkFilterQuality, |
- grPaint.getProcessorDataManager()); |
+ SkAssertResult(shader->asFragmentProcessor(d->fContext, paint, |
+ GrTest::TestMatrix(d->fRandom), nullptr, |
+ &paintColor, grPaint.getProcessorDataManager(), |
+ &effect)); |
delete shader; |
@@ -634,6 +639,10 @@ |
kVec2f_GrSLType, kDefault_GrSLPrecision, |
"baseFrequency"); |
const char* baseFrequencyUni = args.fBuilder->getUniformCStr(fBaseFrequencyUni); |
+ fAlphaUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
+ kFloat_GrSLType, kDefault_GrSLPrecision, |
+ "alpha"); |
+ const char* alphaUni = args.fBuilder->getUniformCStr(fAlphaUni); |
const char* stitchDataUni = nullptr; |
if (fStitchTiles) { |
@@ -866,6 +875,8 @@ |
args.fOutputColor,args.fOutputColor); |
} |
+ fsBuilder->codeAppendf("\n\t\t%s.a *= %s;", args.fOutputColor, alphaUni); |
+ |
// Clamp values |
fsBuilder->codeAppendf("\n\t\t%s = clamp(%s, 0.0, 1.0);", args.fOutputColor, args.fOutputColor); |
@@ -909,6 +920,7 @@ |
const SkVector& baseFrequency = turbulence.baseFrequency(); |
pdman.set2f(fBaseFrequencyUni, baseFrequency.fX, baseFrequency.fY); |
+ pdman.set1f(fAlphaUni, SkIntToScalar(turbulence.alpha()) / 255); |
if (turbulence.stitchTiles()) { |
const SkPerlinNoiseShader::StitchData& stitchData = turbulence.stitchData(); |
@@ -918,10 +930,16 @@ |
} |
///////////////////////////////////////////////////////////////////// |
-const GrFragmentProcessor* SkPerlinNoiseShader::asFragmentProcessor(GrContext* context, |
- const SkMatrix& viewM, const SkMatrix* externalLocalMatrix, SkFilterQuality, |
- GrProcessorDataManager* procDataManager) const { |
+ |
+bool SkPerlinNoiseShader::asFragmentProcessor(GrContext* context, const SkPaint& paint, |
+ const SkMatrix& viewM, |
+ const SkMatrix* externalLocalMatrix, |
+ GrColor* paintColor, |
+ GrProcessorDataManager* procDataManager, |
+ GrFragmentProcessor** fp) const { |
SkASSERT(context); |
+ |
+ *paintColor = SkColor2GrColorJustAlpha(paint.getColor()); |
SkMatrix localMatrix = this->getLocalMatrix(); |
if (externalLocalMatrix) { |
@@ -933,14 +951,13 @@ |
if (0 == fNumOctaves) { |
if (kFractalNoise_Type == fType) { |
- // Extract the incoming alpha and emit rgba = (a/4, a/4, a/4, a/2) |
- SkAutoTUnref<const GrFragmentProcessor> inner( |
- GrConstColorProcessor::Create(0x80404040, |
- GrConstColorProcessor::kModulateRGBA_InputMode)); |
- return GrExtractAlphaFragmentProcessor::Create(inner); |
- } |
- // Emit zero. |
- return GrConstColorProcessor::Create(0x0, GrConstColorProcessor::kIgnore_InputMode); |
+ uint32_t alpha = paint.getAlpha() >> 1; |
+ uint32_t rgb = alpha >> 1; |
+ *paintColor = GrColorPackRGBA(rgb, rgb, rgb, alpha); |
+ } else { |
+ *paintColor = 0; |
+ } |
+ return true; |
} |
// Either we don't stitch tiles, either we have a valid tile size |
@@ -957,18 +974,27 @@ |
m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); |
m.setTranslateY(-localMatrix.getTranslateY() + SK_Scalar1); |
if ((permutationsTexture) && (noiseTexture)) { |
- SkAutoTUnref<GrFragmentProcessor> inner( |
- GrPerlinNoiseEffect::Create(procDataManager, |
- fType, |
- fNumOctaves, |
- fStitchTiles, |
- paintingData, |
- permutationsTexture, noiseTexture, |
- m)); |
- return GrExtractAlphaFragmentProcessor::Create(inner); |
- } |
- delete paintingData; |
- return nullptr; |
+ *fp = GrPerlinNoiseEffect::Create(procDataManager, |
+ fType, |
+ fNumOctaves, |
+ fStitchTiles, |
+ paintingData, |
+ permutationsTexture, noiseTexture, |
+ m, paint.getAlpha()); |
+ } else { |
+ delete paintingData; |
+ *fp = nullptr; |
+ } |
+ return true; |
+} |
+ |
+#else |
+ |
+bool SkPerlinNoiseShader::asFragmentProcessor(GrContext*, const SkPaint&, const SkMatrix&, |
+ const SkMatrix*, GrColor*, GrProcessorDataManager*, |
+ GrFragmentProcessor**) const { |
+ SkDEBUGFAIL("Should not call in GPU-less build"); |
+ return false; |
} |
#endif |