MakeBackendTextureFromSkImage
Creates a static function on SkImage which converts the SkImage to a
GrBackendTexture. The texture is unowned by Skia, and must be deleted
by the caller. Allows for a no-copy / no-conversion fast path if the
provided image is unowned (unique()) and texture backed.
Change-Id: I8a48f9cc39de792725cd72057d98cd1c4594daab
Reviewed-on: https://skia-review.googlesource.com/52440
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Eric Karl <ericrk@chromium.org>
diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp
index b5c8c69..f7259a5 100644
--- a/src/gpu/gl/GrGLTexture.cpp
+++ b/src/gpu/gl/GrGLTexture.cpp
@@ -117,3 +117,15 @@
return sk_sp<GrGLTexture>(new GrGLTexture(gpu, kWrapped, desc, mipMapsStatus, idDesc));
}
+bool GrGLTexture::onStealBackendTexture(GrBackendTexture* backendTexture,
+ SkImage::BackendTextureReleaseProc* releaseProc) {
+ *backendTexture = GrBackendTexture(width(), height(), config(), fInfo);
+ // Set the release proc to a no-op function. GL doesn't require any special cleanup.
+ *releaseProc = [](GrBackendTexture){};
+
+ // It's important that we only abandon this texture's objects, not subclass objects such as
+ // those held by GrGLTextureRenderTarget. Those objects are not being stolen and need to be
+ // cleaned up by us.
+ this->GrGLTexture::onAbandon();
+ return true;
+}