Remove GrCaps::SupportedRead::fSwizzle and supporting code

Add weird color types that handle the swizzling.

Change-Id: Ie37a00eb877fe5e519f7498bf749e02a2f1dc204
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/230135
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2019-07-31 10:24:26 -04:00 committed by Skia Commit-Bot
parent 1a607e7b6e
commit 1cec69ae5c
14 changed files with 131 additions and 85 deletions

View File

@ -1150,6 +1150,14 @@ enum class GrColorType {
kRGBA_F16_Clamped,
kRGBA_F32,
// Unusual formats that come up after reading back in cases where we are reassigning the meaning
// of a texture format's channels to use for a particular color format but have to read back the
// data to a full RGBA quadruple. (e.g. using a R8 texture format as A8 color type but the API
// only supports reading to RGBA8.) None of these have SkColorType equivalents.
kAlpha_8xxx,
kAlpha_F32xxx,
kGray_8xxx,
kR_16, // Not in SkColorType
kRG_1616, // Not in SkColorType
@ -1180,6 +1188,9 @@ static constexpr SkColorType GrColorTypeToSkColorType(GrColorType ct) {
case GrColorType::kRGBA_F16: return kRGBA_F16_SkColorType;
case GrColorType::kRGBA_F16_Clamped: return kRGBA_F16Norm_SkColorType;
case GrColorType::kRGBA_F32: return kRGBA_F32_SkColorType;
case GrColorType::kAlpha_8xxx: return kUnknown_SkColorType;
case GrColorType::kAlpha_F32xxx: return kUnknown_SkColorType;
case GrColorType::kGray_8xxx: return kUnknown_SkColorType;
case GrColorType::kR_16: return kUnknown_SkColorType;
case GrColorType::kRG_1616: return kUnknown_SkColorType;
// Experimental (for Y416 and mutant P016/P010)
@ -1232,6 +1243,9 @@ static constexpr uint32_t GrColorTypeComponentFlags(GrColorType ct) {
case GrColorType::kRGBA_F16: return kRGBA_SkColorTypeComponentFlags;
case GrColorType::kRGBA_F16_Clamped: return kRGBA_SkColorTypeComponentFlags;
case GrColorType::kRGBA_F32: return kRGBA_SkColorTypeComponentFlags;
case GrColorType::kAlpha_8xxx: return kAlpha_SkColorTypeComponentFlag;
case GrColorType::kAlpha_F32xxx: return kAlpha_SkColorTypeComponentFlag;
case GrColorType::kGray_8xxx: return kGray_SkColorTypeComponentFlag;
case GrColorType::kR_16: return kRed_SkColorTypeComponentFlag;
case GrColorType::kRG_1616: return kRed_SkColorTypeComponentFlag |
kGreen_SkColorTypeComponentFlag;
@ -1364,6 +1378,12 @@ static constexpr GrColorTypeDesc GrGetColorTypeDesc(GrColorType ct) {
return GrColorTypeDesc::MakeRGBA(16, GrColorTypeEncoding::kFloat);
case GrColorType::kRGBA_F32:
return GrColorTypeDesc::MakeRGBA(32, GrColorTypeEncoding::kFloat);
case GrColorType::kAlpha_8xxx:
return GrColorTypeDesc::MakeAlpha(8, GrColorTypeEncoding::kUnorm);
case GrColorType::kAlpha_F32xxx:
return GrColorTypeDesc::MakeAlpha(32, GrColorTypeEncoding::kFloat);
case GrColorType::kGray_8xxx:
return GrColorTypeDesc::MakeGray(8, GrColorTypeEncoding::kUnorm);
case GrColorType::kR_16:
return GrColorTypeDesc::MakeR(16, GrColorTypeEncoding::kUnorm);
case GrColorType::kRG_1616:
@ -1421,6 +1441,9 @@ static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct) {
case GrColorType::kRGBA_F16: return 8;
case GrColorType::kRGBA_F16_Clamped: return 8;
case GrColorType::kRGBA_F32: return 16;
case GrColorType::kAlpha_8xxx: return 4;
case GrColorType::kAlpha_F32xxx: return 16;
case GrColorType::kGray_8xxx: return 4;
case GrColorType::kR_16: return 2;
case GrColorType::kRG_1616: return 4;
// Experimental (for Y416 and mutant P016/P010)
@ -1518,6 +1541,9 @@ static constexpr GrPixelConfig GrColorTypeToPixelConfig(GrColorType colorType) {
case GrColorType::kAlpha_F16: return kAlpha_half_GrPixelConfig;
case GrColorType::kRGBA_F16: return kRGBA_half_GrPixelConfig;
case GrColorType::kRGBA_F16_Clamped: return kRGBA_half_Clamped_GrPixelConfig;
case GrColorType::kAlpha_8xxx: return kUnknown_GrPixelConfig;
case GrColorType::kAlpha_F32xxx: return kUnknown_GrPixelConfig;
case GrColorType::kGray_8xxx: return kUnknown_GrPixelConfig;
case GrColorType::kR_16: return kR_16_GrPixelConfig;
case GrColorType::kRG_1616: return kRG_1616_GrPixelConfig;

View File

@ -361,11 +361,13 @@ GrCaps::SupportedRead GrCaps::supportedReadPixelsColorType(GrColorType srcColorT
if (GrColorType::kRGB_888x == read.fColorType) {
read.fOffsetAlignmentForTransferBuffer = 0;
}
// It's very convenient to access 1 byte-per-channel 32 bitvRGB/RGBA color types as uint32_t.
// It's very convenient to access 1 byte-per-channel 32 bit color types as uint32_t on the CPU.
// Make those aligned reads out of the buffer even if the underlying API doesn't require it.
auto componentFlags = GrColorTypeComponentFlags(read.fColorType);
if ((componentFlags == kRGBA_SkColorTypeComponentFlags ||
componentFlags == kRGB_SkColorTypeComponentFlags) &&
componentFlags == kRGB_SkColorTypeComponentFlags ||
componentFlags == kAlpha_SkColorTypeComponentFlag ||
componentFlags == kGray_SkColorTypeComponentFlag) &&
GrColorTypeBytesPerPixel(read.fColorType) == 4) {
switch (read.fOffsetAlignmentForTransferBuffer & 0b11) {
// offset alignment already a multiple of 4

View File

@ -237,7 +237,6 @@ public:
GrColorType srcColorType) const = 0;
struct SupportedRead {
GrSwizzle fSwizzle;
GrColorType fColorType;
// If the read is occurring using GrGpu::transferPixelsFrom then this provides the
// minimum alignment of the offset into the transfer buffer.

View File

@ -390,6 +390,15 @@ static GrSwizzle get_load_and_get_swizzle(GrColorType ct, SkRasterPipeline::Stoc
case GrColorType::kRGBA_F32: *load = SkRasterPipeline::load_f32;
*isNormalized = false;
break;
case GrColorType::kAlpha_8xxx: *load = SkRasterPipeline::load_8888;
swizzle = GrSwizzle("000r");
break;
case GrColorType::kAlpha_F32xxx: *load = SkRasterPipeline::load_f32;
swizzle = GrSwizzle("000r");
break;
case GrColorType::kGray_8xxx: *load = SkRasterPipeline::load_8888;
swizzle = GrSwizzle("rrr1");
break;
case GrColorType::kR_16: *load = SkRasterPipeline::load_a16;
swizzle = GrSwizzle("a001");
break;
@ -440,6 +449,12 @@ static GrSwizzle get_dst_swizzle_and_store(GrColorType ct, SkRasterPipeline::Sto
case GrColorType::kRGBA_F32: *store = SkRasterPipeline::store_f32;
*isNormalized = false;
break;
case GrColorType::kAlpha_8xxx: *store = SkRasterPipeline::store_8888;
swizzle = GrSwizzle("a000");
break;
case GrColorType::kAlpha_F32xxx: *store = SkRasterPipeline::store_f32;
swizzle = GrSwizzle("a000");
break;
case GrColorType::kR_16: swizzle = GrSwizzle("000r");
*store = SkRasterPipeline::store_a16;
break;
@ -451,6 +466,7 @@ static GrSwizzle get_dst_swizzle_and_store(GrColorType ct, SkRasterPipeline::Sto
break;
case GrColorType::kGray_8: // not currently supported as output
case GrColorType::kGray_8xxx: // not currently supported as output
case GrColorType::kUnknown:
SK_ABORT("unexpected CT");
}
@ -466,7 +482,7 @@ static inline void append_clamp_gamut(SkRasterPipeline* pipeline) {
bool GrConvertPixels(const GrPixelInfo& dstInfo, void* dst, size_t dstRB,
const GrPixelInfo& srcInfo, const void* src, size_t srcRB,
bool flipY, GrSwizzle swizzle) {
bool flipY) {
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
if (!srcInfo.isValid() || !dstInfo.isValid()) {
return false;
@ -497,7 +513,6 @@ bool GrConvertPixels(const GrPixelInfo& dstInfo, void* dst, size_t dstRB,
bool srcIsSRGB;
auto loadSwizzle = get_load_and_get_swizzle(srcInfo.colorType(), &load, &srcIsNormalized,
&srcIsSRGB);
loadSwizzle = GrSwizzle::Concat(loadSwizzle, swizzle);
SkRasterPipeline::StockStage store;
bool dstIsNormalized;
@ -583,7 +598,6 @@ bool GrConvertPixels(const GrPixelInfo& dstInfo, void* dst, size_t dstRB,
return true;
}
GrColorType SkColorTypeAndFormatToGrColorType(const GrCaps* caps,
SkColorType skCT,
const GrBackendFormat& format) {

View File

@ -107,6 +107,6 @@ private:
// Swizzle param is applied after loading and before converting from srcInfo to dstInfo.
bool GrConvertPixels(const GrPixelInfo& dstInfo, void* dst, size_t dstRB,
const GrPixelInfo& srcInfo, const void* src, size_t srcRB,
bool flipY = false, GrSwizzle swizzle = GrSwizzle{});
bool flipY = false);
#endif

View File

@ -180,8 +180,7 @@ bool GrSurfaceContext::readPixels(const GrPixelInfo& origDstInfo, void* dst, siz
bool makeTight = !caps->readPixelsRowBytesSupport() && tightRowBytes != rowBytes;
bool convert = unpremul || premul || needColorConversion || flip || makeTight ||
(dstInfo.colorType() != supportedRead.fColorType) ||
supportedRead.fSwizzle != GrSwizzle::RGBA();
(dstInfo.colorType() != supportedRead.fColorType);
std::unique_ptr<char[]> tmpPixels;
GrPixelInfo tmpInfo;
@ -209,8 +208,7 @@ bool GrSurfaceContext::readPixels(const GrPixelInfo& origDstInfo, void* dst, siz
}
if (convert) {
return GrConvertPixels(dstInfo, dst, rowBytes, tmpInfo, readDst, readRB, flip,
supportedRead.fSwizzle);
return GrConvertPixels(dstInfo, dst, rowBytes, tmpInfo, readDst, readRB, flip);
}
return true;
}
@ -629,14 +627,14 @@ GrSurfaceContext::PixelTransferResult GrSurfaceContext::transferPixels(GrColorTy
PixelTransferResult result;
result.fTransferBuffer = std::move(buffer);
auto at = this->colorSpaceInfo().alphaType();
if (supportedRead.fColorType != dstCT || supportedRead.fSwizzle != GrSwizzle("rgba") || flip) {
if (supportedRead.fColorType != dstCT || flip) {
result.fPixelConverter = [w = rect.width(), h = rect.height(), dstCT, supportedRead, at](
void* dst, const void* src) {
GrPixelInfo srcInfo(supportedRead.fColorType, at, nullptr, w, h);
GrPixelInfo dstInfo(dstCT, at, nullptr, w, h);
GrConvertPixels(dstInfo, dst, dstInfo.minRowBytes(),
srcInfo, src, srcInfo.minRowBytes(),
/* flipY = */ false, supportedRead.fSwizzle);
/* flipY = */ false);
};
}
return result;

View File

@ -308,6 +308,9 @@ static inline int32_t dither_range_type_for_config(GrColorType dstColorType) {
case GrColorType::kRGBA_F16:
case GrColorType::kRGBA_F16_Clamped:
case GrColorType::kAlpha_8:
case GrColorType::kAlpha_8xxx:
case GrColorType::kAlpha_F32xxx:
case GrColorType::kGray_8xxx:
return -1;
}
SkUNREACHABLE;

View File

@ -1590,14 +1590,13 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa
ioFormat.fExternalReadFormat = 0;
}
// Format: R8, Surface: kAlpha_8, Data: kRGBA_8888
// Format: R8, Surface: kAlpha_8, Data: kAlpha_8xxx
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_8888;
ioFormat.fColorType = GrColorType::kAlpha_8xxx;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
ioFormat.fReadSwizzle = GrSwizzle("000r");
}
}
@ -1622,14 +1621,13 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa
ioFormat.fExternalReadFormat = 0;
}
// Format: R8, Surface: kGray_8, Data: kRGBA_8888
// Format: R8, Surface: kGray_8, Data: kGray_8xxx
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_8888;
ioFormat.fColorType = GrColorType::kGray_8xxx;
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
ioFormat.fReadSwizzle = GrSwizzle("rrr1");
}
}
}
@ -1704,7 +1702,6 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa
ioFormat.fExternalType = GR_GL_UNSIGNED_BYTE;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
ioFormat.fReadSwizzle = GrSwizzle("000a");
}
}
}
@ -2103,14 +2100,13 @@ void GrGLCaps::initFormatTable(const GrGLContextInfo& ctxInfo, const GrGLInterfa
ioFormat.fExternalReadFormat = 0;
}
// Format: R16F, Surface: kAlpha_F16, Data: kRGBA_F32
// Format: R16F, Surface: kAlpha_F16, Data: kAlpha_F32xxx
{
auto& ioFormat = ctInfo.fExternalIOFormats[ioIdx++];
ioFormat.fColorType = GrColorType::kRGBA_F32;
ioFormat.fColorType = GrColorType::kAlpha_F32xxx;
ioFormat.fExternalType = GR_GL_FLOAT;
ioFormat.fExternalTexImageFormat = 0;
ioFormat.fExternalReadFormat = GR_GL_RGBA;
ioFormat.fReadSwizzle = GrSwizzle("000r");
}
}
}
@ -3688,12 +3684,12 @@ GrCaps::SupportedRead GrGLCaps::onSupportedReadPixelsColorType(
// this as makes sense to increase performance and correctness.
GrGLFormat srcFormat = GrGLBackendFormatToGLFormat(srcBackendFormat);
if (srcFormat == GrGLFormat::kUnknown) {
return {GrSwizzle{}, GrColorType::kUnknown, 0};
return {GrColorType::kUnknown, 0};
}
// We first try to find a supported read pixels GrColorType that matches the requested
// dstColorType. If that doesn't exists we will use any valid read pixels GrColorType.
GrCaps::SupportedRead fallbackRead = {GrSwizzle{}, GrColorType::kUnknown, 0};
GrCaps::SupportedRead fallbackRead = {GrColorType::kUnknown, 0};
const auto& formatInfo = this->getFormatInfo(srcFormat);
bool foundSrcCT = false;
for (int i = 0; !foundSrcCT && i < formatInfo.fColorTypeInfoCount; ++i) {
@ -3706,13 +3702,12 @@ GrCaps::SupportedRead GrGLCaps::onSupportedReadPixelsColorType(
GrGLenum transferOffsetAlignment =
offset_alignment_for_transfer_buffer(ioInfo.fExternalType);
if (ioInfo.fColorType == dstColorType) {
return {ioInfo.fReadSwizzle, dstColorType, transferOffsetAlignment};
return {dstColorType, transferOffsetAlignment};
}
// Currently we just pick the first supported format that we find as our
// fallback.
if (fallbackRead.fColorType == GrColorType::kUnknown) {
fallbackRead = {ioInfo.fReadSwizzle, ioInfo.fColorType,
transferOffsetAlignment};
fallbackRead = {ioInfo.fColorType, transferOffsetAlignment};
}
}
}
@ -4001,6 +3996,12 @@ static GrPixelConfig validate_sized_format(GrGLenum format, GrColorType ct, GrGL
return kRG_half_GrPixelConfig;
}
break;
// These have no equivalent config:
case GrColorType::kAlpha_8xxx:
case GrColorType::kAlpha_F32xxx:
case GrColorType::kGray_8xxx:
break;
}
SkDebugf("Unknown pixel config 0x%x\n", format);
@ -4074,7 +4075,7 @@ GrBackendFormat GrGLCaps::getBackendFormatFromCompressionType(
bool GrGLCaps::canClearTextureOnCreation() const { return fClearTextureSupport; }
#ifdef SK_DEBUG
static bool format_color_type_valid_pair(GrGLenum format, GrColorType colorType) {
static constexpr bool format_color_type_valid_pair(GrGLenum format, GrColorType colorType) {
switch (colorType) {
case GrColorType::kUnknown:
return false;
@ -4119,9 +4120,13 @@ static bool format_color_type_valid_pair(GrGLenum format, GrColorType colorType)
case GrColorType::kRG_F16:
return GR_GL_RG16F == format;
// These have no equivalent config:
case GrColorType::kAlpha_8xxx:
case GrColorType::kAlpha_F32xxx:
case GrColorType::kGray_8xxx:
return false;
}
SK_ABORT("Unknown color type");
return false;
SkUNREACHABLE;
}
#endif

View File

@ -611,10 +611,6 @@ private:
GrGLenum fExternalType = 0;
GrGLenum fExternalTexImageFormat = 0;
GrGLenum fExternalReadFormat = 0;
// This is the swizzle to apply to the data after it is read back using the
// fExternalReadFormat so that the data is in the form expected by fColorType.
GrSwizzle fReadSwizzle = GrSwizzle::RGBA();
};
GrGLenum externalFormat(GrColorType externalColorType, ExternalFormatUsage usage) const {

View File

@ -184,7 +184,7 @@ private:
SupportedRead onSupportedReadPixelsColorType(GrColorType srcColorType, const GrBackendFormat&,
GrColorType) const override {
return SupportedRead{GrSwizzle::RGBA(), srcColorType, 1};
return SupportedRead{srcColorType, 1};
}
static const int kMaxSampleCnt = 16;

View File

@ -599,7 +599,7 @@ bool GrMtlCaps::onSurfaceSupportsWritePixels(const GrSurface* surface) const {
}
// A near clone of format_color_type_valid_pair
GrPixelConfig validate_sized_format(GrMTLPixelFormat grFormat, GrColorType ct) {
static constexpr GrPixelConfig validate_sized_format(GrMTLPixelFormat grFormat, GrColorType ct) {
MTLPixelFormat format = static_cast<MTLPixelFormat>(grFormat);
switch (ct) {
case GrColorType::kUnknown:
@ -615,7 +615,6 @@ GrPixelConfig validate_sized_format(GrMTLPixelFormat grFormat, GrColorType ct) {
case GrColorType::kBGR_565:
case GrColorType::kABGR_4444:
return kUnknown_GrPixelConfig;
break;
#else
case GrColorType::kBGR_565:
if (MTLPixelFormatB5G6R5Unorm == format) {
@ -703,9 +702,12 @@ GrPixelConfig validate_sized_format(GrMTLPixelFormat grFormat, GrColorType ct) {
return kRG_half_GrPixelConfig;
}
break;
case GrColorType::kAlpha_8xxx:
case GrColorType::kAlpha_F32xxx:
case GrColorType::kGray_8xxx:
return kUnknown_GrPixelConfig;
}
return kUnknown_GrPixelConfig;
SkUNREACHABLE;
}
bool GrMtlCaps::onAreColorTypeAndFormatCompatible(GrColorType ct,
@ -782,7 +784,7 @@ GrBackendFormat GrMtlCaps::getBackendFormatFromCompressionType(
}
#ifdef SK_DEBUG
static bool format_color_type_valid_pair(MTLPixelFormat format, GrColorType colorType) {
static constexpr bool format_color_type_valid_pair(MTLPixelFormat format, GrColorType colorType) {
switch (colorType) {
case GrColorType::kUnknown:
return false;
@ -837,9 +839,12 @@ static bool format_color_type_valid_pair(MTLPixelFormat format, GrColorType colo
return MTLPixelFormatRGBA16Unorm == format;
case GrColorType::kRG_F16:
return MTLPixelFormatRG16Float == format;
case GrColorType::kAlpha_8xxx:
case GrColorType::kAlpha_F32xxx:
case GrColorType::kGray_8xxx:
return false;
}
SK_ABORT("Unknown color type");
return false;
SkUNREACHABLE;
}
#endif
@ -902,7 +907,7 @@ GrCaps::SupportedRead GrMtlCaps::onSupportedReadPixelsColorType(
GrColorType dstColorType) const {
const GrMTLPixelFormat* grMtlFormat = srcBackendFormat.getMtlFormat();
if (!grMtlFormat) {
return {GrSwizzle(), GrColorType::kUnknown, 0};
return {GrColorType::kUnknown, 0};
}
GrColorType readCT = GrColorType::kUnknown;
@ -974,6 +979,6 @@ GrCaps::SupportedRead GrMtlCaps::onSupportedReadPixelsColorType(
}
// Metal requires the destination offset for copyFromTexture to be a multiple of the textures
// pixels size.
return {GrSwizzle::RGBA(), readCT, GrColorTypeBytesPerPixel(readCT)};
return {readCT, GrColorTypeBytesPerPixel(readCT)};
}

View File

@ -1065,6 +1065,11 @@ static GrPixelConfig validate_image_info(VkFormat format, GrColorType ct, bool h
return kRG_half_GrPixelConfig;
}
break;
// These have no equivalent:
case GrColorType::kAlpha_8xxx:
case GrColorType::kAlpha_F32xxx:
case GrColorType::kGray_8xxx:
break;
}
return kUnknown_GrPixelConfig;
@ -1142,7 +1147,7 @@ GrBackendFormat GrVkCaps::getBackendFormatFromCompressionType(
bool GrVkCaps::canClearTextureOnCreation() const { return true; }
#ifdef SK_DEBUG
static bool format_color_type_valid_pair(VkFormat vkFormat, GrColorType colorType) {
static constexpr bool format_color_type_valid_pair(VkFormat vkFormat, GrColorType colorType) {
switch (colorType) {
case GrColorType::kUnknown:
return false;
@ -1187,9 +1192,12 @@ static bool format_color_type_valid_pair(VkFormat vkFormat, GrColorType colorTyp
return VK_FORMAT_R16G16B16A16_UNORM == vkFormat;
case GrColorType::kRG_F16:
return VK_FORMAT_R16G16_SFLOAT == vkFormat;
case GrColorType::kAlpha_8xxx:
case GrColorType::kAlpha_F32xxx:
case GrColorType::kGray_8xxx:
return false;
}
SK_ABORT("Unknown color type");
return false;
SkUNREACHABLE;
}
#endif
@ -1240,7 +1248,7 @@ GrCaps::SupportedRead GrVkCaps::onSupportedReadPixelsColorType(
GrColorType dstColorType) const {
const VkFormat* vkFormat = srcBackendFormat.getVkFormat();
if (!vkFormat) {
return {GrSwizzle(), GrColorType::kUnknown, 0};
return {GrColorType::kUnknown, 0};
}
// The VkBufferImageCopy bufferOffset field must be both a multiple of 4 and of a single texel.
@ -1248,53 +1256,53 @@ GrCaps::SupportedRead GrVkCaps::onSupportedReadPixelsColorType(
switch (*vkFormat) {
case VK_FORMAT_R8G8B8A8_UNORM:
return {GrSwizzle::RGBA(), GrColorType::kRGBA_8888, offsetAlignment};
return {GrColorType::kRGBA_8888, offsetAlignment};
case VK_FORMAT_R8_UNORM:
if (srcColorType == GrColorType::kAlpha_8) {
return {GrSwizzle::RGBA(), GrColorType::kAlpha_8, offsetAlignment};
return {GrColorType::kAlpha_8, offsetAlignment};
} else if (srcColorType == GrColorType::kGray_8) {
return {GrSwizzle::RGBA(), GrColorType::kGray_8, offsetAlignment};
return {GrColorType::kGray_8, offsetAlignment};
} else {
return {GrSwizzle(), GrColorType::kUnknown, 0};
return {GrColorType::kUnknown, 0};
}
case VK_FORMAT_B8G8R8A8_UNORM:
return {GrSwizzle::RGBA(), GrColorType::kBGRA_8888, offsetAlignment};
return {GrColorType::kBGRA_8888, offsetAlignment};
case VK_FORMAT_R5G6B5_UNORM_PACK16:
return {GrSwizzle::RGBA(), GrColorType::kBGR_565, offsetAlignment};
return {GrColorType::kBGR_565, offsetAlignment};
case VK_FORMAT_R16G16B16A16_SFLOAT:
if (srcColorType == GrColorType::kRGBA_F16) {
return {GrSwizzle::RGBA(), GrColorType::kRGBA_F16, offsetAlignment};
return {GrColorType::kRGBA_F16, offsetAlignment};
} else if (srcColorType == GrColorType::kRGBA_F16_Clamped) {
return {GrSwizzle::RGBA(), GrColorType::kRGBA_F16_Clamped, offsetAlignment};
return {GrColorType::kRGBA_F16_Clamped, offsetAlignment};
} else {
return {GrSwizzle(), GrColorType::kUnknown, 0};
return {GrColorType::kUnknown, 0};
}
case VK_FORMAT_R16_SFLOAT:
return {GrSwizzle::RGBA(), GrColorType::kAlpha_F16, offsetAlignment};
return {GrColorType::kAlpha_F16, offsetAlignment};
case VK_FORMAT_R8G8B8_UNORM:
return {GrSwizzle::RGBA(), GrColorType::kRGB_888x, offsetAlignment};
return {GrColorType::kRGB_888x, offsetAlignment};
case VK_FORMAT_R8G8_UNORM:
return {GrSwizzle::RGBA(), GrColorType::kRG_88, offsetAlignment};
return {GrColorType::kRG_88, offsetAlignment};
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
return {GrSwizzle::RGBA(), GrColorType::kRGBA_1010102, offsetAlignment};
return {GrColorType::kRGBA_1010102, offsetAlignment};
case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
return {GrSwizzle::RGBA(), GrColorType::kABGR_4444, offsetAlignment};
return {GrColorType::kABGR_4444, offsetAlignment};
case VK_FORMAT_R4G4B4A4_UNORM_PACK16:
return {GrSwizzle::RGBA(), GrColorType::kABGR_4444, offsetAlignment};
return {GrColorType::kABGR_4444, offsetAlignment};
case VK_FORMAT_R32G32B32A32_SFLOAT:
return {GrSwizzle::RGBA(), GrColorType::kRGBA_F32, offsetAlignment};
return {GrColorType::kRGBA_F32, offsetAlignment};
case VK_FORMAT_R8G8B8A8_SRGB:
return {GrSwizzle::RGBA(), GrColorType::kRGBA_8888_SRGB, offsetAlignment};
return {GrColorType::kRGBA_8888_SRGB, offsetAlignment};
case VK_FORMAT_R16_UNORM:
return {GrSwizzle::RGBA(), GrColorType::kR_16, offsetAlignment};
return {GrColorType::kR_16, offsetAlignment};
case VK_FORMAT_R16G16_UNORM:
return {GrSwizzle::RGBA(), GrColorType::kRG_1616, offsetAlignment};
return {GrColorType::kRG_1616, offsetAlignment};
// Experimental (for Y416 and mutant P016/P010)
case VK_FORMAT_R16G16B16A16_UNORM:
return {GrSwizzle::RGBA(), GrColorType::kRGBA_16161616, offsetAlignment};
return {GrColorType::kRGBA_16161616, offsetAlignment};
case VK_FORMAT_R16G16_SFLOAT:
return {GrSwizzle::RGBA(), GrColorType::kRG_F16, offsetAlignment};
return {GrColorType::kRG_F16, offsetAlignment};
default:
return {GrSwizzle(), GrColorType::kUnknown, 0};
return {GrColorType::kUnknown, 0};
}
}

View File

@ -58,7 +58,7 @@ void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context,
// skbug.com/9165
auto supportedRead =
caps->supportedReadPixelsColorType(grCT, backendTex.getBackendFormat(), grCT);
if (supportedRead.fColorType != grCT || supportedRead.fSwizzle != GrSwizzle("rgba")) {
if (supportedRead.fColorType != grCT) {
return;
}

View File

@ -78,7 +78,7 @@ bool read_pixels_from_texture(GrTexture* texture, GrColorType dstColorType, char
GrCaps::SupportedRead supportedRead = caps->supportedReadPixelsColorType(
srcCT, texture->backendFormat(), dstColorType);
std::fill_n(tolerances, 4, 0);
if (supportedRead.fColorType != dstColorType || supportedRead.fSwizzle != GrSwizzle("rgba")) {
if (supportedRead.fColorType != dstColorType) {
size_t tmpRowBytes = GrColorTypeBytesPerPixel(supportedRead.fColorType) * w;
std::unique_ptr<char[]> tmpPixels(new char[tmpRowBytes * h]);
if (!gpu->readPixels(texture, 0, 0, w, h,
@ -88,8 +88,8 @@ bool read_pixels_from_texture(GrTexture* texture, GrColorType dstColorType, char
GrPixelInfo tmpInfo(supportedRead.fColorType, kUnpremul_SkAlphaType, nullptr, w, h);
GrPixelInfo dstInfo(dstColorType, kUnpremul_SkAlphaType, nullptr, w, h);
determine_tolerances(tmpInfo.colorType(), dstInfo.colorType(), tolerances);
return GrConvertPixels(dstInfo, dst, rowBytes, tmpInfo, tmpPixels.get(), tmpRowBytes, false,
supportedRead.fSwizzle);
return GrConvertPixels(dstInfo, dst, rowBytes, tmpInfo, tmpPixels.get(), tmpRowBytes,
false);
}
return gpu->readPixels(texture, 0, 0, w, h, supportedRead.fColorType, dst, rowBytes);
}
@ -364,11 +364,6 @@ void basic_transfer_from_test(skiatest::Reporter* reporter, const sk_gpu_test::C
GrPixelInfo transferInfo(allowedRead.fColorType, kUnpremul_SkAlphaType, nullptr, kTextureWidth,
kTextureHeight);
// Caps may indicate that we should swizzle this data before we compare it.
if (allowedRead.fSwizzle != GrSwizzle("rgba")) {
GrConvertPixels(transferInfo, transferData.get(), fullBufferRowBytes, transferInfo,
transferData.get(), fullBufferRowBytes, false, allowedRead.fSwizzle);
}
float tol[4];
determine_tolerances(allowedRead.fColorType, colorType, tol);
@ -410,11 +405,6 @@ void basic_transfer_from_test(skiatest::Reporter* reporter, const sk_gpu_test::C
buffer->unmap();
transferInfo = transferInfo.makeWH(kPartialWidth, kPartialHeight);
if (allowedRead.fSwizzle != GrSwizzle("rgba")) {
GrConvertPixels(transferInfo, transferData.get(), partialBufferRowBytes, transferInfo,
transferData.get(), partialBufferRowBytes, false, allowedRead.fSwizzle);
}
const char* textureDataStart =
textureData.get() + textureDataRowBytes * kPartialTop + textureDataBpp * kPartialLeft;
textureDataInfo = textureDataInfo.makeWH(kPartialWidth, kPartialHeight);