diff options
author | Jim Van Verth <jvanverth@google.com> | 2018-11-20 11:12:37 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-11-20 16:43:28 +0000 |
commit | c8429addf1c8e8a1d04d9f3576be24ca2e26cfd9 (patch) | |
tree | 7d024a1161a751c946760c6e84ab8db4e4a8a281 /src/image | |
parent | e3deee131979b5e2c6ee07cad59a06c247a40d91 (diff) | |
download | skqp-c8429addf1c8e8a1d04d9f3576be24ca2e26cfd9.tar.gz |
Add SkImage::MakeFromYUVAPixmaps
Bug: skia:7903
Change-Id: I41ee31ad3657aee372e22ec3e7a0a317e31b2791
Reviewed-on: https://skia-review.googlesource.com/c/171007
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src/image')
-rw-r--r-- | src/image/SkImage_Gpu.h | 2 | ||||
-rw-r--r-- | src/image/SkImage_GpuYUVA.cpp | 63 |
2 files changed, 65 insertions, 0 deletions
diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h index 7da0ca4594..e184e177ff 100644 --- a/src/image/SkImage_Gpu.h +++ b/src/image/SkImage_Gpu.h @@ -94,6 +94,8 @@ public: PromiseDoneProc promiseDoneProc, TextureContext textureContext); + /** To be deprecated. Use SkImage_GpuYUVA::MakePromiseYUVATexture instead. + */ static sk_sp<SkImage> MakePromiseYUVATexture(GrContext* context, SkYUVColorSpace yuvColorSpace, const GrBackendFormat yuvaFormats[], diff --git a/src/image/SkImage_GpuYUVA.cpp b/src/image/SkImage_GpuYUVA.cpp index a1d06964d5..3113c1cce3 100644 --- a/src/image/SkImage_GpuYUVA.cpp +++ b/src/image/SkImage_GpuYUVA.cpp @@ -16,6 +16,7 @@ #include "GrRenderTargetContext.h" #include "GrTexture.h" #include "GrTextureProducer.h" +#include "SkAutoPixmapStorage.h" #include "SkGr.h" #include "SkImage_Gpu.h" #include "SkImage_GpuYUVA.h" @@ -144,6 +145,68 @@ sk_sp<SkImage> SkImage::MakeFromYUVATextures(GrContext* ctx, numTextures, yuvaIndices, imageOrigin, imageColorSpace, SkBudgeted::kYes); } + +sk_sp<SkImage> SkImage::MakeFromYUVAPixmaps( + GrContext* context, SkYUVColorSpace yuvColorSpace, const SkPixmap yuvaPixmaps[], + const SkYUVAIndex yuvaIndices[4], SkISize imageSize, GrSurfaceOrigin imageOrigin, + bool buildMips, bool limitToMaxTextureSize, sk_sp<SkColorSpace> imageColorSpace) { + int numPixmaps; + if (!SkYUVAIndex::AreValidIndices(yuvaIndices, &numPixmaps)) { + return nullptr; + } + + // Make proxies + GrProxyProvider* proxyProvider = context->contextPriv().proxyProvider(); + sk_sp<GrTextureProxy> tempTextureProxies[4]; + for (int i = 0; i < numPixmaps; ++i) { + const SkPixmap* pixmap = &yuvaPixmaps[i]; + SkAutoPixmapStorage resized; + int maxTextureSize = context->contextPriv().caps()->maxTextureSize(); + int maxDim = SkTMax(yuvaPixmaps[i].width(), yuvaPixmaps[i].height()); + if (limitToMaxTextureSize && maxDim > maxTextureSize) { + float scale = static_cast<float>(maxTextureSize) / maxDim; + int newWidth = SkTMin(static_cast<int>(yuvaPixmaps[i].width() * scale), + maxTextureSize); + int newHeight = SkTMin(static_cast<int>(yuvaPixmaps[i].height() * scale), + maxTextureSize); + SkImageInfo info = yuvaPixmaps[i].info().makeWH(newWidth, newHeight); + if (!resized.tryAlloc(info) || + !yuvaPixmaps[i].scalePixels(resized, kLow_SkFilterQuality)) { + return nullptr; + } + pixmap = &resized; + } + // Turn the pixmap into a GrTextureProxy + if (buildMips) { + SkBitmap bmp; + bmp.installPixels(*pixmap); + tempTextureProxies[i] = proxyProvider->createMipMapProxyFromBitmap(bmp); + } else { + if (SkImageInfoIsValid(pixmap->info())) { + ATRACE_ANDROID_FRAMEWORK("Upload Texture [%ux%u]", + pixmap->width(), pixmap->height()); + // We don't need a release proc on the data in pixmap since we know we are in a + // GrContext that has a resource provider. Thus the createTextureProxy call will + // immediately upload the data. + sk_sp<SkImage> image = SkImage::MakeFromRaster(*pixmap, nullptr, nullptr); + tempTextureProxies[i] = + proxyProvider->createTextureProxy(std::move(image), kNone_GrSurfaceFlags, 1, + SkBudgeted::kYes, SkBackingFit::kExact); + } + } + + if (!tempTextureProxies[i]) { + return nullptr; + } + } + + return sk_make_sp<SkImage_GpuYUVA>(sk_ref_sp(context), imageSize.width(), imageSize.height(), + kNeedNewImageUniqueID, yuvColorSpace, tempTextureProxies, + numPixmaps, yuvaIndices, imageOrigin, imageColorSpace, + SkBudgeted::kYes); +} + + ///////////////////////////////////////////////////////////////////////////////////////////////// sk_sp<SkImage> SkImage_GpuYUVA::MakePromiseYUVATexture(GrContext* context, SkYUVColorSpace yuvColorSpace, |