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

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

Issue 2807923002: Replace ASSERT, ASSERT_NOT_REACHED, and RELEASE_ASSERT in platform/graphics (Closed)
Patch Set: Replace ASSERT, ASSERT_NOT_REACHED, and RELEASE_ASSERT in platform/graphics Created 3 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 void* pixels, 124 void* pixels,
125 size_t rowBytes) { 125 size_t rowBytes) {
126 if (m_decodeFailed) 126 if (m_decodeFailed)
127 return false; 127 return false;
128 128
129 TRACE_EVENT1("blink", "ImageFrameGenerator::decodeAndScale", "frame index", 129 TRACE_EVENT1("blink", "ImageFrameGenerator::decodeAndScale", "frame index",
130 static_cast<int>(index)); 130 static_cast<int>(index));
131 131
132 // This implementation does not support scaling so check the requested size. 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 DCHECK(m_fullSize == scaledSize);
tkent 2017/04/09 23:17:27 Use DCHECK_EQ if it doesn't cause a compile failur
Hwanseung Lee 2017/04/11 22:24:10 it was cause a compile fail.
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 = tryToResumeDecode(data, allDataReceived, index, scaledSize,
142 &externalAllocator); 142 &externalAllocator);
143 DCHECK(externalAllocator.unique()); // Verify we have the only ref-count. 143 DCHECK(externalAllocator.unique()); // Verify we have the only ref-count.
144 144
145 if (bitmap.isNull()) 145 if (bitmap.isNull())
146 return false; 146 return false;
147 147
148 // Check to see if the decoder has written directly to the pixel memory 148 // Check to see if the decoder has written directly to the pixel memory
149 // provided. If not, make a copy. 149 // provided. If not, make a copy.
150 ASSERT(bitmap.width() == scaledSize.width()); 150 DCHECK_EQ(bitmap.width(), scaledSize.width());
151 ASSERT(bitmap.height() == scaledSize.height()); 151 DCHECK_EQ(bitmap.height(), scaledSize.height());
152 SkAutoLockPixels bitmapLock(bitmap); 152 SkAutoLockPixels bitmapLock(bitmap);
153 if (bitmap.getPixels() != pixels) 153 if (bitmap.getPixels() != pixels)
154 return bitmap.copyPixelsTo(pixels, rowBytes * info.height(), rowBytes); 154 return bitmap.copyPixelsTo(pixels, rowBytes * info.height(), rowBytes);
155 return true; 155 return true;
156 } 156 }
157 157
158 bool ImageFrameGenerator::decodeToYUV(SegmentReader* data, 158 bool ImageFrameGenerator::decodeToYUV(SegmentReader* data,
159 size_t index, 159 size_t index,
160 const SkISize componentSizes[3], 160 const SkISize componentSizes[3],
161 void* planes[3], 161 void* planes[3],
162 const size_t rowBytes[3]) { 162 const size_t rowBytes[3]) {
163 // TODO (scroggo): The only interesting thing this uses from the 163 // TODO (scroggo): The only interesting thing this uses from the
164 // ImageFrameGenerator is m_decodeFailed. Move this into 164 // ImageFrameGenerator is m_decodeFailed. Move this into
165 // DecodingImageGenerator, which is the only class that calls it. 165 // DecodingImageGenerator, which is the only class that calls it.
166 if (m_decodeFailed) 166 if (m_decodeFailed)
167 return false; 167 return false;
168 168
169 TRACE_EVENT1("blink", "ImageFrameGenerator::decodeToYUV", "frame index", 169 TRACE_EVENT1("blink", "ImageFrameGenerator::decodeToYUV", "frame index",
170 static_cast<int>(index)); 170 static_cast<int>(index));
171 171
172 if (!planes || !planes[0] || !planes[1] || !planes[2] || !rowBytes || 172 if (!planes || !planes[0] || !planes[1] || !planes[2] || !rowBytes ||
173 !rowBytes[0] || !rowBytes[1] || !rowBytes[2]) { 173 !rowBytes[0] || !rowBytes[1] || !rowBytes[2]) {
174 return false; 174 return false;
175 } 175 }
176 176
177 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::create( 177 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::create(
178 data, true, ImageDecoder::AlphaPremultiplied, m_decoderColorBehavior); 178 data, true, ImageDecoder::AlphaPremultiplied, m_decoderColorBehavior);
179 // getYUVComponentSizes was already called and was successful, so 179 // getYUVComponentSizes was already called and was successful, so
180 // ImageDecoder::create must succeed. 180 // ImageDecoder::create must succeed.
181 ASSERT(decoder); 181 DCHECK(decoder);
182 182
183 std::unique_ptr<ImagePlanes> imagePlanes = 183 std::unique_ptr<ImagePlanes> imagePlanes =
184 WTF::makeUnique<ImagePlanes>(planes, rowBytes); 184 WTF::makeUnique<ImagePlanes>(planes, rowBytes);
185 decoder->setImagePlanes(std::move(imagePlanes)); 185 decoder->setImagePlanes(std::move(imagePlanes));
186 186
187 ASSERT(decoder->canDecodeToYUV()); 187 DCHECK(decoder->canDecodeToYUV());
188 188
189 if (decoder->decodeToYUV()) { 189 if (decoder->decodeToYUV()) {
190 setHasAlpha(0, false); // YUV is always opaque 190 setHasAlpha(0, false); // YUV is always opaque
191 return true; 191 return true;
192 } 192 }
193 193
194 ASSERT(decoder->failed()); 194 DCHECK(decoder->failed());
195 m_yuvDecodingFailed = true; 195 m_yuvDecodingFailed = true;
196 return false; 196 return false;
197 } 197 }
198 198
199 SkBitmap ImageFrameGenerator::tryToResumeDecode( 199 SkBitmap ImageFrameGenerator::tryToResumeDecode(
200 SegmentReader* data, 200 SegmentReader* data,
201 bool allDataReceived, 201 bool allDataReceived,
202 size_t index, 202 size_t index,
203 const SkISize& scaledSize, 203 const SkISize& scaledSize,
204 SkBitmap::Allocator* allocator) { 204 SkBitmap::Allocator* allocator) {
205 TRACE_EVENT1("blink", "ImageFrameGenerator::tryToResumeDecode", "frame index", 205 TRACE_EVENT1("blink", "ImageFrameGenerator::tryToResumeDecode", "frame index",
206 static_cast<int>(index)); 206 static_cast<int>(index));
207 207
208 ImageDecoder* decoder = 0; 208 ImageDecoder* decoder = 0;
209 209
210 // Lock the mutex, so only one thread can use the decoder at once. 210 // Lock the mutex, so only one thread can use the decoder at once.
211 MutexLocker lock(m_decodeMutex); 211 MutexLocker lock(m_decodeMutex);
212 const bool resumeDecoding = 212 const bool resumeDecoding =
213 ImageDecodingStore::instance().lockDecoder(this, m_fullSize, &decoder); 213 ImageDecodingStore::instance().lockDecoder(this, m_fullSize, &decoder);
214 ASSERT(!resumeDecoding || decoder); 214 DCHECK(!resumeDecoding || decoder);
215 215
216 SkBitmap fullSizeImage; 216 SkBitmap fullSizeImage;
217 bool complete = 217 bool complete =
218 decode(data, allDataReceived, index, &decoder, &fullSizeImage, allocator); 218 decode(data, allDataReceived, index, &decoder, &fullSizeImage, allocator);
219 219
220 if (!decoder) 220 if (!decoder)
221 return SkBitmap(); 221 return SkBitmap();
222 222
223 // If we are not resuming decoding that means the decoder is freshly 223 // If we are not resuming decoding that means the decoder is freshly
224 // created and we have ownership. If we are resuming decoding then 224 // created and we have ownership. If we are resuming decoding then
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 } 274 }
275 m_hasAlpha[index] = hasAlpha; 275 m_hasAlpha[index] = hasAlpha;
276 } 276 }
277 277
278 bool ImageFrameGenerator::decode(SegmentReader* data, 278 bool ImageFrameGenerator::decode(SegmentReader* data,
279 bool allDataReceived, 279 bool allDataReceived,
280 size_t index, 280 size_t index,
281 ImageDecoder** decoder, 281 ImageDecoder** decoder,
282 SkBitmap* bitmap, 282 SkBitmap* bitmap,
283 SkBitmap::Allocator* allocator) { 283 SkBitmap::Allocator* allocator) {
284 ASSERT(m_decodeMutex.locked()); 284 #if DCHECK_IS_ON()
285 DCHECK(m_decodeMutex.locked());
286 #endif
285 TRACE_EVENT2("blink", "ImageFrameGenerator::decode", "width", 287 TRACE_EVENT2("blink", "ImageFrameGenerator::decode", "width",
286 m_fullSize.width(), "height", m_fullSize.height()); 288 m_fullSize.width(), "height", m_fullSize.height());
287 289
288 // Try to create an ImageDecoder if we are not given one. 290 // Try to create an ImageDecoder if we are not given one.
289 ASSERT(decoder); 291 DCHECK(decoder);
290 bool newDecoder = false; 292 bool newDecoder = false;
291 bool shouldCallSetData = true; 293 bool shouldCallSetData = true;
292 if (!*decoder) { 294 if (!*decoder) {
293 newDecoder = true; 295 newDecoder = true;
294 if (m_imageDecoderFactory) 296 if (m_imageDecoderFactory)
295 *decoder = m_imageDecoderFactory->create().release(); 297 *decoder = m_imageDecoderFactory->create().release();
296 298
297 if (!*decoder) { 299 if (!*decoder) {
298 *decoder = ImageDecoder::create(data, allDataReceived, 300 *decoder = ImageDecoder::create(data, allDataReceived,
299 ImageDecoder::AlphaPremultiplied, 301 ImageDecoder::AlphaPremultiplied,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 return false; 345 return false;
344 346
345 // A cache object is considered complete if we can decode a complete frame. 347 // A cache object is considered complete if we can decode a complete frame.
346 // Or we have received all data. The image might not be fully decoded in 348 // Or we have received all data. The image might not be fully decoded in
347 // the latter case. 349 // the latter case.
348 const bool isDecodeComplete = 350 const bool isDecodeComplete =
349 frame->getStatus() == ImageFrame::FrameComplete || allDataReceived; 351 frame->getStatus() == ImageFrame::FrameComplete || allDataReceived;
350 352
351 SkBitmap fullSizeBitmap = frame->bitmap(); 353 SkBitmap fullSizeBitmap = frame->bitmap();
352 if (!fullSizeBitmap.isNull()) { 354 if (!fullSizeBitmap.isNull()) {
353 ASSERT(fullSizeBitmap.width() == m_fullSize.width() && 355 DCHECK(fullSizeBitmap.width() == m_fullSize.width() &&
tkent 2017/04/09 23:17:27 Split this into two DCHECK_EQs.
Hwanseung Lee 2017/04/11 22:24:10 Done.
354 fullSizeBitmap.height() == m_fullSize.height()); 356 fullSizeBitmap.height() == m_fullSize.height());
355 setHasAlpha(index, !fullSizeBitmap.isOpaque()); 357 setHasAlpha(index, !fullSizeBitmap.isOpaque());
356 } 358 }
357 359
358 *bitmap = fullSizeBitmap; 360 *bitmap = fullSizeBitmap;
359 return isDecodeComplete; 361 return isDecodeComplete;
360 } 362 }
361 363
362 bool ImageFrameGenerator::hasAlpha(size_t index) { 364 bool ImageFrameGenerator::hasAlpha(size_t index) {
363 MutexLocker lock(m_alphaMutex); 365 MutexLocker lock(m_alphaMutex);
(...skipping 19 matching lines...) Expand all
383 // do YUV decoding. 385 // do YUV decoding.
384 std::unique_ptr<ImagePlanes> dummyImagePlanes = 386 std::unique_ptr<ImagePlanes> dummyImagePlanes =
385 WTF::wrapUnique(new ImagePlanes); 387 WTF::wrapUnique(new ImagePlanes);
386 decoder->setImagePlanes(std::move(dummyImagePlanes)); 388 decoder->setImagePlanes(std::move(dummyImagePlanes));
387 389
388 return updateYUVComponentSizes(decoder.get(), sizeInfo->fSizes, 390 return updateYUVComponentSizes(decoder.get(), sizeInfo->fSizes,
389 sizeInfo->fWidthBytes); 391 sizeInfo->fWidthBytes);
390 } 392 }
391 393
392 } // namespace blink 394 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698