From 6c70661f864198f82994adee4dda747ada32bbe9 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Mon, 7 Dec 2020 12:12:05 -0500 Subject: [PATCH] Pass GrMipMapped boolean down to GrResourceProvider::createTexture This is the portion of: https://skia-review.googlesource.com/c/skia/+/266916/ (Update two of GrResourceProvider's createTexture entry points) I still care about. Converting the boolean to an int and passing that down is dubious at best. Change-Id: I830cc3bfad36526bfa7884e21c9f376585d27f0b Reviewed-on: https://skia-review.googlesource.com/c/skia/+/341397 Reviewed-by: Greg Daniel Commit-Queue: Robert Phillips --- src/gpu/GrProxyProvider.cpp | 2 +- src/gpu/GrResourceProvider.cpp | 23 +++++++++++++---------- src/gpu/GrResourceProvider.h | 4 ++-- tests/TransferPixelsTest.cpp | 6 +++--- tools/fiddle/fiddle_main.cpp | 9 +++++---- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp index 28f2599883..3ff67281ac 100644 --- a/src/gpu/GrProxyProvider.cpp +++ b/src/gpu/GrProxyProvider.cpp @@ -375,7 +375,7 @@ sk_sp GrProxyProvider::createMippedProxyFromBitmap(const SkBitma } return LazyCallbackResult(resourceProvider->createTexture( desc.fDimensions, desc.fFormat, colorType, GrRenderable::kNo, 1, - desc.fBudgeted, GrProtected::kNo, texels.get(), mipLevelCount)); + desc.fBudgeted, GrMipMapped::kYes, GrProtected::kNo, texels.get())); }, format, dims, GrMipmapped::kYes, GrMipmapStatus::kValid, GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, budgeted, GrProtected::kNo, UseAllocator::kYes); diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp index f0513ecf86..abbc09f26c 100644 --- a/src/gpu/GrResourceProvider.cpp +++ b/src/gpu/GrResourceProvider.cpp @@ -12,6 +12,7 @@ #include "include/private/GrSingleOwner.h" #include "src/core/SkConvertPixels.h" #include "src/core/SkMathPriv.h" +#include "src/core/SkMipmap.h" #include "src/gpu/GrAttachment.h" #include "src/gpu/GrCaps.h" #include "src/gpu/GrDataUtils.h" @@ -47,37 +48,39 @@ sk_sp GrResourceProvider::createTexture(SkISize dimensions, GrRenderable renderable, int renderTargetSampleCnt, SkBudgeted budgeted, + GrMipMapped mipMapped, GrProtected isProtected, - const GrMipLevel texels[], - int mipLevelCount) { + const GrMipLevel texels[]) { ASSERT_SINGLE_OWNER - SkASSERT(mipLevelCount > 0); - if (this->isAbandoned()) { return nullptr; } - GrMipmapped mipMapped = mipLevelCount > 1 ? GrMipmapped::kYes : GrMipmapped::kNo; + int numMipLevels = 1; + if (mipMapped == GrMipMapped::kYes) { + numMipLevels = SkMipmap::ComputeLevelCount(dimensions.fWidth, dimensions.fHeight) + 1; + } + if (!fCaps->validateSurfaceParams(dimensions, format, renderable, renderTargetSampleCnt, mipMapped)) { return nullptr; } // Current rule is that you can provide no level data, just the base, or all the levels. - bool hasPixels = mipLevelCount && texels[0].fPixels; + bool hasPixels = texels[0].fPixels; auto scratch = this->getExactScratch(dimensions, format, renderable, renderTargetSampleCnt, budgeted, mipMapped, isProtected); if (scratch) { if (!hasPixels) { return scratch; } - return this->writePixels(std::move(scratch), colorType, dimensions, texels, mipLevelCount); + return this->writePixels(std::move(scratch), colorType, dimensions, texels, numMipLevels); } SkAutoSTMalloc<14, GrMipLevel> tmpTexels; SkAutoSTArray<14, std::unique_ptr> tmpDatas; GrColorType tempColorType = GrColorType::kUnknown; if (hasPixels) { - tempColorType = this->prepareLevels(format, colorType, dimensions, texels, mipLevelCount, + tempColorType = this->prepareLevels(format, colorType, dimensions, texels, numMipLevels, &tmpTexels, &tmpDatas); if (tempColorType == GrColorType::kUnknown) { return nullptr; @@ -85,7 +88,7 @@ sk_sp GrResourceProvider::createTexture(SkISize dimensions, } return fGpu->createTexture(dimensions, format, renderable, renderTargetSampleCnt, budgeted, isProtected, colorType, tempColorType, tmpTexels.get(), - mipLevelCount); + numMipLevels); } sk_sp GrResourceProvider::getExactScratch(SkISize dimensions, @@ -136,7 +139,7 @@ sk_sp GrResourceProvider::createTexture(SkISize dimensions, return this->writePixels(std::move(tex), colorType, dimensions, &mipLevel, 1); } else { return this->createTexture(dimensions, format, colorType, renderable, renderTargetSampleCnt, - budgeted, isProtected, &mipLevel, 1); + budgeted, GrMipMapped::kNo, isProtected, &mipLevel); } } diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h index 92b068f9a2..72acbc551b 100644 --- a/src/gpu/GrResourceProvider.h +++ b/src/gpu/GrResourceProvider.h @@ -86,9 +86,9 @@ public: GrRenderable renderable, int renderTargetSampleCnt, SkBudgeted budgeted, + GrMipMapped mipMapped, GrProtected isProtected, - const GrMipLevel texels[], - int mipLevelCount); + const GrMipLevel texels[]); /** * Create a potentially loose fit texture with the provided data. The color type must be valid diff --git a/tests/TransferPixelsTest.cpp b/tests/TransferPixelsTest.cpp index 4c369584e7..d6751d17bb 100644 --- a/tests/TransferPixelsTest.cpp +++ b/tests/TransferPixelsTest.cpp @@ -280,9 +280,9 @@ void basic_transfer_from_test(skiatest::Reporter* reporter, const sk_gpu_test::C GrMipLevel data; data.fPixels = textureData.get(); data.fRowBytes = textureDataRowBytes; - sk_sp tex = - resourceProvider->createTexture(kTexDims, format, colorType, renderable, 1, - SkBudgeted::kNo, GrProtected::kNo, &data, 1); + sk_sp tex = resourceProvider->createTexture(kTexDims, format, colorType, renderable, + 1, SkBudgeted::kNo, GrMipMapped::kNo, + GrProtected::kNo, &data); if (!tex) { return; } diff --git a/tools/fiddle/fiddle_main.cpp b/tools/fiddle/fiddle_main.cpp index 0c59132959..b2b02f77c4 100644 --- a/tools/fiddle/fiddle_main.cpp +++ b/tools/fiddle/fiddle_main.cpp @@ -170,7 +170,7 @@ static bool setup_backend_objects(GrDirectContext* context, backingTexture = resourceProvider->createTexture( bm.dimensions(), format, GrColorType::kRGBA_8888, GrRenderable::kNo, 1, - SkBudgeted::kNo, GrProtected::kNo, texels.get(), mipLevelCount); + SkBudgeted::kNo, options.fMipMapping, GrProtected::kNo, texels.get()); if (!backingTexture) { fputs("Failed to create backingTexture.\n", stderr); return false; @@ -195,7 +195,8 @@ static bool setup_backend_objects(GrDirectContext* context, sk_sp tmp = resourceProvider->createTexture( offscreenDims, renderableFormat, GrColorType::kRGBA_8888, GrRenderable::kYes, - options.fOffScreenSampleCount, SkBudgeted::kNo, GrProtected::kNo, &level0, 1); + options.fOffScreenSampleCount, SkBudgeted::kNo, GrMipMapped::kNo, + GrProtected::kNo, &level0); if (!tmp || !tmp->asRenderTarget()) { fputs("GrTexture is invalid.\n", stderr); return false; @@ -227,8 +228,8 @@ static bool setup_backend_objects(GrDirectContext* context, backingTextureRenderTarget = resourceProvider->createTexture( offscreenDims, renderableFormat, GrColorType::kRGBA_8888, GrRenderable::kYes, - options.fOffScreenSampleCount, SkBudgeted::kNo, GrProtected::kNo, texels.get(), - mipLevelCount); + options.fOffScreenSampleCount, SkBudgeted::kNo, options.fOffScreenMipMapping, + GrProtected::kNo, texels.get()); if (!backingTextureRenderTarget || !backingTextureRenderTarget->asRenderTarget()) { fputs("backingTextureRenderTarget is invalid.\n", stderr); return false;