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/codec/SkCodecImageGenerator.cpp b/src/codec/SkCodecImageGenerator.cpp
index 3005ee3..55a6575 100644
--- a/src/codec/SkCodecImageGenerator.cpp
+++ b/src/codec/SkCodecImageGenerator.cpp
@@ -8,7 +8,6 @@
 #include "SkCodecImageGenerator.h"
 #include "SkMakeUnique.h"
 #include "SkPixmapPriv.h"
-#include "SkYUVAIndex.h"
 
 std::unique_ptr<SkImageGenerator> SkCodecImageGenerator::MakeFromEncodedCodec(sk_sp<SkData> data) {
     auto codec = SkCodec::MakeFromData(data);
@@ -59,27 +58,13 @@
     return SkPixmapPriv::Orient(dst, fCodec->getOrigin(), decode);
 }
 
-bool SkCodecImageGenerator::onQueryYUVA8(SkYUVSizeInfo* sizeInfo,
-                                         SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
-                                         SkYUVColorSpace* colorSpace) const {
-    // This image generator always returns 3 separate non-interleaved planes
-    yuvaIndices[SkYUVAIndex::kY_Index].fIndex = 0;
-    yuvaIndices[SkYUVAIndex::kY_Index].fChannel = SkColorChannel::kR;
-    yuvaIndices[SkYUVAIndex::kU_Index].fIndex = 1;
-    yuvaIndices[SkYUVAIndex::kU_Index].fChannel = SkColorChannel::kR;
-    yuvaIndices[SkYUVAIndex::kV_Index].fIndex = 2;
-    yuvaIndices[SkYUVAIndex::kV_Index].fChannel = SkColorChannel::kR;
-    yuvaIndices[SkYUVAIndex::kA_Index].fIndex = -1;
-    yuvaIndices[SkYUVAIndex::kA_Index].fChannel = SkColorChannel::kR;
-
+bool SkCodecImageGenerator::onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const
+{
     return fCodec->queryYUV8(sizeInfo, colorSpace);
 }
 
-bool SkCodecImageGenerator::onGetYUVA8Planes(const SkYUVSizeInfo& sizeInfo,
-                                             const SkYUVAIndex indices[SkYUVAIndex::kIndexCount],
-                                             void* planes[]) {
+bool SkCodecImageGenerator::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) {
     SkCodec::Result result = fCodec->getYUV8Planes(sizeInfo, planes);
-    // TODO: check indices
 
     switch (result) {
         case SkCodec::kSuccess:
diff --git a/src/codec/SkCodecImageGenerator.h b/src/codec/SkCodecImageGenerator.h
index 9a64b7c..b9c9d3c 100644
--- a/src/codec/SkCodecImageGenerator.h
+++ b/src/codec/SkCodecImageGenerator.h
@@ -22,14 +22,12 @@
 protected:
     sk_sp<SkData> onRefEncodedData() override;
 
-    bool onGetPixels(
-        const SkImageInfo& info, void* pixels, size_t rowBytes, const Options& opts) override;
+    bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, const Options& opts)
+                     override;
 
-    bool onQueryYUVA8(
-        SkYUVSizeInfo*, SkYUVAIndex[SkYUVAIndex::kIndexCount], SkYUVColorSpace*) const override;
+    bool onQueryYUV8(SkYUVSizeInfo*, SkYUVColorSpace*) const override;
 
-    bool onGetYUVA8Planes(const SkYUVSizeInfo&, const SkYUVAIndex[SkYUVAIndex::kIndexCount],
-                          void* planes[]) override;
+    bool onGetYUV8Planes(const SkYUVSizeInfo&, void* planes[3]) override;
 
 private:
     /*
diff --git a/src/codec/SkJpegCodec.cpp b/src/codec/SkJpegCodec.cpp
index f5c23a2..257b764 100644
--- a/src/codec/SkJpegCodec.cpp
+++ b/src/codec/SkJpegCodec.cpp
@@ -831,18 +831,11 @@
     }
 
     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;
+    for (auto i : { SkYUVSizeInfo::kY, SkYUVSizeInfo::kU, SkYUVSizeInfo::kV }) {
         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;
-
     if (colorSpace) {
         *colorSpace = kJPEG_SkYUVColorSpace;
     }
@@ -850,22 +843,18 @@
     return true;
 }
 
-SkCodec::Result SkJpegCodec::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo,
-                                             void* planes[SkYUVSizeInfo::kMaxCount]) {
+SkCodec::Result SkJpegCodec::onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) {
     SkYUVSizeInfo defaultInfo;
 
     // 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] ||
-            sizeInfo.fWidthBytes[0] < defaultInfo.fWidthBytes[0] ||
-            sizeInfo.fWidthBytes[1] < defaultInfo.fWidthBytes[1] ||
-            sizeInfo.fWidthBytes[2] < defaultInfo.fWidthBytes[2]) {
+            sizeInfo.fSizes[SkYUVSizeInfo::kY] != defaultInfo.fSizes[SkYUVSizeInfo::kY] ||
+            sizeInfo.fSizes[SkYUVSizeInfo::kU] != defaultInfo.fSizes[SkYUVSizeInfo::kU] ||
+            sizeInfo.fSizes[SkYUVSizeInfo::kV] != defaultInfo.fSizes[SkYUVSizeInfo::kV] ||
+            sizeInfo.fWidthBytes[SkYUVSizeInfo::kY] < defaultInfo.fWidthBytes[SkYUVSizeInfo::kY] ||
+            sizeInfo.fWidthBytes[SkYUVSizeInfo::kU] < defaultInfo.fWidthBytes[SkYUVSizeInfo::kU] ||
+            sizeInfo.fWidthBytes[SkYUVSizeInfo::kV] < defaultInfo.fWidthBytes[SkYUVSizeInfo::kV]) {
         return fDecoderMgr->returnFailure("onGetYUV8Planes", kInvalidInput);
     }
 
@@ -890,9 +879,9 @@
 
     // Currently, we require that the Y plane dimensions match the image dimensions
     // and that the U and V planes are the same dimensions.
-    SkASSERT(sizeInfo.fSizes[1] == sizeInfo.fSizes[2]);
-    SkASSERT((uint32_t) sizeInfo.fSizes[0].width() == dinfo->output_width &&
-             (uint32_t) sizeInfo.fSizes[0].height() == dinfo->output_height);
+    SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kU] == sizeInfo.fSizes[SkYUVSizeInfo::kV]);
+    SkASSERT((uint32_t) sizeInfo.fSizes[SkYUVSizeInfo::kY].width() == dinfo->output_width &&
+            (uint32_t) sizeInfo.fSizes[SkYUVSizeInfo::kY].height() == dinfo->output_height);
 
     // Build a JSAMPIMAGE to handle output from libjpeg-turbo.  A JSAMPIMAGE has
     // a 2-D array of pixels for each of the components (Y, U, V) in the image.
@@ -909,19 +898,20 @@
     // Initialize rowptrs.
     int numYRowsPerBlock = DCTSIZE * dinfo->comp_info[0].v_samp_factor;
     for (int i = 0; i < numYRowsPerBlock; i++) {
-        rowptrs[i] = SkTAddOffset<JSAMPLE>(planes[0], i * sizeInfo.fWidthBytes[0]);
+        rowptrs[i] = SkTAddOffset<JSAMPLE>(planes[SkYUVSizeInfo::kY],
+                i * sizeInfo.fWidthBytes[SkYUVSizeInfo::kY]);
     }
     for (int i = 0; i < DCTSIZE; i++) {
-        rowptrs[i + 2 * DCTSIZE] =
-            SkTAddOffset<JSAMPLE>(planes[1], i * sizeInfo.fWidthBytes[1]);
-        rowptrs[i + 3 * DCTSIZE] =
-            SkTAddOffset<JSAMPLE>(planes[2], i * sizeInfo.fWidthBytes[2]);
+        rowptrs[i + 2 * DCTSIZE] = SkTAddOffset<JSAMPLE>(planes[SkYUVSizeInfo::kU],
+                i * sizeInfo.fWidthBytes[SkYUVSizeInfo::kU]);
+        rowptrs[i + 3 * DCTSIZE] = SkTAddOffset<JSAMPLE>(planes[SkYUVSizeInfo::kV],
+                i * sizeInfo.fWidthBytes[SkYUVSizeInfo::kV]);
     }
 
     // After each loop iteration, we will increment pointers to Y, U, and V.
-    size_t blockIncrementY = numYRowsPerBlock * sizeInfo.fWidthBytes[0];
-    size_t blockIncrementU = DCTSIZE * sizeInfo.fWidthBytes[1];
-    size_t blockIncrementV = DCTSIZE * sizeInfo.fWidthBytes[2];
+    size_t blockIncrementY = numYRowsPerBlock * sizeInfo.fWidthBytes[SkYUVSizeInfo::kY];
+    size_t blockIncrementU = DCTSIZE * sizeInfo.fWidthBytes[SkYUVSizeInfo::kU];
+    size_t blockIncrementV = DCTSIZE * sizeInfo.fWidthBytes[SkYUVSizeInfo::kV];
 
     uint32_t numRowsPerBlock = numYRowsPerBlock;
 
@@ -954,7 +944,7 @@
         // this requirement using a dummy row buffer.
         // FIXME: Should SkCodec have an extra memory buffer that can be shared among
         //        all of the implementations that use temporary/garbage memory?
-        SkAutoTMalloc<JSAMPLE> dummyRow(sizeInfo.fWidthBytes[SkYUVAIndex::kY_Index]);
+        SkAutoTMalloc<JSAMPLE> dummyRow(sizeInfo.fWidthBytes[SkYUVSizeInfo::kY]);
         for (int i = remainingRows; i < numYRowsPerBlock; i++) {
             rowptrs[i] = dummyRow.get();
         }
diff --git a/src/codec/SkJpegCodec.h b/src/codec/SkJpegCodec.h
index c102627..5eff1d5 100644
--- a/src/codec/SkJpegCodec.h
+++ b/src/codec/SkJpegCodec.h
@@ -46,8 +46,7 @@
 
     bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override;
 
-    Result onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo,
-                           void* planes[SkYUVSizeInfo::kMaxCount]) override;
+    Result onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override;
 
     SkEncodedImageFormat onGetEncodedFormat() const override {
         return SkEncodedImageFormat::kJPEG;
diff --git a/src/core/SkImageGenerator.cpp b/src/core/SkImageGenerator.cpp
index 42d5214..e0275a1 100644
--- a/src/core/SkImageGenerator.cpp
+++ b/src/core/SkImageGenerator.cpp
@@ -8,7 +8,6 @@
 #include "SkImage.h"
 #include "SkImageGenerator.h"
 #include "SkNextID.h"
-#include "SkYUVAIndex.h"
 
 SkImageGenerator::SkImageGenerator(const SkImageInfo& info, uint32_t uniqueID)
     : fInfo(info)
@@ -30,119 +29,28 @@
     return this->onGetPixels(info, pixels, rowBytes, defaultOpts);
 }
 
-bool SkImageGenerator::queryYUVA8(SkYUVSizeInfo* sizeInfo,
-                                  SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
-                                  SkYUVColorSpace* colorSpace) const {
+bool SkImageGenerator::queryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const {
     SkASSERT(sizeInfo);
 
-    if (!this->onQueryYUVA8(sizeInfo, yuvaIndices, colorSpace)) {
-        // try the deprecated method and make a guess at the other data
-        if (this->onQueryYUV8(sizeInfo, colorSpace)) {
-            // take a guess at the number of planes
-            int numPlanes = SkYUVSizeInfo::kMaxCount;
-            for (int i = 0; i < SkYUVSizeInfo::kMaxCount; ++i) {
-                if (sizeInfo->fSizes[i].isEmpty()) {
-                    numPlanes = i;
-                    break;
-                }
-            }
-            if (!numPlanes) {
-                return false;
-            }
-            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;
-                    yuvaIndices[SkYUVAIndex::kU_Index].fChannel = SkColorChannel::kG;
-                    yuvaIndices[SkYUVAIndex::kV_Index].fIndex = 0;
-                    yuvaIndices[SkYUVAIndex::kV_Index].fChannel = SkColorChannel::kB;
-                    yuvaIndices[SkYUVAIndex::kA_Index].fIndex = -1;
-                    yuvaIndices[SkYUVAIndex::kA_Index].fChannel = SkColorChannel::kR;
-                    break;
-                case 2:
-                    // Assume 1 Y plane and interleaved UV planes
-                    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;
-                    yuvaIndices[SkYUVAIndex::kU_Index].fChannel = SkColorChannel::kR;
-                    yuvaIndices[SkYUVAIndex::kV_Index].fIndex = 1;
-                    yuvaIndices[SkYUVAIndex::kV_Index].fChannel = SkColorChannel::kG;
-                    yuvaIndices[SkYUVAIndex::kA_Index].fIndex = -1;
-                    yuvaIndices[SkYUVAIndex::kA_Index].fChannel = SkColorChannel::kR;
-                    break;
-                case 3:
-                    // 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;
-                    yuvaIndices[SkYUVAIndex::kU_Index].fChannel = SkColorChannel::kR;
-                    yuvaIndices[SkYUVAIndex::kV_Index].fIndex = 2;
-                    yuvaIndices[SkYUVAIndex::kV_Index].fChannel = SkColorChannel::kR;
-                    yuvaIndices[SkYUVAIndex::kA_Index].fIndex = -1;
-                    yuvaIndices[SkYUVAIndex::kA_Index].fChannel = SkColorChannel::kR;
-                    break;
-                case 4:
-                default:
-                    // Assume 4 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] = kAlpha_8_SkColorType;
-                    yuvaIndices[SkYUVAIndex::kY_Index].fIndex = 0;
-                    yuvaIndices[SkYUVAIndex::kY_Index].fChannel = SkColorChannel::kR;
-                    yuvaIndices[SkYUVAIndex::kU_Index].fIndex = 1;
-                    yuvaIndices[SkYUVAIndex::kU_Index].fChannel = SkColorChannel::kR;
-                    yuvaIndices[SkYUVAIndex::kV_Index].fIndex = 2;
-                    yuvaIndices[SkYUVAIndex::kV_Index].fChannel = SkColorChannel::kR;
-                    yuvaIndices[SkYUVAIndex::kA_Index].fIndex = 3;
-                    yuvaIndices[SkYUVAIndex::kA_Index].fChannel = SkColorChannel::kR;
-                    break;
-            }
-
-            return true;
-        }
-
-        return false;
-    }
-
-    return true;
+    return this->onQueryYUV8(sizeInfo, colorSpace);
 }
 
-bool SkImageGenerator::getYUVA8Planes(const SkYUVSizeInfo& sizeInfo,
-                                      const SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
-                                      void* planes[SkYUVSizeInfo::kMaxCount]) {
+bool SkImageGenerator::getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) {
+    SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth >= 0);
+    SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight >= 0);
+    SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kU].fWidth >= 0);
+    SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kU].fHeight >= 0);
+    SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kV].fWidth >= 0);
+    SkASSERT(sizeInfo.fSizes[SkYUVSizeInfo::kV].fHeight >= 0);
+    SkASSERT(sizeInfo.fWidthBytes[SkYUVSizeInfo::kY] >=
+            (size_t) sizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth);
+    SkASSERT(sizeInfo.fWidthBytes[SkYUVSizeInfo::kU] >=
+            (size_t) sizeInfo.fSizes[SkYUVSizeInfo::kU].fWidth);
+    SkASSERT(sizeInfo.fWidthBytes[SkYUVSizeInfo::kV] >=
+            (size_t) sizeInfo.fSizes[SkYUVSizeInfo::kV].fWidth);
+    SkASSERT(planes && planes[0] && planes[1] && planes[2]);
 
-    for (int i = 0; i < SkYUVSizeInfo::kMaxCount; ++i) {
-        SkASSERT(sizeInfo.fSizes[i].fWidth >= 0);
-        SkASSERT(sizeInfo.fSizes[i].fHeight >= 0);
-        SkASSERT(sizeInfo.fWidthBytes[i] >= (size_t) sizeInfo.fSizes[i].fWidth);
-    }
-
-    int numPlanes = 0;
-    SkASSERT(SkYUVAIndex::AreValidIndices(yuvaIndices, &numPlanes));
-    SkASSERT(planes);
-    for (int i = 0; i < numPlanes; ++i) {
-        SkASSERT(planes[i]);
-    }
-
-    if (!this->onGetYUVA8Planes(sizeInfo, yuvaIndices, planes)) {
-        return this->onGetYUV8Planes(sizeInfo, planes);
-    }
-    return true;
+    return this->onGetYUV8Planes(sizeInfo, planes);
 }
 
 #if SK_SUPPORT_GPU
diff --git a/src/core/SkYUVPlanesCache.h b/src/core/SkYUVPlanesCache.h
index 648f194..1c866a2 100644
--- a/src/core/SkYUVPlanesCache.h
+++ b/src/core/SkYUVPlanesCache.h
@@ -10,7 +10,6 @@
 
 #include "SkCachedData.h"
 #include "SkImageInfo.h"
-#include "SkYUVAIndex.h"
 #include "SkYUVSizeInfo.h"
 
 class SkResourceCache;
@@ -18,15 +17,14 @@
 class SkYUVPlanesCache {
 public:
     /**
-     * The Info struct contains data about the 4 Y, U, V, and A planes of memory stored
+     * The Info struct contains data about the 3 Y, U and V planes of memory stored
      * contiguously, in that order, as a single block of memory within SkYUVPlanesCache.
      *
-     * fSizeInfo: fWidth, fHeight, and fWidthBytes of each of the Y, U, V, and A planes.
+     * fSizeInfo: fWidth, fHeight, and fWidthBytes of each of the Y, U, and V planes.
      * fColorSpace: color space that will be used for the YUV -> RGB conversion.
      */
     struct Info {
         SkYUVSizeInfo   fSizeInfo;
-        SkYUVAIndex     fYUVAIndices[SkYUVAIndex::kIndexCount];
         SkYUVColorSpace fColorSpace;
     };
     /**
diff --git a/src/core/SkYUVSizeInfo.cpp b/src/core/SkYUVSizeInfo.cpp
deleted file mode 100644
index 7ebdbb9..0000000
--- a/src/core/SkYUVSizeInfo.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright 2018 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkYUVSizeInfo.h"
-#include "SkTemplates.h"
-
-void SkYUVSizeInfo::computePlanes(void* base, void* planes[SkYUVSizeInfo::kMaxCount]) const {
-    planes[0] = base;
-    int i = 1;
-    for (; i < SkYUVSizeInfo::kMaxCount; ++i) {
-        if (fSizes[i].isEmpty()) {
-            break;
-        }
-        planes[i] = SkTAddOffset<void>(planes[i - 1], fWidthBytes[i - 1] * fSizes[i - 1].height());
-    }
-    for (; i < SkYUVSizeInfo::kMaxCount; ++i) {
-        planes[i] = nullptr;
-    }
-}
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);
 
diff --git a/src/gpu/GrYUVProvider.h b/src/gpu/GrYUVProvider.h
index 505274e..de6ce33 100644
--- a/src/gpu/GrYUVProvider.h
+++ b/src/gpu/GrYUVProvider.h
@@ -17,7 +17,6 @@
 class GrTexture;
 class GrTextureProxy;
 class SkCachedData;
-struct SkYUVAIndex;
 
 /**
  *  There are at least 2 different ways to extract/retrieve YUV planar data...
@@ -44,8 +43,7 @@
                                             SkColorSpace* srcColorSpace,
                                             SkColorSpace* dstColorSpace);
 
-    sk_sp<SkCachedData> getPlanes(SkYUVSizeInfo*, SkYUVAIndex[SkYUVAIndex::kIndexCount],
-                                  SkYUVColorSpace*, const void* planes[SkYUVSizeInfo::kMaxCount]);
+    sk_sp<SkCachedData> getPlanes(SkYUVSizeInfo*, SkYUVColorSpace*, const void* planes[3]);
 
 private:
     virtual uint32_t onGetID() const = 0;
@@ -56,29 +54,23 @@
      *  If decoding to YUV is supported, this returns true.  Otherwise, this
      *  returns false and does not modify any of the parameters.
      *
-     *  @param sizeInfo    Output parameter indicating the sizes and required
-     *                     allocation widths of the Y, U, V, and A planes.
-     *  @param yuvaIndices How the YUVA planes are used/organized
-     *  @param colorSpace  Output parameter.
+     *  @param sizeInfo   Output parameter indicating the sizes and required
+     *                    allocation widths of the Y, U, and V planes.
+     *  @param colorSpace Output parameter.
      */
-    virtual bool onQueryYUVA8(SkYUVSizeInfo* sizeInfo,
-                              SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
-                              SkYUVColorSpace* colorSpace) const = 0;
+    virtual bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const = 0;
 
     /**
      *  Returns true on success and false on failure.
      *  This always attempts to perform a full decode.  If the client only
-     *  wants size, it should call onQueryYUVA8().
+     *  wants size, it should call onQueryYUV8().
      *
-     *  @param sizeInfo    Needs to exactly match the values returned by the
-     *                     query, except the WidthBytes may be larger than the
-     *                     recommendation (but not smaller).
-     *  @param yuvaIndices How the YUVA planes are used/organized
-     *  @param planes      Memory for each of the Y, U, V, and A planes.
+     *  @param sizeInfo   Needs to exactly match the values returned by the
+     *                    query, except the WidthBytes may be larger than the
+     *                    recommendation (but not smaller).
+     *  @param planes     Memory for each of the Y, U, and V planes.
      */
-    virtual bool onGetYUVA8Planes(const SkYUVSizeInfo& sizeInfo,
-                                  const SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
-                                  void* planes[]) = 0;
+    virtual bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) = 0;
 
     // This is used as release callback for the YUV data that we capture in an SkImage when
     // uploading to a gpu. When the upload is complete and we release the SkImage this callback will
diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp
index dcdd103..75cf127 100644
--- a/src/image/SkImage.cpp
+++ b/src/image/SkImage.cpp
@@ -227,8 +227,7 @@
     return as_IB(this)->onAsLegacyBitmap(bitmap);
 }
 
