Index: third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp |
diff --git a/third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp b/third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp |
index d6c4fc34590f90d78f41595338b3aaec26524d9f..b39997b8cc49ae97fccc1075d531410741940603 100644 |
--- a/third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp |
+++ b/third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp |
@@ -122,24 +122,25 @@ bool ImageFrameGenerator::decodeAndScale(SegmentReader* data, |
size_t index, |
const SkImageInfo& info, |
void* pixels, |
- size_t rowBytes) { |
+ size_t rowBytes, |
+ SkFilterQuality quality) { |
if (m_decodeFailed) |
return false; |
TRACE_EVENT1("blink", "ImageFrameGenerator::decodeAndScale", "frame index", |
static_cast<int>(index)); |
- // This implementation does not support scaling so check the requested size. |
SkISize scaledSize = SkISize::Make(info.width(), info.height()); |
- ASSERT(m_fullSize == scaledSize); |
+ const bool doScaleAfterDecoding = m_fullSize != scaledSize; |
// It is okay to allocate ref-counted ExternalMemoryAllocator on the stack, |
// because 1) it contains references to memory that will be invalid after |
// returning (i.e. a pointer to |pixels|) and therefore 2) should not live |
// longer than the call to the current method. |
ExternalMemoryAllocator externalAllocator(info, pixels, rowBytes); |
- SkBitmap bitmap = tryToResumeDecode(data, allDataReceived, index, scaledSize, |
- &externalAllocator); |
+ SkBitmap bitmap = |
+ tryToResumeDecode(data, allDataReceived, index, m_fullSize, |
+ doScaleAfterDecoding ? nullptr : &externalAllocator); |
DCHECK(externalAllocator.unique()); // Verify we have the only ref-count. |
if (bitmap.isNull()) |
@@ -147,11 +148,17 @@ bool ImageFrameGenerator::decodeAndScale(SegmentReader* data, |
// Check to see if the decoder has written directly to the pixel memory |
// provided. If not, make a copy. |
- ASSERT(bitmap.width() == scaledSize.width()); |
- ASSERT(bitmap.height() == scaledSize.height()); |
+ DCHECK_NE(bitmap.width(), m_fullSize.width()); |
+ DCHECK_NE(bitmap.height(), m_fullSize.height()); |
SkAutoLockPixels bitmapLock(bitmap); |
- if (bitmap.getPixels() != pixels) |
- return bitmap.copyPixelsTo(pixels, rowBytes * info.height(), rowBytes); |
+ if (bitmap.getPixels() != pixels) { |
+ if (!doScaleAfterDecoding) |
+ return bitmap.copyPixelsTo(pixels, rowBytes * info.height(), rowBytes); |
+ SkPixmap pixmap; |
+ SkPixmap scaled(info, pixels, rowBytes); |
+ return bitmap.peekPixels(&pixmap) && pixmap.scalePixels(scaled, quality); |
+ } |
+ DCHECK(!doScaleAfterDecoding); |
return true; |
} |