Add SkBudgeted parameter to SkImage::makeTextureImage().
Also strengthens/adds some guarantees about this function:
* Always returns the same image if the original is texture-backed and
compatible with GrMipMapped (WRT HW MIP support)
* If a new texture backed image is returned it is always an uncached
texture that is not shared with another image or owned by an image
generator.
Adds a GrImageTexGenPolicy that allows control through image/bitmap
GrTextureProducers of whether a new texture must be made and whether
that texture should be budgeted or not.
Increases unit test coverage of this API.
Bug: skia:8669
Change-Id: Ifc0681856114a08fc8cfc57ca83d22efb1c1f166
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/274938
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index 9f79983..10cb353 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -240,7 +240,8 @@
sk_sp<GrTextureProxy> GrProxyProvider::createProxyFromBitmap(const SkBitmap& bitmap,
GrMipMapped mipMapped,
- SkBackingFit fit) {
+ SkBackingFit fit,
+ SkBudgeted budgeted) {
ASSERT_SINGLE_OWNER
SkASSERT(fit == SkBackingFit::kExact || mipMapped == GrMipMapped::kNo);
@@ -277,9 +278,9 @@
sk_sp<GrTextureProxy> proxy;
if (mipMapped == GrMipMapped::kNo ||
0 == SkMipMap::ComputeLevelCount(copyBitmap.width(), copyBitmap.height())) {
- proxy = this->createNonMippedProxyFromBitmap(copyBitmap, fit, format, grCT);
+ proxy = this->createNonMippedProxyFromBitmap(copyBitmap, fit, format, grCT, budgeted);
} else {
- proxy = this->createMippedProxyFromBitmap(copyBitmap, format, grCT);
+ proxy = this->createMippedProxyFromBitmap(copyBitmap, format, grCT, budgeted);
}
if (!proxy) {
@@ -302,20 +303,21 @@
sk_sp<GrTextureProxy> GrProxyProvider::createNonMippedProxyFromBitmap(const SkBitmap& bitmap,
SkBackingFit fit,
const GrBackendFormat& format,
- GrColorType colorType) {
+ GrColorType colorType,
+ SkBudgeted budgeted) {
GrSwizzle swizzle = this->caps()->getReadSwizzle(format, colorType);
auto dims = bitmap.dimensions();
sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
- [dims, format, bitmap, fit, colorType](GrResourceProvider* resourceProvider) {
+ [dims, format, bitmap, fit, colorType, budgeted](GrResourceProvider* resourceProvider) {
GrMipLevel mipLevel = { bitmap.getPixels(), bitmap.rowBytes() };
return LazyCallbackResult(resourceProvider->createTexture(
- dims, format, colorType, GrRenderable::kNo, 1, SkBudgeted::kYes, fit,
+ dims, format, colorType, GrRenderable::kNo, 1, budgeted, fit,
GrProtected::kNo, mipLevel));
},
format, dims, swizzle, GrRenderable::kNo, 1, GrMipMapped::kNo,
- GrMipMapsStatus::kNotAllocated, GrInternalSurfaceFlags::kNone, fit, SkBudgeted::kYes,
+ GrMipMapsStatus::kNotAllocated, GrInternalSurfaceFlags::kNone, fit, budgeted,
GrProtected::kNo, UseAllocator::kYes);
if (!proxy) {
@@ -327,7 +329,8 @@
sk_sp<GrTextureProxy> GrProxyProvider::createMippedProxyFromBitmap(const SkBitmap& bitmap,
const GrBackendFormat& format,
- GrColorType colorType) {
+ GrColorType colorType,
+ SkBudgeted budgeted) {
SkASSERT(this->caps()->mipMapSupport());
@@ -340,7 +343,7 @@
auto dims = bitmap.dimensions();
sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
- [dims, format, bitmap, mipmaps](GrResourceProvider* resourceProvider) {
+ [dims, format, bitmap, mipmaps, budgeted](GrResourceProvider* resourceProvider) {
const int mipLevelCount = mipmaps->countLevels() + 1;
std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[mipLevelCount]);
@@ -357,12 +360,12 @@
SkASSERT(generatedMipLevel.fPixmap.colorType() == bitmap.colorType());
}
return LazyCallbackResult(resourceProvider->createTexture(
- dims, format, colorType, GrRenderable::kNo, 1, SkBudgeted::kYes,
- GrProtected::kNo, texels.get(), mipLevelCount));
+ dims, format, colorType, GrRenderable::kNo, 1, budgeted, GrProtected::kNo,
+ texels.get(), mipLevelCount));
},
format, dims, readSwizzle, GrRenderable::kNo, 1, GrMipMapped::kYes,
- GrMipMapsStatus::kValid, GrInternalSurfaceFlags::kNone, SkBackingFit::kExact,
- SkBudgeted::kYes, GrProtected::kNo, UseAllocator::kYes);
+ GrMipMapsStatus::kValid, GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, budgeted,
+ GrProtected::kNo, UseAllocator::kYes);
if (!proxy) {
return nullptr;