OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
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 "SkLayerRasterizer.h" | 10 #include "SkLayerRasterizer.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 SkLayerRasterizer::SkLayerRasterizer() | 28 SkLayerRasterizer::SkLayerRasterizer() |
29 : fLayers(SkNEW_ARGS(SkDeque, (sizeof(SkLayerRasterizer_Rec)))) | 29 : fLayers(SkNEW_ARGS(SkDeque, (sizeof(SkLayerRasterizer_Rec)))) |
30 { | 30 { |
31 } | 31 } |
32 | 32 |
33 SkLayerRasterizer::SkLayerRasterizer(SkDeque* layers) : fLayers(layers) | 33 SkLayerRasterizer::SkLayerRasterizer(SkDeque* layers) : fLayers(layers) |
34 { | 34 { |
35 } | 35 } |
36 | 36 |
37 SkLayerRasterizer::~SkLayerRasterizer() { | 37 // Helper function to call destructors on SkPaints held by layers and delete lay
ers. |
38 SkASSERT(fLayers); | 38 static void clean_up_layers(SkDeque* layers) { |
39 SkDeque::F2BIter iter(*fLayers); | 39 SkDeque::F2BIter iter(*layers); |
40 SkLayerRasterizer_Rec* rec; | 40 SkLayerRasterizer_Rec* rec; |
41 | 41 |
42 while ((rec = (SkLayerRasterizer_Rec*)iter.next()) != NULL) | 42 while ((rec = (SkLayerRasterizer_Rec*)iter.next()) != NULL) |
43 rec->fPaint.~SkPaint(); | 43 rec->fPaint.~SkPaint(); |
44 | 44 |
45 SkDELETE(fLayers); | 45 SkDELETE(layers); |
| 46 } |
| 47 |
| 48 SkLayerRasterizer::~SkLayerRasterizer() { |
| 49 SkASSERT(fLayers); |
| 50 clean_up_layers(const_cast<SkDeque*>(fLayers)); |
46 } | 51 } |
47 | 52 |
48 #ifdef SK_SUPPORT_LEGACY_LAYERRASTERIZER_API | 53 #ifdef SK_SUPPORT_LEGACY_LAYERRASTERIZER_API |
49 void SkLayerRasterizer::addLayer(const SkPaint& paint, SkScalar dx, | 54 void SkLayerRasterizer::addLayer(const SkPaint& paint, SkScalar dx, |
50 SkScalar dy) { | 55 SkScalar dy) { |
51 SkASSERT(fLayers); | 56 SkASSERT(fLayers); |
52 SkLayerRasterizer_Rec* rec = (SkLayerRasterizer_Rec*)fLayers->push_back(); | 57 SkLayerRasterizer_Rec* rec = (SkLayerRasterizer_Rec*)fLayers->push_back(); |
53 | 58 |
54 SkNEW_PLACEMENT_ARGS(&rec->fPaint, SkPaint, (paint)); | 59 SkNEW_PLACEMENT_ARGS(&rec->fPaint, SkPaint, (paint)); |
55 rec->fOffset.set(dx, dy); | 60 rec->fOffset.set(dx, dy); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } | 192 } |
188 } | 193 } |
189 | 194 |
190 SkLayerRasterizer::Builder::Builder() | 195 SkLayerRasterizer::Builder::Builder() |
191 : fLayers(SkNEW_ARGS(SkDeque, (sizeof(SkLayerRasterizer_Rec)))) | 196 : fLayers(SkNEW_ARGS(SkDeque, (sizeof(SkLayerRasterizer_Rec)))) |
192 { | 197 { |
193 } | 198 } |
194 | 199 |
195 SkLayerRasterizer::Builder::~Builder() | 200 SkLayerRasterizer::Builder::~Builder() |
196 { | 201 { |
197 SkDELETE(fLayers); | 202 if (fLayers != NULL) { |
| 203 clean_up_layers(fLayers); |
| 204 } |
198 } | 205 } |
199 | 206 |
200 void SkLayerRasterizer::Builder::addLayer(const SkPaint& paint, SkScalar dx, | 207 void SkLayerRasterizer::Builder::addLayer(const SkPaint& paint, SkScalar dx, |
201 SkScalar dy) { | 208 SkScalar dy) { |
202 SkASSERT(fLayers); | 209 SkASSERT(fLayers); |
203 SkLayerRasterizer_Rec* rec = (SkLayerRasterizer_Rec*)fLayers->push_back(); | 210 SkLayerRasterizer_Rec* rec = (SkLayerRasterizer_Rec*)fLayers->push_back(); |
204 | 211 |
205 SkNEW_PLACEMENT_ARGS(&rec->fPaint, SkPaint, (paint)); | 212 SkNEW_PLACEMENT_ARGS(&rec->fPaint, SkPaint, (paint)); |
206 rec->fOffset.set(dx, dy); | 213 rec->fOffset.set(dx, dy); |
207 } | 214 } |
208 | 215 |
209 SkLayerRasterizer* SkLayerRasterizer::Builder::detachRasterizer() { | 216 SkLayerRasterizer* SkLayerRasterizer::Builder::detachRasterizer() { |
210 SkLayerRasterizer* rasterizer = SkNEW_ARGS(SkLayerRasterizer, (fLayers)); | 217 SkLayerRasterizer* rasterizer = SkNEW_ARGS(SkLayerRasterizer, (fLayers)); |
211 fLayers = NULL; | 218 fLayers = NULL; |
212 return rasterizer; | 219 return rasterizer; |
213 } | 220 } |
| 221 |
| 222 SkLayerRasterizer* SkLayerRasterizer::Builder::snapshotRasterizer() const { |
| 223 SkDeque* layers = SkNEW_ARGS(SkDeque, (sizeof(SkLayerRasterizer_Rec), fLayer
s->count())); |
| 224 SkDeque::F2BIter iter(*fLayers); |
| 225 const SkLayerRasterizer_Rec* recOrig; |
| 226 SkDEBUGCODE(int count = 0;) |
| 227 while ((recOrig = static_cast<SkLayerRasterizer_Rec*>(iter.next())) != NULL)
{ |
| 228 SkDEBUGCODE(count++); |
| 229 SkLayerRasterizer_Rec* recCopy = static_cast<SkLayerRasterizer_Rec*>(lay
ers->push_back()); |
| 230 SkNEW_PLACEMENT_ARGS(&recCopy->fPaint, SkPaint, (recOrig->fPaint)); |
| 231 recCopy->fOffset = recOrig->fOffset; |
| 232 } |
| 233 SkASSERT(fLayers->count() == count); |
| 234 SkASSERT(layers->count() == count); |
| 235 SkLayerRasterizer* rasterizer = SkNEW_ARGS(SkLayerRasterizer, (layers)); |
| 236 return rasterizer; |
| 237 } |
OLD | NEW |