Add DXGI_FORMAT to BackendFormat.

First steps to getting D3D texture format caps set up.

Bug: skia:9935
Change-Id: I905aaedd7d5fcc8b5137fcc8d8189e93260c9359
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/273797
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
diff --git a/include/gpu/GrBackendSurface.h b/include/gpu/GrBackendSurface.h
index f5c56b2..115dbe8 100644
--- a/include/gpu/GrBackendSurface.h
+++ b/include/gpu/GrBackendSurface.h
@@ -30,6 +30,10 @@
 #include "include/gpu/mtl/GrMtlTypes.h"
 #endif
 
+#ifdef SK_DIRECT3D
+enum DXGI_FORMAT;
+#endif
+
 #if GR_TEST_UTILS
 class SkString;
 #endif
@@ -90,6 +94,12 @@
     }
 #endif
 
+#ifdef SK_DIRECT3D
+    static GrBackendFormat MakeDxgi(DXGI_FORMAT format) {
+        return GrBackendFormat(format);
+    }
+#endif
+
     static GrBackendFormat MakeMock(GrColorType colorType, SkImage::CompressionType compression);
 
     bool operator==(const GrBackendFormat& that) const;
@@ -128,6 +138,14 @@
     GrMTLPixelFormat asMtlFormat() const;
 #endif
 
+#ifdef SK_DIRECT3D
+    /**
+     * If the backend API is Direct3D this gets the format as a DXGI_FORMAT and returns true.
+     * Otherwise, returns false.
+     */
+     bool asDxgiFormat(DXGI_FORMAT*) const;
+#endif
+
     /**
      * If the backend API is not Mock these two calls will return kUnknown and kNone, respectively.
      * Otherwise, if the compression type is kNone then the GrColorType will be valid. If the
@@ -161,6 +179,10 @@
     GrBackendFormat(const GrMTLPixelFormat mtlFormat);
 #endif
 
+#ifdef SK_DIRECT3D
+    GrBackendFormat(DXGI_FORMAT dxgiFormat);
+#endif
+
     GrBackendFormat(GrColorType, SkImage::CompressionType);
 
     GrBackendApi fBackend = GrBackendApi::kMock;
@@ -179,6 +201,10 @@
 #ifdef SK_METAL
         GrMTLPixelFormat fMtlFormat;
 #endif
+
+#ifdef SK_DIRECT3D
+        DXGI_FORMAT fDxgiFormat;
+#endif
         struct {
             GrColorType              fColorType;
             SkImage::CompressionType fCompressionType;
diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp
index 5e267b4..bf9fb40 100644
--- a/src/gpu/GrBackendSurface.cpp
+++ b/src/gpu/GrBackendSurface.cpp
@@ -24,6 +24,9 @@
 #include "include/gpu/mtl/GrMtlTypes.h"
 #include "src/gpu/mtl/GrMtlCppUtil.h"
 #endif
+#ifdef SK_DIRECT3D
+#include "include/gpu/d3d/GrD3D12.h"
+#endif
 
 GrBackendFormat::GrBackendFormat(const GrBackendFormat& that)
         : fBackend(that.fBackend)
@@ -51,7 +54,7 @@
 #endif
 #ifdef SK_DIRECT3D
         case GrBackendApi::kDirect3D:
-            //TODO fD3DFormat = that.fD3DFormat;
+            fDxgiFormat = that.fDxgiFormat;
             break;
 #endif
 #ifdef SK_DAWN
@@ -169,6 +172,23 @@
 }
 #endif
 
+#ifdef SK_DIRECT3D
+GrBackendFormat::GrBackendFormat(DXGI_FORMAT dxgiFormat)
+    : fBackend(GrBackendApi::kDirect3D)
+    , fValid(true)
+    , fDxgiFormat(dxgiFormat)
+    , fTextureType(GrTextureType::k2D) {
+}
+
+bool GrBackendFormat::asDxgiFormat(DXGI_FORMAT* dxgiFormat) const {
+    if (this->isValid() && GrBackendApi::kDirect3D == fBackend) {
+        *dxgiFormat = fDxgiFormat;
+        return true;
+    }
+    return false;
+}
+#endif
+
 GrBackendFormat::GrBackendFormat(GrColorType colorType, SkImage::CompressionType compression)
         : fBackend(GrBackendApi::kMock)
         , fValid(true)