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

Unified Diff: include/utils/SkBufferedStream.h

Issue 23717055: Add a buffered SkStream class. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 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
Index: include/utils/SkBufferedStream.h
diff --git a/include/utils/SkBufferedStream.h b/include/utils/SkBufferedStream.h
new file mode 100644
index 0000000000000000000000000000000000000000..e92b1a0685980c57207ffd18a44f14f0f9388eab
--- /dev/null
+++ b/include/utils/SkBufferedStream.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkStream.h"
+#include "SkTypes.h"
+
+class SkBufferedStream : public SkStreamRewindable {
+public:
+ /**
+ * Creates a new stream that wraps and buffers SkStream.
+ * @param stream SkStream to buffer. If NULL, NULL is returned. After
+ * this call, unref stream and do not refer to it.
+ * SkBufferedStream is expected to be its only owner.
+ * @param bufferSize Exact size of the buffer to be used.
+ * @return An SkStream that can buffer up to bufferSize.
+ */
+ static SkBufferedStream* Create(SkStream* stream, size_t bufferSize);
+
+ ~SkBufferedStream();
+
+ virtual size_t read(void* buffer, size_t size) SK_OVERRIDE;
+
+ virtual bool isAtEnd() const SK_OVERRIDE;
+
+ virtual bool rewind() SK_OVERRIDE;
+
+ virtual bool hasPosition() const SK_OVERRIDE { return true; }
+
+ virtual size_t getPosition() const SK_OVERRIDE { return fOffset; }
+
+ virtual bool hasLength() const SK_OVERRIDE;
+
+ virtual size_t getLength() const SK_OVERRIDE;
+
+ virtual SkStreamRewindable* duplicate() const SK_OVERRIDE { return NULL; }
+
+private:
+ SkStream* fStream;
mtklein 2013/09/17 19:18:32 SkAutoTUnref?
scroggo 2013/09/17 20:12:52 Done.
+ size_t fOffset;
+ size_t fBufferedSoFar;
+ const size_t fBufferSize;
+ SkAutoMalloc fBuffer;
mtklein 2013/09/17 19:18:32 Maybe use an SkAutoTMalloc<char> or <uint8_t> here
scroggo 2013/09/17 20:12:52 Done.
+
+ // Unimplemented.
+ SkBufferedStream();
+
+ // Private. Use Create.
+ SkBufferedStream(SkStream*, size_t bufferSize);
+
+ void* getBufferAtOffset() {
+ return reinterpret_cast<void*>(reinterpret_cast<char*>(fBuffer.get()) + fOffset);
+ }
+
+ typedef SkStream INHERITED;
+};
« no previous file with comments | « gyp/utils.gyp ('k') | src/utils/SkBufferedStream.cpp » ('j') | src/utils/SkBufferedStream.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698