Revert "Widen internal API to support more complex YUV formats"
This reverts commit 0c583af06d50cf3a11a39f5804eccdeefd74fc02.
Reason for revert: DDL is failing
Original change's description:
> Widen internal API to support more complex YUV formats
>
> Bug: skia:7901
> Change-Id: I46fec08711b8b483cf58ccae733e4dc2a9689231
> Reviewed-on: https://skia-review.googlesource.com/c/162280
> Commit-Queue: Jim Van Verth <jvanverth@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
TBR=egdaniel@google.com,jvanverth@google.com,bsalomon@google.com
Change-Id: Ibe3dd7abbce4a3b6afe74c565198dadc61a9f439
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:7901
Reviewed-on: https://skia-review.googlesource.com/c/163257
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp
index beccd7d..da86eac 100644
--- a/src/gpu/GrYUVProvider.cpp
+++ b/src/gpu/GrYUVProvider.cpp
@@ -22,64 +22,40 @@
#include "effects/GrYUVtoRGBEffect.h"
sk_sp<SkCachedData> GrYUVProvider::getPlanes(SkYUVSizeInfo* size,
- SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
SkYUVColorSpace* colorSpace,
- const void* constPlanes[SkYUVSizeInfo::kMaxCount]) {
+ const void* constPlanes[3]) {
sk_sp<SkCachedData> data;
SkYUVPlanesCache::Info yuvInfo;
data.reset(SkYUVPlanesCache::FindAndRef(this->onGetID(), &yuvInfo));
- void* planes[SkYUVSizeInfo::kMaxCount];
+ void* planes[3];
if (data.get()) {
- planes[0] = (void*)data->data(); // we should always have at least one plane
-
- for (int i = 1; i < SkYUVSizeInfo::kMaxCount; ++i) {
- if (!yuvInfo.fSizeInfo.fWidthBytes[i]) {
- SkASSERT(kUnknown_SkColorType == yuvInfo.fSizeInfo.fColorTypes[i] &&
- !yuvInfo.fSizeInfo.fWidthBytes[i] &&
- !yuvInfo.fSizeInfo.fSizes[i].fHeight);
- planes[i] = nullptr;
- continue;
- }
-
- planes[i] = (uint8_t*)planes[i-1] + (yuvInfo.fSizeInfo.fWidthBytes[i-1] *
- yuvInfo.fSizeInfo.fSizes[i-1].fHeight);
- }
+ planes[0] = (void*)data->data();
+ planes[1] = (uint8_t*)planes[0] + (yuvInfo.fSizeInfo.fWidthBytes[SkYUVSizeInfo::kY] *
+ yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight);
+ planes[2] = (uint8_t*)planes[1] + (yuvInfo.fSizeInfo.fWidthBytes[SkYUVSizeInfo::kU] *
+ yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kU].fHeight);
} else {
// Fetch yuv plane sizes for memory allocation.
- if (!this->onQueryYUVA8(&yuvInfo.fSizeInfo, yuvInfo.fYUVAIndices, &yuvInfo.fColorSpace)) {
+ if (!this->onQueryYUV8(&yuvInfo.fSizeInfo, &yuvInfo.fColorSpace)) {
return nullptr;
}
- // Allocate the memory for YUVA
+ // Allocate the memory for YUV
size_t totalSize(0);
- for (int i = 0; i < SkYUVSizeInfo::kMaxCount; i++) {
- SkASSERT(kUnknown_SkColorType != yuvInfo.fSizeInfo.fColorTypes[i] ||
- (!yuvInfo.fSizeInfo.fWidthBytes[i] && !yuvInfo.fSizeInfo.fSizes[i].fHeight));
-
+ for (int i = 0; i < 3; i++) {
totalSize += yuvInfo.fSizeInfo.fWidthBytes[i] * yuvInfo.fSizeInfo.fSizes[i].fHeight;
}
-
data.reset(SkResourceCache::NewCachedData(totalSize));
-
planes[0] = data->writable_data();
-
- for (int i = 1; i < SkYUVSizeInfo::kMaxCount; ++i) {
- if (!yuvInfo.fSizeInfo.fWidthBytes[i]) {
- SkASSERT(kUnknown_SkColorType == yuvInfo.fSizeInfo.fColorTypes[i] &&
- !yuvInfo.fSizeInfo.fWidthBytes[i] &&
- !yuvInfo.fSizeInfo.fSizes[i].fHeight);
- planes[i] = nullptr;
- continue;
- }
-
- planes[i] = (uint8_t*)planes[i-1] + (yuvInfo.fSizeInfo.fWidthBytes[i-1] *
- yuvInfo.fSizeInfo.fSizes[i-1].fHeight);
- }
+ planes[1] = (uint8_t*)planes[0] + (yuvInfo.fSizeInfo.fWidthBytes[SkYUVSizeInfo::kY] *
+ yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight);
+ planes[2] = (uint8_t*)planes[1] + (yuvInfo.fSizeInfo.fWidthBytes[SkYUVSizeInfo::kU] *
+ yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kU].fHeight);
// Get the YUV planes.
- if (!this->onGetYUVA8Planes(yuvInfo.fSizeInfo, yuvInfo.fYUVAIndices, planes)) {
+ if (!this->onGetYUV8Planes(yuvInfo.fSizeInfo, planes)) {
return nullptr;
}
@@ -88,12 +64,10 @@
}
*size = yuvInfo.fSizeInfo;
- memcpy(yuvaIndices, yuvInfo.fYUVAIndices, sizeof(yuvInfo.fYUVAIndices));
*colorSpace = yuvInfo.fColorSpace;
constPlanes[0] = planes[0];
constPlanes[1] = planes[1];
constPlanes[2] = planes[2];
- constPlanes[3] = planes[3];
return data;
}
@@ -107,33 +81,24 @@
SkColorSpace* srcColorSpace,
SkColorSpace* dstColorSpace) {
SkYUVSizeInfo yuvSizeInfo;
- SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount];
SkYUVColorSpace yuvColorSpace;
- const void* planes[SkYUVSizeInfo::kMaxCount];
+ const void* planes[3];
- sk_sp<SkCachedData> dataStorage = this->getPlanes(&yuvSizeInfo, yuvaIndices,
- &yuvColorSpace, planes);
+ sk_sp<SkCachedData> dataStorage = this->getPlanes(&yuvSizeInfo, &yuvColorSpace, planes);
if (!dataStorage) {
return nullptr;
}
- 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]);
- continue;
- }
-
+ sk_sp<GrTextureProxy> yuvTextureProxies[3];
+ for (int i = 0; i < 3; i++) {
int componentWidth = yuvSizeInfo.fSizes[i].fWidth;
int componentHeight = yuvSizeInfo.fSizes[i].fHeight;
// If the sizes of the components are not all the same we choose to create exact-match
// textures for the smaller ones rather than add a texture domain to the draw.
// TODO: revisit this decision to improve texture reuse?
SkBackingFit fit =
- (componentWidth != yuvSizeInfo.fSizes[0].fWidth) ||
- (componentHeight != yuvSizeInfo.fSizes[0].fHeight)
+ (componentWidth != yuvSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth) ||
+ (componentHeight != yuvSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight)
? SkBackingFit::kExact : SkBackingFit::kApprox;
SkImageInfo imageInfo = SkImageInfo::MakeA8(componentWidth, componentHeight);
@@ -166,8 +131,17 @@
return nullptr;
}
+ // This code path only generates I420 (i.e., 3 separate plane) YUVs
+ SkYUVAIndex yuvaIndices[4] = {
+ { 0, SkColorChannel::kA },
+ { 1, SkColorChannel::kA },
+ { 2, SkColorChannel::kA },
+ { -1, SkColorChannel::kA }, // no alpha
+ };
+
GrPaint paint;
- auto yuvToRgbProcessor = GrYUVtoRGBEffect::Make(yuvTextureProxies, yuvaIndices, yuvColorSpace);
+ auto yuvToRgbProcessor =
+ GrYUVtoRGBEffect::Make(yuvTextureProxies, yuvaIndices, yuvColorSpace);
paint.addColorFragmentProcessor(std::move(yuvToRgbProcessor));
// If the caller expects the pixels in a different color space than the one from the image,
@@ -180,8 +154,8 @@
}
paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
- const SkRect r = SkRect::MakeIWH(yuvSizeInfo.fSizes[0].fWidth,
- yuvSizeInfo.fSizes[0].fHeight);
+ const SkRect r = SkRect::MakeIWH(yuvSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth,
+ yuvSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight);
renderTargetContext->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), r);