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 <adlai@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2020-12-08 16:39:32 -05:00 committed by Skia Commit-Bot
parent 5e744acfad
commit 8670c98875
10 changed files with 86 additions and 249 deletions

View File

@ -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

View File

@ -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:

View File

@ -392,46 +392,6 @@ public:
sk_sp<SkColorSpace> 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<SkImage> MakeFromYUVATexturesCopyToExternal(
GrRecordingContext* context,
const GrYUVABackendTextures& yuvaTextures,
const GrBackendTexture& rgbaResultTexture,
SkColorType colorType,
sk_sp<SkColorSpace> imageColorSpace = nullptr,
TextureReleaseProc yuvaReleaseProc = nullptr,
ReleaseContext yuvaReleaseContext = nullptr,
TextureReleaseProc rgbaReleaseProc = nullptr,
ReleaseContext rgbaReleaseContext = nullptr);
/**
Deprecated. Use version that takes GrYUVABackendTextures.

View File

@ -314,68 +314,6 @@ sk_sp<SkImage> SkImage::MakeTextureFromCompressed(GrDirectContext* direct, sk_sp
colorType, kOpaque_SkAlphaType, nullptr);
}
sk_sp<SkImage> SkImage::MakeFromYUVATexturesCopyToExternal(
GrRecordingContext* context,
const GrYUVABackendTextures& yuvaTextures,
const GrBackendTexture& rgbaResultTexture,
SkColorType colorType,
sk_sp<SkColorSpace> 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<SkImage_Gpu>(sk_ref_sp(context), kNeedNewImageUniqueID,
renderTargetContext->readSurfaceView(), colorType, at,
renderTargetContext->colorInfo().refColorSpace());
}
static sk_sp<SkImage> create_image_from_producer(GrRecordingContext* context,
GrTextureProducer* producer,
uint32_t id, GrMipmapped mipMapped) {
@ -388,7 +326,6 @@ static sk_sp<SkImage> create_image_from_producer(GrRecordingContext* context,
producer->alphaType(), sk_ref_sp(producer->colorSpace()));
}
sk_sp<SkImage> SkImage::makeTextureImage(GrDirectContext* dContext,
GrMipmapped mipMapped,
SkBudgeted budgeted) const {

View File

@ -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<GrRefCntedCallback> 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<int>(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<GrColorSpaceXform> 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<GrTextureProxy> SkImage_GpuBase::MakePromiseImageLazyProxy(
GrRecordingContext* context,
SkISize dimensions,

View File

@ -59,11 +59,6 @@ public:
sk_sp<SkColorSpace> 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<GrRefCntedCallback> 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<GrColorSpaceXform>,
GrSurfaceProxyView[4],
const SkYUVAIndex[4]);
protected:
SkImage_GpuBase(sk_sp<GrImageContext>, SkISize size, uint32_t uniqueID, SkColorType,
SkAlphaType, sk_sp<SkColorSpace>);

View File

@ -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<GrRefCntedCallback> 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<int>(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<GrColorSpaceXform> 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> 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> 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;

View File

@ -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<GrRefCntedCallback> releaseHelper);
private:
SkImage_GpuYUVA(sk_sp<GrImageContext>, const SkImage_GpuYUVA* image, sk_sp<SkColorSpace>);

View File

@ -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,7 +252,6 @@ 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(
@ -262,38 +260,6 @@ bool LazyYUVImage::ensureYUVImage(GrRecordingContext* rContext, Type type) {
fColorSpace,
sk_gpu_test::ManagedBackendTexture::ReleaseProc,
planeRelContext);
} else {
SkASSERT(type == Type::kFromTexturesCopyToExternal);
sk_sp<sk_gpu_test::ManagedBackendTexture> 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;
}
}
}
}
}
}
return fYUVImage[idx] != nullptr;

View File

@ -33,12 +33,7 @@ public:
GrMipmapped = GrMipmapped::kNo,
sk_sp<SkColorSpace> = nullptr);
enum class Type {
kFromPixmaps,
kFromGenerator,
kFromTextures,
kFromTexturesCopyToExternal
};
enum class Type { kFromPixmaps, kFromGenerator, kFromTextures };
SkISize dimensions() const { return fPixmaps.yuvaInfo().dimensions(); }