[Dawn] Add YCbCr info to DawnTextureSpec

Ensures that YCbCr info will be preserved when going back and forth
between DawnTextureInfo and TextureInfo.

Bug: b/41488897
Change-Id: Id915c5937fc15e45a3af8f8ca86aa1c5661c741e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/863356
Reviewed-by: Greg Daniel <egdaniel@google.com>
Reviewed-by: Nicolette Prevost <nicolettep@google.com>
Commit-Queue: Colin Blundell <blundell@chromium.org>
diff --git a/include/private/gpu/graphite/DawnTypesPriv.h b/include/private/gpu/graphite/DawnTypesPriv.h
index c3c4aa0..6e4fbad 100644
--- a/include/private/gpu/graphite/DawnTypesPriv.h
+++ b/include/private/gpu/graphite/DawnTypesPriv.h
@@ -20,18 +20,29 @@
             , fViewFormat(info.fViewFormat)
             , fUsage(info.fUsage)
             , fAspect(info.fAspect)
-            , fSlice(info.fSlice) {}
+#if !defined(__EMSCRIPTEN__)
+            , fYcbcrVkDescriptor(info.fYcbcrVkDescriptor)
+#endif
+            , fSlice(info.fSlice) {
+    }
 
     bool operator==(const DawnTextureSpec& that) const {
         return fUsage == that.fUsage && fFormat == that.fFormat &&
                fViewFormat == that.fViewFormat && fAspect == that.fAspect &&
+#if !defined(__EMSCRIPTEN__)
+               IsEqualToYCbCrVkDescriptorField(that.fYcbcrVkDescriptor) &&
+#endif
                fSlice == that.fSlice;
     }
 
     bool isCompatible(const DawnTextureSpec& that) const {
         // The usages may match or the usage passed in may be a superset of the usage stored within.
+        // The YCbCrInfo must be equal.
         // The aspect should either match the plane aspect or should be All.
         return getViewFormat() == that.getViewFormat() && (fUsage & that.fUsage) == fUsage &&
+#if !defined(__EMSCRIPTEN__)
+               IsEqualToYCbCrVkDescriptorField(that.fYcbcrVkDescriptor) &&
+#endif
                (fAspect == that.fAspect || fAspect == wgpu::TextureAspect::All);
     }
 
@@ -47,7 +58,27 @@
     wgpu::TextureFormat fViewFormat = wgpu::TextureFormat::Undefined;
     wgpu::TextureUsage fUsage = wgpu::TextureUsage::None;
     wgpu::TextureAspect fAspect = wgpu::TextureAspect::All;
+#if !defined(__EMSCRIPTEN__)
+    wgpu::YCbCrVkDescriptor fYcbcrVkDescriptor = {};
+#endif
     uint32_t fSlice = 0;
+
+private:
+#if !defined(__EMSCRIPTEN__)
+    bool IsEqualToYCbCrVkDescriptorField(wgpu::YCbCrVkDescriptor that) const {
+        return fYcbcrVkDescriptor.vkFormat == that.vkFormat &&
+               fYcbcrVkDescriptor.vkYCbCrRange == that.vkYCbCrRange &&
+               fYcbcrVkDescriptor.vkComponentSwizzleRed == that.vkComponentSwizzleRed &&
+               fYcbcrVkDescriptor.vkComponentSwizzleGreen == that.vkComponentSwizzleGreen &&
+               fYcbcrVkDescriptor.vkComponentSwizzleBlue == that.vkComponentSwizzleBlue &&
+               fYcbcrVkDescriptor.vkComponentSwizzleAlpha == that.vkComponentSwizzleAlpha &&
+               fYcbcrVkDescriptor.vkXChromaOffset == that.vkXChromaOffset &&
+               fYcbcrVkDescriptor.vkYChromaOffset == that.vkYChromaOffset &&
+               fYcbcrVkDescriptor.vkChromaFilter == that.vkChromaFilter &&
+               fYcbcrVkDescriptor.forceExplicitReconstruction == that.forceExplicitReconstruction &&
+               fYcbcrVkDescriptor.externalFormat == that.externalFormat;
+    }
+#endif
 };
 
 DawnTextureInfo DawnTextureSpecToTextureInfo(const DawnTextureSpec& dawnSpec,
diff --git a/src/gpu/graphite/dawn/DawnTypesPriv.cpp b/src/gpu/graphite/dawn/DawnTypesPriv.cpp
index e015acf..1375aa1 100644
--- a/src/gpu/graphite/dawn/DawnTypesPriv.cpp
+++ b/src/gpu/graphite/dawn/DawnTypesPriv.cpp
@@ -42,6 +42,9 @@
     info.fViewFormat = dawnSpec.fViewFormat;
     info.fUsage = dawnSpec.fUsage;
     info.fAspect = dawnSpec.fAspect;
+#if !defined(__EMSCRIPTEN__)
+    info.fYcbcrVkDescriptor = dawnSpec.fYcbcrVkDescriptor;
+#endif
 
     return info;
 }