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

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

Issue 1858323002: Enable flattening/unflattening with custom unflatten procs (Closed) Base URL: https://skia.googlesource.com/skia.git@flattenable
Patch Set: Avoid duping strings 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
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 SkReadBuffer_DEFINED 8 #ifndef SkReadBuffer_DEFINED
9 #define SkReadBuffer_DEFINED 9 #define SkReadBuffer_DEFINED
10 10
11 #include "SkBitmapHeap.h" 11 #include "SkBitmapHeap.h"
12 #include "SkColorFilter.h" 12 #include "SkColorFilter.h"
13 #include "SkData.h" 13 #include "SkData.h"
14 #include "SkDrawLooper.h" 14 #include "SkDrawLooper.h"
15 #include "SkImageFilter.h" 15 #include "SkImageFilter.h"
16 #include "SkMaskFilter.h" 16 #include "SkMaskFilter.h"
17 #include "SkPath.h" 17 #include "SkPath.h"
18 #include "SkPathEffect.h" 18 #include "SkPathEffect.h"
19 #include "SkPicture.h" 19 #include "SkPicture.h"
20 #include "SkRasterizer.h" 20 #include "SkRasterizer.h"
21 #include "SkReadBuffer.h" 21 #include "SkReadBuffer.h"
22 #include "SkReader32.h" 22 #include "SkReader32.h"
23 #include "SkRefCnt.h" 23 #include "SkRefCnt.h"
24 #include "SkShader.h" 24 #include "SkShader.h"
25 #include "SkTHash.h"
25 #include "SkWriteBuffer.h" 26 #include "SkWriteBuffer.h"
26 #include "SkXfermode.h" 27 #include "SkXfermode.h"
27 28
28 class SkBitmap; 29 class SkBitmap;
29 class SkImage; 30 class SkImage;
30 31
31 #if defined(SK_DEBUG) && defined(SK_BUILD_FOR_MAC) 32 #if defined(SK_DEBUG) && defined(SK_BUILD_FOR_MAC)
32 #define DEBUG_NON_DETERMINISTIC_ASSERT 33 #define DEBUG_NON_DETERMINISTIC_ASSERT
33 #endif 34 #endif
34 35
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 /** 188 /**
188 * Call this with a pre-loaded array of Factories, in the same order as 189 * Call this with a pre-loaded array of Factories, in the same order as
189 * were created/written by the writer. SkPicture uses this. 190 * were created/written by the writer. SkPicture uses this.
190 */ 191 */
191 void setFactoryPlayback(SkFlattenable::Factory array[], int count) { 192 void setFactoryPlayback(SkFlattenable::Factory array[], int count) {
192 fFactoryArray = array; 193 fFactoryArray = array;
193 fFactoryCount = count; 194 fFactoryCount = count;
194 } 195 }
195 196
196 /** 197 /**
198 * For an input flattenable (specified by name), set a custom factory proc
199 * to use when unflattening. Will make a copy of |name|.
200 *
201 * If the global registry already has a default factory for the flattenable ,
202 * this will override that factory. If a custom factory has already been
203 * set for the flattenable, this will override that factory.
204 *
205 * Custom factories cannot be removed.
206 */
207 void setCustomFactory(const SkString& name, SkFlattenable::Factory factory) {
mtklein 2016/04/19 18:14:55 Seems like calling setCustomFactory("...", nullptr
msarett 2016/04/19 18:55:51 Oh yeah of course. Will change the comment to ref
208 fCustomFactory.set(name, factory);
209 }
210
211 /**
197 * Provide a function to decode an SkBitmap from encoded data. Only used if the writer 212 * Provide a function to decode an SkBitmap from encoded data. Only used if the writer
198 * encoded the SkBitmap. If the proper decoder cannot be used, a red bitmap with the 213 * encoded the SkBitmap. If the proper decoder cannot be used, a red bitmap with the
199 * appropriate size will be used. 214 * appropriate size will be used.
200 */ 215 */
201 void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) { 216 void setBitmapDecoder(SkPicture::InstallPixelRefProc bitmapDecoder) {
202 fBitmapDecoder = bitmapDecoder; 217 fBitmapDecoder = bitmapDecoder;
203 } 218 }
204 219
205 // Default impelementations don't check anything. 220 // Default impelementations don't check anything.
206 virtual bool validate(bool isValid) { return true; } 221 virtual bool validate(bool isValid) { return true; }
207 virtual bool isValid() const { return true; } 222 virtual bool isValid() const { return true; }
208 virtual bool validateAvailable(size_t size) { return true; } 223 virtual bool validateAvailable(size_t size) { return true; }
209 224
210 protected: 225 protected:
211 SkReader32 fReader; 226 SkReader32 fReader;
212 227
228 /**
229 * Checks if a custom factory has been set for a given flattenable.
230 * Returns the custom factory if it exists, or nullptr otherwise.
231 */
232 SkFlattenable::Factory getCustomFactory(const SkString& name) {
233 SkFlattenable::Factory* factoryPtr = fCustomFactory.find(name);
234 return factoryPtr ? *factoryPtr : nullptr;
235 }
236
213 private: 237 private:
214 bool readArray(void* value, size_t size, size_t elementSize); 238 bool readArray(void* value, size_t size, size_t elementSize);
215 239
216 uint32_t fFlags; 240 uint32_t fFlags;
217 int fVersion; 241 int fVersion;
218 242
219 void* fMemoryPtr; 243 void* fMemoryPtr;
220 244
221 SkBitmapHeapReader* fBitmapStorage; 245 SkBitmapHeapReader* fBitmapStorage;
222 SkTypeface** fTFArray; 246 SkTypeface** fTFArray;
223 int fTFCount; 247 int fTFCount;
224 248
225 SkFlattenable::Factory* fFactoryArray; 249 SkFlattenable::Factory* fFactoryArray;
226 int fFactoryCount; 250 int fFactoryCount;
227 251
252 // Only used if we do not have an fFactoryArray.
253 SkTHashMap<SkString, SkFlattenable::Factory> fCustomFactory;
254 SkTHashMap<uint32_t, SkString> fFlattenableDict;
255
228 SkPicture::InstallPixelRefProc fBitmapDecoder; 256 SkPicture::InstallPixelRefProc fBitmapDecoder;
229 257
230 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT 258 #ifdef DEBUG_NON_DETERMINISTIC_ASSERT
231 // Debugging counter to keep track of how many bitmaps we 259 // Debugging counter to keep track of how many bitmaps we
232 // have decoded. 260 // have decoded.
233 int fDecodedBitmapIndex; 261 int fDecodedBitmapIndex;
234 #endif // DEBUG_NON_DETERMINISTIC_ASSERT 262 #endif // DEBUG_NON_DETERMINISTIC_ASSERT
235 }; 263 };
236 264
237 #endif // SkReadBuffer_DEFINED 265 #endif // SkReadBuffer_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698