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 "SkPictureData.h" |
| 13 #include "SkPictureRecord.h" |
12 #include "SkPictureRecorder.h" | 14 #include "SkPictureRecorder.h" |
13 #include "SkPictureUtils.h" | 15 #include "SkPictureUtils.h" |
14 #include "SkRecord.h" | 16 #include "SkRecord.h" |
15 #include "SkRecordDraw.h" | 17 #include "SkRecordDraw.h" |
16 #include "SkRecordOpts.h" | 18 #include "SkRecordOpts.h" |
17 #include "SkRecorder.h" | 19 #include "SkRecorder.h" |
18 #include "SkTypes.h" | 20 #include "SkTypes.h" |
| 21 #include "SkWriteBuffer.h" |
19 | 22 |
20 SkPictureRecorder::SkPictureRecorder() { | 23 SkPictureRecorder::SkPictureRecorder() { |
21 fActivelyRecording = false; | 24 fActivelyRecording = false; |
22 fRecorder.reset(new SkRecorder(nullptr, SkRect::MakeWH(0, 0), &fMiniRecorder
)); | 25 fRecorder.reset(new SkRecorder(nullptr, SkRect::MakeWH(0, 0), &fMiniRecorder
)); |
23 } | 26 } |
24 | 27 |
25 SkPictureRecorder::~SkPictureRecorder() {} | 28 SkPictureRecorder::~SkPictureRecorder() {} |
26 | 29 |
27 SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect, | 30 SkCanvas* SkPictureRecorder::beginRecording(const SkRect& cullRect, |
28 SkBBHFactory* bbhFactory /* = nullpt
r */, | 31 SkBBHFactory* bbhFactory /* = nullpt
r */, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 171 |
169 size_t subPictureBytes = 0; | 172 size_t subPictureBytes = 0; |
170 for (int i = 0; pictList && i < pictList->count(); i++) { | 173 for (int i = 0; pictList && i < pictList->count(); i++) { |
171 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->be
gin()[i]); | 174 subPictureBytes += SkPictureUtils::ApproximateBytesUsed(pictList->be
gin()[i]); |
172 } | 175 } |
173 // SkBigPicture will take ownership of a ref on both fRecord and fBBH. | 176 // SkBigPicture will take ownership of a ref on both fRecord and fBBH. |
174 // We're not willing to give up our ownership, so we must ref them for S
kPicture. | 177 // We're not willing to give up our ownership, so we must ref them for S
kPicture. |
175 return new SkBigPicture(fBounds, SkRef(fRecord.get()), pictList, SkSafeR
ef(fBBH.get()), | 178 return new SkBigPicture(fBounds, SkRef(fRecord.get()), pictList, SkSafeR
ef(fBBH.get()), |
176 saveLayerData.release(), subPictureBytes); | 179 saveLayerData.release(), subPictureBytes); |
177 } | 180 } |
| 181 |
| 182 void flatten(SkWriteBuffer& buffer) const { |
| 183 // Write the bounds. |
| 184 buffer.writeRect(fBounds); |
| 185 |
| 186 // Create an SkPictureRecord to record the draw commands. |
| 187 SkPictInfo info; |
| 188 SkPictureRecord pictureRecord(SkISize::Make(fBounds.width(), fBounds.hei
ght()), 0); |
| 189 |
| 190 // If the query contains the whole picture, don't bother with the boundi
ng box hierarchy. |
| 191 SkRect clipBounds; |
| 192 pictureRecord.getClipBounds(&clipBounds); |
| 193 SkBBoxHierarchy* bbh; |
| 194 if (clipBounds.contains(fBounds)) { |
| 195 bbh = nullptr; |
| 196 } else { |
| 197 bbh = fBBH.get(); |
| 198 } |
| 199 |
| 200 // Record the draw commands. |
| 201 pictureRecord.beginRecording(); |
| 202 SkRecordDraw(*fRecord, &pictureRecord, nullptr, fDrawableList->begin(), |
| 203 fDrawableList->count(), bbh, nullptr); |
| 204 pictureRecord.endRecording(); |
| 205 |
| 206 // Flatten the recorded commands and drawables. |
| 207 SkPictureData pictureData(pictureRecord, info, false); |
| 208 pictureData.flatten(buffer); |
| 209 } |
| 210 |
| 211 const char* getTypeName() const override { |
| 212 return "SkRecordedDrawable"; |
| 213 } |
178 }; | 214 }; |
179 | 215 |
180 sk_sp<SkDrawable> SkPictureRecorder::finishRecordingAsDrawable() { | 216 sk_sp<SkDrawable> SkPictureRecorder::finishRecordingAsDrawable() { |
181 fActivelyRecording = false; | 217 fActivelyRecording = false; |
182 fRecorder->flushMiniRecorder(); | 218 fRecorder->flushMiniRecorder(); |
183 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. | 219 fRecorder->restoreToCount(1); // If we were missing any restores, add them
now. |
184 | 220 |
185 // TODO: delay as much of this work until just before first playback? | 221 // TODO: delay as much of this work until just before first playback? |
186 SkRecordOptimize(fRecord); | 222 SkRecordOptimize(fRecord); |
187 | 223 |
188 if (fBBH.get()) { | 224 if (fBBH.get()) { |
189 SkAutoTMalloc<SkRect> bounds(fRecord->count()); | 225 SkAutoTMalloc<SkRect> bounds(fRecord->count()); |
190 SkRecordFillBounds(fCullRect, *fRecord, bounds); | 226 SkRecordFillBounds(fCullRect, *fRecord, bounds); |
191 fBBH->insert(bounds, fRecord->count()); | 227 fBBH->insert(bounds, fRecord->count()); |
192 } | 228 } |
193 | 229 |
194 sk_sp<SkDrawable> drawable = | 230 sk_sp<SkDrawable> drawable = |
195 sk_make_sp<SkRecordedDrawable>(fRecord, fBBH, fRecorder->detachDrawab
leList(), fCullRect, | 231 sk_make_sp<SkRecordedDrawable>(fRecord, fBBH, fRecorder->detachDrawab
leList(), fCullRect, |
196 SkToBool(fFlags & kComputeSaveLayerInfo_Recor
dFlag)); | 232 SkToBool(fFlags & kComputeSaveLayerInfo_Recor
dFlag)); |
197 | 233 |
198 // release our refs now, so only the drawable will be the owner. | 234 // release our refs now, so only the drawable will be the owner. |
199 fRecord.reset(nullptr); | 235 fRecord.reset(nullptr); |
200 fBBH.reset(nullptr); | 236 fBBH.reset(nullptr); |
201 | 237 |
202 return drawable; | 238 return drawable; |
203 } | 239 } |
OLD | NEW |