Index: src/gpu/GrYUVProvider.cpp |
diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp |
index 844849a57567360157fe14b172291a276d4288d1..4102795c8f1fefdbd42e3fc1ceb586b78a0e9e65 100644 |
--- a/src/gpu/GrYUVProvider.cpp |
+++ b/src/gpu/GrYUVProvider.cpp |
@@ -40,22 +40,21 @@ bool YUVScoper::init(GrYUVProvider* provider, SkYUVPlanesCache::Info* yuvInfo, v |
if (fCachedData.get()) { |
planes[0] = (void*)fCachedData->data(); |
- planes[1] = (uint8_t*)planes[0] + yuvInfo->fSizeInMemory[0]; |
- planes[2] = (uint8_t*)planes[1] + yuvInfo->fSizeInMemory[1]; |
+ planes[1] = (uint8_t*)planes[0] + |
+ (yuvInfo->fSizeInfo.fYWidthBytes * yuvInfo->fSizeInfo.fYSize.fHeight); |
+ planes[2] = (uint8_t*)planes[1] + |
+ (yuvInfo->fSizeInfo.fUWidthBytes * yuvInfo->fSizeInfo.fUSize.fHeight); |
} else { |
- // Fetch yuv plane sizes for memory allocation. Here, width and height can be |
- // rounded up to JPEG block size and be larger than the image's width and height. |
- if (!provider->onGetYUVSizes(yuvInfo->fSize)) { |
+ // Fetch yuv plane sizes for memory allocation. |
+ if (!provider->onQueryYUV8(&yuvInfo->fSizeInfo, &yuvInfo->fColorSpace)) { |
return false; |
} |
// Allocate the memory for YUV |
size_t totalSize(0); |
- for (int i = 0; i < GrYUVProvider::kPlaneCount; ++i) { |
- yuvInfo->fRowBytes[i] = yuvInfo->fSize[i].fWidth; // we assume snug fit: rb == width |
- yuvInfo->fSizeInMemory[i] = yuvInfo->fRowBytes[i] * yuvInfo->fSize[i].fHeight; |
- totalSize += yuvInfo->fSizeInMemory[i]; |
- } |
+ totalSize += yuvInfo->fSizeInfo.fYWidthBytes * yuvInfo->fSizeInfo.fYSize.fHeight; |
+ totalSize += yuvInfo->fSizeInfo.fUWidthBytes * yuvInfo->fSizeInfo.fUSize.fHeight; |
+ totalSize += yuvInfo->fSizeInfo.fVWidthBytes * yuvInfo->fSizeInfo.fVSize.fHeight; |
if (useCache) { |
fCachedData.reset(SkResourceCache::NewCachedData(totalSize)); |
planes[0] = fCachedData->writable_data(); |
@@ -63,12 +62,13 @@ bool YUVScoper::init(GrYUVProvider* provider, SkYUVPlanesCache::Info* yuvInfo, v |
fStorage.reset(totalSize); |
planes[0] = fStorage.get(); |
} |
- planes[1] = (uint8_t*)planes[0] + yuvInfo->fSizeInMemory[0]; |
- planes[2] = (uint8_t*)planes[1] + yuvInfo->fSizeInMemory[1]; |
+ planes[1] = (uint8_t*)planes[0] + |
+ (yuvInfo->fSizeInfo.fYWidthBytes * yuvInfo->fSizeInfo.fYSize.fHeight); |
+ planes[2] = (uint8_t*)planes[1] + |
+ (yuvInfo->fSizeInfo.fUWidthBytes * yuvInfo->fSizeInfo.fUSize.fHeight); |
- // Get the YUV planes and update plane sizes to actual image size |
- if (!provider->onGetYUVPlanes(yuvInfo->fSize, planes, yuvInfo->fRowBytes, |
- &yuvInfo->fColorSpace)) { |
+ // Get the YUV planes. |
+ if (!provider->onGetYUV8Planes(yuvInfo->fSizeInfo, planes)) { |
return false; |
} |
@@ -88,25 +88,53 @@ GrTexture* GrYUVProvider::refAsTexture(GrContext* ctx, const GrSurfaceDesc& desc |
return nullptr; |
} |
- GrSurfaceDesc yuvDesc; |
- yuvDesc.fConfig = kAlpha_8_GrPixelConfig; |
- SkAutoTUnref<GrTexture> yuvTextures[3]; |
- for (int i = 0; i < 3; ++i) { |
msarett
2016/02/18 23:00:02
The fact that I needed to unroll this loop makes a
|
- yuvDesc.fWidth = yuvInfo.fSize[i].fWidth; |
- yuvDesc.fHeight = yuvInfo.fSize[i].fHeight; |
- // TODO: why do we need this check? |
- bool needsExactTexture = (yuvDesc.fWidth != yuvInfo.fSize[0].fWidth) || |
- (yuvDesc.fHeight != yuvInfo.fSize[0].fHeight); |
- if (needsExactTexture) { |
- yuvTextures[i].reset(ctx->textureProvider()->createTexture(yuvDesc, true)); |
- } else { |
- yuvTextures[i].reset(ctx->textureProvider()->createApproxTexture(yuvDesc)); |
- } |
- if (!yuvTextures[i] || |
- !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, |
- yuvDesc.fConfig, planes[i], yuvInfo.fRowBytes[i])) { |
- return nullptr; |
- } |
+ GrSurfaceDesc yDesc, uDesc, vDesc; |
+ yDesc.fConfig = kAlpha_8_GrPixelConfig; |
+ uDesc.fConfig = kAlpha_8_GrPixelConfig; |
+ vDesc.fConfig = kAlpha_8_GrPixelConfig; |
+ SkAutoTUnref<GrTexture> yuvTextures[GrYUVProvider::kPlaneCount]; |
+ |
+ yDesc.fWidth = yuvInfo.fSizeInfo.fYSize.fWidth; |
+ yDesc.fHeight = yuvInfo.fSizeInfo.fYSize.fHeight; |
+ yuvTextures[GrYUVProvider::kY_Index].reset(ctx->textureProvider()->createTexture(yDesc, true)); |
+ if (!yuvTextures[GrYUVProvider::kY_Index] || |
+ !yuvTextures[GrYUVProvider::kY_Index]->writePixels(0, 0, yDesc.fWidth, yDesc.fHeight, |
+ yDesc.fConfig, planes[GrYUVProvider::kY_Index], yuvInfo.fSizeInfo.fYWidthBytes)) { |
+ return nullptr; |
+ } |
+ |
+ uDesc.fWidth = yuvInfo.fSizeInfo.fUSize.fWidth; |
+ uDesc.fHeight = yuvInfo.fSizeInfo.fUSize.fHeight; |
+ bool needsExactTexture = (uDesc.fWidth != yDesc.fWidth) || |
+ (uDesc.fHeight != yDesc.fHeight); |
+ if (needsExactTexture) { |
+ yuvTextures[GrYUVProvider::kU_Index].reset( |
+ ctx->textureProvider()->createTexture(uDesc, true)); |
+ } else { |
+ yuvTextures[GrYUVProvider::kU_Index].reset( |
+ ctx->textureProvider()->createApproxTexture(uDesc)); |
+ } |
+ if (!yuvTextures[GrYUVProvider::kU_Index] || |
+ !yuvTextures[GrYUVProvider::kU_Index]->writePixels(0, 0, uDesc.fWidth, uDesc.fHeight, |
+ uDesc.fConfig, planes[GrYUVProvider::kU_Index], yuvInfo.fSizeInfo.fUWidthBytes)) { |
+ return nullptr; |
+ } |
+ |
+ vDesc.fWidth = yuvInfo.fSizeInfo.fVSize.fWidth; |
+ vDesc.fHeight = yuvInfo.fSizeInfo.fVSize.fHeight; |
+ needsExactTexture = (vDesc.fWidth != vDesc.fWidth) || |
+ (vDesc.fHeight != vDesc.fHeight); |
+ if (needsExactTexture) { |
+ yuvTextures[GrYUVProvider::kV_Index].reset( |
+ ctx->textureProvider()->createTexture(vDesc, true)); |
+ } else { |
+ yuvTextures[GrYUVProvider::kV_Index].reset( |
+ ctx->textureProvider()->createApproxTexture(vDesc)); |
+ } |
+ if (!yuvTextures[GrYUVProvider::kV_Index] || |
+ !yuvTextures[GrYUVProvider::kV_Index]->writePixels(0, 0, vDesc.fWidth, vDesc.fHeight, |
+ vDesc.fConfig, planes[GrYUVProvider::kV_Index], yuvInfo.fSizeInfo.fVWidthBytes)) { |
+ return nullptr; |
} |
GrSurfaceDesc rtDesc = desc; |
@@ -125,11 +153,12 @@ GrTexture* GrYUVProvider::refAsTexture(GrContext* ctx, const GrSurfaceDesc& desc |
GrYUVEffect::CreateYUVToRGB(yuvTextures[0], |
yuvTextures[1], |
yuvTextures[2], |
- yuvInfo.fSize, |
+ &yuvInfo.fSizeInfo.fYSize, |
msarett
2016/02/18 23:00:02
Nobody look here. This line isn't hacky at all. :
|
yuvInfo.fColorSpace)); |
paint.addColorFragmentProcessor(yuvToRgbProcessor); |
paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
- const SkRect r = SkRect::MakeIWH(yuvInfo.fSize[0].fWidth, yuvInfo.fSize[0].fHeight); |
+ const SkRect r = SkRect::MakeIWH(yuvInfo.fSizeInfo.fYSize.fWidth, |
+ yuvInfo.fSizeInfo.fYSize.fHeight); |
SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(renderTarget)); |
if (!drawContext) { |