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

Unified Diff: Source/platform/graphics/ImageFrameGenerator.cpp

Issue 105773003: Teach Skia to use discardable memory (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: merged and discardable Created 7 years 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 side-by-side diff with in-line comments
Download patch
Index: Source/platform/graphics/ImageFrameGenerator.cpp
diff --git a/Source/platform/graphics/ImageFrameGenerator.cpp b/Source/platform/graphics/ImageFrameGenerator.cpp
index 038635b38d175da1523e253b5edf6e1f4edc9ac7..1c04365f94f4e12d079c429fade4a4d7e4eab771 100644
--- a/Source/platform/graphics/ImageFrameGenerator.cpp
+++ b/Source/platform/graphics/ImageFrameGenerator.cpp
@@ -105,6 +105,38 @@ const ScaledImageFragment* ImageFrameGenerator::decodeAndScale(const SkISize& sc
return 0;
}
+bool ImageFrameGenerator::decodeAndScale(const SkImageInfo& info, size_t index, void* pixels, size_t rowBytes)
+{
+ // This method is called to populate a discardable memory owned by Skia.
+ // Ideally we want the decoder to write directly to |pixels| but this
+ // simple implementation copies from a decoded bitmap.
+
+ // This implementation does not support scaling so check the requested size.
+ ASSERT(m_fullSize.width() == info.fWidth);
+ ASSERT(m_fullSize.height() == info.fHeight);
+
+ // Don't use discardable memory for decoding if Skia is providing output
+ // memory. By clearing the memory allocator decoding will use heap memory.
+ //
+ // TODO:
+ // This is not pretty because this class is used in two different code
+ // paths: discardable memory decoding on Android and discardable memory
+ // in Skia. Once the transition to caching in Skia is complete we can get
+ // rid of the logic that handles discardable memory.
+ m_allocator.clear();
+
+ const ScaledImageFragment* cachedImage = decodeAndScale(SkISize::Make(info.fWidth, info.fHeight), index);
+ if (!cachedImage)
+ return false;
+
+ ASSERT(cachedImage->bitmap().width() == info.fWidth);
+ ASSERT(cachedImage->bitmap().height() == info.fHeight);
+
+ bool copied = cachedImage->bitmap().copyPixelsTo(pixels, rowBytes * info.fHeight, rowBytes);
+ ImageDecodingStore::instance()->unlockCache(this, cachedImage);
+ return copied;
+}
+
const ScaledImageFragment* ImageFrameGenerator::tryToLockCompleteCache(const SkISize& scaledSize, size_t index)
{
const ScaledImageFragment* cachedImage = 0;

Powered by Google App Engine
This is Rietveld 408576698