Simplify view getters on GrTextureProducer.

The only thing that affects the view returned is whether it ought to
be MIP mapped or not. So don't take a whole GrSamplerState.

The view() function won't ever change the colortype so just query
GrTextureProducer rather than having view() return a tuple.

The rest is transitively reaching through callers and callees of
GrTextureProducer::view() to only pass filter or GrMipMapped instead of
GrSamplerState. Also, some params that indicate whether MIPs are
requested are changed from bool to GrMipMapped. And some minor style
stuff (mainly de-yoda-ifying GrMipMapped checks, using
GrSurfaceProxyView operator bool()).

Change-Id: Ia184aa793cf51d42642ea3bb0521ce06da2efb10
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/274205
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/tests/GrMipMappedTest.cpp b/tests/GrMipMappedTest.cpp
index 1005d7b..ff71aa7 100644
--- a/tests/GrMipMappedTest.cpp
+++ b/tests/GrMipMappedTest.cpp
@@ -112,11 +112,11 @@
         return;
     }
 
-    for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) {
-        for (auto willUseMips : {false, true}) {
+    for (auto betMipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) {
+        for (auto requestMipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) {
             GrBackendTexture backendTex = context->createBackendTexture(
-                    kSize, kSize, kRGBA_8888_SkColorType,
-                    SkColors::kTransparent, mipMapped, GrRenderable::kNo, GrProtected::kNo);
+                    kSize, kSize, kRGBA_8888_SkColorType, SkColors::kTransparent, betMipMapped,
+                    GrRenderable::kNo, GrProtected::kNo);
 
             sk_sp<SkImage> image = SkImage::MakeFromTexture(context, backendTex,
                                                             kTopLeft_GrSurfaceOrigin,
@@ -152,8 +152,8 @@
             SkIPoint origin = SkIPoint::Make(0,0);
             SkImageInfo imageInfo = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType,
                                                       kPremul_SkAlphaType);
-            GrSurfaceProxyView genView = imageGen->generateTexture(context, imageInfo, origin,
-                                                                   willUseMips);
+            GrSurfaceProxyView genView =
+                    imageGen->generateTexture(context, imageInfo, origin, requestMipMapped);
             GrSurfaceProxy* genProxy = genView.proxy();
 
             REPORTER_ASSERT(reporter, genProxy);
@@ -188,7 +188,7 @@
                 GrGLTextureInfo origTexInfo;
                 if (genBackendTex.getGLTextureInfo(&genTexInfo) &&
                     backendTex.getGLTextureInfo(&origTexInfo)) {
-                    if (willUseMips && GrMipMapped::kNo == mipMapped) {
+                    if (requestMipMapped == GrMipMapped::kYes && betMipMapped == GrMipMapped::kNo) {
                         // We did a copy so the texture IDs should be different
                         REPORTER_ASSERT(reporter, origTexInfo.fID != genTexInfo.fID);
                     } else {
@@ -203,7 +203,7 @@
                 GrVkImageInfo origImageInfo;
                 if (genBackendTex.getVkImageInfo(&genImageInfo) &&
                     backendTex.getVkImageInfo(&origImageInfo)) {
-                    if (willUseMips && GrMipMapped::kNo == mipMapped) {
+                    if (requestMipMapped == GrMipMapped::kYes && betMipMapped == GrMipMapped::kNo) {
                         // We did a copy so the texture IDs should be different
                         REPORTER_ASSERT(reporter, origImageInfo.fImage != genImageInfo.fImage);
                     } else {
@@ -219,7 +219,7 @@
                 GrMtlTextureInfo origImageInfo;
                 if (genBackendTex.getMtlTextureInfo(&genImageInfo) &&
                     backendTex.getMtlTextureInfo(&origImageInfo)) {
-                    if (willUseMips && GrMipMapped::kNo == mipMapped) {
+                    if (requestMipMapped == GrMipMapped::kYes && betMipMapped == GrMipMapped::kNo) {
                         // We did a copy so the texture IDs should be different
                         REPORTER_ASSERT(reporter, origImageInfo.fTexture != genImageInfo.fTexture);
                     } else {
diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp
index 65288c4..b14a04b 100644
--- a/tests/GrSurfaceTest.cpp
+++ b/tests/GrSurfaceTest.cpp
@@ -407,7 +407,7 @@
         copySrcBitmap.setImmutable();
 
         GrBitmapTextureMaker maker(context, copySrcBitmap);
-        auto[copySrc, grCT] = maker.view(GrMipMapped::kNo);
+        auto copySrc = maker.view(GrMipMapped::kNo);
 
         REPORTER_ASSERT(reporter, copySrc.proxy());
         auto copyResult = surfContext->testCopy(copySrc.proxy(), copySrc.origin());
diff --git a/tests/ImageFilterCacheTest.cpp b/tests/ImageFilterCacheTest.cpp
index 5033e25..cdd2b9b 100644
--- a/tests/ImageFilterCacheTest.cpp
+++ b/tests/ImageFilterCacheTest.cpp
@@ -210,8 +210,7 @@
 static GrSurfaceProxyView create_proxy_view(GrRecordingContext* context) {
     SkBitmap srcBM = create_bm();
     GrBitmapTextureMaker maker(context, srcBM);
-    auto[view, grCT] = maker.view(GrMipMapped::kNo);
-    return view;
+    return maker.view(GrMipMapped::kNo);
 }
 
 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ctxInfo) {
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index 1a1969a..f2bfdad 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -970,19 +970,17 @@
             sk_sp<SkImage> refImg(imageMaker(ctx));
 
             // Any context should be able to borrow the texture at this point
-            GrSurfaceProxyView view = as_IB(refImg)->refView(ctx, GrSamplerState::Filter::kNearest);
+            GrSurfaceProxyView view = as_IB(refImg)->refView(ctx, GrMipMapped::kNo);
             REPORTER_ASSERT(reporter, view);
 
             // But once it's borrowed, no other context should be able to borrow
             otherTestContext->makeCurrent();
-            GrSurfaceProxyView otherView =
-                    as_IB(refImg)->refView(otherCtx, GrSamplerState::Filter::kNearest);
+            GrSurfaceProxyView otherView = as_IB(refImg)->refView(otherCtx, GrMipMapped::kNo);
             REPORTER_ASSERT(reporter, !otherView);
 
             // Original context (that's already borrowing) should be okay
             testContext->makeCurrent();
-            GrSurfaceProxyView viewSecondRef =
-                    as_IB(refImg)->refView(ctx, GrSamplerState::Filter::kNearest);
+            GrSurfaceProxyView viewSecondRef = as_IB(refImg)->refView(ctx, GrMipMapped::kNo);
             REPORTER_ASSERT(reporter, viewSecondRef);
 
             // Release first ref from the original context
@@ -991,7 +989,7 @@
             // We released one proxy but not the other from the current borrowing context. Make sure
             // a new context is still not able to borrow the texture.
             otherTestContext->makeCurrent();
-            otherView = as_IB(refImg)->refView(otherCtx, GrSamplerState::Filter::kNearest);
+            otherView = as_IB(refImg)->refView(otherCtx, GrMipMapped::kNo);
             REPORTER_ASSERT(reporter, !otherView);
 
             // Release second ref from the original context
@@ -1000,7 +998,7 @@
 
             // Now we should be able to borrow the texture from the other context
             otherTestContext->makeCurrent();
-            otherView = as_IB(refImg)->refView(otherCtx, GrSamplerState::Filter::kNearest);
+            otherView = as_IB(refImg)->refView(otherCtx, GrMipMapped::kNo);
             REPORTER_ASSERT(reporter, otherView);
 
             // Release everything
@@ -1041,7 +1039,7 @@
             sk_sp<SkImage> image = SkImage::MakeCrossContextFromPixmap(ctx, pixmap, false);
             REPORTER_ASSERT(reporter, image);
 
-            GrSurfaceProxyView view = as_IB(image)->refView(ctx, GrSamplerState::Filter::kNearest);
+            GrSurfaceProxyView view = as_IB(image)->refView(ctx, GrMipMapped::kNo);
             REPORTER_ASSERT(reporter, view);
 
             bool expectAlpha = kAlpha_8_SkColorType == ct;
diff --git a/tests/ProcessorTest.cpp b/tests/ProcessorTest.cpp
index c89a750..bee6739 100644
--- a/tests/ProcessorTest.cpp
+++ b/tests/ProcessorTest.cpp
@@ -281,7 +281,7 @@
                              [](void* addr, void* context) { delete[] (GrColor*)addr; }, nullptr);
         bitmap.setImmutable();
         GrBitmapTextureMaker maker(context, bitmap);
-        auto[view, grCT] = maker.view(GrMipMapped::kNo);
+        auto view = maker.view(GrMipMapped::kNo);
         if (!view.proxy() || !view.proxy()->instantiate(resourceProvider)) {
             return false;
         }
@@ -304,7 +304,7 @@
                              [](void* addr, void* context) { delete[] (uint8_t*)addr; }, nullptr);
         bitmap.setImmutable();
         GrBitmapTextureMaker maker(context, bitmap);
-        auto[view, grCT] = maker.view(GrMipMapped::kNo);
+        auto view = maker.view(GrMipMapped::kNo);
         if (!view.proxy() || !view.proxy()->instantiate(resourceProvider)) {
             return false;
         }
@@ -331,8 +331,7 @@
                          [](void* addr, void* context) { delete[] (GrColor*)addr; }, nullptr);
     bitmap.setImmutable();
     GrBitmapTextureMaker maker(context, bitmap);
-    auto[view, grCT] = maker.view(GrMipMapped::kNo);
-    return view;
+    return maker.view(GrMipMapped::kNo);
 }
 
 // We tag logged  data as unpremul to avoid conversion when encoding as  PNG. The input texture
diff --git a/tests/ReadWriteAlphaTest.cpp b/tests/ReadWriteAlphaTest.cpp
index 6435742..b4ddf88 100644
--- a/tests/ReadWriteAlphaTest.cpp
+++ b/tests/ReadWriteAlphaTest.cpp
@@ -67,14 +67,14 @@
         bitmap.installPixels(ii, alphaDataCopy, ii.minRowBytes());
         bitmap.setImmutable();
         GrBitmapTextureMaker maker(context, bitmap);
-        auto[view, grCT] = maker.view(GrMipMapped::kNo);
+        auto view = maker.view(GrMipMapped::kNo);
         if (!view.proxy()) {
             ERRORF(reporter, "Could not create alpha texture.");
             return;
         }
 
-        auto sContext = GrSurfaceContext::Make(context, std::move(view), grCT, kPremul_SkAlphaType,
-                                               nullptr);
+        auto sContext = GrSurfaceContext::Make(context, std::move(view), maker.colorType(),
+                                               kPremul_SkAlphaType, nullptr);
 
         sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, ii));
 
diff --git a/tests/SpecialImageTest.cpp b/tests/SpecialImageTest.cpp
index 026d0fd..74523e7 100644
--- a/tests/SpecialImageTest.cpp
+++ b/tests/SpecialImageTest.cpp
@@ -224,18 +224,18 @@
     {
         // gpu
         GrBitmapTextureMaker maker(context, bm);
-        auto[view, grCT] = maker.view(GrMipMapped::kNo);
-        if (!view.proxy()) {
+        auto view = maker.view(GrMipMapped::kNo);
+        if (!view) {
             return;
         }
 
-        sk_sp<SkSpecialImage> gpuImage(SkSpecialImage::MakeDeferredFromGpu(
-                                                            context,
-                                                            SkIRect::MakeWH(kFullSize, kFullSize),
-                                                            kNeedNewImageUniqueID_SpecialImage,
-                                                            std::move(view),
-                                                            grCT,
-                                                            nullptr));
+        sk_sp<SkSpecialImage> gpuImage(
+                SkSpecialImage::MakeDeferredFromGpu(context,
+                                                    SkIRect::MakeWH(kFullSize, kFullSize),
+                                                    kNeedNewImageUniqueID_SpecialImage,
+                                                    std::move(view),
+                                                    maker.colorType(),
+                                                    nullptr));
 
         {
             sk_sp<SkSpecialImage> fromGPU(gpuImage->makeTextureImage(context));
@@ -255,28 +255,29 @@
     GrContext* context = ctxInfo.grContext();
     SkBitmap bm = create_bm();
     GrBitmapTextureMaker maker(context, bm);
-    auto[view, grCT] = maker.view(GrMipMapped::kNo);
+    auto view = maker.view(GrMipMapped::kNo);
     if (!view.proxy()) {
         return;
     }
 
-    sk_sp<SkSpecialImage> fullSImg(SkSpecialImage::MakeDeferredFromGpu(
-                                                            context,
-                                                            SkIRect::MakeWH(kFullSize, kFullSize),
-                                                            kNeedNewImageUniqueID_SpecialImage,
-                                                            view,
-                                                            grCT,
-                                                            nullptr));
+    sk_sp<SkSpecialImage> fullSImg(
+            SkSpecialImage::MakeDeferredFromGpu(context,
+                                                SkIRect::MakeWH(kFullSize, kFullSize),
+                                                kNeedNewImageUniqueID_SpecialImage,
+                                                view,
+                                                maker.colorType(),
+                                                nullptr));
 
     const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
 
     {
         sk_sp<SkSpecialImage> subSImg1(SkSpecialImage::MakeDeferredFromGpu(
-                                                               context, subset,
-                                                               kNeedNewImageUniqueID_SpecialImage,
-                                                               std::move(view),
-                                                               grCT,
-                                                               nullptr));
+                context,
+                subset,
+                kNeedNewImageUniqueID_SpecialImage,
+                std::move(view),
+                maker.colorType(),
+                nullptr));
         test_image(subSImg1, reporter, context, true);
     }