Title: [202616] trunk/Source/WebCore
Revision
202616
Author
[email protected]
Date
2016-06-29 00:23:51 -0700 (Wed, 29 Jun 2016)

Log Message

REGRESSION(r198782, r201043): [image-decoders] Flickering with some animated gif
https://bugs.webkit.org/show_bug.cgi?id=159089

Reviewed by Antonio Gomes.

There's some flickering when loading big enough animated gifs running the animation in a loop. 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. 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 the flickering
always on the first frame after one iteration. It happens because ImageDecoder::size() is always empty at that
point. The first time 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() is 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() call as we used to do.

 - 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 cache. The gif decoder is designed to always process the
frames in order, the reader keeps an index of the currently processed frame, so 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.

* platform/image-decoders/ImageDecoder.cpp:
(WebCore::ImageDecoder::createFrameImageAtIndex): Check the size after calling frameBufferAtIndex().
* platform/image-decoders/gif/GIFImageDecoder.cpp:
(WebCore::GIFImageDecoder::clearFrameBufferCache): Delete the reader when clearing the cache since it's out of sync.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (202615 => 202616)


--- trunk/Source/WebCore/ChangeLog	2016-06-29 06:33:57 UTC (rev 202615)
+++ trunk/Source/WebCore/ChangeLog	2016-06-29 07:23:51 UTC (rev 202616)
@@ -1,3 +1,39 @@
+2016-06-29  Carlos Garcia Campos  <[email protected]>
+
+        REGRESSION(r198782, r201043): [image-decoders] Flickering with some animated gif
+        https://bugs.webkit.org/show_bug.cgi?id=159089
+
+        Reviewed by Antonio Gomes.
+
+        There's some flickering when loading big enough animated gifs running the animation in a loop. 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. 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 the flickering
+        always on the first frame after one iteration. It happens because ImageDecoder::size() is always empty at that
+        point. The first time 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() is 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() call as we used to do.
+
+         - 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 cache. The gif decoder is designed to always process the
+        frames in order, the reader keeps an index of the currently processed frame, so 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.
+
+        * platform/image-decoders/ImageDecoder.cpp:
+        (WebCore::ImageDecoder::createFrameImageAtIndex): Check the size after calling frameBufferAtIndex().
+        * platform/image-decoders/gif/GIFImageDecoder.cpp:
+        (WebCore::GIFImageDecoder::clearFrameBufferCache): Delete the reader when clearing the cache since it's out of sync.
+
 2016-06-28  Carlos Garcia Campos  <[email protected]>
 
         [GStreamer] Adaptive streaming issues

Modified: trunk/Source/WebCore/platform/image-decoders/ImageDecoder.cpp (202615 => 202616)


--- trunk/Source/WebCore/platform/image-decoders/ImageDecoder.cpp	2016-06-29 06:33:57 UTC (rev 202615)
+++ trunk/Source/WebCore/platform/image-decoders/ImageDecoder.cpp	2016-06-29 07:23:51 UTC (rev 202616)
@@ -312,13 +312,11 @@
 
 NativeImagePtr ImageDecoder::createFrameImageAtIndex(size_t index, SubsamplingLevel)
 {
-    // Zero-height images can cause problems for some ports. If we have an
-    // empty image dimension, just bail.
-    if (size().isEmpty())
-        return nullptr;
-
     ImageFrame* buffer = frameBufferAtIndex(index);
-    if (!buffer || buffer->status() == ImageFrame::FrameEmpty)
+    // Zero-height images can cause problems for some ports. If we have an empty image dimension, just bail.
+    // It's important to check the size after calling frameBufferAtIndex() to ensure the decoder has updated the size.
+    // See https://bugs.webkit.org/show_bug.cgi?id=159089.
+    if (!buffer || buffer->status() == ImageFrame::FrameEmpty || size().isEmpty())
         return nullptr;
 
     // Return the buffer contents as a native image. For some ports, the data

Modified: trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp (202615 => 202616)


--- trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp	2016-06-29 06:33:57 UTC (rev 202615)
+++ trunk/Source/WebCore/platform/image-decoders/gif/GIFImageDecoder.cpp	2016-06-29 07:23:51 UTC (rev 202616)
@@ -176,6 +176,10 @@
         if (j->status() != ImageFrame::FrameEmpty)
             j->clearPixelData();
     }
+
+    // When some frames are cleared, the reader is out of sync, since the caller might ask for any frame not
+    // necessarily in the order expected by the reader. See https://bugs.webkit.org/show_bug.cgi?id=159089.
+    m_reader = nullptr;
 }
 
 bool GIFImageDecoder::haveDecodedRow(unsigned frameIndex, const Vector<unsigned char>& rowBuffer, size_t width, size_t rowNumber, unsigned repeatCount, bool writeTransparentPixels)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to