diff options
author | Eric Karl <ericrk@chromium.org> | 2017-10-12 12:44:50 -0700 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-10-12 20:05:31 +0000 |
commit | 914a36b248ffb538874483d86759254838866dd7 (patch) | |
tree | ea6954b9b3fc41bf87a3be1c30d5fd447656b28a /src/gpu/GrTexture.cpp | |
parent | 708ec81d7a9bba12cd7e574b5c5ae80b2ad77919 (diff) |
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>
Diffstat (limited to 'src/gpu/GrTexture.cpp')
-rw-r--r-- | src/gpu/GrTexture.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/gpu/GrTexture.cpp b/src/gpu/GrTexture.cpp index 250b6dd167..b0dba5142e 100644 --- a/src/gpu/GrTexture.cpp +++ b/src/gpu/GrTexture.cpp @@ -10,6 +10,7 @@ #include "GrGpu.h" #include "GrResourceKey.h" #include "GrRenderTarget.h" +#include "GrSurfacePriv.h" #include "GrTexture.h" #include "GrTexturePriv.h" #include "GrTypes.h" @@ -56,6 +57,25 @@ GrTexture::GrTexture(GrGpu* gpu, const GrSurfaceDesc& desc, GrSLType samplerType } } +bool GrTexture::StealBackendTexture(sk_sp<GrTexture>&& texture, + GrBackendTexture* backendTexture, + SkImage::BackendTextureReleaseProc* releaseProc) { + if (!texture->surfacePriv().hasUniqueRef() || texture->surfacePriv().hasPendingIO()) { + return false; + } + + if (!texture->onStealBackendTexture(backendTexture, releaseProc)) { + return false; + } + + // Release any not-stolen data being held by this class. + texture->onRelease(); + // Abandon the GrTexture so it can't be re-used. + texture->abandon(); + + return true; +} + void GrTexture::computeScratchKey(GrScratchKey* key) const { const GrRenderTarget* rt = this->asRenderTarget(); int sampleCount = 0; |