diff options
author | 2016-03-10 05:44:43 -0800 | |
---|---|---|
committer | 2016-03-10 05:44:43 -0800 | |
commit | 4984c3c95f18eda44492a2126c9958e447f2cca8 (patch) | |
tree | add5bdca2495968a8acc1affd10e5cfe225ff4d0 /src/gpu/GrYUVProvider.cpp | |
parent | d6215cf4a5f416cf0b64a4fbba95c519f03fe467 (diff) |
Update Skia's YUV API
We should match the recently designed API in SkCodec.
https://codereview.chromium.org/1549473003/
This requires changes in Chromium as well.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1716523002
Committed: https://skia.googlesource.com/skia/+/095d31c8a0eeb5d491febf064bc3c8a44e22b94f
Review URL: https://codereview.chromium.org/1716523002
Diffstat (limited to 'src/gpu/GrYUVProvider.cpp')
-rw-r--r-- | src/gpu/GrYUVProvider.cpp | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/gpu/GrYUVProvider.cpp b/src/gpu/GrYUVProvider.cpp index f889641849..708cbecb11 100644 --- a/src/gpu/GrYUVProvider.cpp +++ b/src/gpu/GrYUVProvider.cpp @@ -40,21 +40,20 @@ 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.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); } 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]; + for (int i = 0; i < 3; i++) { + totalSize += yuvInfo->fSizeInfo.fWidthBytes[i] * yuvInfo->fSizeInfo.fSizes[i].fHeight; } if (useCache) { fCachedData.reset(SkResourceCache::NewCachedData(totalSize)); @@ -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.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); - // 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; } @@ -91,20 +91,21 @@ GrTexture* GrYUVProvider::refAsTexture(GrContext* ctx, const GrSurfaceDesc& desc GrSurfaceDesc yuvDesc; yuvDesc.fConfig = kAlpha_8_GrPixelConfig; SkAutoTUnref<GrTexture> yuvTextures[3]; - for (int i = 0; i < 3; ++i) { - yuvDesc.fWidth = yuvInfo.fSize[i].fWidth; - yuvDesc.fHeight = yuvInfo.fSize[i].fHeight; + for (int i = 0; i < 3; i++) { + yuvDesc.fWidth = yuvInfo.fSizeInfo.fSizes[i].fWidth; + yuvDesc.fHeight = yuvInfo.fSizeInfo.fSizes[i].fHeight; // TODO: why do we need this check? - bool needsExactTexture = (yuvDesc.fWidth != yuvInfo.fSize[0].fWidth) || - (yuvDesc.fHeight != yuvInfo.fSize[0].fHeight); + bool needsExactTexture = + (yuvDesc.fWidth != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fWidth) || + (yuvDesc.fHeight != yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].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.fRowBytes[i])) { + !yuvTextures[i]->writePixels(0, 0, yuvDesc.fWidth, yuvDesc.fHeight, yuvDesc.fConfig, + planes[i], yuvInfo.fSizeInfo.fWidthBytes[i])) { return nullptr; } } @@ -126,11 +127,12 @@ GrTexture* GrYUVProvider::refAsTexture(GrContext* ctx, const GrSurfaceDesc& desc GrYUVEffect::CreateYUVToRGB(yuvTextures[0], yuvTextures[1], yuvTextures[2], - yuvInfo.fSize, + yuvInfo.fSizeInfo.fSizes, 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.fSizes[SkYUVSizeInfo::kY].fWidth, + yuvInfo.fSizeInfo.fSizes[SkYUVSizeInfo::kY].fHeight); SkAutoTUnref<GrDrawContext> drawContext(ctx->drawContext(renderTarget)); if (!drawContext) { |