Remove unused copy-to-external YUV SkImage factories.

Also inline some helper functions into newer factory method
that are no longer shared.

Bug: skia:10632
Change-Id: I466c59f668d882802087acad1ec1f229505a3377
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/334596
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
Brian Salomon 2020-11-12 16:34:28 -05:00 committed by Skia Commit-Bot
parent e9783f22db
commit a29ed26cfc
6 changed files with 55 additions and 207 deletions

View File

@ -7,6 +7,17 @@ This file includes a list of high level updates for each milestone release.
Milestone 89
------------
* The following YUV image factories have been removed:
SkImage::MakeFromYUVTexturesCopyWithExternalBackend
SkImage::MakeFromNV12TexturesCopyWithExternalBackend
Replacement pattern outlined below.
1) Make image using MakeFromYUVATextures
2) Make a SkSurface around result texture using SkSurface::MakeFromBackendTexture
3) surface->getCanvas()->drawImage(image, 0, 0);
4) surface->flushAndSubmit()
5) Optional: SkImage::MakeFromBackendTexture() to use as SkImage.
https://review.skia.org/334596
* Added a new interface for GrDirectContext creation in Metal, using
a new struct called GrMtlBackendContext. The previous interface taking
a MTLDevice and MTLCommandQueue is deprecated.

View File

