Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2010 Google Inc. | 2 * Copyright 2010 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 "SkGr.h" | 8 #include "SkGr.h" |
| 9 | 9 |
| 10 #include "GrDrawTargetCaps.h" | 10 #include "GrDrawTargetCaps.h" |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 desc.fConfig = kETC1_GrPixelConfig; | 308 desc.fConfig = kETC1_GrPixelConfig; |
| 309 } else { | 309 } else { |
| 310 return NULL; | 310 return NULL; |
| 311 } | 311 } |
| 312 | 312 |
| 313 return create_texture_for_bmp(ctx, optionalKey, desc, bytes, 0); | 313 return create_texture_for_bmp(ctx, optionalKey, desc, bytes, 0); |
| 314 } | 314 } |
| 315 #endif // SK_IGNORE_ETC1_SUPPORT | 315 #endif // SK_IGNORE_ETC1_SUPPORT |
| 316 | 316 |
| 317 static GrTexture* load_yuv_texture(GrContext* ctx, const GrContentKey& optionalK ey, | 317 static GrTexture* load_yuv_texture(GrContext* ctx, const GrContentKey& optionalK ey, |
| 318 const SkBitmap& bm, const GrSurfaceDesc& desc ) { | 318 const SkBitmap& bm, const GrSurfaceDesc& desc , bool cache) { |
|
bsalomon
2015/02/04 17:19:33
We don't need the cache bool. optionalKey should a
sugoi1
2015/02/04 17:59:51
Done.
| |
| 319 // Subsets are not supported, the whole pixelRef is loaded when using YUV de coding | 319 // Subsets are not supported, the whole pixelRef is loaded when using YUV de coding |
| 320 SkPixelRef* pixelRef = bm.pixelRef(); | 320 SkPixelRef* pixelRef = bm.pixelRef(); |
| 321 if ((NULL == pixelRef) || | 321 if ((NULL == pixelRef) || |
| 322 (pixelRef->info().width() != bm.info().width()) || | 322 (pixelRef->info().width() != bm.info().width()) || |
| 323 (pixelRef->info().height() != bm.info().height())) { | 323 (pixelRef->info().height() != bm.info().height())) { |
| 324 return NULL; | 324 return NULL; |
| 325 } | 325 } |
| 326 | 326 |
| 327 SkYUVPlanesCache::Info yuvInfo; | 327 SkYUVPlanesCache::Info yuvInfo; |
| 328 SkAutoTUnref<SkCachedData> cachedData( | 328 SkAutoTUnref<SkCachedData> cachedData; |
| 329 SkYUVPlanesCache::FindAndRef(pixelRef->getGenerationID(), &yuvInfo)); | 329 SkAutoMalloc storage; |
| 330 if (cache) { | |
| 331 cachedData.reset(SkYUVPlanesCache::FindAndRef(pixelRef->getGenerationID( ), &yuvInfo)); | |
| 332 } | |
| 330 | 333 |
| 331 void* planes[3]; | 334 void* planes[3]; |
| 332 if (cachedData && cachedData->data()) { | 335 if (cachedData.get()) { |
| 333 planes[0] = (void*)cachedData->data(); | 336 planes[0] = (void*)cachedData->data(); |
| 334 planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0]; | 337 planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0]; |
| 335 planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1]; | 338 planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1]; |
| 336 } else { | 339 } else { |
| 337 // Fetch yuv plane sizes for memory allocation. Here, width and height c an be | 340 // Fetch yuv plane sizes for memory allocation. Here, width and height c an be |
| 338 // rounded up to JPEG block size and be larger than the image's width an d height. | 341 // rounded up to JPEG block size and be larger than the image's width an d height. |
| 339 if (!pixelRef->getYUV8Planes(yuvInfo.fSize, NULL, NULL, NULL)) { | 342 if (!pixelRef->getYUV8Planes(yuvInfo.fSize, NULL, NULL, NULL)) { |
| 340 return NULL; | 343 return NULL; |
| 341 } | 344 } |
| 342 | 345 |
| 343 // Allocate the memory for YUV | 346 // Allocate the memory for YUV |
| 344 size_t totalSize(0); | 347 size_t totalSize(0); |
| 345 for (int i = 0; i < 3; ++i) { | 348 for (int i = 0; i < 3; ++i) { |
| 346 yuvInfo.fRowBytes[i] = yuvInfo.fSize[i].fWidth; | 349 yuvInfo.fRowBytes[i] = yuvInfo.fSize[i].fWidth; |
| 347 yuvInfo.fSizeInMemory[i] = yuvInfo.fRowBytes[i] * yuvInfo.fSize[i].f Height; | 350 yuvInfo.fSizeInMemory[i] = yuvInfo.fRowBytes[i] * yuvInfo.fSize[i].f Height; |
| 348 totalSize += yuvInfo.fSizeInMemory[i]; | 351 totalSize += yuvInfo.fSizeInMemory[i]; |
| 349 } | 352 } |
| 350 cachedData.reset(SkResourceCache::NewCachedData(totalSize)); | 353 if (cache) { |
| 351 planes[0] = cachedData->writable_data(); | 354 cachedData.reset(SkResourceCache::NewCachedData(totalSize)); |
| 355 planes[0] = cachedData->writable_data(); | |
| 356 } else { | |
| 357 storage.reset(totalSize); | |
| 358 planes[0] = storage.get(); | |
| 359 } | |
| 352 planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0]; | 360 planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0]; |
| 353 planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1]; | 361 planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1]; |
| 354 | 362 |
| 355 // Get the YUV planes and update plane sizes to actual image size | 363 // Get the YUV planes and update plane sizes to actual image size |
| 356 if (!pixelRef->getYUV8Planes(yuvInfo.fSize, planes, yuvInfo.fRowBytes, | 364 if (!pixelRef->getYUV8Planes(yuvInfo.fSize, planes, yuvInfo.fRowBytes, |
| 357 &yuvInfo.fColorSpace)) { | 365 &yuvInfo.fColorSpace)) { |
| 358 return NULL; | 366 return NULL; |
| 359 } | 367 } |
| 360 | 368 |
| 361 // Decoding is done, cache the resulting YUV planes | 369 if (cache) { |
| 362 SkYUVPlanesCache::Add(pixelRef->getGenerationID(), cachedData, &yuvInfo) ; | 370 // Decoding is done, cache the resulting YUV planes |
| 371 SkYUVPlanesCache::Add(pixelRef->getGenerationID(), cachedData, &yuvI nfo); | |
| 372 } | |
| 363 } | 373 } |
| 364 | 374 |
| 365 GrSurfaceDesc yuvDesc; | 375 GrSurfaceDesc yuvDesc; |
| 366 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; | 376 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 367 SkAutoTUnref<GrTexture> yuvTextures[3]; | 377 SkAutoTUnref<GrTexture> yuvTextures[3]; |
| 368 for (int i = 0; i < 3; ++i) { | 378 for (int i = 0; i < 3; ++i) { |
| 369 yuvDesc.fWidth = yuvInfo.fSize[i].fWidth; | 379 yuvDesc.fWidth = yuvInfo.fSize[i].fWidth; |
| 370 yuvDesc.fHeight = yuvInfo.fSize[i].fHeight; | 380 yuvDesc.fHeight = yuvInfo.fSize[i].fHeight; |
| 371 yuvTextures[i].reset( | 381 yuvTextures[i].reset( |
| 372 ctx->refScratchTexture(yuvDesc, GrContext::kApprox_ScratchTexMatch)) ; | 382 ctx->refScratchTexture(yuvDesc, GrContext::kApprox_ScratchTexMatch)) ; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 // data is. | 457 // data is. |
| 448 && !(bitmap->readyToDraw())) { | 458 && !(bitmap->readyToDraw())) { |
| 449 GrTexture *texture = load_etc1_texture(ctx, optionalKey, *bitmap, desc); | 459 GrTexture *texture = load_etc1_texture(ctx, optionalKey, *bitmap, desc); |
| 450 if (texture) { | 460 if (texture) { |
| 451 return texture; | 461 return texture; |
| 452 } | 462 } |
| 453 } | 463 } |
| 454 #endif // SK_IGNORE_ETC1_SUPPORT | 464 #endif // SK_IGNORE_ETC1_SUPPORT |
| 455 | 465 |
| 456 else { | 466 else { |
| 457 GrTexture *texture = load_yuv_texture(ctx, optionalKey, *bitmap, desc); | 467 GrTexture *texture = load_yuv_texture(ctx, optionalKey, *bitmap, desc, |
| 468 !origBitmap.isVolatile()); | |
| 458 if (texture) { | 469 if (texture) { |
| 459 return texture; | 470 return texture; |
| 460 } | 471 } |
| 461 } | 472 } |
| 462 SkAutoLockPixels alp(*bitmap); | 473 SkAutoLockPixels alp(*bitmap); |
| 463 if (!bitmap->readyToDraw()) { | 474 if (!bitmap->readyToDraw()) { |
| 464 return NULL; | 475 return NULL; |
| 465 } | 476 } |
| 466 | 477 |
| 467 return create_texture_for_bmp(ctx, optionalKey, desc, bitmap->getPixels(), b itmap->rowBytes()); | 478 return create_texture_for_bmp(ctx, optionalKey, desc, bitmap->getPixels(), b itmap->rowBytes()); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol or, &fp) && fp) { | 728 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol or, &fp) && fp) { |
| 718 grPaint->addColorProcessor(fp)->unref(); | 729 grPaint->addColorProcessor(fp)->unref(); |
| 719 constantColor = false; | 730 constantColor = false; |
| 720 } | 731 } |
| 721 } | 732 } |
| 722 | 733 |
| 723 // The grcolor is automatically set when calling asFragmentProcessor. | 734 // The grcolor is automatically set when calling asFragmentProcessor. |
| 724 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint. | 735 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint. |
| 725 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint ); | 736 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint ); |
| 726 } | 737 } |
| OLD | NEW |