Store protectedness on GrVkImageInfo.

Changes the GrBackendSurface to not take it separately.

Change-Id: I5eb9684da1532907e7833e9d7835a74d1e71f5ca
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228396
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp
index 77a5617..257109e 100644
--- a/src/gpu/GrBackendSurface.cpp
+++ b/src/gpu/GrBackendSurface.cpp
@@ -259,17 +259,9 @@
         , fDawnInfo(dawnInfo) {}
 #endif
 
-GrBackendTexture::GrBackendTexture(int width,
-                                   int height,
-                                   const GrVkImageInfo& vkInfo)
-        : GrBackendTexture(width, height, GrProtected::kNo, vkInfo) {}
-
-GrBackendTexture::GrBackendTexture(int width,
-                                   int height,
-                                   GrProtected isProtected,
-                                   const GrVkImageInfo& vkInfo)
+GrBackendTexture::GrBackendTexture(int width, int height, const GrVkImageInfo& vkInfo)
 #ifdef SK_VULKAN
-        : GrBackendTexture(width, height, isProtected, vkInfo,
+        : GrBackendTexture(width, height, vkInfo,
                            sk_sp<GrVkImageLayout>(new GrVkImageLayout(vkInfo.fImageLayout))) {}
 #else
         : fIsValid(false) {}
@@ -300,11 +292,9 @@
 #ifdef SK_VULKAN
 GrBackendTexture::GrBackendTexture(int width,
                                    int height,
-                                   GrProtected isProtected,
                                    const GrVkImageInfo& vkInfo,
                                    sk_sp<GrVkImageLayout> layout)
         : fIsValid(true)
-        , fIsProtected(isProtected)
         , fWidth(width)
         , fHeight(height)
         , fConfig(kUnknown_GrPixelConfig)
@@ -379,7 +369,6 @@
         fIsValid = false;
     }
     fWidth = that.fWidth;
-    fIsProtected = that.fIsProtected;
     fHeight = that.fHeight;
     fConfig = that.fConfig;
     fMipMapped = that.fMipMapped;
@@ -497,6 +486,13 @@
     return false;
 }
 
+bool GrBackendTexture::isProtected() const {
+    if (!this->isValid() || this->backend() != GrBackendApi::kVulkan) {
+        return false;
+    }
+    return fVkInfo.isProtected();
+}
+
 bool GrBackendTexture::isSameTexture(const GrBackendTexture& that) {
     if (!this->isValid() || !that.isValid()) {
         return false;
@@ -624,7 +620,7 @@
                                              int sampleCnt,
                                              int stencilBits,
                                              const GrVkImageInfo& vkInfo)
-        : GrBackendRenderTarget(width, height, sampleCnt, GrProtected::kNo, vkInfo) {
+        : GrBackendRenderTarget(width, height, sampleCnt, vkInfo) {
     // This is a deprecated constructor that takes a bogus stencil bits.
     SkASSERT(0 == stencilBits);
 }
@@ -634,18 +630,7 @@
                                              int sampleCnt,
                                              const GrVkImageInfo& vkInfo)
 #ifdef SK_VULKAN
-        : GrBackendRenderTarget(width, height, sampleCnt, false, vkInfo) {}
-#else
-        : fIsValid(false) {}
-#endif
-
-GrBackendRenderTarget::GrBackendRenderTarget(int width,
-                                             int height,
-                                             int sampleCnt,
-                                             GrProtected isProtected,
-                                             const GrVkImageInfo& vkInfo)
-#ifdef SK_VULKAN
-        : GrBackendRenderTarget(width, height, sampleCnt, isProtected, vkInfo,
+        : GrBackendRenderTarget(width, height, sampleCnt, vkInfo,
                                 sk_sp<GrVkImageLayout>(new GrVkImageLayout(vkInfo.fImageLayout))) {}
 #else
         : fIsValid(false) {}
@@ -655,11 +640,9 @@
 GrBackendRenderTarget::GrBackendRenderTarget(int width,
                                              int height,
                                              int sampleCnt,
-                                             GrProtected isProtected,
                                              const GrVkImageInfo& vkInfo,
                                              sk_sp<GrVkImageLayout> layout)
         : fIsValid(true)
-        , fIsProtected(isProtected)
         , fWidth(width)
         , fHeight(height)
         , fSampleCnt(SkTMax(1, sampleCnt))
@@ -739,7 +722,6 @@
     }
     fWidth = that.fWidth;
     fHeight = that.fHeight;
-    fIsProtected = that.fIsProtected;
     fSampleCnt = that.fSampleCnt;
     fStencilBits = that.fStencilBits;
     fConfig = that.fConfig;
@@ -870,6 +852,13 @@
     return false;
 }
 
