<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - REGRESSION(r198782, r201043): [image-decoders] Flickering with some animated gif"
   href="https://bugs.webkit.org/show_bug.cgi?id=159089">159089</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>REGRESSION(r198782, r201043): [image-decoders] Flickering with some animated gif
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>WebKit
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>WebKit Local Build
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Unspecified
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Unspecified
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Keywords</th>
          <td>Gtk, Regression
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>Normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P2
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Platform
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>webkit-unassigned&#64;lists.webkit.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>cgarcia&#64;igalia.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>bugs-noreply&#64;webkitgtk.org, sabouhallawa&#64;apple.com, simon.fraser&#64;apple.com, thorton&#64;apple.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>There's some flickering when loading big enough animated gifs running the animation in a loop, you can try this one for example:

<a href="https://media0.giphy.com/media/l3UceJyj8Wwlkve8M/200.gif">https://media0.giphy.com/media/l3UceJyj8Wwlkve8M/200.gif</a>

The first time it loads everything is fine, but after the first loop iteration there are several flickering effects, once every time the animation finishes and some others happening in the middle of the animation loop. This doesn't affect mac ports, only ports using image-decoders implementation. The flickering happens because we fail to render some of the frames, and it has two diferent causes:

 - In r198782, ImageDecoder::createFrameImageAtIndex(), was modified to check first if the image is empty to return early, and then try to get the frame image from the decoder. This is the aone causing flickerin always on the first frame after one iteration. It happens because ImageDecoder::size() is always empty at that point. The first doesn't happen because the gif is loaded and BitmapImage calls isSizeAvailable() from BitmapImage::dataChanged(). The isSizeAvailable call makes the gif decoder calculate the size. But for the next iterations, frames are cached and BitmapImage already has the decoded data so isSizeAvailable is not called again. When createFrameImageAtIndex() is called again for the first frame, size is empty, until the gif decoder creates the reader again, which happens when frameBufferAtIndex() si called, so after that the size is available. So, we could call isSizeAvailable before checking the size, or simply do the check after the frameBufferAtIndex() as we used t

 - In r201043 BitmapImage::destroyDecodedDataIfNecessary() was fixed to use the actual bytes used by the frame in order to decide whether to destroy decoded data or not. This actually revealed a bug, it didn't happen before because we were never destroying frames before. The bug is in the gif decoder that doesn't correctly handle the case of destroying only some of the frames from the buffer. The gif decoder is designed to always process the frames in order, the reader keeps an index of the currently processed frame, when some frames are read from the cache, and then we ask the decoder for a not cached frame, the currently processed frame is not in sync with the actual frame we are asking for, and we end do not processing any frame at all.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>