| 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" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 *lowOffset = *highOffset = (d - 1) / 2; | 127 *lowOffset = *highOffset = (d - 1) / 2; |
| 128 *kernelSize3 = d; | 128 *kernelSize3 = d; |
| 129 } else { | 129 } else { |
| 130 *highOffset = d / 2; | 130 *highOffset = d / 2; |
| 131 *lowOffset = *highOffset - 1; | 131 *lowOffset = *highOffset - 1; |
| 132 *kernelSize3 = d + 1; | 132 *kernelSize3 = d + 1; |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 bool SkBlurImageFilter::onFilterImage(Proxy* proxy, | 136 bool SkBlurImageFilter::onFilterImage(Proxy* proxy, |
| 137 const SkBitmap& source, const SkMatrix& ct
m, | 137 const SkBitmap& source, const Context& ctx
, |
| 138 SkBitmap* dst, SkIPoint* offset) const { | 138 SkBitmap* dst, SkIPoint* offset) const { |
| 139 SkBitmap src = source; | 139 SkBitmap src = source; |
| 140 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 140 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| 141 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, &srcO
ffset)) { | 141 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcO
ffset)) { |
| 142 return false; | 142 return false; |
| 143 } | 143 } |
| 144 | 144 |
| 145 if (src.colorType() != kPMColor_SkColorType) { | 145 if (src.colorType() != kPMColor_SkColorType) { |
| 146 return false; | 146 return false; |
| 147 } | 147 } |
| 148 | 148 |
| 149 SkAutoLockPixels alp(src); | 149 SkAutoLockPixels alp(src); |
| 150 if (!src.getPixels()) { | 150 if (!src.getPixels()) { |
| 151 return false; | 151 return false; |
| 152 } | 152 } |
| 153 | 153 |
| 154 SkIRect srcBounds, dstBounds; | 154 SkIRect srcBounds, dstBounds; |
| 155 src.getBounds(&srcBounds); | 155 src.getBounds(&srcBounds); |
| 156 srcBounds.offset(srcOffset); | 156 srcBounds.offset(srcOffset); |
| 157 if (!this->applyCropRect(&srcBounds, ctm)) { | 157 if (!this->applyCropRect(&srcBounds, ctx.ctm())) { |
| 158 return false; | 158 return false; |
| 159 } | 159 } |
| 160 | 160 |
| 161 dst->setConfig(src.config(), srcBounds.width(), srcBounds.height()); | 161 dst->setConfig(src.config(), srcBounds.width(), srcBounds.height()); |
| 162 dst->getBounds(&dstBounds); | 162 dst->getBounds(&dstBounds); |
| 163 if (!dst->allocPixels()) { | 163 if (!dst->allocPixels()) { |
| 164 return false; | 164 return false; |
| 165 } | 165 } |
| 166 | 166 |
| 167 SkVector sigma, localSigma = SkVector::Make(fSigma.width(), fSigma.height())
; | 167 SkVector sigma, localSigma = SkVector::Make(fSigma.width(), fSigma.height())
; |
| 168 ctm.mapVectors(&sigma, &localSigma, 1); | 168 ctx.ctm().mapVectors(&sigma, &localSigma, 1); |
| 169 | 169 |
| 170 int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX; | 170 int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX; |
| 171 int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY; | 171 int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY; |
| 172 getBox3Params(sigma.x(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &highOffs
etX); | 172 getBox3Params(sigma.x(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &highOffs
etX); |
| 173 getBox3Params(sigma.y(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &highOffs
etY); | 173 getBox3Params(sigma.y(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &highOffs
etY); |
| 174 | 174 |
| 175 if (kernelSizeX < 0 || kernelSizeY < 0) { | 175 if (kernelSizeX < 0 || kernelSizeY < 0) { |
| 176 return false; | 176 return false; |
| 177 } | 177 } |
| 178 | 178 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 return false; | 243 return false; |
| 244 } | 244 } |
| 245 SkVector sigma, localSigma = SkVector::Make(fSigma.width(), fSigma.height())
; | 245 SkVector sigma, localSigma = SkVector::Make(fSigma.width(), fSigma.height())
; |
| 246 ctm.mapVectors(&sigma, &localSigma, 1); | 246 ctm.mapVectors(&sigma, &localSigma, 1); |
| 247 bounds.outset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))), | 247 bounds.outset(SkScalarCeilToInt(SkScalarMul(sigma.x(), SkIntToScalar(3))), |
| 248 SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar(3)))); | 248 SkScalarCeilToInt(SkScalarMul(sigma.y(), SkIntToScalar(3)))); |
| 249 *dst = bounds; | 249 *dst = bounds; |
| 250 return true; | 250 return true; |
| 251 } | 251 } |
| 252 | 252 |
| 253 bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
SkMatrix& ctm, | 253 bool SkBlurImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const
Context& ctx, |
| 254 SkBitmap* result, SkIPoint* offset) const
{ | 254 SkBitmap* result, SkIPoint* offset) const
{ |
| 255 #if SK_SUPPORT_GPU | 255 #if SK_SUPPORT_GPU |
| 256 SkBitmap input = src; | 256 SkBitmap input = src; |
| 257 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 257 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
| 258 if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctm, &input,
&srcOffset)) { | 258 if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &input,
&srcOffset)) { |
| 259 return false; | 259 return false; |
| 260 } | 260 } |
| 261 GrTexture* source = input.getTexture(); | 261 GrTexture* source = input.getTexture(); |
| 262 SkIRect rect; | 262 SkIRect rect; |
| 263 src.getBounds(&rect); | 263 src.getBounds(&rect); |
| 264 rect.offset(srcOffset); | 264 rect.offset(srcOffset); |
| 265 if (!this->applyCropRect(&rect, ctm)) { | 265 if (!this->applyCropRect(&rect, ctx.ctm())) { |
| 266 return false; | 266 return false; |
| 267 } | 267 } |
| 268 SkVector sigma, localSigma = SkVector::Make(fSigma.width(), fSigma.height())
; | 268 SkVector sigma, localSigma = SkVector::Make(fSigma.width(), fSigma.height())
; |
| 269 ctm.mapVectors(&sigma, &localSigma, 1); | 269 ctx.ctm().mapVectors(&sigma, &localSigma, 1); |
| 270 offset->fX = rect.fLeft; | 270 offset->fX = rect.fLeft; |
| 271 offset->fY = rect.fTop; | 271 offset->fY = rect.fTop; |
| 272 rect.offset(-srcOffset); | 272 rect.offset(-srcOffset); |
| 273 SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(source->getContext(
), | 273 SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(source->getContext(
), |
| 274 source, | 274 source, |
| 275 false, | 275 false, |
| 276 SkRect::Make(rect), | 276 SkRect::Make(rect), |
| 277 true, | 277 true, |
| 278 sigma.x(), | 278 sigma.x(), |
| 279 sigma.y())); | 279 sigma.y())); |
| 280 WrapTexture(tex, rect.width(), rect.height(), result); | 280 WrapTexture(tex, rect.width(), rect.height(), result); |
| 281 return true; | 281 return true; |
| 282 #else | 282 #else |
| 283 SkDEBUGFAIL("Should not call in GPU-less build"); | 283 SkDEBUGFAIL("Should not call in GPU-less build"); |
| 284 return false; | 284 return false; |
| 285 #endif | 285 #endif |
| 286 } | 286 } |
| OLD | NEW |