+bool GrBackendRenderTarget::isProtected() const {
+    if (!this->isValid() || this->backend() != GrBackendApi::kVulkan) {
+        return false;
+    }
+    return fVkInfo.isProtected();
+}
+
 #if GR_TEST_UTILS
 bool GrBackendRenderTarget::TestingOnly_Equals(const GrBackendRenderTarget& r0,
                                                const GrBackendRenderTarget& r1) {
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index c62a033..b21fc2c 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -1942,7 +1942,7 @@
         SkDebugf("Failed to create testing only image\n");
         return GrBackendTexture();
     }
-    GrBackendTexture beTex = GrBackendTexture(w, h, isProtected, info);
+    GrBackendTexture beTex = GrBackendTexture(w, h, info);
 #if GR_TEST_UTILS
     // Lots of tests don't go through Skia's public interface which will set the config so for
     // testing we make sure we set a config here.
diff --git a/src/gpu/vk/GrVkImage.cpp b/src/gpu/vk/GrVkImage.cpp
index 059f191..a0bcd2f 100644
--- a/src/gpu/vk/GrVkImage.cpp
+++ b/src/gpu/vk/GrVkImage.cpp
@@ -176,7 +176,10 @@
     SkASSERT(VK_IMAGE_TILING_OPTIMAL == imageDesc.fImageTiling ||
              VK_SAMPLE_COUNT_1_BIT == vkSamples);
 
-    VkImageCreateFlags createflags = gpu->protectedContext() ? VK_IMAGE_CREATE_PROTECTED_BIT : 0;
+    VkImageCreateFlags createflags = 0;
+    if (imageDesc.fIsProtected == GrProtected::kYes || gpu->protectedContext()) {
+        createflags |= VK_IMAGE_CREATE_PROTECTED_BIT;
+    }
     const VkImageCreateInfo imageCreateInfo = {
         VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,         // sType
         nullptr,                                     // pNext
@@ -210,6 +213,8 @@
     info->fFormat = imageDesc.fFormat;
     info->fLevelCount = imageDesc.fLevels;
     info->fCurrentQueueFamily = VK_QUEUE_FAMILY_IGNORED;
+    info->fProtected =
+            (createflags & VK_IMAGE_CREATE_PROTECTED_BIT) ? GrProtected::kYes : GrProtected::kNo;
     return true;
 }
 
diff --git a/src/gpu/vk/GrVkRenderTarget.cpp b/src/gpu/vk/GrVkRenderTarget.cpp
index d3acfc1..79e827f 100644
--- a/src/gpu/vk/GrVkRenderTarget.cpp
+++ b/src/gpu/vk/GrVkRenderTarget.cpp
@@ -377,8 +377,7 @@
 
 GrBackendRenderTarget GrVkRenderTarget::getBackendRenderTarget() const {
     SkASSERT(!this->wrapsSecondaryCommandBuffer());
-    return GrBackendRenderTarget(this->width(), this->height(), this->numSamples(),
-                                 this->isProtected() ? GrProtected::kYes : GrProtected::kNo, fInfo,
+    return GrBackendRenderTarget(this->width(), this->height(), this->numSamples(), fInfo,
                                  this->grVkImageLayout());
 }
 
diff --git a/src/gpu/vk/GrVkTexture.cpp b/src/gpu/vk/GrVkTexture.cpp
index 4fba188..3aba5f1 100644
--- a/src/gpu/vk/GrVkTexture.cpp
+++ b/src/gpu/vk/GrVkTexture.cpp
@@ -158,9 +158,7 @@
 }
 
 GrBackendTexture GrVkTexture::getBackendTexture() const {
-    return GrBackendTexture(this->width(), this->height(),
-                            this->isProtected() ? GrProtected::kYes : GrProtected::kNo, fInfo,
-                            this->grVkImageLayout());
+    return GrBackendTexture(this->width(), this->height(), fInfo, this->grVkImageLayout());
 }
 
 GrVkGpu* GrVkTexture::getVkGpu() const {