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

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

Issue 134163010: Refactor read and write buffers. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: original write flags were fine Created 6 years, 10 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 /* 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 "SkAnnotation.h"
19 #include "SkColorFilter.h" 19 #include "SkColorFilter.h"
20 #include "SkDrawLooper.h" 20 #include "SkDrawLooper.h"
21 #include "SkImageFilter.h" 21 #include "SkImageFilter.h"
22 #include "SkMaskFilter.h" 22 #include "SkMaskFilter.h"
23 #include "SkOrderedReadBuffer.h" 23 #include "SkReadBuffer.h"
24 #include "SkPathEffect.h" 24 #include "SkPathEffect.h"
25 #include "SkRasterizer.h" 25 #include "SkRasterizer.h"
26 #include "SkRRect.h" 26 #include "SkRRect.h"
27 #include "SkShader.h" 27 #include "SkShader.h"
28 #include "SkTypeface.h" 28 #include "SkTypeface.h"
29 #include "SkXfermode.h" 29 #include "SkXfermode.h"
30 30
31 static SkFlattenable::Type paintflat_to_flattype(PaintFlats pf) { 31 static SkFlattenable::Type paintflat_to_flattype(PaintFlats pf) {
32 static const uint8_t gEffectTypesInPaintFlatsOrder[] = { 32 static const uint8_t gEffectTypesInPaintFlatsOrder[] = {
33 SkFlattenable::kSkColorFilter_Type, 33 SkFlattenable::kSkColorFilter_Type,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 if (fFlags != flags) { 98 if (fFlags != flags) {
99 fFlags = flags; 99 fFlags = flags;
100 this->updateReader(); 100 this->updateReader();
101 } 101 }
102 } 102 }
103 103
104 unsigned getFlags() const { 104 unsigned getFlags() const {
105 return fFlags; 105 return fFlags;
106 } 106 }
107 107
108 void setReader(SkOrderedReadBuffer* reader) { 108 void setReader(SkReadBuffer* reader) {
109 fReader = reader; 109 fReader = reader;
110 this->updateReader(); 110 this->updateReader();
111 } 111 }
112 112
113 const SkPaint& paint() const { return fPaint; } 113 const SkPaint& paint() const { return fPaint; }
114 SkPaint* editPaint() { return &fPaint; } 114 SkPaint* editPaint() { return &fPaint; }
115 115
116 SkFlattenable* getFlat(unsigned index) const { 116 SkFlattenable* getFlat(unsigned index) const {
117 if (0 == index) { 117 if (0 == index) {
118 return NULL; 118 return NULL;
(...skipping 30 matching lines...) Expand all
149 if(fBitmaps.count() == index) { 149 if(fBitmaps.count() == index) {
150 bm = SkNEW(SkBitmap); 150 bm = SkNEW(SkBitmap);
151 *fBitmaps.append() = bm; 151 *fBitmaps.append() = bm;
152 } else { 152 } else {
153 bm = fBitmaps[index]; 153 bm = fBitmaps[index];
154 } 154 }
155 fReader->readBitmap(bm); 155 fReader->readBitmap(bm);
156 } 156 }
157 157
158 /** 158 /**
159 * Override of SkBitmapHeapReader, so that SkOrderedReadBuffer can use 159 * Override of SkBitmapHeapReader, so that SkReadBuffer can use
160 * these SkBitmaps for bitmap shaders. Used only in cross process mode 160 * these SkBitmaps for bitmap shaders. Used only in cross process mode
161 * without a shared heap. 161 * without a shared heap.
162 */ 162 */
163 virtual SkBitmap* getBitmap(int32_t index) const SK_OVERRIDE { 163 virtual SkBitmap* getBitmap(int32_t index) const SK_OVERRIDE {
164 SkASSERT(shouldFlattenBitmaps(fFlags)); 164 SkASSERT(shouldFlattenBitmaps(fFlags));
165 return fBitmaps[index]; 165 return fBitmaps[index];
166 } 166 }
167 167
168 /** 168 /**
169 * Needed to be a non-abstract subclass of SkBitmapHeapReader. 169 * Needed to be a non-abstract subclass of SkBitmapHeapReader.
(...skipping 26 matching lines...) Expand all
196 paint->setTypeface(id ? fTypefaces[id - 1] : NULL); 196 paint->setTypeface(id ? fTypefaces[id - 1] : NULL);
197 } 197 }
198 198
199 private: 199 private:
200 void updateReader() { 200 void updateReader() {
201 if (NULL == fReader) { 201 if (NULL == fReader) {
202 return; 202 return;
203 } 203 }
204 bool crossProcess = SkToBool(fFlags & SkGPipeWriter::kCrossProcess_Flag) ; 204 bool crossProcess = SkToBool(fFlags & SkGPipeWriter::kCrossProcess_Flag) ;
205 fReader->setFlags(SkSetClearMask(fReader->getFlags(), crossProcess, 205 fReader->setFlags(SkSetClearMask(fReader->getFlags(), crossProcess,
206 SkFlattenableReadBuffer::kCrossProcess_ Flag)); 206 SkReadBuffer::kCrossProcess_Flag));
207 if (crossProcess) { 207 if (crossProcess) {
208 fReader->setFactoryArray(&fFactoryArray); 208 fReader->setFactoryArray(&fFactoryArray);
209 } else { 209 } else {
210 fReader->setFactoryArray(NULL); 210 fReader->setFactoryArray(NULL);
211 } 211 }
212 212
213 if (shouldFlattenBitmaps(fFlags)) { 213 if (shouldFlattenBitmaps(fFlags)) {
214 fReader->setBitmapStorage(this); 214 fReader->setBitmapStorage(this);
215 } else { 215 } else {
216 fReader->setBitmapStorage(fSharedHeap); 216 fReader->setBitmapStorage(fSharedHeap);
217 } 217 }
218 } 218 }
219 SkOrderedReadBuffer* fReader; 219 SkReadBuffer* fReader;
scroggo 2014/01/29 20:07:21 nit: fReader no longer lines up with other members
mtklein 2014/01/29 20:38:29 Done.
220 SkPaint fPaint; 220 SkPaint fPaint;
221 SkTDArray<SkFlattenable*> fFlatArray; 221 SkTDArray<SkFlattenable*> fFlatArray;
222 SkTDArray<SkTypeface*> fTypefaces; 222 SkTDArray<SkTypeface*> fTypefaces;
223 SkTDArray<SkFlattenable::Factory> fFactoryArray; 223 SkTDArray<SkFlattenable::Factory> fFactoryArray;
224 SkTDArray<SkBitmap*> fBitmaps; 224 SkTDArray<SkBitmap*> fBitmaps;
225 bool fSilent; 225 bool fSilent;
226 // Only used when sharing bitmaps with the writer. 226 // Only used when sharing bitmaps with the writer.
227 SkBitmapHeap* fSharedHeap; 227 SkBitmapHeap* fSharedHeap;
228 unsigned fFlags; 228 unsigned fFlags;
229 }; 229 };
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 SkPaint* p = state->editPaint(); 689 SkPaint* p = state->editPaint();
690 p->setTypeface(static_cast<SkTypeface*>(reader->readPtr())); 690 p->setTypeface(static_cast<SkTypeface*>(reader->readPtr()));
691 } 691 }
692 692
693 static void annotation_rp(SkCanvas*, SkReader32* reader, uint32_t op32, 693 static void annotation_rp(SkCanvas*, SkReader32* reader, uint32_t op32,
694 SkGPipeState* state) { 694 SkGPipeState* state) {
695 SkPaint* p = state->editPaint(); 695 SkPaint* p = state->editPaint();
696 696
697 const size_t size = DrawOp_unpackData(op32); 697 const size_t size = DrawOp_unpackData(op32);
698 if (size > 0) { 698 if (size > 0) {
699 SkOrderedReadBuffer buffer(reader->skip(size), size); 699 SkReadBuffer buffer(reader->skip(size), size);
700 p->setAnnotation(SkNEW_ARGS(SkAnnotation, (buffer)))->unref(); 700 p->setAnnotation(SkNEW_ARGS(SkAnnotation, (buffer)))->unref();
701 SkASSERT(buffer.offset() == size); 701 SkASSERT(buffer.offset() == size);
702 } else { 702 } else {
703 p->setAnnotation(NULL); 703 p->setAnnotation(NULL);
704 } 704 }
705 } 705 }
706 706
707 /////////////////////////////////////////////////////////////////////////////// 707 ///////////////////////////////////////////////////////////////////////////////
708 708
709 static void def_Typeface_rp(SkCanvas*, SkReader32*, uint32_t, SkGPipeState* stat e) { 709 static void def_Typeface_rp(SkCanvas*, SkReader32*, uint32_t, SkGPipeState* stat e) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 850
851 if (NULL == fState) { 851 if (NULL == fState) {
852 fState = new SkGPipeState; 852 fState = new SkGPipeState;
853 } 853 }
854 854
855 fState->setSilent(playbackFlags & kSilent_PlaybackFlag); 855 fState->setSilent(playbackFlags & kSilent_PlaybackFlag);
856 856
857 SkASSERT(SK_ARRAY_COUNT(gReadTable) == (kDone_DrawOp + 1)); 857 SkASSERT(SK_ARRAY_COUNT(gReadTable) == (kDone_DrawOp + 1));
858 858
859 const ReadProc* table = gReadTable; 859 const ReadProc* table = gReadTable;
860 SkOrderedReadBuffer reader(data, length); 860 SkReadBuffer reader(data, length);
861 reader.setBitmapDecoder(fProc); 861 reader.setBitmapDecoder(fProc);
862 SkCanvas* canvas = fCanvas; 862 SkCanvas* canvas = fCanvas;
863 Status status = kEOF_Status; 863 Status status = kEOF_Status;
864 864
865 fState->setReader(&reader); 865 fState->setReader(&reader);
866 while (!reader.eof()) { 866 while (!reader.eof()) {
867 uint32_t op32 = reader.readUInt(); 867 uint32_t op32 = reader.readUInt();
868 unsigned op = DrawOp_unpackOp(op32); 868 unsigned op = DrawOp_unpackOp(op32);
869 // SkDEBUGCODE(DrawOps drawOp = (DrawOps)op;) 869 // SkDEBUGCODE(DrawOps drawOp = (DrawOps)op;)
870 870
(...skipping 16 matching lines...) Expand all
887 status = kReadAtom_Status; 887 status = kReadAtom_Status;
888 break; 888 break;
889 } 889 }
890 } 890 }
891 891
892 if (bytesRead) { 892 if (bytesRead) {
893 *bytesRead = reader.offset(); 893 *bytesRead = reader.offset();
894 } 894 }
895 return status; 895 return status;
896 } 896 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698