-sk_sp<SkCachedData> SkImage_Base::getPlanes(SkYUVSizeInfo*, SkYUVAIndex[4],
-                                            SkYUVColorSpace*, const void*[4]) {
+sk_sp<SkCachedData> SkImage_Base::getPlanes(SkYUVSizeInfo*, SkYUVColorSpace*,const void*[3]) {
     return nullptr;
 }
 
diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h
index 7bbd81d..8765f89 100644
--- a/src/image/SkImage_Base.h
+++ b/src/image/SkImage_Base.h
@@ -72,8 +72,7 @@
 
     virtual sk_sp<SkImage> onMakeSubset(const SkIRect&) const = 0;
 
-    virtual sk_sp<SkCachedData> getPlanes(SkYUVSizeInfo*, SkYUVAIndex[4],
-                                          SkYUVColorSpace*, const void* planes[4]);
+    virtual sk_sp<SkCachedData> getPlanes(SkYUVSizeInfo*, SkYUVColorSpace*, const void* planes[3]);
     virtual sk_sp<SkData> onRefEncoded() const { return nullptr; }
 
     virtual bool onAsLegacyBitmap(SkBitmap*) const;
diff --git a/src/image/SkImage_GpuYUVA.cpp b/src/image/SkImage_GpuYUVA.cpp
index 2fd4406..25b9349 100644
--- a/src/image/SkImage_GpuYUVA.cpp
+++ b/src/image/SkImage_GpuYUVA.cpp
@@ -233,7 +233,6 @@
     }
 
     // Set up color types
