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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 ImageDecodingStore::instance().removeCacheIndexedByGenerator(this); 117 ImageDecodingStore::instance().removeCacheIndexedByGenerator(this);
118 } 118 }
119 119
120 bool ImageFrameGenerator::decodeAndScale(SegmentReader* data, bool allDataReceiv ed, size_t index, const SkImageInfo& info, void* pixels, size_t rowBytes) 120 bool ImageFrameGenerator::decodeAndScale(SegmentReader* data, bool allDataReceiv ed, size_t index, const SkImageInfo& info, void* pixels, size_t rowBytes)
121 { 121 {
122 if (m_decodeFailed) 122 if (m_decodeFailed)
123 return false; 123 return false;
124 124
125 TRACE_EVENT1("blink", "ImageFrameGenerator::decodeAndScale", "frame index", static_cast<int>(index)); 125 TRACE_EVENT1("blink", "ImageFrameGenerator::decodeAndScale", "frame index", static_cast<int>(index));
126 126
127 RefPtr<ExternalMemoryAllocator> externalAllocator = adoptRef(new ExternalMem oryAllocator(info, pixels, rowBytes));
128
129 // This implementation does not support scaling so check the requested size. 127 // This implementation does not support scaling so check the requested size.
130 SkISize scaledSize = SkISize::Make(info.width(), info.height()); 128 SkISize scaledSize = SkISize::Make(info.width(), info.height());
131 ASSERT(m_fullSize == scaledSize); 129 ASSERT(m_fullSize == scaledSize);
132 130
133 // TODO (scroggo): Convert tryToResumeDecode() and decode() to take a 131 // It is okay to allocate ref-counted ExternalMemoryAllocator on the stack,
134 // sk_sp<SkBitmap::Allocator> instead of a bare pointer. 132 // because 1) it contains references to memory that will be invalid after
135 SkBitmap bitmap = tryToResumeDecode(data, allDataReceived, index, scaledSize , externalAllocator.get()); 133 // returning (i.e. a pointer to |pixels|) and therefore 2) should not live
134 // longer than the call to the current method.
135 ExternalMemoryAllocator externalAllocator(info, pixels, rowBytes);
136 SkBitmap bitmap = tryToResumeDecode(data, allDataReceived, index, scaledSize , &externalAllocator);
137 DCHECK(externalAllocator.unique()); // Verify we have the only ref-count.
138
136 if (bitmap.isNull()) 139 if (bitmap.isNull())
137 return false; 140 return false;
138 141
139 // Check to see if the decoder has written directly to the pixel memory 142 // Check to see if the decoder has written directly to the pixel memory
140 // provided. If not, make a copy. 143 // provided. If not, make a copy.
141 ASSERT(bitmap.width() == scaledSize.width()); 144 ASSERT(bitmap.width() == scaledSize.width());
142 ASSERT(bitmap.height() == scaledSize.height()); 145 ASSERT(bitmap.height() == scaledSize.height());
143 SkAutoLockPixels bitmapLock(bitmap); 146 SkAutoLockPixels bitmapLock(bitmap);
144 if (bitmap.getPixels() != pixels) 147 if (bitmap.getPixels() != pixels)
145 return bitmap.copyPixelsTo(pixels, rowBytes * info.height(), rowBytes); 148 return bitmap.copyPixelsTo(pixels, rowBytes * info.height(), rowBytes);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 return false; 340 return false;
338 341
339 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding. 342 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding.
340 std::unique_ptr<ImagePlanes> dummyImagePlanes = wrapUnique(new ImagePlanes); 343 std::unique_ptr<ImagePlanes> dummyImagePlanes = wrapUnique(new ImagePlanes);
341 decoder->setImagePlanes(std::move(dummyImagePlanes)); 344 decoder->setImagePlanes(std::move(dummyImagePlanes));
342 345
343 return updateYUVComponentSizes(decoder.get(), sizeInfo->fSizes, sizeInfo->fW idthBytes); 346 return updateYUVComponentSizes(decoder.get(), sizeInfo->fSizes, sizeInfo->fW idthBytes);
344 } 347 }
345 348
346 } // namespace blink 349 } // namespace blink
OLDNEW
« 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