GrContext option to prevent GPU based YUV -> RGB

Rob and I spent a long time debugging why this wasn't working for
Flutter - doing the more complex operations on the loading thread
produces a blank texture when it's used later on the drawing thread.

Limiting ourselves to just creating and uploading RGBA data fixes
that. We need to debug what's going wrong, but in the meantime, this
lets Flutter use Skia APIs to manage GPU uploading and lifetime of
texture-backed images, while still doing those uploads on their IO
thread.

BUG=skia:

Change-Id: Ibf5c37f2439814544beab8c93c2a646f7a9e779d
Reviewed-on: https://skia-review.googlesource.com/8443
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index f7bfd9a..f268b88 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -394,6 +394,7 @@
     GrAtlasGlyphCache*                      fAtlasGlyphCache;
     std::unique_ptr<GrTextBlobCache>        fTextBlobCache;
 
+    bool                                    fDisableGpuYUVConversion;
     bool                                    fDidTestPMConversions;
     int                                     fPMToUPMConversion;
     int                                     fUPMToPMConversion;
diff --git a/include/gpu/GrContextOptions.h b/include/gpu/GrContextOptions.h
index ac38470..a2e4288 100644
--- a/include/gpu/GrContextOptions.h
+++ b/include/gpu/GrContextOptions.h
@@ -85,6 +85,12 @@
      * sRGB support.
      */
     bool fRequireDecodeDisableForSRGB = true;
+
+    /**
+     * If true, the GPU will not be used to perform YUV -> RGB conversion when generating
+     * textures from codec-backed images.
+     */
+    bool fDisableGpuYUVConversion = false;
 };
 
 #endif
diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp
index 8920fc6..9785648 100644
--- a/src/core/SkImageCacherator.cpp
+++ b/src/core/SkImageCacherator.cpp
@@ -17,6 +17,7 @@
 
 #if SK_SUPPORT_GPU
 #include "GrContext.h"
+#include "GrContextPriv.h"
 #include "GrGpuResourcePriv.h"
 #include "GrImageTextureMaker.h"
 #include "GrResourceKey.h"
@@ -569,7 +570,7 @@
 #endif
 
     // 4. Ask the generator to return YUV planes, which the GPU can convert
-    {
+    if (!ctx->contextPriv().disableGpuYUVConversion()) {
         ScopedGenerator generator(fSharedGenerator);
         Generator_GrYUVProvider provider(generator);
         sk_sp<GrTexture> tex = provider.refAsTexture(ctx, desc, true);
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 4b67d54..1001110 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -91,6 +91,7 @@
     fResourceCache = new GrResourceCache(fCaps);
     fResourceProvider = new GrResourceProvider(fGpu, fResourceCache, &fSingleOwner);
 
+    fDisableGpuYUVConversion = options.fDisableGpuYUVConversion;
     fDidTestPMConversions = false;
 
     GrRenderTargetOpList::Options rtOpListOptions;
diff --git a/src/gpu/GrContextPriv.h b/src/gpu/GrContextPriv.h
index 8ad3483..9ee0b9c 100644
--- a/src/gpu/GrContextPriv.h
+++ b/src/gpu/GrContextPriv.h
@@ -57,6 +57,8 @@
                                                                  sk_sp<SkColorSpace> colorSpace,
                                                                  const SkSurfaceProps* = nullptr);
 
+    bool disableGpuYUVConversion() const { return fContext->fDisableGpuYUVConversion; }
+
 private:
     explicit GrContextPriv(GrContext* context) : fContext(context) {}
     GrContextPriv(const GrContextPriv&) {} // unimpl