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