@ -415,11 +415,10 @@ public:
/** 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. This should be preferred over
MakeFromYUVTexturesCopyWithExternalBackend and MakeFromNV12TexturesCopyWithExternalBackend.
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.
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
@ -514,43 +513,6 @@ public:
bool limitToMaxTextureSize = false,
sk_sp<SkColorSpace> imageColorSpace = nullptr);
/** To be deprecated.
*/
static sk_sp<SkImage> MakeFromYUVTexturesCopyWithExternalBackend(
GrRecordingContext* context,
SkYUVColorSpace yuvColorSpace,
const GrBackendTexture yuvTextures[3],
GrSurfaceOrigin textureOrigin,
const GrBackendTexture& backendTexture,
sk_sp<SkColorSpace> imageColorSpace = nullptr);
/** Creates SkImage from copy of nv12Textures, an array of textures on GPU.
nv12Textures[0] contains pixels for YUV component y plane.
nv12Textures[1] contains pixels for YUV component u plane,
followed by pixels for YUV component v plane.
Returned SkImage has the dimensions nv12Textures[2] and stores pixels in backendTexture.
yuvColorSpace describes how YUV colors convert to RGB colors.
@param context GPU context
@param yuvColorSpace How the YUV values are converted to RGB
@param nv12Textures array of YUV textures on GPU
@param textureOrigin origin of textures in nv12Textures and of backendTexture
@param backendTexture the resource that stores the final pixels
@param imageColorSpace range of colors; may be nullptr
@param textureReleaseProc function called when backendTexture can be released
@param releaseContext state passed to textureReleaseProc
@return created SkImage, or nullptr
*/
static sk_sp<SkImage> MakeFromNV12TexturesCopyWithExternalBackend(
GrRecordingContext* context,
SkYUVColorSpace yuvColorSpace,
const GrBackendTexture nv12Textures[2],
GrSurfaceOrigin textureOrigin,
const GrBackendTexture& backendTexture,
sk_sp<SkColorSpace> imageColorSpace = nullptr,
TextureReleaseProc textureReleaseProc = nullptr,
ReleaseContext releaseContext = nullptr);
enum class BitDepth {
kU8, //!< uses 8-bit unsigned int per color component
kF16, //!< uses 16-bit float per color component

View File

@ -575,12 +575,6 @@ sk_sp<SkImage> SkImage::makeTextureImage(GrDirectContext*, GrMipmapped, SkBudget
return nullptr;
}
sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopyWithExternalBackend(
GrRecordingContext*, SkYUVColorSpace, const GrBackendTexture[2], GrSurfaceOrigin,
const GrBackendTexture&, sk_sp<SkColorSpace>, TextureReleaseProc, ReleaseContext) {
return nullptr;
}
#endif
///////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -318,89 +318,6 @@ sk_sp<SkImage> SkImage::MakeTextureFromCompressed(GrDirectContext* direct, sk_sp
colorType, kOpaque_SkAlphaType, nullptr);
}
sk_sp<SkImage> SkImage_Gpu::ConvertYUVATexturesToRGB(GrRecordingContext* rContext,
SkYUVColorSpace yuvColorSpace,
const GrBackendTexture yuvaTextures[],
const SkYUVAIndex yuvaIndices[4],
SkISize size,
GrSurfaceOrigin origin,
GrRenderTargetContext* renderTargetContext,
sk_sp<GrRefCntedCallback> releaseHelper) {
SkASSERT(renderTargetContext);
int numTextures;
if (!SkYUVAIndex::AreValidIndices(yuvaIndices, &numTextures)) {
return nullptr;
}
GrSurfaceProxyView tempViews[4];
if (!SkImage_GpuBase::MakeTempTextureProxies(rContext, yuvaTextures, numTextures, yuvaIndices,
origin, tempViews, std::move(releaseHelper))) {
return nullptr;
}
const SkRect rect = SkRect::MakeIWH(size.width(), size.height());
const GrCaps& caps = *rContext->priv().caps();
if (!RenderYUVAToRGBA(caps, renderTargetContext, rect, yuvColorSpace, nullptr,
tempViews, yuvaIndices)) {
return nullptr;
}
SkColorType ct = GrColorTypeToSkColorType(renderTargetContext->colorInfo().colorType());
SkAlphaType at = GetAlphaTypeFromYUVAIndices(yuvaIndices);
// MDB: this call is okay bc we know 'renderTargetContext' was exact
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(rContext), kNeedNewImageUniqueID,
renderTargetContext->readSurfaceView(), ct, at,
renderTargetContext->colorInfo().refColorSpace());
}
static sk_sp<SkImage> make_flattened_image_with_external_backend(
GrRecordingContext* rContext,
SkYUVColorSpace yuvColorSpace,
const GrBackendTexture yuvaTextures[],
const SkYUVAIndex yuvaIndices[4],
SkISize imageSize,
GrSurfaceOrigin imageOrigin,
const GrBackendTexture& backendTexture,
GrColorType colorType,
sk_sp<SkColorSpace> imageColorSpace,
sk_sp<GrRefCntedCallback> yuvaReleaseHelper,
sk_sp<GrRefCntedCallback> rgbaReleaseHelper) {
const GrCaps* caps = rContext->priv().caps();
SkAlphaType at = SkImage_GpuBase::GetAlphaTypeFromYUVAIndices(yuvaIndices);
if (!SkImage_Gpu::ValidateBackendTexture(caps, backendTexture, colorType,
kRGBA_8888_SkColorType, at, nullptr)) {
return nullptr;
}
// Needs to create a render target with external texture
// in order to draw to it for the yuv->rgb conversion.
auto renderTargetContext = GrRenderTargetContext::MakeFromBackendTexture(
rContext, colorType, std::move(imageColorSpace), backendTexture, 1, imageOrigin,
nullptr, std::move(rgbaReleaseHelper));
if (!renderTargetContext) {
return nullptr;
}
return SkImage_Gpu::ConvertYUVATexturesToRGB(rContext, yuvColorSpace, yuvaTextures, yuvaIndices,
imageSize, imageOrigin, renderTargetContext.get(),
std::move(yuvaReleaseHelper));
}
// Some YUVA factories infer the YUVAIndices. This helper identifies the channel to use for single
// channel textures.
static SkColorChannel get_single_channel(const GrBackendTexture& tex) {
switch (tex.getBackendFormat().channelMask()) {
case kGray_SkColorChannelFlag: // Gray can be read as any of kR, kG, kB.
case kRed_SkColorChannelFlag:
return SkColorChannel::kR;
case kAlpha_SkColorChannelFlag:
return SkColorChannel::kA;
default: // multiple channels in the texture. Guess kR.
return SkColorChannel::kR;
}
}
sk_sp<SkImage> SkImage::MakeFromYUVATexturesCopyToExternal(
GrRecordingContext* context,
const GrYUVABackendTextures& yuvaTextures,
@ -425,70 +342,42 @@ sk_sp<SkImage> SkImage::MakeFromYUVATexturesCopyToExternal(
rgbaResultTexture.dimensions() != yuvaTextures.yuvaInfo().dimensions()) {
return nullptr;
}
return make_flattened_image_with_external_backend(context,
yuvaTextures.yuvaInfo().yuvColorSpace(),
yuvaTextures.textures().data(),
yuvaIndices,
rgbaResultTexture.dimensions(),
yuvaTextures.textureOrigin(),
rgbaResultTexture,
SkColorTypeToGrColorType(colorType),
std::move(imageColorSpace),
std::move(yuvaReleaseHelper),
std::move(rgbaReleaseHelper));
}
sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopyWithExternalBackend(
GrRecordingContext* ctx, SkYUVColorSpace yuvColorSpace,
const GrBackendTexture yuvTextures[3], GrSurfaceOrigin imageOrigin,
const GrBackendTexture& backendTexture, sk_sp<SkColorSpace> imageColorSpace) {
SkYUVAIndex yuvaIndices[4] = {
SkYUVAIndex{0, get_single_channel(yuvTextures[0])},
SkYUVAIndex{1, get_single_channel(yuvTextures[1])},
SkYUVAIndex{2, get_single_channel(yuvTextures[2])},
SkYUVAIndex{-1, SkColorChannel::kA}};
return make_flattened_image_with_external_backend(ctx,
yuvColorSpace,
yuvTextures,
yuvaIndices,
yuvTextures[0].dimensions(),
imageOrigin,
backendTexture,
GrColorType::kRGBA_8888,
std::move(imageColorSpace),
nullptr,
nullptr);
}
const GrCaps* caps = context->priv().caps();
sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopyWithExternalBackend(
GrRecordingContext* ctx,
SkYUVColorSpace yuvColorSpace,
const GrBackendTexture nv12Textures[2],
GrSurfaceOrigin imageOrigin,
const GrBackendTexture& backendTexture,
sk_sp<SkColorSpace> imageColorSpace,
TextureReleaseProc textureReleaseProc,
ReleaseContext releaseContext) {
auto releaseHelper = GrRefCntedCallback::Make(textureReleaseProc, releaseContext);
// 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;
}
SkYUVAIndex yuvaIndices[4] = {
SkYUVAIndex{0, get_single_channel(nv12Textures[0])},
SkYUVAIndex{1, SkColorChannel::kR},
SkYUVAIndex{1, SkColorChannel::kG},
SkYUVAIndex{-1, SkColorChannel::kA}};
SkISize size{nv12Textures[0].width(), nv12Textures[0].height()};
// 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;
}
return make_flattened_image_with_external_backend(ctx,
yuvColorSpace,
nv12Textures,
yuvaIndices,
size,
imageOrigin,
backendTexture,
GrColorType::kRGBA_8888,
std::move(imageColorSpace),
/* plane release helper*/ nullptr,
std::move(releaseHelper));
// 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,

View File

@ -82,16 +82,6 @@ public:
PromiseImageTextureReleaseProc textureReleaseProc,
PromiseImageTextureContext textureContext);
static sk_sp<SkImage> ConvertYUVATexturesToRGB(
GrRecordingContext*,
SkYUVColorSpace,
const GrBackendTexture[],
const SkYUVAIndex[SkYUVAIndex::kIndexCount],
SkISize,
GrSurfaceOrigin,
GrRenderTargetContext*,
sk_sp<GrRefCntedCallback> releaseHelper = nullptr);
private:
GrSurfaceProxyView fView;

View File

@ -76,6 +76,14 @@ 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>);
@ -91,12 +99,6 @@ protected:
PromiseImageTextureFulfillProc,
sk_sp<GrRefCntedCallback> releaseHelper);
static bool RenderYUVAToRGBA(const GrCaps&, GrRenderTargetContext*,
const SkRect&, SkYUVColorSpace,
sk_sp<GrColorSpaceXform>,
GrSurfaceProxyView [4],
const SkYUVAIndex [4]);
sk_sp<GrImageContext> fContext;
private: