Temporarily make TransferPixelsFromTest read BGRA as RGBA on ES.

Remove disable of transfer support on Tegra.

Longer term we want GrGLGpu to handle the swizzle to BGRA after reading
RGBA. However, deferring that work to be part of color-type/format
refactoring.

Bug: skia:8962
Change-Id: Ib1d75fe0330aaaa02330724e58a1374129274a8f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/206699
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index d64b288..7e6f942 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -2649,14 +2649,6 @@
         fTransferBufferType = kNone_TransferBufferType;
     }
 
-    // Unit test for TransferPixelsFromTest fails on Shield with X1. Unclear whether this is a
-    // driver bug or a bug in our implementation. It passes on desktop NVIDIA GPUs, so perhaps
-    // something related to OpenGL ES?
-    if (kTegra_GrGLRenderer == ctxInfo.renderer()) {
-        fTransferBufferSupport = false;
-        fTransferBufferType = kNone_TransferBufferType;
-    }
-
     // Using MIPs on this GPU seems to be a source of trouble.
     if (kPowerVR54x_GrGLRenderer == ctxInfo.renderer()) {
         fMipMapSupport = false;
diff --git a/tests/TransferPixelsTest.cpp b/tests/TransferPixelsTest.cpp
index 41b529b..0db85bb 100644
--- a/tests/TransferPixelsTest.cpp
+++ b/tests/TransferPixelsTest.cpp
@@ -40,10 +40,16 @@
                                     int width,
                                     int height,
                                     size_t rowBytesA,
-                                    size_t rowBytesB) {
+                                    size_t rowBytesB,
+                                    bool swiz) {
     for (int j = 0; j < height; ++j) {
         for (int i = 0; i < width; ++i) {
-            if (bufferA[i] != bufferB[i]) {
+            auto colorA = bufferA[i];
+            if (swiz) {
+                colorA = GrColorPackRGBA(GrColorUnpackB(colorA), GrColorUnpackG(colorA),
+                                         GrColorUnpackR(colorA), GrColorUnpackA(colorA));
+            }
+            if (colorA != bufferB[i]) {
                 return false;
             }
         }
@@ -133,7 +139,8 @@
                                                                      kTextureWidth,
                                                                      kTextureHeight,
                                                                      rowBytes,
-                                                                     rowBytes));
+                                                                     rowBytes,
+                                                                     false));
         }
 
         //////////////////////////
@@ -169,17 +176,28 @@
                                                                      kTextureWidth,
                                                                      kTextureHeight,
                                                                      rowBytes,
-                                                                     rowBytes));
+                                                                     rowBytes,
+                                                                     false));
         }
     }
 }
 
-void basic_transfer_from_test(skiatest::Reporter* reporter, GrContext* context,
+void basic_transfer_from_test(skiatest::Reporter* reporter, const sk_gpu_test::ContextInfo& ctxInfo,
                               GrColorType colorType, bool renderTarget) {
+    auto context = ctxInfo.grContext();
     if (GrCaps::kNone_MapFlags == context->priv().caps()->mapBufferFlags()) {
         return;
     }
 
+    // On OpenGL ES it may not be possible to read back in to BGRA becagse GL_RGBA/GL_UNSIGNED_BYTE
+    // may be the only allowed format/type params to glReadPixels. So read back into GL_RGBA.
+    // TODO(bsalomon): Make this work in GrGLGpu.
+    auto readColorType = colorType;
+    if (GrColorType::kBGRA_8888 == colorType &&
+        ctxInfo.type() == sk_gpu_test::GrContextFactory::kGLES_ContextType) {
+        readColorType = GrColorType::kRGBA_8888;
+    }
+
     auto resourceProvider = context->priv().resourceProvider();
     GrGpu* gpu = context->priv().getGpu();
 
@@ -250,8 +268,8 @@
 
         //////////////////////////
         // transfer full data
-        auto bufferRowBytes = gpu->transferPixelsFrom(tex.get(), 0, 0, kTextureWidth,
-                                                      kTextureHeight, colorType, buffer.get(), 0);
+        auto bufferRowBytes = gpu->transferPixelsFrom(
+                tex.get(), 0, 0, kTextureWidth, kTextureHeight, readColorType, buffer.get(), 0);
         REPORTER_ASSERT(reporter, bufferRowBytes = fullBufferRowBytes);
         if (!bufferRowBytes) {
             continue;
@@ -272,13 +290,15 @@
                                                                  kTextureWidth,
                                                                  kTextureHeight,
                                                                  textureDataRowBytes,
-                                                                 bufferRowBytes));
+                                                                 bufferRowBytes,
+                                                                 readColorType != colorType));
         buffer->unmap();
 
+        ///////////////////////
         // Now test a partial read at an offset into the buffer.
-        bufferRowBytes =
-                gpu->transferPixelsFrom(tex.get(), kPartialLeft, kPartialTop, kPartialWidth,
-                                        kPartialHeight, colorType, buffer.get(), partialReadOffset);
+        bufferRowBytes = gpu->transferPixelsFrom(tex.get(), kPartialLeft, kPartialTop,
+                                                 kPartialWidth, kPartialHeight, readColorType,
+                                                 buffer.get(), partialReadOffset);
         REPORTER_ASSERT(reporter, bufferRowBytes = partialBufferRowBytes);
         if (!bufferRowBytes) {
             continue;
@@ -304,7 +324,8 @@
                                                                  kPartialWidth,
                                                                  kPartialHeight,
                                                                  textureDataRowBytes,
-                                                                 bufferRowBytes));
+                                                                 bufferRowBytes,
+                                                                 readColorType != colorType));
         buffer->unmap();
     }
 #if GR_GPU_STATS
@@ -333,10 +354,10 @@
         return;
     }
     // RGBA
-    basic_transfer_from_test(reporter, ctxInfo.grContext(), GrColorType::kRGBA_8888, false);
-    basic_transfer_from_test(reporter, ctxInfo.grContext(), GrColorType::kRGBA_8888, true);
+    basic_transfer_from_test(reporter, ctxInfo, GrColorType::kRGBA_8888, false);
+    basic_transfer_from_test(reporter, ctxInfo, GrColorType::kRGBA_8888, true);
 
     // BGRA
-    basic_transfer_from_test(reporter, ctxInfo.grContext(), GrColorType::kBGRA_8888, false);
-    basic_transfer_from_test(reporter, ctxInfo.grContext(), GrColorType::kBGRA_8888, true);
+    basic_transfer_from_test(reporter, ctxInfo, GrColorType::kBGRA_8888, false);
+    basic_transfer_from_test(reporter, ctxInfo, GrColorType::kBGRA_8888, true);
 }