| 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 |
| 11 #include "SkTypes.h" | 11 #include "SkTypes.h" |
| 12 | 12 |
| 13 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
| 14 | 14 |
| 15 #include "GrFragmentProcessor.h" | 15 #include "GrFragmentProcessor.h" |
| 16 #include "GrProcessorUnitTest.h" | 16 #include "GrProcessorUnitTest.h" |
| 17 | 17 |
| 18 class GrTextureProvider; | 18 class GrTextureProvider; |
| 19 | 19 |
| 20 // This FP handles the special case of a blurred circle. It uses a 1D | 20 // This FP handles the special case of a blurred circle. It uses a 1D |
| 21 // profile that is just rotated about the origin of the circle. | 21 // profile that is just rotated about the origin of the circle. |
| 22 class GrCircleBlurFragmentProcessor : public GrFragmentProcessor { | 22 class GrCircleBlurFragmentProcessor : public GrFragmentProcessor { |
| 23 public: | 23 public: |
| 24 ~GrCircleBlurFragmentProcessor() override {}; | 24 ~GrCircleBlurFragmentProcessor() override {}; |
| 25 | 25 |
| 26 const char* name() const override { return "CircleBlur"; } | 26 const char* name() const override { return "CircleBlur"; } |
| 27 | 27 |
| 28 static const GrFragmentProcessor* Create(GrTextureProvider*textureProvider, | 28 static const GrFragmentProcessor* Create(GrTextureProvider*textureProvider, |
| 29 const SkRect& circle, float sigma)
{ | 29 const SkRect& circle, float sigma,
GrRenderTarget* dstRT) { |
| 30 float offset; | 30 float offset; |
| 31 | 31 |
| 32 SkAutoTUnref<GrTexture> blurProfile(CreateCircleBlurProfileTexture(textu
reProvider, | 32 SkAutoTUnref<GrTexture> blurProfile(CreateCircleBlurProfileTexture(textu
reProvider, |
| 33 circl
e, | 33 circl
e, |
| 34 sigma
, | 34 sigma
, |
| 35 &offs
et)); | 35 &offs
et, dstRT)); |
| 36 if (!blurProfile) { | 36 if (!blurProfile) { |
| 37 return nullptr; | 37 return nullptr; |
| 38 } | 38 } |
| 39 return new GrCircleBlurFragmentProcessor(circle, sigma, offset, blurProf
ile); | 39 return new GrCircleBlurFragmentProcessor(circle, sigma, offset, blurProf
ile, dstRT); |
| 40 } | 40 } |
| 41 | 41 |
| 42 const SkRect& circle() const { return fCircle; } | 42 const SkRect& circle() const { return fCircle; } |
| 43 float sigma() const { return fSigma; } | 43 float sigma() const { return fSigma; } |
| 44 float offset() const { return fOffset; } | 44 float offset() const { return fOffset; } |
| 45 int profileSize() const { return fBlurProfileAccess.getTexture()->width(); } | 45 int profileSize() const { return fBlurProfileAccess.getTexture()->width(); } |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 GrCircleBlurFragmentProcessor(const SkRect& circle, float sigma, | 48 GrCircleBlurFragmentProcessor(const SkRect& circle, float sigma, |
| 49 float offset, GrTexture* blurProfile); | 49 float offset, GrTexture* blurProfile, GrRender
Target* dstRT); |
| 50 | 50 |
| 51 GrGLFragmentProcessor* onCreateGLInstance() const override; | 51 GrGLFragmentProcessor* onCreateGLInstance() const override; |
| 52 | 52 |
| 53 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; | 53 void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) c
onst override; |
| 54 | 54 |
| 55 bool onIsEqual(const GrFragmentProcessor& other) const override { | 55 bool onIsEqual(const GrFragmentProcessor& other) const override { |
| 56 const GrCircleBlurFragmentProcessor& cbfp = other.cast<GrCircleBlurFragm
entProcessor>(); | 56 const GrCircleBlurFragmentProcessor& cbfp = other.cast<GrCircleBlurFragm
entProcessor>(); |
| 57 // fOffset is computed from the circle width and the sigma | 57 // fOffset is computed from the circle width and the sigma |
| 58 return this->circle().width() == cbfp.circle().width() && fSigma == cbfp
.fSigma; | 58 return this->circle().width() == cbfp.circle().width() && fSigma == cbfp
.fSigma; |
| 59 } | 59 } |
| 60 | 60 |
| 61 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 61 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
| 62 | 62 |
| 63 static GrTexture* CreateCircleBlurProfileTexture(GrTextureProvider*, | 63 static GrTexture* CreateCircleBlurProfileTexture(GrTextureProvider*, |
| 64 const SkRect& circle, | 64 const SkRect& circle, |
| 65 float sigma, float* offset)
; | 65 float sigma, float* offset, |
| 66 GrRenderTarget* dstRT); |
| 66 | 67 |
| 67 SkRect fCircle; | 68 SkRect fCircle; |
| 68 float fSigma; | 69 float fSigma; |
| 69 float fOffset; | 70 float fOffset; |
| 70 GrTextureAccess fBlurProfileAccess; | 71 GrTextureAccess fBlurProfileAccess; |
| 71 | 72 |
| 72 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 73 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 73 | 74 |
| 74 typedef GrFragmentProcessor INHERITED; | 75 typedef GrFragmentProcessor INHERITED; |
| 75 }; | 76 }; |
| 76 | 77 |
| 77 #endif | 78 #endif |
| 78 #endif | 79 #endif |
| OLD | NEW |