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>
This commit is contained in:
Greg Daniel 2020-01-28 17:02:49 -05:00 committed by Skia Commit-Bot
parent 5e58f94d67
commit 6f5441a2f6
39 changed files with 410 additions and 461 deletions

View File

@ -18,6 +18,7 @@
#include "include/core/SkTileMode.h" #include "include/core/SkTileMode.h"
#include "include/core/SkTypes.h" #include "include/core/SkTypes.h"
#include "include/gpu/GrContext.h" #include "include/gpu/GrContext.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrCaps.h" #include "src/gpu/GrCaps.h"
#include "src/gpu/GrContextPriv.h" #include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrCoordTransform.h" #include "src/gpu/GrCoordTransform.h"
@ -81,8 +82,8 @@ DEF_SIMPLE_GPU_GM_BG(fpcoordinateoverride, ctx, rtCtx, canvas, 512, 512,
SkBitmap bmp; SkBitmap bmp;
GetResourceAsBitmap("images/mandrill_512_q075.jpg", &bmp); GetResourceAsBitmap("images/mandrill_512_q075.jpg", &bmp);
GrProxyProvider* proxyProvider = ctx->priv().proxyProvider(); GrBitmapTextureMaker maker(ctx, bmp);
sk_sp<GrTextureProxy> texture = proxyProvider->createProxyFromBitmap(bmp, GrMipMapped::kNo); auto [texture, grCT] = maker.refTextureProxy(GrMipMapped::kNo);
std::unique_ptr<GrFragmentProcessor> imgFP = std::unique_ptr<GrFragmentProcessor> imgFP =
GrTextureEffect::Make(texture, bmp.alphaType(), SkMatrix()); GrTextureEffect::Make(texture, bmp.alphaType(), SkMatrix());
auto fp = std::unique_ptr<GrFragmentProcessor>(new SampleCoordEffect(std::move(imgFP))); auto fp = std::unique_ptr<GrFragmentProcessor>(new SampleCoordEffect(std::move(imgFP)));

View File

@ -19,6 +19,7 @@
#include "include/effects/SkGradientShader.h" #include "include/effects/SkGradientShader.h"
#include "include/private/GrTypesPriv.h" #include "include/private/GrTypesPriv.h"
#include "include/private/SkTArray.h" #include "include/private/SkTArray.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrContextPriv.h" #include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRenderTargetContext.h" #include "src/gpu/GrRenderTargetContext.h"
@ -87,12 +88,11 @@ protected:
DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext, DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
SkCanvas* canvas, SkString* errorMsg) override { SkCanvas* canvas, SkString* errorMsg) override {
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
sk_sp<GrTextureProxy> proxy;
GrMipMapped mipMapped = fFilter == GrSamplerState::Filter::kMipMap && GrMipMapped mipMapped = fFilter == GrSamplerState::Filter::kMipMap &&
context->priv().caps()->mipMapSupport() context->priv().caps()->mipMapSupport()
? GrMipMapped::kYes : GrMipMapped::kNo; ? GrMipMapped::kYes : GrMipMapped::kNo;
proxy = proxyProvider->createProxyFromBitmap(fBitmap, mipMapped); GrBitmapTextureMaker maker(context, fBitmap);
auto [proxy, grCT] = maker.refTextureProxy(mipMapped);
if (!proxy) { if (!proxy) {
*errorMsg = "Failed to create proxy."; *errorMsg = "Failed to create proxy.";
return DrawResult::kFail; return DrawResult::kFail;
@ -114,7 +114,9 @@ protected:
for (size_t d = 0; d < SK_ARRAY_COUNT(texelDomains); ++d) { for (size_t d = 0; d < SK_ARRAY_COUNT(texelDomains); ++d) {
SkBitmap subset; SkBitmap subset;
fBitmap.extractSubset(&subset, texelDomains[d]); fBitmap.extractSubset(&subset, texelDomains[d]);
subsetProxies[d] = proxyProvider->createProxyFromBitmap(subset, mipMapped); subset.setImmutable();
GrBitmapTextureMaker maker(context, subset);
std::tie(subsetProxies[d], std::ignore) = maker.refTextureProxy(mipMapped);
} }
SkRect localRect = SkRect::Make(fBitmap.bounds()).makeOutset(kDrawPad, kDrawPad); SkRect localRect = SkRect::Make(fBitmap.bounds()).makeOutset(kDrawPad, kDrawPad);

View File

@ -23,11 +23,11 @@
#include "include/core/SkYUVAIndex.h" #include "include/core/SkYUVAIndex.h"
#include "include/gpu/GrContext.h" #include "include/gpu/GrContext.h"
#include "include/private/GrTypesPriv.h" #include "include/private/GrTypesPriv.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrClip.h" #include "src/gpu/GrClip.h"
#include "src/gpu/GrContextPriv.h" #include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrFragmentProcessor.h" #include "src/gpu/GrFragmentProcessor.h"
#include "src/gpu/GrPaint.h" #include "src/gpu/GrPaint.h"
#include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRenderTargetContext.h" #include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/GrRenderTargetContextPriv.h" #include "src/gpu/GrRenderTargetContextPriv.h"
#include "src/gpu/GrSamplerState.h" #include "src/gpu/GrSamplerState.h"
@ -67,41 +67,39 @@ protected:
} }
void onOnceBeforeDraw() override { void onOnceBeforeDraw() override {
SkBitmap bmp[3];
SkImageInfo yinfo = SkImageInfo::MakeA8(YSIZE, YSIZE); SkImageInfo yinfo = SkImageInfo::MakeA8(YSIZE, YSIZE);
bmp[0].allocPixels(yinfo); fBitmaps[0].allocPixels(yinfo);
SkImageInfo uinfo = SkImageInfo::MakeA8(USIZE, USIZE); SkImageInfo uinfo = SkImageInfo::MakeA8(USIZE, USIZE);
bmp[1].allocPixels(uinfo); fBitmaps[1].allocPixels(uinfo);
SkImageInfo vinfo = SkImageInfo::MakeA8(VSIZE, VSIZE); SkImageInfo vinfo = SkImageInfo::MakeA8(VSIZE, VSIZE);
bmp[2].allocPixels(vinfo); fBitmaps[2].allocPixels(vinfo);
unsigned char* pixels[3]; unsigned char* pixels[3];
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
pixels[i] = (unsigned char*)bmp[i].getPixels(); pixels[i] = (unsigned char*)fBitmaps[i].getPixels();
} }
int color[] = {0, 85, 170}; int color[] = {0, 85, 170};
const int limit[] = {255, 0, 255}; const int limit[] = {255, 0, 255};
const int invl[] = {0, 255, 0}; const int invl[] = {0, 255, 0};
const int inc[] = {1, -1, 1}; const int inc[] = {1, -1, 1};
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
const size_t nbBytes = bmp[i].rowBytes() * bmp[i].height(); const size_t nbBytes = fBitmaps[i].rowBytes() * fBitmaps[i].height();
for (size_t j = 0; j < nbBytes; ++j) { for (size_t j = 0; j < nbBytes; ++j) {
pixels[i][j] = (unsigned char)color[i]; pixels[i][j] = (unsigned char)color[i];
color[i] = (color[i] == limit[i]) ? invl[i] : color[i] + inc[i]; color[i] = (color[i] == limit[i]) ? invl[i] : color[i] + inc[i];
} }
} }
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
fImage[i] = SkImage::MakeFromBitmap(bmp[i]); fBitmaps[i].setImmutable();
} }
} }
DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext, DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
SkCanvas* canvas, SkString* errorMsg) override { SkCanvas* canvas, SkString* errorMsg) override {
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
sk_sp<GrTextureProxy> proxies[3]; sk_sp<GrTextureProxy> proxies[3];
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
proxies[i] = proxyProvider->createTextureProxy(fImage[i], 1, SkBudgeted::kYes, GrBitmapTextureMaker maker(context, fBitmaps[i]);
SkBackingFit::kExact); std::tie(proxies[i], std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
if (!proxies[i]) { if (!proxies[i]) {
*errorMsg = "Failed to create proxy"; *errorMsg = "Failed to create proxy";
return DrawResult::kFail; return DrawResult::kFail;
@ -109,8 +107,8 @@ protected:
} }
for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpace; ++space) { for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpace; ++space) {
SkRect renderRect = SkRect::MakeWH(SkIntToScalar(fImage[0]->width()), SkRect renderRect = SkRect::MakeWH(SkIntToScalar(fBitmaps[0].width()),
SkIntToScalar(fImage[0]->height())); SkIntToScalar(fBitmaps[0].height()));
renderRect.outset(kDrawPad, kDrawPad); renderRect.outset(kDrawPad, kDrawPad);
SkScalar y = kDrawPad + kTestPad + space * kColorSpaceOffset; SkScalar y = kDrawPad + kTestPad + space * kColorSpaceOffset;
@ -147,7 +145,7 @@ protected:
} }
private: private:
sk_sp<SkImage> fImage[3]; SkBitmap fBitmaps[3];
static constexpr SkScalar kDrawPad = 10.f; static constexpr SkScalar kDrawPad = 10.f;
static constexpr SkScalar kTestPad = 10.f; static constexpr SkScalar kTestPad = 10.f;
@ -177,19 +175,18 @@ protected:
} }
void onOnceBeforeDraw() override { void onOnceBeforeDraw() override {
SkBitmap bmp[2];
SkImageInfo yinfo = SkImageInfo::MakeA8(YSIZE, YSIZE); SkImageInfo yinfo = SkImageInfo::MakeA8(YSIZE, YSIZE);
bmp[0].allocPixels(yinfo); fBitmaps[0].allocPixels(yinfo);
SkImageInfo uvinfo = SkImageInfo::MakeN32Premul(USIZE, USIZE); SkImageInfo uvinfo = SkImageInfo::MakeN32Premul(USIZE, USIZE);
bmp[1].allocPixels(uvinfo); fBitmaps[1].allocPixels(uvinfo);
int color[] = {0, 85, 170}; int color[] = {0, 85, 170};
const int limit[] = {255, 0, 255}; const int limit[] = {255, 0, 255};
const int invl[] = {0, 255, 0}; const int invl[] = {0, 255, 0};
const int inc[] = {1, -1, 1}; const int inc[] = {1, -1, 1};
{ {
unsigned char* pixels = (unsigned char*)bmp[0].getPixels(); unsigned char* pixels = (unsigned char*)fBitmaps[0].getPixels();
const size_t nbBytes = bmp[0].rowBytes() * bmp[0].height(); const size_t nbBytes = fBitmaps[0].rowBytes() * fBitmaps[0].height();
for (size_t j = 0; j < nbBytes; ++j) { for (size_t j = 0; j < nbBytes; ++j) {
pixels[j] = (unsigned char)color[0]; pixels[j] = (unsigned char)color[0];
color[0] = (color[0] == limit[0]) ? invl[0] : color[0] + inc[0]; color[0] = (color[0] == limit[0]) ? invl[0] : color[0] + inc[0];
@ -197,9 +194,9 @@ protected:
} }
{ {
for (int y = 0; y < bmp[1].height(); ++y) { for (int y = 0; y < fBitmaps[1].height(); ++y) {
uint32_t* pixels = bmp[1].getAddr32(0, y); uint32_t* pixels = fBitmaps[1].getAddr32(0, y);
for (int j = 0; j < bmp[1].width(); ++j) { for (int j = 0; j < fBitmaps[1].width(); ++j) {
pixels[j] = SkColorSetARGB(0, color[1], color[2], 0); pixels[j] = SkColorSetARGB(0, color[1], color[2], 0);
color[1] = (color[1] == limit[1]) ? invl[1] : color[1] + inc[1]; color[1] = (color[1] == limit[1]) ? invl[1] : color[1] + inc[1];
color[2] = (color[2] == limit[2]) ? invl[2] : color[2] + inc[2]; color[2] = (color[2] == limit[2]) ? invl[2] : color[2] + inc[2];
@ -208,18 +205,17 @@ protected:
} }
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
fImage[i] = SkImage::MakeFromBitmap(bmp[i]); fBitmaps[i].setImmutable();
} }
} }
DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext, DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
SkCanvas* canvas, SkString* errorMsg) override { SkCanvas* canvas, SkString* errorMsg) override {
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
sk_sp<GrTextureProxy> proxies[2]; sk_sp<GrTextureProxy> proxies[2];
for (int i = 0; i < 2; ++i) { for (int i = 0; i < 2; ++i) {
proxies[i] = proxyProvider->createTextureProxy(fImage[i], 1, SkBudgeted::kYes, GrBitmapTextureMaker maker(context, fBitmaps[i]);
SkBackingFit::kExact); std::tie(proxies[i], std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
if (!proxies[i]) { if (!proxies[i]) {
*errorMsg = "Failed to create proxy"; *errorMsg = "Failed to create proxy";
return DrawResult::kFail; return DrawResult::kFail;
@ -234,8 +230,8 @@ protected:
}; };
for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpace; ++space) { for (int space = kJPEG_SkYUVColorSpace; space <= kLastEnum_SkYUVColorSpace; ++space) {
SkRect renderRect = SkRect::MakeWH(SkIntToScalar(fImage[0]->width()), SkRect renderRect = SkRect::MakeWH(SkIntToScalar(fBitmaps[0].width()),
SkIntToScalar(fImage[0]->height())); SkIntToScalar(fBitmaps[0].height()));
renderRect.outset(kDrawPad, kDrawPad); renderRect.outset(kDrawPad, kDrawPad);
SkScalar y = kDrawPad + kTestPad + space * kColorSpaceOffset; SkScalar y = kDrawPad + kTestPad + space * kColorSpaceOffset;
@ -260,7 +256,7 @@ protected:
} }
private: private:
sk_sp<SkImage> fImage[2]; SkBitmap fBitmaps[2];
static constexpr SkScalar kDrawPad = 10.f; static constexpr SkScalar kDrawPad = 10.f;
static constexpr SkScalar kTestPad = 10.f; static constexpr SkScalar kTestPad = 10.f;
@ -292,32 +288,30 @@ protected:
} }
void onOnceBeforeDraw() override { void onOnceBeforeDraw() override {
SkBitmap bmp[3];
SkImageInfo yinfo = SkImageInfo::MakeA8(YSIZE, YSIZE); SkImageInfo yinfo = SkImageInfo::MakeA8(YSIZE, YSIZE);
bmp[0].allocPixels(yinfo); fBitmaps[0].allocPixels(yinfo);
SkImageInfo uinfo = SkImageInfo::MakeA8(USIZE, USIZE); SkImageInfo uinfo = SkImageInfo::MakeA8(USIZE, USIZE);
bmp[1].allocPixels(uinfo); fBitmaps[1].allocPixels(uinfo);
SkImageInfo vinfo = SkImageInfo::MakeA8(VSIZE, VSIZE); SkImageInfo vinfo = SkImageInfo::MakeA8(VSIZE, VSIZE);
bmp[2].allocPixels(vinfo); fBitmaps[2].allocPixels(vinfo);
int innerColor[] = {149, 43, 21}; int innerColor[] = {149, 43, 21};
int outerColor[] = {128, 128, 128}; int outerColor[] = {128, 128, 128};
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
bmp[i].eraseColor(SkColorSetARGB(outerColor[i], 0, 0, 0)); fBitmaps[i].eraseColor(SkColorSetARGB(outerColor[i], 0, 0, 0));
SkIRect innerRect = i == 0 ? SkIRect::MakeLTRB(2, 2, 6, 6) : SkIRect::MakeLTRB(1, 1, 3, 3); SkIRect innerRect = i == 0 ? SkIRect::MakeLTRB(2, 2, 6, 6) : SkIRect::MakeLTRB(1, 1, 3, 3);
bmp[i].erase(SkColorSetARGB(innerColor[i], 0, 0, 0), innerRect); fBitmaps[i].erase(SkColorSetARGB(innerColor[i], 0, 0, 0), innerRect);
fImage[i] = SkImage::MakeFromBitmap(bmp[i]); fBitmaps[i].setImmutable();
} }
} }
DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext, DrawResult onDraw(GrContext* context, GrRenderTargetContext* renderTargetContext,
SkCanvas* canvas, SkString* errorMsg) override { SkCanvas* canvas, SkString* errorMsg) override {
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
sk_sp<GrTextureProxy> proxies[3]; sk_sp<GrTextureProxy> proxies[3];
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
proxies[i] = proxyProvider->createTextureProxy(fImage[i], 1, SkBudgeted::kYes, GrBitmapTextureMaker maker(context, fBitmaps[i]);
SkBackingFit::kExact); std::tie(proxies[i], std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
if (!proxies[i]) { if (!proxies[i]) {
*errorMsg = "Failed to create proxy"; *errorMsg = "Failed to create proxy";
return DrawResult::kFail; return DrawResult::kFail;
@ -374,7 +368,7 @@ protected:
} }
private: private:
sk_sp<SkImage> fImage[3]; SkBitmap fBitmaps[3];
static constexpr SkScalar kDrawPad = 10.f; static constexpr SkScalar kDrawPad = 10.f;
static constexpr SkScalar kTestPad = 10.f; static constexpr SkScalar kTestPad = 10.f;

View File

@ -57,6 +57,18 @@ void SkAutoPixmapStorage::alloc(const SkImageInfo& info) {
SkASSERT_RELEASE(this->tryAlloc(info)); SkASSERT_RELEASE(this->tryAlloc(info));
} }
void* SkAutoPixmapStorage::detachPixels() {
if (!fStorage) {
return nullptr;
}
void* data = fStorage;
fStorage = nullptr;
this->INHERITED::reset();
return data;
}
sk_sp<SkData> SkAutoPixmapStorage::detachPixelsAsData() { sk_sp<SkData> SkAutoPixmapStorage::detachPixelsAsData() {
if (!fStorage) { if (!fStorage) {
return nullptr; return nullptr;

View File

@ -47,6 +47,13 @@ public:
*/ */
static size_t AllocSize(const SkImageInfo& info, size_t* rowBytes); static size_t AllocSize(const SkImageInfo& info, size_t* rowBytes);
/**
* Returns a void* of the allocated pixel memory and resets the pixmap. If the storage hasn't
* been allocated, the result is NULL. The caller is responsible for calling sk_free to free
* the returned memory.
*/
void* SK_WARN_UNUSED_RESULT detachPixels();
/** /**
* Returns an SkData object wrapping the allocated pixels memory, and resets the pixmap. * Returns an SkData object wrapping the allocated pixels memory, and resets the pixmap.
* If the storage hasn't been allocated, the result is NULL. * If the storage hasn't been allocated, the result is NULL.

View File

@ -759,15 +759,14 @@ bool SkBlurMaskFilterImpl::directFilterMaskGPU(GrRecordingContext* context,
return false; return false;
} }
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
std::unique_ptr<GrFragmentProcessor> fp; std::unique_ptr<GrFragmentProcessor> fp;
if (devRRect.isRect() || SkRRectPriv::IsCircle(devRRect)) { if (devRRect.isRect() || SkRRectPriv::IsCircle(devRRect)) {
if (devRRect.isRect()) { if (devRRect.isRect()) {
fp = GrRectBlurEffect::Make(proxyProvider, *context->priv().caps()->shaderCaps(), fp = GrRectBlurEffect::Make(context, *context->priv().caps()->shaderCaps(),
devRRect.rect(), xformedSigma); devRRect.rect(), xformedSigma);
} else { } else {
fp = GrCircleBlurFragmentProcessor::Make(proxyProvider, devRRect.rect(), xformedSigma); fp = GrCircleBlurFragmentProcessor::Make(context, devRRect.rect(), xformedSigma);
} }
if (!fp) { if (!fp) {

View File

@ -97,7 +97,6 @@ sk_sp<SkSpecialImage> SkSpecialImage::makeTextureImage(GrRecordingContext* conte
return curContext->priv().matches(context) ? sk_ref_sp(this) : nullptr; return curContext->priv().matches(context) ? sk_ref_sp(this) : nullptr;
} }
auto proxyProvider = context->priv().proxyProvider();
SkBitmap bmp; SkBitmap bmp;
// At this point, we are definitely not texture-backed, so we must be raster or generator // At this point, we are definitely not texture-backed, so we must be raster or generator
// backed. If we remove the special-wrapping-an-image subclass, we may be able to assert that // backed. If we remove the special-wrapping-an-image subclass, we may be able to assert that
@ -113,7 +112,7 @@ sk_sp<SkSpecialImage> SkSpecialImage::makeTextureImage(GrRecordingContext* conte
// TODO: this is a tight copy of 'bmp' but it doesn't have to be (given SkSpecialImage's // 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. // semantics). Since this is cached though we would have to bake the fit into the cache key.
sk_sp<GrTextureProxy> proxy = GrMakeCachedBitmapProxy(proxyProvider, bmp); sk_sp<GrTextureProxy> proxy = GrMakeCachedBitmapProxy(context, bmp);
if (!proxy) { if (!proxy) {
return nullptr; return nullptr;
} }
@ -264,7 +263,7 @@ public:
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
sk_sp<GrTextureProxy> onAsTextureProxyRef(GrRecordingContext* context) const override { sk_sp<GrTextureProxy> onAsTextureProxyRef(GrRecordingContext* context) const override {
if (context) { if (context) {
return GrMakeCachedBitmapProxy(context->priv().proxyProvider(), fBitmap); return GrMakeCachedBitmapProxy(context, fBitmap);
} }
return nullptr; return nullptr;

View File

@ -341,13 +341,7 @@ std::unique_ptr<GrFragmentProcessor> ColorTableEffect::Make(GrRecordingContext*
SkASSERT(kPremul_SkAlphaType == bitmap.alphaType()); SkASSERT(kPremul_SkAlphaType == bitmap.alphaType());
SkASSERT(bitmap.isImmutable()); SkASSERT(bitmap.isImmutable());
sk_sp<SkImage> srcImage = SkImage::MakeFromBitmap(bitmap); sk_sp<GrTextureProxy> proxy = GrMakeCachedBitmapProxy(context, bitmap);
if (!srcImage) {
return nullptr;
}
sk_sp<GrTextureProxy> proxy = GrMakeCachedImageProxy(context->priv().proxyProvider(),
std::move(srcImage));
if (!proxy) { if (!proxy) {
return nullptr; return nullptr;
} }

View File

@ -27,10 +27,11 @@ static GrImageInfo get_image_info(GrRecordingContext* context, const SkBitmap& b
} }
GrBitmapTextureMaker::GrBitmapTextureMaker(GrRecordingContext* context, const SkBitmap& bitmap, 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) : INHERITED(context, get_image_info(context, bitmap), useDecal)
, fBitmap(bitmap) { , fBitmap(bitmap)
if (!bitmap.isVolatile() && shouldUseUniqueKey) { , fFit(fit) {
if (!bitmap.isVolatile() && cached == Cached::kYes) {
SkIPoint origin = bitmap.pixelRefOrigin(); SkIPoint origin = bitmap.pixelRefOrigin();
SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.width(), SkIRect subset = SkIRect::MakeXYWH(origin.fX, origin.fY, bitmap.width(),
bitmap.height()); bitmap.height());
@ -65,11 +66,11 @@ sk_sp<GrTextureProxy> GrBitmapTextureMaker::refOriginalTextureProxy(bool willBeM
return nullptr; return nullptr;
} }
copy8888.setImmutable(); copy8888.setImmutable();
proxy = proxyProvider->createProxyFromBitmap(copy8888, willBeMipped ? GrMipMapped::kYes proxy = proxyProvider->createProxyFromBitmap(
: GrMipMapped::kNo); copy8888, willBeMipped ? GrMipMapped::kYes : GrMipMapped::kNo, fFit);
} else { } else {
proxy = proxyProvider->createProxyFromBitmap(fBitmap, willBeMipped ? GrMipMapped::kYes proxy = proxyProvider->createProxyFromBitmap(
: GrMipMapped::kNo); fBitmap, willBeMipped ? GrMipMapped::kYes : GrMipMapped::kNo, fFit);
} }
if (proxy) { if (proxy) {
if (fOriginalKey.isValid()) { if (fOriginalKey.isValid()) {

View File

@ -16,8 +16,11 @@
subset of the pixelref specified by the bitmap. */ subset of the pixelref specified by the bitmap. */
class GrBitmapTextureMaker : public GrTextureMaker { class GrBitmapTextureMaker : public GrTextureMaker {
public: public:
enum class Cached { kNo, kYes };
GrBitmapTextureMaker(GrRecordingContext* context, const SkBitmap& bitmap, GrBitmapTextureMaker(GrRecordingContext* context, const SkBitmap& bitmap,
bool useDecal = false, bool shouldUseUniqueKey = true); Cached cached = Cached::kNo, SkBackingFit = SkBackingFit::kExact,
bool useDecal = false);
private: private:
sk_sp<GrTextureProxy> refOriginalTextureProxy(bool willBeMipped, sk_sp<GrTextureProxy> refOriginalTextureProxy(bool willBeMipped,
@ -26,8 +29,9 @@ private:
void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) override; void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) override;
void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override; void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override;
const SkBitmap fBitmap; const SkBitmap fBitmap;
GrUniqueKey fOriginalKey; const SkBackingFit fFit;
GrUniqueKey fOriginalKey;
typedef GrTextureMaker INHERITED; typedef GrTextureMaker INHERITED;
}; };

View File

@ -8,6 +8,7 @@
#include "src/gpu/GrBlurUtils.h" #include "src/gpu/GrBlurUtils.h"
#include "include/private/GrRecordingContext.h" #include "include/private/GrRecordingContext.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrCaps.h" #include "src/gpu/GrCaps.h"
#include "src/gpu/GrFixedClip.h" #include "src/gpu/GrFixedClip.h"
#include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrProxyProvider.h"
@ -145,13 +146,9 @@ static bool sw_draw_with_mask_filter(GrRecordingContext* context,
} }
bm.setImmutable(); bm.setImmutable();
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bm); GrBitmapTextureMaker maker(context, bm, GrBitmapTextureMaker::Cached::kNo,
if (!image) { SkBackingFit::kApprox);
return false; std::tie(filteredMask, std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
}
filteredMask = proxyProvider->createTextureProxy(std::move(image), 1, SkBudgeted::kYes,
SkBackingFit::kApprox);
if (!filteredMask) { if (!filteredMask) {
return false; return false;
} }

View File

@ -250,83 +250,11 @@ sk_sp<GrTextureProxy> GrProxyProvider::findOrCreateProxyByUniqueKey(const GrUniq
return result; 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, sk_sp<GrTextureProxy> GrProxyProvider::createProxyFromBitmap(const SkBitmap& bitmap,
GrMipMapped mipMapped) { GrMipMapped mipMapped,
SkBackingFit fit) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
SkASSERT(GrMipMapped::kNo == mipMapped || this->caps()->mipMapSupport()); SkASSERT(fit == SkBackingFit::kExact || mipMapped == GrMipMapped::kNo);
if (this->isAbandoned()) { if (this->isAbandoned()) {
return nullptr; return nullptr;
@ -343,56 +271,107 @@ sk_sp<GrTextureProxy> GrProxyProvider::createProxyFromBitmap(const SkBitmap& bit
// In non-ddl we will always instantiate right away. Thus we never want to copy the SkBitmap // 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 // 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. // upload of the data to the gpu can happen at anytime and the bitmap may change by then.
SkCopyPixelsMode copyMode = this->renderingDirectly() ? kNever_SkCopyPixelsMode SkBitmap copyBitmap = bitmap;
: kIfMutable_SkCopyPixelsMode; if (!this->renderingDirectly() && !bitmap.isImmutable()) {
sk_sp<SkImage> baseLevel = SkMakeImageFromRasterBitmap(bitmap, copyMode); copyBitmap.allocPixels();
if (!baseLevel) { if (!bitmap.readPixels(copyBitmap.pixmap())) {
return nullptr; return nullptr;
}
copyBitmap.setImmutable();
} }
// If mips weren't requested (or this was too small to have any), then take the fast path GrColorType grCT = SkColorTypeToGrColorType(copyBitmap.info().colorType());
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());
GrBackendFormat format = this->caps()->getDefaultBackendFormat(grCT, GrRenderable::kNo); GrBackendFormat format = this->caps()->getDefaultBackendFormat(grCT, GrRenderable::kNo);
if (!format.isValid()) { if (!format.isValid()) {
return nullptr; return nullptr;
} }
SkPixmap pixmap; sk_sp<GrTextureProxy> proxy;
SkAssertResult(baseLevel->peekPixels(&pixmap)); if (mipMapped == GrMipMapped::kNo ||
sk_sp<SkMipMap> mipmaps(SkMipMap::Build(pixmap, nullptr)); 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) { if (!mipmaps) {
return nullptr; return nullptr;
} }
GrSwizzle readSwizzle = this->caps()->getReadSwizzle(format, grCT); GrSwizzle readSwizzle = this->caps()->getReadSwizzle(format, colorType);
sk_sp<GrTextureProxy> proxy = this->createLazyProxy( sk_sp<GrTextureProxy> proxy = this->createLazyProxy(
[desc, format, baseLevel, mipmaps](GrResourceProvider* resourceProvider) { [desc, format, bitmap, mipmaps](GrResourceProvider* resourceProvider) {
const int mipLevelCount = mipmaps->countLevels() + 1; const int mipLevelCount = mipmaps->countLevels() + 1;
std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[mipLevelCount]); std::unique_ptr<GrMipLevel[]> texels(new GrMipLevel[mipLevelCount]);
SkPixmap pixmap; texels[0].fPixels = bitmap.getPixels();
SkAssertResult(baseLevel->peekPixels(&pixmap)); texels[0].fRowBytes = bitmap.rowBytes();
texels[0].fPixels = pixmap.addr(); auto colorType = SkColorTypeToGrColorType(bitmap.colorType());
texels[0].fRowBytes = pixmap.rowBytes();
auto colorType = SkColorTypeToGrColorType(pixmap.colorType());
for (int i = 1; i < mipLevelCount; ++i) { for (int i = 1; i < mipLevelCount; ++i) {
SkMipMap::Level generatedMipLevel; SkMipMap::Level generatedMipLevel;
mipmaps->getLevel(i - 1, &generatedMipLevel); mipmaps->getLevel(i - 1, &generatedMipLevel);
texels[i].fPixels = generatedMipLevel.fPixmap.addr(); texels[i].fPixels = generatedMipLevel.fPixmap.addr();
texels[i].fRowBytes = generatedMipLevel.fPixmap.rowBytes(); texels[i].fRowBytes = generatedMipLevel.fPixmap.rowBytes();
SkASSERT(texels[i].fPixels); SkASSERT(texels[i].fPixels);
SkASSERT(generatedMipLevel.fPixmap.colorType() == pixmap.colorType()); SkASSERT(generatedMipLevel.fPixmap.colorType() == bitmap.colorType());
} }
return LazyCallbackResult(resourceProvider->createTexture( return LazyCallbackResult(resourceProvider->createTexture(
desc, format, colorType, GrRenderable::kNo, 1, SkBudgeted::kYes, desc, format, colorType, GrRenderable::kNo, 1, SkBudgeted::kYes,
@ -406,15 +385,9 @@ sk_sp<GrTextureProxy> GrProxyProvider::createProxyFromBitmap(const SkBitmap& bit
return nullptr; return nullptr;
} }
GrContext* direct = fImageContext->priv().asDirectContext(); SkASSERT(proxy->width() == desc.fWidth);
if (direct) { SkASSERT(proxy->height() == desc.fHeight);
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; return proxy;
} }

View File

@ -63,19 +63,11 @@ public:
GrSurfaceOrigin, GrSurfaceOrigin,
UseAllocator = UseAllocator::kYes); 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. * 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. * Create a GrSurfaceProxy without any data.
@ -282,6 +274,20 @@ private:
bool isAbandoned() const; 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. // GrColorType is used to determine the proxy's texture swizzle.
sk_sp<GrTextureProxy> createWrapped(sk_sp<GrTexture> tex, GrColorType, GrSurfaceOrigin origin, sk_sp<GrTextureProxy> createWrapped(sk_sp<GrTexture> tex, GrColorType, GrSurfaceOrigin origin,
UseAllocator useAllocator); UseAllocator useAllocator);

View File

@ -8,6 +8,7 @@
#include "src/gpu/GrSWMaskHelper.h" #include "src/gpu/GrSWMaskHelper.h"
#include "include/private/GrRecordingContext.h" #include "include/private/GrRecordingContext.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrCaps.h" #include "src/gpu/GrCaps.h"
#include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRecordingContextPriv.h" #include "src/gpu/GrRecordingContextPriv.h"
@ -97,16 +98,13 @@ sk_sp<GrTextureProxy> GrSWMaskHelper::toTextureProxy(GrRecordingContext* context
SkImageInfo ii = SkImageInfo::MakeA8(fPixels->width(), fPixels->height()); SkImageInfo ii = SkImageInfo::MakeA8(fPixels->width(), fPixels->height());
size_t rowBytes = fPixels->rowBytes(); size_t rowBytes = fPixels->rowBytes();
sk_sp<SkData> data = fPixels->detachPixelsAsData(); SkBitmap bitmap;
if (!data) { SkAssertResult(bitmap.installPixels(ii, fPixels->detachPixels(), rowBytes,
return nullptr; [](void* addr, void* context) { sk_free(addr); },
} nullptr));
bitmap.setImmutable();
sk_sp<SkImage> img = SkImage::MakeRasterData(ii, std::move(data), rowBytes); GrBitmapTextureMaker maker(context, bitmap, GrBitmapTextureMaker::Cached::kNo, fit);
if (!img) { auto [texture, ct] = maker.refTextureProxy(GrMipMapped::kNo);
return nullptr; return texture;
}
return context->priv().proxyProvider()->createTextureProxy(std::move(img), 1, SkBudgeted::kYes,
fit);
} }

View File

@ -14,6 +14,7 @@
#include "src/core/SkCachedData.h" #include "src/core/SkCachedData.h"
#include "src/core/SkResourceCache.h" #include "src/core/SkResourceCache.h"
#include "src/core/SkYUVPlanesCache.h" #include "src/core/SkYUVPlanesCache.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrCaps.h" #include "src/gpu/GrCaps.h"
#include "src/gpu/GrClip.h" #include "src/gpu/GrClip.h"
#include "src/gpu/GrColorSpaceXform.h" #include "src/gpu/GrColorSpaceXform.h"
@ -97,7 +98,7 @@ sk_sp<SkCachedData> GrYUVProvider::getPlanes(SkYUVASizeInfo* size,
return data; return data;
} }
void GrYUVProvider::YUVGen_DataReleaseProc(const void*, void* data) { void GrYUVProvider::YUVGen_DataReleaseProc(void*, void* data) {
SkCachedData* cachedData = static_cast<SkCachedData*>(data); SkCachedData* cachedData = static_cast<SkCachedData*>(data);
SkASSERT(cachedData); SkASSERT(cachedData);
cachedData->unref(); cachedData->unref();
@ -137,21 +138,23 @@ sk_sp<GrTextureProxy> GrYUVProvider::refAsTextureProxy(GrRecordingContext* ctx,
? SkBackingFit::kExact : SkBackingFit::kApprox; ? SkBackingFit::kExact : SkBackingFit::kApprox;
SkImageInfo imageInfo = SkImageInfo::MakeA8(componentWidth, componentHeight); SkImageInfo imageInfo = SkImageInfo::MakeA8(componentWidth, componentHeight);
SkPixmap pixmap(imageInfo, planes[i], yuvSizeInfo.fWidthBytes[i]);
SkCachedData* dataStoragePtr = dataStorage.get(); SkCachedData* dataStoragePtr = dataStorage.get();
// We grab a ref to cached yuv data. When the SkImage we create below goes away it will call // We grab a ref to cached yuv data. When the SkBitmap we create below goes away it will
// the YUVGen_DataReleaseProc which will release this ref. // 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 // 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 // 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 // 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). // releasing this SkImage after uploads (by deleting the lambda after instantiation).
dataStoragePtr->ref(); dataStoragePtr->ref();
sk_sp<SkImage> yuvImage = SkImage::MakeFromRaster(pixmap, YUVGen_DataReleaseProc, SkBitmap bitmap;
dataStoragePtr); SkAssertResult(bitmap.installPixels(imageInfo, const_cast<void*>(planes[i]),
yuvSizeInfo.fWidthBytes[i],
YUVGen_DataReleaseProc, dataStoragePtr));
bitmap.setImmutable();
GrBitmapTextureMaker maker(ctx, bitmap, GrBitmapTextureMaker::Cached::kNo, fit);
std::tie(yuvTextureProxies[i], std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
auto proxyProvider = ctx->priv().proxyProvider();
yuvTextureProxies[i] =
proxyProvider->createTextureProxy(yuvImage, 1, SkBudgeted::kYes, fit);
if (!yuvTextureProxies[i]) { if (!yuvTextureProxies[i]) {
return nullptr; return nullptr;
} }

View File

@ -87,7 +87,7 @@ private:
// This is used as release callback for the YUV data that we capture in an SkImage when // 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 // uploading to a gpu. When the upload is complete and we release the SkImage this callback will
// release the underlying data. // release the underlying data.
static void YUVGen_DataReleaseProc(const void*, void* data); static void YUVGen_DataReleaseProc(void*, void* data);
}; };
#endif #endif

View File

@ -1183,15 +1183,14 @@ void SkGpuDevice::drawBitmapRect(const SkBitmap& bitmap,
return; return;
} }
} }
GrBitmapTextureMaker maker(fContext.get(), bitmap); GrBitmapTextureMaker maker(fContext.get(), bitmap, GrBitmapTextureMaker::Cached::kYes);
this->drawTextureProducer(&maker, src, dst, constraint, this->localToDevice(), paint, true); this->drawTextureProducer(&maker, src, dst, constraint, this->localToDevice(), paint, true);
} }
sk_sp<SkSpecialImage> SkGpuDevice::makeSpecial(const SkBitmap& bitmap) { 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 // 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. // 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(), sk_sp<GrTextureProxy> proxy = GrMakeCachedBitmapProxy(fContext.get(), bitmap);
bitmap);
if (!proxy) { if (!proxy) {
return nullptr; return nullptr;
} }
@ -1327,7 +1326,7 @@ void SkGpuDevice::drawImageNine(const SkImage* image,
GrImageTextureMaker maker(fContext.get(), image, SkImage::kAllow_CachingHint); GrImageTextureMaker maker(fContext.get(), image, SkImage::kAllow_CachingHint);
this->drawProducerLattice(&maker, std::move(iter), dst, paint); this->drawProducerLattice(&maker, std::move(iter), dst, paint);
} else if (as_IB(image)->getROPixels(&bm)) { } 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); this->drawProducerLattice(&maker, std::move(iter), dst, paint);
} }
} }
@ -1337,7 +1336,7 @@ void SkGpuDevice::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
const SkRect& dst, const SkPaint& paint) { const SkRect& dst, const SkPaint& paint) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
auto iter = std::make_unique<SkLatticeIter>(bitmap.width(), bitmap.height(), center, dst); 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); this->drawProducerLattice(&maker, std::move(iter), dst, paint);
} }
@ -1391,7 +1390,7 @@ void SkGpuDevice::drawImageLattice(const SkImage* image,
GrImageTextureMaker maker(fContext.get(), image, SkImage::kAllow_CachingHint); GrImageTextureMaker maker(fContext.get(), image, SkImage::kAllow_CachingHint);
this->drawProducerLattice(&maker, std::move(iter), dst, paint); this->drawProducerLattice(&maker, std::move(iter), dst, paint);
} else if (as_IB(image)->getROPixels(&bm)) { } 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); this->drawProducerLattice(&maker, std::move(iter), dst, paint);
} }
} }
@ -1402,7 +1401,7 @@ void SkGpuDevice::drawBitmapLattice(const SkBitmap& bitmap,
const SkPaint& paint) { const SkPaint& paint) {
ASSERT_SINGLE_OWNER ASSERT_SINGLE_OWNER
auto iter = std::make_unique<SkLatticeIter>(lattice, dst); 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); this->drawProducerLattice(&maker, std::move(iter), dst, paint);
} }

