OLD | NEW |
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 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkColor.h" | 9 #include "SkColor.h" |
10 #include "SkFlattenableBuffers.h" | 10 #include "SkFlattenableBuffers.h" |
11 #include "SkLayerDrawLooper.h" | 11 #include "SkLayerDrawLooper.h" |
12 #include "SkString.h" | 12 #include "SkString.h" |
13 #include "SkStringUtils.h" | 13 #include "SkStringUtils.h" |
14 #include "SkUnPreMultiply.h" | 14 #include "SkUnPreMultiply.h" |
15 | 15 |
16 SK_DEFINE_INST_COUNT(SkLayerDrawLooper) | 16 SK_DEFINE_INST_COUNT(SkLayerDrawLooper) |
17 | 17 |
18 SkLayerDrawLooper::LayerInfo::LayerInfo() { | 18 SkLayerDrawLooper::LayerInfo::LayerInfo() { |
19 fFlagsMask = 0; // ignore our paint flags | 19 fFlagsMask = 0; // ignore our paint flags |
20 fPaintBits = 0; // ignore our paint fields | 20 fPaintBits = 0; // ignore our paint fields |
21 fColorMode = SkXfermode::kDst_Mode; // ignore our color | 21 fColorMode = SkXfermode::kDst_Mode; // ignore our color |
22 fOffset.set(0, 0); | 22 fOffset.set(0, 0); |
23 fPostTranslate = false; | 23 fPostTranslate = false; |
24 } | 24 } |
25 | 25 |
26 SkLayerDrawLooper::SkLayerDrawLooper() | 26 SkLayerDrawLooper::SkLayerDrawLooper() |
27 : fRecs(NULL), | 27 : fRecs(NULL), |
| 28 fTopRec(NULL), |
28 fCount(0), | 29 fCount(0), |
29 fCurrRec(NULL) { | 30 fCurrRec(NULL) { |
30 } | 31 } |
31 | 32 |
32 SkLayerDrawLooper::~SkLayerDrawLooper() { | 33 SkLayerDrawLooper::~SkLayerDrawLooper() { |
33 Rec* rec = fRecs; | 34 Rec* rec = fRecs; |
34 while (rec) { | 35 while (rec) { |
35 Rec* next = rec->fNext; | 36 Rec* next = rec->fNext; |
36 SkDELETE(rec); | 37 SkDELETE(rec); |
37 rec = next; | 38 rec = next; |
38 } | 39 } |
39 } | 40 } |
40 | 41 |
41 SkPaint* SkLayerDrawLooper::addLayer(const LayerInfo& info) { | 42 SkPaint* SkLayerDrawLooper::addLayer(const LayerInfo& info) { |
42 fCount += 1; | 43 fCount += 1; |
43 | 44 |
44 Rec* rec = SkNEW(Rec); | 45 Rec* rec = SkNEW(Rec); |
45 rec->fNext = fRecs; | 46 rec->fNext = fRecs; |
46 rec->fInfo = info; | 47 rec->fInfo = info; |
47 fRecs = rec; | 48 fRecs = rec; |
| 49 if (NULL == fTopRec) { |
| 50 fTopRec = rec; |
| 51 } |
48 | 52 |
49 return &rec->fPaint; | 53 return &rec->fPaint; |
50 } | 54 } |
51 | 55 |
52 void SkLayerDrawLooper::addLayer(SkScalar dx, SkScalar dy) { | 56 void SkLayerDrawLooper::addLayer(SkScalar dx, SkScalar dy) { |
53 LayerInfo info; | 57 LayerInfo info; |
54 | 58 |
55 info.fOffset.set(dx, dy); | 59 info.fOffset.set(dx, dy); |
56 (void)this->addLayer(info); | 60 (void)this->addLayer(info); |
57 } | 61 } |
58 | 62 |
| 63 SkPaint* SkLayerDrawLooper::addLayerOnTop(const LayerInfo& info) { |
| 64 fCount += 1; |
| 65 |
| 66 Rec* rec = SkNEW(Rec); |
| 67 rec->fNext = NULL; |
| 68 rec->fInfo = info; |
| 69 if (NULL == fRecs) { |
| 70 fRecs = rec; |
| 71 } else { |
| 72 SkASSERT(NULL != fTopRec); |
| 73 fTopRec->fNext = rec; |
| 74 } |
| 75 fTopRec = rec; |
| 76 |
| 77 return &rec->fPaint; |
| 78 } |
| 79 |
59 void SkLayerDrawLooper::init(SkCanvas* canvas) { | 80 void SkLayerDrawLooper::init(SkCanvas* canvas) { |
60 fCurrRec = fRecs; | 81 fCurrRec = fRecs; |
61 canvas->save(SkCanvas::kMatrix_SaveFlag); | 82 canvas->save(SkCanvas::kMatrix_SaveFlag); |
62 } | 83 } |
63 | 84 |
64 static SkColor xferColor(SkColor src, SkColor dst, SkXfermode::Mode mode) { | 85 static SkColor xferColor(SkColor src, SkColor dst, SkXfermode::Mode mode) { |
65 switch (mode) { | 86 switch (mode) { |
66 case SkXfermode::kSrc_Mode: | 87 case SkXfermode::kSrc_Mode: |
67 return src; | 88 return src; |
68 case SkXfermode::kDst_Mode: | 89 case SkXfermode::kDst_Mode: |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 postTranslate(canvas, fCurrRec->fInfo.fOffset.fX, | 184 postTranslate(canvas, fCurrRec->fInfo.fOffset.fX, |
164 fCurrRec->fInfo.fOffset.fY); | 185 fCurrRec->fInfo.fOffset.fY); |
165 } else { | 186 } else { |
166 canvas->translate(fCurrRec->fInfo.fOffset.fX, fCurrRec->fInfo.fOffset.fY
); | 187 canvas->translate(fCurrRec->fInfo.fOffset.fX, fCurrRec->fInfo.fOffset.fY
); |
167 } | 188 } |
168 fCurrRec = fCurrRec->fNext; | 189 fCurrRec = fCurrRec->fNext; |
169 | 190 |
170 return true; | 191 return true; |
171 } | 192 } |
172 | 193 |
173 SkLayerDrawLooper::Rec* SkLayerDrawLooper::Rec::Reverse(Rec* head) { | |
174 Rec* rec = head; | |
175 Rec* prev = NULL; | |
176 while (rec) { | |
177 Rec* next = rec->fNext; | |
178 rec->fNext = prev; | |
179 prev = rec; | |
180 rec = next; | |
181 } | |
182 return prev; | |
183 } | |
184 | |
185 /////////////////////////////////////////////////////////////////////////////// | 194 /////////////////////////////////////////////////////////////////////////////// |
186 | 195 |
187 void SkLayerDrawLooper::flatten(SkFlattenableWriteBuffer& buffer) const { | 196 void SkLayerDrawLooper::flatten(SkFlattenableWriteBuffer& buffer) const { |
188 this->INHERITED::flatten(buffer); | 197 this->INHERITED::flatten(buffer); |
189 | 198 |
190 #ifdef SK_DEBUG | 199 #ifdef SK_DEBUG |
191 { | 200 { |
192 Rec* rec = fRecs; | 201 Rec* rec = fRecs; |
193 int count = 0; | 202 int count = 0; |
194 while (rec) { | 203 while (rec) { |
(...skipping 14 matching lines...) Expand all Loading... |
209 buffer.writePoint(rec->fInfo.fOffset); | 218 buffer.writePoint(rec->fInfo.fOffset); |
210 buffer.writeBool(rec->fInfo.fPostTranslate); | 219 buffer.writeBool(rec->fInfo.fPostTranslate); |
211 buffer.writePaint(rec->fPaint); | 220 buffer.writePaint(rec->fPaint); |
212 rec = rec->fNext; | 221 rec = rec->fNext; |
213 } | 222 } |
214 } | 223 } |
215 | 224 |
216 SkLayerDrawLooper::SkLayerDrawLooper(SkFlattenableReadBuffer& buffer) | 225 SkLayerDrawLooper::SkLayerDrawLooper(SkFlattenableReadBuffer& buffer) |
217 : INHERITED(buffer), | 226 : INHERITED(buffer), |
218 fRecs(NULL), | 227 fRecs(NULL), |
| 228 fTopRec(NULL), |
219 fCount(0), | 229 fCount(0), |
220 fCurrRec(NULL) { | 230 fCurrRec(NULL) { |
221 int count = buffer.readInt(); | 231 int count = buffer.readInt(); |
222 | 232 |
223 for (int i = 0; i < count; i++) { | 233 for (int i = 0; i < count; i++) { |
224 LayerInfo info; | 234 LayerInfo info; |
225 info.fFlagsMask = buffer.readInt(); | 235 info.fFlagsMask = buffer.readInt(); |
226 info.fPaintBits = buffer.readInt(); | 236 info.fPaintBits = buffer.readInt(); |
227 info.fColorMode = (SkXfermode::Mode)buffer.readInt(); | 237 info.fColorMode = (SkXfermode::Mode)buffer.readInt(); |
228 buffer.readPoint(&info.fOffset); | 238 buffer.readPoint(&info.fOffset); |
229 info.fPostTranslate = buffer.readBool(); | 239 info.fPostTranslate = buffer.readBool(); |
230 buffer.readPaint(this->addLayer(info)); | 240 buffer.readPaint(this->addLayerOnTop(info)); |
231 } | 241 } |
232 SkASSERT(count == fCount); | 242 SkASSERT(count == fCount); |
233 | 243 |
234 // we're in reverse order, so fix it now | |
235 fRecs = Rec::Reverse(fRecs); | |
236 | |
237 #ifdef SK_DEBUG | 244 #ifdef SK_DEBUG |
238 { | 245 { |
239 Rec* rec = fRecs; | 246 Rec* rec = fRecs; |
240 int n = 0; | 247 int n = 0; |
241 while (rec) { | 248 while (rec) { |
242 rec = rec->fNext; | 249 rec = rec->fNext; |
243 n += 1; | 250 n += 1; |
244 } | 251 } |
245 SkASSERT(count == n); | 252 SkASSERT(count == n); |
246 } | 253 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 str->append("true "); | 342 str->append("true "); |
336 } else { | 343 } else { |
337 str->append("false "); | 344 str->append("false "); |
338 } | 345 } |
339 | 346 |
340 rec->fPaint.toString(str); | 347 rec->fPaint.toString(str); |
341 rec = rec->fNext; | 348 rec = rec->fNext; |
342 } | 349 } |
343 } | 350 } |
344 #endif | 351 #endif |
OLD | NEW |