Some more clean-up of YUVA code
* Restore pre-colortype interface * Remove other colortype references Bug: skia:7903 Change-Id: I0db6d61e78d719ff941ac195bcbed4416f7d3138 Reviewed-on: https://skia-review.googlesource.com/c/164610 Commit-Queue: Jim Van Verth <jvanverth@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
4935368332
commit
c96740729a
@ -126,7 +126,7 @@ public:
|
||||
*/
|
||||
sk_sp<SkImage> makeYUVAPromiseTexture(SkYUVColorSpace yuvColorSpace,
|
||||
const GrBackendFormat yuvaFormats[],
|
||||
const SkYUVSizeInfo& yuvaSizeInfo,
|
||||
const SkISize yuvaSizes[],
|
||||
const SkYUVAIndex yuvaIndices[4],
|
||||
int imageWidth,
|
||||
int imageHeight,
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "SkColor.h"
|
||||
#include "SkImage.h"
|
||||
#include "SkImageInfo.h"
|
||||
#include "SkYUVSizeInfo.h"
|
||||
#include "SkYUVASizeInfo.h"
|
||||
|
||||
class GrContext;
|
||||
class GrContextThreadSafeProxy;
|
||||
|
@ -231,7 +231,7 @@ sk_sp<SkImage> SkDeferredDisplayListRecorder::makePromiseTexture(
|
||||
sk_sp<SkImage> SkDeferredDisplayListRecorder::makeYUVAPromiseTexture(
|
||||
SkYUVColorSpace yuvColorSpace,
|
||||
const GrBackendFormat yuvaFormats[],
|
||||
const SkYUVSizeInfo& yuvaSizeInfo,
|
||||
const SkISize yuvaSizes[],
|
||||
const SkYUVAIndex yuvaIndices[4],
|
||||
int imageWidth,
|
||||
int imageHeight,
|
||||
@ -248,7 +248,7 @@ sk_sp<SkImage> SkDeferredDisplayListRecorder::makeYUVAPromiseTexture(
|
||||
return SkImage_GpuYUVA::MakePromiseYUVATexture(fContext.get(),
|
||||
yuvColorSpace,
|
||||
yuvaFormats,
|
||||
yuvaSizeInfo,
|
||||
yuvaSizes,
|
||||
yuvaIndices,
|
||||
imageWidth,
|
||||
imageHeight,
|
||||
|
@ -127,8 +127,6 @@ sk_sp<SkImage> SkImage_Gpu::ConvertYUVATexturesToRGB(
|
||||
// of validate_backend_texture.
|
||||
GrBackendTexture yuvaTexturesCopy[4];
|
||||
|
||||
bool nv12 = (yuvaIndices[1].fIndex == yuvaIndices[2].fIndex);
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
// Validate that the yuvaIndices refer to valid backend textures.
|
||||
const SkYUVAIndex& yuvaIndex = yuvaIndices[i];
|
||||
@ -142,32 +140,8 @@ sk_sp<SkImage> SkImage_Gpu::ConvertYUVATexturesToRGB(
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkColorType ct = kUnknown_SkColorType;
|
||||
if (SkYUVAIndex::kA_Index == i) {
|
||||
// The A plane is always kAlpha8 (for now)
|
||||
ct = kAlpha_8_SkColorType;
|
||||
} else {
|
||||
// The UV planes can either be interleaved or planar. If interleaved the Y plane
|
||||
// should have A8 color type but may be RGBA. We fall back in the latter case below.
|
||||
ct = nv12 && SkYUVAIndex::kY_Index != i ? kRGBA_8888_SkColorType : kAlpha_8_SkColorType;
|
||||
}
|
||||
|
||||
if (!yuvaTexturesCopy[yuvaIndex.fIndex].isValid()) {
|
||||
yuvaTexturesCopy[yuvaIndex.fIndex] = yuvaTextures[yuvaIndex.fIndex];
|
||||
|
||||
// TODO: Instead of using assumption about whether it is NV12 format to guess colorType,
|
||||
// actually use channel information here.
|
||||
// Alternate TODO: Don't bother validating.
|
||||
if (!ValidateBackendTexture(ctx, yuvaTexturesCopy[yuvaIndex.fIndex],
|
||||
&yuvaTexturesCopy[yuvaIndex.fIndex].fConfig,
|
||||
ct, kPremul_SkAlphaType, nullptr)) {
|
||||
// Try RGBA in case the assumed colortype is wrong
|
||||
if (!ValidateBackendTexture(ctx, yuvaTexturesCopy[yuvaIndex.fIndex],
|
||||
&yuvaTexturesCopy[yuvaIndex.fIndex].fConfig,
|
||||
kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Check that for each plane, the channel actually exist in the image source we are
|
||||
|
@ -96,94 +96,11 @@ sk_sp<GrTextureProxy> SkImage_GpuYUVA::asTextureProxyRef() const {
|
||||
return fRGBProxy;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//*** bundle this into a helper function used by this and SkImage_Gpu?
|
||||
sk_sp<SkImage> SkImage_GpuYUVA::MakeFromYUVATextures(GrContext* ctx,
|
||||
SkYUVColorSpace colorSpace,
|
||||
const GrBackendTexture yuvaTextures[],
|
||||
const SkYUVAIndex yuvaIndices[4],
|
||||
int width,
|
||||
int height,
|
||||
GrSurfaceOrigin origin,
|
||||
sk_sp<SkColorSpace> imageColorSpace) {
|
||||
GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider();
|
||||
|
||||
// Right now this still only deals with YUV and NV12 formats. Assuming that YUV has different
|
||||
// textures for U and V planes, while NV12 uses same texture for U and V planes.
|
||||
bool nv12 = (yuvaIndices[SkYUVAIndex::kU_Index].fIndex ==
|
||||
yuvaIndices[SkYUVAIndex::kV_Index].fIndex);
|
||||
|
||||
// We need to make a copy of the input backend textures because we need to preserve the result
|
||||
// of validate_backend_texture.
|
||||
GrBackendTexture yuvaTexturesCopy[4];
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
// Validate that the yuvaIndices refer to valid backend textures.
|
||||
const SkYUVAIndex& yuvaIndex = yuvaIndices[i];
|
||||
if (SkYUVAIndex::kA_Index == i && yuvaIndex.fIndex == -1) {
|
||||
// Meaning the A plane isn't passed in.
|
||||
continue;
|
||||
}
|
||||
if (yuvaIndex.fIndex == -1 || yuvaIndex.fIndex > 3) {
|
||||
// Y plane, U plane, and V plane must refer to image sources being passed in. There are
|
||||
// at most 4 image sources being passed in, could not have a index more than 3.
|
||||
return nullptr;
|
||||
}
|
||||
SkColorType ct = kUnknown_SkColorType;
|
||||
if (SkYUVAIndex::kY_Index == i || SkYUVAIndex::kA_Index == i) {
|
||||
// The Y and A planes are always kAlpha8 (for now)
|
||||
ct = kAlpha_8_SkColorType;
|
||||
} else {
|
||||
// The UV planes can either be interleaved or planar
|
||||
ct = nv12 ? kRGBA_8888_SkColorType : kAlpha_8_SkColorType;
|
||||
}
|
||||
|
||||
if (!yuvaTexturesCopy[yuvaIndex.fIndex].isValid()) {
|
||||
yuvaTexturesCopy[yuvaIndex.fIndex] = yuvaTextures[yuvaIndex.fIndex];
|
||||
// TODO: Instead of using assumption about whether it is NV12 format to guess colorType,
|
||||
// actually use channel information here.
|
||||
if (!ValidateBackendTexture(ctx, yuvaTexturesCopy[yuvaIndex.fIndex],
|
||||
&yuvaTexturesCopy[yuvaIndex.fIndex].fConfig,
|
||||
ct, kUnpremul_SkAlphaType, nullptr)) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Check that for each plane, the channel actually exist in the image source we are
|
||||
// reading from.
|
||||
}
|
||||
|
||||
sk_sp<GrTextureProxy> tempTextureProxies[4]; // build from yuvaTextures
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
// Fill in tempTextureProxies to avoid duplicate texture proxies.
|
||||
int textureIndex = yuvaIndices[i].fIndex;
|
||||
|
||||
// Safely ignore since this means we are missing the A plane.
|
||||
if (textureIndex == -1) {
|
||||
SkASSERT(SkYUVAIndex::kA_Index == i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!tempTextureProxies[textureIndex]) {
|
||||
SkASSERT(yuvaTexturesCopy[textureIndex].isValid());
|
||||
tempTextureProxies[textureIndex] =
|
||||
proxyProvider->wrapBackendTexture(yuvaTexturesCopy[textureIndex], origin);
|
||||
if (!tempTextureProxies[textureIndex]) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sk_make_sp<SkImage_GpuYUVA>(sk_ref_sp(ctx), width, height, kNeedNewImageUniqueID,
|
||||
colorSpace, tempTextureProxies, yuvaIndices, origin,
|
||||
imageColorSpace, SkBudgeted::kYes);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
sk_sp<SkImage> SkImage_GpuYUVA::MakePromiseYUVATexture(GrContext* context,
|
||||
SkYUVColorSpace yuvColorSpace,
|
||||
const GrBackendFormat yuvaFormats[],
|
||||
const SkYUVSizeInfo& yuvaSizeInfo,
|
||||
const SkISize yuvaSizes[],
|
||||
const SkYUVAIndex yuvaIndices[4],
|
||||
int imageWidth,
|
||||
int imageHeight,
|
||||
@ -233,16 +150,14 @@ sk_sp<SkImage> SkImage_GpuYUVA::MakePromiseYUVATexture(GrContext* context,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// verify sizeInfo with expected texture count
|
||||
// verify sizes with expected texture count
|
||||
for (int i = 0; i < numTextures; ++i) {
|
||||
if (yuvaSizeInfo.fSizes[i].isEmpty() ||
|
||||
!yuvaSizeInfo.fWidthBytes[i]) {
|
||||
if (yuvaSizes[i].isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
for (int i = numTextures; i < SkYUVSizeInfo::kMaxCount; ++i) {
|
||||
if (!yuvaSizeInfo.fSizes[i].isEmpty() ||
|
||||
yuvaSizeInfo.fWidthBytes[i]) {
|
||||
if (!yuvaSizes[i].isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@ -277,8 +192,8 @@ sk_sp<SkImage> SkImage_GpuYUVA::MakePromiseYUVATexture(GrContext* context,
|
||||
};
|
||||
GrSurfaceDesc desc;
|
||||
desc.fFlags = kNone_GrSurfaceFlags;
|
||||
desc.fWidth = yuvaSizeInfo.fSizes[texIdx].width();
|
||||
desc.fHeight = yuvaSizeInfo.fSizes[texIdx].height();
|
||||
desc.fWidth = yuvaSizes[texIdx].width();
|
||||
desc.fHeight = yuvaSizes[texIdx].height();
|
||||
desc.fConfig = params.fConfig;
|
||||
desc.fSampleCnt = 1;
|
||||
proxies[texIdx] = proxyProvider->createLazyProxy(
|
||||
|
@ -63,7 +63,7 @@ public:
|
||||
@param context Gpu context
|
||||
@param yuvColorSpace color range of expected YUV pixels
|
||||
@param yuvaFormats formats of promised gpu textures for each YUVA plane
|
||||
@param yuvaSizeInfo width, height, and colortype of promised gpu textures
|
||||
@param yuvaSizes width and height of promised gpu textures
|
||||
@param yuvaIndices mapping from yuv plane index to texture representing that plane
|
||||
@param width width of promised gpu texture
|
||||
@param height height of promised gpu texture
|
||||
@ -78,7 +78,7 @@ public:
|
||||
static sk_sp<SkImage> MakePromiseYUVATexture(GrContext* context,
|
||||
SkYUVColorSpace yuvColorSpace,
|
||||
const GrBackendFormat yuvaFormats[],
|
||||
const SkYUVSizeInfo& yuvaSizeInfo,
|
||||
const SkISize yuvaSizes[],
|
||||
const SkYUVAIndex yuvaIndices[4],
|
||||
int width,
|
||||
int height,
|
||||
@ -89,15 +89,6 @@ public:
|
||||
PromiseDoneProc promiseDoneProc,
|
||||
TextureContext textureContexts[]);
|
||||
|
||||
static sk_sp<SkImage> MakeFromYUVATextures(GrContext* context,
|
||||
SkYUVColorSpace yuvColorSpace,
|
||||
const GrBackendTexture yuvaTextures[],
|
||||
const SkYUVAIndex yuvaIndices[4],
|
||||
int width,
|
||||
int height,
|
||||
GrSurfaceOrigin imageOrigin,
|
||||
sk_sp<SkColorSpace> imageColorSpace);
|
||||
|
||||
private:
|
||||
// This array will usually only be sparsely populated.
|
||||
// The actual non-null fields are dictated by the 'fYUVAIndices' indices
|
||||
|
@ -144,7 +144,7 @@ sk_sp<SkImage> DDLPromiseImageHelper::PromiseImageCreator(const void* rawData,
|
||||
if (curImage.isYUV()) {
|
||||
GrBackendFormat backendFormats[SkYUVSizeInfo::kMaxCount];
|
||||
void* contexts[SkYUVSizeInfo::kMaxCount] = { nullptr, nullptr, nullptr, nullptr };
|
||||
SkYUVSizeInfo sizeInfo;
|
||||
SkISize sizes[SkYUVSizeInfo::kMaxCount];
|
||||
// TODO: store this value somewhere?
|
||||
int textureCount;
|
||||
SkAssertResult(SkYUVAIndex::AreValidIndices(curImage.yuvaIndices(), &textureCount));
|
||||
@ -153,17 +153,15 @@ sk_sp<SkImage> DDLPromiseImageHelper::PromiseImageCreator(const void* rawData,
|
||||
backendFormats[i] = caps->createFormatFromBackendTexture(backendTex);
|
||||
|
||||
contexts[i] = curImage.refCallbackContext(i).release();
|
||||
sizeInfo.fSizes[i].set(curImage.yuvPixmap(i).width(), curImage.yuvPixmap(i).height());
|
||||
sizeInfo.fWidthBytes[i] = curImage.yuvPixmap(i).rowBytes();
|
||||
sizes[i].set(curImage.yuvPixmap(i).width(), curImage.yuvPixmap(i).height());
|
||||
}
|
||||
for (int i = textureCount; i < SkYUVSizeInfo::kMaxCount; ++i) {
|
||||
sizeInfo.fSizes[i] = SkISize::MakeEmpty();
|
||||
sizeInfo.fWidthBytes[i] = 0;
|
||||
sizes[i] = SkISize::MakeEmpty();
|
||||
}
|
||||
|
||||
image = recorder->makeYUVAPromiseTexture(curImage.yuvColorSpace(),
|
||||
backendFormats,
|
||||
sizeInfo,
|
||||
sizes,
|
||||
curImage.yuvaIndices(),
|
||||
curImage.overallWidth(),
|
||||
curImage.overallHeight(),
|
||||
|
Loading…
Reference in New Issue
Block a user