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 12 matching lines...) Expand all Loading... |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "platform/graphics/ImageFrameGenerator.h" | 26 #include "platform/graphics/ImageFrameGenerator.h" |
27 | 27 |
28 #include "SkData.h" | 28 #include "SkData.h" |
29 #include "platform/TraceEvent.h" | 29 #include "platform/TraceEvent.h" |
30 #include "platform/graphics/ImageDecodingStore.h" | 30 #include "platform/graphics/ImageDecodingStore.h" |
31 #include "platform/image-decoders/ImageDecoder.h" | 31 #include "platform/image-decoders/ImageDecoder.h" |
32 #include "third_party/skia/include/core/SkYUVSizeInfo.h" | 32 #include "third_party/skia/include/core/SkYUVSizeInfo.h" |
33 #include "wtf/PtrUtil.h" | |
34 #include <memory> | |
35 | 33 |
36 namespace blink { | 34 namespace blink { |
37 | 35 |
38 static bool compatibleInfo(const SkImageInfo& src, const SkImageInfo& dst) | 36 static bool compatibleInfo(const SkImageInfo& src, const SkImageInfo& dst) |
39 { | 37 { |
40 if (src == dst) | 38 if (src == dst) |
41 return true; | 39 return true; |
42 | 40 |
43 // It is legal to write kOpaque_SkAlphaType pixels into a kPremul_SkAlphaTyp
e buffer. | 41 // It is legal to write kOpaque_SkAlphaType pixels into a kPremul_SkAlphaTyp
e buffer. |
44 // This can happen when DeferredImageDecoder allocates an kOpaque_SkAlphaTyp
e image | 42 // This can happen when DeferredImageDecoder allocates an kOpaque_SkAlphaTyp
e image |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 if (m_decodeFailed) | 151 if (m_decodeFailed) |
154 return false; | 152 return false; |
155 | 153 |
156 TRACE_EVENT1("blink", "ImageFrameGenerator::decodeToYUV", "frame index", sta
tic_cast<int>(index)); | 154 TRACE_EVENT1("blink", "ImageFrameGenerator::decodeToYUV", "frame index", sta
tic_cast<int>(index)); |
157 | 155 |
158 if (!planes || !planes[0] || !planes[1] || !planes[2] | 156 if (!planes || !planes[0] || !planes[1] || !planes[2] |
159 || !rowBytes || !rowBytes[0] || !rowBytes[1] || !rowBytes[2]) { | 157 || !rowBytes || !rowBytes[0] || !rowBytes[1] || !rowBytes[2]) { |
160 return false; | 158 return false; |
161 } | 159 } |
162 | 160 |
163 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageDec
oder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied); | 161 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageDecoder::Alp
haPremultiplied, ImageDecoder::GammaAndColorProfileApplied); |
164 // getYUVComponentSizes was already called and was successful, so ImageDecod
er::create must succeed. | 162 // getYUVComponentSizes was already called and was successful, so ImageDecod
er::create must succeed. |
165 ASSERT(decoder); | 163 ASSERT(decoder); |
166 | 164 |
167 decoder->setData(data, true); | 165 decoder->setData(data, true); |
168 | 166 |
169 std::unique_ptr<ImagePlanes> imagePlanes = wrapUnique(new ImagePlanes(planes
, rowBytes)); | 167 OwnPtr<ImagePlanes> imagePlanes = adoptPtr(new ImagePlanes(planes, rowBytes)
); |
170 decoder->setImagePlanes(std::move(imagePlanes)); | 168 decoder->setImagePlanes(std::move(imagePlanes)); |
171 | 169 |
172 ASSERT(decoder->canDecodeToYUV()); | 170 ASSERT(decoder->canDecodeToYUV()); |
173 | 171 |
174 if (decoder->decodeToYUV()) { | 172 if (decoder->decodeToYUV()) { |
175 setHasAlpha(0, false); // YUV is always opaque | 173 setHasAlpha(0, false); // YUV is always opaque |
176 return true; | 174 return true; |
177 } | 175 } |
178 | 176 |
179 ASSERT(decoder->failed()); | 177 ASSERT(decoder->failed()); |
(...skipping 14 matching lines...) Expand all Loading... |
194 | 192 |
195 SkBitmap fullSizeImage; | 193 SkBitmap fullSizeImage; |
196 bool complete = decode(data, allDataReceived, index, &decoder, &fullSizeImag
e, allocator); | 194 bool complete = decode(data, allDataReceived, index, &decoder, &fullSizeImag
e, allocator); |
197 | 195 |
198 if (!decoder) | 196 if (!decoder) |
199 return SkBitmap(); | 197 return SkBitmap(); |
200 | 198 |
201 // If we are not resuming decoding that means the decoder is freshly | 199 // If we are not resuming decoding that means the decoder is freshly |
202 // created and we have ownership. If we are resuming decoding then | 200 // created and we have ownership. If we are resuming decoding then |
203 // the decoder is owned by ImageDecodingStore. | 201 // the decoder is owned by ImageDecodingStore. |
204 std::unique_ptr<ImageDecoder> decoderContainer; | 202 OwnPtr<ImageDecoder> decoderContainer; |
205 if (!resumeDecoding) | 203 if (!resumeDecoding) |
206 decoderContainer = wrapUnique(decoder); | 204 decoderContainer = adoptPtr(decoder); |
207 | 205 |
208 if (fullSizeImage.isNull()) { | 206 if (fullSizeImage.isNull()) { |
209 // If decoding has failed, we can save work in the future by | 207 // If decoding has failed, we can save work in the future by |
210 // ignoring further requests to decode the image. | 208 // ignoring further requests to decode the image. |
211 m_decodeFailed = decoder->failed(); | 209 m_decodeFailed = decoder->failed(); |
212 if (resumeDecoding) | 210 if (resumeDecoding) |
213 ImageDecodingStore::instance().unlockDecoder(this, decoder); | 211 ImageDecodingStore::instance().unlockDecoder(this, decoder); |
214 return SkBitmap(); | 212 return SkBitmap(); |
215 } | 213 } |
216 | 214 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 { | 255 { |
258 ASSERT(m_decodeMutex.locked()); | 256 ASSERT(m_decodeMutex.locked()); |
259 TRACE_EVENT2("blink", "ImageFrameGenerator::decode", "width", m_fullSize.wid
th(), "height", m_fullSize.height()); | 257 TRACE_EVENT2("blink", "ImageFrameGenerator::decode", "width", m_fullSize.wid
th(), "height", m_fullSize.height()); |
260 | 258 |
261 // Try to create an ImageDecoder if we are not given one. | 259 // Try to create an ImageDecoder if we are not given one. |
262 ASSERT(decoder); | 260 ASSERT(decoder); |
263 bool newDecoder = false; | 261 bool newDecoder = false; |
264 if (!*decoder) { | 262 if (!*decoder) { |
265 newDecoder = true; | 263 newDecoder = true; |
266 if (m_imageDecoderFactory) | 264 if (m_imageDecoderFactory) |
267 *decoder = m_imageDecoderFactory->create().release(); | 265 *decoder = m_imageDecoderFactory->create().leakPtr(); |
268 | 266 |
269 if (!*decoder) | 267 if (!*decoder) |
270 *decoder = ImageDecoder::create(*data, ImageDecoder::AlphaPremultipl
ied, ImageDecoder::GammaAndColorProfileApplied).release(); | 268 *decoder = ImageDecoder::create(*data, ImageDecoder::AlphaPremultipl
ied, ImageDecoder::GammaAndColorProfileApplied).leakPtr(); |
271 | 269 |
272 if (!*decoder) | 270 if (!*decoder) |
273 return false; | 271 return false; |
274 } | 272 } |
275 | 273 |
276 if (!m_isMultiFrame && newDecoder && allDataReceived) { | 274 if (!m_isMultiFrame && newDecoder && allDataReceived) { |
277 // If we're using an external memory allocator that means we're decoding | 275 // 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. | 276 // directly into the output memory and we can save one memcpy. |
279 ASSERT(allocator); | 277 ASSERT(allocator); |
280 (*decoder)->setMemoryAllocator(allocator); | 278 (*decoder)->setMemoryAllocator(allocator); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 return true; | 318 return true; |
321 } | 319 } |
322 | 320 |
323 bool ImageFrameGenerator::getYUVComponentSizes(SegmentReader* data, SkYUVSizeInf
o* sizeInfo) | 321 bool ImageFrameGenerator::getYUVComponentSizes(SegmentReader* data, SkYUVSizeInf
o* sizeInfo) |
324 { | 322 { |
325 TRACE_EVENT2("blink", "ImageFrameGenerator::getYUVComponentSizes", "width",
m_fullSize.width(), "height", m_fullSize.height()); | 323 TRACE_EVENT2("blink", "ImageFrameGenerator::getYUVComponentSizes", "width",
m_fullSize.width(), "height", m_fullSize.height()); |
326 | 324 |
327 if (m_yuvDecodingFailed) | 325 if (m_yuvDecodingFailed) |
328 return false; | 326 return false; |
329 | 327 |
330 std::unique_ptr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageDec
oder::AlphaPremultiplied, ImageDecoder::GammaAndColorProfileApplied); | 328 OwnPtr<ImageDecoder> decoder = ImageDecoder::create(*data, ImageDecoder::Alp
haPremultiplied, ImageDecoder::GammaAndColorProfileApplied); |
331 if (!decoder) | 329 if (!decoder) |
332 return false; | 330 return false; |
333 | 331 |
334 // Setting a dummy ImagePlanes object signals to the decoder that we want to
do YUV decoding. | 332 // Setting a dummy ImagePlanes object signals to the decoder that we want to
do YUV decoding. |
335 decoder->setData(data, true); | 333 decoder->setData(data, true); |
336 std::unique_ptr<ImagePlanes> dummyImagePlanes = wrapUnique(new ImagePlanes); | 334 OwnPtr<ImagePlanes> dummyImagePlanes = adoptPtr(new ImagePlanes); |
337 decoder->setImagePlanes(std::move(dummyImagePlanes)); | 335 decoder->setImagePlanes(std::move(dummyImagePlanes)); |
338 | 336 |
339 return updateYUVComponentSizes(decoder.get(), sizeInfo->fSizes, sizeInfo->fW
idthBytes); | 337 return updateYUVComponentSizes(decoder.get(), sizeInfo->fSizes, sizeInfo->fW
idthBytes); |
340 } | 338 } |
341 | 339 |
342 } // namespace blink | 340 } // namespace blink |
OLD | NEW |