| 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 | 
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  222            ImageFrame::DisposeOverwriteBgcolor) && |  222            ImageFrame::DisposeOverwriteBgcolor) && | 
|  223           !prevBuffer->hasAlpha() && |  223           !prevBuffer->hasAlpha() && | 
|  224           buffer.originalFrameRect().contains(prevBuffer->originalFrameRect())) |  224           buffer.originalFrameRect().contains(prevBuffer->originalFrameRect())) | 
|  225         buffer.setHasAlpha(false); |  225         buffer.setHasAlpha(false); | 
|  226     } |  226     } | 
|  227   } |  227   } | 
|  228  |  228  | 
|  229   return true; |  229   return true; | 
|  230 } |  230 } | 
|  231  |  231  | 
|  232 size_t GIFImageDecoder::clearCacheExceptFrame(size_t clearExceptFrame) { |  | 
|  233   // We expect that after this call, we'll be asked to decode frames after |  | 
|  234   // this one.  So we want to avoid clearing frames such that those requests |  | 
|  235   // would force re-decoding from the beginning of the image. |  | 
|  236   // |  | 
|  237   // When |clearExceptFrame| is e.g. DisposeKeep, simply not clearing that |  | 
|  238   // frame is sufficient, as the next frame will be based on it, and in |  | 
|  239   // general future frames can't be based on anything previous. |  | 
|  240   // |  | 
|  241   // However, if this frame is DisposeOverwritePrevious, then subsequent |  | 
|  242   // frames will depend on this frame's required previous frame.  In this |  | 
|  243   // case, we need to preserve both this frame and that one. |  | 
|  244   size_t clearExceptFrame2 = kNotFound; |  | 
|  245   if (clearExceptFrame < m_frameBufferCache.size()) { |  | 
|  246     const ImageFrame& frame = m_frameBufferCache[clearExceptFrame]; |  | 
|  247     if ((frame.getStatus() != ImageFrame::FrameEmpty) && |  | 
|  248         (frame.getDisposalMethod() == ImageFrame::DisposeOverwritePrevious)) { |  | 
|  249       clearExceptFrame2 = clearExceptFrame; |  | 
|  250       clearExceptFrame = frame.requiredPreviousFrameIndex(); |  | 
|  251     } |  | 
|  252   } |  | 
|  253  |  | 
|  254   // Now |clearExceptFrame| indicates the frame that future frames will |  | 
|  255   // depend on.  But if decoding is skipping forward past intermediate frames, |  | 
|  256   // this frame may be FrameEmpty.  So we need to keep traversing back through |  | 
|  257   // the required previous frames until we find the nearest non-empty |  | 
|  258   // ancestor.  Preserving that will minimize the amount of future decoding |  | 
|  259   // needed. |  | 
|  260   while ((clearExceptFrame < m_frameBufferCache.size()) && |  | 
|  261          (m_frameBufferCache[clearExceptFrame].getStatus() == |  | 
|  262           ImageFrame::FrameEmpty)) |  | 
|  263     clearExceptFrame = |  | 
|  264         m_frameBufferCache[clearExceptFrame].requiredPreviousFrameIndex(); |  | 
|  265   return clearCacheExceptTwoFrames(clearExceptFrame, clearExceptFrame2); |  | 
|  266 } |  | 
|  267  |  | 
|  268 void GIFImageDecoder::clearFrameBuffer(size_t frameIndex) { |  232 void GIFImageDecoder::clearFrameBuffer(size_t frameIndex) { | 
|  269   if (m_reader && |  233   if (m_reader && | 
|  270       m_frameBufferCache[frameIndex].getStatus() == ImageFrame::FramePartial) { |  234       m_frameBufferCache[frameIndex].getStatus() == ImageFrame::FramePartial) { | 
|  271     // Reset the state of the partial frame in the reader so that the frame |  235     // Reset the state of the partial frame in the reader so that the frame | 
|  272     // can be decoded again when requested. |  236     // can be decoded again when requested. | 
|  273     m_reader->clearDecodeState(frameIndex); |  237     m_reader->clearDecodeState(frameIndex); | 
|  274   } |  238   } | 
|  275   ImageDecoder::clearFrameBuffer(frameIndex); |  239   ImageDecoder::clearFrameBuffer(frameIndex); | 
|  276 } |  240 } | 
|  277  |  241  | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  339   m_currentBufferSawAlpha = false; |  303   m_currentBufferSawAlpha = false; | 
|  340 } |  304 } | 
|  341  |  305  | 
|  342 bool GIFImageDecoder::canReusePreviousFrameBuffer(size_t frameIndex) const { |  306 bool GIFImageDecoder::canReusePreviousFrameBuffer(size_t frameIndex) const { | 
|  343   DCHECK(frameIndex < m_frameBufferCache.size()); |  307   DCHECK(frameIndex < m_frameBufferCache.size()); | 
|  344   return m_frameBufferCache[frameIndex].getDisposalMethod() != |  308   return m_frameBufferCache[frameIndex].getDisposalMethod() != | 
|  345          ImageFrame::DisposeOverwritePrevious; |  309          ImageFrame::DisposeOverwritePrevious; | 
|  346 } |  310 } | 
|  347  |  311  | 
|  348 }  // namespace blink |  312 }  // namespace blink | 
| OLD | NEW |