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 "SkBlurImageFilter.h" | 8 #include "SkBlurImageFilter.h" |
| 9 | 9 |
| 10 #include "SkAutoPixmapStorage.h" | 10 #include "SkAutoPixmapStorage.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 if (!this->applyCropRect(this->mapContext(ctx), inputBounds, &dstBounds)) { | 88 if (!this->applyCropRect(this->mapContext(ctx), inputBounds, &dstBounds)) { |
| 89 return nullptr; | 89 return nullptr; |
| 90 } | 90 } |
| 91 if (!inputBounds.intersect(dstBounds)) { | 91 if (!inputBounds.intersect(dstBounds)) { |
| 92 return nullptr; | 92 return nullptr; |
| 93 } | 93 } |
| 94 | 94 |
| 95 const SkVector sigma = map_sigma(fSigma, ctx.ctm()); | 95 const SkVector sigma = map_sigma(fSigma, ctx.ctm()); |
| 96 | 96 |
| 97 #if SK_SUPPORT_GPU | 97 #if SK_SUPPORT_GPU |
| 98 if (input->peekTexture() && input->peekTexture()->getContext()) { | 98 if (source->isTextureBacked()) { |
| 99 GrContext* context = source->getContext(); | |
| 100 GrTexture* inputTexture = input->asTextureRef(context); | |
| 101 if (!inputTexture) { | |
|
Stephen White
2016/04/08 15:14:19
Could you change this to an assert? It should be h
robertphillips
2016/04/08 18:07:50
Done.
robertphillips
2016/04/08 18:07:50
Done.
| |
| 102 return nullptr; | |
| 103 } | |
| 104 | |
| 99 if (0 == sigma.x() && 0 == sigma.y()) { | 105 if (0 == sigma.x() && 0 == sigma.y()) { |
| 100 offset->fX = inputBounds.x(); | 106 offset->fX = inputBounds.x(); |
| 101 offset->fY = inputBounds.y(); | 107 offset->fY = inputBounds.y(); |
| 102 return input->makeSubset(inputBounds.makeOffset(-inputOffset.x(), | 108 return input->makeSubset(inputBounds.makeOffset(-inputOffset.x(), |
| 103 -inputOffset.y())); | 109 -inputOffset.y())); |
| 104 } | 110 } |
| 105 | 111 |
| 106 GrTexture* inputTexture = input->peekTexture(); | |
| 107 | |
| 108 offset->fX = dstBounds.fLeft; | 112 offset->fX = dstBounds.fLeft; |
| 109 offset->fY = dstBounds.fTop; | 113 offset->fY = dstBounds.fTop; |
| 110 inputBounds.offset(-inputOffset); | 114 inputBounds.offset(-inputOffset); |
| 111 dstBounds.offset(-inputOffset); | 115 dstBounds.offset(-inputOffset); |
| 112 SkRect inputBoundsF(SkRect::Make(inputBounds)); | 116 SkRect inputBoundsF(SkRect::Make(inputBounds)); |
| 113 SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(inputTexture->g etContext(), | 117 SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(context, |
| 114 inputTexture, | 118 inputTexture, |
| 115 false, | 119 false, |
| 116 source->props() .allowSRGBInputs(), | 120 source->props() .allowSRGBInputs(), |
| 117 SkRect::Make(ds tBounds), | 121 SkRect::Make(ds tBounds), |
| 118 &inputBoundsF, | 122 &inputBoundsF, |
| 119 sigma.x(), | 123 sigma.x(), |
| 120 sigma.y())); | 124 sigma.y())); |
| 121 if (!tex) { | 125 if (!tex) { |
| 122 return nullptr; | 126 return nullptr; |
| 123 } | 127 } |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 138 return nullptr; | 142 return nullptr; |
| 139 } | 143 } |
| 140 | 144 |
| 141 if (kernelSizeX == 0 && kernelSizeY == 0) { | 145 if (kernelSizeX == 0 && kernelSizeY == 0) { |
| 142 offset->fX = inputBounds.x(); | 146 offset->fX = inputBounds.x(); |
| 143 offset->fY = inputBounds.y(); | 147 offset->fY = inputBounds.y(); |
| 144 return input->makeSubset(inputBounds.makeOffset(-inputOffset.x(), | 148 return input->makeSubset(inputBounds.makeOffset(-inputOffset.x(), |
| 145 -inputOffset.y())); | 149 -inputOffset.y())); |
| 146 } | 150 } |
| 147 | 151 |
| 148 SkPixmap inputPixmap; | 152 SkBitmap inputBM; |
| 149 | 153 |
| 150 if (!input->peekPixels(&inputPixmap)) { | 154 if (!input->getROPixels(&inputBM)) { |
| 151 return nullptr; | 155 return nullptr; |
| 152 } | 156 } |
| 153 | 157 |
| 154 if (inputPixmap.colorType() != kN32_SkColorType) { | 158 if (inputBM.colorType() != kN32_SkColorType) { |
| 155 return nullptr; | 159 return nullptr; |
| 156 } | 160 } |
| 157 | 161 |
| 158 SkImageInfo info = SkImageInfo::Make(dstBounds.width(), dstBounds.height(), | 162 SkImageInfo info = SkImageInfo::Make(dstBounds.width(), dstBounds.height(), |
| 159 inputPixmap.colorType(), inputPixmap.al phaType()); | 163 inputBM.colorType(), inputBM.alphaType( )); |
| 160 | 164 |
| 161 SkBitmap tmp, dst; | 165 SkBitmap tmp, dst; |
| 162 if (!tmp.tryAllocPixels(info) || !dst.tryAllocPixels(info)) { | 166 if (!tmp.tryAllocPixels(info) || !dst.tryAllocPixels(info)) { |
| 163 return nullptr; | 167 return nullptr; |
| 164 } | 168 } |
| 165 | 169 |
| 166 SkAutoLockPixels tmpLock(tmp), dstLock(dst); | 170 SkAutoLockPixels inputLock(inputBM), tmpLock(tmp), dstLock(dst); |
| 167 | 171 |
| 168 offset->fX = dstBounds.fLeft; | 172 offset->fX = dstBounds.fLeft; |
| 169 offset->fY = dstBounds.fTop; | 173 offset->fY = dstBounds.fTop; |
| 170 SkPMColor* t = tmp.getAddr32(0, 0); | 174 SkPMColor* t = tmp.getAddr32(0, 0); |
| 171 SkPMColor* d = dst.getAddr32(0, 0); | 175 SkPMColor* d = dst.getAddr32(0, 0); |
| 172 int w = dstBounds.width(), h = dstBounds.height(); | 176 int w = dstBounds.width(), h = dstBounds.height(); |
| 173 const SkPMColor* s = inputPixmap.addr32(inputBounds.x() - inputOffset.x(), | 177 const SkPMColor* s = inputBM.getAddr32(inputBounds.x() - inputOffset.x(), |
| 174 inputBounds.y() - inputOffset.y()); | 178 inputBounds.y() - inputOffset.y()); |
| 175 inputBounds.offset(-dstBounds.x(), -dstBounds.y()); | 179 inputBounds.offset(-dstBounds.x(), -dstBounds.y()); |
| 176 dstBounds.offset(-dstBounds.x(), -dstBounds.y()); | 180 dstBounds.offset(-dstBounds.x(), -dstBounds.y()); |
| 177 SkIRect inputBoundsT = SkIRect::MakeLTRB(inputBounds.top(), inputBounds.left (), | 181 SkIRect inputBoundsT = SkIRect::MakeLTRB(inputBounds.top(), inputBounds.left (), |
| 178 inputBounds.bottom(), inputBounds.r ight()); | 182 inputBounds.bottom(), inputBounds.r ight()); |
| 179 SkIRect dstBoundsT = SkIRect::MakeWH(dstBounds.height(), dstBounds.width()); | 183 SkIRect dstBoundsT = SkIRect::MakeWH(dstBounds.height(), dstBounds.width()); |
| 180 int sw = int(inputPixmap.rowBytes() >> 2); | 184 int sw = int(inputBM.rowBytes() >> 2); |
| 181 | 185 |
| 182 /** | 186 /** |
| 183 * | 187 * |
| 184 * In order to make memory accesses cache-friendly, we reorder the passes to | 188 * In order to make memory accesses cache-friendly, we reorder the passes to |
| 185 * use contiguous memory reads wherever possible. | 189 * use contiguous memory reads wherever possible. |
| 186 * | 190 * |
| 187 * For example, the 6 passes of the X-and-Y blur case are rewritten as | 191 * For example, the 6 passes of the X-and-Y blur case are rewritten as |
| 188 * follows. Instead of 3 passes in X and 3 passes in Y, we perform | 192 * follows. Instead of 3 passes in X and 3 passes in Y, we perform |
| 189 * 2 passes in X, 1 pass in X transposed to Y on write, 2 passes in X, | 193 * 2 passes in X, 1 pass in X transposed to Y on write, 2 passes in X, |
| 190 * then 1 pass in X transposed to Y on write. | 194 * then 1 pass in X transposed to Y on write. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 str->appendf("SkBlurImageFilter: ("); | 244 str->appendf("SkBlurImageFilter: ("); |
| 241 str->appendf("sigma: (%f, %f) input (", fSigma.fWidth, fSigma.fHeight); | 245 str->appendf("sigma: (%f, %f) input (", fSigma.fWidth, fSigma.fHeight); |
| 242 | 246 |
| 243 if (this->getInput(0)) { | 247 if (this->getInput(0)) { |
| 244 this->getInput(0)->toString(str); | 248 this->getInput(0)->toString(str); |
| 245 } | 249 } |
| 246 | 250 |
| 247 str->append("))"); | 251 str->append("))"); |
| 248 } | 252 } |
| 249 #endif | 253 #endif |
| OLD | NEW |