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

Side by Side Diff: include/core/SkRWBuffer.h

Issue 1871953002: Fixes for SkRWBuffer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | src/core/SkRWBuffer.cpp » ('j') | tests/DataRefTest.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkRWBuffer_DEFINED 8 #ifndef SkRWBuffer_DEFINED
9 #define SkRWBuffer_DEFINED 9 #define SkRWBuffer_DEFINED
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 /** 47 /**
48 * Advance to the next contiguous block of memory, returning true if th ere is another 48 * Advance to the next contiguous block of memory, returning true if th ere is another
49 * block, or false if the iterator is exhausted. 49 * block, or false if the iterator is exhausted.
50 */ 50 */
51 bool next(); 51 bool next();
52 52
53 private: 53 private:
54 const SkBufferBlock* fBlock; 54 const SkBufferBlock* fBlock;
55 size_t fRemaining; 55 size_t fRemaining;
56 const SkROBuffer* fBuffer;
scroggo 2016/04/08 16:15:28 SkROBuffer is a const class, so should I remove th
56 }; 57 };
57 58
58 private: 59 private:
59 SkROBuffer(const SkBufferHead* head, size_t used); 60 SkROBuffer(const SkBufferHead* head, size_t used, const SkBufferBlock* tail) ;
60 virtual ~SkROBuffer(); 61 virtual ~SkROBuffer();
61 62
62 const SkBufferHead* fHead; 63 const SkBufferHead* fHead;
63 const size_t fUsed; 64 const size_t fUsed;
65
66 // Final block that existed when this object was created. It is the only blo ck that may
67 // have more bytes in it than this object knows about. Store its fUsed amoun t at creation
68 // time, so it can be read later without racing with a writer updating it.
69 const SkBufferBlock* fTail;
70 const size_t fTailUsed;
scroggo 2016/04/08 16:15:29 I'm not a huge fan of this name, but I don't have
64 71
65 friend class SkRWBuffer; 72 friend class SkRWBuffer;
66 }; 73 };
67 74
68 /** 75 /**
69 * Accumulates bytes of memory that are "appended" to it, growing internal stor age as needed. 76 * Accumulates bytes of memory that are "appended" to it, growing internal stor age as needed.
70 * The growth is done such that at any time, a RBuffer or StreamAsset can be sn apped off, which 77 * The growth is done such that at any time in the writer's thread, an RBuffer or StreamAsset
71 * can see the previously stored bytes, but which will be unaware of any future writes. 78 * can be snapped off (and safely passed to another thread). The RBuffer/Stream Asset snapshot
79 * can see the previously stored bytes, but will be unaware of any future write s.
72 */ 80 */
73 class SK_API SkRWBuffer { 81 class SK_API SkRWBuffer {
74 public: 82 public:
75 SkRWBuffer(size_t initialCapacity = 0); 83 SkRWBuffer(size_t initialCapacity = 0);
76 ~SkRWBuffer(); 84 ~SkRWBuffer();
77 85
78 size_t size() const { return fTotalUsed; } 86 size_t size() const { return fTotalUsed; }
79 void append(const void* buffer, size_t length); 87 void append(const void* buffer, size_t length);
80 void* append(size_t length); 88 void* append(size_t length);
81 89
82 SkROBuffer* newRBufferSnapshot() const; 90 SkROBuffer* newRBufferSnapshot() const;
83 SkStreamAsset* newStreamSnapshot() const; 91 SkStreamAsset* newStreamSnapshot() const;
84 92
85 #ifdef SK_DEBUG 93 #ifdef SK_DEBUG
86 void validate() const; 94 void validate() const;
87 #else 95 #else
88 void validate() const {} 96 void validate() const {}
89 #endif 97 #endif
90 98
91 private: 99 private:
92 SkBufferHead* fHead; 100 SkBufferHead* fHead;
93 SkBufferBlock* fTail; 101 SkBufferBlock* fTail;
94 size_t fTotalUsed; 102 size_t fTotalUsed;
95 }; 103 };
96 104
97 #endif 105 #endif
OLDNEW
« no previous file with comments | « no previous file | src/core/SkRWBuffer.cpp » ('j') | tests/DataRefTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698