| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 std::unique_ptr<DeferredImageDecoder> DeferredImageDecoder::createForTesting( | 83 std::unique_ptr<DeferredImageDecoder> DeferredImageDecoder::createForTesting( |
| 84 std::unique_ptr<ImageDecoder> actualDecoder) { | 84 std::unique_ptr<ImageDecoder> actualDecoder) { |
| 85 return wrapUnique(new DeferredImageDecoder(std::move(actualDecoder))); | 85 return wrapUnique(new DeferredImageDecoder(std::move(actualDecoder))); |
| 86 } | 86 } |
| 87 | 87 |
| 88 DeferredImageDecoder::DeferredImageDecoder( | 88 DeferredImageDecoder::DeferredImageDecoder( |
| 89 std::unique_ptr<ImageDecoder> actualDecoder) | 89 std::unique_ptr<ImageDecoder> actualDecoder) |
| 90 : m_allDataReceived(false), | 90 : m_allDataReceived(false), |
| 91 m_actualDecoder(std::move(actualDecoder)), | 91 m_actualDecoder(std::move(actualDecoder)), |
| 92 m_repetitionCount(cAnimationNone), | 92 m_repetitionCount(cAnimationNone), |
| 93 m_hasColorSpace(false), | |
| 94 m_canYUVDecode(false), | 93 m_canYUVDecode(false), |
| 95 m_hasHotSpot(false) {} | 94 m_hasHotSpot(false) {} |
| 96 | 95 |
| 97 DeferredImageDecoder::~DeferredImageDecoder() {} | 96 DeferredImageDecoder::~DeferredImageDecoder() {} |
| 98 | 97 |
| 99 String DeferredImageDecoder::filenameExtension() const { | 98 String DeferredImageDecoder::filenameExtension() const { |
| 100 return m_actualDecoder ? m_actualDecoder->filenameExtension() | 99 return m_actualDecoder ? m_actualDecoder->filenameExtension() |
| 101 : m_filenameExtension; | 100 : m_filenameExtension; |
| 102 } | 101 } |
| 103 | 102 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 } | 171 } |
| 173 } | 172 } |
| 174 } | 173 } |
| 175 | 174 |
| 176 bool DeferredImageDecoder::isSizeAvailable() { | 175 bool DeferredImageDecoder::isSizeAvailable() { |
| 177 // m_actualDecoder is 0 only if image decoding is deferred and that means | 176 // m_actualDecoder is 0 only if image decoding is deferred and that means |
| 178 // the image header decoded successfully and the size is available. | 177 // the image header decoded successfully and the size is available. |
| 179 return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true; | 178 return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true; |
| 180 } | 179 } |
| 181 | 180 |
| 182 bool DeferredImageDecoder::hasColorSpace() const { | 181 bool DeferredImageDecoder::hasEmbeddedColorSpace() const { |
| 183 return m_actualDecoder ? m_actualDecoder->hasColorSpace() : m_hasColorSpace; | 182 return m_actualDecoder ? m_actualDecoder->hasEmbeddedColorSpace() |
| 183 : m_hasEmbeddedColorSpace; |
| 184 } | 184 } |
| 185 | 185 |
| 186 IntSize DeferredImageDecoder::size() const { | 186 IntSize DeferredImageDecoder::size() const { |
| 187 return m_actualDecoder ? m_actualDecoder->size() : m_size; | 187 return m_actualDecoder ? m_actualDecoder->size() : m_size; |
| 188 } | 188 } |
| 189 | 189 |
| 190 IntSize DeferredImageDecoder::frameSizeAtIndex(size_t index) const { | 190 IntSize DeferredImageDecoder::frameSizeAtIndex(size_t index) const { |
| 191 // FIXME: LocalFrame size is assumed to be uniform. This might not be true for | 191 // FIXME: LocalFrame size is assumed to be uniform. This might not be true for |
| 192 // future supported codecs. | 192 // future supported codecs. |
| 193 return m_actualDecoder ? m_actualDecoder->frameSizeAtIndex(index) : m_size; | 193 return m_actualDecoder ? m_actualDecoder->frameSizeAtIndex(index) : m_size; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 if (m_frameGenerator) | 259 if (m_frameGenerator) |
| 260 return; | 260 return; |
| 261 | 261 |
| 262 m_size = m_actualDecoder->size(); | 262 m_size = m_actualDecoder->size(); |
| 263 m_hasHotSpot = m_actualDecoder->hotSpot(m_hotSpot); | 263 m_hasHotSpot = m_actualDecoder->hotSpot(m_hotSpot); |
| 264 m_filenameExtension = m_actualDecoder->filenameExtension(); | 264 m_filenameExtension = m_actualDecoder->filenameExtension(); |
| 265 // JPEG images support YUV decoding; other decoders do not. (WebP could in the | 265 // JPEG images support YUV decoding; other decoders do not. (WebP could in the |
| 266 // future.) | 266 // future.) |
| 267 m_canYUVDecode = RuntimeEnabledFeatures::decodeToYUVEnabled() && | 267 m_canYUVDecode = RuntimeEnabledFeatures::decodeToYUVEnabled() && |
| 268 (m_filenameExtension == "jpg"); | 268 (m_filenameExtension == "jpg"); |
| 269 m_hasColorSpace = m_actualDecoder->hasColorSpace(); | 269 m_hasEmbeddedColorSpace = m_actualDecoder->hasEmbeddedColorSpace(); |
| 270 | 270 |
| 271 const bool isSingleFrame = | 271 const bool isSingleFrame = |
| 272 m_actualDecoder->repetitionCount() == cAnimationNone || | 272 m_actualDecoder->repetitionCount() == cAnimationNone || |
| 273 (m_allDataReceived && m_actualDecoder->frameCount() == 1u); | 273 (m_allDataReceived && m_actualDecoder->frameCount() == 1u); |
| 274 const SkISize decodedSize = | 274 const SkISize decodedSize = |
| 275 SkISize::Make(m_actualDecoder->decodedSize().width(), | 275 SkISize::Make(m_actualDecoder->decodedSize().width(), |
| 276 m_actualDecoder->decodedSize().height()); | 276 m_actualDecoder->decodedSize().height()); |
| 277 m_frameGenerator = ImageFrameGenerator::create(decodedSize, !isSingleFrame); | 277 m_frameGenerator = ImageFrameGenerator::create( |
| 278 decodedSize, m_actualDecoder->colorSpace(), !isSingleFrame); |
| 278 } | 279 } |
| 279 | 280 |
| 280 void DeferredImageDecoder::prepareLazyDecodedFrames() { | 281 void DeferredImageDecoder::prepareLazyDecodedFrames() { |
| 281 if (!m_actualDecoder || !m_actualDecoder->isSizeAvailable()) | 282 if (!m_actualDecoder || !m_actualDecoder->isSizeAvailable()) |
| 282 return; | 283 return; |
| 283 | 284 |
| 284 activateLazyDecoding(); | 285 activateLazyDecoding(); |
| 285 | 286 |
| 286 const size_t previousSize = m_frameData.size(); | 287 const size_t previousSize = m_frameData.size(); |
| 287 m_frameData.resize(m_actualDecoder->frameCount()); | 288 m_frameData.resize(m_actualDecoder->frameCount()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 304 m_actualDecoder->frameIsCompleteAtIndex(lastFrame); | 305 m_actualDecoder->frameIsCompleteAtIndex(lastFrame); |
| 305 } | 306 } |
| 306 | 307 |
| 307 if (m_allDataReceived) { | 308 if (m_allDataReceived) { |
| 308 m_repetitionCount = m_actualDecoder->repetitionCount(); | 309 m_repetitionCount = m_actualDecoder->repetitionCount(); |
| 309 m_actualDecoder.reset(); | 310 m_actualDecoder.reset(); |
| 310 // Hold on to m_rwBuffer, which is still needed by createFrameAtIndex. | 311 // Hold on to m_rwBuffer, which is still needed by createFrameAtIndex. |
| 311 } | 312 } |
| 312 } | 313 } |
| 313 | 314 |
| 314 inline SkImageInfo imageInfoFrom(const SkISize& decodedSize, | |
| 315 bool knownToBeOpaque) { | |
| 316 return SkImageInfo::MakeN32( | |
| 317 decodedSize.width(), decodedSize.height(), | |
| 318 knownToBeOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | |
| 319 } | |
| 320 | |
| 321 sk_sp<SkImage> DeferredImageDecoder::createFrameImageAtIndex( | 315 sk_sp<SkImage> DeferredImageDecoder::createFrameImageAtIndex( |
| 322 size_t index, | 316 size_t index, |
| 323 bool knownToBeOpaque) { | 317 bool knownToBeOpaque) { |
| 324 const SkISize& decodedSize = m_frameGenerator->getFullSize(); | 318 const SkISize& decodedSize = m_frameGenerator->getFullSize(); |
| 325 ASSERT(decodedSize.width() > 0); | 319 ASSERT(decodedSize.width() > 0); |
| 326 ASSERT(decodedSize.height() > 0); | 320 ASSERT(decodedSize.height() > 0); |
| 327 | 321 |
| 328 sk_sp<SkROBuffer> roBuffer(m_rwBuffer->newRBufferSnapshot()); | 322 sk_sp<SkROBuffer> roBuffer(m_rwBuffer->newRBufferSnapshot()); |
| 329 RefPtr<SegmentReader> segmentReader = | 323 RefPtr<SegmentReader> segmentReader = |
| 330 SegmentReader::createFromSkROBuffer(std::move(roBuffer)); | 324 SegmentReader::createFromSkROBuffer(std::move(roBuffer)); |
| 325 |
| 326 SkImageInfo info = SkImageInfo::MakeN32( |
| 327 decodedSize.width(), decodedSize.height(), |
| 328 knownToBeOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType, |
| 329 m_frameGenerator->getColorSpace()); |
| 330 |
| 331 DecodingImageGenerator* generator = new DecodingImageGenerator( | 331 DecodingImageGenerator* generator = new DecodingImageGenerator( |
| 332 m_frameGenerator, imageInfoFrom(decodedSize, knownToBeOpaque), | 332 m_frameGenerator, info, segmentReader.release(), m_allDataReceived, index, |
| 333 segmentReader.release(), m_allDataReceived, index, | |
| 334 m_frameData[index].m_uniqueID); | 333 m_frameData[index].m_uniqueID); |
| 335 sk_sp<SkImage> image = SkImage::MakeFromGenerator( | 334 sk_sp<SkImage> image = SkImage::MakeFromGenerator( |
| 336 generator); // SkImage takes ownership of the generator. | 335 generator); // SkImage takes ownership of the generator. |
| 337 if (!image) | 336 if (!image) |
| 338 return nullptr; | 337 return nullptr; |
| 339 | 338 |
| 340 // We can consider decoded bitmap constant and reuse uniqueID only after all | 339 // We can consider decoded bitmap constant and reuse uniqueID only after all |
| 341 // data is received. We reuse it also for multiframe images when image data | 340 // data is received. We reuse it also for multiframe images when image data |
| 342 // is partially received but the frame data is fully received. | 341 // is partially received but the frame data is fully received. |
| 343 if (m_allDataReceived || m_frameData[index].m_isComplete) { | 342 if (m_allDataReceived || m_frameData[index].m_isComplete) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 364 | 363 |
| 365 namespace WTF { | 364 namespace WTF { |
| 366 template <> | 365 template <> |
| 367 struct VectorTraits<blink::DeferredFrameData> | 366 struct VectorTraits<blink::DeferredFrameData> |
| 368 : public SimpleClassVectorTraits<blink::DeferredFrameData> { | 367 : public SimpleClassVectorTraits<blink::DeferredFrameData> { |
| 369 STATIC_ONLY(VectorTraits); | 368 STATIC_ONLY(VectorTraits); |
| 370 static const bool canInitializeWithMemset = | 369 static const bool canInitializeWithMemset = |
| 371 false; // Not all DeferredFrameData members initialize to 0. | 370 false; // Not all DeferredFrameData members initialize to 0. |
| 372 }; | 371 }; |
| 373 } | 372 } |
| OLD | NEW |