View File

@ -452,7 +452,8 @@ void SkGpuDevice::drawImageQuad(const SkImage* image, const SkRect* srcRect, con
return; return;
} }
if (as_IB(image)->getROPixels(&bm)) { 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, draw_texture_producer(fContext.get(), fRenderTargetContext.get(), this->clip(), ctm,
paint, &maker, src, dst, dstClip, srcToDst, aa, aaFlags, constraint, paint, &maker, src, dst, dstClip, srcToDst, aa, aaFlags, constraint,
attemptDrawTexture); attemptDrawTexture);

View File

@ -140,75 +140,19 @@ sk_sp<GrTextureProxy> GrRefCachedBitmapTextureProxy(GrRecordingContext* ctx,
const SkBitmap& bitmap, const SkBitmap& bitmap,
GrSamplerState params, GrSamplerState params,
SkScalar scaleAdjust[2]) { 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, const SkBitmap& bitmap,
SkBackingFit fit) { SkBackingFit fit) {
if (!bitmap.peekPixels(nullptr)) { if (!bitmap.peekPixels(nullptr)) {
return nullptr; return nullptr;
} }
// In non-ddl we will always instantiate right away. Thus we never want to copy the SkBitmap GrBitmapTextureMaker maker(context, bitmap, GrBitmapTextureMaker::Cached::kYes, fit);
// even if its mutable. In ddl, if the bitmap is mutable then we must make a copy since the auto [proxy, ct] = maker.refTextureProxy(GrMipMapped::kNo);
// 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());
}
}
}
return proxy; return proxy;
} }

