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

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

Issue 2578803002: Remove full-size bitmap copy on SkImage::scalePixels->IFG::decodeAndScale
Patch Set: Created 4 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: 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;
}

Powered by Google App Engine
This is Rietveld 408576698