| Index: src/image/SkImage_Gpu.cpp
|
| diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
|
| index 06ecda10e2e3303989c91bf312a13a33ff5ec515..4c3e1300c5c09ffc5e070691b12106dce6c04d3e 100644
|
| --- a/src/image/SkImage_Gpu.cpp
|
| +++ b/src/image/SkImage_Gpu.cpp
|
| @@ -6,10 +6,13 @@
|
| */
|
|
|
| #include "SkImage_Gpu.h"
|
| -#include "SkCanvas.h"
|
| #include "GrContext.h"
|
| +#include "GrDrawContext.h"
|
| +#include "effects/GrYUVtoRGBEffect.h"
|
| +#include "SkCanvas.h"
|
| #include "SkGpuDevice.h"
|
|
|
| +
|
| SkImage_Gpu::SkImage_Gpu(int w, int h, SkAlphaType at, GrTexture* tex,
|
| int sampleCountForNewSurfaces, SkSurface::Budgeted budgeted)
|
| : INHERITED(w, h, NULL)
|
| @@ -159,3 +162,75 @@ SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc&
|
| return SkNEW_ARGS(SkImage_Gpu, (dstDesc.fWidth, dstDesc.fHeight, at, dst, sampleCount,
|
| budgeted));
|
| }
|
| +
|
| +SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorSpace,
|
| + const GrBackendObject yuvTextureHandles[3],
|
| + const SkISize yuvSizes[3],
|
| + GrSurfaceOrigin origin) {
|
| + const SkSurface::Budgeted budgeted = SkSurface::kYes_Budgeted;
|
| +
|
| + if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 ||
|
| + yuvSizes[1].fWidth <= 0 || yuvSizes[1].fHeight <= 0 ||
|
| + yuvSizes[2].fWidth <= 0 || yuvSizes[2].fHeight <= 0) {
|
| + return NULL;
|
| + }
|
| + static const GrPixelConfig kConfig = kAlpha_8_GrPixelConfig;
|
| + GrBackendTextureDesc yDesc;
|
| + yDesc.fConfig = kConfig;
|
| + yDesc.fOrigin = origin;
|
| + yDesc.fSampleCnt = 0;
|
| + yDesc.fTextureHandle = yuvTextureHandles[0];
|
| + yDesc.fWidth = yuvSizes[0].fWidth;
|
| + yDesc.fHeight = yuvSizes[0].fHeight;
|
| +
|
| + GrBackendTextureDesc uDesc;
|
| + uDesc.fConfig = kConfig;
|
| + uDesc.fOrigin = origin;
|
| + uDesc.fSampleCnt = 0;
|
| + uDesc.fTextureHandle = yuvTextureHandles[1];
|
| + uDesc.fWidth = yuvSizes[1].fWidth;
|
| + uDesc.fHeight = yuvSizes[1].fHeight;
|
| +
|
| + GrBackendTextureDesc vDesc;
|
| + vDesc.fConfig = kConfig;
|
| + vDesc.fOrigin = origin;
|
| + vDesc.fSampleCnt = 0;
|
| + vDesc.fTextureHandle = yuvTextureHandles[2];
|
| + vDesc.fWidth = yuvSizes[2].fWidth;
|
| + vDesc.fHeight = yuvSizes[2].fHeight;
|
| +
|
| + SkAutoTUnref<GrTexture> yTex(ctx->textureProvider()->wrapBackendTexture(yDesc));
|
| + SkAutoTUnref<GrTexture> uTex(ctx->textureProvider()->wrapBackendTexture(uDesc));
|
| + SkAutoTUnref<GrTexture> vTex(ctx->textureProvider()->wrapBackendTexture(vDesc));
|
| + if (!yTex || !uTex || !vTex) {
|
| + return NULL;
|
| + }
|
| +
|
| + GrSurfaceDesc dstDesc;
|
| + // Needs to be a render target in order to draw to it for the yuv->rgb conversion.
|
| + dstDesc.fFlags = kRenderTarget_GrSurfaceFlag;
|
| + dstDesc.fOrigin = origin;
|
| + dstDesc.fWidth = yuvSizes[0].fWidth;
|
| + dstDesc.fHeight = yuvSizes[0].fHeight;
|
| + dstDesc.fConfig = kRGBA_8888_GrPixelConfig;
|
| + dstDesc.fSampleCnt = 0;
|
| +
|
| + SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->refScratchTexture(
|
| + dstDesc, GrTextureProvider::kExact_ScratchTexMatch));
|
| + if (!dst) {
|
| + return NULL;
|
| + }
|
| +
|
| + GrPaint paint;
|
| + paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
|
| + paint.addColorProcessor(GrYUVtoRGBEffect::Create(yTex, uTex, vTex, yuvSizes,
|
| + colorSpace))->unref();
|
| +
|
| + const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth),
|
| + SkIntToScalar(dstDesc.fHeight));
|
| + ctx->drawContext()->drawRect(dst->asRenderTarget(), GrClip::WideOpen(), paint, SkMatrix::I(),
|
| + rect);
|
| + ctx->flushSurfaceWrites(dst);
|
| + return SkNEW_ARGS(SkImage_Gpu, (dstDesc.fWidth, dstDesc.fHeight, kOpaque_SkAlphaType, dst, 0,
|
| + budgeted));
|
| +}
|
|
|