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 |
11 #if SK_SUPPORT_GPU | 11 #if SK_SUPPORT_GPU |
12 | 12 |
13 #include "GrContext.h" | 13 #include "GrContext.h" |
14 #include "GrTextureProvider.h" | 14 #include "GrTextureProvider.h" |
15 | 15 |
16 #include "gl/GrGLFragmentProcessor.h" | 16 #include "gl/GrGLFragmentProcessor.h" |
17 #include "gl/builders/GrGLProgramBuilder.h" | 17 #include "gl/builders/GrGLProgramBuilder.h" |
| 18 #include "glsl/GrGLSLProgramDataManager.h" |
18 | 19 |
19 class GrGLCircleBlurFragmentProcessor : public GrGLFragmentProcessor { | 20 class GrGLCircleBlurFragmentProcessor : public GrGLFragmentProcessor { |
20 public: | 21 public: |
21 GrGLCircleBlurFragmentProcessor(const GrProcessor&) {} | 22 GrGLCircleBlurFragmentProcessor(const GrProcessor&) {} |
22 void emitCode(EmitArgs&) override; | 23 void emitCode(EmitArgs&) override; |
23 | 24 |
24 protected: | 25 protected: |
25 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; | 26 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
26 | 27 |
27 private: | 28 private: |
28 GrGLProgramDataManager::UniformHandle fDataUniform; | 29 GrGLSLProgramDataManager::UniformHandle fDataUniform; |
29 | 30 |
30 typedef GrGLFragmentProcessor INHERITED; | 31 typedef GrGLFragmentProcessor INHERITED; |
31 }; | 32 }; |
32 | 33 |
33 void GrGLCircleBlurFragmentProcessor::emitCode(EmitArgs& args) { | 34 void GrGLCircleBlurFragmentProcessor::emitCode(EmitArgs& args) { |
34 | 35 |
35 const char *dataName; | 36 const char *dataName; |
36 | 37 |
37 // The data is formatted as: | 38 // The data is formatted as: |
38 // x,y - the center of the circle | 39 // x,y - the center of the circle |
(...skipping 17 matching lines...) Expand all Loading... |
56 fsBuilder->codeAppendf("vec2 vec = %s.xy - %s.xy;", fragmentPos, dataName); | 57 fsBuilder->codeAppendf("vec2 vec = %s.xy - %s.xy;", fragmentPos, dataName); |
57 fsBuilder->codeAppendf("float dist = (length(vec) - %s.z + 0.5) / %s.w;", da
taName, dataName); | 58 fsBuilder->codeAppendf("float dist = (length(vec) - %s.z + 0.5) / %s.w;", da
taName, dataName); |
58 | 59 |
59 fsBuilder->codeAppendf("float intensity = "); | 60 fsBuilder->codeAppendf("float intensity = "); |
60 fsBuilder->appendTextureLookup(args.fSamplers[0], "vec2(dist, 0.5)"); | 61 fsBuilder->appendTextureLookup(args.fSamplers[0], "vec2(dist, 0.5)"); |
61 fsBuilder->codeAppend(".a;"); | 62 fsBuilder->codeAppend(".a;"); |
62 | 63 |
63 fsBuilder->codeAppendf("%s = src * intensity;\n", args.fOutputColor ); | 64 fsBuilder->codeAppendf("%s = src * intensity;\n", args.fOutputColor ); |
64 } | 65 } |
65 | 66 |
66 void GrGLCircleBlurFragmentProcessor::onSetData(const GrGLProgramDataManager& pd
man, | 67 void GrGLCircleBlurFragmentProcessor::onSetData(const GrGLSLProgramDataManager&
pdman, |
67 const GrProcessor& proc) { | 68 const GrProcessor& proc) { |
68 const GrCircleBlurFragmentProcessor& cbfp = proc.cast<GrCircleBlurFragmentPr
ocessor>(); | 69 const GrCircleBlurFragmentProcessor& cbfp = proc.cast<GrCircleBlurFragmentPr
ocessor>(); |
69 const SkRect& circle = cbfp.circle(); | 70 const SkRect& circle = cbfp.circle(); |
70 | 71 |
71 // The data is formatted as: | 72 // The data is formatted as: |
72 // x,y - the center of the circle | 73 // x,y - the center of the circle |
73 // z - the distance at which the intensity starts falling off (e.g., the
start of the table) | 74 // z - the distance at which the intensity starts falling off (e.g., the
start of the table) |
74 // w - the size of the profile texture | 75 // w - the size of the profile texture |
75 pdman.set4f(fDataUniform, circle.centerX(), circle.centerY(), cbfp.offset(), | 76 pdman.set4f(fDataUniform, circle.centerX(), circle.centerY(), cbfp.offset(), |
76 SkIntToScalar(cbfp.profileSize())); | 77 SkIntToScalar(cbfp.profileSize())); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCircleBlurFragmentProcessor); | 251 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCircleBlurFragmentProcessor); |
251 | 252 |
252 const GrFragmentProcessor* GrCircleBlurFragmentProcessor::TestCreate(GrProcessor
TestData* d) { | 253 const GrFragmentProcessor* GrCircleBlurFragmentProcessor::TestCreate(GrProcessor
TestData* d) { |
253 SkScalar wh = d->fRandom->nextRangeScalar(100.f, 1000.f); | 254 SkScalar wh = d->fRandom->nextRangeScalar(100.f, 1000.f); |
254 SkScalar sigma = d->fRandom->nextRangeF(1.f,10.f); | 255 SkScalar sigma = d->fRandom->nextRangeF(1.f,10.f); |
255 SkRect circle = SkRect::MakeWH(wh, wh); | 256 SkRect circle = SkRect::MakeWH(wh, wh); |
256 return GrCircleBlurFragmentProcessor::Create(d->fContext->textureProvider(),
circle, sigma); | 257 return GrCircleBlurFragmentProcessor::Create(d->fContext->textureProvider(),
circle, sigma); |
257 } | 258 } |
258 | 259 |
259 #endif | 260 #endif |
OLD | NEW |