OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkRecorder.h" | |
9 #include "SkPatchUtils.h" | 8 #include "SkPatchUtils.h" |
10 #include "SkPicture.h" | 9 #include "SkPicture.h" |
| 10 #include "SkPictureUtils.h" |
| 11 #include "SkRecorder.h" |
11 | 12 |
12 SkDrawableList::~SkDrawableList() { | 13 SkDrawableList::~SkDrawableList() { |
13 fArray.unrefAll(); | 14 fArray.unrefAll(); |
14 } | 15 } |
15 | 16 |
16 SkPicture::SnapshotArray* SkDrawableList::newDrawableSnapshot() { | 17 SkPicture::SnapshotArray* SkDrawableList::newDrawableSnapshot() { |
17 const int count = fArray.count(); | 18 const int count = fArray.count(); |
18 if (0 == count) { | 19 if (0 == count) { |
19 return NULL; | 20 return NULL; |
20 } | 21 } |
21 SkAutoTMalloc<const SkPicture*> pics(count); | 22 SkAutoTMalloc<const SkPicture*> pics(count); |
22 for (int i = 0; i < count; ++i) { | 23 for (int i = 0; i < count; ++i) { |
23 pics[i] = fArray[i]->newPictureSnapshot(); | 24 pics[i] = fArray[i]->newPictureSnapshot(); |
24 } | 25 } |
25 return SkNEW_ARGS(SkPicture::SnapshotArray, (pics.detach(), count)); | 26 return SkNEW_ARGS(SkPicture::SnapshotArray, (pics.detach(), count)); |
26 } | 27 } |
27 | 28 |
28 void SkDrawableList::append(SkDrawable* drawable) { | 29 void SkDrawableList::append(SkDrawable* drawable) { |
29 *fArray.append() = SkRef(drawable); | 30 *fArray.append() = SkRef(drawable); |
30 } | 31 } |
31 | 32 |
32 ////////////////////////////////////////////////////////////////////////////////
/////////////// | 33 ////////////////////////////////////////////////////////////////////////////////
/////////////// |
33 | 34 |
34 SkRecorder::SkRecorder(SkRecord* record, int width, int height) | 35 SkRecorder::SkRecorder(SkRecord* record, int width, int height) |
35 : SkCanvas(SkIRect::MakeWH(width, height), SkCanvas::kConservativeRasterClip
_InitFlag) | 36 : SkCanvas(SkIRect::MakeWH(width, height), SkCanvas::kConservativeRasterClip
_InitFlag) |
| 37 , fApproxBytesUsedBySubPictures(0) |
36 , fRecord(record) {} | 38 , fRecord(record) {} |
37 | 39 |
38 SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds) | 40 SkRecorder::SkRecorder(SkRecord* record, const SkRect& bounds) |
39 : SkCanvas(bounds.roundOut(), SkCanvas::kConservativeRasterClip_InitFlag) | 41 : SkCanvas(bounds.roundOut(), SkCanvas::kConservativeRasterClip_InitFlag) |
| 42 , fApproxBytesUsedBySubPictures(0) |
40 , fRecord(record) {} | 43 , fRecord(record) {} |
41 | 44 |
42 void SkRecorder::reset(SkRecord* record, const SkRect& bounds) { | 45 void SkRecorder::reset(SkRecord* record, const SkRect& bounds) { |
43 this->forgetRecord(); | 46 this->forgetRecord(); |
44 fRecord = record; | 47 fRecord = record; |
45 this->resetForNextPicture(bounds.roundOut()); | 48 this->resetForNextPicture(bounds.roundOut()); |
46 } | 49 } |
47 | 50 |
48 void SkRecorder::forgetRecord() { | 51 void SkRecorder::forgetRecord() { |
49 fDrawableList.reset(NULL); | 52 fDrawableList.reset(NULL); |
| 53 fApproxBytesUsedBySubPictures = 0; |
50 fRecord = NULL; | 54 fRecord = NULL; |
51 } | 55 } |
52 | 56 |
53 // To make appending to fRecord a little less verbose. | 57 // To make appending to fRecord a little less verbose. |
54 #define APPEND(T, ...) \ | 58 #define APPEND(T, ...) \ |
55 SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__V
A_ARGS__)) | 59 SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__V
A_ARGS__)) |
56 | 60 |
57 // For methods which must call back into SkCanvas. | 61 // For methods which must call back into SkCanvas. |
58 #define INHERITED(method, ...) this->SkCanvas::method(__VA_ARGS__) | 62 #define INHERITED(method, ...) this->SkCanvas::method(__VA_ARGS__) |
59 | 63 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 delay_copy(path), | 245 delay_copy(path), |
242 matrix ? *matrix : SkMatrix::I()); | 246 matrix ? *matrix : SkMatrix::I()); |
243 } | 247 } |
244 | 248 |
245 void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, | 249 void SkRecorder::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
246 const SkPaint& paint) { | 250 const SkPaint& paint) { |
247 APPEND(DrawTextBlob, delay_copy(paint), blob, x, y); | 251 APPEND(DrawTextBlob, delay_copy(paint), blob, x, y); |
248 } | 252 } |
249 | 253 |
250 void SkRecorder::onDrawPicture(const SkPicture* pic, const SkMatrix* matrix, con
st SkPaint* paint) { | 254 void SkRecorder::onDrawPicture(const SkPicture* pic, const SkMatrix* matrix, con
st SkPaint* paint) { |
| 255 fApproxBytesUsedBySubPictures += SkPictureUtils::ApproximateBytesUsed(pic); |
251 APPEND(DrawPicture, this->copy(paint), pic, matrix ? *matrix : SkMatrix::I()
); | 256 APPEND(DrawPicture, this->copy(paint), pic, matrix ? *matrix : SkMatrix::I()
); |
252 } | 257 } |
253 | 258 |
254 void SkRecorder::onDrawVertices(VertexMode vmode, | 259 void SkRecorder::onDrawVertices(VertexMode vmode, |
255 int vertexCount, const SkPoint vertices[], | 260 int vertexCount, const SkPoint vertices[], |
256 const SkPoint texs[], const SkColor colors[], | 261 const SkPoint texs[], const SkColor colors[], |
257 SkXfermode* xmode, | 262 SkXfermode* xmode, |
258 const uint16_t indices[], int indexCount, const
SkPaint& paint) { | 263 const uint16_t indices[], int indexCount, const
SkPaint& paint) { |
259 APPEND(DrawVertices, delay_copy(paint), | 264 APPEND(DrawVertices, delay_copy(paint), |
260 vmode, | 265 vmode, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 } | 337 } |
333 | 338 |
334 void SkRecorder::addComment(const char* key, const char* value) { | 339 void SkRecorder::addComment(const char* key, const char* value) { |
335 APPEND(AddComment, this->copy(key), this->copy(value)); | 340 APPEND(AddComment, this->copy(key), this->copy(value)); |
336 } | 341 } |
337 | 342 |
338 void SkRecorder::endCommentGroup() { | 343 void SkRecorder::endCommentGroup() { |
339 APPEND(EndCommentGroup); | 344 APPEND(EndCommentGroup); |
340 } | 345 } |
341 | 346 |
OLD | NEW |