OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
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 "SkBitmapCache.h" | 8 #include "SkBitmapCache.h" |
9 #include "SkImage_Gpu.h" | 9 #include "SkImage_Gpu.h" |
10 #include "GrCaps.h" | 10 #include "GrCaps.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 return nullptr; | 213 return nullptr; |
214 } | 214 } |
215 } | 215 } |
216 | 216 |
217 bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter: :Context&, | 217 bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter: :Context&, |
218 SkBitmap*, SkIPoint*) override { | 218 SkBitmap*, SkIPoint*) override { |
219 return false; | 219 return false; |
220 } | 220 } |
221 }; | 221 }; |
222 | 222 |
223 static SkIRect compute_fast_ibounds(SkImageFilter* filter, const SkIRect& srcBou nds) { | |
224 SkRect fastBounds; | |
225 fastBounds.set(srcBounds); | |
226 filter->computeFastBounds(fastBounds, &fastBounds); | |
227 return fastBounds.roundOut(); | |
228 } | |
229 | |
223 SkImage* SkImage_Gpu::onApplyFilter(SkImageFilter* filter, SkIPoint* offsetResul t, | 230 SkImage* SkImage_Gpu::onApplyFilter(SkImageFilter* filter, SkIPoint* offsetResul t, |
224 bool forceResultToOriginalSize) const { | 231 bool forceResultToOriginalSize) const { |
Stephen White
2015/10/14 21:41:43
As discussed, please change this bool to a nullabl
| |
225 if (!forceResultToOriginalSize || !filter->canFilterImageGPU()) { | 232 const SkIRect srcBounds = SkIRect::MakeWH(this->width(), this->height()); |
226 return this->INHERITED::onApplyFilter(filter, offsetResult, forceResultT oOriginalSize); | 233 |
234 if (forceResultToOriginalSize) { | |
235 SkBitmap src; | |
236 GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isO paque(), &src); | |
237 | |
238 const SkIRect clipBounds = srcBounds; | |
239 SkGpuImageFilterProxy proxy(fTexture->getContext()); | |
240 SkImageFilter::Context ctx(SkMatrix::I(), clipBounds, SkImageFilter::Cac he::Get()); | |
241 | |
242 SkBitmap dst; | |
243 if (filter->canFilterImageGPU()) { | |
244 if (!filter->filterImageGPU(&proxy, src, ctx, &dst, offsetResult)) { | |
Stephen White
2015/10/14 21:41:43
This is going to bypass the caching logic in filte
| |
245 return nullptr; | |
246 } | |
247 } else { | |
248 if (!filter->filterImage(&proxy, src, ctx, &dst, offsetResult)) { | |
249 return nullptr; | |
250 } | |
251 } | |
252 if (dst.getTexture()) { | |
253 return new SkImage_Gpu(dst.width(), dst.height(), kNeedNewImageUniqu eID, dst.alphaType(), | |
254 dst.getTexture(), SkSurface::kNo_Budgeted); | |
255 } | |
256 // fall-through to the drawing case | |
227 } | 257 } |
228 | 258 |
229 SkBitmap src; | 259 const SkIRect dstR = forceResultToOriginalSize ? |
230 GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isOpaqu e(), &src); | 260 srcBounds : compute_fast_ibounds(filter, srcBounds); |
231 | 261 |
232 GrContext* context = fTexture->getContext(); | 262 SkImageInfo info = SkImageInfo::MakeN32Premul(dstR.width(), dstR.height()); |
233 SkGpuImageFilterProxy proxy(context); | 263 SkAutoTUnref<SkSurface> surface(this->onNewSurface(info)); |
234 SkImageFilter::Context ctx(SkMatrix::I(), | |
235 SkIRect::MakeWH(this->width(), this->height()), | |
236 SkImageFilter::Cache::Get()); | |
237 | 264 |
238 SkBitmap dst; | 265 SkPaint paint; |
239 if (filter->filterImageGPU(&proxy, src, ctx, &dst, offsetResult)) { | 266 paint.setImageFilter(filter); |
240 return new SkImage_Gpu(dst.width(), dst.height(), kNeedNewImageUniqueID, dst.alphaType(), | 267 surface->getCanvas()->drawImage(this, SkIntToScalar(-dstR.x()), SkIntToScala r(-dstR.y()), |
241 dst.getTexture(), SkSurface::kNo_Budgeted); | 268 &paint); |
242 } | 269 |
243 return nullptr; | 270 offsetResult->set(dstR.x(), dstR.y()); |
271 return surface->newImageSnapshot(); | |
244 } | 272 } |
245 | 273 |
246 //////////////////////////////////////////////////////////////////////////////// /////////////////// | 274 //////////////////////////////////////////////////////////////////////////////// /////////////////// |
247 | 275 |
248 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur eDesc& desc, | 276 static SkImage* new_wrapped_texture_common(GrContext* ctx, const GrBackendTextur eDesc& desc, |
249 SkAlphaType at, GrWrapOwnership owner ship, | 277 SkAlphaType at, GrWrapOwnership owner ship, |
250 SkImage::TextureReleaseProc releasePr oc, | 278 SkImage::TextureReleaseProc releasePr oc, |
251 SkImage::ReleaseContext releaseCtx) { | 279 SkImage::ReleaseContext releaseCtx) { |
252 if (desc.fWidth <= 0 || desc.fHeight <= 0) { | 280 if (desc.fWidth <= 0 || desc.fHeight <= 0) { |
253 return nullptr; | 281 return nullptr; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 if (!dst) { | 413 if (!dst) { |
386 return nullptr; | 414 return nullptr; |
387 } | 415 } |
388 | 416 |
389 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 417 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
390 const SkIPoint dstP = SkIPoint::Make(0, 0); | 418 const SkIPoint dstP = SkIPoint::Make(0, 0); |
391 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); | 419 ctx->copySurface(dst, src, srcR, dstP, GrContext::kFlushWrites_PixelOp); |
392 return dst; | 420 return dst; |
393 } | 421 } |
394 | 422 |
OLD | NEW |