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(nullptr), |
26 fTopRec(NULL), | 26 fTopRec(nullptr), |
27 fCount(0) { | 27 fCount(0) { |
28 } | 28 } |
29 | 29 |
30 SkLayerDrawLooper::~SkLayerDrawLooper() { | 30 SkLayerDrawLooper::~SkLayerDrawLooper() { |
31 Rec* rec = fRecs; | 31 Rec* rec = fRecs; |
32 while (rec) { | 32 while (rec) { |
33 Rec* next = rec->fNext; | 33 Rec* next = rec->fNext; |
34 delete rec; | 34 delete rec; |
35 rec = next; | 35 rec = next; |
36 } | 36 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 m.postTranslate(dx, dy); | 127 m.postTranslate(dx, dy); |
128 canvas->setMatrix(m); | 128 canvas->setMatrix(m); |
129 } | 129 } |
130 | 130 |
131 SkLayerDrawLooper::LayerDrawLooperContext::LayerDrawLooperContext( | 131 SkLayerDrawLooper::LayerDrawLooperContext::LayerDrawLooperContext( |
132 const SkLayerDrawLooper* looper) : fCurrRec(looper->fRecs) {} | 132 const SkLayerDrawLooper* looper) : fCurrRec(looper->fRecs) {} |
133 | 133 |
134 bool SkLayerDrawLooper::LayerDrawLooperContext::next(SkCanvas* canvas, | 134 bool SkLayerDrawLooper::LayerDrawLooperContext::next(SkCanvas* canvas, |
135 SkPaint* paint) { | 135 SkPaint* paint) { |
136 canvas->restore(); | 136 canvas->restore(); |
137 if (NULL == fCurrRec) { | 137 if (nullptr == fCurrRec) { |
138 return false; | 138 return false; |
139 } | 139 } |
140 | 140 |
141 ApplyInfo(paint, fCurrRec->fPaint, fCurrRec->fInfo); | 141 ApplyInfo(paint, fCurrRec->fPaint, fCurrRec->fInfo); |
142 | 142 |
143 canvas->save(); | 143 canvas->save(); |
144 if (fCurrRec->fInfo.fPostTranslate) { | 144 if (fCurrRec->fInfo.fPostTranslate) { |
145 postTranslate(canvas, fCurrRec->fInfo.fOffset.fX, | 145 postTranslate(canvas, fCurrRec->fInfo.fOffset.fX, |
146 fCurrRec->fInfo.fOffset.fY); | 146 fCurrRec->fInfo.fOffset.fY); |
147 } else { | 147 } else { |
(...skipping 12 matching lines...) Expand all Loading... |
160 const Rec* rec = fRecs; | 160 const Rec* rec = fRecs; |
161 | 161 |
162 // bottom layer needs to be just blur(maskfilter) | 162 // bottom layer needs to be just blur(maskfilter) |
163 if ((rec->fInfo.fPaintBits & ~kMaskFilter_Bit)) { | 163 if ((rec->fInfo.fPaintBits & ~kMaskFilter_Bit)) { |
164 return false; | 164 return false; |
165 } | 165 } |
166 if (SkXfermode::kSrc_Mode != rec->fInfo.fColorMode) { | 166 if (SkXfermode::kSrc_Mode != rec->fInfo.fColorMode) { |
167 return false; | 167 return false; |
168 } | 168 } |
169 const SkMaskFilter* mf = rec->fPaint.getMaskFilter(); | 169 const SkMaskFilter* mf = rec->fPaint.getMaskFilter(); |
170 if (NULL == mf) { | 170 if (nullptr == mf) { |
171 return false; | 171 return false; |
172 } | 172 } |
173 SkMaskFilter::BlurRec maskBlur; | 173 SkMaskFilter::BlurRec maskBlur; |
174 if (!mf->asABlur(&maskBlur)) { | 174 if (!mf->asABlur(&maskBlur)) { |
175 return false; | 175 return false; |
176 } | 176 } |
177 | 177 |
178 rec = rec->fNext; | 178 rec = rec->fNext; |
179 // top layer needs to be "plain" | 179 // top layer needs to be "plain" |
180 if (rec->fInfo.fPaintBits) { | 180 if (rec->fInfo.fPaintBits) { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 str->append("false "); | 286 str->append("false "); |
287 } | 287 } |
288 | 288 |
289 rec->fPaint.toString(str); | 289 rec->fPaint.toString(str); |
290 rec = rec->fNext; | 290 rec = rec->fNext; |
291 } | 291 } |
292 } | 292 } |
293 #endif | 293 #endif |
294 | 294 |
295 SkLayerDrawLooper::Builder::Builder() | 295 SkLayerDrawLooper::Builder::Builder() |
296 : fRecs(NULL), | 296 : fRecs(nullptr), |
297 fTopRec(NULL), | 297 fTopRec(nullptr), |
298 fCount(0) { | 298 fCount(0) { |
299 } | 299 } |
300 | 300 |
301 SkLayerDrawLooper::Builder::~Builder() { | 301 SkLayerDrawLooper::Builder::~Builder() { |
302 Rec* rec = fRecs; | 302 Rec* rec = fRecs; |
303 while (rec) { | 303 while (rec) { |
304 Rec* next = rec->fNext; | 304 Rec* next = rec->fNext; |
305 delete rec; | 305 delete rec; |
306 rec = next; | 306 rec = next; |
307 } | 307 } |
308 } | 308 } |
309 | 309 |
310 SkPaint* SkLayerDrawLooper::Builder::addLayer(const LayerInfo& info) { | 310 SkPaint* SkLayerDrawLooper::Builder::addLayer(const LayerInfo& info) { |
311 fCount += 1; | 311 fCount += 1; |
312 | 312 |
313 Rec* rec = new Rec; | 313 Rec* rec = new Rec; |
314 rec->fNext = fRecs; | 314 rec->fNext = fRecs; |
315 rec->fInfo = info; | 315 rec->fInfo = info; |
316 fRecs = rec; | 316 fRecs = rec; |
317 if (NULL == fTopRec) { | 317 if (nullptr == fTopRec) { |
318 fTopRec = rec; | 318 fTopRec = rec; |
319 } | 319 } |
320 | 320 |
321 return &rec->fPaint; | 321 return &rec->fPaint; |
322 } | 322 } |
323 | 323 |
324 void SkLayerDrawLooper::Builder::addLayer(SkScalar dx, SkScalar dy) { | 324 void SkLayerDrawLooper::Builder::addLayer(SkScalar dx, SkScalar dy) { |
325 LayerInfo info; | 325 LayerInfo info; |
326 | 326 |
327 info.fOffset.set(dx, dy); | 327 info.fOffset.set(dx, dy); |
328 (void)this->addLayer(info); | 328 (void)this->addLayer(info); |
329 } | 329 } |
330 | 330 |
331 SkPaint* SkLayerDrawLooper::Builder::addLayerOnTop(const LayerInfo& info) { | 331 SkPaint* SkLayerDrawLooper::Builder::addLayerOnTop(const LayerInfo& info) { |
332 fCount += 1; | 332 fCount += 1; |
333 | 333 |
334 Rec* rec = new Rec; | 334 Rec* rec = new Rec; |
335 rec->fNext = NULL; | 335 rec->fNext = nullptr; |
336 rec->fInfo = info; | 336 rec->fInfo = info; |
337 if (NULL == fRecs) { | 337 if (nullptr == fRecs) { |
338 fRecs = rec; | 338 fRecs = rec; |
339 } else { | 339 } else { |
340 SkASSERT(fTopRec); | 340 SkASSERT(fTopRec); |
341 fTopRec->fNext = rec; | 341 fTopRec->fNext = rec; |
342 } | 342 } |
343 fTopRec = rec; | 343 fTopRec = rec; |
344 | 344 |
345 return &rec->fPaint; | 345 return &rec->fPaint; |
346 } | 346 } |
347 | 347 |
348 SkLayerDrawLooper* SkLayerDrawLooper::Builder::detachLooper() { | 348 SkLayerDrawLooper* SkLayerDrawLooper::Builder::detachLooper() { |
349 SkLayerDrawLooper* looper = new SkLayerDrawLooper; | 349 SkLayerDrawLooper* looper = new SkLayerDrawLooper; |
350 looper->fCount = fCount; | 350 looper->fCount = fCount; |
351 looper->fRecs = fRecs; | 351 looper->fRecs = fRecs; |
352 | 352 |
353 fCount = 0; | 353 fCount = 0; |
354 fRecs = NULL; | 354 fRecs = nullptr; |
355 fTopRec = NULL; | 355 fTopRec = nullptr; |
356 | 356 |
357 return looper; | 357 return looper; |
358 } | 358 } |
OLD | NEW |