OLD | NEW |
---|---|
(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 #ifndef SkValidatingReadBuffer_DEFINED | |
9 #define SkValidatingReadBuffer_DEFINED | |
10 | |
11 #include "SkRefCnt.h" | |
12 #include "SkBitmapHeap.h" | |
13 #include "SkFlattenableBuffers.h" | |
14 #include "SkPath.h" | |
15 #include "SkPicture.h" | |
16 #include "SkReader32.h" | |
17 | |
18 class SkBitmap; | |
19 | |
20 #if defined(SK_DEBUG) && defined(SK_BUILD_FOR_MAC) | |
21 #define DEBUG_NON_DETERMINISTIC_ASSERT | |
22 #endif | |
23 | |
24 class SkValidatingReadBuffer : public SkFlattenableReadBuffer { | |
mtklein
2013/09/24 22:52:18
Looks like a solid copy and paste. :) How much o
sugoi1
2013/09/25 21:15:27
I removed everything except skip(), which I'm usin
| |
25 public: | |
26 SkValidatingReadBuffer(); | |
27 SkValidatingReadBuffer(const void* data, size_t size); | |
28 SkValidatingReadBuffer(SkStream* stream); | |
29 virtual ~SkValidatingReadBuffer(); | |
30 | |
31 SkReader32* getReader32() { return &fReader; } | |
32 | |
33 uint32_t size() { return fReader.size(); } | |
34 uint32_t offset() { return fReader.offset(); } | |
35 bool eof() { return fReader.eof(); } | |
36 const void* skip(size_t size); | |
37 | |
38 // primitives | |
39 virtual bool readBool() SK_OVERRIDE; | |
40 virtual SkColor readColor() SK_OVERRIDE; | |
41 virtual SkFixed readFixed() SK_OVERRIDE; | |
42 virtual int32_t readInt() SK_OVERRIDE; | |
43 virtual SkScalar readScalar() SK_OVERRIDE; | |
44 virtual uint32_t readUInt() SK_OVERRIDE; | |
45 virtual int32_t read32() SK_OVERRIDE; | |
46 | |
47 // strings -- the caller is responsible for freeing the string contents | |
48 virtual void readString(SkString* string) SK_OVERRIDE; | |
49 virtual void* readEncodedString(size_t* length, SkPaint::TextEncoding encodi ng) SK_OVERRIDE; | |
50 | |
51 // common data structures | |
52 virtual SkFlattenable* readFlattenable( | |
53 SkFlattenable::Type type = SkFlattenable::kSkFlattenable) SK_OVERRIDE; | |
54 virtual void readPoint(SkPoint* point) SK_OVERRIDE; | |
55 virtual void readMatrix(SkMatrix* matrix) SK_OVERRIDE; | |
56 virtual void readIRect(SkIRect* rect) SK_OVERRIDE; | |
57 virtual void readRect(SkRect* rect) SK_OVERRIDE; | |
58 virtual void readRegion(SkRegion* region) SK_OVERRIDE; | |
59 virtual void readPath(SkPath* path) SK_OVERRIDE; | |
60 | |
61 // binary data and arrays | |
62 virtual uint32_t readByteArray(void* value) SK_OVERRIDE; | |
63 virtual uint32_t readColorArray(SkColor* colors) SK_OVERRIDE; | |
64 virtual uint32_t readIntArray(int32_t* values) SK_OVERRIDE; | |
65 virtual uint32_t readPointArray(SkPoint* points) SK_OVERRIDE; | |
66 virtual uint32_t readScalarArray(SkScalar* values) SK_OVERRIDE; | |
67 | |
68 // helpers to get info about arrays and binary data | |
69 virtual uint32_t getArrayCount() SK_OVERRIDE; | |
70 | |
71 virtual void readBitmap(SkBitmap* bitmap) SK_OVERRIDE; | |
72 virtual SkTypeface* readTypeface() SK_OVERRIDE; | |
73 | |
74 void setBitmapStorage(SkBitmapHeapReader* bitmapStorage) { | |
75 SkRefCnt_SafeAssign(fBitmapStorage, bitmapStorage); | |
76 } | |
77 | |
78 void setTypefaceArray(SkTypeface* array[], int count) { | |
79 fTFArray = array; | |
80 fTFCount = count; | |
81 } | |
82 | |
83 /** | |
84 * Call this with a pre-loaded array of Factories, in the same order as | |
85 * were created/written by the writer. SkPicture uses this. | |
86 */ | |
87 void setFactoryPlayback(SkFlattenable::Factory array[], int count) { | |
88 fFactoryTDArray = NULL; | |
89 fFactoryArray = array; | |
90 fFactoryCount = count; | |
91 } | |
92 | |
93 /** | |
94 * Call this with an initially empty array, so the reader can cache each | |
95 * factory it sees by name. Used by the pipe code in conjunction with | |
96 * SkOrderedWriteBuffer::setNamedFactoryRecorder. | |
97 */ | |
98 void setFactoryArray(SkTDArray<SkFlattenable::Factory>* array) { | |
99 fFactoryTDArray = array; | |
100 fFactoryArray = NULL; | |
101 fFactoryCount = 0; | |
102 } | |
103 | |
104 /** | |
105 * Provide a function to decode an SkBitmap from encoded data. Only used if the writer | |
106 * encoded the SkBitmap. If the proper decoder cannot be used, a red bitmap with the | |
107 * appropriate size will be used. | |
108 */ | |
109 void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) { | |
110 fBitmapDecoder = bitmapDecoder; | |
111 } | |
112 | |
113 private: | |
114 void setMemory(const void* data, size_t size); | |
115 | |
116 static bool ptr_align_4(const void* ptr) { | |
mtklein
2013/09/24 22:52:18
I think we typically make static methods camel cas
sugoi1
2013/09/25 21:15:27
Done.
| |
117 return (((const char*)ptr - (const char*)NULL) & 3) == 0; | |
mtklein
2013/09/24 22:52:18
return (uintptr_t)ptr & 3 == 0?, or better yet Sk
sugoi1
2013/09/25 21:15:27
Done.
| |
118 } | |
119 | |
120 SkReader32 fReader; | |
121 void* fMemoryPtr; | |
122 | |
123 SkBitmapHeapReader* fBitmapStorage; | |
124 SkTypeface** fTFArray; | |
125 int fTFCount; | |
126 | |
127 SkTDArray<SkFlattenable::Factory>* fFactoryTDArray; | |
128 SkFlattenable::Factory* fFactoryArray; | |
129 int fFactoryCount; | |
130 | |
131 SkPicture::InstallPixelRefProc fBitmapDecoder; | |
132 | |
133 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT | |
mtklein
2013/09/24 22:52:18
I think we can throw this feature out too for now.
sugoi1
2013/09/25 21:15:27
Done.
| |
134 // Debugging counter to keep track of how many bitmaps we | |
135 // have decoded. | |
136 int fDecodedBitmapIndex; | |
137 #endif // DEBUG_NON_DETERMINISTIC_ASSERT | |
138 | |
139 typedef SkFlattenableReadBuffer INHERITED; | |
140 }; | |
141 | |
142 #endif // SkValidatingReadBuffer_DEFINED | |
OLD | NEW |