Add bridge between GrContext::createBackendTexture and SkSurface::MakeFromBackendTexture
In order to effectively use the explicit backend texture allocation API Chrome needs a way to use them with surface characterizations
Change-Id: Ic61eff9f3b6b0e8280481149d7c08d37a2fe7ec0
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/222781
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 3a3f43d..604eab0 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -363,6 +363,83 @@
return this->createBackendTexture(width, height, format, mipMapped, renderable, isProtected);
}
+GrBackendTexture GrContext::createBackendTexture(const SkSurfaceCharacterization& c) {
+ const GrCaps* caps = this->caps();
+
+ if (!this->asDirectContext() || !c.isValid()) {
+ return GrBackendTexture();
+ }
+
+ if (this->abandoned()) {
+ return GrBackendTexture();
+ }
+
+ if (c.usesGLFBO0()) {
+ // If we are making the surface we will never use FBO0.
+ return GrBackendTexture();
+ }
+
+ if (c.vulkanSecondaryCBCompatible()) {
+ return {};
+ }
+
+ const GrBackendFormat format = caps->getBackendFormatFromColorType(c.colorType());
+ if (!format.isValid()) {
+ return GrBackendTexture();
+ }
+
+ if (!SkSurface_Gpu::Valid(caps, format)) {
+ return GrBackendTexture();
+ }
+
+ // TODO (PROT-CHAR): pass in protection status once added to characterization
+ GrBackendTexture result = this->createBackendTexture(c.width(), c.height(), format,
+ GrMipMapped(c.isMipMapped()),
+ GrRenderable::kYes,
+ GrProtected::kNo);
+ SkASSERT(c.isCompatible(result));
+ return result;
+}
+
+GrBackendTexture GrContext::createBackendTexture(const SkSurfaceCharacterization& c,
+ const SkColor4f& color) {
+ const GrCaps* caps = this->caps();
+
+ if (!this->asDirectContext() || !c.isValid()) {
+ return GrBackendTexture();
+ }
+
+ if (this->abandoned()) {
+ return GrBackendTexture();
+ }
+
+ if (c.usesGLFBO0()) {
+ // If we are making the surface we will never use FBO0.
+ return GrBackendTexture();
+ }
+
+ if (c.vulkanSecondaryCBCompatible()) {
+ return {};
+ }
+
+ const GrBackendFormat format = caps->getBackendFormatFromColorType(c.colorType());
+ if (!format.isValid()) {
+ return GrBackendTexture();
+ }
+
+ if (!SkSurface_Gpu::Valid(caps, format)) {
+ return GrBackendTexture();
+ }
+
+ // TODO (PROT-CHAR): pass in protection status once added to characterization
+ GrBackendTexture result = this->createBackendTexture(c.width(), c.height(), format, color,
+ GrMipMapped(c.isMipMapped()),
+ GrRenderable::kYes,
+ GrProtected::kNo);
+ SkASSERT(c.isCompatible(result));
+ return result;
+}
+
GrBackendTexture GrContext::createBackendTexture(int width, int height,
const GrBackendFormat& backendFormat,
const SkColor4f& color,
@@ -406,8 +483,8 @@
return GrBackendTexture();
}
- return this->createBackendTexture(width, height, format, color, mipMapped, renderable,
- isProtected);
+ return this->createBackendTexture(width, height, format, color,
+ mipMapped, renderable, isProtected);
}
void GrContext::deleteBackendTexture(GrBackendTexture backendTex) {