Remove create function in proxyProvider that takes a raster SkImage.
Instead in proxyProvider we just have a create a bitmap call which
does no special fallback or logic. All the callers now go through
GrBitmapTextureMaker which handles and special fallbacks or caching
support that we need.
Change-Id: I71bb896cc78f64f9d6d54b54af2490d48e0f5af5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/266842
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrBitmapTextureMaker.cpp b/src/gpu/GrBitmapTextureMaker.cpp
index 129f06e..a896ff6 100644
--- a/src/gpu/GrBitmapTextureMaker.cpp
+++ b/src/gpu/GrBitmapTextureMaker.cpp
@@ -27,10 +27,11 @@
}
GrBitmapTextureMaker::GrBitmapTextureMaker(GrRecordingContext* context, const SkBitmap& bitmap,
- bool useDecal, bool shouldUseUniqueKey)
+ Cached cached, SkBackingFit fit, bool useDecal)
: INHERITED(context, get_image_info(context, bitmap), useDecal)
- , fBitmap(bitmap) {
- if (!bitmap.isVolatile() && shouldUseUniqueKey) {
+ , fBitmap(bitmap)
+ , fFit(fit) {
+ if (!bitmap.isVolatile() && cached == Cached::kYes) {
SkIPoint origin = bitmap.pixelRefOrigin();
SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.width(),
bitmap.height());
@@ -65,11 +66,11 @@
return nullptr;
}
copy8888.setImmutable();
- proxy = proxyProvider->createProxyFromBitmap(copy8888, willBeMipped ? GrMipMapped::kYes
- : GrMipMapped::kNo);
+ proxy = proxyProvider->createProxyFromBitmap(
+ copy8888, willBeMipped ? GrMipMapped::kYes : GrMipMapped::kNo, fFit);
} else {
- proxy = proxyProvider->createProxyFromBitmap(fBitmap, willBeMipped ? GrMipMapped::kYes
- : GrMipMapped::kNo);
+ proxy = proxyProvider->createProxyFromBitmap(
+ fBitmap, willBeMipped ? GrMipMapped::kYes : GrMipMapped::kNo, fFit);
}
if (proxy) {
if (fOriginalKey.isValid()) {
diff --git a/src/gpu/GrBitmapTextureMaker.h b/src/gpu/GrBitmapTextureMaker.h
index 984cd40..717a41c 100644
--- a/src/gpu/GrBitmapTextureMaker.h
+++ b/src/gpu/GrBitmapTextureMaker.h
@@ -16,8 +16,11 @@
subset of the pixelref specified by the bitmap. */
class GrBitmapTextureMaker : public GrTextureMaker {
public:
+ enum class Cached { kNo, kYes };
+
GrBitmapTextureMaker(GrRecordingContext* context, const SkBitmap& bitmap,
- bool useDecal = false, bool shouldUseUniqueKey = true);
+ Cached cached = Cached::kNo, SkBackingFit = SkBackingFit::kExact,
+ bool useDecal = false);
private:
sk_sp<GrTextureProxy> refOriginalTextureProxy(bool willBeMipped,
@@ -26,8 +29,9 @@
void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) override;
void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override;
- const SkBitmap fBitmap;
- GrUniqueKey fOriginalKey;
+ const SkBitmap fBitmap;
+ const SkBackingFit fFit;
+ GrUniqueKey fOriginalKey;
typedef GrTextureMaker INHERITED;
};
diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp
index b2a7f65..c28cccf 100644
--- a/src/gpu/GrBlurUtils.cpp
+++ b/src/gpu/GrBlurUtils.cpp
@@ -8,6 +8,7 @@
#include "src/gpu/GrBlurUtils.h"
#include "include/private/GrRecordingContext.h"
+#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrCaps.h"
#include "src/gpu/GrFixedClip.h"
#include "src/gpu/GrProxyProvider.h"
@@ -145,13 +146,9 @@
}
bm.setImmutable();
- sk_sp<SkImage> image = SkImage::MakeFromBitmap(bm);
- if (!image) {
- return false;
- }
-
- filteredMask = proxyProvider->createTextureProxy(std::move(image), 1, SkBudgeted::kYes,
- SkBackingFit::kApprox);
+ GrBitmapTextureMaker maker(context, bm, GrBitmapTextureMaker::Cached::kNo,
+ SkBackingFit::kApprox);
+ std::tie(filteredMask, std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
if (!filteredMask) {
return false;
}
diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp
index 7bbf53d..24057b0 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -250,83 +250,11 @@
return result;
}
-sk_sp<GrTextureProxy> GrProxyProvider::createTextureProxy(sk_sp<SkImage> srcImage,
- int sampleCnt,
- SkBudgeted budgeted,
- SkBackingFit fit,
- GrInternalSurfaceFlags surfaceFlags) {
- ASSERT_SINGLE_OWNER
- SkASSERT(srcImage);
-
- if (this->isAbandoned()) {
- return nullptr;
- }
-
- const SkImageInfo& info = srcImage->imageInfo();
- GrColorType ct = SkColorTypeToGrColorType(info.colorType());
-
- GrBackendFormat format = this->caps()->getDefaultBackendFormat(ct, GrRenderable::kNo);
-
- if (!format.isValid()) {
- SkBitmap copy8888;
- if (!copy8888.tryAllocPixels(info.makeColorType(kRGBA_8888_SkColorType)) ||
- !srcImage->readPixels(copy8888.pixmap(), 0, 0)) {
- return nullptr;
- }
- copy8888.setImmutable();
- srcImage = SkMakeImageFromRasterBitmap(copy8888, kNever_SkCopyPixelsMode);
- ct = GrColorType::kRGBA_8888;
- format = this->caps()->getDefaultBackendFormat(ct, GrRenderable::kNo);
- if (!format.isValid()) {
- return nullptr;
- }
- }
-
- GrSurfaceDesc desc;
- desc.fWidth = srcImage->width();
- desc.fHeight = srcImage->height();
-
- GrSwizzle swizzle = this->caps()->getReadSwizzle(format, ct);
-
- sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
- [desc, format, sampleCnt, budgeted, srcImage, fit,
- ct](GrResourceProvider* resourceProvider) {
- SkPixmap pixMap;
- SkAssertResult(srcImage->peekPixels(&pixMap));
- GrMipLevel mipLevel = { pixMap.addr(), pixMap.rowBytes() };
-
- return LazyCallbackResult(resourceProvider->createTexture(
- desc, format, ct, GrRenderable::kNo, sampleCnt, budgeted, fit,
- GrProtected::kNo, mipLevel));
- },
- format, desc, swizzle, GrRenderable::kNo, sampleCnt, kTopLeft_GrSurfaceOrigin,
- GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated, surfaceFlags, fit, budgeted,
- GrProtected::kNo, UseAllocator::kYes);
-
- if (!proxy) {
- return nullptr;
- }
-
- GrContext* direct = fImageContext->priv().asDirectContext();
- if (direct) {
- GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
-
- // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however
- // we're better off instantiating the proxy immediately here.
- if (!proxy->priv().doLazyInstantiation(resourceProvider)) {
- return nullptr;
- }
- }
-
- SkASSERT(proxy->width() == desc.fWidth);
- SkASSERT(proxy->height() == desc.fHeight);
- return proxy;
-}
-
sk_sp<GrTextureProxy> GrProxyProvider::createProxyFromBitmap(const SkBitmap& bitmap,
- GrMipMapped mipMapped) {
+ GrMipMapped mipMapped,
+ SkBackingFit fit) {
ASSERT_SINGLE_OWNER
- SkASSERT(GrMipMapped::kNo == mipMapped || this->caps()->mipMapSupport());
+ SkASSERT(fit == SkBackingFit::kExact || mipMapped == GrMipMapped::kNo);
if (this->isAbandoned()) {
return nullptr;
@@ -343,56 +271,107 @@
// 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
// upload of the data to the gpu can happen at anytime and the bitmap may change by then.
- SkCopyPixelsMode copyMode = this->renderingDirectly() ? kNever_SkCopyPixelsMode
- : kIfMutable_SkCopyPixelsMode;
- sk_sp<SkImage> baseLevel = SkMakeImageFromRasterBitmap(bitmap, copyMode);
- if (!baseLevel) {
- return nullptr;
+ SkBitmap copyBitmap = bitmap;
+ if (!this->renderingDirectly() && !bitmap.isImmutable()) {
+ copyBitmap.allocPixels();
+ if (!bitmap.readPixels(copyBitmap.pixmap())) {
+ return nullptr;
+ }
+ copyBitmap.setImmutable();
}
- // 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(std::move(baseLevel), 1, SkBudgeted::kYes,
- SkBackingFit::kExact);
- }
-
- GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info());
-
- GrColorType grCT = SkColorTypeToGrColorType(bitmap.info().colorType());
+ GrColorType grCT = SkColorTypeToGrColorType(copyBitmap.info().colorType());
GrBackendFormat format = this->caps()->getDefaultBackendFormat(grCT, GrRenderable::kNo);
if (!format.isValid()) {
return nullptr;
}
- SkPixmap pixmap;
- SkAssertResult(baseLevel->peekPixels(&pixmap));
- sk_sp<SkMipMap> mipmaps(SkMipMap::Build(pixmap, nullptr));
+ sk_sp<GrTextureProxy> proxy;
+ if (mipMapped == GrMipMapped::kNo ||
+ 0 == SkMipMap::ComputeLevelCount(copyBitmap.width(), copyBitmap.height())) {
+ proxy = this->createNonMippedProxyFromBitmap(copyBitmap, fit, format, grCT);
+ } else {
+ proxy = this->createMippedProxyFromBitmap(copyBitmap, format, grCT);
+ }
+
+ if (!proxy) {
+ return nullptr;
+ }
+
+ GrContext* direct = fImageContext->priv().asDirectContext();
+ if (direct) {
+ GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
+
+ // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however
+ // we're better off instantiating the proxy immediately here.
+ if (!proxy->priv().doLazyInstantiation(resourceProvider)) {
+ return nullptr;
+ }
+ }
+ return proxy;
+}
+
+sk_sp<GrTextureProxy> GrProxyProvider::createNonMippedProxyFromBitmap(const SkBitmap& bitmap,
+ SkBackingFit fit,
+ const GrBackendFormat& format,
+ GrColorType colorType) {
+ GrSurfaceDesc desc;
+ desc.fWidth = bitmap.width();
+ desc.fHeight = bitmap.height();
+
+ GrSwizzle swizzle = this->caps()->getReadSwizzle(format, colorType);
+
+ sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
+ [desc, format, bitmap, fit, colorType]
+ (GrResourceProvider* resourceProvider) {
+ GrMipLevel mipLevel = { bitmap.getPixels(), bitmap.rowBytes() };
+
+ return LazyCallbackResult(resourceProvider->createTexture(
+ desc, format, colorType, GrRenderable::kNo, 1, SkBudgeted::kYes, fit,
+ GrProtected::kNo, mipLevel));
+ },
+ format, desc, swizzle, GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin,
+ GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated, GrInternalSurfaceFlags::kNone, fit,
+ SkBudgeted::kYes, GrProtected::kNo, UseAllocator::kYes);
+
+ if (!proxy) {
+ return nullptr;
+ }
+ SkASSERT(proxy->width() == desc.fWidth);
+ SkASSERT(proxy->height() == desc.fHeight);
+ return proxy;
+}
+
+sk_sp<GrTextureProxy> GrProxyProvider::createMippedProxyFromBitmap(const SkBitmap& bitmap,
+ const GrBackendFormat& format,
+ GrColorType colorType) {
+ SkASSERT(this->caps()->mipMapSupport());
+
+ GrSurfaceDesc desc = GrImageInfoToSurfaceDesc(bitmap.info());
+
+ sk_sp<SkMipMap> mipmaps(SkMipMap::Build(bitmap.pixmap(), nullptr));
if (!mipmaps) {
return nullptr;
}
- GrSwizzle readSwizzle = this->caps()->getReadSwizzle(format, grCT);
+ GrSwizzle readSwizzle = this->caps()->getReadSwizzle(format, colorType);
sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
- [desc, format, baseLevel, mipmaps](GrResourceProvider* resourceProvider) {
+ [desc, format, bitmap, mipmaps](GrResourceProvider* resourceProvider) {
const int mipLevelCount = mipmaps->countLevels() + 1;
std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[mipLevelCount]);
- SkPixmap pixmap;
- SkAssertResult(baseLevel->peekPixels(&pixmap));
+ texels[0].fPixels = bitmap.getPixels();
+ texels[0].fRowBytes = bitmap.rowBytes();
- texels[0].fPixels = pixmap.addr();
- texels[0].fRowBytes = pixmap.rowBytes();
-
- auto colorType = SkColorTypeToGrColorType(pixmap.colorType());
+ auto colorType = SkColorTypeToGrColorType(bitmap.colorType());
for (int i = 1; i < mipLevelCount; ++i) {
SkMipMap::Level generatedMipLevel;
mipmaps->getLevel(i - 1, &generatedMipLevel);
texels[i].fPixels = generatedMipLevel.fPixmap.addr();
texels[i].fRowBytes = generatedMipLevel.fPixmap.rowBytes();
SkASSERT(texels[i].fPixels);
- SkASSERT(generatedMipLevel.fPixmap.colorType() == pixmap.colorType());
+ SkASSERT(generatedMipLevel.fPixmap.colorType() == bitmap.colorType());
}
return LazyCallbackResult(resourceProvider->createTexture(
desc, format, colorType, GrRenderable::kNo, 1, SkBudgeted::kYes,
@@ -406,15 +385,9 @@
return nullptr;
}
- GrContext* direct = fImageContext->priv().asDirectContext();
- if (direct) {
- GrResourceProvider* resourceProvider = direct->priv().resourceProvider();
- // In order to reuse code we always create a lazy proxy. When we aren't in DDL mode however
- // we're better off instantiating the proxy immediately here.
- if (!proxy->priv().doLazyInstantiation(resourceProvider)) {
- return nullptr;
- }
- }
+ SkASSERT(proxy->width() == desc.fWidth);
+ SkASSERT(proxy->height() == desc.fHeight);
+
return proxy;
}
diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h
index 120f3f2..6b13d42 100644
--- a/src/gpu/GrProxyProvider.h
+++ b/src/gpu/GrProxyProvider.h
@@ -64,18 +64,10 @@
UseAllocator = UseAllocator::kYes);
/*
- * Create an un-mipmapped texture proxy with data. The SkImage must be a raster backend image.
- * Since the SkImage is ref counted, we simply take a ref on it to keep the data alive until we
- * actually upload the data to the gpu.
- */
- sk_sp<GrTextureProxy> createTextureProxy(
- sk_sp<SkImage> srcImage, int sampleCnt, SkBudgeted, SkBackingFit,
- GrInternalSurfaceFlags = GrInternalSurfaceFlags::kNone);
-
- /*
* Creates a new texture proxy for the bitmap, optionally with mip levels generated by the cpu.
*/
- sk_sp<GrTextureProxy> createProxyFromBitmap(const SkBitmap& bitmap, GrMipMapped);
+ sk_sp<GrTextureProxy> createProxyFromBitmap(const SkBitmap& bitmap, GrMipMapped,
+ SkBackingFit fit);
/*
* Create a GrSurfaceProxy without any data.
@@ -282,6 +274,20 @@
bool isAbandoned() const;
+ /*
+ * Create an un-mipmapped texture proxy for the bitmap.
+ */
+ sk_sp<GrTextureProxy> createNonMippedProxyFromBitmap(const SkBitmap& bitmap,
+ SkBackingFit fit,
+ const GrBackendFormat& format,
+ GrColorType colorType);
+ /*
+ * Create an mipmapped texture proxy for the bitmap.
+ */
+ sk_sp<GrTextureProxy> createMippedProxyFromBitmap(const SkBitmap& bitmap,
+ const GrBackendFormat& format,
+ GrColorType colorType);
+
// GrColorType is used to determine the proxy's texture swizzle.
sk_sp<GrTextureProxy> createWrapped(sk_sp<GrTexture> tex, GrColorType, GrSurfaceOrigin origin,
UseAllocator useAllocator);
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp
index 879a028..65db58d 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -8,6 +8,7 @@
#include "src/gpu/GrSWMaskHelper.h"
#include "include/private/GrRecordingContext.h"
+#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrCaps.h"
#include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRecordingContextPriv.h"
@@ -97,16 +98,13 @@
SkImageInfo ii = SkImageInfo::MakeA8(fPixels->width(), fPixels->height());
size_t rowBytes = fPixels->rowBytes();
- sk_sp<SkData> data = fPixels->detachPixelsAsData();
- if (!data) {
- return nullptr;
- }
+ SkBitmap bitmap;
+ SkAssertResult(bitmap.installPixels(ii, fPixels->detachPixels(), rowBytes,
+ [](void* addr, void* context) { sk_free(addr); },
+ nullptr));
+ bitmap.setImmutable();
- sk_sp<SkImage> img = SkImage::MakeRasterData(ii, std::move(data), rowBytes);
- if (!img) {
- return nullptr;
- }
-
- return context->priv().proxyProvider()->createTextureProxy(std::move(img), 1, SkBudgeted::kYes,
- fit);
+ GrBitmapTextureMaker maker(context, bitmap, GrBitmapTextureMaker::Cached::kNo, fit);
+ auto [texture, ct] = maker.refTextureProxy(GrMipMapped::kNo);
+ return texture;
}
diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp
index 178554a..4cb2fe9 100644
--- a/src/gpu/GrYUVProvider.cpp
+++ b/src/gpu/GrYUVProvider.cpp
@@ -14,6 +14,7 @@
#include "src/core/SkCachedData.h"
#include "src/core/SkResourceCache.h"
#include "src/core/SkYUVPlanesCache.h"
+#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrCaps.h"
#include "src/gpu/GrClip.h"
#include "src/gpu/GrColorSpaceXform.h"
@@ -97,7 +98,7 @@
return data;
}
-void GrYUVProvider::YUVGen_DataReleaseProc(const void*, void* data) {
+void GrYUVProvider::YUVGen_DataReleaseProc(void*, void* data) {
SkCachedData* cachedData = static_cast<SkCachedData*>(data);
SkASSERT(cachedData);
cachedData->unref();
@@ -137,21 +138,23 @@
? SkBackingFit::kExact : SkBackingFit::kApprox;
SkImageInfo imageInfo = SkImageInfo::MakeA8(componentWidth, componentHeight);
- SkPixmap pixmap(imageInfo, planes[i], yuvSizeInfo.fWidthBytes[i]);
SkCachedData* dataStoragePtr = dataStorage.get();
- // We grab a ref to cached yuv data. When the SkImage we create below goes away it will call
- // the YUVGen_DataReleaseProc which will release this ref.
+ // We grab a ref to cached yuv data. When the SkBitmap we create below goes away it will
+ // call the YUVGen_DataReleaseProc which will release this ref.
// DDL TODO: Currently we end up creating a lazy proxy that will hold onto a ref to the
// SkImage in its lambda. This means that we'll keep the ref on the YUV data around for the
// life time of the proxy and not just upload. For non-DDL draws we should look into
// releasing this SkImage after uploads (by deleting the lambda after instantiation).
dataStoragePtr->ref();
- sk_sp<SkImage> yuvImage = SkImage::MakeFromRaster(pixmap, YUVGen_DataReleaseProc,
- dataStoragePtr);
+ SkBitmap bitmap;
+ SkAssertResult(bitmap.installPixels(imageInfo, const_cast<void*>(planes[i]),
+ yuvSizeInfo.fWidthBytes[i],
+ YUVGen_DataReleaseProc, dataStoragePtr));
+ bitmap.setImmutable();
- auto proxyProvider = ctx->priv().proxyProvider();
- yuvTextureProxies[i] =
- proxyProvider->createTextureProxy(yuvImage, 1, SkBudgeted::kYes, fit);
+ GrBitmapTextureMaker maker(ctx, bitmap, GrBitmapTextureMaker::Cached::kNo, fit);
+ std::tie(yuvTextureProxies[i], std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
+
if (!yuvTextureProxies[i]) {
return nullptr;
}
diff --git a/src/gpu/GrYUVProvider.h b/src/gpu/GrYUVProvider.h
index 330c7fb..bfd1ddc 100644
--- a/src/gpu/GrYUVProvider.h
+++ b/src/gpu/GrYUVProvider.h
@@ -87,7 +87,7 @@
// This is used as release callback for the YUV data that we capture in an SkImage when
// uploading to a gpu. When the upload is complete and we release the SkImage this callback will
// release the underlying data.
- static void YUVGen_DataReleaseProc(const void*, void* data);
+ static void YUVGen_DataReleaseProc(void*, void* data);
};
#endif
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index ba29ad7..2710b03 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1183,15 +1183,14 @@
return;
}
}
- GrBitmapTextureMaker maker(fContext.get(), bitmap);
+ GrBitmapTextureMaker maker(fContext.get(), bitmap, GrBitmapTextureMaker::Cached::kYes);
this->drawTextureProducer(&maker, src, dst, constraint, this->localToDevice(), paint, true);
}
sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkBitmap& bitmap) {
// TODO: this makes a tight copy of 'bitmap' but it doesn't have to be (given SkSpecialImage's
// semantics). Since this is cached we would have to bake the fit into the cache key though.
- sk_sp<GrTextureProxy> proxy = GrMakeCachedBitmapProxy(fContext->priv().proxyProvider(),
- bitmap);
+ sk_sp<GrTextureProxy> proxy = GrMakeCachedBitmapProxy(fContext.get(), bitmap);
if (!proxy) {
return nullptr;
}
@@ -1327,7 +1326,7 @@
GrImageTextureMaker maker(fContext.get(), image, SkImage::kAllow_CachingHint);
this->drawProducerLattice(&maker, std::move(iter), dst, paint);
} else if (as_IB(image)->getROPixels(&bm)) {
- GrBitmapTextureMaker maker(fContext.get(), bm);
+ GrBitmapTextureMaker maker(fContext.get(), bm, GrBitmapTextureMaker::Cached::kYes);
this->drawProducerLattice(&maker, std::move(iter), dst, paint);
}
}
@@ -1337,7 +1336,7 @@
const SkRect& dst, const SkPaint& paint) {
ASSERT_SINGLE_OWNER
auto iter = std::make_unique<SkLatticeIter>(bitmap.width(), bitmap.height(), center, dst);
- GrBitmapTextureMaker maker(fContext.get(), bitmap);
+ GrBitmapTextureMaker maker(fContext.get(), bitmap, GrBitmapTextureMaker::Cached::kYes);
this->drawProducerLattice(&maker, std::move(iter), dst, paint);
}
@@ -1391,7 +1390,7 @@
GrImageTextureMaker maker(fContext.get(), image, SkImage::kAllow_CachingHint);
this->drawProducerLattice(&maker, std::move(iter), dst, paint);
} else if (as_IB(image)->getROPixels(&bm)) {
- GrBitmapTextureMaker maker(fContext.get(), bm);
+ GrBitmapTextureMaker maker(fContext.get(), bm, GrBitmapTextureMaker::Cached::kYes);
this->drawProducerLattice(&maker, std::move(iter), dst, paint);
}
}
@@ -1402,7 +1401,7 @@
const SkPaint& paint) {
ASSERT_SINGLE_OWNER
auto iter = std::make_unique<SkLatticeIter>(lattice, dst);
- GrBitmapTextureMaker maker(fContext.get(), bitmap);
+ GrBitmapTextureMaker maker(fContext.get(), bitmap, GrBitmapTextureMaker::Cached::kYes);
this->drawProducerLattice(&maker, std::move(iter), dst, paint);
}
diff --git a/src/gpu/SkGpuDevice_drawTexture.cpp b/src/gpu/SkGpuDevice_drawTexture.cpp
index 6d5d0f0..26c988a 100644
--- a/src/gpu/SkGpuDevice_drawTexture.cpp
+++ b/src/gpu/SkGpuDevice_drawTexture.cpp
@@ -452,7 +452,8 @@
return;
}
if (as_IB(image)->getROPixels(&bm)) {
- GrBitmapTextureMaker maker(fContext.get(), bm, useDecal);
+ GrBitmapTextureMaker maker(fContext.get(), bm, GrBitmapTextureMaker::Cached::kYes,
+ SkBackingFit::kExact, useDecal);
draw_texture_producer(fContext.get(), fRenderTargetContext.get(), this->clip(), ctm,
paint, &maker, src, dst, dstClip, srcToDst, aa, aaFlags, constraint,
attemptDrawTexture);
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index fa11800..74e43fe 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -140,75 +140,19 @@
const SkBitmap& bitmap,
GrSamplerState params,
SkScalar scaleAdjust[2]) {
- return GrBitmapTextureMaker(ctx, bitmap).refTextureProxyForParams(params, scaleAdjust);
+ GrBitmapTextureMaker maker(ctx, bitmap, GrBitmapTextureMaker::Cached::kYes);
+ return maker.refTextureProxyForParams(params, scaleAdjust);
}
-sk_sp<GrTextureProxy> GrMakeCachedBitmapProxy(GrProxyProvider* proxyProvider,
+sk_sp<GrTextureProxy> GrMakeCachedBitmapProxy(GrRecordingContext* context,
const SkBitmap& bitmap,
SkBackingFit fit) {
if (!bitmap.peekPixels(nullptr)) {
return nullptr;
}
- // 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
- // 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);
-
- if (!image) {
- return nullptr;
- }
-
- return GrMakeCachedImageProxy(proxyProvider, std::move(image), fit);
-}
-
-static void create_unique_key_for_image(const SkImage* image, GrUniqueKey* result) {
- if (!image) {
- result->reset(); // will be invalid
- return;
- }
-
- if (const SkBitmap* bm = as_IB(image)->onPeekBitmap()) {
- if (!bm->isVolatile()) {
- SkIPoint origin = bm->pixelRefOrigin();
- SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bm->width(), bm->height());
- GrMakeKeyFromImageID(result, bm->getGenerationID(), subset);
- }
- return;
- }
-
- GrMakeKeyFromImageID(result, image->uniqueID(), image->bounds());
-}
-
-sk_sp<GrTextureProxy> GrMakeCachedImageProxy(GrProxyProvider* proxyProvider,
- sk_sp<SkImage> srcImage,
- SkBackingFit fit) {
- sk_sp<GrTextureProxy> proxy;
- GrUniqueKey originalKey;
-
- create_unique_key_for_image(srcImage.get(), &originalKey);
-
- if (originalKey.isValid()) {
- proxy = proxyProvider->findOrCreateProxyByUniqueKey(
- originalKey, SkColorTypeToGrColorType(srcImage->colorType()),
- kTopLeft_GrSurfaceOrigin);
- }
- if (!proxy) {
- proxy = proxyProvider->createTextureProxy(srcImage, 1, SkBudgeted::kYes, fit);
- if (proxy && originalKey.isValid()) {
- proxyProvider->assignUniqueKeyToProxy(originalKey, proxy.get());
- const SkBitmap* bm = as_IB(srcImage.get())->onPeekBitmap();
- // When recording DDLs we do not want to install change listeners because doing
- // so isn't threadsafe.
- if (bm && proxyProvider->renderingDirectly()) {
- GrInstallBitmapUniqueKeyInvalidator(originalKey, proxyProvider->contextID(),
- bm->pixelRef());
- }
- }
- }
-
+ GrBitmapTextureMaker maker(context, bitmap, GrBitmapTextureMaker::Cached::kYes, fit);
+ auto [proxy, ct] = maker.refTextureProxy(GrMipMapped::kNo);
return proxy;
}
diff --git a/src/gpu/SkGr.h b/src/gpu/SkGr.h
index 19a3f49..33c5146 100644
--- a/src/gpu/SkGr.h
+++ b/src/gpu/SkGr.h
@@ -185,19 +185,12 @@
GrColorType srcColorType);
/*
- * Create a texture proxy from the provided bitmap by wrapping it in an image and calling
- * GrMakeCachedImageProxy.
+ * Create a texture proxy from the provided bitmap and add it to the texture cache
+ * using the key also extracted from 'bitmp'.
*/
-sk_sp<GrTextureProxy> GrMakeCachedBitmapProxy(GrProxyProvider*, const SkBitmap& bitmap,
+sk_sp<GrTextureProxy> GrMakeCachedBitmapProxy(GrRecordingContext*, const SkBitmap& bitmap,
SkBackingFit fit = SkBackingFit::kExact);
-/*
- * Create a texture proxy from the provided 'srcImage' and add it to the texture cache
- * using the key also extracted from 'srcImage'.
- */
-sk_sp<GrTextureProxy> GrMakeCachedImageProxy(GrProxyProvider*, sk_sp<SkImage> srcImage,
- SkBackingFit fit = SkBackingFit::kExact);
-
/**
* Our key includes the offset, width, and height so that bitmaps created by extractSubset()
* are unique.
diff --git a/src/gpu/effects/GrCircleBlurFragmentProcessor.fp b/src/gpu/effects/GrCircleBlurFragmentProcessor.fp
index a710b2d..d71e9d6 100644
--- a/src/gpu/effects/GrCircleBlurFragmentProcessor.fp
+++ b/src/gpu/effects/GrCircleBlurFragmentProcessor.fp
@@ -21,7 +21,7 @@
}
@make {
- static std::unique_ptr<GrFragmentProcessor> Make(GrProxyProvider*,
+ static std::unique_ptr<GrFragmentProcessor> Make(GrRecordingContext*,
const SkRect& circle, float sigma);
}
@@ -31,7 +31,11 @@
}
@cpp {
+ #include "include/gpu/GrContext.h"
+ #include "include/private/GrRecordingContext.h"
+ #include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrProxyProvider.h"
+ #include "src/gpu/GrRecordingContextPriv.h"
// Computes an unnormalized half kernel (right side). Returns the summation of all the half
// kernel values.
@@ -184,7 +188,7 @@
profile[profileWidth - 1] = 0;
}
- static sk_sp<GrTextureProxy> create_profile_texture(GrProxyProvider* proxyProvider,
+ static sk_sp<GrTextureProxy> create_profile_texture(GrRecordingContext* context,
const SkRect& circle,
float sigma,
float* solidRadius, float* textureRadius) {
@@ -226,6 +230,7 @@
builder[0] = sigmaToCircleRRatioFixed;
builder.finish();
+ GrProxyProvider* proxyProvider = context->priv().proxyProvider();
sk_sp<GrTextureProxy> blurProfile = proxyProvider->findOrCreateProxyByUniqueKey(
key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin);
if (!blurProfile) {
@@ -246,10 +251,9 @@
}
bm.setImmutable();
- sk_sp<SkImage> image = SkImage::MakeFromBitmap(bm);
- blurProfile = proxyProvider->createTextureProxy(std::move(image), 1,
- SkBudgeted::kYes, SkBackingFit::kExact);
+ GrBitmapTextureMaker maker(context, bm);
+ std::tie(blurProfile, std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
if (!blurProfile) {
return nullptr;
}
@@ -260,10 +264,10 @@
}
std::unique_ptr<GrFragmentProcessor> GrCircleBlurFragmentProcessor::Make(
- GrProxyProvider* proxyProvider, const SkRect& circle, float sigma) {
+ GrRecordingContext* context, const SkRect& circle, float sigma) {
float solidRadius;
float textureRadius;
- sk_sp<GrTextureProxy> profile(create_profile_texture(proxyProvider, circle, sigma,
+ sk_sp<GrTextureProxy> profile(create_profile_texture(context, circle, sigma,
&solidRadius, &textureRadius));
if (!profile) {
return nullptr;
@@ -286,5 +290,5 @@
SkScalar wh = testData->fRandom->nextRangeScalar(100.f, 1000.f);
SkScalar sigma = testData->fRandom->nextRangeF(1.f,10.f);
SkRect circle = SkRect::MakeWH(wh, wh);
- return GrCircleBlurFragmentProcessor::Make(testData->proxyProvider(), circle, sigma);
+ return GrCircleBlurFragmentProcessor::Make(testData->context(), circle, sigma);
}
diff --git a/src/gpu/effects/GrConfigConversionEffect.fp b/src/gpu/effects/GrConfigConversionEffect.fp
index 0ff5b2d..ae4c26c 100644
--- a/src/gpu/effects/GrConfigConversionEffect.fp
+++ b/src/gpu/effects/GrConfigConversionEffect.fp
@@ -7,10 +7,10 @@
@header {
#include "include/gpu/GrContext.h"
+ #include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrClip.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrImageInfo.h"
- #include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRenderTargetContext.h"
}
@@ -52,18 +52,16 @@
// draw
readRTC->discard();
- GrProxyProvider* proxyProvider = context->priv().proxyProvider();
-
- SkPixmap pixmap(ii, srcData, 4 * kSize);
-
// This function is only ever called if we are in a GrContext that has a GrGpu since we are
// calling read pixels here. Thus the pixel data will be uploaded immediately and we don't
// need to keep the pixel data alive in the proxy. Therefore the ReleaseProc is nullptr.
- sk_sp<SkImage> image = SkImage::MakeFromRaster(pixmap, nullptr, nullptr);
- sk_sp<GrTextureProxy> dataProxy = proxyProvider->createTextureProxy(std::move(image),
- 1,
- SkBudgeted::kYes,
- SkBackingFit::kExact);
+ SkBitmap bitmap;
+ bitmap.installPixels(ii, srcData, 4 * kSize);
+ bitmap.setImmutable();
+
+ GrBitmapTextureMaker maker(context, bitmap);
+ auto [dataProxy, ct] = maker.refTextureProxy(GrMipMapped::kNo);
+
if (!dataProxy) {
return false;
}
diff --git a/src/gpu/effects/GrRectBlurEffect.fp b/src/gpu/effects/GrRectBlurEffect.fp
index 8cf364b..34f7112 100644
--- a/src/gpu/effects/GrRectBlurEffect.fp
+++ b/src/gpu/effects/GrRectBlurEffect.fp
@@ -9,9 +9,13 @@
#include <cmath>
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
+#include "include/gpu/GrContext.h"
+#include "include/private/GrRecordingContext.h"
#include "src/core/SkBlurMask.h"
#include "src/core/SkMathPriv.h"
+#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrProxyProvider.h"
+#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrShaderCaps.h"
}
@@ -42,7 +46,7 @@
samplerParams
}
@class {
-static sk_sp<GrTextureProxy> CreateIntegralTexture(GrProxyProvider* proxyProvider,
+static sk_sp<GrTextureProxy> CreateIntegralTexture(GrRecordingContext* context,
float sixSigma) {
// The texture we're producing represents the integral of a normal distribution over a six-sigma
// range centered at zero. We want enough resolution so that the linear interpolation done in
@@ -58,6 +62,7 @@
builder[0] = width;
builder.finish();
+ GrProxyProvider* proxyProvider = context->priv().proxyProvider();
sk_sp<GrTextureProxy> proxy(proxyProvider->findOrCreateProxyByUniqueKey(
key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin));
if (!proxy) {
@@ -75,10 +80,9 @@
}
*bitmap.getAddr8(width - 1, 0) = 0;
bitmap.setImmutable();
- // We directly call the proxyProvider instead of going through GrBitmapTextureMaker. This
- // means we won't fall back to RGBA_8888. But we should have support for a single channel
- // unorm format so we shouldn't need the fallback.
- proxy = proxyProvider->createProxyFromBitmap(bitmap, GrMipMapped::kNo);
+
+ GrBitmapTextureMaker maker(context, bitmap);
+ std::tie(proxy, std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
if (!proxy) {
return nullptr;
}
@@ -90,7 +94,7 @@
}
@make {
- static std::unique_ptr<GrFragmentProcessor> Make(GrProxyProvider* proxyProvider,
+ static std::unique_ptr<GrFragmentProcessor> Make(GrRecordingContext* context,
const GrShaderCaps& caps,
const SkRect& rect, float sigma) {
SkASSERT(rect.isSorted());
@@ -105,7 +109,7 @@
}
const float sixSigma = 6 * sigma;
- auto integral = CreateIntegralTexture(proxyProvider, sixSigma);
+ auto integral = CreateIntegralTexture(context, sixSigma);
if (!integral) {
return nullptr;
}
@@ -203,6 +207,6 @@
float sigma = data->fRandom->nextRangeF(3,8);
float width = data->fRandom->nextRangeF(200,300);
float height = data->fRandom->nextRangeF(200,300);
- return GrRectBlurEffect::Make(data->proxyProvider(), *data->caps()->shaderCaps(),
+ return GrRectBlurEffect::Make(data->context(), *data->caps()->shaderCaps(),
SkRect::MakeWH(width, height), sigma);
}
diff --git a/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.cpp b/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.cpp
index 863e88f..a9e477c 100644
--- a/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.cpp
+++ b/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.cpp
@@ -10,7 +10,11 @@
**************************************************************************************************/
#include "GrCircleBlurFragmentProcessor.h"
+#include "include/gpu/GrContext.h"
+#include "include/private/GrRecordingContext.h"
+#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrProxyProvider.h"
+#include "src/gpu/GrRecordingContextPriv.h"
// Computes an unnormalized half kernel (right side). Returns the summation of all the half
// kernel values.
@@ -162,7 +166,7 @@
profile[profileWidth - 1] = 0;
}
-static sk_sp<GrTextureProxy> create_profile_texture(GrProxyProvider* proxyProvider,
+static sk_sp<GrTextureProxy> create_profile_texture(GrRecordingContext* context,
const SkRect& circle, float sigma,
float* solidRadius, float* textureRadius) {
float circleR = circle.width() / 2.0f;
@@ -203,6 +207,7 @@
builder[0] = sigmaToCircleRRatioFixed;
builder.finish();
+ GrProxyProvider* proxyProvider = context->priv().proxyProvider();
sk_sp<GrTextureProxy> blurProfile = proxyProvider->findOrCreateProxyByUniqueKey(
key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin);
if (!blurProfile) {
@@ -223,10 +228,9 @@
}
bm.setImmutable();
- sk_sp<SkImage> image = SkImage::MakeFromBitmap(bm);
- blurProfile = proxyProvider->createTextureProxy(std::move(image), 1, SkBudgeted::kYes,
- SkBackingFit::kExact);
+ GrBitmapTextureMaker maker(context, bm);
+ std::tie(blurProfile, std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
if (!blurProfile) {
return nullptr;
}
@@ -237,11 +241,11 @@
}
std::unique_ptr<GrFragmentProcessor> GrCircleBlurFragmentProcessor::Make(
- GrProxyProvider* proxyProvider, const SkRect& circle, float sigma) {
+ GrRecordingContext* context, const SkRect& circle, float sigma) {
float solidRadius;
float textureRadius;
sk_sp<GrTextureProxy> profile(
- create_profile_texture(proxyProvider, circle, sigma, &solidRadius, &textureRadius));
+ create_profile_texture(context, circle, sigma, &solidRadius, &textureRadius));
if (!profile) {
return nullptr;
}
@@ -346,6 +350,6 @@
SkScalar wh = testData->fRandom->nextRangeScalar(100.f, 1000.f);
SkScalar sigma = testData->fRandom->nextRangeF(1.f, 10.f);
SkRect circle = SkRect::MakeWH(wh, wh);
- return GrCircleBlurFragmentProcessor::Make(testData->proxyProvider(), circle, sigma);
+ return GrCircleBlurFragmentProcessor::Make(testData->context(), circle, sigma);
}
#endif
diff --git a/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.h b/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.h
index a18e756..a0e0396 100644
--- a/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.h
+++ b/src/gpu/effects/generated/GrCircleBlurFragmentProcessor.h
@@ -17,7 +17,7 @@
#include "src/gpu/GrFragmentProcessor.h"
class GrCircleBlurFragmentProcessor : public GrFragmentProcessor {
public:
- static std::unique_ptr<GrFragmentProcessor> Make(GrProxyProvider*, const SkRect& circle,
+ static std::unique_ptr<GrFragmentProcessor> Make(GrRecordingContext*, const SkRect& circle,
float sigma);
GrCircleBlurFragmentProcessor(const GrCircleBlurFragmentProcessor& src);
std::unique_ptr<GrFragmentProcessor> clone() const override;
diff --git a/src/gpu/effects/generated/GrConfigConversionEffect.h b/src/gpu/effects/generated/GrConfigConversionEffect.h
index e892712..51045bc 100644
--- a/src/gpu/effects/generated/GrConfigConversionEffect.h
+++ b/src/gpu/effects/generated/GrConfigConversionEffect.h
@@ -14,10 +14,10 @@
#include "include/private/SkM44.h"
#include "include/gpu/GrContext.h"
+#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrClip.h"
#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrImageInfo.h"
-#include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/GrCoordTransform.h"
@@ -61,16 +61,16 @@
// draw
readRTC->discard();
- GrProxyProvider* proxyProvider = context->priv().proxyProvider();
-
- SkPixmap pixmap(ii, srcData, 4 * kSize);
-
// This function is only ever called if we are in a GrContext that has a GrGpu since we are
// calling read pixels here. Thus the pixel data will be uploaded immediately and we don't
// need to keep the pixel data alive in the proxy. Therefore the ReleaseProc is nullptr.
- sk_sp<SkImage> image = SkImage::MakeFromRaster(pixmap, nullptr, nullptr);
- sk_sp<GrTextureProxy> dataProxy = proxyProvider->createTextureProxy(
- std::move(image), 1, SkBudgeted::kYes, SkBackingFit::kExact);
+ SkBitmap bitmap;
+ bitmap.installPixels(ii, srcData, 4 * kSize);
+ bitmap.setImmutable();
+
+ GrBitmapTextureMaker maker(context, bitmap);
+ auto[dataProxy, ct] = maker.refTextureProxy(GrMipMapped::kNo);
+
if (!dataProxy) {
return false;
}
diff --git a/src/gpu/effects/generated/GrRectBlurEffect.cpp b/src/gpu/effects/generated/GrRectBlurEffect.cpp
index 8ba9506..9cc89b7 100644
--- a/src/gpu/effects/generated/GrRectBlurEffect.cpp
+++ b/src/gpu/effects/generated/GrRectBlurEffect.cpp
@@ -188,7 +188,7 @@
float sigma = data->fRandom->nextRangeF(3, 8);
float width = data->fRandom->nextRangeF(200, 300);
float height = data->fRandom->nextRangeF(200, 300);
- return GrRectBlurEffect::Make(data->proxyProvider(), *data->caps()->shaderCaps(),
+ return GrRectBlurEffect::Make(data->context(), *data->caps()->shaderCaps(),
SkRect::MakeWH(width, height), sigma);
}
#endif
diff --git a/src/gpu/effects/generated/GrRectBlurEffect.h b/src/gpu/effects/generated/GrRectBlurEffect.h
index 9b680a0..4ed6526 100644
--- a/src/gpu/effects/generated/GrRectBlurEffect.h
+++ b/src/gpu/effects/generated/GrRectBlurEffect.h
@@ -16,16 +16,20 @@
#include <cmath>
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
+#include "include/gpu/GrContext.h"
+#include "include/private/GrRecordingContext.h"
#include "src/core/SkBlurMask.h"
#include "src/core/SkMathPriv.h"
+#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrProxyProvider.h"
+#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrShaderCaps.h"
#include "src/gpu/GrCoordTransform.h"
#include "src/gpu/GrFragmentProcessor.h"
class GrRectBlurEffect : public GrFragmentProcessor {
public:
- static sk_sp<GrTextureProxy> CreateIntegralTexture(GrProxyProvider* proxyProvider,
+ static sk_sp<GrTextureProxy> CreateIntegralTexture(GrRecordingContext* context,
float sixSigma) {
// The texture we're producing represents the integral of a normal distribution over a
// six-sigma range centered at zero. We want enough resolution so that the linear
@@ -41,6 +45,7 @@
builder[0] = width;
builder.finish();
+ GrProxyProvider* proxyProvider = context->priv().proxyProvider();
sk_sp<GrTextureProxy> proxy(proxyProvider->findOrCreateProxyByUniqueKey(
key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin));
if (!proxy) {
@@ -58,10 +63,9 @@
}
*bitmap.getAddr8(width - 1, 0) = 0;
bitmap.setImmutable();
- // We directly call the proxyProvider instead of going through GrBitmapTextureMaker.
- // This means we won't fall back to RGBA_8888. But we should have support for a single
- // channel unorm format so we shouldn't need the fallback.
- proxy = proxyProvider->createProxyFromBitmap(bitmap, GrMipMapped::kNo);
+
+ GrBitmapTextureMaker maker(context, bitmap);
+ std::tie(proxy, std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
if (!proxy) {
return nullptr;
}
@@ -71,7 +75,7 @@
return proxy;
}
- static std::unique_ptr<GrFragmentProcessor> Make(GrProxyProvider* proxyProvider,
+ static std::unique_ptr<GrFragmentProcessor> Make(GrRecordingContext* context,
const GrShaderCaps& caps, const SkRect& rect,
float sigma) {
SkASSERT(rect.isSorted());
@@ -86,7 +90,7 @@
}
const float sixSigma = 6 * sigma;
- auto integral = CreateIntegralTexture(proxyProvider, sixSigma);
+ auto integral = CreateIntegralTexture(context, sixSigma);
if (!integral) {
return nullptr;
}
diff --git a/src/gpu/gradients/GrGradientShader.cpp b/src/gpu/gradients/GrGradientShader.cpp
index a794652..cb0514e 100644
--- a/src/gpu/gradients/GrGradientShader.cpp
+++ b/src/gpu/gradients/GrGradientShader.cpp
@@ -59,8 +59,7 @@
SkASSERT(1 == bitmap.height() && SkIsPow2(bitmap.width()));
SkASSERT(bitmap.isImmutable());
- sk_sp<GrTextureProxy> proxy = GrMakeCachedBitmapProxy(
- args.fContext->priv().proxyProvider(), bitmap);
+ sk_sp<GrTextureProxy> proxy = GrMakeCachedBitmapProxy(args.fContext, bitmap);
if (proxy == nullptr) {
SkDebugf("Gradient won't draw. Could not create texture.");
return nullptr;
diff --git a/src/gpu/ops/GrShadowRRectOp.cpp b/src/gpu/ops/GrShadowRRectOp.cpp
index 1ae8b44..e9fab08 100644
--- a/src/gpu/ops/GrShadowRRectOp.cpp
+++ b/src/gpu/ops/GrShadowRRectOp.cpp
@@ -9,6 +9,7 @@
#include "include/private/GrRecordingContext.h"
#include "src/core/SkRRectPriv.h"
+#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrDrawOpTest.h"
#include "src/gpu/GrMemoryPool.h"
#include "src/gpu/GrOpFlushState.h"
@@ -637,12 +638,14 @@
namespace GrShadowRRectOp {
-static sk_sp<GrTextureProxy> create_falloff_texture(GrProxyProvider* proxyProvider) {
+static sk_sp<GrTextureProxy> create_falloff_texture(GrRecordingContext* context) {
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
GrUniqueKey key;
GrUniqueKey::Builder builder(&key, kDomain, 0, "Shadow Gaussian Falloff");
builder.finish();
+ GrProxyProvider* proxyProvider = context->priv().proxyProvider();
+
sk_sp<GrTextureProxy> falloffTexture = proxyProvider->findOrCreateProxyByUniqueKey(
key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin);
if (!falloffTexture) {
@@ -650,23 +653,19 @@
static const size_t kRowBytes = kWidth*GrColorTypeBytesPerPixel(GrColorType::kAlpha_8);
SkImageInfo ii = SkImageInfo::MakeA8(kWidth, 1);
- sk_sp<SkData> data = SkData::MakeUninitialized(kRowBytes);
- if (!data) {
- return nullptr;
- }
- unsigned char* values = (unsigned char*) data->writable_data();
+ SkBitmap bitmap;
+ bitmap.allocPixels(ii, kRowBytes);
+
+ unsigned char* values = (unsigned char*) bitmap.getPixels();
for (int i = 0; i < 128; ++i) {
SkScalar d = SK_Scalar1 - i/SkIntToScalar(127);
values[i] = SkScalarRoundToInt((SkScalarExp(-4*d*d) - 0.018f)*255);
}
+ bitmap.setImmutable();
- sk_sp<SkImage> img = SkImage::MakeRasterData(ii, std::move(data), kRowBytes);
- if (!img) {
- return nullptr;
- }
+ GrBitmapTextureMaker maker(context, bitmap);
+ std::tie(falloffTexture, std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
- falloffTexture = proxyProvider->createTextureProxy(std::move(img), 1, SkBudgeted::kYes,
- SkBackingFit::kExact);
if (!falloffTexture) {
return nullptr;
}
@@ -688,7 +687,7 @@
// Shadow rrect ops only handle simple circular rrects.
SkASSERT(viewMatrix.isSimilarity() && SkRRectPriv::EqualRadii(rrect));
- sk_sp<GrTextureProxy> falloffTexture = create_falloff_texture(context->priv().proxyProvider());
+ sk_sp<GrTextureProxy> falloffTexture = create_falloff_texture(context);
if (!falloffTexture) {
return nullptr;
}