OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2006 Apple Computer, 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/image-decoders/gif/GIFImageDecoder.h" | 26 #include "platform/image-decoders/gif/GIFImageDecoder.h" |
27 | 27 |
28 #include "platform/image-decoders/gif/GIFImageReader.h" | 28 #include <limits> |
29 #include "third_party/skia/include/core/SkImageInfo.h" | |
29 #include "wtf/NotFound.h" | 30 #include "wtf/NotFound.h" |
30 #include "wtf/PtrUtil.h" | 31 #include "wtf/PtrUtil.h" |
31 #include <limits> | |
32 | 32 |
33 namespace blink { | 33 namespace blink { |
34 | 34 |
35 GIFImageDecoder::GIFImageDecoder(AlphaOption alphaOption, | 35 GIFImageDecoder::GIFImageDecoder(AlphaOption alphaOption, |
36 const ColorBehavior& colorBehavior, | 36 const ColorBehavior& colorBehavior, |
37 size_t maxDecodedBytes) | 37 size_t maxDecodedBytes) |
38 : ImageDecoder(alphaOption, colorBehavior, maxDecodedBytes), | 38 : ImageDecoder(alphaOption, colorBehavior, maxDecodedBytes), |
39 m_repetitionCount(cAnimationLoopOnce) {} | 39 m_codec(), |
40 | 40 m_segmentStream(nullptr) {} |
41 GIFImageDecoder::~GIFImageDecoder() {} | 41 |
42 GIFImageDecoder::~GIFImageDecoder() { | |
43 if (!m_codec) { | |
44 // if we did not create m_codec and thus did not pass ownership to it | |
45 if (m_segmentStream) { | |
46 delete m_segmentStream; | |
47 } | |
48 } | |
49 } | |
42 | 50 |
43 void GIFImageDecoder::onSetData(SegmentReader* data) { | 51 void GIFImageDecoder::onSetData(SegmentReader* data) { |
44 if (m_reader) | 52 if (!data) { |
45 m_reader->setData(data); | 53 m_segmentStream = nullptr; |
scroggo_chromium
2017/03/06 16:27:31
This just means we've lost our pointer to it, so n
cblume
2017/03/07 01:18:11
Done.
Interestingly, the crash in DeferredImageDec
| |
54 return; | |
55 } | |
56 | |
57 if (!m_segmentStream) { | |
58 m_segmentStream = new SegmentStream(); | |
59 } | |
60 | |
61 m_segmentStream->setReader(data, isAllDataReceived()); | |
62 | |
63 // If we don't have a SkCodec yet, create one from the stream | |
64 if (!m_codec) { | |
65 SkCodec* codec = SkCodec::NewFromStream(m_segmentStream); | |
66 if (codec) { | |
67 m_codec.reset(codec); | |
68 } else { | |
69 // m_segmentStream's ownership is passed. It is deleted if SkCodec | |
70 // creation fails. In this case, release our reference so we can create a | |
71 // new SegmentStream later. | |
72 m_segmentStream = nullptr; | |
73 return; | |
74 } | |
75 | |
76 // SkCodec::NewFromStream will read enough of the image to get the image | |
77 // size. | |
78 SkImageInfo imageInfo = m_codec->getInfo(); | |
79 setSize(imageInfo.width(), imageInfo.height()); | |
80 } | |
46 } | 81 } |
47 | 82 |
48 int GIFImageDecoder::repetitionCount() const { | 83 int GIFImageDecoder::repetitionCount() const { |
84 if (!m_codec) { | |
85 return cAnimationLoopOnce; | |
86 } | |
87 | |
49 // This value can arrive at any point in the image data stream. Most GIFs | 88 // This value can arrive at any point in the image data stream. Most GIFs |
50 // in the wild declare it near the beginning of the file, so it usually is | 89 // in the wild declare it near the beginning of the file, so it usually is |
51 // set by the time we've decoded the size, but (depending on the GIF and the | 90 // set by the time we've decoded the size, but (depending on the GIF and the |
52 // packets sent back by the webserver) not always. If the reader hasn't | 91 // packets sent back by the webserver) not always. |
53 // seen a loop count yet, it will return cLoopCountNotSeen, in which case we | |
54 // should default to looping once (the initial value for | |
55 // |m_repetitionCount|). | |
56 // | 92 // |
57 // There are some additional wrinkles here. First, ImageSource::clear() | 93 // SkCodec will parse forward in the file if the repetition count has not been |
58 // may destroy the reader, making the result from the reader _less_ | 94 // seen yet. |
59 // authoritative on future calls if the recreated reader hasn't seen the | 95 |
60 // loop count. We don't need to special-case this because in this case the | 96 std::vector<SkCodec::FrameInfo> frameInfos = m_codec->getFrameInfo(); |
61 // new reader will once again return cLoopCountNotSeen, and we won't | 97 if (isAllDataReceived() && frameInfos.size() == 1) |
62 // overwrite the cached correct value. | 98 return cAnimationNone; |
63 // | 99 if (failed()) |
64 // Second, a GIF might never set a loop count at all, in which case we | 100 return cAnimationLoopOnce; |
65 // should continue to treat it as a "loop once" animation. We don't need | 101 |
66 // special code here either, because in this case we'll never change | 102 int repetitionCount = m_codec->getRepetitionCount(); |
67 // |m_repetitionCount| from its default value. | 103 switch (repetitionCount) { |
68 // | 104 case 0: |
69 // Third, we use the same GIFImageReader for counting frames and we might | 105 return cAnimationLoopOnce; |
70 // see the loop count and then encounter a decoding error which happens | 106 case SkCodec::kRepetitionCountInfinite: |
71 // later in the stream. It is also possible that no frames are in the | 107 return cAnimationLoopInfinite; |
72 // stream. In these cases we should just loop once. | 108 default: |
73 if (isAllDataReceived() && parseCompleted() && m_reader->imagesCount() == 1) | 109 return repetitionCount; |
74 m_repetitionCount = cAnimationNone; | 110 } |
75 else if (failed() || (m_reader && (!m_reader->imagesCount()))) | |
76 m_repetitionCount = cAnimationLoopOnce; | |
77 else if (m_reader && m_reader->loopCount() != cLoopCountNotSeen) | |
78 m_repetitionCount = m_reader->loopCount(); | |
79 return m_repetitionCount; | |
80 } | 111 } |
81 | 112 |
82 bool GIFImageDecoder::frameIsCompleteAtIndex(size_t index) const { | 113 bool GIFImageDecoder::frameIsCompleteAtIndex(size_t index) const { |
83 return m_reader && (index < m_reader->imagesCount()) && | 114 if (!m_codec) { |
84 m_reader->frameContext(index)->isComplete(); | 115 return false; |
116 } | |
117 | |
118 std::vector<SkCodec::FrameInfo> frameInfos = m_codec->getFrameInfo(); | |
119 if (frameInfos.size() <= index) { | |
120 return false; | |
121 } | |
122 | |
123 return frameInfos[index].fFullyReceived; | |
85 } | 124 } |
86 | 125 |
87 float GIFImageDecoder::frameDurationAtIndex(size_t index) const { | 126 float GIFImageDecoder::frameDurationAtIndex(size_t index) const { |
scroggo_chromium
2017/03/06 16:27:31
I wonder if we should instead just return m_frameB
cblume
2017/03/07 01:18:11
Done.
| |
88 return (m_reader && (index < m_reader->imagesCount()) && | 127 if (!m_codec) { |
89 m_reader->frameContext(index)->isHeaderDefined()) | 128 return 0; |
90 ? m_reader->frameContext(index)->delayTime() | 129 } |
91 : 0; | 130 |
92 } | 131 std::vector<SkCodec::FrameInfo> frameInfos = m_codec->getFrameInfo(); |
93 | 132 if (frameInfos.size() <= index) { |
94 bool GIFImageDecoder::setFailed() { | 133 return 0; |
95 m_reader.reset(); | 134 } |
96 return ImageDecoder::setFailed(); | 135 |
97 } | 136 return frameInfos[index].fDuration; |
98 | 137 } |
99 bool GIFImageDecoder::haveDecodedRow(size_t frameIndex, | 138 |
100 GIFRow::const_iterator rowBegin, | 139 size_t GIFImageDecoder::decodeFrameCount() { |
101 size_t width, | 140 if (!m_codec) { |
102 size_t rowNumber, | 141 return 0; |
103 unsigned repeatCount, | 142 } |
104 bool writeTransparentPixels) { | 143 |
105 const GIFFrameContext* frameContext = m_reader->frameContext(frameIndex); | 144 std::vector<SkCodec::FrameInfo> frameInfos = m_codec->getFrameInfo(); |
106 // The pixel data and coordinates supplied to us are relative to the frame's | 145 return frameInfos.size(); |
107 // origin within the entire image size, i.e. | 146 } |
108 // (frameContext->xOffset, frameContext->yOffset). There is no guarantee | 147 |
109 // that width == (size().width() - frameContext->xOffset), so | 148 void GIFImageDecoder::decode(size_t index) { |
110 // we must ensure we don't run off the end of either the source data or the | 149 if (failed()) |
111 // row's X-coordinates. | 150 return; |
112 const int xBegin = frameContext->xOffset(); | 151 |
113 const int yBegin = frameContext->yOffset() + rowNumber; | 152 if (!m_codec) |
114 const int xEnd = std::min(static_cast<int>(frameContext->xOffset() + width), | 153 return; |
115 size().width()); | 154 |
116 const int yEnd = std::min( | 155 if (m_frameBufferCache.size() <= index) { |
117 static_cast<int>(frameContext->yOffset() + rowNumber + repeatCount), | 156 // It is a fatal error if all data is received and we have decoded all |
118 size().height()); | 157 // frames available but the file is truncated. |
119 if (!width || (xBegin < 0) || (yBegin < 0) || (xEnd <= xBegin) || | 158 if (isAllDataReceived()) { |
120 (yEnd <= yBegin)) | 159 setFailed(); |
121 return true; | 160 } |
122 | 161 |
123 const GIFColorMap::Table& colorTable = | 162 return; |
124 frameContext->localColorMap().isDefined() | 163 } |
125 ? frameContext->localColorMap().getTable() | 164 |
126 : m_reader->globalColorMap().getTable(); | 165 updateAggressivePurging(index); |
127 | 166 |
128 if (colorTable.isEmpty()) | 167 SkImageInfo imageInfo = m_codec->getInfo().makeColorType(kN32_SkColorType); |
129 return true; | 168 |
130 | 169 ImageFrame& frame = m_frameBufferCache[index]; |
131 GIFColorMap::Table::const_iterator colorTableIter = colorTable.begin(); | 170 |
132 | 171 std::vector<SkCodec::FrameInfo> frameInfos = m_codec->getFrameInfo(); |
133 // Initialize the frame if necessary. | 172 size_t requiredPreviousFrameIndex = frameInfos[index].fRequiredFrame; |
134 ImageFrame& buffer = m_frameBufferCache[frameIndex]; | 173 if (requiredPreviousFrameIndex == SkCodec::kNone) { |
135 if (!initFrameBuffer(frameIndex)) | 174 requiredPreviousFrameIndex = WTF::kNotFound; |
136 return false; | 175 } |
137 | 176 frame.setRequiredPreviousFrameIndex(requiredPreviousFrameIndex); |
138 const size_t transparentPixel = frameContext->transparentPixel(); | 177 |
139 GIFRow::const_iterator rowEnd = rowBegin + (xEnd - xBegin); | 178 SkCodec::Options options; |
140 ImageFrame::PixelData* currentAddress = buffer.getAddr(xBegin, yBegin); | 179 options.fFrameIndex = index; |
141 | 180 options.fHasPriorFrame = false; |
142 // We may or may not need to write transparent pixels to the buffer. | 181 |
143 // If we're compositing against a previous image, it's wrong, and if | 182 if (frame.getStatus() == ImageFrame::FrameEmpty) { |
144 // we're writing atop a cleared, fully transparent buffer, it's | 183 IntSize frameSize = size(); |
145 // unnecessary; but if we're decoding an interlaced gif and | 184 frame.setOriginalFrameRect(IntRect(IntPoint(), frameSize)); |
146 // displaying it "Haeberli"-style, we must write these for passes | 185 frame.setDuration(frameInfos[index].fDuration); |
147 // beyond the first, or the initial passes will "show through" the | 186 // The disposal method is not required any more, but is left in place |
148 // later ones. | 187 // for the other image decoders that do not yet rely on SkCodec. |
149 // | 188 // For now, fill it with DisposeKeep. |
150 // The loops below are almost identical. One writes a transparent pixel | 189 frame.setDisposalMethod(ImageFrame::DisposeKeep); |
151 // and one doesn't based on the value of |writeTransparentPixels|. | 190 if (requiredPreviousFrameIndex == WTF::kNotFound) { |
152 // The condition check is taken out of the loop to enhance performance. | 191 frame.setSizeAndColorSpace(frameSize.width(), frameSize.height(), |
153 // This optimization reduces decoding time by about 15% for a 3MB image. | 192 colorSpaceForSkImages()); |
154 if (writeTransparentPixels) { | 193 } else { |
155 for (; rowBegin != rowEnd; ++rowBegin, ++currentAddress) { | 194 ImageFrame& requiredPreviousFrame = |
156 const size_t sourceValue = *rowBegin; | 195 m_frameBufferCache[requiredPreviousFrameIndex]; |
157 if ((sourceValue != transparentPixel) && | 196 |
158 (sourceValue < colorTable.size())) { | 197 if (requiredPreviousFrame.getStatus() != ImageFrame::FrameComplete) |
159 *currentAddress = colorTableIter[sourceValue]; | 198 decode(requiredPreviousFrameIndex); |
160 } else { | 199 |
161 *currentAddress = 0; | 200 // We try to reuse |requiredPreviousFrame| as starting state to avoid |
162 m_currentBufferSawAlpha = true; | 201 // copying. If canReusePreviousFrameBuffer returns false, we must copy |
202 // the data since |requiredPreviousFrame| is necessary to decode this | |
203 // or later frames. In that case copy the data instead. | |
204 if ((!canReusePreviousFrameBuffer(index) || | |
205 !frame.takeBitmapDataIfWritable(&requiredPreviousFrame)) && | |
206 !frame.copyBitmapData(requiredPreviousFrame)) { | |
207 setFailed(); | |
208 return; | |
163 } | 209 } |
164 } | 210 } |
165 } else { | 211 |
166 for (; rowBegin != rowEnd; ++rowBegin, ++currentAddress) { | 212 if (requiredPreviousFrameIndex != WTF::kNotFound) { |
167 const size_t sourceValue = *rowBegin; | 213 options.fHasPriorFrame = true; |
scroggo_chromium
2017/03/06 16:27:31
I was thinking you could move this into the block
cblume
2017/03/07 01:18:10
Done.
| |
168 if ((sourceValue != transparentPixel) && | 214 } |
169 (sourceValue < colorTable.size())) | 215 |
170 *currentAddress = colorTableIter[sourceValue]; | 216 SkCodec::Result startIncrementalDecodeResult = |
171 else | 217 m_codec->startIncrementalDecode(imageInfo, frame.bitmap().getPixels(), |
172 m_currentBufferSawAlpha = true; | 218 frame.bitmap().rowBytes(), &options, |
173 } | 219 nullptr, nullptr); |
174 } | 220 switch (startIncrementalDecodeResult) { |
175 | 221 case SkCodec::kSuccess: |
176 // Tell the frame to copy the row data if need be. | 222 break; |
177 if (repeatCount > 1) | 223 case SkCodec::kIncompleteInput: |
178 buffer.copyRowNTimes(xBegin, xEnd, yBegin, yEnd); | 224 return; |
179 | 225 default: |
180 buffer.setPixelsChanged(true); | 226 setFailed(); |
181 return true; | 227 return; |
182 } | 228 } |
183 | 229 frame.setStatus(ImageFrame::FramePartial); |
184 bool GIFImageDecoder::parseCompleted() const { | 230 } |
185 return m_reader && m_reader->parseCompleted(); | 231 |
186 } | 232 int rowsDecoded = 0; |
187 | 233 SkCodec::Result incrementalDecodeResult = |
188 bool GIFImageDecoder::frameComplete(size_t frameIndex) { | 234 m_codec->incrementalDecode(&rowsDecoded); |
189 // Initialize the frame if necessary. Some GIFs insert do-nothing frames, | 235 switch (incrementalDecodeResult) { |
190 // in which case we never reach haveDecodedRow() before getting here. | 236 case SkCodec::kSuccess: |
191 if (!initFrameBuffer(frameIndex)) | 237 frame.setPixelsChanged(true); |
192 return false; // initFrameBuffer() has already called setFailed(). | 238 frame.setStatus(ImageFrame::FrameComplete); |
193 | 239 break; |
194 m_frameBufferCache[frameIndex].setStatus(ImageFrame::FrameComplete); | 240 case SkCodec::kIncompleteInput: |
195 if (!m_currentBufferSawAlpha) | 241 // Only frame 0 may return kIncompleteInput without it being an error |
scroggo_chromium
2017/03/06 16:27:31
This comment does not match the code below. You do
cblume
2017/03/07 01:18:10
The comment was not very clear.
I don't want to ac
| |
196 correctAlphaWhenFrameBufferSawNoAlpha(frameIndex); | 242 if (isAllDataReceived()) { |
197 | 243 setFailed(); |
198 return true; | 244 return; |
199 } | 245 } |
200 | 246 |
201 void GIFImageDecoder::clearFrameBuffer(size_t frameIndex) { | 247 frame.setPixelsChanged(true); |
202 if (m_reader && | 248 frame.setStatus(ImageFrame::FramePartial); |
203 m_frameBufferCache[frameIndex].getStatus() == ImageFrame::FramePartial) { | 249 break; |
204 // Reset the state of the partial frame in the reader so that the frame | 250 default: |
205 // can be decoded again when requested. | |
206 m_reader->clearDecodeState(frameIndex); | |
207 } | |
208 ImageDecoder::clearFrameBuffer(frameIndex); | |
209 } | |
210 | |
211 size_t GIFImageDecoder::decodeFrameCount() { | |
212 parse(GIFFrameCountQuery); | |
213 // If decoding fails, |m_reader| will have been destroyed. Instead of | |
214 // returning 0 in this case, return the existing number of frames. This way | |
215 // if we get halfway through the image before decoding fails, we won't | |
216 // suddenly start reporting that the image has zero frames. | |
217 return failed() ? m_frameBufferCache.size() : m_reader->imagesCount(); | |
218 } | |
219 | |
220 void GIFImageDecoder::initializeNewFrame(size_t index) { | |
221 ImageFrame* buffer = &m_frameBufferCache[index]; | |
222 const GIFFrameContext* frameContext = m_reader->frameContext(index); | |
223 buffer->setOriginalFrameRect( | |
224 intersection(frameContext->frameRect(), IntRect(IntPoint(), size()))); | |
225 buffer->setDuration(frameContext->delayTime()); | |
226 buffer->setDisposalMethod(frameContext->getDisposalMethod()); | |
227 buffer->setRequiredPreviousFrameIndex( | |
228 findRequiredPreviousFrame(index, false)); | |
229 } | |
230 | |
231 void GIFImageDecoder::decode(size_t index) { | |
232 parse(GIFFrameCountQuery); | |
233 | |
234 if (failed()) | |
235 return; | |
236 | |
237 updateAggressivePurging(index); | |
238 | |
239 Vector<size_t> framesToDecode = findFramesToDecode(index); | |
240 for (auto i = framesToDecode.rbegin(); i != framesToDecode.rend(); ++i) { | |
241 if (!m_reader->decode(*i)) { | |
242 setFailed(); | 251 setFailed(); |
243 return; | 252 return; |
244 } | 253 } |
245 | 254 |
246 // If this returns false, we need more data to continue decoding. | 255 if (frame.getStatus() == ImageFrame::FrameComplete) { |
247 if (!postDecodeProcessing(*i)) | 256 if (!postDecodeProcessing(index)) |
248 break; | 257 return; |
scroggo_chromium
2017/03/06 16:27:31
There are no statements after this return, so it d
cblume
2017/03/07 01:18:11
Done.
| |
249 } | 258 } |
250 | 259 } |
251 // It is also a fatal error if all data is received and we have decoded all | 260 |
252 // frames available but the file is truncated. | 261 bool GIFImageDecoder::canReusePreviousFrameBuffer(size_t index) const { |
253 if (index >= m_frameBufferCache.size() - 1 && isAllDataReceived() && | 262 DCHECK(index < m_frameBufferCache.size()); |
254 m_reader && !m_reader->parseCompleted()) | 263 |
255 setFailed(); | 264 // If the current frame and the next frame depend on the same frame, we cannot |
256 } | 265 // reuse the old frame. We must preserve it for the next frame. |
257 | 266 // |
258 void GIFImageDecoder::parse(GIFParseQuery query) { | 267 // However, if the current and next frame depend on different frames then we |
259 if (failed()) | 268 // know the current frame is the last one to use the frame it depends on. That |
260 return; | 269 // means the current frame can reuse the previous frame buffer. |
261 | 270 // |
262 if (!m_reader) { | 271 // If we do not have information about the next frame yet, we cannot assume it |
263 m_reader = WTF::makeUnique<GIFImageReader>(this); | 272 // is safe to reuse the previous frame buffer. |
264 m_reader->setData(m_data); | 273 |
265 } | 274 if (index + 1 >= m_frameBufferCache.size()) |
266 | 275 return false; |
267 if (!m_reader->parse(query)) | 276 |
268 setFailed(); | 277 const ImageFrame& frame = m_frameBufferCache[index]; |
269 } | 278 size_t requiredFrameIndex = frame.requiredPreviousFrameIndex(); |
270 | 279 |
271 void GIFImageDecoder::onInitFrameBuffer(size_t frameIndex) { | 280 const ImageFrame& nextFrame = m_frameBufferCache[index + 1]; |
272 m_currentBufferSawAlpha = false; | 281 size_t nextRequiredFrameIndex = nextFrame.requiredPreviousFrameIndex(); |
273 } | 282 |
274 | 283 return requiredFrameIndex != nextRequiredFrameIndex; |
275 bool GIFImageDecoder::canReusePreviousFrameBuffer(size_t frameIndex) const { | |
276 DCHECK(frameIndex < m_frameBufferCache.size()); | |
277 return m_frameBufferCache[frameIndex].getDisposalMethod() != | |
278 ImageFrame::DisposeOverwritePrevious; | |
279 } | 284 } |
280 | 285 |
281 } // namespace blink | 286 } // namespace blink |
OLD | NEW |