Index: third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.h |
diff --git a/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.h b/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.h |
index a2e3d6810f10712af7a482976a43efc3a9668c38..4c567cfa8e5ccf21a7a2b43f4d7c9cd622bad30d 100644 |
--- a/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.h |
+++ b/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.h |
@@ -27,6 +27,7 @@ |
#define PNGImageDecoder_h |
#include "platform/image-decoders/ImageDecoder.h" |
+#include "platform/image-decoders/png/PNGImageReader.h" |
#include <memory> |
namespace blink { |
@@ -45,24 +46,67 @@ class PLATFORM_EXPORT PNGImageDecoder final : public ImageDecoder { |
// ImageDecoder: |
String filenameExtension() const override { return "png"; } |
+ int repetitionCount() const override; |
+ bool frameIsCompleteAtIndex(size_t) const override; |
+ float frameDurationAtIndex(size_t) const override; |
+ // Failures are handled differently, based on the image and state of the |
+ // decoder: |
+ // |
+ // 1) When a non-animated PNG or the first frame of an animated PNG can't be |
+ // decoded or parsed, set the decoder to the failed state, because there |
+ // are no frames we can show to the client. Also set the state to failed if |
+ // a parse error occurs before any frames were received. |
+ // 2) When a decoding failure occurs for non-first frames, we still want to |
+ // show earlier frames. This means the frame count needs to be adjusted. |
+ // 3) When a parsing failure occurs, the frame count is adjusted to the number |
+ // of successfully parsed frames, since we can still show those. |
+ // |
+ // In cases 2 and 3, we have to prevent parse() from adjusting the frame |
+ // count to pre-failure values by setting |m_failedWithCorrectFrames| to true. |
+ bool setFailed() override; |
// Callbacks from libpng |
void headerAvailable(); |
void rowAvailable(unsigned char* row, unsigned rowIndex, int); |
void complete(); |
+ // Additional methods used for APNG |
+ void setRepetitionCount(size_t); |
+ |
private: |
// ImageDecoder: |
- void decodeSize() override { decode(true); } |
- void decode(size_t) override { decode(false); } |
+ void decodeSize() override { |
+ parse(PNGImageReader::PNGParseQuery::PNGSizeQuery); |
+ } |
+ void decode(size_t) override; |
+ size_t decodeFrameCount() override; |
+ void initializeNewFrame(size_t) override; |
+ void clearFrameBuffer(size_t) override; |
+ |
+ // Create an interlacing buffer when the frame is encoded with interlacing. |
+ void onInitFrameBuffer(size_t) override; |
+ |
+ // When the disposal method of the frame is DisposeOverwritePrevious, the |
+ // next frame will use the previous frame's buffer as its starting state, so |
+ // we can't take over the data in that case. Before calling this method, the |
+ // caller must verify that the frame exists. |
+ bool canReusePreviousFrameBuffer(size_t index) const override; |
+ |
+ void parse(PNGImageReader::PNGParseQuery); |
- // Decodes the image. If |onlySize| is true, stops decoding after |
- // calculating the image size. If decoding fails but there is no more |
- // data coming, sets the "decode failure" flag. |
- void decode(bool onlySize); |
+ PNGImageReader m_reader; |
+ size_t m_frameCount; |
+ size_t m_currentFrame; |
+ // m_repetitionCount is set to cAnimationLoopOnce by default, so the |
+ // DeferredImageDecoder takes into account that this may be an animated |
+ // image, but we don't know for sure yet. |
+ int m_repetitionCount; |
+ bool m_hasAlphaChannel; |
+ bool m_currentBufferSawAlpha; |
- std::unique_ptr<PNGImageReader> m_reader; |
- const unsigned m_offset; |
+ // This flag is set to true while PNGImageReader is parsing. This is used by |
+ // setFailed() to determine how to handle a failure. |
+ bool m_isParsing; |
}; |
} // namespace blink |