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

Side by Side Diff: third_party/WebKit/Source/platform/graphics/ImageFrameGenerator.cpp

Issue 1880993003: Use RefPtr for SkBitmap::Allocator in ImageDecoder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sharedBufferInterface6
Patch Set: Rebase to ToT Created 4 years, 8 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
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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 return false; 120 return false;
121 121
122 TRACE_EVENT1("blink", "ImageFrameGenerator::decodeAndScale", "frame index", static_cast<int>(index)); 122 TRACE_EVENT1("blink", "ImageFrameGenerator::decodeAndScale", "frame index", static_cast<int>(index));
123 123
124 RefPtr<ExternalMemoryAllocator> externalAllocator = adoptRef(new ExternalMem oryAllocator(info, pixels, rowBytes)); 124 RefPtr<ExternalMemoryAllocator> externalAllocator = adoptRef(new ExternalMem oryAllocator(info, pixels, rowBytes));
125 125
126 // This implementation does not support scaling so check the requested size. 126 // This implementation does not support scaling so check the requested size.
127 SkISize scaledSize = SkISize::Make(info.width(), info.height()); 127 SkISize scaledSize = SkISize::Make(info.width(), info.height());
128 ASSERT(m_fullSize == scaledSize); 128 ASSERT(m_fullSize == scaledSize);
129 129
130 // TODO (scroggo): Convert tryToResumeDecode() and decode() to take a 130 SkBitmap bitmap = tryToResumeDecode(data, allDataReceived, index, scaledSize , externalAllocator.release());
131 // PassRefPtr<SkBitmap::Allocator> instead of a bare pointer.
132 SkBitmap bitmap = tryToResumeDecode(data, allDataReceived, index, scaledSize , externalAllocator.get());
133 if (bitmap.isNull()) 131 if (bitmap.isNull())
134 return false; 132 return false;
135 133
136 // Check to see if the decoder has written directly to the pixel memory 134 // Check to see if the decoder has written directly to the pixel memory
137 // provided. If not, make a copy. 135 // provided. If not, make a copy.
138 ASSERT(bitmap.width() == scaledSize.width()); 136 ASSERT(bitmap.width() == scaledSize.width());
139 ASSERT(bitmap.height() == scaledSize.height()); 137 ASSERT(bitmap.height() == scaledSize.height());
140 SkAutoLockPixels bitmapLock(bitmap); 138 SkAutoLockPixels bitmapLock(bitmap);
141 if (bitmap.getPixels() != pixels) 139 if (bitmap.getPixels() != pixels)
142 return bitmap.copyPixelsTo(pixels, rowBytes * info.height(), rowBytes); 140 return bitmap.copyPixelsTo(pixels, rowBytes * info.height(), rowBytes);
(...skipping 28 matching lines...) Expand all
171 if (decoder->decodeToYUV()) { 169 if (decoder->decodeToYUV()) {
172 setHasAlpha(0, false); // YUV is always opaque 170 setHasAlpha(0, false); // YUV is always opaque
173 return true; 171 return true;
174 } 172 }
175 173
176 ASSERT(decoder->failed()); 174 ASSERT(decoder->failed());
177 m_yuvDecodingFailed = true; 175 m_yuvDecodingFailed = true;
178 return false; 176 return false;
179 } 177 }
180 178
181 SkBitmap ImageFrameGenerator::tryToResumeDecode(SegmentReader* data, bool allDat aReceived, size_t index, const SkISize& scaledSize, SkBitmap::Allocator* allocat or) 179 SkBitmap ImageFrameGenerator::tryToResumeDecode(SegmentReader* data, bool allDat aReceived, size_t index, const SkISize& scaledSize, PassRefPtr<SkBitmap::Allocat or> allocator)
182 { 180 {
183 TRACE_EVENT1("blink", "ImageFrameGenerator::tryToResumeDecode", "frame index ", static_cast<int>(index)); 181 TRACE_EVENT1("blink", "ImageFrameGenerator::tryToResumeDecode", "frame index ", static_cast<int>(index));
184 182
185 ImageDecoder* decoder = 0; 183 ImageDecoder* decoder = 0;
186 184
187 // Lock the mutex, so only one thread can use the decoder at once. 185 // Lock the mutex, so only one thread can use the decoder at once.
188 MutexLocker lock(m_decodeMutex); 186 MutexLocker lock(m_decodeMutex);
189 const bool resumeDecoding = ImageDecodingStore::instance().lockDecoder(this, m_fullSize, &decoder); 187 const bool resumeDecoding = ImageDecodingStore::instance().lockDecoder(this, m_fullSize, &decoder);
190 ASSERT(!resumeDecoding || decoder); 188 ASSERT(!resumeDecoding || decoder);
191 189
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 MutexLocker lock(m_alphaMutex); 241 MutexLocker lock(m_alphaMutex);
244 if (index >= m_hasAlpha.size()) { 242 if (index >= m_hasAlpha.size()) {
245 const size_t oldSize = m_hasAlpha.size(); 243 const size_t oldSize = m_hasAlpha.size();
246 m_hasAlpha.resize(index + 1); 244 m_hasAlpha.resize(index + 1);
247 for (size_t i = oldSize; i < m_hasAlpha.size(); ++i) 245 for (size_t i = oldSize; i < m_hasAlpha.size(); ++i)
248 m_hasAlpha[i] = true; 246 m_hasAlpha[i] = true;
249 } 247 }
250 m_hasAlpha[index] = hasAlpha; 248 m_hasAlpha[index] = hasAlpha;
251 } 249 }
252 250
253 bool ImageFrameGenerator::decode(SegmentReader* data, bool allDataReceived, size _t index, ImageDecoder** decoder, SkBitmap* bitmap, SkBitmap::Allocator* allocat or) 251 bool ImageFrameGenerator::decode(SegmentReader* data, bool allDataReceived, size _t index, ImageDecoder** decoder, SkBitmap* bitmap, PassRefPtr<SkBitmap::Allocat or> allocator)
254 { 252 {
255 ASSERT(m_decodeMutex.locked()); 253 ASSERT(m_decodeMutex.locked());
256 TRACE_EVENT2("blink", "ImageFrameGenerator::decode", "width", m_fullSize.wid th(), "height", m_fullSize.height()); 254 TRACE_EVENT2("blink", "ImageFrameGenerator::decode", "width", m_fullSize.wid th(), "height", m_fullSize.height());
257 255
258 // Try to create an ImageDecoder if we are not given one. 256 // Try to create an ImageDecoder if we are not given one.
259 ASSERT(decoder); 257 ASSERT(decoder);
260 bool newDecoder = false; 258 bool newDecoder = false;
261 if (!*decoder) { 259 if (!*decoder) {
262 newDecoder = true; 260 newDecoder = true;
263 if (m_imageDecoderFactory) 261 if (m_imageDecoderFactory)
(...skipping 18 matching lines...) Expand all
282 280
283 // For multi-frame image decoders, we need to know how many frames are 281 // For multi-frame image decoders, we need to know how many frames are
284 // in that image in order to release the decoder when all frames are 282 // in that image in order to release the decoder when all frames are
285 // decoded. frameCount() is reliable only if all data is received and set in 283 // decoded. frameCount() is reliable only if all data is received and set in
286 // decoder, particularly with GIF. 284 // decoder, particularly with GIF.
287 if (allDataReceived) 285 if (allDataReceived)
288 m_frameCount = (*decoder)->frameCount(); 286 m_frameCount = (*decoder)->frameCount();
289 287
290 (*decoder)->setData(PassRefPtr<SegmentReader>(nullptr), false); // Unref Seg mentReader from ImageDecoder. 288 (*decoder)->setData(PassRefPtr<SegmentReader>(nullptr), false); // Unref Seg mentReader from ImageDecoder.
291 (*decoder)->clearCacheExceptFrame(index); 289 (*decoder)->clearCacheExceptFrame(index);
292 (*decoder)->setMemoryAllocator(0); 290 (*decoder)->setMemoryAllocator(nullptr);
293 291
294 if (!frame || frame->getStatus() == ImageFrame::FrameEmpty) 292 if (!frame || frame->getStatus() == ImageFrame::FrameEmpty)
295 return false; 293 return false;
296 294
297 // A cache object is considered complete if we can decode a complete frame. 295 // A cache object is considered complete if we can decode a complete frame.
298 // Or we have received all data. The image might not be fully decoded in 296 // Or we have received all data. The image might not be fully decoded in
299 // the latter case. 297 // the latter case.
300 const bool isDecodeComplete = frame->getStatus() == ImageFrame::FrameComplet e || allDataReceived; 298 const bool isDecodeComplete = frame->getStatus() == ImageFrame::FrameComplet e || allDataReceived;
301 299
302 SkBitmap fullSizeBitmap = frame->bitmap(); 300 SkBitmap fullSizeBitmap = frame->bitmap();
(...skipping 27 matching lines...) Expand all
330 328
331 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding. 329 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding.
332 decoder->setData(data, true); 330 decoder->setData(data, true);
333 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes); 331 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes);
334 decoder->setImagePlanes(dummyImagePlanes.release()); 332 decoder->setImagePlanes(dummyImagePlanes.release());
335 333
336 return updateYUVComponentSizes(decoder.get(), sizeInfo->fSizes, sizeInfo->fW idthBytes); 334 return updateYUVComponentSizes(decoder.get(), sizeInfo->fSizes, sizeInfo->fW idthBytes);
337 } 335 }
338 336
339 } // namespace blink 337 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698