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

Side by Side 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, 1 month 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
« no previous file with comments | « src/codec/SkSampledCodec.cpp ('k') | src/codec/SkStreamBuffer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 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 #ifndef SkStreamBuffer_DEFINED
9 #define SkStreamBuffer_DEFINED
10
11 #include "SkStream.h"
12 #include "SkTypes.h"
13
14 /**
15 * Helper class for reading from a stream that may not have all its data
16 * available yet.
17 *
18 * Used by GIFImageReader, and currently set up for that use case.
19 *
20 * Buffers up to 256 * 3 bytes (256 colors, with 3 bytes each) to support GIF.
21 * FIXME (scroggo): Make this more general purpose?
22 */
23 class SkStreamBuffer : SkNoncopyable {
24 public:
25 // Takes ownership of the SkStream.
26 SkStreamBuffer(SkStream*);
27
28 /**
29 * Return a pointer the buffered data.
30 *
31 * The number of bytes buffered is the sum of values returned by calls to
32 * buffer() since the last call to flush().
33 */
34 const char* get() const { SkASSERT(fBytesBuffered >= 1); return fBuffer; }
35
36 /**
37 * Bytes in the buffer.
38 *
39 * Sum of the values returned by calls to buffer() since the last call to
40 * flush().
41 */
42 size_t bytesBuffered() const { return fBytesBuffered; }
43
44 /**
45 * Buffer from the stream into our buffer.
46 *
47 * Returns the number of bytes successfully buffered.
48 */
49 size_t buffer(size_t bytes);
50
51 /**
52 * Flush the buffer.
53 *
54 * After this call, no bytes are buffered.
55 */
56 void flush() {
57 fBytesBuffered = 0;
58 }
59
60 private:
61 static constexpr size_t kMaxSize = 256 * 3;
62
63 std::unique_ptr<SkStream> fStream;
64 char fBuffer[kMaxSize];
65 size_t fBytesBuffered;
66 };
67 #endif // SkStreamBuffer_DEFINED
68
OLDNEW
« 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