Add GrMakeCachedBitmapProxy
This is split out of https://skia-review.googlesource.com/c/7889/ (Remove SkSpecialImage's GrTexture-based ctors) to allow focusing on the caching/subsetting changes.
Change-Id: Ic2af7a0d03e88941ab5b6cdfcecbbdefe3578eda
Reviewed-on: https://skia-review.googlesource.com/8456
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/core/SkSpecialImage.cpp b/src/core/SkSpecialImage.cpp
index 0ec5459..f44d011 100644
--- a/src/core/SkSpecialImage.cpp
+++ b/src/core/SkSpecialImage.cpp
@@ -103,16 +103,24 @@
return SkSpecialImage::MakeFromRaster(SkIRect::MakeEmpty(), bmp, &this->props());
}
- sk_sp<GrTexture> resultTex(
- GrRefCachedBitmapTexture(context, bmp, GrSamplerParams::ClampNoFilter(), nullptr));
- if (!resultTex) {
+ // TODO: this is a tight copy of 'bmp' but it doesn't have to be (given SkSpecialImage's
+ // semantics). Since this is cached though we would have to bake the fit into the cache key.
+ sk_sp<GrTextureProxy> proxy = GrMakeCachedBitmapProxy(context, bmp);
+ if (!proxy) {
return nullptr;
}
- return SkSpecialImage::MakeFromGpu(SkIRect::MakeWH(resultTex->width(), resultTex->height()),
- this->uniqueID(),
- resultTex, sk_ref_sp(this->getColorSpace()), &this->props(),
- this->alphaType());
+ const SkIRect rect = SkIRect::MakeWH(proxy->width(), proxy->height());
+
+ // GrMakeCachedBitmapProxy has uploaded only the specified subset of 'bmp' so we need not
+ // bother with SkBitmap::getSubset
+ return SkSpecialImage::MakeDeferredFromGpu(context,
+ rect,
+ this->uniqueID(),
+ std::move(proxy),
+ sk_ref_sp(this->getColorSpace()),
+ &this->props(),
+ this->alphaType());
#else
return nullptr;
#endif