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 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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
) { |
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 const bool useCache = optionalKey.isValid(); |
327 SkYUVPlanesCache::Info yuvInfo; | 328 SkYUVPlanesCache::Info yuvInfo; |
328 SkAutoTUnref<SkCachedData> cachedData( | 329 SkAutoTUnref<SkCachedData> cachedData; |
329 SkYUVPlanesCache::FindAndRef(pixelRef->getGenerationID(), &yuvInfo)); | 330 SkAutoMalloc storage; |
| 331 if (useCache) { |
| 332 cachedData.reset(SkYUVPlanesCache::FindAndRef(pixelRef->getGenerationID(
), &yuvInfo)); |
| 333 } |
330 | 334 |
331 void* planes[3]; | 335 void* planes[3]; |
332 if (cachedData && cachedData->data()) { | 336 if (cachedData.get()) { |
333 planes[0] = (void*)cachedData->data(); | 337 planes[0] = (void*)cachedData->data(); |
334 planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0]; | 338 planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0]; |
335 planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1]; | 339 planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1]; |
336 } else { | 340 } else { |
337 // Fetch yuv plane sizes for memory allocation. Here, width and height c
an be | 341 // 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. | 342 // 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)) { | 343 if (!pixelRef->getYUV8Planes(yuvInfo.fSize, NULL, NULL, NULL)) { |
340 return NULL; | 344 return NULL; |
341 } | 345 } |
342 | 346 |
343 // Allocate the memory for YUV | 347 // Allocate the memory for YUV |
344 size_t totalSize(0); | 348 size_t totalSize(0); |
345 for (int i = 0; i < 3; ++i) { | 349 for (int i = 0; i < 3; ++i) { |
346 yuvInfo.fRowBytes[i] = yuvInfo.fSize[i].fWidth; | 350 yuvInfo.fRowBytes[i] = yuvInfo.fSize[i].fWidth; |
347 yuvInfo.fSizeInMemory[i] = yuvInfo.fRowBytes[i] * yuvInfo.fSize[i].f
Height; | 351 yuvInfo.fSizeInMemory[i] = yuvInfo.fRowBytes[i] * yuvInfo.fSize[i].f
Height; |
348 totalSize += yuvInfo.fSizeInMemory[i]; | 352 totalSize += yuvInfo.fSizeInMemory[i]; |
349 } | 353 } |
350 cachedData.reset(SkResourceCache::NewCachedData(totalSize)); | 354 if (useCache) { |
351 planes[0] = cachedData->writable_data(); | 355 cachedData.reset(SkResourceCache::NewCachedData(totalSize)); |
| 356 planes[0] = cachedData->writable_data(); |
| 357 } else { |
| 358 storage.reset(totalSize); |
| 359 planes[0] = storage.get(); |
| 360 } |
352 planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0]; | 361 planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0]; |
353 planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1]; | 362 planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1]; |
354 | 363 |
355 // Get the YUV planes and update plane sizes to actual image size | 364 // Get the YUV planes and update plane sizes to actual image size |
356 if (!pixelRef->getYUV8Planes(yuvInfo.fSize, planes, yuvInfo.fRowBytes, | 365 if (!pixelRef->getYUV8Planes(yuvInfo.fSize, planes, yuvInfo.fRowBytes, |
357 &yuvInfo.fColorSpace)) { | 366 &yuvInfo.fColorSpace)) { |
358 return NULL; | 367 return NULL; |
359 } | 368 } |
360 | 369 |
361 // Decoding is done, cache the resulting YUV planes | 370 if (useCache) { |
362 SkYUVPlanesCache::Add(pixelRef->getGenerationID(), cachedData, &yuvInfo)
; | 371 // Decoding is done, cache the resulting YUV planes |
| 372 SkYUVPlanesCache::Add(pixelRef->getGenerationID(), cachedData, &yuvI
nfo); |
| 373 } |
363 } | 374 } |
364 | 375 |
365 GrSurfaceDesc yuvDesc; | 376 GrSurfaceDesc yuvDesc; |
366 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; | 377 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; |
367 SkAutoTUnref<GrTexture> yuvTextures[3]; | 378 SkAutoTUnref<GrTexture> yuvTextures[3]; |
368 for (int i = 0; i < 3; ++i) { | 379 for (int i = 0; i < 3; ++i) { |
369 yuvDesc.fWidth = yuvInfo.fSize[i].fWidth; | 380 yuvDesc.fWidth = yuvInfo.fSize[i].fWidth; |
370 yuvDesc.fHeight = yuvInfo.fSize[i].fHeight; | 381 yuvDesc.fHeight = yuvInfo.fSize[i].fHeight; |
371 yuvTextures[i].reset( | 382 yuvTextures[i].reset( |
372 ctx->refScratchTexture(yuvDesc, GrContext::kApprox_ScratchTexMatch))
; | 383 ctx->refScratchTexture(yuvDesc, GrContext::kApprox_ScratchTexMatch))
; |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol
or, &fp) && fp) { | 737 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol
or, &fp) && fp) { |
727 grPaint->addColorProcessor(fp)->unref(); | 738 grPaint->addColorProcessor(fp)->unref(); |
728 constantColor = false; | 739 constantColor = false; |
729 } | 740 } |
730 } | 741 } |
731 | 742 |
732 // The grcolor is automatically set when calling asFragmentProcessor. | 743 // The grcolor is automatically set when calling asFragmentProcessor. |
733 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 744 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
734 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); | 745 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); |
735 } | 746 } |
OLD | NEW |