-    // TODO: pass in the correct color type rather than deducing it?
     SkColorType texColorTypes[4] = { kUnknown_SkColorType, kUnknown_SkColorType,
                                      kUnknown_SkColorType, kUnknown_SkColorType };
     for (int yuvIndex = 0; yuvIndex < 4; ++yuvIndex) {
@@ -248,6 +247,10 @@
             texColorTypes[texIdx] = kRGBA_8888_SkColorType;
         }
     }
+    // If UV is interleaved, then Y will have RGBA color type
+    if (kRGBA_8888_SkColorType == texColorTypes[yuvaIndices[SkYUVAIndex::kU_Index].fIndex]) {
+        texColorTypes[yuvaIndices[SkYUVAIndex::kY_Index].fIndex] = kRGBA_8888_SkColorType;
+    }
 
     // Get lazy proxies
     GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider();
@@ -258,17 +261,9 @@
             GrPixelConfig fConfig;
             SkPromiseImageHelper fPromiseHelper;
         } params;
-        bool res = context->contextPriv().caps()->getConfigFromBackendFormat(yuvaFormats[texIdx],
-                                                                             texColorTypes[texIdx],
-                                                                             &params.fConfig);
-        // Even though the data is single channel, we might be handed a multi-channel texture.
-        // To cover this case, we'll re-try with the RGBA colortype on failure.
-        if (!res && kAlpha_8_SkColorType == texColorTypes[texIdx]) {
-            res = context->contextPriv().caps()->getConfigFromBackendFormat(yuvaFormats[texIdx],
-                                                                            kRGBA_8888_SkColorType,
-                                                                            &params.fConfig);
-        }
-        if (!res) {
+        if (!context->contextPriv().caps()->getConfigFromBackendFormat(yuvaFormats[texIdx],
+                                                                       texColorTypes[texIdx],
+                                                                       &params.fConfig)) {
             return nullptr;
         }
         params.fPromiseHelper = promiseHelpers[texIdx];
diff --git a/src/image/SkImage_Lazy.cpp b/src/image/SkImage_Lazy.cpp
index 1688a81..7071b4b 100644
--- a/src/image/SkImage_Lazy.cpp
+++ b/src/image/SkImage_Lazy.cpp
@@ -355,15 +355,11 @@
 
 private:
     uint32_t onGetID() const override { return fGen->uniqueID(); }
-    bool onQueryYUVA8(SkYUVSizeInfo* sizeInfo,
-                      SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
-                      SkYUVColorSpace* colorSpace) const override {
-        return fGen->queryYUVA8(sizeInfo, yuvaIndices, colorSpace);
+    bool onQueryYUV8(SkYUVSizeInfo* sizeInfo, SkYUVColorSpace* colorSpace) const override {
+        return fGen->queryYUV8(sizeInfo, colorSpace);
     }
-    bool onGetYUVA8Planes(const SkYUVSizeInfo& sizeInfo,
-                          const SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
-                          void* planes[]) override {
-        return fGen->getYUVA8Planes(sizeInfo, yuvaIndices, planes);
+    bool onGetYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes[3]) override {
+        return fGen->getYUV8Planes(sizeInfo, planes);
     }
 
     SkImageGenerator* fGen;
@@ -388,14 +384,13 @@
     }
 }
 
