OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * 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 |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrCircleBlurFragmentProcessor_DEFINED | 8 #ifndef GrCircleBlurFragmentProcessor_DEFINED |
9 #define GrCircleBlurFragmentProcessor_DEFINED | 9 #define GrCircleBlurFragmentProcessor_DEFINED |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 // This FP handles the special case of a blurred circle. It uses a 1D | 21 // This FP handles the special case of a blurred circle. It uses a 1D |
22 // profile that is just rotated about the origin of the circle. | 22 // profile that is just rotated about the origin of the circle. |
23 class GrCircleBlurFragmentProcessor : public GrFragmentProcessor { | 23 class GrCircleBlurFragmentProcessor : public GrFragmentProcessor { |
24 public: | 24 public: |
25 ~GrCircleBlurFragmentProcessor() override {}; | 25 ~GrCircleBlurFragmentProcessor() override {}; |
26 | 26 |
27 const char* name() const override { return "CircleBlur"; } | 27 const char* name() const override { return "CircleBlur"; } |
28 | 28 |
29 SkString dumpInfo() const override { | 29 SkString dumpInfo() const override { |
30 SkString str; | 30 SkString str; |
31 str.appendf("Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f], Sigma %.2f, Offs
et: %.2f", | 31 str.appendf("Rect [L: %.2f, T: %.2f, R: %.2f, B: %.2f], Sigma %.2f, soli
dR: %.2f, " |
| 32 "textureR: %.2f", |
32 fCircle.fLeft, fCircle.fTop, fCircle.fRight, fCircle.fBottom
, | 33 fCircle.fLeft, fCircle.fTop, fCircle.fRight, fCircle.fBottom
, |
33 fSigma, fOffset); | 34 fSigma, fSolidRadius, fTextureRadius); |
34 return str; | 35 return str; |
35 } | 36 } |
36 | 37 |
37 static sk_sp<GrFragmentProcessor> Make(GrTextureProvider*textureProvider, | 38 static sk_sp<GrFragmentProcessor> Make(GrTextureProvider*textureProvider, |
38 const SkRect& circle, float sigma) { | 39 const SkRect& circle, float sigma) { |
39 float offset; | 40 float solidRadius; |
| 41 float textureRadius; |
40 | 42 |
41 SkAutoTUnref<GrTexture> blurProfile(CreateCircleBlurProfileTexture(textu
reProvider, | 43 SkAutoTUnref<GrTexture> profile(CreateCircleBlurProfileTexture(texturePr
ovider, |
42 circl
e, | 44 circle, |
43 sigma
, | 45 sigma, |
44 &offs
et)); | 46 &solidRad
ius, |
45 if (!blurProfile) { | 47 &textureR
adius)); |
| 48 if (!profile) { |
46 return nullptr; | 49 return nullptr; |
47 } | 50 } |
48 return sk_sp<GrFragmentProcessor>( | 51 return sk_sp<GrFragmentProcessor>( |
49 new GrCircleBlurFragmentProcessor(circle, sigma, offset, blurProfile
)); | 52 new GrCircleBlurFragmentProcessor(circle, sigma, solidRadius, textur
eRadius, profile)); |
50 } | 53 } |
51 | 54 |
52 const SkRect& circle() const { return fCircle; } | 55 private: |
53 float sigma() const { return fSigma; } | 56 // This nested GLSL processor implementation is defined in the cpp file. |
54 float offset() const { return fOffset; } | 57 class GLSLProcessor; |
55 int profileSize() const { return fBlurProfileAccess.getTexture()->width(); } | |
56 | 58 |
57 private: | 59 /** |
| 60 * Creates a profile texture for the circle and sigma. The texture will have
a height of 1. |
| 61 * The x texture coord should map from 0 to 1 across the radius range of sol
idRadius to |
| 62 * solidRadius + textureRadius. |
| 63 */ |
58 GrCircleBlurFragmentProcessor(const SkRect& circle, float sigma, | 64 GrCircleBlurFragmentProcessor(const SkRect& circle, float sigma, |
59 float offset, GrTexture* blurProfile); | 65 float solidRadius, float textureRadius, GrText
ure* blurProfile); |
60 | 66 |
61 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; | 67 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
62 | 68 |
63 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b)
const override; | 69 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b)
const override; |
64 | 70 |
65 bool onIsEqual(const GrFragmentProcessor& other) const override { | 71 bool onIsEqual(const GrFragmentProcessor& other) const override { |
66 const GrCircleBlurFragmentProcessor& cbfp = other.cast<GrCircleBlurFragm
entProcessor>(); | 72 const GrCircleBlurFragmentProcessor& cbfp = other.cast<GrCircleBlurFragm
entProcessor>(); |
67 // fOffset is computed from the circle width and the sigma | 73 // fOffset is computed from the circle width and the sigma |
68 return this->circle() == cbfp.circle() && fSigma == cbfp.fSigma; | 74 return this->fCircle == cbfp.fCircle && fSigma == cbfp.fSigma; |
69 } | 75 } |
70 | 76 |
71 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 77 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
72 | 78 |
73 static GrTexture* CreateCircleBlurProfileTexture(GrTextureProvider*, | 79 static GrTexture* CreateCircleBlurProfileTexture(GrTextureProvider*, |
74 const SkRect& circle, | 80 const SkRect& circle, |
75 float sigma, float* offset)
; | 81 float sigma, |
| 82 float* solidRadius, |
| 83 float* textureRadius); |
76 | 84 |
77 SkRect fCircle; | 85 SkRect fCircle; |
78 float fSigma; | 86 float fSigma; |
79 float fOffset; | 87 float fSolidRadius; |
| 88 float fTextureRadius; |
80 GrTextureAccess fBlurProfileAccess; | 89 GrTextureAccess fBlurProfileAccess; |
81 | 90 |
82 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 91 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
83 | 92 |
84 typedef GrFragmentProcessor INHERITED; | 93 typedef GrFragmentProcessor INHERITED; |
85 }; | 94 }; |
86 | 95 |
87 #endif | 96 #endif |
88 #endif | 97 #endif |
OLD | NEW |