Dawn backend: update to recent Skia changes.
Change-Id: I0cdeb89c3b1efe4d59c65a14cca40a7c4b562972
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/232023
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
diff --git a/src/gpu/GrBackendSurface.cpp b/src/gpu/GrBackendSurface.cpp
index fb297a7..5859f4d 100644
--- a/src/gpu/GrBackendSurface.cpp
+++ b/src/gpu/GrBackendSurface.cpp
@@ -285,7 +285,7 @@
break;
case GrBackendApi::kDawn:
#ifdef SK_DAWN
- str.appendU32(fDawnFormat);
+ str.append(GrDawnFormatToStr(fDawnFormat));
#endif
break;
case GrBackendApi::kMock:
diff --git a/src/gpu/dawn/GrDawnCaps.cpp b/src/gpu/dawn/GrDawnCaps.cpp
index a8af52a..c36d6f3 100644
--- a/src/gpu/dawn/GrDawnCaps.cpp
+++ b/src/gpu/dawn/GrDawnCaps.cpp
@@ -34,25 +34,28 @@
}
GrPixelConfig GrDawnCaps::onGetConfigFromBackendFormat(const GrBackendFormat& format,
- GrColorType colorType) const {
- dawn::TextureFormat textureFormat = *format.getDawnFormat();
+ GrColorType colorType) const {
+ const dawn::TextureFormat* dawnFormat = format.getDawnFormat();
+ if (!dawnFormat) {
+ return kUnknown_GrPixelConfig;
+ }
switch (colorType) {
case GrColorType::kUnknown:
return kUnknown_GrPixelConfig;
case GrColorType::kAlpha_8:
- if (dawn::TextureFormat::R8Unorm == textureFormat) {
+ if (dawn::TextureFormat::R8Unorm == *dawnFormat) {
return kAlpha_8_as_Red_GrPixelConfig;
}
break;
case GrColorType::kRGBA_8888:
- if (dawn::TextureFormat::RGBA8Unorm == textureFormat) {
+ if (dawn::TextureFormat::RGBA8Unorm == *dawnFormat) {
return kRGBA_8888_GrPixelConfig;
}
break;
case GrColorType::kRGB_888x:
break;
case GrColorType::kBGRA_8888:
- if (dawn::TextureFormat::BGRA8Unorm == textureFormat) {
+ if (dawn::TextureFormat::BGRA8Unorm == *dawnFormat) {
return kBGRA_8888_GrPixelConfig;
}
break;
@@ -98,14 +101,33 @@
return this->isConfigTexturable(config);
}
-int GrDawnCaps::getRenderTargetSampleCount(int requestedCount, GrColorType ct,
- const GrBackendFormat& format) const {
- GrPixelConfig config = this->getConfigFromBackendFormat(format, ct);
- if (kUnknown_GrPixelConfig == config) {
- return 0;
+bool GrDawnCaps::isFormatRenderable(GrColorType ct, const GrBackendFormat& format,
+ int sampleCount) const {
+ if (!format.isValid() || sampleCount > 1) {
+ return false;
}
- return this->getRenderTargetSampleCount(requestedCount, config);
+ return GrDawnFormatIsRenderable(*format.getDawnFormat()) ? 1 : 0;
+}
+
+int GrDawnCaps::getRenderTargetSampleCount(int requestedCount, GrColorType ct,
+ const GrBackendFormat& backendFormat) const {
+ if (!backendFormat.getDawnFormat()) {
+ return 0;
+ }
+ return GrDawnFormatIsRenderable(*backendFormat.getDawnFormat()) ? 1 : 0;
+}
+
+int GrDawnCaps::getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const {
+ dawn::TextureFormat format;
+ if (!GrPixelConfigToDawnFormat(config, &format)) {
+ return 0;
+ }
+ return GrDawnFormatIsRenderable(format) ? 1 : 0;
+}
+
+int GrDawnCaps::maxRenderTargetSampleCount(const GrBackendFormat& format) const {
+ return format.isValid() ? 1 : 0;
}
GrBackendFormat GrDawnCaps::onGetDefaultBackendFormat(GrColorType ct,
@@ -148,3 +170,21 @@
GrColorType GrDawnCaps::getYUVAColorTypeFromBackendFormat(const GrBackendFormat&) const {
return GrColorType::kUnknown;
}
+
+#if GR_TEST_UTILS
+std::vector<GrCaps::TestFormatColorTypeCombination> GrDawnCaps::getTestingCombinations() const {
+ std::vector<GrCaps::TestFormatColorTypeCombination> combos = {
+ { GrColorType::kAlpha_8, GrBackendFormat::MakeDawn(dawn::TextureFormat::R8Unorm) },
+ { GrColorType::kRGBA_8888, GrBackendFormat::MakeDawn(dawn::TextureFormat::RGBA8Unorm) },
+ { GrColorType::kRGB_888x, GrBackendFormat::MakeDawn(dawn::TextureFormat::RGBA8Unorm) },
+ { GrColorType::kBGRA_8888, GrBackendFormat::MakeDawn(dawn::TextureFormat::BGRA8Unorm) },
+ };
+
+#ifdef SK_DEBUG
+ for (auto combo : combos) {
+ SkASSERT(this->onAreColorTypeAndFormatCompatible(combo.fColorType, combo.fFormat));
+ }
+#endif
+ return combos;
+}
+#endif
diff --git a/src/gpu/dawn/GrDawnCaps.h b/src/gpu/dawn/GrDawnCaps.h
index ad21910..bb9a6e9 100644
--- a/src/gpu/dawn/GrDawnCaps.h
+++ b/src/gpu/dawn/GrDawnCaps.h
@@ -21,6 +21,8 @@
bool isFormatCompressed(const GrBackendFormat&) const override;
bool isFormatTexturable(GrColorType, const GrBackendFormat& format) const override;
+ bool isFormatRenderable(GrColorType, const GrBackendFormat& format,
+ int sampleCount = 1) const override;
bool isFormatCopyable(const GrBackendFormat& format) const override { return true; }
bool isConfigTexturable(GrPixelConfig config) const override;
@@ -28,8 +30,7 @@
SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType,
const GrBackendFormat& surfaceFormat,
GrColorType srcColorType) const override {
- GrColorType ct = GrPixelConfigToColorType(config);
- return {ct, GrColorTypeBytesPerPixel(ct)};
+ return {surfaceColorType, GrColorTypeBytesPerPixel(surfaceColorType)};
}
SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface*) const override {
@@ -38,19 +39,9 @@
int getRenderTargetSampleCount(int requestedCount, GrColorType,
const GrBackendFormat&) const override;
+ int getRenderTargetSampleCount(int requestedCount, GrPixelConfig) const override;
- int getRenderTargetSampleCount(int requestedCount, GrPixelConfig config) const override {
- return this->isConfigTexturable(config) ? 1 : 0;
- }
-
- int maxRenderTargetSampleCount(GrColorType ct,
- const GrBackendFormat& format) const override {
- return this->maxRenderTargetSampleCount(this->getConfigFromBackendFormat(format, ct));
- }
-
- int maxRenderTargetSampleCount(GrPixelConfig config) const override {
- return this->isConfigTexturable(config) ? 1 : 0;
- }
+ int maxRenderTargetSampleCount(const GrBackendFormat& format) const override;
GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override;
@@ -62,6 +53,10 @@
GrColorType getYUVAColorTypeFromBackendFormat(const GrBackendFormat&) const override;
+#if GR_TEST_UTILS
+ std::vector<TestFormatColorTypeCombination> getTestingCombinations() const override;
+#endif
+
private:
bool onSurfaceSupportsWritePixels(const GrSurface* surface) const override {
return true;
diff --git a/src/gpu/dawn/GrDawnGpu.cpp b/src/gpu/dawn/GrDawnGpu.cpp
index cda57be..29d8ffa 100644
--- a/src/gpu/dawn/GrDawnGpu.cpp
+++ b/src/gpu/dawn/GrDawnGpu.cpp
@@ -80,24 +80,24 @@
}
////////////////////////////////////////////////////////////////////////////////
-bool GrDawnGpu::onWritePixels(GrSurface* surface,
- int left, int top, int width, int height,
- GrColorType colorType,
+bool GrDawnGpu::onWritePixels(GrSurface* surface, int left, int top, int width, int height,
+ GrColorType textureColorType, GrColorType bufferColorType,
const GrMipLevel texels[], int mipLevelCount) {
SkASSERT(!"unimplemented");
return false;
}
-bool GrDawnGpu::onTransferPixelsTo(GrTexture* texture,
- int left, int top, int width, int height,
- GrColorType colorType, GrGpuBuffer* transferBuffer,
- size_t bufferOffset, size_t rowBytes) {
+bool GrDawnGpu::onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height,
+ GrColorType textureColorType, GrColorType bufferColorType,
+ GrGpuBuffer* transferBuffer, size_t bufferOffset,
+ size_t rowBytes) {
SkASSERT(!"unimplemented");
return false;
}
bool GrDawnGpu::onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
- GrColorType, GrGpuBuffer* transferBuffer, size_t offset) {
+ GrColorType surfaceColorType, GrColorType bufferColorType,
+ GrGpuBuffer* transferBuffer, size_t offset) {
SkASSERT(!"unimplemented");
return false;
}
@@ -224,10 +224,8 @@
return false;
}
-bool GrDawnGpu::onReadPixels(GrSurface* surface,
- int left, int top, int width, int height,
- GrColorType colorType,
- void* buffer,
+bool GrDawnGpu::onReadPixels(GrSurface* surface, int left, int top, int width, int height,
+ GrColorType surfaceColorType, GrColorType dstColorType, void* buffer,
size_t rowBytes) {
SkASSERT(!"unimplemented");
return false;
diff --git a/src/gpu/dawn/GrDawnGpu.h b/src/gpu/dawn/GrDawnGpu.h
index 0a6c8aa..35af389 100644
--- a/src/gpu/dawn/GrDawnGpu.h
+++ b/src/gpu/dawn/GrDawnGpu.h
@@ -108,20 +108,21 @@
sk_sp<GrGpuBuffer> onCreateBuffer(size_t size, GrGpuBufferType type, GrAccessPattern,
const void* data) override;
- bool onReadPixels(GrSurface* surface,
- int left, int top, int width, int height,
- GrColorType, void* buffer, size_t rowBytes) override;
+ bool onReadPixels(GrSurface* surface, int left, int top, int width, int height,
+ GrColorType surfaceColorType, GrColorType dstColorType, void* buffer,
+ size_t rowBytes) override;
- bool onWritePixels(GrSurface* surface,
- int left, int top, int width, int height,
- GrColorType, const GrMipLevel texels[], int mipLevelCount) override;
+ bool onWritePixels(GrSurface* surface, int left, int top, int width, int height,
+ GrColorType surfaceColorType, GrColorType dstColorType,
+ const GrMipLevel texels[], int mipLevelCount) override;
bool onTransferPixelsTo(GrTexture*, int left, int top, int width, int height,
- GrColorType colorType, GrGpuBuffer* transferBuffer,
- size_t offset, size_t rowBytes) override;
+ GrColorType textureColorType, GrColorType bufferColorType,
+ GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override;
bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
- GrColorType, GrGpuBuffer* transferBuffer, size_t offset) override;
+ GrColorType surfaceColorType, GrColorType bufferColorType,
+ GrGpuBuffer* transferBuffer, size_t offset) override;
void onResolveRenderTarget(GrRenderTarget* target) override {
}
diff --git a/src/gpu/dawn/GrDawnGpuCommandBuffer.cpp b/src/gpu/dawn/GrDawnGpuCommandBuffer.cpp
index 694e67a..d2db9a6 100644
--- a/src/gpu/dawn/GrDawnGpuCommandBuffer.cpp
+++ b/src/gpu/dawn/GrDawnGpuCommandBuffer.cpp
@@ -81,10 +81,12 @@
SkASSERT(!"unimplemented");
}
-void GrDawnGpuRTCommandBuffer::transferFrom(const SkIRect& srcRect, GrColorType bufferColorType,
+void GrDawnGpuRTCommandBuffer::transferFrom(const SkIRect& srcRect, GrColorType surfaceColorType,
+ GrColorType bufferColorType,
GrGpuBuffer* transferBuffer, size_t offset) {
fGpu->transferPixelsFrom(fRenderTarget, srcRect.fLeft, srcRect.fTop, srcRect.width(),
- srcRect.height(), bufferColorType, transferBuffer, offset);
+ srcRect.height(), surfaceColorType, bufferColorType, transferBuffer,
+ offset);
}
void GrDawnGpuRTCommandBuffer::onClearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
diff --git a/src/gpu/dawn/GrDawnGpuCommandBuffer.h b/src/gpu/dawn/GrDawnGpuCommandBuffer.h
index 700bfbb..be78096 100644
--- a/src/gpu/dawn/GrDawnGpuCommandBuffer.h
+++ b/src/gpu/dawn/GrDawnGpuCommandBuffer.h
@@ -62,8 +62,9 @@
void begin() override { }
void end() override;
- void transferFrom(const SkIRect& srcRect, GrColorType bufferColorType,
- GrGpuBuffer* transferBuffer, size_t offset) override;
+ void transferFrom(const SkIRect& srcRect, GrColorType surfaceColorType,
+ GrColorType bufferColorType, GrGpuBuffer* transferBuffer,
+ size_t offset) override;
void insertEventMarker(const char*) override;
void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override;
diff --git a/src/gpu/dawn/GrDawnUtil.cpp b/src/gpu/dawn/GrDawnUtil.cpp
index c0193ea..ad790ba 100644
--- a/src/gpu/dawn/GrDawnUtil.cpp
+++ b/src/gpu/dawn/GrDawnUtil.cpp
@@ -22,6 +22,12 @@
}
}
+bool GrDawnFormatIsRenderable(dawn::TextureFormat format) {
+ // For now, all the formats above are renderable. If a non-renderable format is added
+ // (see dawn/src/dawn_native/Format.cpp), an exception should be added here.
+ return true;
+}
+
bool GrPixelConfigToDawnFormat(GrPixelConfig config, dawn::TextureFormat* format) {
switch (config) {
case kRGBA_8888_GrPixelConfig:
@@ -40,3 +46,21 @@
return false;
}
}
+
+#if GR_TEST_UTILS
+const char* GrDawnFormatToStr(dawn::TextureFormat format) {
+ switch (format) {
+ case dawn::TextureFormat::RGBA8Unorm:
+ return "RGBA8Unorm";
+ case dawn::TextureFormat::BGRA8Unorm:
+ return "BGRA8Unorm";
+ case dawn::TextureFormat::R8Unorm:
+ return "R8Unorm";
+ case dawn::TextureFormat::Depth24PlusStencil8:
+ return "Depth24PlusStencil8";
+ default:
+ SkASSERT(false);
+ return "Unknown";
+ }
+}
+#endif
diff --git a/src/gpu/dawn/GrDawnUtil.h b/src/gpu/dawn/GrDawnUtil.h
index 6cf973d..ed4f7f1 100644
--- a/src/gpu/dawn/GrDawnUtil.h
+++ b/src/gpu/dawn/GrDawnUtil.h
@@ -12,6 +12,10 @@
#include "dawn/dawncpp.h"
GrPixelConfig GrDawnFormatToPixelConfig(dawn::TextureFormat format);
+bool GrDawnFormatIsRenderable(dawn::TextureFormat format);
bool GrPixelConfigToDawnFormat(GrPixelConfig config, dawn::TextureFormat* format);
+#if GR_TEST_UTILS
+const char* GrDawnFormatToStr(dawn::TextureFormat format);
+#endif
#endif // GrDawnUtil_DEFINED