| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 #include "GrCircleBlurFragmentProcessor.h" | 9 #include "GrCircleBlurFragmentProcessor.h" |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 // The data is formatted as: | 39 // The data is formatted as: |
| 40 // x,y - the center of the circle | 40 // x,y - the center of the circle |
| 41 // z - the distance at which the intensity starts falling off (e.g., the
start of the table) | 41 // z - the distance at which the intensity starts falling off (e.g., the
start of the table) |
| 42 // w - the size of the profile texture | 42 // w - the size of the profile texture |
| 43 fDataUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Vis
ibility, | 43 fDataUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Vis
ibility, |
| 44 kVec4f_GrSLType, | 44 kVec4f_GrSLType, |
| 45 kDefault_GrSLPrecision, | 45 kDefault_GrSLPrecision, |
| 46 "data", | 46 "data", |
| 47 &dataName); | 47 &dataName); |
| 48 | 48 |
| 49 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; | 49 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 50 const char *fragmentPos = fsBuilder->fragmentPosition(); | 50 const char *fragmentPos = fragBuilder->fragmentPosition(); |
| 51 | 51 |
| 52 if (args.fInputColor) { | 52 if (args.fInputColor) { |
| 53 fsBuilder->codeAppendf("vec4 src=%s;", args.fInputColor); | 53 fragBuilder->codeAppendf("vec4 src=%s;", args.fInputColor); |
| 54 } else { | 54 } else { |
| 55 fsBuilder->codeAppendf("vec4 src=vec4(1);"); | 55 fragBuilder->codeAppendf("vec4 src=vec4(1);"); |
| 56 } | 56 } |
| 57 | 57 |
| 58 fsBuilder->codeAppendf("vec2 vec = %s.xy - %s.xy;", fragmentPos, dataName); | 58 fragBuilder->codeAppendf("vec2 vec = %s.xy - %s.xy;", fragmentPos, dataName)
; |
| 59 fsBuilder->codeAppendf("float dist = (length(vec) - %s.z + 0.5) / %s.w;", da
taName, dataName); | 59 fragBuilder->codeAppendf("float dist = (length(vec) - %s.z + 0.5) / %s.w;",
dataName, dataName); |
| 60 | 60 |
| 61 fsBuilder->codeAppendf("float intensity = "); | 61 fragBuilder->codeAppendf("float intensity = "); |
| 62 fsBuilder->appendTextureLookup(args.fSamplers[0], "vec2(dist, 0.5)"); | 62 fragBuilder->appendTextureLookup(args.fSamplers[0], "vec2(dist, 0.5)"); |
| 63 fsBuilder->codeAppend(".a;"); | 63 fragBuilder->codeAppend(".a;"); |
| 64 | 64 |
| 65 fsBuilder->codeAppendf("%s = src * intensity;\n", args.fOutputColor ); | 65 fragBuilder->codeAppendf("%s = src * intensity;\n", args.fOutputColor ); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void GrGLCircleBlurFragmentProcessor::onSetData(const GrGLSLProgramDataManager&
pdman, | 68 void GrGLCircleBlurFragmentProcessor::onSetData(const GrGLSLProgramDataManager&
pdman, |
| 69 const GrProcessor& proc) { | 69 const GrProcessor& proc) { |
| 70 const GrCircleBlurFragmentProcessor& cbfp = proc.cast<GrCircleBlurFragmentPr
ocessor>(); | 70 const GrCircleBlurFragmentProcessor& cbfp = proc.cast<GrCircleBlurFragmentPr
ocessor>(); |
| 71 const SkRect& circle = cbfp.circle(); | 71 const SkRect& circle = cbfp.circle(); |
| 72 | 72 |
| 73 // The data is formatted as: | 73 // The data is formatted as: |
| 74 // x,y - the center of the circle | 74 // x,y - the center of the circle |
| 75 // z - the distance at which the intensity starts falling off (e.g., the
start of the table) | 75 // z - the distance at which the intensity starts falling off (e.g., the
start of the table) |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCircleBlurFragmentProcessor); | 252 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCircleBlurFragmentProcessor); |
| 253 | 253 |
| 254 const GrFragmentProcessor* GrCircleBlurFragmentProcessor::TestCreate(GrProcessor
TestData* d) { | 254 const GrFragmentProcessor* GrCircleBlurFragmentProcessor::TestCreate(GrProcessor
TestData* d) { |
| 255 SkScalar wh = d->fRandom->nextRangeScalar(100.f, 1000.f); | 255 SkScalar wh = d->fRandom->nextRangeScalar(100.f, 1000.f); |
| 256 SkScalar sigma = d->fRandom->nextRangeF(1.f,10.f); | 256 SkScalar sigma = d->fRandom->nextRangeF(1.f,10.f); |
| 257 SkRect circle = SkRect::MakeWH(wh, wh); | 257 SkRect circle = SkRect::MakeWH(wh, wh); |
| 258 return GrCircleBlurFragmentProcessor::Create(d->fContext->textureProvider(),
circle, sigma); | 258 return GrCircleBlurFragmentProcessor::Create(d->fContext->textureProvider(),
circle, sigma); |
| 259 } | 259 } |
| 260 | 260 |
| 261 #endif | 261 #endif |
| OLD | NEW |