Make GrCaps::surfaceSupportsReadPixels return distinct values rather than flags.

Change-Id: I2744ca6cb0e9f1f2fd7d20e293400c788e7d4083
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/224960
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2019-07-01 14:59:32 -04:00 committed by Skia Commit-Bot
parent 45dc1f0001
commit dc0710f2a2
8 changed files with 35 additions and 28 deletions

View File

@ -204,24 +204,29 @@ public:
*/ */
bool surfaceSupportsWritePixels(const GrSurface*) const; bool surfaceSupportsWritePixels(const GrSurface*) const;
/** /**
* Indicates whether surface supports readPixels or the alternatives. * Indicates whether surface supports GrGpu::readPixels, must be copied, or cannot be read.
*/ */
enum ReadFlags { enum class SurfaceReadPixelsSupport {
kSupported_ReadFlag = 0x0, /** GrGpu::readPixels is supported by the surface. */
kRequiresCopy_ReadFlag = 0x1, kSupported,
kProtected_ReadFlag = 0x2, /**
* GrGpu::readPixels is not supported by this surface but this surface can be drawn
* or copied to a Ganesh-created GrTextureType::kTexture2D and then that surface will be
* readable.
*/
kCopyToTexture2D,
/**
* Not supported
*/
kUnsupported,
}; };
/** /**
* Backends may have restrictions on what types of surfaces support GrGpu::readPixels(). * Backends may have restrictions on what types of surfaces support GrGpu::readPixels(). We may
* If this returns kRequiresCopy_ReadFlag then the caller should implement a fallback where a * either be able to read directly from the surface, read from a copy of the surface, or not
* temporary texture is created, the surface is drawn or copied into the temporary, and * read at all.
* pixels are read from the temporary. If this returns kProtected_ReadFlag, then the caller
* should not attempt reading it.
*/ */
virtual ReadFlags surfaceSupportsReadPixels(const GrSurface*) const = 0; virtual SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const = 0;
/** /**
* Given a dst pixel config and a src color type what color type must the caller coax the * Given a dst pixel config and a src color type what color type must the caller coax the

View File

@ -119,11 +119,11 @@ bool GrSurfaceContext::readPixels(const GrPixelInfo& origDstInfo, void* dst, siz
direct->priv().validPMUPMConversionExists(); direct->priv().validPMUPMConversionExists();
auto readFlag = caps->surfaceSupportsReadPixels(srcSurface); auto readFlag = caps->surfaceSupportsReadPixels(srcSurface);
if (readFlag == GrCaps::kProtected_ReadFlag) { if (readFlag == GrCaps::SurfaceReadPixelsSupport::kUnsupported) {
return false; return false;
} }
if (readFlag == GrCaps::kRequiresCopy_ReadFlag || canvas2DFastPath) { if (readFlag == GrCaps::SurfaceReadPixelsSupport::kCopyToTexture2D || canvas2DFastPath) {
GrBackendFormat format; GrBackendFormat format;
GrPixelConfig config; GrPixelConfig config;
GrColorType colorType; GrColorType colorType;

View File

@ -3392,15 +3392,16 @@ bool GrGLCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const {
return true; return true;
} }
GrCaps::ReadFlags GrGLCaps::surfaceSupportsReadPixels(const GrSurface* surface) const { GrCaps::SurfaceReadPixelsSupport GrGLCaps::surfaceSupportsReadPixels(
const GrSurface* surface) const {
if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) { if (auto tex = static_cast<const GrGLTexture*>(surface->asTexture())) {
// We don't support reading pixels directly from EXTERNAL textures as it would require // We don't support reading pixels directly from EXTERNAL textures as it would require
// binding the texture to a FBO. // binding the texture to a FBO.
if (tex->target() == GR_GL_TEXTURE_EXTERNAL) { if (tex->target() == GR_GL_TEXTURE_EXTERNAL) {
return kRequiresCopy_ReadFlag; return SurfaceReadPixelsSupport::kCopyToTexture2D;
} }
} }
return kSupported_ReadFlag; return SurfaceReadPixelsSupport::kSupported;
} }
GrCaps::SupportedRead GrGLCaps::supportedReadPixelsColorType(GrPixelConfig srcPixelConfig, GrCaps::SupportedRead GrGLCaps::supportedReadPixelsColorType(GrPixelConfig srcPixelConfig,

View File

@ -320,7 +320,7 @@ public:
/// Use indices or vertices in CPU arrays rather than VBOs for dynamic content. /// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
bool useNonVBOVertexAndIndexDynamicData() const { return fUseNonVBOVertexAndIndexDynamicData; } bool useNonVBOVertexAndIndexDynamicData() const { return fUseNonVBOVertexAndIndexDynamicData; }
ReadFlags surfaceSupportsReadPixels(const GrSurface*) const override; SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override;
SupportedRead supportedReadPixelsColorType(GrPixelConfig, const GrBackendFormat&, SupportedRead supportedReadPixelsColorType(GrPixelConfig, const GrBackendFormat&,
GrColorType) const override; GrColorType) const override;

View File

@ -110,8 +110,8 @@ public:
return 0; return 0;
} }
ReadFlags surfaceSupportsReadPixels(const GrSurface*) const override { SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override {
return kSupported_ReadFlag; return SurfaceReadPixelsSupport::kSupported;
} }
bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc, bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,

View File

@ -41,8 +41,8 @@ public:
int maxRenderTargetSampleCount(SkColorType, const GrBackendFormat&) const override; int maxRenderTargetSampleCount(SkColorType, const GrBackendFormat&) const override;
int maxRenderTargetSampleCount(GrPixelConfig) const override; int maxRenderTargetSampleCount(GrPixelConfig) const override;
ReadFlags surfaceSupportsReadPixels(const GrSurface*) const override { SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override {
return kSupported_ReadFlag; return SurfaceReadPixelsSupport::kSupported;
} }
bool isFormatCopyable(SkColorType, const GrBackendFormat&) const override { return true; } bool isFormatCopyable(SkColorType, const GrBackendFormat&) const override { return true; }

View File

@ -900,17 +900,18 @@ int GrVkCaps::maxRenderTargetSampleCount(VkFormat format) const {
return table[table.count() - 1]; return table[table.count() - 1];
} }
GrCaps::ReadFlags GrVkCaps::surfaceSupportsReadPixels(const GrSurface* surface) const { GrCaps::SurfaceReadPixelsSupport GrVkCaps::surfaceSupportsReadPixels(
const GrSurface* surface) const {
if (surface->isProtected()) { if (surface->isProtected()) {
return kProtected_ReadFlag; return SurfaceReadPixelsSupport::kUnsupported;
} }
if (auto tex = static_cast<const GrVkTexture*>(surface->asTexture())) { if (auto tex = static_cast<const GrVkTexture*>(surface->asTexture())) {
// We can't directly read from a VkImage that has a ycbcr sampler. // We can't directly read from a VkImage that has a ycbcr sampler.
if (tex->ycbcrConversionInfo().isValid()) { if (tex->ycbcrConversionInfo().isValid()) {
return kRequiresCopy_ReadFlag; return SurfaceReadPixelsSupport::kCopyToTexture2D;
} }
} }
return kSupported_ReadFlag; return SurfaceReadPixelsSupport::kSupported;
} }
bool GrVkCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const { bool GrVkCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const {

View File

@ -52,7 +52,7 @@ public:
int maxRenderTargetSampleCount(GrPixelConfig config) const override; int maxRenderTargetSampleCount(GrPixelConfig config) const override;
int maxRenderTargetSampleCount(VkFormat format) const; int maxRenderTargetSampleCount(VkFormat format) const;
ReadFlags surfaceSupportsReadPixels(const GrSurface*) const override; SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override;
bool isFormatTexturableLinearly(VkFormat format) const { bool isFormatTexturableLinearly(VkFormat format) const {
return SkToBool(FormatInfo::kTextureable_Flag & this->getFormatInfo(format).fLinearFlags); return SkToBool(FormatInfo::kTextureable_Flag & this->getFormatInfo(format).fLinearFlags);