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

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

Issue 481053002: Move SkReadBuffer.h and SkReader32.h out of include. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: second_try Created 6 years, 4 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 | « include/core/SkFlattenableBuffers.h ('k') | include/core/SkReader32.h » ('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 2011 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 SkReadBuffer_DEFINED
9 #define SkReadBuffer_DEFINED
10
11 #include "SkBitmapHeap.h"
12 #include "SkColorFilter.h"
13 #include "SkData.h"
14 #include "SkDrawLooper.h"
15 #include "SkImageFilter.h"
16 #include "SkMaskFilter.h"
17 #include "SkPath.h"
18 #include "SkPathEffect.h"
19 #include "SkPicture.h"
20 #include "SkRasterizer.h"
21 #include "SkReadBuffer.h"
22 #include "SkReader32.h"
23 #include "SkRefCnt.h"
24 #include "SkShader.h"
25 #include "SkWriteBuffer.h"
26 #include "SkXfermode.h"
27
28 class SkBitmap;
29
30 #if defined(SK_DEBUG) && defined(SK_BUILD_FOR_MAC)
31 #define DEBUG_NON_DETERMINISTIC_ASSERT
32 #endif
33
34 class SkReadBuffer {
35 public:
36 SkReadBuffer();
37 SkReadBuffer(const void* data, size_t size);
38 SkReadBuffer(SkStream* stream);
39 virtual ~SkReadBuffer();
40
41 enum Version {
42 kFilterLevelIsEnum_Version = 23,
43 kGradientFlippedFlag_Version = 24,
44 kDashWritesPhaseIntervals_Version = 25,
45 kColorShaderNoBool_Version = 26,
46 kNoUnitMappers_Version = 27,
47 kNoMoreBitmapFlatten_Version = 28,
48 kSimplifyLocalMatrix_Version = 30,
49 kImageFilterUniqueID_Version = 31,
50 kRemoveAndroidPaintOpts_Version = 32,
51 };
52
53 /**
54 * Returns true IFF the version is older than the specified version.
55 */
56 bool isVersionLT(Version targetVersion) const {
57 SkASSERT(targetVersion > 0);
58 return fVersion > 0 && fVersion < targetVersion;
59 }
60
61 /** This may be called at most once; most clients of SkReadBuffer should not mess with it. */
62 void setVersion(int version) {
63 SkASSERT(0 == fVersion || version == fVersion);
64 fVersion = version;
65 }
66
67 enum Flags {
68 kCrossProcess_Flag = 1 << 0,
69 kScalarIsFloat_Flag = 1 << 1,
70 kPtrIs64Bit_Flag = 1 << 2,
71 kValidation_Flag = 1 << 3,
72 };
73
74 void setFlags(uint32_t flags) { fFlags = flags; }
75 uint32_t getFlags() const { return fFlags; }
76
77 bool isCrossProcess() const {
78 return this->isValidating() || SkToBool(fFlags & kCrossProcess_Flag);
79 }
80 bool isScalarFloat() const { return SkToBool(fFlags & kScalarIsFloat_Flag); }
81 bool isPtr64Bit() const { return SkToBool(fFlags & kPtrIs64Bit_Flag); }
82 bool isValidating() const { return SkToBool(fFlags & kValidation_Flag); }
83
84 SkReader32* getReader32() { return &fReader; }
85
86 size_t size() { return fReader.size(); }
87 size_t offset() { return fReader.offset(); }
88 bool eof() { return fReader.eof(); }
89 virtual const void* skip(size_t size) { return fReader.skip(size); }
90 void* readFunctionPtr() { return fReader.readPtr(); }
91
92 // primitives
93 virtual bool readBool();
94 virtual SkColor readColor();
95 virtual SkFixed readFixed();
96 virtual int32_t readInt();
97 virtual SkScalar readScalar();
98 virtual uint32_t readUInt();
99 virtual int32_t read32();
100
101 // strings -- the caller is responsible for freeing the string contents
102 virtual void readString(SkString* string);
103 virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encodi ng);
104
105 // common data structures
106 virtual void readPoint(SkPoint* point);
107 SkPoint readPoint() { SkPoint p; this->readPoint(&p); return p; }
108 virtual void readMatrix(SkMatrix* matrix);
109 virtual void readIRect(SkIRect* rect);
110 virtual void readRect(SkRect* rect);
111 virtual void readRegion(SkRegion* region);
112
113 virtual void readPath(SkPath* path);
114 void readPaint(SkPaint* paint) { paint->unflatten(*this); }
115
116 virtual SkFlattenable* readFlattenable(SkFlattenable::Type);
117 template <typename T> T* readFlattenable() {
118 return (T*) this->readFlattenable(T::GetFlattenableType());
119 }
120 SkColorFilter* readColorFilter() { return this->readFlattenable<SkColorFilte r>(); }
121 SkDrawLooper* readDrawLooper() { return this->readFlattenable<SkDrawLooper >(); }
122 SkImageFilter* readImageFilter() { return this->readFlattenable<SkImageFilte r>(); }
123 SkMaskFilter* readMaskFilter() { return this->readFlattenable<SkMaskFilter >(); }
124 SkPathEffect* readPathEffect() { return this->readFlattenable<SkPathEffect >(); }
125 SkRasterizer* readRasterizer() { return this->readFlattenable<SkRasterizer >(); }
126 SkShader* readShader() { return this->readFlattenable<SkShader>(); }
127 SkXfermode* readXfermode() { return this->readFlattenable<SkXfermode>( ); }
128
129 /**
130 * Like readFlattenable() but explicitly just skips the data that was writt en for the
131 * flattenable (or the sentinel that there wasn't one).
132 */
133 virtual void skipFlattenable();
134
135 // binary data and arrays
136 virtual bool readByteArray(void* value, size_t size);
137 virtual bool readColorArray(SkColor* colors, size_t size);
138 virtual bool readIntArray(int32_t* values, size_t size);
139 virtual bool readPointArray(SkPoint* points, size_t size);
140 virtual bool readScalarArray(SkScalar* values, size_t size);
141
142 SkData* readByteArrayAsData() {
143 size_t len = this->getArrayCount();
144 if (!this->validateAvailable(len)) {
145 return SkData::NewEmpty();
146 }
147 void* buffer = sk_malloc_throw(len);
148 this->readByteArray(buffer, len);
149 return SkData::NewFromMalloc(buffer, len);
150 }
151
152 // helpers to get info about arrays and binary data
153 virtual uint32_t getArrayCount();
154
155 /**
156 * Returns false if the bitmap could not be completely read. In that case, it will be set
157 * to have width/height, but no pixels.
158 */
159 bool readBitmap(SkBitmap* bitmap);
160
161 virtual SkTypeface* readTypeface();
162
163 void setBitmapStorage(SkBitmapHeapReader* bitmapStorage) {
164 SkRefCnt_SafeAssign(fBitmapStorage, bitmapStorage);
165 }
166
167 void setTypefaceArray(SkTypeface* array[], int count) {
168 fTFArray = array;
169 fTFCount = count;
170 }
171
172 /**
173 * Call this with a pre-loaded array of Factories, in the same order as
174 * were created/written by the writer. SkPicture uses this.
175 */
176 void setFactoryPlayback(SkFlattenable::Factory array[], int count) {
177 fFactoryTDArray = NULL;
178 fFactoryArray = array;
179 fFactoryCount = count;
180 }
181
182 /**
183 * Call this with an initially empty array, so the reader can cache each
184 * factory it sees by name. Used by the pipe code in conjunction with
185 * SkWriteBuffer::setNamedFactoryRecorder.
186 */
187 void setFactoryArray(SkTDArray<SkFlattenable::Factory>* array) {
188 fFactoryTDArray = array;
189 fFactoryArray = NULL;
190 fFactoryCount = 0;
191 }
192
193 /**
194 * Provide a function to decode an SkBitmap from encoded data. Only used if the writer
195 * encoded the SkBitmap. If the proper decoder cannot be used, a red bitmap with the
196 * appropriate size will be used.
197 */
198 void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) {
199 fBitmapDecoder = bitmapDecoder;
200 }
201
202 // Default impelementations don't check anything.
203 virtual bool validate(bool isValid) { return true; }
204 virtual bool isValid() const { return true; }
205 virtual bool validateAvailable(size_t size) { return true; }
206
207 protected:
208 SkReader32 fReader;
209
210 private:
211 bool readArray(void* value, size_t size, size_t elementSize);
212
213 uint32_t fFlags;
214 int fVersion;
215
216 void* fMemoryPtr;
217
218 SkBitmapHeapReader* fBitmapStorage;
219 SkTypeface** fTFArray;
220 int fTFCount;
221
222 SkTDArray<SkFlattenable::Factory>* fFactoryTDArray;
223 SkFlattenable::Factory* fFactoryArray;
224 int fFactoryCount;
225
226 SkPicture::InstallPixelRefProc fBitmapDecoder;
227
228 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT
229 // Debugging counter to keep track of how many bitmaps we
230 // have decoded.
231 int fDecodedBitmapIndex;
232 #endif // DEBUG_NON_DETERMINISTIC_ASSERT
233 };
234
235 #endif // SkReadBuffer_DEFINED
OLDNEW
« no previous file with comments | « include/core/SkFlattenableBuffers.h ('k') | include/core/SkReader32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698