aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/image
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2015-05-29 11:37:25 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-05-29 11:37:25 -0700
commit993a4216a6014b9de8f4d8120360c94550dc6761 (patch)
tree75e4863a6fa83d35c519a3103a9d2c94520dbd1e /src/image
parent4061b1262e931be19e1176cbd0e93b8c268eb131 (diff)
SkImage::NewFromYUVTexturesCopy
Diffstat (limited to 'src/image')
-rw-r--r--src/image/SkImage_Gpu.cpp77
1 files changed, 76 insertions, 1 deletions
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index 06ecda10e2..4c3e1300c5 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));
+}