diff --git a/include/private/GrTypesPriv.h b/include/private/GrTypesPriv.h index 04073b4af7..8485817daf 100644 --- a/include/private/GrTypesPriv.h +++ b/include/private/GrTypesPriv.h @@ -1387,16 +1387,6 @@ static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct) { SkUNREACHABLE; } -// We may need a roughly equivalent color type for a compressed texture. This should be the logical -// format for decompressing the data into. -static constexpr GrColorType GrCompressionTypeClosestColorType( - SkImage::CompressionType type) { - switch (type) { - case SkImage::CompressionType::kETC1_CompressionType: return GrColorType::kRGB_888x; - } - SkUNREACHABLE; -} - static constexpr GrColorType GrPixelConfigToColorType(GrPixelConfig config) { switch (config) { case kUnknown_GrPixelConfig: @@ -1432,7 +1422,9 @@ static constexpr GrColorType GrPixelConfigToColorType(GrPixelConfig config) { case kRGBA_half_Clamped_GrPixelConfig: return GrColorType::kRGBA_F16_Clamped; case kRGB_ETC1_GrPixelConfig: - return GrCompressionTypeClosestColorType(SkImage::kETC1_CompressionType); + // We may need a roughly equivalent color type for a compressed texture. This should be + // the logical format for decompressing the data into. + return GrColorType::kRGB_888x; case kAlpha_8_as_Alpha_GrPixelConfig: return GrColorType::kAlpha_8; case kAlpha_8_as_Red_GrPixelConfig: diff --git a/src/gpu/GrCaps.cpp b/src/gpu/GrCaps.cpp index 107fe3021f..7425157c9e 100644 --- a/src/gpu/GrCaps.cpp +++ b/src/gpu/GrCaps.cpp @@ -243,7 +243,7 @@ void GrCaps::dumpJSON(SkJSONWriter* writer) const { writer->beginObject(nullptr, false); writer->appendString("name", GrPixelConfigToStr(config)); //writer->appendS32("max sample count", this->maxRenderTargetSampleCount(config)); - writer->appendBool("texturable", this->isConfigTexturable(config)); +// writer->appendBool("texturable", this->isConfigTexturable(config)); writer->endObject(); } @@ -285,7 +285,7 @@ bool GrCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src bool GrCaps::validateSurfaceParams(const SkISize& size, const GrBackendFormat& format, GrPixelConfig config, GrRenderable renderable, int renderTargetSampleCnt, GrMipMapped mipped) const { - if (!this->isConfigTexturable(config)) { + if (!this->isFormatTexturable(format)) { return false; } @@ -397,7 +397,7 @@ bool GrCaps::AreConfigsCompatible(GrPixelConfig genericConfig, GrPixelConfig spe GrBackendFormat GrCaps::getDefaultBackendFormat(GrColorType grColorType, GrRenderable renderable) const { GrBackendFormat format = this->onGetDefaultBackendFormat(grColorType, renderable); - if (!this->isFormatTexturable(grColorType, format)) { + if (!this->isFormatTexturableAndUploadable(grColorType, format)) { return {}; } diff --git a/src/gpu/GrCaps.h b/src/gpu/GrCaps.h index a796ff24b9..5d2a51bb21 100644 --- a/src/gpu/GrCaps.h +++ b/src/gpu/GrCaps.h @@ -162,8 +162,11 @@ public: virtual bool isFormatSRGB(const GrBackendFormat&) const = 0; virtual bool isFormatCompressed(const GrBackendFormat&) const = 0; - virtual bool isFormatTexturable(GrColorType, const GrBackendFormat&) const = 0; - virtual bool isConfigTexturable(GrPixelConfig) const = 0; + // TODO: Once we use the supportWritePixels call for uploads, we can remove this function and + // instead only have the version that takes a GrBackendFormat. + virtual bool isFormatTexturableAndUploadable(GrColorType, const GrBackendFormat&) const = 0; + // Can a texture be made with the GrBackendFormat, and then be bound and sampled in a shader. + virtual bool isFormatTexturable(const GrBackendFormat&) 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; diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 865610702a..4e927fcc0d 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -233,8 +233,10 @@ int GrContext::maxTextureSize() const { return this->caps()->maxTextureSize(); } int GrContext::maxRenderTargetSize() const { return this->caps()->maxRenderTargetSize(); } bool GrContext::colorTypeSupportedAsImage(SkColorType colorType) const { - GrPixelConfig config = SkColorType2GrPixelConfig(colorType); - return this->caps()->isConfigTexturable(config); + GrBackendFormat format = + this->caps()->getDefaultBackendFormat(SkColorTypeToGrColorType(colorType), + GrRenderable::kNo); + return format.isValid(); } int GrContext::maxSurfaceSampleCountForColorType(SkColorType colorType) const { diff --git a/src/gpu/GrContextThreadSafeProxy.cpp b/src/gpu/GrContextThreadSafeProxy.cpp index 7ad6fb3512..7de2170599 100644 --- a/src/gpu/GrContextThreadSafeProxy.cpp +++ b/src/gpu/GrContextThreadSafeProxy.cpp @@ -75,7 +75,7 @@ SkSurfaceCharacterization GrContextThreadSafeProxy::createCharacterization( return SkSurfaceCharacterization(); // return an invalid characterization } - if (isTextureable && !this->caps()->isFormatTexturable(grColorType, backendFormat)) { + if (isTextureable && !this->caps()->isFormatTexturable(backendFormat)) { // Skia doesn't agree that this is textureable. return SkSurfaceCharacterization(); // return an invalid characterization } diff --git a/src/gpu/GrContext_Base.cpp b/src/gpu/GrContext_Base.cpp index aba1b82c5c..1c79b32eca 100644 --- a/src/gpu/GrContext_Base.cpp +++ b/src/gpu/GrContext_Base.cpp @@ -54,7 +54,7 @@ GrBackendFormat GrContext_Base::defaultBackendFormat(SkColorType skColorType, return GrBackendFormat(); } - SkASSERT(caps->isFormatTexturable(grColorType, format)); + SkASSERT(caps->isFormatTexturableAndUploadable(grColorType, format)); SkASSERT(renderable == GrRenderable::kNo || caps->isFormatAsColorTypeRenderable(grColorType, format)); diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index f0a2bced5a..970c7a3835 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -214,9 +214,14 @@ sk_sp GrGpu::createTexture(const GrSurfaceDesc& desc, const GrBackend } sk_sp GrGpu::createCompressedTexture(int width, int height, + const GrBackendFormat& format, SkImage::CompressionType compressionType, SkBudgeted budgeted, const void* data, size_t dataSize) { + // If we ever add a new CompressionType, we should add a check here to make sure the + // GrBackendFormat and CompressionType are compatible with eachother. + SkASSERT(compressionType == SkImage::kETC1_CompressionType); + this->handleDirtyContext(); if (width < 1 || width > this->caps()->maxTextureSize() || height < 1 || height > this->caps()->maxTextureSize()) { @@ -227,13 +232,13 @@ sk_sp GrGpu::createCompressedTexture(int width, int height, if (!data) { return nullptr; } - if (!this->caps()->isConfigTexturable(GrCompressionTypePixelConfig(compressionType))) { + if (!this->caps()->isFormatTexturable(format)) { return nullptr; } if (dataSize < GrCompressedDataSize(compressionType, width, height)) { return nullptr; } - return this->onCreateCompressedTexture(width, height, compressionType, budgeted, data); + return this->onCreateCompressedTexture(width, height, format, compressionType, budgeted, data); } sk_sp GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex, @@ -246,7 +251,7 @@ sk_sp GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex, const GrCaps* caps = this->caps(); SkASSERT(caps); - if (!caps->isFormatTexturable(colorType, backendTex.getBackendFormat())) { + if (!caps->isFormatTexturable(backendTex.getBackendFormat())) { return nullptr; } if (backendTex.width() > caps->maxTextureSize() || @@ -268,7 +273,7 @@ sk_sp GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& bac const GrCaps* caps = this->caps(); - if (!caps->isFormatTexturable(colorType, backendTex.getBackendFormat()) || + if (!caps->isFormatTexturable(backendTex.getBackendFormat()) || !caps->isFormatRenderable(backendTex.getBackendFormat(), sampleCnt)) { return nullptr; } @@ -356,7 +361,7 @@ bool GrGpu::readPixels(GrSurface* surface, int left, int top, int width, int hei size_t rowBytes) { TRACE_EVENT0("skia.gpu", TRACE_FUNC); SkASSERT(surface); - SkASSERT(this->caps()->isFormatTexturable(surfaceColorType, surface->backendFormat())); + SkASSERT(this->caps()->isFormatTexturable(surface->backendFormat())); auto subRect = SkIRect::MakeXYWH(left, top, width, height); auto bounds = SkIRect::MakeWH(surface->width(), surface->height()); @@ -393,7 +398,8 @@ bool GrGpu::writePixels(GrSurface* surface, int left, int top, int width, int he const GrMipLevel texels[], int mipLevelCount) { TRACE_EVENT0("skia.gpu", TRACE_FUNC); SkASSERT(surface); - SkASSERT(this->caps()->isFormatTexturable(surfaceColorType, surface->backendFormat())); + SkASSERT(this->caps()->isFormatTexturableAndUploadable(surfaceColorType, + surface->backendFormat())); if (surface->readOnly()) { return false; @@ -435,7 +441,8 @@ bool GrGpu::transferPixelsTo(GrTexture* texture, int left, int top, int width, i TRACE_EVENT0("skia.gpu", TRACE_FUNC); SkASSERT(texture); SkASSERT(transferBuffer); - SkASSERT(this->caps()->isFormatTexturable(textureColorType, texture->backendFormat())); + SkASSERT(this->caps()->isFormatTexturableAndUploadable(textureColorType, + texture->backendFormat())); if (texture->readOnly()) { return false; @@ -480,7 +487,7 @@ bool GrGpu::transferPixelsFrom(GrSurface* surface, int left, int top, int width, TRACE_EVENT0("skia.gpu", TRACE_FUNC); SkASSERT(surface); SkASSERT(transferBuffer); - SkASSERT(this->caps()->isFormatTexturable(surfaceColorType, surface->backendFormat())); + SkASSERT(this->caps()->isFormatTexturable(surface->backendFormat())); #ifdef SK_DEBUG auto supportedRead = this->caps()->supportedReadPixelsColorType( diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index ab5cab6612..34be996c98 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -120,8 +120,9 @@ public: GrRenderable renderable, int renderTargetSampleCnt, SkBudgeted budgeted, GrProtected isProtected); - sk_sp createCompressedTexture(int width, int height, SkImage::CompressionType, - SkBudgeted, const void* data, size_t dataSize); + sk_sp createCompressedTexture(int width, int height, const GrBackendFormat&, + SkImage::CompressionType, SkBudgeted, const void* data, + size_t dataSize); /** * Implements GrResourceProvider::wrapBackendTexture @@ -549,6 +550,7 @@ private: const GrMipLevel[], int mipLevelCount) = 0; virtual sk_sp onCreateCompressedTexture(int width, int height, + const GrBackendFormat&, SkImage::CompressionType, SkBudgeted, const void* data) = 0; virtual sk_sp onWrapBackendTexture(const GrBackendTexture&, GrColorType, diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp index 95a5042686..e187448332 100644 --- a/src/gpu/GrProxyProvider.cpp +++ b/src/gpu/GrProxyProvider.cpp @@ -528,17 +528,17 @@ sk_sp GrProxyProvider::createCompressedTextureProxy( desc.fWidth = width; desc.fHeight = height; - GrColorType grColorType = GrCompressionTypeClosestColorType(compressionType); GrBackendFormat format = this->caps()->getBackendFormatFromCompressionType(compressionType); - if (!this->caps()->isFormatTexturable(grColorType, format)) { + if (!this->caps()->isFormatTexturable(format)) { return nullptr; } sk_sp proxy = this->createLazyProxy( - [width, height, compressionType, budgeted, data](GrResourceProvider* resourceProvider) { + [width, height, format, compressionType, budgeted, data] + (GrResourceProvider* resourceProvider) { return LazyInstantiationResult(resourceProvider->createCompressedTexture( - width, height, compressionType, budgeted, data.get())); + width, height, format, compressionType, budgeted, data.get())); }, format, desc, GrRenderable::kNo, 1, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, GrMipMapsStatus::kNotAllocated, SkBackingFit::kExact, SkBudgeted::kYes, diff --git a/src/gpu/GrRecordingContext.cpp b/src/gpu/GrRecordingContext.cpp index 01ed9b16e0..0959dfe3f4 100644 --- a/src/gpu/GrRecordingContext.cpp +++ b/src/gpu/GrRecordingContext.cpp @@ -396,3 +396,4 @@ sk_sp GrRecordingContextPriv::makeDeferredRenderTargetCon GrContext* GrRecordingContextPriv::backdoor() { return (GrContext*) fContext; } + diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp index 1269498438..0541037e6a 100644 --- a/src/gpu/GrResourceProvider.cpp +++ b/src/gpu/GrResourceProvider.cpp @@ -205,13 +205,14 @@ sk_sp GrResourceProvider::createTexture(const GrSurfaceDesc& desc, } sk_sp GrResourceProvider::createCompressedTexture(int width, int height, + const GrBackendFormat& format, SkImage::CompressionType compression, SkBudgeted budgeted, SkData* data) { ASSERT_SINGLE_OWNER if (this->isAbandoned()) { return nullptr; } - return fGpu->createCompressedTexture(width, height, compression, budgeted, data->data(), + return fGpu->createCompressedTexture(width, height, format, compression, budgeted, data->data(), data->size()); } diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h index c6bcef243c..4adb2faa5b 100644 --- a/src/gpu/GrResourceProvider.h +++ b/src/gpu/GrResourceProvider.h @@ -116,8 +116,8 @@ public: * Creates a compressed texture. The GrGpu must support the SkImageImage::Compression type. * This does not currently support MIP maps. It will not be renderable. */ - sk_sp createCompressedTexture(int width, int height, SkImage::CompressionType, - SkBudgeted, SkData* data); + sk_sp createCompressedTexture(int width, int height, const GrBackendFormat&, + SkImage::CompressionType, SkBudgeted, SkData* data); /////////////////////////////////////////////////////////////////////////// // Wrapped Backend Surfaces diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp index ed37ccd7ce..d9e499dda7 100644 --- a/src/gpu/GrSurfaceContext.cpp +++ b/src/gpu/GrSurfaceContext.cpp @@ -268,6 +268,10 @@ bool GrSurfaceContext::writePixels(const GrPixelInfo& origSrcInfo, const void* s srcInfo.colorSpace(), this->colorSpaceInfo().colorSpace()); const GrCaps* caps = direct->priv().caps(); + + auto rgbaDefaultFormat = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, + GrRenderable::kNo); + // For canvas2D putImageData performance we have a special code path for unpremul RGBA_8888 srcs // that are premultiplied on the GPU. This is kept as narrow as possible for now. bool canvas2DFastPath = !caps->avoidWritePixelsFastPath() && premul && !needColorConversion && @@ -276,7 +280,7 @@ bool GrSurfaceContext::writePixels(const GrPixelInfo& origSrcInfo, const void* s SkToBool(this->asRenderTargetContext()) && (dstProxy->config() == kRGBA_8888_GrPixelConfig || dstProxy->config() == kBGRA_8888_GrPixelConfig) && - direct->priv().caps()->isConfigTexturable(kRGBA_8888_GrPixelConfig) && + rgbaDefaultFormat.isValid() && direct->priv().validPMUPMConversionExists(); if (!caps->surfaceSupportsWritePixels(dstSurface) || canvas2DFastPath) { @@ -290,7 +294,7 @@ bool GrSurfaceContext::writePixels(const GrPixelInfo& origSrcInfo, const void* s if (canvas2DFastPath) { desc.fConfig = kRGBA_8888_GrPixelConfig; colorType = GrColorType::kRGBA_8888; - format = caps->getDefaultBackendFormat(colorType, GrRenderable::kNo); + format = rgbaDefaultFormat; alphaType = kUnpremul_SkAlphaType; } else { desc.fConfig = dstProxy->config(); diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp index 19086c1ab4..c58572763d 100644 --- a/src/gpu/gl/GrGLCaps.cpp +++ b/src/gpu/gl/GrGLCaps.cpp @@ -1261,15 +1261,6 @@ void GrGLCaps::getTexImageFormats(GrGLFormat surfaceFormat, GrColorType surfaceC *internalFormat = this->getTexImageInternalFormat(surfaceFormat); } -bool GrGLCaps::getCompressedTexImageFormats(GrPixelConfig surfaceConfig, - GrGLenum* internalFormat) const { - if (!GrPixelConfigIsCompressed(surfaceConfig)) { - return false; - } - *internalFormat = this->getTexImageInternalFormat(this->pixelConfigToFormat(surfaceConfig)); - return true; -} - void GrGLCaps::getReadPixelsFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType, GrColorType memoryColorType, GrGLenum* externalFormat, GrGLenum* externalType) const { @@ -1452,7 +1443,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa texImageSupportsSizedInternalFormat ? GR_GL_RGBA8 : GR_GL_RGBA; info.fInternalFormatForRenderbuffer = GR_GL_RGBA8; info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE; - info.fFlags = FormatInfo::kTextureable_Flag; + info.fFlags = FormatInfo::kTexturable_Flag; if (GR_IS_GR_GL(standard)) { info.fFlags |= msaaRenderFlags; } else if (GR_IS_GR_GL_ES(standard)) { @@ -1560,7 +1551,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa info.fInternalFormatForRenderbuffer = GR_GL_R8; info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE; if (textureRedSupport) { - info.fFlags |= FormatInfo::kTextureable_Flag | msaaRenderFlags; + info.fFlags |= FormatInfo::kTexturable_Flag | msaaRenderFlags; } if (texStorageSupported && @@ -1660,7 +1651,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE; if (alpha8IsValidForGL || alpha8IsValidForGLES || alpha8IsValidForWebGL) { - info.fFlags = FormatInfo::kTextureable_Flag; + info.fFlags = FormatInfo::kTexturable_Flag; } if (fAlpha8IsRenderable && alpha8IsValidForGL) { info.fFlags |= msaaRenderFlags; @@ -1729,7 +1720,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa (GR_IS_GR_GL_ES(standard) && version < GR_GL_VER(3, 0)) || (GR_IS_GR_WEBGL(standard)); if (supportsLum) { - info.fFlags = FormatInfo::kTextureable_Flag; + info.fFlags = FormatInfo::kTexturable_Flag; } if (texStorageSupported && !formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2 && @@ -1837,7 +1828,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa if (GR_IS_GR_GL_ES(standard)) { if (ctxInfo.hasExtension("GL_EXT_texture_format_BGRA8888")) { - info.fFlags = FormatInfo::kTextureable_Flag | nonMSAARenderFlags; + info.fFlags = FormatInfo::kTexturable_Flag | nonMSAARenderFlags; // GL_EXT_texture storage has defined interactions with // GL_EXT_texture_format_BGRA8888. if (ctxInfo.hasExtension("GL_EXT_texture_storage") && @@ -1856,7 +1847,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa if (version >= GR_GL_VER(3,0)) { // The APPLE extension doesn't explicitly make this renderable, but // internally it appears to use RGBA8, which we'll patch up below. - info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags; + info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags; supportsBGRATexStorage = true; } } @@ -1865,7 +1856,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa info.fFlags |= FormatInfo::kCanUseTexStorage_Flag; } - if (SkToBool(info.fFlags &FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fFlags &FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -1914,12 +1905,12 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT_5_6_5; if (GR_IS_GR_GL(standard)) { if (version >= GR_GL_VER(4, 2) || ctxInfo.hasExtension("GL_ARB_ES2_compatibility")) { - info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags; + info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags; } } else if (GR_IS_GR_GL_ES(standard)) { - info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags; + info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags; } else if (GR_IS_GR_WEBGL(standard)) { - info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags; + info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags; } // 565 is not a sized internal format on desktop GL. So on desktop with // 565 we always use an unsized internal format to let the system pick @@ -1932,7 +1923,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa info.fFlags |= FormatInfo::kCanUseTexStorage_Flag; } - if (SkToBool(info.fFlags &FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fFlags &FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -1980,7 +1971,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa info.fInternalFormatForRenderbuffer = GR_GL_RGBA16F; info.fDefaultExternalType = halfFloatType; if (hasFP16Textures) { - info.fFlags = FormatInfo::kTextureable_Flag; + info.fFlags = FormatInfo::kTexturable_Flag; // ES requires 3.2 or EXT_color_buffer_half_float. if (halfFPRenderTargetSupport != HalfFPRenderTargetSupport::kNone) { info.fFlags |= fpRenderFlags; @@ -2072,7 +2063,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa info.fInternalFormatForRenderbuffer = GR_GL_R16F; info.fDefaultExternalType = halfFloatType; if (textureRedSupport && hasFP16Textures) { - info.fFlags = FormatInfo::kTextureable_Flag; + info.fFlags = FormatInfo::kTexturable_Flag; if (halfFPRenderTargetSupport == HalfFPRenderTargetSupport::kAll) { info.fFlags |= fpRenderFlags; } @@ -2155,7 +2146,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa info.fDefaultExternalType = halfFloatType; if (lum16FSupported) { - info.fFlags = FormatInfo::kTextureable_Flag; + info.fFlags = FormatInfo::kTexturable_Flag; if (texStorageSupported && !formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2) { @@ -2214,7 +2205,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa texImageSupportsSizedInternalFormat ? GR_GL_RGB8 : GR_GL_RGB; info.fInternalFormatForRenderbuffer = GR_GL_RGB8; info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE; - info.fFlags = FormatInfo::kTextureable_Flag; + info.fFlags = FormatInfo::kTexturable_Flag; if (GR_IS_GR_GL(standard)) { // Even in OpenGL 4.6 GL_RGB8 is required to be color renderable but not required to be // a supported render buffer format. Since we usually use render buffers for MSAA on @@ -2292,7 +2283,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa info.fInternalFormatForRenderbuffer = GR_GL_RG8; info.fDefaultExternalType = GR_GL_UNSIGNED_BYTE; if (textureRedSupport) { - info.fFlags |= FormatInfo::kTextureable_Flag | msaaRenderFlags; + info.fFlags |= FormatInfo::kTexturable_Flag | msaaRenderFlags; if (texStorageSupported && !formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2) { info.fFlags |= FormatInfo::kCanUseTexStorage_Flag; @@ -2348,16 +2339,16 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa info.fDefaultExternalType = GR_GL_UNSIGNED_INT_2_10_10_10_REV; if (GR_IS_GR_GL(standard) || (GR_IS_GR_GL_ES(standard) && version >= GR_GL_VER(3, 0))) { - info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags; + info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags; } else if (GR_IS_GR_GL_ES(standard) && ctxInfo.hasExtension("GL_EXT_texture_type_2_10_10_10_REV")) { - info.fFlags = FormatInfo::kTextureable_Flag; + info.fFlags = FormatInfo::kTexturable_Flag; } // No WebGL support if (texStorageSupported) { info.fFlags |= FormatInfo::kCanUseTexStorage_Flag; } - if (SkToBool(info.fFlags &FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fFlags &FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -2404,7 +2395,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa texImageSupportsSizedInternalFormat ? GR_GL_RGBA4 : GR_GL_RGBA; info.fInternalFormatForRenderbuffer = GR_GL_RGBA4; info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT_4_4_4_4; - info.fFlags = FormatInfo::kTextureable_Flag; + info.fFlags = FormatInfo::kTexturable_Flag; if (GR_IS_GR_GL(standard)) { if (version >= GR_GL_VER(4, 2)) { info.fFlags |= msaaRenderFlags; @@ -2480,7 +2471,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa formatWorkarounds.fDisableSRGBRenderWithMSAAForMacAMD ? nonMSAARenderFlags : msaaRenderFlags; - info.fFlags = FormatInfo::kTextureable_Flag | srgbRenderFlags; + info.fFlags = FormatInfo::kTexturable_Flag | srgbRenderFlags; } if (texStorageSupported && !formatWorkarounds.fDisablePerFormatTextureStorageForCommandBufferES2) { @@ -2534,15 +2525,15 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_RGB8_ETC2); info.fFormatType = FormatType::kNormalizedFixedPoint; info.fBaseInternalFormat = GR_GL_RGB; - info.fCompressedInternalFormat = GR_GL_COMPRESSED_RGB8_ETC2; + info.fInternalFormatForTexImage = GR_GL_COMPRESSED_RGB8_ETC2; if (GR_IS_GR_GL(standard)) { if (version >= GR_GL_VER(4, 3) || ctxInfo.hasExtension("GL_ARB_ES3_compatibility")) { - info.fFlags = FormatInfo::kTextureable_Flag; + info.fFlags = FormatInfo::kTexturable_Flag; } } else if (GR_IS_GR_GL_ES(standard)) { if (version >= GR_GL_VER(3, 0) || ctxInfo.hasExtension("GL_OES_compressed_ETC2_RGB8_texture")) { - info.fFlags = FormatInfo::kTextureable_Flag; + info.fFlags = FormatInfo::kTexturable_Flag; } } // No WebGL support @@ -2554,10 +2545,10 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa FormatInfo& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_ETC1_RGB8); info.fFormatType = FormatType::kNormalizedFixedPoint; info.fBaseInternalFormat = GR_GL_RGB; - info.fCompressedInternalFormat = GR_GL_COMPRESSED_ETC1_RGB8; + info.fInternalFormatForTexImage = GR_GL_COMPRESSED_ETC1_RGB8; if (GR_IS_GR_GL_ES(standard)) { if (ctxInfo.hasExtension("GL_OES_compressed_ETC1_RGB8_texture")) { - info.fFlags = FormatInfo::kTextureable_Flag; + info.fFlags = FormatInfo::kTexturable_Flag; } } // No GL or WebGL support @@ -2575,7 +2566,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa info.fInternalFormatForRenderbuffer = GR_GL_R16; info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT; if (r16AndRG1616Supported) { - info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags; + info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags; } if (r16AndRG1616Supported) { @@ -2626,7 +2617,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa info.fInternalFormatForRenderbuffer = GR_GL_RG16; info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT; if (r16AndRG1616Supported) { - info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags; + info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags; } if (r16AndRG1616Supported) { @@ -2696,7 +2687,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa info.fInternalFormatForRenderbuffer = GR_GL_RGBA16; info.fDefaultExternalType = GR_GL_UNSIGNED_SHORT; if (rgba16161616Supported) { - info.fFlags = FormatInfo::kTextureable_Flag | msaaRenderFlags; + info.fFlags = FormatInfo::kTexturable_Flag | msaaRenderFlags; } if (rgba16161616Supported) { @@ -2770,7 +2761,7 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa info.fInternalFormatForRenderbuffer = GR_GL_RG16F; info.fDefaultExternalType = halfFloatType; if (rg16fTexturesSupported) { - info.fFlags |= FormatInfo::kTextureable_Flag; + info.fFlags |= FormatInfo::kTexturable_Flag; } if (rg16fRenderingSupported) { info.fFlags |= fpRenderFlags; @@ -3003,8 +2994,8 @@ bool GrGLCaps::canCopyAsBlit(GrGLFormat dstFormat, int dstSampleCnt, return true; } -bool GrGLCaps::canCopyAsDraw(GrGLFormat dstFormat, bool srcIsTextureable) const { - return this->isFormatRenderable(dstFormat, 1) && srcIsTextureable; +bool GrGLCaps::canCopyAsDraw(GrGLFormat dstFormat, bool srcIsTexturable) const { + return this->isFormatRenderable(dstFormat, 1) && srcIsTexturable; } static bool has_msaa_render_buffer(const GrSurfaceProxy* surf, const GrGLCaps& glCaps) { @@ -3759,16 +3750,22 @@ bool GrGLCaps::isFormatCompressed(const GrBackendFormat& format) const { return fmt == GrGLFormat::kCOMPRESSED_RGB8_ETC2 || fmt == GrGLFormat::kCOMPRESSED_ETC1_RGB8; } -bool GrGLCaps::isFormatTexturable(GrColorType ct, GrGLFormat format) const { - const FormatInfo& info = this->getFormatInfo(format); - // Currently we conflate texturable to mean the format itself is texturable in a draw and that - // we are able to upload data of the passed in colortype to it. - return SkToBool(info.fFlags & FormatInfo::kTextureable_Flag) && +bool GrGLCaps::isFormatTexturableAndUploadable(GrColorType ct, + const GrBackendFormat& format) const { + auto glFormat = format.asGLFormat(); + const FormatInfo& info = this->getFormatInfo(glFormat); + + return this->isFormatTexturable(glFormat) && SkToBool(info.colorTypeFlags(ct) & ColorTypeInfo::kUploadData_Flag); } -bool GrGLCaps::isFormatTexturable(GrColorType ct, const GrBackendFormat& format) const { - return this->isFormatTexturable(ct, format.asGLFormat()); +bool GrGLCaps::isFormatTexturable(const GrBackendFormat& format) const { + return this->isFormatTexturable(format.asGLFormat()); +} + +bool GrGLCaps::isFormatTexturable(GrGLFormat format) const { + const FormatInfo& info = this->getFormatInfo(format); + return SkToBool(info.fFlags & FormatInfo::kTexturable_Flag); } bool GrGLCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, @@ -3858,7 +3855,7 @@ GrGLFormat GrGLCaps::pixelConfigToFormat(GrPixelConfig config) const { return GrGLFormat::kR16F; case kRGB_ETC1_GrPixelConfig: { const auto& info = this->getFormatInfo(GrGLFormat::kCOMPRESSED_ETC1_RGB8); - bool usesETC1 = SkToBool(info.fFlags & FormatInfo::kTextureable_Flag); + bool usesETC1 = SkToBool(info.fFlags & FormatInfo::kTexturable_Flag); return usesETC1 ? GrGLFormat::kCOMPRESSED_ETC1_RGB8 : GrGLFormat::kCOMPRESSED_RGB8_ETC2; } diff --git a/src/gpu/gl/GrGLCaps.h b/src/gpu/gl/GrGLCaps.h index e6c2679705..acae8053e4 100644 --- a/src/gpu/gl/GrGLCaps.h +++ b/src/gpu/gl/GrGLCaps.h @@ -111,14 +111,9 @@ public: bool isFormatSRGB(const GrBackendFormat&) const override; bool isFormatCompressed(const GrBackendFormat&) const override; - bool isFormatTexturable(GrColorType, const GrBackendFormat&) const override; - bool isFormatTexturable(GrColorType, GrGLFormat) const; - - bool isConfigTexturable(GrPixelConfig config) const override { - GrColorType ct = GrPixelConfigToColorType(config); - auto format = this->pixelConfigToFormat(config); - return this->isFormatTexturable(ct, format); - } + bool isFormatTexturableAndUploadable(GrColorType, const GrBackendFormat&) const override; + bool isFormatTexturable(const GrBackendFormat&) const override; + bool isFormatTexturable(GrGLFormat) const; bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, int sampleCount = 1) const override; @@ -171,8 +166,6 @@ public: GrColorType memoryColorType, GrGLenum* internalFormat, GrGLenum* externalFormat, GrGLenum* externalType) const; - bool getCompressedTexImageFormats(GrPixelConfig surfaceConfig, GrGLenum* internalFormat) const; - void getReadPixelsFormat(GrGLFormat surfaceFormat, GrColorType surfaceColorType, GrColorType memoryColorType, GrGLenum* externalFormat, GrGLenum* externalType) const; @@ -435,7 +428,7 @@ public: const GrTextureType* srcTypeIfTexture, const SkRect& srcBounds, bool srcBoundsExact, const SkIRect& srcRect, const SkIPoint& dstPoint) const; - bool canCopyAsDraw(GrGLFormat dstFormat, bool srcIsTextureable) const; + bool canCopyAsDraw(GrGLFormat dstFormat, bool srcIsTexturable) const; DstCopyRestrictions getDstCopyRestrictions(const GrRenderTargetProxy* src, GrColorType) const override; @@ -675,7 +668,7 @@ private: } enum { - kTextureable_Flag = 0x1, + kTexturable_Flag = 0x1, /** kFBOColorAttachment means that even if the format cannot be a GrRenderTarget, we can still attach it to a FBO for blitting or reading pixels. */ kFBOColorAttachment_Flag = 0x2, @@ -695,9 +688,9 @@ private: // Not defined for uncompressed formats. Passed to glCompressedTexImage... GrGLenum fCompressedInternalFormat = 0; - // Value to uses as the "internalformat" argument to glTexImage... Usually one of - // fBaseInternalFormat or fSizedInternalFormat but may vary depending on the particular - // format, GL version, extensions. + // Value to uses as the "internalformat" argument to glTexImage and glCompressedTexImage... + // Usually one of fBaseInternalFormat or fSizedInternalFormat but may vary depending on the + // particular format, GL version, extensions. GrGLenum fInternalFormatForTexImage = 0; // Value to uses as the "internalformat" argument to glRenderbufferStorageMultisample... diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index a2280b4030..0ca7ba39de 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -1107,7 +1107,7 @@ bool GrGLGpu::uploadTexData(GrGLFormat textureFormat, GrColorType textureColorTy // If we're uploading compressed data then we should be using uploadCompressedTexData SkASSERT(!GrGLFormatIsCompressed(textureFormat)); - SkASSERT(this->glCaps().isFormatTexturable(textureColorType, textureFormat)); + SkASSERT(this->glCaps().isFormatTexturable(textureFormat)); SkDEBUGCODE( SkIRect subRect = SkIRect::MakeXYWH(left, top, width, height); SkIRect bounds = SkIRect::MakeWH(texWidth, texHeight); @@ -1205,22 +1205,21 @@ bool GrGLGpu::uploadTexData(GrGLFormat textureFormat, GrColorType textureColorTy return succeeded; } -GrGLFormat GrGLGpu::uploadCompressedTexData(SkImage::CompressionType compressionType, - const SkISize& size, - GrGLenum target, - const void* data) { +bool GrGLGpu::uploadCompressedTexData(GrGLFormat format, + SkImage::CompressionType compressionType, + const SkISize& size, + GrGLenum target, + const void* data) { + SkASSERT(format != GrGLFormat::kUnknown); const GrGLCaps& caps = this->glCaps(); - GrPixelConfig config = GrCompressionTypePixelConfig(compressionType); // We only need the internal format for compressed 2D textures. - GrGLenum internalFormat; - if (!caps.getCompressedTexImageFormats(config, &internalFormat)) { - return GrGLFormat::kUnknown; + GrGLenum internalFormat = caps.getTexImageInternalFormat(format); + if (!internalFormat) { + return 0; } - GrGLFormat format = GrGLFormatFromGLEnum(internalFormat); - SkASSERT(format != GrGLFormat::kUnknown); - bool useTexStorage = caps.configSupportsTexStorage(config); + bool useTexStorage = caps.formatSupportsTexStorage(format); static constexpr int kMipLevelCount = 1; @@ -1235,7 +1234,7 @@ GrGLFormat GrGLGpu::uploadCompressedTexData(SkImage::CompressionType compression TexStorage2D(target, kMipLevelCount, internalFormat, size.width(), size.height())); GrGLenum error = CHECK_ALLOC_ERROR(this->glInterface()); if (error != GR_GL_NO_ERROR) { - return GrGLFormat::kUnknown; + return false; } GL_CALL(CompressedTexSubImage2D(target, 0, // level @@ -1258,10 +1257,10 @@ GrGLFormat GrGLGpu::uploadCompressedTexData(SkImage::CompressionType compression GrGLenum error = CHECK_ALLOC_ERROR(this->glInterface()); if (error != GR_GL_NO_ERROR) { - return GrGLFormat::kUnknown; + return false; } } - return format; + return true; } static bool renderbuffer_storage_msaa(const GrGLContext& ctx, @@ -1503,6 +1502,7 @@ sk_sp GrGLGpu::onCreateTexture(const GrSurfaceDesc& desc, } sk_sp GrGLGpu::onCreateCompressedTexture(int width, int height, + const GrBackendFormat& format, SkImage::CompressionType compression, SkBudgeted budgeted, const void* data) { GrGLTextureParameters::SamplerOverriddenState initialState; @@ -1511,8 +1511,9 @@ sk_sp GrGLGpu::onCreateCompressedTexture(int width, int height, desc.fTarget = GR_GL_TEXTURE_2D; desc.fConfig = GrCompressionTypePixelConfig(compression); desc.fOwnership = GrBackendObjectOwnership::kOwned; - desc.fID = this->createCompressedTexture2D(desc.fSize, compression, &initialState, data, - &desc.fFormat); + desc.fFormat = format.asGLFormat(); + desc.fID = this->createCompressedTexture2D(desc.fSize, desc.fFormat, compression, &initialState, + data); if (!desc.fID) { return nullptr; } @@ -1664,10 +1665,13 @@ int GrGLGpu::getCompatibleStencilIndex(GrGLFormat format) { GrGLuint GrGLGpu::createCompressedTexture2D( const SkISize& size, + GrGLFormat format, SkImage::CompressionType compression, GrGLTextureParameters::SamplerOverriddenState* initialState, - const void* data, - GrGLFormat* format) { + const void* data) { + if (format == GrGLFormat::kUnknown) { + return 0; + } GrGLuint id = 0; GL_CALL(GenTextures(1, &id)); if (!id) { @@ -1678,8 +1682,7 @@ GrGLuint GrGLGpu::createCompressedTexture2D( *initialState = set_initial_texture_params(this->glInterface(), GR_GL_TEXTURE_2D); - *format = this->uploadCompressedTexData(compression, size, GR_GL_TEXTURE_2D, data); - if (*format == GrGLFormat::kUnknown) { + if (!this->uploadCompressedTexData(format, compression, size, GR_GL_TEXTURE_2D, data)) { GL_CALL(DeleteTextures(1, &id)); return 0; } @@ -3799,7 +3802,9 @@ GrBackendTexture GrGLGpu::createBackendTexture(int w, int h, return GrBackendTexture(); // invalid } - if (!this->caps()->isConfigTexturable(config)) { + auto textureColorType = GrPixelConfigToColorType(config); + + if (!this->caps()->isFormatTexturableAndUploadable(textureColorType, format)) { return GrBackendTexture(); // invalid } @@ -3838,13 +3843,12 @@ GrBackendTexture GrGLGpu::createBackendTexture(int w, int h, srcPixels = pixelStorage.reset(size); GrFillInCompressedData(compressionType, w, h, (char*)srcPixels, *color); } - GrGLFormat format; info.fID = this->createCompressedTexture2D( - {w, h}, compressionType, &initialState, srcPixels, &format); + {w, h}, glFormat, compressionType, &initialState, srcPixels); if (!info.fID) { return GrBackendTexture(); } - info.fFormat = GrGLFormatToEnum(format); + info.fFormat = GrGLFormatToEnum(glFormat); info.fTarget = GR_GL_TEXTURE_2D; } else { if (srcPixels) { @@ -3885,7 +3889,6 @@ GrBackendTexture GrGLGpu::createBackendTexture(int w, int h, info.fTarget = GR_GL_TEXTURE_2D; info.fFormat = GrGLFormatToEnum(glFormat); // TODO: Take these as parameters. - auto textureColorType = GrPixelConfigToColorType(desc.fConfig); auto srcColorType = GrPixelConfigToColorType(desc.fConfig); info.fID = this->createTexture2D({desc.fWidth, desc.fHeight}, glFormat, diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h index 8128550410..795921676d 100644 --- a/src/gpu/gl/GrGLGpu.h +++ b/src/gpu/gl/GrGLGpu.h @@ -199,7 +199,7 @@ private: GrProtected, const GrMipLevel[], int mipLevelCount) override; - sk_sp onCreateCompressedTexture(int width, int height, + sk_sp onCreateCompressedTexture(int width, int height, const GrBackendFormat&, SkImage::CompressionType compression, SkBudgeted, const void* data) override; @@ -236,11 +236,10 @@ private: int mipLevelCount, GrMipMapsStatus* mipMapsStatus); - GrGLuint createCompressedTexture2D(const SkISize& size, + GrGLuint createCompressedTexture2D(const SkISize& size, GrGLFormat format, SkImage::CompressionType compression, GrGLTextureParameters::SamplerOverriddenState* initialState, - const void* data, - GrGLFormat* format); + const void* data); bool onReadPixels(GrSurface*, int left, int top, int width, int height, GrColorType surfaceColorType, GrColorType dstColorType, void* buffer, @@ -411,13 +410,13 @@ private: const GrMipLevel texels[], int mipLevelCount, GrMipMapsStatus* mipMapsStatus = nullptr); - // Helper for onCreateCompressedTexture. Compressed textures are read-only so we - // only use this to populate a new texture. Returns the internal format of the texture - // or kUnknown on failure. - GrGLFormat uploadCompressedTexData(SkImage::CompressionType, - const SkISize& size, - GrGLenum target, - const void* data); + // Helper for onCreateCompressedTexture. Compressed textures are read-only so we only use this + // to populate a new texture. Returns false if we failed to create and upload the texture. + bool uploadCompressedTexData(GrGLFormat, + SkImage::CompressionType, + const SkISize& size, + GrGLenum target, + const void* data); bool createRenderTargetObjects(const GrGLTexture::Desc&, int sampleCount, diff --git a/src/gpu/gradients/GrGradientShader.cpp b/src/gpu/gradients/GrGradientShader.cpp index 03649c84af..241c6e9de7 100644 --- a/src/gpu/gradients/GrGradientShader.cpp +++ b/src/gpu/gradients/GrGradientShader.cpp @@ -45,9 +45,12 @@ static std::unique_ptr make_textured_colorizer(const SkPMCo // Use 8888 or F16, depending on the destination config. // TODO: Use 1010102 for opaque gradients, at least if destination is 1010102? SkColorType colorType = kRGBA_8888_SkColorType; - if (GrColorTypeIsWiderThan(args.fDstColorSpaceInfo->colorType(), 8) && - args.fContext->priv().caps()->isConfigTexturable(kRGBA_half_GrPixelConfig)) { - colorType = kRGBA_F16_SkColorType; + if (GrColorTypeIsWiderThan(args.fDstColorSpaceInfo->colorType(), 8)) { + auto f16Format = args.fContext->priv().caps()->getDefaultBackendFormat( + GrColorType::kRGBA_F16, GrRenderable::kNo); + if (f16Format.isValid()) { + colorType = kRGBA_F16_SkColorType; + } } SkAlphaType alphaType = premul ? kPremul_SkAlphaType : kUnpremul_SkAlphaType; diff --git a/src/gpu/mock/GrMockCaps.h b/src/gpu/mock/GrMockCaps.h index ceb1317378..099370df4b 100644 --- a/src/gpu/mock/GrMockCaps.h +++ b/src/gpu/mock/GrMockCaps.h @@ -49,16 +49,15 @@ public: return false; } - bool isFormatTexturable(GrColorType, const GrBackendFormat& format) const override { + bool isFormatTexturableAndUploadable(GrColorType, + const GrBackendFormat& format) const override { + return this->isFormatTexturable(format); + } + bool isFormatTexturable(const GrBackendFormat& format) const override { auto index = static_cast(format.asMockColorType()); return fOptions.fConfigOptions[index].fTexturable; } - bool isConfigTexturable(GrPixelConfig config) const override { - GrColorType ct = GrPixelConfigToColorType(config); - return fOptions.fConfigOptions[(int)ct].fTexturable; - } - bool isFormatCopyable(const GrBackendFormat& format) const override { return false; } diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp index d588a5de73..030b2af7bf 100644 --- a/src/gpu/mock/GrMockGpu.cpp +++ b/src/gpu/mock/GrMockGpu.cpp @@ -170,7 +170,7 @@ sk_sp GrMockGpu::onCreateTexture(const GrSurfaceDesc& desc, new GrMockTexture(this, budgeted, desc, isProtected, mipMapsStatus, texInfo)); } -sk_sp GrMockGpu::onCreateCompressedTexture(int width, int height, +sk_sp GrMockGpu::onCreateCompressedTexture(int width, int height, const GrBackendFormat&, SkImage::CompressionType compressionType, SkBudgeted budgeted, const void* data) { return nullptr; @@ -278,7 +278,7 @@ GrBackendTexture GrMockGpu::createBackendTexture(int w, int h, const SkColor4f* /* color */, GrProtected /* isProtected */) { auto colorType = format.asMockColorType(); - if (!this->caps()->isFormatTexturable(colorType, format)) { + if (!this->caps()->isFormatTexturable(format)) { return GrBackendTexture(); // invalid } diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h index 735627e07e..744c770818 100644 --- a/src/gpu/mock/GrMockGpu.h +++ b/src/gpu/mock/GrMockGpu.h @@ -69,8 +69,9 @@ private: const GrMipLevel[], int mipLevelCount) override; - sk_sp onCreateCompressedTexture(int width, int height, SkImage::CompressionType, - SkBudgeted, const void* data) override; + sk_sp onCreateCompressedTexture(int width, int height, const GrBackendFormat&, + SkImage::CompressionType, SkBudgeted, + const void* data) override; sk_sp onWrapBackendTexture(const GrBackendTexture&, GrColorType, GrWrapOwnership, GrWrapCacheable, GrIOType) override; diff --git a/src/gpu/mtl/GrMtlCaps.h b/src/gpu/mtl/GrMtlCaps.h index 336a381bb2..24ac0cc01b 100644 --- a/src/gpu/mtl/GrMtlCaps.h +++ b/src/gpu/mtl/GrMtlCaps.h @@ -29,8 +29,8 @@ public: bool isFormatSRGB(const GrBackendFormat&) const override; bool isFormatCompressed(const GrBackendFormat&) const override; - bool isFormatTexturable(GrColorType, const GrBackendFormat&) const override; - bool isConfigTexturable(GrPixelConfig config) const override; + bool isFormatTexturableAndUploadable(GrColorType, const GrBackendFormat&) const override; + bool isFormatTexturable(const GrBackendFormat&) const override; bool isFormatTexturable(MTLPixelFormat) const; bool isFormatCopyable(const GrBackendFormat&) const override { return true; } @@ -128,12 +128,12 @@ private: } enum { - kTextureable_Flag = 0x1, + kTexturable_Flag = 0x1, kRenderable_Flag = 0x2, // Color attachment and blendable kMSAA_Flag = 0x4, kResolve_Flag = 0x8, }; - static const uint16_t kAllFlags = kTextureable_Flag | kRenderable_Flag | + static const uint16_t kAllFlags = kTexturable_Flag | kRenderable_Flag | kMSAA_Flag | kResolve_Flag; uint16_t fFlags = 0; diff --git a/src/gpu/mtl/GrMtlCaps.mm b/src/gpu/mtl/GrMtlCaps.mm index 04da126611..065c0f44ed 100644 --- a/src/gpu/mtl/GrMtlCaps.mm +++ b/src/gpu/mtl/GrMtlCaps.mm @@ -286,7 +286,8 @@ bool GrMtlCaps::isFormatCompressed(const GrBackendFormat& format) const { #endif } -bool GrMtlCaps::isFormatTexturable(GrColorType ct, const GrBackendFormat& format) const { +bool GrMtlCaps::isFormatTexturableAndUploadable(GrColorType ct, + const GrBackendFormat& format) const { MTLPixelFormat mtlFormat = GrBackendFormatAsMTLPixelFormat(format); uint32_t ctFlags = this->getFormatInfo(mtlFormat).colorTypeFlags(ct); @@ -294,20 +295,14 @@ bool GrMtlCaps::isFormatTexturable(GrColorType ct, const GrBackendFormat& format SkToBool(ctFlags & ColorTypeInfo::kUploadData_Flag); } -bool GrMtlCaps::isConfigTexturable(GrPixelConfig config) const { - MTLPixelFormat format; - if (!GrPixelConfigToMTLFormat(config, &format)) { - return false; - } - GrColorType ct = GrPixelConfigToColorType(config); - uint32_t ctFlags = this->getFormatInfo(format).colorTypeFlags(ct); - return this->isFormatTexturable(format) && - SkToBool(ctFlags & ColorTypeInfo::kUploadData_Flag); +bool GrMtlCaps::isFormatTexturable(const GrBackendFormat& format) const { + MTLPixelFormat mtlFormat = GrBackendFormatAsMTLPixelFormat(format); + return this->isFormatTexturable(mtlFormat); } bool GrMtlCaps::isFormatTexturable(MTLPixelFormat format) const { const FormatInfo& formatInfo = this->getFormatInfo(format); - return SkToBool(FormatInfo::kTextureable_Flag && formatInfo.fFlags); + return SkToBool(FormatInfo::kTexturable_Flag && formatInfo.fFlags); } bool GrMtlCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, @@ -483,7 +478,7 @@ void GrMtlCaps::initFormatTable() { // Format: A8Unorm { info = &fFormatTable[GetFormatIndex(MTLPixelFormatA8Unorm)]; - info->fFlags = FormatInfo::kTextureable_Flag; + info->fFlags = FormatInfo::kTexturable_Flag; info->fColorTypeInfoCount = 1; info->fColorTypeInfos.reset(new ColorTypeInfo[info->fColorTypeInfoCount]()); int ctIdx = 0; @@ -553,7 +548,7 @@ void GrMtlCaps::initFormatTable() { // Format: RG8Unorm { info = &fFormatTable[GetFormatIndex(MTLPixelFormatRG8Unorm)]; - info->fFlags = FormatInfo::kTextureable_Flag; + info->fFlags = FormatInfo::kTexturable_Flag; info->fColorTypeInfoCount = 1; info->fColorTypeInfos.reset(new ColorTypeInfo[info->fColorTypeInfoCount]()); int ctIdx = 0; @@ -601,7 +596,7 @@ void GrMtlCaps::initFormatTable() { if (this->isMac() || fFamilyGroup >= 3) { info->fFlags = FormatInfo::kAllFlags; } else { - info->fFlags = FormatInfo::kTextureable_Flag; + info->fFlags = FormatInfo::kTexturable_Flag; } info->fColorTypeInfoCount = 1; info->fColorTypeInfos.reset(new ColorTypeInfo[info->fColorTypeInfoCount]()); @@ -677,7 +672,7 @@ void GrMtlCaps::initFormatTable() { if (this->isMac()) { info->fFlags = FormatInfo::kAllFlags; } else { - info->fFlags = FormatInfo::kTextureable_Flag | FormatInfo::kRenderable_Flag; + info->fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kRenderable_Flag; } info->fColorTypeInfoCount = 1; info->fColorTypeInfos.reset(new ColorTypeInfo[info->fColorTypeInfoCount]()); @@ -696,7 +691,7 @@ void GrMtlCaps::initFormatTable() { if (this->isMac()) { info->fFlags = FormatInfo::kAllFlags; } else { - info->fFlags = FormatInfo::kTextureable_Flag | FormatInfo::kRenderable_Flag; + info->fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kRenderable_Flag; } info->fColorTypeInfoCount = 1; info->fColorTypeInfos.reset(new ColorTypeInfo[info->fColorTypeInfoCount]()); @@ -725,7 +720,7 @@ void GrMtlCaps::initFormatTable() { if (this->isMac()) { info->fFlags = FormatInfo::kAllFlags; } else { - info->fFlags = FormatInfo::kTextureable_Flag | FormatInfo::kRenderable_Flag; + info->fFlags = FormatInfo::kTexturable_Flag | FormatInfo::kRenderable_Flag; } info->fColorTypeInfoCount = 1; info->fColorTypeInfos.reset(new ColorTypeInfo[info->fColorTypeInfoCount]()); diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h index a3c4432e33..9927b16417 100644 --- a/src/gpu/mtl/GrMtlGpu.h +++ b/src/gpu/mtl/GrMtlGpu.h @@ -143,8 +143,9 @@ private: GrProtected, const GrMipLevel texels[], int mipLevelCount) override; - sk_sp onCreateCompressedTexture(int width, int height, SkImage::CompressionType, - SkBudgeted, const void* data) override { + sk_sp onCreateCompressedTexture(int width, int height, const GrBackendFormat&, + SkImage::CompressionType, SkBudgeted, + const void* data) override { return nullptr; } diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm index 1d3141f6aa..d26f3e0204 100644 --- a/src/gpu/mtl/GrMtlGpu.mm +++ b/src/gpu/mtl/GrMtlGpu.mm @@ -193,7 +193,7 @@ static bool check_max_blit_width(int widthInPixels) { bool GrMtlGpu::uploadToTexture(GrMtlTexture* tex, int left, int top, int width, int height, GrColorType dataColorType, const GrMipLevel texels[], int mipLevelCount) { - SkASSERT(this->caps()->isConfigTexturable(tex->config())); + SkASSERT(this->caps()->isFormatTexturable(tex->backendFormat())); // The assumption is either that we have no mipmaps, or that our rect is the entire texture SkASSERT(1 == mipLevelCount || (0 == left && 0 == top && width == tex->width() && height == tex->height())); @@ -288,7 +288,7 @@ bool GrMtlGpu::uploadToTexture(GrMtlTexture* tex, int left, int top, int width, } bool GrMtlGpu::clearTexture(GrMtlTexture* tex, GrColorType dataColorType, uint32_t levelMask) { - SkASSERT(this->caps()->isFormatTexturable(dataColorType, tex->backendFormat())); + SkASSERT(this->caps()->isFormatTexturableAndUploadable(dataColorType, tex->backendFormat())); if (!levelMask) { return true; diff --git a/src/gpu/text/GrAtlasManager.h b/src/gpu/text/GrAtlasManager.h index 0f31202a6d..1a2871e7a9 100644 --- a/src/gpu/text/GrAtlasManager.h +++ b/src/gpu/text/GrAtlasManager.h @@ -34,7 +34,8 @@ public: // GrStrikeCache.cpp GrMaskFormat resolveMaskFormat(GrMaskFormat format) const { if (kA565_GrMaskFormat == format && - !fProxyProvider->caps()->isConfigTexturable(kRGB_565_GrPixelConfig)) { + !fProxyProvider->caps()->getDefaultBackendFormat(GrColorType::kBGR_565, + GrRenderable::kNo).isValid()) { format = kARGB_GrMaskFormat; } return format; diff --git a/src/gpu/vk/GrVkCaps.cpp b/src/gpu/vk/GrVkCaps.cpp index 83765421b7..bf62ee5ddb 100644 --- a/src/gpu/vk/GrVkCaps.cpp +++ b/src/gpu/vk/GrVkCaps.cpp @@ -681,7 +681,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice { auto& info = this->getFormatInfo(VK_FORMAT_R8G8B8A8_UNORM); info.init(interface, physDev, properties, VK_FORMAT_R8G8B8A8_UNORM); - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 2; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -705,7 +705,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice { auto& info = this->getFormatInfo(VK_FORMAT_R8_UNORM); info.init(interface, physDev, properties, VK_FORMAT_R8_UNORM); - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 2; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -730,7 +730,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice { auto& info = this->getFormatInfo(VK_FORMAT_B8G8R8A8_UNORM); info.init(interface, physDev, properties, VK_FORMAT_B8G8R8A8_UNORM); - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -746,7 +746,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice { auto& info = this->getFormatInfo(VK_FORMAT_R5G6B5_UNORM_PACK16); info.init(interface, physDev, properties, VK_FORMAT_R5G6B5_UNORM_PACK16); - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -762,7 +762,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice { auto& info = this->getFormatInfo(VK_FORMAT_R16G16B16A16_SFLOAT); info.init(interface, physDev, properties, VK_FORMAT_R16G16B16A16_SFLOAT); - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 2; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -784,7 +784,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice { auto& info = this->getFormatInfo(VK_FORMAT_R16_SFLOAT); info.init(interface, physDev, properties, VK_FORMAT_R16_SFLOAT); - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -802,7 +802,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice { auto& info = this->getFormatInfo(VK_FORMAT_R8G8B8_UNORM); info.init(interface, physDev, properties, VK_FORMAT_R8G8B8_UNORM); - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -818,7 +818,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice { auto& info = this->getFormatInfo(VK_FORMAT_R8G8_UNORM); info.init(interface, physDev, properties, VK_FORMAT_R8G8_UNORM); - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -834,7 +834,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice { auto& info = this->getFormatInfo(VK_FORMAT_A2B10G10R10_UNORM_PACK32); info.init(interface, physDev, properties, VK_FORMAT_A2B10G10R10_UNORM_PACK32); - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -850,7 +850,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice { auto& info = this->getFormatInfo(VK_FORMAT_B4G4R4A4_UNORM_PACK16); info.init(interface, physDev, properties, VK_FORMAT_B4G4R4A4_UNORM_PACK16); - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -868,7 +868,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice { auto& info = this->getFormatInfo(VK_FORMAT_R4G4B4A4_UNORM_PACK16); info.init(interface, physDev, properties, VK_FORMAT_R4G4B4A4_UNORM_PACK16); - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -884,7 +884,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice { auto& info = this->getFormatInfo(VK_FORMAT_R32G32B32A32_SFLOAT); info.init(interface, physDev, properties, VK_FORMAT_R32G32B32A32_SFLOAT); - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -902,7 +902,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice if (fSRGBSupport) { info.init(interface, physDev, properties, VK_FORMAT_R8G8B8A8_SRGB); } - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -918,7 +918,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice { auto& info = this->getFormatInfo(VK_FORMAT_R16_UNORM); info.init(interface, physDev, properties, VK_FORMAT_R16_UNORM); - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -934,7 +934,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice { auto& info = this->getFormatInfo(VK_FORMAT_R16G16_UNORM); info.init(interface, physDev, properties, VK_FORMAT_R16G16_UNORM); - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -950,7 +950,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice { auto& info = this->getFormatInfo(VK_FORMAT_R16G16B16A16_UNORM); info.init(interface, physDev, properties, VK_FORMAT_R16G16B16A16_UNORM); - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -966,7 +966,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice { auto& info = this->getFormatInfo(VK_FORMAT_R16G16_SFLOAT); info.init(interface, physDev, properties, VK_FORMAT_R16G16_SFLOAT); - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -984,7 +984,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice if (fSupportsYcbcrConversion) { info.init(interface, physDev, properties, VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM); } - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -1002,7 +1002,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice if (fSupportsYcbcrConversion) { info.init(interface, physDev, properties, VK_FORMAT_G8_B8R8_2PLANE_420_UNORM); } - if (SkToBool(info.fOptimalFlags & FormatInfo::kTextureable_Flag)) { + if (SkToBool(info.fOptimalFlags & FormatInfo::kTexturable_Flag)) { info.fColorTypeInfoCount = 1; info.fColorTypeInfos.reset(new ColorTypeInfo[info.fColorTypeInfoCount]()); int ctIdx = 0; @@ -1025,7 +1025,7 @@ void GrVkCaps::initFormatTable(const GrVkInterface* interface, VkPhysicalDevice void GrVkCaps::FormatInfo::InitFormatFlags(VkFormatFeatureFlags vkFlags, uint16_t* flags) { if (SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT & vkFlags) && SkToBool(VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT & vkFlags)) { - *flags = *flags | kTextureable_Flag; + *flags = *flags | kTexturable_Flag; // Ganesh assumes that all renderable surfaces are also texturable if (SkToBool(VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT & vkFlags)) { @@ -1126,7 +1126,8 @@ bool GrVkCaps::isFormatCompressed(const GrBackendFormat& format) const { return vkFormat == VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK; } -bool GrVkCaps::isFormatTexturable(GrColorType ct, const GrBackendFormat& format) const { +bool GrVkCaps::isFormatTexturableAndUploadable(GrColorType ct, + const GrBackendFormat& format) const { VkFormat vkFormat; if (!format.asVkFormat(&vkFormat)) { return false; @@ -1137,20 +1138,17 @@ bool GrVkCaps::isFormatTexturable(GrColorType ct, const GrBackendFormat& format) SkToBool(ctFlags & ColorTypeInfo::kUploadData_Flag); } -bool GrVkCaps::isVkFormatTexturable(VkFormat format) const { - const FormatInfo& info = this->getFormatInfo(format); - return SkToBool(FormatInfo::kTextureable_Flag & info.fOptimalFlags); -} - -bool GrVkCaps::isConfigTexturable(GrPixelConfig config) const { - VkFormat format; - if (!GrPixelConfigToVkFormat(config, &format)) { +bool GrVkCaps::isFormatTexturable(const GrBackendFormat& format) const { + VkFormat vkFormat; + if (!format.asVkFormat(&vkFormat)) { return false; } - GrColorType ct = GrPixelConfigToColorType(config); - uint32_t ctFlags = this->getFormatInfo(format).colorTypeFlags(ct); - return this->isVkFormatTexturable(format) && - SkToBool(ctFlags & ColorTypeInfo::kUploadData_Flag); + return this->isVkFormatTexturable(vkFormat); +} + +bool GrVkCaps::isVkFormatTexturable(VkFormat format) const { + const FormatInfo& info = this->getFormatInfo(format); + return SkToBool(FormatInfo::kTexturable_Flag & info.fOptimalFlags); } bool GrVkCaps::isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat& format, diff --git a/src/gpu/vk/GrVkCaps.h b/src/gpu/vk/GrVkCaps.h index 21e5bfb863..5d428c8a25 100644 --- a/src/gpu/vk/GrVkCaps.h +++ b/src/gpu/vk/GrVkCaps.h @@ -36,9 +36,9 @@ public: bool isFormatCompressed(const GrBackendFormat&) const override; - bool isFormatTexturable(GrColorType, const GrBackendFormat&) const override; + bool isFormatTexturableAndUploadable(GrColorType, const GrBackendFormat&) const override; + bool isFormatTexturable(const GrBackendFormat&) const override; bool isVkFormatTexturable(VkFormat) const; - bool isConfigTexturable(GrPixelConfig config) const override; bool isFormatCopyable(const GrBackendFormat&) const override { return true; } @@ -60,7 +60,7 @@ public: SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override; bool isVkFormatTexturableLinearly(VkFormat format) const { - return SkToBool(FormatInfo::kTextureable_Flag & this->getFormatInfo(format).fLinearFlags); + return SkToBool(FormatInfo::kTexturable_Flag & this->getFormatInfo(format).fLinearFlags); } bool formatCanBeDstofBlit(VkFormat format, bool linearTiled) const { @@ -239,10 +239,10 @@ private: const VkPhysicalDeviceProperties&, VkFormat); enum { - kTextureable_Flag = 0x1, - kRenderable_Flag = 0x2, - kBlitSrc_Flag = 0x4, - kBlitDst_Flag = 0x8, + kTexturable_Flag = 0x1, + kRenderable_Flag = 0x2, + kBlitSrc_Flag = 0x4, + kBlitDst_Flag = 0x8, }; uint16_t fOptimalFlags = 0; diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index a989b72b71..05109f4ea3 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -1054,9 +1054,9 @@ sk_sp GrVkGpu::onCreateTexture(const GrSurfaceDesc& desc, } sk_sp GrVkGpu::onCreateCompressedTexture(int width, int height, + const GrBackendFormat& format, SkImage::CompressionType compressionType, SkBudgeted budgeted, const void* data) { - GrBackendFormat format = this->caps()->getBackendFormatFromCompressionType(compressionType); VkFormat pixelFormat; if (!format.asVkFormat(&pixelFormat)) { return nullptr; diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h index c16384296b..ca175e5dbb 100644 --- a/src/gpu/vk/GrVkGpu.h +++ b/src/gpu/vk/GrVkGpu.h @@ -199,8 +199,9 @@ private: GrProtected, const GrMipLevel[], int mipLevelCount) override; - sk_sp onCreateCompressedTexture(int width, int height, SkImage::CompressionType, - SkBudgeted, const void* data) override; + sk_sp onCreateCompressedTexture(int width, int height, const GrBackendFormat&, + SkImage::CompressionType, SkBudgeted, + const void* data) override; sk_sp onWrapBackendTexture(const GrBackendTexture&, GrColorType, GrWrapOwnership, GrWrapCacheable, GrIOType) override; diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index 3c568bb116..f50110f6b7 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -418,7 +418,7 @@ static bool validate_backend_texture(const GrCaps* caps, const GrBackendTexture& return false; } - if (texturable && !caps->isFormatTexturable(grCT, backendFormat)) { + if (texturable && !caps->isFormatTexturable(backendFormat)) { return false; } diff --git a/tests/BackendAllocationTest.cpp b/tests/BackendAllocationTest.cpp index 47b279b45a..70a1c6b6b2 100644 --- a/tests/BackendAllocationTest.cpp +++ b/tests/BackendAllocationTest.cpp @@ -433,10 +433,6 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ColorTypeBackendAllocationTest, reporter, ctx for (auto combo : combinations) { SkColorType colorType = combo.fColorType; - if (!caps->isConfigTexturable(combo.fConfig)) { - continue; - } - if (GrBackendApi::kMetal == context->backend()) { // skbug.com/9086 (Metal caps may not be handling RGBA32 correctly) if (kRGBA_F32_SkColorType == combo.fColorType) { @@ -450,15 +446,15 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ColorTypeBackendAllocationTest, reporter, ctx } for (auto renderable : { GrRenderable::kNo, GrRenderable::kYes }) { + if (!caps->getDefaultBackendFormat(SkColorTypeToGrColorType(colorType), + renderable).isValid()) { + continue; + } if (GrRenderable::kYes == renderable) { if (kRGB_888x_SkColorType == combo.fColorType) { // Ganesh can't perform the blends correctly when rendering this format continue; } - if (!caps->getDefaultBackendFormat(SkColorTypeToGrColorType(colorType), - renderable).isValid()) { - continue; - } } { @@ -593,7 +589,7 @@ DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(GLBackendAllocationTest, reporter, ctxInfo) { for (auto combo : combinations) { GrBackendFormat format = GrBackendFormat::MakeGL(combo.fFormat, GR_GL_TEXTURE_2D); - if (!glCaps->isFormatTexturable(combo.fColorType, format)) { + if (!glCaps->isFormatTexturable(format)) { continue; } diff --git a/tests/CopySurfaceTest.cpp b/tests/CopySurfaceTest.cpp index c3095ea17d..dbdfc6af51 100644 --- a/tests/CopySurfaceTest.cpp +++ b/tests/CopySurfaceTest.cpp @@ -92,9 +92,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CopySurface, reporter, ctxInfo) { continue; } } else { - GrPixelConfig config = - SkColorType2GrPixelConfig(kBGRA_8888_SkColorType); - if (!context->priv().caps()->isConfigTexturable(config)) { + if (!context->defaultBackendFormat( + kBGRA_8888_SkColorType, GrRenderable::kNo).isValid()) { continue; } if (!src || !dst) { diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp index ae2367c984..f07fdd52ed 100644 --- a/tests/GrSurfaceTest.cpp +++ b/tests/GrSurfaceTest.cpp @@ -73,7 +73,7 @@ DEF_GPUTEST_FOR_MOCK_CONTEXT(GrSurface, reporter, ctxInfo) { context->deleteBackendTexture(backendTex); } -// This test checks that the isConfigTexturable and isConfigRenderable are +// This test checks that the isFormatTexturable and isFormatRenderable are // consistent with createTexture's result. DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) { GrContext* context = ctxInfo.grContext(); @@ -106,7 +106,8 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) { auto data = SkData::MakeUninitialized(size); SkColor4f color = {0, 0, 0, 0}; GrFillInCompressedData(type, width, height, (char*)data->writable_data(), color); - return rp->createCompressedTexture(width, height, SkImage::kETC1_CompressionType, + return rp->createCompressedTexture(width, height, format, + SkImage::kETC1_CompressionType, SkBudgeted::kNo, data.get()); } else { GrSurfaceDesc desc; @@ -146,7 +147,15 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GrSurfaceRenderability, reporter, ctxInfo) { // Check if 'isFormatTexturable' agrees with 'createTexture' and that the mipmap // support check is working { - bool isTexturable = caps->isFormatTexturable(combo.fColorType, combo.fFormat); + + bool compressed = caps->isFormatCompressed(combo.fFormat); + bool isTexturable; + if (compressed) { + isTexturable = caps->isFormatTexturable(combo.fFormat); + } else { + isTexturable = caps->isFormatTexturableAndUploadable(combo.fColorType, + combo.fFormat); + } sk_sp tex = createTexture(kW, kH, combo.fColorType, combo.fFormat, GrRenderable::kNo, resourceProvider); @@ -246,7 +255,7 @@ DEF_GPUTEST(InitialTextureClear, reporter, baseOptions) { SkASSERT(combo.fColorType != GrColorType::kUnknown); SkASSERT(combo.fFormat.isValid()); - if (!caps->isFormatTexturable(combo.fColorType, combo.fFormat)) { + if (!caps->isFormatTexturableAndUploadable(combo.fColorType, combo.fFormat)) { continue; } diff --git a/tools/gpu/ProxyUtils.cpp b/tools/gpu/ProxyUtils.cpp index 1ecb651bb6..11e9e60de4 100644 --- a/tools/gpu/ProxyUtils.cpp +++ b/tools/gpu/ProxyUtils.cpp @@ -60,13 +60,8 @@ sk_sp MakeTextureProxyFromData(GrContext* context, } } else { - GrPixelConfig config = GrColorTypeToPixelConfig(colorType); - if (!context->priv().caps()->isConfigTexturable(config)) { - return nullptr; - } - GrSurfaceDesc desc; - desc.fConfig = config; + desc.fConfig = GrColorTypeToPixelConfig(colorType); desc.fWidth = width; desc.fHeight = height; proxy = context->priv().proxyProvider()->createProxy(format, desc, renderable, 1, origin,