OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
4 * | 3 * |
5 * 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 |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 #include "GrCircleBlurFragmentProcessor.h" | 8 #include "GrCircleBlurFragmentProcessor.h" |
10 | 9 |
11 #if SK_SUPPORT_GPU | 10 #if SK_SUPPORT_GPU |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 const char *fragmentPos = fragBuilder->fragmentPosition(); | 49 const char *fragmentPos = fragBuilder->fragmentPosition(); |
51 | 50 |
52 if (args.fInputColor) { | 51 if (args.fInputColor) { |
53 fragBuilder->codeAppendf("vec4 src=%s;", args.fInputColor); | 52 fragBuilder->codeAppendf("vec4 src=%s;", args.fInputColor); |
54 } else { | 53 } else { |
55 fragBuilder->codeAppendf("vec4 src=vec4(1);"); | 54 fragBuilder->codeAppendf("vec4 src=vec4(1);"); |
56 } | 55 } |
57 | 56 |
58 // We just want to compute "length(vec) - %s.z + 0.5) * %s.w" but need to re
arrange | 57 // We just want to compute "length(vec) - %s.z + 0.5) * %s.w" but need to re
arrange |
59 // for precision | 58 // for precision |
60 fragBuilder->codeAppendf("vec2 vec = vec2( (%s.x - %s.x) * %s.w , (%s.y - %s
.y) * %s.w );", | 59 fragBuilder->codeAppendf("vec2 vec = vec2( (%s.x - %s.x) * %s.w , (%s.y - %s
.y) * %s.w );", |
61 fragmentPos, dataName, dataName, | 60 fragmentPos, dataName, dataName, |
62 fragmentPos, dataName, dataName); | 61 fragmentPos, dataName, dataName); |
63 fragBuilder->codeAppendf("float dist = length(vec) + ( 0.5 - %s.z ) * %s.w;"
, | 62 fragBuilder->codeAppendf("float dist = length(vec) + ( 0.5 - %s.z ) * %s.w;"
, |
64 dataName, dataName); | 63 dataName, dataName); |
65 | 64 |
66 fragBuilder->codeAppendf("float intensity = "); | 65 fragBuilder->codeAppendf("float intensity = "); |
67 fragBuilder->appendTextureLookup(args.fSamplers[0], "vec2(dist, 0.5)"); | 66 fragBuilder->appendTextureLookup(args.fSamplers[0], "vec2(dist, 0.5)"); |
68 fragBuilder->codeAppend(".a;"); | 67 fragBuilder->codeAppend(".a;"); |
69 | 68 |
70 fragBuilder->codeAppendf("%s = src * intensity;\n", args.fOutputColor ); | 69 fragBuilder->codeAppendf("%s = src * intensity;\n", args.fOutputColor ); |
(...skipping 10 matching lines...) Expand all Loading... |
81 // w - the inverse of the profile texture size | 80 // w - the inverse of the profile texture size |
82 pdman.set4f(fDataUniform, circle.centerX(), circle.centerY(), cbfp.offset(), | 81 pdman.set4f(fDataUniform, circle.centerX(), circle.centerY(), cbfp.offset(), |
83 1.0f / cbfp.profileSize()); | 82 1.0f / cbfp.profileSize()); |
84 } | 83 } |
85 | 84 |
86 /////////////////////////////////////////////////////////////////////////////// | 85 /////////////////////////////////////////////////////////////////////////////// |
87 | 86 |
88 GrCircleBlurFragmentProcessor::GrCircleBlurFragmentProcessor(const SkRect& circl
e, | 87 GrCircleBlurFragmentProcessor::GrCircleBlurFragmentProcessor(const SkRect& circl
e, |
89 float sigma, | 88 float sigma, |
90 float offset, | 89 float offset, |
91 GrTexture* blurProf
ile) | 90 GrTexture* blurProf
ile) |
92 : fCircle(circle) | 91 : fCircle(circle) |
93 , fSigma(sigma) | 92 , fSigma(sigma) |
94 , fOffset(offset) | 93 , fOffset(offset) |
95 , fBlurProfileAccess(blurProfile, GrTextureParams::kBilerp_FilterMode) { | 94 , fBlurProfileAccess(blurProfile, GrTextureParams::kBilerp_FilterMode) { |
96 this->initClassID<GrCircleBlurFragmentProcessor>(); | 95 this->initClassID<GrCircleBlurFragmentProcessor>(); |
97 this->addTextureAccess(&fBlurProfileAccess); | 96 this->addTextureAccess(&fBlurProfileAccess); |
98 this->setWillReadFragmentPosition(); | 97 this->setWillReadFragmentPosition(); |
99 } | 98 } |
100 | 99 |
101 GrGLSLFragmentProcessor* GrCircleBlurFragmentProcessor::onCreateGLSLInstance() c
onst { | 100 GrGLSLFragmentProcessor* GrCircleBlurFragmentProcessor::onCreateGLSLInstance() c
onst { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCircleBlurFragmentProcessor); | 258 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCircleBlurFragmentProcessor); |
260 | 259 |
261 const GrFragmentProcessor* GrCircleBlurFragmentProcessor::TestCreate(GrProcessor
TestData* d) { | 260 const GrFragmentProcessor* GrCircleBlurFragmentProcessor::TestCreate(GrProcessor
TestData* d) { |
262 SkScalar wh = d->fRandom->nextRangeScalar(100.f, 1000.f); | 261 SkScalar wh = d->fRandom->nextRangeScalar(100.f, 1000.f); |
263 SkScalar sigma = d->fRandom->nextRangeF(1.f,10.f); | 262 SkScalar sigma = d->fRandom->nextRangeF(1.f,10.f); |
264 SkRect circle = SkRect::MakeWH(wh, wh); | 263 SkRect circle = SkRect::MakeWH(wh, wh); |
265 return GrCircleBlurFragmentProcessor::Create(d->fContext->textureProvider(),
circle, sigma); | 264 return GrCircleBlurFragmentProcessor::Create(d->fContext->textureProvider(),
circle, sigma); |
266 } | 265 } |
267 | 266 |
268 #endif | 267 #endif |
OLD | NEW |