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