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 SkASSERT(inputTexture); |
| 102 |
99 if (0 == sigma.x() && 0 == sigma.y()) { | 103 if (0 == sigma.x() && 0 == sigma.y()) { |
100 offset->fX = inputBounds.x(); | 104 offset->fX = inputBounds.x(); |
101 offset->fY = inputBounds.y(); | 105 offset->fY = inputBounds.y(); |
102 return input->makeSubset(inputBounds.makeOffset(-inputOffset.x(), | 106 return input->makeSubset(inputBounds.makeOffset(-inputOffset.x(), |
103 -inputOffset.y())); | 107 -inputOffset.y())); |
104 } | 108 } |
105 | 109 |
106 GrTexture* inputTexture = input->peekTexture(); | |
107 | |
108 offset->fX = dstBounds.fLeft; | 110 offset->fX = dstBounds.fLeft; |
109 offset->fY = dstBounds.fTop; | 111 offset->fY = dstBounds.fTop; |
110 inputBounds.offset(-inputOffset); | 112 inputBounds.offset(-inputOffset); |
111 dstBounds.offset(-inputOffset); | 113 dstBounds.offset(-inputOffset); |
112 SkRect inputBoundsF(SkRect::Make(inputBounds)); | 114 SkRect inputBoundsF(SkRect::Make(inputBounds)); |
113 SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(inputTexture->g
etContext(), | 115 SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(context, |
114 inputTexture, | 116 inputTexture, |
115 false, | 117 false, |
116 source->props()
.allowSRGBInputs(), | 118 source->props()
.allowSRGBInputs(), |
117 SkRect::Make(ds
tBounds), | 119 SkRect::Make(ds
tBounds), |
118 &inputBoundsF, | 120 &inputBoundsF, |
119 sigma.x(), | 121 sigma.x(), |
120 sigma.y())); | 122 sigma.y())); |
121 if (!tex) { | 123 if (!tex) { |
122 return nullptr; | 124 return nullptr; |
123 } | 125 } |
(...skipping 14 matching lines...) Expand all Loading... |
138 return nullptr; | 140 return nullptr; |
139 } | 141 } |
140 | 142 |
141 if (kernelSizeX == 0 && kernelSizeY == 0) { | 143 if (kernelSizeX == 0 && kernelSizeY == 0) { |
142 offset->fX = inputBounds.x(); | 144 offset->fX = inputBounds.x(); |
143 offset->fY = inputBounds.y(); | 145 offset->fY = inputBounds.y(); |
144 return input->makeSubset(inputBounds.makeOffset(-inputOffset.x(), | 146 return input->makeSubset(inputBounds.makeOffset(-inputOffset.x(), |
145 -inputOffset.y())); | 147 -inputOffset.y())); |
146 } | 148 } |
147 | 149 |
148 SkPixmap inputPixmap; | 150 SkBitmap inputBM; |
149 | 151 |
150 if (!input->peekPixels(&inputPixmap)) { | 152 if (!input->getROPixels(&inputBM)) { |
151 return nullptr; | 153 return nullptr; |
152 } | 154 } |
153 | 155 |
154 if (inputPixmap.colorType() != kN32_SkColorType) { | 156 if (inputBM.colorType() != kN32_SkColorType) { |
155 return nullptr; | 157 return nullptr; |
156 } | 158 } |
157 | 159 |
158 SkImageInfo info = SkImageInfo::Make(dstBounds.width(), dstBounds.height(), | 160 SkImageInfo info = SkImageInfo::Make(dstBounds.width(), dstBounds.height(), |
159 inputPixmap.colorType(), inputPixmap.al
phaType()); | 161 inputBM.colorType(), inputBM.alphaType(
)); |
160 | 162 |
161 SkBitmap tmp, dst; | 163 SkBitmap tmp, dst; |
162 if (!tmp.tryAllocPixels(info) || !dst.tryAllocPixels(info)) { | 164 if (!tmp.tryAllocPixels(info) || !dst.tryAllocPixels(info)) { |
163 return nullptr; | 165 return nullptr; |
164 } | 166 } |
165 | 167 |
166 SkAutoLockPixels tmpLock(tmp), dstLock(dst); | 168 SkAutoLockPixels inputLock(inputBM), tmpLock(tmp), dstLock(dst); |
167 | 169 |
168 offset->fX = dstBounds.fLeft; | 170 offset->fX = dstBounds.fLeft; |
169 offset->fY = dstBounds.fTop; | 171 offset->fY = dstBounds.fTop; |
170 SkPMColor* t = tmp.getAddr32(0, 0); | 172 SkPMColor* t = tmp.getAddr32(0, 0); |
171 SkPMColor* d = dst.getAddr32(0, 0); | 173 SkPMColor* d = dst.getAddr32(0, 0); |
172 int w = dstBounds.width(), h = dstBounds.height(); | 174 int w = dstBounds.width(), h = dstBounds.height(); |
173 const SkPMColor* s = inputPixmap.addr32(inputBounds.x() - inputOffset.x(), | 175 const SkPMColor* s = inputBM.getAddr32(inputBounds.x() - inputOffset.x(), |
174 inputBounds.y() - inputOffset.y()); | 176 inputBounds.y() - inputOffset.y()); |
175 inputBounds.offset(-dstBounds.x(), -dstBounds.y()); | 177 inputBounds.offset(-dstBounds.x(), -dstBounds.y()); |
176 dstBounds.offset(-dstBounds.x(), -dstBounds.y()); | 178 dstBounds.offset(-dstBounds.x(), -dstBounds.y()); |
177 SkIRect inputBoundsT = SkIRect::MakeLTRB(inputBounds.top(), inputBounds.left
(), | 179 SkIRect inputBoundsT = SkIRect::MakeLTRB(inputBounds.top(), inputBounds.left
(), |
178 inputBounds.bottom(), inputBounds.r
ight()); | 180 inputBounds.bottom(), inputBounds.r
ight()); |
179 SkIRect dstBoundsT = SkIRect::MakeWH(dstBounds.height(), dstBounds.width()); | 181 SkIRect dstBoundsT = SkIRect::MakeWH(dstBounds.height(), dstBounds.width()); |
180 int sw = int(inputPixmap.rowBytes() >> 2); | 182 int sw = int(inputBM.rowBytes() >> 2); |
181 | 183 |
182 /** | 184 /** |
183 * | 185 * |
184 * In order to make memory accesses cache-friendly, we reorder the passes to | 186 * In order to make memory accesses cache-friendly, we reorder the passes to |
185 * use contiguous memory reads wherever possible. | 187 * use contiguous memory reads wherever possible. |
186 * | 188 * |
187 * For example, the 6 passes of the X-and-Y blur case are rewritten as | 189 * 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 | 190 * 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, | 191 * 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. | 192 * 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: ("); | 242 str->appendf("SkBlurImageFilter: ("); |
241 str->appendf("sigma: (%f, %f) input (", fSigma.fWidth, fSigma.fHeight); | 243 str->appendf("sigma: (%f, %f) input (", fSigma.fWidth, fSigma.fHeight); |
242 | 244 |
243 if (this->getInput(0)) { | 245 if (this->getInput(0)) { |
244 this->getInput(0)->toString(str); | 246 this->getInput(0)->toString(str); |
245 } | 247 } |
246 | 248 |
247 str->append("))"); | 249 str->append("))"); |
248 } | 250 } |
249 #endif | 251 #endif |
OLD | NEW |