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 GrSurfaceDesc dstDesc; | 252 const int width = yuvSizes[0].fWidth; |
| 253 const int height = yuvSizes[0].fHeight; |
| 254 |
253 // Needs to be a render target in order to draw to it for the yuv->rgb conve
rsion. | 255 // Needs to be a render target in order to draw to it for the yuv->rgb conve
rsion. |
254 dstDesc.fFlags = kRenderTarget_GrSurfaceFlag; | 256 sk_sp<GrDrawContext> drawContext(ctx->newDrawContext(GrContext::kTight_Backi
ngFit, |
255 dstDesc.fOrigin = origin; | 257 width, height, |
256 dstDesc.fWidth = yuvSizes[0].fWidth; | 258 kRGBA_8888_GrPixelConfi
g, |
257 dstDesc.fHeight = yuvSizes[0].fHeight; | 259 0, |
258 dstDesc.fConfig = kRGBA_8888_GrPixelConfig; | 260 origin)); |
259 dstDesc.fSampleCnt = 0; | 261 if (!drawContext) { |
260 | |
261 SkAutoTUnref<GrTexture> dst(ctx->textureProvider()->createTexture(dstDesc, S
kBudgeted::kYes)); | |
262 if (!dst) { | |
263 return nullptr; | 262 return nullptr; |
264 } | 263 } |
265 | 264 |
266 GrPaint paint; | 265 GrPaint paint; |
267 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); | 266 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); |
268 paint.addColorFragmentProcessor(GrYUVEffect::CreateYUVToRGB(yTex, uTex, vTex
, yuvSizes, | 267 paint.addColorFragmentProcessor(GrYUVEffect::CreateYUVToRGB(yTex, uTex, vTex
, yuvSizes, |
269 colorSpace))->un
ref(); | 268 colorSpace))->un
ref(); |
270 | 269 |
271 const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth), | 270 const SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heigh
t)); |
272 SkIntToScalar(dstDesc.fHeight)); | |
273 sk_sp<GrDrawContext> drawContext(ctx->drawContext(sk_ref_sp(dst->asRenderTar
get()))); | |
274 if (!drawContext) { | |
275 return nullptr; | |
276 } | |
277 | 271 |
278 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect); | 272 drawContext->drawRect(GrClip::WideOpen(), paint, SkMatrix::I(), rect); |
279 ctx->flushSurfaceWrites(dst); | 273 ctx->flushSurfaceWrites(drawContext->accessRenderTarget()); |
280 return sk_make_sp<SkImage_Gpu>(dstDesc.fWidth, dstDesc.fHeight, kNeedNewImag
eUniqueID, | 274 return sk_make_sp<SkImage_Gpu>(width, height, kNeedNewImageUniqueID, |
281 kOpaque_SkAlphaType, dst, budgeted); | 275 kOpaque_SkAlphaType, |
| 276 drawContext->asTexture().get(), budgeted); |
282 } | 277 } |
283 | 278 |
284 static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType
at, uint32_t id) { | 279 static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType
at, uint32_t id) { |
285 SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams::
ClampNoFilter())); | 280 SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams::
ClampNoFilter())); |
286 if (!texture) { | 281 if (!texture) { |
287 return nullptr; | 282 return nullptr; |
288 } | 283 } |
289 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at,
texture, | 284 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at,
texture, |
290 SkBudgeted::kNo); | 285 SkBudgeted::kNo); |
291 } | 286 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 return nullptr; | 449 return nullptr; |
455 } | 450 } |
456 | 451 |
457 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); | 452 const SkIRect srcR = SkIRect::MakeWH(desc.fWidth, desc.fHeight); |
458 const SkIPoint dstP = SkIPoint::Make(0, 0); | 453 const SkIPoint dstP = SkIPoint::Make(0, 0); |
459 ctx->copySurface(dst, src, srcR, dstP); | 454 ctx->copySurface(dst, src, srcR, dstP); |
460 ctx->flushSurfaceWrites(dst); | 455 ctx->flushSurfaceWrites(dst); |
461 return dst; | 456 return dst; |
462 } | 457 } |
463 | 458 |
OLD | NEW |