| 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 "SkBlurImageFilter.h" | 8 #include "SkBlurImageFilter.h" |
| 9 | 9 |
| 10 #include "SkAutoPixmapStorage.h" | 10 #include "SkAutoPixmapStorage.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 if (d % 2 == 1) { | 63 if (d % 2 == 1) { |
| 64 *lowOffset = *highOffset = (d - 1) / 2; | 64 *lowOffset = *highOffset = (d - 1) / 2; |
| 65 *kernelSize3 = d; | 65 *kernelSize3 = d; |
| 66 } else { | 66 } else { |
| 67 *highOffset = d / 2; | 67 *highOffset = d / 2; |
| 68 *lowOffset = *highOffset - 1; | 68 *lowOffset = *highOffset - 1; |
| 69 *kernelSize3 = d + 1; | 69 *kernelSize3 = d + 1; |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 SkSpecialImage* SkBlurImageFilter::onFilterImage(SkSpecialImage* source, const C
ontext& ctx, | 73 sk_sp<SkSpecialImage> SkBlurImageFilter::onFilterImage(SkSpecialImage* source, |
| 74 SkIPoint* offset) const { | 74 const Context& ctx, |
| 75 SkIPoint* offset) const { |
| 75 SkIPoint inputOffset = SkIPoint::Make(0, 0); | 76 SkIPoint inputOffset = SkIPoint::Make(0, 0); |
| 76 | 77 |
| 77 SkAutoTUnref<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputO
ffset)); | 78 sk_sp<SkSpecialImage> input(this->filterInput(0, source, ctx, &inputOffset))
; |
| 78 if (!input) { | 79 if (!input) { |
| 79 return nullptr; | 80 return nullptr; |
| 80 } | 81 } |
| 81 | 82 |
| 82 SkIRect inputBounds = SkIRect::MakeXYWH(inputOffset.fX, inputOffset.fY, | 83 SkIRect inputBounds = SkIRect::MakeXYWH(inputOffset.fX, inputOffset.fY, |
| 83 input->width(), input->height()); | 84 input->width(), input->height()); |
| 84 | 85 |
| 85 SkIRect dstBounds; | 86 SkIRect dstBounds; |
| 86 if (!this->applyCropRect(this->mapContext(ctx), inputBounds, &dstBounds)) { | 87 if (!this->applyCropRect(this->mapContext(ctx), inputBounds, &dstBounds)) { |
| 87 return nullptr; | 88 return nullptr; |
| 88 } | 89 } |
| 89 if (!inputBounds.intersect(dstBounds)) { | 90 if (!inputBounds.intersect(dstBounds)) { |
| 90 return nullptr; | 91 return nullptr; |
| 91 } | 92 } |
| 92 | 93 |
| 93 const SkVector sigma = map_sigma(fSigma, ctx.ctm()); | 94 const SkVector sigma = map_sigma(fSigma, ctx.ctm()); |
| 94 | 95 |
| 95 #if SK_SUPPORT_GPU | 96 #if SK_SUPPORT_GPU |
| 96 if (input->peekTexture()) { | 97 if (input->peekTexture()) { |
| 97 if (0 == sigma.x() && 0 == sigma.y()) { | 98 if (0 == sigma.x() && 0 == sigma.y()) { |
| 98 offset->fX = inputBounds.x(); | 99 offset->fX = inputBounds.x(); |
| 99 offset->fY = inputBounds.y(); | 100 offset->fY = inputBounds.y(); |
| 100 return input->makeSubset(inputBounds.makeOffset(-inputOffset.x(), | 101 return input->makeSubset(inputBounds.makeOffset(-inputOffset.x(), |
| 101 -inputOffset.y())).r
elease(); | 102 -inputOffset.y())); |
| 102 } | 103 } |
| 103 | 104 |
| 104 GrTexture* inputTexture = input->peekTexture(); | 105 GrTexture* inputTexture = input->peekTexture(); |
| 105 | 106 |
| 106 offset->fX = dstBounds.fLeft; | 107 offset->fX = dstBounds.fLeft; |
| 107 offset->fY = dstBounds.fTop; | 108 offset->fY = dstBounds.fTop; |
| 108 inputBounds.offset(-inputOffset); | 109 inputBounds.offset(-inputOffset); |
| 109 dstBounds.offset(-inputOffset); | 110 dstBounds.offset(-inputOffset); |
| 110 SkRect inputBoundsF(SkRect::Make(inputBounds)); | 111 SkRect inputBoundsF(SkRect::Make(inputBounds)); |
| 111 SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(inputTexture->g
etContext(), | 112 SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(inputTexture->g
etContext(), |
| 112 inputTexture, | 113 inputTexture, |
| 113 false, | 114 false, |
| 114 SkRect::Make(ds
tBounds), | 115 SkRect::Make(ds
tBounds), |
| 115 &inputBoundsF, | 116 &inputBoundsF, |
| 116 sigma.x(), | 117 sigma.x(), |
| 117 sigma.y())); | 118 sigma.y())); |
| 118 if (!tex) { | 119 if (!tex) { |
| 119 return nullptr; | 120 return nullptr; |
| 120 } | 121 } |
| 121 | 122 |
| 122 return SkSpecialImage::MakeFromGpu(source->internal_getProxy(), | 123 return SkSpecialImage::MakeFromGpu(source->internal_getProxy(), |
| 123 SkIRect::MakeWH(dstBounds.width(), ds
tBounds.height()), | 124 SkIRect::MakeWH(dstBounds.width(), ds
tBounds.height()), |
| 124 kNeedNewImageUniqueID_SpecialImage, | 125 kNeedNewImageUniqueID_SpecialImage, |
| 125 tex).release(); | 126 tex); |
| 126 } | 127 } |
| 127 #endif | 128 #endif |
| 128 | 129 |
| 129 int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX; | 130 int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX; |
| 130 int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY; | 131 int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY; |
| 131 get_box3_params(sigma.x(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &highOf
fsetX); | 132 get_box3_params(sigma.x(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &highOf
fsetX); |
| 132 get_box3_params(sigma.y(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &highOf
fsetY); | 133 get_box3_params(sigma.y(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &highOf
fsetY); |
| 133 | 134 |
| 134 if (kernelSizeX < 0 || kernelSizeY < 0) { | 135 if (kernelSizeX < 0 || kernelSizeY < 0) { |
| 135 return nullptr; | 136 return nullptr; |
| 136 } | 137 } |
| 137 | 138 |
| 138 if (kernelSizeX == 0 && kernelSizeY == 0) { | 139 if (kernelSizeX == 0 && kernelSizeY == 0) { |
| 139 offset->fX = inputBounds.x(); | 140 offset->fX = inputBounds.x(); |
| 140 offset->fY = inputBounds.y(); | 141 offset->fY = inputBounds.y(); |
| 141 return input->makeSubset(inputBounds.makeOffset(-inputOffset.x(), | 142 return input->makeSubset(inputBounds.makeOffset(-inputOffset.x(), |
| 142 -inputOffset.y())).relea
se(); | 143 -inputOffset.y())); |
| 143 } | 144 } |
| 144 | 145 |
| 145 SkPixmap inputPixmap; | 146 SkPixmap inputPixmap; |
| 146 | 147 |
| 147 if (!input->peekPixels(&inputPixmap)) { | 148 if (!input->peekPixels(&inputPixmap)) { |
| 148 return nullptr; | 149 return nullptr; |
| 149 } | 150 } |
| 150 | 151 |
| 151 if (inputPixmap.colorType() != kN32_SkColorType) { | 152 if (inputPixmap.colorType() != kN32_SkColorType) { |
| 152 return nullptr; | 153 return nullptr; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 SkOpts::box_blur_xx(t, w, dstBounds, d, kernelSizeX3, highOffsetX,
highOffsetX, w, h); | 208 SkOpts::box_blur_xx(t, w, dstBounds, d, kernelSizeX3, highOffsetX,
highOffsetX, w, h); |
| 208 } else if (kernelSizeY > 0) { | 209 } else if (kernelSizeY > 0) { |
| 209 SkOpts::box_blur_yx(s, sw, inputBoundsT, d, kernelSizeY, lowOffsetY,
highOffsetY, h, w); | 210 SkOpts::box_blur_yx(s, sw, inputBoundsT, d, kernelSizeY, lowOffsetY,
highOffsetY, h, w); |
| 210 SkOpts::box_blur_xx(d, h, dstBoundsT, t, kernelSizeY, highOffsetY,
lowOffsetY, h, w); | 211 SkOpts::box_blur_xx(d, h, dstBoundsT, t, kernelSizeY, highOffsetY,
lowOffsetY, h, w); |
| 211 SkOpts::box_blur_xy(t, h, dstBoundsT, d, kernelSizeY3, highOffsetY,
highOffsetY, h, w); | 212 SkOpts::box_blur_xy(t, h, dstBoundsT, d, kernelSizeY3, highOffsetY,
highOffsetY, h, w); |
| 212 } | 213 } |
| 213 | 214 |
| 214 return SkSpecialImage::MakeFromRaster(source->internal_getProxy(), | 215 return SkSpecialImage::MakeFromRaster(source->internal_getProxy(), |
| 215 SkIRect::MakeWH(dstBounds.width(), | 216 SkIRect::MakeWH(dstBounds.width(), |
| 216 dstBounds.height()), | 217 dstBounds.height()), |
| 217 dst).release(); | 218 dst); |
| 218 } | 219 } |
| 219 | 220 |
| 220 | 221 |
| 221 SkRect SkBlurImageFilter::computeFastBounds(const SkRect& src) const { | 222 SkRect SkBlurImageFilter::computeFastBounds(const SkRect& src) const { |
| 222 SkRect bounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src
) : src; | 223 SkRect bounds = this->getInput(0) ? this->getInput(0)->computeFastBounds(src
) : src; |
| 223 bounds.outset(SkScalarMul(fSigma.width(), SkIntToScalar(3)), | 224 bounds.outset(SkScalarMul(fSigma.width(), SkIntToScalar(3)), |
| 224 SkScalarMul(fSigma.height(), SkIntToScalar(3))); | 225 SkScalarMul(fSigma.height(), SkIntToScalar(3))); |
| 225 return bounds; | 226 return bounds; |
| 226 } | 227 } |
| 227 | 228 |
| 228 SkIRect SkBlurImageFilter::onFilterNodeBounds(const SkIRect& src, const SkMatrix
& ctm, | 229 SkIRect SkBlurImageFilter::onFilterNodeBounds(const SkIRect& src, const SkMatrix
& ctm, |
| 229 MapDirection) const { | 230 MapDirection) const { |
| 230 SkVector sigma = map_sigma(fSigma, ctm); | 231 SkVector sigma = map_sigma(fSigma, ctm); |
| 231 return src.makeOutset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar
(3))), | 232 return src.makeOutset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar
(3))), |
| 232 SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar
(3)))); | 233 SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar
(3)))); |
| 233 } | 234 } |
| 234 | 235 |
| 235 #ifndef SK_IGNORE_TO_STRING | 236 #ifndef SK_IGNORE_TO_STRING |
| 236 void SkBlurImageFilter::toString(SkString* str) const { | 237 void SkBlurImageFilter::toString(SkString* str) const { |
| 237 str->appendf("SkBlurImageFilter: ("); | 238 str->appendf("SkBlurImageFilter: ("); |
| 238 str->appendf("sigma: (%f, %f) input (", fSigma.fWidth, fSigma.fHeight); | 239 str->appendf("sigma: (%f, %f) input (", fSigma.fWidth, fSigma.fHeight); |
| 239 | 240 |
| 240 if (this->getInput(0)) { | 241 if (this->getInput(0)) { |
| 241 this->getInput(0)->toString(str); | 242 this->getInput(0)->toString(str); |
| 242 } | 243 } |
| 243 | 244 |
| 244 str->append("))"); | 245 str->append("))"); |
| 245 } | 246 } |
| 246 #endif | 247 #endif |
| OLD | NEW |