Add kRGBX_8888, kRGBA_1010102, and kRGBX_1010102 color types. Unused for now.

BUG= skia:7533

Change-Id: I4b3f6b827fd833ba2d07895884d2abc9a3132366
Reviewed-on: https://skia-review.googlesource.com/99781
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2018-01-25 14:07:47 -05:00 committed by Skia Commit-Bot
parent ecd251bbd2
commit e41e1769e7
9 changed files with 121 additions and 86 deletions

View File

@ -9,15 +9,22 @@
namespace skiagm {
static const char* gColorTypeNames[] = {
"unknown",
"A8",
"565",
"4444",
"8888",
"8888",
"Index8",
};
static const char* color_type_name(SkColorType colorType) {
switch (colorType) {
case kUnknown_SkColorType: return "unknown";
case kAlpha_8_SkColorType: return "A8";
case kRGB_565_SkColorType: return "565";
case kARGB_4444_SkColorType: return "4444";
case kRGBA_8888_SkColorType: return "8888";
case kRGB_888x_SkColorType: return "888x";
case kBGRA_8888_SkColorType: return "8888";
case kRGBA_1010102_SkColorType: return "1010102";
case kRGB_101010x_SkColorType: return "101010x";
case kGray_8_SkColorType: return "G8";
case kRGBA_F16_SkColorType: return "F16";
}
return "";
}
constexpr SkColorType gColorTypes[] = {
kRGB_565_SkColorType,
@ -84,7 +91,7 @@ protected:
height = paint.getFontSpacing();
}
for (unsigned i = 0; i < NUM_CONFIGS; i++) {
const char* name = gColorTypeNames[src.colorType()];
const char* name = color_type_name(src.colorType());
SkScalar textWidth = paint.measureText(name, strlen(name));
if (textWidth > width) {
width = textWidth;
@ -97,7 +104,7 @@ protected:
for (unsigned i = 0; i < NUM_CONFIGS; i++) {
canvas->save();
// Draw destination config name
const char* name = gColorTypeNames[fDst[i].colorType()];
const char* name = color_type_name(fDst[i].colorType());
SkScalar textWidth = paint.measureText(name, strlen(name));
SkScalar x = (width - textWidth) / SkScalar(2);
SkScalar y = paint.getFontSpacing() / SkScalar(2);

View File

@ -58,6 +58,9 @@ static inline bool SkAlphaTypeIsValid(unsigned value) {
///////////////////////////////////////////////////////////////////////////////
/** Temporary macro that allows us to add new color types without breaking Chrome compile. */
#define SK_EXTENDED_COLOR_TYPES
/**
* Describes how to interpret the components of a pixel.
*
@ -71,7 +74,10 @@ enum SkColorType {
kRGB_565_SkColorType,
kARGB_4444_SkColorType,
kRGBA_8888_SkColorType,
kRGB_888x_SkColorType,
kBGRA_8888_SkColorType,
kRGBA_1010102_SkColorType,
kRGB_101010x_SkColorType,
kGray_8_SkColorType,
kRGBA_F16_SkColorType,
@ -87,39 +93,37 @@ enum SkColorType {
};
static int SkColorTypeBytesPerPixel(SkColorType ct) {
static const uint8_t gSize[] = {
0, // Unknown
1, // Alpha_8
2, // RGB_565
2, // ARGB_4444
4, // RGBA_8888
4, // BGRA_8888
1, // kGray_8
8, // kRGBA_F16
};
static_assert(SK_ARRAY_COUNT(gSize) == (size_t)(kLastEnum_SkColorType + 1),
"size_mismatch_with_SkColorType_enum");
SkASSERT((size_t)ct < SK_ARRAY_COUNT(gSize));
return gSize[ct];
switch (ct) {
case kUnknown_SkColorType: return 0;
case kAlpha_8_SkColorType: return 1;
case kRGB_565_SkColorType: return 2;
case kARGB_4444_SkColorType: return 2;
case kRGBA_8888_SkColorType: return 4;
case kBGRA_8888_SkColorType: return 4;
case kRGB_888x_SkColorType: return 4;
case kRGBA_1010102_SkColorType: return 4;
case kRGB_101010x_SkColorType: return 4;
case kGray_8_SkColorType: return 1;
case kRGBA_F16_SkColorType: return 8;
}
return 0;
}
static int SkColorTypeShiftPerPixel(SkColorType ct) {
static const uint8_t gShift[] = {
0, // Unknown
0, // Alpha_8
1, // RGB_565
1, // ARGB_4444
2, // RGBA_8888
2, // BGRA_8888
0, // kGray_8
3, // kRGBA_F16
};
static_assert(SK_ARRAY_COUNT(gShift) == (size_t)(kLastEnum_SkColorType + 1),
"size_mismatch_with_SkColorType_enum");
SkASSERT((size_t)ct < SK_ARRAY_COUNT(gShift));
return gShift[ct];
switch (ct) {
case kUnknown_SkColorType: return 0;
case kAlpha_8_SkColorType: return 0;
case kRGB_565_SkColorType: return 1;
case kARGB_4444_SkColorType: return 1;
case kRGBA_8888_SkColorType: return 2;
case kRGB_888x_SkColorType: return 2;
case kBGRA_8888_SkColorType: return 2;
case kRGBA_1010102_SkColorType: return 2;
case kRGB_101010x_SkColorType: return 2;
case kGray_8_SkColorType: return 0;
case kRGBA_F16_SkColorType: return 3;
}
return 0;
}
static inline size_t SkColorTypeMinRowBytes(SkColorType ct, int width) {

View File

@ -339,6 +339,9 @@ static void pick_memory_stages(SkColorType ct, SkRasterPipeline::StockStage* loa
case kAlpha_8_SkColorType:
case kARGB_4444_SkColorType:
case kGray_8_SkColorType:
case kRGB_888x_SkColorType:
case kRGBA_1010102_SkColorType:
case kRGB_101010x_SkColorType:
SkASSERT(false);
break;
case kRGB_565_SkColorType:

View File

@ -22,51 +22,44 @@ enum Stored_SkColorType {
kIndex_8_Stored_SkColorType_DEPRECATED = 6,
kGray_8_Stored_SkColorType = 7,
kRGBA_F16_Stored_SkColorType = 8,
kLast_Stored_SkColorType = kRGBA_F16_Stored_SkColorType,
};
// Index with Stored_SkColorType
const SkColorType gStoredToLive[] = {
kUnknown_SkColorType,
kAlpha_8_SkColorType,
kRGB_565_SkColorType,
kARGB_4444_SkColorType,
kRGBA_8888_SkColorType,
kBGRA_8888_SkColorType,
kUnknown_SkColorType, // was kIndex_8
kGray_8_SkColorType,
kRGBA_F16_SkColorType,
};
// Index with SkColorType
const Stored_SkColorType gLiveToStored[] = {
kUnknown_Stored_SkColorType,
kAlpha_8_Stored_SkColorType,
kRGB_565_Stored_SkColorType,
kARGB_4444_Stored_SkColorType,
kRGBA_8888_Stored_SkColorType,
kBGRA_8888_Stored_SkColorType,
kGray_8_Stored_SkColorType,
kRGBA_F16_Stored_SkColorType,
kRGB_888x_Stored_SkColorType = 9,
kRGBA_1010102_Stored_SkColorType = 10,
kRGB_101010x_Stored_SkColorType = 11,
};
static uint8_t live_to_stored(unsigned ct) {
static_assert(SK_ARRAY_COUNT(gLiveToStored) == (kLastEnum_SkColorType + 1), "");
if (ct >= SK_ARRAY_COUNT(gLiveToStored)) {
ct = kUnknown_SkColorType;
switch (ct) {
case kUnknown_SkColorType: return kUnknown_Stored_SkColorType;
case kAlpha_8_SkColorType: return kAlpha_8_Stored_SkColorType;
case kRGB_565_SkColorType: return kRGB_565_Stored_SkColorType;
case kARGB_4444_SkColorType: return kARGB_4444_Stored_SkColorType;
case kRGBA_8888_SkColorType: return kRGBA_8888_Stored_SkColorType;
case kRGB_888x_SkColorType: return kRGB_888x_Stored_SkColorType;
case kBGRA_8888_SkColorType: return kBGRA_8888_Stored_SkColorType;
case kRGBA_1010102_SkColorType: return kRGBA_1010102_Stored_SkColorType;
case kRGB_101010x_SkColorType: return kRGB_101010x_Stored_SkColorType;
case kGray_8_SkColorType: return kGray_8_Stored_SkColorType;
case kRGBA_F16_SkColorType: return kRGBA_F16_Stored_SkColorType;
}
return gLiveToStored[ct];
return kUnknown_Stored_SkColorType;
}
static SkColorType stored_to_live(unsigned stored) {
static_assert(SK_ARRAY_COUNT(gStoredToLive) == (kLast_Stored_SkColorType + 1), "");
if (stored >= SK_ARRAY_COUNT(gStoredToLive)) {
stored = kUnknown_Stored_SkColorType;
switch (stored) {
case kUnknown_Stored_SkColorType: return kUnknown_SkColorType;
case kAlpha_8_Stored_SkColorType: return kAlpha_8_SkColorType;
case kRGB_565_Stored_SkColorType: return kRGB_565_SkColorType;
case kARGB_4444_Stored_SkColorType: return kARGB_4444_SkColorType;
case kRGBA_8888_Stored_SkColorType: return kRGBA_8888_SkColorType;
case kRGB_888x_Stored_SkColorType: return kRGB_888x_SkColorType;
case kBGRA_8888_Stored_SkColorType: return kBGRA_8888_SkColorType;
case kRGBA_1010102_Stored_SkColorType: return kRGBA_1010102_SkColorType;
case kRGB_101010x_Stored_SkColorType: return kRGB_101010x_SkColorType;
case kIndex_8_Stored_SkColorType_DEPRECATED: return kUnknown_SkColorType;
case kGray_8_Stored_SkColorType: return kGray_8_SkColorType;
case kRGBA_F16_Stored_SkColorType: return kRGBA_F16_SkColorType;
}
return gStoredToLive[stored];
return kUnknown_SkColorType;
}
///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -285,9 +285,15 @@ GrPixelConfig SkImageInfo2GrPixelConfig(const SkColorType type, SkColorSpace* cs
? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig;
// TODO: We're checking for srgbSupport, but we can then end up picking sBGRA as our pixel
// config (which may not be supported). We need a better test here.
case kRGB_888x_SkColorType:
return kUnknown_GrPixelConfig;
case kBGRA_8888_SkColorType:
return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB())
? kSBGRA_8888_GrPixelConfig : kBGRA_8888_GrPixelConfig;
case kRGBA_1010102_SkColorType:
return kUnknown_GrPixelConfig;
case kRGB_101010x_SkColorType:
return kUnknown_GrPixelConfig;
case kGray_8_SkColorType:
return kGray_8_GrPixelConfig;
case kRGBA_F16_SkColorType:

View File

@ -2459,6 +2459,8 @@ bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* confi
*config = kSRGBA_8888_GrPixelConfig;
}
break;
case kRGB_888x_SkColorType:
return false;
case kBGRA_8888_SkColorType:
if (GR_GL_RGBA8 == format) {
if (kGL_GrGLStandard == standard) {
@ -2472,6 +2474,10 @@ bool validate_sized_format(GrGLenum format, SkColorType ct, GrPixelConfig* confi
*config = kSBGRA_8888_GrPixelConfig;
}
break;
case kRGBA_1010102_SkColorType:
return false;
case kRGB_101010x_SkColorType:
return false;
case kGray_8_SkColorType:
if (GR_GL_LUMINANCE8 == format) {
*config = kGray_8_as_Lum_GrPixelConfig;

View File

@ -432,6 +432,8 @@ bool validate_image_info(const GrVkImageInfo* imageInfo, SkColorType ct, GrPixel
*config = kSRGBA_8888_GrPixelConfig;
}
break;
case kRGB_888x_SkColorType:
return false;
case kBGRA_8888_SkColorType:
if (VK_FORMAT_B8G8R8A8_UNORM == format) {
*config = kBGRA_8888_GrPixelConfig;
@ -439,6 +441,10 @@ bool validate_image_info(const GrVkImageInfo* imageInfo, SkColorType ct, GrPixel
*config = kSBGRA_8888_GrPixelConfig;
}
break;
case kRGBA_1010102_SkColorType:
return false;
case kRGB_101010x_SkColorType:
return false;
case kGray_8_SkColorType:
if (VK_FORMAT_R8_UNORM == format) {
*config = kGray_8_as_Red_GrPixelConfig;

View File

@ -302,6 +302,9 @@ SkImageCacherator::CachedFormat SkImage_Lazy::chooseCacheFormat(SkColorSpace* ds
case kAlpha_8_SkColorType:
case kRGB_565_SkColorType:
case kARGB_4444_SkColorType:
case kRGB_888x_SkColorType:
case kRGBA_1010102_SkColorType:
case kRGB_101010x_SkColorType:
// We don't support color space on these formats, so always decode in legacy mode:
// TODO: Ask the codec to decode these to something else (at least sRGB 8888)?
return kLegacy_CachedFormat;

View File

@ -27,15 +27,22 @@ SkString* SkObjectParser::BitmapToString(const SkBitmap& bitmap) {
mBitmap->append(" H: ");
mBitmap->appendS32(bitmap.height());
const char* gColorTypeStrings[] = {
"None", "A8", "565", "4444", "RGBA", "BGRA",
"G8", "RGBAf16"
};
static_assert(kLastEnum_SkColorType + 1 == SK_ARRAY_COUNT(gColorTypeStrings),
"colortype names do not match colortype enum");
const char* ctString = "<unknown>";
switch (bitmap.colorType()) {
case kUnknown_SkColorType: ctString = "None"; break;
case kAlpha_8_SkColorType: ctString = "A8"; break;
case kRGB_565_SkColorType: ctString = "565"; break;
case kARGB_4444_SkColorType: ctString = "4444"; break;
case kRGBA_8888_SkColorType: ctString = "RGBA"; break;
case kRGB_888x_SkColorType: ctString = "RGB"; break;
case kBGRA_8888_SkColorType: ctString = "BGRA"; break;
case kRGBA_1010102_SkColorType: ctString = "1010102"; break;
case kRGB_101010x_SkColorType: ctString = "101010x"; break;
case kGray_8_SkColorType: ctString = "G8"; break;
case kRGBA_F16_SkColorType: ctString = "RGBAf16"; break;
}
mBitmap->append(" ColorType: ");
mBitmap->append(gColorTypeStrings[bitmap.colorType()]);
mBitmap->append(ctString);
if (bitmap.isOpaque()) {
mBitmap->append(" opaque");