| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkAutoPixmapStorage.h" | 8 #include "SkAutoPixmapStorage.h" |
| 9 #include "GrCaps.h" | 9 #include "GrCaps.h" |
| 10 #include "GrContext.h" | 10 #include "GrContext.h" |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 SkAutoTUnref<GrTexture> yTex(ctx->textureProvider()->wrapBackendTexture( | 242 SkAutoTUnref<GrTexture> yTex(ctx->textureProvider()->wrapBackendTexture( |
| 243 yDesc, kBorrow_GrWrapOwnership)); | 243 yDesc, kBorrow_GrWrapOwnership)); |
| 244 SkAutoTUnref<GrTexture> uTex(ctx->textureProvider()->wrapBackendTexture( | 244 SkAutoTUnref<GrTexture> uTex(ctx->textureProvider()->wrapBackendTexture( |
| 245 uDesc, kBorrow_GrWrapOwnership)); | 245 uDesc, kBorrow_GrWrapOwnership)); |
| 246 SkAutoTUnref<GrTexture> vTex(ctx->textureProvider()->wrapBackendTexture( | 246 SkAutoTUnref<GrTexture> vTex(ctx->textureProvider()->wrapBackendTexture( |
| 247 vDesc, kBorrow_GrWrapOwnership)); | 247 vDesc, kBorrow_GrWrapOwnership)); |
| 248 if (!yTex || !uTex || !vTex) { | 248 if (!yTex || !uTex || !vTex) { |
| 249 return nullptr; | 249 return nullptr; |
| 250 } | 250 } |
| 251 | 251 |
| 252 const int width = yuvSizes[0].fWidth; | 252 GrSurfaceDesc dstDesc; |
| 253 const int height = yuvSizes[0].fHeight; | 253 // Needs to be a render target in order to draw to it for the yuv->rgb conve
rsion. |
| 254 dstDesc.fFlags = kRenderTarget_GrSurfaceFlag; |
| 255 dstDesc.fOrigin = origin; |
| 256 dstDesc.fWidth = yuvSizes[0].fWidth; |
| 257 dstDesc.fHeight = yuvSizes[0].fHeight; |
| 258 dstDesc.fConfig = kRGBA_8888_GrPixelConfig; |
| 259 dstDesc.fSampleCnt = 0; |
| 254 | 260 |
| 255 // Needs to be a render target in order to draw to it for the yuv->rgb conve
rsion. | 261 SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->createTexture(dstDesc, S
kBudgeted::kYes)); |
| 256 sk_sp<GrDrawContext> drawContext(ctx->newDrawContext(GrContext::kTight_Backi
ngFit, | 262 if (!dst) { |
| 257 width, height, | |
| 258 kRGBA_8888_GrPixelConfi
g, | |
| 259 0, | |
| 260 origin)); | |
| 261 if (!drawContext) { | |
| 262 return nullptr; | 263 return nullptr; |
| 263 } | 264 } |
| 264 | 265 |
| 265 GrPaint paint; | 266 GrPaint paint; |
| 266 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 267 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
| 267 paint.addColorFragmentProcessor(GrYUVEffect::CreateYUVToRGB(yTex, uTex, vTex
, yuvSizes, | 268 paint.addColorFragmentProcessor(GrYUVEffect::CreateYUVToRGB(yTex, uTex, vTex
, yuvSizes, |
| 268 colorSpace))->un
ref(); | 269 colorSpace))->un
ref(); |
| 269 | 270 |
| 270 const SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heigh
t)); | 271 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), |
| 272 SkIntToScalar(dstDesc.fHeight)); |
| 273 sk_sp<GrDrawContext> drawContext(ctx->drawContext(sk_ref_sp(dst->asRenderTar
get()))); |
| 274 if (!drawContext) { |
| 275 return nullptr; |
| 276 } |
| 271 | 277 |
| 272 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect); | 278 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect); |
| 273 ctx->flushSurfaceWrites(drawContext->accessRenderTarget()); | 279 ctx->flushSurfaceWrites(dst); |
| 274 return sk_make_sp<SkImage_Gpu>(width, height, kNeedNewImageUniqueID, | 280 return sk_make_sp<SkImage_Gpu>(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImag
eUniqueID, |
| 275 kOpaque_SkAlphaType, | 281 kOpaque_SkAlphaType, dst, budgeted); |
| 276 drawContext->asTexture().get(), budgeted); | |
| 277 } | 282 } |
| 278 | 283 |
| 279 static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType
at, uint32_t id) { | 284 static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType
at, uint32_t id) { |
| 280 SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams::
ClampNoFilter())); | 285 SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams::
ClampNoFilter())); |
| 281 if (!texture) { | 286 if (!texture) { |
| 282 return nullptr; | 287 return nullptr; |
| 283 } | 288 } |
| 284 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at,
texture, | 289 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at,
texture, |
| 285 SkBudgeted::kNo); | 290 SkBudgeted::kNo); |
| 286 } | 291 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 return nullptr; | 454 return nullptr; |
| 450 } | 455 } |
| 451 | 456 |
| 452 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 457 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
| 453 const SkIPoint dstP = SkIPoint::Make(0, 0); | 458 const SkIPoint dstP = SkIPoint::Make(0, 0); |
| 454 ctx->copySurface(dst, src, srcR, dstP); | 459 ctx->copySurface(dst, src, srcR, dstP); |
| 455 ctx->flushSurfaceWrites(dst); | 460 ctx->flushSurfaceWrites(dst); |
| 456 return dst; | 461 return dst; |
| 457 } | 462 } |
| 458 | 463 |
| OLD | NEW |