From 832c817bc8a9567aa379181e71e7c602d2480de8 Mon Sep 17 00:00:00 2001 From: Greg Daniel Date: Fri, 13 Aug 2021 14:06:38 -0400 Subject: [PATCH] Remove GrBackendFormat's textureType use from isFormatTexturable call. The goal of this change was to remove the use of GrBackendFormat::textureType() from GrCaps::isFormatTexturable call. Instead we will always pass in a GrTextureType into this call. To do this a lot of plumbing of GrTextureType was added to various call sites. However, this CL halts the plubming up at the proxy level where we get it from the GrBackendFormat still. Future CLs will continue removing these call sites and others that use GrBackendFormat::textureType(). Bug: skia:12342 Change-Id: Ic0f02b9c7f7402405623b8aa31aa32a9a7c22297 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/439277 Commit-Queue: Greg Daniel Reviewed-by: Brian Salomon --- gm/lazytiling.cpp | 13 ++- include/gpu/GrBackendSurface.h | 2 + src/gpu/GrBackendSurface.cpp | 49 +++++---- src/gpu/GrCaps.cpp | 10 +- src/gpu/GrCaps.h | 7 +- src/gpu/GrContextThreadSafeProxy.cpp | 4 +- src/gpu/GrDynamicAtlas.cpp | 10 +- src/gpu/GrGpu.cpp | 55 +++++++--- src/gpu/GrGpu.h | 3 + src/gpu/GrProxyProvider.cpp | 52 +++++++-- src/gpu/GrResourceProvider.cpp | 124 +++++++++++++++++----- src/gpu/GrResourceProvider.h | 6 ++ src/gpu/GrSurfaceProxy.cpp | 16 ++- src/gpu/d3d/GrD3DCaps.cpp | 2 +- src/gpu/d3d/GrD3DCaps.h | 2 +- src/gpu/d3d/GrD3DGpu.cpp | 2 +- src/gpu/dawn/GrDawnCaps.cpp | 2 +- src/gpu/dawn/GrDawnCaps.h | 2 +- src/gpu/gl/GrGLCaps.cpp | 4 +- src/gpu/gl/GrGLCaps.h | 2 +- src/gpu/mock/GrMockCaps.h | 2 +- src/gpu/mock/GrMockGpu.cpp | 4 +- src/gpu/mtl/GrMtlCaps.h | 2 +- src/gpu/mtl/GrMtlCaps.mm | 2 +- src/gpu/mtl/GrMtlGpu.mm | 6 +- src/gpu/vk/GrVkCaps.cpp | 2 +- src/gpu/vk/GrVkCaps.h | 2 +- src/image/SkSurface_Gpu.cpp | 2 +- tests/BackendAllocationTest.cpp | 7 +- tests/CompressedBackendAllocationTest.cpp | 2 +- tests/GrSurfaceTest.cpp | 24 ++--- tests/LazyProxyTest.cpp | 30 ++++-- tests/MtlCopySurfaceTest.mm | 5 +- tests/PromiseImageTest.cpp | 4 +- tests/ProxyTest.cpp | 16 +-- tests/ResourceAllocatorTest.cpp | 2 + tests/ResourceCacheTest.cpp | 10 +- tests/TextureBindingsResetTest.cpp | 4 +- tests/TransferPixelsTest.cpp | 9 +- tools/DDLPromiseImageHelper.cpp | 2 +- tools/DDLTileHelper.cpp | 7 +- tools/fiddle/fiddle_main.cpp | 5 +- 42 files changed, 355 insertions(+), 161 deletions(-) diff --git a/gm/lazytiling.cpp b/gm/lazytiling.cpp index 7c803f089b..57075c29fd 100644 --- a/gm/lazytiling.cpp +++ b/gm/lazytiling.cpp @@ -47,9 +47,16 @@ static GrSurfaceProxyView create_view(GrDirectContext* dContext, GrMipLevel mipLevel = {src.getPixels(), src.rowBytes(), nullptr}; auto colorType = SkColorTypeToGrColorType(src.colorType()); - return rp->createTexture(src.dimensions(), desc.fFormat, colorType, - desc.fRenderable, desc.fSampleCnt, desc.fBudgeted, - desc.fFit, desc.fProtected, mipLevel); + return rp->createTexture(src.dimensions(), + desc.fFormat, + desc.fFormat.textureType(), + colorType, + desc.fRenderable, + desc.fSampleCnt, + desc.fBudgeted, + desc.fFit, + desc.fProtected, + mipLevel); }, format, GrRenderable::kNo, 1, GrProtected::kNo, *dContext->priv().caps(), GrSurfaceProxy::UseAllocator::kYes); diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h index 34b1c61e11..793a54ee52 100644 --- a/include/gpu/GrBackendSurface.h +++ b/include/gpu/GrBackendSurface.h @@ -288,6 +288,7 @@ public: /** deprecated alias of hasMipmaps(). */ bool hasMipMaps() const { return this->hasMipmaps(); } GrBackendApi backend() const {return fBackend; } + GrTextureType textureType() const { return fTextureType; } // If the backend API is GL, copies a snapshot of the GrGLTextureInfo struct into the passed in // pointer and returns true. Otherwise returns false if the backend API is not GL. @@ -397,6 +398,7 @@ private: int fHeight; // 1)) , fBackend(GrBackendApi::kDawn) + , fTextureType(GrTextureType::k2D) , fDawnInfo(dawnInfo) {} #endif @@ -483,6 +484,13 @@ static GrVkImageInfo apply_default_usage_flags(const GrVkImageInfo& info, return info; } +static GrTextureType vk_image_info_to_texture_type(const GrVkImageInfo& info) { + if (info.fYcbcrConversionInfo.isValid() && info.fYcbcrConversionInfo.fExternalFormat != 0) { + return GrTextureType::kExternal; + } + return GrTextureType::k2D; +} + GrBackendTexture::GrBackendTexture(int width, int height, const GrVkImageInfo& vkInfo, @@ -492,6 +500,7 @@ GrBackendTexture::GrBackendTexture(int width, , fHeight(height) , fMipmapped(GrMipmapped(vkInfo.fLevelCount > 1)) , fBackend(GrBackendApi::kVulkan) + , fTextureType(vk_image_info_to_texture_type(vkInfo)) , fVkInfo(apply_default_usage_flags(vkInfo, kDefaultTexRTUsageFlags)) , fMutableState(std::move(mutableState)) {} #endif @@ -507,6 +516,7 @@ GrBackendTexture::GrBackendTexture(int width, , fHeight(height) , fMipmapped(mipmapped) , fBackend(GrBackendApi::kOpenGL) + , fTextureType(gl_target_to_gr_target(glInfo.fTarget)) , fGLInfo(glInfo, params.release()) {} sk_sp GrBackendTexture::getGLTextureParams() const { @@ -527,6 +537,7 @@ GrBackendTexture::GrBackendTexture(int width, , fHeight(height) , fMipmapped(mipmapped) , fBackend(GrBackendApi::kMetal) + , fTextureType(GrTextureType::k2D) , fMtlInfo(mtlInfo) {} #endif @@ -546,6 +557,7 @@ GrBackendTexture::GrBackendTexture(int width, , fHeight(height) , fMipmapped(GrMipmapped(d3dInfo.fLevelCount > 1)) , fBackend(GrBackendApi::kDirect3D) + , fTextureType(GrTextureType::k2D) , fD3DInfo(d3dInfo, state.release()) {} #endif @@ -569,6 +581,7 @@ GrBackendTexture::GrBackendTexture(int width, , fHeight(height) , fMipmapped(mipmapped) , fBackend(GrBackendApi::kMock) + , fTextureType(GrTextureType::k2D) , fMockInfo(mockInfo) {} GrBackendTexture::~GrBackendTexture() { diff --git a/src/gpu/GrCaps.cpp b/src/gpu/GrCaps.cpp index 47368bd8a9..5c64eb667c 100644 --- a/src/gpu/GrCaps.cpp +++ b/src/gpu/GrCaps.cpp @@ -309,9 +309,11 @@ bool GrCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src bool GrCaps::validateSurfaceParams(const SkISize& dimensions, const GrBackendFormat& format, GrRenderable renderable, int renderTargetSampleCnt, - GrMipmapped mipped) const { - if (!this->isFormatTexturable(format)) { - return false; + GrMipmapped mipped, GrTextureType textureType) const { + if (textureType != GrTextureType::kNone) { + if (!this->isFormatTexturable(format, textureType)) { + return false; + } } if (GrMipmapped::kYes == mipped && !this->mipmapSupport()) { @@ -386,7 +388,7 @@ GrBackendFormat GrCaps::getDefaultBackendFormat(GrColorType colorType, } auto format = this->onGetDefaultBackendFormat(colorType); - if (!this->isFormatTexturable(format)) { + if (!this->isFormatTexturable(format, GrTextureType::k2D)) { return {}; } if (!this->areColorTypeAndFormatCompatible(colorType, format)) { diff --git a/src/gpu/GrCaps.h b/src/gpu/GrCaps.h index 8baa8258fc..25404d6251 100644 --- a/src/gpu/GrCaps.h +++ b/src/gpu/GrCaps.h @@ -221,8 +221,9 @@ public: bool isFormatCompressed(const GrBackendFormat& format) const; - // Can a texture be made with the GrBackendFormat, and then be bound and sampled in a shader. - virtual bool isFormatTexturable(const GrBackendFormat&) const = 0; + // Can a texture be made with the GrBackendFormat and texture type, and then be bound and + // sampled in a shader. + virtual bool isFormatTexturable(const GrBackendFormat&, GrTextureType) const = 0; // Returns whether a texture of the given format can be copied to a texture of the same format. virtual bool isFormatCopyable(const GrBackendFormat&) const = 0; @@ -420,7 +421,7 @@ public: } bool validateSurfaceParams(const SkISize&, const GrBackendFormat&, GrRenderable renderable, - int renderTargetSampleCnt, GrMipmapped) const; + int renderTargetSampleCnt, GrMipmapped, GrTextureType) const; bool areColorTypeAndFormatCompatible(GrColorType grCT, const GrBackendFormat& format) const; diff --git a/src/gpu/GrContextThreadSafeProxy.cpp b/src/gpu/GrContextThreadSafeProxy.cpp index cbdcaa018d..573fa6ee3c 100644 --- a/src/gpu/GrContextThreadSafeProxy.cpp +++ b/src/gpu/GrContextThreadSafeProxy.cpp @@ -99,7 +99,7 @@ SkSurfaceCharacterization GrContextThreadSafeProxy::createCharacterization( return {}; } - if (isTextureable && !fCaps->isFormatTexturable(backendFormat)) { + if (isTextureable && !fCaps->isFormatTexturable(backendFormat, backendFormat.textureType())) { // Skia doesn't agree that this is textureable. return {}; } @@ -158,7 +158,7 @@ GrBackendFormat GrContextThreadSafeProxy::compressedBackendFormat(SkImage::Compr GrBackendFormat format = fCaps->getBackendFormatFromCompressionType(c); - SkASSERT(!format.isValid() || fCaps->isFormatTexturable(format)); + SkASSERT(!format.isValid() || fCaps->isFormatTexturable(format, GrTextureType::k2D)); return format; } diff --git a/src/gpu/GrDynamicAtlas.cpp b/src/gpu/GrDynamicAtlas.cpp index 7fe35a0509..b1e5bb1a59 100644 --- a/src/gpu/GrDynamicAtlas.cpp +++ b/src/gpu/GrDynamicAtlas.cpp @@ -94,8 +94,14 @@ void GrDynamicAtlas::reset(SkISize initialSize, const GrCaps& caps) { [this](GrResourceProvider* resourceProvider, const LazyAtlasDesc& desc) { if (!fBackingTexture) { fBackingTexture = resourceProvider->createTexture( - fTextureProxy->backingStoreDimensions(), desc.fFormat, desc.fRenderable, - desc.fSampleCnt, desc.fMipmapped, desc.fBudgeted, desc.fProtected); + fTextureProxy->backingStoreDimensions(), + desc.fFormat, + desc.fFormat.textureType(), + desc.fRenderable, + desc.fSampleCnt, + desc.fMipmapped, + desc.fBudgeted, + desc.fProtected); } return GrSurfaceProxy::LazyCallbackResult(fBackingTexture); }, diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index e8f33aecd4..023d510cb6 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -98,6 +98,7 @@ static bool validate_texel_levels(SkISize dimensions, GrColorType texelColorType sk_sp GrGpu::createTextureCommon(SkISize dimensions, const GrBackendFormat& format, + GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, SkBudgeted budgeted, @@ -110,8 +111,12 @@ sk_sp GrGpu::createTextureCommon(SkISize dimensions, } GrMipmapped mipMapped = mipLevelCount > 1 ? GrMipmapped::kYes : GrMipmapped::kNo; - if (!this->caps()->validateSurfaceParams(dimensions, format, renderable, renderTargetSampleCnt, - mipMapped)) { + if (!this->caps()->validateSurfaceParams(dimensions, + format, + renderable, + renderTargetSampleCnt, + mipMapped, + textureType)) { return nullptr; } @@ -147,6 +152,7 @@ sk_sp GrGpu::createTextureCommon(SkISize dimensions, sk_sp GrGpu::createTexture(SkISize dimensions, const GrBackendFormat& format, + GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, GrMipmapped mipMapped, @@ -159,8 +165,15 @@ sk_sp GrGpu::createTexture(SkISize dimensions, } uint32_t levelClearMask = this->caps()->shouldInitializeTextures() ? (1 << mipLevelCount) - 1 : 0; - auto tex = this->createTextureCommon(dimensions, format, renderable, renderTargetSampleCnt, - budgeted, isProtected, mipLevelCount, levelClearMask); + auto tex = this->createTextureCommon(dimensions, + format, + textureType, + renderable, + renderTargetSampleCnt, + budgeted, + isProtected, + mipLevelCount, + levelClearMask); if (tex && mipMapped == GrMipmapped::kYes && levelClearMask) { tex->markMipmapsClean(); } @@ -169,6 +182,7 @@ sk_sp GrGpu::createTexture(SkISize dimensions, sk_sp GrGpu::createTexture(SkISize dimensions, const GrBackendFormat& format, + GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, SkBudgeted budgeted, @@ -199,8 +213,15 @@ sk_sp GrGpu::createTexture(SkISize dimensions, } } - auto tex = this->createTextureCommon(dimensions, format, renderable, renderTargetSampleCnt, - budgeted, isProtected, texelLevelCount, levelClearMask); + auto tex = this->createTextureCommon(dimensions, + format, + textureType, + renderable, + renderTargetSampleCnt, + budgeted, + isProtected, + texelLevelCount, + levelClearMask); if (tex) { bool markMipLevelsClean = false; // Currently if level 0 does not have pixels then no other level may, as enforced by @@ -245,12 +266,16 @@ sk_sp GrGpu::createCompressedTexture(SkISize dimensions, if (!data) { return nullptr; } - if (!this->caps()->isFormatTexturable(format)) { - return nullptr; - } // TODO: expand CompressedDataIsCorrect to work here too SkImage::CompressionType compressionType = GrBackendFormatToCompressionType(format); + if (compressionType == SkImage::CompressionType::kNone) { + return nullptr; + } + + if (!this->caps()->isFormatTexturable(format, GrTextureType::k2D)) { + return nullptr; + } if (dataSize < SkCompressedDataSize(compressionType, dimensions, nullptr, mipMapped == GrMipmapped::kYes)) { @@ -270,7 +295,7 @@ sk_sp GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex, const GrCaps* caps = this->caps(); SkASSERT(caps); - if (!caps->isFormatTexturable(backendTex.getBackendFormat())) { + if (!caps->isFormatTexturable(backendTex.getBackendFormat(), backendTex.textureType())) { return nullptr; } if (backendTex.width() > caps->maxTextureSize() || @@ -289,7 +314,7 @@ sk_sp GrGpu::wrapCompressedBackendTexture(const GrBackendTexture& bac const GrCaps* caps = this->caps(); SkASSERT(caps); - if (!caps->isFormatTexturable(backendTex.getBackendFormat())) { + if (!caps->isFormatTexturable(backendTex.getBackendFormat(), backendTex.textureType())) { return nullptr; } if (backendTex.width() > caps->maxTextureSize() || @@ -311,7 +336,7 @@ sk_sp GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& bac const GrCaps* caps = this->caps(); - if (!caps->isFormatTexturable(backendTex.getBackendFormat()) || + if (!caps->isFormatTexturable(backendTex.getBackendFormat(), backendTex.textureType()) || !caps->isFormatRenderable(backendTex.getBackendFormat(), sampleCnt)) { return nullptr; } @@ -391,7 +416,8 @@ bool GrGpu::readPixels(GrSurface* surface, TRACE_EVENT0("skia.gpu", TRACE_FUNC); SkASSERT(surface); SkASSERT(!surface->framebufferOnly()); - SkASSERT(this->caps()->isFormatTexturable(surface->backendFormat())); + SkASSERT(this->caps()->areColorTypeAndFormatCompatible(surfaceColorType, + surface->backendFormat())); if (!SkIRect::MakeSize(surface->dimensions()).contains(rect)) { return false; @@ -523,7 +549,8 @@ bool GrGpu::transferPixelsFrom(GrSurface* surface, TRACE_EVENT0("skia.gpu", TRACE_FUNC); SkASSERT(surface); SkASSERT(transferBuffer); - SkASSERT(this->caps()->isFormatTexturable(surface->backendFormat())); + SkASSERT(this->caps()->areColorTypeAndFormatCompatible(surfaceColorType, + surface->backendFormat())); #ifdef SK_DEBUG auto supportedRead = this->caps()->supportedReadPixelsColorType( diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index e0f93aa5da..a6b330ed7a 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -130,6 +130,7 @@ public: */ sk_sp createTexture(SkISize dimensions, const GrBackendFormat& format, + GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, SkBudgeted budgeted, @@ -144,6 +145,7 @@ public: */ sk_sp createTexture(SkISize dimensions, const GrBackendFormat& format, + GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, GrMipmapped mipMapped, @@ -798,6 +800,7 @@ private: sk_sp createTextureCommon(SkISize, const GrBackendFormat&, + GrTextureType textureType, GrRenderable, int renderTargetSampleCnt, SkBudgeted, diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp index 8eb66f2c9a..a05e84ab43 100644 --- a/src/gpu/GrProxyProvider.cpp +++ b/src/gpu/GrProxyProvider.cpp @@ -142,11 +142,21 @@ sk_sp GrProxyProvider::testingOnly_createInstantiatedProxy( sk_sp tex; if (SkBackingFit::kApprox == fit) { - tex = resourceProvider->createApproxTexture(dimensions, format, renderable, - renderTargetSampleCnt, isProtected); + tex = resourceProvider->createApproxTexture(dimensions, + format, + format.textureType(), + renderable, + renderTargetSampleCnt, + isProtected); } else { - tex = resourceProvider->createTexture(dimensions, format, renderable, renderTargetSampleCnt, - GrMipmapped::kNo, budgeted, isProtected); + tex = resourceProvider->createTexture(dimensions, + format, + format.textureType(), + renderable, + renderTargetSampleCnt, + GrMipmapped::kNo, + budgeted, + isProtected); } if (!tex) { return nullptr; @@ -327,8 +337,16 @@ sk_sp GrProxyProvider::createNonMippedProxyFromBitmap(const SkBi GrMipLevel mipLevel = {bitmap.getPixels(), bitmap.rowBytes(), nullptr}; auto colorType = SkColorTypeToGrColorType(bitmap.colorType()); return LazyCallbackResult(resourceProvider->createTexture( - desc.fDimensions, desc.fFormat, colorType, desc.fRenderable, - desc.fSampleCnt, desc.fBudgeted, desc.fFit, desc.fProtected, mipLevel)); + desc.fDimensions, + desc.fFormat, + desc.fFormat.textureType(), + colorType, + desc.fRenderable, + desc.fSampleCnt, + desc.fBudgeted, + desc.fFit, + desc.fProtected, + mipLevel)); }, format, dims, GrMipmapped::kNo, GrMipmapStatus::kNotAllocated, GrInternalSurfaceFlags::kNone, fit, budgeted, GrProtected::kNo, UseAllocator::kYes); @@ -375,8 +393,16 @@ sk_sp GrProxyProvider::createMippedProxyFromBitmap(const SkBitma SkASSERT(generatedMipLevel.fPixmap.colorType() == bitmap.colorType()); } return LazyCallbackResult(resourceProvider->createTexture( - desc.fDimensions, desc.fFormat, colorType, GrRenderable::kNo, 1, - desc.fBudgeted, GrMipMapped::kYes, GrProtected::kNo, texels.get())); + desc.fDimensions, + desc.fFormat, + desc.fFormat.textureType(), + colorType, + GrRenderable::kNo, + 1, + desc.fBudgeted, + GrMipMapped::kYes, + GrProtected::kNo, + texels.get())); }, format, dims, GrMipmapped::kYes, GrMipmapStatus::kValid, GrInternalSurfaceFlags::kNone, SkBackingFit::kExact, budgeted, GrProtected::kNo, UseAllocator::kYes); @@ -420,8 +446,12 @@ sk_sp GrProxyProvider::createProxy(const GrBackendFormat& format } } - if (!caps->validateSurfaceParams(dimensions, format, renderable, renderTargetSampleCnt, - mipMapped)) { + if (!caps->validateSurfaceParams(dimensions, + format, + renderable, + renderTargetSampleCnt, + mipMapped, + GrTextureType::k2D)) { return nullptr; } GrMipmapStatus mipmapStatus = (GrMipmapped::kYes == mipMapped) @@ -454,7 +484,7 @@ sk_sp GrProxyProvider::createCompressedTextureProxy( GrBackendFormat format = this->caps()->getBackendFormatFromCompressionType(compressionType); - if (!this->caps()->isFormatTexturable(format)) { + if (!this->caps()->isFormatTexturable(format, GrTextureType::k2D)) { return nullptr; } diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp index bfd5a727e9..a85b5f1308 100644 --- a/src/gpu/GrResourceProvider.cpp +++ b/src/gpu/GrResourceProvider.cpp @@ -43,6 +43,7 @@ GrResourceProvider::GrResourceProvider(GrGpu* gpu, GrResourceCache* cache, GrSin sk_sp GrResourceProvider::createTexture(SkISize dimensions, const GrBackendFormat& format, + GrTextureType textureType, GrColorType colorType, GrRenderable renderable, int renderTargetSampleCnt, @@ -61,14 +62,24 @@ sk_sp GrResourceProvider::createTexture(SkISize dimensions, numMipLevels = SkMipmap::ComputeLevelCount(dimensions.fWidth, dimensions.fHeight) + 1; } - if (!fCaps->validateSurfaceParams(dimensions, format, renderable, renderTargetSampleCnt, - mipmapped)) { + if (!fCaps->validateSurfaceParams(dimensions, + format, + renderable, + renderTargetSampleCnt, + mipmapped, + textureType)) { return nullptr; } // Current rule is that you can provide no level data, just the base, or all the levels. bool hasPixels = texels[0].fPixels; - auto scratch = this->getExactScratch(dimensions, format, renderable, renderTargetSampleCnt, - budgeted, mipmapped, isProtected); + auto scratch = this->getExactScratch(dimensions, + format, + textureType, + renderable, + renderTargetSampleCnt, + budgeted, + mipmapped, + isProtected); if (scratch) { if (!hasPixels) { return scratch; @@ -85,20 +96,33 @@ sk_sp GrResourceProvider::createTexture(SkISize dimensions, return nullptr; } } - return fGpu->createTexture(dimensions, format, renderable, renderTargetSampleCnt, budgeted, - isProtected, colorType, tempColorType, tmpTexels.get(), + return fGpu->createTexture(dimensions, + format, + textureType, + renderable, + renderTargetSampleCnt, + budgeted, + isProtected, + colorType, + tempColorType, + tmpTexels.get(), numMipLevels); } sk_sp GrResourceProvider::getExactScratch(SkISize dimensions, const GrBackendFormat& format, + GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, SkBudgeted budgeted, GrMipmapped mipmapped, GrProtected isProtected) { - sk_sp tex(this->findAndRefScratchTexture(dimensions, format, renderable, - renderTargetSampleCnt, mipmapped, + sk_sp tex(this->findAndRefScratchTexture(dimensions, + format, + textureType, + renderable, + renderTargetSampleCnt, + mipmapped, isProtected)); if (tex && SkBudgeted::kNo == budgeted) { tex->resourcePriv().makeUnbudgeted(); @@ -109,6 +133,7 @@ sk_sp GrResourceProvider::getExactScratch(SkISize dimensions, sk_sp GrResourceProvider::createTexture(SkISize dimensions, const GrBackendFormat& format, + GrTextureType textureType, GrColorType colorType, GrRenderable renderable, int renderTargetSampleCnt, @@ -127,19 +152,27 @@ sk_sp GrResourceProvider::createTexture(SkISize dimensions, return nullptr; } if (!fCaps->validateSurfaceParams(dimensions, format, renderable, renderTargetSampleCnt, - GrMipmapped::kNo)) { + GrMipmapped::kNo, textureType)) { return nullptr; } - auto tex = this->createApproxTexture(dimensions, format, renderable, renderTargetSampleCnt, - isProtected); + auto tex = this->createApproxTexture(dimensions, format, textureType, renderable, + renderTargetSampleCnt, isProtected); if (!tex) { return nullptr; } return this->writePixels(std::move(tex), colorType, dimensions, &mipLevel, 1); } else { - return this->createTexture(dimensions, format, colorType, renderable, renderTargetSampleCnt, - budgeted, GrMipmapped::kNo, isProtected, &mipLevel); + return this->createTexture(dimensions, + format, + textureType, + colorType, + renderable, + renderTargetSampleCnt, + budgeted, + GrMipmapped::kNo, + isProtected, + &mipLevel); } } @@ -159,6 +192,7 @@ sk_sp GrResourceProvider::createCompressedTexture(SkISize dimensions, sk_sp GrResourceProvider::createTexture(SkISize dimensions, const GrBackendFormat& format, + GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, GrMipmapped mipmapped, @@ -170,7 +204,7 @@ sk_sp GrResourceProvider::createTexture(SkISize dimensions, } if (!fCaps->validateSurfaceParams(dimensions, format, renderable, renderTargetSampleCnt, - mipmapped)) { + mipmapped, textureType)) { return nullptr; } @@ -180,14 +214,26 @@ sk_sp GrResourceProvider::createTexture(SkISize dimensions, // TODO: Support GrMipmapped::kYes in scratch texture lookup here. sk_sp tex = - this->getExactScratch(dimensions, format, renderable, renderTargetSampleCnt, budgeted, - mipmapped, isProtected); + this->getExactScratch(dimensions, + format, + textureType, + renderable, + renderTargetSampleCnt, + budgeted, + mipmapped, + isProtected); if (tex) { return tex; } - return fGpu->createTexture(dimensions, format, renderable, renderTargetSampleCnt, mipmapped, - budgeted, isProtected); + return fGpu->createTexture(dimensions, + format, + textureType, + renderable, + renderTargetSampleCnt, + mipmapped, + budgeted, + isProtected); } // Map 'value' to a larger multiple of 2. Values <= 'kMagicTol' will pop up to @@ -221,6 +267,7 @@ SkISize GrResourceProvider::MakeApprox(SkISize dimensions) { sk_sp GrResourceProvider::createApproxTexture(SkISize dimensions, const GrBackendFormat& format, + GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, GrProtected isProtected) { @@ -235,20 +282,26 @@ sk_sp GrResourceProvider::createApproxTexture(SkISize dimensions, SkASSERT(!this->caps()->isFormatCompressed(format)); if (!fCaps->validateSurfaceParams(dimensions, format, renderable, renderTargetSampleCnt, - GrMipmapped::kNo)) { + GrMipmapped::kNo, textureType)) { return nullptr; } auto copyDimensions = MakeApprox(dimensions); - if (auto tex = this->findAndRefScratchTexture(copyDimensions, format, renderable, + if (auto tex = this->findAndRefScratchTexture(copyDimensions, format, textureType, renderable, renderTargetSampleCnt, GrMipmapped::kNo, isProtected)) { return tex; } - return fGpu->createTexture(copyDimensions, format, renderable, renderTargetSampleCnt, - GrMipmapped::kNo, SkBudgeted::kYes, isProtected); + return fGpu->createTexture(copyDimensions, + format, + textureType, + renderable, + renderTargetSampleCnt, + GrMipmapped::kNo, + SkBudgeted::kYes, + isProtected); } sk_sp GrResourceProvider::findAndRefScratchTexture(const GrScratchKey& key) { @@ -266,6 +319,7 @@ sk_sp GrResourceProvider::findAndRefScratchTexture(const GrScratchKey sk_sp GrResourceProvider::findAndRefScratchTexture(SkISize dimensions, const GrBackendFormat& format, + GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, GrMipmapped mipmapped, @@ -274,7 +328,7 @@ sk_sp GrResourceProvider::findAndRefScratchTexture(SkISize dimensions SkASSERT(!this->isAbandoned()); SkASSERT(!this->caps()->isFormatCompressed(format)); SkASSERT(fCaps->validateSurfaceParams(dimensions, format, renderable, renderTargetSampleCnt, - GrMipmapped::kNo)); + GrMipmapped::kNo, textureType)); // We could make initial clears work with scratch textures but it is a rare case so we just opt // to fall back to making a new texture. @@ -596,8 +650,12 @@ sk_sp GrResourceProvider::getDiscardableMSAAAttachment(SkISize dim return nullptr; } - if (!fCaps->validateSurfaceParams( - dimensions, format, GrRenderable::kYes, sampleCnt, GrMipmapped::kNo)) { + if (!fCaps->validateSurfaceParams(dimensions, + format, + GrRenderable::kYes, + sampleCnt, + GrMipmapped::kNo, + GrTextureType::kNone)) { return nullptr; } @@ -633,8 +691,12 @@ sk_sp GrResourceProvider::makeMSAAAttachment(SkISize dimensions, return nullptr; } - if (!fCaps->validateSurfaceParams(dimensions, format, GrRenderable::kYes, sampleCnt, - GrMipmapped::kNo)) { + if (!fCaps->validateSurfaceParams(dimensions, + format, + GrRenderable::kYes, + sampleCnt, + GrMipmapped::kNo, + GrTextureType::kNone)) { return nullptr; } @@ -653,8 +715,12 @@ sk_sp GrResourceProvider::refScratchMSAAAttachment(SkISize dimensi ASSERT_SINGLE_OWNER SkASSERT(!this->isAbandoned()); SkASSERT(!this->caps()->isFormatCompressed(format)); - SkASSERT(fCaps->validateSurfaceParams(dimensions, format, GrRenderable::kYes, sampleCnt, - GrMipmapped::kNo)); + SkASSERT(fCaps->validateSurfaceParams(dimensions, + format, + GrRenderable::kYes, + sampleCnt, + GrMipmapped::kNo, + GrTextureType::kNone)); GrScratchKey key; GrAttachment::ComputeScratchKey(*this->caps(), format, dimensions, diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h index c1f46fd92f..bde5ffa33d 100644 --- a/src/gpu/GrResourceProvider.h +++ b/src/gpu/GrResourceProvider.h @@ -62,6 +62,7 @@ public: */ sk_sp createApproxTexture(SkISize dimensions, const GrBackendFormat& format, + GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, GrProtected isProtected); @@ -69,6 +70,7 @@ public: /** Create an exact fit texture with no initial data to upload. */ sk_sp createTexture(SkISize dimensions, const GrBackendFormat& format, + GrTextureType textureType, GrRenderable renderable, int renderTargetSampleCnt, GrMipmapped mipMapped, @@ -82,6 +84,7 @@ public: */ sk_sp createTexture(SkISize dimensions, const GrBackendFormat& format, + GrTextureType textureType, GrColorType colorType, GrRenderable renderable, int renderTargetSampleCnt, @@ -97,6 +100,7 @@ public: */ sk_sp createTexture(SkISize dimensions, const GrBackendFormat&, + GrTextureType textureType, GrColorType srcColorType, GrRenderable, int renderTargetSampleCnt, @@ -112,6 +116,7 @@ public: sk_sp findAndRefScratchTexture(const GrScratchKey&); sk_sp findAndRefScratchTexture(SkISize dimensions, const GrBackendFormat&, + GrTextureType textureType, GrRenderable, int renderTargetSampleCnt, GrMipmapped, @@ -338,6 +343,7 @@ private: */ sk_sp getExactScratch(SkISize dimensions, const GrBackendFormat&, + GrTextureType, GrRenderable, int renderTargetSampleCnt, SkBudgeted, diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp index e4a3e774a2..44713fea99 100644 --- a/src/gpu/GrSurfaceProxy.cpp +++ b/src/gpu/GrSurfaceProxy.cpp @@ -112,11 +112,21 @@ sk_sp GrSurfaceProxy::createSurfaceImpl(GrResourceProvider* resourceP sk_sp surface; if (SkBackingFit::kApprox == fFit) { - surface = resourceProvider->createApproxTexture(fDimensions, fFormat, renderable, sampleCnt, + surface = resourceProvider->createApproxTexture(fDimensions, + fFormat, + fFormat.textureType(), + renderable, + sampleCnt, fIsProtected); } else { - surface = resourceProvider->createTexture(fDimensions, fFormat, renderable, sampleCnt, - mipMapped, fBudgeted, fIsProtected); + surface = resourceProvider->createTexture(fDimensions, + fFormat, + fFormat.textureType(), + renderable, + sampleCnt, + mipMapped, + fBudgeted, + fIsProtected); } if (!surface) { return nullptr; diff --git a/src/gpu/d3d/GrD3DCaps.cpp b/src/gpu/d3d/GrD3DCaps.cpp index 5398f2a7b6..fa814b1d92 100644 --- a/src/gpu/d3d/GrD3DCaps.cpp +++ b/src/gpu/d3d/GrD3DCaps.cpp @@ -783,7 +783,7 @@ bool GrD3DCaps::isFormatSRGB(const GrBackendFormat& format) const { } } -bool GrD3DCaps::isFormatTexturable(const GrBackendFormat& format) const { +bool GrD3DCaps::isFormatTexturable(const GrBackendFormat& format, GrTextureType) const { DXGI_FORMAT dxgiFormat; if (!format.asDxgiFormat(&dxgiFormat)) { return false; diff --git a/src/gpu/d3d/GrD3DCaps.h b/src/gpu/d3d/GrD3DCaps.h index 879bb2edad..efa68b7a6b 100644 --- a/src/gpu/d3d/GrD3DCaps.h +++ b/src/gpu/d3d/GrD3DCaps.h @@ -28,7 +28,7 @@ public: bool isFormatSRGB(const GrBackendFormat&) const override; - bool isFormatTexturable(const GrBackendFormat&) const override; + bool isFormatTexturable(const GrBackendFormat&, GrTextureType) const override; bool isFormatTexturable(DXGI_FORMAT) const; bool isFormatCopyable(const GrBackendFormat&) const override { return true; } diff --git a/src/gpu/d3d/GrD3DGpu.cpp b/src/gpu/d3d/GrD3DGpu.cpp index 958a482c90..b48b6872a1 100644 --- a/src/gpu/d3d/GrD3DGpu.cpp +++ b/src/gpu/d3d/GrD3DGpu.cpp @@ -687,7 +687,7 @@ bool GrD3DGpu::uploadToTexture(GrD3DTexture* tex, GrColorType colorType, const GrMipLevel* texels, int mipLevelCount) { - SkASSERT(this->caps()->isFormatTexturable(tex->backendFormat())); + SkASSERT(this->d3dCaps().isFormatTexturable(tex->dxgiFormat())); // The assumption is either that we have no mipmaps, or that our rect is the entire texture SkASSERT(mipLevelCount == 1 || rect == SkIRect::MakeSize(tex->dimensions())); diff --git a/src/gpu/dawn/GrDawnCaps.cpp b/src/gpu/dawn/GrDawnCaps.cpp index 978d18ec99..ed8387d8c9 100644 --- a/src/gpu/dawn/GrDawnCaps.cpp +++ b/src/gpu/dawn/GrDawnCaps.cpp @@ -37,7 +37,7 @@ bool GrDawnCaps::isFormatSRGB(const GrBackendFormat& format) const { return false; } -bool GrDawnCaps::isFormatTexturable(const GrBackendFormat& format) const { +bool GrDawnCaps::isFormatTexturable(const GrBackendFormat& format, GrTextureType) const { // Currently, all the formats in GrDawnFormatToPixelConfig are texturable. wgpu::TextureFormat dawnFormat; return format.asDawnFormat(&dawnFormat); diff --git a/src/gpu/dawn/GrDawnCaps.h b/src/gpu/dawn/GrDawnCaps.h index c52dd45f0a..0002c3ded9 100644 --- a/src/gpu/dawn/GrDawnCaps.h +++ b/src/gpu/dawn/GrDawnCaps.h @@ -27,7 +27,7 @@ public: bool isFormatCopyable(const GrBackendFormat& format) const override { return true; } - bool isFormatTexturable(const GrBackendFormat& format) const override; + bool isFormatTexturable(const GrBackendFormat& format, GrTextureType) const override; SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType, const GrBackendFormat& surfaceFormat, diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index 809823b7b2..5c7fb18ead 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -4450,8 +4450,8 @@ bool GrGLCaps::isFormatSRGB(const GrBackendFormat& format) const { return format.asGLFormat() == GrGLFormat::kSRGB8_ALPHA8; } -bool GrGLCaps::isFormatTexturable(const GrBackendFormat& format) const { - if (format.textureType() == GrTextureType::kRectangle && !this->rectangleTextureSupport()) { +bool GrGLCaps::isFormatTexturable(const GrBackendFormat& format, GrTextureType textureType) const { + if (textureType == GrTextureType::kRectangle && !this->rectangleTextureSupport()) { return false; } return this->isFormatTexturable(format.asGLFormat()); diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h index e98b23f0fd..c02193f945 100644 --- a/src/gpu/gl/GrGLCaps.h +++ b/src/gpu/gl/GrGLCaps.h @@ -120,7 +120,7 @@ public: bool isFormatSRGB(const GrBackendFormat&) const override; - bool isFormatTexturable(const GrBackendFormat&) const override; + bool isFormatTexturable(const GrBackendFormat&, GrTextureType) const override; bool isFormatTexturable(GrGLFormat) const; bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, diff --git a/src/gpu/mock/GrMockCaps.h b/src/gpu/mock/GrMockCaps.h index 309f161586..ad0a15b7b3 100644 --- a/src/gpu/mock/GrMockCaps.h +++ b/src/gpu/mock/GrMockCaps.h @@ -51,7 +51,7 @@ public: return GrGetColorTypeDesc(ct).encoding() == GrColorTypeEncoding::kSRGBUnorm; } - bool isFormatTexturable(const GrBackendFormat& format) const override { + bool isFormatTexturable(const GrBackendFormat& format, GrTextureType) const override { SkImage::CompressionType compression = format.asMockCompressionType(); if (compression != SkImage::CompressionType::kNone) { return fOptions.fCompressedOptions[(int)compression].fTexturable; diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp index 69a9544ff4..24177ef24d 100644 --- a/src/gpu/mock/GrMockGpu.cpp +++ b/src/gpu/mock/GrMockGpu.cpp @@ -229,7 +229,7 @@ GrBackendTexture GrMockGpu::onCreateBackendTexture(SkISize dimensions, } auto colorType = format.asMockColorType(); - if (!this->caps()->isFormatTexturable(format)) { + if (!this->caps()->isFormatTexturable(format, GrTextureType::k2D)) { return GrBackendTexture(); // invalid } @@ -247,7 +247,7 @@ GrBackendTexture GrMockGpu::onCreateCompressedBackendTexture( return {}; // should go through onCreateBackendTexture } - if (!this->caps()->isFormatTexturable(format)) { + if (!this->caps()->isFormatTexturable(format, GrTextureType::k2D)) { return {}; } diff --git a/src/gpu/mtl/GrMtlCaps.h b/src/gpu/mtl/GrMtlCaps.h index 46698c248c..1a92fbe1c7 100644 --- a/src/gpu/mtl/GrMtlCaps.h +++ b/src/gpu/mtl/GrMtlCaps.h @@ -26,7 +26,7 @@ public: bool isFormatSRGB(const GrBackendFormat&) const override; - bool isFormatTexturable(const GrBackendFormat&) const override; + bool isFormatTexturable(const GrBackendFormat&, GrTextureType) const override; bool isFormatTexturable(MTLPixelFormat) const; bool isFormatCopyable(const GrBackendFormat&) const override { return true; } diff --git a/src/gpu/mtl/GrMtlCaps.mm b/src/gpu/mtl/GrMtlCaps.mm index 178c8af93e..fc18bfe520 100644 --- a/src/gpu/mtl/GrMtlCaps.mm +++ b/src/gpu/mtl/GrMtlCaps.mm @@ -373,7 +373,7 @@ bool GrMtlCaps::isFormatSRGB(const GrBackendFormat& format) const { return format_is_srgb(GrBackendFormatAsMTLPixelFormat(format)); } -bool GrMtlCaps::isFormatTexturable(const GrBackendFormat& format) const { +bool GrMtlCaps::isFormatTexturable(const GrBackendFormat& format, GrTextureType) const { MTLPixelFormat mtlFormat = GrBackendFormatAsMTLPixelFormat(format); return this->isFormatTexturable(mtlFormat); } diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm index dcd4b47f05..457af45ba3 100644 --- a/src/gpu/mtl/GrMtlGpu.mm +++ b/src/gpu/mtl/GrMtlGpu.mm @@ -366,7 +366,7 @@ bool GrMtlGpu::uploadToTexture(GrMtlTexture* tex, GrColorType dataColorType, const GrMipLevel texels[], int mipLevelCount) { - SkASSERT(this->caps()->isFormatTexturable(tex->backendFormat())); + SkASSERT(this->mtlCaps().isFormatTexturable(tex->mtlTexture().pixelFormat)); // The assumption is either that we have no mipmaps, or that our rect is the entire texture SkASSERT(mipLevelCount == 1 || rect == SkIRect::MakeSize(tex->dimensions())); @@ -475,7 +475,7 @@ bool GrMtlGpu::uploadToTexture(GrMtlTexture* tex, } bool GrMtlGpu::clearTexture(GrMtlTexture* tex, size_t bpp, uint32_t levelMask) { - SkASSERT(this->mtlCaps().isFormatTexturable(tex->backendFormat())); + SkASSERT(this->mtlCaps().isFormatTexturable(tex->mtlTexture().pixelFormat)); if (!levelMask) { return true; @@ -645,7 +645,7 @@ sk_sp GrMtlGpu::onCreateCompressedTexture(SkISize dimensions, return nullptr; } - SkASSERT(this->caps()->isFormatTexturable(format)); + SkASSERT(this->caps()->isFormatTexturable(format, GrTextureType::k2D)); SkASSERT(data); if (!check_max_blit_width(dimensions.width())) { diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp index 33f4f67778..d689cb101d 100644 --- a/src/gpu/vk/GrVkCaps.cpp +++ b/src/gpu/vk/GrVkCaps.cpp @@ -1411,7 +1411,7 @@ bool GrVkCaps::isFormatSRGB(const GrBackendFormat& format) const { return format_is_srgb(vkFormat); } -bool GrVkCaps::isFormatTexturable(const GrBackendFormat& format) const { +bool GrVkCaps::isFormatTexturable(const GrBackendFormat& format, GrTextureType) const { VkFormat vkFormat; if (!format.asVkFormat(&vkFormat)) { return false; diff --git a/src/gpu/vk/GrVkCaps.h b/src/gpu/vk/GrVkCaps.h index 1edaa54581..f781a9afa3 100644 --- a/src/gpu/vk/GrVkCaps.h +++ b/src/gpu/vk/GrVkCaps.h @@ -36,7 +36,7 @@ public: bool isFormatSRGB(const GrBackendFormat&) const override; - bool isFormatTexturable(const GrBackendFormat&) const override; + bool isFormatTexturable(const GrBackendFormat&, GrTextureType) const override; bool isVkFormatTexturable(VkFormat) const; bool isFormatCopyable(const GrBackendFormat&) const override { return true; } diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index 104032f73d..873b43104e 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -442,7 +442,7 @@ static bool validate_backend_texture(const GrCaps* caps, const GrBackendTexture& return false; } - if (texturable && !caps->isFormatTexturable(backendFormat)) { + if (texturable && !caps->isFormatTexturable(backendFormat, tex.textureType())) { return false; } diff --git a/tests/BackendAllocationTest.cpp b/tests/BackendAllocationTest.cpp index 28f450177c..5800e6ee5f 100644 --- a/tests/BackendAllocationTest.cpp +++ b/tests/BackendAllocationTest.cpp @@ -798,10 +798,11 @@ DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(GLBackendAllocationTest, reporter, ctxInfo) { }; for (auto combo : combinations) { - for (GrGLenum target : {GR_GL_TEXTURE_2D, GR_GL_TEXTURE_RECTANGLE}) { + for (GrTextureType textureType : {GrTextureType::k2D, GrTextureType::kRectangle}) { + GrGLenum target = textureType == GrTextureType::k2D ? GR_GL_TEXTURE_2D + : GR_GL_TEXTURE_RECTANGLE; GrBackendFormat format = GrBackendFormat::MakeGL(combo.fFormat, target); - - if (!glCaps->isFormatTexturable(format)) { + if (!glCaps->isFormatTexturable(format, textureType)) { continue; } diff --git a/tests/CompressedBackendAllocationTest.cpp b/tests/CompressedBackendAllocationTest.cpp index 618b21cc2f..a328d42917 100644 --- a/tests/CompressedBackendAllocationTest.cpp +++ b/tests/CompressedBackendAllocationTest.cpp @@ -295,7 +295,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CompressedBackendAllocationTest, reporter, ct continue; } - if (!caps->isFormatTexturable(format)) { + if (!caps->isFormatTexturable(format, GrTextureType::k2D)) { continue; } diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp index 1ce611c797..618bde88c8 100644 --- a/tests/GrSurfaceTest.cpp +++ b/tests/GrSurfaceTest.cpp @@ -36,8 +36,8 @@ DEF_GPUTEST_FOR_MOCK_CONTEXT(GrSurface, reporter, ctxInfo) { auto format = context->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, GrRenderable::kYes); sk_sp texRT1 = - resourceProvider->createTexture(kDesc, format, GrRenderable::kYes, 1, GrMipmapped::kNo, - SkBudgeted::kNo, GrProtected::kNo); + resourceProvider->createTexture(kDesc, format, GrTextureType::k2D, GrRenderable::kYes, + 1, GrMipmapped::kNo, SkBudgeted::kNo, GrProtected::kNo); REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asRenderTarget()); REPORTER_ASSERT(reporter, texRT1.get() == texRT1->asTexture()); @@ -49,8 +49,8 @@ DEF_GPUTEST_FOR_MOCK_CONTEXT(GrSurface, reporter, ctxInfo) { static_cast(texRT1->asTexture())); sk_sp tex1 = - resourceProvider->createTexture(kDesc, format, GrRenderable::kNo, 1, GrMipmapped::kNo, - SkBudgeted::kNo, GrProtected::kNo); + resourceProvider->createTexture(kDesc, format, GrTextureType::k2D, GrRenderable::kNo, 1, + GrMipmapped::kNo, SkBudgeted::kNo, GrProtected::kNo); REPORTER_ASSERT(reporter, nullptr == tex1->asRenderTarget()); REPORTER_ASSERT(reporter, tex1.get() == tex1->asTexture()); REPORTER_ASSERT(reporter, static_cast(tex1.get()) == tex1->asTexture()); @@ -100,8 +100,8 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) { return rp->createCompressedTexture(dimensions, format, SkBudgeted::kNo, GrMipmapped::kNo, GrProtected::kNo, data.get()); } else { - return rp->createTexture(dimensions, format, renderable, 1, GrMipmapped::kNo, - SkBudgeted::kNo, GrProtected::kNo); + return rp->createTexture(dimensions, format, GrTextureType::k2D, renderable, 1, + GrMipmapped::kNo, SkBudgeted::kNo, GrProtected::kNo); } }; @@ -126,7 +126,7 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) { // support check is working { bool isCompressed = caps->isFormatCompressed(combo.fFormat); - bool isTexturable = caps->isFormatTexturable(combo.fFormat); + bool isTexturable = caps->isFormatTexturable(combo.fFormat, GrTextureType::k2D); sk_sp tex = createTexture(kDims, combo.fColorType, combo.fFormat, GrRenderable::kNo, resourceProvider); @@ -153,8 +153,8 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) { bool isRenderable = caps->isFormatRenderable(combo.fFormat, 1); sk_sp tex = resourceProvider->createTexture( - kDims, combo.fFormat, GrRenderable::kYes, 1, GrMipmapped::kNo, SkBudgeted::kNo, - GrProtected::kNo); + kDims, combo.fFormat, GrTextureType::k2D, GrRenderable::kYes, 1, + GrMipmapped::kNo, SkBudgeted::kNo, GrProtected::kNo); REPORTER_ASSERT(reporter, SkToBool(tex) == isRenderable, "ct:%s format:%s, tex:%d, isRenderable:%d", GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(), @@ -166,8 +166,8 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) { bool isRenderable = caps->isFormatRenderable(combo.fFormat, 2); sk_sp tex = resourceProvider->createTexture( - kDims, combo.fFormat, GrRenderable::kYes, 2, GrMipmapped::kNo, SkBudgeted::kNo, - GrProtected::kNo); + kDims, combo.fFormat, GrTextureType::k2D, GrRenderable::kYes, 2, + GrMipmapped::kNo, SkBudgeted::kNo, GrProtected::kNo); REPORTER_ASSERT(reporter, SkToBool(tex) == isRenderable, "ct:%s format:%s, tex:%d, isRenderable:%d", GrColorTypeToStr(combo.fColorType), combo.fFormat.toStr().c_str(), @@ -219,7 +219,7 @@ DEF_GPUTEST(InitialTextureClear, reporter, baseOptions) { SkASSERT(combo.fColorType != GrColorType::kUnknown); SkASSERT(combo.fFormat.isValid()); - if (!caps->isFormatTexturable(combo.fFormat)) { + if (!caps->isFormatTexturable(combo.fFormat, GrTextureType::k2D)) { continue; } diff --git a/tests/LazyProxyTest.cpp b/tests/LazyProxyTest.cpp index 526f29ce91..732c7d3951 100644 --- a/tests/LazyProxyTest.cpp +++ b/tests/LazyProxyTest.cpp @@ -92,8 +92,14 @@ public: } else { static constexpr SkISize kDimensions = {1234, 567}; sk_sp texture = rp->createTexture( - kDimensions, desc.fFormat, desc.fRenderable, desc.fSampleCnt, - desc.fMipmapped, desc.fBudgeted, desc.fProtected); + kDimensions, + desc.fFormat, + desc.fFormat.textureType(), + desc.fRenderable, + desc.fSampleCnt, + desc.fMipmapped, + desc.fBudgeted, + desc.fProtected); REPORTER_ASSERT(fTest->fReporter, texture); return texture; } @@ -239,9 +245,14 @@ DEF_GPUTEST(LazyProxyReleaseTest, reporter, /* options */) { GrBackendFormat format = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, GrRenderable::kNo); - auto tex = ctx->priv().resourceProvider()->createTexture({kSize, kSize}, format, - GrRenderable::kNo, 1, GrMipmapped::kNo, - SkBudgeted::kNo, GrProtected::kNo); + auto tex = ctx->priv().resourceProvider()->createTexture({kSize, kSize}, + format, + GrTextureType::k2D, + GrRenderable::kNo, + 1, + GrMipmapped::kNo, + SkBudgeted::kNo, + GrProtected::kNo); using LazyInstantiationResult = GrSurfaceProxy::LazyCallbackResult; for (bool doInstantiate : {true, false}) { for (bool releaseCallback : {false, true}) { @@ -346,8 +357,13 @@ private: *testExecuteValue = 1; return {}; } - return {rp->createTexture(desc.fDimensions, desc.fFormat, desc.fRenderable, - desc.fSampleCnt, desc.fMipmapped, desc.fBudgeted, + return {rp->createTexture(desc.fDimensions, + desc.fFormat, + desc.fFormat.textureType(), + desc.fRenderable, + desc.fSampleCnt, + desc.fMipmapped, + desc.fBudgeted, desc.fProtected), true, GrSurfaceProxy::LazyInstantiationKeyMode::kUnsynced}; }, diff --git a/tests/MtlCopySurfaceTest.mm b/tests/MtlCopySurfaceTest.mm index 29a5b68088..ab8f87d301 100644 --- a/tests/MtlCopySurfaceTest.mm +++ b/tests/MtlCopySurfaceTest.mm @@ -61,8 +61,9 @@ DEF_GPUTEST_FOR_METAL_CONTEXT(MtlCopySurfaceTest, reporter, ctxInfo) { GrBackendFormat backendFormat = GrBackendFormat::MakeMtl(drawable.texture.pixelFormat); GrSurface* src = srcProxy->peekSurface(); sk_sp dst = - gpu->createTexture({kWidth, kHeight}, backendFormat, GrRenderable::kNo, 1, - GrMipmapped::kNo, SkBudgeted::kNo, GrProtected::kNo); + gpu->createTexture({kWidth, kHeight}, backendFormat, GrTextureType::k2D, + GrRenderable::kNo, 1, GrMipmapped::kNo, SkBudgeted::kNo, + GrProtected::kNo); bool result = gpu->copySurface(dst.get(), src, SkIRect::MakeXYWH(0, 0, kWidth, kHeight), SkIPoint::Make(0, 0)); diff --git a/tests/PromiseImageTest.cpp b/tests/PromiseImageTest.cpp index 019a485151..5f8c7c6b0f 100644 --- a/tests/PromiseImageTest.cpp +++ b/tests/PromiseImageTest.cpp @@ -314,8 +314,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(PromiseImageTextureFullCache, reporter, ctxIn auto format = dContext->priv().caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, GrRenderable::kNo); textures.emplace_back(dContext->priv().resourceProvider()->createTexture( - {100, 100}, format, GrRenderable::kNo, 1, GrMipmapped::kNo, SkBudgeted::kYes, - GrProtected::kNo)); + {100, 100}, format, GrTextureType::k2D, GrRenderable::kNo, 1, GrMipmapped::kNo, + SkBudgeted::kYes, GrProtected::kNo)); REPORTER_ASSERT(reporter, textures[i]); } diff --git a/tests/ProxyTest.cpp b/tests/ProxyTest.cpp index 767cb30d5a..9dec7a1b2b 100644 --- a/tests/ProxyTest.cpp +++ b/tests/ProxyTest.cpp @@ -136,12 +136,12 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) { sk_sp tex; if (SkBackingFit::kApprox == fit) { tex = resourceProvider->createApproxTexture( - dims, format, GrRenderable::kYes, numSamples, - GrProtected::kNo); + dims, format, GrTextureType::k2D, GrRenderable::kYes, + numSamples, GrProtected::kNo); } else { tex = resourceProvider->createTexture( - dims, format, GrRenderable::kYes, numSamples, - GrMipmapped::kNo, budgeted, GrProtected::kNo); + dims, format, GrTextureType::k2D, GrRenderable::kYes, + numSamples, GrMipmapped::kNo, budgeted, GrProtected::kNo); } sk_sp proxy = proxyProvider->createProxy( @@ -172,12 +172,12 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DeferredProxyTest, reporter, ctxInfo) { sk_sp tex; if (SkBackingFit::kApprox == fit) { tex = resourceProvider->createApproxTexture( - dims, format, GrRenderable::kNo, numSamples, - GrProtected::kNo); + dims, format, GrTextureType::k2D, GrRenderable::kNo, + numSamples, GrProtected::kNo); } else { tex = resourceProvider->createTexture( - dims, format, GrRenderable::kNo, numSamples, - GrMipmapped::kNo, budgeted, GrProtected::kNo); + dims, format, GrTextureType::k2D, GrRenderable::kNo, + numSamples, GrMipmapped::kNo, budgeted, GrProtected::kNo); } sk_sp proxy(proxyProvider->createProxy( diff --git a/tests/ResourceAllocatorTest.cpp b/tests/ResourceAllocatorTest.cpp index 8b4aae24d4..4aedc8ca71 100644 --- a/tests/ResourceAllocatorTest.cpp +++ b/tests/ResourceAllocatorTest.cpp @@ -91,6 +91,7 @@ static sk_sp make_fully_lazy(GrProxyProvider* proxyProvider, con const GrBackendFormat format = caps->getDefaultBackendFormat(p.fColorType, p.fRenderable); auto cb = [p](GrResourceProvider* provider, const GrSurfaceProxy::LazySurfaceDesc& desc) { auto tex = provider->createTexture({p.fSize, p.fSize}, desc.fFormat, + desc.fFormat.textureType(), desc.fRenderable, desc.fSampleCnt, desc.fMipmapped, desc.fBudgeted, desc.fProtected); @@ -106,6 +107,7 @@ static sk_sp make_lazy(GrProxyProvider* proxyProvider, const GrC const GrBackendFormat format = caps->getDefaultBackendFormat(p.fColorType, p.fRenderable); auto cb = [](GrResourceProvider* provider, const GrSurfaceProxy::LazySurfaceDesc& desc) { auto tex = provider->createTexture(desc.fDimensions, desc.fFormat, + desc.fFormat.textureType(), desc.fRenderable, desc.fSampleCnt, desc.fMipmapped, desc.fBudgeted, desc.fProtected); diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index 3ca5acce46..b56c0e208b 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -89,9 +89,9 @@ static sk_sp create_RT_with_SB(GrResourceProvider* provider, int size, int sampleCount, SkBudgeted budgeted) { auto format = provider->caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, GrRenderable::kYes); - sk_sp tex(provider->createTexture({size, size}, format, GrRenderable::kYes, - sampleCount, GrMipmapped::kNo, budgeted, - GrProtected::kNo)); + sk_sp tex(provider->createTexture({size, size}, format, GrTextureType::k2D, + GrRenderable::kYes, sampleCount, GrMipmapped::kNo, + budgeted, GrProtected::kNo)); if (!tex || !tex->asRenderTarget()) { return nullptr; } @@ -1687,8 +1687,8 @@ static sk_sp make_normal_texture(GrResourceProvider* provider, SkISize dims, int sampleCnt) { auto format = provider->caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, renderable); - return provider->createTexture(dims, format, renderable, sampleCnt, GrMipmapped::kNo, - SkBudgeted::kYes, GrProtected::kNo); + return provider->createTexture(dims, format, GrTextureType::k2D, renderable, sampleCnt, + GrMipmapped::kNo, SkBudgeted::kYes, GrProtected::kNo); } static sk_sp make_mipmap_proxy(GrRecordingContext* rContext, diff --git a/tests/TextureBindingsResetTest.cpp b/tests/TextureBindingsResetTest.cpp index c29362d461..db60a46c53 100644 --- a/tests/TextureBindingsResetTest.cpp +++ b/tests/TextureBindingsResetTest.cpp @@ -77,8 +77,8 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(TextureBindingsResetTest, reporter, ctxInf static constexpr SkISize kDims = {10, 10}; GrBackendFormat format = gpu->caps()->getDefaultBackendFormat(GrColorType::kRGBA_8888, GrRenderable::kNo); - auto tex = gpu->createTexture(kDims, format, GrRenderable::kNo, 1, GrMipmapped::kNo, - SkBudgeted::kNo, GrProtected::kNo); + auto tex = gpu->createTexture(kDims, format, GrTextureType::k2D, GrRenderable::kNo, 1, + GrMipmapped::kNo, SkBudgeted::kNo, GrProtected::kNo); REPORTER_ASSERT(reporter, tex); dContext->resetGLTextureBindings(); checkBindings(); diff --git a/tests/TransferPixelsTest.cpp b/tests/TransferPixelsTest.cpp index 4a3086d7f8..a77235f236 100644 --- a/tests/TransferPixelsTest.cpp +++ b/tests/TransferPixelsTest.cpp @@ -127,8 +127,8 @@ void basic_transfer_to_test(skiatest::Reporter* reporter, const int kBufferHeight = 16; sk_sp tex = - resourceProvider->createTexture(kTexDims, backendFormat, renderable, 1, - GrMipmapped::kNo, SkBudgeted::kNo, GrProtected::kNo); + resourceProvider->createTexture(kTexDims, backendFormat, GrTextureType::k2D, renderable, + 1, GrMipmapped::kNo, SkBudgeted::kNo, GrProtected::kNo); if (!tex) { ERRORF(reporter, "Could not create texture"); return; @@ -313,8 +313,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, GrMipMapped::kNo, + sk_sp tex = resourceProvider->createTexture(kTexDims, format, GrTextureType::k2D, + colorType, renderable, 1, + SkBudgeted::kNo, GrMipMapped::kNo, GrProtected::kNo, &data); if (!tex) { return; diff --git a/tools/DDLPromiseImageHelper.cpp b/tools/DDLPromiseImageHelper.cpp index 9514321b42..565beb79b4 100644 --- a/tools/DDLPromiseImageHelper.cpp +++ b/tools/DDLPromiseImageHelper.cpp @@ -245,7 +245,7 @@ void DDLPromiseImageHelper::createCallbackContexts(GrDirectContext* direct) { GrBackendFormat backendFormat = direct->defaultBackendFormat(baseLevel.colorType(), GrRenderable::kNo); - if (!caps->isFormatTexturable(backendFormat)) { + if (!caps->isFormatTexturable(backendFormat, GrTextureType::k2D)) { continue; } diff --git a/tools/DDLTileHelper.cpp b/tools/DDLTileHelper.cpp index f9a242aa31..c825194a2f 100644 --- a/tools/DDLTileHelper.cpp +++ b/tools/DDLTileHelper.cpp @@ -32,12 +32,11 @@ void DDLTileHelper::TileData::init(int id, this->paddedRectSize().height()); SkASSERT(fPlaybackChar.isValid()); - GrBackendFormat backendFormat = direct->defaultBackendFormat(fPlaybackChar.colorType(), - GrRenderable::kYes); SkDEBUGCODE(const GrCaps* caps = direct->priv().caps()); - SkASSERT(caps->isFormatTexturable(backendFormat)); + SkASSERT(caps->isFormatTexturable(fPlaybackChar.backendFormat(), + fPlaybackChar.backendFormat().textureType())); - fCallbackContext.reset(new PromiseImageCallbackContext(direct, backendFormat)); + fCallbackContext.reset(new PromiseImageCallbackContext(direct, fPlaybackChar.backendFormat())); } DDLTileHelper::TileData::TileData() {} diff --git a/tools/fiddle/fiddle_main.cpp b/tools/fiddle/fiddle_main.cpp index c94e76ed63..e4886a4cb8 100644 --- a/tools/fiddle/fiddle_main.cpp +++ b/tools/fiddle/fiddle_main.cpp @@ -176,8 +176,9 @@ static bool setup_backend_objects(GrDirectContext* dContext, constexpr int kSampleCnt = 0; sk_sp tmp = resourceProvider->createTexture( - offscreenDims, renderableFormat, GrColorType::kRGBA_8888, GrRenderable::kYes, - kSampleCnt, SkBudgeted::kNo, GrMipMapped::kNo, GrProtected::kNo, &level0); + offscreenDims, renderableFormat, GrTextureType::k2D, GrColorType::kRGBA_8888, + GrRenderable::kYes, kSampleCnt, SkBudgeted::kNo, GrMipMapped::kNo, GrProtected::kNo, + &level0); if (!tmp || !tmp->asRenderTarget()) { fputs("GrTexture is invalid.\n", stderr); return false;