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

Side by Side Diff: src/pipe/SkGPipeRead.cpp

Issue 23548034: Follow up to serialization validation code (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "SkBitmapHeap.h" 10 #include "SkBitmapHeap.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkPaint.h" 12 #include "SkPaint.h"
13 #include "SkGPipe.h" 13 #include "SkGPipe.h"
14 #include "SkGPipePriv.h" 14 #include "SkGPipePriv.h"
15 #include "SkReader32.h" 15 #include "SkReader32.h"
16 #include "SkStream.h" 16 #include "SkStream.h"
17 17
18 #include "SkAnnotation.h"
18 #include "SkColorFilter.h" 19 #include "SkColorFilter.h"
19 #include "SkDrawLooper.h" 20 #include "SkDrawLooper.h"
21 #include "SkImageFilter.h"
20 #include "SkMaskFilter.h" 22 #include "SkMaskFilter.h"
21 #include "SkOrderedReadBuffer.h" 23 #include "SkOrderedReadBuffer.h"
22 #include "SkPathEffect.h" 24 #include "SkPathEffect.h"
23 #include "SkRasterizer.h" 25 #include "SkRasterizer.h"
24 #include "SkRRect.h" 26 #include "SkRRect.h"
25 #include "SkShader.h" 27 #include "SkShader.h"
26 #include "SkTypeface.h" 28 #include "SkTypeface.h"
27 #include "SkXfermode.h" 29 #include "SkXfermode.h"
28 30
29 static void set_paintflat(SkPaint* paint, SkFlattenable* obj, unsigned paintFlat ) { 31 static void set_paintflat(SkPaint* paint, SkFlattenable* obj, unsigned paintFlat ) {
(...skipping 24 matching lines...) Expand all
54 paint->setXfermode((SkXfermode*)obj); 56 paint->setXfermode((SkXfermode*)obj);
55 break; 57 break;
56 case kAnnotation_PaintFlat: 58 case kAnnotation_PaintFlat:
57 paint->setAnnotation((SkAnnotation*)obj); 59 paint->setAnnotation((SkAnnotation*)obj);
58 break; 60 break;
59 default: 61 default:
60 SkDEBUGFAIL("never gets here"); 62 SkDEBUGFAIL("never gets here");
61 } 63 }
62 } 64 }
63 65
66 static SkFlattenable* read_paintflat(SkFlattenableReadBuffer* reader, unsigned p aintFlat) {
reed1 2013/09/13 15:42:56 Seems like a lot of code to just check that paintF
sugoi1 2013/09/13 16:53:44 I'm not sure I understand. Each case uses a differ
67 SkASSERT(paintFlat < kCount_PaintFlats);
68 switch (paintFlat) {
69 case kColorFilter_PaintFlat:
70 return reader->readFlattenableT<SkColorFilter>();
71 case kDrawLooper_PaintFlat:
72 return reader->readFlattenableT<SkDrawLooper>();
73 case kMaskFilter_PaintFlat:
74 return reader->readFlattenableT<SkMaskFilter>();
75 case kPathEffect_PaintFlat:
76 return reader->readFlattenableT<SkPathEffect>();
77 case kRasterizer_PaintFlat:
78 return reader->readFlattenableT<SkRasterizer>();
79 case kShader_PaintFlat:
80 return reader->readFlattenableT<SkShader>();
81 case kImageFilter_PaintFlat:
82 return reader->readFlattenableT<SkImageFilter>();
83 case kXfermode_PaintFlat:
84 return reader->readFlattenableT<SkXfermode>();
85 case kAnnotation_PaintFlat:
86 return reader->readFlattenableT<SkAnnotation>();
87 default:
88 SkDEBUGFAIL("never gets here");
89 }
90 return NULL;
91 }
92
64 template <typename T> class SkRefCntTDArray : public SkTDArray<T> { 93 template <typename T> class SkRefCntTDArray : public SkTDArray<T> {
65 public: 94 public:
66 ~SkRefCntTDArray() { this->unrefAll(); } 95 ~SkRefCntTDArray() { this->unrefAll(); }
67 }; 96 };
68 97
69 class SkGPipeState : public SkBitmapHeapReader { 98 class SkGPipeState : public SkBitmapHeapReader {
70 public: 99 public:
71 SkGPipeState(); 100 SkGPipeState();
72 ~SkGPipeState(); 101 ~SkGPipeState();
73 102
(...skipping 26 matching lines...) Expand all
100 129
101 SkFlattenable* getFlat(unsigned index) const { 130 SkFlattenable* getFlat(unsigned index) const {
102 if (0 == index) { 131 if (0 == index) {
103 return NULL; 132 return NULL;
104 } 133 }
105 return fFlatArray[index - 1]; 134 return fFlatArray[index - 1];
106 } 135 }
107 136
108 void defFlattenable(PaintFlats pf, int index) { 137 void defFlattenable(PaintFlats pf, int index) {
109 index--; 138 index--;
110 SkFlattenable* obj = fReader->readFlattenable(); 139 SkFlattenable* obj = read_paintflat(fReader, pf);
111 if (fFlatArray.count() == index) { 140 if (fFlatArray.count() == index) {
112 *fFlatArray.append() = obj; 141 *fFlatArray.append() = obj;
113 } else { 142 } else {
114 SkSafeUnref(fFlatArray[index]); 143 SkSafeUnref(fFlatArray[index]);
115 fFlatArray[index] = obj; 144 fFlatArray[index] = obj;
116 } 145 }
117 } 146 }
118 147
119 void defFactory(const char* name) { 148 void defFactory(const char* name) {
120 SkFlattenable::Factory factory = SkFlattenable::NameToFactory(name); 149 SkFlattenable::Factory factory = SkFlattenable::NameToFactory(name);
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 status = kReadAtom_Status; 882 status = kReadAtom_Status;
854 break; 883 break;
855 } 884 }
856 } 885 }
857 886
858 if (bytesRead) { 887 if (bytesRead) {
859 *bytesRead = reader.offset(); 888 *bytesRead = reader.offset();
860 } 889 }
861 return status; 890 return status;
862 } 891 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698