| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 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/DeferredImageDecoder.h" | 26 #include "platform/graphics/DeferredImageDecoder.h" |
| 27 | 27 |
| 28 #include "platform/RuntimeEnabledFeatures.h" | 28 #include "platform/RuntimeEnabledFeatures.h" |
| 29 #include "platform/SharedBuffer.h" | |
| 30 #include "platform/graphics/DecodingImageGenerator.h" | 29 #include "platform/graphics/DecodingImageGenerator.h" |
| 31 #include "platform/graphics/FrameData.h" | 30 #include "platform/graphics/FrameData.h" |
| 32 #include "platform/graphics/ImageDecodingStore.h" | 31 #include "platform/graphics/ImageDecodingStore.h" |
| 33 #include "platform/graphics/ImageFrameGenerator.h" | 32 #include "platform/graphics/ImageFrameGenerator.h" |
| 34 #include "platform/image-decoders/SegmentReader.h" | |
| 35 #include "third_party/skia/include/core/SkImage.h" | 33 #include "third_party/skia/include/core/SkImage.h" |
| 36 #include "wtf/PassOwnPtr.h" | 34 #include "wtf/PassOwnPtr.h" |
| 37 | 35 |
| 38 namespace blink { | 36 namespace blink { |
| 39 | 37 |
| 40 bool DeferredImageDecoder::s_enabled = true; | 38 bool DeferredImageDecoder::s_enabled = true; |
| 41 | 39 |
| 42 PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::create(const SharedBuffer
& data, ImageDecoder::AlphaOption alphaOption, ImageDecoder::GammaAndColorProfil
eOption colorOptions) | 40 PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::create(const SharedBuffer
& data, ImageDecoder::AlphaOption alphaOption, ImageDecoder::GammaAndColorProfil
eOption colorOptions) |
| 43 { | 41 { |
| 44 OwnPtr<ImageDecoder> actualDecoder = ImageDecoder::create(data, alphaOption,
colorOptions); | 42 OwnPtr<ImageDecoder> actualDecoder = ImageDecoder::create(data, alphaOption,
colorOptions); |
| 45 | 43 |
| 46 if (!actualDecoder) | 44 if (!actualDecoder) |
| 47 return nullptr; | 45 return nullptr; |
| 48 | 46 |
| 49 return adoptPtr(new DeferredImageDecoder(actualDecoder.release())); | 47 return adoptPtr(new DeferredImageDecoder(actualDecoder.release())); |
| 50 } | 48 } |
| 51 | 49 |
| 52 PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::createForTesting(PassOwnP
tr<ImageDecoder> actualDecoder) | 50 PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::createForTesting(PassOwnP
tr<ImageDecoder> actualDecoder) |
| 53 { | 51 { |
| 54 return adoptPtr(new DeferredImageDecoder(std::move(actualDecoder))); | 52 return adoptPtr(new DeferredImageDecoder(std::move(actualDecoder))); |
| 55 } | 53 } |
| 56 | 54 |
| 57 DeferredImageDecoder::DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecode
r) | 55 DeferredImageDecoder::DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecode
r) |
| 58 : m_allDataReceived(false) | 56 : m_allDataReceived(false) |
| 57 , m_lastDataSize(0) |
| 59 , m_actualDecoder(std::move(actualDecoder)) | 58 , m_actualDecoder(std::move(actualDecoder)) |
| 60 , m_repetitionCount(cAnimationNone) | 59 , m_repetitionCount(cAnimationNone) |
| 61 , m_hasColorProfile(false) | 60 , m_hasColorProfile(false) |
| 62 , m_canYUVDecode(false) | 61 , m_canYUVDecode(false) |
| 63 { | 62 { |
| 64 } | 63 } |
| 65 | 64 |
| 66 DeferredImageDecoder::~DeferredImageDecoder() | 65 DeferredImageDecoder::~DeferredImageDecoder() |
| 67 { | 66 { |
| 68 } | 67 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 ImageFrame* frame = m_actualDecoder->frameBufferAtIndex(index); | 104 ImageFrame* frame = m_actualDecoder->frameBufferAtIndex(index); |
| 106 if (!frame || frame->getStatus() == ImageFrame::FrameEmpty) | 105 if (!frame || frame->getStatus() == ImageFrame::FrameEmpty) |
| 107 return nullptr; | 106 return nullptr; |
| 108 | 107 |
| 109 return adoptRef(SkImage::NewFromBitmap(frame->bitmap())); | 108 return adoptRef(SkImage::NewFromBitmap(frame->bitmap())); |
| 110 } | 109 } |
| 111 | 110 |
| 112 void DeferredImageDecoder::setData(SharedBuffer& data, bool allDataReceived) | 111 void DeferredImageDecoder::setData(SharedBuffer& data, bool allDataReceived) |
| 113 { | 112 { |
| 114 if (m_actualDecoder) { | 113 if (m_actualDecoder) { |
| 114 m_data = RefPtr<SharedBuffer>(data); |
| 115 m_lastDataSize = data.size(); |
| 115 m_allDataReceived = allDataReceived; | 116 m_allDataReceived = allDataReceived; |
| 116 m_actualDecoder->setData(&data, allDataReceived); | 117 m_actualDecoder->setData(&data, allDataReceived); |
| 117 prepareLazyDecodedFrames(); | 118 prepareLazyDecodedFrames(); |
| 118 } | 119 } |
| 119 | 120 |
| 120 if (m_frameGenerator) { | 121 if (m_frameGenerator) |
| 121 if (!m_rwBuffer) | 122 m_frameGenerator->setData(&data, allDataReceived); |
| 122 m_rwBuffer = adoptPtr(new SkRWBuffer(data.size())); | |
| 123 | |
| 124 const char* segment = 0; | |
| 125 for (size_t length = data.getSomeData(segment, m_rwBuffer->size()); | |
| 126 length; length = data.getSomeData(segment, m_rwBuffer->size())) | |
| 127 m_rwBuffer->append(segment, length); | |
| 128 } | |
| 129 } | 123 } |
| 130 | 124 |
| 131 bool DeferredImageDecoder::isSizeAvailable() | 125 bool DeferredImageDecoder::isSizeAvailable() |
| 132 { | 126 { |
| 133 // m_actualDecoder is 0 only if image decoding is deferred and that means | 127 // m_actualDecoder is 0 only if image decoding is deferred and that means |
| 134 // the image header decoded successfully and the size is available. | 128 // the image header decoded successfully and the size is available. |
| 135 return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true; | 129 return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true; |
| 136 } | 130 } |
| 137 | 131 |
| 138 bool DeferredImageDecoder::hasColorProfile() const | 132 bool DeferredImageDecoder::hasColorProfile() const |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 if (m_frameGenerator) | 220 if (m_frameGenerator) |
| 227 return; | 221 return; |
| 228 | 222 |
| 229 m_size = m_actualDecoder->size(); | 223 m_size = m_actualDecoder->size(); |
| 230 m_filenameExtension = m_actualDecoder->filenameExtension(); | 224 m_filenameExtension = m_actualDecoder->filenameExtension(); |
| 231 // JPEG images support YUV decoding: other decoders do not, WEBP could in fu
ture. | 225 // JPEG images support YUV decoding: other decoders do not, WEBP could in fu
ture. |
| 232 m_canYUVDecode = RuntimeEnabledFeatures::decodeToYUVEnabled() && (m_filename
Extension == "jpg"); | 226 m_canYUVDecode = RuntimeEnabledFeatures::decodeToYUVEnabled() && (m_filename
Extension == "jpg"); |
| 233 m_hasColorProfile = m_actualDecoder->hasColorProfile(); | 227 m_hasColorProfile = m_actualDecoder->hasColorProfile(); |
| 234 | 228 |
| 235 const bool isSingleFrame = m_actualDecoder->repetitionCount() == cAnimationN
one || (m_allDataReceived && m_actualDecoder->frameCount() == 1u); | 229 const bool isSingleFrame = m_actualDecoder->repetitionCount() == cAnimationN
one || (m_allDataReceived && m_actualDecoder->frameCount() == 1u); |
| 236 const SkISize decodedSize = SkISize::Make(m_actualDecoder->decodedSize().wid
th(), m_actualDecoder->decodedSize().height()); | 230 m_frameGenerator = ImageFrameGenerator::create(SkISize::Make(m_actualDecoder
->decodedSize().width(), m_actualDecoder->decodedSize().height()), m_data, m_all
DataReceived, !isSingleFrame); |
| 237 m_frameGenerator = ImageFrameGenerator::create(decodedSize, !isSingleFrame); | |
| 238 } | 231 } |
| 239 | 232 |
| 240 void DeferredImageDecoder::prepareLazyDecodedFrames() | 233 void DeferredImageDecoder::prepareLazyDecodedFrames() |
| 241 { | 234 { |
| 242 if (!s_enabled | 235 if (!s_enabled |
| 243 || !m_actualDecoder | 236 || !m_actualDecoder |
| 244 || !m_actualDecoder->isSizeAvailable() | 237 || !m_actualDecoder->isSizeAvailable() |
| 245 || m_actualDecoder->filenameExtension() == "ico") | 238 || m_actualDecoder->filenameExtension() == "ico") |
| 246 return; | 239 return; |
| 247 | 240 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 264 // The last lazy decoded frame created from previous call might be | 257 // The last lazy decoded frame created from previous call might be |
| 265 // incomplete so update its state. | 258 // incomplete so update its state. |
| 266 if (previousSize) { | 259 if (previousSize) { |
| 267 const size_t lastFrame = previousSize - 1; | 260 const size_t lastFrame = previousSize - 1; |
| 268 m_frameData[lastFrame].m_isComplete = m_actualDecoder->frameIsCompleteAt
Index(lastFrame); | 261 m_frameData[lastFrame].m_isComplete = m_actualDecoder->frameIsCompleteAt
Index(lastFrame); |
| 269 } | 262 } |
| 270 | 263 |
| 271 if (m_allDataReceived) { | 264 if (m_allDataReceived) { |
| 272 m_repetitionCount = m_actualDecoder->repetitionCount(); | 265 m_repetitionCount = m_actualDecoder->repetitionCount(); |
| 273 m_actualDecoder.clear(); | 266 m_actualDecoder.clear(); |
| 274 // Hold on to m_rwBuffer, which is still needed by createFrameAtIndex. | 267 m_data = nullptr; |
| 275 } | 268 } |
| 276 } | 269 } |
| 277 | 270 |
| 278 inline SkImageInfo imageInfoFrom(const SkISize& decodedSize, bool knownToBeOpaqu
e) | 271 inline SkImageInfo imageInfoFrom(const SkISize& decodedSize, bool knownToBeOpaqu
e) |
| 279 { | 272 { |
| 280 return SkImageInfo::MakeN32(decodedSize.width(), decodedSize.height(), known
ToBeOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 273 return SkImageInfo::MakeN32(decodedSize.width(), decodedSize.height(), known
ToBeOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 281 } | 274 } |
| 282 | 275 |
| 283 PassRefPtr<SkImage> DeferredImageDecoder::createFrameImageAtIndex(size_t index,
bool knownToBeOpaque) const | 276 PassRefPtr<SkImage> DeferredImageDecoder::createFrameImageAtIndex(size_t index,
bool knownToBeOpaque) const |
| 284 { | 277 { |
| 285 const SkISize& decodedSize = m_frameGenerator->getFullSize(); | 278 const SkISize& decodedSize = m_frameGenerator->getFullSize(); |
| 286 ASSERT(decodedSize.width() > 0); | 279 ASSERT(decodedSize.width() > 0); |
| 287 ASSERT(decodedSize.height() > 0); | 280 ASSERT(decodedSize.height() > 0); |
| 288 | 281 |
| 289 RefPtr<SkROBuffer> roBuffer = adoptRef(m_rwBuffer->newRBufferSnapshot()); | 282 DecodingImageGenerator* generator = new DecodingImageGenerator(m_frameGenera
tor, imageInfoFrom(decodedSize, knownToBeOpaque), index); |
| 290 RefPtr<SegmentReader> segmentReader = SegmentReader::createFromSkROBuffer(ro
Buffer.release()); | |
| 291 DecodingImageGenerator* generator = new DecodingImageGenerator(m_frameGenera
tor, imageInfoFrom(decodedSize, knownToBeOpaque), segmentReader.release(), m_all
DataReceived, index); | |
| 292 RefPtr<SkImage> image = adoptRef(SkImage::NewFromGenerator(generator)); // S
kImage takes ownership of the generator. | 283 RefPtr<SkImage> image = adoptRef(SkImage::NewFromGenerator(generator)); // S
kImage takes ownership of the generator. |
| 293 if (!image) | 284 if (!image) |
| 294 return nullptr; | 285 return nullptr; |
| 295 | 286 |
| 296 generator->setGenerationId(image->uniqueID()); | 287 generator->setGenerationId(image->uniqueID()); |
| 297 generator->setCanYUVDecode(m_canYUVDecode); | 288 generator->setCanYUVDecode(m_canYUVDecode); |
| 298 | 289 |
| 299 return image.release(); | 290 return image.release(); |
| 300 } | 291 } |
| 301 | 292 |
| 302 bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const | 293 bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const |
| 303 { | 294 { |
| 304 // TODO: Implement. | 295 // TODO: Implement. |
| 305 return m_actualDecoder ? m_actualDecoder->hotSpot(hotSpot) : false; | 296 return m_actualDecoder ? m_actualDecoder->hotSpot(hotSpot) : false; |
| 306 } | 297 } |
| 307 | 298 |
| 308 } // namespace blink | 299 } // namespace blink |
| OLD | NEW |