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/graphics/DecodingImageGenerator.h" | 29 #include "platform/graphics/DecodingImageGenerator.h" |
30 #include "platform/graphics/FrameData.h" | |
31 #include "platform/graphics/ImageDecodingStore.h" | 30 #include "platform/graphics/ImageDecodingStore.h" |
32 #include "platform/graphics/ImageFrameGenerator.h" | 31 #include "platform/graphics/ImageFrameGenerator.h" |
33 #include "third_party/skia/include/core/SkImage.h" | 32 #include "third_party/skia/include/core/SkImage.h" |
34 #include "wtf/PassOwnPtr.h" | 33 #include "wtf/PassOwnPtr.h" |
35 | 34 |
36 namespace blink { | 35 namespace blink { |
37 | 36 |
37 struct DeferredFrameData { | |
Peter Kasting
2016/04/28 23:07:55
This probably needs comments about why you can't u
aleksandar.stojiljkovic
2016/04/29 17:17:43
After second patch these two diverged further - D
| |
38 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | |
39 WTF_MAKE_NONCOPYABLE(DeferredFrameData); | |
40 public: | |
41 DeferredFrameData() | |
42 : m_orientation(DefaultImageOrientation) | |
43 , m_duration(0) | |
44 , m_isComplete(false) | |
45 , m_frameBytes(0) | |
46 {} | |
47 | |
48 ImageOrientation m_orientation; | |
49 float m_duration; | |
50 bool m_isComplete : 1; | |
51 size_t m_frameBytes; | |
52 }; | |
53 | |
38 bool DeferredImageDecoder::s_enabled = true; | 54 bool DeferredImageDecoder::s_enabled = true; |
39 | 55 |
40 PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::create(const SharedBuffer & data, ImageDecoder::AlphaOption alphaOption, ImageDecoder::GammaAndColorProfil eOption colorOptions) | 56 PassOwnPtr<DeferredImageDecoder> DeferredImageDecoder::create(const SharedBuffer & data, ImageDecoder::AlphaOption alphaOption, ImageDecoder::GammaAndColorProfil eOption colorOptions) |
41 { | 57 { |
42 OwnPtr<ImageDecoder> actualDecoder = ImageDecoder::create(data, alphaOption, colorOptions); | 58 OwnPtr<ImageDecoder> actualDecoder = ImageDecoder::create(data, alphaOption, colorOptions); |
43 | 59 |
44 if (!actualDecoder) | 60 if (!actualDecoder) |
45 return nullptr; | 61 return nullptr; |
46 | 62 |
47 return adoptPtr(new DeferredImageDecoder(actualDecoder.release())); | 63 return adoptPtr(new DeferredImageDecoder(actualDecoder.release())); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 } | 98 } |
83 | 99 |
84 PassRefPtr<SkImage> DeferredImageDecoder::createFrameAtIndex(size_t index) | 100 PassRefPtr<SkImage> DeferredImageDecoder::createFrameAtIndex(size_t index) |
85 { | 101 { |
86 if (m_frameGenerator && m_frameGenerator->decodeFailed()) | 102 if (m_frameGenerator && m_frameGenerator->decodeFailed()) |
87 return nullptr; | 103 return nullptr; |
88 | 104 |
89 prepareLazyDecodedFrames(); | 105 prepareLazyDecodedFrames(); |
90 | 106 |
91 if (index < m_frameData.size()) { | 107 if (index < m_frameData.size()) { |
92 FrameData* frameData = &m_frameData[index]; | 108 DeferredFrameData* frameData = &m_frameData[index]; |
93 // ImageFrameGenerator has the latest known alpha state. There will be a | |
94 // performance boost if this frame is opaque. | |
95 ASSERT(m_frameGenerator); | |
96 frameData->m_hasAlpha = m_frameGenerator->hasAlpha(index); | |
97 if (m_actualDecoder) | 109 if (m_actualDecoder) |
98 frameData->m_frameBytes = m_actualDecoder->frameBytesAtIndex(index); | 110 frameData->m_frameBytes = m_actualDecoder->frameBytesAtIndex(index); |
99 else | 111 else |
100 frameData->m_frameBytes = m_size.area() * sizeof(ImageFrame::PixelDa ta); | 112 frameData->m_frameBytes = m_size.area() * sizeof(ImageFrame::PixelDa ta); |
101 return createFrameImageAtIndex(index, !frameData->m_hasAlpha); | 113 // ImageFrameGenerator has the latest known alpha state. There will be a |
114 // performance boost if this frame is opaque. | |
115 ASSERT(m_frameGenerator); | |
116 return createFrameImageAtIndex(index, !m_frameGenerator->hasAlpha(index) ); | |
102 } | 117 } |
103 | 118 |
104 if (!m_actualDecoder || m_actualDecoder->failed()) | 119 if (!m_actualDecoder || m_actualDecoder->failed()) |
105 return nullptr; | 120 return nullptr; |
106 | 121 |
107 ImageFrame* frame = m_actualDecoder->frameBufferAtIndex(index); | 122 ImageFrame* frame = m_actualDecoder->frameBufferAtIndex(index); |
108 if (!frame || frame->getStatus() == ImageFrame::FrameEmpty) | 123 if (!frame || frame->getStatus() == ImageFrame::FrameEmpty) |
109 return nullptr; | 124 return nullptr; |
110 | 125 |
111 return adoptRef(SkImage::NewFromBitmap(frame->bitmap())); | 126 return adoptRef(SkImage::NewFromBitmap(frame->bitmap())); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 activateLazyDecoding(); | 259 activateLazyDecoding(); |
245 | 260 |
246 const size_t previousSize = m_frameData.size(); | 261 const size_t previousSize = m_frameData.size(); |
247 m_frameData.resize(m_actualDecoder->frameCount()); | 262 m_frameData.resize(m_actualDecoder->frameCount()); |
248 | 263 |
249 // We have encountered a broken image file. Simply bail. | 264 // We have encountered a broken image file. Simply bail. |
250 if (m_frameData.size() < previousSize) | 265 if (m_frameData.size() < previousSize) |
251 return; | 266 return; |
252 | 267 |
253 for (size_t i = previousSize; i < m_frameData.size(); ++i) { | 268 for (size_t i = previousSize; i < m_frameData.size(); ++i) { |
254 m_frameData[i].m_haveMetadata = true; | |
255 m_frameData[i].m_duration = m_actualDecoder->frameDurationAtIndex(i); | 269 m_frameData[i].m_duration = m_actualDecoder->frameDurationAtIndex(i); |
256 m_frameData[i].m_orientation = m_actualDecoder->orientation(); | 270 m_frameData[i].m_orientation = m_actualDecoder->orientation(); |
257 m_frameData[i].m_isComplete = m_actualDecoder->frameIsCompleteAtIndex(i) ; | 271 m_frameData[i].m_isComplete = m_actualDecoder->frameIsCompleteAtIndex(i) ; |
258 } | 272 } |
259 | 273 |
260 // The last lazy decoded frame created from previous call might be | 274 // The last lazy decoded frame created from previous call might be |
261 // incomplete so update its state. | 275 // incomplete so update its state. |
262 if (previousSize) { | 276 if (previousSize) { |
263 const size_t lastFrame = previousSize - 1; | 277 const size_t lastFrame = previousSize - 1; |
264 m_frameData[lastFrame].m_isComplete = m_actualDecoder->frameIsCompleteAt Index(lastFrame); | 278 m_frameData[lastFrame].m_isComplete = m_actualDecoder->frameIsCompleteAt Index(lastFrame); |
(...skipping 28 matching lines...) Expand all Loading... | |
293 return image.release(); | 307 return image.release(); |
294 } | 308 } |
295 | 309 |
296 bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const | 310 bool DeferredImageDecoder::hotSpot(IntPoint& hotSpot) const |
297 { | 311 { |
298 // TODO: Implement. | 312 // TODO: Implement. |
299 return m_actualDecoder ? m_actualDecoder->hotSpot(hotSpot) : false; | 313 return m_actualDecoder ? m_actualDecoder->hotSpot(hotSpot) : false; |
300 } | 314 } |
301 | 315 |
302 } // namespace blink | 316 } // namespace blink |
317 | |
318 namespace WTF { | |
319 template<> struct VectorTraits<blink::DeferredFrameData> : public SimpleClassVec torTraits<blink::DeferredFrameData> { | |
320 STATIC_ONLY(VectorTraits); | |
321 static const bool canInitializeWithMemset = false; // Not all DeferredFrameD ata members initialize to 0. | |
322 }; | |
323 } | |
OLD | NEW |