diff options
author | Brian Osman <brianosman@google.com> | 2017-05-09 13:19:50 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-05-09 18:45:04 +0000 |
commit | 13dddce65fd87a8175a209a49f35615735a2886a (patch) | |
tree | 0f7d85e7ba8db0b3acc7c0ac2dccd839808856cf /src/image | |
parent | 3734c7d9e39cce682c5095a8f187d41223955f5c (diff) |
Added SkImage::MakeCrossContextFromEncoded
Designed for Flutter's threading architecture, with
an eye to being useful to other clients. Under the
hood, uses a new image generator class to lazily wrap
a texture for multiple GrContexts.
Re-land of https://skia-review.googlesource.com/c/14180/
Bug: skia:
Change-Id: I3dd382640629b79b3058f18fee68d043566e43e5
Reviewed-on: https://skia-review.googlesource.com/15895
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/image')
-rw-r--r-- | src/image/SkImage_Gpu.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 1fdd084fa2..9bb98fbf10 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -11,6 +11,7 @@ #include "SkAutoPixmapStorage.h" #include "GrBackendSurface.h" +#include "GrBackendTextureImageGenerator.h" #include "GrBitmapTextureMaker.h" #include "GrCaps.h" #include "GrContext.h" @@ -461,6 +462,46 @@ sk_sp<SkImage> SkImage::makeTextureImage(GrContext* context, SkColorSpace* dstCo return nullptr; } +sk_sp<SkImage> SkImage::MakeCrossContextFromEncoded(GrContext* context, sk_sp<SkData> encoded, + bool buildMips, SkColorSpace* dstColorSpace) { + sk_sp<SkImage> codecImage = SkImage::MakeFromEncoded(std::move(encoded)); + if (!codecImage) { + return nullptr; + } + + // Some backends or drivers don't support (safely) moving resources between contexts + if (!context || !context->caps()->crossContextTextureSupport()) { + return codecImage; + } + + // Turn the codec image into a GrTextureProxy + GrImageTextureMaker maker(context, codecImage.get(), kDisallow_CachingHint); + sk_sp<SkColorSpace> texColorSpace; + GrSamplerParams params(SkShader::kClamp_TileMode, + buildMips ? GrSamplerParams::kMipMap_FilterMode + : GrSamplerParams::kBilerp_FilterMode); + sk_sp<GrTextureProxy> proxy(maker.refTextureProxyForParams(params, dstColorSpace, + &texColorSpace, nullptr)); + if (!proxy) { + return codecImage; + } + + sk_sp<GrTexture> texture(sk_ref_sp(proxy->instantiate(context->resourceProvider()))); + if (!texture) { + return codecImage; + } + + // Flush any writes or uploads + context->contextPriv().prepareSurfaceForExternalIO(proxy.get()); + + sk_sp<GrSemaphore> sema = context->getGpu()->prepareTextureForCrossContextUsage(texture.get()); + + auto gen = GrBackendTextureImageGenerator::Make(std::move(texture), std::move(sema), + codecImage->alphaType(), + std::move(texColorSpace)); + return SkImage::MakeFromGenerator(std::move(gen)); +} + std::unique_ptr<SkCrossContextImageData> SkCrossContextImageData::MakeFromEncoded( GrContext* context, sk_sp<SkData> encoded, SkColorSpace* dstColorSpace) { sk_sp<SkImage> codecImage = SkImage::MakeFromEncoded(std::move(encoded)); |