Index: src/gpu/GrYUVProvider.cpp |
diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp |
index 708cbecb11ff9100bb4c4f36880c26e72a341890..f88964184903135f4354a43035a1ec6237502147 100644 |
--- a/src/gpu/GrYUVProvider.cpp |
+++ b/src/gpu/GrYUVProvider.cpp |
@@ -40,20 +40,21 @@ |
if (fCachedData.get()) { |
planes[0] = (void*)fCachedData->data(); |
- planes[1] = (uint8_t*)planes[0] + (yuvInfo->fSizeInfo.fWidthBytes[SkYUVSizeInfo::kY] * |
- yuvInfo->fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); |
- planes[2] = (uint8_t*)planes[1] + (yuvInfo->fSizeInfo.fWidthBytes[SkYUVSizeInfo::kU] * |
- yuvInfo->fSizeInfo.fSizes[SkYUVSizeInfo::kU].fHeight); |
+ planes[1] = (uint8_t*)planes[0] + yuvInfo->fSizeInMemory[0]; |
+ planes[2] = (uint8_t*)planes[1] + yuvInfo->fSizeInMemory[1]; |
} else { |
- // Fetch yuv plane sizes for memory allocation. |
- if (!provider->onQueryYUV8(&yuvInfo->fSizeInfo, &yuvInfo->fColorSpace)) { |
+ // 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)) { |
return false; |
} |
// Allocate the memory for YUV |
size_t totalSize(0); |
- for (int i = 0; i < 3; i++) { |
- totalSize += yuvInfo->fSizeInfo.fWidthBytes[i] * yuvInfo->fSizeInfo.fSizes[i].fHeight; |
+ 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]; |
} |
if (useCache) { |
fCachedData.reset(SkResourceCache::NewCachedData(totalSize)); |
@@ -62,13 +63,12 @@ |
fStorage.reset(totalSize); |
planes[0] = fStorage.get(); |
} |
- planes[1] = (uint8_t*)planes[0] + (yuvInfo->fSizeInfo.fWidthBytes[SkYUVSizeInfo::kY] * |
- yuvInfo->fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); |
- planes[2] = (uint8_t*)planes[1] + (yuvInfo->fSizeInfo.fWidthBytes[SkYUVSizeInfo::kU] * |
- yuvInfo->fSizeInfo.fSizes[SkYUVSizeInfo::kU].fHeight); |
+ planes[1] = (uint8_t*)planes[0] + yuvInfo->fSizeInMemory[0]; |
+ planes[2] = (uint8_t*)planes[1] + yuvInfo->fSizeInMemory[1]; |
- // Get the YUV planes. |
- if (!provider->onGetYUV8Planes(yuvInfo->fSizeInfo, planes)) { |
+ // Get the YUV planes and update plane sizes to actual image size |
+ if (!provider->onGetYUVPlanes(yuvInfo->fSize, planes, yuvInfo->fRowBytes, |
+ &yuvInfo->fColorSpace)) { |
return false; |
} |
@@ -91,21 +91,20 @@ |
GrSurfaceDesc yuvDesc; |
yuvDesc.fConfig = kAlpha_8_GrPixelConfig; |
SkAutoTUnref<GrTexture> yuvTextures[3]; |
- for (int i = 0; i < 3; i++) { |
- yuvDesc.fWidth = yuvInfo.fSizeInfo.fSizes[i].fWidth; |
- yuvDesc.fHeight = yuvInfo.fSizeInfo.fSizes[i].fHeight; |
+ for (int i = 0; i < 3; ++i) { |
+ yuvDesc.fWidth = yuvInfo.fSize[i].fWidth; |
+ yuvDesc.fHeight = yuvInfo.fSize[i].fHeight; |
// TODO: why do we need this check? |
- bool needsExactTexture = |
- (yuvDesc.fWidth != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth) || |
- (yuvDesc.fHeight != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); |
+ bool needsExactTexture = (yuvDesc.fWidth != yuvInfo.fSize[0].fWidth) || |
+ (yuvDesc.fHeight != yuvInfo.fSize[0].fHeight); |
if (needsExactTexture) { |
yuvTextures[i].reset(ctx->textureProvider()->createTexture(yuvDesc, SkBudgeted::kYes)); |
} 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.fSizeInfo.fWidthBytes[i])) { |
+ !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, |
+ yuvDesc.fConfig, planes[i], yuvInfo.fRowBytes[i])) { |
return nullptr; |
} |
} |
@@ -127,12 +126,11 @@ |
GrYUVEffect::CreateYUVToRGB(yuvTextures[0], |
yuvTextures[1], |
yuvTextures[2], |
- yuvInfo.fSizeInfo.fSizes, |
+ yuvInfo.fSize, |
yuvInfo.fColorSpace)); |
paint.addColorFragmentProcessor(yuvToRgbProcessor); |
paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
- const SkRect r = SkRect::MakeIWH(yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth, |
- yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); |
+ const SkRect r = SkRect::MakeIWH(yuvInfo.fSize[0].fWidth, yuvInfo.fSize[0].fHeight); |
SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(renderTarget)); |
if (!drawContext) { |