Construct mipmaps for internal YUVA planes

Bug: skia:7901
Change-Id: I4d42ad752b18cc1cfbbb5d41eafc499c0541858b
Reviewed-on: https://skia-review.googlesource.com/c/169242
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
diff --git a/src/gpu/GrImageTextureMaker.cpp b/src/gpu/GrImageTextureMaker.cpp
index 0aae4b6..d324c5a 100644
--- a/src/gpu/GrImageTextureMaker.cpp
+++ b/src/gpu/GrImageTextureMaker.cpp
@@ -98,11 +98,10 @@
                                                         filterOrNullForBicubic);
     }
 
-    // Check to see if the client has given us pre-mipped textures
+    // Check to see if the client has given us pre-mipped textures or we can generate them
     // If not, fall back to bilerp
-    // TODO: investigate flattening the image and generating miplevels
     GrSamplerState::Filter filter = *filterOrNullForBicubic;
-    if (GrSamplerState::Filter::kMipMap == filter && !fImage->canBeMipmapped(fContext)) {
+    if (GrSamplerState::Filter::kMipMap == filter && !fImage->setupMipmapsForPlanes()) {
         filter = GrSamplerState::Filter::kBilerp;
     }
 
@@ -110,4 +109,3 @@
                                   fImage->fYUVColorSpace, filter);
 
 }
-
diff --git a/src/image/SkImage_GpuYUVA.cpp b/src/image/SkImage_GpuYUVA.cpp
index e577482..a18a4f4 100644
--- a/src/image/SkImage_GpuYUVA.cpp
+++ b/src/image/SkImage_GpuYUVA.cpp
@@ -56,7 +56,7 @@
                              fAlphaType, fColorSpace);
 }
 
-bool SkImage_GpuYUVA::canBeMipmapped(GrContext* context) const {
+bool SkImage_GpuYUVA::setupMipmapsForPlanes() const {
     int numTextures;
     if (!SkYUVAIndex::AreValidIndices(fYUVAIndices, &numTextures)) {
         return false;
@@ -69,7 +69,11 @@
                                                     fProxies[i].get(),
                                                     GrSamplerState::Filter::kMipMap,
                                                     &copyParams)) {
-            return false;
+            auto mippedProxy = GrCopyBaseMipMapToTextureProxy(fContext.get(), fProxies[i].get());
+            if (!mippedProxy) {
+                return false;
+            }
+            fProxies[i] = mippedProxy;
         }
     }
     return true;
diff --git a/src/image/SkImage_GpuYUVA.h b/src/image/SkImage_GpuYUVA.h
index 7e4150a..db61e67 100644
--- a/src/image/SkImage_GpuYUVA.h
+++ b/src/image/SkImage_GpuYUVA.h
@@ -49,7 +49,7 @@
         return true;
     }
 
-    bool canBeMipmapped(GrContext* context) const;
+    bool setupMipmapsForPlanes() const;
 
     // Returns a ref-ed texture proxy with miplevels
     sk_sp<GrTextureProxy> asMippedTextureProxyRef() const;
@@ -112,7 +112,7 @@
 private:
     // This array will usually only be sparsely populated.
     // The actual non-null fields are dictated by the 'fYUVAIndices' indices
-    sk_sp<GrTextureProxy>            fProxies[4];
+    mutable sk_sp<GrTextureProxy>    fProxies[4];
     SkYUVAIndex                      fYUVAIndices[4];
     // This is only allocated when the image needs to be flattened rather than
     // using the separate YUVA planes. From thence forth we will only use the