Chromium Code Reviews| 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; } | |
| 53 float sigma() const { return fSigma; } | |
| 54 float offset() const { return fOffset; } | |
| 55 int profileSize() const { return fBlurProfileAccess.getTexture()->width(); } | |
| 56 | |
| 57 private: | 55 private: |
| 56 /** | |
| 57 * Creates a profile texture for the circle and sigma. The texture will have a height of 1. | |
| 58 * The x texture coord should map from 0 to 1 across the radius range of sol idRadius to | |
| 59 * solidRadius + textureRadius. | |
| 60 */ | |
| 58 GrCircleBlurFragmentProcessor(const SkRect& circle, float sigma, | 61 GrCircleBlurFragmentProcessor(const SkRect& circle, float sigma, |
| 59 float offset, GrTexture* blurProfile); | 62 float solidRadius, float textureRadius, GrText ure* blurProfile); |
| 60 | 63 |
| 61 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; | 64 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 62 | 65 |
| 63 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override; | 66 void onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override; |
| 64 | 67 |
| 65 bool onIsEqual(const GrFragmentProcessor& other) const override { | 68 bool onIsEqual(const GrFragmentProcessor& other) const override { |
| 66 const GrCircleBlurFragmentProcessor& cbfp = other.cast<GrCircleBlurFragm entProcessor>(); | 69 const GrCircleBlurFragmentProcessor& cbfp = other.cast<GrCircleBlurFragm entProcessor>(); |
| 67 // fOffset is computed from the circle width and the sigma | 70 // fOffset is computed from the circle width and the sigma |
| 68 return this->circle() == cbfp.circle() && fSigma == cbfp.fSigma; | 71 return this->fCircle == cbfp.fCircle && fSigma == cbfp.fSigma; |
| 69 } | 72 } |
| 70 | 73 |
| 71 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 74 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
| 72 | 75 |
| 73 static GrTexture* CreateCircleBlurProfileTexture(GrTextureProvider*, | 76 static GrTexture* CreateCircleBlurProfileTexture(GrTextureProvider*, |
| 74 const SkRect& circle, | 77 const SkRect& circle, |
| 75 float sigma, float* offset) ; | 78 float sigma, |
| 79 float* solidRadius, | |
| 80 float* textureRadius); | |
| 81 | |
| 82 class GLSLProcessor; | |
|
jvanverth1
2016/06/14 18:51:15
This forward declaration is little confusing (it l
bsalomon
2016/06/14 19:16:51
Done.
| |
| 76 | 83 |
| 77 SkRect fCircle; | 84 SkRect fCircle; |
| 78 float fSigma; | 85 float fSigma; |
| 79 float fOffset; | 86 float fSolidRadius; |
| 87 float fTextureRadius; | |
| 80 GrTextureAccess fBlurProfileAccess; | 88 GrTextureAccess fBlurProfileAccess; |
| 81 | 89 |
| 82 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 90 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 83 | 91 |
| 84 typedef GrFragmentProcessor INHERITED; | 92 typedef GrFragmentProcessor INHERITED; |
| 85 }; | 93 }; |
| 86 | 94 |
| 87 #endif | 95 #endif |
| 88 #endif | 96 #endif |
| OLD | NEW |