| 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 "SkDevice.h" |
| 11 #include "SkGpuBlurUtils.h" | 12 #include "SkGpuBlurUtils.h" |
| 12 #include "SkOpts.h" | 13 #include "SkOpts.h" |
| 13 #include "SkReadBuffer.h" | 14 #include "SkReadBuffer.h" |
| 14 #include "SkWriteBuffer.h" | 15 #include "SkWriteBuffer.h" |
| 15 #if SK_SUPPORT_GPU | 16 #if SK_SUPPORT_GPU |
| 16 #include "GrContext.h" | 17 #include "GrContext.h" |
| 17 #endif | 18 #endif |
| 18 | 19 |
| 19 // This rather arbitrary-looking value results in a maximum box blur kernel size | 20 // 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 | 21 // of 1000 pixels on the raster path, which matches the WebKit and Firefox |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 SkIRect srcBounds, dstBounds; | 84 SkIRect srcBounds, dstBounds; |
| 84 if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &srcBounds, &src)) { | 85 if (!this->applyCropRect(ctx, proxy, src, &srcOffset, &srcBounds, &src)) { |
| 85 return false; | 86 return false; |
| 86 } | 87 } |
| 87 | 88 |
| 88 SkAutoLockPixels alp(src); | 89 SkAutoLockPixels alp(src); |
| 89 if (!src.getPixels()) { | 90 if (!src.getPixels()) { |
| 90 return false; | 91 return false; |
| 91 } | 92 } |
| 92 | 93 |
| 93 if (!dst->tryAllocPixels(src.info().makeWH(srcBounds.width(), srcBounds.heig
ht()))) { | 94 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(srcBounds.width(), src
Bounds.height())); |
| 95 if (!device) { |
| 94 return false; | 96 return false; |
| 95 } | 97 } |
| 98 *dst = device->accessBitmap(false); |
| 99 SkAutoLockPixels alp_dst(*dst); |
| 96 dst->getBounds(&dstBounds); | 100 dst->getBounds(&dstBounds); |
| 97 | 101 |
| 98 SkVector sigma = mapSigma(fSigma, ctx.ctm()); | 102 SkVector sigma = mapSigma(fSigma, ctx.ctm()); |
| 99 | 103 |
| 100 int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX; | 104 int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX; |
| 101 int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY; | 105 int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY; |
| 102 getBox3Params(sigma.x(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &highOffs
etX); | 106 getBox3Params(sigma.x(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &highOffs
etX); |
| 103 getBox3Params(sigma.y(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &highOffs
etY); | 107 getBox3Params(sigma.y(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &highOffs
etY); |
| 104 | 108 |
| 105 if (kernelSizeX < 0 || kernelSizeY < 0) { | 109 if (kernelSizeX < 0 || kernelSizeY < 0) { |
| 106 return false; | 110 return false; |
| 107 } | 111 } |
| 108 | 112 |
| 109 if (kernelSizeX == 0 && kernelSizeY == 0) { | 113 if (kernelSizeX == 0 && kernelSizeY == 0) { |
| 110 src.copyTo(dst, dst->colorType()); | 114 src.copyTo(dst, dst->colorType()); |
| 111 offset->fX = srcBounds.fLeft; | 115 offset->fX = srcBounds.fLeft; |
| 112 offset->fY = srcBounds.fTop; | 116 offset->fY = srcBounds.fTop; |
| 113 return true; | 117 return true; |
| 114 } | 118 } |
| 115 | 119 |
| 116 SkBitmap temp; | 120 SkAutoTUnref<SkBaseDevice> tempDevice(proxy->createDevice(dst->width(), dst-
>height())); |
| 117 if (!temp.tryAllocPixels(dst->info())) { | 121 if (!tempDevice) { |
| 118 return false; | 122 return false; |
| 119 } | 123 } |
| 124 SkBitmap temp = tempDevice->accessBitmap(false); |
| 125 SkAutoLockPixels alpTemp(temp); |
| 120 | 126 |
| 121 offset->fX = srcBounds.fLeft; | 127 offset->fX = srcBounds.fLeft; |
| 122 offset->fY = srcBounds.fTop; | 128 offset->fY = srcBounds.fTop; |
| 123 srcBounds.offset(-srcOffset); | 129 srcBounds.offset(-srcOffset); |
| 124 const SkPMColor* s = src.getAddr32(srcBounds.left(), srcBounds.top()); | 130 const SkPMColor* s = src.getAddr32(srcBounds.left(), srcBounds.top()); |
| 125 SkPMColor* t = temp.getAddr32(0, 0); | 131 SkPMColor* t = temp.getAddr32(0, 0); |
| 126 SkPMColor* d = dst->getAddr32(0, 0); | 132 SkPMColor* d = dst->getAddr32(0, 0); |
| 127 int w = dstBounds.width(), h = dstBounds.height(); | 133 int w = dstBounds.width(), h = dstBounds.height(); |
| 128 int sw = src.rowBytesAsPixels(); | 134 int sw = src.rowBytesAsPixels(); |
| 129 | 135 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 str->appendf("SkBlurImageFilter: ("); | 235 str->appendf("SkBlurImageFilter: ("); |
| 230 str->appendf("sigma: (%f, %f) input (", fSigma.fWidth, fSigma.fHeight); | 236 str->appendf("sigma: (%f, %f) input (", fSigma.fWidth, fSigma.fHeight); |
| 231 | 237 |
| 232 if (this->getInput(0)) { | 238 if (this->getInput(0)) { |
| 233 this->getInput(0)->toString(str); | 239 this->getInput(0)->toString(str); |
| 234 } | 240 } |
| 235 | 241 |
| 236 str->append("))"); | 242 str->append("))"); |
| 237 } | 243 } |
| 238 #endif | 244 #endif |
| OLD | NEW |