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

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

Issue 2326473005: Use sk_sp<SkBitmap::Allocator> instead of raw pointers or WTF::RefPtr<T>. (Closed)
Patch Set: Allocating ExternalMemoryAllocator on the stack. Created 4 years, 3 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 60292c6ac26c0d97ad4f97e8b81e716550108352..64395db76a9d3b8b7027981ffebcf5ad7bd0f8db 100644
--- a/third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp
+++ b/third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp
@@ -124,15 +124,18 @@ bool ImageFrameGenerator::decodeAndScale(SegmentReader* data, bool allDataReceiv
TRACE_EVENT1("blink", "ImageFrameGenerator::decodeAndScale", "frame index", static_cast<int>(index));
- RefPtr<ExternalMemoryAllocator> externalAllocator = adoptRef(new ExternalMemoryAllocator(info, pixels, rowBytes));
-
// This implementation does not support scaling so check the requested size.
SkISize scaledSize = SkISize::Make(info.width(), info.height());
ASSERT(m_fullSize == scaledSize);
- // TODO (scroggo): Convert tryToResumeDecode() and decode() to take a
- // sk_sp<SkBitmap::Allocator> instead of a bare pointer.
- SkBitmap bitmap = tryToResumeDecode(data, allDataReceived, index, scaledSize, externalAllocator.get());
+ // 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);
+ DCHECK(externalAllocator.unique()); // Verify we have the only ref-count.
+
if (bitmap.isNull())
return false;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698