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:
parent
45dc1f0001
commit
dc0710f2a2
@ -204,24 +204,29 @@ public:
|
||||
*/
|
||||
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 {
|
||||
kSupported_ReadFlag = 0x0,
|
||||
kRequiresCopy_ReadFlag = 0x1,
|
||||
kProtected_ReadFlag = 0x2,
|
||||
enum class SurfaceReadPixelsSupport {
|
||||
/** GrGpu::readPixels is supported by the surface. */
|
||||
kSupported,
|
||||
/**
|
||||
* 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().
|
||||
* If this returns kRequiresCopy_ReadFlag then the caller should implement a fallback where a
|
||||
* temporary texture is created, the surface is drawn or copied into the temporary, and
|
||||
* pixels are read from the temporary. If this returns kProtected_ReadFlag, then the caller
|
||||
* should not attempt reading it.
|
||||
* Backends may have restrictions on what types of surfaces support GrGpu::readPixels(). We may
|
||||
* either be able to read directly from the surface, read from a copy of the surface, or not
|
||||
* read at all.
|
||||
*/
|
||||
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
|
||||
|
@ -119,11 +119,11 @@ bool GrSurfaceContext::readPixels(const GrPixelInfo& origDstInfo, void* dst, siz
|
||||
direct->priv().validPMUPMConversionExists();
|
||||
|
||||
auto readFlag = caps->surfaceSupportsReadPixels(srcSurface);
|
||||
if (readFlag == GrCaps::kProtected_ReadFlag) {
|
||||
if (readFlag == GrCaps::SurfaceReadPixelsSupport::kUnsupported) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (readFlag == GrCaps::kRequiresCopy_ReadFlag || canvas2DFastPath) {
|
||||
if (readFlag == GrCaps::SurfaceReadPixelsSupport::kCopyToTexture2D || canvas2DFastPath) {
|
||||
GrBackendFormat format;
|
||||
GrPixelConfig config;
|
||||
GrColorType colorType;
|
||||
|
@ -3392,15 +3392,16 @@ bool GrGLCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const {
|
||||
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())) {
|
||||
// We don't support reading pixels directly from EXTERNAL textures as it would require
|
||||
// binding the texture to a FBO.
|
||||
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,
|
||||
|
@ -320,7 +320,7 @@ public:
|
||||
/// Use indices or vertices in CPU arrays rather than VBOs for dynamic content.
|
||||
bool useNonVBOVertexAndIndexDynamicData() const { return fUseNonVBOVertexAndIndexDynamicData; }
|
||||
|
||||
ReadFlags surfaceSupportsReadPixels(const GrSurface*) const override;
|
||||
SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override;
|
||||
SupportedRead supportedReadPixelsColorType(GrPixelConfig, const GrBackendFormat&,
|
||||
GrColorType) const override;
|
||||
|
||||
|
@ -110,8 +110,8 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
ReadFlags surfaceSupportsReadPixels(const GrSurface*) const override {
|
||||
return kSupported_ReadFlag;
|
||||
SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override {
|
||||
return SurfaceReadPixelsSupport::kSupported;
|
||||
}
|
||||
|
||||
bool initDescForDstCopy(const GrRenderTargetProxy* src, GrSurfaceDesc* desc,
|
||||
|
@ -41,8 +41,8 @@ public:
|
||||
int maxRenderTargetSampleCount(SkColorType, const GrBackendFormat&) const override;
|
||||
int maxRenderTargetSampleCount(GrPixelConfig) const override;
|
||||
|
||||
ReadFlags surfaceSupportsReadPixels(const GrSurface*) const override {
|
||||
return kSupported_ReadFlag;
|
||||
SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override {
|
||||
return SurfaceReadPixelsSupport::kSupported;
|
||||
}
|
||||
|
||||
bool isFormatCopyable(SkColorType, const GrBackendFormat&) const override { return true; }
|
||||
|
@ -900,17 +900,18 @@ int GrVkCaps::maxRenderTargetSampleCount(VkFormat format) const {
|
||||
return table[table.count() - 1];
|
||||
}
|
||||
|
||||
GrCaps::ReadFlags GrVkCaps::surfaceSupportsReadPixels(const GrSurface* surface) const {
|
||||
GrCaps::SurfaceReadPixelsSupport GrVkCaps::surfaceSupportsReadPixels(
|
||||
const GrSurface* surface) const {
|
||||
if (surface->isProtected()) {
|
||||
return kProtected_ReadFlag;
|
||||
return SurfaceReadPixelsSupport::kUnsupported;
|
||||
}
|
||||
if (auto tex = static_cast<const GrVkTexture*>(surface->asTexture())) {
|
||||
// We can't directly read from a VkImage that has a ycbcr sampler.
|
||||
if (tex->ycbcrConversionInfo().isValid()) {
|
||||
return kRequiresCopy_ReadFlag;
|
||||
return SurfaceReadPixelsSupport::kCopyToTexture2D;
|
||||
}
|
||||
}
|
||||
return kSupported_ReadFlag;
|
||||
return SurfaceReadPixelsSupport::kSupported;
|
||||
}
|
||||
|
||||
bool GrVkCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const {
|
||||
|
@ -52,7 +52,7 @@ public:
|
||||
int maxRenderTargetSampleCount(GrPixelConfig config) const override;
|
||||
int maxRenderTargetSampleCount(VkFormat format) const;
|
||||
|
||||
ReadFlags surfaceSupportsReadPixels(const GrSurface*) const override;
|
||||
SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override;
|
||||
|
||||
bool isFormatTexturableLinearly(VkFormat format) const {
|
||||
return SkToBool(FormatInfo::kTextureable_Flag & this->getFormatInfo(format).fLinearFlags);
|
||||
|
Loading…
Reference in New Issue
Block a user