Chromium Code Reviews| 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 dacc93828c0ce9879cd776667be3e5fb0c33aed2..4da4f2e3e1bb727f83a1d21ade6ba68aa9bce302 100644 |
| --- a/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.h |
| +++ b/third_party/WebKit/Source/platform/image-decoders/png/PNGImageDecoder.h |
| @@ -44,26 +44,77 @@ class PLATFORM_EXPORT PNGImageDecoder final : public ImageDecoder { |
| size_t offset = 0); |
| ~PNGImageDecoder() override; |
| + enum class PNGParseQuery { PNGSizeQuery, PNGMetaDataQuery }; |
| + |
| // 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(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; |
| - // 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); |
| + // When the disposal method of the frame is DisposeOverwritePrevious, the |
|
scroggo_chromium
2016/12/07 13:44:44
Is this not already explained in the base class? C
joostouwerling
2016/12/07 16:49:10
The base class explains how this method is used (i
|
| + // 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(PNGParseQuery); |
| + // Used by clearCacheExceptFrame if two frames need to be kept in cache. |
| + size_t clearCacheExceptTwoFrames(size_t, size_t); |
|
scroggo_chromium
2016/12/07 13:44:44
I thought this was moved to the base class?
joostouwerling
2016/12/07 16:49:10
Yes. Removed it.
|
| std::unique_ptr<PNGImageReader> m_reader; |
| const unsigned m_offset; |
| + 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; |
| + |
| + // 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; |
| + // This flag is set to true when a failure has occured, but there are earlier |
| + // frames that can still be shown. In that case, the frame count is lowered. |
| + // This flag prevents from calling parse() again, which could change the frame |
|
scroggo_chromium
2016/12/07 13:44:44
What if instead we set the reader's m_parseComplet
joostouwerling
2016/12/07 16:49:10
That'd work for parsing errors, but not for decodi
|
| + // count back to the pre-failure value. |
| + bool m_failedWithCorrectFrames; |
| }; |
| } // namespace blink |