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 "SkBigPicture.h" | 8 #include "SkBigPicture.h" |
9 #include "SkData.h" | 9 #include "SkData.h" |
10 #include "SkDrawable.h" | 10 #include "SkDrawable.h" |
11 #include "SkLayerInfo.h" | 11 #include "SkLayerInfo.h" |
12 #include "SkPictureRecorder.h" | 12 #include "SkPictureRecorder.h" |
13 #include "SkPictureUtils.h" | 13 #include "SkPictureUtils.h" |
14 #include "SkRecord.h" | 14 #include "SkRecord.h" |
15 #include "SkRecordDraw.h" | 15 #include "SkRecordDraw.h" |
16 #include "SkRecordOpts.h" | 16 #include "SkRecordOpts.h" |
17 #include "SkRecorder.h" | 17 #include "SkRecorder.h" |
18 #include "SkTypes.h" | 18 #include "SkTypes.h" |
19 | 19 |
20 SkPictureRecorder::SkPictureRecorder() { | 20 SkPictureRecorder::SkPictureRecorder() { |
21 fActivelyRecording = false; | 21 fActivelyRecording = false; |
22 fRecorder.reset(SkNEW_ARGS(SkRecorder, (nullptr, SkRect::MakeWH(0,0), &fMini
Recorder))); | 22 fRecorder.reset(new SkRecorder(nullptr, SkRect::MakeWH(0, 0), &fMiniRecorder
)); |
23 } | 23 } |
24 | 24 |
25 SkPictureRecorder::~SkPictureRecorder() {} | 25 SkPictureRecorder::~SkPictureRecorder() {} |
26 | 26 |
27 SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect, | 27 SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect, |
28 SkBBHFactory* bbhFactory /* = NULL *
/, | 28 SkBBHFactory* bbhFactory /* = NULL *
/, |
29 uint32_t recordFlags /* = 0 */) { | 29 uint32_t recordFlags /* = 0 */) { |
30 fCullRect = cullRect; | 30 fCullRect = cullRect; |
31 fFlags = recordFlags; | 31 fFlags = recordFlags; |
32 | 32 |
33 if (bbhFactory) { | 33 if (bbhFactory) { |
34 fBBH.reset((*bbhFactory)(cullRect)); | 34 fBBH.reset((*bbhFactory)(cullRect)); |
35 SkASSERT(fBBH.get()); | 35 SkASSERT(fBBH.get()); |
36 } | 36 } |
37 | 37 |
38 if (!fRecord) { | 38 if (!fRecord) { |
39 fRecord.reset(SkNEW(SkRecord)); | 39 fRecord.reset(new SkRecord); |
40 } | 40 } |
41 SkRecorder::DrawPictureMode dpm = (recordFlags & kPlaybackDrawPicture_Record
Flag) | 41 SkRecorder::DrawPictureMode dpm = (recordFlags & kPlaybackDrawPicture_Record
Flag) |
42 ? SkRecorder::Playback_DrawPictureMode | 42 ? SkRecorder::Playback_DrawPictureMode |
43 : SkRecorder::Record_DrawPictureMode; | 43 : SkRecorder::Record_DrawPictureMode; |
44 fRecorder->reset(fRecord.get(), cullRect, dpm, &fMiniRecorder); | 44 fRecorder->reset(fRecord.get(), cullRect, dpm, &fMiniRecorder); |
45 fActivelyRecording = true; | 45 fActivelyRecording = true; |
46 return this->getRecordingCanvas(); | 46 return this->getRecordingCanvas(); |
47 } | 47 } |
48 | 48 |
49 SkCanvas* SkPictureRecorder::getRecordingCanvas() { | 49 SkCanvas* SkPictureRecorder::getRecordingCanvas() { |
50 return fActivelyRecording ? fRecorder.get() : nullptr; | 50 return fActivelyRecording ? fRecorder.get() : nullptr; |
51 } | 51 } |
52 | 52 |
53 SkPicture* SkPictureRecorder::endRecordingAsPicture() { | 53 SkPicture* SkPictureRecorder::endRecordingAsPicture() { |
54 fActivelyRecording = false; | 54 fActivelyRecording = false; |
55 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. | 55 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. |
56 | 56 |
57 if (fRecord->count() == 0) { | 57 if (fRecord->count() == 0) { |
58 return fMiniRecorder.detachAsPicture(fCullRect); | 58 return fMiniRecorder.detachAsPicture(fCullRect); |
59 } | 59 } |
60 | 60 |
61 // TODO: delay as much of this work until just before first playback? | 61 // TODO: delay as much of this work until just before first playback? |
62 SkRecordOptimize(fRecord); | 62 SkRecordOptimize(fRecord); |
63 | 63 |
64 SkAutoTUnref<SkLayerInfo> saveLayerData; | 64 SkAutoTUnref<SkLayerInfo> saveLayerData; |
65 | 65 |
66 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { | 66 if (fBBH && (fFlags & kComputeSaveLayerInfo_RecordFlag)) { |
67 saveLayerData.reset(SkNEW(SkLayerInfo)); | 67 saveLayerData.reset(new SkLayerInfo); |
68 } | 68 } |
69 | 69 |
70 SkDrawableList* drawableList = fRecorder->getDrawableList(); | 70 SkDrawableList* drawableList = fRecorder->getDrawableList(); |
71 SkBigPicture::SnapshotArray* pictList = | 71 SkBigPicture::SnapshotArray* pictList = |
72 drawableList ? drawableList->newDrawableSnapshot() : NULL; | 72 drawableList ? drawableList->newDrawableSnapshot() : NULL; |
73 | 73 |
74 if (fBBH.get()) { | 74 if (fBBH.get()) { |
75 if (saveLayerData) { | 75 if (saveLayerData) { |
76 SkRecordComputeLayers(fCullRect, *fRecord, pictList, fBBH.get(), sav
eLayerData); | 76 SkRecordComputeLayers(fCullRect, *fRecord, pictList, fBBH.get(), sav
eLayerData); |
77 } else { | 77 } else { |
78 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); | 78 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); |
79 } | 79 } |
80 SkRect bbhBound = fBBH->getRootBound(); | 80 SkRect bbhBound = fBBH->getRootBound(); |
81 SkASSERT((bbhBound.isEmpty() || fCullRect.contains(bbhBound)) | 81 SkASSERT((bbhBound.isEmpty() || fCullRect.contains(bbhBound)) |
82 || (bbhBound.isEmpty() && fCullRect.isEmpty())); | 82 || (bbhBound.isEmpty() && fCullRect.isEmpty())); |
83 fCullRect = bbhBound; | 83 fCullRect = bbhBound; |
84 } | 84 } |
85 | 85 |
86 size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures(); | 86 size_t subPictureBytes = fRecorder->approxBytesUsedBySubPictures(); |
87 for (int i = 0; pictList && i < pictList->count(); i++) { | 87 for (int i = 0; pictList && i < pictList->count(); i++) { |
88 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin(
)[i]); | 88 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->begin(
)[i]); |
89 } | 89 } |
90 return SkNEW_ARGS(SkBigPicture, (fCullRect, | 90 return new SkBigPicture(fCullRect, fRecord.detach(), pictList, fBBH.detach()
, |
91 fRecord.detach(), | 91 saveLayerData.detach(), subPictureBytes); |
92 pictList, | |
93 fBBH.detach(), | |
94 saveLayerData.detach(), | |
95 subPictureBytes)); | |
96 } | 92 } |
97 | 93 |
98 SkPicture* SkPictureRecorder::endRecordingAsPicture(const SkRect& cullRect) { | 94 SkPicture* SkPictureRecorder::endRecordingAsPicture(const SkRect& cullRect) { |
99 fCullRect = cullRect; | 95 fCullRect = cullRect; |
100 return this->endRecordingAsPicture(); | 96 return this->endRecordingAsPicture(); |
101 } | 97 } |
102 | 98 |
103 | 99 |
104 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { | 100 void SkPictureRecorder::partialReplay(SkCanvas* canvas) const { |
105 if (NULL == canvas) { | 101 if (NULL == canvas) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 SkBigPicture::SnapshotArray* pictList = NULL; | 148 SkBigPicture::SnapshotArray* pictList = NULL; |
153 if (fDrawableList) { | 149 if (fDrawableList) { |
154 // TODO: should we plumb-down the BBHFactory and recordFlags from ou
r host | 150 // TODO: should we plumb-down the BBHFactory and recordFlags from ou
r host |
155 // PictureRecorder? | 151 // PictureRecorder? |
156 pictList = fDrawableList->newDrawableSnapshot(); | 152 pictList = fDrawableList->newDrawableSnapshot(); |
157 } | 153 } |
158 | 154 |
159 SkAutoTUnref<SkLayerInfo> saveLayerData; | 155 SkAutoTUnref<SkLayerInfo> saveLayerData; |
160 | 156 |
161 if (fBBH && fDoSaveLayerInfo) { | 157 if (fBBH && fDoSaveLayerInfo) { |
162 saveLayerData.reset(SkNEW(SkLayerInfo)); | 158 saveLayerData.reset(new SkLayerInfo); |
163 | 159 |
164 SkBBoxHierarchy* bbh = NULL; // we've already computed fBBH (rece
ived in constructor) | 160 SkBBoxHierarchy* bbh = NULL; // we've already computed fBBH (rece
ived in constructor) |
165 // TODO: update saveLayer info computation to reuse the already comp
uted | 161 // TODO: update saveLayer info computation to reuse the already comp
uted |
166 // bounds in 'fBBH' | 162 // bounds in 'fBBH' |
167 SkRecordComputeLayers(fBounds, *fRecord, pictList, bbh, saveLayerDat
a); | 163 SkRecordComputeLayers(fBounds, *fRecord, pictList, bbh, saveLayerDat
a); |
168 } | 164 } |
169 | 165 |
170 size_t subPictureBytes = 0; | 166 size_t subPictureBytes = 0; |
171 for (int i = 0; pictList && i < pictList->count(); i++) { | 167 for (int i = 0; pictList && i < pictList->count(); i++) { |
172 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->be
gin()[i]); | 168 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->be
gin()[i]); |
173 } | 169 } |
174 // SkBigPicture will take ownership of a ref on both fRecord and fBBH. | 170 // SkBigPicture will take ownership of a ref on both fRecord and fBBH. |
175 // We're not willing to give up our ownership, so we must ref them for S
kPicture. | 171 // We're not willing to give up our ownership, so we must ref them for S
kPicture. |
176 return SkNEW_ARGS(SkBigPicture, (fBounds, | 172 return new SkBigPicture(fBounds, SkRef(fRecord.get()), pictList, SkSafeR
ef(fBBH.get()), |
177 SkRef(fRecord.get()), | 173 saveLayerData.detach(), subPictureBytes); |
178 pictList, | |
179 SkSafeRef(fBBH.get()), | |
180 saveLayerData.detach(), | |
181 subPictureBytes)); | |
182 } | 174 } |
183 }; | 175 }; |
184 | 176 |
185 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { | 177 SkDrawable* SkPictureRecorder::endRecordingAsDrawable() { |
186 fActivelyRecording = false; | 178 fActivelyRecording = false; |
187 fRecorder->flushMiniRecorder(); | 179 fRecorder->flushMiniRecorder(); |
188 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. | 180 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. |
189 | 181 |
190 // TODO: delay as much of this work until just before first playback? | 182 // TODO: delay as much of this work until just before first playback? |
191 SkRecordOptimize(fRecord); | 183 SkRecordOptimize(fRecord); |
192 | 184 |
193 if (fBBH.get()) { | 185 if (fBBH.get()) { |
194 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); | 186 SkRecordFillBounds(fCullRect, *fRecord, fBBH.get()); |
195 } | 187 } |
196 | 188 |
197 SkDrawable* drawable = SkNEW_ARGS(SkRecordedDrawable, | 189 SkDrawable* drawable = |
198 (fRecord, fBBH, fRecorder->detachDrawabl
eList(), | 190 new SkRecordedDrawable(fRecord, fBBH, fRecorder->detachDrawableList(
), fCullRect, |
199 fCullRect, | 191 SkToBool(fFlags & kComputeSaveLayerInfo_Recor
dFlag)); |
200 SkToBool(fFlags & kComputeSaveLayerInfo
_RecordFlag))); | |
201 | 192 |
202 // release our refs now, so only the drawable will be the owner. | 193 // release our refs now, so only the drawable will be the owner. |
203 fRecord.reset(NULL); | 194 fRecord.reset(NULL); |
204 fBBH.reset(NULL); | 195 fBBH.reset(NULL); |
205 | 196 |
206 return drawable; | 197 return drawable; |
207 } | 198 } |
OLD | NEW |