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 "config.h" | 26 #include "config.h" |
27 #include "platform/graphics/DeferredImageDecoder.h" | 27 #include "platform/graphics/DeferredImageDecoder.h" |
28 | 28 |
| 29 #include "platform/RuntimeEnabledFeatures.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" |
33 #include "third_party/skia/include/core/SkImage.h" | 34 #include "third_party/skia/include/core/SkImage.h" |
34 #include "wtf/PassOwnPtr.h" | 35 #include "wtf/PassOwnPtr.h" |
35 | 36 |
36 namespace blink { | 37 namespace blink { |
37 | 38 |
38 bool DeferredImageDecoder::s_enabled = true; | 39 bool DeferredImageDecoder::s_enabled = true; |
(...skipping 12 matching lines...) Expand all Loading... |
51 { | 52 { |
52 return adoptPtr(new DeferredImageDecoder(actualDecoder)); | 53 return adoptPtr(new DeferredImageDecoder(actualDecoder)); |
53 } | 54 } |
54 | 55 |
55 DeferredImageDecoder::DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecode
r) | 56 DeferredImageDecoder::DeferredImageDecoder(PassOwnPtr<ImageDecoder> actualDecode
r) |
56 : m_allDataReceived(false) | 57 : m_allDataReceived(false) |
57 , m_lastDataSize(0) | 58 , m_lastDataSize(0) |
58 , m_actualDecoder(actualDecoder) | 59 , m_actualDecoder(actualDecoder) |
59 , m_repetitionCount(cAnimationNone) | 60 , m_repetitionCount(cAnimationNone) |
60 , m_hasColorProfile(false) | 61 , m_hasColorProfile(false) |
| 62 , m_canYUVDecode(false) |
61 { | 63 { |
62 } | 64 } |
63 | 65 |
64 DeferredImageDecoder::~DeferredImageDecoder() | 66 DeferredImageDecoder::~DeferredImageDecoder() |
65 { | 67 { |
66 } | 68 } |
67 | 69 |
68 void DeferredImageDecoder::setEnabled(bool enabled) | 70 void DeferredImageDecoder::setEnabled(bool enabled) |
69 { | 71 { |
70 s_enabled = enabled; | 72 s_enabled = enabled; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 return m_actualDecoder->orientation(); | 209 return m_actualDecoder->orientation(); |
208 if (index < m_frameData.size()) | 210 if (index < m_frameData.size()) |
209 return m_frameData[index].m_orientation; | 211 return m_frameData[index].m_orientation; |
210 return DefaultImageOrientation; | 212 return DefaultImageOrientation; |
211 } | 213 } |
212 | 214 |
213 void DeferredImageDecoder::activateLazyDecoding() | 215 void DeferredImageDecoder::activateLazyDecoding() |
214 { | 216 { |
215 if (m_frameGenerator) | 217 if (m_frameGenerator) |
216 return; | 218 return; |
| 219 |
217 m_size = m_actualDecoder->size(); | 220 m_size = m_actualDecoder->size(); |
218 m_filenameExtension = m_actualDecoder->filenameExtension(); | 221 m_filenameExtension = m_actualDecoder->filenameExtension(); |
| 222 // JPEG images support YUV decoding: other decoders do not, WEBP could in fu
ture. |
| 223 m_canYUVDecode = RuntimeEnabledFeatures::decodeToYUVEnabled() && (m_filename
Extension == "jpg"); |
219 m_hasColorProfile = m_actualDecoder->hasColorProfile(); | 224 m_hasColorProfile = m_actualDecoder->hasColorProfile(); |
| 225 |
220 const bool isSingleFrame = m_actualDecoder->repetitionCount() == cAnimationN
one || (m_allDataReceived && m_actualDecoder->frameCount() == 1u); | 226 const bool isSingleFrame = m_actualDecoder->repetitionCount() == cAnimationN
one || (m_allDataReceived && m_actualDecoder->frameCount() == 1u); |
221 m_frameGenerator = ImageFrameGenerator::create(SkISize::Make(m_actualDecoder
->decodedSize().width(), m_actualDecoder->decodedSize().height()), m_data, m_all
DataReceived, !isSingleFrame); | 227 m_frameGenerator = ImageFrameGenerator::create(SkISize::Make(m_actualDecoder
->decodedSize().width(), m_actualDecoder->decodedSize().height()), m_data, m_all
DataReceived, !isSingleFrame); |
222 } | 228 } |
223 | 229 |
224 void DeferredImageDecoder::prepareLazyDecodedFrames() | 230 void DeferredImageDecoder::prepareLazyDecodedFrames() |
225 { | 231 { |
226 if (!s_enabled | 232 if (!s_enabled |
227 || !m_actualDecoder | 233 || !m_actualDecoder |
228 || !m_actualDecoder->isSizeAvailable() | 234 || !m_actualDecoder->isSizeAvailable() |
229 || m_actualDecoder->filenameExtension() == "ico") | 235 || m_actualDecoder->filenameExtension() == "ico") |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 return SkImageInfo::MakeN32(decodedSize.width(), decodedSize.height(), known
ToBeOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); | 270 return SkImageInfo::MakeN32(decodedSize.width(), decodedSize.height(), known
ToBeOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType); |
265 } | 271 } |
266 | 272 |
267 PassRefPtr<SkImage> DeferredImageDecoder::createFrameImageAtIndex(size_t index,
bool knownToBeOpaque) const | 273 PassRefPtr<SkImage> DeferredImageDecoder::createFrameImageAtIndex(size_t index,
bool knownToBeOpaque) const |
268 { | 274 { |
269 const SkISize& decodedSize = m_frameGenerator->getFullSize(); | 275 const SkISize& decodedSize = m_frameGenerator->getFullSize(); |
270 ASSERT(decodedSize.width() > 0); | 276 ASSERT(decodedSize.width() > 0); |
271 ASSERT(decodedSize.height() > 0); | 277 ASSERT(decodedSize.height() > 0); |
272 | 278 |
273 DecodingImageGenerator* generator = new DecodingImageGenerator(m_frameGenera
tor, imageInfoFrom(decodedSize, knownToBeOpaque), index); | 279 DecodingImageGenerator* generator = new DecodingImageGenerator(m_frameGenera
tor, imageInfoFrom(decodedSize, knownToBeOpaque), index); |
274 RefPtr<SkImage> image = adoptRef(SkImage::NewFromGenerator(generator)); | 280 RefPtr<SkImage> image = adoptRef(SkImage::NewFromGenerator(generator)); // S
kImage takes ownership of the generator. |
275 if (!image) | 281 if (!image) |
276 return nullptr; | 282 return nullptr; |
277 | 283 |
278 generator->setGenerationId(image->uniqueID()); | 284 generator->setGenerationId(image->uniqueID()); |
| 285 generator->setCanYUVDecode(m_canYUVDecode); |
| 286 |
279 return image.release(); | 287 return image.release(); |
280 } | 288 } |
281 | 289 |
282 bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const | 290 bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const |
283 { | 291 { |
284 // TODO: Implement. | 292 // TODO: Implement. |
285 return m_actualDecoder ? m_actualDecoder->hotSpot(hotSpot) : false; | 293 return m_actualDecoder ? m_actualDecoder->hotSpot(hotSpot) : false; |
286 } | 294 } |
287 | 295 |
288 } // namespace blink | 296 } // namespace blink |
OLD | NEW |