Remove use of colorTypes from SkYUVSizeInfo

Bug: skia:7903
Change-Id: I7301d943b679a4670511b6cf60c594baf615834a
Reviewed-on: https://skia-review.googlesource.com/c/164261
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Jim Van Verth 2018-10-22 14:12:03 -04:00 committed by Skia Commit-Bot
parent 018608f1ef
commit b7f0b9cd5c
16 changed files with 119 additions and 60 deletions

View File

@ -576,13 +576,11 @@ protected:
int i = 0;
for ( ; i < fNumBitmaps; ++i) {
size->fColorTypes[i] = fYUVBitmaps[i].colorType();
size->fSizes[i].fWidth = fYUVBitmaps[i].width();
size->fSizes[i].fHeight = fYUVBitmaps[i].height();
size->fWidthBytes[i] = fYUVBitmaps[i].rowBytes();
}
for ( ; i < SkYUVSizeInfo::kMaxCount; ++i) {
size->fColorTypes[i] = kUnknown_SkColorType;
size->fSizes[i].fWidth = 0;
size->fSizes[i].fHeight = 0;
size->fWidthBytes[i] = 0;

View File

@ -365,11 +365,9 @@ public:
bool result = this->onQueryYUV8(sizeInfo, colorSpace);
if (result) {
for (int i = 0; i <= 2; ++i) {
SkASSERT(kAlpha_8_SkColorType == sizeInfo->fColorTypes[i]);
SkASSERT(sizeInfo->fSizes[i].fWidth > 0 && sizeInfo->fSizes[i].fHeight > 0 &&
sizeInfo->fWidthBytes[i] > 0);
}
SkASSERT(kUnknown_SkColorType == sizeInfo->fColorTypes[3]);
SkASSERT(!sizeInfo->fSizes[3].fWidth &&
!sizeInfo->fSizes[3].fHeight &&
!sizeInfo->fWidthBytes[3]);
@ -391,7 +389,6 @@ public:
if (!planes || !planes[0] || !planes[1] || !planes[2]) {
return kInvalidInput;
}
SkASSERT(kUnknown_SkColorType == sizeInfo.fColorTypes[3]);
SkASSERT(!planes[3]); // TODO: is this a fair assumption?
if (!this->rewindIfNeeded()) {

View File

@ -15,7 +15,6 @@
struct SkYUVSizeInfo {
static constexpr auto kMaxCount = 4;
SkColorType fColorTypes[kMaxCount];
SkISize fSizes[kMaxCount];
/**
@ -34,17 +33,8 @@ struct SkYUVSizeInfo {
bool operator==(const SkYUVSizeInfo& that) const {
for (int i = 0; i < kMaxCount; ++i) {
if (fColorTypes[i] != that.fColorTypes[i]) {
return false;
}
if (kUnknown_SkColorType == fColorTypes[i]) {
SkASSERT(!fSizes[i].fWidth && !fSizes[i].fHeight && !fWidthBytes[i]);
SkASSERT(!that.fSizes[i].fWidth && !that.fSizes[i].fHeight && !that.fWidthBytes[i]);
continue;
}
SkASSERT(fSizes[i].fWidth && fSizes[i].fHeight && fWidthBytes[i]);
SkASSERT((!fSizes[i].isEmpty() && fWidthBytes[i]) ||
(fSizes[i].isEmpty() && !fWidthBytes[i]));
if (fSizes[i] != that.fSizes[i] || fWidthBytes[i] != that.fWidthBytes[i]) {
return false;
}
@ -57,9 +47,8 @@ struct SkYUVSizeInfo {
size_t totalBytes = 0;
for (int i = 0; i < kMaxCount; ++i) {
SkASSERT(kUnknown_SkColorType != fColorTypes[i] ||
(!fSizes[i].fWidth && !fSizes[i].fHeight && !fWidthBytes[i]));
SkASSERT((!fSizes[i].isEmpty() && fWidthBytes[i]) ||
(fSizes[i].isEmpty() && !fWidthBytes[i]));
totalBytes += fWidthBytes[i] * fSizes[i].height();
}

View File

@ -832,13 +832,11 @@ bool SkJpegCodec::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpa
jpeg_component_info * comp_info = dinfo->comp_info;
for (auto i : { SkYUVAIndex::kY_Index, SkYUVAIndex::kU_Index, SkYUVAIndex::kV_Index }) {
sizeInfo->fColorTypes[i] = kAlpha_8_SkColorType;
sizeInfo->fSizes[i].set(comp_info[i].downsampled_width, comp_info[i].downsampled_height);
sizeInfo->fWidthBytes[i] = comp_info[i].width_in_blocks * DCTSIZE;
}
// JPEG never has an alpha channel
sizeInfo->fColorTypes[SkYUVAIndex::kA_Index] = kUnknown_SkColorType;
sizeInfo->fSizes[SkYUVAIndex::kA_Index].fHeight =
sizeInfo->fSizes[SkYUVAIndex::kA_Index].fWidth =
sizeInfo->fWidthBytes[SkYUVAIndex::kA_Index] = 0;
@ -857,9 +855,6 @@ SkCodec::Result SkJpegCodec::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo,
// This will check is_yuv_supported(), so we don't need to here.
bool supportsYUV = this->onQueryYUV8(&defaultInfo, nullptr);
if (!supportsYUV ||
kAlpha_8_SkColorType != sizeInfo.fColorTypes[0] ||
kAlpha_8_SkColorType != sizeInfo.fColorTypes[1] ||
kAlpha_8_SkColorType != sizeInfo.fColorTypes[2] ||
sizeInfo.fSizes[0] != defaultInfo.fSizes[0] ||
sizeInfo.fSizes[1] != defaultInfo.fSizes[1] ||
sizeInfo.fSizes[2] != defaultInfo.fSizes[2] ||

View File

@ -52,10 +52,6 @@ bool SkImageGenerator::queryYUVA8(SkYUVSizeInfo* sizeInfo,
switch (numPlanes) {
case 1:
// Assume 3 interleaved planes
sizeInfo->fColorTypes[0] = kRGBA_8888_SkColorType;
sizeInfo->fColorTypes[1] = kUnknown_SkColorType;
sizeInfo->fColorTypes[2] = kUnknown_SkColorType;
sizeInfo->fColorTypes[3] = kUnknown_SkColorType;
yuvaIndices[SkYUVAIndex::kY_Index].fIndex = 0;
yuvaIndices[SkYUVAIndex::kY_Index].fChannel = SkColorChannel::kR;
yuvaIndices[SkYUVAIndex::kU_Index].fIndex = 0;
@ -67,10 +63,6 @@ bool SkImageGenerator::queryYUVA8(SkYUVSizeInfo* sizeInfo,
break;
case 2:
// Assume 1 Y plane and interleaved UV planes (NV12)
sizeInfo->fColorTypes[0] = kAlpha_8_SkColorType;
sizeInfo->fColorTypes[1] = kRGBA_8888_SkColorType;
sizeInfo->fColorTypes[2] = kUnknown_SkColorType;
sizeInfo->fColorTypes[3] = kUnknown_SkColorType;
yuvaIndices[SkYUVAIndex::kY_Index].fIndex = 0;
yuvaIndices[SkYUVAIndex::kY_Index].fChannel = SkColorChannel::kR;
yuvaIndices[SkYUVAIndex::kU_Index].fIndex = 1;
@ -83,10 +75,6 @@ bool SkImageGenerator::queryYUVA8(SkYUVSizeInfo* sizeInfo,
case 3:
default:
// Assume 3 separate non-interleaved planes
sizeInfo->fColorTypes[0] = kAlpha_8_SkColorType;
sizeInfo->fColorTypes[1] = kAlpha_8_SkColorType;
sizeInfo->fColorTypes[2] = kAlpha_8_SkColorType;
sizeInfo->fColorTypes[3] = kUnknown_SkColorType;
yuvaIndices[SkYUVAIndex::kY_Index].fIndex = 0;
yuvaIndices[SkYUVAIndex::kY_Index].fChannel = SkColorChannel::kR;
yuvaIndices[SkYUVAIndex::kU_Index].fIndex = 1;

View File

@ -287,6 +287,14 @@ public:
virtual bool getConfigFromBackendFormat(const GrBackendFormat& format, SkColorType ct,
GrPixelConfig*) const = 0;
/**
* Special method only for YUVA images. Returns true if the format can be used for a
* YUVA plane, and the passed in GrPixelConfig will be set to a config that matches
* the backend format.
*/
virtual bool getYUVAConfigFromBackendFormat(const GrBackendFormat& format,
GrPixelConfig*) const = 0;
#ifdef GR_TEST_UTILS
/**
* Creates a GrBackendFormat which matches the backend texture. If the backend texture is

View File

@ -36,8 +36,7 @@ sk_sp<SkCachedData> GrYUVProvider::getPlanes(SkYUVSizeInfo* size,
for (int i = 1; i < SkYUVSizeInfo::kMaxCount; ++i) {
if (!yuvInfo.fSizeInfo.fWidthBytes[i]) {
SkASSERT(kUnknown_SkColorType == yuvInfo.fSizeInfo.fColorTypes[i] &&
!yuvInfo.fSizeInfo.fWidthBytes[i] &&
SkASSERT(!yuvInfo.fSizeInfo.fWidthBytes[i] &&
!yuvInfo.fSizeInfo.fSizes[i].fHeight);
planes[i] = nullptr;
continue;
@ -55,7 +54,7 @@ sk_sp<SkCachedData> GrYUVProvider::getPlanes(SkYUVSizeInfo* size,
// Allocate the memory for YUVA
size_t totalSize(0);
for (int i = 0; i < SkYUVSizeInfo::kMaxCount; i++) {
SkASSERT(kUnknown_SkColorType != yuvInfo.fSizeInfo.fColorTypes[i] ||
SkASSERT((yuvInfo.fSizeInfo.fWidthBytes[i] && yuvInfo.fSizeInfo.fSizes[i].fHeight) ||
(!yuvInfo.fSizeInfo.fWidthBytes[i] && !yuvInfo.fSizeInfo.fSizes[i].fHeight));
totalSize += yuvInfo.fSizeInfo.fWidthBytes[i] * yuvInfo.fSizeInfo.fSizes[i].fHeight;
@ -67,8 +66,7 @@ sk_sp<SkCachedData> GrYUVProvider::getPlanes(SkYUVSizeInfo* size,
for (int i = 1; i < SkYUVSizeInfo::kMaxCount; ++i) {
if (!yuvInfo.fSizeInfo.fWidthBytes[i]) {
SkASSERT(kUnknown_SkColorType == yuvInfo.fSizeInfo.fColorTypes[i] &&
!yuvInfo.fSizeInfo.fWidthBytes[i] &&
SkASSERT(!yuvInfo.fSizeInfo.fWidthBytes[i] &&
!yuvInfo.fSizeInfo.fSizes[i].fHeight);
planes[i] = nullptr;
continue;
@ -119,10 +117,8 @@ sk_sp<GrTextureProxy> GrYUVProvider::refAsTextureProxy(GrContext* ctx, const GrS
sk_sp<GrTextureProxy> yuvTextureProxies[SkYUVSizeInfo::kMaxCount];
for (int i = 0; i < SkYUVSizeInfo::kMaxCount; ++i) {
if (kUnknown_SkColorType == yuvSizeInfo.fColorTypes[i]) {
SkASSERT(!yuvSizeInfo.fSizes[i].fWidth ||
!yuvSizeInfo.fSizes[i].fHeight ||
!yuvSizeInfo.fWidthBytes[i]);
if (yuvSizeInfo.fSizes[i].isEmpty()) {
SkASSERT(!yuvSizeInfo.fWidthBytes[i]);
continue;
}

View File

@ -2927,6 +2927,37 @@ bool GrGLCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColor
return validate_sized_format(*glFormat, ct, config, fStandard);
}
bool GrGLCaps::getYUVAConfigFromBackendFormat(const GrBackendFormat& format,
GrPixelConfig* config) const {
const GrGLenum* glFormat = format.getGLFormat();
if (!glFormat) {
return false;
}
switch (*glFormat) {
case GR_GL_ALPHA8:
*config = kAlpha_8_as_Alpha_GrPixelConfig;
break;
case GR_GL_R8:
*config = kAlpha_8_as_Red_GrPixelConfig;
break;
case GR_GL_RGBA8:
*config = kRGBA_8888_GrPixelConfig;
break;
case GR_GL_RGB8:
*config = kRGB_888_GrPixelConfig;
break;
case GR_GL_BGRA8:
*config = kBGRA_8888_GrPixelConfig;
break;
default:
return false;
}
return true;
}
#ifdef GR_TEST_UTILS
GrBackendFormat GrGLCaps::onCreateFormatFromBackendTexture(
const GrBackendTexture& backendTex) const {

View File

@ -436,6 +436,8 @@ public:
bool getConfigFromBackendFormat(const GrBackendFormat&, SkColorType,
GrPixelConfig*) const override;
bool getYUVAConfigFromBackendFormat(const GrBackendFormat&,
GrPixelConfig*) const override;
#if GR_TEST_UTILS
GrGLStandard standard() const { return fStandard; }

View File

@ -104,6 +104,16 @@ public:
return true;
}
bool getYUVAConfigFromBackendFormat(const GrBackendFormat& format,
GrPixelConfig* config) const override {
const GrPixelConfig* mockFormat = format.getMockFormat();
if (!mockFormat) {
return false;
}
*config = *mockFormat;
return true;
}
private:
#ifdef GR_TEST_UTILS
GrBackendFormat onCreateFormatFromBackendTexture(

View File

@ -80,6 +80,11 @@ public:
return false;
}
bool getYUVAConfigFromBackendFormat(const GrBackendFormat&,
GrPixelConfig*) const override {
return false;
}
bool performPartialClearsAsDraws() const override {
return true;
}

View File

@ -782,6 +782,33 @@ bool GrVkCaps::getConfigFromBackendFormat(const GrBackendFormat& format, SkColor
return validate_image_info(*vkFormat, ct, config);
}
bool GrVkCaps::getYUVAConfigFromBackendFormat(const GrBackendFormat& format,
GrPixelConfig* config) const {
const VkFormat* vkFormat = format.getVkFormat();
if (!vkFormat) {
return false;
}
switch (*vkFormat) {
case VK_FORMAT_R8_UNORM:
*config = kAlpha_8_as_Red_GrPixelConfig;
break;
case VK_FORMAT_R8G8B8A8_UNORM:
*config = kRGBA_8888_GrPixelConfig;
break;
case VK_FORMAT_R8G8B8_UNORM:
*config = kRGB_888_GrPixelConfig;
break;
case VK_FORMAT_B8G8R8A8_UNORM:
*config = kBGRA_8888_GrPixelConfig;
break;
default:
return false;
}
return true;
}
#ifdef GR_TEST_UTILS
GrBackendFormat GrVkCaps::onCreateFormatFromBackendTexture(
const GrBackendTexture& backendTex) const {

View File

@ -160,6 +160,8 @@ public:
bool getConfigFromBackendFormat(const GrBackendFormat&, SkColorType,
GrPixelConfig*) const override;
bool getYUVAConfigFromBackendFormat(const GrBackendFormat&,
GrPixelConfig*) const override;
private:
enum VkVendor {

View File

@ -235,15 +235,13 @@ sk_sp<SkImage> SkImage_GpuYUVA::MakePromiseYUVATexture(GrContext* context,
// verify sizeInfo with expected texture count
for (int i = 0; i < numTextures; ++i) {
if (kUnknown_SkColorType == yuvaSizeInfo.fColorTypes[i] ||
yuvaSizeInfo.fSizes[i].isEmpty() ||
if (yuvaSizeInfo.fSizes[i].isEmpty() ||
!yuvaSizeInfo.fWidthBytes[i]) {
return nullptr;
}
}
for (int i = numTextures; i < SkYUVSizeInfo::kMaxCount; ++i) {
if (kUnknown_SkColorType != yuvaSizeInfo.fColorTypes[i] ||
!yuvaSizeInfo.fSizes[i].isEmpty() ||
if (!yuvaSizeInfo.fSizes[i].isEmpty() ||
yuvaSizeInfo.fWidthBytes[i]) {
return nullptr;
}
@ -258,9 +256,8 @@ sk_sp<SkImage> SkImage_GpuYUVA::MakePromiseYUVATexture(GrContext* context,
GrPixelConfig fConfig;
SkPromiseImageHelper fPromiseHelper;
} params;
bool res = context->contextPriv().caps()->getConfigFromBackendFormat(
bool res = context->contextPriv().caps()->getYUVAConfigFromBackendFormat(
yuvaFormats[texIdx],
yuvaSizeInfo.fColorTypes[texIdx],
&params.fConfig);
if (!res) {
return nullptr;

View File

@ -33,7 +33,6 @@ DEF_TEST(YUVPlanesCache, reporter) {
SkYUVPlanesCache::Info yuvInfo;
for (int i = 0; i < SkYUVSizeInfo::kMaxCount; i++) {
yuvInfo.fSizeInfo.fColorTypes[i] = kAlpha_8_SkColorType;
yuvInfo.fSizeInfo.fSizes[i].fWidth = 20 * (i + 1);
yuvInfo.fSizeInfo.fSizes[i].fHeight = 10 * (i + 1);
yuvInfo.fSizeInfo.fWidthBytes[i] = 80 * (i + 1);

View File

@ -154,12 +154,10 @@ sk_sp<SkImage> DDLPromiseImageHelper::PromiseImageCreator(const void* rawData,
contexts[i] = curImage.refCallbackContext(i).release();
sizeInfo.fSizes[i].set(curImage.yuvPixmap(i).width(), curImage.yuvPixmap(i).height());
sizeInfo.fColorTypes[i] = curImage.yuvPixmap(i).colorType();
sizeInfo.fWidthBytes[i] = curImage.yuvPixmap(i).rowBytes();
}
for (int i = textureCount; i < SkYUVSizeInfo::kMaxCount; ++i) {
sizeInfo.fSizes[i] = SkISize::MakeEmpty();
sizeInfo.fColorTypes[i] = kUnknown_SkColorType;
sizeInfo.fWidthBytes[i] = 0;
}
@ -231,17 +229,34 @@ int DDLPromiseImageHelper::addImage(SkImage* image) {
if (yuvData) {
newImageInfo.setYUVData(std::move(yuvData), yuvaIndices, yuvColorSpace);
// determine colortypes from index data
// for testing we only ever use A8 or RGBA8888
SkColorType colorTypes[SkYUVSizeInfo::kMaxCount] = {
kUnknown_SkColorType, kUnknown_SkColorType,
kUnknown_SkColorType, kUnknown_SkColorType
};
for (int yuvIndex = 0; yuvIndex < SkYUVAIndex::kIndexCount; ++yuvIndex) {
int texIdx = yuvaIndices[yuvIndex].fIndex;
if (texIdx < 0) {
SkASSERT(SkYUVAIndex::kA_Index == yuvIndex);
continue;
}
if (kUnknown_SkColorType == colorTypes[texIdx]) {
colorTypes[texIdx] = kAlpha_8_SkColorType;
} else {
colorTypes[texIdx] = kRGBA_8888_SkColorType;
}
}
for (int i = 0; i < SkYUVSizeInfo::kMaxCount; ++i) {
if (kUnknown_SkColorType == yuvaSizeInfo.fColorTypes[i]) {
SkASSERT(!yuvaSizeInfo.fSizes[i].fWidth &&
!yuvaSizeInfo.fSizes[i].fHeight &&
!yuvaSizeInfo.fWidthBytes[i]);
if (yuvaSizeInfo.fSizes[i].isEmpty()) {
SkASSERT(!yuvaSizeInfo.fWidthBytes[i] && kUnknown_SkColorType == colorTypes[i]);
continue;
}
SkImageInfo planeII = SkImageInfo::Make(yuvaSizeInfo.fSizes[i].fWidth,
yuvaSizeInfo.fSizes[i].fHeight,
yuvaSizeInfo.fColorTypes[i],
colorTypes[i],
kUnpremul_SkAlphaType);
newImageInfo.addYUVPlane(i, planeII, planes[i], yuvaSizeInfo.fWidthBytes[i]);
}