OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 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 "SkImageFilter.h" | 8 #include "SkImageFilter.h" |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
11 #include "SkDevice.h" | |
12 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
13 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
14 #include "SkRect.h" | 13 #include "SkRect.h" |
15 #include "SkValidationUtils.h" | 14 #include "SkValidationUtils.h" |
16 #if SK_SUPPORT_GPU | 15 #if SK_SUPPORT_GPU |
17 #include "GrContext.h" | 16 #include "GrContext.h" |
18 #include "SkGrPixelRef.h" | 17 #include "SkGrPixelRef.h" |
19 #include "SkGr.h" | 18 #include "SkGr.h" |
20 #endif | 19 #endif |
21 | 20 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 #if SK_SUPPORT_GPU | 148 #if SK_SUPPORT_GPU |
150 SkBitmap input = src; | 149 SkBitmap input = src; |
151 SkASSERT(fInputCount == 1); | 150 SkASSERT(fInputCount == 1); |
152 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 151 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
153 if (this->getInput(0) && | 152 if (this->getInput(0) && |
154 !this->getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffse
t)) { | 153 !this->getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffse
t)) { |
155 return false; | 154 return false; |
156 } | 155 } |
157 GrTexture* srcTexture = input.getTexture(); | 156 GrTexture* srcTexture = input.getTexture(); |
158 SkIRect bounds; | 157 SkIRect bounds; |
159 if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &bounds, &input)) { | 158 src.getBounds(&bounds); |
| 159 bounds.offset(srcOffset); |
| 160 if (!this->applyCropRect(&bounds, ctx.ctm())) { |
160 return false; | 161 return false; |
161 } | 162 } |
162 SkRect srcRect = SkRect::Make(bounds); | 163 SkRect srcRect = SkRect::Make(bounds); |
163 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); | 164 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); |
164 GrContext* context = srcTexture->getContext(); | 165 GrContext* context = srcTexture->getContext(); |
165 | 166 |
166 GrTextureDesc desc; | 167 GrTextureDesc desc; |
167 desc.fFlags = kRenderTarget_GrTextureFlagBit, | 168 desc.fFlags = kRenderTarget_GrTextureFlagBit, |
168 desc.fWidth = bounds.width(); | 169 desc.fWidth = bounds.width(); |
169 desc.fHeight = bounds.height(); | 170 desc.fHeight = bounds.height(); |
(...skipping 18 matching lines...) Expand all Loading... |
188 context->drawRectToRect(paint, dstRect, srcRect); | 189 context->drawRectToRect(paint, dstRect, srcRect); |
189 | 190 |
190 SkAutoTUnref<GrTexture> resultTex(dst.detach()); | 191 SkAutoTUnref<GrTexture> resultTex(dst.detach()); |
191 WrapTexture(resultTex, bounds.width(), bounds.height(), result); | 192 WrapTexture(resultTex, bounds.width(), bounds.height(), result); |
192 return true; | 193 return true; |
193 #else | 194 #else |
194 return false; | 195 return false; |
195 #endif | 196 #endif |
196 } | 197 } |
197 | 198 |
198 bool SkImageFilter::applyCropRect(const Context& ctx, const SkBitmap& src, | 199 bool SkImageFilter::applyCropRect(SkIRect* rect, const SkMatrix& matrix) const { |
199 const SkIPoint& srcOffset, SkIRect* bounds) co
nst { | |
200 SkIRect srcBounds; | |
201 src.getBounds(&srcBounds); | |
202 srcBounds.offset(srcOffset); | |
203 SkRect cropRect; | 200 SkRect cropRect; |
204 ctx.ctm().mapRect(&cropRect, fCropRect.rect()); | 201 matrix.mapRect(&cropRect, fCropRect.rect()); |
205 SkIRect cropRectI; | 202 SkIRect cropRectI; |
206 cropRect.roundOut(&cropRectI); | 203 cropRect.roundOut(&cropRectI); |
207 uint32_t flags = fCropRect.flags(); | 204 uint32_t flags = fCropRect.flags(); |
208 if (flags & CropRect::kHasLeft_CropEdge) srcBounds.fLeft = cropRectI.fLeft; | 205 // If the original crop rect edges were unset, max out the new crop edges |
209 if (flags & CropRect::kHasTop_CropEdge) srcBounds.fTop = cropRectI.fTop; | 206 if (!(flags & CropRect::kHasLeft_CropEdge)) cropRectI.fLeft = SK_MinS32; |
210 if (flags & CropRect::kHasRight_CropEdge) srcBounds.fRight = cropRectI.fRigh
t; | 207 if (!(flags & CropRect::kHasTop_CropEdge)) cropRectI.fTop = SK_MinS32; |
211 if (flags & CropRect::kHasBottom_CropEdge) srcBounds.fBottom = cropRectI.fBo
ttom; | 208 if (!(flags & CropRect::kHasRight_CropEdge)) cropRectI.fRight = SK_MaxS32; |
212 if (!srcBounds.intersect(ctx.clipBounds())) { | 209 if (!(flags & CropRect::kHasBottom_CropEdge)) cropRectI.fBottom = SK_MaxS32; |
213 return false; | 210 return rect->intersect(cropRectI); |
214 } | |
215 *bounds = srcBounds; | |
216 return true; | |
217 } | |
218 | |
219 bool SkImageFilter::applyCropRect(const Context& ctx, Proxy* proxy, const SkBitm
ap& src, | |
220 SkIPoint* srcOffset, SkIRect* bounds, SkBitmap
* dst) const { | |
221 SkIRect srcBounds; | |
222 src.getBounds(&srcBounds); | |
223 srcBounds.offset(*srcOffset); | |
224 SkRect cropRect; | |
225 ctx.ctm().mapRect(&cropRect, fCropRect.rect()); | |
226 SkIRect cropRectI; | |
227 cropRect.roundOut(&cropRectI); | |
228 uint32_t flags = fCropRect.flags(); | |
229 *bounds = srcBounds; | |
230 if (flags & CropRect::kHasLeft_CropEdge) bounds->fLeft = cropRectI.fLeft; | |
231 if (flags & CropRect::kHasTop_CropEdge) bounds->fTop = cropRectI.fTop; | |
232 if (flags & CropRect::kHasRight_CropEdge) bounds->fRight = cropRectI.fRight; | |
233 if (flags & CropRect::kHasBottom_CropEdge) bounds->fBottom = cropRectI.fBott
om; | |
234 if (!bounds->intersect(ctx.clipBounds())) { | |
235 return false; | |
236 } | |
237 if (srcBounds.contains(*bounds)) { | |
238 *dst = src; | |
239 return true; | |
240 } else { | |
241 SkAutoTUnref<SkBaseDevice> device(proxy->createDevice(bounds->width(), b
ounds->height())); | |
242 if (!device) { | |
243 return false; | |
244 } | |
245 SkCanvas canvas(device); | |
246 canvas.clear(0x00000000); | |
247 canvas.drawBitmap(src, srcOffset->x() - bounds->x(), srcOffset->y() - bo
unds->y()); | |
248 *srcOffset = SkIPoint::Make(bounds->x(), bounds->y()); | |
249 *dst = device->accessBitmap(false); | |
250 return true; | |
251 } | |
252 } | 211 } |
253 | 212 |
254 bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, | 213 bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm, |
255 SkIRect* dst) const { | 214 SkIRect* dst) const { |
256 if (fInputCount < 1) { | 215 if (fInputCount < 1) { |
257 return false; | 216 return false; |
258 } | 217 } |
259 | 218 |
260 SkIRect bounds; | 219 SkIRect bounds; |
261 for (int i = 0; i < fInputCount; ++i) { | 220 for (int i = 0; i < fInputCount; ++i) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 result->setPixelRef(new SkGrPixelRef(info, resultTex))->unref(); | 273 result->setPixelRef(new SkGrPixelRef(info, resultTex))->unref(); |
315 GrUnlockAndUnrefCachedBitmapTexture(resultTex); | 274 GrUnlockAndUnrefCachedBitmapTexture(resultTex); |
316 } | 275 } |
317 return true; | 276 return true; |
318 } else { | 277 } else { |
319 return false; | 278 return false; |
320 } | 279 } |
321 } | 280 } |
322 } | 281 } |
323 #endif | 282 #endif |
OLD | NEW |