Chromium Code Reviews| 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" | |
| 29 #include "platform/graphics/DecodingImageGenerator.h" | 30 #include "platform/graphics/DecodingImageGenerator.h" |
| 30 #include "platform/graphics/FrameData.h" | 31 #include "platform/graphics/FrameData.h" |
| 31 #include "platform/graphics/ImageDecodingStore.h" | 32 #include "platform/graphics/ImageDecodingStore.h" |
| 32 #include "platform/graphics/ImageFrameGenerator.h" | 33 #include "platform/graphics/ImageFrameGenerator.h" |
| 34 #include "platform/image-decoders/ROBufferSegmentReader.h" | |
| 35 #include "platform/image-decoders/SharedBufferSegmentReader.h" | |
| 33 #include "third_party/skia/include/core/SkImage.h" | 36 #include "third_party/skia/include/core/SkImage.h" |
| 34 #include "wtf/PassOwnPtr.h" | 37 #include "wtf/PassOwnPtr.h" |
| 35 | 38 |
| 36 namespace blink { | 39 namespace blink { |
| 37 | 40 |
| 38 bool DeferredImageDecoder::s_enabled = true; | 41 bool DeferredImageDecoder::s_enabled = true; |
| 39 | 42 |
| 40 PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::create(const SharedBuffer & data, ImageDecoder::AlphaOption alphaOption, ImageDecoder::GammaAndColorProfil eOption colorOptions) | 43 PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::create(const SharedBuffer & data, ImageDecoder::AlphaOption alphaOption, ImageDecoder::GammaAndColorProfil eOption colorOptions) |
| 41 { | 44 { |
| 42 OwnPtr<ImageDecoder> actualDecoder = ImageDecoder::create(data, alphaOption, colorOptions); | 45 OwnPtr<ImageDecoder> actualDecoder = ImageDecoder::create(data, alphaOption, colorOptions); |
| 43 | 46 |
| 44 if (!actualDecoder) | 47 if (!actualDecoder) |
| 45 return nullptr; | 48 return nullptr; |
| 46 | 49 |
| 47 return adoptPtr(new DeferredImageDecoder(actualDecoder.release())); | 50 return adoptPtr(new DeferredImageDecoder(actualDecoder.release())); |
| 48 } | 51 } |
| 49 | 52 |
| 50 PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::createForTesting(PassOwnP tr<ImageDecoder> actualDecoder) | 53 PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::createForTesting(PassOwnP tr<ImageDecoder> actualDecoder) |
| 51 { | 54 { |
| 52 return adoptPtr(new DeferredImageDecoder(std::move(actualDecoder))); | 55 return adoptPtr(new DeferredImageDecoder(std::move(actualDecoder))); |
| 53 } | 56 } |
| 54 | 57 |
| 55 DeferredImageDecoder::DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecode r) | 58 DeferredImageDecoder::DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecode r) |
| 56 : m_allDataReceived(false) | 59 : m_allDataReceived(false) |
| 57 , m_lastDataSize(0) | |
| 58 , m_actualDecoder(std::move(actualDecoder)) | 60 , m_actualDecoder(std::move(actualDecoder)) |
| 59 , m_repetitionCount(cAnimationNone) | 61 , m_repetitionCount(cAnimationNone) |
| 60 , m_hasColorProfile(false) | 62 , m_hasColorProfile(false) |
| 61 , m_canYUVDecode(false) | 63 , m_canYUVDecode(false) |
| 62 { | 64 { |
| 63 } | 65 } |
| 64 | 66 |
| 65 DeferredImageDecoder::~DeferredImageDecoder() | 67 DeferredImageDecoder::~DeferredImageDecoder() |
| 66 { | 68 { |
| 67 } | 69 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 ImageFrame* frame = m_actualDecoder->frameBufferAtIndex(index); | 106 ImageFrame* frame = m_actualDecoder->frameBufferAtIndex(index); |
| 105 if (!frame || frame->status() == ImageFrame::FrameEmpty) | 107 if (!frame || frame->status() == ImageFrame::FrameEmpty) |
| 106 return nullptr; | 108 return nullptr; |
| 107 | 109 |
| 108 return adoptRef(SkImage::NewFromBitmap(frame->bitmap())); | 110 return adoptRef(SkImage::NewFromBitmap(frame->bitmap())); |
| 109 } | 111 } |
| 110 | 112 |
| 111 void DeferredImageDecoder::setData(SharedBuffer& data, bool allDataReceived) | 113 void DeferredImageDecoder::setData(SharedBuffer& data, bool allDataReceived) |
| 112 { | 114 { |
| 113 if (m_actualDecoder) { | 115 if (m_actualDecoder) { |
| 114 m_data = RefPtr<SharedBuffer>(data); | |
| 115 m_lastDataSize = data.size(); | |
| 116 m_allDataReceived = allDataReceived; | 116 m_allDataReceived = allDataReceived; |
| 117 m_actualDecoder->setData(&data, allDataReceived); | 117 m_actualDecoder->setData(RefPtr<SharedBuffer>(data).release(), allDataRe ceived); |
|
scroggo_chromium
2016/03/24 13:59:46
I think this can be simplified. We should probably
| |
| 118 prepareLazyDecodedFrames(); | 118 prepareLazyDecodedFrames(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 if (m_frameGenerator) | 121 if (m_frameGenerator) { |
| 122 m_frameGenerator->setData(&data, allDataReceived); | 122 if (!m_rwBuffer) |
| 123 m_rwBuffer = adoptPtr(new SkRWBuffer(data.size())); | |
| 124 | |
| 125 const char* segment = 0; | |
| 126 while (size_t length = data.getSomeData(segment, m_rwBuffer->size())) | |
| 127 m_rwBuffer->append(segment, length); | |
| 128 } | |
| 123 } | 129 } |
| 124 | 130 |
| 125 bool DeferredImageDecoder::isSizeAvailable() | 131 bool DeferredImageDecoder::isSizeAvailable() |
| 126 { | 132 { |
| 127 // m_actualDecoder is 0 only if image decoding is deferred and that means | 133 // m_actualDecoder is 0 only if image decoding is deferred and that means |
| 128 // the image header decoded successfully and the size is available. | 134 // the image header decoded successfully and the size is available. |
| 129 return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true; | 135 return m_actualDecoder ? m_actualDecoder->isSizeAvailable() : true; |
| 130 } | 136 } |
| 131 | 137 |
| 132 bool DeferredImageDecoder::hasColorProfile() const | 138 bool DeferredImageDecoder::hasColorProfile() const |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 if (m_frameGenerator) | 226 if (m_frameGenerator) |
| 221 return; | 227 return; |
| 222 | 228 |
| 223 m_size = m_actualDecoder->size(); | 229 m_size = m_actualDecoder->size(); |
| 224 m_filenameExtension = m_actualDecoder->filenameExtension(); | 230 m_filenameExtension = m_actualDecoder->filenameExtension(); |
| 225 // JPEG images support YUV decoding: other decoders do not, WEBP could in fu ture. | 231 // JPEG images support YUV decoding: other decoders do not, WEBP could in fu ture. |
| 226 m_canYUVDecode = RuntimeEnabledFeatures::decodeToYUVEnabled() && (m_filename Extension == "jpg"); | 232 m_canYUVDecode = RuntimeEnabledFeatures::decodeToYUVEnabled() && (m_filename Extension == "jpg"); |
| 227 m_hasColorProfile = m_actualDecoder->hasColorProfile(); | 233 m_hasColorProfile = m_actualDecoder->hasColorProfile(); |
| 228 | 234 |
| 229 const bool isSingleFrame = m_actualDecoder->repetitionCount() == cAnimationN one || (m_allDataReceived && m_actualDecoder->frameCount() == 1u); | 235 const bool isSingleFrame = m_actualDecoder->repetitionCount() == cAnimationN one || (m_allDataReceived && m_actualDecoder->frameCount() == 1u); |
| 230 m_frameGenerator = ImageFrameGenerator::create(SkISize::Make(m_actualDecoder ->decodedSize().width(), m_actualDecoder->decodedSize().height()), m_data, m_all DataReceived, !isSingleFrame); | 236 const SkISize decodedSize = SkISize::Make(m_actualDecoder->decodedSize().wid th(), m_actualDecoder->decodedSize().height()); |
| 237 m_frameGenerator = ImageFrameGenerator::create(decodedSize, !isSingleFrame); | |
| 231 } | 238 } |
| 232 | 239 |
| 233 void DeferredImageDecoder::prepareLazyDecodedFrames() | 240 void DeferredImageDecoder::prepareLazyDecodedFrames() |
| 234 { | 241 { |
| 235 if (!s_enabled | 242 if (!s_enabled |
| 236 || !m_actualDecoder | 243 || !m_actualDecoder |
| 237 || !m_actualDecoder->isSizeAvailable() | 244 || !m_actualDecoder->isSizeAvailable() |
| 238 || m_actualDecoder->filenameExtension() == "ico") | 245 || m_actualDecoder->filenameExtension() == "ico") |
| 239 return; | 246 return; |
| 240 | 247 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 257 // The last lazy decoded frame created from previous call might be | 264 // The last lazy decoded frame created from previous call might be |
| 258 // incomplete so update its state. | 265 // incomplete so update its state. |
| 259 if (previousSize) { | 266 if (previousSize) { |
| 260 const size_t lastFrame = previousSize - 1; | 267 const size_t lastFrame = previousSize - 1; |
| 261 m_frameData[lastFrame].m_isComplete = m_actualDecoder->frameIsCompleteAt Index(lastFrame); | 268 m_frameData[lastFrame].m_isComplete = m_actualDecoder->frameIsCompleteAt Index(lastFrame); |
| 262 } | 269 } |
| 263 | 270 |
| 264 if (m_allDataReceived) { | 271 if (m_allDataReceived) { |
| 265 m_repetitionCount = m_actualDecoder->repetitionCount(); | 272 m_repetitionCount = m_actualDecoder->repetitionCount(); |
| 266 m_actualDecoder.clear(); | 273 m_actualDecoder.clear(); |
| 267 m_data = nullptr; | 274 // Hold on to the SkRWBuffer, which is still needed by createFrameAtInde x. |
| 268 } | 275 } |
| 269 } | 276 } |
| 270 | 277 |
| 271 inline SkImageInfo imageInfoFrom(const SkISize& decodedSize, bool knownToBeOpaqu e) | 278 inline SkImageInfo imageInfoFrom(const SkISize& decodedSize, bool knownToBeOpaqu e) |
| 272 { | 279 { |
| 273 return SkImageInfo::MakeN32(decodedSize.width(), decodedSize.height(), known ToBeOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 280 return SkImageInfo::MakeN32(decodedSize.width(), decodedSize.height(), known ToBeOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
| 274 } | 281 } |
| 275 | 282 |
| 276 PassRefPtr<SkImage> DeferredImageDecoder::createFrameImageAtIndex(size_t index, bool knownToBeOpaque) const | 283 PassRefPtr<SkImage> DeferredImageDecoder::createFrameImageAtIndex(size_t index, bool knownToBeOpaque) const |
| 277 { | 284 { |
| 278 const SkISize& decodedSize = m_frameGenerator->getFullSize(); | 285 const SkISize& decodedSize = m_frameGenerator->getFullSize(); |
| 279 ASSERT(decodedSize.width() > 0); | 286 ASSERT(decodedSize.width() > 0); |
| 280 ASSERT(decodedSize.height() > 0); | 287 ASSERT(decodedSize.height() > 0); |
| 281 | 288 |
| 282 DecodingImageGenerator* generator = new DecodingImageGenerator(m_frameGenera tor, imageInfoFrom(decodedSize, knownToBeOpaque), index); | 289 RefPtr<SkROBuffer> roBuffer = adoptRef(m_rwBuffer->newRBufferSnapshot()); |
| 290 RefPtr<SegmentReader> segmentReader = adoptRef(new ROBufferSegmentReader(roB uffer.release())); | |
| 291 DecodingImageGenerator* generator = new DecodingImageGenerator(m_frameGenera tor, imageInfoFrom(decodedSize, knownToBeOpaque), segmentReader.release(), m_all DataReceived, index); | |
| 283 RefPtr<SkImage> image = adoptRef(SkImage::NewFromGenerator(generator)); // S kImage takes ownership of the generator. | 292 RefPtr<SkImage> image = adoptRef(SkImage::NewFromGenerator(generator)); // S kImage takes ownership of the generator. |
| 284 if (!image) | 293 if (!image) |
| 285 return nullptr; | 294 return nullptr; |
| 286 | 295 |
| 287 generator->setGenerationId(image->uniqueID()); | 296 generator->setGenerationId(image->uniqueID()); |
| 288 generator->setCanYUVDecode(m_canYUVDecode); | 297 generator->setCanYUVDecode(m_canYUVDecode); |
| 289 | 298 |
| 290 return image.release(); | 299 return image.release(); |
| 291 } | 300 } |
| 292 | 301 |
| 293 bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const | 302 bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const |
| 294 { | 303 { |
| 295 // TODO: Implement. | 304 // TODO: Implement. |
| 296 return m_actualDecoder ? m_actualDecoder->hotSpot(hotSpot) : false; | 305 return m_actualDecoder ? m_actualDecoder->hotSpot(hotSpot) : false; |
| 297 } | 306 } |
| 298 | 307 |
| 299 } // namespace blink | 308 } // namespace blink |
| OLD | NEW |