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

Unified Diff: src/codec/SkStreamBuffer.h

Issue 2045293002: Add support for multiple frames in SkCodec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix a test - we now draw transparent background for missing color table Created 4 years, 2 months 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
« no previous file with comments | « src/codec/SkSampledCodec.cpp ('k') | src/codec/SkStreamBuffer.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/codec/SkStreamBuffer.h
diff --git a/src/codec/SkStreamBuffer.h b/src/codec/SkStreamBuffer.h
new file mode 100644
index 0000000000000000000000000000000000000000..f04ddcbfd8805ad9039d47c8b286cd7c608c074e
--- /dev/null
+++ b/src/codec/SkStreamBuffer.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkStreamBuffer_DEFINED
+#define SkStreamBuffer_DEFINED
+
+#include "SkStream.h"
+#include "SkTypes.h"
+
+/**
+ * Helper class for reading from a stream that may not have all its data
+ * available yet.
+ *
+ * Used by GIFImageReader, and currently set up for that use case.
+ *
+ * Buffers up to 256 * 3 bytes (256 colors, with 3 bytes each) to support GIF.
+ * FIXME (scroggo): Make this more general purpose?
+ */
+class SkStreamBuffer : SkNoncopyable {
+public:
+ // Takes ownership of the SkStream.
+ SkStreamBuffer(SkStream*);
+
+ /**
+ * Return a pointer the buffered data.
+ *
+ * The number of bytes buffered is the sum of values returned by calls to
+ * buffer() since the last call to flush().
+ */
+ const char* get() const { SkASSERT(fBytesBuffered >= 1); return fBuffer; }
+
+ /**
+ * Bytes in the buffer.
+ *
+ * Sum of the values returned by calls to buffer() since the last call to
+ * flush().
+ */
+ size_t bytesBuffered() const { return fBytesBuffered; }
+
+ /**
+ * Buffer from the stream into our buffer.
+ *
+ * Returns the number of bytes successfully buffered.
+ */
+ size_t buffer(size_t bytes);
+
+ /**
+ * Flush the buffer.
+ *
+ * After this call, no bytes are buffered.
+ */
+ void flush() {
+ fBytesBuffered = 0;
+ }
+
+private:
+ static constexpr size_t kMaxSize = 256 * 3;
+
+ std::unique_ptr<SkStream> fStream;
+ char fBuffer[kMaxSize];
+ size_t fBytesBuffered;
+};
+#endif // SkStreamBuffer_DEFINED
+
« no previous file with comments | « src/codec/SkSampledCodec.cpp ('k') | src/codec/SkStreamBuffer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698