diff options
author | 2018-02-02 15:48:33 -0500 | |
---|---|---|
committer | 2018-02-02 21:16:19 +0000 | |
commit | fb3abcd8c335132b6ad8434a171516102bbf4495 (patch) | |
tree | a61244af55debc848e27716742f209dc29d63bc1 /src/gpu/GrYUVProvider.cpp | |
parent | 1d8726fbed346dd2b96d4ef3106262e3d3dee5f4 (diff) |
Update GrYUVGenerator to upload to texture vs use writePixels
Bug: skia:
Change-Id: I891ba25d2018008a32ef01608da9209cf2642b2e
Reviewed-on: https://skia-review.googlesource.com/102902
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'src/gpu/GrYUVProvider.cpp')
-rw-r--r-- | src/gpu/GrYUVProvider.cpp | 60 |
1 files changed, 35 insertions, 25 deletions
diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp index 0ca8cd90bd..62ff0d0e3e 100644 --- a/src/gpu/GrYUVProvider.cpp +++ b/src/gpu/GrYUVProvider.cpp @@ -9,6 +9,7 @@ #include "GrClip.h" #include "GrContext.h" #include "GrContextPriv.h" +#include "GrProxyProvider.h" #include "GrRenderTargetContext.h" #include "GrTextureProxy.h" #include "SkAutoMalloc.h" @@ -60,6 +61,12 @@ sk_sp<SkCachedData> init_provider(GrYUVProvider* provider, SkYUVPlanesCache::Inf return data; } +void GrYUVProvider::YUVGen_DataReleaseProc(const void*, void* data) { + SkCachedData* cachedData = static_cast<SkCachedData*>(data); + SkASSERT(cachedData); + cachedData->unref(); +} + sk_sp<GrTextureProxy> GrYUVProvider::refAsTextureProxy(GrContext* ctx, const GrSurfaceDesc& desc, const SkColorSpace* srcColorSpace, const SkColorSpace* dstColorSpace) { @@ -71,32 +78,35 @@ sk_sp<GrTextureProxy> GrYUVProvider::refAsTextureProxy(GrContext* ctx, const GrS return nullptr; } - GrSurfaceDesc yuvDesc; - yuvDesc.fOrigin = kTopLeft_GrSurfaceOrigin; - yuvDesc.fConfig = kAlpha_8_GrPixelConfig; - sk_sp<GrSurfaceContext> yuvTextureContexts[3]; + sk_sp<GrTextureProxy> yuvTextureProxies[3]; for (int i = 0; i < 3; i++) { - yuvDesc.fWidth = yuvInfo.fSizeInfo.fSizes[i].fWidth; - yuvDesc.fHeight = yuvInfo.fSizeInfo.fSizes[i].fHeight; - // TODO: why do we need this check? + int componentWidth = yuvInfo.fSizeInfo.fSizes[i].fWidth; + int componentHeight = yuvInfo.fSizeInfo.fSizes[i].fHeight; + // If the sizes of the components are not all the same we choose to create exact-match + // textures for the smaller onces rather than add a texture domain to the draw. + // TODO: revisit this decision to imporve texture reuse? SkBackingFit fit = - (yuvDesc.fWidth != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth) || - (yuvDesc.fHeight != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight) + (componentWidth != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth) || + (componentHeight != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight) ? SkBackingFit::kExact : SkBackingFit::kApprox; - yuvTextureContexts[i] = ctx->contextPriv().makeDeferredSurfaceContext(yuvDesc, - GrMipMapped::kNo, - fit, - SkBudgeted::kYes); - if (!yuvTextureContexts[i]) { - return nullptr; - } - - const SkImageInfo ii = SkImageInfo::MakeA8(yuvDesc.fWidth, yuvDesc.fHeight); - if (!yuvTextureContexts[i]->writePixels(ii, planes[i], - yuvInfo.fSizeInfo.fWidthBytes[i], 0, 0)) { - return nullptr; - } + SkImageInfo imageInfo = SkImageInfo::MakeA8(componentWidth, componentHeight); + SkPixmap pixmap(imageInfo, planes[i], yuvInfo.fSizeInfo.fWidthBytes[i]); + SkCachedData* dataStoragePtr = dataStorage.get(); + // We grab a ref to cached yuv data. When the SkImage we create below goes away it will call + // the YUVGen_DataReleaseProc which will release this ref. + // DDL TODO: Currently we end up creating a lazy proxy that will hold onto a ref to the + // SkImage in its lambda. This means that we'll keep the ref on the YUV data around for the + // life time of the proxy and not just upload. For non-DDL draws we should look into + // releasing this SkImage after uploads (by deleting the lambda after instantiation). + dataStoragePtr->ref(); + sk_sp<SkImage> yuvImage = SkImage::MakeFromRaster(pixmap, YUVGen_DataReleaseProc, + dataStoragePtr); + + auto proxyProvider = ctx->contextPriv().proxyProvider(); + yuvTextureProxies[i] = proxyProvider->createTextureProxy(yuvImage, kNone_GrSurfaceFlags, + kTopLeft_GrSurfaceOrigin, + 0, SkBudgeted::kYes, fit); } // We never want to perform color-space conversion during the decode @@ -114,9 +124,9 @@ sk_sp<GrTextureProxy> GrYUVProvider::refAsTextureProxy(GrContext* ctx, const GrS GrPaint paint; auto yuvToRgbProcessor = - GrYUVtoRGBEffect::Make(yuvTextureContexts[0]->asTextureProxyRef(), - yuvTextureContexts[1]->asTextureProxyRef(), - yuvTextureContexts[2]->asTextureProxyRef(), + GrYUVtoRGBEffect::Make(std::move(yuvTextureProxies[0]), + std::move(yuvTextureProxies[1]), + std::move(yuvTextureProxies[2]), yuvInfo.fSizeInfo.fSizes, yuvInfo.fColorSpace, false); paint.addColorFragmentProcessor(std::move(yuvToRgbProcessor)); |