Fold together mippped and non-mippped bitmap to proxy functions
There are still several layers of redundancy and confusion, but this is
the first step to getting parallel/analogous functions to look and be
scoped similarly.
Bug: skia:
Change-Id: Ief5ecbd55335248a1fc04d66d0a95a8042b0fd28
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/202958
Auto-Submit: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrBitmapTextureMaker.cpp b/src/gpu/GrBitmapTextureMaker.cpp
index ee93521..c6d7504 100644
--- a/src/gpu/GrBitmapTextureMaker.cpp
+++ b/src/gpu/GrBitmapTextureMaker.cpp
@@ -48,12 +48,8 @@
}
if (!proxy) {
- if (willBeMipped) {
- proxy = proxyProvider->createMipMapProxyFromBitmap(fBitmap);
- }
- if (!proxy) {
- proxy = GrUploadBitmapToTextureProxy(proxyProvider, fBitmap);
- }
+ proxy = proxyProvider->createProxyFromBitmap(fBitmap, willBeMipped ? GrMipMapped::kYes
+ : GrMipMapped::kNo);
if (proxy) {
if (fOriginalKey.isValid()) {
proxyProvider->assignUniqueKeyToProxy(fOriginalKey, proxy.get());
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index eee6a95..611d4bc 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -294,7 +294,8 @@
budgeted, GrInternalSurfaceFlags::kNone);
}
-sk_sp<GrTextureProxy> GrProxyProvider::createMipMapProxyFromBitmap(const SkBitmap& bitmap) {
+sk_sp<GrTextureProxy> GrProxyProvider::createProxyFromBitmap(const SkBitmap& bitmap,
+ GrMipMapped mipMapped) {
ASSERT_SINGLE_OWNER
if (this->isAbandoned()) {
@@ -305,7 +306,9 @@
return nullptr;
}
- ATRACE_ANDROID_FRAMEWORK("Upload MipMap Texture [%ux%u]", bitmap.width(), bitmap.height());
+ ATRACE_ANDROID_FRAMEWORK("Upload %sTexture [%ux%u]",
+ GrMipMapped::kYes == mipMapped ? "MipMap " : "",
+ bitmap.width(), bitmap.height());
// In non-ddl we will always instantiate right away. Thus we never want to copy the SkBitmap
// even if its mutable. In ddl, if the bitmap is mutable then we must make a copy since the
@@ -317,8 +320,9 @@
return nullptr;
}
- // This was never going to have mips anyway
- if (0 == SkMipMap::ComputeLevelCount(baseLevel->width(), baseLevel->height())) {
+ // If mips weren't requested (or this was too small to have any), then take the fast path
+ if (GrMipMapped::kNo == mipMapped ||
+ 0 == SkMipMap::ComputeLevelCount(baseLevel->width(), baseLevel->height())) {
return this->createTextureProxy(baseLevel, kNone_GrSurfaceFlags, 1, SkBudgeted::kYes,
SkBackingFit::kExact);
}
diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h
index 40f2e62..358cf1d 100644
--- a/src/gpu/GrProxyProvider.h
+++ b/src/gpu/GrProxyProvider.h
@@ -76,9 +76,9 @@
GrSurfaceOrigin, SkBudgeted);
/*
- * Creates a new mipmapped texture proxy for the bitmap with mip levels generated by the cpu.
+ * Creates a new texture proxy for the bitmap, optionally with mip levels generated by the cpu.
*/
- sk_sp<GrTextureProxy> createMipMapProxyFromBitmap(const SkBitmap& bitmap);
+ sk_sp<GrTextureProxy> createProxyFromBitmap(const SkBitmap& bitmap, GrMipMapped);
/*
* Create a GrSurfaceProxy without any data.
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 43bcc6f..4206687 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -107,28 +107,6 @@
builder[4] = imageBounds.fBottom;
}
-//////////////////////////////////////////////////////////////////////////////
-sk_sp<GrTextureProxy> GrUploadBitmapToTextureProxy(GrProxyProvider* proxyProvider,
- const SkBitmap& bitmap) {
- if (!bitmap.peekPixels(nullptr)) {
- return nullptr;
- }
-
- if (!SkImageInfoIsValid(bitmap.info())) {
- return nullptr;
- }
-
- // In non-ddl we will always instantiate right away. Thus we never want to copy the SkBitmap
- // even if it's mutable. In ddl, if the bitmap is mutable then we must make a copy since the
- // upload of the data to the gpu can happen at anytime and the bitmap may change by then.
- SkCopyPixelsMode cpyMode = proxyProvider->renderingDirectly() ? kNever_SkCopyPixelsMode
- : kIfMutable_SkCopyPixelsMode;
- sk_sp<SkImage> image = SkMakeImageFromRasterBitmap(bitmap, cpyMode);
-
- return proxyProvider->createTextureProxy(std::move(image), kNone_GrSurfaceFlags, 1,
- SkBudgeted::kYes, SkBackingFit::kExact);
-}
-
////////////////////////////////////////////////////////////////////////////////
void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, uint32_t contextUniqueID,
diff --git a/src/gpu/SkGr.h b/src/gpu/SkGr.h
index 407bf54..824c06b 100644
--- a/src/gpu/SkGr.h
+++ b/src/gpu/SkGr.h
@@ -191,13 +191,6 @@
SkScalar scaleAdjust[2]);
/**
- * Creates a new texture for the bitmap. Does not concern itself with cache keys or texture params.
- * The bitmap must have CPU-accessible pixels. Attempts to take advantage of faster paths for
- * yuv planes.
- */
-sk_sp<GrTextureProxy> GrUploadBitmapToTextureProxy(GrProxyProvider*, const SkBitmap&);
-
-/**
* Creates a new texture with mipmap levels and copies the baseProxy into the base layer.
*/
sk_sp<GrTextureProxy> GrCopyBaseMipMapToTextureProxy(GrRecordingContext*,