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

Side by Side Diff: include/utils/SkBufferedStream.h

Issue 23717055: Add a buffered SkStream class. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Comments, check for NULL dst 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkStream.h"
9 #include "SkTypes.h"
10
11 class SkBufferedStream : public SkStreamRewindable {
bungeman-skia 2013/09/17 22:19:11 So I'm a bit iffy about the name, simply because t
scroggo 2013/09/18 15:15:44 Good point. How about SkFrontBufferedStream?
12 public:
13 /**
14 * Creates a new stream that wraps and buffers SkStream.
15 * @param stream SkStream to buffer. If NULL, NULL is returned. After
16 * this call, unref stream and do not refer to it.
17 * SkBufferedStream is expected to be its only owner.
18 * @param bufferSize Exact size of the buffer to be used.
19 * @return An SkStream that can buffer up to bufferSize.
20 */
21 static SkBufferedStream* Create(SkStream* stream, size_t bufferSize);
22
23 virtual size_t read(void* buffer, size_t size) SK_OVERRIDE;
24
25 virtual bool isAtEnd() const SK_OVERRIDE;
26
27 virtual bool rewind() SK_OVERRIDE;
28
29 virtual bool hasPosition() const SK_OVERRIDE { return true; }
30
31 virtual size_t getPosition() const SK_OVERRIDE { return fOffset; }
32
33 virtual bool hasLength() const SK_OVERRIDE;
34
35 virtual size_t getLength() const SK_OVERRIDE;
36
37 virtual SkStreamRewindable* duplicate() const SK_OVERRIDE { return NULL; }
38
39 private:
40 SkAutoTUnref<SkStream> fStream;
41 // Current offset into the stream. Always >= 0.
42 size_t fOffset;
43 // Amount that has been buffered by calls to read. Will always be less than
44 // fBufferSize.
45 size_t fBufferedSoFar;
46 // Total size of the buffer.
47 const size_t fBufferSize;
48 SkAutoTMalloc<char> fBuffer;
49
50 // Unimplemented.
51 SkBufferedStream();
52
53 // Private. Use Create.
54 SkBufferedStream(SkStream*, size_t bufferSize);
55
56 char* getBufferAtOffset() {
57 return fBuffer.get() + fOffset;
58 }
59
60 typedef SkStream INHERITED;
61 };
OLDNEW
« 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