| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 GrConvolutionEffect_DEFINED | 8 #ifndef GrConvolutionEffect_DEFINED |
| 9 #define GrConvolutionEffect_DEFINED | 9 #define GrConvolutionEffect_DEFINED |
| 10 | 10 |
| 11 #include "Gr1DKernelEffect.h" | 11 #include "Gr1DKernelEffect.h" |
| 12 #include "GrInvariantOutput.h" | 12 #include "GrInvariantOutput.h" |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * A convolution effect. The kernel is specified as an array of 2 * half-width | 15 * A convolution effect. The kernel is specified as an array of 2 * half-width |
| 16 * + 1 weights. Each texel is multiplied by it's weight and summed to determine | 16 * + 1 weights. Each texel is multiplied by it's weight and summed to determine |
| 17 * the output color. The output color is modulated by the input color. | 17 * the output color. The output color is modulated by the input color. |
| 18 */ | 18 */ |
| 19 class GrConvolutionEffect : public Gr1DKernelEffect { | 19 class GrConvolutionEffect : public Gr1DKernelEffect { |
| 20 | 20 |
| 21 public: | 21 public: |
| 22 | 22 |
| 23 /// Convolve with an arbitrary user-specified kernel | 23 /// Convolve with an arbitrary user-specified kernel |
| 24 static GrFragmentProcessor* Create(GrTexture* tex, | 24 static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, |
| 25 GrTexture* tex, |
| 25 Direction dir, | 26 Direction dir, |
| 26 int halfWidth, | 27 int halfWidth, |
| 27 const float* kernel, | 28 const float* kernel, |
| 28 bool useBounds, | 29 bool useBounds, |
| 29 float bounds[2]) { | 30 float bounds[2]) { |
| 30 return SkNEW_ARGS(GrConvolutionEffect, (tex, | 31 return SkNEW_ARGS(GrConvolutionEffect, (procDataManager, |
| 32 tex, |
| 31 dir, | 33 dir, |
| 32 halfWidth, | 34 halfWidth, |
| 33 kernel, | 35 kernel, |
| 34 useBounds, | 36 useBounds, |
| 35 bounds)); | 37 bounds)); |
| 36 } | 38 } |
| 37 | 39 |
| 38 /// Convolve with a Gaussian kernel | 40 /// Convolve with a Gaussian kernel |
| 39 static GrFragmentProcessor* CreateGaussian(GrTexture* tex, | 41 static GrFragmentProcessor* CreateGaussian(GrProcessorDataManager* procDataM
anager, |
| 42 GrTexture* tex, |
| 40 Direction dir, | 43 Direction dir, |
| 41 int halfWidth, | 44 int halfWidth, |
| 42 float gaussianSigma, | 45 float gaussianSigma, |
| 43 bool useBounds, | 46 bool useBounds, |
| 44 float bounds[2]) { | 47 float bounds[2]) { |
| 45 return SkNEW_ARGS(GrConvolutionEffect, (tex, | 48 return SkNEW_ARGS(GrConvolutionEffect, (procDataManager, |
| 49 tex, |
| 46 dir, | 50 dir, |
| 47 halfWidth, | 51 halfWidth, |
| 48 gaussianSigma, | 52 gaussianSigma, |
| 49 useBounds, | 53 useBounds, |
| 50 bounds)); | 54 bounds)); |
| 51 } | 55 } |
| 52 | 56 |
| 53 virtual ~GrConvolutionEffect(); | 57 virtual ~GrConvolutionEffect(); |
| 54 | 58 |
| 55 const float* kernel() const { return fKernel; } | 59 const float* kernel() const { return fKernel; } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 74 kMaxKernelWidth = 2 * kMaxKernelRadius + 1, | 78 kMaxKernelWidth = 2 * kMaxKernelRadius + 1, |
| 75 }; | 79 }; |
| 76 | 80 |
| 77 protected: | 81 protected: |
| 78 | 82 |
| 79 float fKernel[kMaxKernelWidth]; | 83 float fKernel[kMaxKernelWidth]; |
| 80 bool fUseBounds; | 84 bool fUseBounds; |
| 81 float fBounds[2]; | 85 float fBounds[2]; |
| 82 | 86 |
| 83 private: | 87 private: |
| 84 GrConvolutionEffect(GrTexture*, Direction, | 88 GrConvolutionEffect(GrProcessorDataManager*, |
| 89 GrTexture*, Direction, |
| 85 int halfWidth, | 90 int halfWidth, |
| 86 const float* kernel, | 91 const float* kernel, |
| 87 bool useBounds, | 92 bool useBounds, |
| 88 float bounds[2]); | 93 float bounds[2]); |
| 89 | 94 |
| 90 /// Convolve with a Gaussian kernel | 95 /// Convolve with a Gaussian kernel |
| 91 GrConvolutionEffect(GrTexture*, Direction, | 96 GrConvolutionEffect(GrProcessorDataManager*, |
| 97 GrTexture*, Direction, |
| 92 int halfWidth, | 98 int halfWidth, |
| 93 float gaussianSigma, | 99 float gaussianSigma, |
| 94 bool useBounds, | 100 bool useBounds, |
| 95 float bounds[2]); | 101 float bounds[2]); |
| 96 | 102 |
| 97 bool onIsEqual(const GrFragmentProcessor&) const override; | 103 bool onIsEqual(const GrFragmentProcessor&) const override; |
| 98 | 104 |
| 99 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 105 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
| 100 // If the texture was opaque we could know that the output color if we k
new the sum of the | 106 // If the texture was opaque we could know that the output color if we k
new the sum of the |
| 101 // kernel values. | 107 // kernel values. |
| 102 inout->mulByUnknownFourComponents(); | 108 inout->mulByUnknownFourComponents(); |
| 103 } | 109 } |
| 104 | 110 |
| 105 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 111 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 106 | 112 |
| 107 typedef Gr1DKernelEffect INHERITED; | 113 typedef Gr1DKernelEffect INHERITED; |
| 108 }; | 114 }; |
| 109 | 115 |
| 110 #endif | 116 #endif |
| OLD | NEW |