View File

@ -185,19 +185,12 @@ sk_sp<GrTextureProxy> GrCopyBaseMipMapToTextureProxy(GrRecordingContext*,
GrColorType srcColorType); GrColorType srcColorType);
/* /*
* Create a texture proxy from the provided bitmap by wrapping it in an image and calling * Create a texture proxy from the provided bitmap and add it to the texture cache
* GrMakeCachedImageProxy. * 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); 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() * Our key includes the offset, width, and height so that bitmaps created by extractSubset()
* are unique. * are unique.

View File

@ -21,7 +21,7 @@ uniform half4 circleData;
} }
@make { @make {
static std::unique_ptr<GrFragmentProcessor> Make(GrProxyProvider*, static std::unique_ptr<GrFragmentProcessor> Make(GrRecordingContext*,
const SkRect& circle, float sigma); const SkRect& circle, float sigma);
} }
@ -31,7 +31,11 @@ uniform half4 circleData;
} }
@cpp { @cpp {
#include "include/gpu/GrContext.h"
#include "include/private/GrRecordingContext.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrProxyProvider.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 // Computes an unnormalized half kernel (right side). Returns the summation of all the half
// kernel values. // kernel values.
@ -184,7 +188,7 @@ uniform half4 circleData;
profile[profileWidth - 1] = 0; 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, const SkRect& circle,
float sigma, float sigma,
float* solidRadius, float* textureRadius) { float* solidRadius, float* textureRadius) {
@ -226,6 +230,7 @@ uniform half4 circleData;
builder[0] = sigmaToCircleRRatioFixed; builder[0] = sigmaToCircleRRatioFixed;
builder.finish(); builder.finish();
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
sk_sp<GrTextureProxy> blurProfile = proxyProvider->findOrCreateProxyByUniqueKey( sk_sp<GrTextureProxy> blurProfile = proxyProvider->findOrCreateProxyByUniqueKey(
key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin); key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin);
if (!blurProfile) { if (!blurProfile) {
@ -246,10 +251,9 @@ uniform half4 circleData;
} }
bm.setImmutable(); bm.setImmutable();
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bm);
blurProfile = proxyProvider->createTextureProxy(std::move(image), 1, GrBitmapTextureMaker maker(context, bm);
SkBudgeted::kYes, SkBackingFit::kExact); std::tie(blurProfile, std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
if (!blurProfile) { if (!blurProfile) {
return nullptr; return nullptr;
} }
@ -260,10 +264,10 @@ uniform half4 circleData;
} }
std::unique_ptr<GrFragmentProcessor> GrCircleBlurFragmentProcessor::Make( std::unique_ptr<GrFragmentProcessor> GrCircleBlurFragmentProcessor::Make(
GrProxyProvider* proxyProvider, const SkRect& circle, float sigma) { GrRecordingContext* context, const SkRect& circle, float sigma) {
float solidRadius; float solidRadius;
float textureRadius; float textureRadius;
sk_sp<GrTextureProxy> profile(create_profile_texture(proxyProvider, circle, sigma, sk_sp<GrTextureProxy> profile(create_profile_texture(context, circle, sigma,
&solidRadius, &textureRadius)); &solidRadius, &textureRadius));
if (!profile) { if (!profile) {
return nullptr; return nullptr;
@ -286,5 +290,5 @@ void main() {
SkScalar wh = testData->fRandom->nextRangeScalar(100.f, 1000.f); SkScalar wh = testData->fRandom->nextRangeScalar(100.f, 1000.f);
SkScalar sigma = testData->fRandom->nextRangeF(1.f,10.f); SkScalar sigma = testData->fRandom->nextRangeF(1.f,10.f);
SkRect circle = SkRect::MakeWH(wh, wh); SkRect circle = SkRect::MakeWH(wh, wh);
return GrCircleBlurFragmentProcessor::Make(testData->proxyProvider(), circle, sigma); return GrCircleBlurFragmentProcessor::Make(testData->context(), circle, sigma);
} }

View File

@ -7,10 +7,10 @@
@header { @header {
#include "include/gpu/GrContext.h" #include "include/gpu/GrContext.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrClip.h" #include "src/gpu/GrClip.h"
#include "src/gpu/GrContextPriv.h" #include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrImageInfo.h" #include "src/gpu/GrImageInfo.h"
#include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRenderTargetContext.h" #include "src/gpu/GrRenderTargetContext.h"
} }
@ -52,18 +52,16 @@
// draw // draw
readRTC->discard(); 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 // 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 // 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. // need to keep the pixel data alive in the proxy. Therefore the ReleaseProc is nullptr.
sk_sp<SkImage> image = SkImage::MakeFromRaster(pixmap, nullptr, nullptr); SkBitmap bitmap;
sk_sp<GrTextureProxy> dataProxy = proxyProvider->createTextureProxy(std::move(image), bitmap.installPixels(ii, srcData, 4 * kSize);
1, bitmap.setImmutable();
SkBudgeted::kYes,
SkBackingFit::kExact); GrBitmapTextureMaker maker(context, bitmap);
auto [dataProxy, ct] = maker.refTextureProxy(GrMipMapped::kNo);
if (!dataProxy) { if (!dataProxy) {
return false; return false;
} }

View File

@ -9,9 +9,13 @@
#include <cmath> #include <cmath>
#include "include/core/SkRect.h" #include "include/core/SkRect.h"
#include "include/core/SkScalar.h" #include "include/core/SkScalar.h"
#include "include/gpu/GrContext.h"
#include "include/private/GrRecordingContext.h"
#include "src/core/SkBlurMask.h" #include "src/core/SkBlurMask.h"
#include "src/core/SkMathPriv.h" #include "src/core/SkMathPriv.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrShaderCaps.h" #include "src/gpu/GrShaderCaps.h"
} }
@ -42,7 +46,7 @@ layout(key) in bool isFast;
samplerParams samplerParams
} }
@class { @class {
static sk_sp<GrTextureProxy> CreateIntegralTexture(GrProxyProvider* proxyProvider, static sk_sp<GrTextureProxy> CreateIntegralTexture(GrRecordingContext* context,
float sixSigma) { float sixSigma) {
// The texture we're producing represents the integral of a normal distribution over a six-sigma // 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 // range centered at zero. We want enough resolution so that the linear interpolation done in
@ -58,6 +62,7 @@ static sk_sp<GrTextureProxy> CreateIntegralTexture(GrProxyProvider* proxyProvide
builder[0] = width; builder[0] = width;
builder.finish(); builder.finish();
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
sk_sp<GrTextureProxy> proxy(proxyProvider->findOrCreateProxyByUniqueKey( sk_sp<GrTextureProxy> proxy(proxyProvider->findOrCreateProxyByUniqueKey(
key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin)); key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin));
if (!proxy) { if (!proxy) {
@ -75,10 +80,9 @@ static sk_sp<GrTextureProxy> CreateIntegralTexture(GrProxyProvider* proxyProvide
} }
*bitmap.getAddr8(width - 1, 0) = 0; *bitmap.getAddr8(width - 1, 0) = 0;
bitmap.setImmutable(); 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 GrBitmapTextureMaker maker(context, bitmap);
// unorm format so we shouldn't need the fallback. std::tie(proxy, std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
proxy = proxyProvider->createProxyFromBitmap(bitmap, GrMipMapped::kNo);
if (!proxy) { if (!proxy) {
return nullptr; return nullptr;
} }
@ -90,7 +94,7 @@ static sk_sp<GrTextureProxy> CreateIntegralTexture(GrProxyProvider* proxyProvide
} }
@make { @make {
static std::unique_ptr<GrFragmentProcessor> Make(GrProxyProvider* proxyProvider, static std::unique_ptr<GrFragmentProcessor> Make(GrRecordingContext* context,
const GrShaderCaps& caps, const GrShaderCaps& caps,
const SkRect& rect, float sigma) { const SkRect& rect, float sigma) {
SkASSERT(rect.isSorted()); SkASSERT(rect.isSorted());
@ -105,7 +109,7 @@ static sk_sp<GrTextureProxy> CreateIntegralTexture(GrProxyProvider* proxyProvide
} }
const float sixSigma = 6 * sigma; const float sixSigma = 6 * sigma;
auto integral = CreateIntegralTexture(proxyProvider, sixSigma); auto integral = CreateIntegralTexture(context, sixSigma);
if (!integral) { if (!integral) {
return nullptr; return nullptr;
} }
@ -203,6 +207,6 @@ void main() {
float sigma = data->fRandom->nextRangeF(3,8); float sigma = data->fRandom->nextRangeF(3,8);
float width = data->fRandom->nextRangeF(200,300); float width = data->fRandom->nextRangeF(200,300);
float height = 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); SkRect::MakeWH(width, height), sigma);
} }

View File

@ -10,7 +10,11 @@
**************************************************************************************************/ **************************************************************************************************/
#include "GrCircleBlurFragmentProcessor.h" #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/GrProxyProvider.h"
#include "src/gpu/GrRecordingContextPriv.h"
// Computes an unnormalized half kernel (right side). Returns the summation of all the half // Computes an unnormalized half kernel (right side). Returns the summation of all the half
// kernel values. // kernel values.
@ -162,7 +166,7 @@ static void create_half_plane_profile(uint8_t* profile, int profileWidth) {
profile[profileWidth - 1] = 0; 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, const SkRect& circle, float sigma,
float* solidRadius, float* textureRadius) { float* solidRadius, float* textureRadius) {
float circleR = circle.width() / 2.0f; float circleR = circle.width() / 2.0f;
@ -203,6 +207,7 @@ static sk_sp<GrTextureProxy> create_profile_texture(GrProxyProvider* proxyProvid
builder[0] = sigmaToCircleRRatioFixed; builder[0] = sigmaToCircleRRatioFixed;
builder.finish(); builder.finish();
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
sk_sp<GrTextureProxy> blurProfile = proxyProvider->findOrCreateProxyByUniqueKey( sk_sp<GrTextureProxy> blurProfile = proxyProvider->findOrCreateProxyByUniqueKey(
key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin); key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin);
if (!blurProfile) { if (!blurProfile) {
@ -223,10 +228,9 @@ static sk_sp<GrTextureProxy> create_profile_texture(GrProxyProvider* proxyProvid
} }
bm.setImmutable(); bm.setImmutable();
sk_sp<SkImage> image = SkImage::MakeFromBitmap(bm);
blurProfile = proxyProvider->createTextureProxy(std::move(image), 1, SkBudgeted::kYes, GrBitmapTextureMaker maker(context, bm);
SkBackingFit::kExact); std::tie(blurProfile, std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
if (!blurProfile) { if (!blurProfile) {
return nullptr; return nullptr;
} }
@ -237,11 +241,11 @@ static sk_sp<GrTextureProxy> create_profile_texture(GrProxyProvider* proxyProvid
} }
std::unique_ptr<GrFragmentProcessor> GrCircleBlurFragmentProcessor::Make( std::unique_ptr<GrFragmentProcessor> GrCircleBlurFragmentProcessor::Make(
GrProxyProvider* proxyProvider, const SkRect& circle, float sigma) { GrRecordingContext* context, const SkRect& circle, float sigma) {
float solidRadius; float solidRadius;
float textureRadius; float textureRadius;
sk_sp<GrTextureProxy> profile( sk_sp<GrTextureProxy> profile(
create_profile_texture(proxyProvider, circle, sigma, &solidRadius, &textureRadius)); create_profile_texture(context, circle, sigma, &solidRadius, &textureRadius));
if (!profile) { if (!profile) {
return nullptr; return nullptr;
} }
@ -346,6 +350,6 @@ std::unique_ptr<GrFragmentProcessor> GrCircleBlurFragmentProcessor::TestCreate(
SkScalar wh = testData->fRandom->nextRangeScalar(100.f, 1000.f); SkScalar wh = testData->fRandom->nextRangeScalar(100.f, 1000.f);
SkScalar sigma = testData->fRandom->nextRangeF(1.f, 10.f); SkScalar sigma = testData->fRandom->nextRangeF(1.f, 10.f);
SkRect circle = SkRect::MakeWH(wh, wh); SkRect circle = SkRect::MakeWH(wh, wh);
return GrCircleBlurFragmentProcessor::Make(testData->proxyProvider(), circle, sigma); return GrCircleBlurFragmentProcessor::Make(testData->context(), circle, sigma);
} }
#endif #endif

View File

@ -17,7 +17,7 @@
#include "src/gpu/GrFragmentProcessor.h" #include "src/gpu/GrFragmentProcessor.h"
class GrCircleBlurFragmentProcessor : public GrFragmentProcessor { class GrCircleBlurFragmentProcessor : public GrFragmentProcessor {
public: public:
static std::unique_ptr<GrFragmentProcessor> Make(GrProxyProvider*, const SkRect& circle, static std::unique_ptr<GrFragmentProcessor> Make(GrRecordingContext*, const SkRect& circle,
float sigma); float sigma);
GrCircleBlurFragmentProcessor(const GrCircleBlurFragmentProcessor& src); GrCircleBlurFragmentProcessor(const GrCircleBlurFragmentProcessor& src);
std::unique_ptr<GrFragmentProcessor> clone() const override; std::unique_ptr<GrFragmentProcessor> clone() const override;

View File

@ -14,10 +14,10 @@
#include "include/private/SkM44.h" #include "include/private/SkM44.h"
#include "include/gpu/GrContext.h" #include "include/gpu/GrContext.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrClip.h" #include "src/gpu/GrClip.h"
#include "src/gpu/GrContextPriv.h" #include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrImageInfo.h" #include "src/gpu/GrImageInfo.h"
#include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRenderTargetContext.h" #include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/GrCoordTransform.h" #include "src/gpu/GrCoordTransform.h"
@ -61,16 +61,16 @@ public:
// draw // draw
readRTC->discard(); 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 // 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 // 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. // need to keep the pixel data alive in the proxy. Therefore the ReleaseProc is nullptr.
sk_sp<SkImage> image = SkImage::MakeFromRaster(pixmap, nullptr, nullptr); SkBitmap bitmap;
sk_sp<GrTextureProxy> dataProxy = proxyProvider->createTextureProxy( bitmap.installPixels(ii, srcData, 4 * kSize);
std::move(image), 1, SkBudgeted::kYes, SkBackingFit::kExact); bitmap.setImmutable();
GrBitmapTextureMaker maker(context, bitmap);
auto[dataProxy, ct] = maker.refTextureProxy(GrMipMapped::kNo);
if (!dataProxy) { if (!dataProxy) {
return false; return false;
} }

View File

@ -188,7 +188,7 @@ std::unique_ptr<GrFragmentProcessor> GrRectBlurEffect::TestCreate(GrProcessorTes
float sigma = data->fRandom->nextRangeF(3, 8); float sigma = data->fRandom->nextRangeF(3, 8);
float width = data->fRandom->nextRangeF(200, 300); float width = data->fRandom->nextRangeF(200, 300);
float height = 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); SkRect::MakeWH(width, height), sigma);
} }
#endif #endif

View File

@ -16,16 +16,20 @@
#include <cmath> #include <cmath>
#include "include/core/SkRect.h" #include "include/core/SkRect.h"
#include "include/core/SkScalar.h" #include "include/core/SkScalar.h"
#include "include/gpu/GrContext.h"
#include "include/private/GrRecordingContext.h"
#include "src/core/SkBlurMask.h" #include "src/core/SkBlurMask.h"
#include "src/core/SkMathPriv.h" #include "src/core/SkMathPriv.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrShaderCaps.h" #include "src/gpu/GrShaderCaps.h"
#include "src/gpu/GrCoordTransform.h" #include "src/gpu/GrCoordTransform.h"
#include "src/gpu/GrFragmentProcessor.h" #include "src/gpu/GrFragmentProcessor.h"
class GrRectBlurEffect : public GrFragmentProcessor { class GrRectBlurEffect : public GrFragmentProcessor {
public: public:
static sk_sp<GrTextureProxy> CreateIntegralTexture(GrProxyProvider* proxyProvider, static sk_sp<GrTextureProxy> CreateIntegralTexture(GrRecordingContext* context,
float sixSigma) { float sixSigma) {
// The texture we're producing represents the integral of a normal distribution over a // 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 // six-sigma range centered at zero. We want enough resolution so that the linear
@ -41,6 +45,7 @@ public:
builder[0] = width; builder[0] = width;
builder.finish(); builder.finish();
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
sk_sp<GrTextureProxy> proxy(proxyProvider->findOrCreateProxyByUniqueKey( sk_sp<GrTextureProxy> proxy(proxyProvider->findOrCreateProxyByUniqueKey(
key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin)); key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin));
if (!proxy) { if (!proxy) {
@ -58,10 +63,9 @@ public:
} }
*bitmap.getAddr8(width - 1, 0) = 0; *bitmap.getAddr8(width - 1, 0) = 0;
bitmap.setImmutable(); 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 GrBitmapTextureMaker maker(context, bitmap);
// channel unorm format so we shouldn't need the fallback. std::tie(proxy, std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
proxy = proxyProvider->createProxyFromBitmap(bitmap, GrMipMapped::kNo);
if (!proxy) { if (!proxy) {
return nullptr; return nullptr;
} }
@ -71,7 +75,7 @@ public:
return proxy; return proxy;
} }
static std::unique_ptr<GrFragmentProcessor> Make(GrProxyProvider* proxyProvider, static std::unique_ptr<GrFragmentProcessor> Make(GrRecordingContext* context,
const GrShaderCaps& caps, const SkRect& rect, const GrShaderCaps& caps, const SkRect& rect,
float sigma) { float sigma) {
SkASSERT(rect.isSorted()); SkASSERT(rect.isSorted());
@ -86,7 +90,7 @@ public:
} }
const float sixSigma = 6 * sigma; const float sixSigma = 6 * sigma;
auto integral = CreateIntegralTexture(proxyProvider, sixSigma); auto integral = CreateIntegralTexture(context, sixSigma);
if (!integral) { if (!integral) {
return nullptr; return nullptr;
} }

View File

@ -59,8 +59,7 @@ static std::unique_ptr<GrFragmentProcessor> make_textured_colorizer(const SkPMCo
SkASSERT(1 == bitmap.height() && SkIsPow2(bitmap.width())); SkASSERT(1 == bitmap.height() && SkIsPow2(bitmap.width()));
SkASSERT(bitmap.isImmutable()); SkASSERT(bitmap.isImmutable());
sk_sp<GrTextureProxy> proxy = GrMakeCachedBitmapProxy( sk_sp<GrTextureProxy> proxy = GrMakeCachedBitmapProxy(args.fContext, bitmap);
args.fContext->priv().proxyProvider(), bitmap);
if (proxy == nullptr) { if (proxy == nullptr) {
SkDebugf("Gradient won't draw. Could not create texture."); SkDebugf("Gradient won't draw. Could not create texture.");
return nullptr; return nullptr;

View File

@ -9,6 +9,7 @@
#include "include/private/GrRecordingContext.h" #include "include/private/GrRecordingContext.h"
#include "src/core/SkRRectPriv.h" #include "src/core/SkRRectPriv.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrDrawOpTest.h" #include "src/gpu/GrDrawOpTest.h"
#include "src/gpu/GrMemoryPool.h" #include "src/gpu/GrMemoryPool.h"
#include "src/gpu/GrOpFlushState.h" #include "src/gpu/GrOpFlushState.h"
@ -637,12 +638,14 @@ private:
namespace GrShadowRRectOp { 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(); static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
GrUniqueKey key; GrUniqueKey key;
GrUniqueKey::Builder builder(&key, kDomain, 0, "Shadow Gaussian Falloff"); GrUniqueKey::Builder builder(&key, kDomain, 0, "Shadow Gaussian Falloff");
builder.finish(); builder.finish();
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
sk_sp<GrTextureProxy> falloffTexture = proxyProvider->findOrCreateProxyByUniqueKey( sk_sp<GrTextureProxy> falloffTexture = proxyProvider->findOrCreateProxyByUniqueKey(
key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin); key, GrColorType::kAlpha_8, kTopLeft_GrSurfaceOrigin);
if (!falloffTexture) { if (!falloffTexture) {
@ -650,23 +653,19 @@ static sk_sp<GrTextureProxy> create_falloff_texture(GrProxyProvider* proxyProvid
static const size_t kRowBytes = kWidth*GrColorTypeBytesPerPixel(GrColorType::kAlpha_8); static const size_t kRowBytes = kWidth*GrColorTypeBytesPerPixel(GrColorType::kAlpha_8);
SkImageInfo ii = SkImageInfo::MakeA8(kWidth, 1); SkImageInfo ii = SkImageInfo::MakeA8(kWidth, 1);
sk_sp<SkData> data = SkData::MakeUninitialized(kRowBytes); SkBitmap bitmap;
if (!data) { bitmap.allocPixels(ii, kRowBytes);
return nullptr;
} unsigned char* values = (unsigned char*) bitmap.getPixels();
unsigned char* values = (unsigned char*) data->writable_data();
for (int i = 0; i < 128; ++i) { for (int i = 0; i < 128; ++i) {
SkScalar d = SK_Scalar1 - i/SkIntToScalar(127); SkScalar d = SK_Scalar1 - i/SkIntToScalar(127);
values[i] = SkScalarRoundToInt((SkScalarExp(-4*d*d) - 0.018f)*255); values[i] = SkScalarRoundToInt((SkScalarExp(-4*d*d) - 0.018f)*255);
} }
bitmap.setImmutable();
sk_sp<SkImage> img = SkImage::MakeRasterData(ii, std::move(data), kRowBytes); GrBitmapTextureMaker maker(context, bitmap);
if (!img) { std::tie(falloffTexture, std::ignore) = maker.refTextureProxy(GrMipMapped::kNo);
return nullptr;
}
falloffTexture = proxyProvider->createTextureProxy(std::move(img), 1, SkBudgeted::kYes,
SkBackingFit::kExact);
if (!falloffTexture) { if (!falloffTexture) {
return nullptr; return nullptr;
} }
@ -688,7 +687,7 @@ std::unique_ptr<GrDrawOp> Make(GrRecordingContext* context,
// Shadow rrect ops only handle simple circular rrects. // Shadow rrect ops only handle simple circular rrects.
SkASSERT(viewMatrix.isSimilarity() && SkRRectPriv::EqualRadii(rrect)); 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) { if (!falloffTexture) {
return nullptr; return nullptr;
} }

View File

@ -453,7 +453,7 @@ sk_sp<SkImage> SkImage::makeTextureImage(GrContext* context, GrMipMapped mipMapp
} }
if (const SkBitmap* bmp = as_IB(this)->onPeekBitmap()) { if (const SkBitmap* bmp = as_IB(this)->onPeekBitmap()) {
GrBitmapTextureMaker maker(context, *bmp); GrBitmapTextureMaker maker(context, *bmp, GrBitmapTextureMaker::Cached::kYes);
return create_image_from_producer(context, &maker, this->uniqueID(), mipMapped); return create_image_from_producer(context, &maker, this->uniqueID(), mipMapped);
} }
return nullptr; return nullptr;
@ -556,7 +556,7 @@ sk_sp<SkImage> SkImage::MakeCrossContextFromPixmap(GrContext* context,
// Turn the pixmap into a GrTextureProxy // Turn the pixmap into a GrTextureProxy
SkBitmap bmp; SkBitmap bmp;
bmp.installPixels(*pixmap); bmp.installPixels(*pixmap);
GrBitmapTextureMaker bitmapMaker(context, bmp, false, false); GrBitmapTextureMaker bitmapMaker(context, bmp);
GrMipMapped mipMapped = buildMips ? GrMipMapped::kYes : GrMipMapped::kNo; GrMipMapped mipMapped = buildMips ? GrMipMapped::kYes : GrMipMapped::kNo;
auto [proxy, grCT] = bitmapMaker.refTextureProxy(mipMapped); auto [proxy, grCT] = bitmapMaker.refTextureProxy(mipMapped);
if (!proxy) { if (!proxy) {

View File

@ -296,7 +296,7 @@ sk_sp<SkImage> SkImage::MakeFromYUVAPixmaps(
// Turn the pixmap into a GrTextureProxy // Turn the pixmap into a GrTextureProxy
SkBitmap bmp; SkBitmap bmp;
bmp.installPixels(*pixmap); bmp.installPixels(*pixmap);
GrBitmapTextureMaker bitmapMaker(context, bmp, false, false); GrBitmapTextureMaker bitmapMaker(context, bmp);
GrMipMapped mipMapped = buildMips ? GrMipMapped::kYes : GrMipMapped::kNo; GrMipMapped mipMapped = buildMips ? GrMipMapped::kYes : GrMipMapped::kNo;
std::tie(tempTextureProxies[i], proxyColorTypes[i]) = std::tie(tempTextureProxies[i], proxyColorTypes[i]) =
bitmapMaker.refTextureProxy(mipMapped); bitmapMaker.refTextureProxy(mipMapped);

View File

@ -519,10 +519,9 @@ sk_sp<GrTextureProxy> SkImage_Lazy::lockTextureProxy(
// 4. Ask the generator to return RGB(A) data, which the GPU can convert // 4. Ask the generator to return RGB(A) data, which the GPU can convert
SkBitmap bitmap; SkBitmap bitmap;
if (!proxy && this->getROPixels(&bitmap, chint)) { if (!proxy && this->getROPixels(&bitmap, chint)) {
GrBitmapTextureMaker bitmapMaker(ctx, bitmap, false, false); GrBitmapTextureMaker bitmapMaker(ctx, bitmap);
GrColorType grCT; std::tie(proxy, std::ignore) = bitmapMaker.refTextureProxy(willBeMipped ? GrMipMapped::kYes
std::tie(proxy, grCT) = bitmapMaker.refTextureProxy(willBeMipped ? GrMipMapped::kYes : GrMipMapped::kNo);
: GrMipMapped::kNo);
if (proxy && (!willBeMipped || GrMipMapped::kYes == proxy->mipMapped())) { if (proxy && (!willBeMipped || GrMipMapped::kYes == proxy->mipMapped())) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kRGBA_LockTexturePath, SK_HISTOGRAM_ENUMERATION("LockTexturePath", kRGBA_LockTexturePath,
kLockTexturePathCount); kLockTexturePathCount);

View File

@ -115,17 +115,17 @@ public:
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
SkImageInfo info = SkImageInfo::MakeA8(kBlockSize, 1); SkImageInfo info = SkImageInfo::MakeA8(kBlockSize, 1);
SkPixmap permutationsPixmap(info, fLatticeSelector, info.minRowBytes()); fPermutationsBitmap.installPixels(info, fLatticeSelector, info.minRowBytes());
fPermutationsImage = SkImage::MakeFromRaster(permutationsPixmap, nullptr, nullptr); fPermutationsBitmap.setImmutable();
info = SkImageInfo::MakeN32Premul(kBlockSize, 4); info = SkImageInfo::MakeN32Premul(kBlockSize, 4);
SkPixmap noisePixmap(info, fNoise[0][0], info.minRowBytes()); fNoiseBitmap.installPixels(info, fNoise[0][0], info.minRowBytes());
fNoiseImage = SkImage::MakeFromRaster(noisePixmap, nullptr, nullptr); fNoiseBitmap.setImmutable();
info = SkImageInfo::MakeA8(256, 1); info = SkImageInfo::MakeA8(256, 1);
SkPixmap impPermutationsPixmap(info, improved_noise_permutations, info.minRowBytes()); fImprovedPermutationsBitmap.installPixels(info, improved_noise_permutations,
fImprovedPermutationsImage = SkImage::MakeFromRaster(impPermutationsPixmap, nullptr, info.minRowBytes());
nullptr); fImprovedPermutationsBitmap.setImmutable();
static uint8_t gradients[] = { 2, 2, 1, 0, static uint8_t gradients[] = { 2, 2, 1, 0,
0, 2, 1, 0, 0, 2, 1, 0,
@ -144,8 +144,8 @@ public:
0, 2, 1, 0, 0, 2, 1, 0,
1, 0, 0, 0 }; 1, 0, 0, 0 };
info = SkImageInfo::MakeN32Premul(16, 1); info = SkImageInfo::MakeN32Premul(16, 1);
SkPixmap gradPixmap(info, gradients, info.minRowBytes()); fGradientBitmap.installPixels(info, gradients, info.minRowBytes());
fGradientImage = SkImage::MakeFromRaster(gradPixmap, nullptr, nullptr); fGradientBitmap.setImmutable();
#endif #endif
} }
@ -155,10 +155,10 @@ public:
, fTileSize(that.fTileSize) , fTileSize(that.fTileSize)
, fBaseFrequency(that.fBaseFrequency) , fBaseFrequency(that.fBaseFrequency)
, fStitchDataInit(that.fStitchDataInit) , fStitchDataInit(that.fStitchDataInit)
, fPermutationsImage(that.fPermutationsImage) , fPermutationsBitmap(that.fPermutationsBitmap)
, fNoiseImage(that.fNoiseImage) , fNoiseBitmap(that.fNoiseBitmap)
, fImprovedPermutationsImage(that.fImprovedPermutationsImage) , fImprovedPermutationsBitmap(that.fImprovedPermutationsBitmap)
, fGradientImage(that.fGradientImage) { , fGradientBitmap(that.fGradientBitmap) {
memcpy(fLatticeSelector, that.fLatticeSelector, sizeof(fLatticeSelector)); memcpy(fLatticeSelector, that.fLatticeSelector, sizeof(fLatticeSelector));
memcpy(fNoise, that.fNoise, sizeof(fNoise)); memcpy(fNoise, that.fNoise, sizeof(fNoise));
memcpy(fGradient, that.fGradient, sizeof(fGradient)); memcpy(fGradient, that.fGradient, sizeof(fGradient));
@ -176,10 +176,10 @@ public:
private: private:
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
sk_sp<SkImage> fPermutationsImage; SkBitmap fPermutationsBitmap;
sk_sp<SkImage> fNoiseImage; SkBitmap fNoiseBitmap;
sk_sp<SkImage> fImprovedPermutationsImage; SkBitmap fImprovedPermutationsBitmap;
sk_sp<SkImage> fGradientImage; SkBitmap fGradientBitmap;
#endif #endif
inline int random() { inline int random() {
@ -304,15 +304,15 @@ public:
public: public:
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
const sk_sp<SkImage> getPermutationsImage() const { return fPermutationsImage; } const SkBitmap& getPermutationsBitmap() const { return fPermutationsBitmap; }
const sk_sp<SkImage> getNoiseImage() const { return fNoiseImage; } const SkBitmap& getNoiseBitmap() const { return fNoiseBitmap; }
const sk_sp<SkImage> getImprovedPermutationsImage() const { const SkBitmap& getImprovedPermutationsBitmap() const {
return fImprovedPermutationsImage; return fImprovedPermutationsBitmap;
} }
const sk_sp<SkImage> getGradientImage() const { return fGradientImage; } const SkBitmap& getGradientBitmap() const { return fGradientBitmap; }
#endif #endif
}; };
@ -1417,20 +1417,19 @@ std::unique_ptr<GrFragmentProcessor> SkPerlinNoiseShaderImpl::asFragmentProcesso
m.setTranslateX(-localMatrix->getTranslateX() + SK_Scalar1); m.setTranslateX(-localMatrix->getTranslateX() + SK_Scalar1);
m.setTranslateY(-localMatrix->getTranslateY() + SK_Scalar1); m.setTranslateY(-localMatrix->getTranslateY() + SK_Scalar1);
auto proxyProvider = args.fContext->priv().proxyProvider(); auto context = args.fContext;
if (fType == kImprovedNoise_Type) { if (fType == kImprovedNoise_Type) {
// Need to assert that the textures we'll create are power of 2 so a copy isn't needed. // Need to assert that the textures we'll create are power of 2 so a copy isn't needed.
// We also know that we will not be using mipmaps. If things things weren't true we should // We also know that we will not be using mipmaps. If things things weren't true we should
// go through GrBitmapTextureMaker to handle needed copies. // go through GrBitmapTextureMaker to handle needed copies.
const sk_sp<SkImage> permutationsImage = paintingData->getImprovedPermutationsImage(); const SkBitmap& permutationsBitmap = paintingData->getImprovedPermutationsBitmap();
SkASSERT(SkIsPow2(permutationsImage->width()) && SkIsPow2(permutationsImage->height())); SkASSERT(SkIsPow2(permutationsBitmap.width()) && SkIsPow2(permutationsBitmap.height()));
sk_sp<GrTextureProxy> permutationsTexture( sk_sp<GrTextureProxy> permutationsTexture(
GrMakeCachedImageProxy(proxyProvider, std::move(permutationsImage))); GrMakeCachedBitmapProxy(context, permutationsBitmap));
const sk_sp<SkImage> gradientImage = paintingData->getGradientImage(); const SkBitmap& gradientBitmap = paintingData->getGradientBitmap();
SkASSERT(SkIsPow2(gradientImage->width()) && SkIsPow2(gradientImage->height())); SkASSERT(SkIsPow2(gradientBitmap.width()) && SkIsPow2(gradientBitmap.height()));
sk_sp<GrTextureProxy> gradientTexture( sk_sp<GrTextureProxy> gradientTexture(GrMakeCachedBitmapProxy(context, gradientBitmap));
GrMakeCachedImageProxy(proxyProvider, std::move(gradientImage)));
return GrImprovedPerlinNoiseEffect::Make(fNumOctaves, fSeed, std::move(paintingData), return GrImprovedPerlinNoiseEffect::Make(fNumOctaves, fSeed, std::move(paintingData),
std::move(permutationsTexture), std::move(permutationsTexture),
std::move(gradientTexture), m); std::move(gradientTexture), m);
@ -1455,15 +1454,13 @@ std::unique_ptr<GrFragmentProcessor> SkPerlinNoiseShaderImpl::asFragmentProcesso
// Need to assert that the textures we'll create are power of 2 so that now copy is needed. We // Need to assert that the textures we'll create are power of 2 so that now copy is needed. We
// also know that we will not be using mipmaps. If things things weren't true we should go // also know that we will not be using mipmaps. If things things weren't true we should go
// through GrBitmapTextureMaker to handle needed copies. // through GrBitmapTextureMaker to handle needed copies.
const sk_sp<SkImage> permutationsImage = paintingData->getPermutationsImage(); const SkBitmap& permutationsBitmap = paintingData->getPermutationsBitmap();
SkASSERT(SkIsPow2(permutationsImage->width()) && SkIsPow2(permutationsImage->height())); SkASSERT(SkIsPow2(permutationsBitmap.width()) && SkIsPow2(permutationsBitmap.height()));
sk_sp<GrTextureProxy> permutationsProxy = GrMakeCachedImageProxy(proxyProvider, sk_sp<GrTextureProxy> permutationsProxy = GrMakeCachedBitmapProxy(context, permutationsBitmap);
std::move(permutationsImage));
const sk_sp<SkImage> noiseImage = paintingData->getNoiseImage(); const SkBitmap& noiseBitmap = paintingData->getNoiseBitmap();
SkASSERT(SkIsPow2(noiseImage->width()) && SkIsPow2(noiseImage->height())); SkASSERT(SkIsPow2(noiseBitmap.width()) && SkIsPow2(noiseBitmap.height()));
sk_sp<GrTextureProxy> noiseProxy = GrMakeCachedImageProxy(proxyProvider, sk_sp<GrTextureProxy> noiseProxy = GrMakeCachedBitmapProxy(context, noiseBitmap);
std::move(noiseImage));
if (permutationsProxy && noiseProxy) { if (permutationsProxy && noiseProxy) {
auto inner = GrPerlinNoise2Effect::Make(fType, auto inner = GrPerlinNoise2Effect::Make(fType,

View File

@ -11,6 +11,7 @@
#include "include/gpu/GrTexture.h" #include "include/gpu/GrTexture.h"
#include "src/core/SkAutoPixmapStorage.h" #include "src/core/SkAutoPixmapStorage.h"
#include "src/core/SkCompressedDataUtils.h" #include "src/core/SkCompressedDataUtils.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrClip.h" #include "src/gpu/GrClip.h"
#include "src/gpu/GrContextPriv.h" #include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrGpu.h" #include "src/gpu/GrGpu.h"
@ -420,10 +421,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) {
kSize * GrColorTypeBytesPerPixel(GrColorType::kRGBA_8888)); kSize * GrColorTypeBytesPerPixel(GrColorType::kRGBA_8888));
REPORTER_ASSERT(reporter, gpuWriteResult == (ioType == kRW_GrIOType)); REPORTER_ASSERT(reporter, gpuWriteResult == (ioType == kRW_GrIOType));
// Copies should not work with a read-only texture SkBitmap copySrcBitmap;
auto copySrc = copySrcBitmap.installPixels(write);
proxyProvider->createTextureProxy(SkImage::MakeFromRaster(write, nullptr, nullptr), copySrcBitmap.setImmutable();
1, SkBudgeted::kYes, SkBackingFit::kExact);
GrBitmapTextureMaker maker(context, copySrcBitmap);
auto [copySrc, grCT] = maker.refTextureProxy(GrMipMapped::kNo);
REPORTER_ASSERT(reporter, copySrc); REPORTER_ASSERT(reporter, copySrc);
auto copyResult = surfContext->testCopy(copySrc.get()); auto copyResult = surfContext->testCopy(copySrc.get());
REPORTER_ASSERT(reporter, copyResult == (ioType == kRW_GrIOType)); REPORTER_ASSERT(reporter, copyResult == (ioType == kRW_GrIOType));

View File

@ -29,6 +29,7 @@ static SkBitmap create_bm() {
SkBitmap bm; SkBitmap bm;
bm.allocPixels(ii); bm.allocPixels(ii);
bm.eraseColor(SK_ColorTRANSPARENT); bm.eraseColor(SK_ColorTRANSPARENT);
bm.setImmutable();
return bm; return bm;
} }
@ -199,22 +200,24 @@ DEF_TEST(ImageFilterCache_ImageBackedRaster, reporter) {
#include "include/gpu/GrContext.h" #include "include/gpu/GrContext.h"
#include "include/gpu/GrTexture.h" #include "include/gpu/GrTexture.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrContextPriv.h" #include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrResourceProvider.h" #include "src/gpu/GrResourceProvider.h"
#include "src/gpu/GrSurfaceProxyPriv.h" #include "src/gpu/GrSurfaceProxyPriv.h"
#include "src/gpu/GrTextureProxy.h" #include "src/gpu/GrTextureProxy.h"
static sk_sp<GrTextureProxy> create_proxy(GrProxyProvider* proxyProvider) { static sk_sp<GrTextureProxy> create_proxy(GrRecordingContext* context) {
SkBitmap srcBM = create_bm(); SkBitmap srcBM = create_bm();
sk_sp<SkImage> srcImage(SkImage::MakeFromBitmap(srcBM)); GrBitmapTextureMaker maker(context, srcBM);
return proxyProvider->createTextureProxy(srcImage, 1, SkBudgeted::kYes, SkBackingFit::kExact); auto [proxy, grCT] = maker.refTextureProxy(GrMipMapped::kNo);
return proxy;
} }
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ctxInfo) { DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext(); GrContext* context = ctxInfo.grContext();
sk_sp<GrTextureProxy> srcProxy(create_proxy(context->priv().proxyProvider())); sk_sp<GrTextureProxy> srcProxy(create_proxy(context));
if (!srcProxy) { if (!srcProxy) {
return; return;
} }
@ -255,7 +258,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ct
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_GPUBacked, reporter, ctxInfo) { DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_GPUBacked, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext(); GrContext* context = ctxInfo.grContext();
sk_sp<GrTextureProxy> srcProxy(create_proxy(context->priv().proxyProvider())); sk_sp<GrTextureProxy> srcProxy(create_proxy(context));
if (!srcProxy) { if (!srcProxy) {
return; return;
} }

View File

@ -9,6 +9,7 @@
#include "include/gpu/GrContext.h" #include "include/gpu/GrContext.h"
#include "include/gpu/GrGpuResource.h" #include "include/gpu/GrGpuResource.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrClip.h" #include "src/gpu/GrClip.h"
#include "src/gpu/GrContextPriv.h" #include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrImageInfo.h" #include "src/gpu/GrImageInfo.h"
@ -259,14 +260,14 @@ void render_fp(GrContext* context, GrRenderTargetContext* rtc, GrFragmentProcess
/** Initializes the two test texture proxies that are available to the FP test factories. */ /** Initializes the two test texture proxies that are available to the FP test factories. */
bool init_test_textures(GrResourceProvider* resourceProvider, bool init_test_textures(GrResourceProvider* resourceProvider,
GrProxyProvider* proxyProvider, GrRecordingContext* context,
SkRandom* random, SkRandom* random,
GrProcessorTestData::ProxyInfo proxies[2]) { GrProcessorTestData::ProxyInfo proxies[2]) {
static const int kTestTextureSize = 256; static const int kTestTextureSize = 256;
{ {
// Put premul data into the RGBA texture that the test FPs can optionally use. // Put premul data into the RGBA texture that the test FPs can optionally use.
std::unique_ptr<GrColor[]> rgbaData(new GrColor[kTestTextureSize * kTestTextureSize]); GrColor* rgbaData = new GrColor[kTestTextureSize * kTestTextureSize];
for (int y = 0; y < kTestTextureSize; ++y) { for (int y = 0; y < kTestTextureSize; ++y) {
for (int x = 0; x < kTestTextureSize; ++x) { for (int x = 0; x < kTestTextureSize; ++x) {
rgbaData[kTestTextureSize * y + x] = input_texel_color( rgbaData[kTestTextureSize * y + x] = input_texel_color(
@ -276,10 +277,12 @@ bool init_test_textures(GrResourceProvider* resourceProvider,
SkImageInfo ii = SkImageInfo::Make(kTestTextureSize, kTestTextureSize, SkImageInfo ii = SkImageInfo::Make(kTestTextureSize, kTestTextureSize,
kRGBA_8888_SkColorType, kPremul_SkAlphaType); kRGBA_8888_SkColorType, kPremul_SkAlphaType);
SkPixmap pixmap(ii, rgbaData.get(), ii.minRowBytes()); SkBitmap bitmap;
sk_sp<SkImage> img = SkImage::MakeRasterCopy(pixmap); bitmap.installPixels(ii, rgbaData, ii.minRowBytes(),
auto proxy = [](void* addr, void* context) { delete[] (GrColor*)addr; }, nullptr);
proxyProvider->createTextureProxy(img, 1, SkBudgeted::kYes, SkBackingFit::kExact); bitmap.setImmutable();
GrBitmapTextureMaker maker(context, bitmap);
auto [proxy, grCT] = maker.refTextureProxy(GrMipMapped::kNo);
if (!proxy || !proxy->instantiate(resourceProvider)) { if (!proxy || !proxy->instantiate(resourceProvider)) {
return false; return false;
} }
@ -288,7 +291,7 @@ bool init_test_textures(GrResourceProvider* resourceProvider,
{ {
// Put random values into the alpha texture that the test FPs can optionally use. // Put random values into the alpha texture that the test FPs can optionally use.
std::unique_ptr<uint8_t[]> alphaData(new uint8_t[kTestTextureSize * kTestTextureSize]); uint8_t* alphaData = new uint8_t[kTestTextureSize * kTestTextureSize];
for (int y = 0; y < kTestTextureSize; ++y) { for (int y = 0; y < kTestTextureSize; ++y) {
for (int x = 0; x < kTestTextureSize; ++x) { for (int x = 0; x < kTestTextureSize; ++x) {
alphaData[kTestTextureSize * y + x] = random->nextULessThan(256); alphaData[kTestTextureSize * y + x] = random->nextULessThan(256);
@ -297,10 +300,12 @@ bool init_test_textures(GrResourceProvider* resourceProvider,
SkImageInfo ii = SkImageInfo::Make(kTestTextureSize, kTestTextureSize, SkImageInfo ii = SkImageInfo::Make(kTestTextureSize, kTestTextureSize,
kAlpha_8_SkColorType, kPremul_SkAlphaType); kAlpha_8_SkColorType, kPremul_SkAlphaType);
SkPixmap pixmap(ii, alphaData.get(), ii.minRowBytes()); SkBitmap bitmap;
sk_sp<SkImage> img = SkImage::MakeRasterCopy(pixmap); bitmap.installPixels(ii, alphaData, ii.minRowBytes(),
auto proxy = [](void* addr, void* context) { delete[] (uint8_t*)addr; }, nullptr);
proxyProvider->createTextureProxy(img, 1, SkBudgeted::kYes, SkBackingFit::kExact); bitmap.setImmutable();
GrBitmapTextureMaker maker(context, bitmap);
auto [proxy, grCT] = maker.refTextureProxy(GrMipMapped::kNo);
if (!proxy || !proxy->instantiate(resourceProvider)) { if (!proxy || !proxy->instantiate(resourceProvider)) {
return false; return false;
} }
@ -312,19 +317,23 @@ bool init_test_textures(GrResourceProvider* resourceProvider,
// Creates a texture of premul colors used as the output of the fragment processor that precedes // Creates a texture of premul colors used as the output of the fragment processor that precedes
// the fragment processor under test. Color values are those provided by input_texel_color(). // the fragment processor under test. Color values are those provided by input_texel_color().
sk_sp<GrTextureProxy> make_input_texture(GrProxyProvider* proxyProvider, int width, int height, sk_sp<GrTextureProxy> make_input_texture(GrRecordingContext* context, int width, int height,
SkScalar delta) { SkScalar delta) {
std::unique_ptr<GrColor[]> data(new GrColor[width * height]); GrColor* data = new GrColor[width * height];
for (int y = 0; y < width; ++y) { for (int y = 0; y < width; ++y) {
for (int x = 0; x < height; ++x) { for (int x = 0; x < height; ++x) {
data.get()[width * y + x] = input_texel_color(x, y, delta); data[width * y + x] = input_texel_color(x, y, delta);
} }
} }
SkImageInfo ii = SkImageInfo::Make(width, height, kRGBA_8888_SkColorType, kPremul_SkAlphaType); SkImageInfo ii = SkImageInfo::Make(width, height, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
SkPixmap pixmap(ii, data.get(), ii.minRowBytes()); SkBitmap bitmap;
sk_sp<SkImage> img = SkImage::MakeRasterCopy(pixmap); bitmap.installPixels(ii, data, ii.minRowBytes(),
return proxyProvider->createTextureProxy(img, 1, SkBudgeted::kYes, SkBackingFit::kExact); [](void* addr, void* context) { delete[] (GrColor*)addr; }, nullptr);
bitmap.setImmutable();
GrBitmapTextureMaker maker(context, bitmap);
auto [proxy, grCT] = maker.refTextureProxy(GrMipMapped::kNo);
return proxy;
} }
// We tag logged data as unpremul to avoid conversion when encoding as PNG. The input texture // We tag logged data as unpremul to avoid conversion when encoding as PNG. The input texture
@ -473,7 +482,6 @@ bool legal_modulation(const GrColor in[3], const GrColor out[3]) {
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, reporter, ctxInfo) { DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext(); GrContext* context = ctxInfo.grContext();
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
auto resourceProvider = context->priv().resourceProvider(); auto resourceProvider = context->priv().resourceProvider();
using FPFactory = GrFragmentProcessorTestFactory; using FPFactory = GrFragmentProcessorTestFactory;
@ -493,7 +501,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, repor
{kRenderSize, kRenderSize}); {kRenderSize, kRenderSize});
GrProcessorTestData::ProxyInfo proxies[2]; GrProcessorTestData::ProxyInfo proxies[2];
if (!init_test_textures(resourceProvider, proxyProvider, &random, proxies)) { if (!init_test_textures(resourceProvider, context, &random, proxies)) {
ERRORF(reporter, "Could not create test textures"); ERRORF(reporter, "Could not create test textures");
return; return;
} }
@ -504,9 +512,9 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, repor
// difference between the frame outputs if the FP is properly following the modulation // difference between the frame outputs if the FP is properly following the modulation
// requirements of the coverage optimization. // requirements of the coverage optimization.
static constexpr SkScalar kInputDelta = 0.2f; static constexpr SkScalar kInputDelta = 0.2f;
auto inputTexture1 = make_input_texture(proxyProvider, kRenderSize, kRenderSize, 0.0f); auto inputTexture1 = make_input_texture(context, kRenderSize, kRenderSize, 0.0f);
auto inputTexture2 = make_input_texture(proxyProvider, kRenderSize, kRenderSize, kInputDelta); auto inputTexture2 = make_input_texture(context, kRenderSize, kRenderSize, kInputDelta);
auto inputTexture3 = make_input_texture(proxyProvider, kRenderSize, kRenderSize, 2*kInputDelta); auto inputTexture3 = make_input_texture(context, kRenderSize, kRenderSize, 2*kInputDelta);
// Encoded images are very verbose and this tests many potential images, so only export the // Encoded images are very verbose and this tests many potential images, so only export the
// first failure (subsequent failures have a reasonable chance of being related). // first failure (subsequent failures have a reasonable chance of being related).
@ -716,7 +724,6 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, repor
// progenitors. // progenitors.
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorCloneTest, reporter, ctxInfo) { DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorCloneTest, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext(); GrContext* context = ctxInfo.grContext();
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
auto resourceProvider = context->priv().resourceProvider(); auto resourceProvider = context->priv().resourceProvider();
SkRandom random; SkRandom random;
@ -728,13 +735,13 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(ProcessorCloneTest, reporter, ctxInfo) {
{kRenderSize, kRenderSize}); {kRenderSize, kRenderSize});
GrProcessorTestData::ProxyInfo proxies[2]; GrProcessorTestData::ProxyInfo proxies[2];
if (!init_test_textures(resourceProvider, proxyProvider, &random, proxies)) { if (!init_test_textures(resourceProvider, context, &random, proxies)) {
ERRORF(reporter, "Could not create test textures"); ERRORF(reporter, "Could not create test textures");
return; return;
} }
GrProcessorTestData testData(&random, context, 2, proxies); GrProcessorTestData testData(&random, context, 2, proxies);
auto inputTexture = make_input_texture(proxyProvider, kRenderSize, kRenderSize, 0.0f); auto inputTexture = make_input_texture(context, kRenderSize, kRenderSize, 0.0f);
std::unique_ptr<GrColor[]> readData1(new GrColor[kRenderSize * kRenderSize]); std::unique_ptr<GrColor[]> readData1(new GrColor[kRenderSize * kRenderSize]);
std::unique_ptr<GrColor[]> readData2(new GrColor[kRenderSize * kRenderSize]); std::unique_ptr<GrColor[]> readData2(new GrColor[kRenderSize * kRenderSize]);
// On failure we write out images, but just write the first failing set as the print is very // On failure we write out images, but just write the first failing set as the print is very

View File

@ -11,6 +11,7 @@
#include "include/core/SkSurface.h" #include "include/core/SkSurface.h"
#include "include/gpu/GrContext.h" #include "include/gpu/GrContext.h"
#include "include/private/SkTo.h" #include "include/private/SkTo.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrContextPriv.h" #include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrImageInfo.h" #include "src/gpu/GrImageInfo.h"
#include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrProxyProvider.h"
@ -47,7 +48,6 @@ static void validate_alpha_data(skiatest::Reporter* reporter, int w, int h, cons
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) { DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext(); GrContext* context = ctxInfo.grContext();
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
unsigned char alphaData[X_SIZE * Y_SIZE]; unsigned char alphaData[X_SIZE * Y_SIZE];
@ -62,13 +62,16 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
// We are initializing the texture with zeros here // We are initializing the texture with zeros here
memset(alphaData, 0, X_SIZE * Y_SIZE); memset(alphaData, 0, X_SIZE * Y_SIZE);
unsigned char alphaDataCopy[X_SIZE * Y_SIZE];
memcpy(alphaDataCopy, alphaData, X_SIZE * Y_SIZE);
const SkImageInfo ii = SkImageInfo::MakeA8(X_SIZE, Y_SIZE); const SkImageInfo ii = SkImageInfo::MakeA8(X_SIZE, Y_SIZE);
SkPixmap pixmap(ii, alphaData, ii.minRowBytes()); SkBitmap bitmap;
sk_sp<SkImage> alphaImg = SkImage::MakeRasterCopy(pixmap); bitmap.installPixels(ii, alphaDataCopy, ii.minRowBytes());
sk_sp<GrTextureProxy> proxy = proxyProvider->createTextureProxy( bitmap.setImmutable();
alphaImg, 1, SkBudgeted::kNo, SkBackingFit::kExact); GrBitmapTextureMaker maker(context, bitmap);
auto [proxy, grCT] = maker.refTextureProxy(GrMipMapped::kNo);
if (!proxy) { if (!proxy) {
ERRORF(reporter, "Could not create alpha texture."); ERRORF(reporter, "Could not create alpha texture.");
return; return;
@ -76,10 +79,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) {
SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin); SkASSERT(proxy->origin() == kTopLeft_GrSurfaceOrigin);
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(), GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(proxy->backendFormat(),
GrColorType::kAlpha_8); grCT);
GrSurfaceProxyView view(std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle); GrSurfaceProxyView view(std::move(proxy), kTopLeft_GrSurfaceOrigin, swizzle);
auto sContext = GrSurfaceContext::Make(context, std::move(view), GrColorType::kAlpha_8, auto sContext = GrSurfaceContext::Make(context, std::move(view), grCT, kPremul_SkAlphaType,
kPremul_SkAlphaType, nullptr); nullptr);
sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii)); sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii));

View File

@ -17,6 +17,7 @@
#include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrContext.h" #include "include/gpu/GrContext.h"
#include "src/gpu/GrBitmapTextureMaker.h"
#include "src/gpu/GrContextPriv.h" #include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrProxyProvider.h"
#include "src/gpu/GrSurfaceProxy.h" #include "src/gpu/GrSurfaceProxy.h"
@ -52,6 +53,7 @@ static SkBitmap create_bm() {
SkIntToScalar(kSmallerSize), SkIntToScalar(kSmallerSize)), SkIntToScalar(kSmallerSize), SkIntToScalar(kSmallerSize)),
p); p);
bm.setImmutable();
return bm; return bm;
} }
@ -195,7 +197,6 @@ static void test_texture_backed(skiatest::Reporter* reporter,
// Test out the SkSpecialImage::makeTextureImage entry point // Test out the SkSpecialImage::makeTextureImage entry point
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_MakeTexture, reporter, ctxInfo) { DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_MakeTexture, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext(); GrContext* context = ctxInfo.grContext();
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
SkBitmap bm = create_bm(); SkBitmap bm = create_bm();
const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
@ -222,9 +223,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_MakeTexture, reporter, ctxInfo)
{ {
// gpu // gpu
sk_sp<SkImage> rasterImage = SkImage::MakeFromBitmap(bm); GrBitmapTextureMaker maker(context, bm);
sk_sp<GrTextureProxy> proxy = proxyProvider->createTextureProxy( auto [proxy, grCT] = maker.refTextureProxy(GrMipMapped::kNo);
rasterImage, 1, SkBudgeted::kNo, SkBackingFit::kExact);
if (!proxy) { if (!proxy) {
return; return;
} }
@ -234,7 +234,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_MakeTexture, reporter, ctxInfo)
SkIRect::MakeWH(kFullSize, kFullSize), SkIRect::MakeWH(kFullSize, kFullSize),
kNeedNewImageUniqueID_SpecialImage, kNeedNewImageUniqueID_SpecialImage,
std::move(proxy), std::move(proxy),
GrColorType::kRGBA_8888, grCT,
nullptr)); nullptr));
{ {
@ -253,12 +253,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_MakeTexture, reporter, ctxInfo)
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, ctxInfo) { DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, ctxInfo) {
GrContext* context = ctxInfo.grContext(); GrContext* context = ctxInfo.grContext();
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
SkBitmap bm = create_bm(); SkBitmap bm = create_bm();
sk_sp<SkImage> rasterImage = SkImage::MakeFromBitmap(bm); GrBitmapTextureMaker maker(context, bm);
auto [proxy, grCT] = maker.refTextureProxy(GrMipMapped::kNo);
sk_sp<GrTextureProxy> proxy = proxyProvider->createTextureProxy(rasterImage, 1, SkBudgeted::kNo,
SkBackingFit::kExact);
if (!proxy) { if (!proxy) {
return; return;
} }
@ -268,7 +265,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, ctxInfo) {
SkIRect::MakeWH(kFullSize, kFullSize), SkIRect::MakeWH(kFullSize, kFullSize),
kNeedNewImageUniqueID_SpecialImage, kNeedNewImageUniqueID_SpecialImage,
proxy, proxy,
GrColorType::kRGBA_8888, grCT,
nullptr)); nullptr));
const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize); const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
@ -278,7 +275,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_Gpu, reporter, ctxInfo) {
context, subset, context, subset,
kNeedNewImageUniqueID_SpecialImage, kNeedNewImageUniqueID_SpecialImage,
std::move(proxy), std::move(proxy),
GrColorType::kRGBA_8888, grCT,
nullptr)); nullptr));
test_image(subSImg1, reporter, context, true); test_image(subSImg1, reporter, context, true);
} }