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 "SkData.h" | 8 #include "SkData.h" |
9 #include "SkDrawable.h" | 9 #include "SkDrawable.h" |
10 #include "SkLayerInfo.h" | 10 #include "SkLayerInfo.h" |
11 #include "SkPictureRecorder.h" | 11 #include "SkPictureRecorder.h" |
12 #include "SkRecord.h" | 12 #include "SkRecord.h" |
13 #include "SkRecordDraw.h" | 13 #include "SkRecordDraw.h" |
14 #include "SkRecorder.h" | 14 #include "SkRecorder.h" |
15 #include "SkRecordOpts.h" | 15 #include "SkRecordOpts.h" |
16 #include "SkTypes.h" | 16 #include "SkTypes.h" |
17 | 17 |
18 SkPictureRecorder::SkPictureRecorder() { | 18 SkPictureRecorder::SkPictureRecorder() {} |
19 fRecorder.reset(SkNEW_ARGS(SkRecorder, (nullptr, SkRect::MakeWH(0,0)))); | |
20 } | |
21 | 19 |
22 SkPictureRecorder::~SkPictureRecorder() {} | 20 SkPictureRecorder::~SkPictureRecorder() {} |
23 | 21 |
24 SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect, | 22 SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect, |
25 SkBBHFactory* bbhFactory /* = NULL *
/, | 23 SkBBHFactory* bbhFactory /* = NULL *
/, |
26 uint32_t recordFlags /* = 0 */) { | 24 uint32_t recordFlags /* = 0 */) { |
27 fCullRect = cullRect; | 25 fCullRect = cullRect; |
28 fFlags = recordFlags; | 26 fFlags = recordFlags; |
29 | 27 |
30 if (bbhFactory) { | 28 if (bbhFactory) { |
31 fBBH.reset((*bbhFactory)(cullRect)); | 29 fBBH.reset((*bbhFactory)(cullRect)); |
32 SkASSERT(fBBH.get()); | 30 SkASSERT(fBBH.get()); |
33 } | 31 } |
34 | 32 |
35 fRecord.reset(SkNEW(SkRecord)); | 33 fRecord.reset(SkNEW(SkRecord)); |
36 fRecorder->reset(fRecord.get(), cullRect); | 34 fRecorder.reset(SkNEW_ARGS(SkRecorder, (fRecord.get(), cullRect))); |
37 return this->getRecordingCanvas(); | 35 return this->getRecordingCanvas(); |
38 } | 36 } |
39 | 37 |
40 SkCanvas* SkPictureRecorder::getRecordingCanvas() { | 38 SkCanvas* SkPictureRecorder::getRecordingCanvas() { |
41 return fRecorder.get(); | 39 return fRecorder.get(); |
42 } | 40 } |
43 | 41 |
44 SkPicture* SkPictureRecorder::endRecordingAsPicture() { | 42 SkPicture* SkPictureRecorder::endRecordingAsPicture() { |
45 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. | |
46 // TODO: delay as much of this work until just before first playback? | 43 // TODO: delay as much of this work until just before first playback? |
47 SkRecordOptimize(fRecord); | 44 SkRecordOptimize(fRecord); |
48 | 45 |
49 SkAutoTUnref<SkLayerInfo> saveLayerData; | 46 SkAutoTUnref<SkLayerInfo> saveLayerData; |
50 | 47 |
51 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { | 48 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { |
52 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); | 49 SkPicture::AccelData::Key key = SkLayerInfo::ComputeKey(); |
53 | 50 |
54 saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key))); | 51 saveLayerData.reset(SkNEW_ARGS(SkLayerInfo, (key))); |
55 } | 52 } |
(...skipping 13 matching lines...) Expand all Loading... |
69 fCullRect = bbhBound; | 66 fCullRect = bbhBound; |
70 } | 67 } |
71 | 68 |
72 SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullRect, fRecord, pictList, fBBH)
); | 69 SkPicture* pict = SkNEW_ARGS(SkPicture, (fCullRect, fRecord, pictList, fBBH)
); |
73 | 70 |
74 if (saveLayerData) { | 71 if (saveLayerData) { |
75 pict->EXPERIMENTAL_addAccelData(saveLayerData); | 72 pict->EXPERIMENTAL_addAccelData(saveLayerData); |
76 } | 73 } |
77 | 74 |
78 // release our refs now, so only the picture will be the owner. | 75 // release our refs now, so only the picture will be the owner. |
| 76 fRecorder.reset(NULL); |
79 fRecord.reset(NULL); | 77 fRecord.reset(NULL); |
80 fBBH.reset(NULL); | 78 fBBH.reset(NULL); |
81 | 79 |
82 return pict; | 80 return pict; |
83 } | 81 } |
84 | 82 |
85 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { | 83 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { |
86 if (NULL == canvas) { | 84 if (NULL == canvas) { |
87 return; | 85 return; |
88 } | 86 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 SkPicture* pict = SkNEW_ARGS(SkPicture, (fBounds, fRecord, pictList, fBB
H)); | 151 SkPicture* pict = SkNEW_ARGS(SkPicture, (fBounds, fRecord, pictList, fBB
H)); |
154 | 152 |
155 if (saveLayerData) { | 153 if (saveLayerData) { |
156 pict->EXPERIMENTAL_addAccelData(saveLayerData); | 154 pict->EXPERIMENTAL_addAccelData(saveLayerData); |
157 } | 155 } |
158 return pict; | 156 return pict; |
159 } | 157 } |
160 }; | 158 }; |
161 | 159 |
162 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { | 160 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { |
163 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. | |
164 // TODO: delay as much of this work until just before first playback? | 161 // TODO: delay as much of this work until just before first playback? |
165 SkRecordOptimize(fRecord); | 162 SkRecordOptimize(fRecord); |
166 | 163 |
167 if (fBBH.get()) { | 164 if (fBBH.get()) { |
168 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); | 165 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); |
169 } | 166 } |
170 | 167 |
171 SkDrawable* drawable = SkNEW_ARGS(SkRecordedDrawable, | 168 SkDrawable* drawable = SkNEW_ARGS(SkRecordedDrawable, |
172 (fRecord, fBBH, fRecorder->detachDrawabl
eList(), | 169 (fRecord, fBBH, fRecorder->detachDrawabl
eList(), |
173 fCullRect, | 170 fCullRect, |
174 SkToBool(fFlags & kComputeSaveLayerInfo
_RecordFlag))); | 171 SkToBool(fFlags & kComputeSaveLayerInfo
_RecordFlag))); |
175 | 172 |
176 // release our refs now, so only the drawable will be the owner. | 173 // release our refs now, so only the drawable will be the owner. |
| 174 fRecorder.reset(NULL); |
177 fRecord.reset(NULL); | 175 fRecord.reset(NULL); |
178 fBBH.reset(NULL); | 176 fBBH.reset(NULL); |
179 | 177 |
180 return drawable; | 178 return drawable; |
181 } | 179 } |
OLD | NEW |