Commit dd5d3f23 authored by hclam@chromium.org's avatar hclam@chromium.org

Save a memory copy on Android for decoding images to discardable memory

On Android we can save copying the bitmap if the decoder writes directly
to the discardable memory.

All webkit_unit_tests passed with this change.

BUG=352570

Review URL: https://codereview.chromium.org/198603003

git-svn-id: svn://svn.chromium.org/blink/trunk@169457 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent cf9f7065
...@@ -253,17 +253,16 @@ PassOwnPtr<ScaledImageFragment> ImageFrameGenerator::decode(size_t index, ImageD ...@@ -253,17 +253,16 @@ PassOwnPtr<ScaledImageFragment> ImageFrameGenerator::decode(size_t index, ImageD
return nullptr; return nullptr;
} }
// An external memory allocator is used if this variable is true. // This variable is set to true if we can skip a memcpy of the decoded bitmap.
bool useExternalAllocator = false; bool canSkipBitmapCopy = false;
if (!m_isMultiFrame && newDecoder && allDataReceived) { if (!m_isMultiFrame && newDecoder && allDataReceived) {
// We are supporting two decoding paths in this code. Use the // If we're using an external memory allocator that means we're decoding
// external memory allocator in the Skia discardable path to // directly into the output memory and we can save one memcpy.
// save one memory copy. canSkipBitmapCopy = true;
if (m_externalAllocator) { if (m_externalAllocator)
(*decoder)->setMemoryAllocator(m_externalAllocator.get()); (*decoder)->setMemoryAllocator(m_externalAllocator.get());
useExternalAllocator = true; else
} else
(*decoder)->setMemoryAllocator(m_discardableAllocator.get()); (*decoder)->setMemoryAllocator(m_discardableAllocator.get());
} }
(*decoder)->setData(data, allDataReceived); (*decoder)->setData(data, allDataReceived);
...@@ -302,7 +301,7 @@ PassOwnPtr<ScaledImageFragment> ImageFrameGenerator::decode(size_t index, ImageD ...@@ -302,7 +301,7 @@ PassOwnPtr<ScaledImageFragment> ImageFrameGenerator::decode(size_t index, ImageD
// We early out and do not copy the memory if decoder writes directly to // We early out and do not copy the memory if decoder writes directly to
// the memory provided by Skia and the decode was complete. // the memory provided by Skia and the decode was complete.
if (useExternalAllocator && isCacheComplete) if (canSkipBitmapCopy && isCacheComplete)
return ScaledImageFragment::createComplete(m_fullSize, index, fullSizeBitmap); return ScaledImageFragment::createComplete(m_fullSize, index, fullSizeBitmap);
// If the image is progressively decoded we need to return a copy. // If the image is progressively decoded we need to return a copy.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment