Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: Source/core/platform/image-decoders/ImageDecoder.cpp

Issue 15969015: Reland again "Decode GIF image frames on demand". (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: For landing Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 are no frames or only one frame.
146 if (m_frameBufferCache.size() <= 1)
147 return 0;
148
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.
153 // All other frames can be cleared.
154 while ((clearExceptFrame < m_frameBufferCache.size()) && (m_frameBufferCache [clearExceptFrame].status() == ImageFrame::FrameEmpty))
155 clearExceptFrame = m_frameBufferCache[clearExceptFrame].requiredPrevious FrameIndex();
156
157 size_t frameBytesCleared = 0;
158 for (size_t i = 0; i < m_frameBufferCache.size(); ++i) {
159 if (i != clearExceptFrame) {
160 frameBytesCleared += frameBytesAtIndex(i);
161 clearFrameBuffer(i);
162 }
163 }
164 return frameBytesCleared;
165 }
166
167 void ImageDecoder::clearFrameBuffer(size_t frameIndex)
168 {
169 m_frameBufferCache[frameIndex].clearPixelData();
170 }
171
172 size_t ImageDecoder::findRequiredPreviousFrame(size_t frameIndex)
173 {
174 ASSERT(frameIndex <= m_frameBufferCache.size());
175 if (!frameIndex) {
176 // The first frame doesn't rely on any previous data.
177 return notFound;
178 }
179
180 // The starting state for this frame depends on the previous frame's
181 // disposal method.
182 size_t prevFrame = frameIndex - 1;
183 const ImageFrame* prevBuffer = &m_frameBufferCache[prevFrame];
184 ASSERT(prevBuffer->requiredPreviousFrameIndexValid());
185
186 switch (prevBuffer->disposalMethod()) {
187 case ImageFrame::DisposeNotSpecified:
188 case ImageFrame::DisposeKeep:
189 // prevFrame will be used as the starting state for this frame.
190 // FIXME: Be even smarter by checking the frame sizes and/or alpha-conta ining regions.
191 return prevFrame;
192 case ImageFrame::DisposeOverwritePrevious:
193 // Frames that use the DisposeOverwritePrevious method are effectively
194 // no-ops in terms of changing the starting state of a frame compared to
195 // the starting state of the previous frame, so skip over them and
196 // return the required previous frame of it.
197 return prevBuffer->requiredPreviousFrameIndex();
198 case ImageFrame::DisposeOverwriteBgcolor:
199 // If the previous frame fills the whole image, then the current frame
200 // can be decoded alone. Likewise, if the previous frame could be
201 // decoded without reference to any prior frame, the starting state for
202 // this frame is a blank frame, so it can again be decoded alone.
203 // Otherwise, the previous frame contributes to this frame.
204 return (prevBuffer->originalFrameRect().contains(IntRect(IntPoint(), siz e()))
205 || (prevBuffer->requiredPreviousFrameIndex() == notFound)) ? notFoun d : prevFrame;
206 default:
207 ASSERT_NOT_REACHED();
208 return notFound;
209 }
210 }
211
143 } // namespace WebCore 212 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698