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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 115
116 ImageFrameGenerator::~ImageFrameGenerator() { 116 ImageFrameGenerator::~ImageFrameGenerator() {
117 ImageDecodingStore::instance().removeCacheIndexedByGenerator(this); 117 ImageDecodingStore::instance().removeCacheIndexedByGenerator(this);
118 } 118 }
119 119
120 bool ImageFrameGenerator::decodeAndScale(SegmentReader* data, 120 bool ImageFrameGenerator::decodeAndScale(SegmentReader* data,
121 bool allDataReceived, 121 bool allDataReceived,
122 size_t index, 122 size_t index,
123 const SkImageInfo& info, 123 const SkImageInfo& info,
124 void* pixels, 124 void* pixels,
125 size_t rowBytes) { 125 size_t rowBytes,
126 SkFilterQuality quality) {
126 if (m_decodeFailed) 127 if (m_decodeFailed)
127 return false; 128 return false;
128 129
129 TRACE_EVENT1("blink", "ImageFrameGenerator::decodeAndScale", "frame index", 130 TRACE_EVENT1("blink", "ImageFrameGenerator::decodeAndScale", "frame index",
130 static_cast<int>(index)); 131 static_cast<int>(index));
131 132
132 // This implementation does not support scaling so check the requested size.
133 SkISize scaledSize = SkISize::Make(info.width(), info.height()); 133 SkISize scaledSize = SkISize::Make(info.width(), info.height());
134 ASSERT(m_fullSize == scaledSize); 134 const bool doScaleAfterDecoding = m_fullSize != scaledSize;
135 135
136 // It is okay to allocate ref-counted ExternalMemoryAllocator on the stack, 136 // It is okay to allocate ref-counted ExternalMemoryAllocator on the stack,
137 // because 1) it contains references to memory that will be invalid after 137 // because 1) it contains references to memory that will be invalid after
138 // returning (i.e. a pointer to |pixels|) and therefore 2) should not live 138 // returning (i.e. a pointer to |pixels|) and therefore 2) should not live
139 // longer than the call to the current method. 139 // longer than the call to the current method.
140 ExternalMemoryAllocator externalAllocator(info, pixels, rowBytes); 140 ExternalMemoryAllocator externalAllocator(info, pixels, rowBytes);
141 SkBitmap bitmap = tryToResumeDecode(data, allDataReceived, index, scaledSize, 141 SkBitmap bitmap =
142 &externalAllocator); 142 tryToResumeDecode(data, allDataReceived, index, m_fullSize,
143 doScaleAfterDecoding ? nullptr : &externalAllocator);
143 DCHECK(externalAllocator.unique()); // Verify we have the only ref-count. 144 DCHECK(externalAllocator.unique()); // Verify we have the only ref-count.
144 145
145 if (bitmap.isNull()) 146 if (bitmap.isNull())
146 return false; 147 return false;
147 148
148 // Check to see if the decoder has written directly to the pixel memory 149 // Check to see if the decoder has written directly to the pixel memory
149 // provided. If not, make a copy. 150 // provided. If not, make a copy.
150 ASSERT(bitmap.width() == scaledSize.width()); 151 DCHECK_NE(bitmap.width(), m_fullSize.width());
151 ASSERT(bitmap.height() == scaledSize.height()); 152 DCHECK_NE(bitmap.height(), m_fullSize.height());
152 SkAutoLockPixels bitmapLock(bitmap); 153 SkAutoLockPixels bitmapLock(bitmap);
153 if (bitmap.getPixels() != pixels) 154 if (bitmap.getPixels() != pixels) {
154 return bitmap.copyPixelsTo(pixels, rowBytes * info.height(), rowBytes); 155 if (!doScaleAfterDecoding)
156 return bitmap.copyPixelsTo(pixels, rowBytes * info.height(), rowBytes);
157 SkPixmap pixmap;
158 SkPixmap scaled(info, pixels, rowBytes);
159 return bitmap.peekPixels(&pixmap) && pixmap.scalePixels(scaled, quality);
160 }
161 DCHECK(!doScaleAfterDecoding);
155 return true; 162 return true;
156 } 163 }
157 164
158 bool ImageFrameGenerator::decodeToYUV(SegmentReader* data, 165 bool ImageFrameGenerator::decodeToYUV(SegmentReader* data,
159 size_t index, 166 size_t index,
160 const SkISize componentSizes[3], 167 const SkISize componentSizes[3],
161 void* planes[3], 168 void* planes[3],
162 const size_t rowBytes[3]) { 169 const size_t rowBytes[3]) {
163 // TODO (scroggo): The only interesting thing this uses from the 170 // TODO (scroggo): The only interesting thing this uses from the
164 // ImageFrameGenerator is m_decodeFailed. Move this into 171 // ImageFrameGenerator is m_decodeFailed. Move this into
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 // do YUV decoding. 381 // do YUV decoding.
375 std::unique_ptr<ImagePlanes> dummyImagePlanes = 382 std::unique_ptr<ImagePlanes> dummyImagePlanes =
376 WTF::wrapUnique(new ImagePlanes); 383 WTF::wrapUnique(new ImagePlanes);
377 decoder->setImagePlanes(std::move(dummyImagePlanes)); 384 decoder->setImagePlanes(std::move(dummyImagePlanes));
378 385
379 return updateYUVComponentSizes(decoder.get(), sizeInfo->fSizes, 386 return updateYUVComponentSizes(decoder.get(), sizeInfo->fSizes,
380 sizeInfo->fWidthBytes); 387 sizeInfo->fWidthBytes);
381 } 388 }
382 389
383 } // namespace blink 390 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698