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 "SkBBoxHierarchyRecord.h" | 8 #include "SkBBoxHierarchyRecord.h" |
9 #include "SkPicturePlayback.h" | 9 #include "SkPicturePlayback.h" |
10 #include "SkPictureRecord.h" | 10 #include "SkPictureRecord.h" |
11 #include "SkPictureRecorder.h" | 11 #include "SkPictureRecorder.h" |
12 #include "SkTypes.h" | 12 #include "SkRecord.h" |
| 13 #include "SkRecordDraw.h" |
| 14 #include "SkRecorder.h" |
| 15 #include "SkTypes.h" |
13 | 16 |
14 SkPictureRecorder::~SkPictureRecorder() { | 17 SkPictureRecorder::~SkPictureRecorder() { |
15 SkSafeSetNull(fCanvas); | 18 this->reset(); |
| 19 } |
| 20 |
| 21 void SkPictureRecorder::reset() { |
| 22 SkSafeSetNull(fPictureRecord); |
| 23 SkSafeSetNull(fRecorder); |
| 24 SkDELETE(fRecord); |
| 25 fRecord = NULL; |
16 } | 26 } |
17 | 27 |
18 SkCanvas* SkPictureRecorder::beginRecording(int width, int height, | 28 SkCanvas* SkPictureRecorder::beginRecording(int width, int height, |
19 SkBBHFactory* bbhFactory /* = NULL *
/, | 29 SkBBHFactory* bbhFactory /* = NULL *
/, |
20 uint32_t recordFlags /* = 0 */) { | 30 uint32_t recordFlags /* = 0 */) { |
21 SkSafeSetNull(fCanvas); // terminate any prior recording(s) | 31 this->reset(); // terminate any prior recording(s) |
22 | |
23 fWidth = width; | 32 fWidth = width; |
24 fHeight = height; | 33 fHeight = height; |
25 | 34 |
26 const SkISize size = SkISize::Make(width, height); | 35 const SkISize size = SkISize::Make(width, height); |
27 | 36 |
28 if (NULL != bbhFactory) { | 37 if (NULL != bbhFactory) { |
29 SkAutoTUnref<SkBBoxHierarchy> tree((*bbhFactory)(width, height)); | 38 SkAutoTUnref<SkBBoxHierarchy> tree((*bbhFactory)(width, height)); |
30 SkASSERT(NULL != tree); | 39 SkASSERT(NULL != tree); |
31 fCanvas = SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordFlags, tree.get
())); | 40 fPictureRecord = SkNEW_ARGS(SkBBoxHierarchyRecord, (size, recordFlags, t
ree.get())); |
32 } else { | 41 } else { |
33 fCanvas = SkNEW_ARGS(SkPictureRecord, (size, recordFlags)); | 42 fPictureRecord = SkNEW_ARGS(SkPictureRecord, (size, recordFlags)); |
34 } | 43 } |
35 | 44 |
36 fCanvas->beginRecording(); | 45 fPictureRecord->beginRecording(); |
| 46 return this->getRecordingCanvas(); |
| 47 } |
37 | 48 |
38 return fCanvas; | 49 SkCanvas* SkPictureRecorder::EXPERIMENTAL_beginRecording(int width, int height, |
| 50 SkBBHFactory* bbhFactor
y /* = NULL */) { |
| 51 this->reset(); |
| 52 fWidth = width; |
| 53 fHeight = height; |
| 54 |
| 55 // TODO: plumb bbhFactory through |
| 56 fRecord = SkNEW(SkRecord); |
| 57 fRecorder = SkNEW_ARGS(SkRecorder, (fRecord, width, height)); |
| 58 return this->getRecordingCanvas(); |
39 } | 59 } |
40 | 60 |
41 SkCanvas* SkPictureRecorder::getRecordingCanvas() { | 61 SkCanvas* SkPictureRecorder::getRecordingCanvas() { |
42 return fCanvas; | 62 if (NULL != fRecorder) { |
| 63 return fRecorder; |
| 64 } |
| 65 return fPictureRecord; |
43 } | 66 } |
44 | 67 |
45 SkPicture* SkPictureRecorder::endRecording() { | 68 SkPicture* SkPictureRecorder::endRecording() { |
46 if (NULL == fCanvas) { | 69 SkPicture* picture = NULL; |
47 return NULL; | 70 |
| 71 if (NULL != fRecorder) { |
| 72 // TODO: picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, fRecord)); |
| 73 // fRecord = NULL; |
48 } | 74 } |
49 | 75 |
50 fCanvas->endRecording(); | 76 if (NULL != fPictureRecord) { |
| 77 fPictureRecord->endRecording(); |
| 78 const bool deepCopyOps = false; |
| 79 picture = SkNEW_ARGS(SkPicture, (fWidth, fHeight, *fPictureRecord, deepC
opyOps)); |
| 80 } |
51 | 81 |
52 const bool deepCopyOps = false; | 82 this->reset(); |
53 SkAutoTUnref<SkPicture> picture(SkNEW_ARGS(SkPicture, (fWidth, fHeight, | 83 return picture; |
54 *fCanvas, deepCopyOps
))); | |
55 SkSafeSetNull(fCanvas); | |
56 | |
57 return picture.detach(); | |
58 } | 84 } |
59 | 85 |
60 void SkPictureRecorder::internalOnly_EnableOpts(bool enableOpts) { | 86 void SkPictureRecorder::internalOnly_EnableOpts(bool enableOpts) { |
61 if (NULL != fCanvas) { | 87 if (NULL != fPictureRecord) { |
62 fCanvas->internalOnly_EnableOpts(enableOpts); | 88 fPictureRecord->internalOnly_EnableOpts(enableOpts); |
63 } | 89 } |
64 } | 90 } |
65 | 91 |
66 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { | 92 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { |
67 if (NULL == fCanvas || NULL == canvas) { | 93 if (NULL == canvas) { |
68 // Not recording or nothing to replay into | |
69 return; | 94 return; |
70 } | 95 } |
71 | 96 |
72 const bool deepCopyOps = true; | 97 if (NULL != fRecorder) { |
73 SkAutoTUnref<SkPicture> picture(SkNEW_ARGS(SkPicture, (fWidth, fHeight, | 98 SkRecordDraw(*fRecord, canvas); |
74 *fCanvas, deepCopyOps
))); | 99 } |
75 picture->draw(canvas); | 100 |
| 101 if (NULL != fPictureRecord) { |
| 102 const bool deepCopyOps = true; |
| 103 SkPicture picture(fWidth, fHeight, *fPictureRecord, deepCopyOps); |
| 104 picture.draw(canvas); |
| 105 } |
76 } | 106 } |
OLD | NEW |