-sk_sp<SkCachedData> SkImage_Lazy::getPlanes(SkYUVSizeInfo* yuvaSizeInfo,
-                                            SkYUVAIndex yuvaIndices[SkYUVAIndex::kIndexCount],
+sk_sp<SkCachedData> SkImage_Lazy::getPlanes(SkYUVSizeInfo* yuvSizeInfo,
                                             SkYUVColorSpace* yuvColorSpace,
-                                            const void* planes[SkYUVSizeInfo::kMaxCount]) {
+                                            const void* planes[3]) {
     ScopedGenerator generator(fSharedGenerator);
     Generator_GrYUVProvider provider(generator);
 
-    sk_sp<SkCachedData> data = provider.getPlanes(yuvaSizeInfo, yuvaIndices, yuvColorSpace, planes);
+    sk_sp<SkCachedData> data = provider.getPlanes(yuvSizeInfo, yuvColorSpace, planes);
     if (!data) {
         return nullptr;
     }
diff --git a/src/image/SkImage_Lazy.h b/src/image/SkImage_Lazy.h
index 5c30ee3..a2b434a 100644
--- a/src/image/SkImage_Lazy.h
+++ b/src/image/SkImage_Lazy.h
@@ -49,8 +49,7 @@
                                             const GrSamplerState&, SkColorSpace*,
                                             sk_sp<SkColorSpace>*,
                                             SkScalar scaleAdjust[2]) const override;
-    sk_sp<SkCachedData> getPlanes(SkYUVSizeInfo*, SkYUVAIndex[4],
-                                  SkYUVColorSpace*, const void* planes[4]) override;
+    sk_sp<SkCachedData> getPlanes(SkYUVSizeInfo*, SkYUVColorSpace*, const void* planes[3]) override;
 #endif
     sk_sp<SkData> onRefEncoded() const override;
     sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;