| 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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 SkYUVPlanesCache::Info yuvInfo; | 227 SkYUVPlanesCache::Info yuvInfo; |
| 228 SkAutoTUnref<SkCachedData> cachedData( | 228 SkAutoTUnref<SkCachedData> cachedData( |
| 229 SkYUVPlanesCache::FindAndRef(pixelRef->getGenerationID(), &yuvInfo)); | 229 SkYUVPlanesCache::FindAndRef(pixelRef->getGenerationID(), &yuvInfo)); |
| 230 | 230 |
| 231 void* planes[3]; | 231 void* planes[3]; |
| 232 if (cachedData && cachedData->data()) { | 232 if (cachedData && cachedData->data()) { |
| 233 planes[0] = (void*)cachedData->data(); | 233 planes[0] = (void*)cachedData->data(); |
| 234 planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0]; | 234 planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0]; |
| 235 planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1]; | 235 planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1]; |
| 236 } else { | 236 } else { |
| 237 SkISize optimalAllocationSizes[3]; |
| 237 // Fetch yuv plane sizes for memory allocation. Here, width and height c
an be | 238 // Fetch yuv plane sizes for memory allocation. Here, width and height c
an be |
| 238 // rounded up to JPEG block size and be larger than the image's width an
d height. | 239 // rounded up to JPEG block size and be larger than the image's width an
d height. |
| 239 if (!pixelRef->getYUV8Planes(yuvInfo.fSize, NULL, NULL, NULL)) { | 240 if (!pixelRef->queryYUV8(yuvInfo.fSize, optimalAllocationSizes)) { |
| 240 return NULL; | 241 return NULL; |
| 241 } | 242 } |
| 242 | 243 |
| 243 // Allocate the memory for YUV | 244 // Allocate the memory for YUV |
| 244 size_t totalSize(0); | 245 size_t totalSize(0); |
| 245 for (int i = 0; i < 3; ++i) { | 246 for (int i = 0; i < 3; ++i) { |
| 246 yuvInfo.fRowBytes[i] = yuvInfo.fSize[i].fWidth; | 247 yuvInfo.fRowBytes[i] = optimalAllocationSizes[i].width(); |
| 247 yuvInfo.fSizeInMemory[i] = yuvInfo.fRowBytes[i] * yuvInfo.fSize[i].f
Height; | 248 yuvInfo.fSizeInMemory[i] = yuvInfo.fRowBytes[i] * optimalAllocationS
izes[i].height(); |
| 248 totalSize += yuvInfo.fSizeInMemory[i]; | 249 totalSize += yuvInfo.fSizeInMemory[i]; |
| 249 } | 250 } |
| 250 cachedData.reset(SkResourceCache::NewCachedData(totalSize)); | 251 cachedData.reset(SkResourceCache::NewCachedData(totalSize)); |
| 251 planes[0] = cachedData->writable_data(); | 252 planes[0] = cachedData->writable_data(); |
| 252 planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0]; | 253 planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0]; |
| 253 planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1]; | 254 planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1]; |
| 254 | 255 |
| 255 // Get the YUV planes and update plane sizes to actual image size | 256 // Get the YUV planes and update plane sizes to actual image size |
| 256 if (!pixelRef->getYUV8Planes(yuvInfo.fSize, planes, yuvInfo.fRowBytes, | 257 if (!pixelRef->getYUV8(optimalAllocationSizes, planes, &yuvInfo.fColorSp
ace)) { |
| 257 &yuvInfo.fColorSpace)) { | |
| 258 return NULL; | 258 return NULL; |
| 259 } | 259 } |
| 260 | 260 |
| 261 // Decoding is done, cache the resulting YUV planes | 261 // Decoding is done, cache the resulting YUV planes |
| 262 SkYUVPlanesCache::Add(pixelRef->getGenerationID(), cachedData, &yuvInfo)
; | 262 SkYUVPlanesCache::Add(pixelRef->getGenerationID(), cachedData, &yuvInfo)
; |
| 263 } | 263 } |
| 264 | 264 |
| 265 GrSurfaceDesc yuvDesc; | 265 GrSurfaceDesc yuvDesc; |
| 266 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; | 266 yuvDesc.fConfig = kAlpha_8_GrPixelConfig; |
| 267 SkAutoTUnref<GrTexture> yuvTextures[3]; | 267 SkAutoTUnref<GrTexture> yuvTextures[3]; |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol
or, &fp) && fp) { | 584 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol
or, &fp) && fp) { |
| 585 grPaint->addColorProcessor(fp)->unref(); | 585 grPaint->addColorProcessor(fp)->unref(); |
| 586 constantColor = false; | 586 constantColor = false; |
| 587 } | 587 } |
| 588 } | 588 } |
| 589 | 589 |
| 590 // The grcolor is automatically set when calling asFragmentProcessor. | 590 // The grcolor is automatically set when calling asFragmentProcessor. |
| 591 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. | 591 // If the shader can be seen as an effect it returns true and adds its effec
t to the grpaint. |
| 592 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); | 592 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint
); |
| 593 } | 593 } |
| OLD | NEW |