OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. | 2 * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 } | 120 } |
121 | 121 |
122 bool ImageDecoder::frameIsCompleteAtIndex(size_t index) const | 122 bool ImageDecoder::frameIsCompleteAtIndex(size_t index) const |
123 { | 123 { |
124 return (index < m_frameBufferCache.size()) && | 124 return (index < m_frameBufferCache.size()) && |
125 (m_frameBufferCache[index].status() == ImageFrame::FrameComplete); | 125 (m_frameBufferCache[index].status() == ImageFrame::FrameComplete); |
126 } | 126 } |
127 | 127 |
128 unsigned ImageDecoder::frameBytesAtIndex(size_t index) const | 128 unsigned ImageDecoder::frameBytesAtIndex(size_t index) const |
129 { | 129 { |
130 if (m_frameBufferCache.size() <= index) | 130 if (m_frameBufferCache.size() <= index || m_frameBufferCache[index].status() == ImageFrame::FrameEmpty) |
131 return 0; | 131 return 0; |
132 // FIXME: Use the dimension of the requested frame. | 132 // FIXME: Use the dimension of the requested frame. |
133 return m_size.area() * sizeof(ImageFrame::PixelData); | 133 return m_size.area() * sizeof(ImageFrame::PixelData); |
134 } | 134 } |
135 | 135 |
136 void ImageDecoder::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const | 136 void ImageDecoder::reportMemoryUsage(MemoryObjectInfo* memoryObjectInfo) const |
137 { | 137 { |
138 MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::Image); | 138 MemoryClassInfo info(memoryObjectInfo, this, PlatformMemoryTypes::Image); |
139 info.addMember(m_data, "data"); | 139 info.addMember(m_data, "data"); |
140 info.addMember(m_frameBufferCache, "frameBufferCache"); | 140 info.addMember(m_frameBufferCache, "frameBufferCache"); |
141 } | 141 } |
142 | 142 |
143 size_t ImageDecoder::clearCacheExceptFrame(size_t clearExceptFrame) | |
144 { | |
145 // Don't clear if there is no or only one frame. | |
Peter Kasting
2013/05/29 02:02:18
Nit: "...are no frames or only one frame."
Xianzhu
2013/05/29 18:37:01
Done.
| |
146 if (m_frameBufferCache.size() <= 1) | |
147 return 0; | |
148 | |
Peter Kasting
2013/05/29 02:02:18
In theory, it's technically possible for ICOs to r
Xianzhu
2013/05/29 18:37:01
Done.
| |
149 // We need to preserve frames such that: | |
150 // 1. We don't clear |clearExceptFrame|; | |
151 // 2. We don't clear any frame from which a future initFrameBuffer() call | |
152 // will copy bitmap data; | |
Peter Kasting
2013/05/29 02:02:18
Nit: ; -> .
Xianzhu
2013/05/29 18:37:01
Done.
| |
153 // All other frames can be cleared. | |
154 size_t frameToBeRequired = notFound; | |
Peter Kasting
2013/05/29 02:02:18
Nit: You can actually make this even simpler by re
Xianzhu
2013/05/29 18:37:01
Done.
| |
155 if (clearExceptFrame < m_frameBufferCache.size() && m_frameBufferCache[clear ExceptFrame].status() == ImageFrame::FrameEmpty) { | |
156 frameToBeRequired = clearExceptFrame; | |
157 do { | |
158 frameToBeRequired = m_frameBufferCache[frameToBeRequired].requiredPr eviousFrameIndex(); | |
159 } while (frameToBeRequired != notFound && m_frameBufferCache[frameToBeRe quired].status() == ImageFrame::FrameEmpty); | |
160 } | |
161 | |
162 size_t frameBytesCleared = 0; | |
163 for (size_t i = 0; i < m_frameBufferCache.size(); ++i) { | |
164 if (i != clearExceptFrame && i != frameToBeRequired) { | |
165 frameBytesCleared += frameBytesAtIndex(i); | |
166 clearFrameBuffer(i); | |
167 } | |
168 } | |
169 return frameBytesCleared; | |
170 } | |
171 | |
172 void ImageDecoder::clearFrameBuffer(size_t frameIndex) | |
173 { | |
174 m_frameBufferCache[frameIndex].clearPixelData(); | |
175 } | |
176 | |
177 size_t ImageDecoder::findRequiredPreviousFrame(size_t frameIndex) | |
178 { | |
179 ASSERT(frameIndex <= m_frameBufferCache.size()); | |
180 if (!frameIndex) { | |
181 // The first frame doesn't rely on any previous data. | |
182 return notFound; | |
183 } | |
184 | |
185 // The starting state for this frame depends on the previous frame's | |
186 // disposal method. | |
187 size_t prevFrame = frameIndex - 1; | |
188 const ImageFrame* prevBuffer = &m_frameBufferCache[prevFrame]; | |
Peter Kasting
2013/05/29 02:02:18
Here you should also ASSERT(prevBuffer->m_required
Xianzhu
2013/05/29 18:37:01
Done.
| |
189 switch (prevBuffer->disposalMethod()) { | |
190 case ImageFrame::DisposeNotSpecified: | |
191 case ImageFrame::DisposeKeep: | |
192 // prevFrame will be used as the starting state for this frame. | |
193 // FIXME: Be even smarter by checking the frame sizes and/or alpha-conta ining regions. | |
194 return prevFrame; | |
195 case ImageFrame::DisposeOverwritePrevious: | |
196 // Frames that use the DisposeOverwritePrevious method are effectively | |
197 // no-ops in terms of changing the starting state of a frame compared to | |
198 // the starting state of the previous frame, so skip over them and | |
199 // return the required previous frame of it. | |
200 return prevBuffer->requiredPreviousFrameIndex(); | |
201 case ImageFrame::DisposeOverwriteBgcolor: | |
202 // If the previous frame fills the whole image, then the current frame | |
203 // can be decoded alone. Otherwise, prevFrame contributes to this frame. | |
204 // However, the first frame always clears even it partially covers. | |
Peter Kasting
2013/05/29 02:02:18
We can actually be even smarter here by handling c
Xianzhu
2013/05/29 18:37:01
Done. Thanks for the idea.
| |
205 return !prevFrame || prevBuffer->originalFrameRect().contains(IntRect(In tPoint(), size())) ? notFound : prevFrame; | |
206 default: | |
207 ASSERT_NOT_REACHED(); | |
208 return notFound; | |
209 } | |
210 } | |
211 | |
143 } // namespace WebCore | 212 } // namespace WebCore |
OLD | NEW |