From 8670c9887529e8241511b1e27be748975d4f61f0 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Tue, 8 Dec 2020 16:39:32 -0500 Subject: [PATCH] Remove SkImage::MakeFromYUVATexturesCopyToExternal It's no longer used by Chrome. Inline helper that draws yuva->rgba into the now single use case. Move yuva proxy making helper from SkImage_GpuBase to SkImage_GpuYUVA since it is only used there now. Remove gm that tested the API and associated helper code in YUVUtils. Bug: skia:10632 Change-Id: If6bd49befa1d1098bb6a268b9d856794f7eb80c3 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/342077 Reviewed-by: Adlai Holler Commit-Queue: Brian Salomon --- RELEASE_NOTES.txt | 3 ++ gm/wacky_yuv_formats.cpp | 6 --- include/core/SkImage.h | 40 ------------------ src/image/SkImage_Gpu.cpp | 63 ----------------------------- src/image/SkImage_GpuBase.cpp | 69 ------------------------------- src/image/SkImage_GpuBase.h | 13 ------ src/image/SkImage_GpuYUVA.cpp | 76 ++++++++++++++++++++++++++++++----- src/image/SkImage_GpuYUVA.h | 8 ++++ tools/gpu/YUVUtils.cpp | 50 ++++------------------- tools/gpu/YUVUtils.h | 7 +--- 10 files changed, 86 insertions(+), 249 deletions(-) diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 7323013757..553dff2191 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -7,6 +7,9 @@ This file includes a list of high level updates for each milestone release. Milestone 89 ------------ + * Removed previously deprecated SkImage::MakeFromYUVATexturesCopyToExternal. + https://review.skia.org/342077 + * Add versions of GrDirectContext::createBackendTexture and updateBackendTexture that take a GrSurfaceOrigin. The previous versions are deprecated. https://review.skia.org/341005 diff --git a/gm/wacky_yuv_formats.cpp b/gm/wacky_yuv_formats.cpp index 5993d5e06d..6912ad1778 100644 --- a/gm/wacky_yuv_formats.cpp +++ b/gm/wacky_yuv_formats.cpp @@ -765,9 +765,6 @@ protected: case Type::kFromGenerator: name += "_imggen"; break; - case Type::kFromTexturesCopyToExternal: - name += "_fromtextureswithcopy"; - break; } return name; @@ -959,9 +956,6 @@ DEF_GM(return new WackyYUVFormatsGM(/* target cs */ false, DEF_GM(return new WackyYUVFormatsGM(/* target cs */ false, /* subset */ false, WackyYUVFormatsGM::Type::kFromPixmaps);) -DEF_GM(return new WackyYUVFormatsGM(/* target cs */ false, - /* subset */ false, - WackyYUVFormatsGM::Type::kFromTexturesCopyToExternal);) class YUVMakeColorSpaceGM : public GpuGM { public: diff --git a/include/core/SkImage.h b/include/core/SkImage.h index 4adcaa5177..007ba7f6bc 100644 --- a/include/core/SkImage.h +++ b/include/core/SkImage.h @@ -392,46 +392,6 @@ public: sk_sp imageColorSpace = nullptr, TextureReleaseProc textureReleaseProc = nullptr, ReleaseContext releaseContext = nullptr); - - /** Deprecated. - Creates an SkImage from YUV[A] planar textures by copying them to another caller-provided - texture and retaining that result texture in the SkImage. However, this is deprecated and - instead clients should make a SkSurface from 'rgbaResultTexture` using - SkSurface::MakeFromBackendTexture, make an image from the planes using MakeFromYUVATextures, - and finally draw the image to the surface. - - Note that the draw that converts to RGBA is not issued to the underlying API until a flush/ - submit occurs so the YUVA textures are not safe to delete or overwrite until yuvaReleaseProc - is called. - - The dimensions of the result RGBA texture must match the dimensions of the YUVA planar data. - - @param context GPU context - @param yuvaTextures A set of textures containing YUVA data and a description of the - data and transformation to RGBA. - @param rgbaResultTexture The renderable texture that will hold the result of the conversion - to RGBA and be retained in the resulting SkImage. - @param colorType colorType of the result as stored in rgbaResultTexture. Must be - compatible with the texture's format. - @param imageColorSpace range of colors of the resulting image after conversion to RGB; - may be nullptr - @param yuvaReleaseProc called when the backend textures in 'yuvaTextures' can be released - @param yuvaReleaseContext state passed to yuvaReleaseProc - @param rgbaReleaseProc called when the 'rgbaResultTexture' can be released - @param rgbaReleaseContext state passed to rgbaReleaseProc - @return created SkImage, or nullptr - */ - static sk_sp MakeFromYUVATexturesCopyToExternal( - GrRecordingContext* context, - const GrYUVABackendTextures& yuvaTextures, - const GrBackendTexture& rgbaResultTexture, - SkColorType colorType, - sk_sp imageColorSpace = nullptr, - TextureReleaseProc yuvaReleaseProc = nullptr, - ReleaseContext yuvaReleaseContext = nullptr, - TextureReleaseProc rgbaReleaseProc = nullptr, - ReleaseContext rgbaReleaseContext = nullptr); - /** Deprecated. Use version that takes GrYUVABackendTextures. diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 92b47f68a3..92c95db154 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -314,68 +314,6 @@ sk_sp SkImage::MakeTextureFromCompressed(GrDirectContext* direct, sk_sp colorType, kOpaque_SkAlphaType, nullptr); } -sk_sp SkImage::MakeFromYUVATexturesCopyToExternal( - GrRecordingContext* context, - const GrYUVABackendTextures& yuvaTextures, - const GrBackendTexture& rgbaResultTexture, - SkColorType colorType, - sk_sp imageColorSpace, - TextureReleaseProc yuvaReleaseProc, - ReleaseContext yuvaReleaseContext, - TextureReleaseProc rgbaReleaseProc, - ReleaseContext rgbaReleaseContext) { - auto yuvaReleaseHelper = GrRefCntedCallback::Make(yuvaReleaseProc, yuvaReleaseContext); - auto rgbaReleaseHelper = GrRefCntedCallback::Make(rgbaReleaseProc, rgbaReleaseContext); - - SkYUVAIndex yuvaIndices[4]; - int numTextures; - if (!yuvaTextures.toYUVAIndices(yuvaIndices) || - !SkYUVAIndex::AreValidIndices(yuvaIndices, &numTextures)) { - return nullptr; - } - SkASSERT(numTextures == yuvaTextures.numPlanes()); - if (!rgbaResultTexture.isValid() || - rgbaResultTexture.dimensions() != yuvaTextures.yuvaInfo().dimensions()) { - return nullptr; - } - - const GrCaps* caps = context->priv().caps(); - - // Initialize a render target around the rgba texture for drawing using the passed color type. - SkAlphaType at = yuvaTextures.yuvaInfo().hasAlpha() ? kPremul_SkAlphaType : kOpaque_SkAlphaType; - GrColorType grCT = SkColorTypeToGrColorType(colorType); - if (!SkImage_Gpu::ValidateBackendTexture( - caps, rgbaResultTexture, grCT, colorType, at, nullptr)) { - return nullptr; - } - auto renderTargetContext = GrRenderTargetContext::MakeFromBackendTexture( - context, grCT, std::move(imageColorSpace), rgbaResultTexture, 1, - yuvaTextures.textureOrigin(), nullptr, std::move(rgbaReleaseHelper)); - if (!renderTargetContext) { - return nullptr; - } - - // Make proxies from the YUVA textures. - GrSurfaceProxyView tempViews[4]; - if (!SkImage_GpuBase::MakeTempTextureProxies( - context, yuvaTextures.textures().data(), numTextures, yuvaIndices, - yuvaTextures.textureOrigin(), tempViews, std::move(yuvaReleaseHelper))) { - return nullptr; - } - - // Draw the YUVA proxies to the render target. - const SkRect rect = SkRect::Make(rgbaResultTexture.dimensions()); - if (!SkImage_GpuBase::RenderYUVAToRGBA(*caps, renderTargetContext.get(), rect, - yuvaTextures.yuvaInfo().yuvColorSpace(), nullptr, - tempViews, yuvaIndices)) { - return nullptr; - } - - return sk_make_sp(sk_ref_sp(context), kNeedNewImageUniqueID, - renderTargetContext->readSurfaceView(), colorType, at, - renderTargetContext->colorInfo().refColorSpace()); -} - static sk_sp create_image_from_producer(GrRecordingContext* context, GrTextureProducer* producer, uint32_t id, GrMipmapped mipMapped) { @@ -388,7 +326,6 @@ static sk_sp create_image_from_producer(GrRecordingContext* context, producer->alphaType(), sk_ref_sp(producer->colorSpace())); } - sk_sp SkImage::makeTextureImage(GrDirectContext* dContext, GrMipmapped mipMapped, SkBudgeted budgeted) const { diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp index d5d988bb78..e3da3b5561 100644 --- a/src/image/SkImage_GpuBase.cpp +++ b/src/image/SkImage_GpuBase.cpp @@ -265,75 +265,6 @@ bool SkImage_GpuBase::onIsValid(GrRecordingContext* context) const { return true; } -bool SkImage_GpuBase::MakeTempTextureProxies(GrRecordingContext* rContext, - const GrBackendTexture yuvaTextures[], - int numTextures, - const SkYUVAIndex yuvaIndices[4], - GrSurfaceOrigin imageOrigin, - GrSurfaceProxyView tempViews[4], - sk_sp releaseHelper) { - GrProxyProvider* proxyProvider = rContext->priv().proxyProvider(); - for (int textureIndex = 0; textureIndex < numTextures; ++textureIndex) { - const GrBackendFormat& backendFormat = yuvaTextures[textureIndex].getBackendFormat(); - if (!backendFormat.isValid()) { - return false; - } - - SkASSERT(yuvaTextures[textureIndex].isValid()); - - auto proxy = proxyProvider->wrapBackendTexture(yuvaTextures[textureIndex], - kBorrow_GrWrapOwnership, - GrWrapCacheable::kNo, kRead_GrIOType, - releaseHelper); - if (!proxy) { - return false; - } - tempViews[textureIndex] = - GrSurfaceProxyView(std::move(proxy), imageOrigin, GrSwizzle("rgba")); - - // Check that each texture contains the channel data for the corresponding YUVA index - auto formatChannelMask = backendFormat.channelMask(); - if (formatChannelMask & kGray_SkColorChannelFlag) { - formatChannelMask |= kRGB_SkColorChannelFlags; - } - for (int yuvaIndex = 0; yuvaIndex < SkYUVAIndex::kIndexCount; ++yuvaIndex) { - if (yuvaIndices[yuvaIndex].fIndex == textureIndex) { - uint32_t channelAsMask = 1 << static_cast(yuvaIndices[yuvaIndex].fChannel); - if (!(channelAsMask & formatChannelMask)) { - return false; - } - } - } - } - - return true; -} - -bool SkImage_GpuBase::RenderYUVAToRGBA(const GrCaps& caps, - GrRenderTargetContext* renderTargetContext, - const SkRect& rect, SkYUVColorSpace yuvColorSpace, - sk_sp colorSpaceXform, - GrSurfaceProxyView views[4], - const SkYUVAIndex yuvaIndices[4]) { - SkASSERT(renderTargetContext); - if (!renderTargetContext->asSurfaceProxy()) { - return false; - } - - GrPaint paint; - paint.setPorterDuffXPFactory(SkBlendMode::kSrc); - - auto fp = GrYUVtoRGBEffect::Make(views, yuvaIndices, yuvColorSpace, - GrSamplerState::Filter::kNearest, caps); - if (colorSpaceXform) { - fp = GrColorSpaceXformEffect::Make(std::move(fp), std::move(colorSpaceXform)); - } - paint.setColorFragmentProcessor(std::move(fp)); - - renderTargetContext->drawRect(nullptr, std::move(paint), GrAA::kNo, SkMatrix::I(), rect); - return true; -} - sk_sp SkImage_GpuBase::MakePromiseImageLazyProxy( GrRecordingContext* context, SkISize dimensions, diff --git a/src/image/SkImage_GpuBase.h b/src/image/SkImage_GpuBase.h index fe0e2f2453..e1402f3960 100644 --- a/src/image/SkImage_GpuBase.h +++ b/src/image/SkImage_GpuBase.h @@ -59,11 +59,6 @@ public: sk_sp cs); static bool ValidateCompressedBackendTexture(const GrCaps*, const GrBackendTexture& tex, SkAlphaType); - static bool MakeTempTextureProxies(GrRecordingContext*, const GrBackendTexture yuvaTextures[], - int numTextures, const SkYUVAIndex [4], - GrSurfaceOrigin imageOrigin, - GrSurfaceProxyView tempViews[4], - sk_sp releaseHelper); static SkAlphaType GetAlphaTypeFromYUVAIndices(const SkYUVAIndex yuvaIndices[4]) { return -1 != yuvaIndices[SkYUVAIndex::kA_Index].fIndex ? kPremul_SkAlphaType @@ -76,14 +71,6 @@ public: using PromiseImageTextureReleaseProc = SkDeferredDisplayListRecorder::PromiseImageTextureReleaseProc; - static bool RenderYUVAToRGBA(const GrCaps&, - GrRenderTargetContext*, - const SkRect&, - SkYUVColorSpace, - sk_sp, - GrSurfaceProxyView[4], - const SkYUVAIndex[4]); - protected: SkImage_GpuBase(sk_sp, SkISize size, uint32_t uniqueID, SkColorType, SkAlphaType, sk_sp); diff --git a/src/image/SkImage_GpuYUVA.cpp b/src/image/SkImage_GpuYUVA.cpp index 67621e0fe4..1a376dd062 100644 --- a/src/image/SkImage_GpuYUVA.cpp +++ b/src/image/SkImage_GpuYUVA.cpp @@ -22,6 +22,7 @@ #include "src/gpu/GrDirectContextPriv.h" #include "src/gpu/GrGpu.h" #include "src/gpu/GrImageContextPriv.h" +#include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrRecordingContextPriv.h" #include "src/gpu/GrRenderTargetContext.h" #include "src/gpu/GrTexture.h" @@ -149,6 +150,51 @@ GrSemaphoresSubmitted SkImage_GpuYUVA::onFlush(GrDirectContext* dContext, const GrTextureProxy* SkImage_GpuYUVA::peekProxy() const { return fRGBView.asTextureProxy(); } +bool SkImage_GpuYUVA::MakeTempTextureProxies(GrRecordingContext* rContext, + const GrBackendTexture yuvaTextures[], + int numTextures, + const SkYUVAIndex yuvaIndices[4], + GrSurfaceOrigin imageOrigin, + GrSurfaceProxyView tempViews[4], + sk_sp releaseHelper) { + GrProxyProvider* proxyProvider = rContext->priv().proxyProvider(); + for (int textureIndex = 0; textureIndex < numTextures; ++textureIndex) { + const GrBackendFormat& backendFormat = yuvaTextures[textureIndex].getBackendFormat(); + if (!backendFormat.isValid()) { + return false; + } + + SkASSERT(yuvaTextures[textureIndex].isValid()); + + auto proxy = proxyProvider->wrapBackendTexture(yuvaTextures[textureIndex], + kBorrow_GrWrapOwnership, + GrWrapCacheable::kNo, + kRead_GrIOType, + releaseHelper); + if (!proxy) { + return false; + } + tempViews[textureIndex] = + GrSurfaceProxyView(std::move(proxy), imageOrigin, GrSwizzle("rgba")); + + // Check that each texture contains the channel data for the corresponding YUVA index + auto formatChannelMask = backendFormat.channelMask(); + if (formatChannelMask & kGray_SkColorChannelFlag) { + formatChannelMask |= kRGB_SkColorChannelFlags; + } + for (int yuvaIndex = 0; yuvaIndex < SkYUVAIndex::kIndexCount; ++yuvaIndex) { + if (yuvaIndices[yuvaIndex].fIndex == textureIndex) { + uint32_t channelAsMask = 1 << static_cast(yuvaIndices[yuvaIndex].fChannel); + if (!(channelAsMask & formatChannelMask)) { + return false; + } + } + } + } + + return true; +} + void SkImage_GpuYUVA::flattenToRGB(GrRecordingContext* context) const { if (fRGBView.proxy()) { return; @@ -166,17 +212,27 @@ void SkImage_GpuYUVA::flattenToRGB(GrRecordingContext* context) const { return; } - sk_sp colorSpaceXform; - if (fFromColorSpace) { - colorSpaceXform = GrColorSpaceXform::Make(fFromColorSpace.get(), this->alphaType(), - this->colorSpace(), this->alphaType()); - } const SkRect rect = SkRect::MakeIWH(this->width(), this->height()); const GrCaps& caps = *context->priv().caps(); - if (!RenderYUVAToRGBA(caps, renderTargetContext.get(), rect, fYUVColorSpace, - std::move(colorSpaceXform), fViews, fYUVAIndices)) { - return; + + GrPaint paint; + paint.setPorterDuffXPFactory(SkBlendMode::kSrc); + + auto fp = GrYUVtoRGBEffect::Make(fViews, + fYUVAIndices, + fYUVColorSpace, + GrSamplerState::Filter::kNearest, + caps); + if (fFromColorSpace) { + auto colorSpaceXform = GrColorSpaceXform::Make(fFromColorSpace.get(), + this->alphaType(), + this->colorSpace(), + this->alphaType()); + fp = GrColorSpaceXformEffect::Make(std::move(fp), std::move(colorSpaceXform)); } + paint.setColorFragmentProcessor(std::move(fp)); + + renderTargetContext->drawRect(nullptr, std::move(paint), GrAA::kNo, SkMatrix::I(), rect); fRGBView = renderTargetContext->readSurfaceView(); SkASSERT(fRGBView.swizzle() == GrSwizzle()); @@ -253,7 +309,7 @@ sk_sp SkImage::MakeFromYUVATextures(GrRecordingContext* context, SkASSERT(numTextures == yuvaTextures.numPlanes()); GrSurfaceProxyView tempViews[4]; - if (!SkImage_GpuBase::MakeTempTextureProxies(context, + if (!SkImage_GpuYUVA::MakeTempTextureProxies(context, yuvaTextures.textures().data(), numTextures, yuvaIndices, @@ -290,7 +346,7 @@ sk_sp SkImage::MakeFromYUVATextures(GrRecordingContext* ctx, } GrSurfaceProxyView tempViews[4]; - if (!SkImage_GpuBase::MakeTempTextureProxies(ctx, yuvaTextures, numTextures, yuvaIndices, + if (!SkImage_GpuYUVA::MakeTempTextureProxies(ctx, yuvaTextures, numTextures, yuvaIndices, textureOrigin, tempViews, std::move(releaseHelper))) { return nullptr; diff --git a/src/image/SkImage_GpuYUVA.h b/src/image/SkImage_GpuYUVA.h index 9cba0d1153..594251230c 100644 --- a/src/image/SkImage_GpuYUVA.h +++ b/src/image/SkImage_GpuYUVA.h @@ -77,6 +77,14 @@ public: PromiseImageTextureReleaseProc textureReleaseProc, PromiseImageTextureContext textureContexts[]); + static bool MakeTempTextureProxies(GrRecordingContext*, + const GrBackendTexture yuvaTextures[], + int numTextures, + const SkYUVAIndex[4], + GrSurfaceOrigin imageOrigin, + GrSurfaceProxyView tempViews[4], + sk_sp releaseHelper); + private: SkImage_GpuYUVA(sk_sp, const SkImage_GpuYUVA* image, sk_sp); diff --git a/tools/gpu/YUVUtils.cpp b/tools/gpu/YUVUtils.cpp index 2247047513..9a9ff57e0d 100644 --- a/tools/gpu/YUVUtils.cpp +++ b/tools/gpu/YUVUtils.cpp @@ -221,7 +221,6 @@ bool LazyYUVImage::ensureYUVImage(GrRecordingContext* rContext, Type type) { break; } case Type::kFromTextures: - case Type::kFromTexturesCopyToExternal: if (!rContext || rContext->abandoned()) { return false; } @@ -253,47 +252,14 @@ bool LazyYUVImage::ensureYUVImage(GrRecordingContext* rContext, Type type) { if (!yuvaTextures.isValid()) { return false; } - if (type == Type::kFromTextures) { - void* planeRelContext = - sk_gpu_test::ManagedBackendTexture::MakeYUVAReleaseContext(mbets); - fYUVImage[idx] = SkImage::MakeFromYUVATextures( - direct, - yuvaTextures, - fColorSpace, - sk_gpu_test::ManagedBackendTexture::ReleaseProc, - planeRelContext); - } else { - SkASSERT(type == Type::kFromTexturesCopyToExternal); - sk_sp rgbaMBET; - for (auto ct : {SkYUVAPixmaps::RecommendedRGBAColorType(fPixmaps.dataType()), - kRGBA_8888_SkColorType}) { - rgbaMBET = sk_gpu_test::ManagedBackendTexture::MakeWithoutData( - direct, - fPixmaps.yuvaInfo().width(), - fPixmaps.yuvaInfo().height(), - kUnknown_SkColorType, - GrMipmapped::kNo, - GrRenderable::kYes); - if (rgbaMBET) { - void* planeRelContext = - sk_gpu_test::ManagedBackendTexture::MakeYUVAReleaseContext( - mbets); - fYUVImage[idx] = SkImage::MakeFromYUVATexturesCopyToExternal( - direct, - yuvaTextures, - rgbaMBET->texture(), - ct, - fColorSpace, - sk_gpu_test::ManagedBackendTexture::ReleaseProc, - planeRelContext, - sk_gpu_test::ManagedBackendTexture::ReleaseProc, - rgbaMBET->releaseContext()); - if (fYUVImage[idx]) { - break; - } - } - } - } + void* planeRelContext = + sk_gpu_test::ManagedBackendTexture::MakeYUVAReleaseContext(mbets); + fYUVImage[idx] = SkImage::MakeFromYUVATextures( + direct, + yuvaTextures, + fColorSpace, + sk_gpu_test::ManagedBackendTexture::ReleaseProc, + planeRelContext); } } return fYUVImage[idx] != nullptr; diff --git a/tools/gpu/YUVUtils.h b/tools/gpu/YUVUtils.h index 4cc0878e1a..bfc1babad0 100644 --- a/tools/gpu/YUVUtils.h +++ b/tools/gpu/YUVUtils.h @@ -33,12 +33,7 @@ public: GrMipmapped = GrMipmapped::kNo, sk_sp = nullptr); - enum class Type { - kFromPixmaps, - kFromGenerator, - kFromTextures, - kFromTexturesCopyToExternal - }; + enum class Type { kFromPixmaps, kFromGenerator, kFromTextures }; SkISize dimensions() const { return fPixmaps.yuvaInfo().dimensions(); }