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 "SkFlattenableBuffers.h" | 11 #include "SkFlattenableBuffers.h" |
12 #include "SkGpuBlurUtils.h" | 12 #include "SkGpuBlurUtils.h" |
| 13 #include "SkBlurImage_opts.h" |
13 #if SK_SUPPORT_GPU | 14 #if SK_SUPPORT_GPU |
14 #include "GrContext.h" | 15 #include "GrContext.h" |
15 #include "SkImageFilterUtils.h" | 16 #include "SkImageFilterUtils.h" |
16 #endif | 17 #endif |
17 | 18 |
18 SkBlurImageFilter::SkBlurImageFilter(SkFlattenableReadBuffer& buffer) | 19 SkBlurImageFilter::SkBlurImageFilter(SkFlattenableReadBuffer& buffer) |
19 : INHERITED(buffer) { | 20 : INHERITED(buffer) { |
20 fSigma.fWidth = buffer.readScalar(); | 21 fSigma.fWidth = buffer.readScalar(); |
21 fSigma.fHeight = buffer.readScalar(); | 22 fSigma.fHeight = buffer.readScalar(); |
22 buffer.validate(SkScalarIsFinite(fSigma.fWidth) && | 23 buffer.validate(SkScalarIsFinite(fSigma.fWidth) && |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 if (srcDirection == kY) { | 119 if (srcDirection == kY) { |
119 SK_PREFETCH(sptr + (rightOffset + 1) * srcStrideX); | 120 SK_PREFETCH(sptr + (rightOffset + 1) * srcStrideX); |
120 } | 121 } |
121 dptr += dstStrideX; | 122 dptr += dstStrideX; |
122 } | 123 } |
123 src += srcStrideY; | 124 src += srcStrideY; |
124 dst += dstStrideY; | 125 dst += dstStrideY; |
125 } | 126 } |
126 } | 127 } |
127 | 128 |
128 static void boxBlurX(const SkPMColor* src, int srcStride, SkPMColor* dst, int ke
rnelSize, | |
129 int leftOffset, int rightOffset, int width, int height) | |
130 { | |
131 boxBlur<kX, kX>(src, srcStride, dst, kernelSize, leftOffset, rightOffset, wi
dth, height); | |
132 } | |
133 | |
134 #ifndef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION | |
135 static void boxBlurXY(const SkPMColor* src, int srcStride, SkPMColor* dst, int k
ernelSize, | |
136 int leftOffset, int rightOffset, int width, int he
ight) | |
137 { | |
138 boxBlur<kX, kY>(src, srcStride, dst, kernelSize, leftOffset, rightOffset, wi
dth, height); | |
139 } | |
140 #endif | |
141 | |
142 static void boxBlurY(const SkPMColor* src, int srcStride, SkPMColor* dst, int ke
rnelSize, | |
143 int topOffset, int bottomOffset, int width, int height) | |
144 { | |
145 boxBlur<kY, kY>(src, srcStride, dst, kernelSize, topOffset, bottomOffset, wi
dth, height); | |
146 } | |
147 | |
148 static void getBox3Params(SkScalar s, int *kernelSize, int* kernelSize3, int *lo
wOffset, | 129 static void getBox3Params(SkScalar s, int *kernelSize, int* kernelSize3, int *lo
wOffset, |
149 int *highOffset) | 130 int *highOffset) |
150 { | 131 { |
151 float pi = SkScalarToFloat(SK_ScalarPI); | 132 float pi = SkScalarToFloat(SK_ScalarPI); |
152 int d = static_cast<int>(floorf(SkScalarToFloat(s) * 3.0f * sqrtf(2.0f * pi)
/ 4.0f + 0.5f)); | 133 int d = static_cast<int>(floorf(SkScalarToFloat(s) * 3.0f * sqrtf(2.0f * pi)
/ 4.0f + 0.5f)); |
153 *kernelSize = d; | 134 *kernelSize = d; |
154 if (d % 2 == 1) { | 135 if (d % 2 == 1) { |
155 *lowOffset = *highOffset = (d - 1) / 2; | 136 *lowOffset = *highOffset = (d - 1) / 2; |
156 *kernelSize3 = d; | 137 *kernelSize3 = d; |
157 } else { | 138 } else { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 temp.setConfig(dst->config(), dst->width(), dst->height()); | 186 temp.setConfig(dst->config(), dst->width(), dst->height()); |
206 if (!temp.allocPixels()) { | 187 if (!temp.allocPixels()) { |
207 return false; | 188 return false; |
208 } | 189 } |
209 | 190 |
210 const SkPMColor* s = src.getAddr32(srcBounds.left(), srcBounds.top()); | 191 const SkPMColor* s = src.getAddr32(srcBounds.left(), srcBounds.top()); |
211 SkPMColor* t = temp.getAddr32(0, 0); | 192 SkPMColor* t = temp.getAddr32(0, 0); |
212 SkPMColor* d = dst->getAddr32(0, 0); | 193 SkPMColor* d = dst->getAddr32(0, 0); |
213 int w = dstBounds.width(), h = dstBounds.height(); | 194 int w = dstBounds.width(), h = dstBounds.height(); |
214 int sw = src.rowBytesAsPixels(); | 195 int sw = src.rowBytesAsPixels(); |
| 196 SkBoxBlurProc boxBlurX, boxBlurY, boxBlurXY; |
| 197 if (!SkBoxBlurGetPlatformProcs(&boxBlurX, &boxBlurY, &boxBlurXY)) { |
| 198 boxBlurX = boxBlur<kX, kX>; |
| 199 boxBlurY = boxBlur<kY, kY>; |
| 200 boxBlurXY = boxBlur<kX, kY>; |
| 201 } |
| 202 |
215 if (kernelSizeX > 0 && kernelSizeY > 0) { | 203 if (kernelSizeX > 0 && kernelSizeY > 0) { |
216 #ifndef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION | 204 #ifndef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION |
217 boxBlurX(s, sw, t, kernelSizeX, lowOffsetX, highOffsetX, w, h); | 205 boxBlurX(s, sw, t, kernelSizeX, lowOffsetX, highOffsetX, w, h); |
218 boxBlurX(t, w, d, kernelSizeX, highOffsetX, lowOffsetX, w, h); | 206 boxBlurX(t, w, d, kernelSizeX, highOffsetX, lowOffsetX, w, h); |
219 boxBlurXY(d, w, t, kernelSizeX3, highOffsetX, highOffsetX, w, h); | 207 boxBlurXY(d, w, t, kernelSizeX3, highOffsetX, highOffsetX, w, h); |
220 boxBlurX(t, h, d, kernelSizeY, lowOffsetY, highOffsetY, h, w); | 208 boxBlurX(t, h, d, kernelSizeY, lowOffsetY, highOffsetY, h, w); |
221 boxBlurX(d, h, t, kernelSizeY, highOffsetY, lowOffsetY, h, w); | 209 boxBlurX(d, h, t, kernelSizeY, highOffsetY, lowOffsetY, h, w); |
222 boxBlurXY(t, h, d, kernelSizeY3, highOffsetY, highOffsetY, h, w); | 210 boxBlurXY(t, h, d, kernelSizeY3, highOffsetY, highOffsetY, h, w); |
223 #else | 211 #else |
224 boxBlurX(s, sw, t, kernelSizeX, lowOffsetX, highOffsetX, w, h); | 212 boxBlurX(s, sw, t, kernelSizeX, lowOffsetX, highOffsetX, w, h); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 fSigma.width(), | 251 fSigma.width(), |
264 fSigma.height())); | 252 fSigma.height())); |
265 offset->fX += rect.fLeft; | 253 offset->fX += rect.fLeft; |
266 offset->fY += rect.fTop; | 254 offset->fY += rect.fTop; |
267 return SkImageFilterUtils::WrapTexture(tex, rect.width(), rect.height(), res
ult); | 255 return SkImageFilterUtils::WrapTexture(tex, rect.width(), rect.height(), res
ult); |
268 #else | 256 #else |
269 SkDEBUGFAIL("Should not call in GPU-less build"); | 257 SkDEBUGFAIL("Should not call in GPU-less build"); |
270 return false; | 258 return false; |
271 #endif | 259 #endif |
272 } | 260 } |
OLD | NEW |