Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2011 The Android Open Source Project | 2 * Copyright 2011 The Android Open Source Project |
| 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 "SkBitmap.h" | 8 #include "SkBitmap.h" |
| 9 #include "SkBlurImageFilter.h" | 9 #include "SkBlurImageFilter.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| 11 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
| 12 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
| 13 #include "SkGpuBlurUtils.h" | 13 #include "SkGpuBlurUtils.h" |
| 14 #include "SkBlurImage_opts.h" | 14 #include "SkBlurImage_opts.h" |
| 15 #if SK_SUPPORT_GPU | 15 #if SK_SUPPORT_GPU |
| 16 #include "GrContext.h" | 16 #include "GrContext.h" |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 // This rather arbitrary-looking value results in a maximum box blur kernel size | 19 // This rather arbitrary-looking value results in a maximum box blur kernel size |
| 20 // of 1000 pixels on the raster path, which matches the WebKit and Firefox | 20 // of 1000 pixels on the raster path, which matches the WebKit and Firefox |
| 21 // implementations. Since the GPU path does not compute a box blur, putting | 21 // implementations. Since the GPU path does not compute a box blur, putting |
| 22 // the limit on sigma ensures consistent behaviour between the GPU and | 22 // the limit on sigma ensures consistent behaviour between the GPU and |
| 23 // raster paths. | 23 // raster paths. |
| 24 #define MAX_SIGMA SkIntToScalar(532) | 24 #define MAX_SIGMA SkIntToScalar(532) |
| 25 | 25 |
| 26 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING | |
| 26 SkBlurImageFilter::SkBlurImageFilter(SkReadBuffer& buffer) | 27 SkBlurImageFilter::SkBlurImageFilter(SkReadBuffer& buffer) |
| 27 : INHERITED(1, buffer) { | 28 : INHERITED(1, buffer) { |
| 28 fSigma.fWidth = buffer.readScalar(); | 29 fSigma.fWidth = buffer.readScalar(); |
| 29 fSigma.fHeight = buffer.readScalar(); | 30 fSigma.fHeight = buffer.readScalar(); |
| 30 buffer.validate(SkScalarIsFinite(fSigma.fWidth) && | 31 buffer.validate(SkScalarIsFinite(fSigma.fWidth) && |
| 31 SkScalarIsFinite(fSigma.fHeight) && | 32 SkScalarIsFinite(fSigma.fHeight) && |
| 32 (fSigma.fWidth >= 0) && | 33 (fSigma.fWidth >= 0) && |
| 33 (fSigma.fHeight >= 0)); | 34 (fSigma.fHeight >= 0)); |
| 34 } | 35 } |
| 35 | 36 |
| 36 SkBlurImageFilter::SkBlurImageFilter(SkScalar sigmaX, | 37 SkBlurImageFilter::SkBlurImageFilter(SkScalar sigmaX, |
| 37 SkScalar sigmaY, | 38 SkScalar sigmaY, |
| 38 SkImageFilter* input, | 39 SkImageFilter* input, |
| 39 const CropRect* cropRect) | 40 const CropRect* cropRect) |
| 40 : INHERITED(1, &input, cropRect), fSigma(SkSize::Make(sigmaX, sigmaY)) { | 41 : INHERITED(1, &input, cropRect), fSigma(SkSize::Make(sigmaX, sigmaY)) { |
| 41 SkASSERT(sigmaX >= 0 && sigmaY >= 0); | 42 SkASSERT(sigmaX >= 0 && sigmaY >= 0); |
| 42 } | 43 } |
| 44 #endif | |
| 45 | |
| 46 SkFlattenable* SkBlurImageFilter::CreateProc(SkReadBuffer& buffer) { | |
| 47 Common common; | |
| 48 if (!common.unflatten(buffer, 1)) { | |
| 49 return NULL; | |
| 50 } | |
| 51 SkScalar sigmaX = buffer.readScalar(); | |
| 52 SkScalar sigmaY = buffer.readScalar(); | |
| 53 return Create(sigmaX, sigmaY, common.inputs()[0], &common.cropRect()); | |
|
Stephen White
2014/07/17 21:29:00
Adding a getInput(index) to Common might make this
reed1
2014/07/18 13:40:30
good idea.
| |
| 54 } | |
| 43 | 55 |
| 44 void SkBlurImageFilter::flatten(SkWriteBuffer& buffer) const { | 56 void SkBlurImageFilter::flatten(SkWriteBuffer& buffer) const { |
| 45 this->INHERITED::flatten(buffer); | 57 this->flattenCommon(buffer); |
| 46 buffer.writeScalar(fSigma.fWidth); | 58 buffer.writeScalar(fSigma.fWidth); |
| 47 buffer.writeScalar(fSigma.fHeight); | 59 buffer.writeScalar(fSigma.fHeight); |
| 48 } | 60 } |
| 49 | 61 |
| 50 enum BlurDirection { | 62 enum BlurDirection { |
| 51 kX, kY | 63 kX, kY |
| 52 }; | 64 }; |
| 53 | 65 |
| 54 /** | 66 /** |
| 55 * | 67 * |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 true, | 294 true, |
| 283 sigma.x(), | 295 sigma.x(), |
| 284 sigma.y())); | 296 sigma.y())); |
| 285 WrapTexture(tex, rect.width(), rect.height(), result); | 297 WrapTexture(tex, rect.width(), rect.height(), result); |
| 286 return true; | 298 return true; |
| 287 #else | 299 #else |
| 288 SkDEBUGFAIL("Should not call in GPU-less build"); | 300 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 289 return false; | 301 return false; |
| 290 #endif | 302 #endif |
| 291 } | 303 } |
| OLD | NEW |