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 "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
11 #include "SkWriteBuffer.h" | 11 #include "SkWriteBuffer.h" |
12 #include "SkLayerDrawLooper.h" | 12 #include "SkLayerDrawLooper.h" |
13 #include "SkString.h" | 13 #include "SkString.h" |
14 #include "SkStringUtils.h" | 14 #include "SkStringUtils.h" |
15 #include "SkUnPreMultiply.h" | 15 #include "SkUnPreMultiply.h" |
16 | 16 |
17 SkLayerDrawLooper::LayerInfo::LayerInfo() { | 17 SkLayerDrawLooper::LayerInfo::LayerInfo() { |
18 fPaintBits = 0; // ignore our paint fields | 18 fPaintBits = 0; // ignore our paint fields |
19 fColorMode = SkXfermode::kDst_Mode; // ignore our color | 19 fColorMode = SkXfermode::kDst_Mode; // ignore our color |
20 fOffset.set(0, 0); | 20 fOffset.set(0, 0); |
21 fPostTranslate = false; | 21 fPostTranslate = false; |
22 } | 22 } |
23 | 23 |
24 SkLayerDrawLooper::SkLayerDrawLooper() | 24 SkLayerDrawLooper::SkLayerDrawLooper() |
25 : fRecs(NULL), | 25 : fRecs(NULL), |
26 fTopRec(NULL), | 26 fTopRec(NULL), |
27 fCount(0), | 27 fCount(0) { |
28 fCurrRec(NULL) { | |
29 } | 28 } |
30 | 29 |
31 SkLayerDrawLooper::~SkLayerDrawLooper() { | 30 SkLayerDrawLooper::~SkLayerDrawLooper() { |
32 Rec* rec = fRecs; | 31 Rec* rec = fRecs; |
33 while (rec) { | 32 while (rec) { |
34 Rec* next = rec->fNext; | 33 Rec* next = rec->fNext; |
35 SkDELETE(rec); | 34 SkDELETE(rec); |
36 rec = next; | 35 rec = next; |
37 } | 36 } |
38 } | 37 } |
(...skipping 29 matching lines...) Expand all Loading... |
68 fRecs = rec; | 67 fRecs = rec; |
69 } else { | 68 } else { |
70 SkASSERT(NULL != fTopRec); | 69 SkASSERT(NULL != fTopRec); |
71 fTopRec->fNext = rec; | 70 fTopRec->fNext = rec; |
72 } | 71 } |
73 fTopRec = rec; | 72 fTopRec = rec; |
74 | 73 |
75 return &rec->fPaint; | 74 return &rec->fPaint; |
76 } | 75 } |
77 | 76 |
78 void SkLayerDrawLooper::init(SkCanvas* canvas) { | 77 SkLayerDrawLooper::Context* SkLayerDrawLooper::createContext(SkCanvas* canvas, v
oid* storage) const { |
79 fCurrRec = fRecs; | |
80 canvas->save(SkCanvas::kMatrix_SaveFlag); | 78 canvas->save(SkCanvas::kMatrix_SaveFlag); |
| 79 return SkNEW_PLACEMENT_ARGS(storage, LayerDrawLooperContext, (this)); |
81 } | 80 } |
82 | 81 |
83 static SkColor xferColor(SkColor src, SkColor dst, SkXfermode::Mode mode) { | 82 static SkColor xferColor(SkColor src, SkColor dst, SkXfermode::Mode mode) { |
84 switch (mode) { | 83 switch (mode) { |
85 case SkXfermode::kSrc_Mode: | 84 case SkXfermode::kSrc_Mode: |
86 return src; | 85 return src; |
87 case SkXfermode::kDst_Mode: | 86 case SkXfermode::kDst_Mode: |
88 return dst; | 87 return dst; |
89 default: { | 88 default: { |
90 SkPMColor pmS = SkPreMultiplyColor(src); | 89 SkPMColor pmS = SkPreMultiplyColor(src); |
91 SkPMColor pmD = SkPreMultiplyColor(dst); | 90 SkPMColor pmD = SkPreMultiplyColor(dst); |
92 SkPMColor result = SkXfermode::GetProc(mode)(pmS, pmD); | 91 SkPMColor result = SkXfermode::GetProc(mode)(pmS, pmD); |
93 return SkUnPreMultiply::PMColorToColor(result); | 92 return SkUnPreMultiply::PMColorToColor(result); |
94 } | 93 } |
95 } | 94 } |
96 } | 95 } |
97 | 96 |
98 // Even with kEntirePaint_Bits, we always ensure that the master paint's | 97 // Even with kEntirePaint_Bits, we always ensure that the master paint's |
99 // text-encoding is respected, since that controls how we interpret the | 98 // text-encoding is respected, since that controls how we interpret the |
100 // text/length parameters of a draw[Pos]Text call. | 99 // text/length parameters of a draw[Pos]Text call. |
101 void SkLayerDrawLooper::ApplyInfo(SkPaint* dst, const SkPaint& src, | 100 void SkLayerDrawLooper::LayerDrawLooperContext::ApplyInfo( |
102 const LayerInfo& info) { | 101 SkPaint* dst, const SkPaint& src, const LayerInfo& info) { |
103 | 102 |
104 dst->setColor(xferColor(src.getColor(), dst->getColor(), info.fColorMode)); | 103 dst->setColor(xferColor(src.getColor(), dst->getColor(), info.fColorMode)); |
105 | 104 |
106 BitFlags bits = info.fPaintBits; | 105 BitFlags bits = info.fPaintBits; |
107 SkPaint::TextEncoding encoding = dst->getTextEncoding(); | 106 SkPaint::TextEncoding encoding = dst->getTextEncoding(); |
108 | 107 |
109 if (0 == bits) { | 108 if (0 == bits) { |
110 return; | 109 return; |
111 } | 110 } |
112 if (kEntirePaint_Bits == bits) { | 111 if (kEntirePaint_Bits == bits) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 #endif | 159 #endif |
161 } | 160 } |
162 | 161 |
163 // Should we add this to canvas? | 162 // Should we add this to canvas? |
164 static void postTranslate(SkCanvas* canvas, SkScalar dx, SkScalar dy) { | 163 static void postTranslate(SkCanvas* canvas, SkScalar dx, SkScalar dy) { |
165 SkMatrix m = canvas->getTotalMatrix(); | 164 SkMatrix m = canvas->getTotalMatrix(); |
166 m.postTranslate(dx, dy); | 165 m.postTranslate(dx, dy); |
167 canvas->setMatrix(m); | 166 canvas->setMatrix(m); |
168 } | 167 } |
169 | 168 |
170 bool SkLayerDrawLooper::next(SkCanvas* canvas, SkPaint* paint) { | 169 SkLayerDrawLooper::LayerDrawLooperContext::LayerDrawLooperContext( |
| 170 const SkLayerDrawLooper* looper) : fCurrRec(looper->fRecs) {} |
| 171 |
| 172 bool SkLayerDrawLooper::LayerDrawLooperContext::next(SkCanvas* canvas, |
| 173 SkPaint* paint) { |
171 canvas->restore(); | 174 canvas->restore(); |
172 if (NULL == fCurrRec) { | 175 if (NULL == fCurrRec) { |
173 return false; | 176 return false; |
174 } | 177 } |
175 | 178 |
176 ApplyInfo(paint, fCurrRec->fPaint, fCurrRec->fInfo); | 179 ApplyInfo(paint, fCurrRec->fPaint, fCurrRec->fInfo); |
177 | 180 |
178 canvas->save(SkCanvas::kMatrix_SaveFlag); | 181 canvas->save(SkCanvas::kMatrix_SaveFlag); |
179 if (fCurrRec->fInfo.fPostTranslate) { | 182 if (fCurrRec->fInfo.fPostTranslate) { |
180 postTranslate(canvas, fCurrRec->fInfo.fOffset.fX, | 183 postTranslate(canvas, fCurrRec->fInfo.fOffset.fX, |
181 fCurrRec->fInfo.fOffset.fY); | 184 fCurrRec->fInfo.fOffset.fY); |
182 } else { | 185 } else { |
183 canvas->translate(fCurrRec->fInfo.fOffset.fX, fCurrRec->fInfo.fOffset.fY
); | 186 canvas->translate(fCurrRec->fInfo.fOffset.fX, |
| 187 fCurrRec->fInfo.fOffset.fY); |
184 } | 188 } |
185 fCurrRec = fCurrRec->fNext; | 189 fCurrRec = fCurrRec->fNext; |
186 | 190 |
187 return true; | 191 return true; |
188 } | 192 } |
189 | 193 |
190 /////////////////////////////////////////////////////////////////////////////// | 194 /////////////////////////////////////////////////////////////////////////////// |
191 | 195 |
192 void SkLayerDrawLooper::flatten(SkWriteBuffer& buffer) const { | 196 void SkLayerDrawLooper::flatten(SkWriteBuffer& buffer) const { |
193 this->INHERITED::flatten(buffer); | 197 this->INHERITED::flatten(buffer); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 SkLayerDrawLooper* looper = SkNEW(SkLayerDrawLooper); | 372 SkLayerDrawLooper* looper = SkNEW(SkLayerDrawLooper); |
369 looper->fCount = fCount; | 373 looper->fCount = fCount; |
370 looper->fRecs = fRecs; | 374 looper->fRecs = fRecs; |
371 | 375 |
372 fCount = 0; | 376 fCount = 0; |
373 fRecs = NULL; | 377 fRecs = NULL; |
374 fTopRec = NULL; | 378 fTopRec = NULL; |
375 | 379 |
376 return looper; | 380 return looper; |
377 } | 381 } |
OLD | NEW |