OLD | NEW |
---|---|
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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 if (m_decodeFailed) | 153 if (m_decodeFailed) |
154 return false; | 154 return false; |
155 | 155 |
156 TRACE_EVENT1("blink", "ImageFrameGenerator::decodeToYUV", "frame index", sta tic_cast<int>(index)); | 156 TRACE_EVENT1("blink", "ImageFrameGenerator::decodeToYUV", "frame index", sta tic_cast<int>(index)); |
157 | 157 |
158 if (!planes || !planes[0] || !planes[1] || !planes[2] | 158 if (!planes || !planes[0] || !planes[1] || !planes[2] |
159 || !rowBytes || !rowBytes[0] || !rowBytes[1] || !rowBytes[2]) { | 159 || !rowBytes || !rowBytes[0] || !rowBytes[1] || !rowBytes[2]) { |
160 return false; | 160 return false; |
161 } | 161 } |
162 | 162 |
163 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::create(ImageDecoder::d etermineImageType(*data), ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaA ndColorProfileApplied); | 163 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::create(data, true, |
164 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileAppl ied); | |
164 // getYUVComponentSizes was already called and was successful, so ImageDecod er::create must succeed. | 165 // getYUVComponentSizes was already called and was successful, so ImageDecod er::create must succeed. |
165 ASSERT(decoder); | 166 ASSERT(decoder); |
166 | 167 |
167 decoder->setData(data, true); | |
168 | |
169 std::unique_ptr<ImagePlanes> imagePlanes = wrapUnique(new ImagePlanes(planes , rowBytes)); | 168 std::unique_ptr<ImagePlanes> imagePlanes = wrapUnique(new ImagePlanes(planes , rowBytes)); |
170 decoder->setImagePlanes(std::move(imagePlanes)); | 169 decoder->setImagePlanes(std::move(imagePlanes)); |
171 | 170 |
172 ASSERT(decoder->canDecodeToYUV()); | 171 ASSERT(decoder->canDecodeToYUV()); |
173 | 172 |
174 if (decoder->decodeToYUV()) { | 173 if (decoder->decodeToYUV()) { |
175 setHasAlpha(0, false); // YUV is always opaque | 174 setHasAlpha(0, false); // YUV is always opaque |
176 return true; | 175 return true; |
177 } | 176 } |
178 | 177 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
254 } | 253 } |
255 | 254 |
256 bool ImageFrameGenerator::decode(SegmentReader* data, bool allDataReceived, size _t index, ImageDecoder** decoder, SkBitmap* bitmap, SkBitmap::Allocator* allocat or) | 255 bool ImageFrameGenerator::decode(SegmentReader* data, bool allDataReceived, size _t index, ImageDecoder** decoder, SkBitmap* bitmap, SkBitmap::Allocator* allocat or) |
257 { | 256 { |
258 ASSERT(m_decodeMutex.locked()); | 257 ASSERT(m_decodeMutex.locked()); |
259 TRACE_EVENT2("blink", "ImageFrameGenerator::decode", "width", m_fullSize.wid th(), "height", m_fullSize.height()); | 258 TRACE_EVENT2("blink", "ImageFrameGenerator::decode", "width", m_fullSize.wid th(), "height", m_fullSize.height()); |
260 | 259 |
261 // Try to create an ImageDecoder if we are not given one. | 260 // Try to create an ImageDecoder if we are not given one. |
262 ASSERT(decoder); | 261 ASSERT(decoder); |
263 bool newDecoder = false; | 262 bool newDecoder = false; |
263 bool newNonFactoryDecoder = false; | |
Peter Kasting
2016/08/19 23:04:58
Nit: This is only checked in a negation below, so
f(malita)
2016/08/22 01:51:15
Done.
| |
264 if (!*decoder) { | 264 if (!*decoder) { |
265 newDecoder = true; | 265 newDecoder = true; |
266 if (m_imageDecoderFactory) | 266 if (m_imageDecoderFactory) |
267 *decoder = m_imageDecoderFactory->create().release(); | 267 *decoder = m_imageDecoderFactory->create().release(); |
268 | 268 |
269 if (!*decoder) | 269 if (!*decoder) { |
270 *decoder = ImageDecoder::create(ImageDecoder::determineImageType(*da ta), ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied ).release(); | 270 newNonFactoryDecoder = true; |
271 *decoder = ImageDecoder::create(data, allDataReceived, ImageDecoder: :AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied).release(); | |
272 } | |
271 | 273 |
272 if (!*decoder) | 274 if (!*decoder) |
273 return false; | 275 return false; |
274 } | 276 } |
275 | 277 |
276 if (!m_isMultiFrame && newDecoder && allDataReceived) { | 278 if (!m_isMultiFrame && newDecoder && allDataReceived) { |
277 // If we're using an external memory allocator that means we're decoding | 279 // If we're using an external memory allocator that means we're decoding |
278 // directly into the output memory and we can save one memcpy. | 280 // directly into the output memory and we can save one memcpy. |
279 ASSERT(allocator); | 281 ASSERT(allocator); |
280 (*decoder)->setMemoryAllocator(allocator); | 282 (*decoder)->setMemoryAllocator(allocator); |
281 } | 283 } |
282 | 284 |
283 (*decoder)->setData(data, allDataReceived); | 285 // If we just created a non-factory decoder, it already grabbed the data. N o need to reset. |
286 if (!newNonFactoryDecoder) | |
287 (*decoder)->setData(data, allDataReceived); | |
284 ImageFrame* frame = (*decoder)->frameBufferAtIndex(index); | 288 ImageFrame* frame = (*decoder)->frameBufferAtIndex(index); |
285 | 289 |
286 // For multi-frame image decoders, we need to know how many frames are | 290 // For multi-frame image decoders, we need to know how many frames are |
287 // in that image in order to release the decoder when all frames are | 291 // in that image in order to release the decoder when all frames are |
288 // decoded. frameCount() is reliable only if all data is received and set in | 292 // decoded. frameCount() is reliable only if all data is received and set in |
289 // decoder, particularly with GIF. | 293 // decoder, particularly with GIF. |
290 if (allDataReceived) | 294 if (allDataReceived) |
291 m_frameCount = (*decoder)->frameCount(); | 295 m_frameCount = (*decoder)->frameCount(); |
292 | 296 |
293 (*decoder)->setData(PassRefPtr<SegmentReader>(nullptr), false); // Unref Seg mentReader from ImageDecoder. | 297 (*decoder)->setData(PassRefPtr<SegmentReader>(nullptr), false); // Unref Seg mentReader from ImageDecoder. |
(...skipping 26 matching lines...) Expand all Loading... | |
320 return true; | 324 return true; |
321 } | 325 } |
322 | 326 |
323 bool ImageFrameGenerator::getYUVComponentSizes(SegmentReader* data, SkYUVSizeInf o* sizeInfo) | 327 bool ImageFrameGenerator::getYUVComponentSizes(SegmentReader* data, SkYUVSizeInf o* sizeInfo) |
324 { | 328 { |
325 TRACE_EVENT2("blink", "ImageFrameGenerator::getYUVComponentSizes", "width", m_fullSize.width(), "height", m_fullSize.height()); | 329 TRACE_EVENT2("blink", "ImageFrameGenerator::getYUVComponentSizes", "width", m_fullSize.width(), "height", m_fullSize.height()); |
326 | 330 |
327 if (m_yuvDecodingFailed) | 331 if (m_yuvDecodingFailed) |
328 return false; | 332 return false; |
329 | 333 |
330 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::create(ImageDecoder::d etermineImageType(*data), ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaA ndColorProfileApplied); | 334 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::create(data, true, |
335 ImageDecoder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileAppl ied); | |
331 if (!decoder) | 336 if (!decoder) |
332 return false; | 337 return false; |
333 | 338 |
334 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding. | 339 // Setting a dummy ImagePlanes object signals to the decoder that we want to do YUV decoding. |
335 decoder->setData(data, true); | |
336 std::unique_ptr<ImagePlanes> dummyImagePlanes = wrapUnique(new ImagePlanes); | 340 std::unique_ptr<ImagePlanes> dummyImagePlanes = wrapUnique(new ImagePlanes); |
337 decoder->setImagePlanes(std::move(dummyImagePlanes)); | 341 decoder->setImagePlanes(std::move(dummyImagePlanes)); |
338 | 342 |
339 return updateYUVComponentSizes(decoder.get(), sizeInfo->fSizes, sizeInfo->fW idthBytes); | 343 return updateYUVComponentSizes(decoder.get(), sizeInfo->fSizes, sizeInfo->fW idthBytes); |
340 } | 344 } |
341 | 345 |
342 } // namespace blink | 346 } // namespace blink |
OLD | NEW |