| 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 #include "GrConvolutionEffect.h" | 8 #include "GrConvolutionEffect.h" |
| 9 #include "gl/GrGLFragmentProcessor.h" | 9 #include "gl/GrGLFragmentProcessor.h" |
| 10 #include "gl/GrGLTexture.h" | 10 #include "gl/GrGLTexture.h" |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 key <<= 2; | 138 key <<= 2; |
| 139 if (conv.useBounds()) { | 139 if (conv.useBounds()) { |
| 140 key |= 0x2; | 140 key |= 0x2; |
| 141 key |= GrConvolutionEffect::kY_Direction == conv.direction() ? 0x1 : 0x0
; | 141 key |= GrConvolutionEffect::kY_Direction == conv.direction() ? 0x1 : 0x0
; |
| 142 } | 142 } |
| 143 b->add32(key); | 143 b->add32(key); |
| 144 } | 144 } |
| 145 | 145 |
| 146 /////////////////////////////////////////////////////////////////////////////// | 146 /////////////////////////////////////////////////////////////////////////////// |
| 147 | 147 |
| 148 GrConvolutionEffect::GrConvolutionEffect(GrProcessorDataManager* procDataManager
, | 148 GrConvolutionEffect::GrConvolutionEffect(GrTexture* texture, |
| 149 GrTexture* texture, | |
| 150 Direction direction, | 149 Direction direction, |
| 151 int radius, | 150 int radius, |
| 152 const float* kernel, | 151 const float* kernel, |
| 153 bool useBounds, | 152 bool useBounds, |
| 154 float bounds[2]) | 153 float bounds[2]) |
| 155 : INHERITED(procDataManager, texture, direction, radius), fUseBounds(useBoun
ds) { | 154 : INHERITED(texture, direction, radius), fUseBounds(useBounds) { |
| 156 this->initClassID<GrConvolutionEffect>(); | 155 this->initClassID<GrConvolutionEffect>(); |
| 157 SkASSERT(radius <= kMaxKernelRadius); | 156 SkASSERT(radius <= kMaxKernelRadius); |
| 158 SkASSERT(kernel); | 157 SkASSERT(kernel); |
| 159 int width = this->width(); | 158 int width = this->width(); |
| 160 for (int i = 0; i < width; i++) { | 159 for (int i = 0; i < width; i++) { |
| 161 fKernel[i] = kernel[i]; | 160 fKernel[i] = kernel[i]; |
| 162 } | 161 } |
| 163 memcpy(fBounds, bounds, sizeof(fBounds)); | 162 memcpy(fBounds, bounds, sizeof(fBounds)); |
| 164 } | 163 } |
| 165 | 164 |
| 166 GrConvolutionEffect::GrConvolutionEffect(GrProcessorDataManager* procDataManager
, | 165 GrConvolutionEffect::GrConvolutionEffect(GrTexture* texture, |
| 167 GrTexture* texture, | |
| 168 Direction direction, | 166 Direction direction, |
| 169 int radius, | 167 int radius, |
| 170 float gaussianSigma, | 168 float gaussianSigma, |
| 171 bool useBounds, | 169 bool useBounds, |
| 172 float bounds[2]) | 170 float bounds[2]) |
| 173 : INHERITED(procDataManager, texture, direction, radius), fUseBounds(useBoun
ds) { | 171 : INHERITED(texture, direction, radius), fUseBounds(useBounds) { |
| 174 this->initClassID<GrConvolutionEffect>(); | 172 this->initClassID<GrConvolutionEffect>(); |
| 175 SkASSERT(radius <= kMaxKernelRadius); | 173 SkASSERT(radius <= kMaxKernelRadius); |
| 176 int width = this->width(); | 174 int width = this->width(); |
| 177 | 175 |
| 178 float sum = 0.0f; | 176 float sum = 0.0f; |
| 179 float denom = 1.0f / (2.0f * gaussianSigma * gaussianSigma); | 177 float denom = 1.0f / (2.0f * gaussianSigma * gaussianSigma); |
| 180 for (int i = 0; i < width; ++i) { | 178 for (int i = 0; i < width; ++i) { |
| 181 float x = static_cast<float>(i - this->radius()); | 179 float x = static_cast<float>(i - this->radius()); |
| 182 // Note that the constant term (1/(sqrt(2*pi*sigma^2)) of the Gaussian | 180 // Note that the constant term (1/(sqrt(2*pi*sigma^2)) of the Gaussian |
| 183 // is dropped here, since we renormalize the kernel below. | 181 // is dropped here, since we renormalize the kernel below. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 float kernel[kMaxKernelWidth]; | 223 float kernel[kMaxKernelWidth]; |
| 226 for (size_t i = 0; i < SK_ARRAY_COUNT(kernel); ++i) { | 224 for (size_t i = 0; i < SK_ARRAY_COUNT(kernel); ++i) { |
| 227 kernel[i] = d->fRandom->nextSScalar1(); | 225 kernel[i] = d->fRandom->nextSScalar1(); |
| 228 } | 226 } |
| 229 float bounds[2]; | 227 float bounds[2]; |
| 230 for (size_t i = 0; i < SK_ARRAY_COUNT(bounds); ++i) { | 228 for (size_t i = 0; i < SK_ARRAY_COUNT(bounds); ++i) { |
| 231 bounds[i] = d->fRandom->nextF(); | 229 bounds[i] = d->fRandom->nextF(); |
| 232 } | 230 } |
| 233 | 231 |
| 234 bool useBounds = d->fRandom->nextBool(); | 232 bool useBounds = d->fRandom->nextBool(); |
| 235 return GrConvolutionEffect::Create(d->fProcDataManager, | 233 return GrConvolutionEffect::Create(d->fTextures[texIdx], |
| 236 d->fTextures[texIdx], | |
| 237 dir, | 234 dir, |
| 238 radius, | 235 radius, |
| 239 kernel, | 236 kernel, |
| 240 useBounds, | 237 useBounds, |
| 241 bounds); | 238 bounds); |
| 242 } | 239 } |
| OLD | NEW |