No more caching volatile bitmaps
VideoFrames are always marked as volatile and load_yuv_texture() was caching everything, even volatile bitmaps. To solve this issue, we no longer cache volatile bitmaps' YUV planes in load_yuv_texture().
There is another issue which cause this to happen, related to how VideoImageGenerator::onGetYUV8Planes() is implemented, which is logged here: crbug.com/455235
BUG=450706, 450699
Review URL: https://codereview.chromium.org/900943002
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 2a153af..f4d51b3 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -324,12 +324,16 @@
return NULL;
}
+ const bool useCache = optionalKey.isValid();
SkYUVPlanesCache::Info yuvInfo;
- SkAutoTUnref<SkCachedData> cachedData(
- SkYUVPlanesCache::FindAndRef(pixelRef->getGenerationID(), &yuvInfo));
+ SkAutoTUnref<SkCachedData> cachedData;
+ SkAutoMalloc storage;
+ if (useCache) {
+ cachedData.reset(SkYUVPlanesCache::FindAndRef(pixelRef->getGenerationID(), &yuvInfo));
+ }
void* planes[3];
- if (cachedData && cachedData->data()) {
+ if (cachedData.get()) {
planes[0] = (void*)cachedData->data();
planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0];
planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1];
@@ -347,8 +351,13 @@
yuvInfo.fSizeInMemory[i] = yuvInfo.fRowBytes[i] * yuvInfo.fSize[i].fHeight;
totalSize += yuvInfo.fSizeInMemory[i];
}
- cachedData.reset(SkResourceCache::NewCachedData(totalSize));
- planes[0] = cachedData->writable_data();
+ if (useCache) {
+ cachedData.reset(SkResourceCache::NewCachedData(totalSize));
+ planes[0] = cachedData->writable_data();
+ } else {
+ storage.reset(totalSize);
+ planes[0] = storage.get();
+ }
planes[1] = (uint8_t*)planes[0] + yuvInfo.fSizeInMemory[0];
planes[2] = (uint8_t*)planes[1] + yuvInfo.fSizeInMemory[1];
@@ -358,8 +367,10 @@
return NULL;
}
- // Decoding is done, cache the resulting YUV planes
- SkYUVPlanesCache::Add(pixelRef->getGenerationID(), cachedData, &yuvInfo);
+ if (useCache) {
+ // Decoding is done, cache the resulting YUV planes
+ SkYUVPlanesCache::Add(pixelRef->getGenerationID(), cachedData, &yuvInfo);
+ }
}
GrSurfaceDesc yuvDesc;