Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: src/image/SkImage_Gpu.cpp

Issue 2016593002: Add NV12 texture conversion support. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/effects/GrYUVEffect.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 198
199 SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, SkBudgeted::kYes)); 199 SkAutoTUnref<GrTexture> dst(GrDeepCopyTexture(src, SkBudgeted::kYes));
200 if (!dst) { 200 if (!dst) {
201 return nullptr; 201 return nullptr;
202 } 202 }
203 203
204 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqu eID, at, dst, 204 return sk_make_sp<SkImage_Gpu>(desc.fWidth, desc.fHeight, kNeedNewImageUniqu eID, at, dst,
205 SkBudgeted::kYes); 205 SkBudgeted::kYes);
206 } 206 }
207 207
208 sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorSpace, 208 static sk_sp<SkImage> make_from_yuv_textures_copy(GrContext* ctx, SkYUVColorSpac e colorSpace,
209 const GrBackendObject yuvTexture Handles[3], 209 bool nv12,
210 const SkISize yuvSizes[3], 210 const GrBackendObject yuvTextu reHandles[],
211 GrSurfaceOrigin origin) { 211 const SkISize yuvSizes[],
212 GrSurfaceOrigin origin) {
212 const SkBudgeted budgeted = SkBudgeted::kYes; 213 const SkBudgeted budgeted = SkBudgeted::kYes;
213 214
214 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || 215 if (yuvSizes[0].fWidth <= 0 || yuvSizes[0].fHeight <= 0 || yuvSizes[1].fWidt h <= 0 ||
215 yuvSizes[1].fWidth <= 0 || yuvSizes[1].fHeight <= 0 || 216 yuvSizes[1].fHeight <= 0) {
216 yuvSizes[2].fWidth <= 0 || yuvSizes[2].fHeight <= 0) {
217 return nullptr; 217 return nullptr;
218 } 218 }
219 static const GrPixelConfig kConfig = kAlpha_8_GrPixelConfig; 219 if (!nv12 && (yuvSizes[2].fWidth <= 0 || yuvSizes[2].fHeight <= 0)) {
220 return nullptr;
221 }
222
223 const GrPixelConfig kConfig = nv12 ? kRGBA_8888_GrPixelConfig : kAlpha_8_GrP ixelConfig;
224
220 GrBackendTextureDesc yDesc; 225 GrBackendTextureDesc yDesc;
221 yDesc.fConfig = kConfig; 226 yDesc.fConfig = kConfig;
222 yDesc.fOrigin = origin; 227 yDesc.fOrigin = origin;
223 yDesc.fSampleCnt = 0; 228 yDesc.fSampleCnt = 0;
224 yDesc.fTextureHandle = yuvTextureHandles[0]; 229 yDesc.fTextureHandle = yuvTextureHandles[0];
225 yDesc.fWidth = yuvSizes[0].fWidth; 230 yDesc.fWidth = yuvSizes[0].fWidth;
226 yDesc.fHeight = yuvSizes[0].fHeight; 231 yDesc.fHeight = yuvSizes[0].fHeight;
227 232
228 GrBackendTextureDesc uDesc; 233 GrBackendTextureDesc uDesc;
229 uDesc.fConfig = kConfig; 234 uDesc.fConfig = kConfig;
230 uDesc.fOrigin = origin; 235 uDesc.fOrigin = origin;
231 uDesc.fSampleCnt = 0; 236 uDesc.fSampleCnt = 0;
232 uDesc.fTextureHandle = yuvTextureHandles[1]; 237 uDesc.fTextureHandle = yuvTextureHandles[1];
233 uDesc.fWidth = yuvSizes[1].fWidth; 238 uDesc.fWidth = yuvSizes[1].fWidth;
234 uDesc.fHeight = yuvSizes[1].fHeight; 239 uDesc.fHeight = yuvSizes[1].fHeight;
235 240
236 GrBackendTextureDesc vDesc; 241 sk_sp<GrTexture> yTex(
237 vDesc.fConfig = kConfig; 242 ctx->textureProvider()->wrapBackendTexture(yDesc, kBorrow_GrWrapOwnershi p));
238 vDesc.fOrigin = origin; 243 sk_sp<GrTexture> uTex(
239 vDesc.fSampleCnt = 0; 244 ctx->textureProvider()->wrapBackendTexture(uDesc, kBorrow_GrWrapOwnershi p));
240 vDesc.fTextureHandle = yuvTextureHandles[2]; 245 sk_sp<GrTexture> vTex;
241 vDesc.fWidth = yuvSizes[2].fWidth; 246 if (nv12) {
242 vDesc.fHeight = yuvSizes[2].fHeight; 247 vTex = uTex;
248 } else {
249 GrBackendTextureDesc vDesc;
250 vDesc.fConfig = kConfig;
251 vDesc.fOrigin = origin;
252 vDesc.fSampleCnt = 0;
253 vDesc.fTextureHandle = yuvTextureHandles[2];
254 vDesc.fWidth = yuvSizes[2].fWidth;
255 vDesc.fHeight = yuvSizes[2].fHeight;
243 256
244 SkAutoTUnref<GrTexture> yTex(ctx->textureProvider()->wrapBackendTexture( 257 vTex = sk_sp<GrTexture>(
245 yDesc, kBorrow_GrWrapOwnership)); 258 ctx->textureProvider()->wrapBackendTexture(vDesc, kBorrow_GrWrapOwne rship));
246 SkAutoTUnref<GrTexture> uTex(ctx->textureProvider()->wrapBackendTexture( 259 }
247 uDesc, kBorrow_GrWrapOwnership));
248 SkAutoTUnref<GrTexture> vTex(ctx->textureProvider()->wrapBackendTexture(
249 vDesc, kBorrow_GrWrapOwnership));
250 if (!yTex || !uTex || !vTex) { 260 if (!yTex || !uTex || !vTex) {
251 return nullptr; 261 return nullptr;
252 } 262 }
253 263
254 const int width = yuvSizes[0].fWidth; 264 const int width = yuvSizes[0].fWidth;
255 const int height = yuvSizes[0].fHeight; 265 const int height = yuvSizes[0].fHeight;
256 266
257 // Needs to be a render target in order to draw to it for the yuv->rgb conve rsion. 267 // Needs to be a render target in order to draw to it for the yuv->rgb conve rsion.
258 sk_sp<GrDrawContext> drawContext(ctx->newDrawContext(SkBackingFit::kExact, 268 sk_sp<GrDrawContext> drawContext(ctx->newDrawContext(SkBackingFit::kExact,
259 width, height, 269 width, height,
260 kRGBA_8888_GrPixelConfi g, 270 kRGBA_8888_GrPixelConfi g,
261 0, 271 0,
262 origin)); 272 origin));
263 if (!drawContext) { 273 if (!drawContext) {
264 return nullptr; 274 return nullptr;
265 } 275 }
266 276
267 GrPaint paint; 277 GrPaint paint;
268 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); 278 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
269 paint.addColorFragmentProcessor(GrYUVEffect::MakeYUVToRGB(yTex, uTex, vTex, yuvSizes, 279 paint.addColorFragmentProcessor(
270 colorSpace)); 280 GrYUVEffect::MakeYUVToRGB(yTex.get(), uTex.get(), vTex.get(), yuvSizes, colorSpace, nv12));
271 281
272 const SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heigh t)); 282 const SkRect rect = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(heigh t));
273 283
274 drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect); 284 drawContext->drawRect(GrNoClip(), paint, SkMatrix::I(), rect);
275 ctx->flushSurfaceWrites(drawContext->accessRenderTarget()); 285 ctx->flushSurfaceWrites(drawContext->accessRenderTarget());
276 return sk_make_sp<SkImage_Gpu>(width, height, kNeedNewImageUniqueID, 286 return sk_make_sp<SkImage_Gpu>(width, height, kNeedNewImageUniqueID,
277 kOpaque_SkAlphaType, 287 kOpaque_SkAlphaType,
278 drawContext->asTexture().get(), budgeted); 288 drawContext->asTexture().get(), budgeted);
279 } 289 }
280 290
291 sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace,
292 const GrBackendObject yuvTexture Handles[3],
293 const SkISize yuvSizes[3], GrSur faceOrigin origin) {
294 return make_from_yuv_textures_copy(ctx, colorSpace, false, yuvTextureHandles , yuvSizes, origin);
295 }
296
297 sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace colorSpace,
298 const GrBackendObject yuvTextur eHandles[2],
299 const SkISize yuvSizes[2],
300 GrSurfaceOrigin origin) {
301 return make_from_yuv_textures_copy(ctx, colorSpace, true, yuvTextureHandles, yuvSizes, origin);
302 }
303
281 static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) { 304 static sk_sp<SkImage> create_image_from_maker(GrTextureMaker* maker, SkAlphaType at, uint32_t id) {
282 SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams:: ClampNoFilter(), 305 SkAutoTUnref<GrTexture> texture(maker->refTextureForParams(GrTextureParams:: ClampNoFilter(),
283 SkSourceGammaTrea tment::kRespect)); 306 SkSourceGammaTrea tment::kRespect));
284 if (!texture) { 307 if (!texture) {
285 return nullptr; 308 return nullptr;
286 } 309 }
287 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at, texture, 310 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), id, at, texture,
288 SkBudgeted::kNo); 311 SkBudgeted::kNo);
289 } 312 }
290 313
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 if (!ctx) { 500 if (!ctx) {
478 return nullptr; 501 return nullptr;
479 } 502 }
480 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m ipLevelCount)); 503 SkAutoTUnref<GrTexture> texture(GrUploadMipMapToTexture(ctx, info, texels, m ipLevelCount));
481 if (!texture) { 504 if (!texture) {
482 return nullptr; 505 return nullptr;
483 } 506 }
484 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID, 507 return sk_make_sp<SkImage_Gpu>(texture->width(), texture->height(), kNeedNew ImageUniqueID,
485 info.alphaType(), texture, budgeted); 508 info.alphaType(), texture, budgeted);
486 } 509 }
OLDNEW
« no previous file with comments | « src/gpu/effects/GrYUVEffect.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698