Add stencil formats to all the backends.
Currently there is nothing using these formats, but this change just adds
them along with a quaries about their properties. They will be used in a
follow up change.
Bug: skia:10727
Change-Id: Iaaf13baf372799d47c65bd974fd204a32be57617
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/322622
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrBackendUtils.cpp b/src/gpu/GrBackendUtils.cpp
index b50e574..5b06ea3 100644
--- a/src/gpu/GrBackendUtils.cpp
+++ b/src/gpu/GrBackendUtils.cpp
@@ -137,6 +137,9 @@
SkImage::CompressionType compression = format.asMockCompressionType();
if (compression != SkImage::CompressionType::kNone) {
return GrCompressedRowBytes(compression, 1);
+ } else if (format.isMockStencilFormat()) {
+ static constexpr int kMockStencilSize = 4;
+ return kMockStencilSize;
}
return GrColorTypeBytesPerPixel(format.asMockColorType());
}
@@ -150,3 +153,52 @@
}
return GrBackendFormatBytesPerBlock(format);
}
+
+int GrBackendFormatStencilBits(const GrBackendFormat& format) {
+ switch (format.backend()) {
+ case GrBackendApi::kOpenGL: {
+#ifdef SK_GL
+ GrGLFormat glFormat = format.asGLFormat();
+ return GrGLFormatStencilBits(glFormat);
+#endif
+ break;
+ }
+ case GrBackendApi::kVulkan: {
+#ifdef SK_VULKAN
+ VkFormat vkFormat;
+ SkAssertResult(format.asVkFormat(&vkFormat));
+ return GrVkFormatStencilBits(vkFormat);
+#endif
+ break;
+ }
+ case GrBackendApi::kMetal: {
+#ifdef SK_METAL
+ return GrMtlBackendFormatStencilBits(format);
+#endif
+ break;
+ }
+ case GrBackendApi::kDirect3D: {
+#ifdef SK_DIRECT3D
+ DXGI_FORMAT dxgiFormat;
+ SkAssertResult(format.asDxgiFormat(&dxgiFormat));
+ return GrDxgiFormatStencilBits(dxgiFormat);
+#endif
+ break;
+ }
+ case GrBackendApi::kDawn: {
+#ifdef SK_DAWN
+ wgpu::TextureFormat dawnFormat;
+ SkAssertResult(format.asDawnFormat(&dawnFormat));
+ return GrDawnFormatStencilBits(dawnFormat);
+#endif
+ break;
+ }
+ case GrBackendApi::kMock: {
+ if (format.isMockStencilFormat()) {
+ static constexpr int kMockStencilBits = 8;
+ return kMockStencilBits;
+ }
+ }
+ }
+ return 0;
+}