Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(932)

Unified Diff: third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoder.h

Issue 2565323003: Move gif image decoder to SkCodec (Closed)
Patch Set: Removing impossible branch and old comment. Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoder.h
diff --git a/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoder.h b/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoder.h
index 0f68eb0e58d9711a1da64cd48cd0f5cc12e83b03..cd22c2e2da256de80d0a8f3a4594adad33262c97 100644
--- a/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoder.h
+++ b/third_party/WebKit/Source/platform/image-decoders/gif/GIFImageDecoder.h
@@ -27,13 +27,13 @@
#define GIFImageDecoder_h
#include "platform/image-decoders/ImageDecoder.h"
+#include "third_party/skia/include/codec/SkCodec.h"
+#include "third_party/skia/include/core/SkStream.h"
#include "wtf/Noncopyable.h"
+#include "wtf/RefPtr.h"
+#include <algorithm>
#include <memory>
-class GIFImageReader;
-
-typedef Vector<unsigned char> GIFRow;
-
namespace blink {
// This class decodes the GIF image format.
@@ -47,56 +47,83 @@ class PLATFORM_EXPORT GIFImageDecoder final : public ImageDecoder {
size_t maxDecodedBytes);
~GIFImageDecoder() override;
- enum GIFParseQuery { GIFSizeQuery, GIFFrameCountQuery };
-
// ImageDecoder:
String filenameExtension() const override { return "gif"; }
void onSetData(SegmentReader* data) override;
int repetitionCount() const override;
bool frameIsCompleteAtIndex(size_t) const override;
float frameDurationAtIndex(size_t) const override;
- // CAUTION: setFailed() deletes |m_reader|. Be careful to avoid
- // accessing deleted memory, especially when calling this from inside
- // GIFImageReader!
- bool setFailed() override;
-
- // Callbacks from the GIF reader.
- bool haveDecodedRow(size_t frameIndex,
- GIFRow::const_iterator rowBegin,
- size_t width,
- size_t rowNumber,
- unsigned repeatCount,
- bool writeTransparentPixels);
- bool frameComplete(size_t frameIndex);
-
- // For testing.
- bool parseCompleted() const;
private:
// ImageDecoder:
- void clearFrameBuffer(size_t frameIndex) override;
- virtual void decodeSize() { parse(GIFSizeQuery); }
+ void decodeSize() override;
size_t decodeFrameCount() override;
void initializeNewFrame(size_t) override;
void decode(size_t) override;
- // Parses as much as is needed to answer the query, ignoring bitmap
- // data. If parsing fails, sets the "decode failure" flag.
- void parse(GIFParseQuery);
-
- // Reset the alpha tracker for this frame. Before calling this method, the
- // caller must verify that the frame exists.
- 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) const override;
- bool m_currentBufferSawAlpha;
- mutable int m_repetitionCount;
- std::unique_ptr<GIFImageReader> m_reader;
+ class SegmentStream : public SkStream {
+ public:
+ SegmentStream()
+ : m_reader(),
+ m_position(0),
+ m_hasReadAllContents(true) {}
+
+ void setReader(SegmentReader* reader, bool allContentsReceived) {
+ m_reader = reader;
+ m_position = 0;
scroggo_chromium 2016/12/14 17:49:23 Why does this reset the position? You'll be receiv
cblume 2016/12/16 02:57:10 Yeah, that was a mistake. I removed it.
+ m_hasReadAllContents = false;
scroggo_chromium 2016/12/14 17:49:23 This assumes you will never be given a SegmentRead
cblume 2016/12/16 02:57:10 We might be thinking of different things. Perhaps
scroggo_chromium 2016/12/16 15:03:48 Yes, but that would be determined by m_position, w
cblume 2016/12/16 17:43:41 Done.
+ }
+
+ size_t read(void* dst, size_t len) {
+ len = std::min(len, m_reader->size());
+
+ size_t bytesAdvanced = 0;
+ if (!dst) { // skipping, not reading
+ bytesAdvanced = len;
+ } else {
+ size_t totalBytesRead = 0;
+ intptr_t destAsInt = reinterpret_cast<intptr_t>(dst);
scroggo_chromium 2016/12/14 17:49:23 I haven't seen this pattern before, and do not see
cblume 2016/12/16 02:57:10 Hrmmm you are right, it is optional. We had used t
+ while (len) {
+ const char* segment = nullptr;
+ size_t bytesRead = m_reader->getSomeData(segment, len);
scroggo_chromium 2016/12/14 17:49:23 This came up while I was reviewing the first patch
cblume 2016/12/16 02:57:10 Done.
+ if (!bytesRead) {
+ break;
+ }
+
+ memcpy(reinterpret_cast<void*>(destAsInt), segment, bytesRead);
+ destAsInt += bytesRead;
+ len -= bytesRead;
+ totalBytesRead += bytesRead;
+ }
+
+ bytesAdvanced = totalBytesRead;
+ }
+
+ m_position += bytesAdvanced;
+ m_hasReadAllContents = m_position == m_reader->size();
+
+ return bytesAdvanced;
+ }
+
+ bool isAtEnd() const override { return m_hasReadAllContents; }
+
+ private:
+ WTF::RefPtr<SegmentReader> m_reader;
+ size_t m_position;
+ bool m_hasReadAllContents;
+ };
+
+ std::unique_ptr<SkCodec> m_codec;
+ SegmentStream* m_segmentStream;
+ // m_segmentStream is a raw pointer because it passes ownership to
+ // m_codec when m_codec is created. However, we still need the
+ // reference so we can append more data as it arrives.
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698