Index: src/image/SkImage_Gpu.cpp |
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp |
index 67d1b8cd8632498d8c93b6b7a409a9ee4ec73de9..3000e7c0da9cf0e0150b104dd344f0e2ac04ad62 100644 |
--- a/src/image/SkImage_Gpu.cpp |
+++ b/src/image/SkImage_Gpu.cpp |
@@ -214,33 +214,59 @@ public: |
} |
} |
- bool filterImage(const SkImageFilter*, const SkBitmap&, const SkImageFilter::Context&, |
- SkBitmap*, SkIPoint*) override { |
- return false; |
+ bool filterImage(const SkImageFilter* filter, const SkBitmap& src, |
+ const SkImageFilter::Context& ctx, SkBitmap* dst, SkIPoint* offset) override { |
+ return filter->canFilterImageGPU() && |
+ filter->filterImageGPU(this, src, ctx, dst, offset); |
Stephen White
2015/10/16 20:14:05
This part looks good, I think.
|
} |
}; |
+static SkIRect compute_fast_ibounds(SkImageFilter* filter, const SkIRect& srcBounds) { |
+ SkRect fastBounds; |
+ fastBounds.set(srcBounds); |
+ filter->computeFastBounds(fastBounds, &fastBounds); |
+ return fastBounds.roundOut(); |
+} |
+ |
SkImage* SkImage_Gpu::onApplyFilter(SkImageFilter* filter, SkIPoint* offsetResult, |
bool forceResultToOriginalSize) const { |
Stephen White
2015/10/16 20:14:05
I'd really appreciate if this could be turned into
reed1
2015/10/16 20:41:52
Adding a variant of the public API that takes a re
Stephen White
2015/10/16 21:12:04
BTW, if we also added an SkMatrix param here, and
Stephen White
2015/10/16 21:12:04
It just seems like it would be very easy:
SkImage
|
- if (!forceResultToOriginalSize || !filter->canFilterImageGPU()) { |
- return this->INHERITED::onApplyFilter(filter, offsetResult, forceResultToOriginalSize); |
- } |
+ const SkIRect srcBounds = SkIRect::MakeWH(this->width(), this->height()); |
+ |
+ if (forceResultToOriginalSize) { |
+ SkBitmap src; |
+ GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isOpaque(), &src); |
- SkBitmap src; |
- GrWrapTextureInBitmap(fTexture, this->width(), this->height(), this->isOpaque(), &src); |
+ const SkIRect clipBounds = srcBounds; |
+ SkGpuImageFilterProxy proxy(fTexture->getContext()); |
+ SkImageFilter::Context ctx(SkMatrix::I(), clipBounds, SkImageFilter::Cache::Get()); |
- GrContext* context = fTexture->getContext(); |
- SkGpuImageFilterProxy proxy(context); |
- SkImageFilter::Context ctx(SkMatrix::I(), |
- SkIRect::MakeWH(this->width(), this->height()), |
- SkImageFilter::Cache::Get()); |
+ SkBitmap dst; |
+ if (!filter->filterImage(&proxy, src, ctx, &dst, offsetResult)) { |
+ return nullptr; |
+ } |
+ if (dst.getTexture()) { |
+ return new SkImage_Gpu(dst.width(), dst.height(), kNeedNewImageUniqueID, dst.alphaType(), |
+ dst.getTexture(), SkSurface::kNo_Budgeted); |
+ } |
- SkBitmap dst; |
- if (filter->filterImageGPU(&proxy, src, ctx, &dst, offsetResult)) { |
- return new SkImage_Gpu(dst.width(), dst.height(), kNeedNewImageUniqueID, dst.alphaType(), |
- dst.getTexture(), SkSurface::kNo_Budgeted); |
+ // fall-through to the drawing case |
+ SkDebugf("------ got raster result from gpu-src using filter %s\n", |
Stephen White
2015/10/16 20:14:05
This shouldn't happen. Is it?
reed1
2015/10/16 20:41:52
Done.
|
+ filter->getTypeName()); |
} |
- return nullptr; |
+ |
+ const SkIRect dstR = forceResultToOriginalSize ? |
+ srcBounds : compute_fast_ibounds(filter, srcBounds); |
+ |
+ SkImageInfo info = SkImageInfo::MakeN32Premul(dstR.width(), dstR.height()); |
+ SkAutoTUnref<SkSurface> surface(this->onNewSurface(info)); |
+ |
+ SkPaint paint; |
+ paint.setImageFilter(filter); |
+ surface->getCanvas()->drawImage(this, SkIntToScalar(-dstR.x()), SkIntToScalar(-dstR.y()), |
Stephen White
2015/10/16 20:14:05
It looks like if we fall-through here (when fForce
reed1
2015/10/16 20:41:52
Ah, good point. However, I think your previous poi
|
+ &paint); |
+ |
+ offsetResult->set(dstR.x(), dstR.y()); |
+ return surface->newImageSnapshot(); |
} |
/////////////////////////////////////////////////////////////////////////////////////////////////// |