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 "glsl/GrGLSLFragmentShaderBuilder.h" |
| 18 #include "glsl/GrGLSLProgramBuilder.h" |
18 #include "glsl/GrGLSLProgramDataManager.h" | 19 #include "glsl/GrGLSLProgramDataManager.h" |
19 | 20 |
20 class GrGLCircleBlurFragmentProcessor : public GrGLFragmentProcessor { | 21 class GrGLCircleBlurFragmentProcessor : public GrGLFragmentProcessor { |
21 public: | 22 public: |
22 GrGLCircleBlurFragmentProcessor(const GrProcessor&) {} | 23 GrGLCircleBlurFragmentProcessor(const GrProcessor&) {} |
23 void emitCode(EmitArgs&) override; | 24 void emitCode(EmitArgs&) override; |
24 | 25 |
25 protected: | 26 protected: |
26 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; | 27 void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override
; |
27 | 28 |
28 private: | 29 private: |
29 GrGLSLProgramDataManager::UniformHandle fDataUniform; | 30 GrGLSLProgramDataManager::UniformHandle fDataUniform; |
30 | 31 |
31 typedef GrGLFragmentProcessor INHERITED; | 32 typedef GrGLFragmentProcessor INHERITED; |
32 }; | 33 }; |
33 | 34 |
34 void GrGLCircleBlurFragmentProcessor::emitCode(EmitArgs& args) { | 35 void GrGLCircleBlurFragmentProcessor::emitCode(EmitArgs& args) { |
35 | 36 |
36 const char *dataName; | 37 const char *dataName; |
37 | 38 |
38 // The data is formatted as: | 39 // The data is formatted as: |
39 // x,y - the center of the circle | 40 // x,y - the center of the circle |
40 // 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) |
41 // w - the size of the profile texture | 42 // w - the size of the profile texture |
42 fDataUniform = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visib
ility, | 43 fDataUniform = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Vis
ibility, |
43 kVec4f_GrSLType, | 44 kVec4f_GrSLType, |
44 kDefault_GrSLPrecision, | 45 kDefault_GrSLPrecision, |
45 "data", | 46 "data", |
46 &dataName); | 47 &dataName); |
47 | 48 |
48 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 49 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; |
49 const char *fragmentPos = fsBuilder->fragmentPosition(); | 50 const char *fragmentPos = fsBuilder->fragmentPosition(); |
50 | 51 |
51 if (args.fInputColor) { | 52 if (args.fInputColor) { |
52 fsBuilder->codeAppendf("vec4 src=%s;", args.fInputColor); | 53 fsBuilder->codeAppendf("vec4 src=%s;", args.fInputColor); |
53 } else { | 54 } else { |
54 fsBuilder->codeAppendf("vec4 src=vec4(1);"); | 55 fsBuilder->codeAppendf("vec4 src=vec4(1);"); |
55 } | 56 } |
56 | 57 |
57 fsBuilder->codeAppendf("vec2 vec = %s.xy - %s.xy;", fragmentPos, dataName); | 58 fsBuilder->codeAppendf("vec2 vec = %s.xy - %s.xy;", fragmentPos, dataName); |
58 fsBuilder->codeAppendf("float dist = (length(vec) - %s.z + 0.5) / %s.w;", da
taName, dataName); | 59 fsBuilder->codeAppendf("float dist = (length(vec) - %s.z + 0.5) / %s.w;", da
taName, dataName); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCircleBlurFragmentProcessor); | 252 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrCircleBlurFragmentProcessor); |
252 | 253 |
253 const GrFragmentProcessor* GrCircleBlurFragmentProcessor::TestCreate(GrProcessor
TestData* d) { | 254 const GrFragmentProcessor* GrCircleBlurFragmentProcessor::TestCreate(GrProcessor
TestData* d) { |
254 SkScalar wh = d->fRandom->nextRangeScalar(100.f, 1000.f); | 255 SkScalar wh = d->fRandom->nextRangeScalar(100.f, 1000.f); |
255 SkScalar sigma = d->fRandom->nextRangeF(1.f,10.f); | 256 SkScalar sigma = d->fRandom->nextRangeF(1.f,10.f); |
256 SkRect circle = SkRect::MakeWH(wh, wh); | 257 SkRect circle = SkRect::MakeWH(wh, wh); |
257 return GrCircleBlurFragmentProcessor::Create(d->fContext->textureProvider(),
circle, sigma); | 258 return GrCircleBlurFragmentProcessor::Create(d->fContext->textureProvider(),
circle, sigma); |
258 } | 259 } |
259 | 260 |
260 #endif | 261 #endif |
OLD | NEW |